generator okay (worked but can be improved)

This commit is contained in:
Lendemor 2015-01-14 10:16:10 +01:00
parent c6174a62db
commit e440d92591
3 changed files with 40 additions and 8 deletions

5
.gitignore vendored
View File

@ -1 +1,4 @@
*.o
*.o
.fuse_hidden*
PixelWars
PixelWars.exe

View File

@ -16,7 +16,8 @@ enum{
VILLAGE, PLAINS, FOREST,MOUNTAINS,NB_BIOMES
};
//probability for each 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{
@ -48,7 +49,6 @@ void init_generator();
void create_map(int w, int h){
int i,j;
int type;
//biome variable
int nb_plains, nb_forests, nb_mountains;
@ -90,8 +90,7 @@ void create_map(int w, int h){
map[i][j].data=malloc(sizeof(int));
memset(map[i][j].data,ORANGE,sizeof(int));
}else{
type=generate(i,j);
map[i][j].type = type;
map[i][j].type = generate(i,j);
}
}
}
@ -99,6 +98,7 @@ void create_map(int w, int h){
}
void init_generator(){
}
void set_spawns(t_pixel** map, t_team* teams){
@ -115,9 +115,9 @@ void set_spawns(t_pixel** map, t_team* teams){
sp_y[1] = height-sp_y[0];
for(i=0;i<2;i++){
create_biome(sp_x[i],sp_y[i],VILLAGE);
teams[i].spawn.x = sp_x[i];
teams[i].spawn.y = sp_y[i];
create_biome(sp_x[i],sp_y[i],VILLAGE);
}
}
@ -166,7 +166,7 @@ int check_nears_biomes(int x, int y){
int check_nears_spawn(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]) < 100) c++;
if (distance_manhattan(x,y,sp_x[i],sp_y[i]) < 75) c++;
return c;
}
@ -187,7 +187,14 @@ int generate(int x, int y){
for(i=0;i<size_biomes;i++){
biome = l_biomes[i];
if ((dist=in_radius(x,y,biome)) != -1){
ratio=((biome.radius-dist)*100)/biome.radius;
ratio=(((biome.radius-dist)*100)/biome.radius);
//ne marche pas correctement, besoin de fractale à la place
/* if (biome.type == MOUNTAINS && (ratio < 20)){
sum += biome.power*ratio*100;
proba[0] += biome.power*ratio*20;
proba[3] += biome.power*ratio*75;
proba[4] += biome.power*ratio*5;
}else{*/
sum += biome.power*ratio*100;
for(j=0;j<5;j++){
proba[j]+=(proba_table[biome.type][j])*(biome.power)*ratio;

22
generator_bis.c Normal file
View File

@ -0,0 +1,22 @@
#include "main.h"
int width, height;
void create_map(int w, int h){
width = w;
height = h;
if (w != h){
printf("Error : Use generator_bis.c with square map (w=h=2n) \n");
}
float* height_map = malloc(sizeof(float)*width*height);
generate_height(height_map);
}
void generate_height(float* h_map){
}