Skip to content

Commit

Permalink
Fix two map generation crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
tmsbrg committed Aug 29, 2016
1 parent 9809d4c commit b057c21
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions OpenRA.Mods.Common/MapGenerator.cs
Expand Up @@ -269,18 +269,13 @@ void GenerateRandomMap(Map map, MapPlayers mapPlayers, ActorInfo world)
var playerLandSize = settings.startingMineDistance + settings.playerMinDistance;

var bounds = map.Bounds;
var playerBounds = Rectangle.FromLTRB(
bounds.Left + playerLandSize,
bounds.Top + playerLandSize,
bounds.Right - playerLandSize,
bounds.Bottom - playerLandSize);

var spawnLocations = new List<MPos>();
var bestSpawnLocations = new List<MPos>();
var tries = 20;
for (var t = 0; t < tries; t++)
{
spawnLocations = TryGetLocations(settings.playerNum, playerLandSize * 2, map, () => RandomLocation(playerBounds));
spawnLocations = TryGetLocations(settings.playerNum, playerLandSize * 2, map, () => RandomLocation(bounds));
if (spawnLocations.Count() == settings.playerNum)
{
break;
Expand All @@ -306,7 +301,9 @@ void GenerateRandomMap(Map map, MapPlayers mapPlayers, ActorInfo world)

map.ActorDefinitions.Add(new MiniYamlNode("Actor"+NextActorNumber(), spawn.Save()));

var mineLocations = TryGetLocations(settings.startingMineNum, settings.startingMineInterDistance, map, () => GetMineLocation(location, map));
var mineLocations = TryGetLocations(settings.startingMineNum, () => GetMineLocation(location, map),
(p, locs) => CanPlaceActor(p, settings.startingMineInterDistance, locs, map) &&
map.Contains(p));

// add mines around spawn points
foreach (var mineLocation in mineLocations)
Expand Down

0 comments on commit b057c21

Please sign in to comment.