Skip to content

Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.

fix(gameengine): keep a shocked unit stunned until it lands, read ExtraBounciness

Olcay Seygan3af3c9c6ccde
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2c10ca1c5..e98dbe0f6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -394,6 +394,8 @@ found and fixed — EA's own, not port damage.**
- A toppling building crushes the strip across its fall at any angle. The line was only square to the fall when the building fell along an axis; at forty-five degrees it ran down the length of the building and missed the units beside it.
- A transport killed by the blast of a Terrorist riding in it puts the other passengers out. They were handed back to a vehicle that had already died and were deleted with it, unseen.
- Something that knocks a unit off its feet lets it stand again. The flailing pose could outlast the stun and stay for good.
+- A tank thrown by a carpet bomb or a MOAB is out of your hands until it comes down. A tank hit where it stood got its controls back on the very next frame, before it had left the ground, and anything already in the air got them back at the top of its arc, so it could drive in mid-air. Now the stun lasts until it lands and a few frames after, and a tank that comes down on its roof, in water it cannot drive through, on a cliff or off the edge of the map is lost, the way the game was written to do and never did. Over one carpet bomb, 16 of 20 units that lived through it came down still stunned where none did before, and one Paladin landed on its back. Replays recorded before this change play out differently.
+- Wreckage and bodies that should not bounce, don't. The data tells debris and a soldier flung by a blast to lie where they land, and fifteen entries say so, but the game never read the number and bounced all of it the same. Replays recorded before this change play out differently.
## One crate, one collector
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Locomotor.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Locomotor.h
index 2338297c2..58608ac9e 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Locomotor.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Locomotor.h
@@ -251,6 +251,7 @@ public:
inline LocomotorAppearance getAppearance() const { return m_template->m_appearance; }
inline LocomotorPriority getMovePriority() const { return m_template->m_movePriority; }
inline LocomotorSurfaceTypeMask getLegalSurfaces() const { return m_template->m_surfaces; }
+ inline LocomotorBehaviorZ getBehaviorZ() const { return m_template->m_behaviorZ; }
inline AsciiString getTemplateName() const { return m_template->m_name;}
inline Real getMinSpeed() const { return m_template->m_minSpeed;}
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp
index ab8e0a03a..6530da10b 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp
@@ -36,6 +36,7 @@
#include "Common/ThingTemplate.h"
#include "Common/Xfer.h"
#include "GameLogic/GameLogic.h"
+#include "GameLogic/Locomotor.h"
#include "GameLogic/Module/AIUpdate.h"
#include "GameLogic/Module/BodyModule.h"
#include "GameLogic/Module/ContainModule.h"
@@ -513,7 +514,9 @@ Bool PhysicsBehavior::handleBounce(Real oldZ, Real newZ, Real groundZ, Coord3D*
{
const Real MIN_STIFF = 0.01f;
const Real MAX_STIFF = 0.99f;
- Real stiffness = TheGlobalData->m_groundStiffness;
+ // ExtraBounciness (OCL debris, a flung SlowDeath body) was stored and saved but never read
+ // here, so the -1.0 that fifteen INI entries use to mean "do not bounce" bounced at 0.8
+ Real stiffness = TheGlobalData->m_groundStiffness + m_extraBounciness;
if (stiffness < MIN_STIFF) stiffness = MIN_STIFF;
if (stiffness > MAX_STIFF) stiffness = MAX_STIFF;
@@ -697,18 +700,24 @@ UpdateSleepTime PhysicsBehavior::update()
TheGameLogic->destroyObject(obj);
}
- // Check when to clear the stunned status
+ // Check when to clear the stunned status: at rest, and on the ground unless the locomotor holds
+ // the unit off it (a boat, a helicopter), where at rest is all there is. This was "at rest OR
+ // on the ground", tested on last frame's position, so a vehicle shocked where it stood lost the
+ // stun on the next frame before it ever left the ground, and anything in the air lost it at the
+ // top of its arc where every velocity component passes near zero. Nothing landed stunned, so
+ // the landing checks in testStunnedUnitForDestruction never ran.
if (getIsStunned())
{
- if ( (fabs(m_vel.x) < STUN_RELIEF_EPSILON &&
- fabs(m_vel.y) < STUN_RELIEF_EPSILON &&
- fabs(m_vel.z) < STUN_RELIEF_EPSILON)
- ||
- obj->isSignificantlyAboveTerrain() == FALSE )
+ const AIUpdateInterface* stunnedAI = obj->getAI();
+ Bool heldAloft = stunnedAI != NULL && stunnedAI->getCurLocomotor() != NULL &&
+ stunnedAI->getCurLocomotor()->getBehaviorZ() != Z_NO_Z_MOTIVE_FORCE;
+ if ( fabs(m_vel.x) < STUN_RELIEF_EPSILON &&
+ fabs(m_vel.y) < STUN_RELIEF_EPSILON &&
+ fabs(m_vel.z) < STUN_RELIEF_EPSILON &&
+ ( heldAloft || obj->isSignificantlyAboveTerrain() == FALSE ) )
{
setStunned(false);
- // tested on last frame's position, so this can run before the landing below ever
- // swaps flailing for stunned; clear both or the unit flails for good
+ // clear both: a weak shock can come to rest before the landing below swaps flailing for stunned
getObject()->clearModelConditionFlags( MAKE_MODELCONDITION_MASK2( MODELCONDITION_STUNNED, MODELCONDITION_STUNNED_FLAILING ) );
}
@@ -1850,7 +1859,7 @@ void PhysicsBehavior::testStunnedUnitForDestruction(void)
const Coord3D *pos = obj->getPosition();
// If a stunned object is upside down when it hits the ground, kill it
- if(obj->getTransformMatrix()->Get_Z_Vector().Z < 0.0f)
+ if(obj->getTransformMatrix()->Get_Z_Vector().Z < 0.0f)
{
obj->kill();
return;