BuildUnit order is now in replay
This commit is contained in:
@@ -22,7 +22,6 @@ namespace OpenRa.Game
|
|||||||
foreach (var order in orderGenerator.Order(xy.ToInt2(), left))
|
foreach (var order in orderGenerator.Order(xy.ToInt2(), left))
|
||||||
{
|
{
|
||||||
recentOrders.Add(order);
|
recentOrders.Add(order);
|
||||||
//UnitOrders.ProcessOrder( order );
|
|
||||||
if (order.Subject != null && order.Player == Game.LocalPlayer)
|
if (order.Subject != null && order.Player == Game.LocalPlayer)
|
||||||
doVoice = order.Subject;
|
doVoice = order.Subject;
|
||||||
}
|
}
|
||||||
@@ -30,6 +29,8 @@ namespace OpenRa.Game
|
|||||||
Game.PlaySound(Game.SovietVoices.First.GetNext() + GetVoiceSuffix(doVoice), false);
|
Game.PlaySound(Game.SovietVoices.First.GetNext() + GetVoiceSuffix(doVoice), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void AddOrder(Order o) { recentOrders.Add(o); }
|
||||||
|
|
||||||
public List<Order> GetRecentOrders()
|
public List<Order> GetRecentOrders()
|
||||||
{
|
{
|
||||||
var ret = recentOrders;
|
var ret = recentOrders;
|
||||||
|
|||||||
@@ -253,9 +253,9 @@ namespace OpenRa.Game
|
|||||||
var mobile = unit.traits.Get<Mobile>();
|
var mobile = unit.traits.Get<Mobile>();
|
||||||
mobile.facing = 128;
|
mobile.facing = 128;
|
||||||
mobile.QueueActivity(new Mobile.MoveTo(unit.Location + new int2(0, 3)));
|
mobile.QueueActivity(new Mobile.MoveTo(unit.Location + new int2(0, 3)));
|
||||||
}
|
}
|
||||||
|
|
||||||
world.AddFrameEndTask(_ => world.Add(unit));
|
world.Add(unit);
|
||||||
|
|
||||||
if (producer.traits.Contains<RenderWarFactory>())
|
if (producer.traits.Contains<RenderWarFactory>())
|
||||||
producer.traits.Get<RenderWarFactory>().EjectUnit();
|
producer.traits.Get<RenderWarFactory>().EjectUnit();
|
||||||
|
|||||||
@@ -3,106 +3,111 @@ using System.Collections.Generic;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRa.Game.Traits;
|
using OpenRa.Game.Traits;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
namespace OpenRa.Game
|
namespace OpenRa.Game
|
||||||
{
|
{
|
||||||
sealed class Order
|
sealed class Order
|
||||||
{
|
{
|
||||||
public readonly Player Player;
|
public readonly Player Player;
|
||||||
public readonly string OrderString;
|
public readonly string OrderString;
|
||||||
public readonly Actor Subject;
|
public readonly Actor Subject;
|
||||||
public readonly Actor TargetActor;
|
public readonly Actor TargetActor;
|
||||||
public readonly int2 TargetLocation;
|
public readonly int2 TargetLocation;
|
||||||
public readonly string TargetString;
|
public readonly string TargetString;
|
||||||
|
|
||||||
private Order( Player player, string orderString, Actor subject, Actor targetActor, int2 targetLocation, string targetString )
|
private Order(Player player, string orderString, Actor subject, Actor targetActor, int2 targetLocation, string targetString)
|
||||||
{
|
{
|
||||||
this.Player = player;
|
this.Player = player;
|
||||||
this.OrderString = orderString;
|
this.OrderString = orderString;
|
||||||
this.Subject = subject;
|
this.Subject = subject;
|
||||||
this.TargetActor = targetActor;
|
this.TargetActor = targetActor;
|
||||||
this.TargetLocation = targetLocation;
|
this.TargetLocation = targetLocation;
|
||||||
this.TargetString = targetString;
|
this.TargetString = targetString;
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] Serialize()
|
public byte[] Serialize()
|
||||||
{
|
{
|
||||||
switch( OrderString )
|
switch (OrderString)
|
||||||
{
|
{
|
||||||
// Format:
|
// Format:
|
||||||
// u32 : player, with msb set. (if msb is clear, not an order)
|
// u32 : player, with msb set. (if msb is clear, not an order)
|
||||||
// u8 : orderID.
|
// u8 : orderID.
|
||||||
// 0xFF: Full serialized order.
|
// 0xFF: Full serialized order.
|
||||||
// varies: rest of order.
|
// varies: rest of order.
|
||||||
default:
|
default:
|
||||||
// TODO: specific serializers for specific orders.
|
// TODO: specific serializers for specific orders.
|
||||||
{
|
{
|
||||||
var ret = new MemoryStream();
|
var ret = new MemoryStream();
|
||||||
var w = new BinaryWriter(ret);
|
var w = new BinaryWriter(ret);
|
||||||
w.Write( (uint)Player.Palette | 0x80000000u );
|
w.Write((uint)Player.Palette | 0x80000000u);
|
||||||
w.Write( (byte)0xFF ); //
|
w.Write((byte)0xFF); //
|
||||||
w.Write( OrderString );
|
w.Write(OrderString);
|
||||||
w.Write( Subject == null ? 0xFFFFFFFF : Subject.ActorID );
|
w.Write(Subject == null ? 0xFFFFFFFF : Subject.ActorID);
|
||||||
w.Write( TargetActor == null ? 0xFFFFFFFF : TargetActor.ActorID );
|
w.Write(TargetActor == null ? 0xFFFFFFFF : TargetActor.ActorID);
|
||||||
w.Write( TargetLocation.X );
|
w.Write(TargetLocation.X);
|
||||||
w.Write( TargetLocation.Y );
|
w.Write(TargetLocation.Y);
|
||||||
w.Write( TargetString != null );
|
w.Write(TargetString != null);
|
||||||
if( TargetString != null )
|
if (TargetString != null)
|
||||||
w.Write( TargetString );
|
w.Write(TargetString);
|
||||||
return ret.ToArray();
|
return ret.ToArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Order Deserialize( BinaryReader r, uint first )
|
public static Order Deserialize(BinaryReader r, uint first)
|
||||||
{
|
{
|
||||||
if( ( first >> 31 ) == 0 ) return null;
|
if ((first >> 31) == 0) return null;
|
||||||
|
|
||||||
var player = Game.players.Where( x => x.Value.Palette == (first & 0x7FFFFFFF) ).First().Value;
|
var player = Game.players.Where(x => x.Value.Palette == (first & 0x7FFFFFFF)).First().Value;
|
||||||
switch( r.ReadByte() )
|
switch (r.ReadByte())
|
||||||
{
|
{
|
||||||
case 0xFF:
|
case 0xFF:
|
||||||
{
|
{
|
||||||
var order = r.ReadString();
|
var order = r.ReadString();
|
||||||
var subject = ActorFromUInt( r.ReadUInt32() );
|
var subject = ActorFromUInt(r.ReadUInt32());
|
||||||
var targetActor = ActorFromUInt( r.ReadUInt32() );
|
var targetActor = ActorFromUInt(r.ReadUInt32());
|
||||||
var targetLocation = new int2( r.ReadInt32(), 0 );
|
var targetLocation = new int2(r.ReadInt32(), 0);
|
||||||
targetLocation.Y = r.ReadInt32();
|
targetLocation.Y = r.ReadInt32();
|
||||||
var targetString = null as string;
|
var targetString = null as string;
|
||||||
if( r.ReadBoolean() )
|
if (r.ReadBoolean())
|
||||||
targetString = r.ReadString();
|
targetString = r.ReadString();
|
||||||
return new Order( player, order, subject, targetActor, targetLocation, targetString );
|
return new Order(player, order, subject, targetActor, targetLocation, targetString);
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Actor ActorFromUInt( uint aID )
|
static Actor ActorFromUInt(uint aID)
|
||||||
{
|
{
|
||||||
if( aID == 0xFFFFFFFF ) return null;
|
if (aID == 0xFFFFFFFF) return null;
|
||||||
return Game.world.Actors.Where( x => x.ActorID == aID ).First();
|
return Game.world.Actors.Where(x => x.ActorID == aID).First();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Order Attack( Actor subject, Actor target )
|
public static Order Attack(Actor subject, Actor target)
|
||||||
{
|
{
|
||||||
return new Order( subject.Owner, "Attack", subject, target, int2.Zero, null );
|
return new Order(subject.Owner, "Attack", subject, target, int2.Zero, null);
|
||||||
}
|
|
||||||
|
|
||||||
public static Order Move( Actor subject, int2 target )
|
|
||||||
{
|
|
||||||
return new Order( subject.Owner, "Move", subject, null, target, null );
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Order DeployMcv( Actor subject )
|
|
||||||
{
|
|
||||||
return new Order( subject.Owner, "DeployMcv", subject, null, int2.Zero, null );
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Order PlaceBuilding( Player subject, int2 target, string buildingName )
|
|
||||||
{
|
|
||||||
return new Order( subject, "PlaceBuilding", null, null, target, buildingName );
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public static Order Move(Actor subject, int2 target)
|
||||||
|
{
|
||||||
|
return new Order(subject.Owner, "Move", subject, null, target, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Order DeployMcv(Actor subject)
|
||||||
|
{
|
||||||
|
return new Order(subject.Owner, "DeployMcv", subject, null, int2.Zero, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Order PlaceBuilding(Player subject, int2 target, string buildingName)
|
||||||
|
{
|
||||||
|
return new Order(subject, "PlaceBuilding", null, null, target, buildingName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Order BuildUnit(Player subject, string unitName)
|
||||||
|
{
|
||||||
|
return new Order(subject, "BuildUnit", null, null, int2.Zero, unitName);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,15 +59,14 @@ namespace OpenRa.Game
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void Build(SidebarItem item)
|
public void Build(SidebarItem item)
|
||||||
{
|
{
|
||||||
if (item != null)
|
if (item == null) return;
|
||||||
{
|
|
||||||
if (item.techTreeItem.IsStructure)
|
if (item.techTreeItem.IsStructure)
|
||||||
Game.controller.orderGenerator = new PlaceBuilding(Game.LocalPlayer,
|
Game.controller.orderGenerator = new PlaceBuilding(Game.LocalPlayer,
|
||||||
item.techTreeItem.tag.ToLowerInvariant());
|
item.techTreeItem.tag.ToLowerInvariant());
|
||||||
else
|
else
|
||||||
Game.BuildUnit(Game.LocalPlayer, item.techTreeItem.tag.ToLowerInvariant());
|
Game.controller.AddOrder(Order.BuildUnit(Game.LocalPlayer, item.techTreeItem.tag.ToLowerInvariant()));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoadSprites( string category, string group )
|
void LoadSprites( string category, string group )
|
||||||
|
|||||||
@@ -65,6 +65,11 @@ namespace OpenRa.Game
|
|||||||
} );
|
} );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case "BuildUnit":
|
||||||
|
{
|
||||||
|
Game.world.AddFrameEndTask(_ => Game.BuildUnit( order.Player, order.TargetString ));
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user