Esempio n. 1
0
 void SaveGeneratorArgs()
 {
     generatorArgs = new MapGeneratorArgs {
         DetailScale        = sDetailScale.Value,
         FeatureScale       = sFeatureScale.Value,
         MapHeight          = (int)nMapHeight.Value,
         MapWidth           = (int)nMapWidth.Value,
         MapLength          = (int)nMapLength.Value,
         LayeredHeightmap   = xLayeredHeightmap.Checked,
         MarbledHeightmap   = xMarbledMode.Checked,
         MatchWaterCoverage = xMatchWaterCoverage.Checked,
         MaxDepth           = (int)nMaxDepth.Value,
         MaxHeight          = (int)nMaxHeight.Value,
         AddTrees           = xAddTrees.Checked,
         AddGiantTrees      = xGiantTrees.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 : nMapHeight.Value / 2),
         AddSnow            = xAddSnow.Checked,
         SnowTransition     = (int)nSnowTransition.Value,
         SnowAltitude       = (int)(nSnowAltitude.Value + (xWaterLevel.Checked ? nWaterLevel.Value : nMapHeight.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
     };
 }
Esempio n. 2
0
 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);
         }
     }
 }
Esempio n. 3
0
 private void cTemplates_SelectedIndexChanged(object sender, EventArgs e)
 {
     generatorArgs = MapGenerator.MakeTemplate((MapGenTemplate)cTemplates.SelectedIndex);
     LoadGeneratorArgs();
     bGenerate.PerformClick();
 }
Esempio n. 4
0
 private void cTemplates_SelectedIndexChanged( object sender, EventArgs e ) {
     generatorArgs = MapGenerator.MakeTemplate( (MapGenTemplate)cTemplates.SelectedIndex );
     LoadGeneratorArgs();
     bGenerate.PerformClick();
 }
Esempio n. 5
0
 void SaveGeneratorArgs() {
     generatorArgs = new MapGeneratorArgs {
         DetailScale = sDetailScale.Value,
         FeatureScale = sFeatureScale.Value,
         MapHeight = (int)nMapHeight.Value,
         MapWidth = (int)nMapWidth.Value,
         MapLength = (int)nMapLength.Value,
         LayeredHeightmap = xLayeredHeightmap.Checked,
         MarbledHeightmap = xMarbledMode.Checked,
         MatchWaterCoverage = xMatchWaterCoverage.Checked,
         MaxDepth = (int)nMaxDepth.Value,
         MaxHeight = (int)nMaxHeight.Value,
         AddTrees = xAddTrees.Checked,
         AddGiantTrees = xGiantTrees.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 : nMapHeight.Value / 2),
         AddSnow = xAddSnow.Checked,
         SnowTransition = (int)nSnowTransition.Value,
         SnowAltitude = (int)(nSnowAltitude.Value + (xWaterLevel.Checked ? nWaterLevel.Value : nMapHeight.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
     };
 }
Esempio n. 6
0
 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 );
         }
     }
 }
Esempio n. 7
0
        public static void RealmCreate(Player player, Command cmd, string themeName, string templateName)
        {
            MapGenTemplate template;
            MapGenTheme    theme;

            if (!(cmd.NextInt(out var wx) && cmd.NextInt(out var wy) && cmd.NextInt(out var 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;

            if (player.Name.Contains('.'))
            {
                fileName = player.Name.Replace(".", "-"); //support for email names
            }

            string fullFileName;

            {
                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 map file \"{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 (map.Save(fullFileName))
            {
                player.MessageNow("Generation done. Saved to {0}", fileName);
            }
            else
            {
                player.Message("&WAn error occured while saving generated map to {0}", fileName);
            }
        }