Code:
kbCanMapKey[NUMPAD0] = FALSE;
kbCanMapKey[NUMPAD1] = FALSE;
kbCanMapKey[NUMPAD2] = FALSE;
kbCanMapKey[NUMPAD3] = FALSE;
kbCanMapKey[NUMPAD4] = FALSE;
kbCanMapKey[NUMPAD5] = FALSE;
kbCanMapKey[NUMPAD6] = FALSE;
kbCanMapKey[NUMPAD7] = FALSE;
kbCanMapKey[NUMPAD8] = FALSE;
kbCanMapKey[NUMPAD9] = FALSE;
kbCanMapKey[NUMSTARKEY] = FALSE;
kbCanMapKey[NUMSLASHKEY] = FALSE;
kbCanMapKey[NUMDOTKEY] = FALSE;
***************************************************************************
src\win32\mainrgn.c
in the mrKeyPress():
case NUMSTARKEY:
if ((selSelected.numShips == 1))
{
if (cst)
{
if ((Ship *)CTship != selSelected.ShipPtr[0])
{
CTship->autostabilizeship = TRUE;
CTship->autostabilizestate = 0;
CTship->flightman = 0;
CTship->aistate = 0;
CTship->aistateattack = 0;
CTship->flags = SOF_Rotatable + SOF_Impactable + SOF_Selectable + SOF_Targetable;
CTship->dontapplyforceever = FALSE;
cst = FALSE;
}
}
(Ship *)CTship = selSelected.ShipPtr[0];
shpms = 100 * CTship->staticinfo->staticheader.mass;
shpms2 = 10 * CTship->staticinfo->staticheader.mass;
shpms3 = 2 * CTship->staticinfo->staticheader.momentOfInertiaZ;
fgx = shpms3/MAIN_WindowWidth * 32;
fgy = shpms3/MAIN_WindowWidth * 32;
CTship->shipidle=FALSE;
CTship->autostabilizeship = FALSE;
CTship->autostabilizestate = 3;
CTship->flightman = 30; //// this is the sign of the ship that you controlled
CTship->aistate = 3;
CTship->posinfo.isMoving = TRUE;
CTship->aistateattack = 0;
CTship->aistatecommand = 0;
engF[0]=1;
engF[1]=0;
engF[2]=0;
engF[3]=0;
engfr[0]=CTship->staticinfo->staticheader.mass;
cst = TRUE;
}
else cst = FALSE;
break;
case NUMPAD9:
if(cst)
{
if (keyIsHit(CONTROLKEY))
{
CTship->autostabilizeship = TRUE;
CTship->autostabilizestate = 0;
CTship->flightman = 0;
CTship->aistate = 0;
CTship->aistateattack = 0;
CTship->flags = SOF_Rotatable + SOF_Impactable + SOF_Selectable + SOF_Targetable;
CTship->dontapplyforceever = FALSE;
cst = FALSE;
}
else
{
engF[0] = engF[0] + 1;
if (engF[0] > 3)
engF[0] = 1;
}
}
break;
case NUMPAD4:
if(cst)
{
CTship->rotinfo.torque.x += shpms3;
}
break;
case NUMPAD6:
if(cst)
{
CTship->rotinfo.torque.x -= shpms3;
}
break;
case NUMPAD5:
if(cst)
{
if (keyIsHit(CONTROLKEY))
{
if (engF[1] < 3)
{
engF[1]=engF[1]+1;
engfr[1] = shpms * engF[1];
}
}
else
CTship->rotinfo.torque.y -= shpms3;
}
break;
case NUMPAD2:
if(cst)
{
if (keyIsHit(CONTROLKEY))
{
if (engF[1] > -3)
{
engF[1]=engF[1]-1;
engfr[1] = shpms * engF[1];
}
}
else
CTship->rotinfo.torque.y += shpms3;
}
break;
case NUMPAD1:
if(cst)
{
if (keyIsHit(CONTROLKEY))
{
if (engF[2] > -3)
{
engF[2]=engF[2]-1;
engfr[2] = shpms * engF[2];
}
}
else
CTship->rotinfo.torque.z -= shpms3*2;
}
break;
case NUMPAD3:
if(cst)
{
if (keyIsHit(CONTROLKEY))
{
if (engF[2] < 3)
{
engF[2]=engF[2]+1;
engfr[2] = shpms * engF[2];
}
}
else
CTship->rotinfo.torque.z += shpms3*2;
}
break;
case NUMPAD0:
if(cst)
{
if (keyIsHit(CONTROLKEY))
{
engF[0]=0;
engF[1]=0;
engF[2]=0;
engF[3]=0;
engfr[1]=0.0f;
engfr[2]=0.0f;
engfr[3]=0.0f;
if (CTship->posinfo.velocity.x < 1)
CTship->posinfo.velocity.x = 0;
if (CTship->posinfo.velocity.y < 1)
CTship->posinfo.velocity.y = 0;
if (CTship->posinfo.velocity.z < 1)
CTship->posinfo.velocity.z = 0;
CTship->posinfo.force.x = - CTship->posinfo.velocity.x * shpms2;
CTship->posinfo.force.y = - CTship->posinfo.velocity.y * shpms2;
CTship->posinfo.force.z = - CTship->posinfo.velocity.z * shpms2;
}
else
{
if (engF[3] < 3)
{
engF[3]=engF[3]+1;
engfr[3] = shpms * engF[3];
}
}
}
break;
case NUMDOTKEY:
if(cst)
{
if (keyIsHit(CONTROLKEY))
{
if (CTship->rotinfo.rotspeed.x < 0.4)
CTship->rotinfo.rotspeed.x = 0;
if (CTship->rotinfo.rotspeed.y < 0.4)
CTship->rotinfo.rotspeed.y = 0;
if (CTship->rotinfo.rotspeed.z < 0.4)
CTship->rotinfo.rotspeed.z = 0;
CTship->rotinfo.torque.x = -CTship->rotinfo.rotspeed.x * shpms2;
CTship->rotinfo.torque.y = -CTship->rotinfo.rotspeed.y * shpms2;
CTship->rotinfo.torque.z = -CTship->rotinfo.rotspeed.z * shpms2;
}
else
{
if (engF[3] > -3)
{
engF[3]=engF[3]-1;
engfr[3] = shpms * engF[3];
}
}
}
break;
/////////////////////////////////////////////////////////////
mrRegionProcess():
behind case RPE_HoldRight:
if (bitTest(universe.mainCameraCommand.ccMode,CCMODE_PILOT_SHIP))
{
if (cst)
{
tpx = mouseCursorX();
tpy = mouseCursorY();
tgx =-(tpx - frdX)*fgx;
tgy =-(tpy - frdY)*fgy;
if (keyIsHit(CONTROLKEY))
{
CTship->rotinfo.torque.z -= tgx;
}
else
{
CTship->rotinfo.torque.x += tgx;
}
CTship->rotinfo.torque.y += tgy;
frdX = tpx;
frdY = tpy;
}
}
break;
behind case RPE_PressRight:
if (bitTest(universe.mainCameraCommand.ccMode,CCMODE_PILOT_SHIP))
{
if (cst)
{
mousePositionSet(MAIN_WindowWidth / 2, MAIN_WindowHeight / 2);
frdX = mouseCursorX();
frdY = mouseCursorY();
break;
}
}
behind case RPE_ReleaseRight:
if (bitTest(universe.mainCameraCommand.ccMode,CCMODE_PILOT_SHIP))
{
if (cst)
{
CTship->rotinfo.torque.x = 0.0f;
CTship->rotinfo.torque.y = 0.0f;
break;
}
}
/////////////////////////////////////////////////////////////
add two function in mainrgn.c and mainrgn.h
real32 engfrp( int nmbr)
{
return engfr[nmbr];
}
int engFp( int nmbr)
{
return engF[nmbr];
}
you can also add 2 extern variables instead,but I dont know how to.
***************************************************************************
src\game\CommandLayer.c:
clProcess():
behind case COMMAND_NULL:
if (ship->flightman == 30)
dont holding pattern
/////////////////////////////////////////////////////////////////////
processAttackToDo():
if (ship->flightman == 30)
do passive attack,not rotate
if (leaderShip->flightman == 30)
do passive attack,not rotate
the same to others
**************************************************************
src\game\formation.c
setMilitaryParade():
processMilitaryParadeToDo():
if ( ship->flightman == 30)
{
continue;
}
***************************************************************
src\game\univupdate.c
univUpdateAllPosVelShips():
in while (objnode != NULL)
{
ship = .... ;
if(ship->flightman == 30)
{
if (engFp(0) == 3)
{
matrix dz = ship->rotinfo.coordsys;
vXm(&hea0,&ship->posinfo.velocity,&dz); // vXm is same as matMultiplyVecByMat() in the matrix.c,velocity projection in the up,right,heading
vecCrossProduct(hea,ship->rotinfo.rotspeed,hea0); // acceleration centripetal
vecMultiplyByScalar(hea,engfrp(0)); // centripetal force
vecSet(hea1,engfrp(1),engfrp(2),engfrp(3)); // force from engine
vecAdd(hea,hea,hea1);
mXv(&hea2,&dz,&hea); // mXv is same as matMultiplyMatByVec() in the matrix.c
ship->posinfo.force.x = hea2.x;
ship->posinfo.force.y = hea2.y;
ship->posinfo.force.z = hea2.z;
}
if (engFp(0) == 2)
{
matrix dz = ship->rotinfo.coordsys;
vecSet(hea1,engfrp(1),engfrp(2),engfrp(3));
mXv(&hea2,&dz,&hea1);
ship->posinfo.force.x = hea2.x;
ship->posinfo.force.y = hea2.y;
ship->posinfo.force.z = hea2.z;
}
if (engFp(0) == 1)
{
vecZeroVector(hea);
matGetVectFromMatrixCol3(hea2,ship->rotinfo.coordsys);
vhead = vecDotProduct(hea2,ship->posinfo.velocity);
vecScalarMultiply(ship->posinfo.velocity,hea2,vhead);
if (ship->rotinfo.rotspeed.x != 0)
{
fy = -vhead * ship->rotinfo.rotspeed.x * engfrp(0);
matGetVectFromMatrixCol2(hea1,ship->rotinfo.coordsys);
vecMultiplyByScalar(hea1,fy);
vecAdd(hea,hea,hea1);
}
if (ship->rotinfo.rotspeed.y != 0)
{
fx = vhead * ship->rotinfo.rotspeed.y * engfrp(0);
matGetVectFromMatrixCol1(hea0,ship->rotinfo.coordsys);
vecMultiplyByScalar(hea0,fx);
vecAdd(hea,hea,hea0);
}
if (engFp(3) != 0)
{
vecMultiplyByScalar(hea2,engfrp(3));
vecAdd(hea,hea,hea2);
}
ship->posinfo.force.x = hea.x;
ship->posinfo.force.y = hea.y;
ship->posinfo.force.z = hea.z;
}
physUpdateObjPosVelShip(ship,universe.phystimeelapsed);
{
sdword i;
for (i = 0; i < MAX_NUM_TRAILS; i++)
{
if (ship->trail[i] != NULL)
{
trailUpdate(ship->trail, &ship->enginePosition);
}
}
}
goto ggyy; // skip other test
}
...
ggyy: //update mesh animations
...