Final fix for end of movement
I was being dumb again : if we are adjacent to a target entity, stop moving
This commit is contained in:
parent
b85d46e450
commit
2d8b1e53ce
2 changed files with 9 additions and 10 deletions
16
src/Rule.cpp
16
src/Rule.cpp
|
@ -13,9 +13,7 @@ Rule::Rule(std::shared_ptr<Entity> entity, State targetState, EntityType targetT
|
|||
targetType(targetType),
|
||||
entities(entities),
|
||||
occupiedSquares(occupiedSquares),
|
||||
mapSize(mapSize),
|
||||
previousPosition(this->entity->getPosition()),
|
||||
previousTarget(this->entity->target)
|
||||
mapSize(mapSize)
|
||||
{}
|
||||
|
||||
void Rule::update()
|
||||
|
@ -23,13 +21,10 @@ void Rule::update()
|
|||
if (targetState == State::Moving || targetState == State::Fleeing)
|
||||
{
|
||||
pro_maat::GridPos target = findTarget();
|
||||
if(target != previousPosition && (entity->getPosition() != previousTarget || entity->getPosition() == previousPosition))
|
||||
if(target != entity->getPosition())
|
||||
{
|
||||
entity->nextTarget = target;
|
||||
entity->nextState = targetState;
|
||||
|
||||
previousPosition = entity->getPosition();
|
||||
previousTarget = entity->getTarget();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -130,6 +125,13 @@ pro_maat::GridPos Rule::findTarget()
|
|||
|
||||
|
||||
std::sort(potentialTargets.begin(),potentialTargets.end(),distanceSortSquares);
|
||||
|
||||
// If we are adjacent to a target, we do not need to move
|
||||
if(std::find(potentialTargets.begin(),potentialTargets.end(),entity->getPosition()) != potentialTargets.end())
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
auto target = std::min_element(potentialTargets.begin(),potentialTargets.end(),bestTarget);
|
||||
|
||||
if(target != potentialTargets.end())
|
||||
|
|
|
@ -50,9 +50,6 @@ private:
|
|||
const std::vector<pro_maat::GridPos>& occupiedSquares;
|
||||
|
||||
const pro_maat::GridPos& mapSize;
|
||||
|
||||
pro_maat::GridPos previousPosition;
|
||||
pro_maat::GridPos previousTarget;
|
||||
};
|
||||
|
||||
#endif //PROJECT_MAAT_RULES_H
|
||||
|
|
Loading…
Add table
Reference in a new issue