pushed bibs down into the smudge layer; made Game static
This commit is contained in:
@@ -31,6 +31,10 @@ namespace OpenRa.FileFormats
|
||||
|
||||
public Map(IniFile file)
|
||||
{
|
||||
for (int j = 0; j < 128; j++)
|
||||
for (int i = 0; i < 128; i++)
|
||||
MapTiles[i, j] = new TileReference();
|
||||
|
||||
IniSection basic = file.GetSection("Basic");
|
||||
Title = basic.GetValue("Name", "(null)");
|
||||
|
||||
|
||||
@@ -4,11 +4,12 @@ using System.Text;
|
||||
|
||||
namespace OpenRa.FileFormats
|
||||
{
|
||||
public struct TileReference
|
||||
public class TileReference
|
||||
{
|
||||
public ushort tile;
|
||||
public byte image;
|
||||
public byte overlay;
|
||||
public byte smudge;
|
||||
|
||||
public override int GetHashCode() { return tile.GetHashCode() ^ image.GetHashCode(); }
|
||||
|
||||
|
||||
@@ -45,10 +45,10 @@ namespace OpenRa.Game
|
||||
traits.Add( new Traits.Tree( treeRenderer.GetImage( tree.Image ) ) );
|
||||
}
|
||||
|
||||
public void Tick( Game game )
|
||||
{
|
||||
foreach( var tick in traits.WithInterface<Traits.ITick>() )
|
||||
tick.Tick( this, game );
|
||||
public void Tick()
|
||||
{
|
||||
foreach (var tick in traits.WithInterface<Traits.ITick>())
|
||||
tick.Tick(this);
|
||||
}
|
||||
|
||||
public float2 CenterLocation;
|
||||
@@ -59,10 +59,10 @@ namespace OpenRa.Game
|
||||
return traits.WithInterface<Traits.IRender>().SelectMany( x => x.Render( this ) );
|
||||
}
|
||||
|
||||
public Order Order( Game game, int2 xy )
|
||||
public Order Order( int2 xy )
|
||||
{
|
||||
return traits.WithInterface<Traits.IOrder>()
|
||||
.Select( x => x.Order( this, game, xy ) )
|
||||
.Select( x => x.Order( this, xy ) )
|
||||
.Where( x => x != null )
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace OpenRa.Game
|
||||
{
|
||||
interface IEffect
|
||||
{
|
||||
void Tick(Game g);
|
||||
void Tick();
|
||||
IEnumerable<Pair<Sprite, float2>> Render();
|
||||
Player Owner { get; }
|
||||
}
|
||||
@@ -32,7 +32,7 @@ namespace OpenRa.Game
|
||||
|
||||
/* src, dest are *pixel* coords */
|
||||
public Bullet(string weapon, Player owner, Actor firedBy,
|
||||
int2 src, int2 dest, Game game)
|
||||
int2 src, int2 dest)
|
||||
{
|
||||
Owner = owner;
|
||||
FiredBy = firedBy;
|
||||
@@ -48,18 +48,17 @@ namespace OpenRa.Game
|
||||
|
||||
int TotalTime() { return (Dest - Src).Length * BaseBulletSpeed / Weapon.Speed; }
|
||||
|
||||
public void Tick(Game game)
|
||||
public void Tick()
|
||||
{
|
||||
if (t == 0)
|
||||
game.PlaySound(Weapon.Report + ".aud", false);
|
||||
Game.PlaySound(Weapon.Report + ".aud", false);
|
||||
|
||||
t += 40;
|
||||
|
||||
if (t > TotalTime()) /* remove finished bullets */
|
||||
{
|
||||
game.world.AddFrameEndTask(w => w.Remove(this));
|
||||
game.PlaySound("kaboom25.aud", false);
|
||||
game.world.AddFrameEndTask(w => w.Add(new Explosion(Dest, game)));
|
||||
Game.world.AddFrameEndTask(w => w.Remove(this));
|
||||
Game.world.AddFrameEndTask(w => w.Add(new Explosion(Dest)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,19 +10,12 @@ namespace OpenRa.Game
|
||||
{
|
||||
class Controller
|
||||
{
|
||||
Game game;
|
||||
|
||||
public IOrderGenerator orderGenerator;
|
||||
|
||||
public Controller(Game game)
|
||||
{
|
||||
this.game = game;
|
||||
}
|
||||
|
||||
float2 dragStart, dragEnd;
|
||||
public void HandleMouseInput(MouseInput mi)
|
||||
{
|
||||
var xy = game.viewport.ViewToWorld(mi);
|
||||
var xy = Game.viewport.ViewToWorld(mi);
|
||||
|
||||
if (mi.Button == MouseButtons.Left && mi.Event == MouseInputEvent.Down)
|
||||
{
|
||||
@@ -30,8 +23,8 @@ namespace OpenRa.Game
|
||||
dragStart = dragEnd = xy;
|
||||
|
||||
if (orderGenerator != null)
|
||||
foreach (var order in orderGenerator.Order(game, xy.ToInt2()))
|
||||
order.Apply(game, true);
|
||||
foreach (var order in orderGenerator.Order(xy.ToInt2()))
|
||||
order.Apply(true);
|
||||
}
|
||||
|
||||
if (mi.Button == MouseButtons.Left && mi.Event == MouseInputEvent.Move)
|
||||
@@ -43,10 +36,10 @@ namespace OpenRa.Game
|
||||
{
|
||||
if (dragStart != xy)
|
||||
orderGenerator = new UnitOrderGenerator(
|
||||
game.SelectUnitsInBox( Game.CellSize * dragStart, Game.CellSize * xy ) );
|
||||
Game.SelectUnitsInBox( Game.CellSize * dragStart, Game.CellSize * xy ) );
|
||||
else
|
||||
orderGenerator = new UnitOrderGenerator(
|
||||
game.SelectUnitOrBuilding( Game.CellSize * xy ) );
|
||||
Game.SelectUnitOrBuilding( Game.CellSize * xy ) );
|
||||
}
|
||||
|
||||
dragStart = dragEnd = xy;
|
||||
@@ -61,8 +54,8 @@ namespace OpenRa.Game
|
||||
|
||||
if( mi.Button == MouseButtons.Right && mi.Event == MouseInputEvent.Down )
|
||||
if( orderGenerator != null )
|
||||
foreach( var order in orderGenerator.Order( game, xy.ToInt2() ) )
|
||||
order.Apply( game, false );
|
||||
foreach( var order in orderGenerator.Order( xy.ToInt2() ) )
|
||||
order.Apply( false );
|
||||
}
|
||||
|
||||
public Pair<float2, float2>? SelectionBox
|
||||
@@ -81,7 +74,7 @@ namespace OpenRa.Game
|
||||
if (uog != null && uog.selection.Count > 0 && uog.selection.Any(a => a.traits.Contains<Traits.Mobile>()))
|
||||
return Cursor.Move;
|
||||
|
||||
if (game.SelectUnitOrBuilding(Game.CellSize * dragEnd).Any())
|
||||
if (Game.SelectUnitOrBuilding(Game.CellSize * dragEnd).Any())
|
||||
return Cursor.Select;
|
||||
|
||||
return Cursor.Default;
|
||||
|
||||
@@ -13,15 +13,16 @@ namespace OpenRa.Game
|
||||
Animation anim;
|
||||
int2 pos;
|
||||
|
||||
public Explosion(int2 pixelPos, Game g)
|
||||
public Explosion(int2 pixelPos)
|
||||
{
|
||||
this.pos = pixelPos;
|
||||
|
||||
anim = new Animation("veh-hit3");
|
||||
anim.PlayThen("idle", () => g.world.AddFrameEndTask(w => w.Remove(this)));
|
||||
anim.PlayThen("idle", () => Game.world.AddFrameEndTask(w => w.Remove(this)));
|
||||
Game.PlaySound("kaboom25.aud", false);
|
||||
}
|
||||
|
||||
public void Tick(Game g) { anim.Tick(); }
|
||||
public void Tick() { anim.Tick(); }
|
||||
|
||||
public IEnumerable<Pair<Sprite, float2>> Render()
|
||||
{
|
||||
|
||||
@@ -9,30 +9,30 @@ using IjwFramework.Collections;
|
||||
|
||||
namespace OpenRa.Game
|
||||
{
|
||||
class Game
|
||||
static class Game
|
||||
{
|
||||
public static readonly int CellSize = 24;
|
||||
|
||||
public readonly World world;
|
||||
public readonly Map map;
|
||||
readonly TreeCache treeCache;
|
||||
public readonly TerrainRenderer terrain;
|
||||
public readonly Viewport viewport;
|
||||
public readonly PathFinder pathFinder;
|
||||
public readonly Network network;
|
||||
public readonly WorldRenderer worldRenderer;
|
||||
public readonly Controller controller;
|
||||
public static World world;
|
||||
public static Map map;
|
||||
static TreeCache treeCache;
|
||||
public static TerrainRenderer terrain;
|
||||
public static Viewport viewport;
|
||||
public static PathFinder pathFinder;
|
||||
public static Network network;
|
||||
public static WorldRenderer worldRenderer;
|
||||
public static Controller controller;
|
||||
|
||||
int localPlayerIndex = 0;
|
||||
static int localPlayerIndex = 0;
|
||||
|
||||
public readonly Dictionary<int, Player> players = new Dictionary<int, Player>();
|
||||
public static Dictionary<int, Player> players = new Dictionary<int, Player>();
|
||||
|
||||
public Player LocalPlayer { get { return players[localPlayerIndex]; } }
|
||||
public BuildingInfluenceMap LocalPlayerBuildings;
|
||||
public static Player LocalPlayer { get { return players[localPlayerIndex]; } }
|
||||
public static BuildingInfluenceMap LocalPlayerBuildings;
|
||||
|
||||
ISoundEngine soundEngine;
|
||||
static ISoundEngine soundEngine;
|
||||
|
||||
public Game(string mapName, Renderer renderer, int2 clientSize)
|
||||
public static void Initialize(string mapName, Renderer renderer, int2 clientSize)
|
||||
{
|
||||
Rules.LoadRules( mapName );
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace OpenRa.Game
|
||||
viewport = new Viewport(clientSize, map.Size, renderer);
|
||||
|
||||
terrain = new TerrainRenderer(renderer, map, viewport);
|
||||
world = new World(this);
|
||||
world = new World();
|
||||
treeCache = new TreeCache(map);
|
||||
|
||||
foreach( TreeReference treeReference in map.Trees )
|
||||
@@ -61,8 +61,8 @@ namespace OpenRa.Game
|
||||
|
||||
network = new Network();
|
||||
|
||||
controller = new Controller(this); // CAREFUL THERES AN UGLY HIDDEN DEPENDENCY HERE STILL
|
||||
worldRenderer = new WorldRenderer(renderer, this);
|
||||
controller = new Controller();
|
||||
worldRenderer = new WorldRenderer(renderer);
|
||||
|
||||
soundEngine = new ISoundEngine();
|
||||
sounds = new Cache<string, ISoundSource>(LoadSound);
|
||||
@@ -70,7 +70,7 @@ namespace OpenRa.Game
|
||||
PlaySound("intro.aud", false);
|
||||
}
|
||||
|
||||
void LoadMapBuildings( IniFile mapfile )
|
||||
static void LoadMapBuildings( IniFile mapfile )
|
||||
{
|
||||
foreach( var s in mapfile.GetSection( "STRUCTURES", true ) )
|
||||
{
|
||||
@@ -81,7 +81,7 @@ namespace OpenRa.Game
|
||||
}
|
||||
}
|
||||
|
||||
void LoadMapUnits( IniFile mapfile )
|
||||
static void LoadMapUnits( IniFile mapfile )
|
||||
{
|
||||
foreach( var s in mapfile.GetSection( "UNITS", true ) )
|
||||
{
|
||||
@@ -92,9 +92,9 @@ namespace OpenRa.Game
|
||||
}
|
||||
}
|
||||
|
||||
readonly Cache<string, ISoundSource> sounds;
|
||||
static Cache<string, ISoundSource> sounds;
|
||||
|
||||
ISoundSource LoadSound(string filename)
|
||||
static ISoundSource LoadSound(string filename)
|
||||
{
|
||||
var data = AudLoader.LoadSound(FileSystem.Open(filename));
|
||||
return soundEngine.AddSoundSourceFromPCMData(data, filename,
|
||||
@@ -107,14 +107,14 @@ namespace OpenRa.Game
|
||||
});
|
||||
}
|
||||
|
||||
public void PlaySound(string name, bool loop)
|
||||
public static void PlaySound(string name, bool loop)
|
||||
{
|
||||
var sound = sounds[name];
|
||||
// todo: positioning
|
||||
soundEngine.Play2D(sound, loop, false, false);
|
||||
}
|
||||
|
||||
public void Tick()
|
||||
public static void Tick()
|
||||
{
|
||||
var stuffFromOtherPlayers = network.Tick(); // todo: actually use the orders!
|
||||
world.Update();
|
||||
@@ -122,7 +122,7 @@ namespace OpenRa.Game
|
||||
viewport.DrawRegions();
|
||||
}
|
||||
|
||||
public bool IsCellBuildable(int2 a)
|
||||
public static bool IsCellBuildable(int2 a)
|
||||
{
|
||||
if (LocalPlayerBuildings[a] != null) return false;
|
||||
|
||||
@@ -133,7 +133,7 @@ namespace OpenRa.Game
|
||||
terrain.tileSet.GetWalkability(map.MapTiles[a.X, a.Y])) < double.PositiveInfinity;
|
||||
}
|
||||
|
||||
IEnumerable<Actor> FindUnits(float2 a, float2 b)
|
||||
static IEnumerable<Actor> FindUnits(float2 a, float2 b)
|
||||
{
|
||||
var min = float2.Min(a, b);
|
||||
var max = float2.Max(a, b);
|
||||
@@ -144,12 +144,12 @@ namespace OpenRa.Game
|
||||
.Where(x => x.Bounds.IntersectsWith(rect));
|
||||
}
|
||||
|
||||
public IEnumerable<Actor> SelectUnitsInBox(float2 a, float2 b)
|
||||
public static IEnumerable<Actor> SelectUnitsInBox(float2 a, float2 b)
|
||||
{
|
||||
return FindUnits(a, b).Where(x => x.Owner == LocalPlayer && x.traits.Contains<Traits.Mobile>());
|
||||
}
|
||||
|
||||
public IEnumerable<Actor> SelectUnitOrBuilding(float2 a)
|
||||
public static IEnumerable<Actor> SelectUnitOrBuilding(float2 a)
|
||||
{
|
||||
var q = FindUnits(a, a);
|
||||
return q.Where(x => x.traits.Contains<Traits.Mobile>()).Concat(q).Take(1);
|
||||
|
||||
@@ -44,6 +44,8 @@ namespace OpenRa.Game.Graphics
|
||||
};
|
||||
Sprite[][] overlaySprites;
|
||||
|
||||
Sprite[] smudgeSprites;
|
||||
|
||||
SpriteRenderer spriteRenderer;
|
||||
Map map;
|
||||
|
||||
@@ -53,8 +55,12 @@ namespace OpenRa.Game.Graphics
|
||||
this.map = map;
|
||||
|
||||
overlaySprites = new Sprite[ overlaySpriteNames.Length ][];
|
||||
for( int i = 0 ; i < overlaySpriteNames.Length ; i++ )
|
||||
overlaySprites[ i ] = SpriteSheetBuilder.LoadAllSprites( overlaySpriteNames[ i ], ".shp", ".tem", ".sno" );
|
||||
for (int i = 0; i < overlaySpriteNames.Length; i++)
|
||||
overlaySprites[i] = SpriteSheetBuilder.LoadAllSprites(overlaySpriteNames[i], ".shp", ".tem", ".sno");
|
||||
|
||||
/* todo: add the rest of the smudge sprites */
|
||||
smudgeSprites = new[] { "bib3", "bib2" }.SelectMany(
|
||||
f => SpriteSheetBuilder.LoadAllSprites(f, ".shp", ".tem", ".sno")).ToArray();
|
||||
}
|
||||
|
||||
public void Draw()
|
||||
@@ -62,7 +68,15 @@ namespace OpenRa.Game.Graphics
|
||||
for( int y = 0 ; y < 128 ; y++ )
|
||||
for (int x = 0; x < 128; x++)
|
||||
{
|
||||
var o = map.MapTiles[x, y].overlay;
|
||||
var tr = map.MapTiles[x,y];
|
||||
if (tr.smudge != 0 && tr.smudge <= smudgeSprites.Length)
|
||||
{
|
||||
var location = new int2(x, y);
|
||||
spriteRenderer.DrawSprite(smudgeSprites[tr.smudge - 1],
|
||||
Game.CellSize * (float2)(location - map.Offset), 0);
|
||||
}
|
||||
|
||||
var o = tr.overlay;
|
||||
if (o < overlaySprites.Length)
|
||||
{
|
||||
var location = new int2(x, y);
|
||||
|
||||
@@ -10,23 +10,21 @@ namespace OpenRa.Game.Graphics
|
||||
{
|
||||
public readonly SpriteRenderer spriteRenderer;
|
||||
public readonly LineRenderer lineRenderer;
|
||||
public readonly Game game;
|
||||
public readonly Region region;
|
||||
public readonly UiOverlay uiOverlay;
|
||||
|
||||
public WorldRenderer(Renderer renderer, Game game)
|
||||
public WorldRenderer(Renderer renderer)
|
||||
{
|
||||
// TODO: this is layout policy. it belongs at a higher level than this.
|
||||
this.game = game;
|
||||
region = Region.Create(game.viewport, DockStyle.Left,
|
||||
game.viewport.Width - 128, Draw,
|
||||
game.controller.HandleMouseInput);
|
||||
region = Region.Create(Game.viewport, DockStyle.Left,
|
||||
Game.viewport.Width - 128, Draw,
|
||||
Game.controller.HandleMouseInput);
|
||||
|
||||
game.viewport.AddRegion(region);
|
||||
Game.viewport.AddRegion(region);
|
||||
|
||||
spriteRenderer = new SpriteRenderer(renderer, true);
|
||||
lineRenderer = new LineRenderer(renderer);
|
||||
uiOverlay = new UiOverlay(spriteRenderer, game);
|
||||
uiOverlay = new UiOverlay(spriteRenderer);
|
||||
}
|
||||
|
||||
void DrawSpriteList(Player owner, RectangleF rect,
|
||||
@@ -50,20 +48,20 @@ namespace OpenRa.Game.Graphics
|
||||
|
||||
public void Draw()
|
||||
{
|
||||
var rect = new RectangleF((region.Position + game.viewport.Location).ToPointF(),
|
||||
var rect = new RectangleF((region.Position + Game.viewport.Location).ToPointF(),
|
||||
region.Size.ToSizeF());
|
||||
|
||||
foreach (Actor a in game.world.Actors)
|
||||
foreach (Actor a in Game.world.Actors)
|
||||
DrawSpriteList(a.Owner, rect, a.Render());
|
||||
|
||||
foreach (IEffect e in game.world.Effects)
|
||||
foreach (IEffect e in Game.world.Effects)
|
||||
DrawSpriteList(e.Owner, rect, e.Render());
|
||||
|
||||
uiOverlay.Draw();
|
||||
|
||||
spriteRenderer.Flush();
|
||||
|
||||
var selbox = game.controller.SelectionBox;
|
||||
var selbox = Game.controller.SelectionBox;
|
||||
if (selbox != null)
|
||||
{
|
||||
var a = selbox.Value.First;
|
||||
@@ -75,13 +73,13 @@ namespace OpenRa.Game.Graphics
|
||||
lineRenderer.DrawLine(a + b + c, a + c, Color.White, Color.White);
|
||||
lineRenderer.DrawLine(a, a + c, Color.White, Color.White);
|
||||
|
||||
foreach (var u in game.SelectUnitsInBox(selbox.Value.First, selbox.Value.Second))
|
||||
foreach (var u in Game.SelectUnitsInBox(selbox.Value.First, selbox.Value.Second))
|
||||
DrawSelectionBox(u, Color.Yellow, false);
|
||||
}
|
||||
|
||||
var selection = game.controller.orderGenerator as UnitOrderGenerator;
|
||||
var selection = Game.controller.orderGenerator as UnitOrderGenerator;
|
||||
if (selection != null)
|
||||
foreach( var a in game.world.Actors.Intersect(selection.selection) ) /* make sure we don't grab actors that are dead */
|
||||
foreach( var a in Game.world.Actors.Intersect(selection.selection) ) /* make sure we don't grab actors that are dead */
|
||||
DrawSelectionBox(a, Color.White, true);
|
||||
|
||||
lineRenderer.Flush();
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace OpenRa.Game
|
||||
{
|
||||
interface IOrderGenerator
|
||||
{
|
||||
IEnumerable<Order> Order( Game game, int2 xy );
|
||||
void PrepareOverlay( Game game, int2 xy );
|
||||
IEnumerable<Order> Order( int2 xy );
|
||||
void PrepareOverlay( int2 xy );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,18 +2,18 @@ using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
using OpenRa.FileFormats;
|
||||
using OpenRa.Game.Graphics;
|
||||
using OpenRa.TechTree;
|
||||
using OpenRa.TechTree;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace OpenRa.Game
|
||||
{
|
||||
using GRegion = OpenRa.Game.Graphics.Region;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
|
||||
class MainWindow : Form
|
||||
{
|
||||
readonly Renderer renderer;
|
||||
|
||||
Game game;
|
||||
public readonly Sidebar sidebar;
|
||||
|
||||
static Size GetResolution(Settings settings)
|
||||
@@ -50,37 +50,36 @@ using System.Runtime.InteropServices;
|
||||
renderer = new Renderer(this, GetResolution(settings), windowed);
|
||||
SheetBuilder.Initialize(renderer);
|
||||
|
||||
game = new Game(settings.GetValue("map", "scg11eb.ini"), renderer, new int2(ClientSize));
|
||||
Game.Initialize(settings.GetValue("map", "scg11eb.ini"), renderer, new int2(ClientSize));
|
||||
|
||||
SequenceProvider.ForcePrecache();
|
||||
Traits.RenderBuilding.Prefetch();
|
||||
|
||||
game.world.Add( new Actor( "mcv", new int2( 5, 5 ), game.players[ 3 ]) );
|
||||
game.world.Add( new Actor( "mcv", new int2( 7, 5 ), game.players[ 2 ] ) );
|
||||
game.world.Add( new Actor( "mcv", new int2( 9, 5 ), game.players[ 0 ] ) );
|
||||
var jeep = new Actor( "jeep", new int2( 9, 7 ), game.players[ 1 ] );
|
||||
game.world.Add( jeep );
|
||||
var tank = new Actor( "3tnk", new int2( 12, 7 ), game.players[ 1 ] );
|
||||
game.world.Add( tank );
|
||||
Game.world.Add( new Actor( "mcv", new int2( 5, 5 ), Game.players[ 3 ]) );
|
||||
Game.world.Add( new Actor( "mcv", new int2( 7, 5 ), Game.players[ 2 ] ) );
|
||||
Game.world.Add( new Actor( "mcv", new int2( 9, 5 ), Game.players[ 0 ] ) );
|
||||
var jeep = new Actor( "jeep", new int2( 9, 7 ), Game.players[ 1 ] );
|
||||
Game.world.Add( jeep );
|
||||
var tank = new Actor( "3tnk", new int2( 12, 7 ), Game.players[ 1 ] );
|
||||
Game.world.Add( tank );
|
||||
tank.traits.Get<Traits.AttackTurreted>().target = jeep;
|
||||
|
||||
sidebar = new Sidebar(renderer, game);
|
||||
sidebar = new Sidebar(renderer);
|
||||
|
||||
renderer.BuildPalette(game.map);
|
||||
renderer.BuildPalette(Game.map);
|
||||
|
||||
ShowCursor(false);
|
||||
|
||||
game.world.ResetTimer();
|
||||
Game.world.ResetTimer();
|
||||
}
|
||||
|
||||
internal void Run()
|
||||
{
|
||||
while (Created && Visible)
|
||||
{
|
||||
game.Tick();
|
||||
Game.Tick();
|
||||
|
||||
// rude hack
|
||||
game.viewport.cursor = game.controller.ChooseCursor();
|
||||
Game.viewport.cursor = Game.controller.ChooseCursor();
|
||||
|
||||
Application.DoEvents();
|
||||
}
|
||||
@@ -93,7 +92,7 @@ using System.Runtime.InteropServices;
|
||||
base.OnMouseDown(e);
|
||||
lastPos = new int2(e.Location);
|
||||
|
||||
game.viewport.DispatchMouseInput(new MouseInput
|
||||
Game.viewport.DispatchMouseInput(new MouseInput
|
||||
{
|
||||
Button = e.Button,
|
||||
Event = MouseInputEvent.Down,
|
||||
@@ -108,27 +107,27 @@ using System.Runtime.InteropServices;
|
||||
if (e.Button == MouseButtons.Middle)
|
||||
{
|
||||
int2 p = new int2(e.Location);
|
||||
game.viewport.Scroll(lastPos - p);
|
||||
Game.viewport.Scroll(lastPos - p);
|
||||
lastPos = p;
|
||||
}
|
||||
|
||||
game.viewport.DispatchMouseInput(new MouseInput
|
||||
Game.viewport.DispatchMouseInput(new MouseInput
|
||||
{
|
||||
Button = e.Button,
|
||||
Event = MouseInputEvent.Move,
|
||||
Location = new int2(e.Location)
|
||||
});
|
||||
|
||||
if (game.controller.orderGenerator != null)
|
||||
game.controller.orderGenerator.PrepareOverlay(game,
|
||||
((1 / 24f) * (new float2(e.Location) + game.viewport.Location)).ToInt2());
|
||||
if (Game.controller.orderGenerator != null)
|
||||
Game.controller.orderGenerator.PrepareOverlay(
|
||||
((1 / 24f) * (new float2(e.Location) + Game.viewport.Location)).ToInt2());
|
||||
}
|
||||
|
||||
protected override void OnMouseUp(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseUp(e);
|
||||
|
||||
game.viewport.DispatchMouseInput(new MouseInput
|
||||
Game.viewport.DispatchMouseInput(new MouseInput
|
||||
{
|
||||
Button = e.Button,
|
||||
Event = MouseInputEvent.Up,
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace OpenRa.Game
|
||||
{
|
||||
abstract class Order
|
||||
{
|
||||
public abstract void Apply( Game game, bool leftMButton );
|
||||
public abstract void Apply( bool leftMButton );
|
||||
}
|
||||
|
||||
class MoveOrder : Order
|
||||
@@ -20,11 +20,11 @@ namespace OpenRa.Game
|
||||
this.Destination = destination;
|
||||
}
|
||||
|
||||
public override void Apply( Game game, bool leftMouseButton )
|
||||
public override void Apply( bool leftMouseButton )
|
||||
{
|
||||
if (leftMouseButton) return;
|
||||
if (game.LocalPlayer == Unit.Owner)
|
||||
game.PlaySound("ackno.r00", false);
|
||||
if (Game.LocalPlayer == Unit.Owner)
|
||||
Game.PlaySound("ackno.r00", false);
|
||||
var mobile = Unit.traits.Get<Traits.Mobile>();
|
||||
mobile.destination = Destination;
|
||||
mobile.desiredFacing = null;
|
||||
@@ -42,7 +42,7 @@ namespace OpenRa.Game
|
||||
Location = location;
|
||||
}
|
||||
|
||||
public override void Apply( Game game, bool leftMouseButton )
|
||||
public override void Apply( bool leftMouseButton )
|
||||
{
|
||||
if (leftMouseButton) return;
|
||||
Unit.traits.Get<Traits.McvDeploy>().DeployLocation = Location;
|
||||
|
||||
@@ -17,7 +17,6 @@ namespace OpenRa.Game
|
||||
|
||||
SpriteRenderer spriteRenderer, clockRenderer;
|
||||
Sprite blank;
|
||||
Game game;
|
||||
readonly GRegion region;
|
||||
|
||||
public GRegion Region { get { return region; } }
|
||||
@@ -34,13 +33,12 @@ namespace OpenRa.Game
|
||||
|
||||
List<SidebarItem> items = new List<SidebarItem>();
|
||||
|
||||
public Sidebar( Renderer renderer, Game game )
|
||||
public Sidebar( Renderer renderer )
|
||||
{
|
||||
this.techTree = game.LocalPlayer.TechTree;
|
||||
this.techTree = Game.LocalPlayer.TechTree;
|
||||
this.techTree.BuildableItemsChanged += PopulateItemList;
|
||||
this.game = game;
|
||||
region = GRegion.Create(game.viewport, DockStyle.Right, 128, Paint, MouseHandler);
|
||||
game.viewport.AddRegion( region );
|
||||
region = GRegion.Create(Game.viewport, DockStyle.Right, 128, Paint, MouseHandler);
|
||||
Game.viewport.AddRegion( region );
|
||||
spriteRenderer = new SpriteRenderer(renderer, false);
|
||||
clockRenderer = new SpriteRenderer(renderer, true);
|
||||
|
||||
@@ -63,7 +61,8 @@ namespace OpenRa.Game
|
||||
public void Build(SidebarItem item)
|
||||
{
|
||||
if (item != null)
|
||||
game.controller.orderGenerator = new PlaceBuilding(game.LocalPlayer, item.techTreeItem.tag.ToLowerInvariant());
|
||||
Game.controller.orderGenerator = new PlaceBuilding(Game.LocalPlayer,
|
||||
item.techTreeItem.tag.ToLowerInvariant());
|
||||
}
|
||||
|
||||
void LoadSprites( string category, string group )
|
||||
@@ -186,15 +185,15 @@ namespace OpenRa.Game
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public IEnumerable<Order> Order( Game game, int2 xy )
|
||||
public IEnumerable<Order> Order( int2 xy )
|
||||
{
|
||||
// todo: check that space is free
|
||||
yield return new PlaceBuildingOrder( this, xy );
|
||||
}
|
||||
|
||||
public void PrepareOverlay(Game game, int2 xy)
|
||||
public void PrepareOverlay(int2 xy)
|
||||
{
|
||||
game.worldRenderer.uiOverlay.SetCurrentOverlay(xy, Name);
|
||||
Game.worldRenderer.uiOverlay.SetCurrentOverlay(xy, Name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -209,11 +208,11 @@ namespace OpenRa.Game
|
||||
this.xy = xy;
|
||||
}
|
||||
|
||||
public override void Apply(Game game, bool leftMouseButton)
|
||||
public override void Apply(bool leftMouseButton)
|
||||
{
|
||||
if (leftMouseButton)
|
||||
{
|
||||
game.world.AddFrameEndTask(_ =>
|
||||
Game.world.AddFrameEndTask(_ =>
|
||||
{
|
||||
Log.Write("Player \"{0}\" builds {1}", building.Owner.PlayerName, building.Name);
|
||||
|
||||
@@ -224,18 +223,18 @@ namespace OpenRa.Game
|
||||
if (row.Length > maxWidth)
|
||||
maxWidth = row.Length;
|
||||
|
||||
game.world.Add(new Actor(building.Name, xy - new int2(maxWidth / 2, footprint.Length / 2), building.Owner));
|
||||
Game.world.Add(new Actor(building.Name, xy - new int2(maxWidth / 2, footprint.Length / 2), building.Owner));
|
||||
|
||||
game.controller.orderGenerator = null;
|
||||
game.worldRenderer.uiOverlay.KillOverlay();
|
||||
Game.controller.orderGenerator = null;
|
||||
Game.worldRenderer.uiOverlay.KillOverlay();
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
game.world.AddFrameEndTask(_ =>
|
||||
Game.world.AddFrameEndTask(_ =>
|
||||
{
|
||||
game.controller.orderGenerator = null;
|
||||
game.worldRenderer.uiOverlay.KillOverlay();
|
||||
Game.controller.orderGenerator = null;
|
||||
Game.worldRenderer.uiOverlay.KillOverlay();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace OpenRa.Game.Traits
|
||||
self.traits.Get<Turreted>();
|
||||
}
|
||||
|
||||
public void Tick( Actor self, Game game )
|
||||
public void Tick( Actor self )
|
||||
{
|
||||
if( primaryFireDelay > 0 )
|
||||
--primaryFireDelay;
|
||||
@@ -33,16 +33,16 @@ namespace OpenRa.Game.Traits
|
||||
if( turreted.desiredFacing != turreted.turretFacing )
|
||||
return;
|
||||
|
||||
if( self.unitInfo.Primary != null && CheckFire( self, game, self.unitInfo.Primary, ref primaryFireDelay ) )
|
||||
if( self.unitInfo.Primary != null && CheckFire( self, self.unitInfo.Primary, ref primaryFireDelay ) )
|
||||
{
|
||||
secondaryFireDelay = Math.Max( 4, secondaryFireDelay );
|
||||
return;
|
||||
}
|
||||
if( self.unitInfo.Secondary != null && CheckFire( self, game, self.unitInfo.Secondary, ref secondaryFireDelay ) )
|
||||
if( self.unitInfo.Secondary != null && CheckFire( self, self.unitInfo.Secondary, ref secondaryFireDelay ) )
|
||||
return;
|
||||
}
|
||||
|
||||
bool CheckFire( Actor self, Game game, string weaponName, ref int fireDelay )
|
||||
bool CheckFire( Actor self, string weaponName, ref int fireDelay )
|
||||
{
|
||||
if( fireDelay > 0 )
|
||||
return false;
|
||||
@@ -54,7 +54,10 @@ namespace OpenRa.Game.Traits
|
||||
// FIXME: rules specifies ROF in 1/15 sec units; ticks are 1/25 sec
|
||||
fireDelay = weapon.ROF;
|
||||
|
||||
game.world.Add( new Bullet( weaponName, self.Owner, self, self.CenterLocation.ToInt2(), target.CenterLocation.ToInt2(), game ) );
|
||||
Game.world.Add( new Bullet( weaponName, self.Owner, self,
|
||||
self.CenterLocation.ToInt2(),
|
||||
target.CenterLocation.ToInt2() ) );
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,9 +12,9 @@ namespace OpenRa.Game.Traits
|
||||
}
|
||||
|
||||
bool first = true;
|
||||
public void Tick(Actor self, Game game)
|
||||
public void Tick(Actor self)
|
||||
{
|
||||
if (first && self.Owner == game.LocalPlayer)
|
||||
if (first && self.Owner == Game.LocalPlayer)
|
||||
{
|
||||
self.Owner.TechTree.Build(self.unitInfo.Name, true);
|
||||
self.CenterLocation = Game.CellSize * (float2)self.Location + 0.5f * self.SelectedSize;
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace OpenRa.Game.Traits
|
||||
{
|
||||
}
|
||||
|
||||
public Order Order(Actor self, Game game, int2 xy)
|
||||
public Order Order(Actor self, int2 xy)
|
||||
{
|
||||
DeployLocation = null;
|
||||
// TODO: check that there's enough space at the destination.
|
||||
@@ -23,7 +23,7 @@ namespace OpenRa.Game.Traits
|
||||
return null;
|
||||
}
|
||||
|
||||
public void Tick(Actor self, Game game)
|
||||
public void Tick(Actor self)
|
||||
{
|
||||
if( self.Location != DeployLocation )
|
||||
return;
|
||||
@@ -36,10 +36,10 @@ namespace OpenRa.Game.Traits
|
||||
if( mobile.facing != mobile.desiredFacing )
|
||||
return;
|
||||
|
||||
game.world.AddFrameEndTask(_ =>
|
||||
Game.world.AddFrameEndTask(_ =>
|
||||
{
|
||||
game.world.Remove(self);
|
||||
game.world.Add(new Actor("fact", self.Location - new int2(1, 1), self.Owner));
|
||||
Game.world.Remove(self);
|
||||
Game.world.Add(new Actor("fact", self.Location - new int2(1, 1), self.Owner));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,13 +29,13 @@ namespace OpenRa.Game.Traits
|
||||
self.CenterLocation = new float2(12, 12) + Game.CellSize * float2.Lerp(fromCell, toCell, fraction);
|
||||
}
|
||||
|
||||
public void Tick(Actor self, Game game)
|
||||
public void Tick(Actor self)
|
||||
{
|
||||
Move(self, game);
|
||||
Move(self);
|
||||
UpdateCenterLocation();
|
||||
}
|
||||
|
||||
void Move(Actor self, Game game)
|
||||
void Move(Actor self)
|
||||
{
|
||||
if( fromCell != toCell )
|
||||
desiredFacing = Util.GetFacing( toCell - fromCell, facing );
|
||||
@@ -60,7 +60,7 @@ namespace OpenRa.Game.Traits
|
||||
if (destination == toCell)
|
||||
return;
|
||||
|
||||
List<int2> res = game.pathFinder.FindUnitPath(toCell, PathFinder.DefaultEstimator(destination));
|
||||
List<int2> res = Game.pathFinder.FindUnitPath(toCell, PathFinder.DefaultEstimator(destination));
|
||||
if (res.Count != 0)
|
||||
{
|
||||
self.Location = res[res.Count - 1];
|
||||
@@ -72,12 +72,11 @@ namespace OpenRa.Game.Traits
|
||||
destination = toCell;
|
||||
}
|
||||
|
||||
public Order Order(Actor self, Game game, int2 xy)
|
||||
public Order Order(Actor self, int2 xy)
|
||||
{
|
||||
if (xy != toCell)
|
||||
{
|
||||
return new MoveOrder(self, xy);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,47 +5,43 @@ using System.Text;
|
||||
using IjwFramework.Types;
|
||||
using OpenRa.Game.Graphics;
|
||||
using OpenRa.Game.GameRules;
|
||||
using OpenRa.FileFormats;
|
||||
using OpenRa.Game;
|
||||
|
||||
namespace OpenRa.Game.Traits
|
||||
{
|
||||
class RenderBuilding : RenderSimple
|
||||
{
|
||||
static Sprite[] largeBib;
|
||||
static Sprite[] smallBib;
|
||||
|
||||
static int2[] largeBibPos = new[] { new int2(0,0), new int2(1,0), new int2(2,0),
|
||||
new int2(0,1), new int2(1,1), new int2(2,1) };
|
||||
|
||||
static int2[] smallBibPos = new[] { new int2(0,0), new int2(1,0),
|
||||
new int2(0,1), new int2(1,1)};
|
||||
const int SmallBibStart = 1;
|
||||
const int LargeBibStart = 5;
|
||||
|
||||
public RenderBuilding(Actor self)
|
||||
: base(self)
|
||||
{
|
||||
anim.PlayThen("make", () => anim.PlayRepeating("idle"));
|
||||
}
|
||||
|
||||
public static void Prefetch()
|
||||
{
|
||||
largeBib = SpriteSheetBuilder.LoadAllSprites("bib2.", "tem", "sno", "int");
|
||||
smallBib = SpriteSheetBuilder.LoadAllSprites("bib3.", "tem", "sno", "int");
|
||||
// at this point, we already know where we are, so we can safely place the bib in the smudge
|
||||
if (((UnitInfo.BuildingInfo)self.unitInfo).Bib)
|
||||
{
|
||||
var fp = Rules.Footprint.GetFootprint(self.unitInfo.Name);
|
||||
var bibOffset = fp.Length - 2;
|
||||
var hasSmallBib = fp.First().Length == 2;
|
||||
|
||||
if (hasSmallBib)
|
||||
for (int i = 0; i < 4; i++)
|
||||
Game.map.MapTiles[
|
||||
self.Location.X + i % 2 + Game.map.Offset.X,
|
||||
self.Location.Y + i / 2 + Game.map.Offset.Y + bibOffset].smudge = (byte)(i + SmallBibStart);
|
||||
else
|
||||
for (int i = 0; i < 6; i++)
|
||||
Game.map.MapTiles[
|
||||
self.Location.X + i % 3 + Game.map.Offset.X,
|
||||
self.Location.Y + i / 3 + Game.map.Offset.Y + bibOffset].smudge = (byte)(i + LargeBibStart);
|
||||
}
|
||||
}
|
||||
|
||||
public override IEnumerable<Pair<Sprite, float2>> Render(Actor self)
|
||||
{
|
||||
if (((UnitInfo.BuildingInfo)self.unitInfo).Bib)
|
||||
{
|
||||
var fp = Rules.Footprint.GetFootprint(self.unitInfo.Name );
|
||||
var bibOffset = new int2(0, fp.Length - 2);
|
||||
var hasSmallBib = fp.First().Length == 2;
|
||||
|
||||
var bib = hasSmallBib ? smallBib : largeBib;
|
||||
var bibPos = hasSmallBib ? smallBibPos : largeBibPos;
|
||||
|
||||
for (int i = 0; i < bib.Length; i++)
|
||||
yield return Pair.New(bib[i], 24f * (float2)(self.Location + bibOffset + bibPos[i]));
|
||||
}
|
||||
|
||||
yield return Pair.New(anim.Image, 24f * (float2)self.Location);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,9 +33,9 @@ namespace OpenRa.Game.Traits
|
||||
return base.Render(self);
|
||||
}
|
||||
|
||||
public override void Tick(Actor self, Game game)
|
||||
public override void Tick(Actor self)
|
||||
{
|
||||
base.Tick(self, game);
|
||||
base.Tick(self);
|
||||
roof.Tick();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace OpenRa.Game.Traits
|
||||
|
||||
public abstract IEnumerable<Pair<Sprite, float2>> Render(Actor self);
|
||||
|
||||
public virtual void Tick(Actor self, Game game)
|
||||
public virtual void Tick(Actor self)
|
||||
{
|
||||
anim.Tick();
|
||||
}
|
||||
|
||||
@@ -25,9 +25,9 @@ namespace OpenRa.Game.Traits
|
||||
yield return Centered(turretAnim.Image, self.CenterLocation);
|
||||
}
|
||||
|
||||
public override void Tick(Actor self, Game game)
|
||||
public override void Tick(Actor self)
|
||||
{
|
||||
base.Tick(self, game);
|
||||
base.Tick(self);
|
||||
turretAnim.Tick();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ using IjwFramework.Types;
|
||||
|
||||
namespace OpenRa.Game.Traits
|
||||
{
|
||||
interface ITick { void Tick(Actor self, Game game); }
|
||||
interface ITick { void Tick(Actor self); }
|
||||
interface IRender { IEnumerable<Pair<Sprite, float2>> Render(Actor self); }
|
||||
interface IOrder { Order Order(Actor self, Game game, int2 xy); }
|
||||
interface IOrder { Order Order(Actor self, int2 xy); }
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace OpenRa.Game.Traits
|
||||
{
|
||||
}
|
||||
|
||||
public void Tick( Actor self, Game game )
|
||||
public void Tick( Actor self )
|
||||
{
|
||||
var df = desiredFacing ?? ( self.traits.Contains<Mobile>() ? self.traits.Get<Mobile>().facing : turretFacing );
|
||||
Util.TickFacing( ref turretFacing, df, self.unitInfo.ROT );
|
||||
|
||||
@@ -10,12 +10,10 @@ namespace OpenRa.Game
|
||||
SpriteRenderer spriteRenderer;
|
||||
Sprite buildOk;
|
||||
Sprite buildBlocked;
|
||||
Game game;
|
||||
|
||||
public UiOverlay(SpriteRenderer spriteRenderer, Game game)
|
||||
public UiOverlay(SpriteRenderer spriteRenderer)
|
||||
{
|
||||
this.spriteRenderer = spriteRenderer;
|
||||
this.game = game;
|
||||
|
||||
buildOk = SynthesizeTile(0x80);
|
||||
buildBlocked = SynthesizeTile(0xe6);
|
||||
@@ -38,7 +36,7 @@ namespace OpenRa.Game
|
||||
return;
|
||||
|
||||
foreach (var t in Footprint.Tiles(name,position))
|
||||
spriteRenderer.DrawSprite(game.IsCellBuildable(t) ? buildOk : buildBlocked, Game.CellSize * t, 0);
|
||||
spriteRenderer.DrawSprite(Game.IsCellBuildable(t) ? buildOk : buildBlocked, Game.CellSize * t, 0);
|
||||
|
||||
spriteRenderer.Flush();
|
||||
}
|
||||
|
||||
@@ -14,16 +14,16 @@ namespace OpenRa.Game
|
||||
selection = selected.ToList();
|
||||
}
|
||||
|
||||
public IEnumerable<Order> Order( Game game, int2 xy )
|
||||
public IEnumerable<Order> Order( int2 xy )
|
||||
{
|
||||
foreach( var unit in selection )
|
||||
{
|
||||
var ret = unit.Order( game, xy );
|
||||
var ret = unit.Order( xy );
|
||||
if( ret != null )
|
||||
yield return ret;
|
||||
}
|
||||
}
|
||||
|
||||
public void PrepareOverlay( Game game, int2 xy ) { }
|
||||
public void PrepareOverlay( int2 xy ) { }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,12 +10,9 @@ namespace OpenRa.Game
|
||||
List<Actor> actors = new List<Actor>();
|
||||
List<IEffect> effects = new List<IEffect>();
|
||||
List<Action<World>> frameEndActions = new List<Action<World>>();
|
||||
readonly Game game;
|
||||
int lastTime = Environment.TickCount;
|
||||
const int timestep = 40;
|
||||
|
||||
public World(Game game) { this.game = game; }
|
||||
|
||||
public void Add(Actor a) { actors.Add(a); ActorAdded(a); }
|
||||
public void Remove(Actor a) { actors.Remove(a); ActorRemoved(a); }
|
||||
|
||||
@@ -35,17 +32,15 @@ namespace OpenRa.Game
|
||||
public void Update()
|
||||
{
|
||||
int t = Environment.TickCount;
|
||||
int dt = t - lastTime;
|
||||
if( dt >= timestep )
|
||||
{
|
||||
lastTime += timestep;
|
||||
|
||||
foreach( var a in actors )
|
||||
a.Tick(game);
|
||||
foreach (var b in effects)
|
||||
b.Tick(game);
|
||||
|
||||
Renderer.waterFrame += 0.00125f * timestep;
|
||||
int dt = t - lastTime;
|
||||
if (dt >= timestep)
|
||||
{
|
||||
lastTime += timestep;
|
||||
|
||||
foreach (var a in actors) a.Tick();
|
||||
foreach (var e in effects) e.Tick();
|
||||
|
||||
Renderer.waterFrame += 0.00125f * timestep;
|
||||
}
|
||||
|
||||
foreach (Action<World> a in frameEndActions) a(this);
|
||||
|
||||
Reference in New Issue
Block a user