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
{
public readonly TypeDictionary traits = new TypeDictionary();
public readonly UnitInfo unitInfo;
public readonly UnitInfo unitInfo;
public readonly uint ActorID;
public int2 Location;
public Player Owner;
public int Health;
public Actor( string name, int2 location, Player owner )
{
{
ActorID = Game.world.NextAID();
unitInfo = Rules.UnitInfo[ name ];
Location = location;
CenterLocation = new float2( 12, 12 ) + Game.CellSize * (float2)Location;

View File

@@ -11,20 +11,30 @@ namespace OpenRa.Game
{
class Controller
{
public IOrderGenerator orderGenerator;
public IOrderGenerator orderGenerator;
List<Order> recentOrders = new List<Order>();
void ApplyOrders(float2 xy, bool left)
{
var doVoice = null as Actor;
if (orderGenerator != null)
foreach( var order in orderGenerator.Order( xy.ToInt2(), left ) )
{
UnitOrders.ProcessOrder( order );
if( order.Subject != null && order.Player == Game.LocalPlayer )
doVoice = order.Subject;
var doVoice = null as Actor;
if( orderGenerator != null )
foreach( var order in orderGenerator.Order( xy.ToInt2(), left ) )
{
recentOrders.Add( order );
//UnitOrders.ProcessOrder( order );
if( order.Subject != null && order.Player == Game.LocalPlayer )
doVoice = order.Subject;
}
if( doVoice != null )
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 )

View File

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

View File

@@ -2,7 +2,8 @@ using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using OpenRa.Game.Traits;
using OpenRa.Game.Traits;
using System.IO;
namespace OpenRa.Game
{
@@ -23,10 +24,67 @@ namespace OpenRa.Game
this.TargetActor = targetActor;
this.TargetLocation = targetLocation;
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 )
{
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 )
{
return new Order( subject, "PlaceBuilding", null, null, target, buildingName );
}
}
}
}

View File

@@ -13,15 +13,15 @@ namespace OpenRa.Game
int lastTime = Environment.TickCount;
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 Add(IEffect b) { effects.Add(b); }
public void Add(IEffect b) { effects.Add(b); }
public void Remove(IEffect b) { effects.Remove(b); }
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 void ResetTimer()
@@ -32,16 +32,16 @@ namespace OpenRa.Game
public void Update()
{
int t = Environment.TickCount;
int dt = t - lastTime;
if (dt >= timestep)
{
lastTime += timestep;
foreach (var a in actors) a.Tick();
foreach (var e in effects) e.Tick();
Renderer.waterFrame += 0.00125f * timestep;
Game.viewport.Tick();
int dt = t - lastTime;
if (dt >= timestep)
{
lastTime += timestep;
foreach (var a in actors) a.Tick();
foreach (var e in effects) e.Tick();
Renderer.waterFrame += 0.00125f * timestep;
Game.viewport.Tick();
}
foreach (Action<World> a in frameEndActions) a(this);
@@ -49,6 +49,12 @@ namespace OpenRa.Game
}
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++;
}
}
}