@@ -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 ( ¢erPoint, &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 ) );
0 commit comments