void ZRUser01(float *myState, float *otherState, float time) { //BEGIN::PROC::ZRUser // These are just some costants, don't pay to much attention to them :) #define WAIT_TIME 13 // Seconds to wait before starting spinning #define TIME_OPP_STAT 140 // Will only start considering about going // to a station after TIME_OPP_STAT seconds. #define ACCURACY_STAT 1.975f // Number between 1 and 2, the higher it is, // the more accurate in deciding whether the // opponent is headed towards the station. #define FUEL_STAT 25 // The minimum amount of fuel required to go // to a mining station (below this value, // the sphere's not going anywhere // msg : contains the messages received from the opponent // tt : contains a condition used a couple of times (space optimization) // out : contains the message we're sending our opponent unsigned short msg,tt,out=0; // avoid: is true or false whether the collision avoidance system is activated or not unsigned char avoid; // Don't worry about x and v ^^ float x[2]; float v[3]; // stat : these are some coordinates of stuff, like stations, asteroids and // a couple of corners of the playground float stat[6][3] = { {-0.5f,+0.31f,-0.55f}, {+0.5f,-0.31f,+0.55f}, {0,-0.35f,-0.2f}, {0,+0.35f,+0.2f}, {-0.5f,+0.65f,-0.55f}, {+0.5f,-0.65f,+0.55f}}; msg=PgetMessage(); avoid = PisAvoidingCollision(); tt=(tmp && tmp+WAIT_TIME<time); /* * y0b0tics protocol will be used only when * we're controlling the SPH # 1 */ if (!time) { if (myState[0]>0) { // SPH1 a=0.4; // a is the X coordinate of the nearest laser out=0x0400; // bit 11 sp=1; } else a=-0.4; } /* * If the opponent is willing to work * on Indigens, we're going to Indigens * as well, but we'll try to revolve. * Otherwise we keep sending our * opponent a "I'll revolve on Opulens" * message. */ if (time<60 && time) { if ((msg>3 && msg<6) || ast==1) { out=5; act=2; // Revolve ast=1; // Indigens } else { out=3; } } /* * If we're headed to a mining station, * we're telling our opponents which one * it is */ else if (act==4 && st<2) out=7-st; PsendMessage(out); /* * First of all, the Laser is taken * (btw, there's a "minor" bug in this * condition (&& time<60) is needed * (will add that as soon as some space * is available) */ if (!PhaveLaser()) { /* * If the opponent is trying to "steal" * our laser, we will get the other one */ if (avoid && myState[0]*a>0) a*=-1; /* v contains the * laser coordinates */ v[0]=a; v[1]=0; v[2]=0; ZRSetPositionTarget(v); } else { if (time>TIME_OPP_STAT && st<2) { /* * x[0] is given the value of the distance * between us and our opponent */ mathVecSubtract (v,myState,otherState,3); x[0]=mathVecMagnitude (v,3); /* * if our opponent is going to a station * we decide to go to the other one, but * only if we're able to arrive first */ if (checkTarget(otherState,0)>ACCURACY_STAT) { /* * Even if we're headed towards a station, * if our opponent is going to * the same station as us, we stop going * there and, instead, we move to the * closest corner of the playground, * so that, even if we don't gain anything, * at least we won't activate the collision * avoidance system */ if (!st && x[0]<0.65f) { st=4; } else if (st==-1) { /* * We go to the other station only if * we can reach it first */ if (getInTime(stat[0],otherState,stat[1],myState)) { st=1; act=4; } else st=-2; } } /* * Same stuff as before, but now * the other station is checked. */ else if (checkTarget(otherState,1)>ACCURACY_STAT) { if (st==1 && x[0]<0.65f) { st=5; } else if (st==-1) { if (getInTime(stat[1],otherState,stat[0],myState)) { st=0; act=4; } else st=-2; } } /* * although our opponent is not going to * a station, we leave the asteroid we're * working on to go to a station. * The time we're leaving the asteroid is * not fixed, but is calculated every time * in order to leave the asteroid as late as * possible */ else if (PgetPercentFuelRemaining()>FUEL_STAT && st==-1) { /* * x[0] contains the value of time * at which we have to leave the asteroid * to reach a station * 180-(time needed to reach a station) */ x[0]=timeStation(stat[0],myState); x[1]=timeStation(stat[1],myState); /* * It is then decided which station is * better, keeping in account that, if * we're spinning, our opponent could be * on our way to the station. */ if ((time>=x[0]) && (x[0]>x[1]) && !(act==3 && otherState[0]<0 && otherState[1]>0 && otherState[2]<0.2)) { act=4; st=0; } if ((x[0]<x[1]) && (time>=x[1]) && !(act==3 && otherState[0]>0 && otherState[1]<0 && otherState[2]>-0.2)) { act=4; st=1; } } } /* * act (action) contains a value * related to the action we're * doing. */ switch (act) { /* act = 1 -> melting ice on Opulens */ case 1: meltIce(myState,otherState,time); if (PiceMelted()) act=2; // if the ice is melted, we start revolving // on Opulens break; /* act = 2 -> revolve */ case 2: /* * if the opponent is revolving as * well, we keep revolving as well * for WAIT_TIME seconds. After that * seconds, if the opponent is * still revolving, we start spinning */ if (PisRevolving (otherState)==ast-1) { if (!tmp) tmp=time; if (tt && (checkTarget (otherState,ast)<1.9f) && st!=-2) { act=3; tmp=0; } } revolve(stat[ast],myState,otherState); break; /* act = 3 -> spinning */ case 3: /* * if the avoiding collision system * is working, it probably means that * our opponent wants to spin and he's * close to us so, after a few seconds, * we let him spin and we start revolving ^^ */ if (avoid) { if (!tmp) tmp=time; if (tt) { tmp=0; act=2; } } spin(stat[ast],myState); break; /* act = 4 -> going somewhere */ case 4: SetPosFaster(stat[st],myState); break; default: break; } if (tt) tmp=0; } //END::PROC::ZRUser }
static void revolve (float c[3], float mystate[12], float other[12]) { //BEGIN::PROC::revolve /* * Revolving function */ float v[4]; float q[4]; float a[4]; float a2[4]; float asse[3]; float d; float b; float b2; int dir=sp; if (PisRevolving (other)) { dir = revDir (other,c); if (!dir) dir=sp; } PgetAsteroidNormal(asse); v[3]=0; mathVecSubtract (v,c,mystate,3); d=mathVecMagnitude(v, 3); if(d >= 0.3f) { d=0.2355f/d; // (pi/2)*(0.3/distance) } else { d= 1.57f - 2.615f*d; // pi - (pi/2)*(distance/0.25) } // This creates the quaternion // (yeah, a quaternion, that's cool right?) b=d-1.57f; b2=b*b*b; q[3]=(-b + b2/6 - b2*b*b/120); b2=d*d*d; mathVecMul (q,asse,dir*(d - b2/6 + b2*d*d/120)); // v[] is rotated according to the quaternion funz(a2,q,v); mathVecMul(q,q,-1); funz(a,a2,q); //then it's normalized and converted in velocity mathVecNormalize(a, 3); mathVecMul(a,a,0.0232f); ZRSetVelocityTarget(a); q[3]=1; mathVecMul(q,asse,-dir*0.043619f); funz(a2,q,v); mathVecMul(q,q,-1); funz(a,a2,q); ZRSetAttitudeTarget(a); //END::PROC::revolve }
float distance(float a[3], float b[3]) { //finds distance between two objects float diff[3]; mathVecSubtract(diff,a,b,3); return mathVecMagnitude(diff,3); }
void loop(){ api.getMyZRState(self); //get my own location and save to self api.getOtherZRState(other); //get opponent's location and save to other if (counter < 2) { itemNum = 0; otherNum = 1; if(self[0]<0){ itemNum=1; otherNum=0; } } stayInBounds(); if(step==acquireLaser){ //fist step stayInBounds(); if(game.haveItem(1, itemNum)||counter==68){ if(otherNum!=itemNum){ atarget[0]=-atarget[0]; otherNum=1-otherNum; } else{ step = GravityPull; } } if(counter > 28 && !game.isNetBroken()) { if(otherNum!=itemNum){ atarget[0]=-atarget[0]; otherNum=1-otherNum; } else if (!game.haveItem(1, otherNum)) { if(otherNum!=itemNum){ atarget[0]=-atarget[0]; otherNum=1-otherNum; } } else{ step = GravityPull; } } debrisOnPath=CheckPath(atarget); //check if any debris is on way to laser pack if(debrisOnPath > -1){ //if so if(distance(self, debrisArr[debrisOnPath])< 0.32f){ //slow down as you approach the debris mathVecSubtract(down, self, debrisArr[debrisOnPath], 3); down[1]=0; mathVecNormalize(down, 3); down[0]*=3; down[2]*=3; api.setVelocityTarget (down); } else{ goFast(atarget, 0.07f); } } else{ //if no debris on path, go straight to laser api.setPositionTarget(atarget); arbState[0] = self[3]; arbState[1] = self[4]; arbState[2] = self[5]; //DEBUG(("%f",mathVecMagnitude(arbState, 3))); if(distance(self, atarget)< 0.05f && mathVecMagnitude(arbState, 3) < 0.01f){ //if close enough to laser pack step=spin; } } } else if(step == spin){ aimToPickUpLaser[0]=0.0f; aimToPickUpLaser[1]=0.0f; aimToPickUpLaser[2]=0.3f; api.setAttRateTarget(aimToPickUpLaser); //spin robot to pick up laser pack api.setPositionTarget(atarget); //mantain position on top of laser pack if(game.haveItem(0, otherNum)){ //go to next step if laser pack is acquired if(other[1] > 0.3f) { step=smasherBot; } else { step = moveToShootPos; } atarget[0]=-0.05f;//-0.35;//0.1;//0.30;//0.33; atarget[1]=0.6f;//0.15;//0.3;//0.44;//0.29; atarget[2]=0.1f;//0.1;//0;//-0.2;//-0.31;//-0.48; if(itemNum==1){ atarget[2]=-atarget[2]; } down[0] = 0.0f; down[1] = 0.0f; down[2] = 0.0f; } } else if(step==moveToShootPos){ // if second step game.getCometState(0, arbState); //DEBUG(("%f, %f, %f", arbState[0], arbState[1], arbState[2])); mathVecSubtract(aimVector,arbState,self,3); //find vector between self and the starting position of the comet atarget[0] = arbState[0] - 0.35f; if(itemNum == 1){ atarget[0] = arbState[0] + 0.35f; } debrisOnPath=CheckPath(atarget); //check for any debris on path to Shooting location if(debrisOnPath > -1){ //if there is, get it if(distance(self, debrisArr[debrisOnPath])< 0.3f){ //slow down as you approach the debris mathVecSubtract(down, self, debrisArr[debrisOnPath], 3); down[0]=0.0f; down[1]=0.0f; mathVecNormalize(down, 3); api.setForces(down); } else{ api.setPositionTarget(atarget); } } else{ //if there isn't, go straight to shooting Location api.setPositionTarget(atarget); } api.setAttitudeTarget(aimVector); //constantly be adjusting attitude to face starting position of comet if(counter>87){ down[0] = 0.015f; down[1] = -0.026f;//23; down[2] = 0.005f; if(itemNum == 1){ down[0] *= -1; down[2] *= -1; } api.setVelocityTarget(down); } if(counter==90){ //wait for phase two to begin and go onto next step step=shootLaser; } } if(step==shootLaser){ //phase two: shooting lasers game.getCometState(0, arbState); //get position of comet //game.predictCometState(3, arbState, finState); //predict position of comet in three seconds (gives more sooting accuracy) mathVecSubtract(aimVector,arbState,self,3); //find vector between self and comet's [predicted] position if(counter>92){ down[0] = 0.015f; down[1] = -0.025f;//23; down[2] = 0.01f; if(itemNum == 1){ down[0] *= -1; down[2] *= -1; } api.setVelocityTarget(down); } api.setAttitudeTarget(aimVector); //constantly adjust attitude to aim at the comet if(isInShot()){ hit = game.shootLaser(); //shoot laser if(hit){ //print whether shot was successful DEBUG (("Hit on B5")); //joke referencing the game Battlefield } else{ //print if shot missed DEBUG (("MISS")); } } //api.setPositionTarget(shootPos); if(game.laserShotsRemaining()==0){ //once out of laser shots, go onto next step step=smasherBot; } } if(step==smasherBot){ // once finished shooting comets, play SmasherBot stayInBounds(); goFast(other, 0.09); if(counter>64&&counter<90){ stayInBounds(); step = moveToShootPos; } } /* if(step == antiSmasherBot){ findClosestDebris(); if(game.haveDebris(0,x)){ DEBUG(("Gotcha")); debCounter++; } x=closestDebris; DEBUG((" x is: %d", closestDebris)); goFast(debrisArr[x],0.06); game.getCometState(0, arbState); gravityStartPos[0] = arbState[0] + 0.15; gravityStartPos[2] = arbState[2] - 0.05; if(itemNum == 1){ gravityStartPos[0] = arbState[0] - 0.15; gravityStartPos[2] = arbState[2] + 0.05; } if(debCounter==2 || counter>64){ step=GravityPull; } } */ if(step == GravityPull){ if(counter<91){ gravityStartPos[0] = 0.45;//arbState[0] + 0.15f; gravityStartPos[2] = arbState[2] - 0.05f; if(itemNum == 1){ gravityStartPos[0] = -0.45;//arbState[0] - 0.15f; gravityStartPos[2] = arbState[2] + 0.05f; } debrisOnPath=CheckPath(gravityStartPos); //check if any debris is on way to laser pack if(debrisOnPath > -1){ //if so if(distance(self, debrisArr[debrisOnPath])< 0.3f){ //slow down as you approach the debris mathVecSubtract(down, self, debrisArr[debrisOnPath], 3); down[1]=0; mathVecNormalize(down, 3); api.setForces(down); } else{ goFast(gravityStartPos, 0.06f); } } else{ //if no debris on path, go straight to laser goFast(gravityStartPos, 0.06f); } } else{ game.getCometState(0, arbState); //get position of comet //game.predictCometState(3, arbState, finState); atarget[0] = arbState[0] + 0.2f; if(self[0]<0){ atarget[0] = arbState[0] - 0.2f; } atarget[1] = arbState[1] - 0.1f; atarget[2] = arbState[2]; goFast(atarget, 0.09f); } } counter++; }
/* Checks if we are at target * Returns true if distance < 0.05 and velocity < 0.01 */ bool areWeThereYet(float target[], float me[]) { memcpy(temp, me + 3, 3 * sizeof(float)); return (distance(target, me) < 0.05 && mathVecMagnitude(temp, 3) < 0.01); }
bool areWeThereYet(float target[], float me[]) { float velocity[3]; memcpy(velocity, me + 3, 3 * sizeof(float)); return (distance(target, me) < 0.05 && mathVecMagnitude(velocity, 3) < 0.05); }
//movement_moveto //dst -> Destiny //direct -> If true does not uses debris avoidance //return -> true if we have arrived, false otherwise bool movement_moveto(float dst[3], bool direct) { float delta[3]; float head[3]; mathVecSubtract(delta, dst, &our_state[POS], 3); //delta = dst - pos mathVecScalarMult(head, delta, 1.0f/mathVecMagnitude(delta, 3), 3); //head = delta / |delta| if(mathVecMagnitude(delta, 3) < MAX_ITEM_START_DIST && mathVecMagnitude(&our_state[VEL], 3) < MAX_ITEM_START_VEL) { return true; } else { //delta = zero delta[0] = delta[1] = delta[2] = 0.0f; api.setAttRateTarget(delta); } //delta = head_vel mathVecScalarMult(delta, head, mathVecInner(head, &our_state[VEL], 3), 3); float head_speed = mathVecMagnitude(delta, 3); float side_vel[3]; mathVecSubtract(side_vel, &our_state[VEL], delta, 3); const float danger_radius = (SPHERE_RADIUS + DEBRIS_RADIUS) + 0.03f; const float correction = danger_radius + 0.02f; if(direct || seconds >= 90) { api.setPositionTarget(dst); return false; } int debris_number; float debris_vector[5]; int nearest_debris = -1; float nearest_debris_distance = 1000000.0f; float nearest_debris_vector[5]; for(debris_number = 0; debris_number < NUMBER_OF_DEBRIS; debris_number++) { if(!is_debris_collected[debris_number]) { distanceToDebris(&our_state[POS], dst, debris_position[debris_number], debris_vector); if((debris_vector[SIDE_DIST] - (danger_radius + ((mathVecInner(side_vel, debris_vector, 3)/head_speed)*debris_vector[3]))) < 0.0f) { //Colisión if(debris_vector[HEAD_DIST] < nearest_debris_distance && debris_vector[HEAD_DIST] > 0.0f) { nearest_debris = debris_number; int i; for(i = 0; i < 5; ++i) { nearest_debris_vector[i] = debris_vector[i]; } nearest_debris_distance = debris_vector[3]; } } } } api.setPositionTarget(dst); if(nearest_debris >= 0) { //Si nearest_debris es un debris válido //delta = tmp float needed_speed_up = correction - (nearest_debris_vector[SIDE_DIST] + ((mathVecInner(side_vel, nearest_debris_vector, 3)/head_speed)*nearest_debris_vector[3])); mathVecScalarMult(delta, nearest_debris_vector, needed_speed_up, 3); api.setForces(delta); } #ifdef DEBUG_ACTIVE else { movement_last_debris = -1.0f; nearest_debris_distance = 0.0f; DEBUG(("movement:Clear!\n")); } #endif return false; }
float disBetweenPts (vec pt1, vec pt2) { mathVecSubtract(utilVec1, pt2, pt1, 3); return mathVecMagnitude(utilVec1, 3); }
float angleBetween(float a[], float b[]) { //returns the measure of the angle between vectors a and b return acosf(mathVecInner(a, b, 3) / (mathVecMagnitude(a,3) * mathVecMagnitude(b,3))); }
void loop() { api.getMyZRState(me); if(api.getTime() % 60 == 0 && state != 3) { state = 0; for (int i = 0; i < 3; i++) oldPOIIDs[i] = false; } rebootIfStorm(); DEBUG(("I am in state %d.\n", state)); DEBUG(("I can still take %d photos.\n", game.getMemorySize() - game.getMemoryFilled())); if (state == 0) {// POI Selection game.getPOILoc(POI,0); game.getPOILoc(otherPOI1,1); game.getPOILoc(otherPOI2,2); if (!oldPOIIDs[0] || !oldPOIIDs[1] || !oldPOIIDs[2]) { //if you haven't already been to all the POIs if (oldPOIIDs[0]) for (int i = 0; i < 3; i++) POI[i] = 1000; if (oldPOIIDs[1]) for (int i = 0; i < 3; i++) otherPOI1[i] = 1000; if (oldPOIIDs[2]) for (int i = 0; i < 3; i++) otherPOI2[i] = 1000; //make sure you don't go to a previously-visited POI } if (distance(me,otherPOI1) <= distance(me,POI)) { if (distance(me,otherPOI2) <= distance(me,otherPOI1)){ POIID = 2; for (int i = 0; i < 3; i++) POI[i] = otherPOI2[i]; } else { POIID = 1; for (int i = 0; i < 3; i++) POI[i] = otherPOI1[i]; } } else if (distance(me,otherPOI2) <= distance(me,POI)) { POIID = 2; for (int i = 0; i < 3; i++) POI[i] = otherPOI2[i]; } else POIID = 0; DEBUG(("POI Coors = %f,%f,%f\n",POI[0],POI[1],POI[2])); state = 1; } if (state == 1) {// Take pic in outer zone mathVecSubtract(facing,POI,me,3); if (mathVecMagnitude(me,3) > 0.42 && mathVecMagnitude(me,3) < 0.53 && angleBetween(me, facing) > 2.94159265359) { // in the outer zone and angle between me and POI is less than 0.2 picNum = game.getMemoryFilled(); game.takePic(POIID); if (game.getMemoryFilled() - picNum == 1) { DEBUG(("I just took a picture in the outer zone.\n")); if (solarFlareBegin - api.getTime() > 13) state = 2; else state = 3; } } else { for (int i = 0; i < 3; i++) { destination[i] = POI[i] * 0.43 / mathVecMagnitude(POI, 3); } if (mathVecMagnitude(facing,3) > 0.5) setPositionTarget(destination, 2); else setPositionTarget(destination); } mathVecNormalize(facing,3); api.setAttitudeTarget(facing); } if (state == 2) {// Take pic in inner zone mathVecSubtract(facing,POI,me,3); if (mathVecMagnitude(me,3) < 0.42 && angleBetween(me, facing) > 2.74159265359) { //in the inner zone and angle between me and POI is less than 0.4 picNum = game.getMemoryFilled(); game.takePic(POIID); if (game.getMemoryFilled() - picNum == 1) { DEBUG(("I just took a picture in the inner zone.\n")); state = 3; } } else { for (int i = 0; i < 3; i++) { destination[i] = POI[i] * 0.33 / mathVecMagnitude(POI, 3); } if (mathVecMagnitude(facing,3) > 0.5) setPositionTarget(destination, 2); else setPositionTarget(destination); } mathVecNormalize(facing,3); api.setAttitudeTarget(facing); } if (state == 3) {// Upload the picture if (mathVecMagnitude(me,3) > 0.53) { picNum = game.getMemoryFilled(); game.uploadPic(); DEBUG(("I just uploaded %d picture(s).\n", (picNum - game.getMemoryFilled()))); state = 0; oldPOIIDs[POIID] = true; } else { for (int i = 0; i < 3; i++) { destination[i] = me[i] * 0.61 / mathVecMagnitude(me,3); } if (solarFlareBegin - api.getTime() < 8) setPositionTarget(destination, 4); else if (mathVecMagnitude(me,3) < 0.5) setPositionTarget(destination, 2); else setPositionTarget(destination); } } }
void loop(){ api.getMyZRState(zrstate); if (api.getTime()%60 < 1 && api.getTime() > 20) { target[0] = 3*POI[0]; target[1] = 3*POI[1]; target[2] = 3*POI[2]; POIS[0] = 1; POIS[1] = 1; POIS[2] = 1; state = 2; } if (state == 0) { if (canTakePic(POI,zrstate,0.8,0.42,0.31,ID)) { game.takePic(ID); if (game.getNextFlare() < 17 && game.getNextFlare() > -1) { target[0] = 4*POI[0]; target[1] = 4*POI[1]; target[2] = 4*POI[2]; state = 2; } else { target[0] = 2.5*POI[0]; target[1] = 2.5*POI[1]; target[2] = 2.5*POI[2]; state = 1; } } else { moveTo(target); api.setAttitudeTarget(angle); } } if (state == 1) { if (canTakePic(POI,zrstate,0.4,0.53,0.42,ID)) { game.takePic(ID); POIS[ID] = 0; target[0] = 3*POI[0]; target[1] = 3*POI[1]; target[2] = 3*POI[2]; state = 2; } else { moveTo(target); api.setAttitudeTarget(angle); } } if (state == 2) { if (mathVecMagnitude(zrstate,3) > 0.53) { game.uploadPic(); target[0] = 2.9*POI[0]; target[1] = 2.9*POI[1]; target[2] = 2.9*POI[2]; state = 3; } moveTo(target); } if (state == 3) { game.takePic(ID); if (api.getTime()%60 < 40) { ID = getClosestPOI(POI,POI0,POI1,POI2, POIS, zrstate); getPOI(POI,ID); float tmp[3]; mathVecSubtract(tmp,zrstate,POI,3); if (mathVecMagnitude(tmp,3) <= 0.65) { target[0] = 1.8*POI[0]; target[1] = 1.8*POI[1]; target[2] = 1.8*POI[2]; state = 0; api.setAttitudeTarget(angle); } } api.setPositionTarget(target); if (game.getNextFlare() == 2) { game.turnOff(); game.turnOn(); } } }
void loop(){ api.getMyZRState(me); game.getItemLoc(target, 0); state = getState(target, me); switch (state) { case SPS: switch (game.getNumSPSHeld()) { case 3: game.dropSPS(); origin[0] = 0.5f; origin[1] = 0.0f; origin[2] = 0.0f; break; case 2: api.setPositionTarget(origin); if (distance(origin, me) <= .05) { game.dropSPS(); origin[0] = 0.0f; origin[1] = 0.68f; origin[2] = 0.0f; } break; case 1: api.setPositionTarget(origin); if (distance(origin, me) <= .05) game.dropSPS(); break; } break; case GET_ITEM: //Find vector between bot and item mathVecSubtract(holder, target, me, 3); //magnitude of previous vector mag = mathVecMagnitude(holder, 3); //Face towards the item api.setAttitudeTarget(holder); //DEBUG(("Dist: %f", distance(target, me))); DEBUG(("Dist: %f", mag)); //Scale down the vector so the endpoint is .170 units away from the item //scaleVect(holder, mag, 0.170f); //adjustGoal(holder, 0.170f); adjustGoal(target, 0.170f); //If in proximity /*if (mag <= .17 && mag >= .15) { DEBUG(("Stay")); api.setPositionTarget(me); game.dockItem(); }*/ if (distance(target, me) <= .17 && distance(target, me) >= .15) { DEBUG(("Stay")); DEBUG(("Close: %f", mag)); api.setPositionTarget(me); game.dockItem(); } //else if (mag <= .2 && mag > .17) { //api.setPositionTarget(target); //} else { //Full speed ahead //api.setVelocityTarget(holder); moveTo(holder); } break; case STAY: DEBUG(("Staying")); api.setPositionTarget(me); break; case FIND_ASSEMBLY: DEBUG(("Find Assembly")); //if (isFound) { if (game.getZone(myZone)) { DEBUG(("%f, %f, %f, %f", myZone[0], myZone[1], myZone[2], myZone[3])); } mathVecSubtract(holder, me, myZone, 3); //isFound = false; //} //move to and point to the estimated zone api.setPositionTarget(myZone); scaleVect(holder, 1.0f, -1.0f); api.setAttitudeTarget(holder); if (mathVecMagnitude(holder, 3) <= .17) { DEBUG(("Gottem")); api.setPositionTarget(me); game.dropItem(); } break; case GET_CENTER: break; } }
float distance(float target[3], float pos[3]) { float temp[3]; mathVecSubtract(temp, target, pos, 3); return mathVecMagnitude(temp, 3); }
void ZRUser01(float *myState, float *otherState, float time) { //BEGIN::PROC::ZRUser float opulens[3] = {0.0, -0.6, 0.0}; float Laser[3] = {0.4, 0.0, 0.0}; float shield[3] = {0.0, 0.4, 0.0}; float zero[3] = {0.0, 0.0, 0.0}; float difference[3]; float Asteroid[3] = {0.0, -0.6, 0.0}; float Station[3] = {0.0, 0.0, 0.0}; switch((int)time) { case 0: SphereNumber = !!(myState[0] < 0) + 1; break; case 30: getShield = (otherState[1] <= 0); break; case 61: asteroid = (PinAsteroid(otherState) == 1) ? 1 : 0; break; case 90: asteroid = (PisRevolving(otherState) == 2 && !asteroid) ? 1 : asteroid; break; } Station[0] = (SphereNumber == 1) ? 0.6 : -0.6; //station closer to where you started Asteroid[1] = asteroid ? -0.6 : 0.6; Laser[0] = ((SphereNumber == 1) - (PotherHasLaser() == SphereNumber)) ? 0.4 : -0.4; switch(state) { case 0: ZRSetPositionTarget(Laser); shoot(myState, opulens, 0); if(PhaveLaser() || PgetPhase() == 2) state = 1; break; case 1: if(!getShield) shield[1] = .3; ZRSetPositionTarget(shield); shoot(myState, opulens, 0); if(PotherHasShield() || PhaveShield() || PgetPhase() == 2) state = 2; break; case 2: if(PiceHits() < 14 && !asteroid) shoot(myState, opulens, (PgetPhase() > 1)); if(!(PiceMelted()) && asteroid) { mathVecSubtract(difference, myState, opulens, 3); if(mathVecMagnitude(difference, 3) > .8) ZRSetPositionTarget(opulens); else ZRSetVelocityTarget(zero); shoot(myState, opulens, (PgetPhase() > 1)); return; } orbit(myState, Asteroid, Station[0] == -0.6); if(time + timeToMS(myState, Station) >= 165) state = 3; break; default: ZRSetPositionTarget(Station); break; } //END::PROC::ZRUser }
bool checkUpload( float me[] ){ if( ( me[8] > 0.9689f ) && (mathVecMagnitude(me+9,3) < 0.05f) ) return true; return false; }
float angBetweenVecs (vec v1, vec v2) { return acosf(mathVecInner(v1, v2, 3) / (mathVecMagnitude(v1, 3) * mathVecMagnitude(v2, 3))); }
float distance(float p1[], float p2[]){ // Thanks Cornel float diff[3]; mathVecSubtract(diff,p1,p2,3); return mathVecMagnitude(diff,3); }
bool hitTarget(ZRState satState, vec targetPos) { return (mathVecMagnitude(stateVel(satState), 3) < 0.0095f && disBetweenPts(statePos(satState), targetPos) < stillDis); }
void loop(){ api.getMyZRState(zrstate); if (api.getTime()%60 == 2 && api.getTime() > 60) { target[0] = -0.6; target[1] = 0; target[2] = 0; state = 2; } if (state == 0) { if (canTakePic(POI,zrstate,0.8,0.42,0.31,ID)) { game.takePic(ID); target[0] = 2.5*POI[0]; target[1] = 2.5*POI[1]; target[2] = 2.5*POI[2]; state = 1; } else { api.setPositionTarget(target); api.setAttitudeTarget(angle); } } if (state == 1) { if (canTakePic(POI,zrstate,0.4,0.53,0.42,ID)) { game.takePic(ID); target[0] = -0.6; target[1] = 0; target[2] = 0; state = 2; } else { api.setPositionTarget(target); api.setAttitudeTarget(angle); } } if (state == 2) { if (mathVecMagnitude(zrstate,3) > 0.53) { game.uploadPic(); state = 3; } api.setPositionTarget(target); } if (state == 3) { game.takePic(ID); if (api.getTime()%60 < 30) { getPOI(); target[0] = 1.8*POI[0]; target[1] = 1.8*POI[1]; target[2] = 1.8*POI[2]; state = 0; api.setAttitudeTarget(angle); } api.setPositionTarget(target); if (game.getNextFlare() == 2) { game.turnOff(); game.turnOn(); } } }
/* Simple distance function, returns distance between p1 and p2 */ float distance(float p1[], float p2[]) { mathVecSubtract(temp, p1, p2, 3); return mathVecMagnitude(temp, 3); }
bool hitTarget(ZRState satState, vec targetPos) { return (mathVecMagnitude(satState + 3, 3) < stillVel && disBetweenPts(satState, targetPos) < stillDis); }