PixelWars/generators/anselme.cpp

52 lines
1.1 KiB
C++

#include <map.h>
#include <cmath>
#include <cstdlib>
#include <algorithm>
// g++ -shared anselme.cpp -o anselme.dll -I../src
extern "C" void generate(Map *mapPtr)
{
Map &map = *mapPtr;
int w = map.getWidth();
int h = map.getHeight();
int n = map.getNbTeams();
int i, j, k;
for(i=0; i<n; i++)
map.team(i) = Coord((w/(n*2))*(1+i*2), h/2);
int r = h;
if(n != 0)
r = (w/n < h ? w/n : h)/2;
//génération de la carte
for (i=0;i<w;i++){
for(j=0;j<h;j++){
int d = std::max(w, h);
if(n == 0)
d = h;
for(k=0; k<n; k++){
d = std::min(d, map.team(k).dist(i, j));
if(!d)
break;
}
if(d == 0){
map[i][j].type = SPAWN;
map[i][j].data.nbRes = k;
}else{
int l = (d-20)+(rand()%40);
if(l > r+15) // mountain
map[i][j].type = rand()%8 ? ROCK : IRON_ORE;
else if(l < r-15) // plains
map[i][j].type = rand()%15 ? GRASS : BERRIES;
else // forest
{
l = rand()%10;
map[i][j].type = l > 5 ? TREE : l ? GRASS : BERRIES;
}
}
}
}
}