/// <summary> /// Find the correct definition for the input parameters. /// </summary> /// <param name="square">The square to convert.</param> /// <returns>The matching definition.</returns> private string GetDefinitionName(GeneratedSquare square) { WorldSquareDefinition?matchingDefinition = this.thingFactory.Definitions.WorldSquareDefinitions.FirstOrDefault( d => square.Elevation >= d.MinElevation && square.Elevation <= d.MaxElevation && square.Rainfall >= d.MinRainfall && square.Rainfall <= d.MaxRainfall && square.Drainage >= d.MinDrainage && square.Drainage <= d.MaxDrainage && square.Water == d.IsWater && square.SaltWater == d.IsSaltWater); if (matchingDefinition == null) { throw new InvalidOperationException($"No matching definition found for {square}"); } return(matchingDefinition.Name); }
/// <summary> /// Converts a square, and adjacent lake squares, into an ocean. /// </summary> /// <param name="world">The world.</param> /// <param name="x">The X coord.</param> /// <param name="y">The Y coord.</param> private static void ConvertToOcean(GeneratedWorld world, int x, int y) { if (x < 0 || x >= world.Width || y < 0 || y >= world.Height) { return; } GeneratedSquare square = world.Grid[x, y]; if (!square.Water || square.SaltWater) { return; } square.SaltWater = true; ConvertToOcean(world, x - 1, y); ConvertToOcean(world, x + 1, y); ConvertToOcean(world, x, y - 1); ConvertToOcean(world, x, y + 1); }