cargo: unloading works
This commit is contained in:
@@ -5,7 +5,7 @@ namespace OpenRa.Game.Traits.Activities
|
||||
{
|
||||
public IActivity NextActivity { get; set; }
|
||||
|
||||
public int desiredFacing;
|
||||
int desiredFacing;
|
||||
|
||||
public Turn( int desiredFacing )
|
||||
{
|
||||
|
||||
@@ -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<Unit>();
|
||||
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<Cargo>();
|
||||
if (cargo.IsEmpty(self))
|
||||
return NextActivity;
|
||||
|
||||
var ru = self.traits.WithInterface<RenderUnit>().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<Mobile>().TeleportTo(actor, self.Location);
|
||||
actor.CancelActivity();
|
||||
actor.QueueActivity(new Move(exitTile.Value, 0));
|
||||
});
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -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<Actor> cargo = new List<Actor>();
|
||||
|
||||
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<PipType> GetPips( Actor self )
|
||||
{
|
||||
for (var i = 0; i < self.Info.Passengers; i++)
|
||||
|
||||
@@ -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
|
||||
s5=Multi1,apc,600,12510,Gaurd,None
|
||||
Reference in New Issue
Block a user