From e2ff773e0ebf7ad46e97b24da4500f5bedeb5a05 Mon Sep 17 00:00:00 2001 From: Lee Salzman Date: Mon, 16 Mar 2009 21:04:21 +0000 Subject: [PATCH] make sure inhandnade is cleaned up if bounceent is removed git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@4274 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/entity.h | 3 ++- source/src/weapon.cpp | 9 +++++++++ source/src/weapon.h | 4 +++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/source/src/entity.h b/source/src/entity.h index ee9f0098..b2cfa31b 100644 --- a/source/src/entity.h +++ b/source/src/entity.h @@ -548,7 +548,8 @@ public: bool local; int nadestate; float distsincebounce; - grenadeent (playerent *owner, int millis = 0); + grenadeent(playerent *owner, int millis = 0); + ~grenadeent(); void activate(const vec &from, const vec &to); void _throw(const vec &from, const vec &vel); void explode(); diff --git a/source/src/weapon.cpp b/source/src/weapon.cpp index e224c3e1..bb0286be 100644 --- a/source/src/weapon.cpp +++ b/source/src/weapon.cpp @@ -691,6 +691,11 @@ grenadeent::grenadeent (playerent *owner, int millis) distsincebounce = 0.0f; } +grenadeent::~grenadeent() +{ + if(owner && owner->weapons[GUN_GRENADE]) owner->weapons[GUN_GRENADE]->removebounceent(this); +} + void grenadeent::explode() { if(nadestate!=NS_ACTIVATED && nadestate!=NS_THROWED ) return; @@ -908,6 +913,10 @@ void grenades::onownerdies() if(owner==player1 && inhandnade) dropnade(); } +void grenades::removebounceent(bounceent *b) +{ + if(b == inhandnade) { inhandnade = NULL; reset(); } +} // gun base class diff --git a/source/src/weapon.h b/source/src/weapon.h index 56414ae3..7b5dcf30 100644 --- a/source/src/weapon.h +++ b/source/src/weapon.h @@ -1,5 +1,6 @@ class playerent; +class bounceent; struct weapon { @@ -38,6 +39,7 @@ struct weapon virtual void ondeselecting() {} virtual void onammopicked() {} virtual void onownerdies() {} + virtual void removebounceent(bounceent *b) {} void sendshoot(vec &from, vec &to); bool modelattacking(); @@ -49,7 +51,6 @@ struct weapon }; class grenadeent; -class bounceent; enum { GST_NONE, GST_INHAND, GST_THROWING }; @@ -74,6 +75,7 @@ struct grenades : weapon bool busy(); void onselecting(); void onownerdies(); + void removebounceent(bounceent *b); int flashtime() const; };