mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-26 22:57:00 +02:00
Merge pull request #533 from nullkiller/AI-fix-freeze-on-buyarmy
AI: fix one more freeze in buy army
This commit is contained in:
commit
a1ff355927
@ -528,11 +528,18 @@ creInfo infoFromDC(const dwellingContent & dc)
|
||||
ui64 howManyReinforcementsCanBuy(const CArmedInstance * h, const CGDwelling * t)
|
||||
{
|
||||
ui64 aivalue = 0;
|
||||
|
||||
TResources availableRes = cb->getResourceAmount();
|
||||
int freeHeroSlots = GameConstants::ARMY_SIZE - h->stacksCount();
|
||||
|
||||
for(auto const dc : t->creatures)
|
||||
{
|
||||
creInfo ci = infoFromDC(dc);
|
||||
|
||||
if(!ci.count || ci.creID == -1)
|
||||
continue;
|
||||
|
||||
vstd::amin(ci.count, availableRes / ci.cre->cost); //max count we can afford
|
||||
|
||||
if(ci.count && ci.creID != -1) //valid creature at this level
|
||||
{
|
||||
//can be merged with another stack?
|
||||
@ -547,6 +554,7 @@ ui64 howManyReinforcementsCanBuy(const CArmedInstance * h, const CGDwelling * t)
|
||||
|
||||
//we found matching occupied or free slot
|
||||
aivalue += ci.count * ci.cre->AIValue;
|
||||
availableRes -= ci.cre->cost * ci.count;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -79,12 +79,6 @@ TGoalVec GatherArmy::getAllPossibleSubgoals()
|
||||
|
||||
int val = *std::min_element(values.begin(), values.end());
|
||||
|
||||
logAi->trace(
|
||||
"Army value need %i, to hero %i, to town %i",
|
||||
value,
|
||||
(int)howManyReinforcementsCanBuy(hero.get(), t),
|
||||
(int)howManyReinforcementsCanBuy(t->getUpperArmy(), t));
|
||||
|
||||
if (val)
|
||||
{
|
||||
auto goal = sptr(BuyArmy(t, val).sethero(hero));
|
||||
|
@ -81,7 +81,15 @@ TGoalVec GatherTroops::getAllPossibleSubgoals()
|
||||
|
||||
if(count >= this->value)
|
||||
{
|
||||
vstd::concatenate(solutions, ai->ah->howToVisitObj(t));
|
||||
if(t->visitingHero)
|
||||
{
|
||||
solutions.push_back(sptr(VisitObj(t->id.getNum()).sethero(t->visitingHero.get())));
|
||||
}
|
||||
else
|
||||
{
|
||||
vstd::concatenate(solutions, ai->ah->howToVisitObj(t));
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -97,7 +105,7 @@ TGoalVec GatherTroops::getAllPossibleSubgoals()
|
||||
continue;
|
||||
|
||||
BuildingID bid(BuildingID::DWELL_FIRST + creature->level - 1 + upgradeNumber * GameConstants::CREATURES_PER_TOWN);
|
||||
if(t->hasBuilt(bid)) //this assumes only creatures with dwellings are assigned to faction
|
||||
if(t->hasBuilt(bid) && ai->ah->freeResources().canAfford(creature->cost)) //this assumes only creatures with dwellings are assigned to faction
|
||||
{
|
||||
solutions.push_back(sptr(BuyArmy(t, creature->AIValue * this->value).setobjid(objid)));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user