/* core/entityprojectile.h This file is part of the Osirion project and is distributed under the terms and conditions of the GNU General Public License version 2 */ #ifndef __INCLUDED_CORE_PROJECTILE_H__ #define __INCLUDED_CORE_PROJECTILE_H__ #include "core/entity.h" namespace core { const float PROJECTILE_RADIUS = 0.025f; class EntityProjectile : public core::EntityDynamic { public: EntityProjectile(const Entity *spawn = 0); EntityProjectile(std::istream & is); virtual ~EntityProjectile(); virtual void upkeep(const unsigned long timestamp); virtual void collision(Entity *other); virtual void frame(const unsigned long elapsed); /* --- inspectors ------------------------------------------ */ /** * @brief core type id * */ virtual inline const unsigned int type() const { return Projectile; } inline const unsigned long timestamp() const { return projectile_timestamp; } /** * @brief the lifespan of this projectile, in milliseconds * */ inline const unsigned long lifespan() const { return projectile_lifespan; } /** * @brief the amount of damage this projectile inflicts * */ inline const float damage() const { return projectile_damage; } /** * @brief id of the player who fired the projectile * */ inline const int owner_id() const { return projectile_owner_id; } /** * @brief id of the entity that spawned the projectile * */ inline const unsigned int spawn_id() const { return projectile_spawn_id; } /** * @brief return the projectile model name * */ inline const std::string & projectile_modelname() const { return projectile_modelname_str; } /** * @brief return the projectile sound name * */ inline const std::string & projectile_soundname() const { return projectile_soundname_str; } /*----- serializers ----------------------------------------------- */ /** * @brief serialize the entity to a stream * */ virtual void serialize_server_create(std::ostream & os) const; /*----- mutators -------------------------------------------------- */ /** * @brief receive a server-to-client create from a stream * */ virtual void receive_server_create(std::istream &is); /** * @brief reset physics state * */ virtual void reset(); /** * @brief set the amount of damage this projectile inflicts * */ inline void set_damage(const float damage) { projectile_damage = damage; } /** * @brief set the lifespan of the projectile * */ inline void set_lifespan(const unsigned long lifespan) { projectile_lifespan = lifespan; } /** * @brief set the projectile timestamp * */ inline void set_timestamp(const unsigned int timestamp) { projectile_timestamp = timestamp; } /** * @brief set the projectile model name * */ void set_projectile_modelname(const std::string modelname); /** * @brief set the projectile sound name * */ void set_projectile_soundname(const std::string soundname); /** * @brief set the entity that spawned the projectile * This sets spawn_id() to the id of the entity and owner_id() to the id * of the owner of the spawn, if any. * */ void set_spawn(const Entity *spawn); private: unsigned long projectile_timestamp; unsigned long projectile_lifespan; std::string projectile_modelname_str; std::string projectile_soundname_str; float projectile_damage; int projectile_owner_id; unsigned int projectile_spawn_id; }; } // namespace game #endif // __INCLUDED_CORE_PROJECTILE_H__