From 264a0c4fe72332a1b7a0b88eefd9ef825e810585 Mon Sep 17 00:00:00 2001 From: DjWarmonger Date: Tue, 7 Apr 2015 08:55:13 +0200 Subject: [PATCH] - Restored evaluation of wander targets at every step. - First wander target will be sorted by distance (closest) as well. --- AI/VCAI/VCAI.cpp | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/AI/VCAI/VCAI.cpp b/AI/VCAI/VCAI.cpp index 0ccf2562e..d9dc56415 100644 --- a/AI/VCAI/VCAI.cpp +++ b/AI/VCAI/VCAI.cpp @@ -1413,8 +1413,10 @@ void VCAI::wander(HeroPtr h) } //end of objs empty - while (dests.size()) //performance improvement + if (dests.size()) //performance improvement { + boost::sort(dests, CDistanceSorter(h.get())); //find next closest one + //wander should not cause heroes to be reserved - they are always considered free const ObjectIdRef&dest = dests.front(); logAi->debugStream() << boost::format("Of all %d destinations, object oid=%d seems nice") % dests.size() % dest.id.getNum(); @@ -1430,22 +1432,6 @@ void VCAI::wander(HeroPtr h) return; } } - //TODO: refactor removing deleted objects from the list - std::vector hlp; - retreiveVisitableObjs(hlp, true); - - auto shouldBeErased = [&](const CGObjectInstance *obj) -> bool - { - if(!vstd::contains(hlp, obj)) - { - return true; - } - return false; - }; - erase_if(dests, shouldBeErased); - - erase_if_present(dests, dest); //why that fails sometimes when removing monsters? - boost::sort(dests, CDistanceSorter(h.get())); //find next closest one } if (h->visitedTown)