diff --git a/binaries/data/mods/public/simulation/components/UnitMotionFlying.js b/binaries/data/mods/public/simulation/components/UnitMotionFlying.js index 5671090799..90640762a4 100644 --- a/binaries/data/mods/public/simulation/components/UnitMotionFlying.js +++ b/binaries/data/mods/public/simulation/components/UnitMotionFlying.js @@ -92,12 +92,37 @@ UnitMotionFlying.prototype.OnUpdate = function(msg) { if (this.waterDeath) cmpHealth.Kill(); - this.pitch = 0; - // We've stopped. - cmpGarrisonHolder.AllowGarrisoning(true,"UnitMotionFlying") - canTurn = false; - this.hasTarget = false; - this.landing = false; + else + { + this.pitch = 0; + // We've stopped. + cmpGarrisonHolder.AllowGarrisoning(true,"UnitMotionFlying") + canTurn = false; + this.hasTarget = false; + this.landing = false; + // summon planes back from the edge of the map + var terrainSize = cmpTerrain.GetTilesPerSide() * 4; + var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); + if (cmpRangeManager.GetLosCircular()) + { + var mapRadius = terrainSize/2; + var x = pos.x - mapRadius; + var z = pos.z - mapRadius; + var div = (mapRadius - 12) / Math.sqrt(x*x + z*z); + if (div < 1) + { + pos.x = mapRadius + x*div; + pos.z = mapRadius + z*div; + newangle += Math.PI; + } + } + else + { + pos.x = Math.max(Math.min(pos.x, terrainSize - 12), 12); + pos.z = Math.max(Math.min(pos.z, terrainSize - 12), 12); + newangle += Math.PI; + } + } } else { diff --git a/source/simulation2/components/ICmpTerrain.cpp b/source/simulation2/components/ICmpTerrain.cpp index eaca915d69..5e02f358a5 100644 --- a/source/simulation2/components/ICmpTerrain.cpp +++ b/source/simulation2/components/ICmpTerrain.cpp @@ -24,4 +24,5 @@ BEGIN_INTERFACE_WRAPPER(Terrain) DEFINE_INTERFACE_METHOD_2("GetGroundLevel", entity_pos_t, ICmpTerrain, GetGroundLevel, entity_pos_t, entity_pos_t) DEFINE_INTERFACE_METHOD_2("CalcNormal", CFixedVector3D, ICmpTerrain, CalcNormal, entity_pos_t, entity_pos_t) +DEFINE_INTERFACE_METHOD_0("GetTilesPerSide", u16, ICmpTerrain, GetTilesPerSide) END_INTERFACE_WRAPPER(Terrain)