155 lines
2.6 KiB
C
155 lines
2.6 KiB
C
#include "team.h"
|
|
#include "stdio.h"
|
|
#include "stdlib.h"
|
|
|
|
// Development in progress
|
|
|
|
//Structure definition
|
|
|
|
enum{
|
|
JOBLESS, MASTER, GATHERER, WOODCUTTER, MINER, NB_JOBS
|
|
};
|
|
|
|
enum{
|
|
AIM_SPAWN, AIM_SPOT,NO_AIM
|
|
};
|
|
|
|
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
|
|
} 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 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;
|
|
t_message message;
|
|
} t_com_data;
|
|
|
|
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);
|
|
|
|
t_action orange_update(void* my_info, void* com_data, int success){
|
|
t_info_data* data = (t_info_data*)my_info;
|
|
t_action action;
|
|
|
|
check_action_success(data,success);
|
|
|
|
//search_job(action, data, success);
|
|
switch(data.job){
|
|
case JOBLESS:
|
|
case MASTER:
|
|
case GATHERER:
|
|
gather_food(action,data,success);
|
|
case WOODCUTTER:
|
|
case MINER:
|
|
|
|
}
|
|
|
|
return action;
|
|
}
|
|
|
|
void check_action_success(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;
|
|
}
|
|
break;
|
|
case ATTACK:
|
|
case PICK:
|
|
data->searching=0;
|
|
case PUT:
|
|
case WORK:
|
|
case WAIT:
|
|
case COMMUNICATE:
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
void search_job(t_action* action, t_info_data* data, int success){
|
|
return;
|
|
}
|
|
|
|
void gather_food(t_action* action, t_info_data* data, int success){
|
|
int i,t;
|
|
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;
|
|
case FOOD:
|
|
action.type = PICK;
|
|
action.dir = i;
|
|
action.data = NULL;
|
|
break;
|
|
default:
|
|
action.type = MOVE;
|
|
action.dir = rand()%4;
|
|
action.data = NULL;
|
|
break;
|
|
}
|
|
}
|
|
}else{
|
|
i= newDir(data);
|
|
|
|
}
|
|
return;
|
|
}
|
|
|
|
int newDir(t_info_data* data){
|
|
switch(data->aim){
|
|
case AIM_SPAWN:
|
|
return dirToAim(O,O);
|
|
case AIM_SPOT:
|
|
return dirToAim(data->res_spot->x,data->res_spot->y);
|
|
case NO_TARGET:
|
|
return rand()%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))
|
|
|
|
} |