debugged generator

This commit is contained in:
Lendemor 2015-01-12 20:01:09 +01:00
parent 3052c46e7b
commit a82e9bef82
2 changed files with 48 additions and 24 deletions

View File

@ -1,6 +1,6 @@
CC=gcc
LIB=-lSDL -lm -L./lib
FLAGS=-Wall -I./include
FLAGS=-Wall
ifdef SystemRoot
RM=del /Q

View File

@ -12,7 +12,8 @@ typedef struct{
// variables
t_epicenter* l_epicenters;
int size_epi;
int size_epicenters;
int cpt_epicenter = 0;
int width, height;
// functions
@ -25,41 +26,63 @@ void create_epicenter(int type);
int generate(int x, int y);
void create_map(t_pixel** map, t_team* teams, int w, int h){
int i,j;
int i,j,k,l;
int type;
//epicenter variable
int nb_rock, nb_tree, nb_berries;
//spawn variable
int x_rand, y_rand;
width = w;
height = h;
//génération des épicentres
l_epicenters = malloc(); // TODO : wtf malloc dans le vide
//Epicenters generation
// random choice for numbers of epicenters
nb_rock = rand()%5;
nb_tree = rand()%5;
nb_berries = rand()%5;
size_epicenters = nb_rock + nb_tree + nb_berries + NB_TEAMS;
l_epicenters = malloc(sizeof(t_epicenter)*size_epicenters);
//plains generation for each player => after spawn
for(i=0;i<NB_TEAMS;i++)
create_epicenter(GRASS);
for(i=2; i<5;i++){
int nb_epi = rand()%5;
for(i=0;i<nb_epi;i++)
create_epicenter(i);
}
for(i=0;i<nb_rock;i++)
create_epicenter(ROCK);
for(i=0;i<nb_tree;i++)
create_epicenter(TREE);
for(i=0;i<nb_berries;i++)
create_epicenter(BERRIES);
//génération de la carte
for (i=0;i<width;i++){
for(j=0;j>height;j++){
if (i == 0 || j == 0){
map[i][j]=BEDROCK;
else{
map[i][j] = generate(i,j);
map[i][j].type = BEDROCK;
}else{
type=generate(i,j);
map[i][j].type = type;
}
}
}
for(int k=0;k<NB_TEAMS;k++){
//génération spawns
for(k=0;k<NB_TEAMS;k++){
x_rand= rand()%width;
y_rand= rand()%height;
int error = 1;
while(error != 0){
error = 0;
for (int l=0;l<k;l++){
for (l=0;l<k;l++){
t_coord sp = teams[l].spawn;
if (distance_manhattan(x_rand,y_rand,sp.x,sp.y) < 50)
error = 1;
@ -79,22 +102,24 @@ void create_epicenter(int type){
epicenter.power = rand()%MAX_POWER;
epicenter.radius = rand()%(width*height/4);
l_epicenters[nb_epicenters++]=epicenter;
l_epicenters[cpt_epicenter++]=epicenter;
}
int generate(int x, int y){
int i, type;
int i, ratio, dist_to_epi, sum, val, type;
int proba[5];
for(i=0;i<size_epi;i++){
t_epicenter epi;
for(i=0;i<size_epicenters;i++){
epi = l_epicenters[i];
dist_to_epi = distance_manhattan(x,y,epi.x, epi.y);
if (dist_to_epi < epi.radius){
ratio = (int) ((epi.radius - dist_to_epi) * 100) / radius;
ratio = (int) ((epi.radius - dist_to_epi) * 100) / epi.radius;
proba[epi.type-1]=epi.power * ratio;
}
}
int sum=0;
sum=0;
for (i=0;i<5;i++){
sum += proba[i];
}
@ -102,12 +127,11 @@ int generate(int x, int y){
int seuil = 0;
for (i=0;i<5;i++){
start += proba[i]
if(type < seuil){
seuil += proba[i];
if(val < seuil)
return i+1;
}
}
return 1;
return GRASS;
}
int distance_manhattan(int x1,int y1, int x2, int y2){