diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1530978 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.o \ No newline at end of file diff --git a/generator.c b/generator.c index 8948368..6713ce9 100644 --- a/generator.c +++ b/generator.c @@ -1,8 +1,23 @@ #include "main.h" #define MAX_POWER 10 -#define MAX_EPICENTER_BY_TYPE 10 -#define MAX_RADIUS 75 +#define MAX_EPICENTER_BY_TYPE 7 +#define DIST_MIN_INTER_EPICENTRE 50 +#define MIN_RADIUS 25 +#define OFFSET_RADIUS 50 + +//map type ----> not used for now +enum{ + FLAT, VALLEY, +}; + +//biome type +enum{ + VILLAGE, PLAINS, FOREST,MOUNTAINS,NB_BIOMES +}; + +//probability for each biomes +char proba_table[NB_BIOMES][5] = {{97,2,1,0,0},{85,13,2,0,0},{40,40,20,0,0},{0,0,0,80,20}}; typedef struct{ int x; @@ -10,58 +25,65 @@ typedef struct{ int type; int power; int radius; -} t_epicenter; +} t_biome; // variables -t_epicenter* l_epicenters; -int size_epicenters; -int cpt_epicenter = 0; +int spx[2], spy[2]; +t_biome* l_biomes; +int size_biomes; +int cpt_biome = 0; int width, height; // functions int distance_manhattan(int x1,int y1, int x2, int y2); int absolute(int val); void set_spawns(t_pixel** map, t_team* teams); -void create_epicenter(int x, int y, int type); -void create_epicenter_random(int type); +void create_biome(int x, int y, int type); +void create_biome_random(int type); +int check_nears_biomes(int x, int y); +int check_nears_spawn(int x, int y); +int in_radius(int x,int y,t_biome e); int generate(int x, int y); +void init_generator(); void create_map(t_pixel** map, t_team* teams, int w, int h){ int i,j; int type; - //epicenter variable - int nb_rock, nb_tree, nb_berries; + //biome variable + int nb_plains, nb_forests, nb_mountains; width = w; height = h; + init_generator(); + //Epicenters generation - // random choice for numbers of epicenters - nb_rock = rand()%MAX_EPICENTER_BY_TYPE; - nb_tree = rand()%MAX_EPICENTER_BY_TYPE; - nb_berries = rand()%MAX_EPICENTER_BY_TYPE; + // random choice for numbers of biomes + nb_plains = (rand()%MAX_EPICENTER_BY_TYPE)+3; + nb_forests = (rand()%MAX_EPICENTER_BY_TYPE)+3; + nb_mountains = (rand()%MAX_EPICENTER_BY_TYPE)+3; - size_epicenters = nb_rock + nb_tree + nb_berries + NB_TEAMS; + size_biomes = nb_plains+ nb_forests + nb_mountains + NB_TEAMS; - l_epicenters = malloc(sizeof(t_epicenter)*size_epicenters); + l_biomes = malloc(sizeof(t_biome)*size_biomes); // Spawn generations set_spawns(map,teams); - for(i=0;ix=x; - epicenter->y=y; - epicenter->type = type; - epicenter->power = (rand()%MAX_POWER)+1; - epicenter->radius = (rand()%100)+1; + biome->x=x; + biome->y=y; + biome->type = type; - l_epicenters[cpt_epicenter++]=*epicenter; + switch(type){ + case VILLAGE: + biome->power = (rand()%MAX_POWER)+1; + biome->radius = (rand()%(25-10))+10; + break; + case PLAINS: + case FOREST: + case MOUNTAINS: + default: + biome->power = (rand()%MAX_POWER)+1; + biome->radius = (rand()%(OFFSET_RADIUS))+MIN_RADIUS; + break; + } + + l_biomes[cpt_biome++]=*biome; } -void create_epicenter_random(int type){ - create_epicenter(rand()%width,rand()%height,type); +void create_biome_random(int type){ + int x,y; + do { + x=rand()%width; + y=rand()%height; + } while ((check_nears_biomes(x,y) != 0) || (check_nears_spawn(x,y) != 0)); //prevent biome superposition + + create_biome(x,y,type); +} + +int check_nears_biomes(int x, int y){ + int i, c=0; + for(i=0;i 0 ? val : -val; } diff --git a/team.h b/team.h index 123ce2d..98e19f9 100644 --- a/team.h +++ b/team.h @@ -8,7 +8,7 @@ enum{ // Tile types enum{ - BEDROCK, GRASS, ROCK, IRON_ORE, TREE, BERRIES, // nature + BEDROCK, GRASS, TREE, BERRIES, ROCK, IRON_ORE, // nature FOOD, WOOD, STONE, IRON, // resources CORPSE, DUDE, // humans SPAWN, WALL, ROAD, SWORD, SIGN // buildings