fix bug communication
This commit is contained in:
parent
48ef8a3fa7
commit
da21290c9b
17
main.c
17
main.c
@ -56,6 +56,10 @@ void updateTeam(t_team team){
|
||||
for(i=0; i<team.nb_dudes; i++){
|
||||
current_dude = team.dudes + i;
|
||||
team.dudes[i].action = team.update((void*)(team.dudes[i].custom_data), (void*)(team.dudes[i].com_data), team.dudes[i].success);
|
||||
if(team.dudes[i].com_data != NULL){
|
||||
free(team.dudes[i].com_data);
|
||||
team.dudes[i].com_data = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
for(i=0; i<team.nb_dudes; i++){
|
||||
@ -142,11 +146,8 @@ void handleAction(t_dude* dude){
|
||||
t_action action = dude->action;
|
||||
t_coord target_pos = getPos(dude->pos, action.dir);
|
||||
t_pixel target = map[target_pos.x][target_pos.y];
|
||||
t_dude* target_dude;
|
||||
int* nb_res;
|
||||
if(dude->com_data != NULL){
|
||||
free(dude->com_data);
|
||||
dude->com_data = NULL;
|
||||
}
|
||||
switch(action.type){
|
||||
case MOVE :
|
||||
dude->success = 0;
|
||||
@ -305,10 +306,12 @@ void handleAction(t_dude* dude){
|
||||
switch(target.type){
|
||||
// TODO : conflicts are not handled in a fair way
|
||||
case DUDE :
|
||||
printf("message to dude\n");
|
||||
action.com_data.flag = (action.dir+2)%4;
|
||||
if(dude->com_data == NULL){
|
||||
dude->com_data = malloc(sizeof(t_com));
|
||||
*(dude->com_data) = action.com_data;
|
||||
target_dude = target.data;
|
||||
if(target_dude->com_data == NULL){
|
||||
target_dude->com_data = malloc(sizeof(t_com));
|
||||
*(target_dude->com_data) = action.com_data;
|
||||
dude->success = 1;
|
||||
}else
|
||||
dude->success = 0;
|
||||
|
11
orange.c
11
orange.c
@ -71,6 +71,9 @@ t_action orange_update(void* my_info, t_com* com_data, int success){
|
||||
return action;
|
||||
}
|
||||
|
||||
if (com_data != NULL)
|
||||
printf("%d\n",data->job);
|
||||
|
||||
orangeApplyAction(data,com_data);
|
||||
|
||||
switch(data->job){
|
||||
@ -185,9 +188,9 @@ void orangeWaitEffect(t_orange_info* data, t_com* com_data){
|
||||
}
|
||||
break;
|
||||
case O_MASTER:
|
||||
if ((data->listening == 1) && (com_data != NULL)){
|
||||
if(com_data->data[0] == 1)
|
||||
data->talking = 1;
|
||||
if (com_data != NULL){
|
||||
printf("got a message \n");
|
||||
data->talking = 1;
|
||||
}else{
|
||||
data->talking = 0;
|
||||
}
|
||||
@ -221,6 +224,7 @@ void orangeJobless(t_action* action, t_orange_info* data, t_com* com_data, int s
|
||||
|
||||
void orangeMaster(t_action* action, t_orange_info* data, t_com* com_data, int success){
|
||||
if (data->talking){
|
||||
printf("talking\n");
|
||||
action->type = COMMUNICATE;
|
||||
action->dir = com_data->flag;
|
||||
action->com_data.data[0] = 1;
|
||||
@ -233,7 +237,6 @@ void orangeMaster(t_action* action, t_orange_info* data, t_com* com_data, int su
|
||||
|
||||
void orangeGatherer(t_action* action, t_orange_info* data, t_com* com_data, int success){
|
||||
int i,t;
|
||||
printf("gatherer\n");
|
||||
//action choice
|
||||
for(i=0;i<4;i++){
|
||||
t = getNear(i);
|
||||
|
Loading…
x
Reference in New Issue
Block a user