Project_Maat/src/Rule.h
trotFunky 2d8b1e53ce Final fix for end of movement
I was being dumb again : if we are adjacent to a target entity, stop moving
2019-06-10 21:53:39 +02:00

55 lines
1.6 KiB
C++

//
// Created by trotfunky on 09/06/19.
//
#ifndef PROJECT_MAAT_RULES_H
#define PROJECT_MAAT_RULES_H
#include <vector>
#include <algorithm>
#include <math.h>
#include <memory>
#include "Entity.h"
/// Decorates entities with rules which will modify its behaviour
class Rule : public Entity
{
public:
// The Rule object takes ownership of the Entity*
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
void update() override;
// Simply delegate the following function calls to the original entity
void move(Orientation orientation) override;
State getState() const override;
EntityType getType() const override;
const sf::RectangleShape& getShape() const override;
pro_maat::GridPos getTarget() const override;
const pro_maat::GridPos getPosition() const override;
const std::vector<pro_maat::GridPos> getOccupiedSquares() const override;
private:
/// Finds the closest free square adjacent to the closest target entity type.
/// Currently not thread-safe !
/// \return Suitable target square or current position if none was found.
pro_maat::GridPos findTarget();
std::shared_ptr<Entity> entity;
const State targetState;
const EntityType targetType;
const std::vector<std::shared_ptr<Entity>>& entities;
const std::vector<pro_maat::GridPos>& occupiedSquares;
const pro_maat::GridPos& mapSize;
};
#endif //PROJECT_MAAT_RULES_H