mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-26 06:43:25 -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>>();
|
||||
advGens = new Dictionary<string, Func<MapGenArgs, bool>>();
|
||||
SimpleGen.RegisterGenerators();
|
||||
fCraftMapGenerator.RegisterGenerators();
|
||||
|
||||
AdvNoiseGen.RegisterGenerators();
|
||||
RegisterAdvancedGen("heightmap", HeightmapGen.Generate);
|
||||
}
|
||||
|
@ -1,42 +1,25 @@
|
||||
// Part of fCraft | Copyright 2009-2015 Matvei Stefarov <me@matvei.org> | BSD-3 | See LICENSE.txt
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
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>
|
||||
public enum MapGenTheme {
|
||||
Forest,
|
||||
Arctic,
|
||||
Desert,
|
||||
Hell,
|
||||
Swamp
|
||||
Forest, Arctic, Desert, Hell, Swamp
|
||||
}
|
||||
|
||||
|
||||
/// <summary> Map generator template. Templates define landscape shapes and features. </summary>
|
||||
public enum MapGenTemplate {
|
||||
Archipelago,
|
||||
Atoll,
|
||||
Bay,
|
||||
Dunes,
|
||||
Hills,
|
||||
Ice,
|
||||
Island,
|
||||
Lake,
|
||||
Mountains,
|
||||
Peninsula,
|
||||
Random,
|
||||
River,
|
||||
Streams
|
||||
Archipelago, Atoll, Bay, Dunes, Hills, Ice, Island,
|
||||
Lake, Mountains, Peninsula, Random, River, Streams
|
||||
}
|
||||
|
||||
|
||||
/// <summary> Provides functionality for generating map files. </summary>
|
||||
public sealed class MapGenerator {
|
||||
readonly MapGeneratorArgs args;
|
||||
public sealed class fCraftMapGenerator {
|
||||
readonly fCraftMapGeneratorArgs args;
|
||||
readonly Random rand;
|
||||
readonly Noise noise;
|
||||
float[,] heightmap, slopemap;
|
||||
@ -47,7 +30,7 @@ namespace fCraf2t {
|
||||
internal int groundThickness = 5;
|
||||
const int SeaFloorThickness = 3;
|
||||
|
||||
public MapGenerator( MapGeneratorArgs generatorArgs ) {
|
||||
public fCraftMapGenerator( fCraftMapGeneratorArgs generatorArgs ) {
|
||||
if( generatorArgs == null ) throw new ArgumentNullException( "generatorArgs" );
|
||||
args = generatorArgs;
|
||||
rand = new Random( args.Seed );
|
||||
@ -140,23 +123,6 @@ namespace fCraf2t {
|
||||
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
|
||||
if( args.CliffSmoothing ) {
|
||||
ReportProgress( 2, "Heightmap Processing: Smoothing" );
|
||||
@ -191,7 +157,7 @@ namespace fCraf2t {
|
||||
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 snowStartThreshold = args.SnowAltitude - args.SnowTransition;
|
||||
int snowThreshold = args.SnowAltitude;
|
||||
@ -238,11 +204,11 @@ namespace fCraf2t {
|
||||
} else {
|
||||
int index = (level * length + z) * width + x;
|
||||
if( level >= 0 && level < mapHeight ) {
|
||||
if( slope < args.CliffThreshold ) {
|
||||
map.blocks[index] = bGroundSurface;
|
||||
} else {
|
||||
map.blocks[index] = bCliff;
|
||||
}
|
||||
if( slope < args.CliffThreshold ) {
|
||||
map.blocks[index] = bGroundSurface;
|
||||
} else {
|
||||
map.blocks[index] = bCliff;
|
||||
}
|
||||
}
|
||||
|
||||
for( int yy = level - 1; yy >= 0; yy-- ) {
|
||||
@ -250,11 +216,11 @@ namespace fCraf2t {
|
||||
if( yy >= mapHeight ) continue;
|
||||
|
||||
if( level - yy < groundThickness ) {
|
||||
if( slope < args.CliffThreshold ) {
|
||||
map.blocks[index] = bGround;
|
||||
} else {
|
||||
map.blocks[index] = bCliff;
|
||||
}
|
||||
if( slope < args.CliffThreshold ) {
|
||||
map.blocks[index] = bGround;
|
||||
} else {
|
||||
map.blocks[index] = bCliff;
|
||||
}
|
||||
} else {
|
||||
map.blocks[index] = bBedrock;
|
||||
}
|
||||
@ -281,11 +247,11 @@ namespace fCraf2t {
|
||||
|
||||
int index = (level * length + z) * width + x;
|
||||
if( level >= 0 && level < mapHeight ) {
|
||||
if( slope < args.CliffThreshold ) {
|
||||
map.blocks[index] = (snow ? Block.white : bGroundSurface);
|
||||
} else {
|
||||
map.blocks[index] = bCliff;
|
||||
}
|
||||
if( slope < args.CliffThreshold ) {
|
||||
map.blocks[index] = (snow ? Block.white : bGroundSurface);
|
||||
} else {
|
||||
map.blocks[index] = bCliff;
|
||||
}
|
||||
}
|
||||
|
||||
for( int yy = level - 1; yy >= 0; yy-- ) {
|
||||
@ -293,15 +259,15 @@ namespace fCraf2t {
|
||||
if( yy >= mapHeight ) continue;
|
||||
|
||||
if( level - yy < groundThickness ) {
|
||||
if( slope < args.CliffThreshold ) {
|
||||
if( snow ) {
|
||||
map.blocks[index] = Block.white;
|
||||
} else {
|
||||
map.blocks[index] = bGround;
|
||||
}
|
||||
if( slope < args.CliffThreshold ) {
|
||||
if( snow ) {
|
||||
map.blocks[index] = Block.white;
|
||||
} else {
|
||||
map.blocks[index] = bCliff;
|
||||
map.blocks[index] = bGround;
|
||||
}
|
||||
} else {
|
||||
map.blocks[index] = bCliff;
|
||||
}
|
||||
} else {
|
||||
map.blocks[index] = bBedrock;
|
||||
}
|
||||
@ -429,15 +395,20 @@ namespace fCraf2t {
|
||||
|
||||
public static void RegisterGenerators() {
|
||||
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;
|
||||
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);
|
||||
MapGeneratorArgs args = MapGeneratorArgs.MakeTemplate(templ);
|
||||
fCraftMapGeneratorArgs args = fCraftMapGeneratorArgs.MakeTemplate(templ);
|
||||
Level map = genArgs.Level;
|
||||
|
||||
float ratio = map.Height / 96.0f;
|
||||
@ -450,7 +421,7 @@ namespace fCraf2t {
|
||||
args.AddWater = theme != MapGenTheme.Desert;
|
||||
args.WaterLevel = (map.Height - 1) / 2;
|
||||
|
||||
MapGenerator generator = new MapGenerator(args);
|
||||
fCraftMapGenerator generator = new fCraftMapGenerator(args);
|
||||
generator.Generate(map);
|
||||
return true;
|
||||
}
|
||||
|
@ -2,9 +2,9 @@
|
||||
using System;
|
||||
using MCGalaxy;
|
||||
|
||||
namespace fCraf2t {
|
||||
namespace MCGalaxy.Generator {
|
||||
/// <summary> Contains parameters for advanced map generation. </summary>
|
||||
public sealed class MapGeneratorArgs {
|
||||
public sealed class fCraftMapGeneratorArgs {
|
||||
public string MapName;
|
||||
|
||||
public MapGenTheme Theme = MapGenTheme.Forest;
|
||||
@ -53,11 +53,11 @@ namespace fCraf2t {
|
||||
public int BeachExtent = 6,
|
||||
BeachHeight = 2;
|
||||
|
||||
public MapGeneratorArgs() {
|
||||
public fCraftMapGeneratorArgs() {
|
||||
Seed = (new Random()).Next();
|
||||
}
|
||||
|
||||
public void ApplyTheme( MapGenerator gen ) {
|
||||
public void ApplyTheme( fCraftMapGenerator gen ) {
|
||||
switch( Theme ) {
|
||||
case MapGenTheme.Arctic:
|
||||
gen.bWaterSurface = Block.glass;
|
||||
@ -118,10 +118,10 @@ namespace fCraf2t {
|
||||
}
|
||||
|
||||
|
||||
public static MapGeneratorArgs MakeTemplate( MapGenTemplate template ) {
|
||||
public static fCraftMapGeneratorArgs MakeTemplate( MapGenTemplate template ) {
|
||||
switch( template ) {
|
||||
case MapGenTemplate.Archipelago:
|
||||
return new MapGeneratorArgs {
|
||||
return new fCraftMapGeneratorArgs {
|
||||
MaxHeight = 8,
|
||||
MaxDepth = 20,
|
||||
FeatureScale = 3,
|
||||
@ -131,7 +131,7 @@ namespace fCraf2t {
|
||||
};
|
||||
|
||||
case MapGenTemplate.Atoll:
|
||||
return new MapGeneratorArgs {
|
||||
return new fCraftMapGeneratorArgs {
|
||||
Theme = MapGenTheme.Desert,
|
||||
MaxHeight = 2,
|
||||
MaxDepth = 39,
|
||||
@ -148,7 +148,7 @@ namespace fCraf2t {
|
||||
};
|
||||
|
||||
case MapGenTemplate.Bay:
|
||||
return new MapGeneratorArgs {
|
||||
return new fCraftMapGeneratorArgs {
|
||||
MaxHeight = 22,
|
||||
MaxDepth = 12,
|
||||
UseBias = true,
|
||||
@ -163,7 +163,7 @@ namespace fCraf2t {
|
||||
};
|
||||
|
||||
case MapGenTemplate.Dunes:
|
||||
return new MapGeneratorArgs {
|
||||
return new fCraftMapGeneratorArgs {
|
||||
AddTrees = false,
|
||||
AddWater = false,
|
||||
Theme = MapGenTheme.Desert,
|
||||
@ -177,7 +177,7 @@ namespace fCraf2t {
|
||||
};
|
||||
|
||||
case MapGenTemplate.Hills:
|
||||
return new MapGeneratorArgs {
|
||||
return new fCraftMapGeneratorArgs {
|
||||
AddWater = false,
|
||||
MaxHeight = 8,
|
||||
MaxDepth = 8,
|
||||
@ -187,7 +187,7 @@ namespace fCraf2t {
|
||||
};
|
||||
|
||||
case MapGenTemplate.Ice:
|
||||
return new MapGeneratorArgs {
|
||||
return new fCraftMapGeneratorArgs {
|
||||
AddTrees = false,
|
||||
Theme = MapGenTheme.Arctic,
|
||||
MaxHeight = 2,
|
||||
@ -202,7 +202,7 @@ namespace fCraf2t {
|
||||
};
|
||||
|
||||
case MapGenTemplate.Island:
|
||||
return new MapGeneratorArgs {
|
||||
return new fCraftMapGeneratorArgs {
|
||||
MaxHeight = 16,
|
||||
MaxDepth = 39,
|
||||
UseBias = true,
|
||||
@ -218,7 +218,7 @@ namespace fCraf2t {
|
||||
};
|
||||
|
||||
case MapGenTemplate.Lake:
|
||||
return new MapGeneratorArgs {
|
||||
return new fCraftMapGeneratorArgs {
|
||||
MaxHeight = 14,
|
||||
MaxDepth = 20,
|
||||
UseBias = true,
|
||||
@ -232,7 +232,7 @@ namespace fCraf2t {
|
||||
};
|
||||
|
||||
case MapGenTemplate.Mountains:
|
||||
return new MapGeneratorArgs {
|
||||
return new fCraftMapGeneratorArgs {
|
||||
AddWater = false,
|
||||
MaxHeight = 40,
|
||||
MaxDepth = 10,
|
||||
@ -247,10 +247,10 @@ namespace fCraf2t {
|
||||
};
|
||||
|
||||
case MapGenTemplate.Random:
|
||||
return new MapGeneratorArgs();
|
||||
return new fCraftMapGeneratorArgs();
|
||||
|
||||
case MapGenTemplate.River:
|
||||
return new MapGeneratorArgs {
|
||||
return new fCraftMapGeneratorArgs {
|
||||
MaxHeight = 22,
|
||||
MaxDepth = 8,
|
||||
FeatureScale = 0,
|
||||
@ -261,7 +261,7 @@ namespace fCraf2t {
|
||||
};
|
||||
|
||||
case MapGenTemplate.Streams:
|
||||
return new MapGeneratorArgs {
|
||||
return new fCraftMapGeneratorArgs {
|
||||
MaxHeight = 5,
|
||||
MaxDepth = 4,
|
||||
FeatureScale = 2,
|
||||
@ -275,7 +275,7 @@ namespace fCraf2t {
|
||||
};
|
||||
|
||||
case MapGenTemplate.Peninsula:
|
||||
return new MapGeneratorArgs {
|
||||
return new fCraftMapGeneratorArgs {
|
||||
MaxHeight = 22,
|
||||
MaxDepth = 12,
|
||||
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>
|
||||
using System;
|
||||
|
||||
namespace fCraf2t {
|
||||
namespace MCGalaxy.Generator {
|
||||
|
||||
/// <summary> Interpolation mode for perlin noise. </summary>
|
||||
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];
|
||||
public float InterpolatedNoise( float x, float y ) {
|
||||
int xInt = (int)Math.Floor( x );
|
||||
|
Loading…
x
Reference in New Issue
Block a user