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

Return-To-The-Roots / s25client / 12897291934

21 Jan 2025 10:43PM UTC coverage: 50.336% (+0.005%) from 50.331%
12897291934

Pull #1738

github

web-flow
Merge 35a55bb58 into 828eaad9a
Pull Request #1738: "Show enemy productivity overlay" cheat

7 of 12 new or added lines in 4 files covered. (58.33%)

101 existing lines in 3 files now uncovered.

22378 of 44457 relevant lines covered (50.34%)

37251.18 hits per line

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

10.5
/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)
12✔
40
    : selPt(0, 0), show_bq(SETTINGS.ingame.showBQ), show_names(SETTINGS.ingame.showNames),
12✔
41
      show_productivity(SETTINGS.ingame.showProductivity), offset(0, 0), lastOffset(0, 0), gwv(gwv), origin_(pos),
24✔
42
      size_(size), zoomFactor_(1.f), targetZoomFactor_(1.f), zoomSpeed_(0.f)
24✔
43
{
44
    updateEffectiveZoomFactor();
12✔
45
    MoveBy({0, 0});
12✔
46
}
12✔
47

48
const GameWorldBase& GameWorldView::GetWorld() const
93✔
49
{
50
    return gwv.GetWorld();
93✔
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
void GameWorldView::SetZoomFactor(float zoomFactor, bool smoothTransition /* = true*/)
×
94
{
95
    if(zoomFactor < ZOOM_FACTORS.front())
×
96
        targetZoomFactor_ = ZOOM_FACTORS.front();
×
97
    else if(zoomFactor > ZOOM_FACTORS.back())
×
98
        targetZoomFactor_ = ZOOM_FACTORS.back();
×
99
    else
100
        targetZoomFactor_ = zoomFactor;
×
101
    if(!smoothTransition)
×
102
    {
103
        zoomFactor_ = targetZoomFactor_;
×
104
        updateEffectiveZoomFactor();
×
105
        CalcFxLx();
×
106
    }
107
}
×
108

109
float GameWorldView::GetCurrentTargetZoomFactor() const
×
110
{
111
    return targetZoomFactor_;
×
112
}
113

114
struct ObjectBetweenLines
115
{
116
    noBase& obj;
117
    DrawPoint pos; // Zeichenposition
118

119
    ObjectBetweenLines(noBase& obj, const DrawPoint& pos) : obj(obj), pos(pos) {}
×
120
};
121

122
void GameWorldView::Draw(const RoadBuildState& rb, const MapPoint selected, bool drawMouse, unsigned* water)
×
123
{
124
    SetNextZoomFactor();
×
125

126
    const auto windowSize = VIDEODRIVER.GetWindowSize();
×
127
    const auto& guiScale = VIDEODRIVER.getGuiScale();
×
128
    const auto screenOrigin = guiScale.viewToScreen(origin_);
×
129
    const auto screenSize = guiScale.viewToScreen(size_);
×
130
    glScissor(screenOrigin.x, windowSize.height - (screenOrigin.y + screenSize.y), screenSize.x, screenSize.y);
×
131

132
    int shortestDistToMouse = 100000;
×
133
    Position mousePos = VIDEODRIVER.GetMousePos();
×
134
    mousePos -= Position(origin_);
×
135
    if(effectiveZoomFactor_ != 1.f) //-V550
×
136
    {
137
        glMatrixMode(GL_PROJECTION);
×
138
        glPushMatrix();
×
139
        glScalef(effectiveZoomFactor_, effectiveZoomFactor_, 1);
×
140
        // Offset to center view
141
        PointF diff(size_.x - size_.x / effectiveZoomFactor_, size_.y - size_.y / effectiveZoomFactor_);
×
142
        diff = diff / 2.f;
×
143
        glTranslatef(-diff.x, -diff.y, 0.f);
×
144
        // Also adjust mouse
145
        mousePos = Position(PointF(mousePos) / effectiveZoomFactor_ + diff);
×
146
        glMatrixMode(GL_MODELVIEW);
×
147
    }
148

149
    glTranslatef(static_cast<GLfloat>(origin_.x) / effectiveZoomFactor_,
×
150
                 static_cast<GLfloat>(origin_.y) / effectiveZoomFactor_, 0.0f);
×
151

152
    glTranslatef(static_cast<GLfloat>(-offset.x), static_cast<GLfloat>(-offset.y), 0.0f);
×
153
    const TerrainRenderer& terrainRenderer = gwv.GetTerrainRenderer();
×
154
    terrainRenderer.Draw(GetFirstPt(), GetLastPt(), gwv, water);
×
155
    glTranslatef(static_cast<GLfloat>(offset.x), static_cast<GLfloat>(offset.y), 0.0f);
×
156

157
    for(int y = firstPt.y; y <= lastPt.y; ++y)
×
158
    {
159
        // Figuren speichern, die in dieser Zeile gemalt werden müssen
160
        // und sich zwischen zwei Zeilen befinden, da sie dazwischen laufen
161
        std::vector<ObjectBetweenLines> between_lines;
×
162

163
        for(int x = firstPt.x; x <= lastPt.x; ++x)
×
164
        {
165
            Position curOffset;
×
166
            const MapPoint curPt = terrainRenderer.ConvertCoords(Position(x, y), &curOffset);
×
167
            DrawPoint curPos = GetWorld().GetNodePos(curPt) - offset + curOffset;
×
168

169
            Position mouseDist = mousePos - curPos;
×
170
            mouseDist *= mouseDist;
×
171
            if(std::abs(mouseDist.x) + std::abs(mouseDist.y) < shortestDistToMouse)
×
172
            {
173
                selPt = curPt;
×
174
                selPtOffset = curOffset;
×
175
                shortestDistToMouse = std::abs(mouseDist.x) + std::abs(mouseDist.y);
×
176
            }
177

178
            Visibility visibility = gwv.GetVisibility(curPt);
×
179

180
            DrawBoundaryStone(curPt, curPos, visibility);
×
181

182
            if(visibility == Visibility::Visible)
×
183
            {
184
                DrawObject(curPt, curPos);
×
185
                DrawMovingFiguresFromBelow(terrainRenderer, Position(x, y), between_lines);
×
186
                DrawFigures(curPt, curPos, between_lines);
×
187

188
                // Construction aid mode
189
                if(show_bq)
×
190
                    DrawConstructionAid(curPt, curPos);
×
191
            } else if(visibility == Visibility::FogOfWar)
×
192
            {
193
                const FOWObject* fowobj = gwv.GetYoungestFOWObject(MapPoint(curPt));
×
194
                if(fowobj)
×
195
                    fowobj->Draw(curPos);
×
196
            }
197

198
            for(IDrawNodeCallback* callback : drawNodeCallbacks)
×
199
                callback->onDraw(curPt, curPos);
×
200
        }
201

202
        // Figuren zwischen den Zeilen zeichnen
203
        for(auto& between_line : between_lines)
×
204
            between_line.obj.Draw(between_line.pos);
×
205
    }
206

207
    if(show_names || show_productivity)
×
208
        DrawNameProductivityOverlay(terrainRenderer);
×
209

210
    DrawGUI(rb, terrainRenderer, selected, drawMouse);
×
211

212
    // Umherfliegende Katapultsteine zeichnen
213
    for(auto* catapult_stone : GetWorld().catapult_stones)
×
214
    {
215
        if(gwv.GetVisibility(catapult_stone->dest_building) == Visibility::Visible
×
216
           || gwv.GetVisibility(catapult_stone->dest_map) == Visibility::Visible)
×
217
            catapult_stone->Draw(offset);
×
218
    }
219

220
    if(effectiveZoomFactor_ != 1.f) //-V550
×
221
    {
222
        glMatrixMode(GL_PROJECTION);
×
223
        glPopMatrix();
×
224
        glMatrixMode(GL_MODELVIEW);
×
225
    }
226
    glTranslatef(-static_cast<GLfloat>(origin_.x) / effectiveZoomFactor_,
×
227
                 -static_cast<GLfloat>(origin_.y) / effectiveZoomFactor_, 0.0f);
×
228

229
    glScissor(0, 0, windowSize.width, windowSize.height);
×
230
}
×
231

232
void GameWorldView::DrawGUI(const RoadBuildState& rb, const TerrainRenderer& terrainRenderer,
×
233
                            const MapPoint& selectedPt, bool drawMouse)
234
{
235
    // Falls im Straßenbaumodus: Punkte um den aktuellen Straßenbaupunkt herum ermitteln
236
    helpers::EnumArray<MapPoint, Direction> road_points;
×
237

238
    unsigned maxWaterWayLen = 0;
×
239
    if(rb.mode != RoadBuildMode::Disabled)
×
240
    {
241
        for(const auto dir : helpers::EnumRange<Direction>{})
×
242
            road_points[dir] = GetWorld().GetNeighbour(rb.point, dir);
×
243

244
        const unsigned index = GetWorld().GetGGS().getSelection(AddonId::MAX_WATERWAY_LENGTH);
×
245
        RTTR_Assert(index < waterwayLengths.size());
×
246
        maxWaterWayLen = waterwayLengths[index];
×
247
    }
248

249
    for(int x = firstPt.x; x <= lastPt.x; ++x)
×
250
    {
251
        for(int y = firstPt.y; y <= lastPt.y; ++y)
×
252
        {
253
            // Coordinates transform
254
            Position curOffset;
×
255
            MapPoint curPt = terrainRenderer.ConvertCoords(Position(x, y), &curOffset);
×
256
            Position curPos = GetWorld().GetNodePos(curPt) - offset + curOffset;
×
257

258
            /// Current point indicated by Mouse
259
            if(drawMouse && selPt == curPt)
×
260
            {
261
                // Mauszeiger am boden
262
                unsigned mid = 22;
×
263
                if(rb.mode == RoadBuildMode::Disabled)
×
264
                {
265
                    switch(gwv.GetBQ(curPt))
×
266
                    {
267
                        case BuildingQuality::Flag: mid = 40; break;
×
268
                        case BuildingQuality::Mine: mid = 41; break;
×
269
                        case BuildingQuality::Hut: mid = 42; break;
×
270
                        case BuildingQuality::House: mid = 43; break;
×
271
                        case BuildingQuality::Castle: mid = 44; break;
×
272
                        case BuildingQuality::Harbor: mid = 45; break;
×
273
                        default: break;
×
274
                    }
275
                }
276
                LOADER.GetMapTexture(mid)->DrawFull(curPos);
×
277
            }
278

279
            // Currently selected point
280
            if(selectedPt == curPt)
×
281
                LOADER.GetMapTexture(20)->DrawFull(curPos);
×
282

283
            // not building roads, no further action needed
284
            if(rb.mode == RoadBuildMode::Disabled)
×
285
                continue;
×
286

287
            // we dont own curPt, no need for any rendering...
288
            if(!gwv.IsPlayerTerritory(curPt))
×
289
                continue;
×
290

291
            // we are in road build mode
292
            // highlight current route pt
293
            if(rb.point == curPt)
×
294
            {
295
                LOADER.GetMapTexture(21)->DrawFull(curPos);
×
296
                continue;
×
297
            }
298

299
            // ensure that curPt is a neighbour of rb.point
300
            if(!helpers::contains(road_points, curPt))
×
301
            {
302
                continue;
×
303
            }
304

305
            // test on maximal water way length
306
            if(rb.mode == RoadBuildMode::Boat && maxWaterWayLen != 0 && rb.route.size() >= maxWaterWayLen)
×
307
                continue;
×
308

309
            // render special icon for route revert
310
            if(!rb.route.empty() && road_points[rb.route.back() + 3u] == curPt)
×
311
            {
312
                LOADER.GetMapTexture(67)->DrawFull(curPos);
×
313
                continue;
×
314
            }
315

316
            // is a flag but not the route start flag, as it would revert the route.
317
            const bool targetFlag = GetWorld().GetNO(curPt)->GetType() == NodalObjectType::Flag && curPt != rb.start;
×
318
            int altitude = GetWorld().GetNode(rb.point).altitude;
×
319
            if(targetFlag || gwv.IsRoadAvailable(rb.mode == RoadBuildMode::Boat, curPt))
×
320
            {
321
                unsigned id;
322
                switch(int(GetWorld().GetNode(curPt).altitude) - altitude)
×
323
                {
324
                    case 1: id = 61; break;
×
325
                    case 2:
×
326
                    case 3: id = 62; break;
×
327
                    case 4:
×
328
                    case 5: id = 63; break;
×
329
                    case -1: id = 64; break;
×
330
                    case -2:
×
331
                    case -3: id = 65; break;
×
332
                    case -4:
×
333
                    case -5: id = 66; break;
×
334
                    default: id = 60; break;
×
335
                }
336
                if(!targetFlag)
×
337
                    LOADER.GetMapTexture(id)->DrawFull(curPos);
×
338
                else
339
                {
340
                    DrawPoint lastPos = GetWorld().GetNodePos(rb.point) - offset + curOffset;
×
341
                    DrawPoint halfWayPos = (curPos + lastPos) / 2;
×
342
                    LOADER.GetMapTexture(id)->DrawFull(halfWayPos);
×
343
                    LOADER.GetMapTexture(20)->DrawFull(curPos);
×
344
                }
345
            }
346
        }
347
    }
348
}
×
349

350
void GameWorldView::DrawNameProductivityOverlay(const TerrainRenderer& terrainRenderer)
×
351
{
352
    for(int x = firstPt.x; x <= lastPt.x; ++x)
×
353
    {
354
        for(int y = firstPt.y; y <= lastPt.y; ++y)
×
355
        {
356
            // Coordinate transform
357
            Position curOffset;
×
358
            MapPoint pt = terrainRenderer.ConvertCoords(Position(x, y), &curOffset);
×
359

360
            const auto* no = GetWorld().GetSpecObj<noBaseBuilding>(pt);
×
361
            if(!no)
×
362
                continue;
×
363

364
            Position curPos = GetWorld().GetNodePos(pt) - offset + curOffset;
×
365
            curPos.y -= 22;
×
366

367
            // Is object not belonging to local player?
UNCOV
368
            if(no->GetPlayer() != gwv.GetPlayerId())
×
369
            {
370
                if(GetWorld().GetGGS().getSelection(AddonId::MILITARY_AID) == 2 && gwv.GetNumSoldiersForAttack(pt) > 0)
×
371
                {
UNCOV
372
                    auto* attackAidImage = LOADER.GetImageN("map_new", 20000);
×
373
                    attackAidImage->DrawFull(curPos - DrawPoint(0, attackAidImage->getHeight()));
×
374
                }
375
                // Do not draw enemy productivity overlay unless the object is visible AND the related cheat is on
NEW
UNCOV
376
                if(!(gwv.GetVisibility(pt) == Visibility::Visible
×
NEW
377
                     && GetWorld().GetGameInterface()->GI_GetCheats().shouldShowEnemyProductivityOverlay()))
×
NEW
378
                    continue;
×
379
            }
380

381
            // Draw object name
UNCOV
382
            if(show_names)
×
383
            {
384
                unsigned color = (no->GetGOT() == GO_Type::Buildingsite) ? COLOR_GREY : COLOR_YELLOW;
×
385
                SmallFont->Draw(curPos, _(BUILDING_NAMES[no->GetBuildingType()]),
×
386
                                FontStyle::CENTER | FontStyle::VCENTER, color);
UNCOV
387
                curPos.y += SmallFont->getHeight();
×
388
            }
389

390
            // Draw productivity/soldiers
UNCOV
391
            if(show_productivity)
×
UNCOV
392
                DrawProductivity(*no, curPos);
×
393
        }
394
    }
395
}
×
396

UNCOV
397
void GameWorldView::DrawProductivity(const noBaseBuilding& no, const DrawPoint& curPos)
×
398
{
UNCOV
399
    const GO_Type got = no.GetGOT();
×
400
    if(got == GO_Type::Buildingsite)
×
401
    {
402
        unsigned color = COLOR_GREY;
×
403

UNCOV
404
        unsigned short p = static_cast<const noBuildingSite&>(no).GetBuildProgress();
×
405
        SmallFont->Draw(curPos, (boost::format("(%1% %%)") % p).str(), FontStyle::CENTER | FontStyle::VCENTER, color);
×
UNCOV
406
    } else if(got == GO_Type::NobUsual || got == GO_Type::NobShipyard || got == GO_Type::NobTemple)
×
407
    {
408
        const auto& n = static_cast<const nobUsual&>(no);
×
409
        std::string text;
×
UNCOV
410
        unsigned color = COLOR_0_PERCENT;
×
411

412
        if(!n.HasWorker())
×
413
            text = _("(House unoccupied)");
×
UNCOV
414
        else if(n.IsProductionDisabledVirtual())
×
415
            text = _("(stopped)");
×
416
        else
417
        {
418
            // Catapult and Lookout tower doesn't have productivity!
UNCOV
419
            if(n.GetBuildingType() == BuildingType::Catapult || n.GetBuildingType() == BuildingType::LookoutTower)
×
UNCOV
420
                return;
×
421

422
            unsigned short p = n.GetProductivity();
×
423
            text = helpers::toString(p) + " %";
×
UNCOV
424
            if(p >= 60)
×
425
                color = COLOR_60_PERCENT;
×
426
            else if(p >= 30)
×
427
                color = COLOR_30_PERCENT;
×
428
            else if(p >= 20)
×
429
                color = COLOR_20_PERCENT;
×
430
        }
431
        SmallFont->Draw(curPos, text, FontStyle::CENTER | FontStyle::VCENTER, color);
×
432
    } else if(got == GO_Type::NobMilitary)
×
433
    {
434
        // Display amount of soldiers
435
        unsigned soldiers_count = static_cast<const nobMilitary&>(no).GetNumTroops();
×
UNCOV
436
        std::string sSoldiers;
×
UNCOV
437
        if(soldiers_count == 1)
×
438
            sSoldiers = _("(1 soldier)");
×
439
        else
440
            sSoldiers = boost::str(boost::format(_("(%d soldiers)")) % soldiers_count);
×
441

UNCOV
442
        SmallFont->Draw(curPos, sSoldiers, FontStyle::CENTER | FontStyle::VCENTER,
×
443
                        (soldiers_count > 0) ? COLOR_YELLOW : COLOR_RED);
×
444
    }
445
}
446

UNCOV
447
void GameWorldView::DrawFigures(const MapPoint& pt, const DrawPoint& curPos,
×
448
                                std::vector<ObjectBetweenLines>& between_lines) const
449
{
450
    for(noBase& figure : GetWorld().GetFigures(pt))
×
451
    {
UNCOV
452
        if(figure.IsMoving())
×
453
        {
454
            // Drawn from above
455
            Direction curMoveDir = static_cast<noMovable&>(figure).GetCurMoveDir();
×
UNCOV
456
            if(curMoveDir == Direction::NorthEast || curMoveDir == Direction::NorthWest)
×
UNCOV
457
                continue;
×
458
            // Draw later
459
            between_lines.push_back(ObjectBetweenLines(figure, curPos));
×
460
        } else if(figure.GetGOT() == GO_Type::Ship)
×
UNCOV
461
            between_lines.push_back(ObjectBetweenLines(figure, curPos)); // TODO: Why special handling for ships?
×
462
        else
463
            // Ansonsten jetzt schon zeichnen
464
            figure.Draw(curPos);
×
465
    }
UNCOV
466
}
×
467

UNCOV
468
void GameWorldView::DrawMovingFiguresFromBelow(const TerrainRenderer& terrainRenderer, const DrawPoint& curPos,
×
469
                                               std::vector<ObjectBetweenLines>& between_lines)
470
{
471
    // First draw figures moving towards this point from below
472
    static const std::array<Direction, 2> aboveDirs = {{Direction::NorthEast, Direction::NorthWest}};
UNCOV
473
    for(Direction dir : aboveDirs)
×
474
    {
475
        // Get figures opposite the current dir and check if they are moving in this dir
476
        // Coordinates transform
UNCOV
477
        Position curOffset;
×
UNCOV
478
        MapPoint curPt = terrainRenderer.ConvertCoords(GetNeighbour(curPos, dir + 3u), &curOffset);
×
UNCOV
479
        Position figPos = GetWorld().GetNodePos(curPt) - offset + curOffset;
×
480

481
        for(noBase& figure : GetWorld().GetFigures(curPt))
×
482
        {
UNCOV
483
            if(figure.IsMoving() && static_cast<noMovable&>(figure).GetCurMoveDir() == dir)
×
484
                between_lines.push_back(ObjectBetweenLines(figure, figPos));
×
485
        }
486
    }
487
}
×
488

489
constexpr auto getBqImgs()
490
{
491
    helpers::EnumArray<unsigned, BuildingQuality> imgs{};
492
    imgs[BuildingQuality::Flag] = 50;
493
    imgs[BuildingQuality::Hut] = 51;
494
    imgs[BuildingQuality::House] = 52;
495
    imgs[BuildingQuality::Castle] = 53;
496
    imgs[BuildingQuality::Mine] = 54;
497
    imgs[BuildingQuality::Harbor] = 55;
498
    return imgs;
499
}
500

UNCOV
501
void GameWorldView::DrawConstructionAid(const MapPoint& pt, const DrawPoint& curPos)
×
502
{
UNCOV
503
    BuildingQuality bq = gwv.GetBQ(pt);
×
504
    if(bq != BuildingQuality::Nothing)
×
505
    {
506
        constexpr auto bqImgs = getBqImgs();
×
507
        auto* bm = LOADER.GetMapTexture(bqImgs[bq]);
×
508
        // Draw building quality icon
509
        bm->DrawFull(curPos);
×
510
        // Show ability to construct military buildings
UNCOV
511
        if(GetWorld().GetGGS().isEnabled(AddonId::MILITARY_AID))
×
512
        {
UNCOV
513
            if(!GetWorld().IsMilitaryBuildingNearNode(pt, gwv.GetPlayerId())
×
514
               && (bq == BuildingQuality::Hut || bq == BuildingQuality::House || bq == BuildingQuality::Castle
×
UNCOV
515
                   || bq == BuildingQuality::Harbor))
×
516
                LOADER.GetImageN("map_new", 20000)->DrawFull(curPos - DrawPoint(-1, bm->GetSize().y + 5));
×
517
        }
518
    }
519
}
×
520

UNCOV
521
void GameWorldView::DrawObject(const MapPoint& pt, const DrawPoint& curPos) const
×
522
{
UNCOV
523
    noBase* obj = GetWorld().GetNode(pt).obj;
×
524
    if(!obj)
×
UNCOV
525
        return;
×
526

527
    obj->Draw(curPos);
×
528
}
529

530
void GameWorldView::DrawBoundaryStone(const MapPoint& pt, const DrawPoint pos, Visibility vis)
×
531
{
UNCOV
532
    if(vis == Visibility::Invisible)
×
533
        return;
×
534

535
    const bool isFoW = vis == Visibility::FogOfWar;
×
536

537
    const BoundaryStones& boundary_stones =
538
      isFoW ? gwv.GetYoungestFOWNode(pt).boundary_stones : GetWorld().GetNode(pt).boundary_stones;
×
UNCOV
539
    const unsigned char owner = boundary_stones[BorderStonePos::OnPoint];
×
540

541
    if(!owner)
×
542
        return;
×
543

544
    const Nation nation = GetWorld().GetPlayer(owner - 1).nation;
×
545
    unsigned player_color = GetWorld().GetPlayer(owner - 1).color;
×
UNCOV
546
    if(isFoW)
×
547
        player_color = CalcPlayerFOWDrawColor(player_color);
×
548

549
    const auto curVertexPos = gwv.GetTerrainRenderer().GetVertexPos(pt);
×
550
    for(const auto bPos : helpers::EnumRange<BorderStonePos>{})
×
551
    {
552
        DrawPoint curPos;
×
553
        if(bPos == BorderStonePos::OnPoint)
×
UNCOV
554
            curPos = pos;
×
555
        else if(boundary_stones[bPos])
×
556
            curPos = pos
557
                     - DrawPoint((curVertexPos - gwv.GetTerrainRenderer().GetNeighbourVertexPos(pt, toDirection(bPos)))
×
558
                                 / 2.0f);
×
559
        else
560
            continue;
×
561
        LOADER.boundary_stone_cache[nation].draw(curPos, isFoW ? FOW_DRAW_COLOR : COLOR_WHITE, player_color);
×
562
    }
563
}
564

UNCOV
565
void GameWorldView::ToggleShowBQ()
×
566
{
UNCOV
567
    show_bq = !show_bq;
×
568
    SaveIngameSettingsValues();
×
UNCOV
569
    onHudSettingsChanged();
×
570
}
×
571

572
void GameWorldView::ToggleShowNames()
×
573
{
UNCOV
574
    show_names = !show_names;
×
575
    SaveIngameSettingsValues();
×
UNCOV
576
    onHudSettingsChanged();
×
577
}
×
578

579
void GameWorldView::ToggleShowProductivity()
×
580
{
UNCOV
581
    show_productivity = !show_productivity;
×
582
    SaveIngameSettingsValues();
×
UNCOV
583
    onHudSettingsChanged();
×
584
}
×
585

586
void GameWorldView::ToggleShowNamesAndProductivity()
×
587
{
UNCOV
588
    if(show_productivity && show_names)
×
589
        show_productivity = show_names = false;
×
590
    else
591
        show_productivity = show_names = true;
×
592
    SaveIngameSettingsValues();
×
UNCOV
593
    onHudSettingsChanged();
×
594
}
×
595

596
void GameWorldView::CopyHudSettingsTo(GameWorldView& other, bool copyBQ) const
×
597
{
UNCOV
598
    other.show_bq = (copyBQ ? show_bq : false);
×
599
    other.show_names = show_names;
×
UNCOV
600
    other.show_productivity = show_productivity;
×
601
}
×
602

603
void GameWorldView::MoveBy(const DrawPoint& numPixels)
25✔
604
{
605
    MoveTo(offset + numPixels);
25✔
606
}
25✔
607

608
void GameWorldView::MoveTo(const DrawPoint& newPos)
38✔
609
{
610
    offset = newPos;
38✔
611
    DrawPoint size(GetWorld().GetWidth() * TR_W, GetWorld().GetHeight() * TR_H);
38✔
612
    if(size.x && size.y)
38✔
613
    {
614
        offset.x %= size.x;
38✔
615
        offset.y %= size.y;
38✔
616

617
        if(offset.x < 0)
38✔
618
            offset.x += size.x;
4✔
619
        if(offset.y < 0)
38✔
620
            offset.y += size.y;
5✔
621
    }
622

623
    CalcFxLx();
38✔
624
}
38✔
625

626
void GameWorldView::MoveToMapPt(const MapPoint pt)
9✔
627
{
628
    if(!pt.isValid())
9✔
UNCOV
629
        return;
×
630

631
    lastOffset = offset;
9✔
632
    Position nodePos = GetWorld().GetNodePos(pt);
9✔
633

634
    MoveTo(nodePos - GetSize() / 2u);
9✔
635
}
636

UNCOV
637
void GameWorldView::MoveToLastPosition()
×
638
{
UNCOV
639
    Position newLastOffset = offset;
×
640

UNCOV
641
    MoveTo(lastOffset);
×
642

UNCOV
643
    lastOffset = newLastOffset;
×
644
}
×
645

646
void GameWorldView::AddDrawNodeCallback(IDrawNodeCallback* newCallback)
×
647
{
UNCOV
648
    RTTR_Assert(newCallback);
×
649
    drawNodeCallbacks.push_back(newCallback);
×
UNCOV
650
}
×
651

652
void GameWorldView::RemoveDrawNodeCallback(IDrawNodeCallback* callbackToRemove)
×
653
{
UNCOV
654
    auto itPos = helpers::find(drawNodeCallbacks, callbackToRemove);
×
655
    RTTR_Assert(itPos != drawNodeCallbacks.end());
×
UNCOV
656
    drawNodeCallbacks.erase(itPos);
×
657
}
×
658

659
void GameWorldView::CalcFxLx()
38✔
660
{
661
    // Calc first and last point in map units (with 1 extra for incomplete triangles)
662
    firstPt.x = offset.x / TR_W - 1;
38✔
663
    firstPt.y = offset.y / TR_H - 1;
38✔
664
    lastPt.x = (offset.x + size_.x) / TR_W + 1;
38✔
665
    const auto maxAltitude = gwv.getMaxNodeAltitude();
38✔
666
    lastPt.y = (offset.y + size_.y + maxAltitude * HEIGHT_FACTOR) / TR_H + 1;
38✔
667

668
    if(effectiveZoomFactor_ != 1.f) //-V550
38✔
669
    {
670
        // Calc pixels we can remove from sides, as they are not drawn due to zoom
UNCOV
671
        PointF diff(size_.x - size_.x / effectiveZoomFactor_, size_.y - size_.y / effectiveZoomFactor_);
×
672
        // Stay centered by removing half the pixels from opposite sites
UNCOV
673
        diff = diff / 2.f;
×
674
        // Convert to map points
UNCOV
675
        diff.x /= TR_W;
×
676
        diff.y /= TR_H;
×
677
        // Don't remove to much
678
        diff.x = std::floor(diff.x);
×
679
        diff.y = std::floor(diff.y);
×
UNCOV
680
        firstPt = Position(PointF(firstPt) + diff);
×
681
        lastPt = Position(PointF(lastPt) - diff);
×
682
    }
683
}
38✔
684

UNCOV
685
void GameWorldView::Resize(const Extent& newSize)
×
686
{
UNCOV
687
    size_ = newSize;
×
688
    CalcFxLx();
×
UNCOV
689
}
×
690

691
void GameWorldView::SaveIngameSettingsValues() const
×
692
{
UNCOV
693
    auto& ingameSettings = SETTINGS.ingame;
×
694
    ingameSettings.showBQ = show_bq;
×
UNCOV
695
    ingameSettings.showNames = show_names;
×
696
    ingameSettings.showProductivity = show_productivity;
×
697
}
×
698

699
void GameWorldView::updateEffectiveZoomFactor()
12✔
700
{
701
    // partially "undo" GUI scale depending on DPI scale
702
    // => zoom levels should look the same on screens with different DPI regardless of GUI scale
703
    effectiveZoomFactor_ = VIDEODRIVER.getGuiScale().screenToView(zoomFactor_ * VIDEODRIVER.getDpiScale());
12✔
704
}
12✔
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