Add path auto-tiling tool to map editor

Exposes the TilingPath code used by the map generator as a map editor
tool to help automate the process of tiling sequences of templates
together.

No additional template stitching definitions are added as part of this
commit. As such, the tool currently only supports the same auto tiling
as the map generator does. This includes:

- RA and CnC support.
- Beaches, land cliffs, and roads.

Support for additional mods and templates can be added in follow-ups
by adding the necessary MultiBrush definitions.

Related changes included in this commit to support this work include:

- Add support for sparse EditorBlits.
- Add support for MultiBrush to EditorBlitSource conversion.
- Add support for EditorBlitSource previewing.
- Adjust the "Road" types used in segmented MultiBrush definitions.
This commit is contained in:
Ashley Newson
2025-05-11 00:45:48 +01:00
committed by Gustas Kažukauskas
parent d3d949176d
commit ad08045e5f
28 changed files with 2460 additions and 919 deletions

View File

@@ -125,6 +125,18 @@ namespace OpenRA.Mods.Common.MapGenerator
throw new ArgumentException("bad direction");
}
static readonly ImmutableArray<int2> KiloVectors =
[
new(1024, 0),
new(724, 724),
new(0, 1024),
new(-724, 724),
new(-1024, 0),
new(-724, -724),
new(0, -1024),
new(724, -724),
];
/// <summary>
/// Convert a non-none direction to a CVec offset. Assumes that
/// CVec(1, 0) corresponds to Direction.R.
@@ -137,8 +149,21 @@ namespace OpenRA.Mods.Common.MapGenerator
throw new ArgumentException("bad direction");
}
/// <summary>
/// Convert a non-none direction to a WVec offset. Assumes that
/// WVec(1, 0, 0) corresponds to Direction.R.
/// </summary>
public static WVec ToWVec(int d)
{
if (d >= 0 && d < 8)
return new WVec(Spread8[d].X, Spread8[d].Y, 0);
else
throw new ArgumentException("bad direction");
}
/// <summary>
/// Convert an offset (of arbitrary non-zero magnitude) to a direction.
/// The direction is based purely on the signs of the inputs.
/// Supplying a zero-offset will throw.
/// </summary>
public static int FromOffset(int dx, int dy)
@@ -172,6 +197,32 @@ namespace OpenRA.Mods.Common.MapGenerator
}
}
/// <summary>
/// Convert an offset (of arbitrary non-zero magnitude) to a direction.
/// The direction with the closest angle wins. Keep inputs to 1000000 or less.
/// Supplying a zero-offset will throw.
/// </summary>
public static int FromOffsetRounding(int dx, int dy)
{
if (dx == 0 && dy == 0)
throw new ArgumentException("Bad direction");
var d = new int2(dx, dy);
var direction = None;
var best = 0;
for (var i = 0; i < KiloVectors.Length; i++)
{
var score = int2.Dot(d, KiloVectors[i]);
if (score > best)
{
best = score;
direction = i;
}
}
return direction;
}
/// <summary>
/// Convert an offset (of arbitrary non-zero magnitude) to a direction.
/// Supplying a zero-offset will throw.
@@ -187,6 +238,14 @@ namespace OpenRA.Mods.Common.MapGenerator
public static int FromCVec(CVec delta)
=> FromOffset(delta.X, delta.Y);
/// <summary>
/// Convert an offset (of arbitrary non-zero magnitude) to a direction.
/// Supplying a zero-offset will throw. Assumes that CVec(1, 0)
/// corresponds to Direction.R.
/// </summary>
public static int FromCVecRounding(CVec delta)
=> FromOffsetRounding(delta.X, delta.Y);
/// <summary>
/// Convert an offset (of arbitrary non-zero magnitude) to a non-diagonal direction.
/// Supplying a zero-offset will throw.