Skip to content

Commit

Permalink
Add cliff settings and jitter
Browse files Browse the repository at this point in the history
  • Loading branch information
tmsbrg committed Aug 29, 2016
1 parent c19710e commit c4e8332
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 8 deletions.
27 changes: 20 additions & 7 deletions OpenRA.Mods.Common/MapGenerator.cs
Expand Up @@ -28,12 +28,6 @@ public class MapGeneratorSettings
public int height = 90;
public string tileset = "";

// TODO: UI
public int cliffNum = 50;
public int cliffAverageSize = 8;
public int cliffSizeVariance = 5;
public int cliffJitter = 40;

public int startingMineNum = 2;
public int startingMineDistance = 10;
public int startingMineSize = 32;
Expand All @@ -46,6 +40,12 @@ public class MapGeneratorSettings
public int debrisNumGroups = 20;
public int debrisNumPerGroup = 7;
public int debrisGroupSize = 6;

public int cliffNum = 7;
public int cliffAverageSize = 8;
public int cliffSizeVariance = 5;
public int cliffJitter = 40;

}

public class MapGenerator
Expand Down Expand Up @@ -313,7 +313,7 @@ void AddCliffs(Map map)
if (tileset.Generator == null || tileset.Generator.SimpleCliffs == null) return;

var cliffTileSize = 2;
var cliffDistance = cliffTileSize * settings.cliffAverageSize - settings.cliffSizeVariance;
var cliffDistance = cliffTileSize * 4; // arbitrary, but to keep them from being too close
var cliffStartLocations = GetPoissonLocations(map, settings.cliffNum, cliffDistance, cliffTileSize, cliffTileSize);

// draw lines from start location
Expand Down Expand Up @@ -342,6 +342,7 @@ void AddCliffs(Map map)

var size = rng.Next(settings.cliffAverageSize - settings.cliffSizeVariance,
settings.cliffAverageSize + settings.cliffSizeVariance);
if (size < 2) size = 2;
for (var i = 0; i < size; i++)
{
List<CPos> list;
Expand All @@ -350,11 +351,13 @@ void AddCliffs(Map map)
{
list = cliffsDirection1;
direction = cliffDirections[direction1];
direction1 = jitterCliff(direction1);
}
else
{
list = cliffsDirection2;
direction = cliffDirections[direction2];
direction2 = jitterCliff(direction2);
}
var oldPos = (list.Count > 0) ? list.Last() : startLocation;
var pos = oldPos + direction;
Expand Down Expand Up @@ -401,6 +404,16 @@ void AddCliffs(Map map)
}
}

int jitterCliff(int direction)
{
if (rng.Next(100) < settings.cliffJitter)
{
var change = (rng.Next(2) > 0) ? 1 : -1;
return (direction + 4 + change) % 4;
}
return direction;
}

enum Direction {
NORTH,
EAST,
Expand Down
4 changes: 4 additions & 0 deletions OpenRA.Mods.Common/Widgets/Logic/MapGeneratorLogic.cs
Expand Up @@ -46,6 +46,10 @@ public class MapGeneratorLogic : ChromeLogic
BindSetting("DEBRIS_NUM_GROUPS", (x) => { settings.debrisNumGroups = x; }, () => { return settings.debrisNumGroups; });
BindSetting("DEBRIS_NUM_PER_GROUP", (x) => { settings.debrisNumPerGroup = x; }, () => { return settings.debrisNumPerGroup; });
BindSetting("DEBRIS_GROUP_SIZE", (x) => { settings.debrisGroupSize = x; }, () => { return settings.debrisGroupSize; });
BindSetting("CLIFF_NUM", (x) => { settings.cliffNum = x; }, () => { return settings.cliffNum; });
BindSetting("CLIFF_AVERAGE_SIZE", (x) => { settings.cliffAverageSize = x; }, () => { return settings.cliffAverageSize; });
BindSetting("CLIFF_SIZE_VARIANCE", (x) => { settings.cliffSizeVariance = x; }, () => { return settings.cliffSizeVariance; });
BindSetting("CLIFF_JITTER", (x) => { settings.cliffJitter = x; }, () => { return settings.cliffJitter; });

var tilesetDropDown = widget.GetOrNull<DropDownButtonWidget>("TILESET_DROPDOWN");
if (tilesetDropDown != null)
Expand Down
87 changes: 86 additions & 1 deletion mods/ra/chrome/map-generator.yaml
Expand Up @@ -48,7 +48,7 @@ Background@MAPGENERATOR_PANEL:
Height: 20
MinimumValue: 30
MaximumValue: 90
Ticks: 20
Ticks: 61
TextField@PLAYER_DIST_FIELD:
X: 160
Y: 180
Expand Down Expand Up @@ -324,6 +324,91 @@ Background@MAPGENERATOR_PANEL:
Height: 20
MaxLength: 2

Label@CLIFF_NUM_LABEL:
X: 400
Y: 380
Align: Left
Width: 120
Height: 20
Text: Cliffs
Slider@CLIFF_NUM_SLIDER:
X: 400
Y: 420
Width: 120
Height: 20
MinimumValue: 0
MaximumValue: 20
Ticks: 21
TextField@CLIFF_NUM_FIELD:
X: 520
Y: 420
Width: 28
Height: 20
MaxLength: 2
Label@CLIFF_JITTER_LABEL:
X: 400
Y: 460
Align: Left
Width: 120
Height: 20
Text: Cliff Jitter
Slider@CLIFF_JITTER_SLIDER:
X: 400
Y: 500
Width: 120
Height: 20
MinimumValue: 0
MaximumValue: 100
Ticks: 101
TextField@CLIFF_JITTER_FIELD:
X: 520
Y: 500
Width: 36
Height: 20
MaxLength: 3
Label@CLIFF_AVERAGE_SIZE_LABEL:
X: 580
Y: 380
Align: Left
Width: 120
Height: 20
Text: Cliff Avg. Size
Slider@CLIFF_AVERAGE_SIZE_SLIDER:
X: 580
Y: 420
Width: 120
Height: 20
MinimumValue: 5
MaximumValue: 40
Ticks: 36
TextField@CLIFF_AVERAGE_SIZE_FIELD:
X: 700
Y: 420
Width: 28
Height: 20
MaxLength: 2
Label@CLIFF_SIZE_VARIANCE_LABEL:
X: 580
Y: 460
Align: Left
Width: 120
Height: 20
Text: Cliff Size Variance
Slider@CLIFF_SIZE_VARIANCE_SLIDER:
X: 580
Y: 500
Width: 120
Height: 20
MinimumValue: 0
MaximumValue: 10
Ticks: 11
TextField@CLIFF_SIZE_VARIANCE_FIELD:
X: 700
Y: 500
Width: 28
Height: 20
MaxLength: 2

Button@BUTTON_GENERATE:
X: PARENT_RIGHT - 270
Y: PARENT_BOTTOM - 45
Expand Down

0 comments on commit c4e8332

Please sign in to comment.