From 9af7c63a262b20461f80a2e6225046f7e3cbde9d Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Wed, 10 Jan 2024 21:30:12 +0200 Subject: [PATCH] Fix build --- client/CServerHandler.cpp | 2 +- lib/CHeroHandler.cpp | 15 ++++++++------- lib/VCMI_Lib.cpp | 2 +- lib/VCMI_Lib.h | 2 +- lib/battle/BattleInfo.cpp | 2 +- .../DwellingInstanceConstructor.h | 1 + .../HillFortInstanceConstructor.h | 1 + .../ShipyardInstanceConstructor.h | 1 + lib/modding/ContentTypeHandler.cpp | 2 +- test/game/CGameStateTest.cpp | 5 +---- test/map/CMapEditManagerTest.cpp | 6 +++--- test/map/CMapFormatTest.cpp | 6 +++--- test/map/MapComparer.cpp | 1 + test/mock/mock_MapService.cpp | 6 +++--- test/mock/mock_MapService.h | 4 ++-- test/mock/mock_spells_Mechanics.h | 1 + test/scripting/ScriptFixture.cpp | 2 +- test/spells/effects/CatapultTest.cpp | 8 ++++---- 18 files changed, 35 insertions(+), 32 deletions(-) diff --git a/client/CServerHandler.cpp b/client/CServerHandler.cpp index 6326e7786..302bd9f7e 100644 --- a/client/CServerHandler.cpp +++ b/client/CServerHandler.cpp @@ -642,7 +642,7 @@ void CServerHandler::startGameplay(VCMI_LIB_WRAP_NAMESPACE(CGameState) * gameSta if(CMM) CMM->disable(); - std::swap(client, nextClient);; + std::swap(client, nextClient); highScoreCalc = nullptr; diff --git a/lib/CHeroHandler.cpp b/lib/CHeroHandler.cpp index 3d1ce3482..0fc7b587d 100644 --- a/lib/CHeroHandler.cpp +++ b/lib/CHeroHandler.cpp @@ -157,8 +157,9 @@ bool CHeroClass::isMagicHero() const int CHeroClass::tavernProbability(FactionID faction) const { - if (selectionProbability.count(faction)) - return selectionProbability.at(faction); + auto it = selectionProbability.find(faction); + if (it != selectionProbability.end()) + return it->second; return 0; } @@ -401,9 +402,9 @@ void CHeroClassHandler::afterLoadFinalization() } } - for(auto const & hc : objects) + for(const auto & hc : objects) { - if (!hc->imageMapMale.empty()) + if(!hc->imageMapMale.empty()) { JsonNode templ; templ["animation"].String() = hc->imageMapMale; @@ -539,7 +540,7 @@ static std::vector> createCreatureSpecialty(CreatureID ba { std::set oldTargets = targets; - for (auto const & upgradeSourceID : oldTargets) + for(const auto & upgradeSourceID : oldTargets) { const CCreature * upgradeSource = upgradeSourceID.toCreature(); targets.insert(upgradeSource->upgrades.begin(), upgradeSource->upgrades.end()); @@ -551,7 +552,7 @@ static std::vector> createCreatureSpecialty(CreatureID ba for(CreatureID cid : targets) { - auto const & specCreature = *cid.toCreature(); + const auto & specCreature = *cid.toCreature(); int stepSize = specCreature.getLevel() ? specCreature.getLevel() : 5; { @@ -611,7 +612,7 @@ void CHeroHandler::beforeValidate(JsonNode & object) void CHeroHandler::afterLoadFinalization() { - for (auto const & functor : callAfterLoadFinalization) + for(const auto & functor : callAfterLoadFinalization) functor(); callAfterLoadFinalization.clear(); diff --git a/lib/VCMI_Lib.cpp b/lib/VCMI_Lib.cpp index 45edced97..f1b0a3cfd 100644 --- a/lib/VCMI_Lib.cpp +++ b/lib/VCMI_Lib.cpp @@ -91,7 +91,7 @@ const HeroTypeService * LibClasses::heroTypes() const #if SCRIPTING_ENABLED const scripting::Service * LibClasses::scripts() const { - return scriptHandler; + return scriptHandler.get(); } #endif diff --git a/lib/VCMI_Lib.h b/lib/VCMI_Lib.h index 85bfce994..10cdaecba 100644 --- a/lib/VCMI_Lib.h +++ b/lib/VCMI_Lib.h @@ -101,7 +101,7 @@ public: std::shared_ptr settingsHandler; #if SCRIPTING_ENABLED - scripting::ScriptHandler * scriptHandler; + std::shared_ptr scriptHandler; #endif LibClasses(); //c-tor, loads .lods and NULLs handlers diff --git a/lib/battle/BattleInfo.cpp b/lib/battle/BattleInfo.cpp index d25b81d28..cebbaeeeb 100644 --- a/lib/battle/BattleInfo.cpp +++ b/lib/battle/BattleInfo.cpp @@ -1009,7 +1009,7 @@ scripting::Pool * BattleInfo::getContextPool() const { //this is real battle, use global scripting context pool //TODO: make this line not ugly - return IObjectInterface::cb->getGlobalContextPool(); + return battleGetFightingHero(0)->cb->getGlobalContextPool(); } #endif diff --git a/lib/mapObjectConstructors/DwellingInstanceConstructor.h b/lib/mapObjectConstructors/DwellingInstanceConstructor.h index ee06219be..78d32f60a 100644 --- a/lib/mapObjectConstructors/DwellingInstanceConstructor.h +++ b/lib/mapObjectConstructors/DwellingInstanceConstructor.h @@ -10,6 +10,7 @@ #pragma once #include "CDefaultObjectTypeHandler.h" +#include "../mapObjects/CGDwelling.h" VCMI_LIB_NAMESPACE_BEGIN diff --git a/lib/mapObjectConstructors/HillFortInstanceConstructor.h b/lib/mapObjectConstructors/HillFortInstanceConstructor.h index ace75dd1d..e43ab93c5 100644 --- a/lib/mapObjectConstructors/HillFortInstanceConstructor.h +++ b/lib/mapObjectConstructors/HillFortInstanceConstructor.h @@ -10,6 +10,7 @@ #pragma once #include "CDefaultObjectTypeHandler.h" +#include "../mapObjects/MiscObjects.h" VCMI_LIB_NAMESPACE_BEGIN diff --git a/lib/mapObjectConstructors/ShipyardInstanceConstructor.h b/lib/mapObjectConstructors/ShipyardInstanceConstructor.h index 845bf77b0..334031cd1 100644 --- a/lib/mapObjectConstructors/ShipyardInstanceConstructor.h +++ b/lib/mapObjectConstructors/ShipyardInstanceConstructor.h @@ -10,6 +10,7 @@ #pragma once #include "CDefaultObjectTypeHandler.h" +#include "../mapObjects/MiscObjects.h" VCMI_LIB_NAMESPACE_BEGIN diff --git a/lib/modding/ContentTypeHandler.cpp b/lib/modding/ContentTypeHandler.cpp index 4323bddc0..c255ebc07 100644 --- a/lib/modding/ContentTypeHandler.cpp +++ b/lib/modding/ContentTypeHandler.cpp @@ -199,7 +199,7 @@ void CContentHandler::init() handlers.insert(std::make_pair("skills", ContentTypeHandler(VLC->skillh.get(), "skill"))); handlers.insert(std::make_pair("templates", ContentTypeHandler(VLC->tplh.get(), "template"))); #if SCRIPTING_ENABLED - handlers.insert(std::make_pair("scripts", ContentTypeHandler(VLC->scriptHandler, "script"))); + handlers.insert(std::make_pair("scripts", ContentTypeHandler(VLC->scriptHandler.get(), "script"))); #endif handlers.insert(std::make_pair("battlefields", ContentTypeHandler(VLC->battlefieldsHandler.get(), "battlefield"))); handlers.insert(std::make_pair("terrains", ContentTypeHandler(VLC->terrainTypeHandler.get(), "terrain"))); diff --git a/test/game/CGameStateTest.cpp b/test/game/CGameStateTest.cpp index 1edf8c5cb..921f76108 100644 --- a/test/game/CGameStateTest.cpp +++ b/test/game/CGameStateTest.cpp @@ -46,17 +46,14 @@ public: void SetUp() override { - IObjectInterface::cb = gameCallback.get(); - gameState = std::make_shared(); gameCallback->setGameState(gameState.get()); - gameState->preInit(&services); + gameState->preInit(&services, gameCallback.get()); } void TearDown() override { gameState.reset(); - IObjectInterface::cb = nullptr; } bool describeChanges() const override diff --git a/test/map/CMapEditManagerTest.cpp b/test/map/CMapEditManagerTest.cpp index b8ae125ca..f25a0434b 100644 --- a/test/map/CMapEditManagerTest.cpp +++ b/test/map/CMapEditManagerTest.cpp @@ -25,7 +25,7 @@ TEST(MapManager, DrawTerrain_Type) { try { - auto map = std::make_unique(); + auto map = std::make_unique(nullptr); map->width = 52; map->height = 52; map->initTerrain(); @@ -114,8 +114,8 @@ TEST(MapManager, DrawTerrain_View) const ResourcePath testMap("test/TerrainViewTest", EResType::MAP); // Load maps and json config CMapService mapService; - const auto originalMap = mapService.loadMap(testMap); - auto map = mapService.loadMap(testMap); + const auto originalMap = mapService.loadMap(testMap, nullptr); + auto map = mapService.loadMap(testMap, nullptr); // Validate edit manager auto editManager = map->getEditManager(); diff --git a/test/map/CMapFormatTest.cpp b/test/map/CMapFormatTest.cpp index 2e0dd623a..cf20dfed1 100644 --- a/test/map/CMapFormatTest.cpp +++ b/test/map/CMapFormatTest.cpp @@ -62,7 +62,7 @@ TEST(MapFormat, DISABLED_Random) opt.setPlayerTypeForStandardPlayer(PlayerColor(2), EPlayerType::AI); opt.setPlayerTypeForStandardPlayer(PlayerColor(3), EPlayerType::AI); - CMapGenerator gen(opt, TEST_RANDOM_SEED); + CMapGenerator gen(opt, nullptr, TEST_RANDOM_SEED); std::unique_ptr initialMap = gen.generate(); initialMap->name.appendRawString("Test"); @@ -80,7 +80,7 @@ TEST(MapFormat, DISABLED_Random) serializeBuffer.seek(0); { CMapLoaderJson loader(&serializeBuffer); - std::unique_ptr serialized = loader.loadMap(); + std::unique_ptr serialized = loader.loadMap(nullptr); MapComparer c; c(serialized, initialMap); @@ -130,7 +130,7 @@ static std::unique_ptr loadOriginal(const JsonNode & header, const JsonNod CMapLoaderJson initialLoader(&initialBuffer); - return initialLoader.loadMap(); + return initialLoader.loadMap(nullptr); } static void loadActual(CMemoryBuffer * serializeBuffer, const std::unique_ptr & originalMap, JsonNode & header, JsonNode & objects, JsonNode & surface, JsonNode & underground) diff --git a/test/map/MapComparer.cpp b/test/map/MapComparer.cpp index 62ffcabfb..28ace85c2 100644 --- a/test/map/MapComparer.cpp +++ b/test/map/MapComparer.cpp @@ -12,6 +12,7 @@ #include "MapComparer.h" #include "../lib/mapping/CMap.h" +#include "../lib/mapObjects/CGObjectInstance.h" #include "../lib/mapObjects/ObjectTemplate.h" #define VCMI_CHECK_FIELD_EQUAL_P(field) EXPECT_EQ(actual->field, expected->field) diff --git a/test/mock/mock_MapService.cpp b/test/mock/mock_MapService.cpp index d9883c9d6..6b44d634a 100644 --- a/test/mock/mock_MapService.cpp +++ b/test/mock/mock_MapService.cpp @@ -45,7 +45,7 @@ std::unique_ptr MapServiceMock::loadMap() const initialBuffer.seek(0); CMapLoaderJson initialLoader(&initialBuffer); - std::unique_ptr res = initialLoader.loadMap(); + std::unique_ptr res = initialLoader.loadMap(nullptr); if(mapListener) mapListener->mapLoaded(res.get()); @@ -53,7 +53,7 @@ std::unique_ptr MapServiceMock::loadMap() const return res; } -std::unique_ptr MapServiceMock::loadMap(const ResourcePath & name) const +std::unique_ptr MapServiceMock::loadMap(const ResourcePath & name, IGameCallback * cb) const { return loadMap(); } @@ -65,7 +65,7 @@ std::unique_ptr MapServiceMock::loadMapHeader(const ResourcePath & n return initialLoader.loadMapHeader(); } -std::unique_ptr MapServiceMock::loadMap(const ui8 * buffer, int size, const std::string & name, const std::string & modName, const std::string & encoding) const +std::unique_ptr MapServiceMock::loadMap(const ui8 * buffer, int size, const std::string & name, const std::string & modName, const std::string & encoding, IGameCallback * cb) const { return loadMap(); } diff --git a/test/mock/mock_MapService.h b/test/mock/mock_MapService.h index cf2da28a9..3f1413683 100644 --- a/test/mock/mock_MapService.h +++ b/test/mock/mock_MapService.h @@ -29,9 +29,9 @@ class MapServiceMock : public IMapService public: MapServiceMock(const std::string & path, MapListener * mapListener_); - std::unique_ptr loadMap(const ResourcePath & name) const override; + std::unique_ptr loadMap(const ResourcePath & name, IGameCallback * cb) const override; std::unique_ptr loadMapHeader(const ResourcePath & name) const override; - std::unique_ptr loadMap(const ui8 * buffer, int size, const std::string & name, const std::string & modName, const std::string & encoding) const override; + std::unique_ptr loadMap(const ui8 * buffer, int size, const std::string & name, const std::string & modName, const std::string & encoding, IGameCallback * cb) const override; std::unique_ptr loadMapHeader(const ui8 * buffer, int size, const std::string & name, const std::string & modName, const std::string & encoding) const override; void saveMap(const std::unique_ptr & map, boost::filesystem::path fullPath) const override; diff --git a/test/mock/mock_spells_Mechanics.h b/test/mock/mock_spells_Mechanics.h index 985e093f3..288c06fa4 100644 --- a/test/mock/mock_spells_Mechanics.h +++ b/test/mock/mock_spells_Mechanics.h @@ -11,6 +11,7 @@ #pragma once #include "../../lib/spells/ISpellMechanics.h" +#include "../../lib/CGameInfoCallback.h" namespace spells { diff --git a/test/scripting/ScriptFixture.cpp b/test/scripting/ScriptFixture.cpp index e350c6c61..aabcea131 100644 --- a/test/scripting/ScriptFixture.cpp +++ b/test/scripting/ScriptFixture.cpp @@ -41,7 +41,7 @@ void ScriptFixture::loadScript(const JsonNode & scriptConfig) void ScriptFixture::loadScript(ModulePtr module, const std::string & scriptSource) { - subject = std::make_shared(VLC->scriptHandler); + subject = std::make_shared(VLC->scriptHandler.get()); subject->host = module; subject->sourceText = scriptSource; diff --git a/test/spells/effects/CatapultTest.cpp b/test/spells/effects/CatapultTest.cpp index f88b582ad..690d9cb5c 100644 --- a/test/spells/effects/CatapultTest.cpp +++ b/test/spells/effects/CatapultTest.cpp @@ -50,7 +50,7 @@ TEST_F(CatapultTest, NotApplicableWithoutTown) TEST_F(CatapultTest, NotApplicableInVillage) { - auto fakeTown = std::make_shared(); + auto fakeTown = std::make_shared(nullptr); EXPECT_CALL(*battleFake, getDefendedTown()).WillRepeatedly(Return(fakeTown.get())); EXPECT_CALL(mechanicsMock, adaptProblem(_, _)).WillOnce(Return(false)); @@ -62,7 +62,7 @@ TEST_F(CatapultTest, NotApplicableInVillage) TEST_F(CatapultTest, NotApplicableForDefenderIfSmart) { - auto fakeTown = std::make_shared(); + auto fakeTown = std::make_shared(nullptr); fakeTown->builtBuildings.insert(BuildingID::FORT); mechanicsMock.casterSide = BattleSide::DEFENDER; @@ -76,7 +76,7 @@ TEST_F(CatapultTest, NotApplicableForDefenderIfSmart) TEST_F(CatapultTest, DISABLED_ApplicableInTown) { - auto fakeTown = std::make_shared(); + auto fakeTown = std::make_shared(nullptr); fakeTown->builtBuildings.insert(BuildingID::FORT); EXPECT_CALL(*battleFake, getDefendedTown()).WillRepeatedly(Return(fakeTown.get())); @@ -106,7 +106,7 @@ protected: void SetUp() override { EffectFixture::setUp(); - fakeTown = std::make_shared(); + fakeTown = std::make_shared(nullptr); fakeTown->builtBuildings.insert(BuildingID::FORT); } private: