00001
00002 #include "Revolt.h"
00003 #include "ctrlread.h"
00004 #ifdef _PC
00005 #include "input.h"
00006 #endif
00007 #include "Model.h"
00008 #ifdef _PC
00009 #include "Play.h"
00010 #endif
00011 #include "Particle.h"
00012 #include "Aerial.h"
00013 #include "NewColl.h"
00014 #include "Body.h"
00015 #include "Car.h"
00016 #ifdef _PC
00017 #include "input.h"
00018 #endif
00019 #ifndef _PSX
00020 #include "Main.h"
00021 #include "level.h"
00022 #endif
00023 #include "object.h"
00024 #include "player.h"
00025 #include "geom.h"
00026 #ifndef _PSX
00027 #include "timing.h"
00028 #endif
00029 #include "camera.h"
00030 #include "move.h"
00031 #ifndef _PSX
00032 #include "obj_init.h"
00033 #include "AIZone.h"
00034 #endif
00035
00036
00037
00038
00039
00040 void CON_DoPlayerControl(void);
00041 void CON_LocalCarControl(CTRL *Control, OBJECT *CarObj);
00042
00043
00044
00045 static long Pickup2WeaponTable[PICKUP_NUM] = {
00046 OBJECT_TYPE_SHOCKWAVE,
00047 OBJECT_TYPE_FIREWORK,
00048 OBJECT_TYPE_FIREWORK,
00049 OBJECT_TYPE_PUTTYBOMB,
00050 OBJECT_TYPE_WATERBOMB,
00051 OBJECT_TYPE_ELECTROPULSE,
00052 OBJECT_TYPE_OILSLICK_DROPPER,
00053 OBJECT_TYPE_CHROMEBALL,
00054 OBJECT_TYPE_TURBO,
00055 };
00056
00057
00058
00059 void CON_DoPlayerControl(void)
00060 {
00061 PLAYER *player;
00062 unsigned short lastdigital;
00063
00064
00065
00066 for (player = PLR_PlayerHead; player; player = player->next)
00067 {
00068
00069
00070
00071 lastdigital = player->controls.digital;
00072
00073
00074
00075 #ifdef _PC
00076 if (CountdownTime || GameSettings.Paws)
00077 {
00078 player->controls.dx = 0;
00079 player->controls.dy = 0;
00080 player->controls.digital = 0;
00081 player->controls.idigital = 0;
00082 continue;
00083 }
00084 #endif
00085
00086
00087
00088 if (player->type == PLAYER_LOCAL)
00089 {
00090 player->controls.dx = 0;
00091 player->controls.dy = 0;
00092 player->controls.digital = 0;
00093 }
00094
00095
00096
00097 if (player->ctrlhandler)
00098 {
00099 player->ctrlhandler(&player->controls);
00100 player->controls.idigital = (player->controls.digital ^ lastdigital) & player->controls.digital;
00101 }
00102
00103
00104
00105 if (player->car.PowerTimer)
00106 {
00107 player->controls.dy = 0;
00108 }
00109
00110
00111
00112 if (player->conhandler)
00113 {
00114 player->conhandler(&player->controls, player->ownobj);
00115 }
00116 }
00117 }
00118
00119
00120
00121 void CON_LocalCarControl(CTRL *Control, OBJECT *CarObj)
00122 {
00123 CAR *car;
00124 REAL dest, step;
00125 VEC vec, vec2;
00126 MAT mat;
00127 long flag;
00128
00129 car = &CarObj->player->car;
00130 if (car == NULL)
00131 {
00132 return;
00133 }
00134
00135
00136
00137
00138
00139 dest = ((ONE / CTRL_RANGE_MAX) * (REAL)(Control->dx));
00140 #ifndef _PSX
00141 step = MulScalar(car->SteerRate, TimeStep);
00142 #else
00143 step = MulScalar(car->SteerRate, TimeStep) << 1;
00144 #endif
00145 if ((dest == ZERO) || (Sign(dest) != Sign(car->SteerAngle))) {
00146 step *= 2;
00147 }
00148 #ifndef _PSX
00149 else {
00150 step *= ONE - (car->SteerModifier * VecDotVec(&car->Body->Centre.Vel, &car->Body->Centre.WMatrix.mv[L]) / car->TopSpeed);
00151 }
00152 #endif
00153 if (dest > car->SteerAngle) {
00154 if (dest - car->SteerAngle < step) {
00155 car->SteerAngle = dest;
00156 } else {
00157 car->SteerAngle += step;
00158 }
00159 }
00160 if (dest < car->SteerAngle) {
00161 if (car->SteerAngle - dest < step) {
00162 car->SteerAngle = dest;
00163 } else {
00164 car->SteerAngle -= step;
00165 }
00166 }
00167
00168
00169
00170 dest = -((ONE / CTRL_RANGE_MAX) * (REAL)(Control->dy));
00171 step = MulScalar(car->EngineRate, TimeStep);
00172 if ((dest < ZERO && car->EngineVolt > ZERO) || (dest > ZERO && car->EngineVolt < ZERO)) {
00173 car->EngineVolt = ZERO;
00174 }
00175 if (dest > car->EngineVolt) {
00176 if (dest - car->EngineVolt < step) {
00177 car->EngineVolt = dest;
00178 } else {
00179 car->EngineVolt += step;
00180 }
00181 }
00182 if (dest < car->EngineVolt) {
00183 if (car->EngineVolt - dest < step) {
00184 car->EngineVolt = dest;
00185 } else {
00186 car->EngineVolt -= step;
00187 }
00188 }
00189
00190
00191 if (Control->idigital & CTRL_RESET)
00192 {
00193 #ifdef _PC
00194 if ((Keys[DIK_LSHIFT] || Keys[DIK_RSHIFT]) && Everything) {
00195 SetVector(&vec2, 0, 0, 256);
00196 RotTransVector(&CAM_MainCamera->WMatrix, &CAM_MainCamera->WPos, &vec2, &vec);
00197
00198 CopyVec(&CAM_MainCamera->WMatrix.mv[R], &mat.mv[R]);
00199 SetVector(&mat.mv[U], 0, 1, 0);
00200 CrossProduct(&mat.mv[R], &mat.mv[U], &mat.mv[L]);
00201 SetCarPos(car, &vec, &mat);
00202 }
00203 #endif
00204 CarObj->player->car.RightingCollide = TRUE;
00205 CarObj->player->car.RightingReachDest = FALSE;
00206 CarObj->movehandler = (MOVE_HANDLER)MOV_RightCar;
00207 }
00208
00209
00210 #ifndef _PSX
00211 if (CarObj->player->controls.idigital & CTRL_RESTART && !CountdownTime)
00212 {
00213 GetCarGrid(0, &vec, &mat);
00214 SetCarPos(car, &vec, &mat);
00215
00216 car->Laps = -1;
00217 CarObj->player->CarAI.ZoneID = AiZoneNumID - 1;
00218
00219 CarObj->player->CarAI.FinishDistNode = AiStartNode;
00220 CarObj->player->CarAI.FinishDist = 0.0f;
00221 CarObj->player->CarAI.FinishDistPanel = 0.0f;
00222
00223 CarObj->movehandler = (MOVE_HANDLER)MOV_MoveCarNew;
00224
00225 #ifdef _PC // !MT! TEMP OUT of N64 version
00226 CarObj->player->car.CurrentLapStartTime = CurrentTimer() - MS2TIME(MAKE_TIME(10, 0, 0));
00227
00228 SaveTrackTimes(&LevelInf[GameSettings.Level]);
00229 LoadTrackTimes(&LevelInf[GameSettings.Level]);
00230 #endif
00231 }
00232 #else
00233 if (CarObj->player->controls.idigital & CTRL_RESTART)
00234 {
00235 GetCarGrid(0, &vec, &mat);
00236 SetCarPos(car, &vec, &Identity);
00237
00238 CarObj->movehandler = (MOVE_HANDLER)MOV_MoveCarNew;
00239 }
00240 #endif
00241
00242 #ifdef _PC
00243
00244 if (Control->idigital & CTRL_FIRE && CarObj->player->PickupNum)
00245 {
00246 flag = (long)CarObj->player;
00247 CreateObject(&CarObj->player->car.Body->Centre.Pos, &CarObj->player->car.Body->Centre.WMatrix, Pickup2WeaponTable[CarObj->player->PickupType], &flag);
00248
00249 if (--CarObj->player->PickupNum == 0) {
00250 CarObj->player->PickupType = PICKUP_NONE;
00251 }
00252
00253 }
00254 #endif
00255 }
00256
00257