diff --git a/src/simulation.cpp b/src/simulation.cpp index f7d845a..1dd1f14 100644 --- a/src/simulation.cpp +++ b/src/simulation.cpp @@ -24,7 +24,6 @@ void Simulation::update() for (auto dude : m_dudes){ auto action = m_teams[dude->getTeam()].update(*dude); //get action for this dude from behavior function in team handleAction(action,dude); - // TODO perform action (cf old_code/main.c -> void handleAction(t_dude* dude) ) } // for each team, spawn dude if condition met @@ -39,6 +38,8 @@ void Simulation::update() } } +// TODO perform action (cf old_code/main.c -> void handleAction(t_dude* dude) ) + void Simulation::handleAction(Action *action, Dude *dude){ Coord targetPos(dude->getPos() + Coord(action->dir)); Pixel target = p_map->getPixel(targetPos); @@ -153,47 +154,46 @@ void Simulation::handleAction(Action *action, Dude *dude){ } // TODO : update pixel break; - } -} - -/* - case WAIT : - dude->success = 1; + case Action::WAIT: + dude->setSuccess(true); + break; + case Action::COMMUNICATE: + switch(target.type){ + case Pixel::DUDE: + action->com_data.flag = (action->dir+2)%4; + // TODO : find a way to get targetDude + //targetDude = + if(targetDude->getCom().data == NULL){ + targetDude->receiveComData(action->com_data); + dude->setSuccess(true); + }else + dude->setSuccess(false); break; - case COMMUNICATE : - 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; - 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; - break; - case LIBRARY : - if(action.com_data.flag & READ){ - if(dude->com_data == NULL){ - action.com_data.flag = action.dir; - dude->com_data = malloc(sizeof(t_com)); - *(dude->com_data) = action.com_data; - memcpy(dude->com_data + sizeof(int), target.data + (action.com_data.flag | 3), 32); - }else{ - dude->success = 0; - break; - } - }else{ - memcpy(target.data + action.com_data.flag, action.com_data.data, 32); - } - dude->success = 1; - break; - default : - dude->success = 0; + case Pixel::LIBRARY: + if(action->com_data.flag & Com::READ) + { + if(dude->getCom().data == NULL) + { + action->com_data.flag = action->dir; + dude->receiveComData(action->com_data); + // TODO: understand what the fuck this line is doing + //memcpy(dude->getCom() + sizeof(int), target.data.knowledge + (action->com_data.flag | 3), COM_SIZE); + } + else + { + dude->setSuccess(false); break; + } + } + else{ + // TODO: understand what the fuck this line is doing bis + //memcpy(target.data.knowledge + action->com_data.flag, action->com_data.data, COM_SIZE); + dude->setSuccess(true); } break; + default: + dude->setSuccess(false); + break; + } } -}*/ +}