Skip to content

Commit

Permalink
Move Cheats out of GameWorld and into GameInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
kubaau committed Dec 13, 2024
1 parent 64b1600 commit 0665d3d
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
4 changes: 3 additions & 1 deletion libs/s25main/GameInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include "gameTypes/MapCoordinates.h"

class Window;
class Cheats;

/// Interface, welches vom Spiel angesprocehn werden kann, um beispielsweise GUI wichtige Nachrichten
/// zu übermiteln
Expand Down Expand Up @@ -36,4 +36,6 @@ class GameInterface
virtual void GI_CancelRoadBuilding() = 0;
/// Executes the construction of a road
virtual void GI_BuildRoad() = 0;

virtual Cheats& GI_GetCheats() = 0;
};
7 changes: 4 additions & 3 deletions libs/s25main/desktops/dskGameInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ enum
dskGameInterface::dskGameInterface(std::shared_ptr<Game> game, std::shared_ptr<const NWFInfo> nwfInfo,
unsigned playerIdx, bool initOGL)
: Desktop(nullptr), game_(std::move(game)), nwfInfo_(std::move(nwfInfo)),
cheats_(std::make_unique<Cheats>(const_cast<Game&>(*game_).world_)),
worldViewer(playerIdx, const_cast<Game&>(*game_).world_),
gwv(worldViewer, Position(0, 0), VIDEODRIVER.GetRenderSize()), cbb(*LOADER.GetPaletteN("pal5")),
actionwindow(nullptr), roadwindow(nullptr), minimap(worldViewer), isScrolling(false), zoomLvl(ZOOM_DEFAULT_INDEX)
Expand Down Expand Up @@ -424,7 +425,7 @@ void dskGameInterface::Msg_PaintAfter()
DrawPoint iconPos(VIDEODRIVER.GetRenderSize().x - 56, 32);

// Draw cheating indicator icon (WINTER)
if(world.IsCheatModeOn())
if(GI_GetCheats().isCheatModeOn())
{
glArchivItem_Bitmap* cheatingImg = LOADER.GetImageN("io", 75);
cheatingImg->DrawFull(iconPos);
Expand Down Expand Up @@ -738,7 +739,7 @@ bool dskGameInterface::Msg_RightUp(const MouseCoords& /*mc*/) //-V524
*/
bool dskGameInterface::Msg_KeyDown(const KeyEvent& ke)
{
game_->world_.GetCheats().trackKeyEvent(ke);
GI_GetCheats().trackKeyEvent(ke);

switch(ke.kt)
{
Expand Down Expand Up @@ -1096,7 +1097,7 @@ void dskGameInterface::ShowActionWindow(const iwAction::Tabs& action_tabs, MapPo

void dskGameInterface::OnChatCommand(const std::string& cmd)
{
game_->world_.GetCheats().trackChatCommand(cmd);
GI_GetCheats().trackChatCommand(cmd);

if(cmd == "surrender")
GAMECLIENT.Surrender();
Expand Down
3 changes: 3 additions & 0 deletions libs/s25main/desktops/dskGameInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ class dskGameInterface :
/// Baut die gewünschte bis jetzt noch visuelle Straße (schickt Anfrage an Server)
void GI_BuildRoad() override;

Cheats& GI_GetCheats() override { return *cheats_; }

// Sucht einen Weg von road_point_x/y zu cselx/y und baut ihn ( nur visuell )
// Bei Wasserwegen kann die Reichweite nicht bis zum gewünschten
// Punkt reichen. Dann werden die Zielkoordinaten geändert, daher
Expand Down Expand Up @@ -140,6 +142,7 @@ class dskGameInterface :
PostBox& GetPostBox();
std::shared_ptr<const Game> game_;
std::shared_ptr<const NWFInfo> nwfInfo_;
std::unique_ptr<Cheats> cheats_;
GameWorldViewer worldViewer;
GameWorldView gwv;

Expand Down
11 changes: 8 additions & 3 deletions libs/s25main/world/GameWorldBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "world/GameWorldBase.h"
#include "BQCalculator.h"
#include "Cheats.h"
#include "GameInterface.h"
#include "GamePlayer.h"
#include "GlobalGameSettings.h"
#include "MapGeometry.h"
Expand All @@ -30,8 +31,7 @@

GameWorldBase::GameWorldBase(std::vector<GamePlayer> players, const GlobalGameSettings& gameSettings, EventManager& em)
: roadPathFinder(new RoadPathFinder(*this)), freePathFinder(new FreePathFinder(*this)), players(std::move(players)),
gameSettings(gameSettings), em(em), soundManager(std::make_unique<SoundManager>()), lua(nullptr),
cheats(std::make_unique<Cheats>(*this)), gi(nullptr)
gameSettings(gameSettings), em(em), soundManager(std::make_unique<SoundManager>()), lua(nullptr), gi(nullptr)
{}

GameWorldBase::~GameWorldBase() = default;
Expand Down Expand Up @@ -258,9 +258,14 @@ Position GameWorldBase::GetNodePos(const MapPoint pt) const
return ::GetNodePos(pt, GetNode(pt).altitude);
}

Cheats& GameWorldBase::GetCheats() const
{
return gi->GI_GetCheats();
}

bool GameWorldBase::IsCheatModeOn() const
{
return cheats->isCheatModeOn();
return GetCheats().isCheatModeOn();
}

void GameWorldBase::VisibilityChanged(const MapPoint pt, unsigned player, Visibility /*oldVis*/, Visibility /*newVis*/)
Expand Down
3 changes: 1 addition & 2 deletions libs/s25main/world/GameWorldBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ class GameWorldBase : public World
std::unique_ptr<SoundManager> soundManager;
std::set<MapPoint, MapPointLess> ptsInsideComputerBarriers;
LuaInterfaceGame* lua;
std::unique_ptr<Cheats> cheats;

protected:
/// Interface zum GUI
Expand Down Expand Up @@ -220,7 +219,7 @@ class GameWorldBase : public World
LuaInterfaceGame& GetLua() const { return *lua; }
void SetLua(LuaInterfaceGame* newLua) { lua = newLua; }

Cheats& GetCheats() const { return *cheats; }
Cheats& GetCheats() const;
bool IsCheatModeOn() const;

protected:
Expand Down

0 comments on commit 0665d3d

Please sign in to comment.