From 08ee425415c900c9e77e3e3ce8d1e05851167d03 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sat, 26 Jun 2010 12:02:30 +1200 Subject: [PATCH] Fix some stupid bugs; remove hardcoded references to water/ore/tree terraintypes --- OpenRA.FileFormats/Map/TileSet.cs | 8 +++--- OpenRA.Game/Combat.cs | 3 +-- OpenRA.Game/Graphics/Minimap.cs | 32 +++++++++++------------- OpenRA.Game/Traits/Mobile.cs | 16 ++++++------ OpenRA.Game/Traits/World/ResourceType.cs | 2 +- OpenRA.Game/WorldUtils.cs | 3 +-- OpenRA.Mods.RA/Crate.cs | 2 +- mods/cnc/tileset-des.yaml | 1 + mods/cnc/tileset-tem.yaml | 1 + mods/cnc/tileset-win.yaml | 1 + mods/ra/tileset-int.yaml | 1 + mods/ra/tileset-sno.yaml | 1 + mods/ra/tileset-tem.yaml | 1 + 13 files changed, 39 insertions(+), 33 deletions(-) diff --git a/OpenRA.FileFormats/Map/TileSet.cs b/OpenRA.FileFormats/Map/TileSet.cs index 6164a2603b..946e8495e2 100644 --- a/OpenRA.FileFormats/Map/TileSet.cs +++ b/OpenRA.FileFormats/Map/TileSet.cs @@ -30,6 +30,7 @@ namespace OpenRA.FileFormats public string Type; public bool Buildable = true; public bool AcceptSmudge = true; + public bool IsWater = false; public Color Color; public TerrainTypeInfo(MiniYaml my) @@ -46,13 +47,15 @@ namespace OpenRA.FileFormats public string Bridge; public float HP; public bool PickAny; - public Dictionary Tiles = new Dictionary(); + public Dictionary Tiles = new Dictionary(); static List fields = new List() {"Id", "Image", "Size", "Bridge", "HP", "PickAny"}; public TileTemplate(Dictionary my) { FieldLoader.LoadFields(this, my, fields); + foreach (var tt in my["Tiles"].Nodes) + Tiles.Add(byte.Parse(tt.Key), tt.Value.Value); } } @@ -107,8 +110,7 @@ namespace OpenRA.FileFormats var tt = Templates[r.type].Tiles; string ret; if (!tt.TryGetValue(r.image, out ret)) - return "Clear";// Default zero (walkable) - + return "Clear"; // Default walkable return ret; } } diff --git a/OpenRA.Game/Combat.cs b/OpenRA.Game/Combat.cs index 78175ce07e..fa981fa80a 100644 --- a/OpenRA.Game/Combat.cs +++ b/OpenRA.Game/Combat.cs @@ -48,8 +48,7 @@ namespace OpenRA if (!world.Map.IsInMap(targetTile)) return; - // Todo: Unhardcode "Water" terraintype reference - var isWater = world.GetTerrainType(targetTile) == "Water"; + var isWater = world.GetTerrainInfo(targetTile).IsWater; if (warhead.Explosion != 0) world.AddFrameEndTask( diff --git a/OpenRA.Game/Graphics/Minimap.cs b/OpenRA.Game/Graphics/Minimap.cs index 218c75f834..269e48ad08 100644 --- a/OpenRA.Game/Graphics/Minimap.cs +++ b/OpenRA.Game/Graphics/Minimap.cs @@ -34,7 +34,7 @@ namespace OpenRA.Graphics SpriteRenderer rgbaRenderer; LineRenderer lineRenderer; Sprite sprite; - Bitmap terrain, oreLayer; + Bitmap terrain, customLayer; Rectangle bounds; Sprite ownedSpawnPoint; @@ -74,7 +74,7 @@ namespace OpenRA.Graphics static Color shroudColor; - public void InvalidateOre() { oreLayer = null; } + public void InvalidateCustom() { customLayer = null; } public static Bitmap RenderTerrainBitmap(Map map, TileSet tileset) { @@ -92,28 +92,29 @@ namespace OpenRA.Graphics } public void Update() - { + { if (terrain == null) terrain = RenderTerrainBitmap(world.Map, world.TileSet); - if (oreLayer == null) + // Custom terrain layer + if (customLayer == null) { - var res = world.WorldActor.traits.Get(); - - // This is an ugly hack - Color oreColor = world.TileSet.Terrain["Ore"].Color; - - oreLayer = new Bitmap(terrain); + customLayer = new Bitmap(terrain); for (var x = world.Map.TopLeft.X; x < world.Map.BottomRight.X; x++) for (var y = world.Map.TopLeft.Y; y < world.Map.BottomRight.Y; y++) - if (res.GetResource(new int2(x,y)) != null) - oreLayer.SetPixel(x, y, Color.FromArgb(alpha, oreColor)); + { + var customTerrain = world.WorldActor.traits.WithInterface() + .Select( t => t.GetTerrainType(new int2(x,y)) ) + .FirstOrDefault( t => t != null ); + if (customTerrain == null) continue; + customLayer.SetPixel(x, y, Color.FromArgb(alpha, world.TileSet.Terrain[customTerrain].Color)); + } } if (!world.GameHasStarted || !world.Queries.OwnedBy[world.LocalPlayer].WithTrait().Any()) return; - var bitmap = new Bitmap(oreLayer); + var bitmap = new Bitmap(customLayer); var bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); @@ -135,11 +136,8 @@ namespace OpenRA.Graphics } var b = world.WorldActor.traits.Get().GetBuildingAt(new int2(x, y)); - // This is an even worse hack than the ore! - var treeColor = world.TileSet.Terrain["tree"].Color; if (b != null) - *(c + (y * bitmapData.Stride >> 2) + x) = - (b.Owner != null ? Color.FromArgb(alpha, b.Owner.Color) : Color.FromArgb(alpha, treeColor)).ToArgb(); + *(c + (y * bitmapData.Stride >> 2) + x) = Color.FromArgb(alpha, b.Owner.Color).ToArgb(); } } diff --git a/OpenRA.Game/Traits/Mobile.cs b/OpenRA.Game/Traits/Mobile.cs index 962c721fda..c4cafa934f 100644 --- a/OpenRA.Game/Traits/Mobile.cs +++ b/OpenRA.Game/Traits/Mobile.cs @@ -144,6 +144,9 @@ namespace OpenRA.Traits var building = self.World.WorldActor.traits.Get().GetBuildingBlocking(cell); if (building != null && building != ignoreActor) { + if (Info.Crushes == null) + return false; + var crushable = building.traits.WithInterface(); if (crushable.Count() == 0) return false; @@ -164,7 +167,10 @@ namespace OpenRA.Traits if (shareable.Count() >= 5) return false; - // We can enter a cell with nonshareable units if we can crush all of them + // We can enter a cell with nonshareable units only if we can crush all of them + if (Info.Crushes == null && nonshareable.Count() > 0) + return false; + if (nonshareable.Any(a => !(a.traits.Contains() && a.traits.WithInterface().Any(b => b.CrushClasses.Intersect(Info.Crushes).Any())))) return false; @@ -191,11 +197,9 @@ namespace OpenRA.Traits // Custom terrain types don't stack: pick one var customTerrain = self.World.WorldActor.traits.WithInterface() - .Where( t => t.GetTerrainType(cell) != null ) .Select( t => t.GetTerrainType(cell) ) - .FirstOrDefault(); + .FirstOrDefault( t => t != null ); - // Todo: Hack this until i finish migrating TerrainType to a string var type = (customTerrain != null) ? customTerrain : self.World.GetTerrainType(cell); var additionalCost = self.World.WorldActor.traits.WithInterface() .Select( t => t.GetTerrainCost(cell, self) ).Sum(); @@ -211,11 +215,9 @@ namespace OpenRA.Traits // Custom terrain types don't stack: pick one var customTerrain = self.World.WorldActor.traits.WithInterface() - .Where( t => t.GetTerrainType(cell) != null ) .Select( t => t.GetTerrainType(cell) ) - .FirstOrDefault(); + .FirstOrDefault( t => t != null ); - // Todo: Hack this until i finish migrating TerrainType to a string var type = (customTerrain != null) ? customTerrain : self.World.GetTerrainType(cell); var modifier = self.traits diff --git a/OpenRA.Game/Traits/World/ResourceType.cs b/OpenRA.Game/Traits/World/ResourceType.cs index cc58575d09..093536f85d 100644 --- a/OpenRA.Game/Traits/World/ResourceType.cs +++ b/OpenRA.Game/Traits/World/ResourceType.cs @@ -32,7 +32,7 @@ namespace OpenRA.Traits public readonly int ValuePerUnit = 0; public readonly string Name = null; - public readonly string TerrainType = null; + public readonly string TerrainType = "Ore"; public Sprite[][] Sprites; diff --git a/OpenRA.Game/WorldUtils.cs b/OpenRA.Game/WorldUtils.cs index 8faf5b3283..1e927ceb14 100755 --- a/OpenRA.Game/WorldUtils.cs +++ b/OpenRA.Game/WorldUtils.cs @@ -41,9 +41,8 @@ namespace OpenRA if (world.WorldActor.traits.Get().GetBuildingAt(a) != null) return false; if (world.WorldActor.traits.Get().GetUnitsAt(a).Any(b => b != toIgnore)) return false; - // Todo: Unhardcode "Water" terraintype reference if (waterBound) - return world.Map.IsInMap(a.X,a.Y) && GetTerrainType(world,a) == "Water"; + return world.Map.IsInMap(a.X,a.Y) && GetTerrainInfo(world,a).IsWater; return world.Map.IsInMap(a.X, a.Y) && world.GetTerrainInfo(a).Buildable; } diff --git a/OpenRA.Mods.RA/Crate.cs b/OpenRA.Mods.RA/Crate.cs index 4d9aac39e9..affa820b44 100644 --- a/OpenRA.Mods.RA/Crate.cs +++ b/OpenRA.Mods.RA/Crate.cs @@ -91,7 +91,7 @@ namespace OpenRA.Mods.RA if (++ticks >= self.Info.Traits.Get().Lifetime * 25) self.World.AddFrameEndTask(w => w.Remove(self)); - var seq = self.World.GetTerrainType(cell) == "Water" ? "water" : "idle"; + var seq = self.World.GetTerrainInfo(cell).IsWater ? "water" : "idle"; if (seq != self.traits.Get().anim.CurrentSequence.Name) self.traits.Get().anim.PlayRepeating(seq); } diff --git a/mods/cnc/tileset-des.yaml b/mods/cnc/tileset-des.yaml index 9dd63906f7..23e30fccb1 100644 --- a/mods/cnc/tileset-des.yaml +++ b/mods/cnc/tileset-des.yaml @@ -6,6 +6,7 @@ Terrain: Color: 134, 95, 69 TerrainType@Water: Type: Water + IsWater: true Buildable: False AcceptSmudge: False Color: 93, 165, 206 diff --git a/mods/cnc/tileset-tem.yaml b/mods/cnc/tileset-tem.yaml index 88cc145c43..65dfc849d9 100644 --- a/mods/cnc/tileset-tem.yaml +++ b/mods/cnc/tileset-tem.yaml @@ -6,6 +6,7 @@ Terrain: Color: 40, 68, 40 TerrainType@Water: Type: Water + IsWater: true Buildable: False AcceptSmudge: False Color: 92, 116, 164 diff --git a/mods/cnc/tileset-win.yaml b/mods/cnc/tileset-win.yaml index ee1cc92945..4df9bb9d05 100644 --- a/mods/cnc/tileset-win.yaml +++ b/mods/cnc/tileset-win.yaml @@ -6,6 +6,7 @@ Terrain: Color: 40, 68, 40 TerrainType@Water: Type: Water + IsWater: true Buildable: False AcceptSmudge: False Color: 92, 116, 164 diff --git a/mods/ra/tileset-int.yaml b/mods/ra/tileset-int.yaml index 5a004d101d..5d3aff476a 100644 --- a/mods/ra/tileset-int.yaml +++ b/mods/ra/tileset-int.yaml @@ -6,6 +6,7 @@ Terrain: Color: 40, 68, 40 TerrainType@Water: Type: Water + IsWater: true Buildable: False AcceptSmudge: False Color: 92, 116, 164 diff --git a/mods/ra/tileset-sno.yaml b/mods/ra/tileset-sno.yaml index 67bc4c5da5..8e1b84d4ef 100644 --- a/mods/ra/tileset-sno.yaml +++ b/mods/ra/tileset-sno.yaml @@ -6,6 +6,7 @@ Terrain: Color: 196, 196, 196 TerrainType@Water: Type: Water + IsWater: true Buildable: False AcceptSmudge: False Color: 92, 116, 164 diff --git a/mods/ra/tileset-tem.yaml b/mods/ra/tileset-tem.yaml index 9cfeb7ec75..e63e978894 100644 --- a/mods/ra/tileset-tem.yaml +++ b/mods/ra/tileset-tem.yaml @@ -6,6 +6,7 @@ Terrain: Color: 40, 68, 40 TerrainType@Water: Type: Water + IsWater: true Buildable: False AcceptSmudge: False Color: 92, 116, 164