mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-14 02:33:51 +02:00
VCAI::wander: map object selection refactoring
Avoid doing extra steps that's not needed. Related to issue 2454.
This commit is contained in:
parent
8533ee3256
commit
b83dea2008
@ -1408,24 +1408,6 @@ bool VCAI::isGoodForVisit(const CGObjectInstance *obj, HeroPtr h, SectorMap &sm)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<const CGObjectInstance *> VCAI::getPossibleDestinations(HeroPtr h)
|
|
||||||
{
|
|
||||||
validateVisitableObjs();
|
|
||||||
std::vector<const CGObjectInstance *> possibleDestinations;
|
|
||||||
auto sm = getCachedSectorMap(h);
|
|
||||||
for(const CGObjectInstance *obj : visitableObjs)
|
|
||||||
{
|
|
||||||
if (isGoodForVisit(obj, h, *sm))
|
|
||||||
{
|
|
||||||
possibleDestinations.push_back(obj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
boost::sort(possibleDestinations, CDistanceSorter(h.get()));
|
|
||||||
|
|
||||||
return possibleDestinations;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool VCAI::isTileNotReserved(const CGHeroInstance * h, int3 t)
|
bool VCAI::isTileNotReserved(const CGHeroInstance * h, int3 t)
|
||||||
{
|
{
|
||||||
if (t.valid())
|
if (t.valid())
|
||||||
@ -1468,20 +1450,25 @@ void VCAI::wander(HeroPtr h)
|
|||||||
while (h->movement)
|
while (h->movement)
|
||||||
{
|
{
|
||||||
validateVisitableObjs();
|
validateVisitableObjs();
|
||||||
std::vector <ObjectIdRef> dests, tmp;
|
std::vector <ObjectIdRef> dests;
|
||||||
|
|
||||||
auto sm = getCachedSectorMap(h);
|
auto sm = getCachedSectorMap(h);
|
||||||
|
|
||||||
range::copy(reservedHeroesMap[h], std::back_inserter(tmp)); //also visit our reserved objects - but they are not prioritized to avoid running back and forth
|
//also visit our reserved objects - but they are not prioritized to avoid running back and forth
|
||||||
for (auto obj : tmp)
|
vstd::copy_if(reservedHeroesMap[h], std::back_inserter(dests), [&](ObjectIdRef obj) -> bool
|
||||||
{
|
{
|
||||||
int3 pos = sm->firstTileToGet(h, obj->visitablePos());
|
int3 pos = sm->firstTileToGet(h, obj->visitablePos());
|
||||||
if (pos.valid())
|
if(pos.valid() && isAccessibleForHero(pos, h)) //even nearby objects could be blocked by other heroes :(
|
||||||
if (isAccessibleForHero (pos, h)) //even nearby objects could be blocked by other heroes :(
|
return true;
|
||||||
dests.push_back(obj); //can't use lambda for member function :(
|
|
||||||
}
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
vstd::copy_if(visitableObjs, std::back_inserter(dests), [&](ObjectIdRef obj) -> bool
|
||||||
|
{
|
||||||
|
return isGoodForVisit(obj, h, *sm);
|
||||||
|
});
|
||||||
|
|
||||||
range::copy(getPossibleDestinations(h), std::back_inserter(dests));
|
|
||||||
vstd::erase_if(dests, [&](ObjectIdRef obj) -> bool
|
vstd::erase_if(dests, [&](ObjectIdRef obj) -> bool
|
||||||
{
|
{
|
||||||
return !isSafeToVisit(h, sm->firstTileToGet(h, obj->visitablePos()));
|
return !isSafeToVisit(h, sm->firstTileToGet(h, obj->visitablePos()));
|
||||||
|
@ -259,7 +259,6 @@ public:
|
|||||||
|
|
||||||
void recruitHero(const CGTownInstance * t, bool throwing = false);
|
void recruitHero(const CGTownInstance * t, bool throwing = false);
|
||||||
bool isGoodForVisit(const CGObjectInstance *obj, HeroPtr h, SectorMap &sm);
|
bool isGoodForVisit(const CGObjectInstance *obj, HeroPtr h, SectorMap &sm);
|
||||||
std::vector<const CGObjectInstance *> getPossibleDestinations(HeroPtr h);
|
|
||||||
void buildStructure(const CGTownInstance * t);
|
void buildStructure(const CGTownInstance * t);
|
||||||
//void recruitCreatures(const CGTownInstance * t);
|
//void recruitCreatures(const CGTownInstance * t);
|
||||||
void recruitCreatures(const CGDwelling * d, const CArmedInstance * recruiter);
|
void recruitCreatures(const CGDwelling * d, const CArmedInstance * recruiter);
|
||||||
|
Loading…
Reference in New Issue
Block a user