Skip to content

Commit 98d8391

Browse files
authored
add water check to HeightDieUpdate (#77)
1 parent f8aa416 commit 98d8391

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

GeneralsMD/Code/GameEngine/Include/GameLogic/Module/HeightDieUpdate.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class HeightDieUpdateModuleData: public UpdateModuleData
5151
Real m_destroyAttachedParticlesAtHeight; ///< HACK, destroy any attached particle system of object when below this height
5252
Bool m_snapToGroundOnDeath; ///< snap to the ground when killed
5353
UnsignedInt m_initialDelay; ///< Don't explode before this time
54-
54+
Bool m_targetHeightIncludesWater; ///< target height considers water height instead of terrain
5555
};
5656

5757
//-------------------------------------------------------------------------------------------------

GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/HeightDieUpdate.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ HeightDieUpdateModuleData::HeightDieUpdateModuleData( void )
5656
m_destroyAttachedParticlesAtHeight = -1.0f;
5757
m_snapToGroundOnDeath = FALSE;
5858
m_initialDelay = 0;
59-
59+
m_targetHeightIncludesWater = false;
6060
}
6161

6262
//-------------------------------------------------------------------------------------------------
@@ -76,6 +76,7 @@ void HeightDieUpdateModuleData::buildFieldParse(MultiIniFieldParse& p)
7676
{ "DestroyAttachedParticlesAtHeight", INI::parseReal, nullptr, offsetof( HeightDieUpdateModuleData, m_destroyAttachedParticlesAtHeight ) },
7777
{ "SnapToGroundOnDeath", INI::parseBool, nullptr, offsetof( HeightDieUpdateModuleData, m_snapToGroundOnDeath ) },
7878
{ "InitialDelay", INI::parseDurationUnsignedInt, nullptr, offsetof( HeightDieUpdateModuleData, m_initialDelay ) },
79+
{ "TargetHeightIncludesWater", INI::parseBool, nullptr, offsetof(HeightDieUpdateModuleData, m_targetHeightIncludesWater) },
7980
{ nullptr, nullptr, nullptr, 0 }
8081

8182
};
@@ -161,7 +162,14 @@ UpdateSleepTime HeightDieUpdate::update( void )
161162
}
162163

163164
// get the terrain height
164-
Real terrainHeightAtPos = TheTerrainLogic->getGroundHeight( pos->x, pos->y );
165+
Real terrainHeightAtPosNoWater = TheTerrainLogic->getGroundHeight(pos->x, pos->y);
166+
Real terrainHeightAtPos{ terrainHeightAtPosNoWater };
167+
if (modData->m_targetHeightIncludesWater) {
168+
Real waterz{ 0 };
169+
if (TheTerrainLogic->isUnderwater(pos->x, pos->y, &waterz)) {
170+
terrainHeightAtPos = waterz;
171+
}
172+
}
165173

166174
// if including structures, check for bridges
167175
if (modData->m_targetHeightIncludesStructures)
@@ -240,13 +248,13 @@ UpdateSleepTime HeightDieUpdate::update( void )
240248

241249
// if we're supposed to snap us to the ground on death do so
242250
// AND: even if we're not snapping to ground, be sure we don't go BELOW ground
243-
if( modData->m_snapToGroundOnDeath || pos->z < terrainHeightAtPos )
251+
if( modData->m_snapToGroundOnDeath || pos->z < terrainHeightAtPosNoWater )
244252
{
245253
Coord3D ground;
246254

247255
ground.x = pos->x;
248256
ground.y = pos->y;
249-
ground.z = terrainHeightAtPos;
257+
ground.z = terrainHeightAtPosNoWater;
250258
getObject()->setPosition( &ground );
251259

252260
}

0 commit comments

Comments
 (0)