diff --git a/OpenRa.Game/Actor.cs b/OpenRa.Game/Actor.cs index 5321298f5b..c483fd6d78 100644 --- a/OpenRa.Game/Actor.cs +++ b/OpenRa.Game/Actor.cs @@ -11,7 +11,7 @@ namespace OpenRa.Game abstract class Actor { public abstract float2 RenderLocation { get; } - public int palette; + public Player owner; public abstract Sprite[] CurrentImages { get; } public virtual void Tick(Game game, int t) { } } diff --git a/OpenRa.Game/Building.cs b/OpenRa.Game/Building.cs index 1ab5fbf1b4..04171865c9 100644 --- a/OpenRa.Game/Building.cs +++ b/OpenRa.Game/Building.cs @@ -9,10 +9,10 @@ namespace OpenRa.Game protected Animation animation; protected int2 location; - public Building( string name, int2 location, int palette ) + public Building( string name, int2 location, Player owner ) { this.location = location; - this.palette = palette; + this.owner = owner; animation = new Animation( name ); animation.PlayThen( "make", delegate { animation.Play( "idle" ); } ); diff --git a/OpenRa.Game/ConstructionYard.cs b/OpenRa.Game/ConstructionYard.cs index f9be7c8f88..f740283876 100644 --- a/OpenRa.Game/ConstructionYard.cs +++ b/OpenRa.Game/ConstructionYard.cs @@ -7,8 +7,8 @@ namespace OpenRa.Game { class ConstructionYard : Building { - public ConstructionYard( int2 location, int palette ) - : base( "fact", location, palette ) + public ConstructionYard( int2 location, Player owner ) + : base( "fact", location, owner ) { animation.PlayThen( "make", delegate { animation.PlayRepeating( "build" ); } ); } diff --git a/OpenRa.Game/Game.cs b/OpenRa.Game/Game.cs index 541031a69f..485278b88e 100644 --- a/OpenRa.Game/Game.cs +++ b/OpenRa.Game/Game.cs @@ -18,11 +18,16 @@ namespace OpenRa.Game public readonly Network network; public readonly TechTree.TechTree techTree = new TechTree.TechTree(); + public readonly Dictionary players = new Dictionary(); + // temporary, until we remove all the subclasses of Building - public Dictionary> buildingCreation = new Dictionary>(); + public Dictionary> buildingCreation = new Dictionary>(); public Game(string mapName, Renderer renderer, int2 clientSize) { + for( int i = 0 ; i < 8 ; i++ ) + players.Add( i, new Player( i, string.Format( "Multi{0}", i ) ) ); + map = new Map(new IniFile(FileSystem.Open(mapName))); FileSystem.Mount(new Package("../../../" + map.Theater + ".mix")); @@ -40,14 +45,14 @@ namespace OpenRa.Game network = new Network(); buildingCreation.Add( "fact", - delegate( int2 location, int palette ) + delegate( int2 location, Player owner ) { - return new ConstructionYard( location, palette ); + return new ConstructionYard( location, owner ); } ); buildingCreation.Add( "proc", - delegate( int2 location, int palette ) + delegate( int2 location, Player owner ) { - return new Refinery( location, palette ); + return new Refinery( location, owner ); } ); string[] buildings = { "powr", "apwr", "weap", "barr", "atek", "stek", "dome" }; @@ -55,13 +60,13 @@ namespace OpenRa.Game AddBuilding(s); } - void AddBuilding(string name) + void AddBuilding( string name ) { - buildingCreation.Add(name, - delegate(int2 location, int palette) + buildingCreation.Add( name, + delegate( int2 location, Player owner ) { - return new Building(name, location, palette); - }); + return new Building( name, location, owner ); + } ); } public void Tick() diff --git a/OpenRa.Game/Harvester.cs b/OpenRa.Game/Harvester.cs index 3afa52261d..860fe6d7b0 100644 --- a/OpenRa.Game/Harvester.cs +++ b/OpenRa.Game/Harvester.cs @@ -6,8 +6,8 @@ namespace OpenRa.Game { class Harvester : Unit { - public Harvester( int2 cell, int palette ) - : base( "harv", cell, palette, new float2( 12, 12 ) ) + public Harvester( int2 cell, Player owner ) + : base( "harv", cell, owner, new float2( 12, 12 ) ) { } diff --git a/OpenRa.Game/MainWindow.cs b/OpenRa.Game/MainWindow.cs index 7a1de14d28..49c231ab60 100644 --- a/OpenRa.Game/MainWindow.cs +++ b/OpenRa.Game/MainWindow.cs @@ -45,12 +45,12 @@ namespace OpenRa.Game SequenceProvider.ForcePrecache(); - game.world.Add( new Mcv( new int2( 5, 5 ), 3 ) ); - game.world.Add( new Mcv( new int2( 7, 5 ), 2 ) ); - Mcv mcv = new Mcv( new int2( 9, 5 ), 1 ); + game.world.Add( new Mcv( new int2( 5, 5 ), game.players[ 3 ] ) ); + game.world.Add( new Mcv( new int2( 7, 5 ), game.players[ 2 ] ) ); + Mcv mcv = new Mcv( new int2( 9, 5 ), game.players[ 1 ] ); game.world.orderGenerator = mcv; game.world.Add( mcv ); - game.world.Add( new Refinery( new int2( 7, 5 ), 2 ) ); + game.world.Add( new Refinery( new int2( 7, 5 ), game.players[ 2 ] ) ); sidebar = new Sidebar(Race.Soviet, renderer, game); diff --git a/OpenRa.Game/Mcv.cs b/OpenRa.Game/Mcv.cs index b900861875..5e68fddb79 100644 --- a/OpenRa.Game/Mcv.cs +++ b/OpenRa.Game/Mcv.cs @@ -9,8 +9,8 @@ namespace OpenRa.Game { class Mcv : Unit { - public Mcv( int2 location, int palette ) - : base( "mcv", location, palette, new float2( 12, 12 ) ) + public Mcv( int2 location, Player owner ) + : base( "mcv", location, owner, new float2( 12, 12 ) ) { } @@ -25,10 +25,10 @@ namespace OpenRa.Game world.AddFrameEndTask( delegate { world.Remove( this ); - world.Add( new ConstructionYard( fromCell - new int2( 1, 1 ), palette ) ); - world.Add( new Refinery( fromCell - new int2( 1, -2 ), palette ) ); + world.Add( new ConstructionYard( fromCell - new int2( 1, 1 ), owner ) ); + world.Add( new Refinery( fromCell - new int2( 1, -2 ), owner ) ); - world.orderGenerator = new Harvester( fromCell - new int2( 0, -4 ), palette ); + world.orderGenerator = new Harvester( fromCell - new int2( 0, -4 ), owner ); world.Add( (Actor)world.orderGenerator ); } ); currentOrder = null; diff --git a/OpenRa.Game/OpenRa.Game.csproj b/OpenRa.Game/OpenRa.Game.csproj index edac3ad24f..22e27db09e 100644 --- a/OpenRa.Game/OpenRa.Game.csproj +++ b/OpenRa.Game/OpenRa.Game.csproj @@ -46,6 +46,7 @@ + @@ -76,7 +77,6 @@ - diff --git a/OpenRa.Game/Player.cs b/OpenRa.Game/Player.cs new file mode 100644 index 0000000000..2fa988b8fd --- /dev/null +++ b/OpenRa.Game/Player.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenRa.Game +{ + class Player + { + public int Palette; + public string PlayerName; + + public Player( int palette, string playerName ) + { + this.Palette = palette; + this.PlayerName = playerName; + } + } +} diff --git a/OpenRa.Game/Refinery.cs b/OpenRa.Game/Refinery.cs index 6fa7cac46f..429f055d07 100644 --- a/OpenRa.Game/Refinery.cs +++ b/OpenRa.Game/Refinery.cs @@ -9,8 +9,8 @@ namespace OpenRa.Game { class Refinery : Building { - public Refinery(int2 location, int palette) - : base( "proc", location, palette ) + public Refinery( int2 location, Player owner ) + : base( "proc", location, owner ) { } } diff --git a/OpenRa.Game/Sidebar.cs b/OpenRa.Game/Sidebar.cs index 821396bd5d..f11c94ea14 100644 --- a/OpenRa.Game/Sidebar.cs +++ b/OpenRa.Game/Sidebar.cs @@ -50,8 +50,8 @@ namespace OpenRa.Game public void Build(SidebarItem item) { - if (item != null) - game.world.orderGenerator = new PlaceBuilding( 1, item.techTreeItem.tag.ToLowerInvariant() ); + if( item != null ) + game.world.orderGenerator = new PlaceBuilding( game.players[ 1 ], item.techTreeItem.tag.ToLowerInvariant() ); } void LoadSprites(string filename) @@ -128,12 +128,12 @@ namespace OpenRa.Game class PlaceBuilding : IOrderGenerator { - int palette; + Player owner; string buildingName; - public PlaceBuilding( int palette, string buildingName ) + public PlaceBuilding( Player owner, string buildingName ) { - this.palette = palette; + this.owner = owner; this.buildingName = buildingName; } @@ -158,10 +158,11 @@ namespace OpenRa.Game { game.world.AddFrameEndTask( delegate { - Provider newBuilding; + Provider newBuilding; if( game.buildingCreation.TryGetValue( building.buildingName, out newBuilding ) ) { - game.world.Add( newBuilding( xy, building.palette ) ); + Log.Write( "Player \"{0}\" builds {1}", building.owner.PlayerName, building.buildingName ); + game.world.Add( newBuilding( xy, building.owner ) ); game.techTree.Build( building.buildingName ); } game.world.orderGenerator = null; diff --git a/OpenRa.Game/Truck.cs b/OpenRa.Game/Truck.cs deleted file mode 100644 index 49dcd56a9b..0000000000 --- a/OpenRa.Game/Truck.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace OpenRa.Game -{ - class Truck : Unit - { - public Truck( int2 cell, int palette ) - : base( "truk", cell, palette, float2.Zero ) - { - } - } -} diff --git a/OpenRa.Game/Unit.cs b/OpenRa.Game/Unit.cs index d0e08335c2..c2d87c567b 100644 --- a/OpenRa.Game/Unit.cs +++ b/OpenRa.Game/Unit.cs @@ -18,11 +18,11 @@ namespace OpenRa.Game protected readonly float2 renderOffset; - public Unit( string name, int2 cell, int palette, float2 renderOffset ) + public Unit( string name, int2 cell, Player owner, float2 renderOffset ) { fromCell = toCell = cell; this.renderOffset = renderOffset; - this.palette = palette; + this.owner = owner; animation = new Animation( name ); animation.PlayFetchIndex( "idle", delegate { return facing; } ); diff --git a/OpenRa.Game/World.cs b/OpenRa.Game/World.cs index f6a2087692..a9076ed459 100644 --- a/OpenRa.Game/World.cs +++ b/OpenRa.Game/World.cs @@ -64,7 +64,7 @@ namespace OpenRa.Game continue; foreach( Sprite image in images ) - spriteRenderer.DrawSprite(image, loc, a.palette); + spriteRenderer.DrawSprite(image, loc, (a.owner != null) ? a.owner.Palette : 0); } foreach( Action a in frameEndActions )