From 3101ffa6711002972675708eb9ffaa2e0e295123 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Mon, 18 Jan 2010 22:53:39 +1300 Subject: [PATCH 01/25] initial bridges hack --- OpenRa.FileFormats/TileSet.cs | 6 +-- OpenRa.FileFormats/Walkability.cs | 48 ++++++++++++------ OpenRa.Game/Bridges.cs | 63 ++++++++++++++++++++++++ OpenRa.Game/Graphics/SequenceProvider.cs | 2 - OpenRa.Game/OpenRa.Game.csproj | 2 + OpenRa.Game/Shroud.cs | 2 + OpenRa.Game/Traits/Bridge.cs | 43 ++++++++++++++++ OpenRa.Game/World.cs | 2 + ra.yaml | 7 +++ templates.ini | 24 +++++++++ units.ini | 5 ++ 11 files changed, 183 insertions(+), 21 deletions(-) create mode 100644 OpenRa.Game/Bridges.cs create mode 100644 OpenRa.Game/Traits/Bridge.cs diff --git a/OpenRa.FileFormats/TileSet.cs b/OpenRa.FileFormats/TileSet.cs index 6ea58a157d..6f2e05df1d 100644 --- a/OpenRa.FileFormats/TileSet.cs +++ b/OpenRa.FileFormats/TileSet.cs @@ -8,8 +8,8 @@ namespace OpenRa.FileFormats { public readonly Dictionary tiles = new Dictionary(); - readonly Dictionary> walk = - new Dictionary>(); // cjf will fix + public readonly Dictionary walk = + new Dictionary(); // cjf will fix string NextLine( StreamReader reader ) { @@ -82,7 +82,7 @@ namespace OpenRa.FileFormats if (r.tile == 0xff || r.tile == 0xffff) r.image = 0; - return walk[r.tile][r.image]; + return walk[r.tile].TerrainType[r.image]; } } } diff --git a/OpenRa.FileFormats/Walkability.cs b/OpenRa.FileFormats/Walkability.cs index 7ddfceab71..5095c49a3a 100644 --- a/OpenRa.FileFormats/Walkability.cs +++ b/OpenRa.FileFormats/Walkability.cs @@ -1,35 +1,51 @@ using System.Collections.Generic; using System.Text.RegularExpressions; +using System.Linq; namespace OpenRa.FileFormats { - public class Walkability + public class TileTemplate { - Dictionary> walkability = - new Dictionary>(); + public int Index; + public string Name; + public int2 Size; + public bool IsBridge; + public float HP; + public Dictionary TerrainType = new Dictionary(); + } + + class Walkability + { + public Dictionary walkability + = new Dictionary(); public Walkability() { - IniFile file = new IniFile( FileSystem.Open( "templates.ini" ) ); - Regex pattern = new Regex(@"tiletype(\d+)"); + var file = new IniFile( FileSystem.Open( "templates.ini" ) ); - foreach (IniSection section in file.Sections) + foreach (var section in file.Sections) { - string name = section.GetValue("Name", null).ToLowerInvariant(); - - Dictionary tileWalkability = new Dictionary(); - foreach (KeyValuePair p in section) + var tile = new TileTemplate { - Match m = pattern.Match(p.Key); - if (m != null && m.Success) - tileWalkability.Add(int.Parse(m.Groups[1].Value), int.Parse(p.Value)); - } + Size = new int2( + int.Parse(section.GetValue("width", "0")), + int.Parse(section.GetValue("height", "0"))), + TerrainType = section + .Where(p => p.Key.StartsWith("tiletype")) + .ToDictionary( + p => int.Parse(p.Key.Substring(8)), + p => int.Parse(p.Value)), + Name = section.GetValue("Name", null).ToLowerInvariant(), + Index = int.Parse(section.Name.Substring(3)), + IsBridge = section.GetValue("bridge", "no") != "no", + HP = float.Parse(section.GetValue("hp", "0")) + }; - walkability[name] = tileWalkability; + walkability[tile.Name] = tile; } } - public Dictionary GetWalkability(string terrainName) + public TileTemplate GetWalkability(string terrainName) { return walkability[terrainName]; } diff --git a/OpenRa.Game/Bridges.cs b/OpenRa.Game/Bridges.cs new file mode 100644 index 0000000000..dd53c32d51 --- /dev/null +++ b/OpenRa.Game/Bridges.cs @@ -0,0 +1,63 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using OpenRa.Traits; + +namespace OpenRa +{ + static class Bridges + { + public static void MakeBridges(World w) + { + var mini = w.Map.XOffset; var maxi = w.Map.XOffset + w.Map.Width; + var minj = w.Map.YOffset; var maxj = w.Map.YOffset + w.Map.Height; + + for (var j = minj; j < maxj; j++) + for (var i = mini; i < maxi; i++) + if (IsBridge(w, w.Map.MapTiles[i, j].tile)) + ConvertBridgeToActor(w, i, j); + } + + static void ConvertBridgeToActor(World w, int i, int j) + { + var tile = w.Map.MapTiles[i, j].tile; + var image = w.Map.MapTiles[i, j].image; + var template = w.TileSet.walk[tile]; + + // base position of the tile + var ni = i - image % template.Size.X; + var nj = j - image / template.Size.X; + + var replacedTiles = new Dictionary(); + for (var y = nj; y < nj + template.Size.Y; y++) + for (var x = ni; x < ni + template.Size.X; x++) + { + var n = (x - ni) + template.Size.X * (y - nj); + if (!template.TerrainType.ContainsKey(n)) continue; + + if (w.Map.IsInMap(x, y)) + if (w.Map.MapTiles[x, y].tile == tile) + { + // stash it + replacedTiles[new int2(x, y)] = w.Map.MapTiles[x, y].image; + // remove the tile from the actual map + w.Map.MapTiles[x, y].tile = 0xff; + w.Map.MapTiles[x, y].image = 0; + } + } + + if (replacedTiles.Any()) + { + var a = w.CreateActor("Bridge", new int2(ni, nj), null); + var br = a.traits.Get(); + br.SetTiles(template, replacedTiles); + } + } + + static bool IsBridge(World w, ushort t) + { + return w.TileSet.walk[t].IsBridge; + } + } +} diff --git a/OpenRa.Game/Graphics/SequenceProvider.cs b/OpenRa.Game/Graphics/SequenceProvider.cs index 66a45e2f43..64e0ab4e1f 100644 --- a/OpenRa.Game/Graphics/SequenceProvider.cs +++ b/OpenRa.Game/Graphics/SequenceProvider.cs @@ -107,8 +107,6 @@ namespace OpenRa.Graphics public static Sprite GetImageFromCollection(Renderer renderer,string collection, string image) { - - // Cached sprite if (cachedSprites.ContainsKey(collection) && cachedSprites[collection].ContainsKey(image)) return cachedSprites[collection][image]; diff --git a/OpenRa.Game/OpenRa.Game.csproj b/OpenRa.Game/OpenRa.Game.csproj index a287dcbac4..3b0747c4f5 100644 --- a/OpenRa.Game/OpenRa.Game.csproj +++ b/OpenRa.Game/OpenRa.Game.csproj @@ -77,6 +77,7 @@ + @@ -210,6 +211,7 @@ + diff --git a/OpenRa.Game/Shroud.cs b/OpenRa.Game/Shroud.cs index 91622065cd..b3a9e0adc2 100644 --- a/OpenRa.Game/Shroud.cs +++ b/OpenRa.Game/Shroud.cs @@ -137,6 +137,8 @@ namespace OpenRa internal void Draw(SpriteRenderer r) { + return; + if (dirty) { dirty = false; diff --git a/OpenRa.Game/Traits/Bridge.cs b/OpenRa.Game/Traits/Bridge.cs new file mode 100644 index 0000000000..e626e2c93d --- /dev/null +++ b/OpenRa.Game/Traits/Bridge.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using OpenRa.Graphics; +using OpenRa.FileFormats; + +namespace OpenRa.Traits +{ + class BridgeInfo : ITraitInfo + { + public object Create(Actor self) { return new Bridge(); } + } + + class Bridge : IRender, ITick + { + Animation anim; + + public Bridge() {} + + public IEnumerable Render(Actor self) + { + if (anim != null) + return new[] { Util.Centered(self, anim.Image, self.CenterLocation) }; + else + return new Renderable[] { }; + } + + public void Tick(Actor self) + { + if (anim == null) + { + anim = new Animation("3tnk"); + anim.PlayRepeating("idle"); + } + } + + public void SetTiles(TileTemplate template, Dictionary replacedTiles) + { + /* todo: stash these, etc */ + } + } +} diff --git a/OpenRa.Game/World.cs b/OpenRa.Game/World.cs index d572b437ee..31c2e63444 100644 --- a/OpenRa.Game/World.cs +++ b/OpenRa.Game/World.cs @@ -44,6 +44,8 @@ namespace OpenRa CreateActor("World", new int2(int.MaxValue, int.MaxValue), null); + Bridges.MakeBridges(this); + WorldRenderer = new WorldRenderer(this, Game.renderer); Minimap = new Minimap(this, Game.renderer); } diff --git a/ra.yaml b/ra.yaml index fc8c476214..5c153858d1 100644 --- a/ra.yaml +++ b/ra.yaml @@ -1435,6 +1435,13 @@ DOMF: Image: DOME Fake: +BRIDGE: + Inherits: ^Building + Bridge: + BelowUnits: + -Selectable: + -Building: + T01: Inherits: ^Building Building: diff --git a/templates.ini b/templates.ini index e06254252f..b06455bb34 100644 --- a/templates.ini +++ b/templates.ini @@ -2491,6 +2491,8 @@ tiletype3=3 Name=BR1A width=4 height=3 +bridge=yes +hp=1 tiletype1=3 tiletype2=2 tiletype4=3 @@ -2505,6 +2507,8 @@ tiletype11=3 Name=BR1B width=4 height=3 +bridge=yes +hp=.5 tiletype1=3 tiletype2=6 tiletype4=3 @@ -2519,6 +2523,8 @@ tiletype11=3 Name=BR1C width=4 height=3 +bridge=yes +hp=0 tiletype1=3 tiletype2=3 tiletype4=3 @@ -2533,6 +2539,8 @@ tiletype11=3 Name=BR2A width=5 height=3 +bridge=yes +hp=1 tiletype1=3 tiletype2=2 tiletype5=3 @@ -2548,6 +2556,8 @@ tiletype13=3 Name=BR2B width=5 height=3 +bridge=yes +hp=.5 tiletype1=3 tiletype2=6 tiletype5=3 @@ -2563,6 +2573,8 @@ tiletype13=3 Name=BR2C width=5 height=3 +bridge=yes +hp=0 tiletype1=1 tiletype2=1 tiletype5=3 @@ -2578,6 +2590,8 @@ tiletype13=3 Name=BR3A width=4 height=2 +bridge=yes +hp=1 tiletype0=3 tiletype1=2 tiletype5=2 @@ -2588,6 +2602,8 @@ tiletype7=3 Name=BR3B width=4 height=2 +bridge=yes +hp=.5 tiletype0=3 tiletype1=2 tiletype5=2 @@ -2598,6 +2614,8 @@ tiletype7=3 Name=BR3C width=4 height=2 +bridge=yes +hp=0 tiletype0=3 tiletype1=3 tiletype5=3 @@ -2608,6 +2626,8 @@ tiletype7=3 Name=BR3D width=4 height=2 +bridge=yes +hp=0 tiletype0=5 tiletype1=3 tiletype5=5 @@ -2618,6 +2638,8 @@ tiletype7=5 Name=BR3E width=4 height=2 +bridge=yes +hp=0 tiletype0=1 tiletype1=1 tiletype5=3 @@ -2628,6 +2650,8 @@ tiletype7=1 Name=BR3F width=4 height=2 +bridge=yes +hp=0 tiletype0=1 tiletype1=1 tiletype5=1 diff --git a/units.ini b/units.ini index 9edf088fa8..9f9fbf2d23 100644 --- a/units.ini +++ b/units.ini @@ -253,6 +253,7 @@ DOMF ; pseudo-buildings MINP MINV +BRIDGE ; `Dimensions` is the size of a box that will include the whole building, excluding bib. @@ -533,6 +534,10 @@ Selectable=no Traits=Unit,RenderUnit,BelowUnits,InvisibleToOthers Selectable=no +[Bridge] +Traits=Bridge, BelowUnits +Selectable=no + [InfantryTypes] DOG E1 From faf28a90ae2d75a0928adeffb9cefe54d344cac4 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Mon, 18 Jan 2010 23:22:00 +1300 Subject: [PATCH 02/25] made a real terrain type for it; still not quite right though. will crash on snow maps atm too. --- OpenRa.Game/Bridges.cs | 2 +- OpenRa.Game/Graphics/Minimap.cs | 2 +- OpenRa.Game/TerrainCosts.cs | 6 ++++-- OpenRa.Game/Traits/Production.cs | 2 +- OpenRa.Game/Traits/ProductionSurround.cs | 4 ++-- RulesConverter/Program.cs | 4 ++++ bogus.tem | Bin 0 -> 619 bytes ra.yaml | 2 ++ templates.ini | 6 ++++++ tileSet.til | 5 +++++ 10 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 bogus.tem diff --git a/OpenRa.Game/Bridges.cs b/OpenRa.Game/Bridges.cs index dd53c32d51..fda09d3db5 100644 --- a/OpenRa.Game/Bridges.cs +++ b/OpenRa.Game/Bridges.cs @@ -42,7 +42,7 @@ namespace OpenRa // stash it replacedTiles[new int2(x, y)] = w.Map.MapTiles[x, y].image; // remove the tile from the actual map - w.Map.MapTiles[x, y].tile = 0xff; + w.Map.MapTiles[x, y].tile = 0xfffe; w.Map.MapTiles[x, y].image = 0; } } diff --git a/OpenRa.Game/Graphics/Minimap.cs b/OpenRa.Game/Graphics/Minimap.cs index b985b77f07..023101aa6d 100644 --- a/OpenRa.Game/Graphics/Minimap.cs +++ b/OpenRa.Game/Graphics/Minimap.cs @@ -49,7 +49,7 @@ namespace OpenRa.Graphics if (terrainTypeColors == null) { var pal = new Palette(FileSystem.Open(Game.world.Map.Theater + ".pal")); - terrainTypeColors = new[] {theater.ToLowerInvariant() == "snow" ? 0xe3 :0x1a, 0x63, 0x2f, 0x1f, 0x14, 0x64, 0x1f, 0x68, 0x6b, 0x6d } + terrainTypeColors = new[] {theater.ToLowerInvariant() == "snow" ? 0xe3 :0x1a, 0x63, 0x2f, 0x1f, 0x14, 0x64, 0x1f, 0x68, 0x6b, 0x6d, 0x67 } .Select( a => Color.FromArgb(alpha, pal.GetColor(a) )).ToArray(); playerColors = Util.MakeArray( 8, b => Color.FromArgb(alpha, Chat.paletteColors[b]) ); diff --git a/OpenRa.Game/TerrainCosts.cs b/OpenRa.Game/TerrainCosts.cs index a1cddc3b73..b074d47a8f 100644 --- a/OpenRa.Game/TerrainCosts.cs +++ b/OpenRa.Game/TerrainCosts.cs @@ -23,16 +23,17 @@ namespace OpenRa Wall = 7, Beach = 8, Ore = 9, + Special = 10, } static class TerrainCosts { static double[][] costs = Util.MakeArray( 4, - a => Util.MakeArray( 10, b => double.PositiveInfinity )); + a => Util.MakeArray( 11, b => double.PositiveInfinity )); static TerrainCosts() { - for( int i = 0 ; i < 10 ; i++ ) + for( int i = 0 ; i < 11 ; i++ ) { if( i == 4 ) continue; var section = Rules.AllRules.GetSection( ( (TerrainMovementType)i ).ToString() ); @@ -46,6 +47,7 @@ namespace OpenRa public static double Cost( UnitMovementType unitMovementType, int r ) { + if (r >= 10) return 1.0; return costs[ (byte)unitMovementType ][ r ]; } } diff --git a/OpenRa.Game/Traits/Production.cs b/OpenRa.Game/Traits/Production.cs index 30b1514467..5562c043e5 100755 --- a/OpenRa.Game/Traits/Production.cs +++ b/OpenRa.Game/Traits/Production.cs @@ -9,7 +9,7 @@ namespace OpenRa.Traits public readonly int[] SpawnOffset = null; public readonly string[] Produces = { }; - public object Create(Actor self) { return new Production(self); } + public virtual object Create(Actor self) { return new Production(self); } } class Production : IIssueOrder, IResolveOrder, IProducer, ITags diff --git a/OpenRa.Game/Traits/ProductionSurround.cs b/OpenRa.Game/Traits/ProductionSurround.cs index 9abb584492..aeca50ad11 100644 --- a/OpenRa.Game/Traits/ProductionSurround.cs +++ b/OpenRa.Game/Traits/ProductionSurround.cs @@ -3,9 +3,9 @@ using OpenRa.GameRules; namespace OpenRa.Traits { - class ProductionSurroundInfo : ITraitInfo + class ProductionSurroundInfo : ProductionInfo { - public object Create(Actor self) { return new ProductionSurround(self); } + public override object Create(Actor self) { return new ProductionSurround(self); } } class ProductionSurround : Production diff --git a/RulesConverter/Program.cs b/RulesConverter/Program.cs index 9bfef9e0a9..40b5bbe649 100644 --- a/RulesConverter/Program.cs +++ b/RulesConverter/Program.cs @@ -138,6 +138,10 @@ namespace RulesConverter { "Produces", "Produces" } } }, + { "ProductionSurround", new PL { + { "Produces", "Produces" } } + }, + { "Minelayer", new PL { { "Mine", "Primary" } } }, diff --git a/bogus.tem b/bogus.tem new file mode 100644 index 0000000000000000000000000000000000000000..bc2b351f54c2a98a3a136f2d0e32ba1867a3402e GIT binary patch literal 619 zcmW-fL5`#_3`OZ#&2A7@u!(_`)-K(_b2KTrMogGUH3gpUO7`%Ce2K1%9-xln#El;shAX{ot0Bc zns@W+3+GadnDd%giFo;4?P%d9&&pshAbDLktA0Eppm{4ezwQYfUCfTF)i{_eTzFRC zITgDd(awliNZbyhaZcHm#k`%h;)B90=0r4ea=*p1)`%;-SP`khJSx?w)mpqB-OdYL zA;Y3Zn0u|)3myG3v}F?L4n1JBl5uJ7F5q)!Gi%55x_raA67HZ7G9ogA`F5HWmg?Vr zc*3T{1AbZ{nW>oZJQJ;&UD_4Z(SJh(L=#OtBIEN>?G)&O#nZ@?bW`)|3JEjJW2Hz2 z8GelAs-PIA1N)oAh|LOyk<$4NpEx>VkCAb2Dm{(Bs6x}&?UNRZ({kQ0X@SA6vT7zS g_jkd%-Mz>>jvbOTt^J}Xt^$4>q+YltJPbeo18dn&IsgCw literal 0 HcmV?d00001 diff --git a/ra.yaml b/ra.yaml index 5c153858d1..bcdc69117f 100644 --- a/ra.yaml +++ b/ra.yaml @@ -999,6 +999,7 @@ SYRD: Sight: 4 RenderBuilding: ProductionSurround: + Produces: Ship IronCurtainable: SPEN: @@ -1023,6 +1024,7 @@ SPEN: Sight: 4 RenderBuilding: ProductionSurround: + Produces: Ship IronCurtainable: FACT: diff --git a/templates.ini b/templates.ini index b06455bb34..023e01336a 100644 --- a/templates.ini +++ b/templates.ini @@ -2822,3 +2822,9 @@ tiletype18=2 tiletype19=2 tiletype23=2 tiletype24=2 + +[TEM65534] +Name=Bogus +width=1 +height=1 +tiletype0=10 \ No newline at end of file diff --git a/tileSet.til b/tileSet.til index aaf2fc11b7..39ed4bac67 100644 --- a/tileSet.til +++ b/tileSet.til @@ -304,3 +304,8 @@ gflr{0:0000} 0118 gstr{0:0000} +; bogus +TS- +1 +fffe +bogus \ No newline at end of file From 5bc826e916b705723781b3eac2959bc982a2a0fc Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Tue, 19 Jan 2010 07:23:06 +1300 Subject: [PATCH 03/25] make that a real movement type --- OpenRa.Game/Orders/NetworkOrderSource.cs | 2 +- OpenRa.Game/TerrainCosts.cs | 1 - rules.ini | 8 ++++++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/OpenRa.Game/Orders/NetworkOrderSource.cs b/OpenRa.Game/Orders/NetworkOrderSource.cs index ce0bc2de4a..cf3c24f79c 100644 --- a/OpenRa.Game/Orders/NetworkOrderSource.cs +++ b/OpenRa.Game/Orders/NetworkOrderSource.cs @@ -65,7 +65,7 @@ namespace OpenRa.Orders } } } - catch (IOException e) + catch (IOException) { State = ConnectionState.NotConnected; } diff --git a/OpenRa.Game/TerrainCosts.cs b/OpenRa.Game/TerrainCosts.cs index b074d47a8f..f794344c77 100644 --- a/OpenRa.Game/TerrainCosts.cs +++ b/OpenRa.Game/TerrainCosts.cs @@ -47,7 +47,6 @@ namespace OpenRa public static double Cost( UnitMovementType unitMovementType, int r ) { - if (r >= 10) return 1.0; return costs[ (byte)unitMovementType ][ r ]; } } diff --git a/rules.ini b/rules.ini index 1bb007ac1a..b58fd7412b 100644 --- a/rules.ini +++ b/rules.ini @@ -2525,6 +2525,14 @@ Wheel=0% Float=0% Buildable=no +; special tile for bridge hacks +[Special] +Foot=100% +Track=100% +Wheel=100% +Float=100% +Buildable=no + ; ******* Random Crate Powerups ******* ; This specifies the chance for the specified crate powerup to appear From 382ebbac35c5c7c409325700f612be913ce5cd6c Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Tue, 19 Jan 2010 07:25:25 +1300 Subject: [PATCH 04/25] order matters here; now bridges are passable by everything --- OpenRa.Game/World.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/OpenRa.Game/World.cs b/OpenRa.Game/World.cs index 31c2e63444..bd68474af9 100644 --- a/OpenRa.Game/World.cs +++ b/OpenRa.Game/World.cs @@ -40,11 +40,10 @@ namespace OpenRa oreTicks = oreFrequency; Map.InitOreDensity(); - PathFinder = new PathFinder(this); - CreateActor("World", new int2(int.MaxValue, int.MaxValue), null); Bridges.MakeBridges(this); + PathFinder = new PathFinder(this); WorldRenderer = new WorldRenderer(this, Game.renderer); Minimap = new Minimap(this, Game.renderer); From 2b77980918755bb073442258266a691d19327dc7 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Tue, 19 Jan 2010 09:03:54 +1300 Subject: [PATCH 05/25] a bit more careful, for broken maps --- OpenRa.Game/Bridges.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/OpenRa.Game/Bridges.cs b/OpenRa.Game/Bridges.cs index fda09d3db5..939bc5f2b3 100644 --- a/OpenRa.Game/Bridges.cs +++ b/OpenRa.Game/Bridges.cs @@ -37,7 +37,8 @@ namespace OpenRa if (!template.TerrainType.ContainsKey(n)) continue; if (w.Map.IsInMap(x, y)) - if (w.Map.MapTiles[x, y].tile == tile) + if (w.Map.MapTiles[x, y].tile == tile + && w.Map.MapTiles[x,y].image == n) { // stash it replacedTiles[new int2(x, y)] = w.Map.MapTiles[x, y].image; From d56e2c8e2636ab625d95f89504fbed9cf7e684f0 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Tue, 19 Jan 2010 09:35:22 +1300 Subject: [PATCH 06/25] better bogus.{tem,sno} --- bogus.sno | Bin 0 -> 619 bytes bogus.tem | Bin 619 -> 619 bytes 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 bogus.sno diff --git a/bogus.sno b/bogus.sno new file mode 100644 index 0000000000000000000000000000000000000000..db18593048cc571b13781f323f9c715cab3f15ed GIT binary patch literal 619 wcmb1OkYHeBU;tu9hHNGV1`Qw^1bX<3buxkcEFjJRV*61r8UhrA00RRD00@kc3;+NC literal 0 HcmV?d00001 diff --git a/bogus.tem b/bogus.tem index bc2b351f54c2a98a3a136f2d0e32ba1867a3402e..db18593048cc571b13781f323f9c715cab3f15ed 100644 GIT binary patch literal 619 wcmb1OkYHeBU;tu9hHNGV1`Qw^1bX<3buxkcEFjJRV*61r8UhrA00RRD00@kc3;+NC literal 619 zcmW-fL5`#_3`OZ#&2A7@u!(_`)-K(_b2KTrMogGUH3gpUO7`%Ce2K1%9-xln#El;shAX{ot0Bc zns@W+3+GadnDd%giFo;4?P%d9&&pshAbDLktA0Eppm{4ezwQYfUCfTF)i{_eTzFRC zITgDd(awliNZbyhaZcHm#k`%h;)B90=0r4ea=*p1)`%;-SP`khJSx?w)mpqB-OdYL zA;Y3Zn0u|)3myG3v}F?L4n1JBl5uJ7F5q)!Gi%55x_raA67HZ7G9ogA`F5HWmg?Vr zc*3T{1AbZ{nW>oZJQJ;&UD_4Z(SJh(L=#OtBIEN>?G)&O#nZ@?bW`)|3JEjJW2Hz2 z8GelAs-PIA1N)oAh|LOyk<$4NpEx>VkCAb2Dm{(Bs6x}&?UNRZ({kQ0X@SA6vT7zS g_jkd%-Mz>>jvbOTt^J}Xt^$4>q+YltJPbeo18dn&IsgCw From 77418f4227a7529b2bd2f3720d5964144e5a6773 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Tue, 19 Jan 2010 09:35:42 +1300 Subject: [PATCH 07/25] ICustomTerrain; more bridge code --- OpenRa.Game/Shroud.cs | 2 +- OpenRa.Game/Traits/Bridge.cs | 19 +++++++++++++++---- OpenRa.Game/Traits/TraitsInterfaces.cs | 2 ++ OpenRa.Game/World.cs | 4 ++++ 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/OpenRa.Game/Shroud.cs b/OpenRa.Game/Shroud.cs index b3a9e0adc2..8943aaa216 100644 --- a/OpenRa.Game/Shroud.cs +++ b/OpenRa.Game/Shroud.cs @@ -137,7 +137,7 @@ namespace OpenRa internal void Draw(SpriteRenderer r) { - return; + return; // temp; just so i can see until i'm done with the bridges. if (dirty) { diff --git a/OpenRa.Game/Traits/Bridge.cs b/OpenRa.Game/Traits/Bridge.cs index e626e2c93d..43b5b5635a 100644 --- a/OpenRa.Game/Traits/Bridge.cs +++ b/OpenRa.Game/Traits/Bridge.cs @@ -12,11 +12,11 @@ namespace OpenRa.Traits public object Create(Actor self) { return new Bridge(); } } - class Bridge : IRender, ITick + class Bridge : IRender, ITick, ICustomTerrain { Animation anim; - - public Bridge() {} + Dictionary Tiles; + TileTemplate Template; public IEnumerable Render(Actor self) { @@ -37,7 +37,18 @@ namespace OpenRa.Traits public void SetTiles(TileTemplate template, Dictionary replacedTiles) { - /* todo: stash these, etc */ + Template = template; + Tiles = replacedTiles; + + foreach (var t in replacedTiles.Keys) + Game.world.customTerrain[t.X, t.Y] = this; + } + + public double GetCost(int2 p, UnitMovementType umt) + { + var origTile = Tiles[p]; // if this explodes, then SetTiles did something horribly wrong. + + return 1.0; } } } diff --git a/OpenRa.Game/Traits/TraitsInterfaces.cs b/OpenRa.Game/Traits/TraitsInterfaces.cs index cc7afc4569..51f401d358 100644 --- a/OpenRa.Game/Traits/TraitsInterfaces.cs +++ b/OpenRa.Game/Traits/TraitsInterfaces.cs @@ -25,6 +25,8 @@ namespace OpenRa.Traits public interface IAcceptThief { void OnSteal(Actor self, Actor thief); } public interface IAcceptSpy { void OnInfiltrate(Actor self, Actor spy); } + public interface ICustomTerrain { double GetCost(int2 p, UnitMovementType umt); } + interface IProducer { bool Produce( Actor self, ActorInfo producee ); diff --git a/OpenRa.Game/World.cs b/OpenRa.Game/World.cs index bd68474af9..26e46e35e7 100644 --- a/OpenRa.Game/World.cs +++ b/OpenRa.Game/World.cs @@ -4,6 +4,7 @@ using OpenRa.Effects; using OpenRa.Support; using OpenRa.FileFormats; using OpenRa.Graphics; +using OpenRa.Traits; namespace OpenRa { @@ -21,6 +22,9 @@ namespace OpenRa public readonly Map Map; public readonly TileSet TileSet; + // for tricky things like bridges. + public readonly ICustomTerrain[,] customTerrain = new ICustomTerrain[128, 128]; + public readonly WorldRenderer WorldRenderer; internal readonly Minimap Minimap; From 76a9e293b2082cceb076acf8aa780aa0d2c0c6c5 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Tue, 19 Jan 2010 10:22:09 +1300 Subject: [PATCH 08/25] render in bridge code --- OpenRa.Game/Actor.cs | 4 +++- OpenRa.Game/Traits/Bridge.cs | 34 +++++++++++++++++++--------------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/OpenRa.Game/Actor.cs b/OpenRa.Game/Actor.cs index 67cd3ba7f6..3aee607451 100755 --- a/OpenRa.Game/Actor.cs +++ b/OpenRa.Game/Actor.cs @@ -120,6 +120,7 @@ namespace OpenRa public bool IsDead { get { return Health <= 0; } } public bool IsInWorld { get; set; } + public bool RemoveOnDeath = true; public DamageState GetDamageState() { @@ -145,7 +146,8 @@ namespace OpenRa if (attacker.Owner != null) attacker.Owner.Kills++; - Game.world.AddFrameEndTask(w => w.Remove(this)); + if (RemoveOnDeath) + Game.world.AddFrameEndTask(w => w.Remove(this)); } var maxHP = this.GetMaxHP(); diff --git a/OpenRa.Game/Traits/Bridge.cs b/OpenRa.Game/Traits/Bridge.cs index 43b5b5635a..cda11d1923 100644 --- a/OpenRa.Game/Traits/Bridge.cs +++ b/OpenRa.Game/Traits/Bridge.cs @@ -4,36 +4,37 @@ using System.Linq; using System.Text; using OpenRa.Graphics; using OpenRa.FileFormats; +using IjwFramework.Collections; +using System.Drawing; namespace OpenRa.Traits { class BridgeInfo : ITraitInfo { - public object Create(Actor self) { return new Bridge(); } + public object Create(Actor self) { return new Bridge(self); } } class Bridge : IRender, ITick, ICustomTerrain { - Animation anim; Dictionary Tiles; TileTemplate Template; + Dictionary TileSprites; + + public Bridge(Actor self) { self.RemoveOnDeath = false; } + + static Cache Sprites = + new Cache( + x => SheetBuilder.Add(Game.world.TileSet.GetBytes(x), + new Size(Game.CellSize, Game.CellSize))); public IEnumerable Render(Actor self) { - if (anim != null) - return new[] { Util.Centered(self, anim.Image, self.CenterLocation) }; - else - return new Renderable[] { }; + if (Template == null) yield break; + foreach (var t in TileSprites) + yield return new Renderable(t.Value, Game.CellSize * t.Key, PaletteType.Gold); } - public void Tick(Actor self) - { - if (anim == null) - { - anim = new Animation("3tnk"); - anim.PlayRepeating("idle"); - } - } + public void Tick(Actor self) {} public void SetTiles(TileTemplate template, Dictionary replacedTiles) { @@ -42,12 +43,15 @@ namespace OpenRa.Traits foreach (var t in replacedTiles.Keys) Game.world.customTerrain[t.X, t.Y] = this; + + TileSprites = replacedTiles.ToDictionary( + a => a.Key, + a => Sprites[new TileReference { tile = (ushort)template.Index, image = (byte)a.Value }]); } public double GetCost(int2 p, UnitMovementType umt) { var origTile = Tiles[p]; // if this explodes, then SetTiles did something horribly wrong. - return 1.0; } } From f0b26e8ee2fe2cc5f3cbace6b4d5d592c69397cc Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Tue, 19 Jan 2010 10:32:03 +1300 Subject: [PATCH 09/25] PathSearch patched to support ICustomTerrain --- OpenRa.Game/PathSearch.cs | 36 +++++++++++++------------- OpenRa.Game/Traits/Bridge.cs | 10 +++---- OpenRa.Game/Traits/TraitsInterfaces.cs | 2 +- 3 files changed, 23 insertions(+), 25 deletions(-) diff --git a/OpenRa.Game/PathSearch.cs b/OpenRa.Game/PathSearch.cs index 02561b8ace..b2a8ec43fc 100755 --- a/OpenRa.Game/PathSearch.cs +++ b/OpenRa.Game/PathSearch.cs @@ -14,7 +14,6 @@ namespace OpenRa public UnitMovementType umt; Func customBlock; public bool checkForBlocked; - public bool ignoreTerrain; public Actor ignoreBuilding; public PathSearch() @@ -40,9 +39,8 @@ namespace OpenRa var p = queue.Pop(); cellInfo[ p.Location.X, p.Location.Y ].Seen = true; - if (!ignoreTerrain) - if (passableCost[(int)umt][p.Location.X, p.Location.Y] == float.PositiveInfinity) - return p.Location; + if (passableCost[(int)umt][p.Location.X, p.Location.Y] == float.PositiveInfinity) + return p.Location; foreach( int2 d in Util.directions ) { @@ -51,17 +49,18 @@ namespace OpenRa if (!Game.world.Map.IsInMap(newHere.X, newHere.Y)) continue; if( cellInfo[ newHere.X, newHere.Y ].Seen ) continue; - - if (!ignoreTerrain) - { - if (passableCost[(int)umt][newHere.X, newHere.Y] == float.PositiveInfinity) - continue; - if (!Game.world.BuildingInfluence.CanMoveHere(newHere) && - Game.world.BuildingInfluence.GetBuildingAt(newHere) != ignoreBuilding) - continue; - if (Game.world.Map.IsOverlaySolid(newHere)) - continue; - } + + var custom = Game.world.customTerrain[newHere.X, newHere.Y]; + if (custom != null + && custom.GetCost(newHere, umt) == float.PositiveInfinity) + continue; + if (passableCost[(int)umt][newHere.X, newHere.Y] == float.PositiveInfinity) + continue; + if (!Game.world.BuildingInfluence.CanMoveHere(newHere) && + Game.world.BuildingInfluence.GetBuildingAt(newHere) != ignoreBuilding) + continue; + if (Game.world.Map.IsOverlaySolid(newHere)) + continue; // Replicate real-ra behavior of not being able to enter a cell if there is a mixture of crushable and uncrushable units if (checkForBlocked && (Game.world.UnitInfluence.GetUnitsAt(newHere).Any(a => !Game.world.IsActorPathableToCrush(a, umt)))) @@ -69,14 +68,15 @@ namespace OpenRa if (customBlock != null && customBlock(newHere)) continue; - var est = heuristic( newHere ); if( est == float.PositiveInfinity ) continue; - float cellCost = ( ( d.X * d.Y != 0 ) ? 1.414213563f : 1.0f ) * - (ignoreTerrain ? 1 : passableCost[ (int)umt ][ newHere.X, newHere.Y ]); + float cellCost = ((d.X * d.Y != 0) ? 1.414213563f : 1.0f) * + (custom != null + ? custom.GetCost(newHere, umt) : + passableCost[(int)umt][newHere.X, newHere.Y]); float newCost = cellInfo[ p.Location.X, p.Location.Y ].MinCost + cellCost; if( newCost >= cellInfo[ newHere.X, newHere.Y ].MinCost ) diff --git a/OpenRa.Game/Traits/Bridge.cs b/OpenRa.Game/Traits/Bridge.cs index cda11d1923..f00434601e 100644 --- a/OpenRa.Game/Traits/Bridge.cs +++ b/OpenRa.Game/Traits/Bridge.cs @@ -9,12 +9,12 @@ using System.Drawing; namespace OpenRa.Traits { - class BridgeInfo : ITraitInfo + class BridgeInfo : OwnedActorInfo, ITraitInfo { public object Create(Actor self) { return new Bridge(self); } } - class Bridge : IRender, ITick, ICustomTerrain + class Bridge : IRender, ICustomTerrain { Dictionary Tiles; TileTemplate Template; @@ -34,8 +34,6 @@ namespace OpenRa.Traits yield return new Renderable(t.Value, Game.CellSize * t.Key, PaletteType.Gold); } - public void Tick(Actor self) {} - public void SetTiles(TileTemplate template, Dictionary replacedTiles) { Template = template; @@ -49,10 +47,10 @@ namespace OpenRa.Traits a => Sprites[new TileReference { tile = (ushort)template.Index, image = (byte)a.Value }]); } - public double GetCost(int2 p, UnitMovementType umt) + public float GetCost(int2 p, UnitMovementType umt) { var origTile = Tiles[p]; // if this explodes, then SetTiles did something horribly wrong. - return 1.0; + return float.PositiveInfinity; } } } diff --git a/OpenRa.Game/Traits/TraitsInterfaces.cs b/OpenRa.Game/Traits/TraitsInterfaces.cs index 51f401d358..ad2094dc40 100644 --- a/OpenRa.Game/Traits/TraitsInterfaces.cs +++ b/OpenRa.Game/Traits/TraitsInterfaces.cs @@ -25,7 +25,7 @@ namespace OpenRa.Traits public interface IAcceptThief { void OnSteal(Actor self, Actor thief); } public interface IAcceptSpy { void OnInfiltrate(Actor self, Actor spy); } - public interface ICustomTerrain { double GetCost(int2 p, UnitMovementType umt); } + public interface ICustomTerrain { float GetCost(int2 p, UnitMovementType umt); } interface IProducer { From e82a398091d5ac003b923810ee363e49aea524ab Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Tue, 19 Jan 2010 10:38:50 +1300 Subject: [PATCH 10/25] more tweaks --- OpenRa.Game/PathSearch.cs | 13 +++++-------- OpenRa.Game/Traits/Bridge.cs | 17 ++++++++++++----- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/OpenRa.Game/PathSearch.cs b/OpenRa.Game/PathSearch.cs index b2a8ec43fc..e4db641604 100755 --- a/OpenRa.Game/PathSearch.cs +++ b/OpenRa.Game/PathSearch.cs @@ -51,11 +51,11 @@ namespace OpenRa continue; var custom = Game.world.customTerrain[newHere.X, newHere.Y]; - if (custom != null - && custom.GetCost(newHere, umt) == float.PositiveInfinity) - continue; - if (passableCost[(int)umt][newHere.X, newHere.Y] == float.PositiveInfinity) + var costHere = (custom != null) ? custom.GetCost(newHere, umt) : passableCost[(int)umt][newHere.X, newHere.Y]; + + if (costHere == float.PositiveInfinity) continue; + if (!Game.world.BuildingInfluence.CanMoveHere(newHere) && Game.world.BuildingInfluence.GetBuildingAt(newHere) != ignoreBuilding) continue; @@ -73,10 +73,7 @@ namespace OpenRa if( est == float.PositiveInfinity ) continue; - float cellCost = ((d.X * d.Y != 0) ? 1.414213563f : 1.0f) * - (custom != null - ? custom.GetCost(newHere, umt) : - passableCost[(int)umt][newHere.X, newHere.Y]); + float cellCost = ((d.X * d.Y != 0) ? 1.414213563f : 1.0f) * costHere; float newCost = cellInfo[ p.Location.X, p.Location.Y ].MinCost + cellCost; if( newCost >= cellInfo[ newHere.X, newHere.Y ].MinCost ) diff --git a/OpenRa.Game/Traits/Bridge.cs b/OpenRa.Game/Traits/Bridge.cs index f00434601e..0ef1ff41f1 100644 --- a/OpenRa.Game/Traits/Bridge.cs +++ b/OpenRa.Game/Traits/Bridge.cs @@ -22,10 +22,8 @@ namespace OpenRa.Traits public Bridge(Actor self) { self.RemoveOnDeath = false; } - static Cache Sprites = - new Cache( - x => SheetBuilder.Add(Game.world.TileSet.GetBytes(x), - new Size(Game.CellSize, Game.CellSize))); + static string cachedTheater; + static Cache sprites; public IEnumerable Render(Actor self) { @@ -42,13 +40,22 @@ namespace OpenRa.Traits foreach (var t in replacedTiles.Keys) Game.world.customTerrain[t.X, t.Y] = this; + if (cachedTheater != Game.world.Map.Theater) + { + cachedTheater = Game.world.Map.Theater; + sprites = new Cache( + x => SheetBuilder.Add(Game.world.TileSet.GetBytes(x), + new Size(Game.CellSize, Game.CellSize))); + } + TileSprites = replacedTiles.ToDictionary( a => a.Key, - a => Sprites[new TileReference { tile = (ushort)template.Index, image = (byte)a.Value }]); + a => sprites[new TileReference { tile = (ushort)template.Index, image = (byte)a.Value }]); } public float GetCost(int2 p, UnitMovementType umt) { + throw new NotImplementedException(); var origTile = Tiles[p]; // if this explodes, then SetTiles did something horribly wrong. return float.PositiveInfinity; } From 00abdce68f34300f2e6bb9c321fb7850479d9647 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Tue, 19 Jan 2010 11:21:45 +1300 Subject: [PATCH 11/25] oh ffs. old world was being referenced. fixed so it crashes if you do that. --- OpenRa.Game/Bridges.cs | 2 +- OpenRa.Game/Game.cs | 1 + OpenRa.Game/PathFinder.cs | 7 +++---- OpenRa.Game/PathSearch.cs | 8 +++++++- OpenRa.Game/Traits/Bridge.cs | 8 ++++---- 5 files changed, 16 insertions(+), 10 deletions(-) diff --git a/OpenRa.Game/Bridges.cs b/OpenRa.Game/Bridges.cs index 939bc5f2b3..1d9ad28626 100644 --- a/OpenRa.Game/Bridges.cs +++ b/OpenRa.Game/Bridges.cs @@ -52,7 +52,7 @@ namespace OpenRa { var a = w.CreateActor("Bridge", new int2(ni, nj), null); var br = a.traits.Get(); - br.SetTiles(template, replacedTiles); + br.SetTiles(w, template, replacedTiles); } } diff --git a/OpenRa.Game/Game.cs b/OpenRa.Game/Game.cs index 71246c54cf..96e3f572fb 100644 --- a/OpenRa.Game/Game.cs +++ b/OpenRa.Game/Game.cs @@ -58,6 +58,7 @@ namespace OpenRa FileSystem.UnmountTemporaryPackages(); Rules.LoadRules(mapName, usingAftermath); + world = null; // trying to access the old world will NRE, rather than silently doing it wrong. world = new World(); Game.world.ActorAdded += a => { diff --git a/OpenRa.Game/PathFinder.cs b/OpenRa.Game/PathFinder.cs index e27ca54284..aabf600d62 100644 --- a/OpenRa.Game/PathFinder.cs +++ b/OpenRa.Game/PathFinder.cs @@ -4,6 +4,7 @@ using System.Linq; using OpenRa.FileFormats; using OpenRa.Support; using OpenRa.Traits; +using System.Diagnostics; namespace OpenRa { @@ -143,9 +144,7 @@ namespace OpenRa return ret; } - - - [System.Diagnostics.Conditional( "SANITY_CHECKS" )] + [Conditional( "SANITY_CHECKS" )] static void CheckSanePath( List path ) { if( path.Count == 0 ) @@ -160,7 +159,7 @@ namespace OpenRa } } - [System.Diagnostics.Conditional("SANITY_CHECKS")] + [Conditional("SANITY_CHECKS")] static void CheckSanePath2(List path, int2 src, int2 dest) { if (path.Count == 0) diff --git a/OpenRa.Game/PathSearch.cs b/OpenRa.Game/PathSearch.cs index e4db641604..30c79ae194 100755 --- a/OpenRa.Game/PathSearch.cs +++ b/OpenRa.Game/PathSearch.cs @@ -39,7 +39,12 @@ namespace OpenRa var p = queue.Pop(); cellInfo[ p.Location.X, p.Location.Y ].Seen = true; - if (passableCost[(int)umt][p.Location.X, p.Location.Y] == float.PositiveInfinity) + var custom2 = Game.world.customTerrain[p.Location.X, p.Location.Y]; + var thisCost = (custom2 != null) + ? custom2.GetCost(p.Location, umt) + : passableCost[(int)umt][p.Location.X, p.Location.Y]; + + if (thisCost == float.PositiveInfinity) return p.Location; foreach( int2 d in Util.directions ) @@ -51,6 +56,7 @@ namespace OpenRa continue; var custom = Game.world.customTerrain[newHere.X, newHere.Y]; + if (custom != null) throw new NotImplementedException(); var costHere = (custom != null) ? custom.GetCost(newHere, umt) : passableCost[(int)umt][newHere.X, newHere.Y]; if (costHere == float.PositiveInfinity) diff --git a/OpenRa.Game/Traits/Bridge.cs b/OpenRa.Game/Traits/Bridge.cs index 0ef1ff41f1..5cc841a203 100644 --- a/OpenRa.Game/Traits/Bridge.cs +++ b/OpenRa.Game/Traits/Bridge.cs @@ -32,17 +32,17 @@ namespace OpenRa.Traits yield return new Renderable(t.Value, Game.CellSize * t.Key, PaletteType.Gold); } - public void SetTiles(TileTemplate template, Dictionary replacedTiles) + public void SetTiles(World world, TileTemplate template, Dictionary replacedTiles) { Template = template; Tiles = replacedTiles; foreach (var t in replacedTiles.Keys) - Game.world.customTerrain[t.X, t.Y] = this; + world.customTerrain[t.X, t.Y] = this; - if (cachedTheater != Game.world.Map.Theater) + if (cachedTheater != world.Map.Theater) { - cachedTheater = Game.world.Map.Theater; + cachedTheater = world.Map.Theater; sprites = new Cache( x => SheetBuilder.Add(Game.world.TileSet.GetBytes(x), new Size(Game.CellSize, Game.CellSize))); From 500772519d952c883ddfd15c20fee7bd999265f9 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Tue, 19 Jan 2010 11:22:50 +1300 Subject: [PATCH 12/25] GOOD, the crash i *wanted* --- OpenRa.Game/Traits/Bridge.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenRa.Game/Traits/Bridge.cs b/OpenRa.Game/Traits/Bridge.cs index 5cc841a203..f9ce4106f5 100644 --- a/OpenRa.Game/Traits/Bridge.cs +++ b/OpenRa.Game/Traits/Bridge.cs @@ -44,7 +44,7 @@ namespace OpenRa.Traits { cachedTheater = world.Map.Theater; sprites = new Cache( - x => SheetBuilder.Add(Game.world.TileSet.GetBytes(x), + x => SheetBuilder.Add(world.TileSet.GetBytes(x), new Size(Game.CellSize, Game.CellSize))); } From 0aeef8c3f719d70c7bd4ca28c1606cc2b9db62b6 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Tue, 19 Jan 2010 11:49:01 +1300 Subject: [PATCH 13/25] bridge pathing works --- OpenRa.Game/PathSearch.cs | 1 - OpenRa.Game/TerrainCosts.cs | 8 ++++---- OpenRa.Game/Traits/Bridge.cs | 11 ++++++----- ra.yaml | 9 ++++++--- units.ini | 7 +++++-- 5 files changed, 21 insertions(+), 15 deletions(-) diff --git a/OpenRa.Game/PathSearch.cs b/OpenRa.Game/PathSearch.cs index 30c79ae194..f6a9c0266c 100755 --- a/OpenRa.Game/PathSearch.cs +++ b/OpenRa.Game/PathSearch.cs @@ -56,7 +56,6 @@ namespace OpenRa continue; var custom = Game.world.customTerrain[newHere.X, newHere.Y]; - if (custom != null) throw new NotImplementedException(); var costHere = (custom != null) ? custom.GetCost(newHere, umt) : passableCost[(int)umt][newHere.X, newHere.Y]; if (costHere == float.PositiveInfinity) diff --git a/OpenRa.Game/TerrainCosts.cs b/OpenRa.Game/TerrainCosts.cs index f794344c77..66bda9cea1 100644 --- a/OpenRa.Game/TerrainCosts.cs +++ b/OpenRa.Game/TerrainCosts.cs @@ -28,8 +28,8 @@ namespace OpenRa static class TerrainCosts { - static double[][] costs = Util.MakeArray( 4, - a => Util.MakeArray( 11, b => double.PositiveInfinity )); + static float[][] costs = Util.MakeArray(4, + a => Util.MakeArray(11, b => float.PositiveInfinity)); static TerrainCosts() { @@ -40,12 +40,12 @@ namespace OpenRa for( int j = 0 ; j < 4 ; j++ ) { string val = section.GetValue( ( (UnitMovementType)j ).ToString(), "0%" ); - costs[ j ][ i ] = 100.0 / double.Parse( val.Substring( 0, val.Length - 1 ) ); + costs[j][i] = 100f / float.Parse(val.Substring(0, val.Length - 1)); } } } - public static double Cost( UnitMovementType unitMovementType, int r ) + public static float Cost( UnitMovementType unitMovementType, int r ) { return costs[ (byte)unitMovementType ][ r ]; } diff --git a/OpenRa.Game/Traits/Bridge.cs b/OpenRa.Game/Traits/Bridge.cs index f9ce4106f5..7d4da56189 100644 --- a/OpenRa.Game/Traits/Bridge.cs +++ b/OpenRa.Game/Traits/Bridge.cs @@ -9,7 +9,7 @@ using System.Drawing; namespace OpenRa.Traits { - class BridgeInfo : OwnedActorInfo, ITraitInfo + class BridgeInfo : ITraitInfo { public object Create(Actor self) { return new Bridge(self); } } @@ -19,8 +19,9 @@ namespace OpenRa.Traits Dictionary Tiles; TileTemplate Template; Dictionary TileSprites; + Actor self; - public Bridge(Actor self) { self.RemoveOnDeath = false; } + public Bridge(Actor self) { this.self = self; self.RemoveOnDeath = false; } static string cachedTheater; static Cache sprites; @@ -55,9 +56,9 @@ namespace OpenRa.Traits public float GetCost(int2 p, UnitMovementType umt) { - throw new NotImplementedException(); - var origTile = Tiles[p]; // if this explodes, then SetTiles did something horribly wrong. - return float.PositiveInfinity; + return self.Health > 0 + ? TerrainCosts.Cost(umt, Template.TerrainType[Tiles[p]]) + : TerrainCosts.Cost(umt, 1); } } } diff --git a/ra.yaml b/ra.yaml index bcdc69117f..c41ded2c59 100644 --- a/ra.yaml +++ b/ra.yaml @@ -1438,11 +1438,14 @@ DOMF: Fake: BRIDGE: - Inherits: ^Building + Category: Building + Selectable: Bridge: BelowUnits: - -Selectable: - -Building: + Building: + Footprint: ____ ____ + Dimensions: 4,2 + HP: 1000 T01: Inherits: ^Building diff --git a/units.ini b/units.ini index 9f9fbf2d23..44d99972c5 100644 --- a/units.ini +++ b/units.ini @@ -535,8 +535,11 @@ Traits=Unit,RenderUnit,BelowUnits,InvisibleToOthers Selectable=no [Bridge] -Traits=Bridge, BelowUnits -Selectable=no +Traits=Bridge, BelowUnits, Building +Strength=1000 +Dimensions=4,2 +Footprint=____ ____ +Selectable=yes ;; temp hack [InfantryTypes] DOG From 6345f7baee4f09efc165b733ed6e00633bc61e8d Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Tue, 19 Jan 2010 11:50:12 +1300 Subject: [PATCH 14/25] spawn bridges with correct HP --- OpenRa.Game/Traits/Bridge.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/OpenRa.Game/Traits/Bridge.cs b/OpenRa.Game/Traits/Bridge.cs index 7d4da56189..22a67aff06 100644 --- a/OpenRa.Game/Traits/Bridge.cs +++ b/OpenRa.Game/Traits/Bridge.cs @@ -52,6 +52,8 @@ namespace OpenRa.Traits TileSprites = replacedTiles.ToDictionary( a => a.Key, a => sprites[new TileReference { tile = (ushort)template.Index, image = (byte)a.Value }]); + + self.Health = (int)(self.GetMaxHP() * template.HP); } public float GetCost(int2 p, UnitMovementType umt) From eb81076bce36a41babde20c229e5ca9b6debb7f4 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Tue, 19 Jan 2010 11:54:10 +1300 Subject: [PATCH 15/25] require force-fire to attack bridges --- OpenRa.Game/Traits/AttackBase.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/OpenRa.Game/Traits/AttackBase.cs b/OpenRa.Game/Traits/AttackBase.cs index 4eae9534da..d43434412c 100644 --- a/OpenRa.Game/Traits/AttackBase.cs +++ b/OpenRa.Game/Traits/AttackBase.cs @@ -180,9 +180,19 @@ namespace OpenRa.Traits if (self == underCursor) return null; var isHeal = self.GetPrimaryWeapon().Damage < 0; - if (((underCursor.Owner == self.Owner) ^ isHeal) - && !mi.Modifiers.HasModifier( Modifiers.Ctrl )) return null; + var forceFire = mi.Modifiers.HasModifier(Modifiers.Ctrl); + if (isHeal) + { + if (underCursor.Owner == null) + return null; + if (underCursor.Owner != self.Owner && !forceFire) + return null; + } + else + if ((underCursor.Owner == self.Owner || underCursor.Owner == null) && !forceFire) + return null; + if (!Combat.HasAnyValidWeapons(self, underCursor)) return null; return new Order(isHeal ? "Heal" : "Attack", self, underCursor, int2.Zero, null); From df8f37c5e440db004e506360cc0f41ffc86174b6 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Tue, 19 Jan 2010 12:37:11 +1300 Subject: [PATCH 16/25] split bridges to use different actor types for the various bridge types --- OpenRa.FileFormats/Walkability.cs | 4 ++-- OpenRa.Game/Bridges.cs | 4 ++-- ra.yaml | 22 +++++++++++++++++++++- templates.ini | 24 ++++++++++++------------ units.ini | 22 ++++++++++++++++++++-- 5 files changed, 57 insertions(+), 19 deletions(-) diff --git a/OpenRa.FileFormats/Walkability.cs b/OpenRa.FileFormats/Walkability.cs index 5095c49a3a..536517a8b6 100644 --- a/OpenRa.FileFormats/Walkability.cs +++ b/OpenRa.FileFormats/Walkability.cs @@ -9,7 +9,7 @@ namespace OpenRa.FileFormats public int Index; public string Name; public int2 Size; - public bool IsBridge; + public string Bridge; public float HP; public Dictionary TerrainType = new Dictionary(); } @@ -37,7 +37,7 @@ namespace OpenRa.FileFormats p => int.Parse(p.Value)), Name = section.GetValue("Name", null).ToLowerInvariant(), Index = int.Parse(section.Name.Substring(3)), - IsBridge = section.GetValue("bridge", "no") != "no", + Bridge = section.GetValue("bridge", null), HP = float.Parse(section.GetValue("hp", "0")) }; diff --git a/OpenRa.Game/Bridges.cs b/OpenRa.Game/Bridges.cs index 1d9ad28626..2c3d7132ff 100644 --- a/OpenRa.Game/Bridges.cs +++ b/OpenRa.Game/Bridges.cs @@ -50,7 +50,7 @@ namespace OpenRa if (replacedTiles.Any()) { - var a = w.CreateActor("Bridge", new int2(ni, nj), null); + var a = w.CreateActor(template.Bridge, new int2(ni, nj), null); var br = a.traits.Get(); br.SetTiles(w, template, replacedTiles); } @@ -58,7 +58,7 @@ namespace OpenRa static bool IsBridge(World w, ushort t) { - return w.TileSet.walk[t].IsBridge; + return w.TileSet.walk[t].Bridge != null; } } } diff --git a/ra.yaml b/ra.yaml index c41ded2c59..9d675df2b2 100644 --- a/ra.yaml +++ b/ra.yaml @@ -1437,7 +1437,27 @@ DOMF: Image: DOME Fake: -BRIDGE: +BR1: + Category: Building + Selectable: + Bridge: + BelowUnits: + Building: + Footprint: ____ ____ + Dimensions: 4,2 + HP: 1000 + +BR2: + Category: Building + Selectable: + Bridge: + BelowUnits: + Building: + Footprint: ____ ____ + Dimensions: 4,2 + HP: 1000 + +BR3: Category: Building Selectable: Bridge: diff --git a/templates.ini b/templates.ini index 023e01336a..22b7a963d0 100644 --- a/templates.ini +++ b/templates.ini @@ -2491,7 +2491,7 @@ tiletype3=3 Name=BR1A width=4 height=3 -bridge=yes +bridge=br1 hp=1 tiletype1=3 tiletype2=2 @@ -2507,7 +2507,7 @@ tiletype11=3 Name=BR1B width=4 height=3 -bridge=yes +bridge=br1 hp=.5 tiletype1=3 tiletype2=6 @@ -2523,7 +2523,7 @@ tiletype11=3 Name=BR1C width=4 height=3 -bridge=yes +bridge=br1 hp=0 tiletype1=3 tiletype2=3 @@ -2539,7 +2539,7 @@ tiletype11=3 Name=BR2A width=5 height=3 -bridge=yes +bridge=br2 hp=1 tiletype1=3 tiletype2=2 @@ -2556,7 +2556,7 @@ tiletype13=3 Name=BR2B width=5 height=3 -bridge=yes +bridge=br2 hp=.5 tiletype1=3 tiletype2=6 @@ -2573,7 +2573,7 @@ tiletype13=3 Name=BR2C width=5 height=3 -bridge=yes +bridge=br2 hp=0 tiletype1=1 tiletype2=1 @@ -2590,7 +2590,7 @@ tiletype13=3 Name=BR3A width=4 height=2 -bridge=yes +bridge=br3 hp=1 tiletype0=3 tiletype1=2 @@ -2602,7 +2602,7 @@ tiletype7=3 Name=BR3B width=4 height=2 -bridge=yes +bridge=br3 hp=.5 tiletype0=3 tiletype1=2 @@ -2614,7 +2614,7 @@ tiletype7=3 Name=BR3C width=4 height=2 -bridge=yes +bridge=br3 hp=0 tiletype0=3 tiletype1=3 @@ -2626,7 +2626,7 @@ tiletype7=3 Name=BR3D width=4 height=2 -bridge=yes +bridge=br3 hp=0 tiletype0=5 tiletype1=3 @@ -2638,7 +2638,7 @@ tiletype7=5 Name=BR3E width=4 height=2 -bridge=yes +bridge=br3 hp=0 tiletype0=1 tiletype1=1 @@ -2650,7 +2650,7 @@ tiletype7=1 Name=BR3F width=4 height=2 -bridge=yes +bridge=br3 hp=0 tiletype0=1 tiletype1=1 diff --git a/units.ini b/units.ini index 44d99972c5..86cf02629d 100644 --- a/units.ini +++ b/units.ini @@ -253,7 +253,9 @@ DOMF ; pseudo-buildings MINP MINV -BRIDGE +BR1 +BR2 +BR3 ; `Dimensions` is the size of a box that will include the whole building, excluding bib. @@ -534,13 +536,29 @@ Selectable=no Traits=Unit,RenderUnit,BelowUnits,InvisibleToOthers Selectable=no -[Bridge] +[BR1] +Traits=Bridge, BelowUnits, Building +Strength=1000 +Dimensions=4,2 +Footprint=____ ____ +Selectable=yes + +[BR2] Traits=Bridge, BelowUnits, Building Strength=1000 Dimensions=4,2 Footprint=____ ____ Selectable=yes ;; temp hack +[BR3] +Traits=Bridge, BelowUnits, Building +Strength=1000 +Dimensions=4,2 +Footprint=____ ____ +Selectable=yes ;; temp hack + +;; todo: short bridges + [InfantryTypes] DOG E1 From 84a6bfaca01be28e8906410ed7144a0ebad72e88 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Tue, 19 Jan 2010 12:54:16 +1300 Subject: [PATCH 17/25] unhacking most of that mess. --- OpenRa.FileFormats/TileSet.cs | 9 ++++---- OpenRa.FileFormats/Walkability.cs | 4 ++-- OpenRa.Game/Traits/Bridge.cs | 36 +++++++++++++++++++++---------- merge-ra.yaml | 4 ++++ ra.yaml | 21 +++++++++--------- 5 files changed, 47 insertions(+), 27 deletions(-) diff --git a/OpenRa.FileFormats/TileSet.cs b/OpenRa.FileFormats/TileSet.cs index 6f2e05df1d..894a46be4f 100644 --- a/OpenRa.FileFormats/TileSet.cs +++ b/OpenRa.FileFormats/TileSet.cs @@ -8,8 +8,9 @@ namespace OpenRa.FileFormats { public readonly Dictionary tiles = new Dictionary(); - public readonly Dictionary walk = - new Dictionary(); // cjf will fix + public readonly Walkability Walkability = new Walkability(); + public readonly Dictionary walk + = new Dictionary(); string NextLine( StreamReader reader ) { @@ -27,7 +28,7 @@ namespace OpenRa.FileFormats public TileSet( string suffix ) { - Walkability walkability = new Walkability(); + Walkability = new Walkability(); char tileSetChar = char.ToUpperInvariant( suffix[ 1 ] ); StreamReader tileIdFile = new StreamReader( FileSystem.Open( "tileSet.til" ) ); @@ -51,7 +52,7 @@ namespace OpenRa.FileFormats string tilename = string.Format(pattern, i + 1); if (!walk.ContainsKey((ushort)(start + i))) - walk.Add((ushort)(start + i), walkability.GetWalkability(tilename)); + walk.Add((ushort)(start + i), Walkability.GetWalkability(tilename)); using( Stream s = FileSystem.Open( tilename + suffix ) ) { diff --git a/OpenRa.FileFormats/Walkability.cs b/OpenRa.FileFormats/Walkability.cs index 536517a8b6..a94045b6f2 100644 --- a/OpenRa.FileFormats/Walkability.cs +++ b/OpenRa.FileFormats/Walkability.cs @@ -14,9 +14,9 @@ namespace OpenRa.FileFormats public Dictionary TerrainType = new Dictionary(); } - class Walkability + public class Walkability { - public Dictionary walkability + Dictionary walkability = new Dictionary(); public Walkability() diff --git a/OpenRa.Game/Traits/Bridge.cs b/OpenRa.Game/Traits/Bridge.cs index 22a67aff06..34dacffbad 100644 --- a/OpenRa.Game/Traits/Bridge.cs +++ b/OpenRa.Game/Traits/Bridge.cs @@ -11,15 +11,17 @@ namespace OpenRa.Traits { class BridgeInfo : ITraitInfo { + public readonly bool Long = false; public object Create(Actor self) { return new Bridge(self); } } class Bridge : IRender, ICustomTerrain { Dictionary Tiles; - TileTemplate Template; - Dictionary TileSprites; + List> TileSprites = new List>(); + List Templates = new List(); Actor self; + int state; public Bridge(Actor self) { this.self = self; self.RemoveOnDeath = false; } @@ -28,15 +30,14 @@ namespace OpenRa.Traits public IEnumerable Render(Actor self) { - if (Template == null) yield break; - foreach (var t in TileSprites) + foreach (var t in TileSprites[state]) yield return new Renderable(t.Value, Game.CellSize * t.Key, PaletteType.Gold); } public void SetTiles(World world, TileTemplate template, Dictionary replacedTiles) { - Template = template; Tiles = replacedTiles; + state = template.Name[template.Name.Length - 1] - 'a'; foreach (var t in replacedTiles.Keys) world.customTerrain[t.X, t.Y] = this; @@ -49,18 +50,31 @@ namespace OpenRa.Traits new Size(Game.CellSize, Game.CellSize))); } - TileSprites = replacedTiles.ToDictionary( - a => a.Key, - a => sprites[new TileReference { tile = (ushort)template.Index, image = (byte)a.Value }]); + var numStates = self.Info.Traits.Get().Long ? 6 : 3; + for (var n = 0; n < numStates; n++) + { + var stateTemplate = world.TileSet.Walkability.GetWalkability(template.Bridge + (char)(n + 'a')); + Templates.Add( stateTemplate ); + + TileSprites.Add(replacedTiles.ToDictionary( + a => a.Key, + a => sprites[new TileReference { tile = (ushort)stateTemplate.Index, image = (byte)a.Value }])); + } self.Health = (int)(self.GetMaxHP() * template.HP); } + public void FinalizeBridges(World world) + { + // go looking for our neighbors + } + public float GetCost(int2 p, UnitMovementType umt) { - return self.Health > 0 - ? TerrainCosts.Cost(umt, Template.TerrainType[Tiles[p]]) - : TerrainCosts.Cost(umt, 1); + // just use the standard walkability from templates.ini. no hackery. + + return TerrainCosts.Cost(umt, + Templates[state].TerrainType[Tiles[p]]); } } } diff --git a/merge-ra.yaml b/merge-ra.yaml index 91a72aedc9..a5e511b71b 100644 --- a/merge-ra.yaml +++ b/merge-ra.yaml @@ -28,3 +28,7 @@ MINV: Warhead: ATMine TriggeredBy: Wheel, Track AvoidFriendly: yes + +BR3: + Bridge: + Long: yes \ No newline at end of file diff --git a/ra.yaml b/ra.yaml index 9d675df2b2..a27e127cbb 100644 --- a/ra.yaml +++ b/ra.yaml @@ -83,6 +83,17 @@ MINV: -Selectable: -Building: +BR3: + Bridge: + Long: yes + Category: Building + Selectable: + BelowUnits: + Building: + Footprint: ____ ____ + Dimensions: 4,2 + HP: 1000 + V2RL: Inherits: ^Vehicle Buildable: @@ -1457,16 +1468,6 @@ BR2: Dimensions: 4,2 HP: 1000 -BR3: - Category: Building - Selectable: - Bridge: - BelowUnits: - Building: - Footprint: ____ ____ - Dimensions: 4,2 - HP: 1000 - T01: Inherits: ^Building Building: From 61a543db3ca4b9d0c9ad7bf62b25925da923826f Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Tue, 19 Jan 2010 12:55:30 +1300 Subject: [PATCH 18/25] FinalizeBridges hooked up --- OpenRa.Game/Bridges.cs | 3 +++ OpenRa.Game/Traits/Bridge.cs | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/OpenRa.Game/Bridges.cs b/OpenRa.Game/Bridges.cs index 2c3d7132ff..42b0daf25e 100644 --- a/OpenRa.Game/Bridges.cs +++ b/OpenRa.Game/Bridges.cs @@ -17,6 +17,9 @@ namespace OpenRa for (var i = mini; i < maxi; i++) if (IsBridge(w, w.Map.MapTiles[i, j].tile)) ConvertBridgeToActor(w, i, j); + + foreach (var br in w.Actors.SelectMany(a => a.traits.WithInterface())) + br.FinalizeBridges(w); } static void ConvertBridgeToActor(World w, int i, int j) diff --git a/OpenRa.Game/Traits/Bridge.cs b/OpenRa.Game/Traits/Bridge.cs index 34dacffbad..a3d7af158b 100644 --- a/OpenRa.Game/Traits/Bridge.cs +++ b/OpenRa.Game/Traits/Bridge.cs @@ -66,7 +66,7 @@ namespace OpenRa.Traits public void FinalizeBridges(World world) { - // go looking for our neighbors + // go looking for our neighbors, if this is a long bridge. } public float GetCost(int2 p, UnitMovementType umt) From e07f4c926ea0095c9881410f7c752a4cf9b716ea Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Tue, 19 Jan 2010 13:05:20 +1300 Subject: [PATCH 19/25] almost. got a problem with missing tiles, though --- OpenRa.Game/Traits/Bridge.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/OpenRa.Game/Traits/Bridge.cs b/OpenRa.Game/Traits/Bridge.cs index a3d7af158b..3e4e6abbe1 100644 --- a/OpenRa.Game/Traits/Bridge.cs +++ b/OpenRa.Game/Traits/Bridge.cs @@ -15,7 +15,7 @@ namespace OpenRa.Traits public object Create(Actor self) { return new Bridge(self); } } - class Bridge : IRender, ICustomTerrain + class Bridge : IRender, ICustomTerrain, INotifyDamage { Dictionary Tiles; List> TileSprites = new List>(); @@ -76,5 +76,12 @@ namespace OpenRa.Traits return TerrainCosts.Cost(umt, Templates[state].TerrainType[Tiles[p]]); } + + public void Damaged(Actor self, AttackInfo e) + { + // todo: long bridges have d/e/f states too. + if (e.DamageStateChanged) + state = (int)e.DamageState; + } } } From f623aea8649078fdfd37a806ad796a22787ebb80 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Tue, 19 Jan 2010 13:25:56 +1300 Subject: [PATCH 20/25] fixed tileset --- tileSet.til | 72 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 54 insertions(+), 18 deletions(-) diff --git a/tileSet.til b/tileSet.til index 39ed4bac67..4dfd06827d 100644 --- a/tileSet.til +++ b/tileSet.til @@ -91,18 +91,72 @@ TS- 00eb br1a +; long bridge (north end, damaged) +TS- +1 +00ec +br1b + +; long bridge (north end, broken) +TS- +1 +00ed +br1c + ; long bridge (south end) TS- 1 00ee br2a +; long bridge (south end, damaged) +TS- +1 +00ef +br2b + +; long bridge (south end, broken) +TS- +1 +00f0 +br2c + ; long bridge (middle) TS- 1 00f1 br3a +; long bridge (middle, damaged) +TS- +1 +00f2 +br3b + +; long bridge (middle, broken) +TS- +1 +00f3 +br3c + +; long bridge (middle, broken, south end missing) +TS- +1 +00f4 +br3d + +; long bridge (middle, broken, north end missing) +TS- +1 +00f5 +br3e + +; long bridge (water / totally broken) +TS- +1 +00f6 +br3f + ; long bridge (north surround) TS- 1 @@ -115,24 +169,6 @@ TS- 017d br2x -; long bridge (north end, broken) -TS- -1 -00ed -br1c - -; long bridge (south end, broken) -TS- -1 -00f0 -br2c - -; long bridge (water / totally broken) -TS- -1 -00f6 -br3f - ; short bridge "/" TS- 1 From 29728bb6fb598f367f16dd6ec6e75ac31146eedb Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Tue, 19 Jan 2010 13:45:32 +1300 Subject: [PATCH 21/25] allow alternate names (''/'h'/'d') so we can do short bridges --- OpenRa.Game/Traits/Bridge.cs | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/OpenRa.Game/Traits/Bridge.cs b/OpenRa.Game/Traits/Bridge.cs index 3e4e6abbe1..84e0de14cc 100644 --- a/OpenRa.Game/Traits/Bridge.cs +++ b/OpenRa.Game/Traits/Bridge.cs @@ -12,6 +12,7 @@ namespace OpenRa.Traits class BridgeInfo : ITraitInfo { public readonly bool Long = false; + public readonly bool UseAlternateNames = false; public object Create(Actor self) { return new Bridge(self); } } @@ -34,10 +35,32 @@ namespace OpenRa.Traits yield return new Renderable(t.Value, Game.CellSize * t.Key, PaletteType.Gold); } + public int StateFromTemplate(TileTemplate t) + { + var info = self.Info.Traits.Get(); + if (info.UseAlternateNames) + { + if (t.Name.EndsWith("d")) return 2; + if (t.Name.EndsWith("h")) return 1; + return 0; + } + else + return t.Name[t.Name.Length - 1] - 'a'; + } + + public string NameFromState(TileTemplate t, int state) + { + var info = self.Info.Traits.Get(); + if (info.UseAlternateNames) + return t.Bridge + new[] { "", "h", "d" }[state]; + else + return t.Bridge + (char)(state + 'a'); + } + public void SetTiles(World world, TileTemplate template, Dictionary replacedTiles) { Tiles = replacedTiles; - state = template.Name[template.Name.Length - 1] - 'a'; + state = StateFromTemplate(template); foreach (var t in replacedTiles.Keys) world.customTerrain[t.X, t.Y] = this; @@ -53,7 +76,7 @@ namespace OpenRa.Traits var numStates = self.Info.Traits.Get().Long ? 6 : 3; for (var n = 0; n < numStates; n++) { - var stateTemplate = world.TileSet.Walkability.GetWalkability(template.Bridge + (char)(n + 'a')); + var stateTemplate = world.TileSet.Walkability.GetWalkability(NameFromState(template, n)); Templates.Add( stateTemplate ); TileSprites.Add(replacedTiles.ToDictionary( From fb6a8a2cddda89d2a135634c8f5c61c1691848d7 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Tue, 19 Jan 2010 13:56:01 +1300 Subject: [PATCH 22/25] short bridges --- merge-ra.yaml | 10 +++++++++- ra.yaml | 22 ++++++++++++++++++++++ templates.ini | 12 ++++++++++++ tileSet.til | 6 ++++++ units.ini | 16 +++++++++++++++- 5 files changed, 64 insertions(+), 2 deletions(-) diff --git a/merge-ra.yaml b/merge-ra.yaml index a5e511b71b..4c28e1dd42 100644 --- a/merge-ra.yaml +++ b/merge-ra.yaml @@ -31,4 +31,12 @@ MINV: BR3: Bridge: - Long: yes \ No newline at end of file + Long: yes + +BRIDGE1: + Bridge: + UseAlternateNames: yes + +BRIDGE2: + Bridge: + UseAlternateNames: yes diff --git a/ra.yaml b/ra.yaml index a27e127cbb..4005550a1a 100644 --- a/ra.yaml +++ b/ra.yaml @@ -94,6 +94,28 @@ BR3: Dimensions: 4,2 HP: 1000 +BRIDGE1: + Bridge: + UseAlternateNames: yes + Category: Building + Selectable: + BelowUnits: + Building: + Footprint: _____ _____ _____ + Dimensions: 5,3 + HP: 1000 + +BRIDGE2: + Bridge: + UseAlternateNames: yes + Category: Building + Selectable: + BelowUnits: + Building: + Footprint: _____ _____ + Dimensions: 5,2 + HP: 1000 + V2RL: Inherits: ^Vehicle Buildable: diff --git a/templates.ini b/templates.ini index 22b7a963d0..b3d10064a0 100644 --- a/templates.ini +++ b/templates.ini @@ -1533,6 +1533,8 @@ tiletype8=0 Name=BRIDGE1 width=5 height=3 +bridge=bridge1 +hp=1 tiletype1=3 tiletype2=2 tiletype3=2 @@ -1548,6 +1550,8 @@ tiletype12=3 Name=BRIDGE1D width=5 height=3 +bridge=bridge1 +hp=0 tiletype1=3 tiletype2=3 tiletype3=3 @@ -1563,6 +1567,8 @@ tiletype12=3 Name=BRIDGE2 width=5 height=2 +bridge=bridge2 +hp=1 tiletype0=3 tiletype1=2 tiletype2=2 @@ -1577,6 +1583,8 @@ tiletype9=3 Name=BRIDGE2D width=5 height=2 +bridge=bridge2 +hp=0 tiletype0=3 tiletype1=3 tiletype2=3 @@ -2750,6 +2758,8 @@ tiletype0=0 Name=BRIDGE1H width=5 height=3 +bridge=bridge1 +hp=.5 tiletype1=3 tiletype2=6 tiletype3=6 @@ -2765,6 +2775,8 @@ tiletype12=6 Name=BRIDGE2H width=5 height=2 +bridge=bridge2 +hp=.5 tiletype0=3 tiletype1=6 tiletype2=6 diff --git a/tileSet.til b/tileSet.til index 4dfd06827d..0506843ffc 100644 --- a/tileSet.til +++ b/tileSet.til @@ -208,6 +208,12 @@ bridge2d ; short bridge "\" (damaged) TS- 1 +017b +bridge2h + +; short bridge "\" (surround) +TS- +1 017f bridge2x diff --git a/units.ini b/units.ini index 86cf02629d..f504743fdf 100644 --- a/units.ini +++ b/units.ini @@ -256,6 +256,8 @@ MINV BR1 BR2 BR3 +BRIDGE1 +BRIDGE2 ; `Dimensions` is the size of a box that will include the whole building, excluding bib. @@ -557,7 +559,19 @@ Dimensions=4,2 Footprint=____ ____ Selectable=yes ;; temp hack -;; todo: short bridges +[BRIDGE1] +Traits=Bridge, BelowUnits, Building +Strength=1000 +Dimensions=5,3 +Footprint=_____ _____ _____ +Selectable = yes + +[BRIDGE2] +Traits=Bridge, BelowUnits, Building +Strength=1000 +Dimensions=5,2 +Footprint=_____ _____ +Selectable = yes [InfantryTypes] DOG From 8b1ad5722570db62c2521c2d1186d41c5c4cdaa2 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Tue, 19 Jan 2010 14:06:32 +1300 Subject: [PATCH 23/25] fix engineer/bridge interaction --- OpenRa.Mods.RA/EngineerCapture.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/OpenRa.Mods.RA/EngineerCapture.cs b/OpenRa.Mods.RA/EngineerCapture.cs index c053c3bb78..1d07608b1f 100644 --- a/OpenRa.Mods.RA/EngineerCapture.cs +++ b/OpenRa.Mods.RA/EngineerCapture.cs @@ -17,6 +17,7 @@ namespace OpenRa.Mods.RA if (!underCursor.traits.Contains()) return null; // todo: other bits + if (underCursor.Owner == null) return null; // don't allow capturing of bridges, etc. return new Order(underCursor.Health <= EngineerDamage ? "Capture" : "Infiltrate", self, underCursor, int2.Zero, null); From bf8a947c9e86b4be0504b338fc9c5bf30f17a335 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Tue, 19 Jan 2010 14:39:03 +1300 Subject: [PATCH 24/25] bridge pieces connect --- OpenRa.Game/Traits/Bridge.cs | 52 ++++++++++++++++++++++++++++++++++-- merge-ra.yaml | 8 ++++++ ra.yaml | 44 ++++++++++++++++-------------- 3 files changed, 82 insertions(+), 22 deletions(-) diff --git a/OpenRa.Game/Traits/Bridge.cs b/OpenRa.Game/Traits/Bridge.cs index 84e0de14cc..cbbb238513 100644 --- a/OpenRa.Game/Traits/Bridge.cs +++ b/OpenRa.Game/Traits/Bridge.cs @@ -13,6 +13,8 @@ namespace OpenRa.Traits { public readonly bool Long = false; public readonly bool UseAlternateNames = false; + public readonly int[] NorthOffset = null; + public readonly int[] SouthOffset = null; public object Create(Actor self) { return new Bridge(self); } } @@ -24,6 +26,8 @@ namespace OpenRa.Traits Actor self; int state; + Bridge northNeighbour, southNeighbour; + public Bridge(Actor self) { this.self = self; self.RemoveOnDeath = false; } static string cachedTheater; @@ -87,9 +91,22 @@ namespace OpenRa.Traits self.Health = (int)(self.GetMaxHP() * template.HP); } + Bridge GetNeighbor(World world, int[] offset) + { + if (offset == null) return null; + var pos = self.Location + new int2(offset[0], offset[1]); + if (!world.Map.IsInMap(pos.X, pos.Y)) return null; + return world.customTerrain[pos.X, pos.Y] as Bridge; + } + public void FinalizeBridges(World world) { // go looking for our neighbors, if this is a long bridge. + var info = self.Info.Traits.Get(); + if (info.NorthOffset != null) + northNeighbour = GetNeighbor(world, info.NorthOffset); + if (info.SouthOffset != null) + southNeighbour = GetNeighbor(world, info.SouthOffset); } public float GetCost(int2 p, UnitMovementType umt) @@ -100,11 +117,42 @@ namespace OpenRa.Traits Templates[state].TerrainType[Tiles[p]]); } + bool IsIntact(Bridge b) + { + return b != null && b.self.IsInWorld && b.self.Health > 0; + } + + bool IsLong(Bridge b) + { + return b != null && b.self.IsInWorld && b.self.Info.Traits.Get().Long; + } + + void UpdateState() + { + var ds = self.GetDamageState(); + if (!self.Info.Traits.Get().Long) + { + state = (int)ds; + return; + } + + bool waterToSouth = !IsIntact(southNeighbour) && (!IsLong(southNeighbour) || !IsIntact(this)); + bool waterToNorth = !IsIntact(northNeighbour) && (!IsLong(northNeighbour) || !IsIntact(this)); + + if (waterToSouth && waterToNorth) { state = 5; return; } + if (waterToNorth) { state = 4; return; } + if (waterToSouth) { state = 3; return; } + state = (int)ds; + } + public void Damaged(Actor self, AttackInfo e) { - // todo: long bridges have d/e/f states too. if (e.DamageStateChanged) - state = (int)e.DamageState; + { + UpdateState(); + if (northNeighbour != null) northNeighbour.UpdateState(); + if (southNeighbour != null) southNeighbour.UpdateState(); + } } } } diff --git a/merge-ra.yaml b/merge-ra.yaml index 4c28e1dd42..9a7ddcdd3c 100644 --- a/merge-ra.yaml +++ b/merge-ra.yaml @@ -29,9 +29,17 @@ MINV: TriggeredBy: Wheel, Track AvoidFriendly: yes +BR1: + Bridge: + SouthOffset:0,2 +BR2: + Bridge: + NorthOffset:3,0 BR3: Bridge: Long: yes + NorthOffset: 2,0 + SouthOffset: 0,1 BRIDGE1: Bridge: diff --git a/ra.yaml b/ra.yaml index 4005550a1a..c4dd2271b0 100644 --- a/ra.yaml +++ b/ra.yaml @@ -83,9 +83,33 @@ MINV: -Selectable: -Building: +BR1: + Bridge: + SouthOffset: 0,2 + Category: Building + Selectable: + BelowUnits: + Building: + Footprint: ____ ____ + Dimensions: 4,2 + HP: 1000 + +BR2: + Bridge: + NorthOffset: 3,0 + Category: Building + Selectable: + BelowUnits: + Building: + Footprint: ____ ____ + Dimensions: 4,2 + HP: 1000 + BR3: Bridge: Long: yes + NorthOffset: 2,0 + SouthOffset: 0,1 Category: Building Selectable: BelowUnits: @@ -1470,26 +1494,6 @@ DOMF: Image: DOME Fake: -BR1: - Category: Building - Selectable: - Bridge: - BelowUnits: - Building: - Footprint: ____ ____ - Dimensions: 4,2 - HP: 1000 - -BR2: - Category: Building - Selectable: - Bridge: - BelowUnits: - Building: - Footprint: ____ ____ - Dimensions: 4,2 - HP: 1000 - T01: Inherits: ^Building Building: From 266fc91062e4e0d455c930931ab8375ce5d34559 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Tue, 19 Jan 2010 15:10:42 +1300 Subject: [PATCH 25/25] restore normal shroud --- OpenRa.Game/Shroud.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/OpenRa.Game/Shroud.cs b/OpenRa.Game/Shroud.cs index 8943aaa216..91622065cd 100644 --- a/OpenRa.Game/Shroud.cs +++ b/OpenRa.Game/Shroud.cs @@ -137,8 +137,6 @@ namespace OpenRa internal void Draw(SpriteRenderer r) { - return; // temp; just so i can see until i'm done with the bridges. - if (dirty) { dirty = false;