#include "main.h" #include "team.h" #include "tools.h" #include "generator.h" #include #include #include #include typedef struct{ t_dude dude1; t_dude dude2; int attack; } t_fight; // temp code t_action purple_update(void* my_info, void* com_data, int my_id); t_action orange_update(void* my_info, void* com_data, int my_id); int get_purple_size(); int get_orange_size(); void initWorld(){ int i; // allocations printf("Allocating memory...\n"); teams = malloc(sizeof(t_team)*NB_TEAMS); for(i=0; i 0) teams[i].spawn_count++; if(teams[i].spawn_count > 10 && map[teams[i].spawn.x][teams[i].spawn.y].type == SPAWN){ teams[i].spawn_food--; teams[i].spawn_count = 0; new_dude.pos = teams[i].spawn; new_dude.team = teams[i].team; new_dude.inventory = -1; new_dude.ground = map[teams[i].spawn.x][teams[i].spawn.y]; new_dude.custom_data = malloc(teams[i].dude_size); memset(new_dude.custom_data, 0, teams[i].dude_size); new_dude.com_data = NULL; teams[i].dudes[teams[i].nb_dudes++] = new_dude; } } } void handleAction(t_action action, t_dude* dude){ t_coord target_pos = getPos(dude->pos, action.dir); t_pixel target = map[target_pos.x][target_pos.y]; switch(action.type){ case MOVE : if( target.type != WALL && target.type != ROCK && target.type != BEDROCK && target.type != IRON_ORE && target.type != DUDE && target.type != TREE ) add_move(dude, target_pos); break; case ATTACK : printf("forbidden action\n"); //if(target.type == DUDE) // addFight(dude, *((t_dude*)(target.data))); break; case PICK : printf("forbidden action\n"); // if target is resource : // put target in inventory // put grass on target break; case PUT : printf("forbidden action\n"); // if target is grass or road or corpse // target = inventory // inventory = NULL // else if target is spawn and inventory is food // spawn.food ++ break; case WORK : printf("forbidden action\n"); // switch target // case rock -> stone // case berries -> food // case tree -> wood // case grass -> road // case road -> grass // case stone -> wall // case wood -> sign // case sign -> wood // case iron_ore -> iron // case iron -> sword // case corpse -> grass break; case WAIT : printf("forbidden action\n"); // ... break; case COMMUNICATE : printf("forbidden action\n"); // if target is sign -> set sign message // if target is dude -> sent message to dude break; } } void generateImg(){ int i, j; for(i=0; iformat, 255, 255, 255)); if (SDL_Init(SDL_INIT_VIDEO) == -1) { fprintf(stderr, "Erreur d'initialisation de la SDL");// and you don't want my french comment :p exit(EXIT_FAILURE); } } int MAIN( int argc, char** argv ) { Uint8 *keystate = SDL_GetKeyState(NULL); int over = 0; Uint32 temps; printf("Starting Pixel Wars on %s\n", OS); initSDL(); initWorld(); SDL_Flip(img); printf("Launching simulation... press ESCAPE to stop.\n"); while (!keystate[SDLK_ESCAPE] && !over){ temps = SDL_GetTicks(); SDL_PumpEvents(); int i; spawnDudes(); for(i=0; i