From 4fa05a6d40f27464628536f19d6e3bb6cc9bc33a Mon Sep 17 00:00:00 2001 From: Bob Date: Sat, 10 Oct 2009 19:30:19 +1300 Subject: [PATCH] sequences for the rest of the buildable buildings, and fixes to make HBOX and MSLO work - HBOX and MSLO sprites are in temperat/snow mixes with .tem/.sno extensions (and not present in interior) --- OpenRa.FileFormats/FileSystem.cs | 15 +++ OpenRa.Game/Actor.cs | 121 +++++++++++++++------ OpenRa.Game/GameRules/UnitInfo.cs | 2 +- OpenRa.Game/Graphics/UnitSheetBuilder.cs | 2 +- sequences.xml | 133 +++++++++++++++++------ 5 files changed, 201 insertions(+), 72 deletions(-) diff --git a/OpenRa.FileFormats/FileSystem.cs b/OpenRa.FileFormats/FileSystem.cs index 9361a40f2f..4c8b1ab4fc 100644 --- a/OpenRa.FileFormats/FileSystem.cs +++ b/OpenRa.FileFormats/FileSystem.cs @@ -26,5 +26,20 @@ namespace OpenRa.FileFormats throw new FileNotFoundException("File not found", filename); } + + public static Stream OpenWithExts( string filename, params string[] exts ) + { + foreach( var ext in exts ) + { + foreach( IFolder folder in mountedFolders ) + { + Stream s = folder.GetContent( filename + ext ); + if( s != null ) + return s; + } + } + + throw new FileNotFoundException( "File not found", filename ); + } } } diff --git a/OpenRa.Game/Actor.cs b/OpenRa.Game/Actor.cs index 01e5bccc8c..c7b5ac4f81 100755 --- a/OpenRa.Game/Actor.cs +++ b/OpenRa.Game/Actor.cs @@ -21,7 +21,8 @@ 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; switch( name ) @@ -29,7 +30,7 @@ namespace OpenRa.Game ///// vehicles ///// case "mcv": traits.Add( new Traits.Mobile( this ) ); - traits.Add( new Traits.RenderUnit( this, name ) ); + traits.Add( new Traits.RenderUnit( this ) ); traits.Add( new Traits.McvDeploy( this ) ); break; case "mnly": @@ -37,7 +38,7 @@ namespace OpenRa.Game case "v2rl": case "arty": traits.Add( new Traits.Mobile( this ) ); - traits.Add( new Traits.RenderUnit( this, name ) ); + traits.Add( new Traits.RenderUnit( this ) ); break; case "jeep": case "1tnk": @@ -48,11 +49,11 @@ namespace OpenRa.Game case "mgg": traits.Add( new Traits.Mobile( this ) ); traits.Add( new Traits.Turreted( this ) ); - traits.Add( new Traits.RenderUnitTurreted( this, name ) ); + traits.Add( new Traits.RenderUnitTurreted( this ) ); break; case "harv": traits.Add( new Traits.Mobile( this ) ); - traits.Add( new Traits.RenderUnit( this, name ) ); + traits.Add( new Traits.RenderUnit( this ) ); break; ///// TODO: infantry ///// @@ -66,7 +67,6 @@ namespace OpenRa.Game case "mslo": case "atek": case "stek": - case "weap": case "fact": case "proc": case "silo": @@ -79,7 +79,8 @@ namespace OpenRa.Game case "tent": case "kenn": case "fix": - //SYRD, SPEN + case "spen": + case "syrd": //GAP //SBAG, BRIK, FENC //FACF, WEAF, SYRF, SPEF, DOMF @@ -88,14 +89,18 @@ namespace OpenRa.Game case "tsla": case "ftur": traits.Add( new Traits.Building( this ) ); - traits.Add( new Traits.RenderBuilding( this, name ) ); - break; + traits.Add( new Traits.RenderBuilding( this ) ); + break; + case "weap": + traits.Add( new Traits.Building( this ) ); + traits.Add( new Traits.RenderWarFactory( this ) ); + break; case "gun": case "agun": case "sam": traits.Add( new Traits.Building( this ) ); traits.Add( new Traits.Turreted( this ) ); - traits.Add( new Traits.RenderBuildingTurreted( this, name ) ); + traits.Add( new Traits.RenderBuildingTurreted( this ) ); break; default: throw new NotImplementedException( "Actor traits for " + name ); @@ -112,9 +117,9 @@ namespace OpenRa.Game { foreach( var tick in traits.WithInterface() ) tick.Tick( this, game, dt ); - } - - public float2 CenterLocation { get { return new float2( 12, 12 ) + 24 * (float2)Location; } } + } + + public float2 CenterLocation; public float2 SelectedSize { get { return Render().FirstOrDefault().First.size; } } public IEnumerable> Render() @@ -152,9 +157,9 @@ namespace OpenRa.Game { public Animation anim; - public RenderSimple( Actor self, string unitName ) + public RenderSimple( Actor self ) { - anim = new Animation( unitName ); + anim = new Animation( self.unitInfo.Name ); } public abstract IEnumerable> Render( Actor self ); @@ -167,10 +172,10 @@ namespace OpenRa.Game class RenderBuilding : RenderSimple { - public RenderBuilding( Actor self, string unitName ) - : base( self, unitName ) + public RenderBuilding( Actor self ) + : base( self ) { - anim.PlayThen( "make", () => anim.Play( "idle" ) ); + anim.PlayThen( "make", () => anim.PlayRepeating( "idle" ) ); } public override IEnumerable> Render( Actor self ) @@ -181,19 +186,50 @@ namespace OpenRa.Game class RenderBuildingTurreted : RenderBuilding { - public RenderBuildingTurreted( Actor self, string unitName ) - : base( self, unitName ) + public RenderBuildingTurreted( Actor self ) + : base( self ) { 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 RenderUnit : RenderSimple - { - public RenderUnit( Actor self, string unitName ) - :base( self, unitName ) - { - 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 ) @@ -215,20 +251,18 @@ namespace OpenRa.Game { public Animation turretAnim; - public RenderUnitTurreted( Actor self, string unitName ) - : base( self, unitName ) + public RenderUnitTurreted( Actor self ) + : base( self ) { - turretAnim = new Animation( unitName ); + turretAnim = new Animation( self.unitInfo.Name ); turretAnim.PlayFetchIndex( "turret", () => self.traits.Get().turretFacing ); } public override IEnumerable> Render( Actor self ) { var mobile = self.traits.Get(); - float fraction = ( mobile.moveFraction > 0 ) ? (float)mobile.moveFraction / mobile.moveFractionTotal : 0f; - var centerLocation = new float2( 12, 12 ) + 24 * float2.Lerp( mobile.fromCell, mobile.toCell, fraction ); - yield return Centered( anim.Image, centerLocation ); - yield return Centered( turretAnim.Image, centerLocation ); + yield return Centered( anim.Image, self.CenterLocation ); + yield return Centered( turretAnim.Image, self.CenterLocation ); } public override void Tick( Actor self, Game game, int dt ) @@ -285,9 +319,21 @@ 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 ); } public void Tick( Actor self, Game game, int dt ) + { + Move( self, game, dt ); + UpdateCenterLocation(); + } + + void Move( Actor self, Game game, int dt ) { if( fromCell != toCell ) { @@ -378,14 +424,17 @@ 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 ); + { + 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/GameRules/UnitInfo.cs b/OpenRa.Game/GameRules/UnitInfo.cs index 0821e2b99c..39f36158e6 100755 --- a/OpenRa.Game/GameRules/UnitInfo.cs +++ b/OpenRa.Game/GameRules/UnitInfo.cs @@ -84,7 +84,7 @@ namespace OpenRa.Game.GameRules public BaseInfo( string name, IniSection ini ) { - Name = name; + Name = name.ToLowerInvariant(); foreach( var x in ini ) { diff --git a/OpenRa.Game/Graphics/UnitSheetBuilder.cs b/OpenRa.Game/Graphics/UnitSheetBuilder.cs index 96b0b23860..e455ba2dc1 100644 --- a/OpenRa.Game/Graphics/UnitSheetBuilder.cs +++ b/OpenRa.Game/Graphics/UnitSheetBuilder.cs @@ -24,7 +24,7 @@ namespace OpenRa.Game.Graphics int low = sprites.Count; - ShpReader reader = new ShpReader(FileSystem.Open(name + ".shp")); + ShpReader reader = new ShpReader( FileSystem.OpenWithExts( name, ".shp", ".tem", ".sno", ".int" ) ); foreach (ImageHeader h in reader) sprites.Add(SheetBuilder.Add(h.Image, reader.Size)); diff --git a/sequences.xml b/sequences.xml index 346a5b4f6b..9c9f4f873b 100644 --- a/sequences.xml +++ b/sequences.xml @@ -31,7 +31,6 @@ - @@ -41,23 +40,27 @@ - - + + + + + + + - - + @@ -65,7 +68,6 @@ - @@ -73,15 +75,20 @@ - - + + + + + + + @@ -89,7 +96,6 @@ - @@ -97,7 +103,6 @@ - @@ -105,39 +110,111 @@ - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - @@ -150,37 +227,32 @@ - - + - - - + - - @@ -188,47 +260,40 @@ - - - - - - -