Replay stuff.
FYI: Don't try to replay a game where you built any vehicles. It WILL fail horribly.
This commit is contained in:
@@ -16,12 +16,14 @@ namespace OpenRa.Game
|
|||||||
public readonly TypeDictionary traits = new TypeDictionary();
|
public readonly TypeDictionary traits = new TypeDictionary();
|
||||||
public readonly UnitInfo unitInfo;
|
public readonly UnitInfo unitInfo;
|
||||||
|
|
||||||
|
public readonly uint ActorID;
|
||||||
public int2 Location;
|
public int2 Location;
|
||||||
public Player Owner;
|
public Player Owner;
|
||||||
public int Health;
|
public int Health;
|
||||||
|
|
||||||
public Actor( string name, int2 location, Player owner )
|
public Actor( string name, int2 location, Player owner )
|
||||||
{
|
{
|
||||||
|
ActorID = Game.world.NextAID();
|
||||||
unitInfo = Rules.UnitInfo[ name ];
|
unitInfo = Rules.UnitInfo[ name ];
|
||||||
Location = location;
|
Location = location;
|
||||||
CenterLocation = new float2( 12, 12 ) + Game.CellSize * (float2)Location;
|
CenterLocation = new float2( 12, 12 ) + Game.CellSize * (float2)Location;
|
||||||
|
|||||||
@@ -13,13 +13,16 @@ namespace OpenRa.Game
|
|||||||
{
|
{
|
||||||
public IOrderGenerator orderGenerator;
|
public IOrderGenerator orderGenerator;
|
||||||
|
|
||||||
|
List<Order> recentOrders = new List<Order>();
|
||||||
|
|
||||||
void ApplyOrders(float2 xy, bool left)
|
void ApplyOrders(float2 xy, bool left)
|
||||||
{
|
{
|
||||||
var doVoice = null as Actor;
|
var doVoice = null as Actor;
|
||||||
if( orderGenerator != null )
|
if( orderGenerator != null )
|
||||||
foreach( var order in orderGenerator.Order( xy.ToInt2(), left ) )
|
foreach( var order in orderGenerator.Order( xy.ToInt2(), left ) )
|
||||||
{
|
{
|
||||||
UnitOrders.ProcessOrder( 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;
|
||||||
}
|
}
|
||||||
@@ -27,6 +30,13 @@ namespace OpenRa.Game
|
|||||||
Game.PlaySound( Game.SovietVoices.First.GetNext() + GetVoiceSuffix( doVoice ), false );
|
Game.PlaySound( Game.SovietVoices.First.GetNext() + GetVoiceSuffix( doVoice ), false );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Order> GetRecentOrders()
|
||||||
|
{
|
||||||
|
var ret = recentOrders;
|
||||||
|
recentOrders = new List<Order>();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static string GetVoiceSuffix( Actor unit )
|
static string GetVoiceSuffix( Actor unit )
|
||||||
{
|
{
|
||||||
var suffixes = new[] { ".r01", ".r03" };
|
var suffixes = new[] { ".r01", ".r03" };
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ namespace OpenRa.Game
|
|||||||
public static WorldRenderer worldRenderer;
|
public static WorldRenderer worldRenderer;
|
||||||
public static Controller controller;
|
public static Controller controller;
|
||||||
|
|
||||||
|
public static OrderManager orderManager;
|
||||||
|
|
||||||
static int localPlayerIndex;
|
static int localPlayerIndex;
|
||||||
|
|
||||||
public static Dictionary<int, Player> players = new Dictionary<int, Player>();
|
public static Dictionary<int, Player> players = new Dictionary<int, Player>();
|
||||||
@@ -75,6 +77,8 @@ namespace OpenRa.Game
|
|||||||
soundEngine = new ISoundEngine();
|
soundEngine = new ISoundEngine();
|
||||||
sounds = new Cache<string, ISoundSource>(LoadSound);
|
sounds = new Cache<string, ISoundSource>(LoadSound);
|
||||||
|
|
||||||
|
orderManager = new OrderManager( new OrderSource[] { new LocalOrderSource() }, "replay.rep" );
|
||||||
|
|
||||||
PlaySound("intro.aud", false);
|
PlaySound("intro.aud", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,6 +133,8 @@ namespace OpenRa.Game
|
|||||||
UnitInfluence.Tick();
|
UnitInfluence.Tick();
|
||||||
|
|
||||||
viewport.DrawRegions();
|
viewport.DrawRegions();
|
||||||
|
|
||||||
|
orderManager.Tick();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsCellBuildable(int2 a, UnitMovementType umt)
|
public static bool IsCellBuildable(int2 a, UnitMovementType umt)
|
||||||
|
|||||||
@@ -74,6 +74,7 @@
|
|||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="OrderManager.cs" />
|
||||||
<Compile Include="Traits\Activities\DeployMcv.cs" />
|
<Compile Include="Traits\Activities\DeployMcv.cs" />
|
||||||
<Compile Include="Actor.cs" />
|
<Compile Include="Actor.cs" />
|
||||||
<Compile Include="Bullet.cs" />
|
<Compile Include="Bullet.cs" />
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ 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;
|
||||||
|
|
||||||
namespace OpenRa.Game
|
namespace OpenRa.Game
|
||||||
{
|
{
|
||||||
@@ -25,7 +26,64 @@ namespace OpenRa.Game
|
|||||||
this.TargetString = targetString;
|
this.TargetString = targetString;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: serialize / deserialize
|
public byte[] Serialize()
|
||||||
|
{
|
||||||
|
switch( OrderString )
|
||||||
|
{
|
||||||
|
// Format:
|
||||||
|
// u32 : player, with msb set. (if msb is clear, not an order)
|
||||||
|
// u8 : orderID.
|
||||||
|
// 0xFF: Full serialized order.
|
||||||
|
// varies: rest of order.
|
||||||
|
default:
|
||||||
|
// TODO: specific serializers for specific orders.
|
||||||
|
{
|
||||||
|
var ret = new MemoryStream();
|
||||||
|
var w = new BinaryWriter(ret);
|
||||||
|
w.Write( (uint)Player.Palette | 0x80000000u );
|
||||||
|
w.Write( (byte)0xFF ); //
|
||||||
|
w.Write( OrderString );
|
||||||
|
w.Write( Subject == null ? 0xFFFFFFFF : Subject.ActorID );
|
||||||
|
w.Write( TargetActor == null ? 0xFFFFFFFF : TargetActor.ActorID );
|
||||||
|
w.Write( TargetLocation.X );
|
||||||
|
w.Write( TargetLocation.Y );
|
||||||
|
w.Write( TargetString != null );
|
||||||
|
if( TargetString != null )
|
||||||
|
w.Write( TargetString );
|
||||||
|
return ret.ToArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Order Deserialize( BinaryReader r, uint first )
|
||||||
|
{
|
||||||
|
if( ( first >> 31 ) == 0 ) return null;
|
||||||
|
|
||||||
|
var player = Game.players.Where( x => x.Value.Palette == (first & 0x7FFFFFFF) ).First().Value;
|
||||||
|
switch( r.ReadByte() )
|
||||||
|
{
|
||||||
|
case 0xFF:
|
||||||
|
{
|
||||||
|
var order = r.ReadString();
|
||||||
|
var subject = ActorFromUInt( r.ReadUInt32() );
|
||||||
|
var targetActor = ActorFromUInt( r.ReadUInt32() );
|
||||||
|
var targetLocation = new int2( r.ReadInt32(), 0 );
|
||||||
|
targetLocation.Y = r.ReadInt32();
|
||||||
|
var targetString = null as string;
|
||||||
|
if( r.ReadBoolean() )
|
||||||
|
targetString = r.ReadString();
|
||||||
|
return new Order( player, order, subject, targetActor, targetLocation, targetString );
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static Actor ActorFromUInt( uint aID )
|
||||||
|
{
|
||||||
|
if( aID == 0xFFFFFFFF ) return null;
|
||||||
|
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 )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -50,5 +50,11 @@ namespace OpenRa.Game
|
|||||||
|
|
||||||
public IEnumerable<Actor> Actors { get { return actors; } }
|
public IEnumerable<Actor> Actors { get { return actors; } }
|
||||||
public IEnumerable<IEffect> Effects { get { return effects; } }
|
public IEnumerable<IEffect> Effects { get { return effects; } }
|
||||||
|
|
||||||
|
uint nextAID = 0;
|
||||||
|
internal uint NextAID()
|
||||||
|
{
|
||||||
|
return nextAID++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user