diff --git a/OpenRa.Game/Traits/Activities/Turn.cs b/OpenRa.Game/Traits/Activities/Turn.cs index f07033d93e..1b81859e31 100755 --- a/OpenRa.Game/Traits/Activities/Turn.cs +++ b/OpenRa.Game/Traits/Activities/Turn.cs @@ -5,7 +5,7 @@ namespace OpenRa.Game.Traits.Activities { public IActivity NextActivity { get; set; } - public int desiredFacing; + int desiredFacing; public Turn( int desiredFacing ) { diff --git a/OpenRa.Game/Traits/Activities/UnloadCargo.cs b/OpenRa.Game/Traits/Activities/UnloadCargo.cs index 3a620f8ab4..705e97b473 100644 --- a/OpenRa.Game/Traits/Activities/UnloadCargo.cs +++ b/OpenRa.Game/Traits/Activities/UnloadCargo.cs @@ -10,6 +10,21 @@ namespace OpenRa.Game.Traits.Activities public IActivity NextActivity { get; set; } bool isCanceled; + int2? ChooseExitTile(Actor self) + { + if (!Game.IsCellBuildable(self.Location, UnitMovementType.Foot, self)) + return null; + + for (var i = -1; i < 2; i++) + for (var j = -1; j < 2; j++) + if ((i != 0 || j != 0) && + Game.IsCellBuildable(self.Location + new int2(i, j), + UnitMovementType.Foot)) + return self.Location + new int2(i, j); + + return null; + } + public IActivity Tick(Actor self) { if (isCanceled) return NextActivity; @@ -18,13 +33,31 @@ namespace OpenRa.Game.Traits.Activities // right facing for the unload animation var unit = self.traits.GetOrDefault(); if (unit != null && unit.Facing != self.Info.UnloadFacing) - return Util.SequenceActivities(new Turn(self.Info.UnloadFacing), this); + return new Turn(self.Info.UnloadFacing) { NextActivity = this }; - // todo: play the `open` anim (or the `close` anim backwards) - // todo: unload all the cargo - // todo: play the `close` anim (or the `open` anim backwards) + // todo: handle the BS of open/close sequences, which are inconsistent, + // for reasons that probably make good sense to the westwood guys. - // as for open/close... the westwood guys suck at being consistent. + var cargo = self.traits.Get(); + if (cargo.IsEmpty(self)) + return NextActivity; + + var ru = self.traits.WithInterface().FirstOrDefault(); + if (ru != null) + ru.PlayCustomAnimation(self, "unload", null); + + var exitTile = ChooseExitTile(self); + if (exitTile == null) + return this; + + var actor = cargo.UnloadOne(self); + Game.world.AddFrameEndTask(w => + { + w.Add(actor); + actor.traits.Get().TeleportTo(actor, self.Location); + actor.CancelActivity(); + actor.QueueActivity(new Move(exitTile.Value, 0)); + }); return this; } diff --git a/OpenRa.Game/Traits/Cargo.cs b/OpenRa.Game/Traits/Cargo.cs index a1202b5440..2f2bff52a8 100644 --- a/OpenRa.Game/Traits/Cargo.cs +++ b/OpenRa.Game/Traits/Cargo.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using OpenRa.Game.GameRules; +using OpenRa.Game.Traits.Activities; namespace OpenRa.Game.Traits { @@ -10,7 +11,15 @@ namespace OpenRa.Game.Traits { List cargo = new List(); - public Cargo(Actor self) { } + public Cargo(Actor self) + { + // hack: + cargo.Add(new Actor(Rules.UnitInfo["E1"], int2.Zero, self.Owner)); + cargo.Add(new Actor(Rules.UnitInfo["E1"], int2.Zero, self.Owner)); + cargo.Add(new Actor(Rules.UnitInfo["E1"], int2.Zero, self.Owner)); + cargo.Add(new Actor(Rules.UnitInfo["E6"], int2.Zero, self.Owner)); + cargo.Add(new Actor(Rules.UnitInfo["E7"], int2.Zero, self.Owner)); + } public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor) { @@ -27,6 +36,7 @@ namespace OpenRa.Game.Traits { // todo: eject the units self.CancelActivity(); + self.QueueActivity(new UnloadCargo()); } } @@ -35,6 +45,18 @@ namespace OpenRa.Game.Traits return cargo.Count == self.Info.Passengers; } + public bool IsEmpty(Actor self) + { + return cargo.Count == 0; + } + + public Actor UnloadOne(Actor self) + { + var a = cargo[0]; + cargo.RemoveAt(0); + return a; + } + public IEnumerable GetPips( Actor self ) { for (var i = 0; i < self.Info.Passengers; i++) diff --git a/session.ini b/session.ini index acafbf8481..d63ac62a10 100644 --- a/session.ini +++ b/session.ini @@ -10,4 +10,4 @@ s2=Multi1,mcv,600,12505,0,Guard,None ;s2=Multi1,e3,600,12505,0,Guard,None s3=Multi3,mcv,600,2910,0,Guard,None ;s4=Multi1,ctnk,600,12506,Gaurd,None -s5=Multi1,pdox,600,12510,Gaurd,None \ No newline at end of file +s5=Multi1,apc,600,12510,Gaurd,None \ No newline at end of file diff --git a/units.ini b/units.ini index 76c9ac4a54..b85b9faf0e 100644 --- a/units.ini +++ b/units.ini @@ -61,6 +61,7 @@ PrimaryOffset=0,0,0,-4 MuzzleFlash=yes Voice=VehicleVoice LongDesc=Tough infantry transport.\n Strong vs Infantry, Light Vehicles\n Weak vs Tanks, Aircraft +UnloadFacing=220 ;; non-combat vehicles [MRJ]