void Grader::catchObj(Obj obj)
{float dist,ang;
do
{
execute
{
if(exist(obj)&&obj->_free)
{
cartToPol(dist,ang,obj->getX()-getX(),obj->getY()-getY());
if(dist<=_step)
{
_obj=obj;
_obj->_free=false;
Ghost ghost = new Ghost(_obj,_ground);
ghost->setLocation(_obj->getX(),_obj->getY(),0);
ghost->attachTo(_ground);
_obj->location=location;
_obj->attachTo(this);
_obj->_ghost=ghost;
_monAutomat->_m1->_memory=1;
if(_sonde)
{
_god->_output2->writeString(format("\t","P"));
print("P");
_god->_output2->writeString(format("\t","(",
_monAutomat->_m1->_memory,_monAutomat->_m2->_memory,")","\n"));
print("(",_monAutomat->_m1->_memory,_monAutomat->_m2->_memory,")");
}
return;
}
}
else return;
}
setTheta(ang);
yield();
} while(true);
}
void Grader::dropObjNear(Obj obj)
{
float dist,ang;
do
{
execute
{
if(exist(obj)&&obj->_free)
{
cartToPol(dist,ang,obj->getX()-getX(),obj->getY()-getY());
if(dist<=_step/2)
{
_obj->setLocation(obj->getX(),obj->getY(),obj->getTheta());
_obj->attachTo(_ground);
_obj->_free=true;
delete(_obj->_ghost);
_obj->_ghost=(Ghost)NONE;
_obj=(Obj)NONE;
_monAutomat->_m1->_memory=0;
if(_sonde)
{
_god->_output2->writeString(format("\t","O"));
print("O");
_god->_output2->writeString(format("\t","(",
_monAutomat->_m1->_memory,_monAutomat->_m2->_memory,")","\n"));
print("(",_monAutomat->_m1->_memory,_monAutomat->_m2->_memory,")");
}
return;
}
}
else return;}
setTheta(ang);
yield();
} while(true);
}
void Grader::main(void)
{
while(!_obj) catchObj(lookForObj("Obj"));
while(_obj) dropObjNear(lookForObj(_obj->className()));
}