Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow additional actor IDs to be send with orders. #16999

Merged
merged 2 commits into from
Nov 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 36 additions & 9 deletions OpenRA.Game/Network/Order.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ enum OrderFields : byte
{
None = 0x0,
Target = 0x01,
ExtraActors = 0x02,
TargetString = 0x04,
Queued = 0x08,
ExtraLocation = 0x10,
Expand All @@ -53,6 +54,7 @@ public sealed class Order
public readonly Target Target;
public string TargetString;
public CPos ExtraLocation;
public Actor[] ExtraActors;
public uint ExtraData;
public bool IsImmediate;
public OrderType Type = OrderType.Fields;
Expand All @@ -62,13 +64,14 @@ public sealed class Order

public Player Player { get { return Subject != null ? Subject.Owner : null; } }

Order(string orderString, Actor subject, Target target, string targetString, bool queued, CPos extraLocation, uint extraData)
Order(string orderString, Actor subject, Target target, string targetString, bool queued, Actor[] extraActors, CPos extraLocation, uint extraData)
{
OrderString = orderString ?? "";
Subject = subject;
Target = target;
TargetString = targetString;
Queued = queued;
ExtraActors = extraActors;
ExtraLocation = extraLocation;
ExtraData = extraData;
}
Expand Down Expand Up @@ -147,16 +150,27 @@ public static Order Deserialize(World world, BinaryReader r)

var targetString = flags.HasField(OrderFields.TargetString) ? r.ReadString() : null;
var queued = flags.HasField(OrderFields.Queued);

Actor[] extraActors = null;
if (flags.HasField(OrderFields.ExtraActors))
{
var count = r.ReadInt32();
tovl marked this conversation as resolved.
Show resolved Hide resolved
if (world != null)
extraActors = Exts.MakeArray(count, _ => world.GetActorById(r.ReadUInt32()));
else
r.ReadBytes(4 * count);
}

var extraLocation = flags.HasField(OrderFields.ExtraLocation) ? new CPos(r.ReadInt32()) : CPos.Zero;
var extraData = flags.HasField(OrderFields.ExtraData) ? r.ReadUInt32() : 0;

if (world == null)
return new Order(order, null, target, targetString, queued, extraLocation, extraData);
return new Order(order, null, target, targetString, queued, extraActors, extraLocation, extraData);

if (subject == null && flags.HasField(OrderFields.Subject))
return null;

return new Order(order, subject, target, targetString, queued, extraLocation, extraData);
return new Order(order, subject, target, targetString, queued, extraActors, extraLocation, extraData);
}

case OrderType.Handshake:
Expand Down Expand Up @@ -239,21 +253,24 @@ public static Order CancelProduction(Actor subject, string item, int count)

// For scripting special powers
public Order()
: this(null, null, Target.Invalid, null, false, CPos.Zero, 0) { }
: this(null, null, Target.Invalid, null, false, null, CPos.Zero, 0) { }

public Order(string orderString, Actor subject, bool queued)
: this(orderString, subject, Target.Invalid, null, queued, CPos.Zero, 0) { }
public Order(string orderString, Actor subject, bool queued, Actor[] extraActors = null)
: this(orderString, subject, Target.Invalid, null, queued, extraActors, CPos.Zero, 0) { }

public Order(string orderString, Actor subject, Target target, bool queued)
: this(orderString, subject, target, null, queued, CPos.Zero, 0) { }
public Order(string orderString, Actor subject, Target target, bool queued, Actor[] extraActors = null)
: this(orderString, subject, target, null, queued, extraActors, CPos.Zero, 0) { }
RoosterDragon marked this conversation as resolved.
Show resolved Hide resolved

public byte[] Serialize()
{
var minLength = 1 + OrderString.Length + 1;
if (Type == OrderType.Handshake)
minLength += TargetString.Length + 1;
else if (Type == OrderType.Fields)
minLength += 4 + 1 + 13 + (TargetString != null ? TargetString.Length + 1 : 0) + 4 + 4;
minLength += 4 + 1 + 13 + (TargetString != null ? TargetString.Length + 1 : 0) + 4 + 4 + 4;

if (ExtraActors != null)
minLength += ExtraActors.Length * 4;

// ProtocolVersion.Orders and the associated documentation MUST be updated if the serialized format changes
var ret = new MemoryStream(minLength);
Expand Down Expand Up @@ -291,6 +308,9 @@ public byte[] Serialize()
if (Queued)
fields |= OrderFields.Queued;

if (ExtraActors != null)
fields |= OrderFields.ExtraActors;

if (ExtraLocation != CPos.Zero)
fields |= OrderFields.ExtraLocation;

Expand Down Expand Up @@ -329,6 +349,13 @@ public byte[] Serialize()
if (fields.HasField(OrderFields.TargetString))
w.Write(TargetString);

if (fields.HasField(OrderFields.ExtraActors))
{
w.Write(ExtraActors.Length);
foreach (var a in ExtraActors)
w.Write(UIntFromActor(a));
}

if (fields.HasField(OrderFields.ExtraLocation))
w.Write(ExtraLocation);

Expand Down
5 changes: 1 addition & 4 deletions OpenRA.Game/Orders/UnitOrderGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ public virtual IEnumerable<Order> Order(World world, CPos cell, int2 worldPixel,

// HACK: This is required by the hacky player actions-per-minute calculation
// TODO: Reimplement APM properly and then remove this
yield return new Order("CreateGroup", actorsInvolved.First().Owner.PlayerActor, false)
{
TargetString = actorsInvolved.Select(a => a.ActorID).JoinWith(",")
};
yield return new Order("CreateGroup", actorsInvolved.First().Owner.PlayerActor, false, actorsInvolved.ToArray());

foreach (var o in orders)
yield return CheckSameOrder(o.Order, o.Trait.IssueOrder(o.Actor, o.Order, o.Target, mi.Modifiers.HasModifier(Modifiers.Shift)));
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Game/Server/ProtocolVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ public static class ProtocolVersion
// The protocol for server and world orders
// This applies after the handshake has completed, and is provided to support
// alternative server implementations that wish to support multiple versions in parallel
public const int Orders = 8;
public const int Orders = 9;
}
}