moved cargo-related traits to ra

This commit is contained in:
Chris Forbes
2010-05-20 17:28:24 +12:00
parent 151f5acb2f
commit ed21b3be8d
7 changed files with 17 additions and 9 deletions

View File

@@ -153,7 +153,6 @@
<Compile Include="Traits\World\CrateSpawner.cs" />
<Compile Include="Traits\Activities\Attack.cs" />
<Compile Include="Traits\Activities\CallFunc.cs" />
<Compile Include="Traits\Activities\EnterTransport.cs" />
<Compile Include="Traits\Activities\Fly.cs" />
<Compile Include="Traits\Activities\FlyAttack.cs" />
<Compile Include="Traits\Activities\FlyTimed.cs" />
@@ -207,7 +206,6 @@
<Compile Include="Traits\Activities\Follow.cs" />
<Compile Include="Traits\Activities\Turn.cs" />
<Compile Include="Traits\Activities\UndeployMcv.cs" />
<Compile Include="Traits\Activities\UnloadCargo.cs" />
<Compile Include="Traits\Attack\AttackBase.cs" />
<Compile Include="Traits\Attack\AttackFrontal.cs" />
<Compile Include="Traits\Attack\AttackHeli.cs" />
@@ -222,7 +220,6 @@
<Compile Include="Traits\Building.cs" />
<Compile Include="Traits\World\BuildingInfluence.cs" />
<Compile Include="Traits\CanPowerDown.cs" />
<Compile Include="Traits\Cargo.cs" />
<Compile Include="Traits\Crate.cs" />
<Compile Include="Traits\Explodes.cs" />
<Compile Include="Traits\Fake.cs" />
@@ -234,7 +231,6 @@
<Compile Include="Traits\LimitedAmmo.cs" />
<Compile Include="Traits\World\PaletteFromFile.cs" />
<Compile Include="Traits\World\PaletteFromRGBA.cs" />
<Compile Include="Traits\Passenger.cs" />
<Compile Include="Traits\Player\PlaceBuilding.cs" />
<Compile Include="Traits\World\PlayerColorPalette.cs" />
<Compile Include="Traits\World\ResourceLayer.cs" />

View File

@@ -1,51 +0,0 @@
#region Copyright & License Information
/*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA.
*
* OpenRA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenRA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
namespace OpenRA.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);
self.World.AddFrameEndTask(w => w.Remove(self));
return this;
}
public void Cancel(Actor self) { isCanceled = true; NextActivity = null; }
}
}

View File

@@ -1,88 +0,0 @@
#region Copyright & License Information
/*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA.
*
* OpenRA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenRA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
using System.Linq;
using OpenRA.GameRules;
namespace OpenRA.Traits.Activities
{
public class UnloadCargo : IActivity
{
public IActivity NextActivity { get; set; }
bool isCanceled;
int2? ChooseExitTile(Actor self)
{
// is anyone still hogging this tile?
if (self.World.WorldActor.traits.Get<UnitInfluence>().GetUnitsAt(self.Location).Count() > 1)
return null;
for (var i = -1; i < 2; i++)
for (var j = -1; j < 2; j++)
if ((i != 0 || j != 0) &&
self.World.IsPathableCell(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;
// if we're a thing that can turn, turn to the
// right facing for the unload animation
var unit = self.traits.GetOrDefault<Unit>();
var unloadFacing = self.Info.Traits.Get<CargoInfo>().UnloadFacing;
if (unit != null && unit.Facing != unloadFacing)
return new Turn(unloadFacing) { NextActivity = this };
// todo: handle the BS of open/close sequences, which are inconsistent,
// for reasons that probably make good sense to the westwood guys.
var cargo = self.traits.Get<Cargo>();
if (cargo.IsEmpty(self))
return NextActivity;
var ru = self.traits.GetOrDefault<RenderUnit>();
if (ru != null)
ru.PlayCustomAnimation(self, "unload", null);
var exitTile = ChooseExitTile(self);
if (exitTile == null)
return this;
var actor = cargo.Unload(self);
self.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;
}
public void Cancel(Actor self) { NextActivity = null; isCanceled = true; }
}
}

View File

@@ -1,103 +0,0 @@
#region Copyright & License Information
/*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA.
*
* OpenRA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenRA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
using System.Collections.Generic;
using OpenRA.Traits.Activities;
using OpenRA.GameRules;
namespace OpenRA.Traits
{
public class CargoInfo : ITraitInfo
{
public readonly int Passengers = 0;
public readonly UnitMovementType[] PassengerTypes = { };
public readonly int UnloadFacing = 0;
public object Create(Actor self) { return new Cargo(self); }
}
public class Cargo : IPips, IIssueOrder, IResolveOrder
{
List<Actor> cargo = new List<Actor>();
public Cargo(Actor self) {}
public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor)
{
// todo: check if there is an unoccupied `land` tile adjacent
if (mi.Button == MouseButton.Right && underCursor == self && cargo.Count > 0)
{
var unit = underCursor.traits.GetOrDefault<Unit>();
if (unit != null && unit.Altitude > 0) return null;
return new Order("Deploy", self);
}
return null;
}
public void ResolveOrder(Actor self, Order order)
{
if (order.OrderString == "Deploy")
{
// todo: eject the units
self.CancelActivity();
self.QueueActivity(new UnloadCargo());
}
}
public bool IsFull(Actor self)
{
return cargo.Count == self.Info.Traits.Get<CargoInfo>().Passengers;
}
public bool IsEmpty(Actor self)
{
return cargo.Count == 0;
}
public Actor Unload(Actor self)
{
var a = cargo[0];
cargo.RemoveAt(0);
return a;
}
public IEnumerable<PipType> GetPips( Actor self )
{
var numPips = self.Info.Traits.Get<CargoInfo>().Passengers;
for (var i = 0; i < numPips; i++)
if (i >= cargo.Count)
yield return PipType.Transparent;
else
yield return GetPipForPassenger(cargo[i]);
}
static PipType GetPipForPassenger(Actor a)
{
return a.traits.Get<Passenger>().ColorOfCargoPip( a );
}
public void Load(Actor self, Actor a)
{
cargo.Add(a);
}
}
}

View File

@@ -1,67 +0,0 @@
#region Copyright & License Information
/*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA.
*
* OpenRA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenRA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
using System.Linq;
using OpenRA.Traits.Activities;
namespace OpenRA.Traits
{
class PassengerInfo : TraitInfo<Passenger>
{
public readonly PipType ColorOfCargoPip = PipType.Green;
}
class Passenger : IIssueOrder, IResolveOrder
{
public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor)
{
if (mi.Button != MouseButton.Right)
return null;
if (underCursor == null || underCursor.Owner != self.Owner)
return null;
var cargo = underCursor.traits.GetOrDefault<Cargo>();
if (cargo == null || cargo.IsFull(underCursor))
return null;
var umt = self.traits.Get<IMovement>().GetMovementType();
if (!underCursor.Info.Traits.Get<CargoInfo>().PassengerTypes.Contains(umt))
return null;
return new Order("EnterTransport", self, underCursor);
}
public void ResolveOrder(Actor self, Order order)
{
if (order.OrderString == "EnterTransport")
{
self.CancelActivity();
self.QueueActivity(new Move(order.TargetActor.Location, 1));
self.QueueActivity(new EnterTransport(self, order.TargetActor));
}
}
public PipType ColorOfCargoPip( Actor self )
{
return self.Info.Traits.Get<PassengerInfo>().ColorOfCargoPip;
}
}
}