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);
/*
case WAIT :
dude->success = 1;
break; break;
case COMMUNICATE : case Action::COMMUNICATE:
switch(target.type){ switch(target.type){
// TODO : conflicts are not handled in a fair way case Pixel::DUDE:
case DUDE : action->com_data.flag = (action->dir+2)%4;
printf("message to dude\n"); // TODO : find a way to get targetDude
action.com_data.flag = (action.dir+2)%4; //targetDude =
target_dude = target.data; if(targetDude->getCom().data == NULL){
if(target_dude->com_data == NULL){ targetDude->receiveComData(action->com_data);
target_dude->com_data = malloc(sizeof(t_com)); dude->setSuccess(true);
*(target_dude->com_data) = action.com_data;
dude->success = 1;
}else }else
dude->success = 0; dude->setSuccess(false);
break; break;
case LIBRARY : case Pixel::LIBRARY:
if(action.com_data.flag & READ){ if(action->com_data.flag & Com::READ)
if(dude->com_data == NULL){ {
action.com_data.flag = action.dir; if(dude->getCom().data == NULL)
dude->com_data = malloc(sizeof(t_com)); {
*(dude->com_data) = action.com_data; action->com_data.flag = action->dir;
memcpy(dude->com_data + sizeof(int), target.data + (action.com_data.flag | 3), 32); dude->receiveComData(action->com_data);
}else{ // TODO: understand what the fuck this line is doing
dude->success = 0; //memcpy(dude->getCom() + sizeof(int), target.data.knowledge + (action->com_data.flag | 3), COM_SIZE);
}
else
{
dude->setSuccess(false);
break; break;
} }
}else{
memcpy(target.data + action.com_data.flag, action.com_data.data, 32);
} }
dude->success = 1; 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: default:
dude->success = 0; dude->setSuccess(false);
break; break;
} }
break;
} }
}*/ }