git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1335 993157c7-ee19-0410-b2c4-bb4e9862e678
This commit is contained in:
@@ -8,4 +8,6 @@ namespace OpenRa
|
||||
// they are generic.
|
||||
|
||||
public delegate T Provider<T>();
|
||||
public delegate T Provider<T,U>( U u );
|
||||
public delegate T Provider<T,U,V>( U u, V v );
|
||||
}
|
||||
|
||||
@@ -14,6 +14,10 @@ namespace OpenRa.Game
|
||||
public readonly Viewport viewport;
|
||||
public readonly PathFinder pathFinder;
|
||||
public readonly Network network;
|
||||
public readonly TechTree.TechTree techTree = new TechTree.TechTree();
|
||||
|
||||
// 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 Game(string mapName, Renderer renderer, int2 clientSize)
|
||||
{
|
||||
@@ -32,6 +36,27 @@ namespace OpenRa.Game
|
||||
pathFinder = new PathFinder(map, terrain.tileSet);
|
||||
|
||||
network = new Network();
|
||||
|
||||
buildingCreation.Add( "fact",
|
||||
delegate( int2 location, int palette )
|
||||
{
|
||||
return new ConstructionYard( location, palette );
|
||||
} );
|
||||
buildingCreation.Add( "proc",
|
||||
delegate( int2 location, int palette )
|
||||
{
|
||||
return new Refinery( location, palette );
|
||||
} );
|
||||
buildingCreation.Add( "powr",
|
||||
delegate( int2 location, int palette )
|
||||
{
|
||||
return new Building( "powr", location, palette );
|
||||
} );
|
||||
buildingCreation.Add( "apwr",
|
||||
delegate( int2 location, int palette )
|
||||
{
|
||||
return new Building( "apwr", location, palette );
|
||||
} );
|
||||
}
|
||||
|
||||
public void Tick()
|
||||
@@ -41,7 +66,7 @@ namespace OpenRa.Game
|
||||
|
||||
public void Issue(IOrder order)
|
||||
{
|
||||
order.Apply();
|
||||
order.Apply( this );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace OpenRa.Game
|
||||
harvester = harv;
|
||||
}
|
||||
|
||||
public void Apply()
|
||||
public void Apply( Game game )
|
||||
{
|
||||
harvester.AcceptHarvestOrder();
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ using System.Text;
|
||||
|
||||
namespace OpenRa.Game
|
||||
{
|
||||
interface ISelectable
|
||||
interface IOrderGenerator
|
||||
{
|
||||
//Sprite CurrentCursor( int x, int y );
|
||||
IOrder Order( int2 xy );
|
||||
@@ -48,11 +48,11 @@ namespace OpenRa.Game
|
||||
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.myUnit = mcv;
|
||||
game.world.orderGenerator = mcv;
|
||||
game.world.Add( mcv );
|
||||
game.world.Add( new Refinery( new int2( 7, 5 ), 2 ) );
|
||||
|
||||
sidebar = new Sidebar(Race.Soviet, renderer, game.viewport);
|
||||
sidebar = new Sidebar(game.techTree, Race.Soviet, renderer, game.viewport);
|
||||
|
||||
renderer.SetPalette( new HardwarePalette( renderer, game.map ) );
|
||||
}
|
||||
@@ -79,12 +79,15 @@ namespace OpenRa.Game
|
||||
RectangleF rect = new RectangleF(sidebar.Location.ToPointF(), new SizeF(sidebar.Width, game.viewport.Height));
|
||||
if (rect.Contains(point.ToPointF()))
|
||||
{
|
||||
sidebar.Build(sidebar.FindSpriteAtPoint(point));
|
||||
sidebar.Build( sidebar.FindSpriteAtPoint( point ), game );
|
||||
return;
|
||||
}
|
||||
float2 xy = (1 / 24.0f) * point;
|
||||
IOrder order = game.world.myUnit.Order( new int2( (int)xy.X, (int)xy.Y ) );
|
||||
game.Issue( order );
|
||||
if( game.world.orderGenerator != null )
|
||||
{
|
||||
IOrder order = game.world.orderGenerator.Order( new int2( (int)xy.X, (int)xy.Y ) );
|
||||
game.Issue( order );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,8 +28,8 @@ namespace OpenRa.Game
|
||||
world.Add( new ConstructionYard( fromCell - new int2( 1, 1 ), palette ) );
|
||||
world.Add( new Refinery( fromCell - new int2( 1, -2 ), palette ) );
|
||||
|
||||
world.myUnit = new Harvester( fromCell - new int2( 0, -4 ), palette );
|
||||
world.Add( (Actor)world.myUnit );
|
||||
world.orderGenerator = new Harvester( fromCell - new int2( 0, -4 ), palette );
|
||||
world.Add( (Actor)world.orderGenerator );
|
||||
} );
|
||||
currentOrder = null;
|
||||
};
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace OpenRa.Game
|
||||
{
|
||||
interface IOrder
|
||||
{
|
||||
void Apply();
|
||||
void Apply( Game game );
|
||||
}
|
||||
|
||||
class MoveOrder : IOrder
|
||||
@@ -20,7 +20,7 @@ namespace OpenRa.Game
|
||||
this.Destination = destination;
|
||||
}
|
||||
|
||||
public void Apply()
|
||||
public void Apply( Game game )
|
||||
{
|
||||
Unit.AcceptMoveOrder( Destination );
|
||||
}
|
||||
@@ -35,7 +35,7 @@ namespace OpenRa.Game
|
||||
this.Mcv = mcv;
|
||||
}
|
||||
|
||||
public void Apply()
|
||||
public void Apply( Game game )
|
||||
{
|
||||
Mcv.AcceptDeployOrder();
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
<Compile Include="Animation.cs" />
|
||||
<Compile Include="Building.cs" />
|
||||
<Compile Include="Game.cs" />
|
||||
<Compile Include="IOrderGenerator.cs" />
|
||||
<Compile Include="Network\Packet.cs" />
|
||||
<Compile Include="Sheet.cs" />
|
||||
<Compile Include="Harvester.cs" />
|
||||
@@ -52,7 +53,6 @@
|
||||
<Compile Include="PathFinder.cs" />
|
||||
<Compile Include="Sequence.cs" />
|
||||
<Compile Include="ConstructionYard.cs" />
|
||||
<Compile Include="ISelectable.cs" />
|
||||
<Compile Include="MoveOrder.cs" />
|
||||
<Compile Include="Region.cs" />
|
||||
<Compile Include="SequenceProvider.cs" />
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace OpenRa.Game
|
||||
{
|
||||
class Sidebar
|
||||
{
|
||||
TechTree.TechTree techTree = new TechTree.TechTree();
|
||||
TechTree.TechTree techTree;
|
||||
|
||||
SpriteRenderer spriteRenderer;
|
||||
Sprite blank;
|
||||
@@ -24,11 +24,12 @@ namespace OpenRa.Game
|
||||
public float Width
|
||||
{
|
||||
get { return spriteWidth * 2; }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Sidebar(Race race, Renderer renderer, Viewport viewport)
|
||||
public Sidebar( TechTree.TechTree techTree, Race race, Renderer renderer, Viewport viewport )
|
||||
{
|
||||
this.techTree = techTree;
|
||||
this.viewport = viewport;
|
||||
viewport.AddRegion( Region.Create(viewport, DockStyle.Right, 128, Paint));
|
||||
techTree.CurrentRace = race;
|
||||
@@ -41,9 +42,9 @@ namespace OpenRa.Game
|
||||
blank = SheetBuilder.Add(new Size((int)spriteWidth, (int)spriteHeight), 16);
|
||||
}
|
||||
|
||||
public bool Build(string key)
|
||||
public void Build(string key, Game game )
|
||||
{
|
||||
return techTree.Build(key);
|
||||
game.world.orderGenerator = new PlaceBuilding( 1, key.ToLowerInvariant() );
|
||||
}
|
||||
|
||||
void LoadSprites(string filename)
|
||||
@@ -117,4 +118,48 @@ namespace OpenRa.Game
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
class PlaceBuilding : IOrderGenerator
|
||||
{
|
||||
int palette;
|
||||
string buildingName;
|
||||
|
||||
public PlaceBuilding( int palette, string buildingName )
|
||||
{
|
||||
this.palette = palette;
|
||||
this.buildingName = buildingName;
|
||||
}
|
||||
|
||||
public IOrder Order( int2 xy )
|
||||
{
|
||||
// todo: check that space is free
|
||||
return new PlaceBuildingOrder( this, xy );
|
||||
}
|
||||
|
||||
class PlaceBuildingOrder : IOrder
|
||||
{
|
||||
PlaceBuilding building;
|
||||
int2 xy;
|
||||
|
||||
public PlaceBuildingOrder( PlaceBuilding building, int2 xy )
|
||||
{
|
||||
this.building = building;
|
||||
this.xy = xy;
|
||||
}
|
||||
|
||||
public void Apply( Game game )
|
||||
{
|
||||
game.world.AddFrameEndTask( delegate
|
||||
{
|
||||
Provider<Building, int2, int> newBuilding;
|
||||
if( game.buildingCreation.TryGetValue( building.buildingName, out newBuilding ) )
|
||||
{
|
||||
game.world.Add( newBuilding( xy, building.palette ) );
|
||||
game.techTree.Build( building.buildingName );
|
||||
}
|
||||
game.world.orderGenerator = null;
|
||||
} );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ using System.Text;
|
||||
|
||||
namespace OpenRa.Game
|
||||
{
|
||||
abstract class Unit : Actor, ISelectable
|
||||
abstract class Unit : Actor, IOrderGenerator
|
||||
{
|
||||
protected Animation animation;
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace OpenRa.Game
|
||||
List<Action<World>> frameEndActions = new List<Action<World>>();
|
||||
SpriteRenderer spriteRenderer;
|
||||
Viewport viewport;
|
||||
public ISelectable myUnit;
|
||||
public IOrderGenerator orderGenerator;
|
||||
|
||||
public World(Renderer renderer, Viewport viewport)
|
||||
{
|
||||
|
||||
@@ -65,8 +65,9 @@ namespace OpenRa.TechTree
|
||||
|
||||
public bool Build(string key, bool force)
|
||||
{
|
||||
if (string.IsNullOrEmpty(key)) return false;
|
||||
Item b = objects[key];
|
||||
if( string.IsNullOrEmpty( key ) ) return false;
|
||||
key = key.ToUpperInvariant();
|
||||
Item b = objects[ key ];
|
||||
if (!force && !b.CanBuild) return false;
|
||||
built.Add(key);
|
||||
CheckAll();
|
||||
@@ -80,6 +81,7 @@ namespace OpenRa.TechTree
|
||||
|
||||
public bool Unbuild(string key)
|
||||
{
|
||||
key = key.ToUpperInvariant();
|
||||
Item b = objects[key];
|
||||
if (!built.Contains(key)) return false;
|
||||
built.Remove(key);
|
||||
|
||||
@@ -47,7 +47,23 @@
|
||||
<sequence name="damaged-idle" start="1"/>
|
||||
<sequence name="make" start="0" length="*" src="procmake" />
|
||||
</unit>
|
||||
|
||||
<!-- power plant -->
|
||||
|
||||
<unit name="powr">
|
||||
<sequence name="idle" start="0"/>
|
||||
<sequence name="damaged-idle" start="1"/>
|
||||
<sequence name="make" start="0" length="*" src="powrmake" />
|
||||
</unit>
|
||||
|
||||
<!-- advanced power plant -->
|
||||
|
||||
<unit name="apwr">
|
||||
<sequence name="idle" start="0"/>
|
||||
<sequence name="damaged-idle" start="1"/>
|
||||
<sequence name="make" start="0" length="*" src="apwrmake" />
|
||||
</unit>
|
||||
|
||||
<!-- mcv -->
|
||||
|
||||
<unit name="mcv">
|
||||
|
||||
Reference in New Issue
Block a user