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

Return-To-The-Roots / s25client / 20538043148

27 Dec 2025 10:46AM UTC coverage: 50.495% (-0.008%) from 50.503%
20538043148

Pull #1849

github

web-flow
Merge 207e98f6b into af2863637
Pull Request #1849: Wrap around from highest to lowest speed with "V" key

4 of 30 new or added lines in 2 files covered. (13.33%)

5 existing lines in 2 files now uncovered.

22559 of 44676 relevant lines covered (50.49%)

36064.69 hits per line

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

34.84
/libs/s25main/desktops/dskGameInterface.cpp
1
// Copyright (C) 2005 - 2025 Settlers Freaks (sf-team at siedler25.org)
2
//
3
// SPDX-License-Identifier: GPL-2.0-or-later
4

5
#include "dskGameInterface.h"
6
#include "CollisionDetection.h"
7
#include "EventManager.h"
8
#include "Game.h"
9
#include "GamePlayer.h"
10
#include "Loader.h"
11
#include "NWFInfo.h"
12
#include "Settings.h"
13
#include "SoundManager.h"
14
#include "WindowManager.h"
15
#include "addons/AddonMaxWaterwayLength.h"
16
#include "buildings/noBuildingSite.h"
17
#include "buildings/nobHQ.h"
18
#include "buildings/nobHarborBuilding.h"
19
#include "buildings/nobMilitary.h"
20
#include "buildings/nobStorehouse.h"
21
#include "buildings/nobTemple.h"
22
#include "buildings/nobUsual.h"
23
#include "controls/ctrlImageButton.h"
24
#include "controls/ctrlText.h"
25
#include "driver/MouseCoords.h"
26
#include "drivers/VideoDriverWrapper.h"
27
#include "helpers/format.hpp"
28
#include "helpers/strUtils.h"
29
#include "helpers/toString.h"
30
#include "ingameWindows/iwAIDebug.h"
31
#include "ingameWindows/iwAction.h"
32
#include "ingameWindows/iwBaseWarehouse.h"
33
#include "ingameWindows/iwBuildOrder.h"
34
#include "ingameWindows/iwBuilding.h"
35
#include "ingameWindows/iwBuildingProductivities.h"
36
#include "ingameWindows/iwBuildingSite.h"
37
#include "ingameWindows/iwBuildings.h"
38
#include "ingameWindows/iwDiplomacy.h"
39
#include "ingameWindows/iwDistribution.h"
40
#include "ingameWindows/iwEconomicProgress.h"
41
#include "ingameWindows/iwEndgame.h"
42
#include "ingameWindows/iwHQ.h"
43
#include "ingameWindows/iwHarborBuilding.h"
44
#include "ingameWindows/iwInventory.h"
45
#include "ingameWindows/iwMainMenu.h"
46
#include "ingameWindows/iwMapDebug.h"
47
#include "ingameWindows/iwMerchandiseStatistics.h"
48
#include "ingameWindows/iwMilitary.h"
49
#include "ingameWindows/iwMilitaryBuilding.h"
50
#include "ingameWindows/iwMinimap.h"
51
#include "ingameWindows/iwMusicPlayer.h"
52
#include "ingameWindows/iwOptionsWindow.h"
53
#include "ingameWindows/iwPostWindow.h"
54
#include "ingameWindows/iwRoadWindow.h"
55
#include "ingameWindows/iwSave.h"
56
#include "ingameWindows/iwShip.h"
57
#include "ingameWindows/iwSkipGFs.h"
58
#include "ingameWindows/iwStatistics.h"
59
#include "ingameWindows/iwTempleBuilding.h"
60
#include "ingameWindows/iwTextfile.h"
61
#include "ingameWindows/iwTools.h"
62
#include "ingameWindows/iwTrade.h"
63
#include "ingameWindows/iwTransport.h"
64
#include "ingameWindows/iwVictory.h"
65
#include "lua/GameDataLoader.h"
66
#include "network/GameClient.h"
67
#include "notifications/BuildingNote.h"
68
#include "notifications/NotificationManager.h"
69
#include "ogl/FontStyle.h"
70
#include "ogl/SoundEffectItem.h"
71
#include "ogl/glArchivItem_Bitmap_Player.h"
72
#include "ogl/glFont.h"
73
#include "pathfinding/FindPathForRoad.h"
74
#include "postSystem/PostBox.h"
75
#include "postSystem/PostMsg.h"
76
#include "random/Random.h"
77
#include "world/GameWorldBase.h"
78
#include "world/GameWorldViewer.h"
79
#include "nodeObjs/noFlag.h"
80
#include "nodeObjs/noTree.h"
81
#include "gameData/BuildingProperties.h"
82
#include "gameData/GameConsts.h"
83
#include "gameData/GuiConsts.h"
84
#include "gameData/TerrainDesc.h"
85
#include "gameData/const_gui_ids.h"
86
#include "liblobby/LobbyClient.h"
87
#include <algorithm>
88
#include <cstdio>
89
#include <utility>
90

91
namespace {
92
enum
93
{
94
    ID_btMap,
95
    ID_btOptions,
96
    ID_btConstructionAid,
97
    ID_btPost,
98
    ID_txtNumMsg
99
};
100

101
float getNextZoomLevel(const float currentZoom)
7✔
102
{
103
    // Get first level bigger than current zoom
104
    // NOLINTNEXTLINE(readability-qualified-auto)
105
    auto it = std::upper_bound(ZOOM_FACTORS.begin(), ZOOM_FACTORS.end(), currentZoom);
7✔
106
    return (it == ZOOM_FACTORS.end()) ? ZOOM_FACTORS.front() : *it;
7✔
107
}
108

109
float getPreviousZoomLevel(const float currentZoom)
4✔
110
{
111
    // Get last level bigger or equal than current zoom
112
    // NOLINTNEXTLINE(readability-qualified-auto)
113
    auto it = std::lower_bound(ZOOM_FACTORS.begin(), ZOOM_FACTORS.end(), currentZoom);
4✔
114
    return (it == ZOOM_FACTORS.begin()) ? ZOOM_FACTORS.back() : *(--it);
4✔
115
}
116
} // namespace
117

118
dskGameInterface::dskGameInterface(std::shared_ptr<Game> game, std::shared_ptr<const NWFInfo> nwfInfo,
6✔
119
                                   unsigned playerIdx, bool initOGL)
6✔
120
    : Desktop(nullptr), game_(std::move(game)), nwfInfo_(std::move(nwfInfo)),
12✔
121
      worldViewer(playerIdx, const_cast<Game&>(*game_).world_),
6✔
122
      gwv(worldViewer, Position(0, 0), VIDEODRIVER.GetRenderSize()), cbb(*LOADER.GetPaletteN("pal5")),
18✔
123
      actionwindow(nullptr), roadwindow(nullptr), minimap(worldViewer), isScrolling(false),
6✔
124
      cheats_(const_cast<Game&>(*game_).world_), cheatCommandTracker_(cheats_)
18✔
125
{
126
    road.mode = RoadBuildMode::Disabled;
6✔
127
    road.point = MapPoint(0, 0);
6✔
128
    road.start = MapPoint(0, 0);
6✔
129

130
    SetScale(false);
6✔
131

132
    DrawPoint barPos((GetSize().x - LOADER.GetImageN("resource", 29)->getWidth()) / 2 + 44,
12✔
133
                     GetSize().y - LOADER.GetImageN("resource", 29)->getHeight() + 4);
18✔
134

135
    Extent btSize = Extent(37, 32);
6✔
136
    AddImageButton(ID_btMap, barPos, btSize, TextureColor::Green1, LOADER.GetImageN("io", 50), _("Map"))
6✔
137
      ->SetBorder(false);
12✔
138
    barPos.x += btSize.x;
6✔
139
    AddImageButton(ID_btOptions, barPos, btSize, TextureColor::Green1, LOADER.GetImageN("io", 192), _("Main selection"))
6✔
140
      ->SetBorder(false);
12✔
141
    barPos.x += btSize.x;
6✔
142
    AddImageButton(ID_btConstructionAid, barPos, btSize, TextureColor::Green1, LOADER.GetImageN("io", 83),
6✔
143
                   _("Construction aid mode"))
144
      ->SetBorder(false);
12✔
145
    barPos.x += btSize.x;
6✔
146
    AddImageButton(ID_btPost, barPos, btSize, TextureColor::Green1, LOADER.GetImageN("io", 62), _("Post office"))
6✔
147
      ->SetBorder(false);
12✔
148
    barPos += DrawPoint(18, 24);
6✔
149

150
    AddText(ID_txtNumMsg, barPos, "", COLOR_YELLOW, FontStyle::CENTER | FontStyle::VCENTER, SmallFont);
6✔
151

152
    const_cast<Game&>(*game_).world_.SetGameInterface(this);
6✔
153

154
    std::fill(borders.begin(), borders.end(), (glArchivItem_Bitmap*)(nullptr));
6✔
155
    cbb.loadEdges(LOADER.GetArchive("resource"));
12✔
156
    cbb.buildBorder(VIDEODRIVER.GetRenderSize(), borders);
6✔
157

158
    InitPlayer();
6✔
159
    if(initOGL)
6✔
160
        worldViewer.InitTerrainRenderer();
×
161

162
    VIDEODRIVER.setTargetFramerate(SETTINGS.video.framerate); // Use requested setting for ingame
6✔
163
}
6✔
164

165
void dskGameInterface::InitPlayer()
6✔
166
{
167
    // Jump to players HQ if it exists
168
    if(worldViewer.GetPlayer().GetHQPos().isValid())
6✔
169
        gwv.MoveToMapPt(worldViewer.GetPlayer().GetHQPos());
6✔
170

171
    evBld = worldViewer.GetWorld().GetNotifications().subscribe<BuildingNote>([this](const auto& note) {
12✔
172
        if(note.player == worldViewer.GetPlayerId())
×
173
            this->OnBuildingNote(note);
×
174
    });
6✔
175
    PostBox& postBox = GetPostBox();
6✔
176
    postBox.ObserveNewMsg([this](const auto& msg, auto msgCt) { this->NewPostMessage(msg, msgCt); });
6✔
177
    postBox.ObserveDeletedMsg([this](auto msgCt) { this->PostMessageDeleted(msgCt); });
6✔
178
    UpdatePostIcon(postBox.GetNumMsgs(), true);
6✔
179
}
6✔
180

181
PostBox& dskGameInterface::GetPostBox()
6✔
182
{
183
    PostBox* postBox = worldViewer.GetWorld().GetPostMgr().GetPostBox(worldViewer.GetPlayerId());
6✔
184
    if(!postBox)
6✔
185
        postBox = &worldViewer.GetWorldNonConst().GetPostMgr().AddPostBox(worldViewer.GetPlayerId());
6✔
186
    RTTR_Assert(postBox != nullptr);
6✔
187
    return *postBox;
6✔
188
}
189

190
dskGameInterface::~dskGameInterface()
6✔
191
{
192
    for(auto& border : borders)
30✔
193
        deletePtr(border);
24✔
194
    GAMECLIENT.RemoveInterface(this);
6✔
195
    LOBBYCLIENT.RemoveListener(this);
6✔
196
}
6✔
197

198
void dskGameInterface::SetActive(bool activate)
18✔
199
{
200
    if(activate == IsActive())
18✔
201
        return;
9✔
202
    if(!activate && isScrolling)
9✔
203
    {
204
        // Stay active if scrolling and no modal window is open
205
        const IngameWindow* wnd = WINDOWMANAGER.GetTopMostWindow();
1✔
206
        if(wnd && wnd->IsModal())
1✔
207
            StopScrolling();
×
208
        else
209
            return;
1✔
210
    }
211
    Desktop::SetActive(activate);
8✔
212
    // Do this here to allow previous screen to keep control
213
    if(activate)
8✔
214
    {
215
        GAMECLIENT.SetInterface(this);
6✔
216
        LOBBYCLIENT.AddListener(this);
6✔
217
        if(!game_->IsStarted())
6✔
218
        {
219
            GAMECLIENT.OnGameStart();
6✔
220

221
            ShowPersistentWindowsAfterSwitch();
6✔
222
        }
223
    }
224
}
225

226
void dskGameInterface::StopScrolling()
6✔
227
{
228
    isScrolling = false;
6✔
229
    WINDOWMANAGER.SetCursor(road.mode == RoadBuildMode::Disabled ? Cursor::Hand : Cursor::Remove);
6✔
230
}
6✔
231

232
void dskGameInterface::StartScrolling(const Position& mousePos)
11✔
233
{
234
    startScrollPt = mousePos;
11✔
235
    isScrolling = true;
11✔
236
    WINDOWMANAGER.SetCursor(Cursor::Scroll);
11✔
237
}
11✔
238

239
void dskGameInterface::ToggleFoW()
×
240
{
241
    DisableFoW(!GAMECLIENT.IsReplayFOWDisabled());
×
242
}
×
243

244
void dskGameInterface::DisableFoW(const bool hideFOW)
×
245
{
246
    GAMECLIENT.SetReplayFOW(hideFOW);
×
247
    // Notify viewer and minimap to recalculate the visibility
248
    worldViewer.RecalcAllColors();
×
249
    minimap.UpdateAll();
×
250
}
×
251

252
void dskGameInterface::ShowPersistentWindowsAfterSwitch()
6✔
253
{
254
    auto& windows = SETTINGS.windows.persistentSettings;
6✔
255

256
    if(windows[CGI_CHAT].isOpen)
6✔
257
        WINDOWMANAGER.ShowAfterSwitch(std::make_unique<iwChat>(this));
×
258
    if(windows[CGI_POSTOFFICE].isOpen)
6✔
259
        WINDOWMANAGER.ShowAfterSwitch(std::make_unique<iwPostWindow>(gwv, GetPostBox()));
×
260
    if(windows[CGI_DISTRIBUTION].isOpen)
6✔
261
        WINDOWMANAGER.ShowAfterSwitch(std::make_unique<iwDistribution>(gwv.GetViewer(), GAMECLIENT));
×
262
    if(windows[CGI_BUILDORDER].isOpen && gwv.GetWorld().GetGGS().isEnabled(AddonId::CUSTOM_BUILD_SEQUENCE))
6✔
263
        WINDOWMANAGER.ShowAfterSwitch(std::make_unique<iwBuildOrder>(gwv.GetViewer()));
×
264
    if(windows[CGI_TRANSPORT].isOpen)
6✔
265
        WINDOWMANAGER.ShowAfterSwitch(std::make_unique<iwTransport>(gwv.GetViewer(), GAMECLIENT));
×
266
    if(windows[CGI_MILITARY].isOpen)
6✔
267
        WINDOWMANAGER.ShowAfterSwitch(std::make_unique<iwMilitary>(gwv.GetViewer(), GAMECLIENT));
×
268
    if(windows[CGI_TOOLS].isOpen)
6✔
269
        WINDOWMANAGER.ShowAfterSwitch(std::make_unique<iwTools>(gwv.GetViewer(), GAMECLIENT));
×
270
    if(windows[CGI_INVENTORY].isOpen)
6✔
271
        WINDOWMANAGER.ShowAfterSwitch(std::make_unique<iwInventory>(gwv.GetViewer().GetPlayer()));
×
272
    if(windows[CGI_MINIMAP].isOpen)
6✔
273
        WINDOWMANAGER.ShowAfterSwitch(std::make_unique<iwMinimap>(minimap, gwv));
×
274
    if(windows[CGI_BUILDINGS].isOpen)
6✔
275
        WINDOWMANAGER.ShowAfterSwitch(std::make_unique<iwBuildings>(gwv, GAMECLIENT));
×
276
    if(windows[CGI_BUILDINGSPRODUCTIVITY].isOpen)
6✔
277
        WINDOWMANAGER.ShowAfterSwitch(std::make_unique<iwBuildingProductivities>(gwv.GetViewer().GetPlayer()));
×
278
    if(windows[CGI_MUSICPLAYER].isOpen)
6✔
279
        WINDOWMANAGER.ShowAfterSwitch(std::make_unique<iwMusicPlayer>());
×
280
    if(windows[CGI_STATISTICS].isOpen)
6✔
281
        WINDOWMANAGER.ShowAfterSwitch(std::make_unique<iwStatistics>(gwv.GetViewer()));
×
282
    if(windows[CGI_ECONOMICPROGRESS].isOpen && gwv.GetWorld().getEconHandler())
6✔
283
        WINDOWMANAGER.ShowAfterSwitch(std::make_unique<iwEconomicProgress>(gwv.GetViewer()));
×
284
    if(windows[CGI_DIPLOMACY].isOpen)
6✔
285
        WINDOWMANAGER.ShowAfterSwitch(std::make_unique<iwDiplomacy>(gwv.GetViewer(), GAMECLIENT));
×
286
    if(windows[CGI_SHIP].isOpen)
6✔
287
        WINDOWMANAGER.ShowAfterSwitch(
×
288
          std::make_unique<iwShip>(gwv, GAMECLIENT, gwv.GetViewer().GetPlayer().GetShipByID(0)));
×
289
    if(windows[CGI_MERCHANDISE_STATISTICS].isOpen)
6✔
290
        WINDOWMANAGER.ShowAfterSwitch(std::make_unique<iwMerchandiseStatistics>(gwv.GetViewer().GetPlayer()));
×
291
}
6✔
292

293
void dskGameInterface::Resize(const Extent& newSize)
×
294
{
295
    Window::Resize(newSize);
×
296

297
    // recreate borders
298
    for(auto& border : borders)
×
299
        deletePtr(border);
×
300
    cbb.buildBorder(newSize, borders);
×
301

302
    // move buttons
303
    DrawPoint barPos((newSize.x - LOADER.GetImageN("resource", 29)->getWidth()) / 2 + 44,
×
304
                     newSize.y - LOADER.GetImageN("resource", 29)->getHeight() + 4);
×
305

306
    auto* button = GetCtrl<ctrlButton>(ID_btMap);
×
307
    button->SetPos(barPos);
×
308

309
    barPos.x += button->GetSize().x;
×
310
    button = GetCtrl<ctrlButton>(ID_btOptions);
×
311
    button->SetPos(barPos);
×
312

313
    barPos.x += button->GetSize().x;
×
314
    button = GetCtrl<ctrlButton>(ID_btConstructionAid);
×
315
    button->SetPos(barPos);
×
316

317
    barPos.x += button->GetSize().x;
×
318
    button = GetCtrl<ctrlButton>(ID_btPost);
×
319
    button->SetPos(barPos);
×
320

321
    barPos += DrawPoint(18, 24);
×
322
    auto* text = GetCtrl<ctrlText>(ID_txtNumMsg);
×
323
    text->SetPos(barPos);
×
324

325
    gwv.Resize(newSize);
×
326
}
×
327

328
void dskGameInterface::Msg_ButtonClick(const unsigned ctrl_id)
×
329
{
330
    switch(ctrl_id)
×
331
    {
332
        case ID_btMap: WINDOWMANAGER.ToggleWindow(std::make_unique<iwMinimap>(minimap, gwv)); break;
×
333
        case ID_btOptions: WINDOWMANAGER.ToggleWindow(std::make_unique<iwMainMenu>(gwv, GAMECLIENT)); break;
×
334
        case ID_btConstructionAid:
×
335
            if(WINDOWMANAGER.IsDesktopActive())
×
336
                gwv.ToggleShowBQ();
×
337
            break;
×
338
        case ID_btPost:
×
339
            WINDOWMANAGER.ToggleWindow(std::make_unique<iwPostWindow>(gwv, GetPostBox()));
×
340
            UpdatePostIcon(GetPostBox().GetNumMsgs(), false);
×
341
            break;
×
342
    }
343
}
×
344

345
void dskGameInterface::Msg_PaintBefore()
×
346
{
347
    Desktop::Msg_PaintBefore();
×
348

349
    // Spiel ausführen
350
    Run();
×
351

352
    /// Padding of the figures
353
    const DrawPoint figPadding(12, 12);
×
354
    const DrawPoint screenSize(VIDEODRIVER.GetRenderSize());
×
355
    // Rahmen zeichnen
356
    borders[0]->DrawFull(DrawPoint(0, 0));                                      // oben (mit Ecken)
×
357
    borders[1]->DrawFull(DrawPoint(0, screenSize.y - figPadding.y));            // unten (mit Ecken)
×
358
    borders[2]->DrawFull(DrawPoint(0, figPadding.y));                           // links
×
359
    borders[3]->DrawFull(DrawPoint(screenSize.x - figPadding.x, figPadding.y)); // rechts
×
360

361
    // The figure/statues and the button bar
362
    glArchivItem_Bitmap& imgFigLeftTop = *LOADER.GetImageN("resource", 17);
×
363
    glArchivItem_Bitmap& imgFigRightTop = *LOADER.GetImageN("resource", 18);
×
364
    glArchivItem_Bitmap& imgFigLeftBot = *LOADER.GetImageN("resource", 19);
×
365
    glArchivItem_Bitmap& imgFigRightBot = *LOADER.GetImageN("resource", 20);
×
366
    imgFigLeftTop.DrawFull(figPadding);
×
367
    imgFigRightTop.DrawFull(DrawPoint(screenSize.x - figPadding.x - imgFigRightTop.getWidth(), figPadding.y));
×
368
    imgFigLeftBot.DrawFull(DrawPoint(figPadding.x, screenSize.y - figPadding.y - imgFigLeftBot.getHeight()));
×
369
    imgFigRightBot.DrawFull(screenSize - figPadding - imgFigRightBot.GetSize());
×
370

371
    glArchivItem_Bitmap& imgButtonBar = *LOADER.GetImageN("resource", 29);
×
372
    imgButtonBar.DrawFull(
×
373
      DrawPoint((screenSize.x - imgButtonBar.getWidth()) / 2, screenSize.y - imgButtonBar.getHeight()));
×
374
}
×
375

376
void dskGameInterface::Msg_PaintAfter()
×
377
{
378
    Desktop::Msg_PaintAfter();
×
379

380
    const GameWorldBase& world = worldViewer.GetWorld();
×
381

382
    if(SETTINGS.global.showGFInfo)
×
383
    {
384
        std::array<char, 256> nwf_string;
385
        if(GAMECLIENT.IsReplayModeOn())
×
386
        {
387
            snprintf(nwf_string.data(), nwf_string.size(),
×
388
                     _("(Replay-Mode) Current GF: %u (End at: %u) / GF length: %u ms / NWF length: %u gf (%u ms)"),
389
                     world.GetEvMgr().GetCurrentGF(), GAMECLIENT.GetLastReplayGF(),
×
390
                     GAMECLIENT.GetGFLength() / FramesInfo::milliseconds32_t(1), GAMECLIENT.GetNWFLength(),
×
391
                     GAMECLIENT.GetNWFLength() * GAMECLIENT.GetGFLength() / FramesInfo::milliseconds32_t(1));
×
392
        } else
393
            snprintf(nwf_string.data(), nwf_string.size(),
×
394
                     _("Current GF: %u / GF length: %u ms / NWF length: %u gf (%u ms) /  Ping: %u ms"),
395
                     world.GetEvMgr().GetCurrentGF(), GAMECLIENT.GetGFLength() / FramesInfo::milliseconds32_t(1),
×
396
                     GAMECLIENT.GetNWFLength(),
×
397
                     GAMECLIENT.GetNWFLength() * GAMECLIENT.GetGFLength() / FramesInfo::milliseconds32_t(1),
×
398
                     worldViewer.GetPlayer().ping);
×
399
        NormalFont->Draw(DrawPoint(30, 1), nwf_string.data(), FontStyle{}, COLOR_YELLOW);
×
400
    }
401

402
    // tournament mode?
403
    const unsigned tournamentDuration = GAMECLIENT.GetTournamentModeDuration();
×
404
    if(tournamentDuration)
×
405
    {
406
        unsigned curGF = world.GetEvMgr().GetCurrentGF();
×
407
        std::string tournamentNotice;
×
408
        if(curGF >= tournamentDuration)
×
409
            tournamentNotice = _("Tournament finished");
×
410
        else
411
        {
412
            tournamentNotice =
413
              helpers::format("Tournament mode: %1% remaining", GAMECLIENT.FormatGFTime(tournamentDuration - curGF));
×
414
        }
415
        NormalFont->Draw(DrawPoint(VIDEODRIVER.GetRenderSize().x - 30, 1), tournamentNotice, FontStyle::AlignH::RIGHT,
×
416
                         COLOR_YELLOW);
417
    }
418

419
    // Replaydateianzeige in der linken unteren Ecke
420
    if(GAMECLIENT.IsReplayModeOn())
×
421
    {
422
        NormalFont->Draw(DrawPoint(0, VIDEODRIVER.GetRenderSize().y), GAMECLIENT.GetReplayFilename().string(),
×
423
                         FontStyle::BOTTOM, COLOR_YELLOW);
424
    } else
425
    {
426
        // Laggende Spieler anzeigen in Form von Schnecken
427
        DrawPoint snailPos(VIDEODRIVER.GetRenderSize().x - 70, 35);
×
428
        for(const NWFPlayerInfo& player : nwfInfo_->getPlayerInfos())
×
429
        {
430
            if(player.isLagging)
×
431
            {
432
                LOADER.GetPlayerImage("rttr", 0)->DrawFull(Rect(snailPos, 30, 30), COLOR_WHITE,
×
433
                                                           game_->world_.GetPlayer(player.id).color);
×
434
                snailPos.x -= 40;
×
435
            }
436
        }
437
    }
438

439
    // Show icons in the upper right corner of the game interface
440
    DrawPoint iconPos(VIDEODRIVER.GetRenderSize().x - 56, 32);
×
441

442
    // Draw cheating indicator icon (WINTER)
443
    if(cheats_.isCheatModeOn())
×
444
    {
445
        glArchivItem_Bitmap* cheatingImg = LOADER.GetImageN("io", 75);
×
446
        cheatingImg->DrawFull(iconPos);
×
447
        iconPos -= DrawPoint(cheatingImg->getWidth() + 6, 0);
×
448
    }
449

450
    // Draw speed indicator icon
451
    const int speedStep = static_cast<int>(REFERENCE_SPEED / 10ms) - static_cast<int>(GAMECLIENT.GetGFLength() / 10ms);
×
452

453
    if(speedStep != 0)
×
454
    {
455
        glArchivItem_Bitmap* runnerImg = LOADER.GetImageN("io", 164);
×
456

457
        runnerImg->DrawFull(iconPos);
×
458

459
        if(speedStep != 1)
×
460
        {
461
            std::string multiplier = helpers::toString(std::abs(speedStep));
×
462
            NormalFont->Draw(iconPos - runnerImg->GetOrigin() + DrawPoint(19, 6), multiplier, FontStyle::LEFT,
×
463
                             speedStep > 0 ? COLOR_YELLOW : COLOR_RED);
464
        }
465
        iconPos -= DrawPoint(runnerImg->getWidth() + 4, 0);
×
466
    }
467

468
    // Draw zoom level indicator icon
469
    if(gwv.GetCurrentTargetZoomFactor() != 1.f) //-V550
×
470
    {
471
        glArchivItem_Bitmap* magnifierImg = LOADER.GetImageN("io", 36);
×
472

473
        magnifierImg->DrawFull(iconPos);
×
474

475
        std::string zoom_percent = helpers::toString((int)(gwv.GetCurrentTargetZoomFactor() * 100)) + "%";
×
476
        NormalFont->Draw(iconPos - magnifierImg->GetOrigin() + DrawPoint(9, 7), zoom_percent, FontStyle::CENTER,
×
477
                         COLOR_YELLOW);
478
        iconPos -= DrawPoint(magnifierImg->getWidth() + 4, 0);
×
479
    }
480
}
×
481

482
bool dskGameInterface::Msg_LeftDown(const MouseCoords& mc)
3✔
483
{
484
    DrawPoint btOrig(VIDEODRIVER.GetRenderSize().x / 2 - LOADER.GetImageN("resource", 29)->getWidth() / 2 + 44,
6✔
485
                     VIDEODRIVER.GetRenderSize().y - LOADER.GetImageN("resource", 29)->getHeight() + 4);
9✔
486
    Extent btSize = Extent(37, 32) * 4u;
3✔
487
    if(IsPointInRect(mc.pos, Rect(btOrig, btSize)))
3✔
488
        return false;
×
489

490
    // Start scrolling also on Ctrl + left click
491
    if(VIDEODRIVER.GetModKeyState().ctrl)
3✔
492
    {
493
        Msg_RightDown(mc);
1✔
494
        return true;
1✔
495
    } else if(isScrolling)
2✔
496
        StopScrolling();
2✔
497

498
    // Unterscheiden je nachdem Straäcnbaumodus an oder aus ist
499
    if(road.mode != RoadBuildMode::Disabled)
2✔
500
    {
501
        // in "richtige" Map-Koordinaten Konvertieren, den aktuellen selektierten Punkt
502
        const MapPoint selPt = gwv.GetSelectedPt();
1✔
503

504
        if(selPt == road.point)
1✔
505
        {
506
            // Selektierter Punkt ist der gleiche wie der Straßenpunkt --> Fenster mit Wegbau abbrechen
507
            ShowRoadWindow(mc.pos);
×
508
        } else
509
        {
510
            // altes Roadwindow schließen
511
            WINDOWMANAGER.Close((unsigned)CGI_ROADWINDOW);
1✔
512

513
            // Ist das ein gültiger neuer Wegpunkt?
514
            if(worldViewer.IsRoadAvailable(road.mode == RoadBuildMode::Boat, selPt)
1✔
515
               && worldViewer.IsPlayerTerritory(selPt))
1✔
516
            {
517
                MapPoint targetPt = selPt;
1✔
518
                if(!BuildRoadPart(targetPt))
1✔
519
                    ShowRoadWindow(mc.pos);
×
520
            } else if(worldViewer.GetBQ(selPt) != BuildingQuality::Nothing)
×
521
            {
522
                // Wurde bereits auf das gebaute Stück geklickt?
523
                unsigned idOnRoad = GetIdInCurBuildRoad(selPt);
×
524
                if(idOnRoad)
×
525
                    DemolishRoad(idOnRoad);
×
526
                else
527
                {
528
                    MapPoint targetPt = selPt;
×
529
                    if(BuildRoadPart(targetPt))
×
530
                    {
531
                        // Ist der Zielpunkt der gleiche geblieben?
532
                        if(selPt == targetPt)
×
533
                            GI_BuildRoad();
×
534
                    } else if(selPt == targetPt)
×
535
                        ShowRoadWindow(mc.pos);
×
536
                }
537
            }
538
            // Wurde auf eine Flagge geklickt und ist diese Flagge nicht der Weganfangspunkt?
539
            else if(worldViewer.GetWorld().GetNO(selPt)->GetType() == NodalObjectType::Flag && selPt != road.start)
×
540
            {
541
                MapPoint targetPt = selPt;
×
542
                if(BuildRoadPart(targetPt))
×
543
                {
544
                    if(selPt == targetPt)
×
545
                        GI_BuildRoad();
×
546
                } else if(selPt == targetPt)
×
547
                    ShowRoadWindow(mc.pos);
×
548
            } else
549
            {
550
                unsigned tbr = GetIdInCurBuildRoad(selPt);
×
551
                // Wurde bereits auf das gebaute Stück geklickt?
552
                if(tbr)
×
553
                    DemolishRoad(tbr);
×
554
                else
555
                    ShowRoadWindow(mc.pos);
×
556
            }
557
        }
558
    } else
559
    {
560
        bool enable_military_buildings = false;
1✔
561

562
        iwAction::Tabs action_tabs;
1✔
563

564
        const MapPoint cSel = gwv.GetSelectedPt();
1✔
565

566
        // Vielleicht steht hier auch ein Schiff?
567
        if(const noShip* ship = worldViewer.GetShip(cSel))
1✔
568
        {
569
            WINDOWMANAGER.Show(std::make_unique<iwShip>(gwv, GAMECLIENT, ship));
×
570
            return true;
×
571
        }
572

573
        // Evtl ists nen Haus? (unser Haus)
574
        const noBase& selObj = *worldViewer.GetWorld().GetNO(cSel);
1✔
575
        if(selObj.GetType() == NodalObjectType::Building && worldViewer.IsOwner(cSel))
1✔
576
        {
577
            if(auto* wnd = WINDOWMANAGER.FindNonModalWindow(CGI_BUILDING + MapBase::CreateGUIID(cSel)))
×
578
            {
579
                WINDOWMANAGER.SetActiveWindow(*wnd);
×
580
                return true;
×
581
            }
582
            BuildingType bt = static_cast<const noBuilding&>(selObj).GetBuildingType();
×
583
            // HQ
584
            if(bt == BuildingType::Headquarters)
×
585
                WINDOWMANAGER.Show(
×
586
                  std::make_unique<iwHQ>(gwv, GAMECLIENT, worldViewer.GetWorldNonConst().GetSpecObj<nobHQ>(cSel)));
×
587
            // Lagerhäuser
588
            else if(bt == BuildingType::Storehouse)
×
589
                WINDOWMANAGER.Show(std::make_unique<iwBaseWarehouse>(
×
590
                  gwv, GAMECLIENT, worldViewer.GetWorldNonConst().GetSpecObj<nobStorehouse>(cSel)));
×
591
            // Hafengebäude
592
            else if(bt == BuildingType::HarborBuilding)
×
593
                WINDOWMANAGER.Show(std::make_unique<iwHarborBuilding>(
×
594
                  gwv, GAMECLIENT, worldViewer.GetWorldNonConst().GetSpecObj<nobHarborBuilding>(cSel)));
×
595
            // Militärgebäude
596
            else if(BuildingProperties::IsMilitary(bt))
×
597
                WINDOWMANAGER.Show(std::make_unique<iwMilitaryBuilding>(
×
598
                  gwv, GAMECLIENT, worldViewer.GetWorldNonConst().GetSpecObj<nobMilitary>(cSel)));
×
599
            else if(bt == BuildingType::Temple)
×
600
                WINDOWMANAGER.Show(std::make_unique<iwTempleBuilding>(
×
601
                  gwv, GAMECLIENT, worldViewer.GetWorldNonConst().GetSpecObj<nobTemple>(cSel)));
×
602
            else
603
                WINDOWMANAGER.Show(std::make_unique<iwBuilding>(
×
604
                  gwv, GAMECLIENT, worldViewer.GetWorldNonConst().GetSpecObj<nobUsual>(cSel)));
×
605
            return true;
×
606
        }
607
        // oder vielleicht eine Baustelle?
608
        else if(selObj.GetType() == NodalObjectType::Buildingsite && worldViewer.IsOwner(cSel))
1✔
609
        {
610
            if(!WINDOWMANAGER.FindNonModalWindow(CGI_BUILDING + MapBase::CreateGUIID(cSel)))
×
611
                WINDOWMANAGER.Show(
×
612
                  std::make_unique<iwBuildingSite>(gwv, worldViewer.GetWorld().GetSpecObj<noBuildingSite>(cSel)));
×
613
            return true;
×
614
        }
615

616
        action_tabs.watch = true;
1✔
617
        // Unser Land
618
        if(worldViewer.IsOwner(cSel))
1✔
619
        {
620
            const BuildingQuality bq = worldViewer.GetBQ(cSel);
1✔
621
            // Kann hier was gebaut werden?
622
            if(bq >= BuildingQuality::Mine)
1✔
623
            {
624
                action_tabs.build = true;
1✔
625

626
                // Welches Gebäude kann gebaut werden?
627
                switch(bq)
1✔
628
                {
629
                    case BuildingQuality::Mine: action_tabs.build_tabs = iwAction::BuildTab::Mine; break;
×
630
                    case BuildingQuality::Hut: action_tabs.build_tabs = iwAction::BuildTab::Hut; break;
×
631
                    case BuildingQuality::House: action_tabs.build_tabs = iwAction::BuildTab::House; break;
×
632
                    case BuildingQuality::Castle: action_tabs.build_tabs = iwAction::BuildTab::Castle; break;
1✔
633
                    case BuildingQuality::Harbor: action_tabs.build_tabs = iwAction::BuildTab::Harbor; break;
×
634
                    default: break;
×
635
                }
636

637
                if(!worldViewer.GetWorld().IsFlagAround(cSel))
1✔
638
                    action_tabs.setflag = true;
1✔
639

640
                // Prüfen, ob sich Militärgebäude in der Nähe befinden, wenn nein, können auch eigene
641
                // Militärgebäude gebaut werden
642
                enable_military_buildings =
1✔
643
                  !worldViewer.GetWorld().IsMilitaryBuildingNearNode(cSel, worldViewer.GetPlayerId());
1✔
644
            } else if(bq == BuildingQuality::Flag)
×
645
                action_tabs.setflag = true;
×
646
            else if(selObj.GetType() == NodalObjectType::Flag)
×
647
                action_tabs.flag = true;
×
648

649
            if(selObj.GetType() != NodalObjectType::Flag && selObj.GetType() != NodalObjectType::Building)
1✔
650
            {
651
                // Check if there are roads
652
                for(const Direction dir : helpers::EnumRange<Direction>{})
16✔
653
                {
654
                    const PointRoad curRoad = worldViewer.GetVisiblePointRoad(cSel, dir);
6✔
655
                    if(curRoad != PointRoad::None)
6✔
656
                    {
657
                        action_tabs.cutroad = true;
×
658
                        action_tabs.upgradeRoad |= (curRoad == PointRoad::Normal);
×
659
                    }
660
                }
661
            }
662
        }
663
        // evtl ists ein feindliches Militärgebäude, welches NICHT im Nebel liegt?
664
        else if(worldViewer.GetVisibility(cSel) == Visibility::Visible)
×
665
        {
666
            if(selObj.GetType() == NodalObjectType::Building)
×
667
            {
668
                const auto* building = worldViewer.GetWorld().GetSpecObj<noBuilding>(cSel); //-V807
×
669
                BuildingType bt = building->GetBuildingType();
×
670

671
                // Only if trade is enabled
672
                if(worldViewer.GetWorld().GetGGS().isEnabled(AddonId::TRADE))
×
673
                {
674
                    // Allied warehouse? -> Show trade window
675
                    if(BuildingProperties::IsWareHouse(bt) && worldViewer.GetPlayer().IsAlly(building->GetPlayer()))
×
676
                    {
677
                        WINDOWMANAGER.Show(std::make_unique<iwTrade>(*static_cast<const nobBaseWarehouse*>(building),
×
678
                                                                     worldViewer, GAMECLIENT));
×
679
                        return true;
×
680
                    }
681
                }
682

683
                // Ist es ein gewöhnliches Militärgebäude?
684
                if(BuildingProperties::IsMilitary(bt))
×
685
                {
686
                    // Dann darf es nicht neu gebaut sein!
687
                    if(!static_cast<const nobMilitary*>(building)->IsNewBuilt())
×
688
                        action_tabs.attack = true;
×
689
                }
690
                // oder ein HQ oder Hafen?
691
                else if(bt == BuildingType::Headquarters || bt == BuildingType::HarborBuilding)
×
692
                    action_tabs.attack = true;
×
693
                action_tabs.sea_attack =
×
694
                  action_tabs.attack && worldViewer.GetWorld().GetGGS().isEnabled(AddonId::SEA_ATTACK);
×
695
            }
696
        }
697

698
        // Bisheriges Actionfenster schließen, falls es eins gab
699
        // aktuelle Mausposition merken, da diese durch das Schließen verändert werden kann
700
        if(actionwindow)
1✔
701
            actionwindow->Close();
×
702
        VIDEODRIVER.SetMousePos(mc.pos);
1✔
703

704
        ShowActionWindow(action_tabs, cSel, mc.pos, enable_military_buildings);
1✔
705
    }
706

707
    return true;
2✔
708
}
709

710
bool dskGameInterface::Msg_LeftUp(const MouseCoords&)
2✔
711
{
712
    if(isScrolling)
2✔
713
    {
714
        StopScrolling();
1✔
715
        return true;
1✔
716
    }
717
    return false;
1✔
718
}
719

720
bool dskGameInterface::Msg_MouseMove(const MouseCoords& mc)
21✔
721
{
722
    if(!isScrolling)
21✔
723
        return false;
13✔
724

725
    int acceleration = SETTINGS.global.smartCursor ? 2 : 3;
8✔
726

727
    if(SETTINGS.interface.invertMouse)
8✔
728
        acceleration = -acceleration;
1✔
729

730
    gwv.MoveBy((mc.pos - startScrollPt) * acceleration);
8✔
731
    VIDEODRIVER.SetMousePos(startScrollPt);
8✔
732

733
    if(!SETTINGS.global.smartCursor)
8✔
734
        startScrollPt = mc.pos;
×
735
    return true;
8✔
736
}
737

738
bool dskGameInterface::Msg_RightDown(const MouseCoords& mc)
11✔
739
{
740
    StartScrolling(mc.pos);
11✔
741
    return true;
11✔
742
}
743

744
bool dskGameInterface::Msg_RightUp(const MouseCoords& /*mc*/) //-V524
3✔
745
{
746
    if(isScrolling)
3✔
747
        StopScrolling();
3✔
748
    return false;
3✔
749
}
750

751
bool dskGameInterface::Msg_KeyDown(const KeyEvent& ke)
15✔
752
{
753
    cheatCommandTracker_.onKeyEvent(ke);
15✔
754

755
    switch(ke.kt)
15✔
756
    {
757
        default: break;
15✔
NEW
758
        case KeyType::Return: // Open chat
×
759
            WINDOWMANAGER.Show(std::make_unique<iwChat>(this));
×
760
            return true;
×
761

NEW
762
        case KeyType::Space: // Show / hide construction aid
×
763
            gwv.ToggleShowBQ();
×
764
            return true;
×
765

NEW
766
        case KeyType::Left: // Scroll left
×
767
            gwv.MoveBy({-30, 0});
×
768
            return true;
×
NEW
769
        case KeyType::Right: // Scroll right
×
770
            gwv.MoveBy({30, 0});
×
771
            return true;
×
NEW
772
        case KeyType::Up: // Scroll up
×
773
            gwv.MoveBy({0, -30});
×
774
            return true;
×
NEW
775
        case KeyType::Down: // Scroll down
×
776
            gwv.MoveBy({0, 30});
×
777
            return true;
×
778

NEW
779
        case KeyType::F2: // Open save game window
×
780
            WINDOWMANAGER.ToggleWindow(std::make_unique<iwSave>());
×
781
            return true;
×
NEW
782
        case KeyType::F3: // Map debug window
×
783
        {
784
            const bool replayMode = GAMECLIENT.IsReplayModeOn();
×
785
            if(replayMode)
×
786
                DisableFoW(true);
×
787
            WINDOWMANAGER.ToggleWindow(std::make_unique<iwMapDebug>(gwv, game_->world_.IsSinglePlayer() || replayMode));
×
788
            return true;
×
789
        }
NEW
790
        case KeyType::F8:
×
791
            WINDOWMANAGER.ToggleWindow(std::make_unique<iwTextfile>("keyboardlayout.txt", _("Keyboard layout")));
×
792
            return true;
×
NEW
793
        case KeyType::F9:
×
794
            WINDOWMANAGER.ToggleWindow(std::make_unique<iwTextfile>("readme.txt", _("Readme!")));
×
795
            return true;
×
796
        case KeyType::F11: // Music player (midi files)
×
797
            WINDOWMANAGER.ToggleWindow(std::make_unique<iwMusicPlayer>());
×
798
            return true;
×
NEW
799
        case KeyType::F12: // Ingame options
×
800
            WINDOWMANAGER.ToggleWindow(std::make_unique<iwOptionsWindow>(gwv.GetSoundMgr()));
×
801
            return true;
×
802
    }
803

804
    switch(ke.c)
15✔
805
    {
806
        case '+':
×
807
            if(GAMECLIENT.IsReplayModeOn() || game_->world_.IsSinglePlayer())
×
808
                GAMECLIENT.IncreaseSpeed();
×
809
            return true;
×
810
        case '-':
×
811
            if(GAMECLIENT.IsReplayModeOn() || game_->world_.IsSinglePlayer())
×
812
                GAMECLIENT.DecreaseSpeed();
×
813
            return true;
×
814

815
        // Switch to specific player
UNCOV
816
        case '1':
×
817
        case '2':
818
        case '3':
819
        case '4':
820
        case '5':
821
        case '6':
822
        case '7':
823
        case '8':
824
        {
825
            unsigned playerIdx = ke.c - '1';
×
826
            if(GAMECLIENT.IsReplayModeOn())
×
827
            {
828
                unsigned oldPlayerId = worldViewer.GetPlayerId();
×
829
                GAMECLIENT.ChangePlayerIngame(worldViewer.GetPlayerId(), playerIdx);
×
830
                RTTR_Assert(worldViewer.GetPlayerId() == oldPlayerId || worldViewer.GetPlayerId() == playerIdx);
×
831
            } else if(playerIdx < worldViewer.GetWorld().GetNumPlayers())
×
832
            {
833
                // On multiplayer this currently asyncs, but as this is a debug feature anyway just disable it.
834
                // If this should be enabled again, look into the handling/clearing of accumulated GCs
835
                if(game_->world_.IsSinglePlayer())
×
836
                {
837
                    const GamePlayer& player = worldViewer.GetWorld().GetPlayer(playerIdx);
×
838
                    if(player.ps == PlayerState::AI && player.aiInfo.type == AI::Type::Dummy)
×
839
                        GAMECLIENT.RequestSwapToPlayer(playerIdx);
×
840
                }
841
            }
842
            return true;
×
843
        }
844

NEW
845
        case 'b': gwv.MoveToLastPosition(); return true;
×
846
        case 'v':
×
847
            if(game_->world_.IsSinglePlayer())
×
NEW
848
                GAMECLIENT.IncreaseSpeed(true);
×
849
            return true;
×
NEW
850
        case 'c': // Show/hide building names
×
851
            gwv.ToggleShowNames();
×
852
            return true;
×
NEW
853
        case 'd': // Enable/Disable fog of war (in replay mode)
×
854
            ToggleFoW();
×
855
            return true;
×
NEW
856
        case 'h': // Go to HQ
×
857
        {
858
            const GamePlayer& player = worldViewer.GetPlayer();
×
859
            // HQ might not exist anymore
860
            if(player.GetHQPos().isValid())
×
861
                gwv.MoveToMapPt(player.GetHQPos());
×
862
        }
863
            return true;
×
864
        case 'i': // Show inventory
×
865
            WINDOWMANAGER.ToggleWindow(std::make_unique<iwInventory>(worldViewer.GetPlayer()));
×
866
            return true;
×
NEW
867
        case 'j': // Skip GFs (fast forward)
×
868
            if(game_->world_.IsSinglePlayer() || GAMECLIENT.IsReplayModeOn())
×
869
                WINDOWMANAGER.ToggleWindow(std::make_unique<iwSkipGFs>(gwv));
×
870
            return true;
×
NEW
871
        case 'l': // Show minimap
×
872
            WINDOWMANAGER.ToggleWindow(std::make_unique<iwMinimap>(minimap, gwv));
×
873
            return true;
×
874
        case 'm': // Show main menu
2✔
875
            WINDOWMANAGER.ToggleWindow(std::make_unique<iwMainMenu>(gwv, GAMECLIENT));
2✔
876
            return true;
2✔
NEW
877
        case 'n': // Show message window
×
878
            WINDOWMANAGER.ToggleWindow(std::make_unique<iwPostWindow>(gwv, GetPostBox()));
×
879
            UpdatePostIcon(GetPostBox().GetNumMsgs(), false);
×
880
            return true;
×
881
        case 'p': // Pause
×
882
            GAMECLIENT.TogglePause();
×
883
            return true;
×
NEW
884
        case 'q': // Quit game (dialog)
×
885
            if(ke.alt)
×
886
                WINDOWMANAGER.ToggleWindow(std::make_unique<iwEndgame>());
×
887
            return true;
×
NEW
888
        case 's': // Show/hide productivity overlay
×
889
            gwv.ToggleShowProductivity();
×
890
            return true;
×
891
        case 26: // ctrl+z
×
892
            gwv.SetZoomFactor(ZOOM_FACTORS[ZOOM_DEFAULT_INDEX]);
×
893
            return true;
×
894
        case 'z':
9✔
895
            if(ke.ctrl) // Reset zoom
9✔
896
                gwv.SetZoomFactor(ZOOM_FACTORS[ZOOM_DEFAULT_INDEX]);
2✔
897
            else // zoom in
898
                gwv.SetZoomFactor(getNextZoomLevel(gwv.GetCurrentTargetZoomFactor()));
7✔
899
            return true;
9✔
900
        case 'Z': // shift-z, zoom out
4✔
901
            gwv.SetZoomFactor(getPreviousZoomLevel(gwv.GetCurrentTargetZoomFactor()));
4✔
902
            return true;
4✔
903
    }
904

905
    return false;
×
906
}
907

908
bool dskGameInterface::Msg_WheelUp(const MouseCoords&)
11✔
909
{
910
    WheelZoom(ZOOM_WHEEL_INCREMENT);
11✔
911
    return true;
11✔
912
}
913
bool dskGameInterface::Msg_WheelDown(const MouseCoords&)
12✔
914
{
915
    WheelZoom(-ZOOM_WHEEL_INCREMENT);
12✔
916
    return true;
12✔
917
}
918

919
void dskGameInterface::WheelZoom(const float step)
23✔
920
{
921
    auto targetZoomFactor = gwv.GetCurrentTargetZoomFactor() * (1 + step);
23✔
922
    targetZoomFactor = std::clamp(targetZoomFactor, ZOOM_FACTORS.front(), ZOOM_FACTORS.back());
23✔
923
    if(targetZoomFactor > 1 - ZOOM_WHEEL_INCREMENT && targetZoomFactor < 1 + ZOOM_WHEEL_INCREMENT)
23✔
924
        targetZoomFactor = 1.f; // Snap to 100%
2✔
925

926
    gwv.SetZoomFactor(targetZoomFactor);
23✔
927
}
23✔
928

929
void dskGameInterface::OnBuildingNote(const BuildingNote& note)
×
930
{
931
    switch(note.type)
×
932
    {
933
        case BuildingNote::Constructed:
×
934
        case BuildingNote::Destroyed:
935
        case BuildingNote::Lost:
936
            // Close the related window as the building does not exist anymore
937
            // In "Constructed" this means the buildingsite
938
            WINDOWMANAGER.Close(CGI_BUILDING + MapBase::CreateGUIID(note.pos));
×
939
            break;
×
940
        default: break;
×
941
    }
942
}
×
943

944
void dskGameInterface::Run()
×
945
{
946
    // Reset draw counter of the trees before drawing
947
    noTree::ResetDrawCounter();
×
948

949
    unsigned water_percent;
950
    // Draw mouse only if not on window
951
    bool drawMouse = WINDOWMANAGER.FindWindowAtPos(VIDEODRIVER.GetMousePos()) == nullptr;
×
952
    gwv.Draw(road, actionwindow != nullptr ? actionwindow->GetSelectedPt() : MapPoint::Invalid(), drawMouse,
×
953
             &water_percent);
954

955
    // Indicate that the game is paused by darkening the screen (dark semi-transparent overlay)
956
    if(GAMECLIENT.IsPaused())
×
957
        DrawRectangle(Rect(DrawPoint(0, 0), VIDEODRIVER.GetRenderSize()), COLOR_SHADOW);
×
958
    else
959
    {
960
        // Play ambient sounds if game is not paused
961
        worldViewer.GetSoundMgr().playOceanBrawling(water_percent);
×
962
        worldViewer.GetSoundMgr().playBirdSounds(noTree::QueryDrawCounter());
×
963
    }
964

965
    messenger.Draw();
×
966
}
×
967

968
void dskGameInterface::GI_StartRoadBuilding(const MapPoint startPt, bool waterRoad)
3✔
969
{
970
    // Im Replay keine Straßen bauen
971
    if(GAMECLIENT.IsReplayModeOn())
3✔
972
        return;
×
973

974
    road.mode = waterRoad ? RoadBuildMode::Boat : RoadBuildMode::Normal;
3✔
975
    road.route.clear();
3✔
976
    road.start = road.point = startPt;
3✔
977
    WINDOWMANAGER.SetCursor(Cursor::Remove);
3✔
978
}
979

980
void dskGameInterface::GI_CancelRoadBuilding()
2✔
981
{
982
    if(road.mode == RoadBuildMode::Disabled)
2✔
983
        return;
×
984
    road.mode = RoadBuildMode::Disabled;
2✔
985
    worldViewer.RemoveVisualRoad(road.start, road.route);
2✔
986
    WINDOWMANAGER.SetCursor(isScrolling ? Cursor::Scroll : Cursor::Hand);
2✔
987
}
988

989
bool dskGameInterface::BuildRoadPart(MapPoint& cSel)
3✔
990
{
991
    std::vector<Direction> new_route =
992
      FindPathForRoad(worldViewer, road.point, cSel, road.mode == RoadBuildMode::Boat, 100);
6✔
993
    // Weg gefunden?
994
    if(new_route.empty())
3✔
995
        return false;
×
996

997
    // Test on water way length
998
    if(road.mode == RoadBuildMode::Boat)
3✔
999
    {
1000
        unsigned char index = worldViewer.GetWorld().GetGGS().getSelection(AddonId::MAX_WATERWAY_LENGTH);
×
1001

1002
        RTTR_Assert(index < waterwayLengths.size());
×
1003
        const unsigned max_length = waterwayLengths[index];
×
1004

1005
        unsigned length = road.route.size() + new_route.size();
×
1006

1007
        // max_length == 0 heißt beliebig lang, ansonsten
1008
        // Weg zurechtstutzen.
1009
        if(max_length > 0)
×
1010
        {
1011
            while(length > max_length)
×
1012
            {
1013
                new_route.pop_back();
×
1014
                --length;
×
1015
            }
1016
        }
1017
    }
1018

1019
    // Weg (visuell) bauen
1020
    for(const auto dir : new_route)
22✔
1021
    {
1022
        worldViewer.SetVisiblePointRoad(road.point, dir,
19✔
1023
                                        (road.mode == RoadBuildMode::Boat) ? PointRoad::Boat : PointRoad::Normal);
19✔
1024
        worldViewer.RecalcBQForRoad(road.point);
19✔
1025
        road.point = worldViewer.GetWorld().GetNeighbour(road.point, dir);
19✔
1026
    }
1027
    worldViewer.RecalcBQForRoad(road.point);
3✔
1028

1029
    // Zielpunkt updaten (für Wasserweg)
1030
    cSel = road.point;
3✔
1031

1032
    road.route.insert(road.route.end(), new_route.begin(), new_route.end());
3✔
1033

1034
    return true;
3✔
1035
}
1036

1037
unsigned dskGameInterface::GetIdInCurBuildRoad(const MapPoint pt)
1✔
1038
{
1039
    MapPoint curPt = road.start;
1✔
1040
    for(unsigned i = 0; i < road.route.size(); ++i)
2✔
1041
    {
1042
        if(curPt == pt)
2✔
1043
            return i + 1;
1✔
1044

1045
        curPt = worldViewer.GetNeighbour(curPt, road.route[i]);
1✔
1046
    }
1047
    return 0;
×
1048
}
1049

1050
void dskGameInterface::ShowRoadWindow(const Position& mousePos)
×
1051
{
1052
    roadwindow = &WINDOWMANAGER.Show(
×
1053
      std::make_unique<iwRoadWindow>(*this, worldViewer.GetBQ(road.point) != BuildingQuality::Nothing, mousePos), true);
×
1054
}
×
1055

1056
void dskGameInterface::ShowActionWindow(const iwAction::Tabs& action_tabs, MapPoint cSel, const DrawPoint& mousePos,
2✔
1057
                                        const bool enable_military_buildings)
1058
{
1059
    const GameWorldBase& world = worldViewer.GetWorld();
2✔
1060

1061
    iwAction::Params params;
2✔
1062

1063
    // Sind wir am Wasser?
1064
    if(action_tabs.setflag)
2✔
1065
    {
1066
        auto isWater = [](const auto& desc) { return desc.kind == TerrainKind::Water; };
6✔
1067
        if(world.HasTerrain(cSel, isWater))
1✔
1068
            params = iwAction::FlagType::WaterFlag;
×
1069
    }
1070

1071
    // Wenn es einen Flaggen-Tab gibt, dann den Flaggentyp herausfinden und die Art des Fensters entsprechende setzen
1072
    if(action_tabs.flag)
2✔
1073
    {
1074
        if(world.GetNO(world.GetNeighbour(cSel, Direction::NorthWest))->GetGOT() == GO_Type::NobHq)
×
1075
            params = iwAction::FlagType::HQ;
×
1076
        else if(world.GetNO(cSel)->GetType() == NodalObjectType::Flag)
×
1077
        {
1078
            if(world.GetSpecObj<noFlag>(cSel)->GetFlagType() == FlagType::Water)
×
1079
                params = iwAction::FlagType::WaterFlag;
×
1080
        }
1081
    }
1082

1083
    // Angriffstab muss wissen, wieviel Soldaten maximal entsendet werden können
1084
    if(action_tabs.attack)
2✔
1085
    {
1086
        params = worldViewer.GetNumSoldiersForAttack(cSel);
×
1087
    }
1088

1089
    actionwindow = &WINDOWMANAGER.Show(
2✔
1090
      std::make_unique<iwAction>(*this, gwv, action_tabs, cSel, mousePos, params, enable_military_buildings), true);
2✔
1091
}
2✔
1092

1093
void dskGameInterface::OnChatCommand(const std::string& cmd)
×
1094
{
1095
    cheatCommandTracker_.onChatCommand(cmd);
×
1096

1097
    if(cmd == "surrender")
×
1098
        GAMECLIENT.Surrender();
×
1099
    else if(cmd == "async")
×
1100
        (void)RANDOM.Rand(RANDOM_CONTEXT2(0), 255);
×
1101
    else if(cmd == "segfault")
×
1102
    {
1103
        char* x = nullptr;
×
1104
        *x = 1; //-V522 // NOLINT
×
1105
    } else if(cmd == "reload")
×
1106
    {
1107
        WorldDescription newDesc;
×
1108
        GameDataLoader gdLoader(newDesc);
×
1109
        if(gdLoader.Load())
×
1110
        {
1111
            const_cast<GameWorld&>(game_->world_).GetDescriptionWriteable() = newDesc;
×
1112
            worldViewer.InitTerrainRenderer();
×
1113
        }
1114
    }
1115
}
×
1116

1117
void dskGameInterface::GI_BuildRoad()
×
1118
{
1119
    if(GAMECLIENT.BuildRoad(road.start, road.mode == RoadBuildMode::Boat, road.route))
×
1120
    {
1121
        road.mode = RoadBuildMode::Disabled;
×
1122
        WINDOWMANAGER.SetCursor(Cursor::Hand);
×
1123
    }
1124
}
×
1125

1126
void dskGameInterface::Msg_WindowClosed(IngameWindow& wnd)
2✔
1127
{
1128
    if(actionwindow == &wnd)
2✔
1129
        actionwindow = nullptr;
1✔
1130
    else if(roadwindow == &wnd)
1✔
1131
        roadwindow = nullptr;
×
1132
}
2✔
1133

1134
void dskGameInterface::GI_FlagDestroyed(const MapPoint pt)
×
1135
{
1136
    // Im Wegbaumodus und haben wir von hier eine Flagge gebaut?
1137
    if(road.mode != RoadBuildMode::Disabled && road.start == pt)
×
1138
    {
1139
        GI_CancelRoadBuilding();
×
1140
    }
1141

1142
    // Evtl Actionfenster schließen, da sich das ja auch auf diese Flagge bezieht
1143
    if(actionwindow)
×
1144
    {
1145
        if(actionwindow->GetSelectedPt() == pt)
×
1146
            actionwindow->Close();
×
1147
    }
1148
}
×
1149

1150
void dskGameInterface::CI_PlayerLeft(const unsigned playerId)
×
1151
{
1152
    // Info-Meldung ausgeben
1153
    std::string text =
1154
      helpers::format(_("Player '%s' left the game!"), worldViewer.GetWorld().GetPlayer(playerId).name);
×
1155
    messenger.AddMessage("", 0, ChatDestination::System, text, COLOR_RED);
×
1156
    // Im Spiel anzeigen, dass die KI das Spiel betreten hat
1157
    text = helpers::format(_("Player '%s' joined the game!"), "KI");
×
1158
    messenger.AddMessage("", 0, ChatDestination::System, text, COLOR_GREEN);
×
1159
}
×
1160

1161
void dskGameInterface::CI_GGSChanged(const GlobalGameSettings& /*ggs*/)
×
1162
{
1163
    // TODO: print what has changed
1164
    const std::string text = helpers::format(_("Note: Game settings changed by the server%s"), "");
×
1165
    messenger.AddMessage("", 0, ChatDestination::System, text);
×
1166
}
×
1167

1168
void dskGameInterface::CI_Chat(const unsigned playerId, const ChatDestination cd, const std::string& msg)
×
1169
{
1170
    messenger.AddMessage(worldViewer.GetWorld().GetPlayer(playerId).name,
×
1171
                         worldViewer.GetWorld().GetPlayer(playerId).color, cd, msg);
×
1172
}
×
1173

1174
void dskGameInterface::CI_Async(const std::string& checksums_list)
×
1175
{
1176
    messenger.AddMessage("", 0, ChatDestination::System,
×
1177
                         _("The Game is not in sync. Checksums of some players don't match."), COLOR_RED);
1178
    messenger.AddMessage("", 0, ChatDestination::System, checksums_list, COLOR_YELLOW);
×
1179
    messenger.AddMessage("", 0, ChatDestination::System, _("A auto-savegame is created..."), COLOR_RED);
×
1180
}
×
1181

1182
void dskGameInterface::CI_ReplayAsync(const std::string& msg)
×
1183
{
1184
    messenger.AddMessage("", 0, ChatDestination::System, msg, COLOR_RED);
×
1185
}
×
1186

1187
void dskGameInterface::CI_ReplayEndReached(const std::string& msg)
×
1188
{
1189
    messenger.AddMessage("", 0, ChatDestination::System, msg, COLOR_BLUE);
×
1190
}
×
1191

1192
void dskGameInterface::CI_GamePaused()
×
1193
{
1194
    messenger.AddMessage(_("SYSTEM"), COLOR_GREY, ChatDestination::System, _("Game was paused."));
×
1195
}
×
1196

1197
void dskGameInterface::CI_GameResumed()
×
1198
{
1199
    messenger.AddMessage(_("SYSTEM"), COLOR_GREY, ChatDestination::System, _("Game was resumed."));
×
1200
}
×
1201

1202
void dskGameInterface::CI_Error(const ClientError ce)
×
1203
{
1204
    messenger.AddMessage("", 0, ChatDestination::System, ClientErrorToStr(ce), COLOR_RED);
×
1205
    GAMECLIENT.SetPause(true);
×
1206
}
×
1207

1208
/**
1209
 *  Status: Verbindung verloren.
1210
 */
1211
void dskGameInterface::LC_Status_ConnectionLost()
×
1212
{
1213
    messenger.AddMessage("", 0, ChatDestination::System, _("Lost connection to lobby!"), COLOR_RED);
×
1214
}
×
1215

1216
/**
1217
 *  (Lobby-)Status: Benutzerdefinierter Fehler
1218
 */
1219
void dskGameInterface::LC_Status_Error(const std::string& error)
×
1220
{
1221
    messenger.AddMessage("", 0, ChatDestination::System, error, COLOR_RED);
×
1222
}
×
1223

1224
void dskGameInterface::CI_PlayersSwapped(const unsigned player1, const unsigned player2)
×
1225
{
1226
    // Meldung anzeigen
1227
    std::string text = "Player '" + worldViewer.GetWorld().GetPlayer(player1).name + "' switched to player '"
×
1228
                       + worldViewer.GetWorld().GetPlayer(player2).name + "'";
×
1229
    messenger.AddMessage("", 0, ChatDestination::System, text, COLOR_YELLOW);
×
1230

1231
    // Sichtbarkeiten und Minimap neu berechnen, wenn wir ein von den beiden Spielern sind
1232
    const unsigned localPlayerId = worldViewer.GetPlayerId();
×
1233
    if(player1 == localPlayerId || player2 == localPlayerId)
×
1234
    {
1235
        worldViewer.ChangePlayer(player1 == localPlayerId ? player2 : player1);
×
1236
        // Set visual settings back to the actual ones
1237
        GAMECLIENT.ResetVisualSettings();
×
1238
        minimap.UpdateAll();
×
1239
        InitPlayer();
×
1240
    }
1241
}
×
1242

1243
/**
1244
 *  Wenn ein Spieler verloren hat
1245
 */
1246
void dskGameInterface::GI_PlayerDefeated(const unsigned playerId)
×
1247
{
1248
    const std::string text =
1249
      helpers::format(_("Player '%s' was defeated!"), worldViewer.GetWorld().GetPlayer(playerId).name);
×
1250
    messenger.AddMessage("", 0, ChatDestination::System, text, COLOR_ORANGE);
×
1251

1252
    /// Lokaler Spieler?
1253
    if(playerId == worldViewer.GetPlayerId())
×
1254
    {
1255
        /// Sichtbarkeiten neu berechnen
1256
        worldViewer.RecalcAllColors();
×
1257
        // Minimap updaten
1258
        minimap.UpdateAll();
×
1259
    }
1260
}
×
1261

1262
void dskGameInterface::GI_UpdateMinimap(const MapPoint pt)
×
1263
{
1264
    // Minimap Bescheid sagen
1265
    minimap.UpdateNode(pt);
×
1266
}
×
1267

1268
void dskGameInterface::GI_UpdateMapVisibility()
×
1269
{
1270
    // recalculate visibility
1271
    worldViewer.RecalcAllColors();
×
1272
    // update minimap
1273
    minimap.UpdateAll();
×
1274
}
×
1275

1276
/**
1277
 *  Bündnisvertrag wurde abgeschlossen oder abgebrochen --> Minimap updaten
1278
 */
1279
void dskGameInterface::GI_TreatyOfAllianceChanged(unsigned playerId)
×
1280
{
1281
    // Nur wenn Team-Sicht aktiviert ist, können sihc die Sichtbarkeiten auch ändern
1282
    if(playerId == worldViewer.GetPlayerId() && worldViewer.GetWorld().GetGGS().teamView)
×
1283
    {
1284
        /// Sichtbarkeiten neu berechnen
1285
        worldViewer.RecalcAllColors();
×
1286
        // Minimap updaten
1287
        minimap.UpdateAll();
×
1288
    }
1289
}
×
1290

1291
/**
1292
 *  Baut Weg zurück von Ende bis zu start_id
1293
 */
1294
void dskGameInterface::DemolishRoad(const unsigned start_id)
1✔
1295
{
1296
    RTTR_Assert(start_id > 0);
1✔
1297
    for(unsigned i = road.route.size(); i >= start_id; --i)
6✔
1298
    {
1299
        MapPoint t = road.point;
5✔
1300
        road.point = worldViewer.GetWorld().GetNeighbour(road.point, road.route[i - 1] + 3u);
5✔
1301
        worldViewer.SetVisiblePointRoad(road.point, road.route[i - 1], PointRoad::None);
5✔
1302
        worldViewer.RecalcBQForRoad(t);
5✔
1303
    }
1304

1305
    road.route.resize(start_id - 1);
1✔
1306
}
1✔
1307

1308
/**
1309
 *  Updatet das Post-Icon mit der Nachrichtenanzahl und der Taube
1310
 */
1311
void dskGameInterface::UpdatePostIcon(const unsigned postmessages_count, bool showPigeon)
6✔
1312
{
1313
    // Taube setzen oder nicht (Post)
1314
    if(postmessages_count == 0 || !showPigeon)
6✔
1315
        GetCtrl<ctrlImageButton>(3)->SetImage(LOADER.GetImageN("io", 62));
12✔
1316
    else
1317
        GetCtrl<ctrlImageButton>(3)->SetImage(LOADER.GetImageN("io", 59));
×
1318

1319
    // und Anzahl der Postnachrichten aktualisieren
1320
    if(postmessages_count > 0)
6✔
1321
    {
1322
        GetCtrl<ctrlText>(ID_txtNumMsg)->SetText(std::to_string(postmessages_count));
×
1323
    } else
1324
        GetCtrl<ctrlText>(ID_txtNumMsg)->SetText("");
6✔
1325
}
6✔
1326

1327
/**
1328
 *  Neue Post-Nachricht eingetroffen
1329
 */
1330
void dskGameInterface::NewPostMessage(const PostMsg& msg, const unsigned msgCt)
×
1331
{
1332
    UpdatePostIcon(msgCt, true);
×
1333
    SoundEffect soundEffect = msg.GetSoundEffect();
×
1334
    switch(soundEffect)
×
1335
    {
1336
        case SoundEffect::Pidgeon: LOADER.GetSoundN("sound", 114)->Play(100, false); break;
×
1337
        case SoundEffect::Fanfare: LOADER.GetSoundN("sound", 110)->Play(100, false);
×
1338
    }
1339
}
×
1340

1341
/**
1342
 *  Es wurde eine Postnachricht vom Spieler gelöscht
1343
 */
1344
void dskGameInterface::PostMessageDeleted(const unsigned msgCt)
×
1345
{
1346
    UpdatePostIcon(msgCt, false);
×
1347
}
×
1348

1349
/**
1350
 *  Ein Spieler hat das Spiel gewonnen.
1351
 */
1352
void dskGameInterface::GI_Winner(const unsigned playerId)
×
1353
{
1354
    const std::string name = worldViewer.GetWorld().GetPlayer(playerId).name;
×
1355
    const std::string text = (boost::format(_("Player '%s' is the winner!")) % name).str();
×
1356
    messenger.AddMessage("", 0, ChatDestination::System, text, COLOR_ORANGE);
×
1357
    WINDOWMANAGER.Show(std::make_unique<iwVictory>(std::vector<std::string>(1, name)));
×
1358
}
×
1359

1360
/**
1361
 *  Ein Team hat das Spiel gewonnen.
1362
 */
1363
void dskGameInterface::GI_TeamWinner(const unsigned playerMask)
×
1364
{
1365
    std::vector<std::string> winners;
×
1366
    const GameWorldBase& world = worldViewer.GetWorld();
×
1367
    for(unsigned i = 0; i < world.GetNumPlayers(); i++)
×
1368
    {
1369
        if(playerMask & (1 << i))
×
1370
            winners.push_back(world.GetPlayer(i).name);
×
1371
    }
1372
    const std::string text =
1373
      (boost::format(_("%1% are the winners!")) % helpers::join(winners, ", ", _(" and "))).str();
×
1374
    messenger.AddMessage("", 0, ChatDestination::System, text, COLOR_ORANGE);
×
1375
    WINDOWMANAGER.Show(std::make_unique<iwVictory>(winners));
×
1376
}
×
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