rename function in orange with prefix

This commit is contained in:
Lendemor 2015-01-19 15:54:52 +01:00
parent 0bda0053a9
commit 9b6cbe6aad

View File

@ -17,7 +17,7 @@ enum{
typedef struct{ typedef struct{
char type; //the type of ressource that was found char type; //the type of ressource that was found
t_coord pos; // pos where ressource was found t_coord pos; // pos where ressource was found
} t_ressource_spot; } t_orange_ressource_spot;
typedef struct{ typedef struct{
char name; // name of the dude char name; // name of the dude
@ -25,32 +25,32 @@ typedef struct{
char hatched; char hatched;
char job; char job;
char aim; char aim;
t_ressource_spot res_spot; t_orange_ressource_spot res_spot;
char last_action; char last_action;
char last_dir; char last_dir;
} t_info_data; } t_orange_info_data;
typedef union{ typedef union{
t_ressource_spot res_spot; t_orange_ressource_spot res_spot;
}t_message; }t_orange_message;
typedef struct{ typedef struct{
char name_sender; char name_sender;
char type_message; char type_message;
t_message message; t_orange_message message;
} t_com_custom; } t_orange_com;
//check function //check function
void checkActionSuccess(t_info_data*, int); void orangeCheckActionSuccess(t_info_data*, int);
//tools functions //tools functions
int newDir(t_info_data*); int orangeNewDir(t_info_data*);
t_coord orangeNewPos(t_coord, int); t_coord orangeNewPos(t_coord, int);
int distance(t_coord,t_coord); int orangeDistance(t_coord,t_coord);
//jobs function //jobs function
void searchJob(t_action*, t_info_data*, int); void orangeSearchJob(t_action*, t_info_data*, int);
void gatherFood(t_action*, t_info_data*, int); void orangeGatherFood(t_action*, t_info_data*, int);
t_action orange_update(void* my_info, t_com* communication_data, int success){ t_action orange_update(void* my_info, t_com* communication_data, int success){
t_info_data* data = (t_info_data*)my_info; t_info_data* data = (t_info_data*)my_info;
@ -65,9 +65,9 @@ t_action orange_update(void* my_info, t_com* communication_data, int success){
data->pos.y=0; data->pos.y=0;
} }
checkActionSuccess(data,success); orangeCheckActionSuccess(data,success);
//searchJob(&action, data, success); //orangeSearchJob(&action, data, success);
switch(data->job){ switch(data->job){
case JOBLESS: case JOBLESS:
action.type = WAIT; action.type = WAIT;
@ -79,7 +79,7 @@ t_action orange_update(void* my_info, t_com* communication_data, int success){
action.dir=0; action.dir=0;
break; break;
case GATHERER: case GATHERER:
gatherFood(&action,data,success); orangeGatherFood(&action,data,success);
break; break;
case WOODCUTTER: case WOODCUTTER:
case MINER: case MINER:
@ -89,7 +89,7 @@ t_action orange_update(void* my_info, t_com* communication_data, int success){
data->last_dir = action.dir; data->last_dir = action.dir;
return action; return action;
} }
void checkActionSuccess(t_info_data* data, int success){ void orangeCheckActionSuccess(t_info_data* data, int success){
if (!success) return; if (!success) return;
t_coord aim_pos; t_coord aim_pos;
@ -99,13 +99,13 @@ void checkActionSuccess(t_info_data* data, int success){
data->pos=orangeNewPos(data->pos, data->last_dir); data->pos=orangeNewPos(data->pos, data->last_dir);
//update aim //update aim
if (getInventory() == -1){ if (getInventory() == -1){
if (distance(data->pos,data->res_spot.pos) == 0){ if (orangeDistance(data->pos,data->res_spot.pos) == 0){
data->aim = NO_AIM; data->aim = NO_AIM;
} }
}else{ }else{
aim_pos.x = 0; aim_pos.x = 0;
aim_pos.y = 0; aim_pos.y = 0;
if(distance(data->pos, aim_pos) == 1){ if(orangeDistance(data->pos, aim_pos) == 1){
data->aim=AIM_SPOT; data->aim=AIM_SPOT;
} }
} }
@ -126,10 +126,12 @@ void checkActionSuccess(t_info_data* data, int success){
break; break;
} }
} }
void searchJob(t_action* action, t_info_data* data, int success){
// job functions
void orangeSearchJob(t_action* action, t_info_data* data, int success){
return; return;
} }
void gatherFood(t_action* action, t_info_data* data, int success){ void orangeGatherFood(t_action* action, t_info_data* data, int success){
int i,t; int i,t;
//action choice //action choice
for(i=0;i<4;i++){ for(i=0;i<4;i++){
@ -158,12 +160,12 @@ void gatherFood(t_action* action, t_info_data* data, int success){
} }
} }
action->type= MOVE; action->type= MOVE;
action->dir = newDir(data); action->dir = orangeNewDir(data);
return; return;
} }
//orange tools //orange tools
int newDir(t_info_data* data){ int orangeNewDir(t_info_data* data){
int dir; int dir;
int current_dist,new_dist; int current_dist,new_dist;
t_coord aim_pos; t_coord aim_pos;
@ -178,12 +180,11 @@ int newDir(t_info_data* data){
aim_pos=data->res_spot.pos; aim_pos=data->res_spot.pos;
break; break;
} }
// printf("[%d : %d] [%d : %d]",data->pos.x,data->pos.y,aim_pos.x,aim_pos.y); current_dist = orangeDistance(data->pos,aim_pos);
current_dist = distance(data->pos,aim_pos);
if (current_dist == 0) return 0; if (current_dist == 0) return 0;
do{ do{
dir= rand()%4; dir= rand()%4;
new_dist = distance(orangeNewPos(data->pos,dir),aim_pos); new_dist = orangeDistance(orangeNewPos(data->pos,dir),aim_pos);
}while(current_dist <= new_dist); }while(current_dist <= new_dist);
if (getNear(dir) == DUDE || getNear(dir) == TREE || getNear(dir) == ROCK || getNear(dir) == IRON_ORE){ if (getNear(dir) == DUDE || getNear(dir) == TREE || getNear(dir) == ROCK || getNear(dir) == IRON_ORE){
@ -211,6 +212,6 @@ t_coord orangeNewPos(t_coord pos, int dir){
} }
return new_pos; return new_pos;
} }
int distance(t_coord p1, t_coord p2){ int orangeDistance(t_coord p1, t_coord p2){
return abs(p2.x-p1.x) + abs(p2.y-p1.y); return abs(p2.x-p1.x) + abs(p2.y-p1.y);
} }