diff --git a/lib/callback/CGameInfoCallback.cpp b/lib/callback/CGameInfoCallback.cpp index b79612d26..07988d86e 100644 --- a/lib/callback/CGameInfoCallback.cpp +++ b/lib/callback/CGameInfoCallback.cpp @@ -574,7 +574,7 @@ EDiggingStatus CGameInfoCallback::getTileDigStatus(int3 tile, bool verbose) cons return getTile(tile)->getDiggingStatus(); } -EBuildingState CGameInfoCallback::canBuildStructure( const CGTownInstance *t, BuildingID ID ) +EBuildingState CGameInfoCallback::canBuildStructure( const CGTownInstance *t, BuildingID ID ) const { ERROR_RET_VAL_IF(!canGetFullInfo(t), "Town is not owned!", EBuildingState::TOWN_NOT_OWNED); @@ -947,7 +947,7 @@ void CGameInfoCallback::getAllTiles(std::unordered_set & tiles, std::optio } } -void CGameInfoCallback::getAllowedSpells(std::vector & out, std::optional level) +void CGameInfoCallback::getAllowedSpells(std::vector & out, std::optional level) const { for (auto const & spellID : gameState().getMap().allowedSpells) { diff --git a/lib/callback/CGameInfoCallback.h b/lib/callback/CGameInfoCallback.h index d9f31b287..a9fbddc91 100644 --- a/lib/callback/CGameInfoCallback.h +++ b/lib/callback/CGameInfoCallback.h @@ -93,7 +93,7 @@ public: int howManyTowns(PlayerColor Player) const; std::vector getAvailableHeroes(const CGObjectInstance * townOrTavern) const; std::string getTavernRumor(const CGObjectInstance * townOrTavern) const; - EBuildingState canBuildStructure(const CGTownInstance *t, BuildingID ID); + EBuildingState canBuildStructure(const CGTownInstance *t, BuildingID ID) const; bool getTownInfo(const CGObjectInstance * town, InfoAboutTown & dest, const CGObjectInstance * selectedObject = nullptr) const; //from gs @@ -115,7 +115,7 @@ public: void getTilesInRange(std::unordered_set & tiles, const int3 & pos, int radius, ETileVisibility mode, std::optional player = std::optional(), int3::EDistanceFormula formula = int3::DIST_2D) const override; void getAllTiles(std::unordered_set &tiles, std::optional player, int level, std::function filter) const override; - void getAllowedSpells(std::vector &out, std::optional level = std::nullopt); + void getAllowedSpells(std::vector &out, std::optional level = std::nullopt) const; #if SCRIPTING_ENABLED virtual scripting::Pool * getGlobalContextPool() const override; diff --git a/lib/gameState/CGameState.cpp b/lib/gameState/CGameState.cpp index e2e75f7e3..7381d9cc4 100644 --- a/lib/gameState/CGameState.cpp +++ b/lib/gameState/CGameState.cpp @@ -1028,7 +1028,7 @@ BattleInfo * CGameState::getBattle(const BattleID & battle) return nullptr; } -BattleField CGameState::battleGetBattlefieldType(int3 tile, vstd::RNG & randomGenerator) +BattleField CGameState::battleGetBattlefieldType(int3 tile, vstd::RNG & randomGenerator) const { assert(tile.isValid()); @@ -1394,7 +1394,7 @@ bool CGameState::checkForStandardLoss(const PlayerColor & player) const return pState.checkVanquished(); } -void CGameState::obtainPlayersStats(SThievesGuildInfo & tgi, int level) +void CGameState::obtainPlayersStats(SThievesGuildInfo & tgi, int level) const { auto playerInactive = [&](const PlayerColor & color) { diff --git a/lib/gameState/CGameState.h b/lib/gameState/CGameState.h index abc033290..71601f9e1 100644 --- a/lib/gameState/CGameState.h +++ b/lib/gameState/CGameState.h @@ -95,7 +95,7 @@ public: HeroTypeID pickNextHeroType(vstd::RNG & randomGenerator, const PlayerColor & owner); void apply(CPackForClient & pack); - BattleField battleGetBattlefieldType(int3 tile, vstd::RNG & randomGenerator); + BattleField battleGetBattlefieldType(int3 tile, vstd::RNG & randomGenerator) const; PlayerRelations getPlayerRelations(PlayerColor color1, PlayerColor color2) const override; void calculatePaths(const std::shared_ptr & config) const override; @@ -123,7 +123,8 @@ public: PlayerColor checkForStandardWin() const; //returns color of player that accomplished standard victory conditions or 255 (NEUTRAL) if no winner bool checkForStandardLoss(const PlayerColor & player) const; //checks if given player lost the game - void obtainPlayersStats(SThievesGuildInfo & tgi, int level); //fills tgi with info about other players that is available at given level of thieves' guild + //fills tgi with info about other players that is available at given level of thieves' guild + void obtainPlayersStats(SThievesGuildInfo & tgi, int level) const; const IGameSettings & getSettings() const override; StartInfo * getStartInfo() diff --git a/lib/gameState/GameStatistics.cpp b/lib/gameState/GameStatistics.cpp index 4fc84edd0..87d24fa89 100644 --- a/lib/gameState/GameStatistics.cpp +++ b/lib/gameState/GameStatistics.cpp @@ -79,7 +79,7 @@ StatisticDataSetEntry StatisticDataSet::createEntry(const PlayerState * ps, cons return data; } -std::string StatisticDataSet::toCsv(std::string sep) +std::string StatisticDataSet::toCsv(std::string sep) const { std::stringstream ss; @@ -162,7 +162,7 @@ std::string StatisticDataSet::toCsv(std::string sep) for(auto & resource : resources) ss << sep << entry.resources[resource]; for(auto & resource : resources) - ss << sep << entry.numMines[resource]; + ss << sep << entry.numMines.at(resource); for(auto & resource : resources) ss << sep << entry.spentResourcesForArmy[resource]; for(auto & resource : resources) @@ -175,7 +175,7 @@ std::string StatisticDataSet::toCsv(std::string sep) return ss.str(); } -std::string StatisticDataSet::writeCsv() +std::string StatisticDataSet::writeCsv() const { const boost::filesystem::path outPath = VCMIDirs::get().userCachePath() / "statistic"; boost::filesystem::create_directories(outPath); diff --git a/lib/gameState/GameStatistics.h b/lib/gameState/GameStatistics.h index d8626cfc5..67bad5282 100644 --- a/lib/gameState/GameStatistics.h +++ b/lib/gameState/GameStatistics.h @@ -102,8 +102,8 @@ class DLL_LINKAGE StatisticDataSet public: void add(StatisticDataSetEntry entry); static StatisticDataSetEntry createEntry(const PlayerState * ps, const CGameState * gs); - std::string toCsv(std::string sep); - std::string writeCsv(); + std::string toCsv(std::string sep) const; + std::string writeCsv() const; struct PlayerAccumulatedValueStorage // holds some actual values needed for stats { diff --git a/lib/mapping/CMap.cpp b/lib/mapping/CMap.cpp index 29c71def3..d215419e7 100644 --- a/lib/mapping/CMap.cpp +++ b/lib/mapping/CMap.cpp @@ -868,12 +868,12 @@ const CArtifactInstance * CMap::getArtifactInstance(const ArtifactInstanceID & a return artInstances.at(artifactID.getNum()).get(); } -const std::vector & CMap::getAllTowns() +const std::vector & CMap::getAllTowns() const { return towns; } -const std::vector & CMap::getHeroesOnMap() +const std::vector & CMap::getHeroesOnMap() const { return heroesOnMap; } diff --git a/lib/mapping/CMap.h b/lib/mapping/CMap.h index 44d534c5c..ed7440859 100644 --- a/lib/mapping/CMap.h +++ b/lib/mapping/CMap.h @@ -236,10 +236,10 @@ public: /// Returns ID's of all heroes that are currently present on map /// Includes all garrisoned and imprisoned heroes - const std::vector & getHeroesOnMap(); + const std::vector & getHeroesOnMap() const; /// Returns ID's of all towns present on map - const std::vector & getAllTowns(); + const std::vector & getAllTowns() const; /// Sets the victory/loss condition objectives ?? void checkForObjectives(); diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index b6b08a5d3..7b4db85ef 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -438,10 +438,7 @@ void CGameHandler::handleClientDisconnection(std::shared_ptr c) for(auto & playerConnections : connections) { PlayerColor playerId = playerConnections.first; - const auto * playerSettings = gameState().getStartInfo()->getPlayersSettings(playerId.getNum()); - if(!playerSettings) - continue; - + auto playerConnection = vstd::find(playerConnections.second, c); if(playerConnection == playerConnections.second.end()) continue; @@ -818,8 +815,8 @@ bool CGameHandler::moveHero(ObjectInstanceID hid, int3 dst, EMovementMode moveme const TerrainTile t = *gameInfo().getTile(hmpos); const int3 guardPos = gameState().guardingCreaturePosition(hmpos); - CGObjectInstance * objectToVisit = nullptr; - CGObjectInstance * guardian = nullptr; + const CGObjectInstance * objectToVisit = nullptr; + const CGObjectInstance * guardian = nullptr; if (!t.visitableObjects.empty()) objectToVisit = gameState().getObjInstance(t.visitableObjects.back()); @@ -1003,7 +1000,7 @@ bool CGameHandler::moveHero(ObjectInstanceID hid, int3 dst, EMovementMode moveme // do not visit any other objects, e.g. monoliths to avoid double-teleporting if (objectToVisit) { - if (CGTownInstance * town = dynamic_cast(objectToVisit)) + if (const CGTownInstance * town = dynamic_cast(objectToVisit)) objectVisited(town, h); } @@ -2320,7 +2317,7 @@ bool CGameHandler::razeStructure (ObjectInstanceID tid, BuildingID bid) bool CGameHandler::spellResearch(ObjectInstanceID tid, SpellID spellAtSlot, bool accepted) { - CGTownInstance *t = gameState().getTown(tid); + const CGTownInstance * t = gameState().getTown(tid); if(!gameInfo().getSettings().getBoolean(EGameSettings::TOWNS_SPELL_RESEARCH) && complain("Spell research not allowed!")) return false; @@ -2721,7 +2718,7 @@ bool CGameHandler::bulkMoveArtifacts(const PlayerColor & player, ObjectInstanceI auto & slotsDstSrc = ma.artsPack1; // Temporary fitting set for artifacts. Used to select available slots before sending data. - CArtifactFittingSet artFittingSet(&gameState(), pdstSet->bearerType()); + CArtifactFittingSet artFittingSet(&gameInfo(), pdstSet->bearerType()); auto moveArtifact = [this, &artFittingSet, dstId](const CArtifactInstance * artifact, ArtifactPosition srcSlot, std::vector & slots) -> void @@ -4288,7 +4285,7 @@ std::shared_ptr CGameHandler::createNewObject(const int3 & vis auto handler = LIBRARY->objtypeh->getHandlerFor(objectID, subID); - auto o = handler->create(&gameState(), nullptr); + auto o = handler->create(&gameInfo(), nullptr); handler->configureObject(o.get(), *randomizer); assert(o->ID == objectID); gameState().getMap().generateUniqueInstanceName(o.get()); @@ -4321,7 +4318,7 @@ void CGameHandler::createWanderingMonster(const int3 & visitablePosition, Creatu cre->gainedArtifact = ArtifactID::NONE; cre->identifier = -1; cre->temppower = static_cast(unitSize) * 1000; - cre->addToSlot(SlotID(0), std::make_unique(&gameState(), creature, unitSize)); + cre->addToSlot(SlotID(0), std::make_unique(&gameInfo(), creature, unitSize)); newObject(createdObject, PlayerColor::NEUTRAL); } diff --git a/server/CGameHandler.h b/server/CGameHandler.h index beb6a33e5..a3fcb78ff 100644 --- a/server/CGameHandler.h +++ b/server/CGameHandler.h @@ -11,7 +11,6 @@ #include -#include "../lib/callback/CGameInfoCallback.h" #include "../lib/callback/IGameEventCallback.h" #include "../lib/LoadProgress.h" #include "../lib/ScriptHandler.h" @@ -29,6 +28,8 @@ class EVictoryLossCheckResult; class CRandomGenerator; class GameRandomizer; +struct StartInfo; +struct TerrainTile; struct CPackForServer; struct NewTurn; struct CGarrisonOperationPack; diff --git a/server/battles/BattleProcessor.cpp b/server/battles/BattleProcessor.cpp index 7fa59fa85..e0054e925 100644 --- a/server/battles/BattleProcessor.cpp +++ b/server/battles/BattleProcessor.cpp @@ -175,7 +175,7 @@ BattleID BattleProcessor::setupBattle(int3 tile, BattleSideArraygameState(), tile, terrain, battlefieldType, armies, heroes, layout, town); + bs.info = BattleInfo::setupBattle(&gameHandler->gameInfo(), tile, terrain, battlefieldType, armies, heroes, layout, town); bs.battleID = gameHandler->gameState().nextBattleID; engageIntoBattle(bs.info->getSide(BattleSide::ATTACKER).color); diff --git a/server/processors/NewTurnProcessor.cpp b/server/processors/NewTurnProcessor.cpp index c5e022a14..d6383b92b 100644 --- a/server/processors/NewTurnProcessor.cpp +++ b/server/processors/NewTurnProcessor.cpp @@ -567,7 +567,7 @@ std::vector NewTurnProcessor::updateHeroesManaPoints() for (auto & elem : gameHandler->gameState().players) { - for (CGHeroInstance *h : elem.second.getHeroes()) + for (const CGHeroInstance *h : elem.second.getHeroes()) { int32_t newMana = h->getManaNewTurn(); @@ -584,7 +584,7 @@ std::vector NewTurnProcessor::updateHeroesMovementPoints() for (auto & elem : gameHandler->gameState().players) { - for (CGHeroInstance *h : elem.second.getHeroes()) + for (const CGHeroInstance *h : elem.second.getHeroes()) { auto ti = h->getTurnInfo(1); // NOTE: this code executed when bonuses of previous day not yet updated (this happen in NewTurn::applyGs). See issue 2356 diff --git a/server/queries/MapQueries.cpp b/server/queries/MapQueries.cpp index 56ca4baa3..9db164f82 100644 --- a/server/queries/MapQueries.cpp +++ b/server/queries/MapQueries.cpp @@ -13,6 +13,7 @@ #include "QueriesProcessor.h" #include "../CGameHandler.h" #include "../TurnTimerHandler.h" +#include "../../lib/callback/IGameInfoCallback.h" #include "../../lib/mapObjects/CGHeroInstance.h" #include "../../lib/mapObjects/MiscObjects.h" #include "../../lib/networkPacks/PacksForServer.h"