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

Return-To-The-Roots / s25client / 19550882615

20 Nov 2025 08:47PM UTC coverage: 50.483% (+0.01%) from 50.469%
19550882615

push

github

web-flow
Merge pull request #1829 from Flamefire/speed

Make all game speeds available to "v" key

13 of 35 new or added lines in 7 files covered. (37.14%)

4 existing lines in 1 file now uncovered.

22515 of 44599 relevant lines covered (50.48%)

35056.13 hits per line

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

31.13
/libs/s25main/desktops/dskGameInterface.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 "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

102
dskGameInterface::dskGameInterface(std::shared_ptr<Game> game, std::shared_ptr<const NWFInfo> nwfInfo,
5✔
103
                                   unsigned playerIdx, bool initOGL)
5✔
104
    : Desktop(nullptr), game_(std::move(game)), nwfInfo_(std::move(nwfInfo)),
10✔
105
      worldViewer(playerIdx, const_cast<Game&>(*game_).world_),
5✔
106
      gwv(worldViewer, Position(0, 0), VIDEODRIVER.GetRenderSize()), cbb(*LOADER.GetPaletteN("pal5")),
15✔
107
      actionwindow(nullptr), roadwindow(nullptr), minimap(worldViewer), isScrolling(false), zoomLvl(ZOOM_DEFAULT_INDEX),
5✔
108
      cheats_(const_cast<Game&>(*game_).world_), cheatCommandTracker_(cheats_)
15✔
109
{
110
    road.mode = RoadBuildMode::Disabled;
5✔
111
    road.point = MapPoint(0, 0);
5✔
112
    road.start = MapPoint(0, 0);
5✔
113

114
    SetScale(false);
5✔
115

116
    DrawPoint barPos((GetSize().x - LOADER.GetImageN("resource", 29)->getWidth()) / 2 + 44,
10✔
117
                     GetSize().y - LOADER.GetImageN("resource", 29)->getHeight() + 4);
15✔
118

119
    Extent btSize = Extent(37, 32);
5✔
120
    AddImageButton(ID_btMap, barPos, btSize, TextureColor::Green1, LOADER.GetImageN("io", 50), _("Map"))
5✔
121
      ->SetBorder(false);
10✔
122
    barPos.x += btSize.x;
5✔
123
    AddImageButton(ID_btOptions, barPos, btSize, TextureColor::Green1, LOADER.GetImageN("io", 192), _("Main selection"))
5✔
124
      ->SetBorder(false);
10✔
125
    barPos.x += btSize.x;
5✔
126
    AddImageButton(ID_btConstructionAid, barPos, btSize, TextureColor::Green1, LOADER.GetImageN("io", 83),
5✔
127
                   _("Construction aid mode"))
128
      ->SetBorder(false);
10✔
129
    barPos.x += btSize.x;
5✔
130
    AddImageButton(ID_btPost, barPos, btSize, TextureColor::Green1, LOADER.GetImageN("io", 62), _("Post office"))
5✔
131
      ->SetBorder(false);
10✔
132
    barPos += DrawPoint(18, 24);
5✔
133

134
    AddText(ID_txtNumMsg, barPos, "", COLOR_YELLOW, FontStyle::CENTER | FontStyle::VCENTER, SmallFont);
5✔
135

136
    const_cast<Game&>(*game_).world_.SetGameInterface(this);
5✔
137

138
    std::fill(borders.begin(), borders.end(), (glArchivItem_Bitmap*)(nullptr));
5✔
139
    cbb.loadEdges(LOADER.GetArchive("resource"));
10✔
140
    cbb.buildBorder(VIDEODRIVER.GetRenderSize(), borders);
5✔
141

142
    InitPlayer();
5✔
143
    if(initOGL)
5✔
144
        worldViewer.InitTerrainRenderer();
×
145

146
    VIDEODRIVER.setTargetFramerate(SETTINGS.video.framerate); // Use requested setting for ingame
5✔
147
}
5✔
148

149
void dskGameInterface::InitPlayer()
5✔
150
{
151
    // Jump to players HQ if it exists
152
    if(worldViewer.GetPlayer().GetHQPos().isValid())
5✔
153
        gwv.MoveToMapPt(worldViewer.GetPlayer().GetHQPos());
5✔
154

155
    evBld = worldViewer.GetWorld().GetNotifications().subscribe<BuildingNote>([this](const auto& note) {
10✔
156
        if(note.player == worldViewer.GetPlayerId())
×
157
            this->OnBuildingNote(note);
×
158
    });
5✔
159
    PostBox& postBox = GetPostBox();
5✔
160
    postBox.ObserveNewMsg([this](const auto& msg, auto msgCt) { this->NewPostMessage(msg, msgCt); });
5✔
161
    postBox.ObserveDeletedMsg([this](auto msgCt) { this->PostMessageDeleted(msgCt); });
5✔
162
    UpdatePostIcon(postBox.GetNumMsgs(), true);
5✔
163
}
5✔
164

165
PostBox& dskGameInterface::GetPostBox()
5✔
166
{
167
    PostBox* postBox = worldViewer.GetWorld().GetPostMgr().GetPostBox(worldViewer.GetPlayerId());
5✔
168
    if(!postBox)
5✔
169
        postBox = &worldViewer.GetWorldNonConst().GetPostMgr().AddPostBox(worldViewer.GetPlayerId());
5✔
170
    RTTR_Assert(postBox != nullptr);
5✔
171
    return *postBox;
5✔
172
}
173

174
dskGameInterface::~dskGameInterface()
5✔
175
{
176
    for(auto& border : borders)
25✔
177
        deletePtr(border);
20✔
178
    GAMECLIENT.RemoveInterface(this);
5✔
179
    LOBBYCLIENT.RemoveListener(this);
5✔
180
}
5✔
181

182
void dskGameInterface::SetActive(bool activate)
17✔
183
{
184
    if(activate == IsActive())
17✔
185
        return;
9✔
186
    if(!activate && isScrolling)
8✔
187
    {
188
        // Stay active if scrolling and no modal window is open
189
        const IngameWindow* wnd = WINDOWMANAGER.GetTopMostWindow();
1✔
190
        if(wnd && wnd->IsModal())
1✔
191
            StopScrolling();
×
192
        else
193
            return;
1✔
194
    }
195
    Desktop::SetActive(activate);
7✔
196
    // Do this here to allow previous screen to keep control
197
    if(activate)
7✔
198
    {
199
        GAMECLIENT.SetInterface(this);
5✔
200
        LOBBYCLIENT.AddListener(this);
5✔
201
        if(!game_->IsStarted())
5✔
202
        {
203
            GAMECLIENT.OnGameStart();
5✔
204

205
            ShowPersistentWindowsAfterSwitch();
5✔
206
        }
207
    }
208
}
209

210
void dskGameInterface::StopScrolling()
6✔
211
{
212
    isScrolling = false;
6✔
213
    WINDOWMANAGER.SetCursor(road.mode == RoadBuildMode::Disabled ? Cursor::Hand : Cursor::Remove);
6✔
214
}
6✔
215

216
void dskGameInterface::StartScrolling(const Position& mousePos)
11✔
217
{
218
    startScrollPt = mousePos;
11✔
219
    isScrolling = true;
11✔
220
    WINDOWMANAGER.SetCursor(Cursor::Scroll);
11✔
221
}
11✔
222

223
void dskGameInterface::ToggleFoW()
×
224
{
225
    DisableFoW(!GAMECLIENT.IsReplayFOWDisabled());
×
226
}
×
227

228
void dskGameInterface::DisableFoW(const bool hideFOW)
×
229
{
230
    GAMECLIENT.SetReplayFOW(hideFOW);
×
231
    // Notify viewer and minimap to recalculate the visibility
232
    worldViewer.RecalcAllColors();
×
233
    minimap.UpdateAll();
×
234
}
×
235

236
void dskGameInterface::ShowPersistentWindowsAfterSwitch()
5✔
237
{
238
    auto& windows = SETTINGS.windows.persistentSettings;
5✔
239

240
    if(windows[CGI_CHAT].isOpen)
5✔
241
        WINDOWMANAGER.ShowAfterSwitch(std::make_unique<iwChat>(this));
×
242
    if(windows[CGI_POSTOFFICE].isOpen)
5✔
243
        WINDOWMANAGER.ShowAfterSwitch(std::make_unique<iwPostWindow>(gwv, GetPostBox()));
×
244
    if(windows[CGI_DISTRIBUTION].isOpen)
5✔
245
        WINDOWMANAGER.ShowAfterSwitch(std::make_unique<iwDistribution>(gwv.GetViewer(), GAMECLIENT));
×
246
    if(windows[CGI_BUILDORDER].isOpen && gwv.GetWorld().GetGGS().isEnabled(AddonId::CUSTOM_BUILD_SEQUENCE))
5✔
247
        WINDOWMANAGER.ShowAfterSwitch(std::make_unique<iwBuildOrder>(gwv.GetViewer()));
×
248
    if(windows[CGI_TRANSPORT].isOpen)
5✔
249
        WINDOWMANAGER.ShowAfterSwitch(std::make_unique<iwTransport>(gwv.GetViewer(), GAMECLIENT));
×
250
    if(windows[CGI_MILITARY].isOpen)
5✔
251
        WINDOWMANAGER.ShowAfterSwitch(std::make_unique<iwMilitary>(gwv.GetViewer(), GAMECLIENT));
×
252
    if(windows[CGI_TOOLS].isOpen)
5✔
253
        WINDOWMANAGER.ShowAfterSwitch(std::make_unique<iwTools>(gwv.GetViewer(), GAMECLIENT));
×
254
    if(windows[CGI_INVENTORY].isOpen)
5✔
255
        WINDOWMANAGER.ShowAfterSwitch(std::make_unique<iwInventory>(gwv.GetViewer().GetPlayer()));
×
256
    if(windows[CGI_MINIMAP].isOpen)
5✔
257
        WINDOWMANAGER.ShowAfterSwitch(std::make_unique<iwMinimap>(minimap, gwv));
×
258
    if(windows[CGI_BUILDINGS].isOpen)
5✔
259
        WINDOWMANAGER.ShowAfterSwitch(std::make_unique<iwBuildings>(gwv, GAMECLIENT));
×
260
    if(windows[CGI_BUILDINGSPRODUCTIVITY].isOpen)
5✔
261
        WINDOWMANAGER.ShowAfterSwitch(std::make_unique<iwBuildingProductivities>(gwv.GetViewer().GetPlayer()));
×
262
    if(windows[CGI_MUSICPLAYER].isOpen)
5✔
263
        WINDOWMANAGER.ShowAfterSwitch(std::make_unique<iwMusicPlayer>());
×
264
    if(windows[CGI_STATISTICS].isOpen)
5✔
265
        WINDOWMANAGER.ShowAfterSwitch(std::make_unique<iwStatistics>(gwv.GetViewer()));
×
266
    if(windows[CGI_ECONOMICPROGRESS].isOpen && gwv.GetWorld().getEconHandler())
5✔
267
        WINDOWMANAGER.ShowAfterSwitch(std::make_unique<iwEconomicProgress>(gwv.GetViewer()));
×
268
    if(windows[CGI_DIPLOMACY].isOpen)
5✔
269
        WINDOWMANAGER.ShowAfterSwitch(std::make_unique<iwDiplomacy>(gwv.GetViewer(), GAMECLIENT));
×
270
    if(windows[CGI_SHIP].isOpen)
5✔
271
        WINDOWMANAGER.ShowAfterSwitch(
×
272
          std::make_unique<iwShip>(gwv, GAMECLIENT, gwv.GetViewer().GetPlayer().GetShipByID(0)));
×
273
    if(windows[CGI_MERCHANDISE_STATISTICS].isOpen)
5✔
274
        WINDOWMANAGER.ShowAfterSwitch(std::make_unique<iwMerchandiseStatistics>(gwv.GetViewer().GetPlayer()));
×
275
}
5✔
276

277
void dskGameInterface::Resize(const Extent& newSize)
×
278
{
279
    Window::Resize(newSize);
×
280

281
    // recreate borders
282
    for(auto& border : borders)
×
283
        deletePtr(border);
×
284
    cbb.buildBorder(newSize, borders);
×
285

286
    // move buttons
287
    DrawPoint barPos((newSize.x - LOADER.GetImageN("resource", 29)->getWidth()) / 2 + 44,
×
288
                     newSize.y - LOADER.GetImageN("resource", 29)->getHeight() + 4);
×
289

290
    auto* button = GetCtrl<ctrlButton>(ID_btMap);
×
291
    button->SetPos(barPos);
×
292

293
    barPos.x += button->GetSize().x;
×
294
    button = GetCtrl<ctrlButton>(ID_btOptions);
×
295
    button->SetPos(barPos);
×
296

297
    barPos.x += button->GetSize().x;
×
298
    button = GetCtrl<ctrlButton>(ID_btConstructionAid);
×
299
    button->SetPos(barPos);
×
300

301
    barPos.x += button->GetSize().x;
×
302
    button = GetCtrl<ctrlButton>(ID_btPost);
×
303
    button->SetPos(barPos);
×
304

305
    barPos += DrawPoint(18, 24);
×
306
    auto* text = GetCtrl<ctrlText>(ID_txtNumMsg);
×
307
    text->SetPos(barPos);
×
308

309
    gwv.Resize(newSize);
×
310
}
×
311

312
void dskGameInterface::Msg_ButtonClick(const unsigned ctrl_id)
×
313
{
314
    switch(ctrl_id)
×
315
    {
316
        case ID_btMap: WINDOWMANAGER.ToggleWindow(std::make_unique<iwMinimap>(minimap, gwv)); break;
×
317
        case ID_btOptions: WINDOWMANAGER.ToggleWindow(std::make_unique<iwMainMenu>(gwv, GAMECLIENT)); break;
×
318
        case ID_btConstructionAid:
×
319
            if(WINDOWMANAGER.IsDesktopActive())
×
320
                gwv.ToggleShowBQ();
×
321
            break;
×
322
        case ID_btPost:
×
323
            WINDOWMANAGER.ToggleWindow(std::make_unique<iwPostWindow>(gwv, GetPostBox()));
×
324
            UpdatePostIcon(GetPostBox().GetNumMsgs(), false);
×
325
            break;
×
326
    }
327
}
×
328

329
void dskGameInterface::Msg_PaintBefore()
×
330
{
331
    Desktop::Msg_PaintBefore();
×
332

333
    // Spiel ausführen
334
    Run();
×
335

336
    /// Padding of the figures
337
    const DrawPoint figPadding(12, 12);
×
338
    const DrawPoint screenSize(VIDEODRIVER.GetRenderSize());
×
339
    // Rahmen zeichnen
340
    borders[0]->DrawFull(DrawPoint(0, 0));                                      // oben (mit Ecken)
×
341
    borders[1]->DrawFull(DrawPoint(0, screenSize.y - figPadding.y));            // unten (mit Ecken)
×
342
    borders[2]->DrawFull(DrawPoint(0, figPadding.y));                           // links
×
343
    borders[3]->DrawFull(DrawPoint(screenSize.x - figPadding.x, figPadding.y)); // rechts
×
344

345
    // The figure/statues and the button bar
346
    glArchivItem_Bitmap& imgFigLeftTop = *LOADER.GetImageN("resource", 17);
×
347
    glArchivItem_Bitmap& imgFigRightTop = *LOADER.GetImageN("resource", 18);
×
348
    glArchivItem_Bitmap& imgFigLeftBot = *LOADER.GetImageN("resource", 19);
×
349
    glArchivItem_Bitmap& imgFigRightBot = *LOADER.GetImageN("resource", 20);
×
350
    imgFigLeftTop.DrawFull(figPadding);
×
351
    imgFigRightTop.DrawFull(DrawPoint(screenSize.x - figPadding.x - imgFigRightTop.getWidth(), figPadding.y));
×
352
    imgFigLeftBot.DrawFull(DrawPoint(figPadding.x, screenSize.y - figPadding.y - imgFigLeftBot.getHeight()));
×
353
    imgFigRightBot.DrawFull(screenSize - figPadding - imgFigRightBot.GetSize());
×
354

355
    glArchivItem_Bitmap& imgButtonBar = *LOADER.GetImageN("resource", 29);
×
356
    imgButtonBar.DrawFull(
×
357
      DrawPoint((screenSize.x - imgButtonBar.getWidth()) / 2, screenSize.y - imgButtonBar.getHeight()));
×
358
}
×
359

360
void dskGameInterface::Msg_PaintAfter()
×
361
{
362
    Desktop::Msg_PaintAfter();
×
363

364
    const GameWorldBase& world = worldViewer.GetWorld();
×
365

366
    if(SETTINGS.global.showGFInfo)
×
367
    {
368
        std::array<char, 256> nwf_string;
369
        if(GAMECLIENT.IsReplayModeOn())
×
370
        {
371
            snprintf(nwf_string.data(), nwf_string.size(),
×
372
                     _("(Replay-Mode) Current GF: %u (End at: %u) / GF length: %u ms / NWF length: %u gf (%u ms)"),
373
                     world.GetEvMgr().GetCurrentGF(), GAMECLIENT.GetLastReplayGF(),
×
374
                     GAMECLIENT.GetGFLength() / FramesInfo::milliseconds32_t(1), GAMECLIENT.GetNWFLength(),
×
375
                     GAMECLIENT.GetNWFLength() * GAMECLIENT.GetGFLength() / FramesInfo::milliseconds32_t(1));
×
376
        } else
377
            snprintf(nwf_string.data(), nwf_string.size(),
×
378
                     _("Current GF: %u / GF length: %u ms / NWF length: %u gf (%u ms) /  Ping: %u ms"),
379
                     world.GetEvMgr().GetCurrentGF(), GAMECLIENT.GetGFLength() / FramesInfo::milliseconds32_t(1),
×
380
                     GAMECLIENT.GetNWFLength(),
×
381
                     GAMECLIENT.GetNWFLength() * GAMECLIENT.GetGFLength() / FramesInfo::milliseconds32_t(1),
×
382
                     worldViewer.GetPlayer().ping);
×
383
        NormalFont->Draw(DrawPoint(30, 1), nwf_string.data(), FontStyle{}, COLOR_YELLOW);
×
384
    }
385

386
    // tournament mode?
387
    const unsigned tournamentDuration = GAMECLIENT.GetTournamentModeDuration();
×
388
    if(tournamentDuration)
×
389
    {
390
        unsigned curGF = world.GetEvMgr().GetCurrentGF();
×
391
        std::string tournamentNotice;
×
392
        if(curGF >= tournamentDuration)
×
393
            tournamentNotice = _("Tournament finished");
×
394
        else
395
        {
396
            tournamentNotice =
397
              helpers::format("Tournament mode: %1% remaining", GAMECLIENT.FormatGFTime(tournamentDuration - curGF));
×
398
        }
399
        NormalFont->Draw(DrawPoint(VIDEODRIVER.GetRenderSize().x - 30, 1), tournamentNotice, FontStyle::AlignH::RIGHT,
×
400
                         COLOR_YELLOW);
401
    }
402

403
    // Replaydateianzeige in der linken unteren Ecke
404
    if(GAMECLIENT.IsReplayModeOn())
×
405
    {
406
        NormalFont->Draw(DrawPoint(0, VIDEODRIVER.GetRenderSize().y), GAMECLIENT.GetReplayFilename().string(),
×
407
                         FontStyle::BOTTOM, COLOR_YELLOW);
408
    } else
409
    {
410
        // Laggende Spieler anzeigen in Form von Schnecken
411
        DrawPoint snailPos(VIDEODRIVER.GetRenderSize().x - 70, 35);
×
412
        for(const NWFPlayerInfo& player : nwfInfo_->getPlayerInfos())
×
413
        {
414
            if(player.isLagging)
×
415
            {
416
                LOADER.GetPlayerImage("rttr", 0)->DrawFull(Rect(snailPos, 30, 30), COLOR_WHITE,
×
417
                                                           game_->world_.GetPlayer(player.id).color);
×
418
                snailPos.x -= 40;
×
419
            }
420
        }
421
    }
422

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

426
    // Draw cheating indicator icon (WINTER)
427
    if(cheats_.isCheatModeOn())
×
428
    {
429
        glArchivItem_Bitmap* cheatingImg = LOADER.GetImageN("io", 75);
×
430
        cheatingImg->DrawFull(iconPos);
×
431
        iconPos -= DrawPoint(cheatingImg->getWidth() + 6, 0);
×
432
    }
433

434
    // Draw speed indicator icon
NEW
435
    const int speedStep = static_cast<int>(REFERENCE_SPEED / 10ms) - static_cast<int>(GAMECLIENT.GetGFLength() / 10ms);
×
436

437
    if(speedStep != 0)
×
438
    {
439
        glArchivItem_Bitmap* runnerImg = LOADER.GetImageN("io", 164);
×
440

441
        runnerImg->DrawFull(iconPos);
×
442

443
        if(speedStep != 1)
×
444
        {
445
            std::string multiplier = helpers::toString(std::abs(speedStep));
×
446
            NormalFont->Draw(iconPos - runnerImg->GetOrigin() + DrawPoint(19, 6), multiplier, FontStyle::LEFT,
×
447
                             speedStep > 0 ? COLOR_YELLOW : COLOR_RED);
448
        }
449
        iconPos -= DrawPoint(runnerImg->getWidth() + 4, 0);
×
450
    }
451

452
    // Draw zoom level indicator icon
453
    if(gwv.GetCurrentTargetZoomFactor() != 1.f) //-V550
×
454
    {
455
        glArchivItem_Bitmap* magnifierImg = LOADER.GetImageN("io", 36);
×
456

457
        magnifierImg->DrawFull(iconPos);
×
458

459
        std::string zoom_percent = helpers::toString((int)(gwv.GetCurrentTargetZoomFactor() * 100)) + "%";
×
460
        NormalFont->Draw(iconPos - magnifierImg->GetOrigin() + DrawPoint(9, 7), zoom_percent, FontStyle::CENTER,
×
461
                         COLOR_YELLOW);
462
        iconPos -= DrawPoint(magnifierImg->getWidth() + 4, 0);
×
463
    }
464
}
×
465

466
bool dskGameInterface::Msg_LeftDown(const MouseCoords& mc)
3✔
467
{
468
    DrawPoint btOrig(VIDEODRIVER.GetRenderSize().x / 2 - LOADER.GetImageN("resource", 29)->getWidth() / 2 + 44,
6✔
469
                     VIDEODRIVER.GetRenderSize().y - LOADER.GetImageN("resource", 29)->getHeight() + 4);
9✔
470
    Extent btSize = Extent(37, 32) * 4u;
3✔
471
    if(IsPointInRect(mc.pos, Rect(btOrig, btSize)))
3✔
472
        return false;
×
473

474
    // Start scrolling also on Ctrl + left click
475
    if(VIDEODRIVER.GetModKeyState().ctrl)
3✔
476
    {
477
        Msg_RightDown(mc);
1✔
478
        return true;
1✔
479
    } else if(isScrolling)
2✔
480
        StopScrolling();
2✔
481

482
    // Unterscheiden je nachdem Straäcnbaumodus an oder aus ist
483
    if(road.mode != RoadBuildMode::Disabled)
2✔
484
    {
485
        // in "richtige" Map-Koordinaten Konvertieren, den aktuellen selektierten Punkt
486
        const MapPoint selPt = gwv.GetSelectedPt();
1✔
487

488
        if(selPt == road.point)
1✔
489
        {
490
            // Selektierter Punkt ist der gleiche wie der Straßenpunkt --> Fenster mit Wegbau abbrechen
491
            ShowRoadWindow(mc.pos);
×
492
        } else
493
        {
494
            // altes Roadwindow schließen
495
            WINDOWMANAGER.Close((unsigned)CGI_ROADWINDOW);
1✔
496

497
            // Ist das ein gültiger neuer Wegpunkt?
498
            if(worldViewer.IsRoadAvailable(road.mode == RoadBuildMode::Boat, selPt)
1✔
499
               && worldViewer.IsPlayerTerritory(selPt))
1✔
500
            {
501
                MapPoint targetPt = selPt;
1✔
502
                if(!BuildRoadPart(targetPt))
1✔
503
                    ShowRoadWindow(mc.pos);
×
504
            } else if(worldViewer.GetBQ(selPt) != BuildingQuality::Nothing)
×
505
            {
506
                // Wurde bereits auf das gebaute Stück geklickt?
507
                unsigned idOnRoad = GetIdInCurBuildRoad(selPt);
×
508
                if(idOnRoad)
×
509
                    DemolishRoad(idOnRoad);
×
510
                else
511
                {
512
                    MapPoint targetPt = selPt;
×
513
                    if(BuildRoadPart(targetPt))
×
514
                    {
515
                        // Ist der Zielpunkt der gleiche geblieben?
516
                        if(selPt == targetPt)
×
517
                            GI_BuildRoad();
×
518
                    } else if(selPt == targetPt)
×
519
                        ShowRoadWindow(mc.pos);
×
520
                }
521
            }
522
            // Wurde auf eine Flagge geklickt und ist diese Flagge nicht der Weganfangspunkt?
523
            else if(worldViewer.GetWorld().GetNO(selPt)->GetType() == NodalObjectType::Flag && selPt != road.start)
×
524
            {
525
                MapPoint targetPt = selPt;
×
526
                if(BuildRoadPart(targetPt))
×
527
                {
528
                    if(selPt == targetPt)
×
529
                        GI_BuildRoad();
×
530
                } else if(selPt == targetPt)
×
531
                    ShowRoadWindow(mc.pos);
×
532
            } else
533
            {
534
                unsigned tbr = GetIdInCurBuildRoad(selPt);
×
535
                // Wurde bereits auf das gebaute Stück geklickt?
536
                if(tbr)
×
537
                    DemolishRoad(tbr);
×
538
                else
539
                    ShowRoadWindow(mc.pos);
×
540
            }
541
        }
542
    } else
543
    {
544
        bool enable_military_buildings = false;
1✔
545

546
        iwAction::Tabs action_tabs;
1✔
547

548
        const MapPoint cSel = gwv.GetSelectedPt();
1✔
549

550
        // Vielleicht steht hier auch ein Schiff?
551
        if(const noShip* ship = worldViewer.GetShip(cSel))
1✔
552
        {
553
            WINDOWMANAGER.Show(std::make_unique<iwShip>(gwv, GAMECLIENT, ship));
×
554
            return true;
×
555
        }
556

557
        // Evtl ists nen Haus? (unser Haus)
558
        const noBase& selObj = *worldViewer.GetWorld().GetNO(cSel);
1✔
559
        if(selObj.GetType() == NodalObjectType::Building && worldViewer.IsOwner(cSel))
1✔
560
        {
561
            if(auto* wnd = WINDOWMANAGER.FindNonModalWindow(CGI_BUILDING + MapBase::CreateGUIID(cSel)))
×
562
            {
563
                WINDOWMANAGER.SetActiveWindow(*wnd);
×
564
                return true;
×
565
            }
566
            BuildingType bt = static_cast<const noBuilding&>(selObj).GetBuildingType();
×
567
            // HQ
568
            if(bt == BuildingType::Headquarters)
×
569
                WINDOWMANAGER.Show(
×
570
                  std::make_unique<iwHQ>(gwv, GAMECLIENT, worldViewer.GetWorldNonConst().GetSpecObj<nobHQ>(cSel)));
×
571
            // Lagerhäuser
572
            else if(bt == BuildingType::Storehouse)
×
573
                WINDOWMANAGER.Show(std::make_unique<iwBaseWarehouse>(
×
574
                  gwv, GAMECLIENT, worldViewer.GetWorldNonConst().GetSpecObj<nobStorehouse>(cSel)));
×
575
            // Hafengebäude
576
            else if(bt == BuildingType::HarborBuilding)
×
577
                WINDOWMANAGER.Show(std::make_unique<iwHarborBuilding>(
×
578
                  gwv, GAMECLIENT, worldViewer.GetWorldNonConst().GetSpecObj<nobHarborBuilding>(cSel)));
×
579
            // Militärgebäude
580
            else if(BuildingProperties::IsMilitary(bt))
×
581
                WINDOWMANAGER.Show(std::make_unique<iwMilitaryBuilding>(
×
582
                  gwv, GAMECLIENT, worldViewer.GetWorldNonConst().GetSpecObj<nobMilitary>(cSel)));
×
583
            else if(bt == BuildingType::Temple)
×
584
                WINDOWMANAGER.Show(std::make_unique<iwTempleBuilding>(
×
585
                  gwv, GAMECLIENT, worldViewer.GetWorldNonConst().GetSpecObj<nobTemple>(cSel)));
×
586
            else
587
                WINDOWMANAGER.Show(std::make_unique<iwBuilding>(
×
588
                  gwv, GAMECLIENT, worldViewer.GetWorldNonConst().GetSpecObj<nobUsual>(cSel)));
×
589
            return true;
×
590
        }
591
        // oder vielleicht eine Baustelle?
592
        else if(selObj.GetType() == NodalObjectType::Buildingsite && worldViewer.IsOwner(cSel))
1✔
593
        {
594
            if(!WINDOWMANAGER.FindNonModalWindow(CGI_BUILDING + MapBase::CreateGUIID(cSel)))
×
595
                WINDOWMANAGER.Show(
×
596
                  std::make_unique<iwBuildingSite>(gwv, worldViewer.GetWorld().GetSpecObj<noBuildingSite>(cSel)));
×
597
            return true;
×
598
        }
599

600
        action_tabs.watch = true;
1✔
601
        // Unser Land
602
        if(worldViewer.IsOwner(cSel))
1✔
603
        {
604
            const BuildingQuality bq = worldViewer.GetBQ(cSel);
1✔
605
            // Kann hier was gebaut werden?
606
            if(bq >= BuildingQuality::Mine)
1✔
607
            {
608
                action_tabs.build = true;
1✔
609

610
                // Welches Gebäude kann gebaut werden?
611
                switch(bq)
1✔
612
                {
613
                    case BuildingQuality::Mine: action_tabs.build_tabs = iwAction::BuildTab::Mine; break;
×
614
                    case BuildingQuality::Hut: action_tabs.build_tabs = iwAction::BuildTab::Hut; break;
×
615
                    case BuildingQuality::House: action_tabs.build_tabs = iwAction::BuildTab::House; break;
×
616
                    case BuildingQuality::Castle: action_tabs.build_tabs = iwAction::BuildTab::Castle; break;
1✔
617
                    case BuildingQuality::Harbor: action_tabs.build_tabs = iwAction::BuildTab::Harbor; break;
×
618
                    default: break;
×
619
                }
620

621
                if(!worldViewer.GetWorld().IsFlagAround(cSel))
1✔
622
                    action_tabs.setflag = true;
1✔
623

624
                // Prüfen, ob sich Militärgebäude in der Nähe befinden, wenn nein, können auch eigene
625
                // Militärgebäude gebaut werden
626
                enable_military_buildings =
1✔
627
                  !worldViewer.GetWorld().IsMilitaryBuildingNearNode(cSel, worldViewer.GetPlayerId());
1✔
628
            } else if(bq == BuildingQuality::Flag)
×
629
                action_tabs.setflag = true;
×
630
            else if(selObj.GetType() == NodalObjectType::Flag)
×
631
                action_tabs.flag = true;
×
632

633
            if(selObj.GetType() != NodalObjectType::Flag && selObj.GetType() != NodalObjectType::Building)
1✔
634
            {
635
                // Check if there are roads
636
                for(const Direction dir : helpers::EnumRange<Direction>{})
16✔
637
                {
638
                    const PointRoad curRoad = worldViewer.GetVisiblePointRoad(cSel, dir);
6✔
639
                    if(curRoad != PointRoad::None)
6✔
640
                    {
641
                        action_tabs.cutroad = true;
×
642
                        action_tabs.upgradeRoad |= (curRoad == PointRoad::Normal);
×
643
                    }
644
                }
645
            }
646
        }
647
        // evtl ists ein feindliches Militärgebäude, welches NICHT im Nebel liegt?
648
        else if(worldViewer.GetVisibility(cSel) == Visibility::Visible)
×
649
        {
650
            if(selObj.GetType() == NodalObjectType::Building)
×
651
            {
652
                const auto* building = worldViewer.GetWorld().GetSpecObj<noBuilding>(cSel); //-V807
×
653
                BuildingType bt = building->GetBuildingType();
×
654

655
                // Only if trade is enabled
656
                if(worldViewer.GetWorld().GetGGS().isEnabled(AddonId::TRADE))
×
657
                {
658
                    // Allied warehouse? -> Show trade window
659
                    if(BuildingProperties::IsWareHouse(bt) && worldViewer.GetPlayer().IsAlly(building->GetPlayer()))
×
660
                    {
661
                        WINDOWMANAGER.Show(std::make_unique<iwTrade>(*static_cast<const nobBaseWarehouse*>(building),
×
662
                                                                     worldViewer, GAMECLIENT));
×
663
                        return true;
×
664
                    }
665
                }
666

667
                // Ist es ein gewöhnliches Militärgebäude?
668
                if(BuildingProperties::IsMilitary(bt))
×
669
                {
670
                    // Dann darf es nicht neu gebaut sein!
671
                    if(!static_cast<const nobMilitary*>(building)->IsNewBuilt())
×
672
                        action_tabs.attack = true;
×
673
                }
674
                // oder ein HQ oder Hafen?
675
                else if(bt == BuildingType::Headquarters || bt == BuildingType::HarborBuilding)
×
676
                    action_tabs.attack = true;
×
677
                action_tabs.sea_attack =
×
678
                  action_tabs.attack && worldViewer.GetWorld().GetGGS().isEnabled(AddonId::SEA_ATTACK);
×
679
            }
680
        }
681

682
        // Bisheriges Actionfenster schließen, falls es eins gab
683
        // aktuelle Mausposition merken, da diese durch das Schließen verändert werden kann
684
        if(actionwindow)
1✔
685
            actionwindow->Close();
×
686
        VIDEODRIVER.SetMousePos(mc.pos);
1✔
687

688
        ShowActionWindow(action_tabs, cSel, mc.pos, enable_military_buildings);
1✔
689
    }
690

691
    return true;
2✔
692
}
693

694
bool dskGameInterface::Msg_LeftUp(const MouseCoords&)
2✔
695
{
696
    if(isScrolling)
2✔
697
    {
698
        StopScrolling();
1✔
699
        return true;
1✔
700
    }
701
    return false;
1✔
702
}
703

704
bool dskGameInterface::Msg_MouseMove(const MouseCoords& mc)
20✔
705
{
706
    if(!isScrolling)
20✔
707
        return false;
12✔
708

709
    int acceleration = SETTINGS.global.smartCursor ? 2 : 3;
8✔
710

711
    if(SETTINGS.interface.invertMouse)
8✔
712
        acceleration = -acceleration;
1✔
713

714
    gwv.MoveBy((mc.pos - startScrollPt) * acceleration);
8✔
715
    VIDEODRIVER.SetMousePos(startScrollPt);
8✔
716

717
    if(!SETTINGS.global.smartCursor)
8✔
718
        startScrollPt = mc.pos;
×
719
    return true;
8✔
720
}
721

722
bool dskGameInterface::Msg_RightDown(const MouseCoords& mc)
11✔
723
{
724
    StartScrolling(mc.pos);
11✔
725
    return true;
11✔
726
}
727

728
bool dskGameInterface::Msg_RightUp(const MouseCoords& /*mc*/) //-V524
3✔
729
{
730
    if(isScrolling)
3✔
731
        StopScrolling();
3✔
732
    return false;
3✔
733
}
734

735
/**
736
 *  Druck von Spezialtasten auswerten.
737
 */
738
bool dskGameInterface::Msg_KeyDown(const KeyEvent& ke)
2✔
739
{
740
    cheatCommandTracker_.onKeyEvent(ke);
2✔
741

742
    switch(ke.kt)
2✔
743
    {
744
        default: break;
2✔
745
        case KeyType::Return: // Chatfenster öffnen
×
746
            WINDOWMANAGER.Show(std::make_unique<iwChat>(this));
×
747
            return true;
×
748

749
        case KeyType::Space: // Bauqualitäten anzeigen
×
750
            gwv.ToggleShowBQ();
×
751
            return true;
×
752

753
        case KeyType::Left: // Nach Links Scrollen
×
754
            gwv.MoveBy({-30, 0});
×
755
            return true;
×
756
        case KeyType::Right: // Nach Rechts Scrollen
×
757
            gwv.MoveBy({30, 0});
×
758
            return true;
×
759
        case KeyType::Up: // Nach Oben Scrollen
×
760
            gwv.MoveBy({0, -30});
×
761
            return true;
×
762
        case KeyType::Down: // Nach Unten Scrollen
×
763
            gwv.MoveBy({0, 30});
×
764
            return true;
×
765

766
        case KeyType::F2: // Spiel speichern
×
767
            WINDOWMANAGER.ToggleWindow(std::make_unique<iwSave>());
×
768
            return true;
×
769
        case KeyType::F3: // Map debug window/ Multiplayer coordinates
×
770
        {
771
            const bool replayMode = GAMECLIENT.IsReplayModeOn();
×
772
            if(replayMode)
×
773
                DisableFoW(true);
×
774
            WINDOWMANAGER.ToggleWindow(std::make_unique<iwMapDebug>(gwv, game_->world_.IsSinglePlayer() || replayMode));
×
775
            return true;
×
776
        }
777
        case KeyType::F8: // Tastaturbelegung
×
778
            WINDOWMANAGER.ToggleWindow(std::make_unique<iwTextfile>("keyboardlayout.txt", _("Keyboard layout")));
×
779
            return true;
×
780
        case KeyType::F9: // Readme
×
781
            WINDOWMANAGER.ToggleWindow(std::make_unique<iwTextfile>("readme.txt", _("Readme!")));
×
782
            return true;
×
783
        case KeyType::F11: // Music player (midi files)
×
784
            WINDOWMANAGER.ToggleWindow(std::make_unique<iwMusicPlayer>());
×
785
            return true;
×
786
        case KeyType::F12: // Optionsfenster
×
787
            WINDOWMANAGER.ToggleWindow(std::make_unique<iwOptionsWindow>(gwv.GetSoundMgr()));
×
788
            return true;
×
789
    }
790

791
    switch(ke.c)
2✔
792
    {
793
        case '+':
×
794
            if(GAMECLIENT.IsReplayModeOn() || game_->world_.IsSinglePlayer())
×
795
                GAMECLIENT.IncreaseSpeed();
×
796
            return true;
×
797
        case '-':
×
798
            if(GAMECLIENT.IsReplayModeOn() || game_->world_.IsSinglePlayer())
×
799
                GAMECLIENT.DecreaseSpeed();
×
800
            return true;
×
801

802
        case '1':
×
803
        case '2':
804
        case '3': // Spieler umschalten
805
        case '4':
806
        case '5':
807
        case '6':
808
        case '7':
809
        case '8':
810
        {
811
            unsigned playerIdx = ke.c - '1';
×
812
            if(GAMECLIENT.IsReplayModeOn())
×
813
            {
814
                unsigned oldPlayerId = worldViewer.GetPlayerId();
×
815
                GAMECLIENT.ChangePlayerIngame(worldViewer.GetPlayerId(), playerIdx);
×
816
                RTTR_Assert(worldViewer.GetPlayerId() == oldPlayerId || worldViewer.GetPlayerId() == playerIdx);
×
817
            } else if(playerIdx < worldViewer.GetWorld().GetNumPlayers())
×
818
            {
819
                // On mutiplayer this currently asyncs, but as this is a debug feature anyway just disable it there.
820
                // If this should be enabled again, look into the handling/clearing of accumulated GCs
821
                if(game_->world_.IsSinglePlayer())
×
822
                {
823
                    const GamePlayer& player = worldViewer.GetWorld().GetPlayer(playerIdx);
×
824
                    if(player.ps == PlayerState::AI && player.aiInfo.type == AI::Type::Dummy)
×
825
                        GAMECLIENT.RequestSwapToPlayer(playerIdx);
×
826
                }
827
            }
828
            return true;
×
829
        }
830

831
        case 'b': // Zur lezten Position zurückspringen
×
832
            gwv.MoveToLastPosition();
×
833
            return true;
×
834
        case 'v':
×
835
            if(game_->world_.IsSinglePlayer())
×
836
                GAMECLIENT.IncreaseSpeed();
×
837
            return true;
×
838
        case 'c': // Gebäudenamen anzeigen
×
839
            gwv.ToggleShowNames();
×
840
            return true;
×
841
        case 'd': // Replay: FoW an/ausschalten
×
842
            ToggleFoW();
×
843
            return true;
×
844
        case 'h': // Zum HQ springen
×
845
        {
846
            const GamePlayer& player = worldViewer.GetPlayer();
×
847
            // Prüfen, ob dieses überhaupt noch existiert
848
            if(player.GetHQPos().isValid())
×
849
                gwv.MoveToMapPt(player.GetHQPos());
×
850
        }
851
            return true;
×
852
        case 'i': // Show inventory
×
853
            WINDOWMANAGER.ToggleWindow(std::make_unique<iwInventory>(worldViewer.GetPlayer()));
×
854
            return true;
×
855
        case 'j': // GFs überspringen
×
856
            if(game_->world_.IsSinglePlayer() || GAMECLIENT.IsReplayModeOn())
×
857
                WINDOWMANAGER.ToggleWindow(std::make_unique<iwSkipGFs>(gwv));
×
858
            return true;
×
859
        case 'l': // Minimap anzeigen
×
860
            WINDOWMANAGER.ToggleWindow(std::make_unique<iwMinimap>(minimap, gwv));
×
861
            return true;
×
862
        case 'm': // Hauptauswahl
2✔
863
            WINDOWMANAGER.ToggleWindow(std::make_unique<iwMainMenu>(gwv, GAMECLIENT));
2✔
864
            return true;
2✔
865
        case 'n': // Show Post window
×
866
            WINDOWMANAGER.ToggleWindow(std::make_unique<iwPostWindow>(gwv, GetPostBox()));
×
867
            UpdatePostIcon(GetPostBox().GetNumMsgs(), false);
×
868
            return true;
×
869
        case 'p': // Pause
×
870
            GAMECLIENT.TogglePause();
×
871
            return true;
×
872
        case 'q': // Spiel verlassen
×
873
            if(ke.alt)
×
874
                WINDOWMANAGER.ToggleWindow(std::make_unique<iwEndgame>());
×
875
            return true;
×
876
        case 's': // Produktivität anzeigen
×
877
            gwv.ToggleShowProductivity();
×
878
            return true;
×
879
        case 26: // ctrl+z
×
880
            gwv.SetZoomFactor(ZOOM_FACTORS[ZOOM_DEFAULT_INDEX]);
×
881
            return true;
×
882
        case 'z': // zoom
×
883
            if(++zoomLvl >= ZOOM_FACTORS.size())
×
884
                zoomLvl = 0;
×
885

886
            gwv.SetZoomFactor(ZOOM_FACTORS[zoomLvl]);
×
887
            return true;
×
888
        case 'Z': // shift-z, reverse zoom
×
889
            if(zoomLvl == 0)
×
890
                zoomLvl = ZOOM_FACTORS.size() - 1;
×
891
            else
892
                zoomLvl--;
×
893

894
            gwv.SetZoomFactor(ZOOM_FACTORS[zoomLvl]);
×
895
            return true;
×
896
    }
897

898
    return false;
×
899
}
900

901
bool dskGameInterface::Msg_WheelUp(const MouseCoords&)
×
902
{
903
    WheelZoom(ZOOM_WHEEL_INCREMENT);
×
904
    return true;
×
905
}
906
bool dskGameInterface::Msg_WheelDown(const MouseCoords&)
×
907
{
908
    WheelZoom(-ZOOM_WHEEL_INCREMENT);
×
909
    return true;
×
910
}
911

912
void dskGameInterface::WheelZoom(float step)
×
913
{
914
    float new_zoom = gwv.GetCurrentTargetZoomFactor() * (1 + step);
×
915
    gwv.SetZoomFactor(new_zoom);
×
916

917
    // also keep track in terms of fixed defined zoom levels
918
    zoomLvl = ZOOM_DEFAULT_INDEX;
×
919
    for(size_t i = ZOOM_DEFAULT_INDEX; i < ZOOM_FACTORS.size(); ++i)
×
920
    {
921
        if(ZOOM_FACTORS[i] < new_zoom)
×
922
            zoomLvl = i;
×
923
    }
924

925
    for(size_t i = ZOOM_DEFAULT_INDEX; i-- > 0;)
×
926
    {
927
        if(ZOOM_FACTORS[i] > new_zoom)
×
928
            zoomLvl = i;
×
929
    }
930
}
×
931

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

947
void dskGameInterface::Run()
×
948
{
949
    // Reset draw counter of the trees before drawing
950
    noTree::ResetDrawCounter();
×
951

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

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

968
    messenger.Draw();
×
969
}
×
970

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

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

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

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

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

1005
        RTTR_Assert(index < waterwayLengths.size());
×
1006
        const unsigned max_length = waterwayLengths[index];
×
1007

1008
        unsigned length = road.route.size() + new_route.size();
×
1009

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

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

1032
    // Zielpunkt updaten (für Wasserweg)
1033
    cSel = road.point;
3✔
1034

1035
    road.route.insert(road.route.end(), new_route.begin(), new_route.end());
3✔
1036

1037
    return true;
3✔
1038
}
1039

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

1048
        curPt = worldViewer.GetNeighbour(curPt, road.route[i]);
1✔
1049
    }
1050
    return 0;
×
1051
}
1052

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

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

1064
    iwAction::Params params;
2✔
1065

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

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

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

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

1096
void dskGameInterface::OnChatCommand(const std::string& cmd)
×
1097
{
1098
    cheatCommandTracker_.onChatCommand(cmd);
×
1099

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1265
void dskGameInterface::GI_UpdateMinimap(const MapPoint pt)
×
1266
{
1267
    // Minimap Bescheid sagen
1268
    minimap.UpdateNode(pt);
×
1269
}
×
1270

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

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

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

1308
    road.route.resize(start_id - 1);
1✔
1309
}
1✔
1310

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

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

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

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

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

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