1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-26 22:57:00 +02:00

moatHexes: add saves and mods compatability

This commit is contained in:
Arseniy Shestakov 2016-01-28 01:35:01 +03:00
parent 48aedaef47
commit 8c39ecf538
4 changed files with 26 additions and 5 deletions

View File

@ -233,7 +233,6 @@
"moatHexes": { "moatHexes": {
"type" : "array", "type" : "array",
"description" : "Numbers of battlefield hexes affected by moat during siege", "description" : "Numbers of battlefield hexes affected by moat during siege",
"minItems" : 1,
"items" : { "type" : "number" } "items" : { "type" : "number" }
}, },
"musicTheme": { "musicTheme": {

View File

@ -86,6 +86,12 @@ CTown::~CTown()
str.dellNull(); str.dellNull();
} }
std::vector<BattleHex> CTown::defaultMoatHexes()
{
static const BattleHex moatHexes[] = {11, 28, 44, 61, 77, 111, 129, 146, 164, 181};
return std::vector<BattleHex>(moatHexes, moatHexes + ARRAY_COUNT(moatHexes));
}
CTownHandler::CTownHandler() CTownHandler::CTownHandler()
{ {
VLC->townh = this; VLC->townh = this;
@ -543,8 +549,13 @@ void CTownHandler::loadTown(CTown &town, const JsonNode & source)
town.moatDamage = source["moatDamage"].Float(); town.moatDamage = source["moatDamage"].Float();
town.moatHexes = source["moatHexes"].convertTo<std::vector<BattleHex> >(); // Mods Compatability for pre 0.99
if(source["moatHexes"].isNull())
{
town.moatHexes = CTown::defaultMoatHexes();
}
else
town.moatHexes = source["moatHexes"].convertTo<std::vector<BattleHex> >();
town.mageLevel = source["mageGuild"].Float(); town.mageLevel = source["mageGuild"].Float();
town.names = source["names"].convertTo<std::vector<std::string> >(); town.names = source["names"].convertTo<std::vector<std::string> >();

View File

@ -137,6 +137,8 @@ class DLL_LINKAGE CTown
public: public:
CTown(); CTown();
~CTown(); ~CTown();
// TODO: remove once save and mod compatability not needed
static std::vector<BattleHex> defaultMoatHexes();
CFaction * faction; CFaction * faction;
@ -207,7 +209,16 @@ public:
template <typename Handler> void serialize(Handler &h, const int version) template <typename Handler> void serialize(Handler &h, const int version)
{ {
h & names & faction & creatures & dwellings & dwellingNames & buildings & hordeLvl & mageLevel h & names & faction & creatures & dwellings & dwellingNames & buildings & hordeLvl & mageLevel
& primaryRes & warMachine & clientInfo & moatDamage & moatHexes & defaultTavernChance; & primaryRes & warMachine & clientInfo & moatDamage;
if(version >= 758)
{
h & moatHexes;
}
else if(!h.saving)
{
moatHexes = defaultMoatHexes();
}
h & defaultTavernChance;
auto findNull = [](const std::pair<BuildingID, ConstTransitivePtr<CBuilding>> &building) auto findNull = [](const std::pair<BuildingID, ConstTransitivePtr<CBuilding>> &building)
{ return building.second == nullptr; }; { return building.second == nullptr; };

View File

@ -27,7 +27,7 @@
#include "mapping/CCampaignHandler.h" //for CCampaignState #include "mapping/CCampaignHandler.h" //for CCampaignState
#include "rmg/CMapGenerator.h" // for CMapGenOptions #include "rmg/CMapGenerator.h" // for CMapGenOptions
const ui32 version = 757; const ui32 version = 758;
const ui32 minSupportedVersion = 753; const ui32 minSupportedVersion = 753;
class CISer; class CISer;