fixed memory issue ith more than 50 dudes
This commit is contained in:
parent
858a9f6201
commit
695f9e79a0
8
main.c
8
main.c
@ -99,7 +99,7 @@ void spawnDudes(){
|
||||
for(i=0; i<NB_TEAMS; i++){
|
||||
if(teams[i].spawn_food > 0)
|
||||
teams[i].spawn_count++;
|
||||
if(teams[i].spawn_count > SPAWN_COOLDOWN && map[teams[i].spawn.x][teams[i].spawn.y].type == SPAWN){
|
||||
if(teams[i].nb_dudes < MAX_DUDES && teams[i].spawn_count > SPAWN_COOLDOWN && map[teams[i].spawn.x][teams[i].spawn.y].type == SPAWN){
|
||||
teams[i].spawn_food--;
|
||||
teams[i].spawn_count = 0;
|
||||
|
||||
@ -332,8 +332,8 @@ int MAIN
|
||||
int new_time = 0;
|
||||
int remaining_time = -1;
|
||||
int fullscreen = 0;
|
||||
int width = DEFAULT_WIDTH;
|
||||
int height = DEFAULT_HEIGHT;
|
||||
int width = DEFAULT_GAME_WIDTH;
|
||||
int height = DEFAULT_GAME_HEIGHT;
|
||||
|
||||
#ifndef _WIN32
|
||||
argv++;
|
||||
@ -366,8 +366,6 @@ int MAIN
|
||||
|
||||
printf("Launching simulation...\n");
|
||||
|
||||
printf("spawn (%d, %d)\n", teams[PURPLE].spawn.x, teams[PURPLE].spawn.y);
|
||||
|
||||
time = SDL_GetTicks();
|
||||
while (!over){
|
||||
while(SDL_PollEvent(&event)){
|
||||
|
6
main.h
6
main.h
@ -13,8 +13,10 @@
|
||||
|
||||
#define MAX_DUDES 50
|
||||
#define STACK_SIZE 5
|
||||
#define DEFAULT_WIDTH 400
|
||||
#define DEFAULT_HEIGHT 250
|
||||
#define DEFAULT_GAME_WIDTH 400
|
||||
#define DEFAULT_GAME_HEIGHT 250
|
||||
#define DEFAULT_WINDOW_WIDTH 400
|
||||
#define DEFAULT_WINDOW_HEIGHT 250
|
||||
#define NB_STARTING_FOOD 5
|
||||
#define SPAWN_COOLDOWN 30
|
||||
|
||||
|
5
team.h
5
team.h
@ -33,6 +33,11 @@ typedef struct{
|
||||
void* data;
|
||||
} t_action;
|
||||
|
||||
typedef struct{
|
||||
int dest;
|
||||
void* message;
|
||||
} t_communication;
|
||||
|
||||
int getInventory();
|
||||
|
||||
int getNear(int dir);
|
||||
|
9
tools.c
9
tools.c
@ -24,6 +24,15 @@ void add_move(t_dude* dude, t_coord dst){
|
||||
|
||||
void applyMove(t_move* move){
|
||||
t_pixel target = map[move->dst.x][move->dst.y];
|
||||
if( target.type == WALL
|
||||
|| target.type == ROCK
|
||||
|| target.type == BEDROCK
|
||||
|| target.type == IRON_ORE
|
||||
|| target.type == TREE
|
||||
|| target.type == DUDE
|
||||
|| target.type == LIBRARY){
|
||||
free(move);
|
||||
}
|
||||
move->dude->success = 1;
|
||||
map[move->dude->pos.x][move->dude->pos.y] = move->dude->ground; // set the ground where the dude was
|
||||
move->dude->ground = target; // set the ground of the dude to where he goes
|
||||
|
Loading…
x
Reference in New Issue
Block a user