From ced4d24793ba9b3afc86930ab55205da583a39bc Mon Sep 17 00:00:00 2001 From: "(no author)" <(no author)@993157c7-ee19-0410-b2c4-bb4e9862e678> Date: Tue, 24 Jul 2007 10:22:34 +0000 Subject: [PATCH] refinery comes with a harvester git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1344 993157c7-ee19-0410-b2c4-bb4e9862e678 --- OpenRa.Game/Actor.cs | 7 +++++++ OpenRa.Game/Building.cs | 3 ++- OpenRa.Game/ConstructionYard.cs | 4 ++-- OpenRa.Game/Game.cs | 8 ++++---- OpenRa.Game/Harvester.cs | 4 ++-- OpenRa.Game/MainWindow.cs | 7 +++---- OpenRa.Game/Mcv.cs | 10 +++------- OpenRa.Game/Refinery.cs | 16 ++++++++++++++-- OpenRa.Game/Sidebar.cs | 2 +- OpenRa.Game/Tree.cs | 3 ++- OpenRa.Game/Unit.cs | 5 +++-- 11 files changed, 43 insertions(+), 26 deletions(-) diff --git a/OpenRa.Game/Actor.cs b/OpenRa.Game/Actor.cs index c483fd6d78..9a73b02f03 100644 --- a/OpenRa.Game/Actor.cs +++ b/OpenRa.Game/Actor.cs @@ -10,9 +10,16 @@ namespace OpenRa.Game { abstract class Actor { + protected readonly Game game; + public abstract float2 RenderLocation { get; } public Player owner; public abstract Sprite[] CurrentImages { get; } public virtual void Tick(Game game, int t) { } + + protected Actor(Game game) + { + this.game = game; + } } } diff --git a/OpenRa.Game/Building.cs b/OpenRa.Game/Building.cs index c3a9f6db73..2f47e992fb 100644 --- a/OpenRa.Game/Building.cs +++ b/OpenRa.Game/Building.cs @@ -9,7 +9,8 @@ namespace OpenRa.Game protected Animation animation; protected int2 location; - public Building( string name, int2 location, Player owner ) + public Building( string name, int2 location, Player owner, Game game ) + : base( game ) { this.location = location; this.owner = owner; diff --git a/OpenRa.Game/ConstructionYard.cs b/OpenRa.Game/ConstructionYard.cs index f740283876..bd4db2b1d0 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, Player owner ) - : base( "fact", location, owner ) + public ConstructionYard( int2 location, Player owner, Game game ) + : base( "fact", location, owner, game ) { animation.PlayThen( "make", delegate { animation.PlayRepeating( "build" ); } ); } diff --git a/OpenRa.Game/Game.cs b/OpenRa.Game/Game.cs index ac1e9cf6f3..1ee4ac4749 100644 --- a/OpenRa.Game/Game.cs +++ b/OpenRa.Game/Game.cs @@ -39,7 +39,7 @@ namespace OpenRa.Game treeCache = new TreeCache(renderer.Device, map); foreach (TreeReference treeReference in map.Trees) - world.Add(new Tree(treeReference, treeCache, map)); + world.Add(new Tree(treeReference, treeCache, map, this)); pathFinder = new PathFinder(map, terrain.tileSet); @@ -48,12 +48,12 @@ namespace OpenRa.Game buildingCreation.Add( "fact", delegate( int2 location, Player owner ) { - return new ConstructionYard( location, owner ); + return new ConstructionYard( location, owner, this ); } ); buildingCreation.Add( "proc", delegate( int2 location, Player owner ) { - return new Refinery( location, owner ); + return new Refinery( location, owner, this ); } ); string[] buildings = { "powr", "apwr", "weap", "barr", "atek", "stek", "dome" }; @@ -66,7 +66,7 @@ namespace OpenRa.Game buildingCreation.Add( name, delegate( int2 location, Player owner ) { - return new Building( name, location, owner ); + return new Building( name, location, owner, this ); } ); } diff --git a/OpenRa.Game/Harvester.cs b/OpenRa.Game/Harvester.cs index 67e46d22d4..8ec7d5f458 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, Player owner ) - : base( "harv", cell, owner, new float2( 12, 12 ) ) + public Harvester( int2 cell, Player owner, Game game ) + : base( "harv", cell, owner, new float2( 12, 12 ), game ) { } diff --git a/OpenRa.Game/MainWindow.cs b/OpenRa.Game/MainWindow.cs index 7b1af0f8a8..8086a749cc 100644 --- a/OpenRa.Game/MainWindow.cs +++ b/OpenRa.Game/MainWindow.cs @@ -45,12 +45,11 @@ namespace OpenRa.Game SequenceProvider.ForcePrecache(); - 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.Add( new Mcv( new int2( 5, 5 ), game.players[ 3 ], game ) ); + game.world.Add( new Mcv( new int2( 7, 5 ), game.players[ 2 ], game ) ); + Mcv mcv = new Mcv( new int2( 9, 5 ), game.players[ 1 ], game ); game.world.orderGenerator = mcv; game.world.Add( mcv ); - 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 a5656f3dee..98637ab3e6 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, Player owner ) - : base( "mcv", location, owner, new float2( 12, 12 ) ) + public Mcv( int2 location, Player owner, Game game ) + : base( "mcv", location, owner, new float2( 12, 12 ), game ) { } @@ -25,11 +25,7 @@ namespace OpenRa.Game world.AddFrameEndTask( delegate { world.Remove( this ); - 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 ), owner ); - world.Add( (Actor)world.orderGenerator ); + world.Add( new ConstructionYard( fromCell - new int2( 1, 1 ), owner, game ) ); } ); currentOrder = null; }; diff --git a/OpenRa.Game/Refinery.cs b/OpenRa.Game/Refinery.cs index 429f055d07..3e575c9f2e 100644 --- a/OpenRa.Game/Refinery.cs +++ b/OpenRa.Game/Refinery.cs @@ -9,9 +9,21 @@ namespace OpenRa.Game { class Refinery : Building { - public Refinery( int2 location, Player owner ) - : base( "proc", location, owner ) + public Refinery( int2 location, Player owner, Game game ) + : base( "proc", location, owner, game ) { + animation.PlayThen("make", delegate + { + animation.PlayRepeating("idle"); + + game.world.AddFrameEndTask(delegate + { + Unit harvester = new Harvester(location + new int2(1, 2), owner, game); + harvester.facing = 8; + game.world.Add(harvester); + game.world.orderGenerator = harvester; + }); + }); } } } diff --git a/OpenRa.Game/Sidebar.cs b/OpenRa.Game/Sidebar.cs index 2d57ce3474..022c7874f5 100644 --- a/OpenRa.Game/Sidebar.cs +++ b/OpenRa.Game/Sidebar.cs @@ -143,7 +143,6 @@ namespace OpenRa.Game public IOrder Order( Game game, int2 xy ) { - game.world.uiOverlay.KillOverlay(); // todo: check that space is free return new PlaceBuildingOrder( this, xy ); } @@ -175,6 +174,7 @@ namespace OpenRa.Game game.world.Add( newBuilding( xy, building.owner ) ); } game.world.orderGenerator = null; + game.world.uiOverlay.KillOverlay(); } ); } } diff --git a/OpenRa.Game/Tree.cs b/OpenRa.Game/Tree.cs index 0916e5bfc7..68d8a2b3e4 100644 --- a/OpenRa.Game/Tree.cs +++ b/OpenRa.Game/Tree.cs @@ -10,7 +10,8 @@ namespace OpenRa.Game { int2 location; - public Tree(TreeReference r, TreeCache renderer, Map map) + public Tree(TreeReference r, TreeCache renderer, Map map, Game game) + : base( game ) { location = new int2( r.Location ) - map.Offset; currentImages = new Sprite[] { renderer.GetImage(r.Image) }; diff --git a/OpenRa.Game/Unit.cs b/OpenRa.Game/Unit.cs index 8dae1c3ff6..9571dd74bb 100644 --- a/OpenRa.Game/Unit.cs +++ b/OpenRa.Game/Unit.cs @@ -8,7 +8,7 @@ namespace OpenRa.Game { protected Animation animation; - protected int facing = 0; + public int facing = 0; protected int2 fromCell, toCell; protected int moveFraction, moveFractionTotal; @@ -18,7 +18,8 @@ namespace OpenRa.Game protected readonly float2 renderOffset; - public Unit( string name, int2 cell, Player owner, float2 renderOffset ) + public Unit( string name, int2 cell, Player owner, float2 renderOffset, Game game ) + : base( game ) { fromCell = toCell = cell; this.renderOffset = renderOffset;