diff --git a/source/src/entity.h b/source/src/entity.h index 8200b214..027d6d74 100644 --- a/source/src/entity.h +++ b/source/src/entity.h @@ -136,6 +136,7 @@ struct physent } virtual void oncollision() {}; + virtual void onmoved(const vec &dist) {}; }; struct dynent : physent // animated ent @@ -505,7 +506,7 @@ struct grenadeent : bounceent { bool local; int nadestate; - int lastcollision; + float distsincebounce; grenadeent (playerent *owner, int millis = 0); void activate(const vec &from, const vec &to); void _throw(const vec &from, const vec &vel); @@ -515,5 +516,6 @@ struct grenadeent : bounceent virtual bool applyphysics(); void moveoutsidebbox(const vec &direction, playerent *boundingbox); void oncollision(); + void onmoved(const vec &dist); }; diff --git a/source/src/physics.cpp b/source/src/physics.cpp index c264c224..26a25bec 100644 --- a/source/src/physics.cpp +++ b/source/src/physics.cpp @@ -387,6 +387,8 @@ void moveplayer(physent *pl, int moveres, bool local, int curtime) } bool collided = false; + vec oldorigin = pl->o; + if(!editfly) loopi(moveres) // discrete steps collision detection & sliding { const float f = 1.0f/moveres; @@ -442,6 +444,7 @@ void moveplayer(physent *pl, int moveres, bool local, int curtime) } if(collided) pl->oncollision(); + else pl->onmoved(oldorigin.sub(pl->o)); if(pl->type==ENT_CAMERA) return; else if(pl->type!=ENT_BOUNCE) diff --git a/source/src/weapon.cpp b/source/src/weapon.cpp index 747a3e43..02731cf1 100644 --- a/source/src/weapon.cpp +++ b/source/src/weapon.cpp @@ -553,7 +553,7 @@ grenadeent::grenadeent (playerent *owner, int millis) bouncetype = BT_NADE; maxspeed = 30.0f; rotspeed = 6.0f; - lastcollision = 0; + distsincebounce = 0.0f; } void grenadeent::explode() @@ -633,11 +633,13 @@ bool grenadeent::applyphysics() { return nadestate==NS_THROWED; } void grenadeent::oncollision() { - if(nadestate==NS_THROWED && (!lastcollision || lastmillis-lastcollision>50)) - { - playsound(S_GRENADEBOUNCE1+rnd(2), 0, 0, &o); - lastcollision = lastmillis; - } + if(distsincebounce>=1.5f) playsound(S_GRENADEBOUNCE1+rnd(2), 0, 0, &o); + distsincebounce = 0.0f; +} + +void grenadeent::onmoved(const vec &dist) +{ + distsincebounce += dist.magnitude(); } // grenades