Enable Repairable actors to call for transport to the repair pad
This commit is contained in:
51
OpenRA.Mods.Common/Activities/WaitForTransport.cs
Normal file
51
OpenRA.Mods.Common/Activities/WaitForTransport.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2015 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.Activities;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Activities
|
||||
{
|
||||
public class WaitForTransport : Activity
|
||||
{
|
||||
readonly ICallForTransport transportable;
|
||||
|
||||
Activity inner;
|
||||
|
||||
public WaitForTransport(Actor self, Activity innerActivity)
|
||||
{
|
||||
transportable = self.TraitOrDefault<ICallForTransport>();
|
||||
inner = innerActivity;
|
||||
}
|
||||
|
||||
public override Activity Tick(Actor self)
|
||||
{
|
||||
if (inner == null)
|
||||
{
|
||||
if (transportable != null)
|
||||
transportable.MovementCancelled(self);
|
||||
|
||||
return NextActivity;
|
||||
}
|
||||
|
||||
inner = Util.RunActivity(self, inner);
|
||||
return this;
|
||||
}
|
||||
|
||||
public override void Cancel(Actor self)
|
||||
{
|
||||
if (transportable != null)
|
||||
transportable.WantsTransport = false;
|
||||
|
||||
inner.Cancel(self);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -115,6 +115,7 @@
|
||||
<Compile Include="Activities\Turn.cs" />
|
||||
<Compile Include="Activities\UnloadCargo.cs" />
|
||||
<Compile Include="Activities\Wait.cs" />
|
||||
<Compile Include="Activities\WaitForTransport.cs" />
|
||||
<Compile Include="ActorExts.cs" />
|
||||
<Compile Include="AI\AttackOrFleeFuzzy.cs" />
|
||||
<Compile Include="AI\BaseBuilder.cs" />
|
||||
|
||||
@@ -42,8 +42,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
get
|
||||
{
|
||||
yield return new EnterAlliedActorTargeter<Building>("Repair", 5,
|
||||
target => CanRepairAt(target), _ => CanRepair() || CanRearm());
|
||||
yield return new EnterAlliedActorTargeter<Building>("Repair", 5, CanRepairAt, _ => CanRepair() || CanRearm());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,7 +91,20 @@ namespace OpenRA.Mods.Common.Traits
|
||||
self.SetTargetLine(target, Color.Green);
|
||||
|
||||
self.CancelActivity();
|
||||
self.QueueActivity(new MoveAdjacentTo(self, target));
|
||||
self.QueueActivity(new WaitForTransport(self, Util.SequenceActivities(new MoveAdjacentTo(self, target),
|
||||
new CallFunc(() => AfterReachActivities(self, order, movement)))));
|
||||
|
||||
TryCallTransport(self, target, new CallFunc(() => AfterReachActivities(self, order, movement)));
|
||||
}
|
||||
}
|
||||
|
||||
void AfterReachActivities(Actor self, Order order, IMove movement)
|
||||
{
|
||||
if (!order.TargetActor.IsInWorld || order.TargetActor.IsDead || order.TargetActor.IsDisabled())
|
||||
return;
|
||||
|
||||
// TODO: This is hacky, but almost every single component affected
|
||||
// will need to be rewritten anyway, so this is OK for now.
|
||||
self.QueueActivity(movement.MoveTo(self.World.Map.CellContaining(order.TargetActor.CenterPosition), order.TargetActor));
|
||||
if (CanRearmAt(order.TargetActor) && CanRearm())
|
||||
self.QueueActivity(new Rearm(self));
|
||||
@@ -101,6 +113,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
var rp = order.TargetActor.TraitOrDefault<RallyPoint>();
|
||||
if (rp != null)
|
||||
{
|
||||
self.QueueActivity(new CallFunc(() =>
|
||||
{
|
||||
self.SetTargetLine(Target.FromCell(self.World, rp.Location), Color.Green);
|
||||
@@ -120,5 +133,18 @@ namespace OpenRA.Mods.Common.Traits
|
||||
// Worst case FirstOrDefault() will return a TraitPair<null, null>, which is OK.
|
||||
return repairBuilding.FirstOrDefault().Actor;
|
||||
}
|
||||
|
||||
static void TryCallTransport(Actor self, Target target, Activity nextActivity)
|
||||
{
|
||||
var transport = self.TraitOrDefault<ICallForTransport>();
|
||||
if (transport == null)
|
||||
return;
|
||||
|
||||
var targetCell = self.World.Map.CellContaining(target.CenterPosition);
|
||||
if ((self.CenterPosition - target.CenterPosition).LengthSquared < transport.MinimumDistance.Range * transport.MinimumDistance.Range)
|
||||
return;
|
||||
|
||||
transport.RequestTransport(targetCell, nextActivity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user