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

Return-To-The-Roots / s25client / 18856213349

27 Oct 2025 09:18PM UTC coverage: 50.471% (-0.02%) from 50.491%
18856213349

Pull #1804

github

web-flow
Merge 1556dcccf into 2d6849772
Pull Request #1804: Android build

75 of 242 new or added lines in 14 files covered. (30.99%)

3 existing lines in 3 files now uncovered.

22552 of 44683 relevant lines covered (50.47%)

35157.57 hits per line

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

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

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

46
const GameWorldBase& GameWorldView::GetWorld() const
75✔
47
{
48
    return gwv.GetWorld();
75✔
49
}
50

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

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

61
    float remainingZoomDiff = targetZoomFactor_ - zoomFactor_;
×
62

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

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

86
    zoomFactor_ = zoomFactor_ + zoomSpeed_;
×
87
    updateEffectiveZoomFactor();
×
88
    CalcFxLx();
×
89
}
90

91
void GameWorldView::SetZoomFactor(float zoomFactor, bool smoothTransition /* = true*/)
×
92
{
93
    if(zoomFactor < ZOOM_FACTORS.front())
×
94
        targetZoomFactor_ = ZOOM_FACTORS.front();
×
95
    else if(zoomFactor > ZOOM_FACTORS.back())
×
96
        targetZoomFactor_ = ZOOM_FACTORS.back();
×
97
    else
98
        targetZoomFactor_ = zoomFactor;
×
99
    if(!smoothTransition)
×
100
    {
101
        zoomFactor_ = targetZoomFactor_;
×
102
        updateEffectiveZoomFactor();
×
103
        CalcFxLx();
×
104
    }
105
}
×
106

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

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

122
    return pos;
3✔
123
}
124

125
struct ObjectBetweenLines
126
{
127
    noBase& obj;
128
    DrawPoint pos; // Zeichenposition
129

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

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

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

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

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

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

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
        }
212

213
        // Figuren zwischen den Zeilen zeichnen
214
        for(auto& between_line : between_lines)
×
215
            between_line.obj.Draw(between_line.pos);
×
216
    }
217

218
    if(show_names || show_productivity)
×
219
        DrawNameProductivityOverlay(terrainRenderer);
×
220

221
    DrawGUI(rb, terrainRenderer, selected, drawMouse);
×
222

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

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

240
    glScissor(0, 0, windowSize.width, windowSize.height);
×
241
}
×
242

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

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

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

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

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

290
            // Currently selected point
291
            if(selectedPt == curPt)
×
292
                LOADER.GetMapTexture(20)->DrawFull(curPos);
×
293

294
            // not building roads, no further action needed
295
            if(rb.mode == RoadBuildMode::Disabled)
×
296
                continue;
×
297

298
            // we dont own curPt, no need for any rendering...
299
            if(!gwv.IsPlayerTerritory(curPt))
×
300
                continue;
×
301

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

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

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

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

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

361
void GameWorldView::DrawNameProductivityOverlay(const TerrainRenderer& terrainRenderer)
×
362
{
363
    for(int x = firstPt.x; x <= lastPt.x; ++x)
×
364
    {
365
        for(int y = firstPt.y; y <= lastPt.y; ++y)
×
366
        {
367
            // Coordinate transform
368
            Position curOffset;
×
369
            MapPoint pt = terrainRenderer.ConvertCoords(Position(x, y), &curOffset);
×
370

371
            const auto* no = GetWorld().GetSpecObj<noBaseBuilding>(pt);
×
372
            if(!no)
×
373
                continue;
×
374

375
            Position curPos = GetWorld().GetNodePos(pt) - offset + curOffset;
×
376
            curPos.y -= 22;
×
377

378
            // Is object not belonging to local player?
379
            if(no->GetPlayer() != gwv.GetPlayerId())
×
380
            {
381
                if(GetWorld().GetGGS().getSelection(AddonId::MILITARY_AID) == 2 && gwv.GetNumSoldiersForAttack(pt) > 0)
×
382
                {
383
                    auto* attackAidImage = LOADER.GetImageN("map_new", 20000);
×
384
                    attackAidImage->DrawFull(curPos - DrawPoint(0, attackAidImage->getHeight()));
×
385
                }
386
                continue;
×
387
            }
388

389
            // Draw object name
390
            if(show_names)
×
391
            {
392
                unsigned color = (no->GetGOT() == GO_Type::Buildingsite) ? COLOR_GREY : COLOR_YELLOW;
×
393
                SmallFont->Draw(curPos, _(BUILDING_NAMES[no->GetBuildingType()]),
×
394
                                FontStyle::CENTER | FontStyle::VCENTER, color);
395
                curPos.y += SmallFont->getHeight();
×
396
            }
397

398
            // Draw productivity/soldiers
399
            if(show_productivity)
×
400
                DrawProductivity(*no, curPos);
×
401
        }
402
    }
403
}
×
404

405
void GameWorldView::DrawProductivity(const noBaseBuilding& no, const DrawPoint& curPos)
×
406
{
407
    const GO_Type got = no.GetGOT();
×
408
    if(got == GO_Type::Buildingsite)
×
409
    {
410
        unsigned color = COLOR_GREY;
×
411

412
        unsigned short p = static_cast<const noBuildingSite&>(no).GetBuildProgress();
×
413
        SmallFont->Draw(curPos, (boost::format("(%1% %%)") % p).str(), FontStyle::CENTER | FontStyle::VCENTER, color);
×
414
    } else if(got == GO_Type::NobUsual || got == GO_Type::NobShipyard || got == GO_Type::NobTemple)
×
415
    {
416
        const auto& n = static_cast<const nobUsual&>(no);
×
417
        std::string text;
×
418
        unsigned color = COLOR_0_PERCENT;
×
419

420
        if(!n.HasWorker())
×
421
            text = _("(House unoccupied)");
×
422
        else if(n.IsProductionDisabledVirtual())
×
423
            text = _("(stopped)");
×
424
        else
425
        {
426
            // Catapult and Lookout tower doesn't have productivity!
427
            if(n.GetBuildingType() == BuildingType::Catapult || n.GetBuildingType() == BuildingType::LookoutTower)
×
428
                return;
×
429

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

450
        SmallFont->Draw(curPos, sSoldiers, FontStyle::CENTER | FontStyle::VCENTER,
×
451
                        (soldiers_count > 0) ? COLOR_YELLOW : COLOR_RED);
×
452
    }
453
}
454

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

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

489
        for(noBase& figure : GetWorld().GetFigures(curPt))
×
490
        {
491
            if(figure.IsMoving() && static_cast<noMovable&>(figure).GetCurMoveDir() == dir)
×
492
                between_lines.push_back(ObjectBetweenLines(figure, figPos));
×
493
        }
494
    }
495
}
×
496

497
constexpr auto getBqImgs()
498
{
499
    helpers::EnumArray<unsigned, BuildingQuality> imgs{};
500
    imgs[BuildingQuality::Flag] = 50;
501
    imgs[BuildingQuality::Hut] = 51;
502
    imgs[BuildingQuality::House] = 52;
503
    imgs[BuildingQuality::Castle] = 53;
504
    imgs[BuildingQuality::Mine] = 54;
505
    imgs[BuildingQuality::Harbor] = 55;
506
    return imgs;
507
}
508

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

529
void GameWorldView::DrawObject(const MapPoint& pt, const DrawPoint& curPos) const
×
530
{
531
    noBase* obj = GetWorld().GetNode(pt).obj;
×
532
    if(!obj)
×
533
        return;
×
534

535
    obj->Draw(curPos);
×
536
}
537

538
void GameWorldView::DrawBoundaryStone(const MapPoint& pt, const DrawPoint pos, Visibility vis)
×
539
{
540
    if(vis == Visibility::Invisible)
×
541
        return;
×
542

543
    const bool isFoW = vis == Visibility::FogOfWar;
×
544

545
    const BoundaryStones& boundary_stones =
546
      isFoW ? gwv.GetYoungestFOWNode(pt).boundary_stones : GetWorld().GetNode(pt).boundary_stones;
×
547
    const unsigned char owner = boundary_stones[BorderStonePos::OnPoint];
×
548

549
    if(!owner)
×
550
        return;
×
551

552
    const Nation nation = GetWorld().GetPlayer(owner - 1).nation;
×
553
    unsigned player_color = GetWorld().GetPlayer(owner - 1).color;
×
554
    if(isFoW)
×
555
        player_color = CalcPlayerFOWDrawColor(player_color);
×
556

557
    const auto curVertexPos = gwv.GetTerrainRenderer().GetVertexPos(pt);
×
558
    for(const auto bPos : helpers::EnumRange<BorderStonePos>{})
×
559
    {
560
        DrawPoint curPos;
×
561
        if(bPos == BorderStonePos::OnPoint)
×
562
            curPos = pos;
×
563
        else if(boundary_stones[bPos])
×
564
            curPos = pos
565
                     - DrawPoint((curVertexPos - gwv.GetTerrainRenderer().GetNeighbourVertexPos(pt, toDirection(bPos)))
×
566
                                 / 2.0f);
×
567
        else
568
            continue;
×
569
        LOADER.boundary_stone_cache[nation].draw(curPos, isFoW ? FOW_DRAW_COLOR : COLOR_WHITE, player_color);
×
570
    }
571
}
572

573
void GameWorldView::ToggleShowBQ()
×
574
{
575
    show_bq = !show_bq;
×
576
    SaveIngameSettingsValues();
×
577
    onHudSettingsChanged();
×
578
}
×
579

580
void GameWorldView::ToggleShowNames()
×
581
{
582
    show_names = !show_names;
×
583
    SaveIngameSettingsValues();
×
584
    onHudSettingsChanged();
×
585
}
×
586

587
void GameWorldView::ToggleShowProductivity()
×
588
{
589
    show_productivity = !show_productivity;
×
590
    SaveIngameSettingsValues();
×
591
    onHudSettingsChanged();
×
592
}
×
593

594
void GameWorldView::ToggleShowNamesAndProductivity()
×
595
{
596
    if(show_productivity && show_names)
×
597
        show_productivity = show_names = false;
×
598
    else
599
        show_productivity = show_names = true;
×
600
    SaveIngameSettingsValues();
×
601
    onHudSettingsChanged();
×
602
}
×
603

604
void GameWorldView::CopyHudSettingsTo(GameWorldView& other, bool copyBQ) const
×
605
{
606
    other.show_bq = (copyBQ ? show_bq : false);
×
607
    other.show_names = show_names;
×
608
    other.show_productivity = show_productivity;
×
609
}
×
610

611
void GameWorldView::MoveBy(const DrawPoint& numPixels)
22✔
612
{
613
    MoveTo(offset + numPixels);
22✔
614
}
22✔
615

616
void GameWorldView::MoveTo(const DrawPoint& newPos)
31✔
617
{
618
    offset = newPos;
31✔
619
    DrawPoint size(GetWorld().GetWidth() * TR_W, GetWorld().GetHeight() * TR_H);
31✔
620
    if(size.x && size.y)
31✔
621
    {
622
        offset.x %= size.x;
31✔
623
        offset.y %= size.y;
31✔
624

625
        if(offset.x < 0)
31✔
626
            offset.x += size.x;
4✔
627
        if(offset.y < 0)
31✔
628
            offset.y += size.y;
5✔
629
    }
630

631
    CalcFxLx();
31✔
632
}
31✔
633

634
void GameWorldView::MoveToMapPt(const MapPoint pt)
5✔
635
{
636
    if(!pt.isValid())
5✔
637
        return;
×
638

639
    lastOffset = offset;
5✔
640
    Position nodePos = GetWorld().GetNodePos(pt);
5✔
641

642
    MoveTo(nodePos - GetSize() / 2u);
5✔
643
}
644

645
void GameWorldView::MoveToLastPosition()
×
646
{
647
    Position newLastOffset = offset;
×
648

649
    MoveTo(lastOffset);
×
650

651
    lastOffset = newLastOffset;
×
652
}
×
653

654
void GameWorldView::AddDrawNodeCallback(IDrawNodeCallback* newCallback)
×
655
{
656
    RTTR_Assert(newCallback);
×
657
    drawNodeCallbacks.push_back(newCallback);
×
658
}
×
659

660
void GameWorldView::RemoveDrawNodeCallback(IDrawNodeCallback* callbackToRemove)
×
661
{
662
    auto itPos = helpers::find(drawNodeCallbacks, callbackToRemove);
×
663
    RTTR_Assert(itPos != drawNodeCallbacks.end());
×
664
    drawNodeCallbacks.erase(itPos);
×
665
}
×
666

667
void GameWorldView::CalcFxLx()
31✔
668
{
669
    // Calc first and last point in map units (with 1 extra for incomplete triangles)
670
    firstPt.x = offset.x / TR_W - 1;
31✔
671
    firstPt.y = offset.y / TR_H - 1;
31✔
672
    lastPt.x = (offset.x + size_.x) / TR_W + 1;
31✔
673
    const auto maxAltitude = gwv.getMaxNodeAltitude();
31✔
674
    lastPt.y = (offset.y + size_.y + maxAltitude * HEIGHT_FACTOR) / TR_H + 1;
31✔
675

676
    if(effectiveZoomFactor_ != 1.f) //-V550
31✔
677
    {
678
        // Calc pixels we can remove from sides, as they are not drawn due to zoom
679
        PointF diff(size_.x - size_.x / effectiveZoomFactor_, size_.y - size_.y / effectiveZoomFactor_);
×
680
        // Stay centered by removing half the pixels from opposite sites
681
        diff = diff / 2.f;
×
682
        // Convert to map points
683
        diff.x /= TR_W;
×
684
        diff.y /= TR_H;
×
685
        // Don't remove to much
686
        diff.x = std::floor(diff.x);
×
687
        diff.y = std::floor(diff.y);
×
688
        firstPt = Position(PointF(firstPt) + diff);
×
689
        lastPt = Position(PointF(lastPt) - diff);
×
690
    }
691
}
31✔
692

693
void GameWorldView::Resize(const Extent& newSize)
×
694
{
695
    size_ = newSize;
×
696
    CalcFxLx();
×
697
}
×
698

699
void GameWorldView::SaveIngameSettingsValues() const
×
700
{
701
    auto& ingameSettings = SETTINGS.ingame;
×
702
    ingameSettings.showBQ = show_bq;
×
703
    ingameSettings.showNames = show_names;
×
704
    ingameSettings.showProductivity = show_productivity;
×
705
}
×
706

707
void GameWorldView::updateEffectiveZoomFactor()
8✔
708
{
709
    // partially "undo" GUI scale depending on DPI scale
710
    // => zoom levels should look the same on screens with different DPI regardless of GUI scale
711
    effectiveZoomFactor_ = VIDEODRIVER.getGuiScale().screenToView(zoomFactor_ * VIDEODRIVER.getDpiScale());
8✔
712
}
8✔
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