public MapGenerator( [NotNull] MapGeneratorArgs generatorArgs ) { if( generatorArgs == null ) throw new ArgumentNullException( "generatorArgs" ); args = generatorArgs; args.Validate(); if( !args.CustomWaterLevel ) { args.WaterLevel = (args.MapHeight - 1) / 2; } rand = new Random( args.Seed ); noise = new Noise( args.Seed, NoiseInterpolationMode.Bicubic ); ApplyTheme( args.Theme ); EstimateComplexity(); }
public MapGeneratorOld([NotNull] MapGeneratorArgs generatorArgs) { if (generatorArgs == null) { throw new ArgumentNullException("generatorArgs"); } args = generatorArgs; args.Validate(); if (!args.CustomWaterLevel) { args.WaterLevel = (args.MapHeight - 1) / 2; } rand = new Random(args.Seed); noise = new Noise(args.Seed, NoiseInterpolationMode.Bicubic); ApplyTheme(args.Theme); EstimateComplexity(); }
public static void RealmCreate(Player player, Command cmd, string themeName, string templateName) { MapGenTemplate template; MapGenTheme theme; int wx, wy, height = 128; if (!(cmd.NextInt(out wx) && cmd.NextInt(out wy) && cmd.NextInt(out height))) { if (player.World != null) { wx = 128; wy = 128; height = 128; } else { player.Message("When used from console, /gen requires map dimensions."); return; } cmd.Rewind(); cmd.Next(); cmd.Next(); } if (!Map.IsValidDimension(wx)) { player.Message("Cannot make map with width {0}: dimensions must be multiples of 16.", wx); return; } else if (!Map.IsValidDimension(wy)) { player.Message("Cannot make map with length {0}: dimensions must be multiples of 16.", wy); return; } else if (!Map.IsValidDimension(height)) { player.Message("Cannot make map with height {0}: dimensions must be multiples of 16.", height); return; } string fileName = player.Name; string fullFileName = null; if (fileName == null) { if (player.World == null) { player.Message("When used from console, /gen requires FileName."); return; } if (!cmd.IsConfirmed) { player.Confirm(cmd, "Replace this realm's map with a generated one?"); return; } } else { fileName = fileName.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar); if (!fileName.EndsWith(".fcm", StringComparison.OrdinalIgnoreCase)) { fileName += ".fcm"; } fullFileName = Path.Combine(Paths.MapPath, fileName); if (!Paths.IsValidPath(fullFileName)) { player.Message("Invalid filename."); return; } if (!Paths.Contains(Paths.MapPath, fullFileName)) { player.MessageUnsafePath(); return; } string dirName = fullFileName.Substring(0, fullFileName.LastIndexOf(Path.DirectorySeparatorChar)); if (!Directory.Exists(dirName)) { Directory.CreateDirectory(dirName); } if (!cmd.IsConfirmed && File.Exists(fullFileName)) { player.Confirm(cmd, "The mapfile \"{0}\" already exists. Overwrite?", fileName); return; } } bool noTrees; if (themeName.Equals("grass", StringComparison.OrdinalIgnoreCase)) { theme = MapGenTheme.Forest; noTrees = true; } else { try { theme = (MapGenTheme)Enum.Parse(typeof(MapGenTheme), themeName, true); noTrees = (theme != MapGenTheme.Forest); } catch (Exception) { player.MessageNow("Unrecognized theme \"{0}\". Available themes are: Grass, {1}", themeName, String.Join(", ", Enum.GetNames(typeof(MapGenTheme)))); return; } } try { template = (MapGenTemplate)Enum.Parse(typeof(MapGenTemplate), templateName, true); } catch (Exception) { player.Message("Unrecognized template \"{0}\". Available templates are: {1}", templateName, String.Join(", ", Enum.GetNames(typeof(MapGenTemplate)))); return; } if (!Enum.IsDefined(typeof(MapGenTheme), theme) || !Enum.IsDefined(typeof(MapGenTemplate), template)) { return; } MapGeneratorArgs args = MapGenerator.MakeTemplate(template); args.MapWidth = wx; args.MapLength = wy; args.MapHeight = height; args.MaxHeight = (int)(args.MaxHeight / 80d * height); args.MaxDepth = (int)(args.MaxDepth / 80d * height); args.Theme = theme; args.AddTrees = !noTrees; Map map; try { if (theme == MapGenTheme.Forest && noTrees) { player.MessageNow("Generating Grass {0}...", template); } else { player.MessageNow("Generating {0} {1}...", theme, template); } if (theme == MapGenTheme.Forest && noTrees && template == MapGenTemplate.Flat) { map = MapGenerator.GenerateFlatgrass(args.MapWidth, args.MapLength, args.MapHeight); } else { MapGenerator generator = new MapGenerator(args); map = generator.Generate(); } } catch (Exception ex) { Logger.Log(LogType.Error, "MapGenerator: Generation failed: {0}", ex); player.MessageNow("&WAn error occured while generating the map."); return; } if (fileName != null) { if (map.Save(fullFileName)) { player.MessageNow("Generation done. Saved to {0}", fileName); } else { player.Message("&WAn error occured while saving generated map to {0}", fileName); } } else { player.MessageNow("Generation done. Changing map..."); player.World.ChangeMap(map); } }
private void cTemplates_SelectedIndexChanged( object sender, EventArgs e ) { generatorArgs = MapGenerator.MakeTemplate( (MapGenTemplate)cTemplates.SelectedIndex ); LoadGeneratorArgs(); bGenerate.PerformClick(); }
void SaveGeneratorArgs() { generatorArgs = new MapGeneratorArgs { DetailScale = sDetailScale.Value, FeatureScale = sFeatureScale.Value, Height = (int)nHeight.Value, WidthX = (int)nWidthX.Value, WidthY = (int)nWidthY.Value, LayeredHeightmap = xLayeredHeightmap.Checked, MarbledHeightmap = xMarbledMode.Checked, MatchWaterCoverage = xMatchWaterCoverage.Checked, MaxDepth = (int)nMaxDepth.Value, MaxHeight = (int)nMaxHeight.Value, AddTrees = xAddTrees.Checked, Roughness = sRoughness.Value / 100f, Seed = (int)nSeed.Value, Theme = (MapGenTheme)cTheme.SelectedIndex, TreeHeightMax = (int)(nTreeHeight.Value + nTreeHeightVariation.Value), TreeHeightMin = (int)(nTreeHeight.Value - nTreeHeightVariation.Value), TreeSpacingMax = (int)(nTreeSpacing.Value + nTreeSpacingVariation.Value), TreeSpacingMin = (int)(nTreeSpacing.Value - nTreeSpacingVariation.Value), UseBias = (sBias.Value != 0), DelayBias = xDelayBias.Checked, WaterCoverage = sWaterCoverage.Value / 100f, Bias = sBias.Value / 100f, MidPoint = cMidpoint.SelectedIndex - 1, RaisedCorners = (int)nRaisedCorners.Value, LoweredCorners = (int)nLoweredCorners.Value, InvertHeightmap = xInvert.Checked, AddWater = xWater.Checked, AddCaves = xCaves.Checked, AddOre = xOre.Checked, AddCaveLava = xCaveLava.Checked, AddCaveWater = xCaveWater.Checked, CaveDensity = sCaveDensity.Value / 100f, CaveSize = sCaveSize.Value / 100f, CustomWaterLevel = xWaterLevel.Checked, WaterLevel = (int)(xWaterLevel.Checked ? nWaterLevel.Value : nHeight.Value / 2), AddSnow = xAddSnow.Checked, SnowTransition = (int)nSnowTransition.Value, SnowAltitude = (int)(nSnowAltitude.Value + (xWaterLevel.Checked ? nWaterLevel.Value : nHeight.Value / 2)), AddCliffs = xAddCliffs.Checked, CliffThreshold = sCliffThreshold.Value / 100f, CliffSmoothing = xCliffSmoothing.Checked, AddBeaches = xAddBeaches.Checked, BeachExtent = (int)nBeachExtent.Value, BeachHeight = (int)nBeachHeight.Value, AboveFuncExponent = TrackBarToExponent( sAboveFunc ), BelowFuncExponent = TrackBarToExponent( sBelowFunc ), MaxHeightVariation = (int)nMaxHeightVariation.Value, MaxDepthVariation = (int)nMaxDepthVariation.Value }; }
private void bBrowseTemplate_Click( object sender, EventArgs e ) { if( browseTemplateDialog.ShowDialog() == DialogResult.OK && !String.IsNullOrEmpty( browseTemplateDialog.FileName ) ) { try { generatorArgs = new MapGeneratorArgs( browseTemplateDialog.FileName ); LoadGeneratorArgs(); bGenerate.PerformClick(); } catch( Exception ex ) { MessageBox.Show( "Could not open template file: " + ex ); } } }