3737#include " GameLogic/GameLogic.h"
3838#include " GameLogic/Module/DieModule.h"
3939#include " GameLogic/Object.h"
40+ #include < GameLogic/TerrainLogic.h>
41+
4042
4143
4244
@@ -50,6 +52,8 @@ DieMuxData::DieMuxData() {
5052 if (TheGlobalData) {
5153 m_deathTypes &= ~TheGlobalData->m_defaultExcludedDeathTypes ;
5254 }
55+ m_minWaterDepth = 0 .0f ;
56+ m_maxWaterDepth = std::numeric_limits<Real>::infinity ();
5357}
5458
5559// -------------------------------------------------------------------------------------------------
@@ -61,7 +65,9 @@ const FieldParse* DieMuxData::getFieldParse()
6165 { " VeterancyLevels" , INI ::parseVeterancyLevelFlags, nullptr , offsetof ( DieMuxData, m_veterancyLevels ) },
6266 { " ExemptStatus" , ObjectStatusMaskType::parseFromINI, nullptr , offsetof ( DieMuxData, m_exemptStatus ) },
6367 { " RequiredStatus" , ObjectStatusMaskType::parseFromINI, nullptr , offsetof ( DieMuxData, m_requiredStatus ) },
64- { nullptr , nullptr , nullptr , 0 }
68+ { " MinWaterDepth" , INI ::parseReal, nullptr , offsetof (DieMuxData, m_minWaterDepth )},
69+ { " MaxWaterDepth" , INI ::parseReal, nullptr , offsetof (DieMuxData, m_maxWaterDepth )},
70+ { nullptr , nullptr , nullptr , 0 }
6571 };
6672 return dataFieldParse;
6773}
@@ -86,6 +92,27 @@ Bool DieMuxData::isDieApplicable(const Object* obj, const DamageInfo *damageInfo
8692 if ( m_requiredStatus.any () && !obj->getStatusBits ().testForAll ( m_requiredStatus ) )
8793 return false ;
8894
95+ if ((m_minWaterDepth > 0 .0f || m_maxWaterDepth < std::numeric_limits<Short>::infinity ()) && obj != nullptr ) {
96+
97+ // if on bride and we need water -> not applicable
98+ if (obj->getLayer () > LAYER_GROUND && m_minWaterDepth > 0 .0f ) {
99+ return false ;
100+ }
101+
102+ // Water level restriction
103+ const Coord3D* pos = obj->getPosition ();
104+ Real waterZ{ 0 }, terrainZ{ 0 };
105+
106+ if (TheTerrainLogic->isUnderwater (pos->x , pos->y , &waterZ, &terrainZ)) {
107+ Real depth = waterZ - terrainZ;
108+ return depth >= m_minWaterDepth && depth < m_maxWaterDepth;
109+ }
110+ else {
111+ // we are over land
112+ if (m_minWaterDepth > 0 .0f ) return false ;
113+ }
114+ }
115+
89116 return true ;
90117}
91118
0 commit comments