From ffeb7f253b1169a6baf0835a1e3aff571642add8 Mon Sep 17 00:00:00 2001 From: Arseniy Shestakov Date: Wed, 6 Jan 2016 12:52:52 +0300 Subject: [PATCH 1/4] moatHexes: update faction schema and configuration files --- config/factions/castle.json | 2 ++ config/factions/conflux.json | 1 + config/factions/dungeon.json | 1 + config/factions/fortress.json | 4 +++- config/factions/inferno.json | 1 + config/factions/necropolis.json | 3 ++- config/factions/rampart.json | 1 + config/factions/stronghold.json | 1 + config/factions/tower.json | 1 + config/schemas/faction.json | 6 ++++++ 10 files changed, 19 insertions(+), 2 deletions(-) diff --git a/config/factions/castle.json b/config/factions/castle.json index c17eb618e..f7f9108ee 100644 --- a/config/factions/castle.json +++ b/config/factions/castle.json @@ -146,6 +146,8 @@ "mageGuild" : 4, "warMachine" : "ballista", "moatDamage" : 70, + "moatHexes" : [ 11, 28, 44, 61, 77, 111, 129, 146, 164, 181 ], + "primaryResource": "ore", "buildings" : { diff --git a/config/factions/conflux.json b/config/factions/conflux.json index b34e83a29..31f901b11 100644 --- a/config/factions/conflux.json +++ b/config/factions/conflux.json @@ -151,6 +151,7 @@ "primaryResource" : "mercury", "warMachine" : "ballista", "moatDamage" : 70, + "moatHexes" : [ 11, 28, 44, 61, 77, 111, 129, 146, 164, 181 ], "buildings" : { diff --git a/config/factions/dungeon.json b/config/factions/dungeon.json index 7c15be082..bd0f7797d 100644 --- a/config/factions/dungeon.json +++ b/config/factions/dungeon.json @@ -146,6 +146,7 @@ "primaryResource" : "sulfur", "warMachine" : "ballista", "moatDamage" : 90, + "moatHexes" : [ 11, 28, 44, 61, 77, 111, 129, 146, 164, 181 ], "buildings" : { diff --git a/config/factions/fortress.json b/config/factions/fortress.json index 7dc1c924b..ec13b2efe 100644 --- a/config/factions/fortress.json +++ b/config/factions/fortress.json @@ -144,9 +144,11 @@ ], "horde" : [ 0, -1 ], "mageGuild" : 3, + "primaryResource":"ore", "warMachine" : "firstAidTent", "moatDamage" : 90, - "primaryResource":"ore", + "moatHexes" : [ 10, 11, 27, 28, 43, 44, 60, 61, 76, 77, 94, 110, 111, 128, 129, 145, 146, 163, 164, 180, 181 ], + "buildings" : { "mageGuild1": { "id" : 0 }, diff --git a/config/factions/inferno.json b/config/factions/inferno.json index 15797e446..268f7db4c 100644 --- a/config/factions/inferno.json +++ b/config/factions/inferno.json @@ -147,6 +147,7 @@ "primaryResource" : "mercury", "warMachine" : "ammoCart", "moatDamage" : 90, + "moatHexes" : [ 11, 28, 44, 61, 77, 111, 129, 146, 164, 181 ], "buildings" : { diff --git a/config/factions/necropolis.json b/config/factions/necropolis.json index a12f4cd88..bb243afbb 100644 --- a/config/factions/necropolis.json +++ b/config/factions/necropolis.json @@ -148,9 +148,10 @@ ], "horde" : [ 0, -1 ], "mageGuild" : 5, + "primaryResource": "ore", "warMachine" : "firstAidTent", "moatDamage" : 70, - "primaryResource": "ore", + "moatHexes" : [ 11, 28, 44, 61, 77, 111, 129, 146, 164, 181 ], "buildings" : { diff --git a/config/factions/rampart.json b/config/factions/rampart.json index af09ed901..7c3f18102 100644 --- a/config/factions/rampart.json +++ b/config/factions/rampart.json @@ -151,6 +151,7 @@ "primaryResource" : "crystal", "warMachine" : "firstAidTent", "moatDamage" : 70, + "moatHexes" : [ 11, 28, 44, 61, 77, 111, 129, 146, 164, 181 ], "buildings" : { diff --git a/config/factions/stronghold.json b/config/factions/stronghold.json index f88e38472..f694b5e4c 100644 --- a/config/factions/stronghold.json +++ b/config/factions/stronghold.json @@ -145,6 +145,7 @@ "mageGuild" : 3, "warMachine" : "ammoCart", "moatDamage" : 70, + "moatHexes" : [ 11, 28, 44, 61, 77, 111, 129, 146, 164, 181 ], "buildings" : { diff --git a/config/factions/tower.json b/config/factions/tower.json index b6abda16b..b6d2d25db 100644 --- a/config/factions/tower.json +++ b/config/factions/tower.json @@ -146,6 +146,7 @@ "mageGuild" : 5, "warMachine" : "ammoCart", "moatDamage" : 0, //TODO: minefield + "moatHexes" : [ 11, 28, 44, 61, 77, 111, 129, 146, 164, 181 ], "buildings" : { diff --git a/config/schemas/faction.json b/config/schemas/faction.json index 5607eaa76..58f841350 100644 --- a/config/schemas/faction.json +++ b/config/schemas/faction.json @@ -230,6 +230,12 @@ "type":"number", "description": "Damage dealt to creature that entered town moat during siege" }, + "moatHexes": { + "type" : "array", + "description" : "Numbers of battlefield hexes affected by moat during siege", + "minItems" : 1, + "items" : { "type" : "number" } + }, "musicTheme": { "type":"string", "description": "Path to town music theme", From c93f8fea489fa36601d1d9d11c35964861fe0d39 Mon Sep 17 00:00:00 2001 From: Arseniy Shestakov Date: Wed, 6 Jan 2016 12:53:40 +0300 Subject: [PATCH 2/4] moatHexes: implement reading moat hexes from configuration files This also fix Fortess moat that previously used wrong hexes --- lib/CObstacleInstance.cpp | 5 ++--- lib/CTownHandler.cpp | 2 ++ lib/CTownHandler.h | 4 +++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/CObstacleInstance.cpp b/lib/CObstacleInstance.cpp index b1ed5ca86..168490e12 100644 --- a/lib/CObstacleInstance.cpp +++ b/lib/CObstacleInstance.cpp @@ -1,6 +1,7 @@ #include "StdInc.h" #include "CObstacleInstance.h" #include "CHeroHandler.h" +#include "CTownHandler.h" #include "VCMI_Lib.h" #include "spells/CSpellHandler.h" @@ -145,7 +146,5 @@ void SpellCreatedObstacle::battleTurnPassed() std::vector MoatObstacle::getAffectedTiles() const { - //rrr... need initializer lists - static const BattleHex moatHexes[] = {11, 28, 44, 61, 77, 111, 129, 146, 164, 181}; - return std::vector(moatHexes, moatHexes + ARRAY_COUNT(moatHexes)); + return VLC->townh->factions[ID]->town->moatHexes; } diff --git a/lib/CTownHandler.cpp b/lib/CTownHandler.cpp index 340deab4c..bda6520ed 100644 --- a/lib/CTownHandler.cpp +++ b/lib/CTownHandler.cpp @@ -13,6 +13,7 @@ #include "filesystem/Filesystem.h" #include "mapObjects/CObjectClassesHandler.h" #include "mapObjects/CObjectHandler.h" +#include "BattleHex.h" /* * CTownHandler.cpp, part of VCMI engine @@ -542,6 +543,7 @@ void CTownHandler::loadTown(CTown &town, const JsonNode & source) town.moatDamage = source["moatDamage"].Float(); + town.moatHexes = source["moatHexes"].convertTo >(); town.mageLevel = source["mageGuild"].Float(); diff --git a/lib/CTownHandler.h b/lib/CTownHandler.h index 8997b6712..308121afc 100644 --- a/lib/CTownHandler.h +++ b/lib/CTownHandler.h @@ -21,6 +21,7 @@ class CLegacyConfigParser; class JsonNode; class CTown; class CFaction; +struct BattleHex; /// a typical building encountered in every castle ;] /// this is structure available to both client and server @@ -156,6 +157,7 @@ public: ui16 primaryRes; ArtifactID warMachine; si32 moatDamage; + std::vector moatHexes; // default chance for hero of specific class to appear in tavern, if field "tavern" was not set // resulting chance = sqrt(town.chance * heroClass.chance) ui32 defaultTavernChance; @@ -205,7 +207,7 @@ public: template void serialize(Handler &h, const int version) { h & names & faction & creatures & dwellings & dwellingNames & buildings & hordeLvl & mageLevel - & primaryRes & warMachine & clientInfo & moatDamage & defaultTavernChance; + & primaryRes & warMachine & clientInfo & moatDamage & moatHexes & defaultTavernChance; auto findNull = [](const std::pair> &building) { return building.second == nullptr; }; From 8c39ecf538edf3e620ea39222efd3f599031fcd3 Mon Sep 17 00:00:00 2001 From: Arseniy Shestakov Date: Thu, 28 Jan 2016 01:35:01 +0300 Subject: [PATCH 3/4] moatHexes: add saves and mods compatability --- config/schemas/faction.json | 1 - lib/CTownHandler.cpp | 15 +++++++++++++-- lib/CTownHandler.h | 13 ++++++++++++- lib/Connection.h | 2 +- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/config/schemas/faction.json b/config/schemas/faction.json index 58f841350..016a97bef 100644 --- a/config/schemas/faction.json +++ b/config/schemas/faction.json @@ -233,7 +233,6 @@ "moatHexes": { "type" : "array", "description" : "Numbers of battlefield hexes affected by moat during siege", - "minItems" : 1, "items" : { "type" : "number" } }, "musicTheme": { diff --git a/lib/CTownHandler.cpp b/lib/CTownHandler.cpp index bda6520ed..9ed82563b 100644 --- a/lib/CTownHandler.cpp +++ b/lib/CTownHandler.cpp @@ -86,6 +86,12 @@ CTown::~CTown() str.dellNull(); } +std::vector CTown::defaultMoatHexes() +{ + static const BattleHex moatHexes[] = {11, 28, 44, 61, 77, 111, 129, 146, 164, 181}; + return std::vector(moatHexes, moatHexes + ARRAY_COUNT(moatHexes)); +} + CTownHandler::CTownHandler() { VLC->townh = this; @@ -543,8 +549,13 @@ void CTownHandler::loadTown(CTown &town, const JsonNode & source) town.moatDamage = source["moatDamage"].Float(); - town.moatHexes = source["moatHexes"].convertTo >(); - + // Mods Compatability for pre 0.99 + if(source["moatHexes"].isNull()) + { + town.moatHexes = CTown::defaultMoatHexes(); + } + else + town.moatHexes = source["moatHexes"].convertTo >(); town.mageLevel = source["mageGuild"].Float(); town.names = source["names"].convertTo >(); diff --git a/lib/CTownHandler.h b/lib/CTownHandler.h index 308121afc..bb49bc48f 100644 --- a/lib/CTownHandler.h +++ b/lib/CTownHandler.h @@ -137,6 +137,8 @@ class DLL_LINKAGE CTown public: CTown(); ~CTown(); + // TODO: remove once save and mod compatability not needed + static std::vector defaultMoatHexes(); CFaction * faction; @@ -207,7 +209,16 @@ public: template void serialize(Handler &h, const int version) { 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> &building) { return building.second == nullptr; }; diff --git a/lib/Connection.h b/lib/Connection.h index 69e3725b4..11ff7fede 100644 --- a/lib/Connection.h +++ b/lib/Connection.h @@ -27,7 +27,7 @@ #include "mapping/CCampaignHandler.h" //for CCampaignState #include "rmg/CMapGenerator.h" // for CMapGenOptions -const ui32 version = 757; +const ui32 version = 758; const ui32 minSupportedVersion = 753; class CISer; From 75f278b91397cc05601447cfed48f1d9f3fb9968 Mon Sep 17 00:00:00 2001 From: Arseniy Shestakov Date: Fri, 29 Jan 2016 19:25:25 +0300 Subject: [PATCH 4/4] moatHexes: use initializer list and update comment --- lib/CTownHandler.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/CTownHandler.cpp b/lib/CTownHandler.cpp index 9ed82563b..4e1906c1b 100644 --- a/lib/CTownHandler.cpp +++ b/lib/CTownHandler.cpp @@ -88,8 +88,8 @@ CTown::~CTown() std::vector CTown::defaultMoatHexes() { - static const BattleHex moatHexes[] = {11, 28, 44, 61, 77, 111, 129, 146, 164, 181}; - return std::vector(moatHexes, moatHexes + ARRAY_COUNT(moatHexes)); + static const std::vector moatHexes = {11, 28, 44, 61, 77, 111, 129, 146, 164, 181}; + return moatHexes; } CTownHandler::CTownHandler() @@ -549,7 +549,7 @@ void CTownHandler::loadTown(CTown &town, const JsonNode & source) town.moatDamage = source["moatDamage"].Float(); - // Mods Compatability for pre 0.99 + // Compatability for <= 0.98f mods if(source["moatHexes"].isNull()) { town.moatHexes = CTown::defaultMoatHexes();