@@ -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