#250 resources should have a list of allowed terrain types

This commit is contained in:
Chris Forbes
2011-01-08 09:31:36 +13:00
parent 712eb437ea
commit 93a56f9a18
5 changed files with 29 additions and 15 deletions

View File

@@ -58,14 +58,17 @@ namespace OpenRA.Traits
for (int x = map.Bounds.Left; x < map.Bounds.Right; x++) for (int x = map.Bounds.Left; x < map.Bounds.Right; x++)
for (int y = map.Bounds.Top; y < map.Bounds.Bottom; y++) for (int y = map.Bounds.Top; y < map.Bounds.Bottom; y++)
{ {
// Todo: Valid terrain should be specified in the resource var type = resourceTypes.FirstOrDefault(
if (!AllowResourceAt(new int2(x,y)))
continue;
content[x, y].type = resourceTypes.FirstOrDefault(
r => r.info.ResourceType == w.Map.MapResources[x, y].type); 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++) for (int x = map.Bounds.Left; x < map.Bounds.Right; x++)
@@ -77,13 +80,13 @@ namespace OpenRA.Traits
} }
} }
public bool AllowResourceAt( int2 a ) public bool AllowResourceAt(ResourceType rt, int2 a)
{ {
if( !world.Map.IsInMap( a.X, a.Y ) ) return false; if (!world.Map.IsInMap(a.X, a.Y)) return false;
if( !world.GetTerrainInfo( a ).Buildable ) return false; if (!rt.info.AllowedTerrainTypes.Contains(world.GetTerrainInfo(a).Type)) return false;
if( world.WorldActor.Trait<UnitInfluence>().AnyUnitsAt( a ) ) return false; if (!rt.info.AllowUnderActors && world.WorldActor.Trait<UnitInfluence>().AnyUnitsAt(a)) return false;
return true; return true;
} }
Sprite[] ChooseContent(ResourceType t) Sprite[] ChooseContent(ResourceType t)
{ {

View File

@@ -22,6 +22,9 @@ namespace OpenRA.Traits
public readonly string Name = null; public readonly string Name = null;
public readonly string TerrainType = "Ore"; public readonly string TerrainType = "Ore";
public readonly string[] AllowedTerrainTypes = { };
public readonly bool AllowUnderActors = false;
public Sprite[][] Sprites; public Sprite[][] Sprites;
public int PaletteIndex; public int PaletteIndex;

View File

@@ -51,7 +51,7 @@ namespace OpenRA.Mods.RA
// Todo: Valid terrain should be specified in the resource // Todo: Valid terrain should be specified in the resource
if (cell != null && self.World.Map.IsInMap(cell.Value) && if (cell != null && self.World.Map.IsInMap(cell.Value) &&
(resLayer.GetResource(cell.Value) == resourceType (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); resLayer.AddResource(resourceType, cell.Value.X, cell.Value.Y, 1);
ticks = info.Interval; ticks = info.Interval;

View File

@@ -111,6 +111,8 @@ World:
ValuePerUnit: 30 ValuePerUnit: 30
Name: Tiberium Name: Tiberium
PipColor: Green PipColor: Green
AllowedTerrainTypes: Clear,Road
AllowUnderActors: false
ResourceType@blue-tib: ResourceType@blue-tib:
ResourceType: 2 ResourceType: 2
Palette: terrain Palette: terrain
@@ -120,6 +122,8 @@ World:
Name: Blue Tiberium Name: Blue Tiberium
# todo: add a blue pip. # todo: add a blue pip.
PipColor: Red PipColor: Red
AllowedTerrainTypes: Clear,Road
AllowUnderActors: false
SmudgeLayer@SCORCH: SmudgeLayer@SCORCH:
Type:Scorch Type:Scorch
Types:sc1,sc2,sc3,sc4,sc5,sc6 Types:sc1,sc2,sc3,sc4,sc5,sc6

View File

@@ -160,6 +160,8 @@ World:
ValuePerUnit: 25 ValuePerUnit: 25
Name: Ore Name: Ore
PipColor: Yellow PipColor: Yellow
AllowedTerrainTypes: Clear,Road
AllowUnderActors: false
ResourceType@gem: ResourceType@gem:
ResourceType: 2 ResourceType: 2
Palette: terrain Palette: terrain
@@ -167,6 +169,8 @@ World:
ValuePerUnit: 50 ValuePerUnit: 50
Name: Gems Name: Gems
PipColor: Red PipColor: Red
AllowedTerrainTypes: Clear,Road
AllowUnderActors: false
SmudgeLayer@SCORCH: SmudgeLayer@SCORCH:
Type:Scorch Type:Scorch
Types:sc1,sc2,sc3,sc4,sc5,sc6 Types:sc1,sc2,sc3,sc4,sc5,sc6