diff --git a/OpenRa.FileFormats/Map.cs b/OpenRa.FileFormats/Map.cs index aa6da63604..99916e58ab 100644 --- a/OpenRa.FileFormats/Map.cs +++ b/OpenRa.FileFormats/Map.cs @@ -124,7 +124,6 @@ namespace OpenRa.FileFormats for( int i = 0 ; i < 128 ; i++ ) for( int j = 0 ; j < 128 ; j++ ) MapTiles[ j, i ].overlay = ReadByte( ms ); - } void ReadTrees( IniFile file ) diff --git a/OpenRa.Game/Actor.cs b/OpenRa.Game/Actor.cs index c7b5ac4f81..270ac07df1 100755 --- a/OpenRa.Game/Actor.cs +++ b/OpenRa.Game/Actor.cs @@ -21,7 +21,7 @@ namespace OpenRa.Game public Actor( string name, int2 location, Player owner ) { unitInfo = Rules.UnitInfo.Get( name ); - Location = location; + Location = location; CenterLocation = new float2( 12, 12 ) + 24 * (float2)Location; Owner = owner; @@ -90,11 +90,11 @@ namespace OpenRa.Game case "ftur": traits.Add( new Traits.Building( this ) ); traits.Add( new Traits.RenderBuilding( this ) ); - break; - case "weap": - traits.Add( new Traits.Building( this ) ); - traits.Add( new Traits.RenderWarFactory( this ) ); - break; + break; + case "weap": + traits.Add( new Traits.Building( this ) ); + traits.Add( new Traits.RenderWarFactory( this ) ); + break; case "gun": case "agun": case "sam": @@ -117,8 +117,8 @@ namespace OpenRa.Game { foreach( var tick in traits.WithInterface() ) tick.Tick( this, game, dt ); - } - + } + public float2 CenterLocation; public float2 SelectedSize { get { return Render().FirstOrDefault().First.size; } } @@ -191,45 +191,45 @@ namespace OpenRa.Game { anim.PlayThen( "make", () => anim.PlayFetchIndex( "idle", () => self.traits.Get().turretFacing ) ); } - } - - class RenderWarFactory : RenderBuilding - { - public Animation roof; - bool doneBuilding; - - public RenderWarFactory( Actor self ) - : base( self ) - { - roof = new Animation( self.unitInfo.Name ); - anim.PlayThen( "make", () => - { - doneBuilding = true; - anim.Play( "idle" ); - roof.Play( "idle-top" ); - } ); - } - - public override IEnumerable> Render( Actor self ) - { - yield return Pair.New( anim.Image, 24f * (float2)self.Location ); - if( doneBuilding ) - yield return Pair.New( roof.Image, 24f * (float2)self.Location ); - } - - public override void Tick( Actor self, Game game, int dt ) - { - base.Tick( self, game, dt ); - roof.Tick( dt ); - } + } + + class RenderWarFactory : RenderBuilding + { + public Animation roof; + bool doneBuilding; + + public RenderWarFactory( Actor self ) + : base( self ) + { + roof = new Animation( self.unitInfo.Name ); + anim.PlayThen( "make", () => + { + doneBuilding = true; + anim.Play( "idle" ); + roof.Play( "idle-top" ); + } ); + } + + public override IEnumerable> Render( Actor self ) + { + yield return Pair.New( anim.Image, 24f * (float2)self.Location ); + if( doneBuilding ) + yield return Pair.New( roof.Image, 24f * (float2)self.Location ); + } + + public override void Tick( Actor self, Game game, int dt ) + { + base.Tick( self, game, dt ); + roof.Tick( dt ); + } } class RenderUnit : RenderSimple - { - public RenderUnit( Actor self ) - : base( self ) - { - anim.PlayFetchIndex( "idle", () => self.traits.Get().facing ); + { + public RenderUnit( Actor self ) + : base( self ) + { + anim.PlayFetchIndex( "idle", () => self.traits.Get().facing ); } protected static Pair Centered( Sprite s, float2 location ) @@ -319,20 +319,20 @@ namespace OpenRa.Game } return highest; - } - - void UpdateCenterLocation() - { - float fraction = ( moveFraction > 0 ) ? (float)moveFraction / moveFractionTotal : 0f; - self.CenterLocation = new float2( 12, 12 ) + 24 * float2.Lerp( fromCell, toCell, fraction ); + } + + void UpdateCenterLocation() + { + float fraction = ( moveFraction > 0 ) ? (float)moveFraction / moveFractionTotal : 0f; + self.CenterLocation = new float2( 12, 12 ) + 24 * float2.Lerp( fromCell, toCell, fraction ); } public void Tick( Actor self, Game game, int dt ) - { - Move( self, game, dt ); + { + Move( self, game, dt ); UpdateCenterLocation(); - } - + } + void Move( Actor self, Game game, int dt ) { if( fromCell != toCell ) @@ -424,16 +424,16 @@ namespace OpenRa.Game class Building : ITick { public Building( Actor self ) - { + { } bool first = true; public void Tick( Actor self, Game game, int dt ) - { - if( first && self.Owner == game.LocalPlayer ) - { - self.Owner.TechTree.Build( self.unitInfo.Name, true ); - self.CenterLocation = 24 * (float2)self.Location + 0.5f * self.SelectedSize; + { + if( first && self.Owner == game.LocalPlayer ) + { + self.Owner.TechTree.Build( self.unitInfo.Name, true ); + self.CenterLocation = 24 * (float2)self.Location + 0.5f * self.SelectedSize; } first = false; } diff --git a/OpenRa.Game/Game.cs b/OpenRa.Game/Game.cs index b3ec25dce4..a97f177de1 100644 --- a/OpenRa.Game/Game.cs +++ b/OpenRa.Game/Game.cs @@ -30,7 +30,7 @@ namespace OpenRa.Game Rules.LoadRules(); for( int i = 0 ; i < 8 ; i++ ) - players.Add(i, new Player(i, string.Format("Multi{0}", i), OpenRa.TechTree.Race.Soviet)); + players.Add(i, new Player(i, string.Format("Multi{0}", i), OpenRa.TechTree.Race.Allies)); map = new Map(new IniFile(FileSystem.Open(mapName))); FileSystem.Mount(new Package(map.Theater + ".mix")); diff --git a/OpenRa.Game/Graphics/OverlayRenderer.cs b/OpenRa.Game/Graphics/OverlayRenderer.cs new file mode 100755 index 0000000000..50b7ce0e94 --- /dev/null +++ b/OpenRa.Game/Graphics/OverlayRenderer.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using OpenRa.FileFormats; + +namespace OpenRa.Game.Graphics +{ + class OverlayRenderer + { + static string[] overlaySpriteNames = new string[] + { + "sbag", "cycl", "brik", "fenc", "wood", + "gold01", "gold02", "gold03", "gold04", + "gem01", "gem02", "gem03", "gem04", + "v12", "v13", "v14", "v15", "v16", "v17", "v18", + "fpls", "wcrate", "scrate", "barb", "sbag" + }; + Sprite[][] overlaySprites; + + SpriteRenderer spriteRenderer; + Map map; + + public OverlayRenderer( Renderer renderer, Map map ) + { + this.spriteRenderer = new SpriteRenderer( renderer, true ); + 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" ); + } + + public void Draw() + { + for( int y = 0 ; y < 128 ; y++ ) + { + for( int x = 0 ; x < 128 ; x++ ) + { + if( map.MapTiles[ x, y ].overlay < overlaySprites.Length ) + { + var location = new int2( x, y ); + var sprites = overlaySprites[ map.MapTiles[ x, y ].overlay ]; + spriteRenderer.DrawSprite( sprites[ sprites.Length / 2-1 ], 24 * (float2)( location - map.Offset ), 0 ); + } + } + } + + spriteRenderer.Flush(); + } + } +} diff --git a/OpenRa.Game/Graphics/SpriteSheetBuilder.cs b/OpenRa.Game/Graphics/SpriteSheetBuilder.cs index 5813c74e4e..200ab655f1 100644 --- a/OpenRa.Game/Graphics/SpriteSheetBuilder.cs +++ b/OpenRa.Game/Graphics/SpriteSheetBuilder.cs @@ -5,16 +5,24 @@ namespace OpenRa.Game.Graphics { static class SpriteSheetBuilder { - static Dictionary sprites = - new Dictionary(); + static Dictionary sprites = + new Dictionary(); - public static Sprite LoadSprite(string filename) + public static Sprite LoadSprite(string filename, params string[] exts ) { - Sprite value; - if (!sprites.TryGetValue(filename, out value)) + return LoadAllSprites( filename, exts )[ 0 ]; + } + + public static Sprite[] LoadAllSprites( string filename, params string[] exts ) + { + Sprite[] value; + if( !sprites.TryGetValue( filename, out value ) ) { - ShpReader shp = new ShpReader(FileSystem.Open(filename)); - sprites.Add(filename, value = SheetBuilder.Add(shp[0].Image, shp.Size)); + ShpReader shp = new ShpReader( FileSystem.OpenWithExts( filename, exts ) ); + value = new Sprite[ shp.ImageCount ]; + for( int i = 0 ; i < shp.ImageCount ; i++ ) + value[ i ] = SheetBuilder.Add( shp[ i ].Image, shp.Size ); + sprites.Add( filename, value ); } return value; diff --git a/OpenRa.Game/Graphics/TerrainRenderer.cs b/OpenRa.Game/Graphics/TerrainRenderer.cs index c99896932d..c713375ce5 100644 --- a/OpenRa.Game/Graphics/TerrainRenderer.cs +++ b/OpenRa.Game/Graphics/TerrainRenderer.cs @@ -17,6 +17,7 @@ namespace OpenRa.Game.Graphics Renderer renderer; Map map; Viewport viewport; + OverlayRenderer overlayRenderer; public TerrainRenderer(Renderer renderer, Map map, Viewport viewport) { @@ -25,6 +26,7 @@ namespace OpenRa.Game.Graphics region = Region.Create(viewport, DockStyle.Left, viewport.Width - 128, Draw, null ); viewport.AddRegion(region); this.map = map; + overlayRenderer = new OverlayRenderer( renderer, map ); tileSet = new TileSet( map.TileSuffix ); @@ -78,6 +80,8 @@ namespace OpenRa.Game.Graphics new Range(verticesPerRow * firstRow, verticesPerRow * lastRow), new Range(indicesPerRow * firstRow, indicesPerRow * lastRow), terrainSheet.Texture, PrimitiveType.TriangleList)); + + overlayRenderer.Draw(); } } } diff --git a/OpenRa.Game/OpenRa.Game.csproj b/OpenRa.Game/OpenRa.Game.csproj index 62cf0d3fbd..24ddd6e70b 100644 --- a/OpenRa.Game/OpenRa.Game.csproj +++ b/OpenRa.Game/OpenRa.Game.csproj @@ -77,6 +77,7 @@ + diff --git a/OpenRa.Game/Sidebar.cs b/OpenRa.Game/Sidebar.cs index c412453c8d..df6d240c12 100644 --- a/OpenRa.Game/Sidebar.cs +++ b/OpenRa.Game/Sidebar.cs @@ -70,8 +70,8 @@ namespace OpenRa.Game { string key = line.Substring(0, line.IndexOf(',')); int secondComma = line.IndexOf(',', line.IndexOf(',') + 1); - string group = line.Substring(secondComma + 1, line.Length - secondComma - 1); - sprites.Add(key, SpriteSheetBuilder.LoadSprite(key + "icon.shp")); + string group = line.Substring(secondComma + 1, line.Length - secondComma - 1); + sprites.Add( key, SpriteSheetBuilder.LoadSprite( key + "icon", ".shp" ) ); itemGroups.Add(key, group); } } diff --git a/OpenRa.Game/World.cs b/OpenRa.Game/World.cs index a3bb5c4040..19a998aad4 100644 --- a/OpenRa.Game/World.cs +++ b/OpenRa.Game/World.cs @@ -5,7 +5,7 @@ using System.Windows.Forms; namespace OpenRa.Game { class World - { + { List actors = new List(); List> frameEndActions = new List>(); @@ -19,8 +19,6 @@ namespace OpenRa.Game int lastTime = Environment.TickCount + 2000; - - public void Update() { int t = Environment.TickCount; @@ -35,8 +33,8 @@ namespace OpenRa.Game foreach (Action a in frameEndActions) a(this); frameEndActions.Clear(); - } - + } + public IEnumerable Actors { get { return actors; } } } } diff --git a/sequences.xml b/sequences.xml index 9c9f4f873b..2bec7d02cb 100644 --- a/sequences.xml +++ b/sequences.xml @@ -183,6 +183,20 @@ + + + + + + + + + + + + + +