/* Copyright (C) 2011 Weber Yann, Schuck Clement This file is part of Tansive. Tansive is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Tansive is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Tansive. If not, see . */ #include "map.h" t_map* create_map(int x, int y) { int i,j; t_map* res = malloc(sizeof(t_map)); res->x = x; res->y = y; res->map = malloc(sizeof(t_map_element*)*x); for(i=0;ix;i++) { res->map[i] = malloc(sizeof(t_map_element)*y); for(j=0;jy;j++) res->map[i][j].type = 0; } return res; } void map_regen_veget(t_map* mp) { int i,j,k,l, mod = 0, pred_mod = 0; char end = 0; for(j=1; jy-1;j++) { pred_mod = 0; if(mp->map[0][j-1].type == MAP_ELT_VEGET) pred_mod++; if(mp->map[0][j].type == MAP_ELT_VEGET) pred_mod++; if(mp->map[0][j+1].type == MAP_ELT_VEGET) pred_mod++; if(mp->map[1][j-1].type == MAP_ELT_VEGET) pred_mod++; if(mp->map[1][j+1].type == MAP_ELT_VEGET) pred_mod++; for(i=1;ix-1;i++) { mod = pred_mod; pred_mod = 0; k = i+1; if(mp->map[k][j-1].type == MAP_ELT_VEGET) { mod++; pred_mod++; } if(mp->map[k][j].type == MAP_ELT_VEGET) { mod++; pred_mod++; } if(mp->map[k][j+1].type == MAP_ELT_VEGET) { mod++; pred_mod++; } if(mp->map[i][j].type == MAP_ELT_EMPTY && !(rand()%(MAP_VEG_SPAWN/( (mod==0?1:mod * MAP_VEG_COEFPROX)))) ) { mp->map[i][j].type = MAP_ELT_VEGET; mp->map[i][j].timeleft_veget = rand()%(MAP_VEG_MAX_TIMELEFT-MAP_VEG_MIN_TIMELEFT)+MAP_VEG_MIN_TIMELEFT; pred_mod++; } else if(mp->map[i][j].type == MAP_ELT_VEGET) { mp->map[i][j].timeleft_veget--; if(mp->map[i][j].timeleft_veget == 0) mp->map[i][j].type = MAP_ELT_EMPTY; } } } } void disp_map(t_map* mp, int xbeg, int ybeg, int xend, int yend) { int i,j,k; if(xbeg>=xend || ybeg>=yend || yend > mp->y || xend > mp->x || xbeg<0 || ybeg<0) fprintf(stderr,"disp_map : Bad parameters\n"); for(j=ybeg;jmap[i][j].type == MAP_ELT_EMPTY?' ':(mp->map[i][j].type == MAP_ELT_VEGET?'#':'C'))); } printf("%c|\n",(mp->map[i][j].type == MAP_ELT_EMPTY?' ':(mp->map[i][j].type == MAP_ELT_VEGET?'#':'C'))); } printf("+"); for(k=xbeg;k