2
0
Эх сурвалжийг харах

Disable building from army goals, re-fix building capitol prereqs

Dydzio 7 жил өмнө
parent
commit
12e1e5b315

+ 14 - 12
AI/VCAI/BuildingManager.cpp

@@ -157,6 +157,8 @@ bool BuildingManager::getBuildingOptions(const CGTownInstance * t)
 	//TODO: faction-specific development: use special buildings, build dwellings in better order, etc
 	//TODO: build resource silo, defences when needed
 	//Possible - allow "locking" on specific building (build prerequisites and then building itself)
+	
+	//TODO: There is some disabled building code in GatherTroops and GatherArmy - take it into account when enhancing building. For now AI works best with building only via Build goal.
 
 	immediateBuildings.clear();
 	expensiveBuildings.clear();
@@ -169,26 +171,26 @@ bool BuildingManager::getBuildingOptions(const CGTownInstance * t)
 	if (tryBuildAnyStructure(t, std::vector<BuildingID>(essential, essential + ARRAY_COUNT(essential))))
 		return true;
 
-	//the more gold the better and less problems later //TODO: what about building mage guild / marketplace etc. with city hall disabled in editor?
-	if (tryBuildNextStructure(t, std::vector<BuildingID>(goldSource, goldSource + ARRAY_COUNT(goldSource))))
-		return true;
-
-	if(!t->hasBuilt(BuildingID::FORT)) //in vast majority of situations fort is top priority building if we already have city hall, TODO: unite with unitGrowth building chain
-		if(tryBuildThisStructure(t, BuildingID::FORT))
-			return true;
-
-	//workaround for mantis #2696 - build fort and citadel - building castle will be handled without bug //RECHECK THIS CODE BLOCK - its logic predates building manager
-	if (vstd::contains(t->builtBuildings, BuildingID::CITY_HALL) &&
+	//workaround for mantis #2696 - build fort and citadel - building castle prerequisite when trying to build capitol will be then handled without bug
+	if(vstd::contains(t->builtBuildings, BuildingID::CITY_HALL) &&
 		cb->canBuildStructure(t, BuildingID::CAPITOL) != EBuildingState::HAVE_CAPITAL)
 	{
-		if (cb->canBuildStructure(t, BuildingID::CAPITOL) != EBuildingState::FORBIDDEN)
+		if(cb->canBuildStructure(t, BuildingID::CAPITOL) != EBuildingState::FORBIDDEN)
 		{
-			if (tryBuildNextStructure(t, std::vector<BuildingID>(capitolRequirements,
+			if(tryBuildNextStructure(t, std::vector<BuildingID>(capitolRequirements,
 				capitolRequirements + ARRAY_COUNT(capitolRequirements))))
 				return true;
 		}
 	}
 
+	//the more gold the better and less problems later //TODO: what about building mage guild / marketplace etc. with city hall disabled in editor?
+	if (tryBuildNextStructure(t, std::vector<BuildingID>(goldSource, goldSource + ARRAY_COUNT(goldSource))))
+		return true;
+
+	if(!t->hasBuilt(BuildingID::FORT)) //in vast majority of situations fort is top priority building if we already have city hall, TODO: unite with unitGrowth building chain
+		if(tryBuildThisStructure(t, BuildingID::FORT))
+			return true;
+
 	//TODO: save money for capitol or city hall if capitol unavailable
 	//do not build other things (unless gold source buildings are disabled in map editor)
 

+ 7 - 5
AI/VCAI/Goals.cpp

@@ -1227,10 +1227,10 @@ TSubgoal GatherTroops::whatToDoToAchieve()
 			{
 				dwellings.push_back(t);
 			}
-			else
-			{
+			/*else //disable random building requests for now - this code needs to know a lot of town/resource context to do more good than harm
+			{	
 				return sptr(Goals::BuildThis(bid, t).setpriority(priority));
-			}
+			}*/
 		}
 	}
 	for(auto obj : ai->visitableObjs)
@@ -1459,7 +1459,9 @@ TGoalVec GatherArmy::getAllPossibleSubgoals()
 			//build dwelling
 			//TODO: plan building over multiple turns?
 			//auto bid = ah->canBuildAnyStructure(t, std::vector<BuildingID>(unitsSource, unitsSource + ARRAY_COUNT(unitsSource)), 8 - cb->getDate(Date::DAY_OF_WEEK));
-			auto bid = ai->ah->canBuildAnyStructure(t, std::vector<BuildingID>(unitsSource, unitsSource + ARRAY_COUNT(unitsSource)), 1);
+
+			//Do not use below code for now, rely on generic Build. Code below needs to know a lot of town/resource context to do more good than harm
+			/*auto bid = ai->ah->canBuildAnyStructure(t, std::vector<BuildingID>(unitsSource, unitsSource + ARRAY_COUNT(unitsSource)), 1);
 			if (bid.is_initialized())
 			{
 				auto goal = sptr(BuildThis(bid.get(), t).setpriority(priority));
@@ -1467,7 +1469,7 @@ TGoalVec GatherArmy::getAllPossibleSubgoals()
 					ret.push_back(goal);
 				else
 					logAi->debug("Can not build a structure, because of ai->ah->containsObjective");
-			}
+			}*/
 		}
 	}