Replay stuff.

FYI: Don't try to replay a game where you built any vehicles. It WILL fail horribly.
This commit is contained in:
Bob
2009-10-29 01:57:47 +13:00
parent 7c5fc4aa76
commit 89f9a96de5
6 changed files with 308 additions and 225 deletions

View File

@@ -14,14 +14,16 @@ namespace OpenRa.Game
class Actor class Actor
{ {
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;

View File

@@ -11,20 +11,30 @@ namespace OpenRa.Game
{ {
class Controller class Controller
{ {
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 );
if( order.Subject != null && order.Player == Game.LocalPlayer ) //UnitOrders.ProcessOrder( order );
doVoice = order.Subject; if( order.Subject != null && order.Player == Game.LocalPlayer )
doVoice = order.Subject;
} }
if( doVoice != null ) if( doVoice != null )
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 )

View File

@@ -25,7 +25,9 @@ namespace OpenRa.Game
public static PathFinder PathFinder; public static PathFinder PathFinder;
public static Network network; public static Network network;
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;
@@ -73,7 +75,9 @@ namespace OpenRa.Game
worldRenderer = new WorldRenderer(renderer); worldRenderer = new WorldRenderer(renderer);
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);
} }
@@ -128,7 +132,9 @@ namespace OpenRa.Game
world.Update(); world.Update();
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)

View File

@@ -1,197 +1,198 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5"> <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup> <PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion> <ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion> <SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{0DFB103F-2962-400F-8C6D-E2C28CCBA633}</ProjectGuid> <ProjectGuid>{0DFB103F-2962-400F-8C6D-E2C28CCBA633}</ProjectGuid>
<OutputType>WinExe</OutputType> <OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>OpenRa.Game</RootNamespace> <RootNamespace>OpenRa.Game</RootNamespace>
<AssemblyName>OpenRa.Game</AssemblyName> <AssemblyName>OpenRa.Game</AssemblyName>
<FileUpgradeFlags> <FileUpgradeFlags>
</FileUpgradeFlags> </FileUpgradeFlags>
<OldToolsVersion>2.0</OldToolsVersion> <OldToolsVersion>2.0</OldToolsVersion>
<UpgradeBackupLocation> <UpgradeBackupLocation>
</UpgradeBackupLocation> </UpgradeBackupLocation>
<PublishUrl>publish\</PublishUrl> <PublishUrl>publish\</PublishUrl>
<Install>true</Install> <Install>true</Install>
<InstallFrom>Disk</InstallFrom> <InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled> <UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode> <UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval> <UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits> <UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically> <UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired> <UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions> <MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision> <ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion> <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper> <IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust> <UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled> <BootstrapperEnabled>true</BootstrapperEnabled>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion> <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath> <OutputPath>bin\x86\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants> <DefineConstants>DEBUG;TRACE</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DebugType>full</DebugType> <DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget> <PlatformTarget>x86</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess> <UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<OutputPath>bin\x86\Release\</OutputPath> <OutputPath>bin\x86\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants> <DefineConstants>TRACE</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Optimize>true</Optimize> <Optimize>true</Optimize>
<DebugType>pdbonly</DebugType> <DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget> <PlatformTarget>x86</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess> <UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Ijw.DirectX, Version=0.0.0.0, Culture=neutral, processorArchitecture=x86"> <Reference Include="Ijw.DirectX, Version=0.0.0.0, Culture=neutral, processorArchitecture=x86">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\Ijw.DirectX\Release\Ijw.DirectX.dll</HintPath> <HintPath>..\Ijw.DirectX\Release\Ijw.DirectX.dll</HintPath>
</Reference> </Reference>
<Reference Include="IjwFramework, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="IjwFramework, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\Ijw.DirectX\Ijw.Framework\IjwFramework\bin\Debug\IjwFramework.dll</HintPath> <HintPath>..\Ijw.DirectX\Ijw.Framework\IjwFramework\bin\Debug\IjwFramework.dll</HintPath>
</Reference> </Reference>
<Reference Include="irrKlang.NET2.0, Version=1.1.3.0, Culture=neutral, PublicKeyToken=a854741bd80517c7, processorArchitecture=x86"> <Reference Include="irrKlang.NET2.0, Version=1.1.3.0, Culture=neutral, PublicKeyToken=a854741bd80517c7, processorArchitecture=x86">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\thirdparty\irrKlang.NET2.0.dll</HintPath> <HintPath>..\thirdparty\irrKlang.NET2.0.dll</HintPath>
</Reference> </Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core"> <Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework> <RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference> </Reference>
<Reference Include="System.Data" /> <Reference Include="System.Data" />
<Reference Include="System.Drawing" /> <Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" /> <Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Traits\Activities\DeployMcv.cs" /> <Compile Include="OrderManager.cs" />
<Compile Include="Actor.cs" /> <Compile Include="Traits\Activities\DeployMcv.cs" />
<Compile Include="Bullet.cs" /> <Compile Include="Actor.cs" />
<Compile Include="Controller.cs" /> <Compile Include="Bullet.cs" />
<Compile Include="Cursor.cs" /> <Compile Include="Controller.cs" />
<Compile Include="Explosion.cs" /> <Compile Include="Cursor.cs" />
<Compile Include="GameRules\FieldLoader.cs" /> <Compile Include="Explosion.cs" />
<Compile Include="GameRules\Footprint.cs" /> <Compile Include="GameRules\FieldLoader.cs" />
<Compile Include="GameRules\InfoLoader.cs" /> <Compile Include="GameRules\Footprint.cs" />
<Compile Include="GameRules\ProjectileInfo.cs" /> <Compile Include="GameRules\InfoLoader.cs" />
<Compile Include="GameRules\Rules.cs" /> <Compile Include="GameRules\ProjectileInfo.cs" />
<Compile Include="GameRules\UnitInfo.cs" /> <Compile Include="GameRules\Rules.cs" />
<Compile Include="GameRules\WarheadInfo.cs" /> <Compile Include="GameRules\UnitInfo.cs" />
<Compile Include="GameRules\WeaponInfo.cs" /> <Compile Include="GameRules\WarheadInfo.cs" />
<Compile Include="Graphics\Animation.cs" /> <Compile Include="GameRules\WeaponInfo.cs" />
<Compile Include="Game.cs" /> <Compile Include="Graphics\Animation.cs" />
<Compile Include="Graphics\CursorSequence.cs" /> <Compile Include="Game.cs" />
<Compile Include="Graphics\CursorSheetBuilder.cs" /> <Compile Include="Graphics\CursorSequence.cs" />
<Compile Include="Graphics\LineRenderer.cs" /> <Compile Include="Graphics\CursorSheetBuilder.cs" />
<Compile Include="Graphics\OverlayRenderer.cs" /> <Compile Include="Graphics\LineRenderer.cs" />
<Compile Include="Graphics\WorldRenderer.cs" /> <Compile Include="Graphics\OverlayRenderer.cs" />
<Compile Include="BuildingInfluenceMap.cs" /> <Compile Include="Graphics\WorldRenderer.cs" />
<Compile Include="IOrderGenerator.cs" /> <Compile Include="BuildingInfluenceMap.cs" />
<Compile Include="PlaceBuilding.cs" /> <Compile Include="IOrderGenerator.cs" />
<Compile Include="TechTree\Item.cs" /> <Compile Include="PlaceBuilding.cs" />
<Compile Include="Network\Packet.cs" /> <Compile Include="TechTree\Item.cs" />
<Compile Include="Player.cs" /> <Compile Include="Network\Packet.cs" />
<Compile Include="Race.cs" /> <Compile Include="Player.cs" />
<Compile Include="Support\SharedResources.cs" /> <Compile Include="Race.cs" />
<Compile Include="Graphics\Sheet.cs" /> <Compile Include="Support\SharedResources.cs" />
<Compile Include="Support\Log.cs" /> <Compile Include="Graphics\Sheet.cs" />
<Compile Include="Network\Network.cs" /> <Compile Include="Support\Log.cs" />
<Compile Include="PathFinder.cs" /> <Compile Include="Network\Network.cs" />
<Compile Include="Graphics\Sequence.cs" /> <Compile Include="PathFinder.cs" />
<Compile Include="Order.cs" /> <Compile Include="Graphics\Sequence.cs" />
<Compile Include="Graphics\Region.cs" /> <Compile Include="Order.cs" />
<Compile Include="Graphics\SequenceProvider.cs" /> <Compile Include="Graphics\Region.cs" />
<Compile Include="Graphics\SheetBuilder.cs" /> <Compile Include="Graphics\SequenceProvider.cs" />
<Compile Include="Graphics\HardwarePalette.cs" /> <Compile Include="Graphics\SheetBuilder.cs" />
<Compile Include="MainWindow.cs"> <Compile Include="Graphics\HardwarePalette.cs" />
<SubType>Form</SubType> <Compile Include="MainWindow.cs">
</Compile> <SubType>Form</SubType>
<Compile Include="Support\Program.cs" /> </Compile>
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Support\Program.cs" />
<Compile Include="Graphics\Renderer.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Support\Settings.cs" /> <Compile Include="Graphics\Renderer.cs" />
<Compile Include="Sidebar.cs" /> <Compile Include="Support\Settings.cs" />
<Compile Include="SidebarItem.cs" /> <Compile Include="Sidebar.cs" />
<Compile Include="Graphics\Sprite.cs" /> <Compile Include="SidebarItem.cs" />
<Compile Include="Graphics\SpriteRenderer.cs" /> <Compile Include="Graphics\Sprite.cs" />
<Compile Include="Graphics\SpriteSheetBuilder.cs" /> <Compile Include="Graphics\SpriteRenderer.cs" />
<Compile Include="TechTree\TechTree.cs" /> <Compile Include="Graphics\SpriteSheetBuilder.cs" />
<Compile Include="TerrainCosts.cs" /> <Compile Include="TechTree\TechTree.cs" />
<Compile Include="Graphics\TerrainRenderer.cs" /> <Compile Include="TerrainCosts.cs" />
<Compile Include="Graphics\TreeCache.cs" /> <Compile Include="Graphics\TerrainRenderer.cs" />
<Compile Include="Traits\AttackTurreted.cs" /> <Compile Include="Graphics\TreeCache.cs" />
<Compile Include="Traits\Building.cs" /> <Compile Include="Traits\AttackTurreted.cs" />
<Compile Include="Traits\McvDeploy.cs" /> <Compile Include="Traits\Building.cs" />
<Compile Include="Traits\Mobile.cs" /> <Compile Include="Traits\McvDeploy.cs" />
<Compile Include="Traits\RenderBuilding.cs" /> <Compile Include="Traits\Mobile.cs" />
<Compile Include="Traits\RenderBuildingOre.cs" /> <Compile Include="Traits\RenderBuilding.cs" />
<Compile Include="Traits\RenderBuildingTurreted.cs" /> <Compile Include="Traits\RenderBuildingOre.cs" />
<Compile Include="Traits\RenderBuildingWarFactory.cs" /> <Compile Include="Traits\RenderBuildingTurreted.cs" />
<Compile Include="Traits\RenderSimple.cs" /> <Compile Include="Traits\RenderBuildingWarFactory.cs" />
<Compile Include="Traits\RenderUnit.cs" /> <Compile Include="Traits\RenderSimple.cs" />
<Compile Include="Traits\RenderUnitTurreted.cs" /> <Compile Include="Traits\RenderUnit.cs" />
<Compile Include="Traits\TraitsInterfaces.cs" /> <Compile Include="Traits\RenderUnitTurreted.cs" />
<Compile Include="Traits\Tree.cs" /> <Compile Include="Traits\TraitsInterfaces.cs" />
<Compile Include="Traits\Turreted.cs" /> <Compile Include="Traits\Tree.cs" />
<Compile Include="UnitOrders.cs" /> <Compile Include="Traits\Turreted.cs" />
<Compile Include="Traits\Util.cs" /> <Compile Include="UnitOrders.cs" />
<Compile Include="UiOverlay.cs" /> <Compile Include="Traits\Util.cs" />
<Compile Include="Graphics\UnitSheetBuilder.cs" /> <Compile Include="UiOverlay.cs" />
<Compile Include="Graphics\Util.cs" /> <Compile Include="Graphics\UnitSheetBuilder.cs" />
<Compile Include="Graphics\Vertex.cs" /> <Compile Include="Graphics\Util.cs" />
<Compile Include="Graphics\Viewport.cs" /> <Compile Include="Graphics\Vertex.cs" />
<Compile Include="UnitInfluenceMap.cs" /> <Compile Include="Graphics\Viewport.cs" />
<Compile Include="UnitOrderGenerator.cs" /> <Compile Include="UnitInfluenceMap.cs" />
<Compile Include="VoicePool.cs" /> <Compile Include="UnitOrderGenerator.cs" />
<Compile Include="World.cs" /> <Compile Include="VoicePool.cs" />
</ItemGroup> <Compile Include="World.cs" />
<ItemGroup> </ItemGroup>
<ProjectReference Include="..\OpenRa.DataStructures\OpenRa.DataStructures.csproj"> <ItemGroup>
<Project>{2F9E7A23-56C0-4286-9C8E-1060A9B2F073}</Project> <ProjectReference Include="..\OpenRa.DataStructures\OpenRa.DataStructures.csproj">
<Name>OpenRa.DataStructures</Name> <Project>{2F9E7A23-56C0-4286-9C8E-1060A9B2F073}</Project>
</ProjectReference> <Name>OpenRa.DataStructures</Name>
<ProjectReference Include="..\OpenRa.FileFormats\OpenRa.FileFormats.csproj"> </ProjectReference>
<Project>{BDAEAB25-991E-46A7-AF1E-4F0E03358DAA}</Project> <ProjectReference Include="..\OpenRa.FileFormats\OpenRa.FileFormats.csproj">
<Name>OpenRa.FileFormats</Name> <Project>{BDAEAB25-991E-46A7-AF1E-4F0E03358DAA}</Project>
</ProjectReference> <Name>OpenRa.FileFormats</Name>
</ItemGroup> </ProjectReference>
<ItemGroup> </ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Framework.2.0"> <ItemGroup>
<Visible>False</Visible> <BootstrapperPackage Include="Microsoft.Net.Framework.2.0">
<ProductName>.NET Framework 2.0 %28x86%29</ProductName> <Visible>False</Visible>
<Install>true</Install> <ProductName>.NET Framework 2.0 %28x86%29</ProductName>
</BootstrapperPackage> <Install>true</Install>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.0"> </BootstrapperPackage>
<Visible>False</Visible> <BootstrapperPackage Include="Microsoft.Net.Framework.3.0">
<ProductName>.NET Framework 3.0 %28x86%29</ProductName> <Visible>False</Visible>
<Install>false</Install> <ProductName>.NET Framework 3.0 %28x86%29</ProductName>
</BootstrapperPackage> <Install>false</Install>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5"> </BootstrapperPackage>
<Visible>False</Visible> <BootstrapperPackage Include="Microsoft.Net.Framework.3.5">
<ProductName>.NET Framework 3.5</ProductName> <Visible>False</Visible>
<Install>false</Install> <ProductName>.NET Framework 3.5</ProductName>
</BootstrapperPackage> <Install>false</Install>
</ItemGroup> </BootstrapperPackage>
<ItemGroup> </ItemGroup>
<None Include="Game Code.cd" /> <ItemGroup>
<None Include="Graphics\Graphics.cd" /> <None Include="Game Code.cd" />
</ItemGroup> <None Include="Graphics\Graphics.cd" />
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild"> <Target Name="BeforeBuild">
</Target> </Target>
<Target Name="AfterBuild"> <Target Name="AfterBuild">
</Target> </Target>
--> -->
</Project> </Project>

View File

@@ -2,7 +2,8 @@ using System;
using System.Collections.Generic; 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
{ {
@@ -23,10 +24,67 @@ namespace OpenRa.Game
this.TargetActor = targetActor; this.TargetActor = targetActor;
this.TargetLocation = targetLocation; this.TargetLocation = targetLocation;
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 )
{ {
return new Order( subject.Owner, "Attack", subject, target, int2.Zero, null ); return new Order( subject.Owner, "Attack", subject, target, int2.Zero, null );
@@ -45,6 +103,6 @@ namespace OpenRa.Game
public static Order PlaceBuilding( Player subject, int2 target, string buildingName ) public static Order PlaceBuilding( Player subject, int2 target, string buildingName )
{ {
return new Order( subject, "PlaceBuilding", null, null, target, buildingName ); return new Order( subject, "PlaceBuilding", null, null, target, buildingName );
} }
} }
} }

View File

@@ -13,15 +13,15 @@ namespace OpenRa.Game
int lastTime = Environment.TickCount; int lastTime = Environment.TickCount;
const int timestep = 40; const int timestep = 40;
public void Add(Actor a) { actors.Add(a); ActorAdded(a); } public void Add(Actor a) { actors.Add(a); ActorAdded(a); }
public void Remove(Actor a) { actors.Remove(a); ActorRemoved(a); } public void Remove(Actor a) { actors.Remove(a); ActorRemoved(a); }
public void Add(IEffect b) { effects.Add(b); } public void Add(IEffect b) { effects.Add(b); }
public void Remove(IEffect b) { effects.Remove(b); } public void Remove(IEffect b) { effects.Remove(b); }
public void AddFrameEndTask( Action<World> a ) { frameEndActions.Add( a ); } public void AddFrameEndTask( Action<World> a ) { frameEndActions.Add( a ); }
public event Action<Actor> ActorAdded = _ => { }; public event Action<Actor> ActorAdded = _ => { };
public event Action<Actor> ActorRemoved = a => { a.Health = 0; }; /* make sure everyone sees it as dead */ public event Action<Actor> ActorRemoved = a => { a.Health = 0; }; /* make sure everyone sees it as dead */
public void ResetTimer() public void ResetTimer()
@@ -32,16 +32,16 @@ namespace OpenRa.Game
public void Update() public void Update()
{ {
int t = Environment.TickCount; int t = Environment.TickCount;
int dt = t - lastTime; int dt = t - lastTime;
if (dt >= timestep) if (dt >= timestep)
{ {
lastTime += timestep; lastTime += timestep;
foreach (var a in actors) a.Tick(); foreach (var a in actors) a.Tick();
foreach (var e in effects) e.Tick(); foreach (var e in effects) e.Tick();
Renderer.waterFrame += 0.00125f * timestep; Renderer.waterFrame += 0.00125f * timestep;
Game.viewport.Tick(); Game.viewport.Tick();
} }
foreach (Action<World> a in frameEndActions) a(this); foreach (Action<World> a in frameEndActions) a(this);
@@ -49,6 +49,12 @@ 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++;
}
} }
} }