#include "team.h" #include "stdio.h" #include "stdlib.h" // Development in progress //Structure definition enum{ JOBLESS, MASTER, GATHERER, WOODCUTTER, MINER, NB_JOBS }; enum{ NO_AIM, AIM_SPAWN, AIM_SPOT, }; typedef struct{ char type; //the type of ressource that was found t_coord pos; // pos where ressource was found } t_ressource_spot; typedef struct{ char name; // name of the dude t_coord pos; // position relative to the spawn char job; char aim; t_ressource_spot res_spot; char last_action; char last_dir; } t_info_data; typedef union{ t_ressource_spot res_spot; }t_message; typedef struct{ char name_sender; char type_message; t_message message; } t_com_custom; //check function void checkActionSuccess(t_info_data*, int); //tools functions int newDir(t_info_data*); t_coord orangeNewPos(t_coord, int); int distance(t_coord,t_coord); //jobs function void searchJob(t_action*, t_info_data*, int); void gatherFood(t_action*, t_info_data*, int); t_action orange_update(void* my_info, t_com* communication_data, int success){ t_info_data* data = (t_info_data*)my_info; //t_data* data = (t_data*)my_info; t_action action; checkActionSuccess(data,success); //searchJob(&action, data, success); switch(data->job){ case JOBLESS: case MASTER: case GATHERER: gatherFood(&action,data,success); break; case WOODCUTTER: case MINER: break; } return action; } void checkActionSuccess(t_info_data* data, int success){ if (!success) return; switch(data->last_action){ case MOVE: data->pos=orangeNewPos(data->pos, data->last_dir); break; case ATTACK: case PICK: data->aim=AIM_SPAWN; case PUT: case WORK: case WAIT: case COMMUNICATE: default: break; } } void searchJob(t_action* action, t_info_data* data, int success){ return; } void gatherFood(t_action* action, t_info_data* data, int success){ int i,t; //action choice if (getInventory() == -1){ for(i=0;i<4;i++){ t = getNear(i); switch(t){ case BERRIES: action->type = WORK; action->dir = i; return; case FOOD: action->type = PICK; action->dir = i; return; default: break; } } } action->type= MOVE; action->dir = newDir(data); return; } //orange tools int newDir(t_info_data* data){ int dir; t_coord aim_pos; switch(data->aim){ case AIM_SPAWN: aim_pos.x=0; aim_pos.y=0; break; case AIM_SPOT: aim_pos=data->res_spot.pos; break; case NO_AIM: return (data->last_dir + rand()%3)%4; } do{ dir= rand()%4; }while(distance(orangeNewPos(data->pos,dir),aim_pos) < distance(data->pos,aim_pos)); return dir; } t_coord orangeNewPos(t_coord pos, int dir){ t_coord new_pos; switch(dir){ case NORTH: new_pos.x=pos.x; new_pos.y=pos.y+1; break; case SOUTH: new_pos.x=pos.x; new_pos.y=pos.y-1; break; case EAST: new_pos.x=pos.x+1; new_pos.y=pos.y; break; case WEST: new_pos.x=pos.x-1; new_pos.y=pos.y; break; } return new_pos; } int distance(t_coord p1, t_coord p2){ return abs(p2.x-p1.x) + abs(p2.y-p1.y); }