فهرست منبع

moatHexes: implement reading moat hexes from configuration files

This also fix Fortess moat that previously used wrong hexes
Arseniy Shestakov 10 سال پیش
والد
کامیت
c93f8fea48
3فایلهای تغییر یافته به همراه7 افزوده شده و 4 حذف شده
  1. 2 3
      lib/CObstacleInstance.cpp
  2. 2 0
      lib/CTownHandler.cpp
  3. 3 1
      lib/CTownHandler.h

+ 2 - 3
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<BattleHex> MoatObstacle::getAffectedTiles() const
 {
-	//rrr... need initializer lists
-	static const BattleHex moatHexes[] = {11, 28, 44, 61, 77, 111, 129, 146, 164, 181};
-	return std::vector<BattleHex>(moatHexes, moatHexes + ARRAY_COUNT(moatHexes));
+	return VLC->townh->factions[ID]->town->moatHexes;
 }

+ 2 - 0
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<std::vector<BattleHex> >();
 	
 
 	town.mageLevel = source["mageGuild"].Float();

+ 3 - 1
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<BattleHex> 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 <typename Handler> 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<BuildingID, ConstTransitivePtr<CBuilding>> &building)
 		{ return building.second == nullptr; };