git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1340 993157c7-ee19-0410-b2c4-bb4e9862e678

This commit is contained in:
(no author)
2007-07-24 09:16:41 +00:00
parent 5bf38488d2
commit 3d3316a188
14 changed files with 63 additions and 53 deletions

View File

@@ -11,7 +11,7 @@ namespace OpenRa.Game
abstract class Actor abstract class Actor
{ {
public abstract float2 RenderLocation { get; } public abstract float2 RenderLocation { get; }
public int palette; public Player owner;
public abstract Sprite[] CurrentImages { get; } public abstract Sprite[] CurrentImages { get; }
public virtual void Tick(Game game, int t) { } public virtual void Tick(Game game, int t) { }
} }

View File

@@ -9,10 +9,10 @@ namespace OpenRa.Game
protected Animation animation; protected Animation animation;
protected int2 location; protected int2 location;
public Building( string name, int2 location, int palette ) public Building( string name, int2 location, Player owner )
{ {
this.location = location; this.location = location;
this.palette = palette; this.owner = owner;
animation = new Animation( name ); animation = new Animation( name );
animation.PlayThen( "make", delegate { animation.Play( "idle" ); } ); animation.PlayThen( "make", delegate { animation.Play( "idle" ); } );

View File

@@ -7,8 +7,8 @@ namespace OpenRa.Game
{ {
class ConstructionYard : Building class ConstructionYard : Building
{ {
public ConstructionYard( int2 location, int palette ) public ConstructionYard( int2 location, Player owner )
: base( "fact", location, palette ) : base( "fact", location, owner )
{ {
animation.PlayThen( "make", delegate { animation.PlayRepeating( "build" ); } ); animation.PlayThen( "make", delegate { animation.PlayRepeating( "build" ); } );
} }

View File

@@ -18,11 +18,16 @@ namespace OpenRa.Game
public readonly Network network; public readonly Network network;
public readonly TechTree.TechTree techTree = new TechTree.TechTree(); public readonly TechTree.TechTree techTree = new TechTree.TechTree();
public readonly Dictionary<int, Player> players = new Dictionary<int, Player>();
// temporary, until we remove all the subclasses of Building // temporary, until we remove all the subclasses of Building
public Dictionary<string, Provider<Building, int2, int>> buildingCreation = new Dictionary<string, Provider<Building, int2, int>>(); public Dictionary<string, Provider<Building, int2, Player>> buildingCreation = new Dictionary<string, Provider<Building, int2, Player>>();
public Game(string mapName, Renderer renderer, int2 clientSize) 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))); map = new Map(new IniFile(FileSystem.Open(mapName)));
FileSystem.Mount(new Package("../../../" + map.Theater + ".mix")); FileSystem.Mount(new Package("../../../" + map.Theater + ".mix"));
@@ -40,14 +45,14 @@ namespace OpenRa.Game
network = new Network(); network = new Network();
buildingCreation.Add( "fact", 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", 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" }; string[] buildings = { "powr", "apwr", "weap", "barr", "atek", "stek", "dome" };
@@ -55,13 +60,13 @@ namespace OpenRa.Game
AddBuilding(s); AddBuilding(s);
} }
void AddBuilding(string name) void AddBuilding( string name )
{ {
buildingCreation.Add(name, buildingCreation.Add( name,
delegate(int2 location, int palette) delegate( int2 location, Player owner )
{ {
return new Building(name, location, palette); return new Building( name, location, owner );
}); } );
} }
public void Tick() public void Tick()

View File

@@ -6,8 +6,8 @@ namespace OpenRa.Game
{ {
class Harvester : Unit class Harvester : Unit
{ {
public Harvester( int2 cell, int palette ) public Harvester( int2 cell, Player owner )
: base( "harv", cell, palette, new float2( 12, 12 ) ) : base( "harv", cell, owner, new float2( 12, 12 ) )
{ {
} }

View File

@@ -45,12 +45,12 @@ namespace OpenRa.Game
SequenceProvider.ForcePrecache(); SequenceProvider.ForcePrecache();
game.world.Add( new Mcv( new int2( 5, 5 ), 3 ) ); game.world.Add( new Mcv( new int2( 5, 5 ), game.players[ 3 ] ) );
game.world.Add( new Mcv( new int2( 7, 5 ), 2 ) ); game.world.Add( new Mcv( new int2( 7, 5 ), game.players[ 2 ] ) );
Mcv mcv = new Mcv( new int2( 9, 5 ), 1 ); Mcv mcv = new Mcv( new int2( 9, 5 ), game.players[ 1 ] );
game.world.orderGenerator = mcv; game.world.orderGenerator = mcv;
game.world.Add( 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); sidebar = new Sidebar(Race.Soviet, renderer, game);

View File

@@ -9,8 +9,8 @@ namespace OpenRa.Game
{ {
class Mcv : Unit class Mcv : Unit
{ {
public Mcv( int2 location, int palette ) public Mcv( int2 location, Player owner )
: base( "mcv", location, palette, new float2( 12, 12 ) ) : base( "mcv", location, owner, new float2( 12, 12 ) )
{ {
} }
@@ -25,10 +25,10 @@ namespace OpenRa.Game
world.AddFrameEndTask( delegate world.AddFrameEndTask( delegate
{ {
world.Remove( this ); world.Remove( this );
world.Add( new ConstructionYard( fromCell - new int2( 1, 1 ), palette ) ); world.Add( new ConstructionYard( fromCell - new int2( 1, 1 ), owner ) );
world.Add( new Refinery( fromCell - new int2( 1, -2 ), palette ) ); 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 ); world.Add( (Actor)world.orderGenerator );
} ); } );
currentOrder = null; currentOrder = null;

View File

@@ -46,6 +46,7 @@
<Compile Include="Game.cs" /> <Compile Include="Game.cs" />
<Compile Include="IOrderGenerator.cs" /> <Compile Include="IOrderGenerator.cs" />
<Compile Include="Network\Packet.cs" /> <Compile Include="Network\Packet.cs" />
<Compile Include="Player.cs" />
<Compile Include="Sheet.cs" /> <Compile Include="Sheet.cs" />
<Compile Include="Harvester.cs" /> <Compile Include="Harvester.cs" />
<Compile Include="Log.cs" /> <Compile Include="Log.cs" />
@@ -76,7 +77,6 @@
<Compile Include="TerrainRenderer.cs" /> <Compile Include="TerrainRenderer.cs" />
<Compile Include="Tree.cs" /> <Compile Include="Tree.cs" />
<Compile Include="TreeCache.cs" /> <Compile Include="TreeCache.cs" />
<Compile Include="Truck.cs" />
<Compile Include="Unit.cs" /> <Compile Include="Unit.cs" />
<Compile Include="UnitSheetBuilder.cs" /> <Compile Include="UnitSheetBuilder.cs" />
<Compile Include="Util.cs" /> <Compile Include="Util.cs" />

18
OpenRa.Game/Player.cs Normal file
View File

@@ -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;
}
}
}

View File

@@ -9,8 +9,8 @@ namespace OpenRa.Game
{ {
class Refinery : Building class Refinery : Building
{ {
public Refinery(int2 location, int palette) public Refinery( int2 location, Player owner )
: base( "proc", location, palette ) : base( "proc", location, owner )
{ {
} }
} }

View File

@@ -50,8 +50,8 @@ namespace OpenRa.Game
public void Build(SidebarItem item) public void Build(SidebarItem item)
{ {
if (item != null) if( item != null )
game.world.orderGenerator = new PlaceBuilding( 1, item.techTreeItem.tag.ToLowerInvariant() ); game.world.orderGenerator = new PlaceBuilding( game.players[ 1 ], item.techTreeItem.tag.ToLowerInvariant() );
} }
void LoadSprites(string filename) void LoadSprites(string filename)
@@ -128,12 +128,12 @@ namespace OpenRa.Game
class PlaceBuilding : IOrderGenerator class PlaceBuilding : IOrderGenerator
{ {
int palette; Player owner;
string buildingName; string buildingName;
public PlaceBuilding( int palette, string buildingName ) public PlaceBuilding( Player owner, string buildingName )
{ {
this.palette = palette; this.owner = owner;
this.buildingName = buildingName; this.buildingName = buildingName;
} }
@@ -158,10 +158,11 @@ namespace OpenRa.Game
{ {
game.world.AddFrameEndTask( delegate game.world.AddFrameEndTask( delegate
{ {
Provider<Building, int2, int> newBuilding; Provider<Building, int2, Player> newBuilding;
if( game.buildingCreation.TryGetValue( building.buildingName, out 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.techTree.Build( building.buildingName );
} }
game.world.orderGenerator = null; game.world.orderGenerator = null;

View File

@@ -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 )
{
}
}
}

View File

@@ -18,11 +18,11 @@ namespace OpenRa.Game
protected readonly float2 renderOffset; 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; fromCell = toCell = cell;
this.renderOffset = renderOffset; this.renderOffset = renderOffset;
this.palette = palette; this.owner = owner;
animation = new Animation( name ); animation = new Animation( name );
animation.PlayFetchIndex( "idle", delegate { return facing; } ); animation.PlayFetchIndex( "idle", delegate { return facing; } );

View File

@@ -64,7 +64,7 @@ namespace OpenRa.Game
continue; continue;
foreach( Sprite image in images ) foreach( Sprite image in images )
spriteRenderer.DrawSprite(image, loc, a.palette); spriteRenderer.DrawSprite(image, loc, (a.owner != null) ? a.owner.Palette : 0);
} }
foreach( Action<World> a in frameEndActions ) foreach( Action<World> a in frameEndActions )