55 lines
1.6 KiB
C++
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
|