#include #include // rand #include // memset // g++ -shared biome.cpp -o biome.dll -I../src #define MAX_POWER 10 #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 // in following order {GRASS,TREE,BERRIES, ROCK, IRON_ORE} 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; int y; int type; int power; int radius; } t_biome; // variables t_biome* l_biomes; int size_biomes; int nb_plains, nb_forests, nb_mountains; int cpt_biome; int width, height, n; // functions int distance_manhattan(int x1,int y1, int x2, int y2); void set_spawns(Map &map); void create_biome(int x, int y, int type); void create_biome_random(Map &map, int type); int check_nears_biomes(int x, int y); int check_nears_spawn(Map &map, int x, int y); int in_radius(int x,int y,t_biome e); Pixel::Type generate(int x, int y); void init_generator(); extern "C" void generate(Map *mapPtr) { Map &map = *mapPtr; width = map.getWidth(); height = map.getHeight(); n = map.getNbTeams(); int i,j; //biome variable init_generator(); //Epicenters generation // 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_biomes = nb_plains+ nb_forests + nb_mountains + n; l_biomes = (t_biome*)malloc(sizeof(t_biome)*size_biomes); cpt_biome = 0; // Spawn generations set_spawns(map); for(i=0;ix=x; biome->y=y; biome->type = type; 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; } } void create_biome_random(Map &map, int type){ int x,y; do { x=rand()%width; y=rand()%height; } while ((check_nears_biomes(x,y) != 0) || (check_nears_spawn(map, 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