浏览代码

Town building build mode fixes
* CGameHandler::buildStructure was using wrong requirements for buildings in auto mode.
* Build mode loading was wrong in case of omitted value
* Show town hall slot for not built building only if it have normal build mode

AlexVinS 8 年之前
父节点
当前提交
c39cd5f951
共有 5 个文件被更改,包括 58 次插入13 次删除
  1. 15 7
      client/windows/CCastleInterface.cpp
  2. 2 2
      config/factions/dungeon.json
  3. 31 2
      lib/CTownHandler.cpp
  4. 6 0
      lib/CTownHandler.h
  5. 4 2
      server/CGameHandler.cpp

+ 15 - 7
client/windows/CCastleInterface.cpp

@@ -1339,14 +1339,22 @@ CHallInterface::CHallInterface(const CGTownInstance *Town):
 	{
 		for(size_t col=0; col<boxList[row].size(); col++) //for each box
 		{
-			const CBuilding *building = nullptr;
-			for(auto & elem : boxList[row][col])//we are looking for the first not build structure
+			const CBuilding * building = nullptr;
+			for(auto & buildingID : boxList[row][col])//we are looking for the first not built structure
 			{
-				auto buildingID = elem;
-				building = town->town->buildings.at(buildingID);
-
-				if(!vstd::contains(town->builtBuildings,buildingID))
-					break;
+				const CBuilding * current = town->town->buildings.at(buildingID);
+				if(vstd::contains(town->builtBuildings, buildingID))
+				{
+					building = current;
+				}
+				else
+				{
+					if(current->mode == CBuilding::BUILD_NORMAL)
+					{
+						building = current;
+						break;
+					}
+				}
 			}
 			int posX = pos.w/2 - boxList[row].size()*154/2 - (boxList[row].size()-1)*20 + 194*col,
 			    posY = 35 + 104*row;

+ 2 - 2
config/factions/dungeon.json

@@ -129,7 +129,7 @@
 			[
 				[ [ "villageHall", "townHall", "cityHall", "capitol" ], [ "fort", "citadel", "castle" ], [ "tavern" ], [ "blacksmith" ] ],
 				[ [ "marketplace", "resourceSilo" ], [ "mageGuild1", "mageGuild2", "mageGuild3", "mageGuild4", "mageGuild5" ], [ "special2" ], [ "special3" ] ],
-				[ [ "special1" ], [ "special4" ], [ "horde1" ] ],
+				[ [ "special1" ], [ "special4" ], [ "horde1", "horde1Upgr" ] ],
 				[ [ "dwellingLvl1", "dwellingUpLvl1" ], [ "dwellingLvl2", "dwellingUpLvl2" ], [ "dwellingLvl3", "dwellingUpLvl3" ], [ "dwellingLvl4", "dwellingUpLvl4" ] ],
 				[ [ "dwellingLvl5", "dwellingUpLvl5" ], [ "dwellingLvl6", "dwellingUpLvl6" ], [ "dwellingLvl7", "dwellingUpLvl7" ] ]
 			],
@@ -171,7 +171,7 @@
 
 				"special1":       { "id" : 17, "requires" : [ "marketplace" ] },
 				"horde1":         { "id" : 18, "upgrades" : "dwellingLvl1" },
-				"horde1Upgr":     { "id" : 19, "upgrades" : "dwellingUpLvl1", "requires" : [ "allOf", [ "horde1" ], [ "dwellingUpLvl1" ] ], "mode" : "auto" },
+				"horde1Upgr":     { "id" : 19, "upgrades" : "dwellingUpLvl1", "requires" : [ "horde1" ], "mode" : "auto" },
 				"special2":       { "id" : 21, "requires" : [ "mageGuild1" ] },
 				"special3":       { "id" : 22 },
 				"special4":       { "id" : 23 },

+ 31 - 2
lib/CTownHandler.cpp

@@ -66,6 +66,24 @@ si32 CBuilding::getDistance(BuildingID buildID) const
 	return -1;
 }
 
+void CBuilding::deserializeFix()
+{
+	//default value for mode was broken, have to fix it here for old saves (v777 and older)
+	switch(mode)
+	{
+	case BUILD_NORMAL:
+	case BUILD_AUTO:
+	case BUILD_SPECIAL:
+	case BUILD_GRAIL:
+		break;
+
+	default:
+		mode = BUILD_NORMAL;
+		break;
+	}
+}
+
+
 CFaction::CFaction()
 {
 	town = nullptr;
@@ -329,9 +347,20 @@ void CTownHandler::loadBuilding(CTown * town, const std::string & stringID, cons
 {
 	auto ret = new CBuilding();
 
-	static const std::string modes [] = {"normal", "auto", "special", "grail"};
+	static const std::vector<std::string> MODES =
+	{
+		"normal", "auto", "special", "grail"
+	};
 
-	ret->mode = static_cast<CBuilding::EBuildMode>(boost::find(modes, source["mode"].String()) - modes);
+	ret->mode = CBuilding::BUILD_NORMAL;
+	{
+		if(source["mode"].getType() == JsonNode::DATA_STRING)
+		{
+			auto rawMode = vstd::find_pos(MODES, source["mode"].String());
+			if(rawMode > 0)
+				ret->mode = static_cast<CBuilding::EBuildMode>(rawMode);
+		}
+	}
 
 	ret->identifier = stringID;
 	ret->town = town;

+ 6 - 0
lib/CTownHandler.h

@@ -78,9 +78,15 @@ public:
 		h & requirements;
 		h & upgrade;
 		h & mode;
+		if(!h.saving)
+			deserializeFix();
 	}
 
 	friend class CTownHandler;
+
+private:
+
+	void deserializeFix();
 };
 
 /// This is structure used only by client

+ 4 - 2
server/CGameHandler.cpp

@@ -2993,9 +2993,11 @@ bool CGameHandler::buildStructure(ObjectInstanceID tid, BuildingID requestedID,
 		buildingsThatWillBe.insert(b->bid);
 		remainingAutoBuildings -= b;
 
-		for (auto autoBuilding : remainingAutoBuildings)
+		for(auto autoBuilding : remainingAutoBuildings)
 		{
-			if (autoBuilding->requirements.test(areRequirementsFullfilled))
+			auto actualRequirements = t->genBuildingRequirements(autoBuilding->bid);
+
+			if(actualRequirements.test(areRequirementsFullfilled))
 				buildingsToAdd.push(autoBuilding);
 		}
 	}