Skip to content

Commit d5d32e6

Browse files
authored
enable water salvage (#74)
1 parent e6399b7 commit d5d32e6

3 files changed

Lines changed: 26 additions & 2 deletions

File tree

GeneralsMD/Code/GameEngine/Include/GameLogic/CrateSystem.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class CrateTemplate : public Overridable
7373
ScienceType m_killerScience; ///< Must be killed by something posessing this science
7474
crateCreationEntryList m_possibleCrates; ///< CreationChance is for this CrateData to succeed, this list controls one-of-n crates created on success
7575
Bool m_isOwnedByMaker; ///< Design needs crates to be owned sometimes.
76+
Bool m_allowWater; ///< Crate can spawn on water
7677

7778
private:
7879

GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Die/CreateCrateDie.cpp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,14 @@ Object *CreateCrateDie::createCrate( CrateTemplate const *currentCrateData )
208208
fpOptions.minRadius = 0.0f;
209209
fpOptions.maxRadius = 5.0f;
210210
fpOptions.relationshipObject = getObject();
211-
fpOptions.flags = FPF_IGNORE_ALLY_OR_NEUTRAL_UNITS; // So the dead guy won't block, nor will his dead hulk.
211+
212+
if (currentCrateData->m_allowWater) {
213+
fpOptions.flags = static_cast<FindPositionFlags>(FPF_IGNORE_ALLY_OR_NEUTRAL_UNITS | FPF_IGNORE_WATER);
214+
}
215+
else {
216+
fpOptions.flags = FPF_IGNORE_ALLY_OR_NEUTRAL_UNITS; // So the dead guy won't block, nor will his dead hulk.
217+
}
218+
212219
if (layer != LAYER_GROUND) {
213220
creationPoint = centerPoint;
214221
spotFound = true;
@@ -223,7 +230,13 @@ Object *CreateCrateDie::createCrate( CrateTemplate const *currentCrateData )
223230
fpOptions.minRadius = 0.0f;
224231
fpOptions.maxRadius = 125.0f;
225232
fpOptions.relationshipObject = NULL;
226-
fpOptions.flags = FPF_NONE;
233+
234+
if (currentCrateData->m_allowWater) {
235+
fpOptions.flags = FPF_IGNORE_WATER;
236+
}
237+
else {
238+
fpOptions.flags = FPF_NONE;
239+
}
227240
if( ThePartitionManager->findPositionAround( &centerPoint, &fpOptions, &creationPoint ) )
228241
{
229242
spotFound = TRUE;
@@ -232,6 +245,14 @@ Object *CreateCrateDie::createCrate( CrateTemplate const *currentCrateData )
232245

233246
if( spotFound )
234247
{
248+
//Move up to water surface if unterwater
249+
if (currentCrateData->m_allowWater && getObject()->isOverWater()) {
250+
Real waterZ{ 0 };
251+
if (TheTerrainLogic->isUnderwater(creationPoint.x, creationPoint.y, &waterZ)) {
252+
creationPoint.z = std::max(creationPoint.z, waterZ);
253+
}
254+
}
255+
235256
Object *newCrate = TheThingFactory->newObject( crateType, NULL );
236257
newCrate->setPosition( &creationPoint );
237258
newCrate->setOrientation( GameLogicRandomValueReal( 0, 2*PI ) );

GeneralsMD/Code/GameEngine/Source/GameLogic/System/CrateSystem.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ const FieldParse CrateTemplate::TheCrateTemplateFieldParseTable[] =
185185
{ "CrateObject", CrateTemplate::parseCrateCreationEntry, NULL, NULL },
186186
{ "KillerScience", INI::parseScience, NULL, offsetof( CrateTemplate, m_killerScience) },
187187
{ "OwnedByMaker", INI::parseBool, NULL, offsetof( CrateTemplate, m_isOwnedByMaker) },
188+
{ "AllowWater", INI::parseBool, NULL, offsetof( CrateTemplate, m_allowWater) },
188189
{ NULL, NULL, NULL, NULL },
189190
};
190191

@@ -196,6 +197,7 @@ CrateTemplate::CrateTemplate()
196197
m_killerScience = SCIENCE_INVALID;
197198
m_possibleCrates.clear();
198199
m_isOwnedByMaker = FALSE;
200+
m_allowWater = false;
199201
}
200202

201203
CrateTemplate::~CrateTemplate()

0 commit comments

Comments
 (0)