1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-21 21:17:49 +02:00

New object target handling in wander

This commit is contained in:
Dydzio 2018-08-09 16:28:15 +02:00
parent 01709bd196
commit 616a6bbdf7
2 changed files with 11 additions and 10 deletions

View File

@ -1142,7 +1142,7 @@ TGoalVec Goals::CollectRes::getAllPossibleSubgoals()
if (dest != t) //there is something blocking our way if (dest != t) //there is something blocking our way
ret.push_back(sptr(Goals::ClearWayTo(dest, h).setisAbstract(true))); ret.push_back(sptr(Goals::ClearWayTo(dest, h).setisAbstract(true)));
else 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 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))); ret.push_back(sptr(Goals::GatherArmy(evaluateDanger(dest, h) * SAFE_ATTACK_CONSTANT).sethero(h).setisAbstract(true)));

View File

@ -1460,17 +1460,18 @@ void VCAI::wander(HeroPtr h)
//end of objs empty //end of objs empty
if(dests.size()) //performance improvement 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); targetObjectGoals.push_back(sptr(Goals::GetObj(destination.id.getNum()).sethero(h).setisAbstract(true)));
}; }
auto bestObjectGoal = fh->chooseSolution(targetObjectGoals);
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 decomposeGoal(bestObjectGoal)->accept(this);
//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
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(), bestObjectGoal->objid);
if (!goVisitObj(dest, h)) /*if (!goVisitObj(dest, h))
{ {
if (!dest) if (!dest)
{ {
@ -1483,7 +1484,7 @@ void VCAI::wander(HeroPtr h)
} }
} }
else //we reached our destination else //we reached our destination
visitTownIfAny(h); visitTownIfAny(h);*/
} }
} }
visitTownIfAny(h); //in case hero is just sitting in town visitTownIfAny(h); //in case hero is just sitting in town