diff --git a/OpenRA.Mods.Common/Traits/World/SpawnStartingUnits.cs b/OpenRA.Mods.Common/Traits/World/SpawnStartingUnits.cs index c4337113a03b..ea55ef04f010 100644 --- a/OpenRA.Mods.Common/Traits/World/SpawnStartingUnits.cs +++ b/OpenRA.Mods.Common/Traits/World/SpawnStartingUnits.cs @@ -13,6 +13,7 @@ using System.Collections.Generic; using System.Linq; using OpenRA.Graphics; +using OpenRA.Mods.Common.Activities; using OpenRA.Primitives; using OpenRA.Traits; @@ -73,6 +74,23 @@ public void WorldLoaded(World world, WorldRenderer wr) SpawnUnitsForPlayer(world, p); } + static void InitActor(Actor actor, CPos spawnLocation) + { + // Spawn aircraft at cruise altitude. + var aircraft = actor.TraitOrDefault(); + if (aircraft != null) + { + if (!aircraft.Info.TakeOffOnCreation && aircraft.CanLand(spawnLocation)) + aircraft.AddInfluence(spawnLocation); + else + { + var pos = aircraft.CenterPosition; + aircraft.SetCenterPosition(actor, new WPos(pos.X, pos.Y, pos.Z + aircraft.Info.CruiseAltitude.Length)); + actor.QueueActivity(new FlyIdle(actor)); + } + } + } + void SpawnUnitsForPlayer(World w, Player p) { var spawnClass = p.PlayerReference.StartingUnitsClass ?? w.LobbyInfo.GlobalSettings @@ -87,14 +105,17 @@ void SpawnUnitsForPlayer(World w, Player p) if (unitGroup.BaseActor != null) { + var pos = p.HomeLocation + unitGroup.BaseActorOffset; var facing = unitGroup.BaseActorFacing ?? new WAngle(w.SharedRandom.Next(1024)); - w.CreateActor(unitGroup.BaseActor.ToLowerInvariant(), new TypeDictionary + var actor = w.CreateActor(unitGroup.BaseActor.ToLowerInvariant(), new TypeDictionary { - new LocationInit(p.HomeLocation + unitGroup.BaseActorOffset), + new LocationInit(pos), new OwnerInit(p), new SkipMakeAnimsInit(), new FacingInit(facing), }); + + InitActor(actor, pos); } if (unitGroup.SupportActors.Length == 0) @@ -117,13 +138,15 @@ void SpawnUnitsForPlayer(World w, Player p) var subCell = ip.SharesCell ? w.ActorMap.FreeSubCell(validCell) : 0; var facing = unitGroup.SupportActorsFacing ?? new WAngle(w.SharedRandom.Next(1024)); - w.CreateActor(s.ToLowerInvariant(), new TypeDictionary + var actor = w.CreateActor(s.ToLowerInvariant(), new TypeDictionary { new OwnerInit(p), new LocationInit(validCell), new SubCellInit(subCell), new FacingInit(facing), }); + + InitActor(actor, validCell); } } } diff --git a/mods/d2k/rules/aircraft.yaml b/mods/d2k/rules/aircraft.yaml index 7a030b32149f..e871bd55c3e8 100644 --- a/mods/d2k/rules/aircraft.yaml +++ b/mods/d2k/rules/aircraft.yaml @@ -18,6 +18,7 @@ carryall.reinforce: LandableTerrainTypes: Sand, Rock, Transition, Spice, SpiceSand, Dune, Concrete Repulsable: False AirborneCondition: airborne + CanForceLand: false CanSlide: True VTOL: true IdleTurnSpeed: 4