Merge pull request #8056 from penev92/bleed_carryalls
Added unit repair via order button with optional Carryall transport
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\Turn.cs" />
|
||||||
<Compile Include="Activities\UnloadCargo.cs" />
|
<Compile Include="Activities\UnloadCargo.cs" />
|
||||||
<Compile Include="Activities\Wait.cs" />
|
<Compile Include="Activities\Wait.cs" />
|
||||||
|
<Compile Include="Activities\WaitForTransport.cs" />
|
||||||
<Compile Include="ActorExts.cs" />
|
<Compile Include="ActorExts.cs" />
|
||||||
<Compile Include="AI\AttackOrFleeFuzzy.cs" />
|
<Compile Include="AI\AttackOrFleeFuzzy.cs" />
|
||||||
<Compile Include="AI\BaseBuilder.cs" />
|
<Compile Include="AI\BaseBuilder.cs" />
|
||||||
|
|||||||
@@ -26,21 +26,35 @@ namespace OpenRA.Mods.Common.Orders
|
|||||||
return OrderInner(world, mi);
|
return OrderInner(world, mi);
|
||||||
}
|
}
|
||||||
|
|
||||||
IEnumerable<Order> OrderInner(World world, MouseInput mi)
|
static IEnumerable<Order> OrderInner(World world, MouseInput mi)
|
||||||
{
|
{
|
||||||
if (mi.Button == MouseButton.Left)
|
if (mi.Button != MouseButton.Left)
|
||||||
{
|
yield break;
|
||||||
var underCursor = world.ScreenMap.ActorsAt(mi)
|
|
||||||
.FirstOrDefault(a => !world.FogObscures(a) && a.AppearsFriendlyTo(world.LocalPlayer.PlayerActor)
|
|
||||||
&& a.TraitsImplementing<RepairableBuilding>().Any(t => !t.IsTraitDisabled));
|
|
||||||
|
|
||||||
if (underCursor == null)
|
var underCursor = world.ScreenMap.ActorsAt(mi)
|
||||||
yield break;
|
.FirstOrDefault(a => a.AppearsFriendlyTo(world.LocalPlayer.PlayerActor) && !world.FogObscures(a));
|
||||||
|
|
||||||
if (underCursor.Info.Traits.Contains<RepairableBuildingInfo>()
|
if (underCursor == null)
|
||||||
&& underCursor.GetDamageState() > DamageState.Undamaged)
|
yield break;
|
||||||
yield return new Order("RepairBuilding", world.LocalPlayer.PlayerActor, false) { TargetActor = underCursor };
|
|
||||||
}
|
if (underCursor.GetDamageState() == DamageState.Undamaged)
|
||||||
|
yield break;
|
||||||
|
|
||||||
|
// Repair a building.
|
||||||
|
if (underCursor.Info.Traits.Contains<RepairableBuildingInfo>())
|
||||||
|
yield return new Order("RepairBuilding", world.LocalPlayer.PlayerActor, false) { TargetActor = underCursor };
|
||||||
|
|
||||||
|
// Test for generic Repairable (used on units).
|
||||||
|
var repairable = underCursor.TraitOrDefault<Repairable>();
|
||||||
|
if (repairable == null)
|
||||||
|
yield break;
|
||||||
|
|
||||||
|
// Find a building to repair at.
|
||||||
|
var repairBuilding = repairable.FindRepairBuilding(underCursor);
|
||||||
|
if (repairBuilding == null)
|
||||||
|
yield break;
|
||||||
|
|
||||||
|
yield return new Order("Repair", underCursor, false) { TargetActor = repairBuilding };
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Tick(World world)
|
public void Tick(World world)
|
||||||
|
|||||||
@@ -42,8 +42,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
yield return new EnterAlliedActorTargeter<Building>("Repair", 5,
|
yield return new EnterAlliedActorTargeter<Building>("Repair", 5, CanRepairAt, _ => CanRepair() || CanRearm());
|
||||||
target => CanRepairAt(target), _ => CanRepair() || CanRearm());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,21 +91,60 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
self.SetTargetLine(target, Color.Green);
|
self.SetTargetLine(target, Color.Green);
|
||||||
|
|
||||||
self.CancelActivity();
|
self.CancelActivity();
|
||||||
self.QueueActivity(new MoveAdjacentTo(self, target));
|
self.QueueActivity(new WaitForTransport(self, Util.SequenceActivities(new MoveAdjacentTo(self, target),
|
||||||
self.QueueActivity(movement.MoveTo(self.World.Map.CellContaining(order.TargetActor.CenterPosition), order.TargetActor));
|
new CallFunc(() => AfterReachActivities(self, order, movement)))));
|
||||||
if (CanRearmAt(order.TargetActor) && CanRearm())
|
|
||||||
self.QueueActivity(new Rearm(self));
|
|
||||||
|
|
||||||
self.QueueActivity(new Repair(order.TargetActor));
|
TryCallTransport(self, target, new CallFunc(() => AfterReachActivities(self, order, movement)));
|
||||||
|
|
||||||
var rp = order.TargetActor.TraitOrDefault<RallyPoint>();
|
|
||||||
if (rp != null)
|
|
||||||
self.QueueActivity(new CallFunc(() =>
|
|
||||||
{
|
|
||||||
self.SetTargetLine(Target.FromCell(self.World, rp.Location), Color.Green);
|
|
||||||
self.QueueActivity(movement.MoveTo(rp.Location, order.TargetActor));
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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));
|
||||||
|
|
||||||
|
self.QueueActivity(new Repair(order.TargetActor));
|
||||||
|
|
||||||
|
var rp = order.TargetActor.TraitOrDefault<RallyPoint>();
|
||||||
|
if (rp != null)
|
||||||
|
{
|
||||||
|
self.QueueActivity(new CallFunc(() =>
|
||||||
|
{
|
||||||
|
self.SetTargetLine(Target.FromCell(self.World, rp.Location), Color.Green);
|
||||||
|
self.QueueActivity(movement.MoveTo(rp.Location, order.TargetActor));
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Actor FindRepairBuilding(Actor self)
|
||||||
|
{
|
||||||
|
var repairBuilding = self.World.ActorsWithTrait<RepairsUnits>()
|
||||||
|
.Where(a => !a.Actor.IsDead && a.Actor.IsInWorld
|
||||||
|
&& a.Actor.Owner == self.Owner &&
|
||||||
|
info.RepairBuildings.Contains(a.Actor.Info.Name))
|
||||||
|
.OrderBy(p => (self.Location - p.Actor.Location).LengthSquared);
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,4 +85,12 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
IEnumerable<string> PaletteNames { get; }
|
IEnumerable<string> PaletteNames { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface ICallForTransport
|
||||||
|
{
|
||||||
|
WRange MinimumDistance { get; }
|
||||||
|
bool WantsTransport { get; set; }
|
||||||
|
void MovementCancelled(Actor self);
|
||||||
|
void RequestTransport(CPos destination, Activity afterLandActivity);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,13 +18,13 @@ namespace OpenRA.Mods.D2k.Traits
|
|||||||
[Desc("Can be carried by units with the trait `Carryall`.")]
|
[Desc("Can be carried by units with the trait `Carryall`.")]
|
||||||
public class CarryableInfo : ITraitInfo
|
public class CarryableInfo : ITraitInfo
|
||||||
{
|
{
|
||||||
[Desc("Required distance away from destination before requesting a pickup.")]
|
[Desc("Required distance away from destination before requesting a pickup. Default is 6 cells.")]
|
||||||
public int MinDistance = 6;
|
public WRange MinDistance = WRange.FromCells(6);
|
||||||
|
|
||||||
public object Create(ActorInitializer init) { return new Carryable(init.Self, this); }
|
public object Create(ActorInitializer init) { return new Carryable(init.Self, this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Carryable : IDisableMove, INotifyHarvesterAction
|
public class Carryable : IDisableMove, INotifyHarvesterAction, ICallForTransport
|
||||||
{
|
{
|
||||||
readonly CarryableInfo info;
|
readonly CarryableInfo info;
|
||||||
readonly Actor self;
|
readonly Actor self;
|
||||||
@@ -34,7 +34,7 @@ namespace OpenRA.Mods.D2k.Traits
|
|||||||
// If we're locked there isn't much we can do. We'll have to wait for the carrier to finish with us. We should not move or get new orders!
|
// If we're locked there isn't much we can do. We'll have to wait for the carrier to finish with us. We should not move or get new orders!
|
||||||
bool locked;
|
bool locked;
|
||||||
|
|
||||||
public bool WantsTransport { get; private set; }
|
public bool WantsTransport { get; set; }
|
||||||
public CPos Destination;
|
public CPos Destination;
|
||||||
Activity afterLandActivity;
|
Activity afterLandActivity;
|
||||||
|
|
||||||
@@ -51,9 +51,12 @@ namespace OpenRA.Mods.D2k.Traits
|
|||||||
public void MovingToResources(Actor self, CPos targetCell, Activity next) { RequestTransport(targetCell, next); }
|
public void MovingToResources(Actor self, CPos targetCell, Activity next) { RequestTransport(targetCell, next); }
|
||||||
public void MovingToRefinery(Actor self, CPos targetCell, Activity next) { RequestTransport(targetCell, next); }
|
public void MovingToRefinery(Actor self, CPos targetCell, Activity next) { RequestTransport(targetCell, next); }
|
||||||
|
|
||||||
void RequestTransport(CPos destination, Activity afterLandActivity)
|
public WRange MinimumDistance { get { return info.MinDistance; } }
|
||||||
|
|
||||||
|
public void RequestTransport(CPos destination, Activity afterLandActivity)
|
||||||
{
|
{
|
||||||
if (destination == CPos.Zero || (self.Location - destination).Length < info.MinDistance)
|
var destPos = self.World.Map.CenterOfCell(destination);
|
||||||
|
if (destination == CPos.Zero || (self.CenterPosition - destPos).LengthSquared < info.MinDistance.Range * info.MinDistance.Range)
|
||||||
{
|
{
|
||||||
WantsTransport = false; // Be sure to cancel any pending transports
|
WantsTransport = false; // Be sure to cancel any pending transports
|
||||||
return;
|
return;
|
||||||
@@ -71,12 +74,9 @@ namespace OpenRA.Mods.D2k.Traits
|
|||||||
.Where(c => !c.Trait.IsBusy && !c.Actor.IsDead && c.Actor.Owner == self.Owner && c.Actor.IsInWorld)
|
.Where(c => !c.Trait.IsBusy && !c.Actor.IsDead && c.Actor.Owner == self.Owner && c.Actor.IsInWorld)
|
||||||
.OrderBy(p => (self.Location - p.Actor.Location).LengthSquared);
|
.OrderBy(p => (self.Location - p.Actor.Location).LengthSquared);
|
||||||
|
|
||||||
foreach (var carrier in carriers)
|
// Is any carrier able to transport the actor?
|
||||||
{
|
// Any will return once it finds a carrier that returns true.
|
||||||
// Notify the carrier and see if he's willing to transport us..
|
carriers.Any(carrier => carrier.Trait.RequestTransportNotify(self));
|
||||||
if (carrier.Trait.RequestTransportNotify(self))
|
|
||||||
break; // If true then we're done
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// No longer want to be carried
|
// No longer want to be carried
|
||||||
@@ -119,7 +119,8 @@ namespace OpenRA.Mods.D2k.Traits
|
|||||||
if (Reserved)
|
if (Reserved)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if ((self.Location - Destination).Length < info.MinDistance)
|
var destPos = self.World.Map.CenterOfCell(Destination);
|
||||||
|
if ((self.CenterPosition - destPos).LengthSquared < info.MinDistance.Range * info.MinDistance.Range)
|
||||||
{
|
{
|
||||||
MovementCancelled(self);
|
MovementCancelled(self);
|
||||||
return false;
|
return false;
|
||||||
@@ -146,7 +147,8 @@ namespace OpenRA.Mods.D2k.Traits
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Last change to change our mind...
|
// Last change to change our mind...
|
||||||
if ((self.Location - Destination).Length < info.MinDistance)
|
var destPos = self.World.Map.CenterOfCell(Destination);
|
||||||
|
if ((self.CenterPosition - destPos).LengthSquared < info.MinDistance.Range * info.MinDistance.Range)
|
||||||
{
|
{
|
||||||
MovementCancelled(self);
|
MovementCancelled(self);
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -103,6 +103,9 @@ namespace OpenRA.Mods.D2k.Traits
|
|||||||
if (!trait.WantsTransport)
|
if (!trait.WantsTransport)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if (actor.IsIdle)
|
||||||
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
})
|
})
|
||||||
.OrderBy(p => (self.Location - p.Actor.Location).LengthSquared);
|
.OrderBy(p => (self.Location - p.Actor.Location).LengthSquared);
|
||||||
|
|||||||
@@ -53,6 +53,11 @@
|
|||||||
Notification: EnemyUnitsDetected
|
Notification: EnemyUnitsDetected
|
||||||
Voiced:
|
Voiced:
|
||||||
VoiceSet: VehicleVoice
|
VoiceSet: VehicleVoice
|
||||||
|
Carryable:
|
||||||
|
WithDecorationCarryable:
|
||||||
|
Image: pips
|
||||||
|
Sequence: pickup-indicator
|
||||||
|
Offset: -12, -12
|
||||||
|
|
||||||
^Tank:
|
^Tank:
|
||||||
AppearsOnRadar:
|
AppearsOnRadar:
|
||||||
@@ -109,6 +114,11 @@
|
|||||||
Notification: EnemyUnitsDetected
|
Notification: EnemyUnitsDetected
|
||||||
Voiced:
|
Voiced:
|
||||||
VoiceSet: VehicleVoice
|
VoiceSet: VehicleVoice
|
||||||
|
Carryable:
|
||||||
|
WithDecorationCarryable:
|
||||||
|
Image: pips
|
||||||
|
Sequence: pickup-indicator
|
||||||
|
Offset: -12, -12
|
||||||
|
|
||||||
^Husk:
|
^Husk:
|
||||||
Health:
|
Health:
|
||||||
|
|||||||
@@ -61,11 +61,6 @@ harvester:
|
|||||||
UnloadTicksPerBale: 5
|
UnloadTicksPerBale: 5
|
||||||
SearchFromProcRadius: 24
|
SearchFromProcRadius: 24
|
||||||
SearchFromOrderRadius: 12
|
SearchFromOrderRadius: 12
|
||||||
Carryable:
|
|
||||||
WithDecorationCarryable:
|
|
||||||
Image: pips
|
|
||||||
Sequence: pickup-indicator
|
|
||||||
Offset: -12, -12
|
|
||||||
Health:
|
Health:
|
||||||
HP: 1000
|
HP: 1000
|
||||||
Armor:
|
Armor:
|
||||||
|
|||||||
Reference in New Issue
Block a user