#ifndef CC_MAP_GEN_H
#define CC_MAP_GEN_H
#include "String.h"
#include "ExtMath.h"
#include "Vectors.h"
/* Implements flatgrass map generator, and original classic vanilla map generation (with perlin noise)
   Based on: https://github.com/UnknownShadow200/ClassicalSharp/wiki/Minecraft-Classic-map-generation-algorithm
   Thanks to Jerralish for originally reverse engineering classic's algorithm, then preparing a high level overview of the algorithm.
   Copyright 2014 - 2017 ClassicalSharp | Licensed under BSD-3
*/

volatile Real32 Gen_CurrentProgress;
volatile const UChar* Gen_CurrentState;
volatile bool Gen_Done;
Int32 Gen_Width, Gen_Height, Gen_Length, Gen_Seed;
bool Gen_Vanilla;
BlockID* Gen_Blocks;
#define Gen_SetDimensions(x, y, z) Gen_Width = x; Gen_Height = y; Gen_Length = z;

void FlatgrassGen_Generate(void);
void NotchyGen_Generate(void);

#define NOISE_TABLE_SIZE 512
void ImprovedNoise_Init(UInt8* p, Random* rnd);
Real32 ImprovedNoise_Calc(UInt8* p, Real32 x, Real32 y);

struct OctaveNoise { UInt8 p[8][NOISE_TABLE_SIZE]; Int32 octaves; };
void OctaveNoise_Init(struct OctaveNoise* n, Random* rnd, Int32 octaves);
Real32 OctaveNoise_Calc(struct OctaveNoise* n, Real32 x, Real32 y);

struct CombinedNoise { struct OctaveNoise noise1, noise2; };
void CombinedNoise_Init(struct CombinedNoise* n, Random* rnd, Int32 octaves1, Int32 octaves2);
Real32 CombinedNoise_Calc(struct CombinedNoise* n, Real32 x, Real32 y);


Int32 Tree_Width, Tree_Height, Tree_Length;
BlockID* Tree_Blocks;
Random* Tree_Rnd;
/* Appropriate buffer size to hold positions and blocks generated by the tree generator. */
#define Tree_BufferCount 96

bool TreeGen_CanGrow(Int32 treeX, Int32 treeY, Int32 treeZ, Int32 treeHeight);
Int32 TreeGen_Grow(Int32 treeX, Int32 treeY, Int32 treeZ, Int32 height, Vector3I* coords, BlockID* blocks);
#endif
