1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-26 03:52:01 +02:00

Minor optimisations. Also, shoter code.

This commit is contained in:
DJWarmonger 2018-07-19 17:36:10 +02:00
parent f8a9a0af2b
commit 3d59420bb5
2 changed files with 12 additions and 18 deletions

View File

@ -313,9 +313,7 @@ Goals::TSubgoal FuzzyHelper::chooseSolution(Goals::TGoalVec vec)
{ {
return lhs->priority < rhs->priority; return lhs->priority < rhs->priority;
}; };
boost::sort(vec, compareGoals); return *boost::max_element(vec, compareGoals);
return vec.back();
} }
float FuzzyHelper::evaluate(Goals::Explore & g) float FuzzyHelper::evaluate(Goals::Explore & g)

View File

@ -841,8 +841,7 @@ void VCAI::makeTurnInternal()
{ {
return m1.second->priority < m2.second->priority; return m1.second->priority < m2.second->priority;
}; };
boost::sort(safeCopy, lockedHeroesSorter); striveToGoal(boost::max_element(safeCopy, lockedHeroesSorter)->second);
striveToGoal(safeCopy.back().second);
} }
} }
@ -1585,9 +1584,8 @@ void VCAI::wander(HeroPtr h)
} }
else if(townsNotReachable.size()) else if(townsNotReachable.size())
{ {
boost::sort(townsNotReachable, compareReinforcements);
//TODO pick the truly best //TODO pick the truly best
const CGTownInstance * t = townsNotReachable.back(); const CGTownInstance * t = *boost::max_element(townsNotReachable, compareReinforcements);
logAi->debug("%s can't reach any town, we'll try to make our way to %s at %s", h->name, t->name, t->visitablePos().toString()); logAi->debug("%s can't reach any town, we'll try to make our way to %s at %s", h->name, t->name, t->visitablePos().toString());
int3 pos1 = h->pos; int3 pos1 = h->pos;
striveToGoal(sptr(Goals::ClearWayTo(t->visitablePos()).sethero(h))); striveToGoal(sptr(Goals::ClearWayTo(t->visitablePos()).sethero(h)));
@ -1612,9 +1610,10 @@ void VCAI::wander(HeroPtr h)
} }
return false; return false;
}); });
boost::sort(towns, compareArmyStrength); if (towns.size())
if(towns.size()) {
recruitHero(towns.back()); recruitHero(*boost::max_element(towns, compareArmyStrength));
}
break; break;
} }
else else
@ -1627,10 +1626,9 @@ void VCAI::wander(HeroPtr h)
if(dests.size()) //performance improvement if(dests.size()) //performance improvement
{ {
boost::sort(dests, CDistanceSorter(h.get())); //find next closest one const ObjectIdRef & dest = *boost::min_element(dests, CDistanceSorter(h.get())); //find next closest one
//wander should not cause heroes to be reserved - they are always considered free //wander should not cause heroes to be reserved - they are always considered free
const ObjectIdRef & dest = dests.front();
logAi->debug("Of all %d destinations, object oid=%d seems nice", dests.size(), dest.id.getNum()); logAi->debug("Of all %d destinations, object oid=%d seems nice", dests.size(), dest.id.getNum());
if(!goVisitObj(dest, h)) if(!goVisitObj(dest, h))
{ {
@ -2317,12 +2315,10 @@ bool VCAI::canAct(HeroPtr h) const
HeroPtr VCAI::primaryHero() const HeroPtr VCAI::primaryHero() const
{ {
auto hs = cb->getHeroesInfo(); auto hs = cb->getHeroesInfo();
boost::sort(hs, compareHeroStrength); if (hs.empty())
if(hs.empty())
return nullptr; return nullptr;
else
return hs.back(); return *boost::max_element(hs, compareHeroStrength);
} }
void VCAI::endTurn() void VCAI::endTurn()