diff --git a/generators/anselme.cpp b/generators/anselme.cpp index f3c485b..fd40bff 100644 --- a/generators/anselme.cpp +++ b/generators/anselme.cpp @@ -11,20 +11,24 @@ extern "C" void generate(Map *mapPtr) int w = map.getWidth(); int h = map.getHeight(); int n = map.getNbTeams(); - int i,j, k; - int r = (w/n < h ? w/n : h)/2; - int *teamCoord = new int[n*2]; + int i, j, k; for(i=0; i +#include // rand +#include // memset + +// g++ -shared biome.cpp -o biome.dll -I../src #define MAX_POWER 10 #define MAX_EPICENTER_BY_TYPE 7 @@ -8,7 +12,7 @@ //map type ----> not used for now enum{ - FLAT, VALLEY, + FLAT, VALLEY }; //biome type @@ -29,33 +33,33 @@ typedef struct{ } t_biome; // variables -int sp_x[NB_TEAMS], sp_y[NB_TEAMS]; t_biome* l_biomes; int size_biomes; int nb_plains, nb_forests, nb_mountains; -int cpt_biome = 0; -int width, height; +int cpt_biome; +int width, height, n; // 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 set_spawns(Map &map); void create_biome(int x, int y, int type); -void create_biome_random(int type); +void create_biome_random(Map &map, int type); int check_nears_biomes(int x, int y); -int check_nears_spawn(int x, int y); +int check_nears_spawn(Map &map, 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(int w, int h){ +extern "C" void generate(Map *mapPtr) +{ + Map &map = *mapPtr; + width = map.getWidth(); + height = map.getHeight(); + n = map.getNbTeams(); int i,j; //biome variable - width = w; - height = h; - init_generator(); //Epicenters generation @@ -64,70 +68,66 @@ void create_map(int w, int h){ nb_forests = (rand()%MAX_EPICENTER_BY_TYPE)+3; nb_mountains = (rand()%MAX_EPICENTER_BY_TYPE)+3; - size_biomes = nb_plains+ nb_forests + nb_mountains + NB_TEAMS; - - l_biomes = malloc(sizeof(t_biome)*size_biomes); + 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,teams); + set_spawns(map); for(i=0;ix=x; biome->y=y; @@ -146,16 +146,14 @@ void create_biome(int x, int y, int type){ biome->radius = (rand()%(OFFSET_RADIUS))+MIN_RADIUS; break; } - - l_biomes[cpt_biome++]=*biome; } -void create_biome_random(int type){ +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(x,y) != 0)); //prevent biome superposition + } while ((check_nears_biomes(x,y) != 0) || (check_nears_spawn(map, x,y) != 0)); //prevent biome superposition create_biome(x,y,type); } @@ -168,10 +166,11 @@ int check_nears_biomes(int x, int y){ return c; } -int check_nears_spawn(int x, int y){ +int check_nears_spawn(Map &map, int x, int y){ int i,c = 0; - for(i=0;i<2;i++) - if (distance_manhattan(x,y,sp_x[i],sp_y[i]) < 75) c++; + for(i=0;i 0 ? val : -val; + return Coord::dist(Coord(x1, y1), Coord(x2, y2)); } diff --git a/generators/biome.dll b/generators/biome.dll new file mode 100644 index 0000000..33e4e0c Binary files /dev/null and b/generators/biome.dll differ diff --git a/teams/hello.dll b/teams/hello.dll deleted file mode 100644 index d3f0b3a..0000000 Binary files a/teams/hello.dll and /dev/null differ