mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-27 15:30:58 -04:00
Generator: actually add the fCraft themes
This commit is contained in:
parent
4e500f8806
commit
5a1df1cc61
@ -79,6 +79,8 @@ namespace MCGalaxy.Generator {
|
|||||||
simpleGens = new Dictionary<string, Func<MapGenArgs, bool>>();
|
simpleGens = new Dictionary<string, Func<MapGenArgs, bool>>();
|
||||||
advGens = new Dictionary<string, Func<MapGenArgs, bool>>();
|
advGens = new Dictionary<string, Func<MapGenArgs, bool>>();
|
||||||
SimpleGen.RegisterGenerators();
|
SimpleGen.RegisterGenerators();
|
||||||
|
fCraftMapGenerator.RegisterGenerators();
|
||||||
|
|
||||||
AdvNoiseGen.RegisterGenerators();
|
AdvNoiseGen.RegisterGenerators();
|
||||||
RegisterAdvancedGen("heightmap", HeightmapGen.Generate);
|
RegisterAdvancedGen("heightmap", HeightmapGen.Generate);
|
||||||
}
|
}
|
||||||
|
@ -1,42 +1,25 @@
|
|||||||
// Part of fCraft | Copyright 2009-2015 Matvei Stefarov <me@matvei.org> | BSD-3 | See LICENSE.txt
|
// Part of fCraft | Copyright 2009-2015 Matvei Stefarov <me@matvei.org> | BSD-3 | See LICENSE.txt
|
||||||
using System;
|
using System;
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using MCGalaxy;
|
|
||||||
|
|
||||||
namespace fCraf2t {
|
namespace MCGalaxy.Generator {
|
||||||
|
|
||||||
/// <summary> Map generator themes. A theme defines what type of blocks are used to fill the map. </summary>
|
/// <summary> Map generator themes. A theme defines what type of blocks are used to fill the map. </summary>
|
||||||
public enum MapGenTheme {
|
public enum MapGenTheme {
|
||||||
Forest,
|
Forest, Arctic, Desert, Hell, Swamp
|
||||||
Arctic,
|
|
||||||
Desert,
|
|
||||||
Hell,
|
|
||||||
Swamp
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary> Map generator template. Templates define landscape shapes and features. </summary>
|
/// <summary> Map generator template. Templates define landscape shapes and features. </summary>
|
||||||
public enum MapGenTemplate {
|
public enum MapGenTemplate {
|
||||||
Archipelago,
|
Archipelago, Atoll, Bay, Dunes, Hills, Ice, Island,
|
||||||
Atoll,
|
Lake, Mountains, Peninsula, Random, River, Streams
|
||||||
Bay,
|
|
||||||
Dunes,
|
|
||||||
Hills,
|
|
||||||
Ice,
|
|
||||||
Island,
|
|
||||||
Lake,
|
|
||||||
Mountains,
|
|
||||||
Peninsula,
|
|
||||||
Random,
|
|
||||||
River,
|
|
||||||
Streams
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary> Provides functionality for generating map files. </summary>
|
/// <summary> Provides functionality for generating map files. </summary>
|
||||||
public sealed class MapGenerator {
|
public sealed class fCraftMapGenerator {
|
||||||
readonly MapGeneratorArgs args;
|
readonly fCraftMapGeneratorArgs args;
|
||||||
readonly Random rand;
|
readonly Random rand;
|
||||||
readonly Noise noise;
|
readonly Noise noise;
|
||||||
float[,] heightmap, slopemap;
|
float[,] heightmap, slopemap;
|
||||||
@ -47,7 +30,7 @@ namespace fCraf2t {
|
|||||||
internal int groundThickness = 5;
|
internal int groundThickness = 5;
|
||||||
const int SeaFloorThickness = 3;
|
const int SeaFloorThickness = 3;
|
||||||
|
|
||||||
public MapGenerator( MapGeneratorArgs generatorArgs ) {
|
public fCraftMapGenerator( fCraftMapGeneratorArgs generatorArgs ) {
|
||||||
if( generatorArgs == null ) throw new ArgumentNullException( "generatorArgs" );
|
if( generatorArgs == null ) throw new ArgumentNullException( "generatorArgs" );
|
||||||
args = generatorArgs;
|
args = generatorArgs;
|
||||||
rand = new Random( args.Seed );
|
rand = new Random( args.Seed );
|
||||||
@ -140,23 +123,6 @@ namespace fCraf2t {
|
|||||||
aboveWaterMultiplier = (args.MaxHeight / (1 - desiredWaterLevel));
|
aboveWaterMultiplier = (args.MaxHeight / (1 - desiredWaterLevel));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Apply power functions to above/below water parts of the heightmap
|
|
||||||
if( args.BelowFuncExponent != 1 || args.AboveFuncExponent != 1 ) {
|
|
||||||
ReportProgress( 5, "Heightmap Processing: Adjusting slope" );
|
|
||||||
for( int x = heightmap.GetLength( 0 ) - 1; x >= 0; x-- ) {
|
|
||||||
for( int y = heightmap.GetLength( 1 ) - 1; y >= 0; y-- ) {
|
|
||||||
if( heightmap[x, y] < desiredWaterLevel ) {
|
|
||||||
float normalizedDepth = 1 - heightmap[x, y] / desiredWaterLevel;
|
|
||||||
heightmap[x, y] = desiredWaterLevel - (float)Math.Pow( normalizedDepth, args.BelowFuncExponent ) * desiredWaterLevel;
|
|
||||||
} else {
|
|
||||||
float normalizedHeight = (heightmap[x, y] - desiredWaterLevel) / (1 - desiredWaterLevel);
|
|
||||||
heightmap[x, y] = desiredWaterLevel + (float)Math.Pow( normalizedHeight, args.AboveFuncExponent ) * (1 - desiredWaterLevel);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calculate the slope
|
// Calculate the slope
|
||||||
if( args.CliffSmoothing ) {
|
if( args.CliffSmoothing ) {
|
||||||
ReportProgress( 2, "Heightmap Processing: Smoothing" );
|
ReportProgress( 2, "Heightmap Processing: Smoothing" );
|
||||||
@ -191,7 +157,7 @@ namespace fCraf2t {
|
|||||||
ReportProgress( 0, "Generation complete" );
|
ReportProgress( 0, "Generation complete" );
|
||||||
}
|
}
|
||||||
|
|
||||||
void Fill(Level map, float desiredWaterLevel, float aboveWaterMultiplier, float[,] altmap) {
|
void Fill( Level map, float desiredWaterLevel, float aboveWaterMultiplier, float[,] altmap ) {
|
||||||
int width = map.Width, length = map.Length, mapHeight = map.Height;
|
int width = map.Width, length = map.Length, mapHeight = map.Height;
|
||||||
int snowStartThreshold = args.SnowAltitude - args.SnowTransition;
|
int snowStartThreshold = args.SnowAltitude - args.SnowTransition;
|
||||||
int snowThreshold = args.SnowAltitude;
|
int snowThreshold = args.SnowAltitude;
|
||||||
@ -238,11 +204,11 @@ namespace fCraf2t {
|
|||||||
} else {
|
} else {
|
||||||
int index = (level * length + z) * width + x;
|
int index = (level * length + z) * width + x;
|
||||||
if( level >= 0 && level < mapHeight ) {
|
if( level >= 0 && level < mapHeight ) {
|
||||||
if( slope < args.CliffThreshold ) {
|
if( slope < args.CliffThreshold ) {
|
||||||
map.blocks[index] = bGroundSurface;
|
map.blocks[index] = bGroundSurface;
|
||||||
} else {
|
} else {
|
||||||
map.blocks[index] = bCliff;
|
map.blocks[index] = bCliff;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for( int yy = level - 1; yy >= 0; yy-- ) {
|
for( int yy = level - 1; yy >= 0; yy-- ) {
|
||||||
@ -250,11 +216,11 @@ namespace fCraf2t {
|
|||||||
if( yy >= mapHeight ) continue;
|
if( yy >= mapHeight ) continue;
|
||||||
|
|
||||||
if( level - yy < groundThickness ) {
|
if( level - yy < groundThickness ) {
|
||||||
if( slope < args.CliffThreshold ) {
|
if( slope < args.CliffThreshold ) {
|
||||||
map.blocks[index] = bGround;
|
map.blocks[index] = bGround;
|
||||||
} else {
|
} else {
|
||||||
map.blocks[index] = bCliff;
|
map.blocks[index] = bCliff;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
map.blocks[index] = bBedrock;
|
map.blocks[index] = bBedrock;
|
||||||
}
|
}
|
||||||
@ -281,11 +247,11 @@ namespace fCraf2t {
|
|||||||
|
|
||||||
int index = (level * length + z) * width + x;
|
int index = (level * length + z) * width + x;
|
||||||
if( level >= 0 && level < mapHeight ) {
|
if( level >= 0 && level < mapHeight ) {
|
||||||
if( slope < args.CliffThreshold ) {
|
if( slope < args.CliffThreshold ) {
|
||||||
map.blocks[index] = (snow ? Block.white : bGroundSurface);
|
map.blocks[index] = (snow ? Block.white : bGroundSurface);
|
||||||
} else {
|
} else {
|
||||||
map.blocks[index] = bCliff;
|
map.blocks[index] = bCliff;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for( int yy = level - 1; yy >= 0; yy-- ) {
|
for( int yy = level - 1; yy >= 0; yy-- ) {
|
||||||
@ -293,15 +259,15 @@ namespace fCraf2t {
|
|||||||
if( yy >= mapHeight ) continue;
|
if( yy >= mapHeight ) continue;
|
||||||
|
|
||||||
if( level - yy < groundThickness ) {
|
if( level - yy < groundThickness ) {
|
||||||
if( slope < args.CliffThreshold ) {
|
if( slope < args.CliffThreshold ) {
|
||||||
if( snow ) {
|
if( snow ) {
|
||||||
map.blocks[index] = Block.white;
|
map.blocks[index] = Block.white;
|
||||||
} else {
|
|
||||||
map.blocks[index] = bGround;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
map.blocks[index] = bCliff;
|
map.blocks[index] = bGround;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
map.blocks[index] = bCliff;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
map.blocks[index] = bBedrock;
|
map.blocks[index] = bBedrock;
|
||||||
}
|
}
|
||||||
@ -429,15 +395,20 @@ namespace fCraf2t {
|
|||||||
|
|
||||||
public static void RegisterGenerators() {
|
public static void RegisterGenerators() {
|
||||||
foreach (MapGenTemplate templ in Enum.GetValues(typeof(MapGenTemplate))) {
|
foreach (MapGenTemplate templ in Enum.GetValues(typeof(MapGenTemplate))) {
|
||||||
MCGalaxy.Generator.MapGen.RegisterSimpleGen("fc_" + templ, GenerateFCRAFT);
|
MapGen.RegisterSimpleGen("fc_" + templ, GenerateMap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool GenerateFCRAFT(MCGalaxy.Generator.MapGenArgs genArgs) {
|
static bool GenerateMap(MapGenArgs genArgs) {
|
||||||
MapGenTheme theme = MapGenTheme.Forest;
|
MapGenTheme theme = MapGenTheme.Forest;
|
||||||
Enum.TryParse(genArgs.Args, true, out theme);
|
if (genArgs.Args != "" && !Enum.TryParse(genArgs.Args, true, out theme)) {
|
||||||
|
string[] themes = Enum.GetNames(typeof(MapGenTheme));
|
||||||
|
Player.Message(genArgs.Player, "Seed must be one of the following themes: " + themes.Join());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
MapGenTemplate templ = (MapGenTemplate)Enum.Parse(typeof(MapGenTemplate), genArgs.Theme.Substring(3), true);
|
MapGenTemplate templ = (MapGenTemplate)Enum.Parse(typeof(MapGenTemplate), genArgs.Theme.Substring(3), true);
|
||||||
MapGeneratorArgs args = MapGeneratorArgs.MakeTemplate(templ);
|
fCraftMapGeneratorArgs args = fCraftMapGeneratorArgs.MakeTemplate(templ);
|
||||||
Level map = genArgs.Level;
|
Level map = genArgs.Level;
|
||||||
|
|
||||||
float ratio = map.Height / 96.0f;
|
float ratio = map.Height / 96.0f;
|
||||||
@ -450,7 +421,7 @@ namespace fCraf2t {
|
|||||||
args.AddWater = theme != MapGenTheme.Desert;
|
args.AddWater = theme != MapGenTheme.Desert;
|
||||||
args.WaterLevel = (map.Height - 1) / 2;
|
args.WaterLevel = (map.Height - 1) / 2;
|
||||||
|
|
||||||
MapGenerator generator = new MapGenerator(args);
|
fCraftMapGenerator generator = new fCraftMapGenerator(args);
|
||||||
generator.Generate(map);
|
generator.Generate(map);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,9 @@
|
|||||||
using System;
|
using System;
|
||||||
using MCGalaxy;
|
using MCGalaxy;
|
||||||
|
|
||||||
namespace fCraf2t {
|
namespace MCGalaxy.Generator {
|
||||||
/// <summary> Contains parameters for advanced map generation. </summary>
|
/// <summary> Contains parameters for advanced map generation. </summary>
|
||||||
public sealed class MapGeneratorArgs {
|
public sealed class fCraftMapGeneratorArgs {
|
||||||
public string MapName;
|
public string MapName;
|
||||||
|
|
||||||
public MapGenTheme Theme = MapGenTheme.Forest;
|
public MapGenTheme Theme = MapGenTheme.Forest;
|
||||||
@ -53,11 +53,11 @@ namespace fCraf2t {
|
|||||||
public int BeachExtent = 6,
|
public int BeachExtent = 6,
|
||||||
BeachHeight = 2;
|
BeachHeight = 2;
|
||||||
|
|
||||||
public MapGeneratorArgs() {
|
public fCraftMapGeneratorArgs() {
|
||||||
Seed = (new Random()).Next();
|
Seed = (new Random()).Next();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ApplyTheme( MapGenerator gen ) {
|
public void ApplyTheme( fCraftMapGenerator gen ) {
|
||||||
switch( Theme ) {
|
switch( Theme ) {
|
||||||
case MapGenTheme.Arctic:
|
case MapGenTheme.Arctic:
|
||||||
gen.bWaterSurface = Block.glass;
|
gen.bWaterSurface = Block.glass;
|
||||||
@ -118,10 +118,10 @@ namespace fCraf2t {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static MapGeneratorArgs MakeTemplate( MapGenTemplate template ) {
|
public static fCraftMapGeneratorArgs MakeTemplate( MapGenTemplate template ) {
|
||||||
switch( template ) {
|
switch( template ) {
|
||||||
case MapGenTemplate.Archipelago:
|
case MapGenTemplate.Archipelago:
|
||||||
return new MapGeneratorArgs {
|
return new fCraftMapGeneratorArgs {
|
||||||
MaxHeight = 8,
|
MaxHeight = 8,
|
||||||
MaxDepth = 20,
|
MaxDepth = 20,
|
||||||
FeatureScale = 3,
|
FeatureScale = 3,
|
||||||
@ -131,7 +131,7 @@ namespace fCraf2t {
|
|||||||
};
|
};
|
||||||
|
|
||||||
case MapGenTemplate.Atoll:
|
case MapGenTemplate.Atoll:
|
||||||
return new MapGeneratorArgs {
|
return new fCraftMapGeneratorArgs {
|
||||||
Theme = MapGenTheme.Desert,
|
Theme = MapGenTheme.Desert,
|
||||||
MaxHeight = 2,
|
MaxHeight = 2,
|
||||||
MaxDepth = 39,
|
MaxDepth = 39,
|
||||||
@ -148,7 +148,7 @@ namespace fCraf2t {
|
|||||||
};
|
};
|
||||||
|
|
||||||
case MapGenTemplate.Bay:
|
case MapGenTemplate.Bay:
|
||||||
return new MapGeneratorArgs {
|
return new fCraftMapGeneratorArgs {
|
||||||
MaxHeight = 22,
|
MaxHeight = 22,
|
||||||
MaxDepth = 12,
|
MaxDepth = 12,
|
||||||
UseBias = true,
|
UseBias = true,
|
||||||
@ -163,7 +163,7 @@ namespace fCraf2t {
|
|||||||
};
|
};
|
||||||
|
|
||||||
case MapGenTemplate.Dunes:
|
case MapGenTemplate.Dunes:
|
||||||
return new MapGeneratorArgs {
|
return new fCraftMapGeneratorArgs {
|
||||||
AddTrees = false,
|
AddTrees = false,
|
||||||
AddWater = false,
|
AddWater = false,
|
||||||
Theme = MapGenTheme.Desert,
|
Theme = MapGenTheme.Desert,
|
||||||
@ -177,7 +177,7 @@ namespace fCraf2t {
|
|||||||
};
|
};
|
||||||
|
|
||||||
case MapGenTemplate.Hills:
|
case MapGenTemplate.Hills:
|
||||||
return new MapGeneratorArgs {
|
return new fCraftMapGeneratorArgs {
|
||||||
AddWater = false,
|
AddWater = false,
|
||||||
MaxHeight = 8,
|
MaxHeight = 8,
|
||||||
MaxDepth = 8,
|
MaxDepth = 8,
|
||||||
@ -187,7 +187,7 @@ namespace fCraf2t {
|
|||||||
};
|
};
|
||||||
|
|
||||||
case MapGenTemplate.Ice:
|
case MapGenTemplate.Ice:
|
||||||
return new MapGeneratorArgs {
|
return new fCraftMapGeneratorArgs {
|
||||||
AddTrees = false,
|
AddTrees = false,
|
||||||
Theme = MapGenTheme.Arctic,
|
Theme = MapGenTheme.Arctic,
|
||||||
MaxHeight = 2,
|
MaxHeight = 2,
|
||||||
@ -202,7 +202,7 @@ namespace fCraf2t {
|
|||||||
};
|
};
|
||||||
|
|
||||||
case MapGenTemplate.Island:
|
case MapGenTemplate.Island:
|
||||||
return new MapGeneratorArgs {
|
return new fCraftMapGeneratorArgs {
|
||||||
MaxHeight = 16,
|
MaxHeight = 16,
|
||||||
MaxDepth = 39,
|
MaxDepth = 39,
|
||||||
UseBias = true,
|
UseBias = true,
|
||||||
@ -218,7 +218,7 @@ namespace fCraf2t {
|
|||||||
};
|
};
|
||||||
|
|
||||||
case MapGenTemplate.Lake:
|
case MapGenTemplate.Lake:
|
||||||
return new MapGeneratorArgs {
|
return new fCraftMapGeneratorArgs {
|
||||||
MaxHeight = 14,
|
MaxHeight = 14,
|
||||||
MaxDepth = 20,
|
MaxDepth = 20,
|
||||||
UseBias = true,
|
UseBias = true,
|
||||||
@ -232,7 +232,7 @@ namespace fCraf2t {
|
|||||||
};
|
};
|
||||||
|
|
||||||
case MapGenTemplate.Mountains:
|
case MapGenTemplate.Mountains:
|
||||||
return new MapGeneratorArgs {
|
return new fCraftMapGeneratorArgs {
|
||||||
AddWater = false,
|
AddWater = false,
|
||||||
MaxHeight = 40,
|
MaxHeight = 40,
|
||||||
MaxDepth = 10,
|
MaxDepth = 10,
|
||||||
@ -247,10 +247,10 @@ namespace fCraf2t {
|
|||||||
};
|
};
|
||||||
|
|
||||||
case MapGenTemplate.Random:
|
case MapGenTemplate.Random:
|
||||||
return new MapGeneratorArgs();
|
return new fCraftMapGeneratorArgs();
|
||||||
|
|
||||||
case MapGenTemplate.River:
|
case MapGenTemplate.River:
|
||||||
return new MapGeneratorArgs {
|
return new fCraftMapGeneratorArgs {
|
||||||
MaxHeight = 22,
|
MaxHeight = 22,
|
||||||
MaxDepth = 8,
|
MaxDepth = 8,
|
||||||
FeatureScale = 0,
|
FeatureScale = 0,
|
||||||
@ -261,7 +261,7 @@ namespace fCraf2t {
|
|||||||
};
|
};
|
||||||
|
|
||||||
case MapGenTemplate.Streams:
|
case MapGenTemplate.Streams:
|
||||||
return new MapGeneratorArgs {
|
return new fCraftMapGeneratorArgs {
|
||||||
MaxHeight = 5,
|
MaxHeight = 5,
|
||||||
MaxDepth = 4,
|
MaxDepth = 4,
|
||||||
FeatureScale = 2,
|
FeatureScale = 2,
|
||||||
@ -275,7 +275,7 @@ namespace fCraf2t {
|
|||||||
};
|
};
|
||||||
|
|
||||||
case MapGenTemplate.Peninsula:
|
case MapGenTemplate.Peninsula:
|
||||||
return new MapGeneratorArgs {
|
return new fCraftMapGeneratorArgs {
|
||||||
MaxHeight = 22,
|
MaxHeight = 22,
|
||||||
MaxDepth = 12,
|
MaxDepth = 12,
|
||||||
UseBias = true,
|
UseBias = true,
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// Part of fCraft | Copyright 2009-2015 Matvei Stefarov <me@matvei.org> | BSD-3 | See LICENSE.txt //Copyright (c) 2011-2013 Jon Baker, Glenn Marien and Lao Tszy <Jonty800@gmail.com> //Copyright (c) <2012-2014> <LeChosenOne, DingusBungus> | ProCraft Copyright 2014-2016 Joseph Beauvais <123DMWM@gmail.com>
|
// Part of fCraft | Copyright 2009-2015 Matvei Stefarov <me@matvei.org> | BSD-3 | See LICENSE.txt //Copyright (c) 2011-2013 Jon Baker, Glenn Marien and Lao Tszy <Jonty800@gmail.com> //Copyright (c) <2012-2014> <LeChosenOne, DingusBungus> | ProCraft Copyright 2014-2016 Joseph Beauvais <123DMWM@gmail.com>
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace fCraf2t {
|
namespace MCGalaxy.Generator {
|
||||||
|
|
||||||
/// <summary> Interpolation mode for perlin noise. </summary>
|
/// <summary> Interpolation mode for perlin noise. </summary>
|
||||||
public enum NoiseInterpolationMode {
|
public enum NoiseInterpolationMode {
|
||||||
@ -57,13 +57,6 @@ namespace fCraf2t {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public float StaticNoise( int x, int y, int z ) {
|
|
||||||
int n = Seed + x + y * 1625 + z * 2642245;
|
|
||||||
n = (n << 13) ^ n;
|
|
||||||
return (float)(1.0 - ((n * (n * n * 15731 + 789221) + 1376312589) & 0x7FFFFFFF) / 1073741824d);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
readonly float[,] points = new float[4, 4];
|
readonly float[,] points = new float[4, 4];
|
||||||
public float InterpolatedNoise( float x, float y ) {
|
public float InterpolatedNoise( float x, float y ) {
|
||||||
int xInt = (int)Math.Floor( x );
|
int xInt = (int)Math.Floor( x );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user