finished conversion of handleAction, left some TODOs

This commit is contained in:
Lendemor 2016-05-19 20:09:06 +02:00
parent 3fbb83932b
commit 88d43e9f74

View File

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