mirror of
https://github.com/vcmi/vcmi.git
synced 2025-07-17 01:32:21 +02:00
vcmi: fix tests with latest develop
This commit is contained in:
@ -47,8 +47,6 @@ class DLL_LINKAGE CCreature : public Creature, public CBonusSystemNode
|
||||
|
||||
bool doubleWide = false;
|
||||
|
||||
si32 iconIndex = -1; // index of icon in files like twcrport
|
||||
|
||||
TResources cost; //cost[res_id] - amount of that resource required to buy creature from dwelling
|
||||
|
||||
public:
|
||||
@ -61,6 +59,7 @@ public:
|
||||
std::string animDefName; // creature animation used during battles
|
||||
std::string advMapDef; //for new creatures only, image for adventure map
|
||||
|
||||
si32 iconIndex = -1; // index of icon in files like twcrport, used in tests now.
|
||||
/// names of files with appropriate icons. Used only during loading
|
||||
std::string smallIconName;
|
||||
std::string largeIconName;
|
||||
|
@ -722,7 +722,7 @@ void CGameState::preInit(Services * services)
|
||||
this->services = services;
|
||||
}
|
||||
|
||||
void CGameState::init(const CMapService * mapService, StartInfo * si, bool allowSavingRandomMap)
|
||||
void CGameState::init(const IMapService * mapService, StartInfo * si, bool allowSavingRandomMap)
|
||||
{
|
||||
preInitAuto();
|
||||
logGlobal->info("\tUsing random seed: %d", si->seedToBeUsed);
|
||||
@ -851,7 +851,7 @@ void CGameState::preInitAuto()
|
||||
}
|
||||
}
|
||||
|
||||
void CGameState::initNewGame(const CMapService * mapService, bool allowSavingRandomMap)
|
||||
void CGameState::initNewGame(const IMapService * mapService, bool allowSavingRandomMap)
|
||||
{
|
||||
if(scenarioOps->createRandomMap())
|
||||
{
|
||||
|
@ -57,7 +57,7 @@ class CQuest;
|
||||
class CCampaignScenario;
|
||||
struct EventCondition;
|
||||
class CScenarioTravel;
|
||||
class CMapService;
|
||||
class IMapService;
|
||||
|
||||
|
||||
template<typename T> class CApplier;
|
||||
@ -161,7 +161,7 @@ public:
|
||||
|
||||
void preInit(Services * services);
|
||||
|
||||
void init(const CMapService * mapService, StartInfo * si, bool allowSavingRandomMap = false);
|
||||
void init(const IMapService * mapService, StartInfo * si, bool allowSavingRandomMap = false);
|
||||
void updateOnLoad(StartInfo * si);
|
||||
|
||||
ConstTransitivePtr<StartInfo> scenarioOps, initialOpts; //second one is a copy of settings received from pregame (not randomized)
|
||||
@ -252,7 +252,7 @@ private:
|
||||
|
||||
// ----- initialization -----
|
||||
void preInitAuto();
|
||||
void initNewGame(const CMapService * mapService, bool allowSavingRandomMap);
|
||||
void initNewGame(const IMapService * mapService, bool allowSavingRandomMap);
|
||||
void initCampaign();
|
||||
void checkMapChecksum();
|
||||
void initGlobalBonuses();
|
||||
|
@ -24,57 +24,67 @@ class IMapPatcher;
|
||||
class ModCompatibilityInfo;
|
||||
|
||||
/**
|
||||
* The map service provides loading and saving of VCMI/H3 map files.
|
||||
* The map service provides loading of VCMI/H3 map files. It can
|
||||
* be extended to save maps later as well.
|
||||
*/
|
||||
class DLL_LINKAGE CMapService
|
||||
class DLL_LINKAGE IMapService
|
||||
{
|
||||
public:
|
||||
CMapService() = default;
|
||||
virtual ~CMapService() = default;
|
||||
|
||||
IMapService() = default;
|
||||
virtual ~IMapService() = default;
|
||||
/**
|
||||
* Loads the VCMI/H3 map file specified by the name.
|
||||
*
|
||||
* @param name the name of the map
|
||||
* @return a unique ptr to the loaded map class
|
||||
*/
|
||||
std::unique_ptr<CMap> loadMap(const ResourceID & name) const;
|
||||
|
||||
virtual std::unique_ptr<CMap> loadMap(const ResourceID & name) const = 0;
|
||||
|
||||
/**
|
||||
* Loads the VCMI/H3 map header specified by the name.
|
||||
*
|
||||
* @param name the name of the map
|
||||
* @return a unique ptr to the loaded map header class
|
||||
*/
|
||||
std::unique_ptr<CMapHeader> loadMapHeader(const ResourceID & name) const;
|
||||
|
||||
virtual std::unique_ptr<CMapHeader> loadMapHeader(const ResourceID & name) const = 0;
|
||||
|
||||
/**
|
||||
* Loads the VCMI/H3 map file from a buffer. This method is temporarily
|
||||
* in use to ease the transition to use the new map service.
|
||||
*
|
||||
* TODO Replace method params with a CampaignMapInfo struct which contains
|
||||
* a campaign loading object + name of map.
|
||||
*
|
||||
* @param buffer a pointer to a buffer containing the map data
|
||||
* @param size the size of the buffer
|
||||
@@ -60,8 +60,8 @@ class DLL_LINKAGE CMapService
|
||||
* @param name indicates name of file that will be used during map header patching
|
||||
* @return a unique ptr to the loaded map class
|
||||
*/
|
||||
std::unique_ptr<CMap> loadMap(const ui8 * buffer, int size, const std::string & name, const std::string & modName, const std::string & encoding) const;
|
||||
|
||||
virtual std::unique_ptr<CMap> loadMap(const ui8 * buffer, int size, const std::string & name, const std::string & modName, const std::string & encoding) const = 0;
|
||||
|
||||
/**
|
||||
* Loads the VCMI/H3 map header from a buffer. This method is temporarily
|
||||
* in use to ease the transition to use the new map service.
|
||||
*
|
||||
* TODO Replace method params with a CampaignMapInfo struct which contains
|
||||
* a campaign loading object + name of map.
|
||||
*
|
||||
* @param buffer a pointer to a buffer containing the map header data
|
||||
* @param size the size of the buffer
|
||||
@@ -74,7 +74,27 @@ class DLL_LINKAGE CMapService
|
||||
* @param name indicates name of file that will be used during map header patching
|
||||
* @return a unique ptr to the loaded map class
|
||||
*/
|
||||
std::unique_ptr<CMapHeader> loadMapHeader(const ui8 * buffer, int size, const std::string & name, const std::string & modName, const std::string & encoding) const;
|
||||
virtual std::unique_ptr<CMapHeader> loadMapHeader(const ui8 * buffer, int size, const std::string & name, const std::string & modName, const std::string & encoding) const = 0;
|
||||
|
||||
/**
|
||||
* Saves map into VCMI format with name specified
|
||||
* @param map to save
|
||||
* @param fullPath full path to file to write, including extension
|
||||
*/
|
||||
virtual void saveMap(const std::unique_ptr<CMap> & map, boost::filesystem::path fullPath) const = 0;
|
||||
};
|
||||
|
||||
class DLL_LINKAGE CMapService : public IMapService
|
||||
{
|
||||
public:
|
||||
CMapService() = default;
|
||||
virtual ~CMapService() = default;
|
||||
|
||||
std::unique_ptr<CMap> loadMap(const ResourceID & name) const override;
|
||||
std::unique_ptr<CMapHeader> loadMapHeader(const ResourceID & name) const override;
|
||||
std::unique_ptr<CMap> loadMap(const ui8 * buffer, int size, const std::string & name, const std::string & modName, const std::string & encoding) const override;
|
||||
std::unique_ptr<CMapHeader> 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<CMap> & map, boost::filesystem::path fullPath) const override;
|
||||
|
||||
/**
|
||||
* Tests if mods used in the map are currently loaded
|
||||
@ -82,14 +92,7 @@ public:
|
||||
* @return data structure representing missing or incompatible mods (those which are needed from map but not loaded)
|
||||
*/
|
||||
static ModCompatibilityInfo verifyMapHeaderMods(const CMapHeader & map);
|
||||
|
||||
/**
|
||||
* Saves map into VCMI format with name specified
|
||||
* @param map to save
|
||||
* @param fullPath full path to file to write, including extension
|
||||
*/
|
||||
void saveMap(const std::unique_ptr<CMap> & map, boost::filesystem::path fullPath) const;
|
||||
|
||||
|
||||
private:
|
||||
/**
|
||||
* Gets a map input stream object specified by a map name.
|
||||
|
@ -36,9 +36,9 @@ TEST(MapManager, DrawTerrain_Type)
|
||||
editManager->getTerrainSelection().select(int3(5, 5, 0));
|
||||
editManager->drawTerrain(ETerrainId::GRASS);
|
||||
static const int3 squareCheck[] = { int3(5,5,0), int3(5,4,0), int3(4,4,0), int3(4,5,0) };
|
||||
for(int i = 0; i < ARRAY_COUNT(squareCheck); ++i)
|
||||
for(const auto & tile : squareCheck)
|
||||
{
|
||||
EXPECT_EQ(map->getTile(squareCheck[i]).terType->getId(), ETerrainId::GRASS);
|
||||
EXPECT_EQ(map->getTile(tile).terType->getId(), ETerrainId::GRASS);
|
||||
}
|
||||
|
||||
// Concat to square
|
||||
@ -63,9 +63,9 @@ TEST(MapManager, DrawTerrain_Type)
|
||||
static const int3 diagonalCheck[] = { int3(31,42,0), int3(32,42,0), int3(32,43,0), int3(33,43,0), int3(33,44,0),
|
||||
int3(34,44,0), int3(34,45,0), int3(35,45,0), int3(35,46,0), int3(36,46,0),
|
||||
int3(36,47,0), int3(37,47,0)};
|
||||
for(int i = 0; i < ARRAY_COUNT(diagonalCheck); ++i)
|
||||
for(const auto & tile : diagonalCheck)
|
||||
{
|
||||
editManager->getTerrainSelection().select(diagonalCheck[i]);
|
||||
editManager->getTerrainSelection().select(tile);
|
||||
}
|
||||
editManager->drawTerrain(ETerrainId::GRASS);
|
||||
EXPECT_EQ(map->getTile(int3(35, 44, 0)).terType->getId(), ETerrainId::WATER);
|
||||
@ -134,7 +134,7 @@ TEST(MapManager, DrawTerrain_View)
|
||||
|
||||
// Get mapping range
|
||||
const auto & pattern = VLC->terviewh->getTerrainViewPatternById(groupStr, id);
|
||||
const auto & mapping = (*pattern).mapping;
|
||||
const auto & mapping = pattern->get().mapping;
|
||||
|
||||
const auto & positionsNode = node["pos"].Vector();
|
||||
for (const auto & posNode : positionsNode)
|
||||
|
@ -56,4 +56,8 @@ public:
|
||||
|
||||
MOCK_CONST_METHOD1(getCost, int32_t(int32_t));
|
||||
MOCK_CONST_METHOD0(isDoubleWide, bool());
|
||||
|
||||
MOCK_CONST_METHOD1(getRecruitCost, int32_t(Identifier<EGameResID>));
|
||||
MOCK_CONST_METHOD0(getFullRecruitCost, ResourceSet());
|
||||
MOCK_CONST_METHOD0(hasUpgrades, bool());
|
||||
};
|
||||
|
@ -33,6 +33,8 @@ public:
|
||||
MOCK_CONST_METHOD2(battleGetUnitByPos, const battle::Unit *(BattleHex, bool));
|
||||
MOCK_CONST_METHOD0(battleActiveUnit, const battle::Unit *());
|
||||
|
||||
MOCK_CONST_METHOD0(getBonusBearer, IBonusBearer*());
|
||||
|
||||
MOCK_CONST_METHOD2(battleGetAllObstaclesOnPos, std::vector<std::shared_ptr<const CObstacleInstance>>(BattleHex, bool));
|
||||
MOCK_CONST_METHOD2(getAllAffectedObstaclesByStack, std::vector<std::shared_ptr<const CObstacleInstance>>(const battle::Unit *, const std::set<BattleHex> &));
|
||||
|
||||
|
@ -48,7 +48,7 @@ public:
|
||||
void showGarrisonDialog(ObjectInstanceID upobj, ObjectInstanceID hid, bool removableUnits) override {} //cb will be called when player closes garrison window
|
||||
void showTeleportDialog(TeleportDialog *iw) override {}
|
||||
void showThievesGuildWindow(PlayerColor player, ObjectInstanceID requestingObjId) override {}
|
||||
void giveResource(PlayerColor player, EGameResID which, int val) override {}
|
||||
void giveResource(PlayerColor player, GameResID which, int val) override {}
|
||||
void giveResources(PlayerColor player, TResources resources) override {}
|
||||
|
||||
void giveCreatures(const CArmedInstance *objid, const CGHeroInstance * h, const CCreatureSet &creatures, bool remove) override {}
|
||||
@ -85,7 +85,8 @@ public:
|
||||
void changeObjPos(ObjectInstanceID objid, int3 newPos) override {}
|
||||
void heroExchange(ObjectInstanceID hero1, ObjectInstanceID hero2) override {} //when two heroes meet on adventure map
|
||||
void changeFogOfWar(int3 center, ui32 radius, PlayerColor player, bool hide) override {}
|
||||
void changeFogOfWar(std::unordered_set<int3, ShashInt3> &tiles, PlayerColor player, bool hide) override {}
|
||||
void changeFogOfWar(std::unordered_set<int3> &tiles, PlayerColor player, bool hide) override {}
|
||||
void castSpell(const spells::Caster * caster, SpellID spellID, const int3 &pos) override {}
|
||||
|
||||
///useful callback methods
|
||||
void sendAndApply(CPackForClient * pack) override;
|
||||
|
@ -30,6 +30,8 @@ public:
|
||||
MOCK_CONST_METHOD1(getCasterName, void(MetaString &));
|
||||
MOCK_CONST_METHOD3(getCastDescription, void(const spells::Spell *, const std::vector<const battle::Unit *> &, MetaString &));
|
||||
MOCK_CONST_METHOD2(spendMana, void(ServerCallback *, const int32_t));
|
||||
MOCK_CONST_METHOD0(manaLimit, int32_t());
|
||||
MOCK_CONST_METHOD0(getHeroCaster, CGHeroInstance*());
|
||||
|
||||
MOCK_CONST_METHOD0(unitBaseAmount, int32_t());
|
||||
MOCK_CONST_METHOD0(unitId, uint32_t());
|
||||
@ -77,6 +79,8 @@ public:
|
||||
MOCK_CONST_METHOD1(willMove, bool(int));
|
||||
MOCK_CONST_METHOD1(waited, bool(int));
|
||||
|
||||
MOCK_CONST_METHOD0(getFaction, FactionID());
|
||||
|
||||
MOCK_CONST_METHOD1(battleQueuePhase, battle::BattlePhases::Type(int));
|
||||
|
||||
MOCK_CONST_METHOD0(acquire, std::shared_ptr<battle::Unit>());
|
||||
|
Reference in New Issue
Block a user