@@ -928,6 +928,26 @@ class GenericObjectCreationNugget : public ObjectCreationNugget
928928
929929protected:
930930
931+ static Real getGroundHeight (const Coord3D* pos, PathfindLayerEnum layer) {
932+
933+ if (layer != LAYER_GROUND ) { // Bridge
934+ return TheTerrainLogic->getLayerHeight (pos->x , pos->y , layer) + 1.0 ;
935+ }
936+ else if (TheGlobalData->m_heightAboveTerrainIncludesWater ) { // do water check
937+ Real waterZ = 0 ;
938+ Real terrainZ = 0 ;
939+
940+ if (TheTerrainLogic->isUnderwater (pos->x , pos->y , &waterZ, &terrainZ))
941+ return waterZ;
942+
943+ return terrainZ;
944+ }
945+ else { // Ground height only
946+ return TheTerrainLogic->getLayerHeight (pos->x , pos->y , layer);
947+ }
948+ }
949+
950+
931951 void doStuffToObj (
932952 Object* obj,
933953 const AsciiString& modelName,
@@ -1058,7 +1078,14 @@ class GenericObjectCreationNugget : public ObjectCreationNugget
10581078 obj->setTransformMatrix (mtx);
10591079 else
10601080 obj->setOrientation (orientation);
1081+
1082+ if (BitIsSet (m_disposition, ON_GROUND_ALIGNED )) {
1083+ PathfindLayerEnum layer = TheTerrainLogic->getLayerForDestination (pos);
1084+ chunkPos.z = getGroundHeight (pos, layer);
1085+ obj->setLayer (layer);
1086+ }
10611087 obj->setPosition (&chunkPos);
1088+
10621089 if (sourceObj && sourceObj->isAboveTerrain ())
10631090 {
10641091 PhysicsBehavior* physics = obj->getPhysics ();
@@ -1090,15 +1117,11 @@ class GenericObjectCreationNugget : public ObjectCreationNugget
10901117
10911118 }
10921119
1093- if ( BitIsSet ( m_disposition, ON_GROUND_ALIGNED ) )
1120+ else if ( BitIsSet ( m_disposition, ON_GROUND_ALIGNED ))
10941121 {
1095- chunkPos.z = 99999 .0f ;
1096- PathfindLayerEnum layer = TheTerrainLogic->getHighestLayerForDestination (&chunkPos);
10971122 obj->setOrientation (GameLogicRandomValueReal (0 .0f , 2 * PI ));
1098- chunkPos.z = TheTerrainLogic->getLayerHeight ( chunkPos.x , chunkPos.y , layer );
1099- // ensure we are slightly above the bridge, to account for fudge & sloppy art
1100- if (layer != LAYER_GROUND )
1101- chunkPos.z += 1 .0f ;
1123+ PathfindLayerEnum layer = TheTerrainLogic->getLayerForDestination (pos);
1124+ chunkPos.z = getGroundHeight (pos, layer);
11021125 obj->setLayer (layer);
11031126 obj->setPosition (&chunkPos);
11041127 }
0 commit comments