generator okay (worked but can be improved)
This commit is contained in:
parent
c6174a62db
commit
e440d92591
5
.gitignore
vendored
5
.gitignore
vendored
@ -1 +1,4 @@
|
|||||||
*.o
|
*.o
|
||||||
|
.fuse_hidden*
|
||||||
|
PixelWars
|
||||||
|
PixelWars.exe
|
||||||
|
21
generator.c
21
generator.c
@ -16,7 +16,8 @@ enum{
|
|||||||
VILLAGE, PLAINS, FOREST,MOUNTAINS,NB_BIOMES
|
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}};
|
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{
|
typedef struct{
|
||||||
@ -48,7 +49,6 @@ void init_generator();
|
|||||||
|
|
||||||
void create_map(int w, int h){
|
void create_map(int w, int h){
|
||||||
int i,j;
|
int i,j;
|
||||||
int type;
|
|
||||||
|
|
||||||
//biome variable
|
//biome variable
|
||||||
int nb_plains, nb_forests, nb_mountains;
|
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));
|
map[i][j].data=malloc(sizeof(int));
|
||||||
memset(map[i][j].data,ORANGE,sizeof(int));
|
memset(map[i][j].data,ORANGE,sizeof(int));
|
||||||
}else{
|
}else{
|
||||||
type=generate(i,j);
|
map[i][j].type = generate(i,j);
|
||||||
map[i][j].type = type;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -99,6 +98,7 @@ void create_map(int w, int h){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void init_generator(){
|
void init_generator(){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_spawns(t_pixel** map, t_team* teams){
|
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];
|
sp_y[1] = height-sp_y[0];
|
||||||
|
|
||||||
for(i=0;i<2;i++){
|
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.x = sp_x[i];
|
||||||
teams[i].spawn.y = sp_y[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 check_nears_spawn(int x, int y){
|
||||||
int i,c = 0;
|
int i,c = 0;
|
||||||
for(i=0;i<2;i++)
|
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;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,7 +187,14 @@ int generate(int x, int y){
|
|||||||
for(i=0;i<size_biomes;i++){
|
for(i=0;i<size_biomes;i++){
|
||||||
biome = l_biomes[i];
|
biome = l_biomes[i];
|
||||||
if ((dist=in_radius(x,y,biome)) != -1){
|
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;
|
sum += biome.power*ratio*100;
|
||||||
for(j=0;j<5;j++){
|
for(j=0;j<5;j++){
|
||||||
proba[j]+=(proba_table[biome.type][j])*(biome.power)*ratio;
|
proba[j]+=(proba_table[biome.type][j])*(biome.power)*ratio;
|
||||||
|
22
generator_bis.c
Normal file
22
generator_bis.c
Normal 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){
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user