00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "revolt.h"
00021 #include "main.h"
00022 #include "dx.h"
00023 #include "geom.h"
00024 #include "particle.h"
00025 #include "texture.h"
00026 #include "model.h"
00027 #include "aerial.h"
00028 #include "play.h"
00029 #include "NewColl.h"
00030 #include "Body.h"
00031 #include "car.h"
00032 #include "input.h"
00033 #include "camera.h"
00034 #include "light.h"
00035 #include "visibox.h"
00036 #include "level.h"
00037 #include "ctrlread.h"
00038 #include "object.h"
00039 #include "obj_init.h"
00040 #include "control.h"
00041 #include "player.h"
00042 #include "editobj.h"
00043 #include "aizone.h"
00044 #include "timing.h"
00045 #include "ghost.h"
00046 #include "registry.h"
00047 #include "panel.h"
00048 #include "move.h"
00049 #include "Readinit.h"
00050
00051
00052 extern char *CarInfoFile;
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062 static void s_RationaliseControl(CTRL *Control);
00063
00064
00065
00066
00067
00068 void CRD_CheckLocalKeys(void);
00069 void CRD_InitPlayerControl(PLAYER *player, CTRL_TYPE CtrlType);
00070 void CRD_KeyboardInput(CTRL *Control);
00071 void CRD_JoystickInput(CTRL *Control);
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081 void CRD_CheckLocalKeys(void)
00082 {
00083 CAR *car;
00084 #if CHRIS_EXTRAS
00085 REAL impPos, impMag;
00086 VEC vPos, vImp;
00087 #endif
00088
00089 car = &PLR_LocalPlayer->car;
00090
00091 if (car == NULL)
00092 {
00093 return;
00094 }
00095
00096
00097 if (Keys[DIK_X] || Keys[DIK_Y] || Keys[DIK_Z] || Keys[DIK_LCONTROL])
00098 car->CurrentLapStartTime -= MS2TIME(1000);
00099
00100
00101 if (Keys[DIK_8] && !LastKeys[DIK_8])
00102 GhostSolid = !GhostSolid;
00103
00104
00105 if (Keys[DIK_PGUP] && !LastKeys[DIK_PGUP] && Everything)
00106 {
00107 GameSettings.CarID = PrevValidCarID(GameSettings.CarID);
00108 SetupCar(PLR_LocalPlayer, GameSettings.CarID);
00109 SetCarAerialPos(car);
00110 car->CurrentLapStartTime -= 10000;
00111 }
00112
00113 if (Keys[DIK_PGDN] && !LastKeys[DIK_PGDN] && Everything)
00114 {
00115 GameSettings.CarID = NextValidCarID(GameSettings.CarID);
00116 SetupCar(PLR_LocalPlayer, GameSettings.CarID);
00117 SetCarAerialPos(car);
00118 car->CurrentLapStartTime -= 10000;
00119 }
00120
00121
00122 if (Keys[DIK_LSHIFT] && Keys[DIK_F1] && !LastKeys[DIK_F1] && Everything) {
00123 if (!ReadAllCarInfo(CarInfoFile)){
00124 QuitGame = TRUE;
00125 return;
00126 }
00127 SetAllCarCoMs();
00128 }
00129
00130
00131 if (Keys[DIK_F1] && !LastKeys[DIK_F1]) {
00132 long subType;
00133 if (CAM_MainCamera->Type != CAM_FOLLOW) {
00134 subType = 0;
00135 } else {
00136 subType = ++(CAM_MainCamera->SubType);
00137 if (subType >= CAM_FOLLOW_NTYPES) subType = 0;
00138 }
00139 SetCameraFollow(CAM_MainCamera, PLR_LocalPlayer->ownobj, subType);
00140 }
00141
00142 if (Keys[DIK_F2] && !LastKeys[DIK_F2]) {
00143 long subType;
00144 if (CAM_MainCamera->Type != CAM_ATTACHED) {
00145 subType = 0;
00146 } else {
00147 subType = CAM_MainCamera->SubType + 1;
00148 if (subType >= CAM_ATTACHED_NTYPES) subType = 0;
00149 }
00150 SetCameraAttached(CAM_MainCamera, PLR_LocalPlayer->ownobj, subType);
00151 }
00152
00153 if (Keys[DIK_F3] && !LastKeys[DIK_F3]) {
00154 if (CAM_MainCamera->Type != CAM_FREEDOM) {
00155 SetCameraFreedom(CAM_MainCamera, NULL, 0);
00156 } else {
00157 if (CAM_MainCamera->Object == NULL) {
00158 SetCameraFreedom(CAM_MainCamera, PLR_LocalPlayer->ownobj, 0);
00159 } else {
00160 SetCameraFreedom(CAM_MainCamera, NULL, 0);
00161 }
00162 }
00163 }
00164
00165 if (Keys[DIK_F4] && EditMode) SetCameraEdit(CAM_MainCamera, NULL, 0);
00166
00167 if (Keys[DIK_F5] && !LastKeys[DIK_F5]) {
00168 long subType;
00169 if (CAM_MainCamera->Type != CAM_RAIL) {
00170 subType = 0;
00171 } else {
00172 subType = CAM_MainCamera->SubType + 1;
00173 if (subType == CAM_RAIL_NTYPES) subType = 0;
00174 }
00175 SetCameraRail(CAM_MainCamera, PLR_LocalPlayer->ownobj, subType);
00176 }
00177
00178
00179
00180 if (Keys[DIK_SPACE]) {
00181 SetWheelLocked(&car->Wheel[2]);
00182 SetWheelLocked(&car->Wheel[3]);
00183 } else {
00184 SetWheelNotLocked(&car->Wheel[2]);
00185 SetWheelNotLocked(&car->Wheel[3]);
00186 }
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196 if (Keys[DIK_4] && !LastKeys[DIK_4] && Everything) {
00197 GameSettings.AutoBrake = !GameSettings.AutoBrake;
00198 }
00199
00200
00201 if (Keys[DIK_5] && Everything) {
00202 if (Keys[DIK_LSHIFT]) {
00203 ClearBestGhostData();
00204 }
00205 InitBestGhostData();
00206 }
00207
00208
00209 if (Keys[DIK_9] && !LastKeys[DIK_9] && Everything) {
00210 PLR_CreatePlayer(PLAYER_CPU, CTRL_TYPE_NONE, 0, &CAM_MainCamera->WPos, &IdentityMatrix);
00211 }
00212
00213
00214 if (Keys[DIK_0] && !LastKeys[DIK_0] && Everything) {
00215 PLAYER *newPlayer;
00216
00217 for (newPlayer = PLR_LocalPlayer->next; newPlayer != NULL; newPlayer = newPlayer->next) {
00218 if (newPlayer->type == PLAYER_CPU || newPlayer->type == PLAYER_LOCAL) {
00219 break;
00220 }
00221 }
00222 if (newPlayer == NULL) {
00223 for (newPlayer = PLR_PlayerHead; newPlayer != NULL; newPlayer = newPlayer->next) {
00224 if (newPlayer->type == PLAYER_CPU || newPlayer->type == PLAYER_LOCAL) {
00225 break;
00226 }
00227 }
00228 }
00229 if (newPlayer != NULL) {
00230 if (Keys[DIK_LSHIFT]) {
00231 PLR_KillPlayer(PLR_LocalPlayer);
00232 } else {
00233 PLR_SetPlayerType(PLR_LocalPlayer, newPlayer->type);
00234 }
00235 PLR_SetPlayerType(newPlayer, PLAYER_LOCAL);
00236 PLR_LocalPlayer = newPlayer;
00237 CAM_MainCamera->Object = PLR_LocalPlayer->ownobj;
00238 }
00239 }
00240
00241
00242 #if PHYSICS_DEBUG_KEYS
00243
00244 if (!Everything)
00245 return;
00246
00247
00248 if (Keys[DIK_1] && !LastKeys[DIK_1]) {
00249
00250 SpeedUnits++;
00251 if (SpeedUnits == SPEED_NTYPES) SpeedUnits = 0;
00252 }
00253
00254
00255 if (Keys[DIK_2] && !LastKeys[DIK_2]) CAR_DrawCarAxes = !CAR_DrawCarAxes;
00256
00257
00258 if (Keys[DIK_P] && !LastKeys[DIK_P]) {
00259 int ii;
00260 for (ii = 0; ii < CAR_NWHEELS; ii++) {
00261 car->Wheel[ii].StaticFriction += Real(0.1);
00262 Limit(car->Wheel[ii].StaticFriction, ZERO, Real(5.0));
00263 }
00264 }
00265 if (Keys[DIK_O] && !LastKeys[DIK_O]) {
00266 int ii;
00267 for (ii = 0; ii < CAR_NWHEELS; ii++) {
00268 car->Wheel[ii].StaticFriction -= Real(0.1);
00269 Limit(car->Wheel[ii].StaticFriction, ZERO, Real(5.0));
00270 }
00271 }
00272 if (Keys[DIK_L] && !LastKeys[DIK_L]) {
00273 int ii;
00274 for (ii = 0; ii < CAR_NWHEELS; ii++) {
00275 car->Wheel[ii].KineticFriction += Real(0.1);
00276 Limit(car->Wheel[ii].KineticFriction, ZERO, Real(5.0));
00277 }
00278 }
00279 if (Keys[DIK_K] && !LastKeys[DIK_K]) {
00280 int ii;
00281 for (ii = 0; ii < CAR_NWHEELS; ii++) {
00282 car->Wheel[ii].KineticFriction -= Real(0.1);
00283 Limit(car->Wheel[ii].KineticFriction, ZERO, Real(5.0));
00284 }
00285 }
00286
00287
00288 #ifdef CHRIS_EXTRAS
00289 impPos = 10.0f;
00290 impMag = 100.0f;
00291 SetVec(&vPos, 0.0f, 0.0f, 0.0f);
00292
00293 if (Keys[DIK_X]) {
00294 if (Keys[DIK_LSHIFT]) {
00295 SetVec(&vImp, -impMag, 0.0f, 0.0f);
00296
00297 ApplyBodyImpulse(car->Body, &vImp, &vPos);
00298 } else {
00299 SetVec(&vImp, impMag, 0.0f, 0.0f);
00300
00301 ApplyBodyImpulse(car->Body, &vImp, &vPos);
00302 }
00303 }
00304 if (Keys[DIK_Y]) {
00305 if (Keys[DIK_LSHIFT]) {
00306 SetVec(&vImp, 0.0f, -impMag, 0.0f);
00307
00308 ApplyBodyImpulse(car->Body, &vImp, &vPos);
00309 } else {
00310 SetVec(&vImp, 0.0f, impMag, 0.0f);
00311
00312 ApplyBodyImpulse(car->Body, &vImp, &vPos);
00313 }
00314 }
00315 if (Keys[DIK_Z]) {
00316 if (Keys[DIK_LSHIFT]) {
00317 SetVec(&vImp, 0.0f, 0.0f, -impMag);
00318
00319 ApplyBodyImpulse(car->Body, &vImp, &vPos);
00320 } else {
00321 SetVec(&vImp, 0.0f, 0.0f, impMag);
00322
00323 ApplyBodyImpulse(car->Body, &vImp, &vPos);
00324 }
00325 }
00326
00327
00328 if (Keys[DIK_B]) {
00329 if (Keys[DIK_LSHIFT]) {
00330 SetVec(&vPos, 0.0f, 0.0f, impPos);
00331 SetVec(&vImp, 0.0f, -impMag, 0.0f);
00332 ApplyBodyImpulse(car->Body, &vImp, &vPos);
00333 SetVec(&vPos, 0.0f, 0.0f, -impPos);
00334 SetVec(&vImp, 0.0f, impMag, 0.0f);
00335 ApplyBodyImpulse(car->Body, &vImp, &vPos);
00336 } else {
00337 SetVec(&vPos, 0.0f, 0.0f, impPos);
00338 SetVec(&vImp, 0.0f, impMag, 0.0f);
00339 ApplyBodyImpulse(car->Body, &vImp, &vPos);
00340 SetVec(&vPos, 0.0f, 0.0f, -impPos);
00341 SetVec(&vImp, 0.0f, -impMag, 0.0f);
00342 ApplyBodyImpulse(car->Body, &vImp, &vPos);
00343 }
00344 }
00345 if (Keys[DIK_N]) {
00346 if (Keys[DIK_LSHIFT]) {
00347 SetVec(&vPos, 0.0f, 0.0f, impPos);
00348 SetVec(&vImp, impMag, 0.0f, 0.0f);
00349 ApplyBodyImpulse(car->Body, &vImp, &vPos);
00350 SetVec(&vPos, 0.0f, 0.0f, -impPos);
00351 SetVec(&vImp, -impMag, 0.0f, 0.0f);
00352 ApplyBodyImpulse(car->Body, &vImp, &vPos);
00353 } else {
00354 SetVec(&vPos, 0.0f, 0.0f, -impPos);
00355 SetVec(&vImp, impMag, 0.0f, 0.0f);
00356 ApplyBodyImpulse(car->Body, &vImp, &vPos);
00357 SetVec(&vPos, 0.0f, 0.0f, impPos);
00358 SetVec(&vImp, -impMag, 0.0f, 0.0f);
00359 ApplyBodyImpulse(car->Body, &vImp, &vPos);
00360 }
00361 }
00362 if (Keys[DIK_M]) {
00363 if (Keys[DIK_LSHIFT]) {
00364 SetVec(&vPos, 0.0f, impPos, 0.0f);
00365 SetVec(&vImp, impMag, 0.0f, 0.0f);
00366 ApplyBodyImpulse(car->Body, &vImp, &vPos);
00367 SetVec(&vPos, 0.0f, -impPos, 0.0f);
00368 SetVec(&vImp, -impMag, 0.0f, 0.0f);
00369 ApplyBodyImpulse(car->Body, &vImp, &vPos);
00370 } else {
00371 SetVec(&vPos, 0.0f, -impPos, 0.0f);
00372 SetVec(&vImp, impMag, 0.0f, 0.0f);
00373 ApplyBodyImpulse(car->Body, &vImp, &vPos);
00374 SetVec(&vPos, 0.0f, impPos, 0.0f);
00375 SetVec(&vImp, -impMag, 0.0f, 0.0f);
00376 ApplyBodyImpulse(car->Body, &vImp, &vPos);
00377 }
00378 }
00379 #endif
00380
00381
00382 if (Keys[DIK_T]) {
00383 SetVecZero(&car->Body->AngVel);
00384 SetVecZero(&car->Body->Centre.Vel);
00385 }
00386
00387 #endif
00388
00389 }
00390
00391
00392
00393
00394 void CRD_InitPlayerControl(PLAYER *player, CTRL_TYPE CtrlType)
00395 {
00396 switch(CtrlType)
00397 {
00398 case CTRL_TYPE_KBD:
00399 player->ctrlhandler = (CTRL_HANDLER)CRD_KeyboardInput;
00400 break;
00401
00402 case CTRL_TYPE_JOY:
00403 player->ctrlhandler = (CTRL_HANDLER)CRD_JoystickInput;
00404 break;
00405
00406 case CTRL_TYPE_NONE:
00407 break;
00408
00409
00410
00411
00412
00413
00414 default:
00415 break;
00416 };
00417 }
00418
00419
00420
00421
00422 void CRD_KeyboardInput(CTRL *Control)
00423 {
00424 if (!DetailMenuTogg)
00425 {
00426 if (GameSettings.Mirrored)
00427 {
00428 if (Keys[DIK_RIGHT]) { Control->digital += CTRL_LEFT; }
00429 if (Keys[DIK_LEFT]) { Control->digital += CTRL_RIGHT; }
00430 }
00431 else
00432 {
00433 if (Keys[DIK_LEFT]) { Control->digital += CTRL_LEFT; }
00434 if (Keys[DIK_RIGHT]) { Control->digital += CTRL_RIGHT; }
00435 }
00436 if (Keys[DIK_UP] || Keys[DIK_F]) { Control->digital += CTRL_FWD; }
00437 if (Keys[DIK_DOWN] || Keys[DIK_V]) { Control->digital += CTRL_BACK; }
00438
00439 if (Keys[DIK_HOME]) { Control->digital += CTRL_RESTART; }
00440 if (Keys[DIK_END]) { Control->digital += CTRL_RESET; }
00441 if (Keys[DIK_LCONTROL]) { Control->digital += CTRL_FIRE; }
00442
00443 }
00444 s_RationaliseControl(Control);
00445 }
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456 static void s_RationaliseControl(CTRL *Control)
00457 {
00458
00459 if ((Control->digital & CTRL_LR) == CTRL_LR)
00460 {
00461 Control->digital &= ~CTRL_LR;
00462 }
00463
00464 if ((Control->digital & CTRL_FB) == CTRL_FB)
00465 {
00466 Control->digital &= ~CTRL_FB;
00467 }
00468
00469
00470 if (Control->digital & CTRL_LEFT)
00471 {
00472 Control->dx = -CTRL_RANGE_MAX;
00473 }
00474 else
00475 if (Control->digital & CTRL_RIGHT)
00476 {
00477 Control->dx = CTRL_RANGE_MAX;
00478 }
00479
00480 if (Control->digital & CTRL_FWD)
00481 {
00482 Control->dy = -CTRL_RANGE_MAX;
00483 }
00484 else
00485 if (Control->digital & CTRL_BACK)
00486 {
00487 Control->dy = CTRL_RANGE_MAX;
00488 }
00489 }
00490
00491
00492
00493
00494 void CRD_JoystickInput(CTRL *Control)
00495 {
00496 long delta;
00497
00498
00499
00500 static long x= 0, y = 1;
00501 if (Keys[DIK_1] && !LastKeys[DIK_1] && Everything) x = (x + 1) % 6;
00502 if (Keys[DIK_2] && !LastKeys[DIK_2] && Everything) y = (y + 1) % 6;
00503
00504
00505
00506 CRD_KeyboardInput(Control);
00507
00508
00509
00510 if (GameSettings.Mirrored) delta = Control->dx - ((long*)&JoystickState)[x];
00511 else delta = Control->dx + ((long*)&JoystickState)[x];
00512
00513 if (delta < -CTRL_RANGE_MAX) delta = -CTRL_RANGE_MAX;
00514 else if (delta > CTRL_RANGE_MAX) delta = CTRL_RANGE_MAX;
00515 Control->dx = (char)delta;
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527 if (JoystickState.rgbButtons[3])
00528 Control->dy = CTRL_RANGE_MAX;
00529
00530 if (JoystickState.rgbButtons[1])
00531 Control->dy = -CTRL_RANGE_MAX;
00532
00533 if (JoystickState.rgbButtons[3])
00534 Control->digital += CTRL_FIRE;
00535
00536 if (JoystickState.rgbButtons[4])
00537 Control->digital += CTRL_RESET;
00538 }