Fixed movement of multiple entities.

Changed std::unique_ptr<Entity> to std::shared_ptr<Entity>.
Fixed pathfinding away from targets

TODO :
 - Fix oscillation around destination
 - Fix fleeing from adjacent target
 - Win conditions
 - GUI
This commit is contained in:
trotFunky 2019-06-10 18:44:45 +02:00
parent 293a564a29
commit 5ccd7d0c13
6 changed files with 33 additions and 21 deletions

View file

@ -8,7 +8,7 @@
#include <vector>
#include <algorithm>
#include <math.h>
#include <iostream>
#include <memory>
#include "Entity.h"
@ -18,7 +18,8 @@ class Rule : public Entity
{
public:
// The Rule object takes ownership of the Entity*
Rule(Entity* entity, State targetState, EntityType targetType, std::vector<std::unique_ptr<Entity>>& entities,
Rule(std::shared_ptr<Entity> entity, State targetState, EntityType targetType,
const std::vector<std::shared_ptr<Entity>>& entities,
const std::vector<pro_maat::GridPos>& occupiedSquares, const pro_maat::GridPos& mapSize);
/// Update according to the targetState and targetType
@ -40,13 +41,12 @@ private:
/// \return Suitable target square or current position if none was found.
pro_maat::GridPos findTarget();
std::unique_ptr<Entity> entity;
std::shared_ptr<Entity> entity;
State targetState;
EntityType targetType;
// TOOD : dropped const-qualifier. Consider using shared_ptr ?
std::vector<std::unique_ptr<Entity>>& entities;
const std::vector<std::shared_ptr<Entity>>& entities;
const std::vector<pro_maat::GridPos>& occupiedSquares;
const pro_maat::GridPos& mapSize;