From 5701da5df3e5f0d3a40af0abf7e03302275dcca2 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Tue, 4 Dec 2012 21:42:54 +0000 Subject: Introduce Entity::hit() callback, prevent projectiles from doing no damage. --- src/core/entity.cc | 4 ++++ src/core/entity.h | 6 ++++++ src/core/entityprojectile.cc | 8 +++++--- src/core/entityprojectile.h | 6 +++--- 4 files changed, 18 insertions(+), 6 deletions(-) (limited to 'src/core') diff --git a/src/core/entity.cc b/src/core/entity.cc index 67227ca..4d8c4c7 100644 --- a/src/core/entity.cc +++ b/src/core/entity.cc @@ -955,6 +955,10 @@ void EntityDynamic::collision(Entity *other) { } +void EntityDynamic::hit(Entity *other) +{ +} + void EntityDynamic::serialize_server_create(std::ostream & os) const { Entity::serialize_server_create(os); diff --git a/src/core/entity.h b/src/core/entity.h index 0be81b9..df65843 100644 --- a/src/core/entity.h +++ b/src/core/entity.h @@ -662,6 +662,12 @@ public: * Warning: this can be called multiple times for a single collision * */ virtual void collision(Entity *other); + + /** + * @brief weapon hit callback + * This method is called by the core-engine if the entity is hit by a weapon. + * */ + virtual void hit(Entity *other); protected: float entity_mass; diff --git a/src/core/entityprojectile.cc b/src/core/entityprojectile.cc index 8c6c57b..e89c7f7 100644 --- a/src/core/entityprojectile.cc +++ b/src/core/entityprojectile.cc @@ -56,10 +56,12 @@ void EntityProjectile::collision(Entity *other) { if (state() == Entity::Destroyed) { return; + } else { + if ((other->type() == Dynamic) || (other->type() == Controlable)) { + static_cast(other)->hit(this); + } + set_state(Entity::Destroyed); } - - set_state(Entity::Destroyed); - // this method is a bullet callback, we can not reset() here } void EntityProjectile::frame(const unsigned long elapsed) diff --git a/src/core/entityprojectile.h b/src/core/entityprojectile.h index 04070ff..6bbcdfd 100644 --- a/src/core/entityprojectile.h +++ b/src/core/entityprojectile.h @@ -59,7 +59,7 @@ public: /** * @brief id of the player who fired the projectile * */ - inline const int ownerid() const + inline const unsigned int ownerid() const { return projectile_ownerid; } @@ -110,7 +110,7 @@ public: /** * @brief set the id of the player who fired the projectile * */ - inline void set_ownerid(const int ownerid) + inline void set_ownerid(const unsigned int ownerid) { projectile_ownerid = ownerid; } @@ -137,7 +137,7 @@ private: float projectile_damage; - int projectile_ownerid; + unsigned int projectile_ownerid; }; } // namespace game -- cgit v1.2.3