1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Important fix for unreserving objects.

This commit is contained in:
DjWarmonger 2014-02-23 20:37:33 +00:00
parent 94c8f01732
commit 8ce6659633
2 changed files with 12 additions and 5 deletions

View File

@ -245,8 +245,7 @@ void VCAI::heroVisit(const CGHeroInstance *visitor, const CGObjectInstance *visi
if(start)
{
markObjectVisited (visitedObj);
erase_if_present(reservedObjs, visitedObj); //unreserve objects
erase_if_present(reservedHeroesMap[visitor], visitedObj);
unreserveObject(visitor, visitedObj);
completeGoal (sptr(Goals::GetObj(visitedObj->id.getNum()).sethero(visitor))); //we don't need to visit it anymore
//TODO: what if we visited one-time visitable object that was reserved by another hero (shouldn't, but..)
}
@ -1249,10 +1248,11 @@ bool VCAI::canRecruitAnyHero (const CGTownInstance * t) const
void VCAI::wander(HeroPtr h)
{
//unclaim objects that are now dangerous for us
erase_if(reservedHeroesMap[h], [h](const CGObjectInstance * obj) -> bool
for (auto obj : reservedHeroesMap[h])
{
return !isSafeToVisit(h, obj->visitablePos());
});
if (!isSafeToVisit(h, obj->visitablePos()))
unreserveObject(h, obj);
}
TimeCheck tc("looking for wander destination");
@ -1462,6 +1462,12 @@ void VCAI::reserveObject(HeroPtr h, const CGObjectInstance *obj)
logAi->debugStream() << "reserved object id=" << obj->id << "; address=" << (intptr_t)obj << "; name=" << obj->getHoverText();
}
void VCAI::unreserveObject(HeroPtr h, const CGObjectInstance *obj)
{
erase_if_present(reservedObjs, obj); //unreserve objects
erase_if_present(reservedHeroesMap[h], obj);
}
void VCAI::validateVisitableObjs()
{
std::vector<const CGObjectInstance *> hlp;

View File

@ -282,6 +282,7 @@ public:
void addVisitableObj(const CGObjectInstance *obj);
void markObjectVisited (const CGObjectInstance *obj);
void reserveObject (HeroPtr h, const CGObjectInstance *obj); //TODO: reserve all objects that heroes attempt to visit
void unreserveObject (HeroPtr h, const CGObjectInstance *obj);
//void removeVisitableObj(const CGObjectInstance *obj);
void validateObject(const CGObjectInstance *obj); //checks if object is still visible and if not, removes references to it
void validateObject(ObjectIdRef obj); //checks if object is still visible and if not, removes references to it