public static void RegisterGenerators() { string[] names = Enum.GetNames(typeof(MapGenBiome)); string desc = "%HSeed specifies biome of the map. " + "It must be one of the following: &f" + names.Join(); for (MapGenTheme theme = 0; theme < MapGenTheme.Count; theme++) { // Because of the way C# implements for loop closures, '=> Gen(p, lvl, seed, theme_)' // captures the variable from the LAST iteration, not the current one // Hence this causes an error to get thrown later, because 'Gen' is always executed // with 'MapGenTheme.Count' theme instead of the expected theme // Using a local variable copy fixes this MapGenTheme theme_ = theme; MapGen.Register(theme_.ToString(), GenType.fCraft, (p, lvl, seed) => Gen(p, lvl, seed, theme_), desc); } }
public void ApplyTheme(MapGenTheme theme) { // base defaults ("Grass") SurfaceThickness = 1; SoilThickness = 5; BedrockThickness = 1; AirBlock = Block.Air; SurfaceBlock = Block.Grass; ShallowBlock = Block.Dirt; DeepBlock = Block.Stone; BedrockBlock = Block.Admincrete; Preset = theme.ToString(); switch (theme) { case MapGenTheme.Arctic: DeepBlock = Block.White; SurfaceThickness = 0; SoilThickness = 0; break; case MapGenTheme.Desert: DeepBlock = Block.Sand; SurfaceThickness = 0; SoilThickness = 0; break; case MapGenTheme.Hell: DeepBlock = Block.Obsidian; SurfaceThickness = 0; SoilThickness = 0; break; case MapGenTheme.Swamp: SurfaceBlock = Block.Dirt; break; } // TODO: actually add trees in "Forest" mode }