void ZRUser(float myState[12], float otherState[12], float time) {
    if (time < 150) {
        //TODO: move to center of panel initialization circle, instead of
        //assuming that position from the start
        float attitude[3] = {0, 1, 0};
        ZRSetAttitudeTarget(attitude);
        //TODO: rotate around the circle to find the panel; in this case,
        //panel angle is 0 so we automatically see it after the attitude change
        if (isPanelFound() && time > 20) {
            float velocity[3] = {0, 0.01, 0};
            ZRSetVelocityTarget(velocity);
        }
        if (iHavePanel() && time > 70 && time < 75) {
            float stop[3] = {0, 0, 0};
            ZRSetVelocityTarget(stop);
        }
        if (iHavePanel() && time > 75 && time < 150) {
            float station[3] = {-.7, 0, 0};
            ZRSetPositionTarget(station);
        }
    }
    if (iHavePanel() && time == 150) {
        float searchStation[3] = {0, 0.1, 0};
        ZRSetTorques(searchStation);
    }
    if (isStationInSync() && time > 150) {
        float stop[3] = {0, 0, 0};
        float velocity[3] = {0, 0, .01};
        ZRSetTorques(stop);
        ZRSetVelocityTarget(velocity);
    }
}
static void leaveOrbit (float myState[12], float asteroidLoc[3], float mPanel[3])
{
//BEGIN::PROC::leaveOrbit
#define SinAngle(a, b) sqrt(1 - mathSquare(mathVecInner((a), (b), 3)/(mathVecMagnitude((a), 3) * mathVecMagnitude((b), 3)))) 

float targetVel[3];
float r, toMS;
float desiredMag;
float vecToAst[3];
float vecToMS[3];
int i;

for(i = 0; i < 3; i++){
    vecToAst[i] = asteroidLoc[i] - myState[i];
    vecToMS[i] = mPanel[i] - myState[i];
}
toMS = mathVecMagnitude(vecToMS, 3);

r = sqrt(mathVecInner(vecToAst, vecToAst, 3));

for(i = 0; i < 3; i++)
targetVel[i] = mPanel[i] - myState[i];

if(toMS < .19){
    if(mathVecMagnitude(&myState[3], 3) > 0.01)
        desiredMag = 0.002;
    else
        desiredMag = 0.01;
}
else if(toMS < 0.25)
    desiredMag = toMS/12;
else if(toMS < 0.35)
    desiredMag = toMS/7;
else
    desiredMag = r*3.141592/(45*SinAngle(vecToAst, &myState[3]));
    
if(desiredMag > toMS/6)
    desiredMag = toMS/6;

mathVecNormalize(targetVel, 3);

for(i = 0; i < 3; i++)
    targetVel[i] *= desiredMag;
ZRSetVelocityTarget(targetVel);
//ZRSetAttitudeTarget(att);
//END::PROC::leaveOrbit
}
void CollideFromPoint(float * mState, float * oState, float * fromPoint, float velMag) {

if (stage == 0) {
ZRSetPositionTarget(fromPoint);
if (Vfunc(6, mState, fromPoint, NULL, 0) < 0.09) {
stage = 1;
}
}

if (stage == 1) {

Vfunc(9, fromPoint, oState, dir, 0);
Vfunc(4, dir, NULL, dir, velMag);
ZRSetVelocityTarget(dir);
}

}
static void CoastToTarget(float* myPos, float* coastTarget, float magnitude)
{
 float temp[3];
 if (magnitude > 0.04) magnitude = 0.04;
 Vfunc(2, (coastTarget), (myPos), (temp), 0);
 if (mathVecMagnitude((temp), 3) < (mathSquare(mathVecMagnitude((&myPos[3]), 3)) * 50.0 + 0.08))
 {
  ZRSetPositionTarget(coastTarget);
 }
 else
 {
  mathVecNormalize((temp), 3);
  Vfunc(4, (temp), NULL, (temp), (magnitude));
  if (Vfunc(6, (temp), (&myPos[3]), NULL, 0) > 0.02)
   ZRSetVelocityTarget(temp);
 }
}
Example #5
0
void CoastToTarget(float* myPos, float* coastTarget)
{
 float temp[3];

 VSub(coastTarget, myPos, temp);

 if (VLen(temp) < CLOSE)
 {
  SET_POSITION_TARGET(coastTarget);
 }
 else
 {
  VUnit(temp, temp);
  VMult(temp, MAGNITUDE, temp);

  ZRSetVelocityTarget(temp);
 }
}
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
}
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
}
Example #8
0
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
}
//User01: blakeelias Team: Stuy-Naught Project: Kill-Retreat
void ZRUser01(float *myState, float *otherState, float time)
{
#define position procvar
#define attitude (procvar+3)
#define panel_location (procvar+6)
   
memcpy(vOtherPrev, vOther, sizeof(float)*3); //original value copied to previous value
   
memcpy(vOther, otherState+3, sizeof(float)*3); // this is set to the current value
 
// Wait for them to run out of fuel (constant velocity)
if ((Vfunc(6, vOther, vOtherPrev, NULL, 0)) <= 0.01)
    counter++;
else
    counter = 0;
   
DEBUG(("time: %3.0f, SPH%d: state %i\n", time, getPanelSide() == 1 ? 1 : 2, state));
 
if (state == 1) { //Zapping
    // Get between the opponent and the sun
    memcpy(position, otherState, sizeof(float)*3);
    mathVecNormalize(position, 3);
    Vfunc(4, position, NULL, position, 0.1);
  
    CoastToTarget(myState, position, 0.04);
      
    // Face the opponent
    Vfunc(9, myState, otherState, attitude, 0);
    ZRSetAttitudeTarget(attitude);
      
    // Zap once we see them
    if (fabs (Vfunc(8, myState+6, attitude, NULL, 0)) < 6.0) {
        ZRRepel();
        }
     
           
    //DEBUG(("Counter = %i \n", counter));
 
 
    if(iHavePanel()) {
        if (counter >= 15 || getPercentFuelRemaining() < 10)
            state = 6;
    }
    else {
        if (counter >= 15 || time > 100)
            state = 2;
        else if (getPercentFuelRemaining() < 20)
            state = 3;
    }
}
   
if (state == 2) { //Moving to panel circle, they're dead
    if (isPanelFound())
        state = 5;
    else {
        attitude[0] = 0;
        attitude[1] = 1*getPanelSide();
        attitude[2] = 0;
    
        position[0] = .7*getPanelSide();
        position[1] = 0;
        position[2] = 0;
    
        CoastToTarget(myState, position, 0.04);
        ZRSetAttitudeTarget(attitude);
            
        if (Vfunc(6, myState, position, NULL, 0) < 0.03)
            state = 4;
    }
}
  
if (state == 3) { // Retreating to panel, they are alive
    if (isPanelFound())
        state = 5;
    else {
        position[0] = .7*getPanelSide();
        position[1] = 0;
        position[2] = 0;
        CoastToTarget(myState, position, 0.04);
    }
  
    if (Vfunc(6, position, myState, NULL, 0) < 0.03)
        state = 4;
}
  
if (state == 4) { //Finding panel
    RotateTarget(myState, position);
        if (isPanelFound())
            state = 5;
        if (iHavePanel())
            state = 6;
    }
           
if (state == 5) { //Get the panel
        getPanelState(position);
        attitude[0] = 0.7*getPanelSide();
        attitude[1] = attitude[2] = 0;
        Vfunc(9, attitude, position, attitude, 0);
        ZRSetAttitudeTarget(attitude);
        CoastToTarget(myState, position, 0.04);
        if (iHavePanel())
            state++;
        }
   
if (state == 6) { //Stop
    if (counter < 15)
        state = 1;
    position[0] = position[1] = position[2] = 0;
    ZRSetVelocityTarget(position);
        }
}