Entities are now managed with unique_ptr to allow polymorphism (and good memory management) Rules can be added via the Level object Fixed Rule::findTarget not caring about targetType TODO : Find why pathfinding (unlikely) or findTarget (most likely) is broken
92 lines
1.9 KiB
C++
92 lines
1.9 KiB
C++
//
|
|
// Created by trotfunky on 06/06/19.
|
|
//
|
|
|
|
#ifndef SRC_ENTITY_H
|
|
#define SRC_ENTITY_H
|
|
|
|
#include <SFML/Graphics.hpp>
|
|
#include <pugixml.hpp>
|
|
#include <cinttypes>
|
|
|
|
#include "Utils.h"
|
|
|
|
|
|
enum class EntityType
|
|
{
|
|
Citizen,
|
|
Significant,
|
|
House,
|
|
Car,
|
|
};
|
|
|
|
enum class State
|
|
{
|
|
Moving,
|
|
Fleeing,
|
|
Waiting,
|
|
Idle,
|
|
};
|
|
|
|
enum class Orientation
|
|
{
|
|
North = 0,
|
|
East = 90,
|
|
South = 180,
|
|
West = 270,
|
|
None,
|
|
};
|
|
|
|
|
|
class Entity
|
|
{
|
|
public:
|
|
/// x,y, width and height are in grid coordinates
|
|
Entity(pro_maat::GridUnit x, pro_maat::GridUnit y, EntityType type, sf::Texture* texture, int width = 1,
|
|
int height = 1);
|
|
explicit Entity(const pugi::xml_node& entityNode, sf::Texture* texture);
|
|
virtual ~Entity() = default;
|
|
|
|
virtual void move(Orientation orientation);
|
|
virtual void update();
|
|
|
|
virtual State getState() const;
|
|
virtual EntityType getType() const;
|
|
virtual pro_maat::GridPos getTarget() const;
|
|
|
|
virtual const sf::RectangleShape& getShape() const;
|
|
/// Returns the grid coordinates at the center of the entity
|
|
virtual const pro_maat::GridPos getPosition() const;
|
|
|
|
// Don't like it : iterates over every square every tick
|
|
virtual const std::vector<pro_maat::GridPos> getOccupiedSquares() const;
|
|
|
|
|
|
protected:
|
|
/// Empty constructor for derived class instanciation
|
|
Entity();
|
|
|
|
|
|
private:
|
|
static const std::map<std::string,EntityType> entityTypeLookup;
|
|
|
|
EntityType type;
|
|
|
|
// As it contains position, size and orientation, we do not need anything more
|
|
// TODO : Maybe we need something more : lots of computations
|
|
sf::RectangleShape shape;
|
|
|
|
State currentState;
|
|
/// Used with rules : last to update has priority
|
|
State nextState;
|
|
|
|
/// Target position on the map of the current action
|
|
pro_maat::GridPos target;
|
|
/// Used with rules : last to update has priority
|
|
pro_maat::GridPos nextTarget;
|
|
|
|
friend class Rule;
|
|
};
|
|
|
|
|
|
#endif //SRC_ENTITY_H
|