From f6a34aab9cff064186cffcdf8adcff83f12e6f1c Mon Sep 17 00:00:00 2001 From: Taryn Hill Date: Tue, 7 Apr 2015 13:57:58 -0500 Subject: [PATCH] Add UnloadTerrainTypes restriction to Cargo. --- OpenRA.Mods.Common/Traits/Cargo.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/OpenRA.Mods.Common/Traits/Cargo.cs b/OpenRA.Mods.Common/Traits/Cargo.cs index 389d21162f..74e6bbcc59 100644 --- a/OpenRA.Mods.Common/Traits/Cargo.cs +++ b/OpenRA.Mods.Common/Traits/Cargo.cs @@ -27,6 +27,9 @@ namespace OpenRA.Mods.Common.Traits public readonly string[] InitialUnits = { }; public readonly bool EjectOnSell = true; + [Desc("Terrain types that this actor is allowed to eject actors onto. Leave empty for all terrain types.")] + public readonly string[] UnloadTerrainTypes = { }; + [Desc("Which direction the passenger will face (relative to the transport) when unloading.")] public readonly int PassengerFacing = 128; @@ -46,6 +49,7 @@ namespace OpenRA.Mods.Common.Traits readonly Stack cargo = new Stack(); readonly HashSet reserves = new HashSet(); readonly Lazy facing; + readonly bool checkTerrainType; int totalWeight = 0; int reservedWeight = 0; @@ -62,6 +66,7 @@ namespace OpenRA.Mods.Common.Traits self = init.Self; Info = info; Unloading = false; + checkTerrainType = info.UnloadTerrainTypes.Length > 0; if (init.Contains()) { @@ -139,6 +144,14 @@ namespace OpenRA.Mods.Common.Traits bool CanUnload() { + if (checkTerrainType) + { + var terrainType = self.World.Map.GetTerrainInfo(self.Location).Type; + + if (!Info.UnloadTerrainTypes.Contains(terrainType)) + return false; + } + return !IsEmpty(self) && (helicopter == null || helicopter.CanLand(self.Location)) && CurrentAdjacentCells != null && CurrentAdjacentCells.Any(c => Passengers.Any(p => p.Trait().CanEnterCell(c))); }