MCV Undeploy

This commit is contained in:
Paul Chote
2010-01-03 00:04:46 +13:00
parent d183cd708e
commit b44686f39d
4 changed files with 115 additions and 1 deletions

View File

@@ -181,6 +181,7 @@
<Compile Include="Traits\Activities\Move.cs" />
<Compile Include="Traits\Activities\Follow.cs" />
<Compile Include="Traits\Activities\Turn.cs" />
<Compile Include="Traits\Activities\UndeployMcv.cs" />
<Compile Include="Traits\APMine.cs" />
<Compile Include="Traits\ATMine.cs" />
<Compile Include="Traits\AttackBase.cs" />
@@ -201,6 +202,7 @@
<Compile Include="Traits\Harvester.cs" />
<Compile Include="Traits\Helicopter.cs" />
<Compile Include="Traits\InvisibleToOthers.cs" />
<Compile Include="Traits\McvUndeploy.cs" />
<Compile Include="Traits\MineImmune.cs" />
<Compile Include="Traits\Minelayer.cs" />
<Compile Include="Traits\LimitedAmmo.cs" />

View File

@@ -0,0 +1,43 @@
using System;
namespace OpenRa.Game.Traits.Activities
{
class UndeployMcv : IActivity
{
public IActivity NextActivity { get; set; }
bool started;
void DoUndeploy(World w,Actor self)
{
self.Health = 0;
foreach (var ns in self.traits.WithInterface<INotifySold>())
ns.Sold(self);
w.Remove(self);
var mcv = new Actor(Rules.UnitInfo["MCV"], self.Location + new int2(1, 1), self.Owner);
mcv.traits.Get<Unit>().Facing = 96;
w.Add(mcv);
}
public IActivity Tick(Actor self)
{
if (!started)
{
var rb = self.traits.Get<RenderBuilding>();
rb.PlayCustomAnimBackwards(self, "make",
() => Game.world.AddFrameEndTask(w => DoUndeploy(w,self)));
Sound.Play("cashturn.aud");
started = true;
}
return this;
}
public void Cancel(Actor self)
{
// Cancel can't happen between this being moved to the head of the list, and it being Ticked.
throw new InvalidOperationException("UndeployMcvAction: Cancel() should never occur.");
}
}
}

View File

@@ -0,0 +1,69 @@
using OpenRa.Game.GameRules;
using OpenRa.Game.Traits.Activities;
namespace OpenRa.Game.Traits
{
class McvUndeploy : IOrder, IMovement
{
readonly Actor self;
public McvUndeploy(Actor self)
{
this.self = self;
}
public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor)
{
if (!Rules.General.MCVUndeploy) return null;
if (mi.Button == MouseButton.Left) return null;
if (underCursor != null)
{
// force-move
if (!mi.Modifiers.HasModifier(Modifiers.Alt)) return null;
if (!Game.IsActorCrushableByActor(underCursor, self)) return null;
}
return new Order("Move", self, null, xy, null);
}
public void ResolveOrder(Actor self, Order order)
{
if (order.OrderString == "Move")
{
self.CancelActivity();
self.QueueActivity(new UndeployMcv());
}
}
// HACK: This should make reference to an MCV actor, and use of its Mobile trait
public UnitMovementType GetMovementType()
{
return UnitMovementType.Wheel;
}
public bool CanEnterCell(int2 a)
{
if (!Game.BuildingInfluence.CanMoveHere(a)) return false;
var crushable = true;
foreach (Actor actor in Game.UnitInfluence.GetUnitsAt(a))
{
if (actor == self) continue;
if (!Game.IsActorCrushableByActor(actor, self))
{
crushable = false;
break;
}
}
if (!crushable) return false;
return Rules.Map.IsInMap(a.X, a.Y) &&
TerrainCosts.Cost(GetMovementType(),
Rules.TileSet.GetWalkability(Rules.Map.MapTiles[a.X, a.Y])) < double.PositiveInfinity;
}
}
}

View File

@@ -373,7 +373,7 @@ SelectionPriority=3
LongDesc=Produces and repairs submarines and \ntransports
[FACT]
Description=Construction Yard
Traits=Building, RenderBuilding
Traits=Building, RenderBuilding, McvUndeploy
Dimensions=3,3
Footprint=xxx xxx xxx
Produces=Building,Defense