From da21290c9b7cdeec4a922c54abad882bf84fd012 Mon Sep 17 00:00:00 2001 From: Lendemor Date: Thu, 22 Jan 2015 14:25:38 +0100 Subject: [PATCH] fix bug communication --- main.c | 17 ++++++++++------- orange.c | 11 +++++++---- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/main.c b/main.c index ea46358..1d5e59b 100755 --- a/main.c +++ b/main.c @@ -56,6 +56,10 @@ void updateTeam(t_team team){ for(i=0; iaction; 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; diff --git a/orange.c b/orange.c index 404ab73..dc64c67 100644 --- a/orange.c +++ b/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);