• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Return-To-The-Roots / s25client / 21285142390

23 Jan 2026 11:49AM UTC coverage: 50.761% (+0.1%) from 50.663%
21285142390

Pull #1679

github

web-flow
Merge b1ffe8192 into 12da8bf44
Pull Request #1679: Add all classic S2 cheats and a few more

94 of 155 new or added lines in 12 files covered. (60.65%)

8 existing lines in 6 files now uncovered.

22800 of 44916 relevant lines covered (50.76%)

41543.76 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

11.96
/libs/s25main/world/GameWorldView.cpp
1
// Copyright (C) 2005 - 2021 Settlers Freaks (sf-team at siedler25.org)
2
//
3
// SPDX-License-Identifier: GPL-2.0-or-later
4

5
#include "world/GameWorldView.h"
6
#include "CatapultStone.h"
7
#include "Cheats.h"
8
#include "FOWObjects.h"
9
#include "GameInterface.h"
10
#include "GamePlayer.h"
11
#include "GlobalGameSettings.h"
12
#include "Loader.h"
13
#include "MapGeometry.h"
14
#include "Settings.h"
15
#include "addons/AddonMaxWaterwayLength.h"
16
#include "buildings/noBuildingSite.h"
17
#include "buildings/nobMilitary.h"
18
#include "buildings/nobUsual.h"
19
#include "drivers/VideoDriverWrapper.h"
20
#include "helpers/EnumArray.h"
21
#include "helpers/containerUtils.h"
22
#include "helpers/toString.h"
23
#include "ogl/FontStyle.h"
24
#include "ogl/glArchivItem_Bitmap.h"
25
#include "ogl/glFont.h"
26
#include "ogl/glSmartBitmap.h"
27
#include "world/GameWorldBase.h"
28
#include "world/GameWorldViewer.h"
29
#include "gameTypes/RoadBuildState.h"
30
#include "gameData/BuildingConsts.h"
31
#include "gameData/GuiConsts.h"
32
#include "gameData/MapConsts.h"
33
#include "s25util/error.h"
34
#include "s25util/warningSuppression.h"
35
#include <glad/glad.h>
36
#include <boost/format.hpp>
37
#include <cmath>
38

39
GameWorldView::GameWorldView(const GameWorldViewer& gwv, const Position& pos, const Extent& size)
10✔
40
    : selPt(0, 0), show_bq(SETTINGS.ingame.showBQ), show_names(SETTINGS.ingame.showNames),
10✔
41
      show_productivity(SETTINGS.ingame.showProductivity), offset(0, 0), lastOffset(0, 0), gwv(gwv), origin_(pos),
20✔
42
      size_(size), zoomFactor_(1.f), targetZoomFactor_(1.f), zoomSpeed_(0.f)
20✔
43
{
44
    updateEffectiveZoomFactor();
10✔
45
    MoveBy({0, 0});
10✔
46
}
10✔
47

48
const GameWorldBase& GameWorldView::GetWorld() const
82✔
49
{
50
    return gwv.GetWorld();
82✔
51
}
52

53
SoundManager& GameWorldView::GetSoundMgr()
×
54
{
55
    return const_cast<GameWorldViewer&>(gwv).GetSoundMgr();
×
56
}
57

58
void GameWorldView::SetNextZoomFactor()
×
59
{
60
    if(zoomFactor_ == targetZoomFactor_) // == with float is ok here, is explicitly set in last step //-V550
×
61
        return;
×
62

63
    float remainingZoomDiff = targetZoomFactor_ - zoomFactor_;
×
64

65
    if(std::abs(remainingZoomDiff) <= 0.5 * zoomSpeed_ * zoomSpeed_ / ZOOM_ACCELERATION)
×
66
    {
67
        // deceleration towards zero zoom speed
68
        if(zoomSpeed_ > 0)
×
69
            zoomSpeed_ -= ZOOM_ACCELERATION;
×
70
        else
71
            zoomSpeed_ += ZOOM_ACCELERATION;
×
72
    } else
73
    {
74
        // acceleration to unlimited speed
75
        if(remainingZoomDiff > 0)
×
76
            zoomSpeed_ += ZOOM_ACCELERATION;
×
77
        else
78
            zoomSpeed_ -= ZOOM_ACCELERATION;
×
79
    }
80

81
    if(std::abs(remainingZoomDiff) < std::abs(zoomSpeed_))
×
82
    {
83
        // last step
84
        zoomFactor_ = targetZoomFactor_;
×
85
        zoomSpeed_ = 0;
×
86
    }
87

88
    zoomFactor_ = zoomFactor_ + zoomSpeed_;
×
89
    updateEffectiveZoomFactor();
×
90
    CalcFxLx();
×
91
}
92

93
float GameWorldView::SetZoomFactor(float zoomFactor, bool smoothTransition /* = true*/)
36✔
94
{
95
    targetZoomFactor_ = zoomFactor;
36✔
96
    if(!smoothTransition)
36✔
97
    {
98
        zoomFactor_ = targetZoomFactor_;
×
99
        updateEffectiveZoomFactor();
×
100
        CalcFxLx();
×
101
    }
102
    return targetZoomFactor_;
36✔
103
}
104

105
float GameWorldView::GetCurrentTargetZoomFactor() const
52✔
106
{
107
    return targetZoomFactor_;
52✔
108
}
109

110
Position GameWorldView::ViewPosToMap(Position pos) const
2✔
111
{
112
    pos -= origin_;
2✔
113
    if(effectiveZoomFactor_ != 1.f)
2✔
114
    {
115
        PointF diff(size_.x - size_.x / effectiveZoomFactor_, size_.y - size_.y / effectiveZoomFactor_);
×
116
        diff /= 2.f;
×
117
        pos = Position(PointF(pos) / effectiveZoomFactor_ + diff);
×
118
    }
119

120
    return pos;
2✔
121
}
122

123
struct ObjectBetweenLines
124
{
125
    noBase& obj;
126
    DrawPoint pos; // Zeichenposition
127

128
    ObjectBetweenLines(noBase& obj, const DrawPoint& pos) : obj(obj), pos(pos) {}
×
129
};
130

131
void GameWorldView::Draw(const RoadBuildState& rb, const MapPoint selected, bool drawMouse, unsigned* water)
×
132
{
133
    SetNextZoomFactor();
×
134

135
    const auto windowSize = VIDEODRIVER.GetWindowSize();
×
136
    const auto& guiScale = VIDEODRIVER.getGuiScale();
×
137
    const auto screenOrigin = guiScale.viewToScreen(origin_);
×
138
    const auto screenSize = guiScale.viewToScreen(size_);
×
139
    glScissor(screenOrigin.x, windowSize.height - (screenOrigin.y + screenSize.y), screenSize.x, screenSize.y);
×
140

141
    int shortestDistToMouse = 100000;
×
142
    Position mousePos = VIDEODRIVER.GetMousePos();
×
143
    mousePos -= Position(origin_);
×
144
    if(effectiveZoomFactor_ != 1.f) //-V550
×
145
    {
146
        glMatrixMode(GL_PROJECTION);
×
147
        glPushMatrix();
×
148
        glScalef(effectiveZoomFactor_, effectiveZoomFactor_, 1);
×
149
        // Offset to center view
150
        PointF diff(size_.x - size_.x / effectiveZoomFactor_, size_.y - size_.y / effectiveZoomFactor_);
×
151
        diff = diff / 2.f;
×
152
        glTranslatef(-diff.x, -diff.y, 0.f);
×
153
        // Also adjust mouse
154
        mousePos = Position(PointF(mousePos) / effectiveZoomFactor_ + diff);
×
155
        glMatrixMode(GL_MODELVIEW);
×
156
    }
157

158
    glTranslatef(static_cast<GLfloat>(origin_.x) / effectiveZoomFactor_,
×
159
                 static_cast<GLfloat>(origin_.y) / effectiveZoomFactor_, 0.0f);
×
160

161
    glTranslatef(static_cast<GLfloat>(-offset.x), static_cast<GLfloat>(-offset.y), 0.0f);
×
162
    const TerrainRenderer& terrainRenderer = gwv.GetTerrainRenderer();
×
163
    terrainRenderer.Draw(GetFirstPt(), GetLastPt(), gwv, water);
×
164
    glTranslatef(static_cast<GLfloat>(offset.x), static_cast<GLfloat>(offset.y), 0.0f);
×
165

NEW
166
    const auto resourceRevealMode = GetWorld().GetGameInterface()->GI_GetCheats().getResourceRevealMode();
×
167

UNCOV
168
    for(int y = firstPt.y; y <= lastPt.y; ++y)
×
169
    {
170
        // Figuren speichern, die in dieser Zeile gemalt werden müssen
171
        // und sich zwischen zwei Zeilen befinden, da sie dazwischen laufen
172
        std::vector<ObjectBetweenLines> between_lines;
×
173

174
        for(int x = firstPt.x; x <= lastPt.x; ++x)
×
175
        {
176
            Position curOffset;
×
177
            const MapPoint curPt = terrainRenderer.ConvertCoords(Position(x, y), &curOffset);
×
178
            DrawPoint curPos = GetWorld().GetNodePos(curPt) - offset + curOffset;
×
179

180
            Position mouseDist = mousePos - curPos;
×
181
            mouseDist *= mouseDist;
×
182
            if(std::abs(mouseDist.x) + std::abs(mouseDist.y) < shortestDistToMouse)
×
183
            {
184
                selPt = curPt;
×
185
                selPtOffset = curOffset;
×
186
                shortestDistToMouse = std::abs(mouseDist.x) + std::abs(mouseDist.y);
×
187
            }
188

189
            Visibility visibility = gwv.GetVisibility(curPt);
×
190

191
            DrawBoundaryStone(curPt, curPos, visibility);
×
192

193
            if(visibility == Visibility::Visible)
×
194
            {
195
                DrawObject(curPt, curPos);
×
196
                DrawMovingFiguresFromBelow(terrainRenderer, Position(x, y), between_lines);
×
197
                DrawFigures(curPt, curPos, between_lines);
×
198

199
                // Construction aid mode
200
                if(show_bq)
×
201
                    DrawConstructionAid(curPt, curPos);
×
202
            } else if(visibility == Visibility::FogOfWar)
×
203
            {
204
                const FOWObject* fowobj = gwv.GetYoungestFOWObject(MapPoint(curPt));
×
205
                if(fowobj)
×
206
                    fowobj->Draw(curPos);
×
207
            }
208

209
            for(IDrawNodeCallback* callback : drawNodeCallbacks)
×
210
                callback->onDraw(curPt, curPos);
×
211

NEW
212
            if(visibility == Visibility::Visible)
×
NEW
213
                DrawResource(curPt, curPos, resourceRevealMode);
×
214
        }
215

216
        // Figuren zwischen den Zeilen zeichnen
217
        for(auto& between_line : between_lines)
×
218
            between_line.obj.Draw(between_line.pos);
×
219
    }
220

221
    if(show_names || show_productivity)
×
222
        DrawNameProductivityOverlay(terrainRenderer);
×
223

224
    DrawGUI(rb, terrainRenderer, selected, drawMouse);
×
225

226
    // Umherfliegende Katapultsteine zeichnen
227
    for(auto* catapult_stone : GetWorld().catapult_stones)
×
228
    {
229
        if(gwv.GetVisibility(catapult_stone->dest_building) == Visibility::Visible
×
230
           || gwv.GetVisibility(catapult_stone->dest_map) == Visibility::Visible)
×
231
            catapult_stone->Draw(offset);
×
232
    }
233

234
    if(effectiveZoomFactor_ != 1.f) //-V550
×
235
    {
236
        glMatrixMode(GL_PROJECTION);
×
237
        glPopMatrix();
×
238
        glMatrixMode(GL_MODELVIEW);
×
239
    }
240
    glTranslatef(-static_cast<GLfloat>(origin_.x) / effectiveZoomFactor_,
×
241
                 -static_cast<GLfloat>(origin_.y) / effectiveZoomFactor_, 0.0f);
×
242

243
    glScissor(0, 0, windowSize.width, windowSize.height);
×
244
}
×
245

246
void GameWorldView::DrawGUI(const RoadBuildState& rb, const TerrainRenderer& terrainRenderer,
×
247
                            const MapPoint& selectedPt, bool drawMouse)
248
{
249
    // Falls im Straßenbaumodus: Punkte um den aktuellen Straßenbaupunkt herum ermitteln
250
    helpers::EnumArray<MapPoint, Direction> road_points;
×
251

252
    unsigned maxWaterWayLen = 0;
×
253
    if(rb.mode != RoadBuildMode::Disabled)
×
254
    {
255
        for(const auto dir : helpers::EnumRange<Direction>{})
×
256
            road_points[dir] = GetWorld().GetNeighbour(rb.point, dir);
×
257

258
        const unsigned index = GetWorld().GetGGS().getSelection(AddonId::MAX_WATERWAY_LENGTH);
×
259
        RTTR_Assert(index < waterwayLengths.size());
×
260
        maxWaterWayLen = waterwayLengths[index];
×
261
    }
262

263
    for(int x = firstPt.x; x <= lastPt.x; ++x)
×
264
    {
265
        for(int y = firstPt.y; y <= lastPt.y; ++y)
×
266
        {
267
            // Coordinates transform
268
            Position curOffset;
×
269
            MapPoint curPt = terrainRenderer.ConvertCoords(Position(x, y), &curOffset);
×
270
            Position curPos = GetWorld().GetNodePos(curPt) - offset + curOffset;
×
271

272
            /// Current point indicated by Mouse
273
            if(drawMouse && selPt == curPt)
×
274
            {
275
                // Mauszeiger am boden
276
                unsigned mid = 22;
×
277
                if(rb.mode == RoadBuildMode::Disabled)
×
278
                {
279
                    switch(gwv.GetBQ(curPt))
×
280
                    {
281
                        case BuildingQuality::Flag: mid = 40; break;
×
282
                        case BuildingQuality::Mine: mid = 41; break;
×
283
                        case BuildingQuality::Hut: mid = 42; break;
×
284
                        case BuildingQuality::House: mid = 43; break;
×
285
                        case BuildingQuality::Castle: mid = 44; break;
×
286
                        case BuildingQuality::Harbor: mid = 45; break;
×
287
                        default: break;
×
288
                    }
289
                }
290
                LOADER.GetMapTexture(mid)->DrawFull(curPos);
×
291
            }
292

293
            // Currently selected point
294
            if(selectedPt == curPt)
×
295
                LOADER.GetMapTexture(20)->DrawFull(curPos);
×
296

297
            // not building roads, no further action needed
298
            if(rb.mode == RoadBuildMode::Disabled)
×
299
                continue;
×
300

301
            // we dont own curPt, no need for any rendering...
302
            if(!gwv.IsPlayerTerritory(curPt))
×
303
                continue;
×
304

305
            // we are in road build mode
306
            // highlight current route pt
307
            if(rb.point == curPt)
×
308
            {
309
                LOADER.GetMapTexture(21)->DrawFull(curPos);
×
310
                continue;
×
311
            }
312

313
            // ensure that curPt is a neighbour of rb.point
314
            if(!helpers::contains(road_points, curPt))
×
315
            {
316
                continue;
×
317
            }
318

319
            // test on maximal water way length
320
            if(rb.mode == RoadBuildMode::Boat && maxWaterWayLen != 0 && rb.route.size() >= maxWaterWayLen)
×
321
                continue;
×
322

323
            // render special icon for route revert
324
            if(!rb.route.empty() && road_points[rb.route.back() + 3u] == curPt)
×
325
            {
326
                LOADER.GetMapTexture(67)->DrawFull(curPos);
×
327
                continue;
×
328
            }
329

330
            // is a flag but not the route start flag, as it would revert the route.
331
            const bool targetFlag = GetWorld().GetNO(curPt)->GetType() == NodalObjectType::Flag && curPt != rb.start;
×
332
            int altitude = GetWorld().GetNode(rb.point).altitude;
×
333
            if(targetFlag || gwv.IsRoadAvailable(rb.mode == RoadBuildMode::Boat, curPt))
×
334
            {
335
                unsigned id;
336
                switch(int(GetWorld().GetNode(curPt).altitude) - altitude)
×
337
                {
338
                    case 1: id = 61; break;
×
339
                    case 2:
×
340
                    case 3: id = 62; break;
×
341
                    case 4:
×
342
                    case 5: id = 63; break;
×
343
                    case -1: id = 64; break;
×
344
                    case -2:
×
345
                    case -3: id = 65; break;
×
346
                    case -4:
×
347
                    case -5: id = 66; break;
×
348
                    default: id = 60; break;
×
349
                }
350
                if(!targetFlag)
×
351
                    LOADER.GetMapTexture(id)->DrawFull(curPos);
×
352
                else
353
                {
354
                    DrawPoint lastPos = GetWorld().GetNodePos(rb.point) - offset + curOffset;
×
355
                    DrawPoint halfWayPos = (curPos + lastPos) / 2;
×
356
                    LOADER.GetMapTexture(id)->DrawFull(halfWayPos);
×
357
                    LOADER.GetMapTexture(20)->DrawFull(curPos);
×
358
                }
359
            }
360
        }
361
    }
362
}
×
363

364
void GameWorldView::DrawNameProductivityOverlay(const TerrainRenderer& terrainRenderer)
×
365
{
366
    const bool showEnemyProductivity =
367
      GetWorld().GetGameInterface()->GI_GetCheats().shouldShowEnemyProductivityOverlay();
×
368
    auto* attackAidImage =
369
      (GetWorld().GetGGS().getSelection(AddonId::MILITARY_AID) == 2) ? LOADER.GetImageN("map_new", 20000) : nullptr;
×
370
    const bool isAllVisible = gwv.IsAllVisible();
×
371
    for(int x = firstPt.x; x <= lastPt.x; ++x)
×
372
    {
373
        for(int y = firstPt.y; y <= lastPt.y; ++y)
×
374
        {
375
            // Coordinate transform
376
            Position curOffset;
×
377
            MapPoint pt = terrainRenderer.ConvertCoords(Position(x, y), &curOffset);
×
378

379
            const auto* no = GetWorld().GetSpecObj<noBaseBuilding>(pt);
×
380
            if(!no)
×
381
                continue;
×
382

383
            Position curPos = GetWorld().GetNodePos(pt) - offset + curOffset;
×
384
            curPos.y -= 22;
×
385

386
            // Is object not belonging to local player?
387
            if(no->GetPlayer() != gwv.GetPlayerId())
×
388
            {
389
                if(!isAllVisible && gwv.GetVisibility(pt, false) != Visibility::Visible)
×
390
                    continue;
×
391
                if(attackAidImage && gwv.GetNumSoldiersForAttack(pt) > 0)
×
392
                    attackAidImage->DrawFull(curPos - DrawPoint(0, attackAidImage->getHeight()));
×
393
                // Do not draw enemy productivity overlay unless the related cheat is on
394
                if(!showEnemyProductivity)
×
395
                    continue;
×
396
            }
397

398
            // Draw object name
399
            if(show_names)
×
400
            {
401
                unsigned color = (no->GetGOT() == GO_Type::Buildingsite) ? COLOR_GREY : COLOR_YELLOW;
×
402
                SmallFont->Draw(curPos, _(BUILDING_NAMES[no->GetBuildingType()]),
×
403
                                FontStyle::CENTER | FontStyle::VCENTER, color);
404
                curPos.y += SmallFont->getHeight();
×
405
            }
406

407
            // Draw productivity/soldiers
408
            if(show_productivity)
×
409
                DrawProductivity(*no, curPos);
×
410
        }
411
    }
412
}
×
413

414
void GameWorldView::DrawProductivity(const noBaseBuilding& no, const DrawPoint& curPos)
×
415
{
416
    const GO_Type got = no.GetGOT();
×
417
    if(got == GO_Type::Buildingsite)
×
418
    {
419
        unsigned color = COLOR_GREY;
×
420

421
        unsigned short p = static_cast<const noBuildingSite&>(no).GetBuildProgress();
×
422
        SmallFont->Draw(curPos, (boost::format("(%1% %%)") % p).str(), FontStyle::CENTER | FontStyle::VCENTER, color);
×
423
    } else if(got == GO_Type::NobUsual || got == GO_Type::NobShipyard || got == GO_Type::NobTemple)
×
424
    {
425
        const auto& n = static_cast<const nobUsual&>(no);
×
426
        std::string text;
×
427
        unsigned color = COLOR_0_PERCENT;
×
428

429
        if(!n.HasWorker())
×
430
            text = _("(House unoccupied)");
×
431
        else if(n.IsProductionDisabledVirtual())
×
432
            text = _("(stopped)");
×
433
        else
434
        {
435
            // Catapult and Lookout tower doesn't have productivity!
436
            if(n.GetBuildingType() == BuildingType::Catapult || n.GetBuildingType() == BuildingType::LookoutTower)
×
437
                return;
×
438

439
            unsigned short p = n.GetProductivity();
×
440
            text = helpers::toString(p) + " %";
×
441
            if(p >= 60)
×
442
                color = COLOR_60_PERCENT;
×
443
            else if(p >= 30)
×
444
                color = COLOR_30_PERCENT;
×
445
            else if(p >= 20)
×
446
                color = COLOR_20_PERCENT;
×
447
        }
448
        SmallFont->Draw(curPos, text, FontStyle::CENTER | FontStyle::VCENTER, color);
×
449
    } else if(got == GO_Type::NobMilitary)
×
450
    {
451
        // Display amount of soldiers
452
        unsigned soldiers_count = static_cast<const nobMilitary&>(no).GetNumTroops();
×
453
        std::string sSoldiers;
×
454
        if(soldiers_count == 1)
×
455
            sSoldiers = _("(1 soldier)");
×
456
        else
457
            sSoldiers = boost::str(boost::format(_("(%d soldiers)")) % soldiers_count);
×
458

459
        SmallFont->Draw(curPos, sSoldiers, FontStyle::CENTER | FontStyle::VCENTER,
×
460
                        (soldiers_count > 0) ? COLOR_YELLOW : COLOR_RED);
×
461
    }
462
}
463

464
void GameWorldView::DrawFigures(const MapPoint& pt, const DrawPoint& curPos,
×
465
                                std::vector<ObjectBetweenLines>& between_lines) const
466
{
467
    for(noBase& figure : GetWorld().GetFigures(pt))
×
468
    {
469
        if(figure.IsMoving())
×
470
        {
471
            // Drawn from above
472
            Direction curMoveDir = static_cast<noMovable&>(figure).GetCurMoveDir();
×
473
            if(curMoveDir == Direction::NorthEast || curMoveDir == Direction::NorthWest)
×
474
                continue;
×
475
            // Draw later
476
            between_lines.push_back(ObjectBetweenLines(figure, curPos));
×
477
        } else if(figure.GetGOT() == GO_Type::Ship)
×
478
            between_lines.push_back(ObjectBetweenLines(figure, curPos)); // TODO: Why special handling for ships?
×
479
        else
480
            // Ansonsten jetzt schon zeichnen
481
            figure.Draw(curPos);
×
482
    }
483
}
×
484

485
void GameWorldView::DrawMovingFiguresFromBelow(const TerrainRenderer& terrainRenderer, const DrawPoint& curPos,
×
486
                                               std::vector<ObjectBetweenLines>& between_lines)
487
{
488
    // First draw figures moving towards this point from below
489
    static const std::array<Direction, 2> aboveDirs = {{Direction::NorthEast, Direction::NorthWest}};
490
    for(Direction dir : aboveDirs)
×
491
    {
492
        // Get figures opposite the current dir and check if they are moving in this dir
493
        // Coordinates transform
494
        Position curOffset;
×
495
        MapPoint curPt = terrainRenderer.ConvertCoords(GetNeighbour(curPos, dir + 3u), &curOffset);
×
496
        Position figPos = GetWorld().GetNodePos(curPt) - offset + curOffset;
×
497

498
        for(noBase& figure : GetWorld().GetFigures(curPt))
×
499
        {
500
            if(figure.IsMoving() && static_cast<noMovable&>(figure).GetCurMoveDir() == dir)
×
501
                between_lines.push_back(ObjectBetweenLines(figure, figPos));
×
502
        }
503
    }
504
}
×
505

506
constexpr auto getBqImgs()
507
{
508
    helpers::EnumArray<unsigned, BuildingQuality> imgs{};
509
    imgs[BuildingQuality::Flag] = 50;
510
    imgs[BuildingQuality::Hut] = 51;
511
    imgs[BuildingQuality::House] = 52;
512
    imgs[BuildingQuality::Castle] = 53;
513
    imgs[BuildingQuality::Mine] = 54;
514
    imgs[BuildingQuality::Harbor] = 55;
515
    return imgs;
516
}
517

518
void GameWorldView::DrawConstructionAid(const MapPoint& pt, const DrawPoint& curPos)
×
519
{
520
    BuildingQuality bq = gwv.GetBQ(pt);
×
521
    if(bq != BuildingQuality::Nothing)
×
522
    {
523
        constexpr auto bqImgs = getBqImgs();
×
524
        auto* bm = LOADER.GetMapTexture(bqImgs[bq]);
×
525
        // Draw building quality icon
526
        bm->DrawFull(curPos);
×
527
        // Show ability to construct military buildings
528
        if(GetWorld().GetGGS().isEnabled(AddonId::MILITARY_AID))
×
529
        {
530
            if(!GetWorld().IsMilitaryBuildingNearNode(pt, gwv.GetPlayerId())
×
531
               && (bq == BuildingQuality::Hut || bq == BuildingQuality::House || bq == BuildingQuality::Castle
×
532
                   || bq == BuildingQuality::Harbor))
×
533
                LOADER.GetImageN("map_new", 20000)->DrawFull(curPos - DrawPoint(-1, bm->GetSize().y + 5));
×
534
        }
535
    }
536
}
×
537

538
void GameWorldView::DrawObject(const MapPoint& pt, const DrawPoint& curPos) const
×
539
{
540
    noBase* obj = GetWorld().GetNode(pt).obj;
×
541
    if(!obj)
×
542
        return;
×
543

544
    obj->Draw(curPos);
×
545
}
546

547
void GameWorldView::DrawBoundaryStone(const MapPoint& pt, const DrawPoint pos, Visibility vis)
×
548
{
549
    if(vis == Visibility::Invisible)
×
550
        return;
×
551

552
    const bool isFoW = vis == Visibility::FogOfWar;
×
553

554
    const BoundaryStones& boundary_stones =
555
      isFoW ? gwv.GetYoungestFOWNode(pt).boundary_stones : GetWorld().GetNode(pt).boundary_stones;
×
556
    const unsigned char owner = boundary_stones[BorderStonePos::OnPoint];
×
557

558
    if(!owner)
×
559
        return;
×
560

561
    const Nation nation = GetWorld().GetPlayer(owner - 1).nation;
×
562
    unsigned player_color = GetWorld().GetPlayer(owner - 1).color;
×
563
    if(isFoW)
×
564
        player_color = CalcPlayerFOWDrawColor(player_color);
×
565

566
    const auto curVertexPos = gwv.GetTerrainRenderer().GetVertexPos(pt);
×
567
    for(const auto bPos : helpers::EnumRange<BorderStonePos>{})
×
568
    {
569
        DrawPoint curPos;
×
570
        if(bPos == BorderStonePos::OnPoint)
×
571
            curPos = pos;
×
572
        else if(boundary_stones[bPos])
×
573
            curPos = pos
574
                     - DrawPoint((curVertexPos - gwv.GetTerrainRenderer().GetNeighbourVertexPos(pt, toDirection(bPos)))
×
575
                                 / 2.0f);
×
576
        else
577
            continue;
×
578
        LOADER.boundary_stone_cache[nation].draw(curPos, isFoW ? FOW_DRAW_COLOR : COLOR_WHITE, player_color);
×
579
    }
580
}
581

NEW
582
void GameWorldView::DrawResource(const MapPoint& pt, DrawPoint curPos, Cheats::ResourceRevealMode resRevealMode)
×
583
{
584
    using RRM = Cheats::ResourceRevealMode;
585

NEW
586
    if(resRevealMode == RRM::Nothing)
×
NEW
587
        return;
×
588

NEW
589
    const Resource res = gwv.GetNode(pt).resources;
×
NEW
590
    const auto amount = res.getAmount();
×
591

NEW
592
    if(!amount)
×
NEW
593
        return;
×
594

NEW
595
    GoodType gt = GoodType::Nothing;
×
596

NEW
597
    switch(res.getType())
×
598
    {
NEW
599
        case ResourceType::Iron: gt = GoodType::IronOre; break;
×
NEW
600
        case ResourceType::Gold: gt = GoodType::Gold; break;
×
NEW
601
        case ResourceType::Coal: gt = GoodType::Coal; break;
×
NEW
602
        case ResourceType::Granite: gt = GoodType::Stones; break;
×
NEW
603
        case ResourceType::Water:
×
NEW
604
            if(resRevealMode >= RRM::Water)
×
605
            {
NEW
606
                gt = GoodType::Water;
×
NEW
607
                break;
×
608
            } else
NEW
609
                return;
×
NEW
610
        case ResourceType::Fish:
×
NEW
611
            if(resRevealMode >= RRM::Fish)
×
612
            {
NEW
613
                gt = GoodType::Fish;
×
NEW
614
                break;
×
615
            } else
NEW
616
                return;
×
NEW
617
        default: return;
×
618
    }
619

NEW
620
    if(auto* bm = LOADER.GetWareTex(gt))
×
621
    {
NEW
622
        for(auto i = 0u; i < amount; ++i)
×
623
        {
NEW
624
            bm->DrawFull(curPos);
×
NEW
625
            curPos.y -= 4;
×
626
        }
627
    }
628
}
629

UNCOV
630
void GameWorldView::ToggleShowBQ()
×
631
{
632
    show_bq = !show_bq;
×
633
    SaveIngameSettingsValues();
×
634
    onHudSettingsChanged();
×
635
}
×
636

637
void GameWorldView::ToggleShowNames()
×
638
{
639
    show_names = !show_names;
×
640
    SaveIngameSettingsValues();
×
641
    onHudSettingsChanged();
×
642
}
×
643

644
void GameWorldView::ToggleShowProductivity()
×
645
{
646
    show_productivity = !show_productivity;
×
647
    SaveIngameSettingsValues();
×
648
    onHudSettingsChanged();
×
649
}
×
650

651
void GameWorldView::ToggleShowNamesAndProductivity()
×
652
{
653
    if(show_productivity && show_names)
×
654
        show_productivity = show_names = false;
×
655
    else
656
        show_productivity = show_names = true;
×
657
    SaveIngameSettingsValues();
×
658
    onHudSettingsChanged();
×
659
}
×
660

661
void GameWorldView::CopyHudSettingsTo(GameWorldView& other, bool copyBQ) const
×
662
{
663
    other.show_bq = (copyBQ ? show_bq : false);
×
664
    other.show_names = show_names;
×
665
    other.show_productivity = show_productivity;
×
666
}
×
667

668
void GameWorldView::MoveBy(const DrawPoint& numPixels)
24✔
669
{
670
    MoveTo(offset + numPixels);
24✔
671
}
24✔
672

673
void GameWorldView::MoveTo(const DrawPoint& newPos)
34✔
674
{
675
    offset = newPos;
34✔
676
    DrawPoint size(GetWorld().GetWidth() * TR_W, GetWorld().GetHeight() * TR_H);
34✔
677
    if(size.x && size.y)
34✔
678
    {
679
        offset.x %= size.x;
34✔
680
        offset.y %= size.y;
34✔
681

682
        if(offset.x < 0)
34✔
683
            offset.x += size.x;
5✔
684
        if(offset.y < 0)
34✔
685
            offset.y += size.y;
6✔
686
    }
687

688
    CalcFxLx();
34✔
689
}
34✔
690

691
void GameWorldView::MoveToMapPt(const MapPoint pt)
6✔
692
{
693
    if(!pt.isValid())
6✔
694
        return;
×
695

696
    lastOffset = offset;
6✔
697
    Position nodePos = GetWorld().GetNodePos(pt);
6✔
698

699
    MoveTo(nodePos - GetSize() / 2u);
6✔
700
}
701

702
void GameWorldView::MoveToLastPosition()
×
703
{
704
    Position newLastOffset = offset;
×
705

706
    MoveTo(lastOffset);
×
707

708
    lastOffset = newLastOffset;
×
709
}
×
710

711
void GameWorldView::AddDrawNodeCallback(IDrawNodeCallback* newCallback)
×
712
{
713
    RTTR_Assert(newCallback);
×
714
    drawNodeCallbacks.push_back(newCallback);
×
715
}
×
716

717
void GameWorldView::RemoveDrawNodeCallback(IDrawNodeCallback* callbackToRemove)
×
718
{
719
    auto itPos = helpers::find(drawNodeCallbacks, callbackToRemove);
×
720
    RTTR_Assert(itPos != drawNodeCallbacks.end());
×
721
    drawNodeCallbacks.erase(itPos);
×
722
}
×
723

724
void GameWorldView::CalcFxLx()
34✔
725
{
726
    // Calc first and last point in map units (with 1 extra for incomplete triangles)
727
    firstPt.x = offset.x / TR_W - 1;
34✔
728
    firstPt.y = offset.y / TR_H - 1;
34✔
729
    lastPt.x = (offset.x + size_.x) / TR_W + 1;
34✔
730
    const auto maxAltitude = gwv.getMaxNodeAltitude();
34✔
731
    lastPt.y = (offset.y + size_.y + maxAltitude * HEIGHT_FACTOR) / TR_H + 1;
34✔
732

733
    if(effectiveZoomFactor_ != 1.f) //-V550
34✔
734
    {
735
        // Calc pixels we can remove from sides, as they are not drawn due to zoom
736
        PointF diff(size_.x - size_.x / effectiveZoomFactor_, size_.y - size_.y / effectiveZoomFactor_);
×
737
        // Stay centered by removing half the pixels from opposite sites
738
        diff = diff / 2.f;
×
739
        // Convert to map points
740
        diff.x /= TR_W;
×
741
        diff.y /= TR_H;
×
742
        // Don't remove to much
743
        diff.x = std::floor(diff.x);
×
744
        diff.y = std::floor(diff.y);
×
745
        firstPt = Position(PointF(firstPt) + diff);
×
746
        lastPt = Position(PointF(lastPt) - diff);
×
747
    }
748
}
34✔
749

750
void GameWorldView::Resize(const Extent& newSize)
×
751
{
752
    size_ = newSize;
×
753
    CalcFxLx();
×
754
}
×
755

756
void GameWorldView::SaveIngameSettingsValues() const
×
757
{
758
    auto& ingameSettings = SETTINGS.ingame;
×
759
    ingameSettings.showBQ = show_bq;
×
760
    ingameSettings.showNames = show_names;
×
761
    ingameSettings.showProductivity = show_productivity;
×
762
}
×
763

764
void GameWorldView::updateEffectiveZoomFactor()
10✔
765
{
766
    // partially "undo" GUI scale depending on DPI scale
767
    // => zoom levels should look the same on screens with different DPI regardless of GUI scale
768
    effectiveZoomFactor_ = VIDEODRIVER.getGuiScale().screenToView(zoomFactor_ * VIDEODRIVER.getDpiScale());
10✔
769
}
10✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc