shuffling
This commit is contained in:
11
OpenRa.Game/Orders/IOrderGenerator.cs
Normal file
11
OpenRa.Game/Orders/IOrderGenerator.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace OpenRa.Game
|
||||
{
|
||||
interface IOrderGenerator
|
||||
{
|
||||
IEnumerable<Order> Order( int2 xy, MouseInput mi );
|
||||
void Tick();
|
||||
void Render();
|
||||
}
|
||||
}
|
||||
11
OpenRa.Game/Orders/IOrderSource.cs
Normal file
11
OpenRa.Game/Orders/IOrderSource.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace OpenRa.Game.Orders
|
||||
{
|
||||
interface IOrderSource
|
||||
{
|
||||
void SendLocalOrders(int localFrame, List<Order> localOrders);
|
||||
List<Order> OrdersForFrame(int currentFrame);
|
||||
bool IsReadyForFrame(int frameNumber);
|
||||
}
|
||||
}
|
||||
30
OpenRa.Game/Orders/LocalOrderSource.cs
Normal file
30
OpenRa.Game/Orders/LocalOrderSource.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace OpenRa.Game.Orders
|
||||
{
|
||||
class LocalOrderSource : IOrderSource
|
||||
{
|
||||
Dictionary<int, List<Order>> orders = new Dictionary<int, List<Order>>();
|
||||
|
||||
public List<Order> OrdersForFrame(int currentFrame)
|
||||
{
|
||||
if (!orders.ContainsKey(currentFrame))
|
||||
return new List<Order>();
|
||||
|
||||
var result = orders[currentFrame];
|
||||
orders.Remove(currentFrame);
|
||||
return result;
|
||||
}
|
||||
|
||||
public void SendLocalOrders(int localFrame, List<Order> localOrders)
|
||||
{
|
||||
if (localFrame == 0) return;
|
||||
orders[localFrame] = localOrders;
|
||||
}
|
||||
|
||||
public bool IsReadyForFrame(int frameNumber)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
78
OpenRa.Game/Orders/NetworkOrderSource.cs
Normal file
78
OpenRa.Game/Orders/NetworkOrderSource.cs
Normal file
@@ -0,0 +1,78 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.Sockets;
|
||||
using System.Threading;
|
||||
|
||||
namespace OpenRa.Game.Orders
|
||||
{
|
||||
class NetworkOrderSource : IOrderSource
|
||||
{
|
||||
TcpClient socket;
|
||||
|
||||
Dictionary<int, List<byte[]>> orderBuffers = new Dictionary<int, List<byte[]>>();
|
||||
Dictionary<int, bool> gotEverything = new Dictionary<int, bool>();
|
||||
|
||||
public NetworkOrderSource(TcpClient socket)
|
||||
{
|
||||
this.socket = socket;
|
||||
this.socket.NoDelay = true;
|
||||
var reader = new BinaryReader(socket.GetStream());
|
||||
|
||||
new Thread(() =>
|
||||
{
|
||||
for (; ; )
|
||||
{
|
||||
var len = reader.ReadInt32();
|
||||
var frame = reader.ReadInt32();
|
||||
var buf = reader.ReadBytes(len - 4);
|
||||
|
||||
lock (orderBuffers)
|
||||
{
|
||||
if (len == 5 && buf[0] == 0xef) /* got everything marker */
|
||||
gotEverything[frame] = true;
|
||||
else
|
||||
{
|
||||
/* accumulate this chunk */
|
||||
if (!orderBuffers.ContainsKey(frame))
|
||||
orderBuffers[frame] = new List<byte[]> { buf };
|
||||
else
|
||||
orderBuffers[frame].Add(buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
}) { IsBackground = true }.Start();
|
||||
}
|
||||
|
||||
static List<byte[]> NoOrders = new List<byte[]>();
|
||||
List<byte[]> ExtractOrders(int frame)
|
||||
{
|
||||
lock (orderBuffers)
|
||||
{
|
||||
List<byte[]> result;
|
||||
if (!orderBuffers.TryGetValue(frame, out result))
|
||||
result = NoOrders;
|
||||
orderBuffers.Remove(frame);
|
||||
gotEverything.Remove(frame);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public List<Order> OrdersForFrame(int currentFrame)
|
||||
{
|
||||
var orderData = ExtractOrders(currentFrame);
|
||||
return orderData.SelectMany(a => a.ToOrderList()).ToList();
|
||||
}
|
||||
|
||||
public void SendLocalOrders(int localFrame, List<Order> localOrders)
|
||||
{
|
||||
socket.GetStream().WriteFrameData(localOrders, localFrame);
|
||||
}
|
||||
|
||||
public bool IsReadyForFrame(int frameNumber)
|
||||
{
|
||||
lock (orderBuffers)
|
||||
return gotEverything.ContainsKey(frameNumber);
|
||||
}
|
||||
}
|
||||
}
|
||||
157
OpenRa.Game/Orders/Order.cs
Normal file
157
OpenRa.Game/Orders/Order.cs
Normal file
@@ -0,0 +1,157 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace OpenRa.Game
|
||||
{
|
||||
sealed class Order
|
||||
{
|
||||
public readonly string OrderString;
|
||||
readonly uint SubjectId;
|
||||
readonly uint TargetActorId;
|
||||
public readonly int2 TargetLocation;
|
||||
public readonly string TargetString;
|
||||
public bool IsImmediate;
|
||||
|
||||
public Actor Subject { get { return ActorFromUInt(SubjectId); } }
|
||||
public Actor TargetActor { get { return ActorFromUInt(TargetActorId); } }
|
||||
public Player Player { get { return Subject.Owner; } }
|
||||
|
||||
public Order(string orderString, Actor subject,
|
||||
Actor targetActor, int2 targetLocation, string targetString)
|
||||
: this( orderString, UIntFromActor( subject ),
|
||||
UIntFromActor( targetActor ), targetLocation, targetString ) {}
|
||||
|
||||
Order(string orderString, uint subjectId,
|
||||
uint targetActorId, int2 targetLocation, string targetString)
|
||||
{
|
||||
this.OrderString = orderString;
|
||||
this.SubjectId = subjectId;
|
||||
this.TargetActorId = targetActorId;
|
||||
this.TargetLocation = targetLocation;
|
||||
this.TargetString = targetString;
|
||||
}
|
||||
|
||||
public bool Validate()
|
||||
{
|
||||
if ((SubjectId != 0xffffffff) && Subject == null)
|
||||
return false;
|
||||
if ((TargetActorId != 0xffffffff) && TargetActor == null)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public byte[] Serialize()
|
||||
{
|
||||
if (IsImmediate) /* chat, whatever */
|
||||
{
|
||||
var ret = new MemoryStream();
|
||||
var w = new BinaryWriter(ret);
|
||||
w.Write((byte)0xfe);
|
||||
w.Write((uint)Player.Index);
|
||||
w.Write(OrderString);
|
||||
w.Write(TargetString);
|
||||
return ret.ToArray();
|
||||
}
|
||||
|
||||
switch (OrderString)
|
||||
{
|
||||
// Format:
|
||||
// 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( (byte)0xFF );
|
||||
w.Write(OrderString);
|
||||
w.Write(SubjectId);
|
||||
w.Write(TargetActorId);
|
||||
w.Write(TargetLocation.X);
|
||||
w.Write(TargetLocation.Y);
|
||||
w.Write(TargetString != null);
|
||||
if (TargetString != null)
|
||||
w.Write(TargetString);
|
||||
return ret.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static Player LookupPlayer(uint index)
|
||||
{
|
||||
return Game.players
|
||||
.Where(x => x.Value.Index == index)
|
||||
.First().Value;
|
||||
}
|
||||
|
||||
public static Order Deserialize(BinaryReader r)
|
||||
{
|
||||
switch (r.ReadByte())
|
||||
{
|
||||
case 0xFF:
|
||||
{
|
||||
var order = r.ReadString();
|
||||
var subjectId = r.ReadUInt32();
|
||||
var targetActorId = 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( order, subjectId, targetActorId, targetLocation, targetString);
|
||||
}
|
||||
|
||||
case 0xfe:
|
||||
{
|
||||
var playerID = r.ReadUInt32();
|
||||
var name = r.ReadString();
|
||||
var data = r.ReadString();
|
||||
|
||||
return new Order( name, LookupPlayer( playerID ).PlayerActor, null, int2.Zero, data ) { IsImmediate = true };
|
||||
}
|
||||
|
||||
default:
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
static uint UIntFromActor(Actor a)
|
||||
{
|
||||
if (a == null) return 0xffffffff;
|
||||
return a.ActorID;
|
||||
}
|
||||
|
||||
static Actor ActorFromUInt(uint aID)
|
||||
{
|
||||
if (aID == 0xFFFFFFFF) return null;
|
||||
return Game.world.Actors.SingleOrDefault(x => x.ActorID == aID);
|
||||
}
|
||||
|
||||
// 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(Player subject, string text)
|
||||
{
|
||||
return new Order("Chat", subject.PlayerActor, null, int2.Zero, text)
|
||||
{ IsImmediate = true };
|
||||
}
|
||||
|
||||
public static Order StartProduction(Player subject, string item)
|
||||
{
|
||||
return new Order("StartProduction", subject.PlayerActor, null, int2.Zero, item );
|
||||
}
|
||||
|
||||
public static Order PauseProduction(Player subject, string item, bool pause)
|
||||
{
|
||||
return new Order("PauseProduction", subject.PlayerActor, null, new int2( pause ? 1 : 0, 0 ), item);
|
||||
}
|
||||
|
||||
public static Order CancelProduction(Player subject, string item)
|
||||
{
|
||||
return new Order("CancelProduction", subject.PlayerActor, null, int2.Zero, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
35
OpenRa.Game/Orders/OrderIO.cs
Normal file
35
OpenRa.Game/Orders/OrderIO.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace OpenRa.Game.Orders
|
||||
{
|
||||
static class OrderIO
|
||||
{
|
||||
static void Write(this Stream s, byte[] buf)
|
||||
{
|
||||
s.Write(buf, 0, buf.Length);
|
||||
}
|
||||
|
||||
public static void WriteFrameData(this Stream s, IEnumerable<Order> orders, int frameNumber)
|
||||
{
|
||||
var ms = new MemoryStream();
|
||||
ms.Write(BitConverter.GetBytes(frameNumber));
|
||||
foreach (var order in orders)
|
||||
ms.Write(order.Serialize());
|
||||
|
||||
s.Write(BitConverter.GetBytes((int)ms.Length));
|
||||
ms.WriteTo(s);
|
||||
}
|
||||
|
||||
public static List<Order> ToOrderList(this byte[] bytes)
|
||||
{
|
||||
var ms = new MemoryStream(bytes);
|
||||
var reader = new BinaryReader(ms);
|
||||
var ret = new List<Order>();
|
||||
while (ms.Position < ms.Length)
|
||||
ret.Add(Order.Deserialize(reader));
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
96
OpenRa.Game/Orders/OrderManager.cs
Normal file
96
OpenRa.Game/Orders/OrderManager.cs
Normal file
@@ -0,0 +1,96 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace OpenRa.Game.Orders
|
||||
{
|
||||
class OrderManager
|
||||
{
|
||||
Stream savingReplay;
|
||||
List<IOrderSource> sources;
|
||||
int frameNumber = 0;
|
||||
|
||||
public int FramesAhead = 3;
|
||||
|
||||
public bool GameStarted { get { return frameNumber != 0; } }
|
||||
public bool IsNetplay { get { return sources.OfType<NetworkOrderSource>().Any(); } }
|
||||
|
||||
public void StartGame()
|
||||
{
|
||||
if (GameStarted) return;
|
||||
|
||||
frameNumber = 1;
|
||||
foreach (var p in this.sources)
|
||||
for (int i = frameNumber; i <= FramesAhead; i++)
|
||||
p.SendLocalOrders(i, new List<Order>());
|
||||
}
|
||||
|
||||
public int FrameNumber { get { return frameNumber; } }
|
||||
|
||||
public OrderManager( IEnumerable<IOrderSource> sources )
|
||||
{
|
||||
this.sources = sources.ToList();
|
||||
if (!IsNetplay)
|
||||
StartGame();
|
||||
}
|
||||
|
||||
public OrderManager( IEnumerable<IOrderSource> sources, string replayFilename )
|
||||
: this( sources )
|
||||
{
|
||||
savingReplay = new FileStream( replayFilename, FileMode.Create );
|
||||
}
|
||||
|
||||
public bool IsReadyForNextFrame
|
||||
{
|
||||
get
|
||||
{
|
||||
foreach( var p in sources )
|
||||
if( !p.IsReadyForFrame( frameNumber ) )
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void ProcessOrders(int frame, bool save)
|
||||
{
|
||||
var orders = sources
|
||||
.SelectMany(s => s.OrdersForFrame(frame))
|
||||
.Where(o => o.Validate()) /* drop bogus things */
|
||||
.OrderBy(o => o.Player.Index)
|
||||
.ToList();
|
||||
|
||||
foreach (var o in orders)
|
||||
UnitOrders.ProcessOrder(o);
|
||||
|
||||
if (save && savingReplay != null)
|
||||
savingReplay.WriteFrameData(orders, frame);
|
||||
}
|
||||
|
||||
public void TickImmediate()
|
||||
{
|
||||
var localOrders = Game.controller.GetRecentOrders(true);
|
||||
if (localOrders.Count > 0)
|
||||
foreach (var p in sources)
|
||||
p.SendLocalOrders(0, localOrders);
|
||||
|
||||
ProcessOrders(0, false);
|
||||
}
|
||||
|
||||
public void Tick()
|
||||
{
|
||||
var localOrders = Game.controller.GetRecentOrders(false);
|
||||
|
||||
foreach( var p in sources )
|
||||
p.SendLocalOrders( frameNumber + FramesAhead, localOrders );
|
||||
|
||||
ProcessOrders(frameNumber, true);
|
||||
|
||||
++frameNumber;
|
||||
|
||||
// sanity check on the framenumber. This is 2^31 frames maximum, or multiple *years* at 40ms/frame.
|
||||
if( ( frameNumber & 0x80000000 ) != 0 )
|
||||
throw new InvalidOperationException( "(OrderManager) Frame number too large" );
|
||||
}
|
||||
}
|
||||
}
|
||||
53
OpenRa.Game/Orders/PlaceBuildingOrderGenerator.cs
Normal file
53
OpenRa.Game/Orders/PlaceBuildingOrderGenerator.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using System.Collections.Generic;
|
||||
using OpenRa.Game.GameRules;
|
||||
|
||||
namespace OpenRa.Game.Orders
|
||||
{
|
||||
class PlaceBuildingOrderGenerator : IOrderGenerator
|
||||
{
|
||||
readonly Actor Producer;
|
||||
readonly BuildingInfo Building;
|
||||
|
||||
public PlaceBuildingOrderGenerator(Actor producer, string name)
|
||||
{
|
||||
Producer = producer;
|
||||
Building = (BuildingInfo)Rules.UnitInfo[ name ];
|
||||
}
|
||||
|
||||
public IEnumerable<Order> Order(int2 xy, MouseInput mi)
|
||||
{
|
||||
if( mi.Button == MouseButton.Left )
|
||||
{
|
||||
if (!Game.CanPlaceBuilding(Building, xy, null, true))
|
||||
{
|
||||
Sound.Play("nodeply1.aud");
|
||||
yield break;
|
||||
}
|
||||
|
||||
if (!Game.IsCloseEnoughToBase(Producer.Owner, Building, xy))
|
||||
{
|
||||
Sound.Play("nodeply1.aud");
|
||||
yield break;
|
||||
}
|
||||
|
||||
yield return new Order("PlaceBuilding", Producer.Owner.PlayerActor, null, xy, Building.Name);
|
||||
}
|
||||
else // rmb
|
||||
{
|
||||
Game.world.AddFrameEndTask( _ => { Game.controller.orderGenerator = null; } );
|
||||
}
|
||||
}
|
||||
|
||||
public void Tick()
|
||||
{
|
||||
var producing = Producer.traits.Get<Traits.ProductionQueue>().CurrentItem( Rules.UnitCategory[ Building.Name ] );
|
||||
if( producing == null || producing.Item != Building.Name || producing.RemainingTime != 0 )
|
||||
Game.world.AddFrameEndTask( _ => { Game.controller.orderGenerator = null; } );
|
||||
}
|
||||
|
||||
public void Render()
|
||||
{
|
||||
Game.worldRenderer.uiOverlay.DrawBuildingGrid( Building );
|
||||
}
|
||||
}
|
||||
}
|
||||
44
OpenRa.Game/Orders/ReplayOrderSource.cs
Normal file
44
OpenRa.Game/Orders/ReplayOrderSource.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace OpenRa.Game.Orders
|
||||
{
|
||||
class ReplayOrderSource : IOrderSource
|
||||
{
|
||||
BinaryReader replayReader;
|
||||
public ReplayOrderSource(string replayFilename)
|
||||
{
|
||||
replayReader = new BinaryReader(File.Open(replayFilename, FileMode.Open));
|
||||
}
|
||||
|
||||
public void SendLocalOrders(int localFrame, List<Order> localOrders) { }
|
||||
|
||||
public List<Order> OrdersForFrame(int frameNumber)
|
||||
{
|
||||
if (frameNumber == 0)
|
||||
return new List<Order>();
|
||||
|
||||
try
|
||||
{
|
||||
var len = replayReader.ReadInt32() - 4;
|
||||
var frame = replayReader.ReadInt32();
|
||||
var ret = replayReader.ReadBytes(len).ToOrderList();
|
||||
|
||||
if (frameNumber != frame)
|
||||
throw new InvalidOperationException("Attempted time-travel in OrdersForFrame (replay)");
|
||||
|
||||
return ret;
|
||||
}
|
||||
catch (EndOfStreamException)
|
||||
{
|
||||
return new List<Order>();
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsReadyForFrame(int frameNumber)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
37
OpenRa.Game/Orders/UnitOrderGenerator.cs
Normal file
37
OpenRa.Game/Orders/UnitOrderGenerator.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
|
||||
namespace OpenRa.Game.Orders
|
||||
{
|
||||
class UnitOrderGenerator : IOrderGenerator
|
||||
{
|
||||
public readonly List<Actor> selection;
|
||||
|
||||
public UnitOrderGenerator( IEnumerable<Actor> selected )
|
||||
{
|
||||
selection = selected.ToList();
|
||||
}
|
||||
|
||||
public IEnumerable<Order> Order( int2 xy, MouseInput mi )
|
||||
{
|
||||
foreach( var unit in selection )
|
||||
{
|
||||
var ret = unit.Order( xy, mi );
|
||||
if( ret != null )
|
||||
yield return ret;
|
||||
}
|
||||
}
|
||||
|
||||
public void Tick()
|
||||
{
|
||||
selection.RemoveAll(a => a.IsDead);
|
||||
}
|
||||
|
||||
public void Render()
|
||||
{
|
||||
foreach( var a in selection )
|
||||
Game.worldRenderer.DrawSelectionBox( a, Color.White, true );
|
||||
}
|
||||
}
|
||||
}
|
||||
107
OpenRa.Game/Orders/UnitOrders.cs
Normal file
107
OpenRa.Game/Orders/UnitOrders.cs
Normal file
@@ -0,0 +1,107 @@
|
||||
using System.Drawing;
|
||||
using OpenRa.Game.GameRules;
|
||||
using OpenRa.Game.Graphics;
|
||||
using OpenRa.Game.Traits;
|
||||
|
||||
namespace OpenRa.Game.Orders
|
||||
{
|
||||
static class UnitOrders
|
||||
{
|
||||
public static void ProcessOrder( Order order )
|
||||
{
|
||||
switch( order.OrderString )
|
||||
{
|
||||
case "PlaceBuilding":
|
||||
{
|
||||
Game.world.AddFrameEndTask( _ =>
|
||||
{
|
||||
var queue = order.Player.PlayerActor.traits.Get<Traits.ProductionQueue>();
|
||||
var building = (BuildingInfo)Rules.UnitInfo[ order.TargetString ];
|
||||
var producing = queue.CurrentItem(Rules.UnitCategory[order.TargetString]);
|
||||
if( producing == null || producing.Item != order.TargetString || producing.RemainingTime != 0 )
|
||||
return;
|
||||
|
||||
Log.Write( "Player \"{0}\" builds {1}", order.Player.PlayerName, building.Name );
|
||||
|
||||
Game.world.Add( new Actor( building, order.TargetLocation - GameRules.Footprint.AdjustForBuildingSize( building ), order.Player ) );
|
||||
if (order.Player == Game.LocalPlayer)
|
||||
{
|
||||
Sound.Play("placbldg.aud");
|
||||
Sound.Play("build5.aud");
|
||||
}
|
||||
|
||||
queue.FinishProduction(Rules.UnitCategory[building.Name]);
|
||||
} );
|
||||
break;
|
||||
}
|
||||
case "Chat":
|
||||
{
|
||||
Game.chat.AddLine(order.Player, order.TargetString);
|
||||
break;
|
||||
}
|
||||
case "ToggleReady":
|
||||
{
|
||||
Game.chat.AddLine(order.Player, "is " + order.TargetString );
|
||||
break;
|
||||
}
|
||||
case "AssignPlayer":
|
||||
{
|
||||
Game.LocalPlayer = order.Player;
|
||||
Game.chat.AddLine(order.Player, "is now YOU.");
|
||||
break;
|
||||
}
|
||||
case "SetName":
|
||||
{
|
||||
Game.chat.AddLine(order.Player, "is now known as " + order.TargetString);
|
||||
order.Player.PlayerName = order.TargetString;
|
||||
break;
|
||||
}
|
||||
case "SetRace":
|
||||
{
|
||||
order.Player.Race = order.TargetString == "0" ? Race.Soviet : Race.Allies;
|
||||
Game.chat.AddLine(order.Player, "is now playing {0}".F(order.Player.Race));
|
||||
break;
|
||||
}
|
||||
case "SetLag":
|
||||
{
|
||||
int lag = int.Parse(order.TargetString);
|
||||
if (Game.orderManager.GameStarted)
|
||||
{
|
||||
Game.chat.AddLine(Color.White, "Server", "Failed to change lag to {0} frames".F(lag));
|
||||
return;
|
||||
}
|
||||
|
||||
Game.orderManager.FramesAhead = lag;
|
||||
Game.chat.AddLine(Color.White, "Server", "Order lag is now {0} frames.".F(lag));
|
||||
break;
|
||||
}
|
||||
case "SetPalette":
|
||||
{
|
||||
int palette = int.Parse(order.TargetString);
|
||||
Game.chat.AddLine(order.Player, "has changed color to {0}".F(palette));
|
||||
order.Player.Palette = (PaletteType) palette;
|
||||
break;
|
||||
}
|
||||
case "StartGame":
|
||||
{
|
||||
Game.chat.AddLine(Color.White, "Server", "The game has started.");
|
||||
Game.orderManager.StartGame();
|
||||
break;
|
||||
}
|
||||
case "ChangeMap":
|
||||
{
|
||||
Game.chat.AddLine(Color.White, "Server", "Changing map to {0}".F(order.TargetString));
|
||||
Game.ChangeMap(order.TargetString);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
foreach (var t in order.Subject.traits.WithInterface<IOrder>())
|
||||
t.ResolveOrder(order.Subject, order);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user