mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
ResourceManager-compliant money saving for income buildings
This commit is contained in:
parent
b69c316409
commit
e13e88bf5c
@ -163,7 +163,8 @@ bool BuildingManager::getBuildingOptions(const CGTownInstance * t)
|
||||
immediateBuildings.clear();
|
||||
expensiveBuildings.clear();
|
||||
|
||||
//below algorithm focuses on economy growth at start of the game.
|
||||
//below algorithm focuses on economy growth at start of the game, saving money instead of build rushing is handled by Build goal
|
||||
//changing code blocks order will alter behavior by changing order of adding elements to immediateBuildings / expensiveBuildings
|
||||
|
||||
TResources currentRes = cb->getResourceAmount();
|
||||
TResources currentIncome = t->dailyIncome();
|
||||
@ -187,8 +188,6 @@ bool BuildingManager::getBuildingOptions(const CGTownInstance * t)
|
||||
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)
|
||||
|
||||
|
||||
if (cb->getDate(Date::DAY_OF_WEEK) > 6) // last 2 days of week - try to focus on growth
|
||||
|
@ -1364,18 +1364,39 @@ TGoalVec Goals::Build::getAllPossibleSubgoals()
|
||||
{
|
||||
//start fresh with every town
|
||||
ai->ah->getBuildingOptions(t);
|
||||
auto ib = ai->ah->immediateBuilding();
|
||||
if (ib.is_initialized())
|
||||
auto immediateBuilding = ai->ah->immediateBuilding();
|
||||
auto expensiveBuilding = ai->ah->expensiveBuilding();
|
||||
|
||||
//handling for early town development to save money and focus on income
|
||||
if(!t->hasBuilt(ai->ah->getMaxPossibleGoldBuilding(t)) && expensiveBuilding.is_initialized())
|
||||
{
|
||||
ret.push_back(sptr(Goals::BuildThis(ib.get().bid, t).setpriority(2))); //prioritize buildings we can build quick
|
||||
auto potentialBuilding = expensiveBuilding.get();
|
||||
switch(expensiveBuilding.get().bid)
|
||||
{
|
||||
case BuildingID::TOWN_HALL:
|
||||
case BuildingID::CITY_HALL:
|
||||
case BuildingID::CAPITOL:
|
||||
case BuildingID::FORT:
|
||||
case BuildingID::CITADEL:
|
||||
case BuildingID::CASTLE:
|
||||
//If above buildings are next to be bought, but no money... do not buy anything else, try to gather resources for these. Simple but has to suffice for now.
|
||||
auto goal = ai->ah->whatToDo(potentialBuilding.price, sptr(Goals::BuildThis(potentialBuilding.bid, t).setpriority(2.25)));
|
||||
ret.push_back(goal);
|
||||
return ret;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (immediateBuilding.is_initialized())
|
||||
{
|
||||
ret.push_back(sptr(Goals::BuildThis(immediateBuilding.get().bid, t).setpriority(2))); //prioritize buildings we can build quick
|
||||
}
|
||||
else //try build later
|
||||
{
|
||||
auto eb = ai->ah->expensiveBuilding();
|
||||
if (eb.is_initialized())
|
||||
if (expensiveBuilding.is_initialized())
|
||||
{
|
||||
auto pb = eb.get(); //gather resources for any we can't afford
|
||||
auto goal = ai->ah->whatToDo(pb.price, sptr(Goals::BuildThis(pb.bid, t).setpriority(0.5)));
|
||||
auto potentialBuilding = expensiveBuilding.get(); //gather resources for any we can't afford
|
||||
auto goal = ai->ah->whatToDo(potentialBuilding.price, sptr(Goals::BuildThis(potentialBuilding.bid, t).setpriority(0.5)));
|
||||
ret.push_back(goal);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user