diff --git a/AI/VCAI/Goals.cpp b/AI/VCAI/Goals.cpp index 6bdca1c0f..16561de7d 100644 --- a/AI/VCAI/Goals.cpp +++ b/AI/VCAI/Goals.cpp @@ -1142,7 +1142,7 @@ TGoalVec Goals::CollectRes::getAllPossibleSubgoals() if (dest != t) //there is something blocking our way ret.push_back(sptr(Goals::ClearWayTo(dest, h).setisAbstract(true))); else - ret.push_back(sptr(Goals::VisitTile(dest).sethero(h).setisAbstract(true))); + ret.push_back(sptr(Goals::GetObj(obj->id.getNum()).sethero(h).setisAbstract(true))); } else //we need to get army in order to pick that object ret.push_back(sptr(Goals::GatherArmy(evaluateDanger(dest, h) * SAFE_ATTACK_CONSTANT).sethero(h).setisAbstract(true))); diff --git a/AI/VCAI/VCAI.cpp b/AI/VCAI/VCAI.cpp index 1f20abf64..1d532879c 100644 --- a/AI/VCAI/VCAI.cpp +++ b/AI/VCAI/VCAI.cpp @@ -1460,17 +1460,18 @@ void VCAI::wander(HeroPtr h) //end of objs empty if(dests.size()) //performance improvement - { - auto fuzzyLogicSorter = [h](const ObjectIdRef & l, const ObjectIdRef & r) -> bool //TODO: create elementar GetObj goal usable for goal decomposition and Wander based on VisitTile logic and object value on top of it + { + Goals::TGoalVec targetObjectGoals; + for(auto destination : dests) { - return fh->getWanderTargetObjectValue( *h.get(), l) < fh->getWanderTargetObjectValue(*h.get(), r); - }; - - const ObjectIdRef & dest = *boost::max_element(dests, fuzzyLogicSorter); //find best object to visit based on fuzzy logic evaluation, TODO: use elementar version of GetObj here in future + targetObjectGoals.push_back(sptr(Goals::GetObj(destination.id.getNum()).sethero(h).setisAbstract(true))); + } + auto bestObjectGoal = fh->chooseSolution(targetObjectGoals); + decomposeGoal(bestObjectGoal)->accept(this); //wander should not cause heroes to be reserved - they are always considered free - logAi->debug("Of all %d destinations, object oid=%d seems nice", dests.size(), dest.id.getNum()); - if (!goVisitObj(dest, h)) + logAi->debug("Of all %d destinations, object oid=%d seems nice", dests.size(), bestObjectGoal->objid); + /*if (!goVisitObj(dest, h)) { if (!dest) { @@ -1483,7 +1484,7 @@ void VCAI::wander(HeroPtr h) } } else //we reached our destination - visitTownIfAny(h); + visitTownIfAny(h);*/ } } visitTownIfAny(h); //in case hero is just sitting in town