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 disrupt[3] = {0.0,0.2,0.0}; float zero[3] = {0.0, 0.0, 0.0}; float difference[3]; float facing[3]; float Asteroid[3] = {0.0, -0.6, 0.0}; int recieved; switch((int)time) { case 0: SphereNumber = !!(myState[0] < 0) + 1; Station[0] = (SphereNumber == 1) ? 0.6 : -0.6; //station closer to where you started break; case 30: getUp = (otherState[1] <= 0); break; case 61: case 66: Spin = PisRevolving(otherState) ? 1 : 0; break; case 75: if(PinAsteroid(otherState) == 1) asteroid = 1; } Laser[0] = ((SphereNumber == 1) - (PotherHasLaser() == SphereNumber)) ? 0.4 : -0.4; recieved = (int)PgetMessage(); switch(recieved) { case 6: if(!(Station[0] < 0.0) && switchedStation++ < 3) Station[0] = -0.6; break; case 7: if(!(Station[0] > 0.0) && switchedStation++ < 3) Station[0] = 0.6; break; case 2: case 3: if(time < 45) asteroid = 1; break; case 4: case 5: if(time < 45) asteroid = 0; break; } if(time <= 120) PsendMessage(4 - 2*asteroid + (Spin == 0)); else PsendMessage((Station[0] < 0) + 6); Asteroid[1] = asteroid ? -0.6 : 0.6; switch(state) { case 0: ZRSetPositionTarget(Laser); shoot(myState, opulens, 0); if(PhaveLaser() || PgetPhase() == 2) state = 1; break; case 1: if(!getUp) { shield[1] = .3; disrupt[1] = .3; } ZRSetPositionTarget(disrupt); shoot(myState, opulens, 0); if(PotherDisruptorUpgraded() || PdisruptorUpgraded()) state = 2; if(PgetPhase() == 2) state = 3; break; case 2: ZRSetPositionTarget(shield); shoot(myState, opulens, 0); if(PotherHasShield() || PhaveShield() || PgetPhase() == 2) state = 3; break; case 3: if(PiceHits() < 15 && !asteroid) shoot(myState, opulens, (PgetPhase() > 1)); if(!(PiceMelted()) && asteroid) { mathVecSubtract(difference, myState, opulens, 3); if(mathVecMagnitude(difference, 3) > .8) ZRSetPositionTarget(opulens); else if(!Spin) ZRSetVelocityTarget(zero); shoot(myState, opulens, (PgetPhase() > 1)); return; } if(Spin){ ZRSetPositionTarget(Asteroid); spin(myState); } else orbit(myState, Asteroid, Station[0] == -0.6); if((!Spin && (time + timeToMS(myState, Station) >= 165)) || (Spin && (time >= 156))) state = 4; break; default: leaveOrbit(myState, Asteroid, Station); mathVecSubtract(facing, otherState, myState, 3); mathVecNormalize(facing, 3); ZRSetAttitudeTarget(facing); if (acos(mathVecInner(&myState[6], facing, 3) / mathVecMagnitude(&myState[6], 3)) < (0.1)) Ptractor(); break; } //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 }
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 }
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 }