Browse Source

Remove hardcoded checks for Conflux and Inferno Grails

Ivan Savenko 1 month ago
parent
commit
8e74797650

+ 1 - 1
config/factions/conflux.json

@@ -196,7 +196,7 @@
 						"earthMagic"
 					]
 				},
-				"grail":          { },
+				"grail":          { "type" : "auroraBorealis" },
 				"extraTownHall":  { },
 				"extraCityHall":  { },
 				"extraCapitol":   { },

+ 1 - 1
config/factions/inferno.json

@@ -205,7 +205,7 @@
 				},
 				"horde2":         { "upgrades" : "dwellingLvl3" },
 				"horde2Upgr":     { "upgrades" : "dwellingUpLvl3", "requires" : [ "horde2" ] },
-				"grail":          { },
+				"grail":          { "type" : "deityOfFire" },
 
 				"dwellingLvl1":   { "requires" : [ "fort" ] },
 				"dwellingLvl2":   { "requires" : [ "dwellingLvl1" ] },

+ 3 - 1
lib/constants/Enumerations.h

@@ -31,7 +31,9 @@ namespace BuildingSubID
 		PORTAL_OF_SUMMONING,
 		ESCAPE_TUNNEL,
 		TREASURY,
-		BANK
+		BANK,
+		AURORA_BOREALIS,
+		DEITY_OF_FIRE
 	};
 }
 

+ 3 - 1
lib/constants/StringConstants.h

@@ -135,7 +135,9 @@ namespace MappedKeys
 		{ "library", BuildingSubID::LIBRARY },
 		{ "escapeTunnel", BuildingSubID::ESCAPE_TUNNEL },
 		{ "treasury", BuildingSubID::TREASURY },
-		{ "bank", BuildingSubID::BANK }
+		{ "bank", BuildingSubID::BANK },
+		{ "auroraBorealis", BuildingSubID::AURORA_BOREALIS },
+		{ "deityOfFire", BuildingSubID::DEITY_OF_FIRE }
 	};
 
 	static const std::map<std::string, EMarketMode> MARKET_NAMES_TO_TYPES =

+ 0 - 7
lib/mapObjects/CGTownInstance.cpp

@@ -905,13 +905,6 @@ bool CGTownInstance::hasBuilt(const BuildingID & buildingID) const
 	return vstd::contains(builtBuildings, buildingID);
 }
 
-bool CGTownInstance::hasBuilt(const BuildingID & buildingID, FactionID townID) const
-{
-	if (townID == getTown()->faction->getId() || townID == FactionID::ANY)
-		return hasBuilt(buildingID);
-	return false;
-}
-
 void CGTownInstance::addBuilding(const BuildingID & buildingID)
 {
 	if(buildingID == BuildingID::NONE)

+ 0 - 1
lib/mapObjects/CGTownInstance.h

@@ -165,7 +165,6 @@ public:
 	bool hasBuilt(BuildingSubID::EBuildingSubID buildingID) const;
 	//checks if building is constructed and town has same subID
 	bool hasBuilt(const BuildingID & buildingID) const;
-	bool hasBuilt(const BuildingID & buildingID, FactionID townID) const;
 	void addBuilding(const BuildingID & buildingID);
 	void removeBuilding(const BuildingID & buildingID);
 	void removeAllBuildings();

+ 15 - 19
server/CGameHandler.cpp

@@ -773,7 +773,7 @@ void CGameHandler::giveSpells(const CGTownInstance *t, const CGHeroInstance *h)
 	ChangeSpells cs;
 	cs.hid = h->id;
 	cs.learn = true;
-	if (t->hasBuilt(BuildingID::GRAIL, ETownType::CONFLUX) && t->hasBuilt(BuildingID::MAGES_GUILD_1))
+	if (t->hasBuilt(BuildingSubID::AURORA_BOREALIS) && t->hasBuilt(BuildingID::MAGES_GUILD_1))
 	{
 		// Aurora Borealis give spells of all levels even if only level 1 mages guild built
 		for (int i = 0; i < h->maxSpellLevel(); i++)
@@ -2115,22 +2115,6 @@ bool CGameHandler::buildStructure(ObjectInstanceID tid, BuildingID requestedID,
 		}
 	};
 
-	//Performs stuff that has to be done after new building is built
-	auto processAfterBuiltStructure = [t, this](const BuildingID buildingID)
-	{
-		auto isMageGuild = (buildingID <= BuildingID::MAGES_GUILD_5 && buildingID >= BuildingID::MAGES_GUILD_1);
-		auto isLibrary = isMageGuild ? false
-			: t->getTown()->buildings.at(buildingID)->subId == BuildingSubID::EBuildingSubID::LIBRARY;
-
-		if(isMageGuild || isLibrary || (t->getFactionID() == ETownType::CONFLUX && buildingID == BuildingID::GRAIL))
-		{
-			if(t->getVisitingHero())
-				giveSpells(t,t->getVisitingHero());
-			if(t->getGarrisonHero())
-				giveSpells(t,t->getGarrisonHero());
-		}
-	};
-
 	//Checks if all requirements will be met with expected building list "buildingsThatWillBe"
 	auto areRequirementsFulfilled = [&buildingsThatWillBe](const BuildingID & buildID)
 	{
@@ -2192,8 +2176,20 @@ bool CGameHandler::buildStructure(ObjectInstanceID tid, BuildingID requestedID,
 	sendAndApply(ns);
 
 	//Other post-built events. To some logic like giving spells to work gamestate changes for new building must be already in place!
-	for(auto builtID : ns.bid)
-		processAfterBuiltStructure(builtID);
+	for(auto buildingID : ns.bid)
+	{
+		bool isMageGuild = buildingID <= BuildingID::MAGES_GUILD_5 && buildingID >= BuildingID::MAGES_GUILD_1;
+		bool isLibrary = t->getTown()->buildings.at(buildingID)->subId == BuildingSubID::LIBRARY;
+		bool isAurora = t->getTown()->buildings.at(buildingID)->subId == BuildingSubID::AURORA_BOREALIS;
+
+		if(isMageGuild || isLibrary || isAurora)
+		{
+			if(t->getVisitingHero())
+				giveSpells(t,t->getVisitingHero());
+			if(t->getGarrisonHero())
+				giveSpells(t,t->getGarrisonHero());
+		}
+	};
 
 	// now when everything is built - reveal tiles for lookout tower
 	changeFogOfWar(t->getSightCenter(), t->getSightRadius(), t->getOwner(), ETileVisibility::REVEALED);

+ 1 - 1
server/processors/NewTurnProcessor.cpp

@@ -512,7 +512,7 @@ std::tuple<EWeekType, CreatureID> NewTurnProcessor::pickWeekType(bool newMonth)
 	for (const auto & townID : gameHandler->gameState().getMap().getAllTowns())
 	{
 		const auto * t = gameHandler->gameState().getTown(townID);
-		if (t->hasBuilt(BuildingID::GRAIL, ETownType::INFERNO))
+		if (t->hasBuilt(BuildingSubID::DEITY_OF_FIRE))
 			return { EWeekType::DEITYOFFIRE, CreatureID::IMP };
 	}