Skip to content

Commit

Permalink
Merge pull request OpenRA#7898 from Phrohdoh/unload-terrain-types
Browse files Browse the repository at this point in the history
Add UnloadTerrainTypes to Cargo.
  • Loading branch information
chrisforbes committed Apr 29, 2015
2 parents 2d5517f + f6a34aa commit 1c08099
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions OpenRA.Mods.Common/Traits/Cargo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public class CargoInfo : ITraitInfo, Requires<IOccupySpaceInfo>
[Desc("When this actor is sold should all of its passengers be unloaded?")]
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;

Expand All @@ -55,6 +58,7 @@ public class Cargo : IPips, IIssueOrder, IResolveOrder, IOrderVoice, INotifyCrea
readonly Stack<Actor> cargo = new Stack<Actor>();
readonly HashSet<Actor> reserves = new HashSet<Actor>();
readonly Lazy<IFacing> facing;
readonly bool checkTerrainType;

int totalWeight = 0;
int reservedWeight = 0;
Expand All @@ -71,6 +75,7 @@ public Cargo(ActorInitializer init, CargoInfo info)
self = init.Self;
Info = info;
Unloading = false;
checkTerrainType = info.UnloadTerrainTypes.Length > 0;

if (init.Contains<RuntimeCargoInit>())
{
Expand Down Expand Up @@ -148,6 +153,14 @@ IEnumerable<CPos> GetAdjacentCells()

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<IPositionable>().CanEnterCell(c)));
}
Expand Down

0 comments on commit 1c08099

Please sign in to comment.