diff --git a/OpenRA.Game/Traits/World/ResourceLayer.cs b/OpenRA.Game/Traits/World/ResourceLayer.cs index 2cf2b315cc..19986376f9 100644 --- a/OpenRA.Game/Traits/World/ResourceLayer.cs +++ b/OpenRA.Game/Traits/World/ResourceLayer.cs @@ -58,14 +58,17 @@ namespace OpenRA.Traits for (int x = map.Bounds.Left; x < map.Bounds.Right; x++) for (int y = map.Bounds.Top; y < map.Bounds.Bottom; y++) { - // Todo: Valid terrain should be specified in the resource - if (!AllowResourceAt(new int2(x,y))) - continue; - - content[x, y].type = resourceTypes.FirstOrDefault( + var type = resourceTypes.FirstOrDefault( r => r.info.ResourceType == w.Map.MapResources[x, y].type); - if (content[x, y].type != null) - content[x, y].image = ChooseContent(content[x, y].type); + + if (type == null) + continue; + + if (!AllowResourceAt(type, new int2(x,y))) + continue; + + content[x, y].type = type; + content[x, y].image = ChooseContent(type); } for (int x = map.Bounds.Left; x < map.Bounds.Right; x++) @@ -77,13 +80,13 @@ namespace OpenRA.Traits } } - public bool AllowResourceAt( int2 a ) - { - if( !world.Map.IsInMap( a.X, a.Y ) ) return false; - if( !world.GetTerrainInfo( a ).Buildable ) return false; - if( world.WorldActor.Trait().AnyUnitsAt( a ) ) return false; - return true; - } + public bool AllowResourceAt(ResourceType rt, int2 a) + { + if (!world.Map.IsInMap(a.X, a.Y)) return false; + if (!rt.info.AllowedTerrainTypes.Contains(world.GetTerrainInfo(a).Type)) return false; + if (!rt.info.AllowUnderActors && world.WorldActor.Trait().AnyUnitsAt(a)) return false; + return true; + } Sprite[] ChooseContent(ResourceType t) { diff --git a/OpenRA.Game/Traits/World/ResourceType.cs b/OpenRA.Game/Traits/World/ResourceType.cs index fde8923301..a1bd2b0a23 100644 --- a/OpenRA.Game/Traits/World/ResourceType.cs +++ b/OpenRA.Game/Traits/World/ResourceType.cs @@ -22,6 +22,9 @@ namespace OpenRA.Traits public readonly string Name = null; public readonly string TerrainType = "Ore"; + public readonly string[] AllowedTerrainTypes = { }; + public readonly bool AllowUnderActors = false; + public Sprite[][] Sprites; public int PaletteIndex; diff --git a/OpenRA.Mods.RA/SeedsResource.cs b/OpenRA.Mods.RA/SeedsResource.cs index 06cc07a67d..8a597b836c 100644 --- a/OpenRA.Mods.RA/SeedsResource.cs +++ b/OpenRA.Mods.RA/SeedsResource.cs @@ -51,7 +51,7 @@ namespace OpenRA.Mods.RA // Todo: Valid terrain should be specified in the resource if (cell != null && self.World.Map.IsInMap(cell.Value) && (resLayer.GetResource(cell.Value) == resourceType - || (resLayer.GetResource(cell.Value) == null && resLayer.AllowResourceAt(cell.Value)))) + || (resLayer.GetResource(cell.Value) == null && resLayer.AllowResourceAt(resourceType, cell.Value)))) resLayer.AddResource(resourceType, cell.Value.X, cell.Value.Y, 1); ticks = info.Interval; diff --git a/mods/cnc/rules/system.yaml b/mods/cnc/rules/system.yaml index f1634b052b..c9ceaf4e3d 100644 --- a/mods/cnc/rules/system.yaml +++ b/mods/cnc/rules/system.yaml @@ -111,6 +111,8 @@ World: ValuePerUnit: 30 Name: Tiberium PipColor: Green + AllowedTerrainTypes: Clear,Road + AllowUnderActors: false ResourceType@blue-tib: ResourceType: 2 Palette: terrain @@ -120,6 +122,8 @@ World: Name: Blue Tiberium # todo: add a blue pip. PipColor: Red + AllowedTerrainTypes: Clear,Road + AllowUnderActors: false SmudgeLayer@SCORCH: Type:Scorch Types:sc1,sc2,sc3,sc4,sc5,sc6 diff --git a/mods/ra/rules/system.yaml b/mods/ra/rules/system.yaml index 58fd15de0f..f13f317d7c 100644 --- a/mods/ra/rules/system.yaml +++ b/mods/ra/rules/system.yaml @@ -160,6 +160,8 @@ World: ValuePerUnit: 25 Name: Ore PipColor: Yellow + AllowedTerrainTypes: Clear,Road + AllowUnderActors: false ResourceType@gem: ResourceType: 2 Palette: terrain @@ -167,6 +169,8 @@ World: ValuePerUnit: 50 Name: Gems PipColor: Red + AllowedTerrainTypes: Clear,Road + AllowUnderActors: false SmudgeLayer@SCORCH: Type:Scorch Types:sc1,sc2,sc3,sc4,sc5,sc6