Add plumbing to issue orders against a generic Target.
This commit is contained in:
@@ -12,6 +12,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using OpenRA.Network;
|
using OpenRA.Network;
|
||||||
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA
|
namespace OpenRA
|
||||||
{
|
{
|
||||||
@@ -63,6 +64,21 @@ namespace OpenRA
|
|||||||
ExtraData = extraData;
|
ExtraData = extraData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Order(string orderString, Actor subject, Target target, bool queued, CPos extraLocation, uint extraData)
|
||||||
|
{
|
||||||
|
var targetType = target.SerializableType;
|
||||||
|
|
||||||
|
OrderString = orderString;
|
||||||
|
Subject = subject;
|
||||||
|
TargetActor = targetType == TargetType.Actor ? target.SerializableActor : null;
|
||||||
|
TargetLocation = targetType == TargetType.Terrain ? target.SerializableCell.HasValue ?
|
||||||
|
target.SerializableCell.Value : subject.World.Map.CellContaining(target.CenterPosition) : CPos.Zero;
|
||||||
|
TargetString = null;
|
||||||
|
Queued = queued;
|
||||||
|
ExtraLocation = extraLocation;
|
||||||
|
ExtraData = targetType == TargetType.FrozenActor ? target.FrozenActor.ID : extraData;
|
||||||
|
}
|
||||||
|
|
||||||
public static Order Deserialize(World world, BinaryReader r)
|
public static Order Deserialize(World world, BinaryReader r)
|
||||||
{
|
{
|
||||||
var magic = r.ReadByte();
|
var magic = r.ReadByte();
|
||||||
@@ -174,6 +190,9 @@ namespace OpenRA
|
|||||||
public Order(string orderString, Actor subject, bool queued)
|
public Order(string orderString, Actor subject, bool queued)
|
||||||
: this(orderString, subject, null, CPos.Zero, null, queued, CPos.Zero, 0) { }
|
: this(orderString, subject, null, CPos.Zero, null, queued, CPos.Zero, 0) { }
|
||||||
|
|
||||||
|
public Order(string orderString, Actor subject, Target target, bool queued)
|
||||||
|
: this(orderString, subject, target, queued, CPos.Zero, 0) { }
|
||||||
|
|
||||||
public Order(string orderstring, Order order)
|
public Order(string orderstring, Order order)
|
||||||
: this(orderstring, order.Subject, order.TargetActor, order.TargetLocation,
|
: this(orderstring, order.Subject, order.TargetActor, order.TargetLocation,
|
||||||
order.TargetString, order.Queued, order.ExtraLocation, order.ExtraData) { }
|
order.TargetString, order.Queued, order.ExtraLocation, order.ExtraData) { }
|
||||||
|
|||||||
@@ -25,12 +25,13 @@ namespace OpenRA.Traits
|
|||||||
Actor actor;
|
Actor actor;
|
||||||
FrozenActor frozen;
|
FrozenActor frozen;
|
||||||
WPos pos;
|
WPos pos;
|
||||||
|
CPos? cell;
|
||||||
int generation;
|
int generation;
|
||||||
|
|
||||||
public static Target FromPos(WPos p) { return new Target { pos = p, type = TargetType.Terrain }; }
|
public static Target FromPos(WPos p) { return new Target { pos = p, type = TargetType.Terrain }; }
|
||||||
public static Target FromCell(World w, CPos c, SubCell subCell = SubCell.FullCell)
|
public static Target FromCell(World w, CPos c, SubCell subCell = SubCell.FullCell)
|
||||||
{
|
{
|
||||||
return new Target { pos = w.Map.CenterOfSubCell(c, subCell), type = TargetType.Terrain };
|
return new Target { pos = w.Map.CenterOfSubCell(c, subCell), cell = c, type = TargetType.Terrain };
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Target FromOrder(World w, Order o)
|
public static Target FromOrder(World w, Order o)
|
||||||
@@ -191,5 +192,10 @@ namespace OpenRA.Traits
|
|||||||
return "Invalid";
|
return "Invalid";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Expose internal state for serialization by the orders code *only*
|
||||||
|
internal TargetType SerializableType { get { return type; } }
|
||||||
|
internal Actor SerializableActor { get { return actor; } }
|
||||||
|
internal CPos? SerializableCell { get { return cell; } }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user