diff --git a/OpenRA.Game/Graphics/Minimap.cs b/OpenRA.Game/Graphics/Minimap.cs index f9adfa55df..8810b58755 100644 --- a/OpenRA.Game/Graphics/Minimap.cs +++ b/OpenRA.Game/Graphics/Minimap.cs @@ -120,11 +120,13 @@ namespace OpenRA.Graphics if (oreLayer == null) { + var res = world.WorldActor.traits.Get(); var colors = terrainTypeColors[world.Map.Theater.ToLowerInvariant()]; + oreLayer = new Bitmap(terrain); for (var y = world.Map.YOffset; y < world.Map.YOffset + world.Map.Height; y++) for (var x = world.Map.XOffset; x < world.Map.XOffset + world.Map.Width; x++) - if (world.Map.ContainsResource(new int2(x, y))) + if (res.GetResource(new int2(x,y)) != null) oreLayer.SetPixel(x, y, colors[(int)TerrainMovementType.Ore]); } diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj index 2d7b51d370..f41e09dee1 100644 --- a/OpenRA.Game/OpenRA.Game.csproj +++ b/OpenRA.Game/OpenRA.Game.csproj @@ -98,7 +98,6 @@ - diff --git a/OpenRA.Game/Ore.cs b/OpenRA.Game/Ore.cs deleted file mode 100644 index bf8b25f807..0000000000 --- a/OpenRA.Game/Ore.cs +++ /dev/null @@ -1,67 +0,0 @@ -#region Copyright & License Information -/* - * Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford. - * This file is part of OpenRA. - * - * OpenRA is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * OpenRA is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with OpenRA. If not, see . - */ -#endregion - -using System; -using OpenRA.FileFormats; -using OpenRA.Traits; - -namespace OpenRA -{ - public static class Ore - { - static bool HasOverlay(this Map map, int i, int j) - { - return map.MapTiles[i, j].overlay < overlayIsOre.Length; - } - - static bool ContainsOre(this Map map, int i, int j) - { - return map.HasOverlay(i, j) && overlayIsOre[map.MapTiles[i, j].overlay]; - } - - static bool ContainsGem(this Map map, int i, int j) - { - return map.HasOverlay(i, j) && overlayIsGems[map.MapTiles[i, j].overlay]; - } - - public static bool ContainsResource(this Map map, int2 p) - { - return map.ContainsGem(p.X, p.Y) || map.ContainsOre(p.X, p.Y); - } - - static bool[] overlayIsOre = - { - false, false, false, false, false, - true, true, true, true, - false, false, false, false, - false, false, false, false, false, false, false, - false, false, false, false, false, - }; - - static bool[] overlayIsGems = - { - false, false, false, false, false, - false, false, false, false, - true, true, true, true, - false, false, false, false, false, false, false, - false, false, false, false, false, - }; - } -} diff --git a/OpenRA.Game/Traits/Activities/Harvest.cs b/OpenRA.Game/Traits/Activities/Harvest.cs index 6179c54e02..3c66a5d728 100644 --- a/OpenRA.Game/Traits/Activities/Harvest.cs +++ b/OpenRA.Game/Traits/Activities/Harvest.cs @@ -64,12 +64,14 @@ namespace OpenRA.Traits.Activities void FindMoreOre(Actor self) { + var res = self.World.WorldActor.traits.Get(); + self.QueueActivity(new Move( () => { var search = new PathSearch { - heuristic = loc => (self.World.Map.ContainsResource(loc) ? 0 : 1), + heuristic = loc => (res.GetResource(loc) != null ? 0 : 1), umt = UnitMovementType.Wheel, checkForBlocked = true }; diff --git a/OpenRA.Game/Traits/Harvester.cs b/OpenRA.Game/Traits/Harvester.cs index e62a7efa7e..3422ebadb7 100644 --- a/OpenRA.Game/Traits/Harvester.cs +++ b/OpenRA.Game/Traits/Harvester.cs @@ -71,7 +71,7 @@ namespace OpenRA.Traits && underCursor.traits.Contains() && !IsEmpty) return new Order("Deliver", self, underCursor); - if (underCursor == null && self.World.Map.ContainsResource(xy)) + if (underCursor == null && self.World.WorldActor.traits.Get().GetResource(xy) != null) return new Order("Harvest", self, xy); return null; diff --git a/OpenRA.Game/Traits/World/ResourceLayer.cs b/OpenRA.Game/Traits/World/ResourceLayer.cs index 69a1b31ea4..6f389afcd3 100644 --- a/OpenRA.Game/Traits/World/ResourceLayer.cs +++ b/OpenRA.Game/Traits/World/ResourceLayer.cs @@ -35,7 +35,7 @@ namespace OpenRA.Traits World w; public ResourceTypeInfo[] resourceTypes; - public CellContents[,] content = new CellContents[128, 128]; + CellContents[,] content = new CellContents[128, 128]; public ResourceLayer(Actor self) { @@ -185,6 +185,8 @@ namespace OpenRA.Traits } } + public ResourceTypeInfo GetResource(int2 p) { return content[p.X, p.Y].type; } + public struct CellContents { public ResourceTypeInfo type; diff --git a/OpenRA.Game/UiOverlay.cs b/OpenRA.Game/UiOverlay.cs index 170ea0857f..6e7293f3f9 100644 --- a/OpenRA.Game/UiOverlay.cs +++ b/OpenRA.Game/UiOverlay.cs @@ -67,10 +67,11 @@ namespace OpenRA var position = Game.controller.MousePosition.ToInt2(); var topLeft = position - Footprint.AdjustForBuildingSize( bi ); var isCloseEnough = world.IsCloseEnoughToBase(world.LocalPlayer, name, bi, topLeft); + var res = world.WorldActor.traits.Get(); foreach( var t in Footprint.Tiles( name, bi, topLeft ) ) spriteRenderer.DrawSprite( ( isCloseEnough && world.IsCellBuildable( t, bi.WaterBound - ? UnitMovementType.Float : UnitMovementType.Wheel ) && !world.Map.ContainsResource( t ) ) + ? UnitMovementType.Float : UnitMovementType.Wheel ) && res.GetResource(t) == null ) ? buildOk : buildBlocked, Game.CellSize * t, "terrain" ); // Linebuild for walls. diff --git a/OpenRA.Game/WorldUtils.cs b/OpenRA.Game/WorldUtils.cs index 2fb4ec8d86..79b44f93e2 100755 --- a/OpenRA.Game/WorldUtils.cs +++ b/OpenRA.Game/WorldUtils.cs @@ -149,8 +149,9 @@ namespace OpenRA public static bool CanPlaceBuilding(this World world, string name, BuildingInfo building, int2 topLeft, Actor toIgnore) { + var res = world.WorldActor.traits.Get(); return !Footprint.Tiles(name, building, topLeft).Any( - t => !world.Map.IsInMap(t.X, t.Y) || world.Map.ContainsResource(t) || !world.IsCellBuildable(t, + t => !world.Map.IsInMap(t.X, t.Y) || res.GetResource(t) != null || !world.IsCellBuildable(t, building.WaterBound ? UnitMovementType.Float : UnitMovementType.Wheel, toIgnore)); }