123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- /*
- 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 <http://www.gnu.org/licenses/>.
- */
- #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;i<res->x;i++)
- {
- res->map[i] = malloc(sizeof(t_map_element)*y);
- for(j=0;j<res->y;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; j<mp->y-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;i<mp->x-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;j<yend-1;j++)
- {
- printf("+");
- for(k=xbeg;k<xend;k++)
- printf("-+");
- printf("-+\n");
- printf("|");
- for(i=xbeg;i<xend;i++)
- {
- printf("%c|",(mp->map[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<xend;k++)
- printf("-+");
- printf("-+\n");
- }
|