cargo: added EnterTransport activity; made things mostly work. still very WIP.

This commit is contained in:
Chris Forbes
2010-01-05 15:25:12 +13:00
parent 026a33d2e2
commit 8c9fbb8d6b
7 changed files with 58 additions and 16 deletions

View File

@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace OpenRa.Game.Traits.Activities
{
class EnterTransport : IActivity
{
public IActivity NextActivity { get; set; }
bool isCanceled;
public Actor transport;
public EnterTransport(Actor self, Actor transport)
{
this.transport = transport;
}
public IActivity Tick(Actor self)
{
if (isCanceled) return NextActivity;
if (transport == null || !transport.IsInWorld) return NextActivity;
var cargo = transport.traits.Get<Cargo>();
if (cargo.IsFull(transport))
return NextActivity;
cargo.Load(transport, self);
Game.world.AddFrameEndTask(w => w.Remove(self));
return this;
}
public void Cancel(Actor self) { isCanceled = true; NextActivity = null; }
}
}

View File

@@ -51,7 +51,8 @@ namespace OpenRa.Game.Traits.Activities
if (exitTile == null)
return this;
var actor = cargo.UnloadOne(self);
var actor = cargo.Unload(self);
Game.world.AddFrameEndTask(w =>
{
w.Add(actor);

View File

@@ -11,15 +11,7 @@ namespace OpenRa.Game.Traits
{
List<Actor> cargo = new List<Actor>();
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 Cargo(Actor self) {}
public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor)
{
@@ -50,7 +42,7 @@ namespace OpenRa.Game.Traits
return cargo.Count == 0;
}
public Actor UnloadOne(Actor self)
public Actor Unload(Actor self)
{
var a = cargo[0];
cargo.RemoveAt(0);
@@ -79,5 +71,10 @@ namespace OpenRa.Game.Traits
return PipType.Green;
}
public void Load(Actor self, Actor a)
{
cargo.Add(a);
}
}
}

View File

@@ -34,8 +34,8 @@ namespace OpenRa.Game.Traits
if (order.OrderString == "EnterTransport")
{
self.CancelActivity();
self.QueueActivity(new Move(order.TargetActor, 0));
// todo: actually enter the transport
self.QueueActivity(new Move(order.TargetActor.Location, 1));
self.QueueActivity(new EnterTransport(self, order.TargetActor));
}
}
}