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

Return-To-The-Roots / s25client / 18856213349

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

Pull #1804

github

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

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

3 existing lines in 3 files now uncovered.

22552 of 44683 relevant lines covered (50.47%)

35157.57 hits per line

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

31.82
/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)
18✔
183
{
184
    if(activate == IsActive())
18✔
185
        return;
10✔
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()
7✔
211
{
212
    isScrolling = false;
7✔
213
    WINDOWMANAGER.SetCursor(road.mode == RoadBuildMode::Disabled ? Cursor::Hand : Cursor::Remove);
7✔
214
}
7✔
215

216
void dskGameInterface::StartScrolling(const Position& mousePos)
13✔
217
{
218
    startScrollPt = mousePos;
13✔
219
    isScrolling = true;
13✔
220
    WINDOWMANAGER.SetCursor(Cursor::Scroll);
13✔
221
}
13✔
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
bool dskGameInterface::ContextClick(const MouseCoords& mc)
2✔
313
{
314
    // Unterscheiden je nachdem Straäcnbaumodus an oder aus ist
315
    if(road.mode != RoadBuildMode::Disabled)
2✔
316
    {
317
        // in "richtige" Map-Koordinaten Konvertieren, den aktuellen selektierten Punkt
318
        const MapPoint selPt = gwv.GetSelectedPt();
1✔
319

320
        if(selPt == road.point)
1✔
321
        {
322
            // Selektierter Punkt ist der gleiche wie der Straßenpunkt --> Fenster mit Wegbau abbrechen
NEW
323
            ShowRoadWindow(mc.pos);
×
324
        } else
325
        {
326
            // altes Roadwindow schließen
327
            WINDOWMANAGER.Close((unsigned)CGI_ROADWINDOW);
1✔
328

329
            // Ist das ein gültiger neuer Wegpunkt?
330
            if(worldViewer.IsRoadAvailable(road.mode == RoadBuildMode::Boat, selPt)
1✔
331
               && worldViewer.IsPlayerTerritory(selPt))
1✔
332
            {
333
                MapPoint targetPt = selPt;
1✔
334
                if(!BuildRoadPart(targetPt))
1✔
NEW
335
                    ShowRoadWindow(mc.pos);
×
336
            } else if(worldViewer.GetBQ(selPt) != BuildingQuality::Nothing)
×
337
            {
338
                // Wurde bereits auf das gebaute Stück geklickt?
339
                unsigned idOnRoad = GetIdInCurBuildRoad(selPt);
×
340
                if(idOnRoad)
×
341
                    DemolishRoad(idOnRoad);
×
342
                else
343
                {
344
                    MapPoint targetPt = selPt;
×
345
                    if(BuildRoadPart(targetPt))
×
346
                    {
347
                        // Ist der Zielpunkt der gleiche geblieben?
348
                        if(selPt == targetPt)
×
349
                            GI_BuildRoad();
×
350
                    } else if(selPt == targetPt)
×
NEW
351
                        ShowRoadWindow(mc.pos);
×
352
                }
353
            }
354
            // Wurde auf eine Flagge geklickt und ist diese Flagge nicht der Weganfangspunkt?
355
            else if(worldViewer.GetWorld().GetNO(selPt)->GetType() == NodalObjectType::Flag && selPt != road.start)
×
356
            {
357
                MapPoint targetPt = selPt;
×
358
                if(BuildRoadPart(targetPt))
×
359
                {
360
                    if(selPt == targetPt)
×
361
                        GI_BuildRoad();
×
362
                } else if(selPt == targetPt)
×
NEW
363
                    ShowRoadWindow(mc.pos);
×
364
            } else
365
            {
366
                unsigned tbr = GetIdInCurBuildRoad(selPt);
×
367
                // Wurde bereits auf das gebaute Stück geklickt?
368
                if(tbr)
×
369
                    DemolishRoad(tbr);
×
370
                else
NEW
371
                    ShowRoadWindow(mc.pos);
×
372
            }
373
        }
374
    } else
375
    {
376
        bool enable_military_buildings = false;
1✔
377

378
        iwAction::Tabs action_tabs;
1✔
379

380
        const MapPoint cSel = gwv.GetSelectedPt();
1✔
381

382
        // Vielleicht steht hier auch ein Schiff?
383
        if(const noShip* ship = worldViewer.GetShip(cSel))
1✔
384
        {
385
            WINDOWMANAGER.Show(std::make_unique<iwShip>(gwv, GAMECLIENT, ship));
×
386
            return true;
×
387
        }
388

389
        // Evtl ists nen Haus? (unser Haus)
390
        const noBase& selObj = *worldViewer.GetWorld().GetNO(cSel);
1✔
391
        if(selObj.GetType() == NodalObjectType::Building && worldViewer.IsOwner(cSel))
1✔
392
        {
393
            if(auto* wnd = WINDOWMANAGER.FindNonModalWindow(CGI_BUILDING + MapBase::CreateGUIID(cSel)))
×
394
            {
395
                WINDOWMANAGER.SetActiveWindow(*wnd);
×
396
                return true;
×
397
            }
398
            BuildingType bt = static_cast<const noBuilding&>(selObj).GetBuildingType();
×
399
            // HQ
400
            if(bt == BuildingType::Headquarters)
×
401
                WINDOWMANAGER.Show(
×
402
                  std::make_unique<iwHQ>(gwv, GAMECLIENT, worldViewer.GetWorldNonConst().GetSpecObj<nobHQ>(cSel)));
×
403
            // Lagerhäuser
404
            else if(bt == BuildingType::Storehouse)
×
405
                WINDOWMANAGER.Show(std::make_unique<iwBaseWarehouse>(
×
406
                  gwv, GAMECLIENT, worldViewer.GetWorldNonConst().GetSpecObj<nobStorehouse>(cSel)));
×
407
            // Hafengebäude
408
            else if(bt == BuildingType::HarborBuilding)
×
409
                WINDOWMANAGER.Show(std::make_unique<iwHarborBuilding>(
×
410
                  gwv, GAMECLIENT, worldViewer.GetWorldNonConst().GetSpecObj<nobHarborBuilding>(cSel)));
×
411
            // Militärgebäude
412
            else if(BuildingProperties::IsMilitary(bt))
×
413
                WINDOWMANAGER.Show(std::make_unique<iwMilitaryBuilding>(
×
414
                  gwv, GAMECLIENT, worldViewer.GetWorldNonConst().GetSpecObj<nobMilitary>(cSel)));
×
415
            else if(bt == BuildingType::Temple)
×
416
                WINDOWMANAGER.Show(std::make_unique<iwTempleBuilding>(
×
417
                  gwv, GAMECLIENT, worldViewer.GetWorldNonConst().GetSpecObj<nobTemple>(cSel)));
×
418
            else
419
                WINDOWMANAGER.Show(std::make_unique<iwBuilding>(
×
420
                  gwv, GAMECLIENT, worldViewer.GetWorldNonConst().GetSpecObj<nobUsual>(cSel)));
×
421
            return true;
×
422
        }
423
        // oder vielleicht eine Baustelle?
424
        else if(selObj.GetType() == NodalObjectType::Buildingsite && worldViewer.IsOwner(cSel))
1✔
425
        {
426
            if(!WINDOWMANAGER.FindNonModalWindow(CGI_BUILDING + MapBase::CreateGUIID(cSel)))
×
427
                WINDOWMANAGER.Show(
×
428
                  std::make_unique<iwBuildingSite>(gwv, worldViewer.GetWorld().GetSpecObj<noBuildingSite>(cSel)));
×
429
            return true;
×
430
        }
431

432
        action_tabs.watch = true;
1✔
433
        // Unser Land
434
        if(worldViewer.IsOwner(cSel))
1✔
435
        {
436
            const BuildingQuality bq = worldViewer.GetBQ(cSel);
1✔
437
            // Kann hier was gebaut werden?
438
            if(bq >= BuildingQuality::Mine)
1✔
439
            {
440
                action_tabs.build = true;
1✔
441

442
                // Welches Gebäude kann gebaut werden?
443
                switch(bq)
1✔
444
                {
445
                    case BuildingQuality::Mine: action_tabs.build_tabs = iwAction::BuildTab::Mine; break;
×
446
                    case BuildingQuality::Hut: action_tabs.build_tabs = iwAction::BuildTab::Hut; break;
×
447
                    case BuildingQuality::House: action_tabs.build_tabs = iwAction::BuildTab::House; break;
×
448
                    case BuildingQuality::Castle: action_tabs.build_tabs = iwAction::BuildTab::Castle; break;
1✔
449
                    case BuildingQuality::Harbor: action_tabs.build_tabs = iwAction::BuildTab::Harbor; break;
×
450
                    default: break;
×
451
                }
452

453
                if(!worldViewer.GetWorld().IsFlagAround(cSel))
1✔
454
                    action_tabs.setflag = true;
1✔
455

456
                // Prüfen, ob sich Militärgebäude in der Nähe befinden, wenn nein, können auch eigene
457
                // Militärgebäude gebaut werden
458
                enable_military_buildings =
1✔
459
                  !worldViewer.GetWorld().IsMilitaryBuildingNearNode(cSel, worldViewer.GetPlayerId());
1✔
460
            } else if(bq == BuildingQuality::Flag)
×
461
                action_tabs.setflag = true;
×
462
            else if(selObj.GetType() == NodalObjectType::Flag)
×
463
                action_tabs.flag = true;
×
464

465
            if(selObj.GetType() != NodalObjectType::Flag && selObj.GetType() != NodalObjectType::Building)
1✔
466
            {
467
                // Check if there are roads
468
                for(const Direction dir : helpers::EnumRange<Direction>{})
16✔
469
                {
470
                    const PointRoad curRoad = worldViewer.GetVisiblePointRoad(cSel, dir);
6✔
471
                    if(curRoad != PointRoad::None)
6✔
472
                    {
473
                        action_tabs.cutroad = true;
×
474
                        action_tabs.upgradeRoad |= (curRoad == PointRoad::Normal);
×
475
                    }
476
                }
477
            }
478
        }
479
        // evtl ists ein feindliches Militärgebäude, welches NICHT im Nebel liegt?
480
        else if(worldViewer.GetVisibility(cSel) == Visibility::Visible)
×
481
        {
482
            if(selObj.GetType() == NodalObjectType::Building)
×
483
            {
484
                const auto* building = worldViewer.GetWorld().GetSpecObj<noBuilding>(cSel); //-V807
×
485
                BuildingType bt = building->GetBuildingType();
×
486

487
                // Only if trade is enabled
488
                if(worldViewer.GetWorld().GetGGS().isEnabled(AddonId::TRADE))
×
489
                {
490
                    // Allied warehouse? -> Show trade window
491
                    if(BuildingProperties::IsWareHouse(bt) && worldViewer.GetPlayer().IsAlly(building->GetPlayer()))
×
492
                    {
493
                        WINDOWMANAGER.Show(std::make_unique<iwTrade>(*static_cast<const nobBaseWarehouse*>(building),
×
494
                                                                     worldViewer, GAMECLIENT));
×
495
                        return true;
×
496
                    }
497
                }
498

499
                // Ist es ein gewöhnliches Militärgebäude?
500
                if(BuildingProperties::IsMilitary(bt))
×
501
                {
502
                    // Dann darf es nicht neu gebaut sein!
503
                    if(!static_cast<const nobMilitary*>(building)->IsNewBuilt())
×
504
                        action_tabs.attack = true;
×
505
                }
506
                // oder ein HQ oder Hafen?
507
                else if(bt == BuildingType::Headquarters || bt == BuildingType::HarborBuilding)
×
508
                    action_tabs.attack = true;
×
509
                action_tabs.sea_attack =
×
510
                  action_tabs.attack && worldViewer.GetWorld().GetGGS().isEnabled(AddonId::SEA_ATTACK);
×
511
            }
512
        }
513

514
        // Bisheriges Actionfenster schließen, falls es eins gab
515
        // aktuelle Mausposition merken, da diese durch das Schließen verändert werden kann
516
        if(actionwindow)
1✔
517
            actionwindow->Close();
×
518
        VIDEODRIVER.SetMousePos(mc.pos);
1✔
519

520
        ShowActionWindow(action_tabs, cSel, mc.pos, enable_military_buildings);
1✔
521
    }
522

523
    return true;
2✔
524
}
525

NEW
526
void dskGameInterface::Msg_ButtonClick(const unsigned ctrl_id)
×
527
{
NEW
528
    switch(ctrl_id)
×
529
    {
NEW
530
        case ID_btMap: WINDOWMANAGER.ToggleWindow(std::make_unique<iwMinimap>(minimap, gwv)); break;
×
NEW
531
        case ID_btOptions: WINDOWMANAGER.ToggleWindow(std::make_unique<iwMainMenu>(gwv, GAMECLIENT)); break;
×
NEW
532
        case ID_btConstructionAid:
×
NEW
533
            if(WINDOWMANAGER.IsDesktopActive())
×
NEW
534
                gwv.ToggleShowBQ();
×
NEW
535
            break;
×
NEW
536
        case ID_btPost:
×
NEW
537
            WINDOWMANAGER.ToggleWindow(std::make_unique<iwPostWindow>(gwv, GetPostBox()));
×
NEW
538
            UpdatePostIcon(GetPostBox().GetNumMsgs(), false);
×
NEW
539
            break;
×
540
    }
NEW
541
}
×
542

NEW
543
void dskGameInterface::Msg_PaintBefore()
×
544
{
NEW
545
    Desktop::Msg_PaintBefore();
×
546

547
    // Spiel ausführen
NEW
548
    Run();
×
549

550
    /// Padding of the figures
NEW
551
    const DrawPoint figPadding(12, 12);
×
NEW
552
    const DrawPoint screenSize(VIDEODRIVER.GetRenderSize());
×
553
    // Rahmen zeichnen
NEW
554
    borders[0]->DrawFull(DrawPoint(0, 0));                                      // oben (mit Ecken)
×
NEW
555
    borders[1]->DrawFull(DrawPoint(0, screenSize.y - figPadding.y));            // unten (mit Ecken)
×
NEW
556
    borders[2]->DrawFull(DrawPoint(0, figPadding.y));                           // links
×
NEW
557
    borders[3]->DrawFull(DrawPoint(screenSize.x - figPadding.x, figPadding.y)); // rechts
×
558

559
    // The figure/statues and the button bar
NEW
560
    glArchivItem_Bitmap& imgFigLeftTop = *LOADER.GetImageN("resource", 17);
×
NEW
561
    glArchivItem_Bitmap& imgFigRightTop = *LOADER.GetImageN("resource", 18);
×
NEW
562
    glArchivItem_Bitmap& imgFigLeftBot = *LOADER.GetImageN("resource", 19);
×
NEW
563
    glArchivItem_Bitmap& imgFigRightBot = *LOADER.GetImageN("resource", 20);
×
NEW
564
    imgFigLeftTop.DrawFull(figPadding);
×
NEW
565
    imgFigRightTop.DrawFull(DrawPoint(screenSize.x - figPadding.x - imgFigRightTop.getWidth(), figPadding.y));
×
NEW
566
    imgFigLeftBot.DrawFull(DrawPoint(figPadding.x, screenSize.y - figPadding.y - imgFigLeftBot.getHeight()));
×
NEW
567
    imgFigRightBot.DrawFull(screenSize - figPadding - imgFigRightBot.GetSize());
×
568

NEW
569
    glArchivItem_Bitmap& imgButtonBar = *LOADER.GetImageN("resource", 29);
×
NEW
570
    imgButtonBar.DrawFull(
×
NEW
571
      DrawPoint((screenSize.x - imgButtonBar.getWidth()) / 2, screenSize.y - imgButtonBar.getHeight()));
×
NEW
572
}
×
573

NEW
574
void dskGameInterface::Msg_PaintAfter()
×
575
{
NEW
576
    Desktop::Msg_PaintAfter();
×
577

NEW
578
    const GameWorldBase& world = worldViewer.GetWorld();
×
579

NEW
580
    if(SETTINGS.global.showGFInfo)
×
581
    {
582
        std::array<char, 256> nwf_string;
NEW
583
        if(GAMECLIENT.IsReplayModeOn())
×
584
        {
NEW
585
            snprintf(nwf_string.data(), nwf_string.size(),
×
586
                     _("(Replay-Mode) Current GF: %u (End at: %u) / GF length: %u ms / NWF length: %u gf (%u ms)"),
NEW
587
                     world.GetEvMgr().GetCurrentGF(), GAMECLIENT.GetLastReplayGF(),
×
NEW
588
                     GAMECLIENT.GetGFLength() / FramesInfo::milliseconds32_t(1), GAMECLIENT.GetNWFLength(),
×
NEW
589
                     GAMECLIENT.GetNWFLength() * GAMECLIENT.GetGFLength() / FramesInfo::milliseconds32_t(1));
×
590
        } else
NEW
591
            snprintf(nwf_string.data(), nwf_string.size(),
×
592
                     _("Current GF: %u / GF length: %u ms / NWF length: %u gf (%u ms) /  Ping: %u ms"),
NEW
593
                     world.GetEvMgr().GetCurrentGF(), GAMECLIENT.GetGFLength() / FramesInfo::milliseconds32_t(1),
×
NEW
594
                     GAMECLIENT.GetNWFLength(),
×
NEW
595
                     GAMECLIENT.GetNWFLength() * GAMECLIENT.GetGFLength() / FramesInfo::milliseconds32_t(1),
×
NEW
596
                     worldViewer.GetPlayer().ping);
×
NEW
597
        NormalFont->Draw(DrawPoint(30, 1), nwf_string.data(), FontStyle{}, COLOR_YELLOW);
×
598
    }
599

600
    // tournament mode?
NEW
601
    const unsigned tournamentDuration = GAMECLIENT.GetTournamentModeDuration();
×
NEW
602
    if(tournamentDuration)
×
603
    {
NEW
604
        unsigned curGF = world.GetEvMgr().GetCurrentGF();
×
NEW
605
        std::string tournamentNotice;
×
NEW
606
        if(curGF >= tournamentDuration)
×
NEW
607
            tournamentNotice = _("Tournament finished");
×
608
        else
609
        {
610
            tournamentNotice =
NEW
611
              helpers::format("Tournament mode: %1% remaining", GAMECLIENT.FormatGFTime(tournamentDuration - curGF));
×
612
        }
NEW
613
        NormalFont->Draw(DrawPoint(VIDEODRIVER.GetRenderSize().x - 30, 1), tournamentNotice, FontStyle::AlignH::RIGHT,
×
614
                         COLOR_YELLOW);
615
    }
616

617
    // Replaydateianzeige in der linken unteren Ecke
NEW
618
    if(GAMECLIENT.IsReplayModeOn())
×
619
    {
NEW
620
        NormalFont->Draw(DrawPoint(0, VIDEODRIVER.GetRenderSize().y), GAMECLIENT.GetReplayFilename().string(),
×
621
                         FontStyle::BOTTOM, COLOR_YELLOW);
622
    } else
623
    {
624
        // Laggende Spieler anzeigen in Form von Schnecken
NEW
625
        DrawPoint snailPos(VIDEODRIVER.GetRenderSize().x - 70, 35);
×
NEW
626
        for(const NWFPlayerInfo& player : nwfInfo_->getPlayerInfos())
×
627
        {
NEW
628
            if(player.isLagging)
×
629
            {
NEW
630
                LOADER.GetPlayerImage("rttr", 0)->DrawFull(Rect(snailPos, 30, 30), COLOR_WHITE,
×
NEW
631
                                                           game_->world_.GetPlayer(player.id).color);
×
NEW
632
                snailPos.x -= 40;
×
633
            }
634
        }
635
    }
636

637
    // Show icons in the upper right corner of the game interface
NEW
638
    DrawPoint iconPos(VIDEODRIVER.GetRenderSize().x - 56, 32);
×
639

640
    // Draw cheating indicator icon (WINTER)
NEW
641
    if(cheats_.isCheatModeOn())
×
642
    {
NEW
643
        glArchivItem_Bitmap* cheatingImg = LOADER.GetImageN("io", 75);
×
NEW
644
        cheatingImg->DrawFull(iconPos);
×
NEW
645
        iconPos -= DrawPoint(cheatingImg->getWidth() + 6, 0);
×
646
    }
647

648
    // Draw speed indicator icon
649
    const int speedStep =
NEW
650
      static_cast<int>(SPEED_GF_LENGTHS[referenceSpeed] / 10ms) - static_cast<int>(GAMECLIENT.GetGFLength() / 10ms);
×
651

NEW
652
    if(speedStep != 0)
×
653
    {
NEW
654
        glArchivItem_Bitmap* runnerImg = LOADER.GetImageN("io", 164);
×
655

NEW
656
        runnerImg->DrawFull(iconPos);
×
657

NEW
658
        if(speedStep != 1)
×
659
        {
NEW
660
            std::string multiplier = helpers::toString(std::abs(speedStep));
×
NEW
661
            NormalFont->Draw(iconPos - runnerImg->GetOrigin() + DrawPoint(19, 6), multiplier, FontStyle::LEFT,
×
662
                             speedStep > 0 ? COLOR_YELLOW : COLOR_RED);
663
        }
NEW
664
        iconPos -= DrawPoint(runnerImg->getWidth() + 4, 0);
×
665
    }
666

667
    // Draw zoom level indicator icon
NEW
668
    if(gwv.GetCurrentTargetZoomFactor() != 1.f) //-V550
×
669
    {
NEW
670
        glArchivItem_Bitmap* magnifierImg = LOADER.GetImageN("io", 36);
×
671

NEW
672
        magnifierImg->DrawFull(iconPos);
×
673

NEW
674
        std::string zoom_percent = helpers::toString((int)(gwv.GetCurrentTargetZoomFactor() * 100)) + "%";
×
NEW
675
        NormalFont->Draw(iconPos - magnifierImg->GetOrigin() + DrawPoint(9, 7), zoom_percent, FontStyle::CENTER,
×
676
                         COLOR_YELLOW);
NEW
677
        iconPos -= DrawPoint(magnifierImg->getWidth() + 4, 0);
×
678
    }
NEW
679
}
×
680

681
bool dskGameInterface::Msg_LeftDown(const MouseCoords& mc)
3✔
682
{
683
    DrawPoint btOrig(VIDEODRIVER.GetRenderSize().x / 2 - LOADER.GetImageN("resource", 29)->getWidth() / 2 + 44,
6✔
684
                     VIDEODRIVER.GetRenderSize().y - LOADER.GetImageN("resource", 29)->getHeight() + 4);
9✔
685
    Extent btSize = Extent(37, 32) * 4u;
3✔
686
    if(IsPointInRect(mc.pos, Rect(btOrig, btSize)))
3✔
NEW
687
        return false;
×
688

689
    if(!VIDEODRIVER.IsTouch())
3✔
690
    {
691
        // Start scrolling also on Ctrl + left click
692
        if(VIDEODRIVER.GetModKeyState().ctrl)
3✔
693
        {
694
            Msg_RightDown(mc);
1✔
695
            return true;
1✔
696
        } else if(isScrolling)
2✔
697
            StopScrolling();
2✔
698

699
        return ContextClick(mc);
2✔
700

NEW
701
    } else if(mc.num_tfingers < 2)
×
NEW
702
        touchDuration = VIDEODRIVER.GetTickCount();
×
NEW
703
    else if(isScrolling) // 2 fingers down -> zoom mode. Do not click or scroll map
×
NEW
704
        StopScrolling();
×
705

UNCOV
706
    return true;
×
707
}
708

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

717
    // num_tfingers is reduced after this function to check if it's still a touch event
718
    // Was touch duration short enough to trigger conext click?
719
    if(mc.num_tfingers == 1 && (VIDEODRIVER.GetTickCount() - touchDuration) < TOUCH_MAX_CLICK_INTERVAL)
1✔
NEW
720
        return ContextClick(mc);
×
721

722
    return false;
1✔
723
}
724

725
bool dskGameInterface::Msg_MouseMove(const MouseCoords& mc)
21✔
726
{
727
    if(!isScrolling)
21✔
728
    {
729
        if(mc.num_tfingers == 1)
12✔
NEW
730
            Msg_RightDown(mc);
×
731
        else
732
            return false;
12✔
733
    }
734

735
    if(SETTINGS.interface.mapScrollMode == MapScrollMode::GrabAndDrag)
9✔
736
    {
737
        const Position mapPos = gwv.ViewPosToMap(mc.pos);
1✔
738
        gwv.MoveBy(-(mapPos - startScrollPt));
1✔
739
        startScrollPt = mapPos;
1✔
740
    } else
741
    {
742
        int acceleration = SETTINGS.global.smartCursor ? 2 : 3;
8✔
743

744
        if(SETTINGS.interface.mapScrollMode == MapScrollMode::ScrollSame)
8✔
745
            acceleration = -acceleration;
1✔
746

747
        gwv.MoveBy((mc.pos - startScrollPt) * acceleration);
8✔
748
        VIDEODRIVER.SetMousePos(startScrollPt);
8✔
749

750
        if(!SETTINGS.global.smartCursor)
8✔
NEW
751
            startScrollPt = mc.pos;
×
752
    }
753

754
    return true;
9✔
755
}
756

757
bool dskGameInterface::Msg_RightDown(const MouseCoords& mc)
13✔
758
{
759
    if(SETTINGS.interface.mapScrollMode == MapScrollMode::GrabAndDrag)
13✔
760
        StartScrolling(gwv.ViewPosToMap(mc.pos));
2✔
761
    else
762
        StartScrolling(mc.pos);
11✔
763
    return true;
13✔
764
}
765

766
bool dskGameInterface::Msg_RightUp(const MouseCoords& /*mc*/) //-V524
4✔
767
{
768
    if(isScrolling)
4✔
769
        StopScrolling();
4✔
770
    return false;
4✔
771
}
772

773
/**
774
 *  Druck von Spezialtasten auswerten.
775
 */
776
bool dskGameInterface::Msg_KeyDown(const KeyEvent& ke)
2✔
777
{
778
    cheatCommandTracker_.onKeyEvent(ke);
2✔
779

780
    switch(ke.kt)
2✔
781
    {
782
        default: break;
2✔
783
        case KeyType::Return: // Chatfenster öffnen
×
784
            WINDOWMANAGER.Show(std::make_unique<iwChat>(this));
×
785
            return true;
×
786

787
        case KeyType::Space: // Bauqualitäten anzeigen
×
788
            gwv.ToggleShowBQ();
×
789
            return true;
×
790

791
        case KeyType::Left: // Nach Links Scrollen
×
792
            gwv.MoveBy({-30, 0});
×
793
            return true;
×
794
        case KeyType::Right: // Nach Rechts Scrollen
×
795
            gwv.MoveBy({30, 0});
×
796
            return true;
×
797
        case KeyType::Up: // Nach Oben Scrollen
×
798
            gwv.MoveBy({0, -30});
×
799
            return true;
×
800
        case KeyType::Down: // Nach Unten Scrollen
×
801
            gwv.MoveBy({0, 30});
×
802
            return true;
×
803

804
        case KeyType::F2: // Spiel speichern
×
805
            WINDOWMANAGER.ToggleWindow(std::make_unique<iwSave>());
×
806
            return true;
×
807
        case KeyType::F3: // Map debug window/ Multiplayer coordinates
×
808
        {
809
            const bool replayMode = GAMECLIENT.IsReplayModeOn();
×
810
            if(replayMode)
×
811
                DisableFoW(true);
×
812
            WINDOWMANAGER.ToggleWindow(std::make_unique<iwMapDebug>(gwv, game_->world_.IsSinglePlayer() || replayMode));
×
813
            return true;
×
814
        }
815
        case KeyType::F8: // Tastaturbelegung
×
816
            WINDOWMANAGER.ToggleWindow(std::make_unique<iwTextfile>("keyboardlayout.txt", _("Keyboard layout")));
×
817
            return true;
×
818
        case KeyType::F9: // Readme
×
819
            WINDOWMANAGER.ToggleWindow(std::make_unique<iwTextfile>("readme.txt", _("Readme!")));
×
820
            return true;
×
821
        case KeyType::F11: // Music player (midi files)
×
822
            WINDOWMANAGER.ToggleWindow(std::make_unique<iwMusicPlayer>());
×
823
            return true;
×
824
        case KeyType::F12: // Optionsfenster
×
825
            WINDOWMANAGER.ToggleWindow(std::make_unique<iwOptionsWindow>(gwv.GetSoundMgr()));
×
826
            return true;
×
827
    }
828

829
    switch(ke.c)
2✔
830
    {
831
        case '+':
×
832
            if(GAMECLIENT.IsReplayModeOn() || game_->world_.IsSinglePlayer())
×
833
                GAMECLIENT.IncreaseSpeed();
×
834
            return true;
×
835
        case '-':
×
836
            if(GAMECLIENT.IsReplayModeOn() || game_->world_.IsSinglePlayer())
×
837
                GAMECLIENT.DecreaseSpeed();
×
838
            return true;
×
839

840
        case '1':
×
841
        case '2':
842
        case '3': // Spieler umschalten
843
        case '4':
844
        case '5':
845
        case '6':
846
        case '7':
847
        case '8':
848
        {
849
            unsigned playerIdx = ke.c - '1';
×
850
            if(GAMECLIENT.IsReplayModeOn())
×
851
            {
852
                unsigned oldPlayerId = worldViewer.GetPlayerId();
×
853
                GAMECLIENT.ChangePlayerIngame(worldViewer.GetPlayerId(), playerIdx);
×
854
                RTTR_Assert(worldViewer.GetPlayerId() == oldPlayerId || worldViewer.GetPlayerId() == playerIdx);
×
855
            } else if(playerIdx < worldViewer.GetWorld().GetNumPlayers())
×
856
            {
857
                // On mutiplayer this currently asyncs, but as this is a debug feature anyway just disable it there.
858
                // If this should be enabled again, look into the handling/clearing of accumulated GCs
859
                if(game_->world_.IsSinglePlayer())
×
860
                {
861
                    const GamePlayer& player = worldViewer.GetWorld().GetPlayer(playerIdx);
×
862
                    if(player.ps == PlayerState::AI && player.aiInfo.type == AI::Type::Dummy)
×
863
                        GAMECLIENT.RequestSwapToPlayer(playerIdx);
×
864
                }
865
            }
866
            return true;
×
867
        }
868

869
        case 'b': // Zur lezten Position zurückspringen
×
870
            gwv.MoveToLastPosition();
×
871
            return true;
×
872
        case 'v':
×
873
            if(game_->world_.IsSinglePlayer())
×
874
                GAMECLIENT.IncreaseSpeed();
×
875
            return true;
×
876
        case 'c': // Gebäudenamen anzeigen
×
877
            gwv.ToggleShowNames();
×
878
            return true;
×
879
        case 'd': // Replay: FoW an/ausschalten
×
880
            ToggleFoW();
×
881
            return true;
×
882
        case 'h': // Zum HQ springen
×
883
        {
884
            const GamePlayer& player = worldViewer.GetPlayer();
×
885
            // Prüfen, ob dieses überhaupt noch existiert
886
            if(player.GetHQPos().isValid())
×
887
                gwv.MoveToMapPt(player.GetHQPos());
×
888
        }
889
            return true;
×
890
        case 'i': // Show inventory
×
891
            WINDOWMANAGER.ToggleWindow(std::make_unique<iwInventory>(worldViewer.GetPlayer()));
×
892
            return true;
×
893
        case 'j': // GFs überspringen
×
894
            if(game_->world_.IsSinglePlayer() || GAMECLIENT.IsReplayModeOn())
×
895
                WINDOWMANAGER.ToggleWindow(std::make_unique<iwSkipGFs>(gwv));
×
896
            return true;
×
897
        case 'l': // Minimap anzeigen
×
898
            WINDOWMANAGER.ToggleWindow(std::make_unique<iwMinimap>(minimap, gwv));
×
899
            return true;
×
900
        case 'm': // Hauptauswahl
2✔
901
            WINDOWMANAGER.ToggleWindow(std::make_unique<iwMainMenu>(gwv, GAMECLIENT));
2✔
902
            return true;
2✔
903
        case 'n': // Show Post window
×
904
            WINDOWMANAGER.ToggleWindow(std::make_unique<iwPostWindow>(gwv, GetPostBox()));
×
905
            UpdatePostIcon(GetPostBox().GetNumMsgs(), false);
×
906
            return true;
×
907
        case 'p': // Pause
×
908
            GAMECLIENT.TogglePause();
×
909
            return true;
×
910
        case 'q': // Spiel verlassen
×
911
            if(ke.alt)
×
912
                WINDOWMANAGER.ToggleWindow(std::make_unique<iwEndgame>());
×
913
            return true;
×
914
        case 's': // Produktivität anzeigen
×
915
            gwv.ToggleShowProductivity();
×
916
            return true;
×
917
        case 26: // ctrl+z
×
918
            gwv.SetZoomFactor(ZOOM_FACTORS[ZOOM_DEFAULT_INDEX]);
×
919
            return true;
×
920
        case 'z': // zoom
×
921
            if(++zoomLvl >= ZOOM_FACTORS.size())
×
922
                zoomLvl = 0;
×
923

924
            gwv.SetZoomFactor(ZOOM_FACTORS[zoomLvl]);
×
925
            return true;
×
926
        case 'Z': // shift-z, reverse zoom
×
927
            if(zoomLvl == 0)
×
928
                zoomLvl = ZOOM_FACTORS.size() - 1;
×
929
            else
930
                zoomLvl--;
×
931

932
            gwv.SetZoomFactor(ZOOM_FACTORS[zoomLvl]);
×
933
            return true;
×
934
    }
935

936
    return false;
×
937
}
938

939
bool dskGameInterface::Msg_WheelUp(const MouseCoords&)
×
940
{
941
    WheelZoom(ZOOM_WHEEL_INCREMENT);
×
942
    return true;
×
943
}
944
bool dskGameInterface::Msg_WheelDown(const MouseCoords&)
×
945
{
946
    WheelZoom(-ZOOM_WHEEL_INCREMENT);
×
947
    return true;
×
948
}
949

950
void dskGameInterface::WheelZoom(float step)
×
951
{
952
    float new_zoom = gwv.GetCurrentTargetZoomFactor() * (1 + step);
×
953
    gwv.SetZoomFactor(new_zoom);
×
954

955
    // also keep track in terms of fixed defined zoom levels
956
    zoomLvl = ZOOM_DEFAULT_INDEX;
×
957
    for(size_t i = ZOOM_DEFAULT_INDEX; i < ZOOM_FACTORS.size(); ++i)
×
958
    {
959
        if(ZOOM_FACTORS[i] < new_zoom)
×
960
            zoomLvl = i;
×
961
    }
962

963
    for(size_t i = ZOOM_DEFAULT_INDEX; i-- > 0;)
×
964
    {
965
        if(ZOOM_FACTORS[i] > new_zoom)
×
966
            zoomLvl = i;
×
967
    }
968
}
×
969

970
void dskGameInterface::OnBuildingNote(const BuildingNote& note)
×
971
{
972
    switch(note.type)
×
973
    {
974
        case BuildingNote::Constructed:
×
975
        case BuildingNote::Destroyed:
976
        case BuildingNote::Lost:
977
            // Close the related window as the building does not exist anymore
978
            // In "Constructed" this means the buildingsite
979
            WINDOWMANAGER.Close(CGI_BUILDING + MapBase::CreateGUIID(note.pos));
×
980
            break;
×
981
        default: break;
×
982
    }
983
}
×
984

985
void dskGameInterface::Run()
×
986
{
987
    // Reset draw counter of the trees before drawing
988
    noTree::ResetDrawCounter();
×
989

990
    unsigned water_percent;
991
    // Draw mouse only if not on window
992
    bool drawMouse = WINDOWMANAGER.FindWindowAtPos(VIDEODRIVER.GetMousePos()) == nullptr;
×
993
    gwv.Draw(road, actionwindow != nullptr ? actionwindow->GetSelectedPt() : MapPoint::Invalid(), drawMouse,
×
994
             &water_percent);
995

996
    // Indicate that the game is paused by darkening the screen (dark semi-transparent overlay)
997
    if(GAMECLIENT.IsPaused())
×
998
        DrawRectangle(Rect(DrawPoint(0, 0), VIDEODRIVER.GetRenderSize()), COLOR_SHADOW);
×
999
    else
1000
    {
1001
        // Play ambient sounds if game is not paused
1002
        worldViewer.GetSoundMgr().playOceanBrawling(water_percent);
×
1003
        worldViewer.GetSoundMgr().playBirdSounds(noTree::QueryDrawCounter());
×
1004
    }
1005

1006
    messenger.Draw();
×
1007
}
×
1008

1009
void dskGameInterface::GI_StartRoadBuilding(const MapPoint startPt, bool waterRoad)
3✔
1010
{
1011
    // Im Replay keine Straßen bauen
1012
    if(GAMECLIENT.IsReplayModeOn())
3✔
1013
        return;
×
1014

1015
    road.mode = waterRoad ? RoadBuildMode::Boat : RoadBuildMode::Normal;
3✔
1016
    road.route.clear();
3✔
1017
    road.start = road.point = startPt;
3✔
1018
    WINDOWMANAGER.SetCursor(Cursor::Remove);
3✔
1019
}
1020

1021
void dskGameInterface::GI_CancelRoadBuilding()
2✔
1022
{
1023
    if(road.mode == RoadBuildMode::Disabled)
2✔
1024
        return;
×
1025
    road.mode = RoadBuildMode::Disabled;
2✔
1026
    worldViewer.RemoveVisualRoad(road.start, road.route);
2✔
1027
    WINDOWMANAGER.SetCursor(isScrolling ? Cursor::Scroll : Cursor::Hand);
2✔
1028
}
1029

1030
bool dskGameInterface::BuildRoadPart(MapPoint& cSel)
3✔
1031
{
1032
    std::vector<Direction> new_route =
1033
      FindPathForRoad(worldViewer, road.point, cSel, road.mode == RoadBuildMode::Boat, 100);
6✔
1034
    // Weg gefunden?
1035
    if(new_route.empty())
3✔
1036
        return false;
×
1037

1038
    // Test on water way length
1039
    if(road.mode == RoadBuildMode::Boat)
3✔
1040
    {
1041
        unsigned char index = worldViewer.GetWorld().GetGGS().getSelection(AddonId::MAX_WATERWAY_LENGTH);
×
1042

1043
        RTTR_Assert(index < waterwayLengths.size());
×
1044
        const unsigned max_length = waterwayLengths[index];
×
1045

1046
        unsigned length = road.route.size() + new_route.size();
×
1047

1048
        // max_length == 0 heißt beliebig lang, ansonsten
1049
        // Weg zurechtstutzen.
1050
        if(max_length > 0)
×
1051
        {
1052
            while(length > max_length)
×
1053
            {
1054
                new_route.pop_back();
×
1055
                --length;
×
1056
            }
1057
        }
1058
    }
1059

1060
    // Weg (visuell) bauen
1061
    for(const auto dir : new_route)
22✔
1062
    {
1063
        worldViewer.SetVisiblePointRoad(road.point, dir,
19✔
1064
                                        (road.mode == RoadBuildMode::Boat) ? PointRoad::Boat : PointRoad::Normal);
19✔
1065
        worldViewer.RecalcBQForRoad(road.point);
19✔
1066
        road.point = worldViewer.GetWorld().GetNeighbour(road.point, dir);
19✔
1067
    }
1068
    worldViewer.RecalcBQForRoad(road.point);
3✔
1069

1070
    // Zielpunkt updaten (für Wasserweg)
1071
    cSel = road.point;
3✔
1072

1073
    road.route.insert(road.route.end(), new_route.begin(), new_route.end());
3✔
1074

1075
    return true;
3✔
1076
}
1077

1078
unsigned dskGameInterface::GetIdInCurBuildRoad(const MapPoint pt)
1✔
1079
{
1080
    MapPoint curPt = road.start;
1✔
1081
    for(unsigned i = 0; i < road.route.size(); ++i)
2✔
1082
    {
1083
        if(curPt == pt)
2✔
1084
            return i + 1;
1✔
1085

1086
        curPt = worldViewer.GetNeighbour(curPt, road.route[i]);
1✔
1087
    }
1088
    return 0;
×
1089
}
1090

1091
void dskGameInterface::ShowRoadWindow(const Position& mousePos)
×
1092
{
1093
    roadwindow = &WINDOWMANAGER.Show(
×
1094
      std::make_unique<iwRoadWindow>(*this, worldViewer.GetBQ(road.point) != BuildingQuality::Nothing, mousePos), true);
×
1095
}
×
1096

1097
void dskGameInterface::ShowActionWindow(const iwAction::Tabs& action_tabs, MapPoint cSel, const DrawPoint& mousePos,
2✔
1098
                                        const bool enable_military_buildings)
1099
{
1100
    const GameWorldBase& world = worldViewer.GetWorld();
2✔
1101

1102
    iwAction::Params params;
2✔
1103

1104
    // Sind wir am Wasser?
1105
    if(action_tabs.setflag)
2✔
1106
    {
1107
        auto isWater = [](const auto& desc) { return desc.kind == TerrainKind::Water; };
6✔
1108
        if(world.HasTerrain(cSel, isWater))
1✔
1109
            params = iwAction::FlagType::WaterFlag;
×
1110
    }
1111

1112
    // Wenn es einen Flaggen-Tab gibt, dann den Flaggentyp herausfinden und die Art des Fensters entsprechende setzen
1113
    if(action_tabs.flag)
2✔
1114
    {
1115
        if(world.GetNO(world.GetNeighbour(cSel, Direction::NorthWest))->GetGOT() == GO_Type::NobHq)
×
1116
            params = iwAction::FlagType::HQ;
×
1117
        else if(world.GetNO(cSel)->GetType() == NodalObjectType::Flag)
×
1118
        {
1119
            if(world.GetSpecObj<noFlag>(cSel)->GetFlagType() == FlagType::Water)
×
1120
                params = iwAction::FlagType::WaterFlag;
×
1121
        }
1122
    }
1123

1124
    // Angriffstab muss wissen, wieviel Soldaten maximal entsendet werden können
1125
    if(action_tabs.attack)
2✔
1126
    {
1127
        params = worldViewer.GetNumSoldiersForAttack(cSel);
×
1128
    }
1129

1130
    actionwindow = &WINDOWMANAGER.Show(
2✔
1131
      std::make_unique<iwAction>(*this, gwv, action_tabs, cSel, mousePos, params, enable_military_buildings), true);
2✔
1132
}
2✔
1133

1134
void dskGameInterface::OnChatCommand(const std::string& cmd)
×
1135
{
1136
    cheatCommandTracker_.onChatCommand(cmd);
×
1137

1138
    if(cmd == "surrender")
×
1139
        GAMECLIENT.Surrender();
×
1140
    else if(cmd == "async")
×
1141
        (void)RANDOM.Rand(RANDOM_CONTEXT2(0), 255);
×
1142
    else if(cmd == "segfault")
×
1143
    {
1144
        char* x = nullptr;
×
1145
        *x = 1; //-V522 // NOLINT
×
1146
    } else if(cmd == "reload")
×
1147
    {
1148
        WorldDescription newDesc;
×
1149
        GameDataLoader gdLoader(newDesc);
×
1150
        if(gdLoader.Load())
×
1151
        {
1152
            const_cast<GameWorld&>(game_->world_).GetDescriptionWriteable() = newDesc;
×
1153
            worldViewer.InitTerrainRenderer();
×
1154
        }
1155
    }
1156
}
×
1157

1158
void dskGameInterface::GI_BuildRoad()
×
1159
{
1160
    if(GAMECLIENT.BuildRoad(road.start, road.mode == RoadBuildMode::Boat, road.route))
×
1161
    {
1162
        road.mode = RoadBuildMode::Disabled;
×
1163
        WINDOWMANAGER.SetCursor(Cursor::Hand);
×
1164
    }
1165
}
×
1166

1167
void dskGameInterface::Msg_WindowClosed(IngameWindow& wnd)
2✔
1168
{
1169
    if(actionwindow == &wnd)
2✔
1170
        actionwindow = nullptr;
1✔
1171
    else if(roadwindow == &wnd)
1✔
1172
        roadwindow = nullptr;
×
1173
}
2✔
1174

1175
void dskGameInterface::GI_FlagDestroyed(const MapPoint pt)
×
1176
{
1177
    // Im Wegbaumodus und haben wir von hier eine Flagge gebaut?
1178
    if(road.mode != RoadBuildMode::Disabled && road.start == pt)
×
1179
    {
1180
        GI_CancelRoadBuilding();
×
1181
    }
1182

1183
    // Evtl Actionfenster schließen, da sich das ja auch auf diese Flagge bezieht
1184
    if(actionwindow)
×
1185
    {
1186
        if(actionwindow->GetSelectedPt() == pt)
×
1187
            actionwindow->Close();
×
1188
    }
1189
}
×
1190

1191
void dskGameInterface::CI_PlayerLeft(const unsigned playerId)
×
1192
{
1193
    // Info-Meldung ausgeben
1194
    std::string text =
1195
      helpers::format(_("Player '%s' left the game!"), worldViewer.GetWorld().GetPlayer(playerId).name);
×
1196
    messenger.AddMessage("", 0, ChatDestination::System, text, COLOR_RED);
×
1197
    // Im Spiel anzeigen, dass die KI das Spiel betreten hat
1198
    text = helpers::format(_("Player '%s' joined the game!"), "KI");
×
1199
    messenger.AddMessage("", 0, ChatDestination::System, text, COLOR_GREEN);
×
1200
}
×
1201

1202
void dskGameInterface::CI_GGSChanged(const GlobalGameSettings& /*ggs*/)
×
1203
{
1204
    // TODO: print what has changed
1205
    const std::string text = helpers::format(_("Note: Game settings changed by the server%s"), "");
×
1206
    messenger.AddMessage("", 0, ChatDestination::System, text);
×
1207
}
×
1208

1209
void dskGameInterface::CI_Chat(const unsigned playerId, const ChatDestination cd, const std::string& msg)
×
1210
{
1211
    messenger.AddMessage(worldViewer.GetWorld().GetPlayer(playerId).name,
×
1212
                         worldViewer.GetWorld().GetPlayer(playerId).color, cd, msg);
×
1213
}
×
1214

1215
void dskGameInterface::CI_Async(const std::string& checksums_list)
×
1216
{
1217
    messenger.AddMessage("", 0, ChatDestination::System,
×
1218
                         _("The Game is not in sync. Checksums of some players don't match."), COLOR_RED);
1219
    messenger.AddMessage("", 0, ChatDestination::System, checksums_list, COLOR_YELLOW);
×
1220
    messenger.AddMessage("", 0, ChatDestination::System, _("A auto-savegame is created..."), COLOR_RED);
×
1221
}
×
1222

1223
void dskGameInterface::CI_ReplayAsync(const std::string& msg)
×
1224
{
1225
    messenger.AddMessage("", 0, ChatDestination::System, msg, COLOR_RED);
×
1226
}
×
1227

1228
void dskGameInterface::CI_ReplayEndReached(const std::string& msg)
×
1229
{
1230
    messenger.AddMessage("", 0, ChatDestination::System, msg, COLOR_BLUE);
×
1231
}
×
1232

1233
void dskGameInterface::CI_GamePaused()
×
1234
{
1235
    messenger.AddMessage(_("SYSTEM"), COLOR_GREY, ChatDestination::System, _("Game was paused."));
×
1236
}
×
1237

1238
void dskGameInterface::CI_GameResumed()
×
1239
{
1240
    messenger.AddMessage(_("SYSTEM"), COLOR_GREY, ChatDestination::System, _("Game was resumed."));
×
1241
}
×
1242

1243
void dskGameInterface::CI_Error(const ClientError ce)
×
1244
{
1245
    messenger.AddMessage("", 0, ChatDestination::System, ClientErrorToStr(ce), COLOR_RED);
×
1246
    GAMECLIENT.SetPause(true);
×
1247
}
×
1248

1249
/**
1250
 *  Status: Verbindung verloren.
1251
 */
1252
void dskGameInterface::LC_Status_ConnectionLost()
×
1253
{
1254
    messenger.AddMessage("", 0, ChatDestination::System, _("Lost connection to lobby!"), COLOR_RED);
×
1255
}
×
1256

1257
/**
1258
 *  (Lobby-)Status: Benutzerdefinierter Fehler
1259
 */
1260
void dskGameInterface::LC_Status_Error(const std::string& error)
×
1261
{
1262
    messenger.AddMessage("", 0, ChatDestination::System, error, COLOR_RED);
×
1263
}
×
1264

1265
void dskGameInterface::CI_PlayersSwapped(const unsigned player1, const unsigned player2)
×
1266
{
1267
    // Meldung anzeigen
1268
    std::string text = "Player '" + worldViewer.GetWorld().GetPlayer(player1).name + "' switched to player '"
×
1269
                       + worldViewer.GetWorld().GetPlayer(player2).name + "'";
×
1270
    messenger.AddMessage("", 0, ChatDestination::System, text, COLOR_YELLOW);
×
1271

1272
    // Sichtbarkeiten und Minimap neu berechnen, wenn wir ein von den beiden Spielern sind
1273
    const unsigned localPlayerId = worldViewer.GetPlayerId();
×
1274
    if(player1 == localPlayerId || player2 == localPlayerId)
×
1275
    {
1276
        worldViewer.ChangePlayer(player1 == localPlayerId ? player2 : player1);
×
1277
        // Set visual settings back to the actual ones
1278
        GAMECLIENT.ResetVisualSettings();
×
1279
        minimap.UpdateAll();
×
1280
        InitPlayer();
×
1281
    }
1282
}
×
1283

1284
/**
1285
 *  Wenn ein Spieler verloren hat
1286
 */
1287
void dskGameInterface::GI_PlayerDefeated(const unsigned playerId)
×
1288
{
1289
    const std::string text =
1290
      helpers::format(_("Player '%s' was defeated!"), worldViewer.GetWorld().GetPlayer(playerId).name);
×
1291
    messenger.AddMessage("", 0, ChatDestination::System, text, COLOR_ORANGE);
×
1292

1293
    /// Lokaler Spieler?
1294
    if(playerId == worldViewer.GetPlayerId())
×
1295
    {
1296
        /// Sichtbarkeiten neu berechnen
1297
        worldViewer.RecalcAllColors();
×
1298
        // Minimap updaten
1299
        minimap.UpdateAll();
×
1300
    }
1301
}
×
1302

1303
void dskGameInterface::GI_UpdateMinimap(const MapPoint pt)
×
1304
{
1305
    // Minimap Bescheid sagen
1306
    minimap.UpdateNode(pt);
×
1307
}
×
1308

1309
void dskGameInterface::GI_UpdateMapVisibility()
×
1310
{
1311
    // recalculate visibility
1312
    worldViewer.RecalcAllColors();
×
1313
    // update minimap
1314
    minimap.UpdateAll();
×
1315
}
×
1316

1317
/**
1318
 *  Bündnisvertrag wurde abgeschlossen oder abgebrochen --> Minimap updaten
1319
 */
1320
void dskGameInterface::GI_TreatyOfAllianceChanged(unsigned playerId)
×
1321
{
1322
    // Nur wenn Team-Sicht aktiviert ist, können sihc die Sichtbarkeiten auch ändern
1323
    if(playerId == worldViewer.GetPlayerId() && worldViewer.GetWorld().GetGGS().teamView)
×
1324
    {
1325
        /// Sichtbarkeiten neu berechnen
1326
        worldViewer.RecalcAllColors();
×
1327
        // Minimap updaten
1328
        minimap.UpdateAll();
×
1329
    }
1330
}
×
1331

1332
/**
1333
 *  Baut Weg zurück von Ende bis zu start_id
1334
 */
1335
void dskGameInterface::DemolishRoad(const unsigned start_id)
1✔
1336
{
1337
    RTTR_Assert(start_id > 0);
1✔
1338
    for(unsigned i = road.route.size(); i >= start_id; --i)
6✔
1339
    {
1340
        MapPoint t = road.point;
5✔
1341
        road.point = worldViewer.GetWorld().GetNeighbour(road.point, road.route[i - 1] + 3u);
5✔
1342
        worldViewer.SetVisiblePointRoad(road.point, road.route[i - 1], PointRoad::None);
5✔
1343
        worldViewer.RecalcBQForRoad(t);
5✔
1344
    }
1345

1346
    road.route.resize(start_id - 1);
1✔
1347
}
1✔
1348

1349
/**
1350
 *  Updatet das Post-Icon mit der Nachrichtenanzahl und der Taube
1351
 */
1352
void dskGameInterface::UpdatePostIcon(const unsigned postmessages_count, bool showPigeon)
5✔
1353
{
1354
    // Taube setzen oder nicht (Post)
1355
    if(postmessages_count == 0 || !showPigeon)
5✔
1356
        GetCtrl<ctrlImageButton>(3)->SetImage(LOADER.GetImageN("io", 62));
10✔
1357
    else
1358
        GetCtrl<ctrlImageButton>(3)->SetImage(LOADER.GetImageN("io", 59));
×
1359

1360
    // und Anzahl der Postnachrichten aktualisieren
1361
    if(postmessages_count > 0)
5✔
1362
    {
1363
        GetCtrl<ctrlText>(ID_txtNumMsg)->SetText(std::to_string(postmessages_count));
×
1364
    } else
1365
        GetCtrl<ctrlText>(ID_txtNumMsg)->SetText("");
5✔
1366
}
5✔
1367

1368
/**
1369
 *  Neue Post-Nachricht eingetroffen
1370
 */
1371
void dskGameInterface::NewPostMessage(const PostMsg& msg, const unsigned msgCt)
×
1372
{
1373
    UpdatePostIcon(msgCt, true);
×
1374
    SoundEffect soundEffect = msg.GetSoundEffect();
×
1375
    switch(soundEffect)
×
1376
    {
1377
        case SoundEffect::Pidgeon: LOADER.GetSoundN("sound", 114)->Play(100, false); break;
×
1378
        case SoundEffect::Fanfare: LOADER.GetSoundN("sound", 110)->Play(100, false);
×
1379
    }
1380
}
×
1381

1382
/**
1383
 *  Es wurde eine Postnachricht vom Spieler gelöscht
1384
 */
1385
void dskGameInterface::PostMessageDeleted(const unsigned msgCt)
×
1386
{
1387
    UpdatePostIcon(msgCt, false);
×
1388
}
×
1389

1390
/**
1391
 *  Ein Spieler hat das Spiel gewonnen.
1392
 */
1393
void dskGameInterface::GI_Winner(const unsigned playerId)
×
1394
{
1395
    const std::string name = worldViewer.GetWorld().GetPlayer(playerId).name;
×
1396
    const std::string text = (boost::format(_("Player '%s' is the winner!")) % name).str();
×
1397
    messenger.AddMessage("", 0, ChatDestination::System, text, COLOR_ORANGE);
×
1398
    WINDOWMANAGER.Show(std::make_unique<iwVictory>(std::vector<std::string>(1, name)));
×
1399
}
×
1400

1401
/**
1402
 *  Ein Team hat das Spiel gewonnen.
1403
 */
1404
void dskGameInterface::GI_TeamWinner(const unsigned playerMask)
×
1405
{
1406
    std::vector<std::string> winners;
×
1407
    const GameWorldBase& world = worldViewer.GetWorld();
×
1408
    for(unsigned i = 0; i < world.GetNumPlayers(); i++)
×
1409
    {
1410
        if(playerMask & (1 << i))
×
1411
            winners.push_back(world.GetPlayer(i).name);
×
1412
    }
1413
    const std::string text =
1414
      (boost::format(_("%1% are the winners!")) % helpers::join(winners, ", ", _(" and "))).str();
×
1415
    messenger.AddMessage("", 0, ChatDestination::System, text, COLOR_ORANGE);
×
1416
    WINDOWMANAGER.Show(std::make_unique<iwVictory>(winners));
×
1417
}
×
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