Add Lua Scripting for Carryall.
This commit is contained in:
committed by
abcdefg30
parent
860ec642b8
commit
d149624b84
@@ -12,6 +12,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using OpenRA.Activities;
|
using OpenRA.Activities;
|
||||||
using OpenRA.Mods.Common.Traits;
|
using OpenRA.Mods.Common.Traits;
|
||||||
|
using OpenRA.Primitives;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA.Mods.Common.Activities
|
namespace OpenRA.Mods.Common.Activities
|
||||||
@@ -22,19 +23,21 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
readonly BodyOrientation body;
|
readonly BodyOrientation body;
|
||||||
readonly bool assignTargetOnFirstRun;
|
readonly bool assignTargetOnFirstRun;
|
||||||
readonly WDist deliverRange;
|
readonly WDist deliverRange;
|
||||||
|
readonly Color? targetLineColor;
|
||||||
|
|
||||||
Target destination;
|
Target destination;
|
||||||
|
|
||||||
public DeliverUnit(Actor self, WDist deliverRange)
|
public DeliverUnit(Actor self, WDist deliverRange, Color? targetLineColor)
|
||||||
: this(self, Target.Invalid, deliverRange)
|
: this(self, Target.Invalid, deliverRange, targetLineColor)
|
||||||
{
|
{
|
||||||
assignTargetOnFirstRun = true;
|
assignTargetOnFirstRun = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DeliverUnit(Actor self, in Target destination, WDist deliverRange)
|
public DeliverUnit(Actor self, in Target destination, WDist deliverRange, Color? targetLineColor)
|
||||||
{
|
{
|
||||||
this.destination = destination;
|
this.destination = destination;
|
||||||
this.deliverRange = deliverRange;
|
this.deliverRange = deliverRange;
|
||||||
|
this.targetLineColor = targetLineColor;
|
||||||
|
|
||||||
carryall = self.Trait<Carryall>();
|
carryall = self.Trait<Carryall>();
|
||||||
body = self.Trait<BodyOrientation>();
|
body = self.Trait<BodyOrientation>();
|
||||||
@@ -59,7 +62,8 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
|
|
||||||
public override IEnumerable<TargetLineNode> TargetLineNodes(Actor self)
|
public override IEnumerable<TargetLineNode> TargetLineNodes(Actor self)
|
||||||
{
|
{
|
||||||
yield return new TargetLineNode(destination, carryall.Info.TargetLineColor);
|
if (targetLineColor != null)
|
||||||
|
yield return new TargetLineNode(destination, targetLineColor.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
class ReleaseUnit : Activity
|
class ReleaseUnit : Activity
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using OpenRA.Activities;
|
using OpenRA.Activities;
|
||||||
using OpenRA.Mods.Common.Traits;
|
using OpenRA.Mods.Common.Traits;
|
||||||
|
using OpenRA.Primitives;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA.Mods.Common.Activities
|
namespace OpenRA.Mods.Common.Activities
|
||||||
@@ -25,6 +26,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
readonly BodyOrientation carryableBody;
|
readonly BodyOrientation carryableBody;
|
||||||
|
|
||||||
readonly int delay;
|
readonly int delay;
|
||||||
|
readonly Color? targetLineColor;
|
||||||
|
|
||||||
// TODO: Expose this to yaml
|
// TODO: Expose this to yaml
|
||||||
readonly WDist targetLockRange = WDist.FromCells(4);
|
readonly WDist targetLockRange = WDist.FromCells(4);
|
||||||
@@ -32,10 +34,11 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
enum PickupState { Intercept, LockCarryable, Pickup }
|
enum PickupState { Intercept, LockCarryable, Pickup }
|
||||||
PickupState state = PickupState.Intercept;
|
PickupState state = PickupState.Intercept;
|
||||||
|
|
||||||
public PickupUnit(Actor self, Actor cargo, int delay)
|
public PickupUnit(Actor self, Actor cargo, int delay, Color? targetLineColor)
|
||||||
{
|
{
|
||||||
this.cargo = cargo;
|
this.cargo = cargo;
|
||||||
this.delay = delay;
|
this.delay = delay;
|
||||||
|
this.targetLineColor = targetLineColor;
|
||||||
carryable = cargo.Trait<Carryable>();
|
carryable = cargo.Trait<Carryable>();
|
||||||
carryableFacing = cargo.Trait<IFacing>();
|
carryableFacing = cargo.Trait<IFacing>();
|
||||||
carryableBody = cargo.Trait<BodyOrientation>();
|
carryableBody = cargo.Trait<BodyOrientation>();
|
||||||
@@ -115,7 +118,8 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
|
|
||||||
public override IEnumerable<TargetLineNode> TargetLineNodes(Actor self)
|
public override IEnumerable<TargetLineNode> TargetLineNodes(Actor self)
|
||||||
{
|
{
|
||||||
yield return new TargetLineNode(Target.FromActor(cargo), carryall.Info.TargetLineColor);
|
if (targetLineColor != null)
|
||||||
|
yield return new TargetLineNode(Target.FromActor(cargo), targetLineColor.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
class AttachUnit : Activity
|
class AttachUnit : Activity
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright 2007-2021 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, either version 3 of
|
||||||
|
* the License, or (at your option) any later version. For more
|
||||||
|
* information, see COPYING.
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using Eluant;
|
||||||
|
using OpenRA.Mods.Common.Activities;
|
||||||
|
using OpenRA.Mods.Common.Traits;
|
||||||
|
using OpenRA.Scripting;
|
||||||
|
using OpenRA.Traits;
|
||||||
|
|
||||||
|
namespace OpenRA.Mods.Common.Scripting
|
||||||
|
{
|
||||||
|
[ScriptPropertyGroup("Ability")]
|
||||||
|
public class CarryallProperties : ScriptActorProperties, Requires<CarryallInfo>
|
||||||
|
{
|
||||||
|
readonly Carryall carryall;
|
||||||
|
|
||||||
|
public CarryallProperties(ScriptContext context, Actor self)
|
||||||
|
: base(context, self)
|
||||||
|
{
|
||||||
|
carryall = Self.Trait<Carryall>();
|
||||||
|
}
|
||||||
|
|
||||||
|
[ScriptActorPropertyActivity]
|
||||||
|
[Desc("Pick up the target actor.")]
|
||||||
|
public void PickupCarryable(Actor target)
|
||||||
|
{
|
||||||
|
var carryable = target.TraitOrDefault<Carryable>();
|
||||||
|
if (carryable == null)
|
||||||
|
throw new LuaException("Actor '{0}' cannot carry actor '{1}'!".F(Self, target));
|
||||||
|
|
||||||
|
Self.QueueActivity(new PickupUnit(Self, target, carryall.Info.BeforeLoadDelay, null));
|
||||||
|
}
|
||||||
|
|
||||||
|
[ScriptActorPropertyActivity]
|
||||||
|
[Desc("Drop the actor being carried at the target location.")]
|
||||||
|
public void DeliverCarryable(CPos target)
|
||||||
|
{
|
||||||
|
Self.QueueActivity(new DeliverUnit(Self, Target.FromCell(Self.World, target), carryall.Info.DropRange, null));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -105,16 +105,20 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
class FerryUnit : Activity
|
class FerryUnit : Activity
|
||||||
{
|
{
|
||||||
readonly Actor cargo;
|
readonly Actor cargo;
|
||||||
|
readonly Carryable carryable;
|
||||||
|
readonly CarryallInfo carryallInfo;
|
||||||
|
|
||||||
public FerryUnit(Actor self, Actor cargo)
|
public FerryUnit(Actor self, Actor cargo)
|
||||||
{
|
{
|
||||||
this.cargo = cargo;
|
this.cargo = cargo;
|
||||||
|
carryable = cargo.Trait<Carryable>();
|
||||||
|
carryallInfo = self.Trait<Carryall>().Info;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnFirstRun(Actor self)
|
protected override void OnFirstRun(Actor self)
|
||||||
{
|
{
|
||||||
if (!cargo.IsDead)
|
if (!cargo.IsDead)
|
||||||
QueueChild(new PickupUnit(self, cargo, 0));
|
QueueChild(new PickupUnit(self, cargo, 0, carryallInfo.TargetLineColor));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool Tick(Actor self)
|
public override bool Tick(Actor self)
|
||||||
@@ -122,10 +126,10 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (cargo.IsDead)
|
if (cargo.IsDead)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
var dropRange = self.Trait<Carryall>().Info.DropRange;
|
var dropRange = carryallInfo.DropRange;
|
||||||
var destination = cargo.Trait<Carryable>().Destination;
|
var destination = carryable.Destination;
|
||||||
if (destination != null)
|
if (destination != null)
|
||||||
self.QueueActivity(true, new DeliverUnit(self, Target.FromCell(self.World, destination.Value), dropRange));
|
self.QueueActivity(true, new DeliverUnit(self, Target.FromCell(self.World, destination.Value), dropRange, carryallInfo.TargetLineColor));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,8 +65,9 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
var carryable = cargo.Trait<Carryable>();
|
var carryable = cargo.Trait<Carryable>();
|
||||||
carryable.Reserve(cargo, carrier);
|
carryable.Reserve(cargo, carrier);
|
||||||
|
|
||||||
carrier.Trait<Carryall>().AttachCarryable(carrier, cargo);
|
var carryall = carrier.Trait<Carryall>();
|
||||||
carrier.QueueActivity(new DeliverUnit(carrier, Target.FromCell(self.World, location), info.DeliveryRange));
|
carryall.AttachCarryable(carrier, cargo);
|
||||||
|
carrier.QueueActivity(new DeliverUnit(carrier, Target.FromCell(self.World, location), info.DeliveryRange, carryall.Info.TargetLineColor));
|
||||||
carrier.QueueActivity(new Fly(carrier, Target.FromCell(self.World, self.World.Map.ChooseRandomEdgeCell(self.World.SharedRandom))));
|
carrier.QueueActivity(new Fly(carrier, Target.FromCell(self.World, self.World.Map.ChooseRandomEdgeCell(self.World.SharedRandom))));
|
||||||
carrier.QueueActivity(new RemoveSelf());
|
carrier.QueueActivity(new RemoveSelf());
|
||||||
|
|
||||||
|
|||||||
@@ -348,7 +348,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
var targetLocation = move.NearestMoveableCell(cell);
|
var targetLocation = move.NearestMoveableCell(cell);
|
||||||
self.QueueActivity(order.Queued, new DeliverUnit(self, order.Target, Info.DropRange));
|
self.QueueActivity(order.Queued, new DeliverUnit(self, order.Target, Info.DropRange, Info.TargetLineColor));
|
||||||
self.ShowTargetLines();
|
self.ShowTargetLines();
|
||||||
}
|
}
|
||||||
else if (order.OrderString == "Unload")
|
else if (order.OrderString == "Unload")
|
||||||
@@ -356,14 +356,14 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (!order.Queued && !CanUnload())
|
if (!order.Queued && !CanUnload())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
self.QueueActivity(order.Queued, new DeliverUnit(self, Info.DropRange));
|
self.QueueActivity(order.Queued, new DeliverUnit(self, Info.DropRange, Info.TargetLineColor));
|
||||||
}
|
}
|
||||||
else if (order.OrderString == "PickupUnit")
|
else if (order.OrderString == "PickupUnit")
|
||||||
{
|
{
|
||||||
if (order.Target.Type != TargetType.Actor)
|
if (order.Target.Type != TargetType.Actor)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
self.QueueActivity(order.Queued, new PickupUnit(self, order.Target.Actor, Info.BeforeLoadDelay));
|
self.QueueActivity(order.Queued, new PickupUnit(self, order.Target.Actor, Info.BeforeLoadDelay, Info.TargetLineColor));
|
||||||
self.ShowTargetLines();
|
self.ShowTargetLines();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user