Add experimental RA procedural map generator
Add an experimental procedural map generator for the Red Alert mod, along with supporting code that may assist in the development of map generators for other mods. Map generation may be accessed as a tool in the Map Editor. This change does not presently introduce direct lobby options for generated maps. Features: - Terrain with land, water, beaches, cliffs, roads, debris, and trees. - Placement of mpspawns, neutral buildings, and resources. - Rotational and mirror symmetry options. - Various configurable parameters with presets. - Deterministic with configurable seed. - Performant.
This commit is contained in:
@@ -63,12 +63,16 @@ namespace OpenRA
|
||||
|
||||
var u = (x - y) / 2;
|
||||
var v = x + y;
|
||||
if (!Bounds.Contains(u, v))
|
||||
throw new IndexOutOfRangeException();
|
||||
return v * Size.Width + u;
|
||||
}
|
||||
|
||||
// Resolve an array index from map coordinates
|
||||
int Index(MPos uv)
|
||||
{
|
||||
if (!Bounds.Contains(uv.U, uv.V))
|
||||
throw new IndexOutOfRangeException();
|
||||
return uv.V * Size.Width + uv.U;
|
||||
}
|
||||
|
||||
@@ -145,6 +149,9 @@ namespace OpenRA
|
||||
{
|
||||
return uv.Clamp(new Rectangle(0, 0, Size.Width - 1, Size.Height - 1));
|
||||
}
|
||||
|
||||
public CellRegion CellRegion =>
|
||||
new(GridType, new MPos(0, 0), new MPos(Size.Width - 1, Size.Height - 1));
|
||||
}
|
||||
|
||||
// Helper functions
|
||||
|
||||
@@ -1145,6 +1145,11 @@ namespace OpenRA
|
||||
}
|
||||
|
||||
public byte GetTerrainIndex(CPos cell)
|
||||
{
|
||||
return GetTerrainIndex(cell.ToMPos(this));
|
||||
}
|
||||
|
||||
public byte GetTerrainIndex(MPos uv)
|
||||
{
|
||||
// Lazily initialize a cache for terrain indexes.
|
||||
if (cachedTerrainIndexes == null)
|
||||
@@ -1153,7 +1158,6 @@ namespace OpenRA
|
||||
cachedTerrainIndexes.Clear(InvalidCachedTerrainIndex);
|
||||
}
|
||||
|
||||
var uv = cell.ToMPos(this);
|
||||
var terrainIndex = cachedTerrainIndexes[uv];
|
||||
|
||||
// PERF: Cache terrain indexes per cell on demand.
|
||||
@@ -1168,7 +1172,12 @@ namespace OpenRA
|
||||
|
||||
public TerrainTypeInfo GetTerrainInfo(CPos cell)
|
||||
{
|
||||
return Rules.TerrainInfo.TerrainTypes[GetTerrainIndex(cell)];
|
||||
return GetTerrainInfo(cell.ToMPos(this));
|
||||
}
|
||||
|
||||
public TerrainTypeInfo GetTerrainInfo(MPos uv)
|
||||
{
|
||||
return Rules.TerrainInfo.TerrainTypes[GetTerrainIndex(uv)];
|
||||
}
|
||||
|
||||
public CPos Clamp(CPos cell)
|
||||
|
||||
@@ -25,6 +25,21 @@ namespace OpenRA
|
||||
public override int GetHashCode() { return Type.GetHashCode() ^ Index.GetHashCode(); }
|
||||
|
||||
public override string ToString() { return Type + "," + Index; }
|
||||
|
||||
public static bool TryParse(string s, out TerrainTile tt)
|
||||
{
|
||||
var split = s.Split(',');
|
||||
if (split.Length == 2 &&
|
||||
Exts.TryParseUshortInvariant(split[0], out var type) &&
|
||||
Exts.TryParseByteInvariant(split[1], out var index))
|
||||
{
|
||||
tt = new TerrainTile(type, index);
|
||||
return true;
|
||||
}
|
||||
|
||||
tt = default;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public readonly struct ResourceTile
|
||||
|
||||
Reference in New Issue
Block a user