fix compil error in orange.c

This commit is contained in:
Lendemor 2015-01-17 12:03:13 +01:00
parent dd480fe352
commit b1ed0df54a

148
orange.c
View File

@ -11,19 +11,17 @@ enum{
};
enum{
AIM_SPAWN, AIM_SPOT,NO_AIM
NO_AIM, AIM_SPAWN, AIM_SPOT,
};
typedef struct{
char type; //the type of ressource that was found
int x; // x where ressource was found
int y; // y where ressource was found
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
int x; // x relative to the spawn
int y; // y relative to the spawn
char name; // name of the dude
t_coord pos; // position relative to the spawn
char job;
char aim;
t_ressource_spot res_spot;
@ -37,58 +35,52 @@ typedef union{
typedef struct{
char name_sender;
char type_message;
t_message message;
} t_com_data;
} t_com_custom;
void check_action_success(t_info_data*, int);
void search_job(t_action*, t_info_data*, int);
void gather_res(t_action*, t_info_data*, int);
//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;
check_action_success(data,success);
checkActionSuccess(data,success);
//search_job(action, data, success);
switch(data.job){
//searchJob(&action, data, success);
switch(data->job){
case JOBLESS:
case MASTER:
case GATHERER:
gather_food(action,data,success);
gatherFood(&action,data,success);
break;
case WOODCUTTER:
case MINER:
break;
}
return action;
}
void check_action_success(t_info_data* data, int success){
void checkActionSuccess(t_info_data* data, int success){
if (!success) return;
switch(data->last_action){
case MOVE:
switch(data->last_dir){
case NORTH:
data->x++;
break;
case SOUTH:
data->x--;
break;
case EAST:
data->y++;
break;
case WEST:
data->y--;
break;
default:
break;
}
data->pos=orangeNewPos(data->pos, data->last_dir);
break;
case ATTACK:
case PICK:
data->searching=0;
data->aim=AIM_SPAWN;
case PUT:
case WORK:
case WAIT:
@ -97,60 +89,78 @@ void check_action_success(t_info_data* data, int success){
break;
}
}
void search_job(t_action* action, t_info_data* data, int success){
void searchJob(t_action* action, t_info_data* data, int success){
return;
}
void gather_food(t_action* action, t_info_data* data, int success){
void gatherFood(t_action* action, t_info_data* data, int success){
int i,t;
//default data for action
action->data = NULL;
//action choice
if (getInventory() == -1){
for(i=0;i<4;i++){
t = getNear(i);
switch(t){
case BERRIES:
action.type = WORK;
action.dir = i;
action.data = NULL;
break;
action->type = WORK;
action->dir = i;
return;
case FOOD:
action.type = PICK;
action.dir = i;
action.data = NULL;
break;
action->type = PICK;
action->dir = i;
return;
default:
action.type = MOVE;
action.dir = rand()%4;
action.data = NULL;
break;
}
}
}else{
i= newDir(data);
}
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:
return dirToAim(O,O);
aim_pos.x=0;
aim_pos.y=0;
break;
case AIM_SPOT:
return dirToAim(data->res_spot->x,data->res_spot->y);
case NO_TARGET:
return rand()%4;
aim_pos=data->res_spot.pos;
break;
case NO_AIM:
return (data->last_dir + rand()%3)%4;
}
}
int distTo(x1,y1,x2,y2){
return abs(x2-x1) + abs(y2-y1);
}
int dirToAim(int x, int y){
do{
}while(distTo(x,y) > distTo(x,y))
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);
}