StyleCop clean Order
This commit is contained in:
@@ -62,6 +62,111 @@ namespace OpenRA
|
||||
this.ExtraData = extraData;
|
||||
}
|
||||
|
||||
public static Order Deserialize(World world, BinaryReader r)
|
||||
{
|
||||
switch (r.ReadByte())
|
||||
{
|
||||
case 0xFF:
|
||||
{
|
||||
var order = r.ReadString();
|
||||
var subjectId = r.ReadUInt32();
|
||||
var flags = (OrderFields)r.ReadByte();
|
||||
|
||||
var targetActorId = flags.HasField(OrderFields.TargetActor) ? r.ReadUInt32() : 0xffffffff;
|
||||
var targetLocation = (CPos)(flags.HasField(OrderFields.TargetLocation) ? r.ReadInt2() : int2.Zero);
|
||||
var targetString = flags.HasField(OrderFields.TargetString) ? r.ReadString() : null;
|
||||
var queued = flags.HasField(OrderFields.Queued);
|
||||
var extraLocation = (CPos)(flags.HasField(OrderFields.ExtraLocation) ? r.ReadInt2() : int2.Zero);
|
||||
var extraData = flags.HasField(OrderFields.ExtraData) ? r.ReadUInt32() : 0;
|
||||
|
||||
Actor subject, targetActor;
|
||||
if (!TryGetActorFromUInt(world, subjectId, out subject) || !TryGetActorFromUInt(world, targetActorId, out targetActor))
|
||||
return null;
|
||||
|
||||
return new Order(order, subject, targetActor, targetLocation, targetString, queued, extraLocation, extraData);
|
||||
}
|
||||
|
||||
case 0xfe:
|
||||
{
|
||||
var name = r.ReadString();
|
||||
var data = r.ReadString();
|
||||
|
||||
return new Order(name, null, false) { IsImmediate = true, TargetString = data };
|
||||
}
|
||||
|
||||
default:
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
static uint UIntFromActor(Actor a)
|
||||
{
|
||||
if (a == null) return 0xffffffff;
|
||||
return a.ActorID;
|
||||
}
|
||||
|
||||
static bool TryGetActorFromUInt(World world, uint aID, out Actor ret)
|
||||
{
|
||||
if (aID == 0xFFFFFFFF)
|
||||
{
|
||||
ret = null;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var a in world.Actors.Where(x => x.ActorID == aID))
|
||||
{
|
||||
ret = a;
|
||||
return true;
|
||||
}
|
||||
|
||||
ret = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Named constructors for Orders.
|
||||
// Now that Orders are resolved by individual Actors, these are weird; you unpack orders manually, but not pack them.
|
||||
public static Order Chat(bool team, string text)
|
||||
{
|
||||
return new Order(team ? "TeamChat" : "Chat", null, false) { IsImmediate = true, TargetString = text };
|
||||
}
|
||||
|
||||
public static Order HandshakeResponse(string text)
|
||||
{
|
||||
return new Order("HandshakeResponse", null, false) { IsImmediate = true, TargetString = text };
|
||||
}
|
||||
|
||||
public static Order Pong(string pingTime)
|
||||
{
|
||||
return new Order("Pong", null, false) { IsImmediate = true, TargetString = pingTime };
|
||||
}
|
||||
|
||||
public static Order PauseGame(bool paused)
|
||||
{
|
||||
return new Order("PauseGame", null, false) { TargetString = paused ? "Pause" : "UnPause" };
|
||||
}
|
||||
|
||||
public static Order Command(string text)
|
||||
{
|
||||
return new Order("Command", null, false) { IsImmediate = true, TargetString = text };
|
||||
}
|
||||
|
||||
public static Order StartProduction(Actor subject, int queueID, string item, int count)
|
||||
{
|
||||
return new Order("StartProduction", subject, false) { TargetString = item, ExtraLocation = new CPos(queueID, count) };
|
||||
}
|
||||
|
||||
public static Order PauseProduction(Actor subject, int queueID, string item, bool pause)
|
||||
{
|
||||
return new Order("PauseProduction", subject, false) { TargetString = item, ExtraLocation = new CPos(queueID, pause ? 1 : 0) };
|
||||
}
|
||||
|
||||
public static Order CancelProduction(Actor subject, int queueID, string item, int count)
|
||||
{
|
||||
return new Order("CancelProduction", subject, false) { TargetString = item, ExtraLocation = new CPos(queueID, count) };
|
||||
}
|
||||
|
||||
// For scripting special powers
|
||||
public Order()
|
||||
: this(null, null, null, CPos.Zero, null, false, CPos.Zero, 0) { }
|
||||
@@ -75,7 +180,7 @@ namespace OpenRA
|
||||
|
||||
public byte[] Serialize()
|
||||
{
|
||||
if (IsImmediate) /* chat, whatever */
|
||||
if (IsImmediate)
|
||||
{
|
||||
var ret = new MemoryStream();
|
||||
var w = new BinaryWriter(ret);
|
||||
@@ -126,116 +231,11 @@ namespace OpenRA
|
||||
}
|
||||
}
|
||||
|
||||
public static Order Deserialize(World world, BinaryReader r)
|
||||
{
|
||||
switch (r.ReadByte())
|
||||
{
|
||||
case 0xFF:
|
||||
{
|
||||
var order = r.ReadString();
|
||||
var subjectId = r.ReadUInt32();
|
||||
var flags = (OrderFields)r.ReadByte();
|
||||
|
||||
var targetActorId = flags.HasField(OrderFields.TargetActor) ? r.ReadUInt32() : 0xffffffff;
|
||||
var targetLocation = (CPos)( flags.HasField(OrderFields.TargetLocation) ? r.ReadInt2() : int2.Zero );
|
||||
var targetString = flags.HasField(OrderFields.TargetString) ? r.ReadString() : null;
|
||||
var queued = flags.HasField(OrderFields.Queued);
|
||||
var extraLocation = (CPos)(flags.HasField(OrderFields.ExtraLocation) ? r.ReadInt2() : int2.Zero);
|
||||
var extraData = flags.HasField(OrderFields.ExtraData) ? r.ReadUInt32() : 0;
|
||||
|
||||
Actor subject, targetActor;
|
||||
if (!TryGetActorFromUInt(world, subjectId, out subject) || !TryGetActorFromUInt(world, targetActorId, out targetActor))
|
||||
return null;
|
||||
|
||||
return new Order(order, subject, targetActor, targetLocation, targetString, queued, extraLocation, extraData);
|
||||
}
|
||||
|
||||
case 0xfe:
|
||||
{
|
||||
var name = r.ReadString();
|
||||
var data = r.ReadString();
|
||||
|
||||
return new Order( name, null, false ) { IsImmediate = true, TargetString = data };
|
||||
}
|
||||
|
||||
default:
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return ("OrderString: \"{0}\" \n\t Subject: \"{1}\". \n\t TargetActor: \"{2}\" \n\t TargetLocation: {3}." +
|
||||
"\n\t TargetString: \"{4}\".\n\t IsImmediate: {5}.\n\t Player(PlayerName): {6}\n").F(
|
||||
OrderString, Subject, TargetActor != null ? TargetActor.Info.Name : null, TargetLocation, TargetString, IsImmediate, Player != null ? Player.PlayerName : null);
|
||||
}
|
||||
|
||||
static uint UIntFromActor(Actor a)
|
||||
{
|
||||
if (a == null) return 0xffffffff;
|
||||
return a.ActorID;
|
||||
}
|
||||
|
||||
static bool TryGetActorFromUInt(World world, uint aID, out Actor ret)
|
||||
{
|
||||
if (aID == 0xFFFFFFFF)
|
||||
{
|
||||
ret = null;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var a in world.Actors.Where(x => x.ActorID == aID))
|
||||
{
|
||||
ret = a;
|
||||
return true;
|
||||
}
|
||||
ret = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Named constructors for Orders.
|
||||
// Now that Orders are resolved by individual Actors, these are weird; you unpack orders manually, but not pack them.
|
||||
|
||||
public static Order Chat(bool team, string text)
|
||||
{
|
||||
return new Order(team ? "TeamChat" : "Chat", null, false) { IsImmediate = true, TargetString = text};
|
||||
}
|
||||
|
||||
public static Order HandshakeResponse(string text)
|
||||
{
|
||||
return new Order("HandshakeResponse", null, false) { IsImmediate = true, TargetString = text };
|
||||
}
|
||||
|
||||
public static Order Pong(string pingTime)
|
||||
{
|
||||
return new Order("Pong", null, false) { IsImmediate = true, TargetString = pingTime };
|
||||
}
|
||||
|
||||
public static Order PauseGame(bool paused)
|
||||
{
|
||||
return new Order("PauseGame", null, false) { TargetString = paused ? "Pause" : "UnPause" };
|
||||
}
|
||||
|
||||
public static Order Command(string text)
|
||||
{
|
||||
return new Order("Command", null, false) { IsImmediate = true, TargetString = text };
|
||||
}
|
||||
|
||||
public static Order StartProduction(Actor subject, int queueID, string item, int count)
|
||||
{
|
||||
return new Order("StartProduction", subject, false) { TargetString = item, ExtraLocation = new CPos(queueID, count) };
|
||||
}
|
||||
|
||||
public static Order PauseProduction(Actor subject, int queueID, string item, bool pause)
|
||||
{
|
||||
return new Order("PauseProduction", subject, false) { TargetString = item, ExtraLocation = new CPos(queueID, pause ? 1 : 0) };
|
||||
}
|
||||
|
||||
public static Order CancelProduction(Actor subject, int queueID, string item, int count)
|
||||
{
|
||||
return new Order("CancelProduction", subject, false) { TargetString = item, ExtraLocation = new CPos(queueID, count) };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user