Fixed pathfinding for usage with Rule::findTarget()
Fixed Entity::target being public
This commit is contained in:
parent
08e922b0d4
commit
4ab83f1124
4 changed files with 23 additions and 16 deletions
|
@ -57,9 +57,9 @@ void Level::runStep()
|
|||
{
|
||||
heuristicSign = -1;
|
||||
}
|
||||
if(entity.target != entity.getPosition())
|
||||
if(entity.getTarget() != entity.getPosition())
|
||||
{
|
||||
entity.move(findPath(entity.getPosition(),entity.target,heuristicSign));
|
||||
entity.move(findPath(entity.getPosition(),entity.getTarget(),heuristicSign));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -93,14 +93,6 @@ Orientation Level::findPath(pro_maat::GridPos start, pro_maat::GridPos goal, int
|
|||
std::map<pro_maat::GridPos,pro_maat::GridPos> paths{};
|
||||
|
||||
|
||||
// TODO : Should be OK with raycasting to find goal
|
||||
// FIXME : Just get to goal (Might break)
|
||||
const std::vector<pro_maat::GridPos> goalNeighbours = pro_maat::getNeighbours(goal,size);
|
||||
// Save the iterators : vector is const and .begin() and .end() might get called a lot
|
||||
auto goalNeighboursBeginIterator = goalNeighbours.begin();
|
||||
auto goalNeighboursEndIterator = goalNeighbours.end();
|
||||
|
||||
|
||||
// FIXME : Find an efficient way to get rid of openNodes.find calls
|
||||
// Lambda checking if the current element is also in the open nodes set
|
||||
auto compWithOpen = [&openNodes](const std::pair<pro_maat::GridPos,float>& leftHandSide,
|
||||
|
@ -125,7 +117,7 @@ Orientation Level::findPath(pro_maat::GridPos start, pro_maat::GridPos goal, int
|
|||
// Expand from the open node with the smallest estimated cost
|
||||
pro_maat::GridPos currentNode = std::min_element(estimatedCosts.begin(),estimatedCosts.end(),compWithOpen)->first;
|
||||
|
||||
if(std::find(goalNeighboursBeginIterator,goalNeighboursEndIterator,currentNode) != goalNeighboursEndIterator)
|
||||
if(currentNode == goal)
|
||||
{
|
||||
if(currentNode == start)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue