/* core/entity.h This file is part of the Osirion project and is distributed under the terms of the GNU General Public License version 2. */ #ifndef __INCLUDED_CORE_ENTITY_H__ #define __INCLUDED_CORE_ENTITY_H__ namespace core { class EntityControlable; } #include "core/player.h" #include "math/mathlib.h" #include #include namespace core { /// The base world entity. All gameworld entities must derive from this class. class Entity { public: /// Entity flags enum Flags {Static=1, Solid=2}; /// Entity type constants enum Type {Default = 0, Dynamic = 1, Controlable = 2}; /// Entity shape constants enum Shape {Diamond=0, Sphere=1, Cube=2}; /// create a new entity and add it to the registry Entity(unsigned int flags = 0); /// destroy an entity virtual ~Entity(); /*----- inspectors ------------------------------------------------ */ /// entity id inline unsigned int id() const { return entity_id; } /// module type id inline unsigned int moduletype() const { return entity_moduletypeid; } /// core type id virtual inline unsigned int type() { return Default; } /// entity flags inline unsigned int flags() const { return entity_flags; } /// entity name inline std::string const & name() { return entity_name; } /// entity location inline math::Vector3f const & location() const { return entity_location; } /// direction the entity is facing, in degrees. inline float direction() const { return entity_direction; } /// base color of the entity inline math::Color const & color() const { return entity_color; } /// base shape of the entity inline Shape shape() const { return entity_shape; } /// base radius of the entity inline float radius() const { return entity_radius; } /*----- mutators -------------------------------------------------- */ /// runs one game frame for the entity /** * The default implementation does nothing */ virtual void frame(float seconds); /*----- static ---------------------------------------------------- */ /// the entity registry static std::map registry; /// find an entity in the registry static Entity *find(unsigned int id); /// remove one entity from the registry and deletes it static void remove(unsigned int entity_id); /// list the entity registry static void list(); /* entity_ variables can be set by the module */ float entity_radius; std::string entity_name; Shape entity_shape; math::Vector3f entity_location; math::Color entity_color; /* * A direction of 0 degrees means the entity is looking * along the positive X-axis. Positive angle is along the negative Z-axis. */ float entity_direction; unsigned int entity_moduletypeid; unsigned int entity_flags; private: /// add an entity to the registry static void add(Entity *ent); /// the id is set by add() unsigned int entity_id; }; /// an entity that can move around in the game world class EntityDynamic : public Entity { public: EntityDynamic(unsigned int flags = 0); virtual ~EntityDynamic(); /*----- inspectors ------------------------------------------------ */ /// core type id virtual inline unsigned int type() { return Entity::Dynamic; } /// current speed of the entity in game units per second inline float speed() const { return entity_speed; } /*----- mutators -------------------------------------------------- */ /// runs one game frame for the entity /** * The default implementation will update the position() of the entity, * determined by its speed() and direction() */ virtual void frame(float seconds); /// speed of the entity float entity_speed; }; /// an entity that can be controlled by a player class EntityControlable : public EntityDynamic { public: /// create EntityControlable(Player *player, unsigned int flags = 0); virtual ~EntityControlable(); /*----- inspectors ------------------------------------------------ */ /// core type id virtual inline unsigned int type() { return Entity::Controlable; } /// owner of this entity inline Player *owner() const { return entity_owner; } /// thrust inline float thrust() const { return entity_thrust; } /*----- mutators -------------------------------------------------- */ /// set the target thrust void set_thrust(float t); /// set the target direction void set_direction(float t); /// runs one game frame for the entity /** * The default implementation will set direction() and thrust() to the desired targets * and calls its parent frame() funcion. */ virtual void frame(float seconds); /* entity_ variables can be set by the module */ /// owner of the entity Player *entity_owner; /// current thrust float entity_thrust; /* target_ variables can be set by the client */ /// target thrust as set by the client float target_thrust; /// target direction as set by the client float target_direction; }; } #endif // __INCLUDED_CORE_ENTITY_H__