From 7dd07e2b8c717e1cc256e3852b9874a19988a216 Mon Sep 17 00:00:00 2001 From: Ilya Shurumov Date: Wed, 7 Oct 2020 15:11:47 +0600 Subject: [PATCH 01/41] - fix up mission names --- src_rebuild/GAME/C/MISSION.C | 62 ++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/src_rebuild/GAME/C/MISSION.C b/src_rebuild/GAME/C/MISSION.C index 7f0da860..df8b582b 100644 --- a/src_rebuild/GAME/C/MISSION.C +++ b/src_rebuild/GAME/C/MISSION.C @@ -35,49 +35,49 @@ char* MissionName[37] = { // Chicago - "Surveillance Tip Off", - "Chase the Witness", - "Train Pursuit", - "Tailing the Drop", - "Escape to the Safe House", - "Chase the Intruder", - "Caine's Compound", + "Surveillance tip off", + "Chase the witness", + "Train pursuit", + "Tailing the drop", + "Escape to the safe house", + "Chase the intruder", + "Caine's compound", "Leaving Chicago", // Havana - "Follow Up the Lead", - "Hijack the Truck", - "Stop the Truck", - "Find the Clue", - "Escape to Ferry", - "To the Docks", + "Follow up the lead", + "Hijack the truck", + "Stop the truck", + "Find the clue", + "Escape to ferry", + "To the docks", "Back to Jones", "Tail Jericho", "Pursue Jericho", "Escape the Brazilians", // Vegas - "Casino Getaway", - "Beat the Train", - "Car Bomb", - "Car Bomb Getaway", - "Bank Job", - "Steal the Ambulance", + "Casino getaway", + "Beat the train", + "Car bomb", + "Car bomb getaway", + "Bank job", + "Steal the ambulance", "Stake Out", - "Steal the Keys", - "C4 Deal", - "Destroy the Yard", + "Steal the keys", + "C4 deal", + "Destroy the yard", // Rio - "Bus Crash", - "Steal the Cop Car", - "Caine's Cash", + "Bus crash", + "Steal the cop car", + "Caine's cash", "Save Jones", - "Boat Jump", - "Jones in Trouble", - "Chase the Gunman", - "Lenny Escaping", - "Pink Lenny Gets Caught", + "Boat jump", + "Jones in trouble", + "Chase the Gun Man", + "Lenny escaping", + "Lenny gets caught", }; // decompiled code @@ -921,7 +921,7 @@ void RegisterChaseHit(int car1, int car2) Mission.ChaseHitDelay = 20; player[1 - player_id].targetCarId = gPlayerWithTheFlag; - SetPlayerMessage(player_id, "You got the flag!",2,1); + SetPlayerMessage(player_id, "You've got the flag!",2,1); } } } From 689bd5f156511f344f06e7d36e505a3bfe3828f6 Mon Sep 17 00:00:00 2001 From: Ilya Shurumov Date: Wed, 7 Oct 2020 15:11:58 +0600 Subject: [PATCH 02/41] - fix up pause strings --- src_rebuild/GAME/C/PAUSE.C | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src_rebuild/GAME/C/PAUSE.C b/src_rebuild/GAME/C/PAUSE.C index 6aab9680..218a2a27 100644 --- a/src_rebuild/GAME/C/PAUSE.C +++ b/src_rebuild/GAME/C/PAUSE.C @@ -188,7 +188,7 @@ MENU_HEADER DebugTimeOfDayHeader = MENU_ITEM DebugJustForFunItems[] = { { "Secret Car Fun", 3, 2, ToggleSecretCarFun, MENU_QUIT_RESTART, NULL }, - { "Mini cars", 3, 2, ToggleMiniCars, MENU_QUIT_NONE, NULL }, + { "Mini Cars", 3, 2, ToggleMiniCars, MENU_QUIT_NONE, NULL }, { "Jericho Mode", 3, 2, ToggleJerichoMode, MENU_QUIT_NONE, NULL }, { NULL, 128u, 0u, NULL, MENU_QUIT_NONE, NULL } }; @@ -208,7 +208,7 @@ MENU_ITEM DebugOptionsItems[] = #endif { "Back on Wheels", 3, 2, SetRightWayUp, MENU_QUIT_NONE, NULL}, { "Time of Day", 65, 2, NULL, MENU_QUIT_NONE, &DebugTimeOfDayHeader }, - { "Fun cheats", 65, 2, NULL, MENU_QUIT_NONE, &DebugJustForFunHeader }, + { "Fun Cheats", 65, 2, NULL, MENU_QUIT_NONE, &DebugJustForFunHeader }, { "Invincibility", 3, 2, ToggleInvincibility,MENU_QUIT_NONE, NULL}, { "Immunity", 3, 2, ToggleImmunity, MENU_QUIT_NONE, NULL}, { "Puppy Dog Cops", 3, 2, TogglePuppyDogCops, MENU_QUIT_NONE, NULL }, @@ -406,7 +406,7 @@ MENU_HEADER ChaseGameFinishedHeader = MENU_HEADER NoPadHeader = { - "Insert controller in slot 1", + "Insert a Controller in port 1", { 0, 0, 0, 0 }, 0u, NoPadItems @@ -414,7 +414,7 @@ MENU_HEADER NoPadHeader = MENU_HEADER NoMultiPadHeader = { - "Insert controller in slot 1", + "Insert a Controller in port 2", { 0, 0, 0, 0 }, 0u, NoMultiPadItems @@ -422,7 +422,7 @@ MENU_HEADER NoMultiPadHeader = MENU_HEADER InvalidPadHeader = { - "Incompatible controller in port 1", + "Unsupported controller in port 1", { 0, 0, 0, 0 }, 0u, InvalidPadItems @@ -430,7 +430,7 @@ MENU_HEADER InvalidPadHeader = MENU_HEADER InvalidMultiPadHeader = { - "Incompatible controller in port 1", + "Unsupported controller in port 2", { 0, 0, 0, 0 }, 0u, InvalidMultiPadItems From 7d3a4083e65e5face46303d8985df6386e73375c Mon Sep 17 00:00:00 2001 From: Ilya Shurumov Date: Wed, 7 Oct 2020 20:45:52 +0600 Subject: [PATCH 03/41] - fix PlaceCameraFollowCar losing angular pricision on very close distances --- src_rebuild/GAME/C/CAMERA.C | 46 ++++++++++++++----------------------- 1 file changed, 17 insertions(+), 29 deletions(-) diff --git a/src_rebuild/GAME/C/CAMERA.C b/src_rebuild/GAME/C/CAMERA.C index 4ccabbd3..41d9e902 100644 --- a/src_rebuild/GAME/C/CAMERA.C +++ b/src_rebuild/GAME/C/CAMERA.C @@ -630,8 +630,8 @@ void TurnHead(_PLAYER *lp) // End Line: 1744 int maxCameraDist; -short gCameraDistance = 0x3e8; -short gCameraMaxDistance = 0x3e8; +short gCameraDistance = 1000; +short gCameraMaxDistance = 1000; _CAR_DATA *jcam = NULL; int switch_detail_distance = 10000; @@ -649,13 +649,11 @@ void PlaceCameraFollowCar(_PLAYER *lp) int cammapht; int camPosVy; - if (lp->cameraCarId < 0) - { - maxCameraDist = 850; - carheight = -220; - camExpandSpeed = 10; - } - else + maxCameraDist = 850; + carheight = -220; + camExpandSpeed = 10; + + if (lp->cameraCarId >= 0) { _CAR_DATA* camCar; int carSpeed; @@ -665,7 +663,7 @@ void PlaceCameraFollowCar(_PLAYER *lp) if(car_cos) { - carheight = car_cos->colBox.vy * -3 + 0x55; + carheight = car_cos->colBox.vy * -3 + 85; maxCameraDist = car_cos->colBox.vz * 2 + car_cos->colBox.vy + 248; carSpeed = FIXEDH(camCar->hd.wheel_speed); @@ -673,17 +671,9 @@ void PlaceCameraFollowCar(_PLAYER *lp) if (carSpeed < 0) carSpeed = -carSpeed; - camExpandSpeed = 10; - if (carSpeed > 9 && (gCameraDistance + 30 <= maxCameraDist)) camExpandSpeed = 20; } - else - { - maxCameraDist = 850; - carheight = -220; - camExpandSpeed = 10; - } } if (pauseflag == 0) @@ -700,7 +690,7 @@ void PlaceCameraFollowCar(_PLAYER *lp) } else { - angleDelta = (((baseDir + gCameraAngle) - lp->cameraAngle) + 0x800U & 0xfff) - 0x800; + angleDelta = (((baseDir + gCameraAngle) - lp->cameraAngle) + 2048U & 0xfff) - 2048; lp->cameraAngle += (angleDelta >> 3) & 0xfff; } } @@ -748,9 +738,9 @@ void PlaceCameraFollowCar(_PLAYER *lp) sdist = maxCameraDist * rcossin_tbl[camAngle * 2] + 0x800; cdist = maxCameraDist * rcossin_tbl[camAngle * 2 + 1] + 0x800; - jcam->hd.oBox.location.vx = jcam->hd.where.t[0] = basePos[0] + ((sdist >> 0xc) - (sdist >> 0x1f) >> 1); + jcam->hd.oBox.location.vx = jcam->hd.where.t[0] = basePos[0] + (sdist >> 13); jcam->hd.oBox.location.vy = jcam->hd.where.t[1] = -lp->cameraPos.vy; - jcam->hd.oBox.location.vz = jcam->hd.where.t[2] = basePos[2] + ((cdist >> 0xc) - (cdist >> 0x1f) >> 1); + jcam->hd.oBox.location.vz = jcam->hd.where.t[2] = basePos[2] + (cdist >> 13); CheckScenaryCollisions(jcam); @@ -759,17 +749,15 @@ void PlaceCameraFollowCar(_PLAYER *lp) if (lp->cameraDist > gCameraDistance) lp->cameraDist = gCameraDistance; - jcam->hd.direction = jcam->hd.direction & 0xfff; - lp->cameraPos.vy = -jcam->hd.where.t[1]; - lp->cameraPos.vx = basePos[0] + FIXEDH(lp->cameraDist * rcossin_tbl[jcam->hd.direction * 2]); - lp->cameraPos.vz = basePos[2] + FIXEDH(lp->cameraDist * rcossin_tbl[jcam->hd.direction * 2 + 1]); + lp->cameraPos.vx = basePos[0] + FIXEDH(lp->cameraDist * rcossin_tbl[(jcam->hd.direction & 0xfff) * 2]); + lp->cameraPos.vz = basePos[2] + FIXEDH(lp->cameraDist * rcossin_tbl[(jcam->hd.direction & 0xfff) * 2 + 1]); - camera_angle.vy = -ratan2(basePos[0] - lp->cameraPos.vx, basePos[2] - lp->cameraPos.vz) & 0xfff; + camera_angle.vy = -(jcam->hd.direction + 2048);//-ratan2(basePos[0] - lp->cameraPos.vx, basePos[2] - lp->cameraPos.vz) & 0xfff; camera_angle.vz = 0; - SetGeomScreen(0x100); - scr_z = 0x100; + SetGeomScreen(256); + scr_z = 256; switch_detail_distance = 10000; BuildWorldMatrix(); @@ -996,7 +984,7 @@ void PlaceCameraInCar(_PLAYER *lp, int BumperCam) { ClearMem((char *)&inv_camera_matrix, sizeof(MATRIX)); - angle = 0x800U - baseDir & 0xfff; + angle = 2048U - baseDir & 0xfff; inv_camera_matrix.m[0][0] = rcossin_tbl[angle * 2 + 1]; inv_camera_matrix.m[0][2] = rcossin_tbl[angle * 2]; From b7f7363f79f5227eaf382fda40d6ea9eec9e9bc6 Mon Sep 17 00:00:00 2001 From: Ilya Shurumov Date: Wed, 7 Oct 2020 20:54:48 +0600 Subject: [PATCH 04/41] - bomberman refactoring update --- src_rebuild/GAME/C/BOMBERMAN.C | 31 ++++++++++++++++--------------- src_rebuild/GAME/C/BOMBERMAN.H | 1 - src_rebuild/GAME/C/JOB_FX.C | 10 ++++++---- src_rebuild/GAME/C/JOB_FX.H | 1 + src_rebuild/GAME/C/PEDEST.C | 3 +-- src_rebuild/GAME/DR2LIMITS.H | 10 ++++++---- 6 files changed, 30 insertions(+), 26 deletions(-) diff --git a/src_rebuild/GAME/C/BOMBERMAN.C b/src_rebuild/GAME/C/BOMBERMAN.C index a9100e25..4fa8cb33 100644 --- a/src_rebuild/GAME/C/BOMBERMAN.C +++ b/src_rebuild/GAME/C/BOMBERMAN.C @@ -23,8 +23,9 @@ #include "RAND.H" MODEL* gBombModel; -_ExOBJECT explosion[5]; -static BOMB ThrownBombs[5]; + +static BOMB ThrownBombs[MAX_THROWN_BOMBS]; + static int ThrownBombDelay = 0; static int CurrentBomb = 0; static int gWantFlash = 0; @@ -71,7 +72,7 @@ void InitThrownBombs(void) { int i; - for (i = 0; i < 5; i++) + for (i = 0; i < MAX_THROWN_BOMBS; i++) ThrownBombs[i].flags = 0; ThrownBombDelay = Random2(0) % 45 + 8; @@ -153,7 +154,7 @@ void HandleThrownBombs(void) ThrownBombDelay = Random2(0) % 45 + 8; bomb = &ThrownBombs[CurrentBomb++]; - CurrentBomb = CurrentBomb % 5; + CurrentBomb = CurrentBomb % MAX_THROWN_BOMBS; bomb->flags = 1; bomb->active = 1; @@ -182,7 +183,7 @@ void HandleThrownBombs(void) bomb = ThrownBombs; i = 0; - while (i < 5) + while (i < MAX_THROWN_BOMBS) { if ((bomb->flags & 1) != 0) { @@ -303,7 +304,7 @@ void DrawThrownBombs(void) bomb = ThrownBombs; i = 0; - while (i < 5) + while (i < MAX_THROWN_BOMBS) { if ((bomb->flags & 1) != 0) { @@ -406,7 +407,7 @@ void BombThePlayerToHellAndBack(int car) gBombTargetVehicle = &car_data[(car + 1) % maxCivCars]; bomb = &ThrownBombs[CurrentBomb++]; - CurrentBomb = CurrentBomb % 5; + CurrentBomb = CurrentBomb % MAX_THROWN_BOMBS; bomb->flags = 1; bomb->active = 1; @@ -420,7 +421,7 @@ void BombThePlayerToHellAndBack(int car) bomb->velocity.vz = 0; bomb = &ThrownBombs[CurrentBomb++]; - CurrentBomb = CurrentBomb % 5; + CurrentBomb = CurrentBomb % MAX_THROWN_BOMBS; bomb->flags = 1; bomb->active = 1; @@ -434,7 +435,7 @@ void BombThePlayerToHellAndBack(int car) bomb->velocity.vz = 0; bomb = &ThrownBombs[CurrentBomb++]; - CurrentBomb = CurrentBomb % 5; + CurrentBomb = CurrentBomb % MAX_THROWN_BOMBS; bomb->flags = 1; bomb->active = 1; @@ -769,13 +770,13 @@ void ExplosionCollisionCheck(_CAR_DATA *cp, _ExOBJECT *pE) pointVel[1] = denom * (collisionResult.surfNormal.vy >> 6); pointVel[2] = denom * (collisionResult.surfNormal.vz >> 6); - cp->st.n.linearVelocity[0] = cp->st.n.linearVelocity[0] + pointVel[0]; - cp->st.n.linearVelocity[1] = cp->st.n.linearVelocity[1] + pointVel[1]; - cp->st.n.linearVelocity[2] = cp->st.n.linearVelocity[2] + pointVel[2]; + cp->st.n.linearVelocity[0] += pointVel[0]; + cp->st.n.linearVelocity[1] += pointVel[1]; + cp->st.n.linearVelocity[2] += pointVel[2]; - cp->hd.aacc[0] = (cp->hd.aacc[0] + FIXEDH(lever[1] * pointVel[2])) - FIXEDH(lever[2] * pointVel[1]); - cp->hd.aacc[1] = (cp->hd.aacc[1] + FIXEDH(lever[2] * pointVel[0])) - FIXEDH(lever[0] * pointVel[2]); - cp->hd.aacc[2] = (cp->hd.aacc[2] + FIXEDH(lever[0] * pointVel[1])) - FIXEDH(lever[1] * pointVel[0]); + cp->hd.aacc[0] += FIXEDH(lever[1] * pointVel[2]) - FIXEDH(lever[2] * pointVel[1]); + cp->hd.aacc[1] += FIXEDH(lever[2] * pointVel[0]) - FIXEDH(lever[0] * pointVel[2]); + cp->hd.aacc[2] += FIXEDH(lever[0] * pointVel[1]) - FIXEDH(lever[1] * pointVel[0]); } } diff --git a/src_rebuild/GAME/C/BOMBERMAN.H b/src_rebuild/GAME/C/BOMBERMAN.H index c91459a0..e6f384ed 100644 --- a/src_rebuild/GAME/C/BOMBERMAN.H +++ b/src_rebuild/GAME/C/BOMBERMAN.H @@ -2,7 +2,6 @@ #define BOMBERMAN_H extern MODEL* gBombModel; -extern _ExOBJECT explosion[5]; extern _CAR_DATA *gBombTargetVehicle; extern void InitThrownBombs(); // 0x0001F570 diff --git a/src_rebuild/GAME/C/JOB_FX.C b/src_rebuild/GAME/C/JOB_FX.C index c41711e9..0f363139 100644 --- a/src_rebuild/GAME/C/JOB_FX.C +++ b/src_rebuild/GAME/C/JOB_FX.C @@ -12,6 +12,8 @@ #include "INLINE_C.H" +_ExOBJECT explosion[MAX_EXPLOSION_OBJECTS]; + MATRIX SS = { 0 }; // decompiled code @@ -54,7 +56,7 @@ void InitExObjects(void) { int i; - for (i = 0; i < 5; i++) + for (i = 0; i < MAX_EXPLOSION_OBJECTS; i++) explosion[i].time = -1; initExplosion(); @@ -186,7 +188,7 @@ void HandleExplosion(void) i = 0; exp = explosion; - while (i < 5) + while (i < MAX_EXPLOSION_OBJECTS) { if (exp->time != -1 && exp->type != BANG_USED) { @@ -207,7 +209,7 @@ void HandleExplosion(void) i = 0; exp = explosion; - while (i < 5) + while (i < MAX_EXPLOSION_OBJECTS) { if (exp->time != -1) { @@ -277,7 +279,7 @@ void DrawAllExplosions(void) { int i; i = 0; - while (i < 5) + while (i < MAX_EXPLOSION_OBJECTS) { if (explosion[i].time != -1) DrawExplosion(explosion[i].time, explosion[i].pos, explosion[i].hscale, explosion[i].rscale); diff --git a/src_rebuild/GAME/C/JOB_FX.H b/src_rebuild/GAME/C/JOB_FX.H index 121d6277..40342615 100644 --- a/src_rebuild/GAME/C/JOB_FX.H +++ b/src_rebuild/GAME/C/JOB_FX.H @@ -1,6 +1,7 @@ #ifndef JOB_FX_H #define JOB_FX_H +extern _ExOBJECT explosion[MAX_EXPLOSION_OBJECTS]; extern void InitExObjects(); // 0x00057B0C diff --git a/src_rebuild/GAME/C/PEDEST.C b/src_rebuild/GAME/C/PEDEST.C index 83ac96af..7fe83d2f 100644 --- a/src_rebuild/GAME/C/PEDEST.C +++ b/src_rebuild/GAME/C/PEDEST.C @@ -8,7 +8,6 @@ #include "DR2ROADS.H" #include "MOTION_C.H" #include "CONVERT.H" -#include "GAMESND.H" #include "SOUND.H" #include "PAD.H" #include "CIV_AI.H" @@ -19,7 +18,7 @@ #include "AI.H" #include "CARS.H" #include "FELONY.H" -#include "BOMBERMAN.H" +#include "JOB_FX.H" #include "BCOLLIDE.H" #include "MAP.H" #include "SYSTEM.H" diff --git a/src_rebuild/GAME/DR2LIMITS.H b/src_rebuild/GAME/DR2LIMITS.H index 0b0824c3..1ae62ff0 100644 --- a/src_rebuild/GAME/DR2LIMITS.H +++ b/src_rebuild/GAME/DR2LIMITS.H @@ -4,9 +4,11 @@ // DRIVER 2 game engine limits // please populate this file only with engine limits during refactoring -#define MAX_CARS 20 -#define MAX_CAR_MODELS 5 -#define MAX_PEDESTRIANS 28 -#define MAX_TRAFFIC_CARS 19 +#define MAX_CARS 20 +#define MAX_CAR_MODELS 5 +#define MAX_PEDESTRIANS 28 +#define MAX_TRAFFIC_CARS 19 +#define MAX_EXPLOSION_OBJECTS 5 +#define MAX_THROWN_BOMBS 5 #endif // DRLIMITS_H \ No newline at end of file From b6820f7b085cf495ec8bf0d5f9ec693544aa0ffd Mon Sep 17 00:00:00 2001 From: Ilya Shurumov Date: Wed, 7 Oct 2020 21:17:03 +0600 Subject: [PATCH 05/41] - add -startpos command line parameter --- src_rebuild/GAME/C/MAIN.C | 39 ++++++++++++++++++++++++++---------- src_rebuild/GAME/C/MAIN.H | 2 ++ src_rebuild/GAME/C/MISSION.C | 13 +++++++++++- 3 files changed, 42 insertions(+), 12 deletions(-) diff --git a/src_rebuild/GAME/C/MAIN.C b/src_rebuild/GAME/C/MAIN.C index 3769f72d..137fd739 100644 --- a/src_rebuild/GAME/C/MAIN.C +++ b/src_rebuild/GAME/C/MAIN.C @@ -42,7 +42,6 @@ #include "CIV_AI.H" #include "COP_AI.H" #include "CAMERA.H" -#include "EVENT.H" #include "OVERLAY.H" #include "DEBRIS.H" #include "JOB_FX.H" @@ -54,14 +53,10 @@ #include "DR2ROADS.H" #include "MODELS.H" #include "CARS.H" -#include "COP_AI.H" -#include "GLAUNCH.H" #include "OBJCOLL.H" #include "MC_SND.H" #include "FELONY.H" #include "LEADAI.H" -#include "ENVIRO.H" -#include "SEARCH.H" #include "LOADSAVE.H" #include "XAPLAY.H" @@ -89,6 +84,8 @@ int levelstartpos[8][4] = { { 0xFFFFDCDD, 0xFFFFE7ED, 0xF8A7, 0}, }; +XZPAIR gStartPos = { 0 }; + enum LevLumpType { // known lumps indexes @@ -217,6 +214,7 @@ extern SPEECH_QUEUE gSpeechQueue; bool gDriver1Level = false; bool gDemoLevel = false; +// [D] void ProcessLumps(char *lump_ptr, int lump_size) { int quit; @@ -2398,10 +2396,13 @@ void PrintCommandLineArguments() { const char* argumentsMessage = "Example: REDRIVER2 [arguments]\n\n" +#ifdef DEBUG_OPTIONS + " -startpos : Set player start position\n" " -players : Set player count (1 or 2)\n" " -playercar , -player2car : set player wanted car\n" - " -mission : starts specified mission\n" " -chase : using specified chase number for mission\n" + " -mission : starts specified mission\n" +#endif // DEBUG_OPTIONS " -replay : starts replay from file\n" #ifdef CUTSCENE_RECORDER " -recordcutscene : starts cutscene recorder session\n" @@ -2506,7 +2507,21 @@ int redriver2_main(int argc, char** argv) for (int i = 1; i < argc; i++) { - if (!_stricmp(argv[i], "-playercar")) +#ifdef DEBUG_OPTIONS + if (!_stricmp(argv[i], "-startpos")) + { + if (argc - i < 3) + { + printError("-startpos missing two number argument!"); + return -1; + } + + gStartPos.x = atoi(argv[i+1]); + gStartPos.z = atoi(argv[i+2]); + + i+=2; + } + else if (!_stricmp(argv[i], "-playercar")) { if (argc - i < 2) { @@ -2564,6 +2579,7 @@ int redriver2_main(int argc, char** argv) i++; LaunchGame(); } +#endif // _DEBUG_OPTIONS else if (!_stricmp(argv[i], "-nofmv")) { gNoFMV = 1; @@ -3269,8 +3285,9 @@ void InitGameVariables(void) PlayerStartInfo[0]->flags = 0; PlayerStartInfo[0]->rotation = levelstartpos[GameLevel][1]; - PlayerStartInfo[0]->position.vx = levelstartpos[GameLevel][0]; + PlayerStartInfo[0]->position.vy = 0; + PlayerStartInfo[0]->position.vx = levelstartpos[GameLevel][0]; PlayerStartInfo[0]->position.vz = levelstartpos[GameLevel][2]; numPlayersToCreate = 1; @@ -3285,9 +3302,11 @@ void InitGameVariables(void) PlayerStartInfo[1]->palette = defaultPlayerPalette; PlayerStartInfo[1]->controlType = CONTROL_TYPE_PLAYER; PlayerStartInfo[1]->flags = 0; + PlayerStartInfo[1]->rotation = levelstartpos[GameLevel][1]; - PlayerStartInfo[1]->position.vx = levelstartpos[GameLevel][0] + 600; + PlayerStartInfo[1]->position.vy = 0; + PlayerStartInfo[1]->position.vx = levelstartpos[GameLevel][0] + 600; PlayerStartInfo[1]->position.vz = levelstartpos[GameLevel][2]; numPlayersToCreate = NumPlayers; @@ -3308,9 +3327,7 @@ void InitGameVariables(void) } #endif // CUTSCENE_RECORDER - InitCivCars(); - return; } diff --git a/src_rebuild/GAME/C/MAIN.H b/src_rebuild/GAME/C/MAIN.H index 4e4bfc1e..9318ca78 100644 --- a/src_rebuild/GAME/C/MAIN.H +++ b/src_rebuild/GAME/C/MAIN.H @@ -3,6 +3,8 @@ extern int game_over; +extern XZPAIR gStartPos; + extern int xa_timeout; extern int FrameCnt; extern int CurrentPlayerView; diff --git a/src_rebuild/GAME/C/MISSION.C b/src_rebuild/GAME/C/MISSION.C index df8b582b..a79fd805 100644 --- a/src_rebuild/GAME/C/MISSION.C +++ b/src_rebuild/GAME/C/MISSION.C @@ -484,9 +484,20 @@ void LoadMission(int missionnum) if (gCutsceneAsReplay == 0) #endif { - PlayerStartInfo[0]->position.vx = MissionHeader->playerStartPosition.x; PlayerStartInfo[0]->rotation = MissionHeader->playerStartRotation; + + PlayerStartInfo[0]->position.vx = MissionHeader->playerStartPosition.x; PlayerStartInfo[0]->position.vz = MissionHeader->playerStartPosition.y; + +#ifdef DEBUG_OPTIONS + if(gStartPos.x != 0 && gStartPos.z != 0) + { + PlayerStartInfo[0]->rotation = 0; + PlayerStartInfo[0]->position.vx = gStartPos.x; + PlayerStartInfo[0]->position.vz = gStartPos.z; + } +#endif + PlayerStartInfo[0]->model = MissionHeader->playerCarModel; PlayerStartInfo[0]->palette = MissionHeader->playerCarColour; } From e5e79532760feb84bbef812821f6945ee8af8630 Mon Sep 17 00:00:00 2001 From: Ilya Shurumov Date: Thu, 8 Oct 2020 17:09:38 +0600 Subject: [PATCH 06/41] - fixed most of GetNextRoadInfo bugs --- src_rebuild/GAME/C/CIV_AI.C | 200 +++++++++++++++++------------------- 1 file changed, 95 insertions(+), 105 deletions(-) diff --git a/src_rebuild/GAME/C/CIV_AI.C b/src_rebuild/GAME/C/CIV_AI.C index 4cb0ee5c..d72408cd 100644 --- a/src_rebuild/GAME/C/CIV_AI.C +++ b/src_rebuild/GAME/C/CIV_AI.C @@ -534,15 +534,6 @@ void CivCarFX(_CAR_DATA* cp) /* WARNING: Type propagation algorithm not settling */ -int currentRoadId = 0; -int tmpNewRoad[2]; -int newExit = 0; -int tmpNewLane[2]; -int laneFit[2]; -DRIVER2_STRAIGHT* tmpStr[2]; -DRIVER2_CURVE* tmpCrv[2]; -short validExitIdx[4]; - // [D] [T] // BUGS: sometimes not getting right lane when road direction switched int GetNextRoadInfo(_CAR_DATA* cp, int randomExit, int* turnAngle, int* startDist, CIV_ROUTE_ENTRY* oldNode) @@ -550,8 +541,18 @@ int GetNextRoadInfo(_CAR_DATA* cp, int randomExit, int* turnAngle, int* startDis unsigned long junctionFlags; DRIVER2_JUNCTION* jn; + DRIVER2_ROAD_INFO currentRoadInfo; DRIVER2_ROAD_INFO roadInfo; + int currentRoadId = 0; + int tmpNewRoad[2]; + int newExit = 0; + int tmpNewLane[2]; + int laneFit[2]; + DRIVER2_STRAIGHT* tmpStr[2]; + DRIVER2_CURVE* tmpCrv[2]; + short validExitIdx[4]; + int newLane; int newRoad; @@ -562,15 +563,12 @@ int GetNextRoadInfo(_CAR_DATA* cp, int randomExit, int* turnAngle, int* startDis int oldOppDir; int oppDir; int turnDir; + int currentLaneDir; currentRoadId = cp->ai.c.currentRoad; - - //straight = NULL; - //curve = NULL; - if (GetSurfaceRoadInfo(&roadInfo, currentRoadId)) + if (GetSurfaceRoadInfo(¤tRoadInfo, currentRoadId)) { - int currentLaneDir; int widthInLanes; int laneNo; int count; @@ -578,27 +576,28 @@ int GetNextRoadInfo(_CAR_DATA* cp, int randomExit, int* turnAngle, int* startDis junctionIdx = -1; - widthInLanes = ROAD_WIDTH_IN_LANES(&roadInfo); + widthInLanes = ROAD_WIDTH_IN_LANES(¤tRoadInfo); - currentLaneDir = ROAD_LANE_DIR(&roadInfo, cp->ai.c.currentLane); - oldOppDir = currentLaneDir << 0xb; + currentLaneDir = ROAD_LANE_DIR(¤tRoadInfo, cp->ai.c.currentLane); - tmpNewRoad[0] = ((short*)roadInfo.ConnectIdx)[currentLaneDir * 2]; - - if (currentLaneDir != 0) - tmpNewRoad[1] = ((short*)roadInfo.ConnectIdx)[3]; - else - tmpNewRoad[1] = ((short*)roadInfo.ConnectIdx)[1]; - - /* - // [A] strict check for junction first - if (!IS_JUNCTION_SURFACE(tmpNewRoad[0]) && IS_JUNCTION_SURFACE(_st->ConnectIdx[currentLaneDir * 2 - 1])) + if (currentRoadInfo.straight) { - junctionIdx = _st->ConnectIdx[currentLaneDir * 2 - 1]; + oldOppDir = (currentRoadInfo.straight->angle - oldNode->dir) + 0x400U & 0x800; + } + else + { + int dx, dz; + dx = oldNode->x - currentRoadInfo.curve->Midx; + dz = oldNode->z - currentRoadInfo.curve->Midz; - if (junctionIdx != -1 && tmpNewRoad[0] != junctionIdx) - tmpNewRoad[0] = junctionIdx; - }*/ + oldOppDir = (((oldNode->dir - ratan2(dx, dz)) + 0x800U & 0xfff) - 0x800) < 1; + } + + // first road is picked from road direction + tmpNewRoad[0] = ((short*)currentRoadInfo.ConnectIdx)[(oldOppDir > 0) * 2]; + + // and second picked from lane direction + tmpNewRoad[1] = ((short*)currentRoadInfo.ConnectIdx)[(currentLaneDir > 0) ? 3 : 1]; count = widthInLanes; // counter laneNo = widthInLanes; // bestLane @@ -606,9 +605,9 @@ int GetNextRoadInfo(_CAR_DATA* cp, int randomExit, int* turnAngle, int* startDis do { count--; - if (ROAD_IS_AI_LANE(&roadInfo, count) && !ROAD_IS_PARKING_ALLOWED_AT(&roadInfo, count)) + if (ROAD_IS_AI_LANE(¤tRoadInfo, count) && !ROAD_IS_PARKING_ALLOWED_AT(¤tRoadInfo, count)) { - test42 = ROAD_LANE_DIR(&roadInfo, count); + test42 = ROAD_LANE_DIR(¤tRoadInfo, count); laneNo = count; } } while (count >= 0); @@ -618,15 +617,15 @@ int GetNextRoadInfo(_CAR_DATA* cp, int randomExit, int* turnAngle, int* startDis else rightLane = laneNo & 0xff; - // if speed lane, use other first lane. WTF idk why - count = ROAD_HAS_FAST_LANES(&roadInfo); // counter - laneNo = widthInLanes; // bestLane + // ifhas fast lane, use second lane + count = ROAD_HAS_FAST_LANES(¤tRoadInfo); + laneNo = widthInLanes; while (count < widthInLanes) { - if (ROAD_IS_AI_LANE(&roadInfo, count) && !ROAD_IS_PARKING_ALLOWED_AT(&roadInfo, count)) + if (ROAD_IS_AI_LANE(¤tRoadInfo, count) && !ROAD_IS_PARKING_ALLOWED_AT(¤tRoadInfo, count)) { - test555 = ROAD_LANE_DIR(&roadInfo, count) ^ 1; + test555 = ROAD_LANE_DIR(¤tRoadInfo, count) ^ 1; laneNo = count; if (test555 == 0) @@ -728,7 +727,7 @@ int GetNextRoadInfo(_CAR_DATA* cp, int randomExit, int* turnAngle, int* startDis if(roadInfo.straight) { - oppDir = (turnDir - roadInfo.straight->angle) + 1024U & 0x800; + oppDir = (roadInfo.straight->angle - turnDir) + 1024U & 0x800; } else { @@ -747,16 +746,9 @@ int GetNextRoadInfo(_CAR_DATA* cp, int randomExit, int* turnAngle, int* startDis if (turnAng == 0) // going forward { if (oppDir != oldOppDir) // next road is flipped - { newLane = ROAD_WIDTH_IN_LANES(&roadInfo) - (cp->ai.c.currentLane + 1); - - //if (newLane == 0) // [A] temporary hack - // newLane++; - } else - { newLane = cp->ai.c.currentLane; - } // goes on invalid lane? // [A] bug fix with exitDir == 0 @@ -818,11 +810,7 @@ int GetNextRoadInfo(_CAR_DATA* cp, int randomExit, int* turnAngle, int* startDis if (newLane > -1 && newLane < laneCount) { valid = ROAD_IS_AI_LANE(&roadInfo, newLane) && !ROAD_IS_PARKING_ALLOWED_AT(&roadInfo, newLane); - //printInfo("Valid exit: %d, dir: %d vs %d, turnDir: %d, oppDir: %d (%d), turnAng: %d\n", exitIdx, tmpSt->angle, oldNode->dir, turnDir, oppDir, (turnDir - tmpSt->angle) + 1024, turnAng); } - - //printInfo("car %d check %s, valid: %d\n", cp->id, (turnAng == 1024) ? "right" : (turnAng == -1024 ? "left" : "forward"), valid); - } } @@ -1099,6 +1087,7 @@ int GetNextRoadInfo(_CAR_DATA* cp, int randomExit, int* turnAngle, int* startDis } else { + // road continuation using connections int roadCnt; if (turnAngle == NULL) @@ -1111,14 +1100,12 @@ int GetNextRoadInfo(_CAR_DATA* cp, int randomExit, int* turnAngle, int* startDis newExit = -1; roadCnt = 0; - + + // check the connections + // determine new lanes on possible new roads based on the old node position for (roadCnt = 0; roadCnt < 2; roadCnt++) { - if (tmpNewRoad[roadCnt] == -1) - { - laneFit[roadCnt] = 666; - } - else + if (tmpNewRoad[roadCnt] != -1) { int dx, dz; int numLanes; @@ -1128,7 +1115,8 @@ int GetNextRoadInfo(_CAR_DATA* cp, int randomExit, int* turnAngle, int* startDis if (GetSurfaceRoadInfo(&roadInfo, tmpNewRoad[roadCnt])) { numLanes = ROAD_WIDTH_IN_LANES(&roadInfo); - + + // determine new lane by old node position if(roadInfo.straight) { int laneNo; @@ -1137,32 +1125,32 @@ int GetNextRoadInfo(_CAR_DATA* cp, int randomExit, int* turnAngle, int* startDis dx = (oldNode->x - roadInfo.straight->Midx); dz = (oldNode->z - roadInfo.straight->Midz); - test555 = dx * rcossin_tbl[(roadInfo.straight->angle & 0xfff) * 2 + 1] - dz * rcossin_tbl[(roadInfo.straight->angle & 0xfff) * 2]; - test42 = ROAD_LANES_COUNT(&roadInfo) - (FIXEDH(test555) + 512 >> 9); + //test555 = dx * rcossin_tbl[(roadInfo.straight->angle & 0xfff) * 2 + 1] - dz * rcossin_tbl[(roadInfo.straight->angle & 0xfff) * 2]; + //test42 = ROAD_LANES_COUNT(&roadInfo) - (FIXEDH(test555) + 512 >> 9); tmpStr[roadCnt] = roadInfo.straight; - tmpNewLane[roadCnt] = test42; + tmpNewLane[roadCnt] = ROAD_LANES_COUNT(&roadInfo) - (FIXEDH(dx * rcossin_tbl[(roadInfo.straight->angle & 0xfff) * 2 + 1] - dz * rcossin_tbl[(roadInfo.straight->angle & 0xfff) * 2]) + 512 >> 9); + // [A] I don't think that is needed + #if 0 count = numLanes; laneNo = numLanes; do { if (ROAD_IS_AI_LANE(&roadInfo, count) && !ROAD_IS_PARKING_ALLOWED_AT(&roadInfo, count)) { - test42 = (ROAD_LANE_DIR(&roadInfo, count) ^ 1) & 1; + //test42 = (ROAD_LANE_DIR(&roadInfo, count) ^ 1) & 1; laneNo = count; } count--; } while (count >= 0); - //if (laneNo == 0) // [A] temporary dirty hack. Still needed here, idk why - // laneNo++; - - if (laneNo < 0 || laneNo >= numLanes) // [A] and here. Was laneNo > numLanes + if (laneNo < 0 || laneNo >= numLanes) { laneFit[roadCnt] = 666; continue; } + #endif } else { @@ -1174,22 +1162,29 @@ int GetNextRoadInfo(_CAR_DATA* cp, int randomExit, int* turnAngle, int* startDis } } - test123 = tmpNewLane[roadCnt]; + // fit new lane + newLane = tmpNewLane[roadCnt]; - if (test123 < 0) - laneFit[roadCnt] = test123; - else if (test123 <= numLanes - 1) + if (newLane < 0) + laneFit[roadCnt] = newLane; + else if (newLane <= numLanes - 1) laneFit[roadCnt] = 0; else - laneFit[roadCnt] = test123 - numLanes - 1; + laneFit[roadCnt] = newLane - numLanes - 1; + // clamp lane if (tmpNewLane[roadCnt] >= numLanes - 1) tmpNewLane[roadCnt] = numLanes - 1; - newExit = roadCnt; - if (tmpNewLane[roadCnt] < 0) tmpNewLane[roadCnt] = 0; + + // set this a s correct exit + newExit = roadCnt; + } + else + { + laneFit[roadCnt] = 666; } } @@ -1219,8 +1214,7 @@ int GetNextRoadInfo(_CAR_DATA* cp, int randomExit, int* turnAngle, int* startDis if(roadInfo.straight) { - oppDir = (oldNode->dir - roadInfo.straight->angle) + 0x400U & 0x800; - test123 = oppDir; + oppDir = (oldNode->dir - roadInfo.straight->angle) + 0x400U & 0x800 > 0; } else { @@ -1231,11 +1225,15 @@ int GetNextRoadInfo(_CAR_DATA* cp, int randomExit, int* turnAngle, int* startDis oppDir = (((oldNode->dir - ratan2(dx, dz)) + 0x800U & 0xfff) - 0x800) < 1; } - if (laneDirCorrect && oppDir == 0 || !laneDirCorrect && oppDir != 0) + // road width might be changed too, so we have to clamp it + if (laneDirCorrect != oppDir) { + //&& ROAD_WIDTH_IN_LANES(¤tRoadInfo) != numLanes + + // find drivable leftmost and rightmost lane laneFromLeft = numLanes; - laneFromRight = 0; - + laneFromRight = -1; + count = numLanes; do @@ -1284,7 +1282,7 @@ int GetNextRoadInfo(_CAR_DATA* cp, int randomExit, int* turnAngle, int* startDis if (laneFromLeft < 0) laneFromLeft = 42; - + if (laneFromRight >= numLanes) laneFromRight = 42; @@ -1294,12 +1292,15 @@ int GetNextRoadInfo(_CAR_DATA* cp, int randomExit, int* turnAngle, int* startDis return 0; } - - // [A] this is bugged still + // swap if (ABS(laneFromRight - newLane) < ABS(laneFromLeft - newLane)) + { + int tmp = laneFromRight; laneFromRight = laneFromLeft; + laneFromLeft = tmp; + } - + // it doesn't work well laneFit[newExit] = laneFromRight; if (laneFromRight > -1) @@ -1310,8 +1311,10 @@ int GetNextRoadInfo(_CAR_DATA* cp, int randomExit, int* turnAngle, int* startDis laneFit[newExit] = 0; } + // [A] IDK... this is bugged. Might get back to it any time + /* int oldLane = newLane; - + if (laneFromRight >= numLanes - 1) newLane = numLanes - 1; //else @@ -1319,25 +1322,14 @@ int GetNextRoadInfo(_CAR_DATA* cp, int randomExit, int* turnAngle, int* startDis if (newLane < 0) newLane = 0; + */ } } if (laneFit[newExit] != 0) { cp->ai.c.turnNode = GET_NODE_ID(cp, GET_NEXT_NODE(cp, oldNode)); - - if (IS_STRAIGHT_SURFACE(newRoad)) - { - cp->ai.c.turnDir = (ROAD_LANE_DIR(tmpStr[newExit], laneFit[newExit]) ^ 1) & 1; - } - else - { - cp->ai.c.turnDir = (ROAD_LANE_DIR(tmpCrv[newExit], laneFit[newExit]) ^ 1) & 1; - } - - //printWarning("new turn dir: %d\n", cp->ai.c.turnDir); - - //cp->ai.c.turnDir = bVar6; + cp->ai.c.turnDir = ROAD_LANE_DIR(&roadInfo, laneFit[newExit]); } } } @@ -1351,9 +1343,6 @@ int GetNextRoadInfo(_CAR_DATA* cp, int randomExit, int* turnAngle, int* startDis // determine distance and speed limit if (startDist != NULL) { - //DRIVER2_CURVE* curve; - //DRIVER2_STRAIGHT* straight; - if (GetSurfaceRoadInfo(&roadInfo, newRoad)) { if(roadInfo.straight) @@ -1375,14 +1364,15 @@ int GetNextRoadInfo(_CAR_DATA* cp, int randomExit, int* turnAngle, int* startDis } } + if (newRoad < 0) + { + CIV_STATE_SET_CONFUSED(cp); + return 0; + } + cp->ai.c.currentLane = newLane; - if (newRoad > -1) - return newRoad; - - CIV_STATE_SET_CONFUSED(cp); - - return 0; + return newRoad; } @@ -4039,7 +4029,7 @@ int CivControl(_CAR_DATA * cp) if (cp->ai.c.thrustState != 3) cp->wheel_angle = CivSteerAngle(cp); -#if 0 +#if 1 { //maxCivCars = 2; //maxCopCars = 0; From d9ea1e105460b7a8d35ecfaed965852a4d690555 Mon Sep 17 00:00:00 2001 From: Ilya Shurumov Date: Thu, 8 Oct 2020 17:19:05 +0600 Subject: [PATCH 07/41] - fix follow camera jerking --- src_rebuild/GAME/C/CAMERA.C | 6 +++++- src_rebuild/GAME/C/CIV_AI.C | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src_rebuild/GAME/C/CAMERA.C b/src_rebuild/GAME/C/CAMERA.C index 41d9e902..a0af6c1f 100644 --- a/src_rebuild/GAME/C/CAMERA.C +++ b/src_rebuild/GAME/C/CAMERA.C @@ -753,7 +753,11 @@ void PlaceCameraFollowCar(_PLAYER *lp) lp->cameraPos.vx = basePos[0] + FIXEDH(lp->cameraDist * rcossin_tbl[(jcam->hd.direction & 0xfff) * 2]); lp->cameraPos.vz = basePos[2] + FIXEDH(lp->cameraDist * rcossin_tbl[(jcam->hd.direction & 0xfff) * 2 + 1]); - camera_angle.vy = -(jcam->hd.direction + 2048);//-ratan2(basePos[0] - lp->cameraPos.vx, basePos[2] - lp->cameraPos.vz) & 0xfff; + if (lp->cameraCarId < 0) + camera_angle.vy = -(jcam->hd.direction + 2048); + else + camera_angle.vy = -ratan2(basePos[0] - lp->cameraPos.vx, basePos[2] - lp->cameraPos.vz) & 0xfff; + camera_angle.vz = 0; SetGeomScreen(256); diff --git a/src_rebuild/GAME/C/CIV_AI.C b/src_rebuild/GAME/C/CIV_AI.C index d72408cd..7561fefa 100644 --- a/src_rebuild/GAME/C/CIV_AI.C +++ b/src_rebuild/GAME/C/CIV_AI.C @@ -4029,7 +4029,7 @@ int CivControl(_CAR_DATA * cp) if (cp->ai.c.thrustState != 3) cp->wheel_angle = CivSteerAngle(cp); -#if 1 +#if 0 { //maxCivCars = 2; //maxCopCars = 0; From a1b33f2f28575eeed2b5466b206227f24c359676 Mon Sep 17 00:00:00 2001 From: Ilya Shurumov Date: Thu, 8 Oct 2020 19:00:41 +0600 Subject: [PATCH 08/41] - fix civ AI bugs seen in Havana docks --- src_rebuild/GAME/C/CIV_AI.C | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src_rebuild/GAME/C/CIV_AI.C b/src_rebuild/GAME/C/CIV_AI.C index 7561fefa..32598dc4 100644 --- a/src_rebuild/GAME/C/CIV_AI.C +++ b/src_rebuild/GAME/C/CIV_AI.C @@ -64,6 +64,7 @@ int test555 = 0; #define CIV_STATE_SET_CONFUSED(cp) \ cp->ai.c.thrustState = 3; cp->ai.c.ctrlState = 7; + // decompiled code // original method signature: // int /*$ra*/ InitCar(struct _CAR_DATA *cp /*$s0*/, int direction /*$s6*/, long (*startPos)[4] /*$s2*/, unsigned char control /*$s4*/, int model /*stack 16*/, int palette /*stack 20*/, char *extraData /*stack 24*/) @@ -590,7 +591,8 @@ int GetNextRoadInfo(_CAR_DATA* cp, int randomExit, int* turnAngle, int* startDis dx = oldNode->x - currentRoadInfo.curve->Midx; dz = oldNode->z - currentRoadInfo.curve->Midz; - oldOppDir = (((oldNode->dir - ratan2(dx, dz)) + 0x800U & 0xfff) - 0x800) < 1; + oldOppDir = (((oldNode->dir - ratan2(dx, dz)) + 0x800U & 0xfff) - 0x800); + oldOppDir = (oldOppDir < 1) << 0xb; } // first road is picked from road direction @@ -984,7 +986,7 @@ int GetNextRoadInfo(_CAR_DATA* cp, int randomExit, int* turnAngle, int* startDis } else { - newLane = numLanes - cp->ai.c.currentLane + 1; + newLane = numLanes - (cp->ai.c.currentLane + 1); //if (newLane == 0)// [A] temporary hack // newLane++; @@ -1132,7 +1134,7 @@ int GetNextRoadInfo(_CAR_DATA* cp, int randomExit, int* turnAngle, int* startDis tmpNewLane[roadCnt] = ROAD_LANES_COUNT(&roadInfo) - (FIXEDH(dx * rcossin_tbl[(roadInfo.straight->angle & 0xfff) * 2 + 1] - dz * rcossin_tbl[(roadInfo.straight->angle & 0xfff) * 2]) + 512 >> 9); // [A] I don't think that is needed - #if 0 + count = numLanes; laneNo = numLanes; do @@ -1150,7 +1152,7 @@ int GetNextRoadInfo(_CAR_DATA* cp, int randomExit, int* turnAngle, int* startDis laneFit[roadCnt] = 666; continue; } - #endif + } else { @@ -1226,10 +1228,8 @@ int GetNextRoadInfo(_CAR_DATA* cp, int randomExit, int* turnAngle, int* startDis } // road width might be changed too, so we have to clamp it - if (laneDirCorrect != oppDir) + if (laneDirCorrect != oppDir) // && ROAD_WIDTH_IN_LANES(¤tRoadInfo) != numLanes) { - //&& ROAD_WIDTH_IN_LANES(¤tRoadInfo) != numLanes - // find drivable leftmost and rightmost lane laneFromLeft = numLanes; laneFromRight = -1; @@ -1293,13 +1293,13 @@ int GetNextRoadInfo(_CAR_DATA* cp, int randomExit, int* turnAngle, int* startDis } // swap - if (ABS(laneFromRight - newLane) < ABS(laneFromLeft - newLane)) + if (ABS(laneFromRight - newLane) >= ABS(laneFromLeft - newLane)) { int tmp = laneFromRight; laneFromRight = laneFromLeft; laneFromLeft = tmp; } - + /* // it doesn't work well laneFit[newExit] = laneFromRight; @@ -1312,7 +1312,7 @@ int GetNextRoadInfo(_CAR_DATA* cp, int randomExit, int* turnAngle, int* startDis } // [A] IDK... this is bugged. Might get back to it any time - /* + int oldLane = newLane; if (laneFromRight >= numLanes - 1) @@ -1323,6 +1323,7 @@ int GetNextRoadInfo(_CAR_DATA* cp, int randomExit, int* turnAngle, int* startDis if (newLane < 0) newLane = 0; */ + } } @@ -4029,7 +4030,7 @@ int CivControl(_CAR_DATA * cp) if (cp->ai.c.thrustState != 3) cp->wheel_angle = CivSteerAngle(cp); -#if 0 +#if 1 { //maxCivCars = 2; //maxCopCars = 0; From 41704621a87e5229c604d73e97924b4bfbcca725 Mon Sep 17 00:00:00 2001 From: Ilya Shurumov Date: Thu, 8 Oct 2020 21:25:40 +0600 Subject: [PATCH 09/41] - load custom cutscenes/chases to separate buffer --- src_rebuild/DebugOverlay.cpp | 23 ++++++++++--------- src_rebuild/GAME/C/CUTSCENE.C | 42 ++++++++++++++++++++--------------- src_rebuild/GAME/C/PAUSE.C | 2 +- 3 files changed, 38 insertions(+), 29 deletions(-) diff --git a/src_rebuild/DebugOverlay.cpp b/src_rebuild/DebugOverlay.cpp index 7218a31c..a968ee49 100644 --- a/src_rebuild/DebugOverlay.cpp +++ b/src_rebuild/DebugOverlay.cpp @@ -3,17 +3,17 @@ #include "LIBGTE.H" #include "LIBGPU.H" #include "INLINE_C.H" -#include "GTEREG.H" +#include "C/MISSION.H" -#include "GAME/ASM/ASMTEST.H" -#include "GAME/C/CONVERT.H" -#include "GAME/C/CAMERA.H" -#include "GAME/C/DRAW.H" -#include "GAME/C/SYSTEM.H" -#include "GAME/C/PRES.H" -#include "GAME/C/SPOOL.H" -#include "GAME/C/CARS.H" -#include "GAME/C/PLAYERS.H" +#include "C/CONVERT.H" +#include "C/CAMERA.H" +#include "C/DRAW.H" +#include "C/SYSTEM.H" +#include "C/PRES.H" +#include "C/SPOOL.H" +#include "C/CARS.H" +#include "C/PLAYERS.H" +#include "C/GLAUNCH.H" int gDisplayDrawStats = 0; @@ -112,6 +112,9 @@ void DrawDebugOverlays() sprintf(tempBuf, "Car speed: %d", speed); PrintString(tempBuf, 10, 60); + + sprintf(tempBuf, "Mission %d Chase: %d", gCurrentMissionNumber, gRandomChase); + PrintString(tempBuf, 10, 70); } } diff --git a/src_rebuild/GAME/C/CUTSCENE.C b/src_rebuild/GAME/C/CUTSCENE.C index 40f6ce88..ebbc65e7 100644 --- a/src_rebuild/GAME/C/CUTSCENE.C +++ b/src_rebuild/GAME/C/CUTSCENE.C @@ -54,6 +54,10 @@ PLAYBACKCAMERA *CutsceneCamera = NULL; static int CutsceneCameraOffset = 0; +#ifndef PSX +char* gCustomCutsceneBuffer; +#endif + // decompiled code // original method signature: // void /*$ra*/ InitInGameCutsceneVariables() @@ -1318,6 +1322,20 @@ int LoadCutsceneToBuffer(int subindex) #ifndef PSX // [A] REDRIVER2 PC - custom cutcenes or chases for debugging sprintf(customFilename, "REPLAYS\\CUT%d\\%d.D2RP", gCurrentMissionNumber, subindex); + + if (FileExists(customFilename)) + { + printInfo("Custom cutscene replay file loaded\n"); + size = LoadfileSeg(customFilename, gCustomCutsceneBuffer, 0, 0xffff); + + // load into custom buffer + CutsceneBuffer.residentCutscenes[CutsceneBuffer.numResident] = subindex; + CutsceneBuffer.residentPointers[CutsceneBuffer.numResident] = gCustomCutsceneBuffer; + CutsceneBuffer.numResident++; + + gCustomCutsceneBuffer += size; + return 1; + } #endif if (CutsceneBuffer.bytesFree < size) { @@ -1328,27 +1346,11 @@ int LoadCutsceneToBuffer(int subindex) CutsceneBuffer.currentPointer = _other_buffer2; CutsceneBuffer.bytesFree = 0xc000; -#ifndef PSX - if (FileExists(customFilename)) - { - printInfo("Custom cutscene replay file loaded\n"); - LoadfileSeg(customFilename, _other_buffer2, 0, size); - } - else -#endif - LoadfileSeg(filename, _other_buffer2, offset, size); + LoadfileSeg(filename, _other_buffer2, offset, size); } else { -#ifndef PSX - if (FileExists(customFilename)) - { - printInfo("Custom cutscene replay file loaded\n"); - LoadfileSeg(customFilename, _other_buffer2, 0, size); - } - else -#endif - LoadfileSeg(filename, CutsceneBuffer.currentPointer, offset, size); + LoadfileSeg(filename, CutsceneBuffer.currentPointer, offset, size); } CutsceneBuffer.residentCutscenes[CutsceneBuffer.numResident] = subindex; @@ -1527,6 +1529,10 @@ void FreeCutsceneBuffer(void) CutsceneBuffer.bytesFree = sizeof(CutsceneBuffer.buffer); ClearMem(CutsceneBuffer.buffer, sizeof(CutsceneBuffer.buffer)); + +#ifndef PSX + gCustomCutsceneBuffer = _other_buffer2; +#endif } diff --git a/src_rebuild/GAME/C/PAUSE.C b/src_rebuild/GAME/C/PAUSE.C index 218a2a27..08ed2b09 100644 --- a/src_rebuild/GAME/C/PAUSE.C +++ b/src_rebuild/GAME/C/PAUSE.C @@ -679,7 +679,7 @@ void SaveReplay(int direction) CallMemoryCard(0x10, 1); #else int size = SaveReplayToBuffer(_other_buffer); - + FILE* fp = fopen("chase.d2rp", "wb"); if (fp) { From ca181c1661cb8acdb6e07d5a5ddbea210937f42f Mon Sep 17 00:00:00 2001 From: Ilya Shurumov Date: Fri, 9 Oct 2020 00:18:14 +0600 Subject: [PATCH 10/41] - fix CIV AI bug - fix collision code mistake --- src_rebuild/GAME/C/BCOLLIDE.C | 2 +- src_rebuild/GAME/C/CIV_AI.C | 10 +++++----- src_rebuild/GAME/C/LOADVIEW.C | 3 ++- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src_rebuild/GAME/C/BCOLLIDE.C b/src_rebuild/GAME/C/BCOLLIDE.C index 9a43fba1..64609aec 100644 --- a/src_rebuild/GAME/C/BCOLLIDE.C +++ b/src_rebuild/GAME/C/BCOLLIDE.C @@ -1226,7 +1226,7 @@ int CarBuildingCollision(_CAR_DATA *cp, BUILDING_BOX *building, CELL_OBJECT *cop while (sip->name != NULL) { - if (modelpointers[sip->modelIdx] == model) + if (sip->modelIdx == cop->type) { match = sip; break; diff --git a/src_rebuild/GAME/C/CIV_AI.C b/src_rebuild/GAME/C/CIV_AI.C index 32598dc4..83fb6165 100644 --- a/src_rebuild/GAME/C/CIV_AI.C +++ b/src_rebuild/GAME/C/CIV_AI.C @@ -62,6 +62,7 @@ int test555 = 0; #define GET_NODE_ID(cp, node) int((node) - cp->ai.c.targetRoute) #define CIV_STATE_SET_CONFUSED(cp) \ + printInfo("CIV confused: at %s, %d\n", __FUNCTION__, __LINE__);\ cp->ai.c.thrustState = 3; cp->ai.c.ctrlState = 7; @@ -1101,8 +1102,6 @@ int GetNextRoadInfo(_CAR_DATA* cp, int randomExit, int* turnAngle, int* startDis *turnAngle = 0; newExit = -1; - roadCnt = 0; - // check the connections // determine new lanes on possible new roads based on the old node position for (roadCnt = 0; roadCnt < 2; roadCnt++) @@ -1141,7 +1140,8 @@ int GetNextRoadInfo(_CAR_DATA* cp, int randomExit, int* turnAngle, int* startDis { if (ROAD_IS_AI_LANE(&roadInfo, count) && !ROAD_IS_PARKING_ALLOWED_AT(&roadInfo, count)) { - //test42 = (ROAD_LANE_DIR(&roadInfo, count) ^ 1) & 1; + // this line below needed because fucking compiler seem to be omitting it completely + test42 = (ROAD_LANE_DIR(&roadInfo, count) ^ 1) & 1; laneNo = count; } count--; @@ -3852,7 +3852,7 @@ int PingInCivCar(int minPingInDist) carCnt++; } - if (retDistSq != 56) // [A] This was decompiled wrong. Can't get the meaning for it + //if (retDistSq != 56) // [A] This was decompiled wrong. Can't get the meaning for it distSq = retDistSq; if (distSq < (lbody * lbody * 8 * 8)) @@ -4030,7 +4030,7 @@ int CivControl(_CAR_DATA * cp) if (cp->ai.c.thrustState != 3) cp->wheel_angle = CivSteerAngle(cp); -#if 1 +#if 0 { //maxCivCars = 2; //maxCopCars = 0; diff --git a/src_rebuild/GAME/C/LOADVIEW.C b/src_rebuild/GAME/C/LOADVIEW.C index 231707c9..0967a9df 100644 --- a/src_rebuild/GAME/C/LOADVIEW.C +++ b/src_rebuild/GAME/C/LOADVIEW.C @@ -56,7 +56,8 @@ void ShowLoading(void) { POLY_G4 poly; - if ((NewLevel != 0) || (gInFrontend != 0)) { + if (NewLevel != 0 || gInFrontend != 0) + { int col = (VERTTYPE)(++loading_bar_pos * load_steps); if (col > 120) From 3ca59a4489220274f49e8dc835e23efcf8d79112 Mon Sep 17 00:00:00 2001 From: Ilya Shurumov Date: Fri, 9 Oct 2020 00:18:33 +0600 Subject: [PATCH 11/41] - LoadCurrentProfile to clear screen --- src_rebuild/GAME/C/LOADSAVE.C | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src_rebuild/GAME/C/LOADSAVE.C b/src_rebuild/GAME/C/LOADSAVE.C index 15876717..06b5d6e9 100644 --- a/src_rebuild/GAME/C/LOADSAVE.C +++ b/src_rebuild/GAME/C/LOADSAVE.C @@ -106,6 +106,17 @@ void LoadCurrentProfile() SetTextColour(128, 128, 64); ShowSavingWaitMessage("Loading configuration...", 0); + { + RECT16 rect; + rect.x = 0; + rect.y = 0; + rect.w = 320; + rect.h = 512; + + ClearImage(&rect, 0, 0, 0); + DrawSync(0); + } + error = 1; // load config @@ -126,6 +137,10 @@ void LoadCurrentProfile() error = 0; } } + else + { + ShowSavingWaitMessage("No saved data", 0); + } if (error) { From ce7139b94c195642b7bb0bd4b1a7e6345312704d Mon Sep 17 00:00:00 2001 From: Ilya Shurumov Date: Fri, 9 Oct 2020 00:18:59 +0600 Subject: [PATCH 12/41] - fix cutscene pedestrians getting stuck --- src_rebuild/GAME/C/PEDEST.C | 236 +++++++++++++++++------------------- 1 file changed, 109 insertions(+), 127 deletions(-) diff --git a/src_rebuild/GAME/C/PEDEST.C b/src_rebuild/GAME/C/PEDEST.C index 7fe83d2f..d1de0250 100644 --- a/src_rebuild/GAME/C/PEDEST.C +++ b/src_rebuild/GAME/C/PEDEST.C @@ -70,8 +70,8 @@ pedFunc fpPedPersonalityFunctions[] = { VECTOR tannerLookAngle = { 0, 0, 0, 0 }; -int tannerTurnMax = 16; -int tannerTurnStep = 4; +const int tannerTurnMax = 16; +const int tannerTurnStep = 4; long force[4] = { 0x9000, 0, 0, 0 }; long point[4] = { 0, 0, 90, 0 }; @@ -1094,6 +1094,7 @@ int ActivatePlayerPedestrian(_CAR_DATA *pCar, char *padId, int direction, long(* } pedptr->doing_turn = 0; + gGotInStolenCar = 0; bKillTanner = 0; bKilled = 0; @@ -1101,6 +1102,7 @@ int ActivatePlayerPedestrian(_CAR_DATA *pCar, char *padId, int direction, long(* if (gCurrentMissionNumber == 23 && playerType != TANNER_MODEL) { pedptr->doing_turn = 16; + pedptr->dir.vy = (pedptr->dir.vy - (tannerTurnMax + 16) * tannerTurnStep) + 294; } @@ -1701,7 +1703,7 @@ void SetupDoNowt(PEDESTRIAN *pPed) { pPed->speed = 0; pPed->dir.vz = 0; - pPed->doing_turn = 0; + //pPed->doing_turn = 0; pPed->type = PED_ACTION_BACK; SetupPedMotionData(pPed); @@ -1895,109 +1897,101 @@ void CopStand(PEDESTRIAN *pPed) int iAllowWatch = 0; +//int tannerTurn = 0; + // [D] void PedDoNothing(PEDESTRIAN *pPed) { pPed->speed = 0; - if ((pPed->flags & 0x10U) == 0) + if ((pPed->flags & 0x10U) == 0) { SetupDoNowt(pPed); - pPed->flags = pPed->flags | 0x10; + pPed->flags |= 0x10; } - if ((tannerPad & 0x1040) != 0) + if (tannerPad & 0x1040) { pPed->interest = 0; pPed->flags &= ~0x10; - pPed->fpAgitatedState = PedUserRunner; + pPed->fpAgitatedState = fpPedPersonalityFunctions[2]; + SetupRunner(pPed); - goto LAB_0006f530; } - - if ((tannerPad & 0x4080) != 0) + else if (tannerPad & 0x4080) { pPed->interest = 0; pPed->flags &= ~0x10; - pPed->fpAgitatedState = PedUserWalker; + pPed->fpAgitatedState = fpPedPersonalityFunctions[1]; + SetupBack(pPed); - - goto LAB_0006f530; } - - if ((tannerPad & 0x2000) == 0) - { - if ((tannerPad & 0x8000) == 0) - { - pPed->frame1 = 0; - - pPed->interest++; // idle timer is this now - - if (pPed->doing_turn < 0) - { - pPed->doing_turn += 2; - - if (0 < pPed->doing_turn) - { - pPed->doing_turn = 0; - goto LAB_0006f4a8; - } - } - else - { - LAB_0006f4a8: - if (0 < pPed->doing_turn) - { - pPed->doing_turn -= 2; - - if(pPed->doing_turn < 0) - pPed->doing_turn = 0; - } - } - - if (pPed->doing_turn != 0) - { - if (pPed->doing_turn < 0) - pPed->dir.vy = pPed->dir.vy + 64 - (pPed->doing_turn + tannerTurnMax) * tannerTurnStep; - else - pPed->dir.vy = pPed->dir.vy - 64 + (tannerTurnMax - pPed->doing_turn) * tannerTurnStep; - } - - goto LAB_0006f530; - } - - pPed->interest = 0; - pPed->doing_turn += 2; - - if (tannerTurnMax < pPed->doing_turn) - pPed->doing_turn = tannerTurnMax; - - pPed->frame1++; - pPed->dir.vy += -64 + (tannerTurnMax - pPed->doing_turn) * tannerTurnStep; - - if (pPed->frame1 > 15) - pPed->frame1 = 0; - } - else + else if (tannerPad & 0x2000) { pPed->interest = 0; + pPed->doing_turn -= 2; - + if (pPed->doing_turn < -tannerTurnMax) pPed->doing_turn = -tannerTurnMax; - pPed->dir.vy += 64 - (pPed->doing_turn + tannerTurnMax) * tannerTurnStep; - + pPed->dir.vy = pPed->dir.vy + 64 - (pPed->doing_turn + tannerTurnMax) * tannerTurnStep; + if (pPed->frame1 == 0) pPed->frame1 = 15; else pPed->frame1--; - } - pPed->head_rot = 0; -LAB_0006f530: - if (pPed->interest > 119) + pPed->head_rot = 0; + } + else if (tannerPad & 0x8000) + { + pPed->interest = 0; + + pPed->doing_turn += 2; + + if (pPed->doing_turn > tannerTurnMax) + pPed->doing_turn = tannerTurnMax; + + pPed->dir.vy = pPed->dir.vy - 64 + (tannerTurnMax - pPed->doing_turn) * tannerTurnStep; + + if (pPed->frame1 > 16) + pPed->frame1 = 0; + + pPed->head_rot = 0; + } + else + { + pPed->frame1 = 0; + pPed->interest += 1; + + if (pPed->doing_turn < 0) + { + pPed->doing_turn += 2; + + if (pPed->doing_turn > 0) + pPed->doing_turn = 0; + } + + if (pPed->doing_turn > 0) + { + pPed->doing_turn -= 2; + + if(pPed->doing_turn < 0) + pPed->doing_turn = 0; + } + + if (pPed->doing_turn != 0) + { + if (pPed->doing_turn < 0) + pPed->dir.vy = pPed->dir.vy + 64 - (pPed->doing_turn + tannerTurnMax) * tannerTurnStep; + else + pPed->dir.vy = pPed->dir.vy - 64 + (tannerTurnMax - pPed->doing_turn) * tannerTurnStep; + } + } + + if (pPed->interest > 119) { pPed->frame1 = 0; pPed->type = PED_ACTION_TIME; @@ -2005,15 +1999,15 @@ LAB_0006f530: SetupPedMotionData(pPed); pPed->flags |= 0x10; - pPed->fpAgitatedState = PedCarryOutAnimation; - + pPed->fpAgitatedState = fpPedPersonalityFunctions[5]; pPed->interest = -2; - + if (pPed->type == PED_ACTION_TIME) iAllowWatch = 3; if (iAllowWatch != 0) iAllowWatch--; + } } @@ -2038,90 +2032,78 @@ LAB_0006f530: // [D] void PedUserRunner(PEDESTRIAN *pPed) { - if ((pPed->flags & 0x10U) == 0) { SetupRunner(pPed); } - if ((tannerPad & 0x1040) == 0) + if (tannerPad & 0x1040) + { + if (bStopTanner == 0) + pPed->speed = 40 - (tannerDeathTimer >> 1); + else + pPed->speed = 0; + } + else { pPed->dir.vz = 0; pPed->speed = 0; pPed->fpAgitatedState = NULL; pPed->flags &= ~0x10; } - else - { - if (bStopTanner == 0) - pPed->speed = 40 - (tannerDeathTimer >> 1); - else - pPed->speed = 0; - } - - if ((tannerPad & 0x2000) != 0) + + if (tannerPad & 0x2000) { + if (pPed->dir.vz > -80) + pPed->dir.vz -= 20; + pPed->doing_turn -= 2; - + if (pPed->doing_turn < -tannerTurnMax) pPed->doing_turn = -tannerTurnMax; pPed->head_rot = 0; - - if (pPed->dir.vz > -80) - pPed->dir.vz -= 20; - pPed->dir.vy = pPed->dir.vy + 64 - (pPed->doing_turn + tannerTurnMax) * tannerTurnStep; - - AnimatePed(pPed); - return; } - - if ((tannerPad & 0x8000) != 0) + else if (tannerPad & 0x8000) { - pPed->doing_turn += 2; - - if (tannerTurnMax < pPed->doing_turn) - pPed->doing_turn = tannerTurnMax; - - pPed->head_rot = 0; - if (pPed->dir.vz < 80) pPed->dir.vz += 20; - pPed->dir.vy = pPed->dir.vy - 64 + (tannerTurnMax - pPed->doing_turn) * tannerTurnStep; - - AnimatePed(pPed); - return; - } - - if (pPed->dir.vz < 0) - pPed->dir.vz += 20; - else if (pPed->dir.vz > 0) - pPed->dir.vz -= 20; - - if (pPed->doing_turn < 0) - { pPed->doing_turn += 2; - if (pPed->doing_turn > 0) - { - pPed->doing_turn = 0; - goto code_r0x0006f79c; - } + + if (pPed->doing_turn > tannerTurnMax) + pPed->doing_turn = tannerTurnMax; + + pPed->head_rot = 0; + pPed->dir.vy = pPed->dir.vy - 64 + (tannerTurnMax - pPed->doing_turn) * tannerTurnStep; } else { - code_r0x0006f79c: - if (pPed->doing_turn > 0) + if (pPed->dir.vz < 0) + pPed->dir.vz += 40; + + if (pPed->dir.vz > 0) + pPed->dir.vz -= 40; + + if (pPed->doing_turn < 0) + { + pPed->doing_turn += 2; + if (pPed->doing_turn > 0) + pPed->doing_turn = 0; + } + + if(pPed->doing_turn > 0) { pPed->doing_turn -= 2; if (pPed->doing_turn < 0) pPed->doing_turn = 0; } + + pPed->dir.vy = pPed->dir.vy - 64 + (tannerTurnMax - pPed->doing_turn) * tannerTurnStep; } - pPed->dir.vy = pPed->dir.vy - 64 + (tannerTurnMax - pPed->doing_turn) * tannerTurnStep; AnimatePed(pPed); } From f03ac0459f70e8fe491134ca5411013c46c87c95 Mon Sep 17 00:00:00 2001 From: Ilya Shurumov Date: Fri, 9 Oct 2020 11:09:28 +0600 Subject: [PATCH 13/41] - fix CIV AI node debug drawing --- src_rebuild/GAME/C/CIV_AI.C | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src_rebuild/GAME/C/CIV_AI.C b/src_rebuild/GAME/C/CIV_AI.C index 83fb6165..74a64cfb 100644 --- a/src_rebuild/GAME/C/CIV_AI.C +++ b/src_rebuild/GAME/C/CIV_AI.C @@ -4097,10 +4097,7 @@ int CivControl(_CAR_DATA * cp) Debug_AddLineOfs(_zero, ofs, b1p, rrcv); } - pn++; - - if (pn > cp->ai.c.targetRoute + 13) - pn -= 12; + pn = GET_NEXT_NODE(cp, pn); } } From abfe25c9d961d92b47f1ef87b092be8f69109033 Mon Sep 17 00:00:00 2001 From: Ilya Shurumov Date: Fri, 9 Oct 2020 14:43:22 +0600 Subject: [PATCH 14/41] - fix & improve CellEmpty bugs (cops in tunnels) --- src_rebuild/GAME/C/OBJCOLL.C | 169 ++++++++++++++++++++++++++++------- 1 file changed, 136 insertions(+), 33 deletions(-) diff --git a/src_rebuild/GAME/C/OBJCOLL.C b/src_rebuild/GAME/C/OBJCOLL.C index 0f7e39dc..306ab6de 100644 --- a/src_rebuild/GAME/C/OBJCOLL.C +++ b/src_rebuild/GAME/C/OBJCOLL.C @@ -81,30 +81,29 @@ char CellEmpty(VECTOR *pPosition, int radius) int num_cb; int box_loop; int sphere_sq; - int iVar1; + int zd; int iVar2; int iVar3; - uint uVar4; - int iVar5; + uint theta; + int sn; int* piVar6; - int iVar7; - int iVar8; + int ypos; + int cs; COLLISION_PACKET* collide; - int iVar9; - int iVar10; - int iVar11; + int xs; + int zs; + int xd; + int cell_x, cell_z; CELL_ITERATOR ci; - iVar3 = pPosition->vx + units_across_halved; - iVar1 = pPosition->vz + units_down_halved; + cell_x = (pPosition->vx + units_across_halved) / 2048; + cell_z = (pPosition->vz + units_down_halved) / 2048; - ppco = GetFirstPackedCop(FixFloorSigned(iVar3, 11), FixFloorSigned(iVar1, 11), &ci, 0); + ppco = GetFirstPackedCop(cell_x, cell_z, &ci, 0); pCellObject = UnpackCellObject(ppco, &ci.nearCell); - do { - if (!pCellObject) - return 1; - + while(pCellObject) + { pModel = modelpointers[pCellObject->type]; piVar6 = (int*)pModel->collision_block; @@ -113,38 +112,143 @@ char CellEmpty(VECTOR *pPosition, int radius) { num_cb = *piVar6; - iVar11 = ((pCellObject->pos.vx - pPosition->vx) * 0x10000) >> 0x10; - iVar1 = ((pCellObject->pos.vz - pPosition->vz) * 0x10000) >> 0x10; + xd = (pCellObject->pos.vx - pPosition->vx); + zd = (pCellObject->pos.vz - pPosition->vz); sphere_sq = pModel->bounding_sphere + 580; sphere_sq = (sphere_sq * sphere_sq); collide = (COLLISION_PACKET*)(piVar6 + 1); - if (iVar11 * iVar11 + iVar1 * iVar1 < sphere_sq) + if (xd * xd + zd * zd < sphere_sq) { box_loop = 0; while (box_loop < num_cb) { - iVar10 = collide->zsize * 0x800 + radius * 0x1000; - iVar9 = collide->xsize * 0x800 + radius * 0x1000; - uVar4 = (pCellObject->yang + collide->yang) * 0x100 & 0x3f00; - iVar7 = pPosition->vy + ((int)(((uint) * (ushort*)&(pCellObject->pos).vy + (uint)(ushort)collide->ypos) * 0x10000) >> 0x10) + 0x50; + // ORIGINAL + /* + zs = collide->zsize * 0x800 + radius * 0x1000; + xs = collide->xsize * 0x800 + radius * 0x1000; - if (iVar7 < 0) - iVar7 = -iVar7; + theta = (pCellObject->yang + collide->yang) * 64 & 0xfff; + ypos = pPosition->vy + (pCellObject->pos.vy + collide->ypos) + 80; - iVar8 = (int)*(short*)((int)rcossin_tbl + uVar4 + 2); - iVar5 = (int)*(short*)((int)rcossin_tbl + uVar4); - iVar2 = (uint)(ushort)collide->ysize << 0x10; + cs = rcossin_tbl[theta * 2 + 1]; + sn = rcossin_tbl[theta * 2]; + */ - if (((iVar7 < ((iVar2 >> 0x10) - (iVar2 >> 0x1f) >> 1) + 0x3c) && - ((uint)((iVar11 * iVar8 - iVar1 * iVar5) + iVar9) < (uint)(iVar9 * 2))) && - ((uint)(iVar1 * iVar8 + iVar11 * iVar5 + iVar10) < (uint)(iVar10 * 2))) + // NEW + int xxd, zzd; + int yang; + int theta; + MATRIX2* mat; + + yang = -pCellObject->yang & 0x3f; + theta = (pCellObject->yang + collide->yang) * 64 & 0xfff; + + mat = &matrixtable[yang]; + + cs = rcossin_tbl[theta * 2 + 1]; + sn = rcossin_tbl[theta * 2]; + + xxd = FIXEDH(collide->xpos * mat->m[0][0] + collide->zpos * mat->m[2][0]); + zzd = FIXEDH(collide->xpos * mat->m[0][2] + collide->zpos * mat->m[2][2]); + + xd = (pCellObject->pos.vx - pPosition->vx) + xxd; + zd = (pCellObject->pos.vz - pPosition->vz) + zzd; + + zs = (collide->zsize * 2048 + radius * 4096); + xs = (collide->xsize * 2048 + radius * 4096); + + ypos = pPosition->vy + (pCellObject->pos.vy + collide->ypos) + 80; + +#ifdef COLLISION_DEBUG + int result = 0; + + if (collide->ysize / 2 + 60 > ABS(ypos) && + xs * 2 > ABS(xd * cs - zd * sn) + xs && + zs * 2 > ABS(zd * cs + xd * sn) + zs) + { + result = 1; + } + + extern int gShowCollisionDebug; + if (gShowCollisionDebug == 3) + { + CDATA2D cd[1]; + + cd[0].x.vx = (pCellObject->pos.vx + xxd);//FIXEDH(collide->xpos * mat->m[0][0] + collide->zpos * mat->m[2][0])); + cd[0].x.vz = (pCellObject->pos.vz + zzd);//FIXEDH(collide->xpos * mat->m[0][2] + collide->zpos * mat->m[2][2])); + cd[0].x.vy = pPosition->vy; + + cd[0].theta = theta; // (pCellObject->yang + collide->yang) * 64 & 0xfff; + cd[0].length[0] = collide->zsize / 2; + cd[0].length[1] = collide->xsize / 2; + + // calc axes of box + int dtheta = cd[0].theta & 0xfff; + + cd[0].axis[0].vx = rcossin_tbl[dtheta * 2]; + cd[0].axis[0].vz = rcossin_tbl[dtheta * 2 + 1]; + + cd[0].axis[1].vz = -rcossin_tbl[dtheta * 2]; + cd[0].axis[1].vx = rcossin_tbl[dtheta * 2 + 1]; + + extern void Debug_AddLine(VECTOR & pointA, VECTOR & pointB, CVECTOR & color); + extern void Debug_AddLineOfs(VECTOR & pointA, VECTOR & pointB, VECTOR & ofs, CVECTOR & color); + + CVECTOR ggcv = { 0, 250, 0 }; + CVECTOR rrcv = { 250, 0, 0 }; + CVECTOR yycv = { 250, 250, 0 }; + + // show both box axes + { + VECTOR _zero = { 0 }; + VECTOR b1p = cd[0].x; + + // show position to position + //Debug_AddLine(b1p1, b2p1, yycv); + + VECTOR b1ax[2] = { {0} , {0} }; + b1ax[0].vx = FIXEDH(cd[0].axis[0].vx * cd[0].length[0]); + b1ax[0].vz = FIXEDH(cd[0].axis[0].vz * cd[0].length[0]); + b1ax[1].vx = FIXEDH(cd[0].axis[1].vx * cd[0].length[1]); + b1ax[1].vz = FIXEDH(cd[0].axis[1].vz * cd[0].length[1]); + + // show axis of body 1 + Debug_AddLineOfs(_zero, b1ax[0], b1p, rrcv); + Debug_AddLineOfs(_zero, b1ax[1], b1p, yycv); + + // display 2D box 1 + { + int h = b1ax[0].vy; + VECTOR box_points[4] = { + {b1ax[0].vx - b1ax[1].vx, h, b1ax[0].vz - b1ax[1].vz, 0}, // front left + {b1ax[0].vx + b1ax[1].vx, h, b1ax[0].vz + b1ax[1].vz, 0}, // front right + + {-b1ax[0].vx + b1ax[1].vx, h, -b1ax[0].vz + b1ax[1].vz, 0}, // back right + {-b1ax[0].vx - b1ax[1].vx, h, -b1ax[0].vz - b1ax[1].vz, 0} // back left + }; + + Debug_AddLineOfs(box_points[0], box_points[1], b1p, result ? rrcv : ggcv); + Debug_AddLineOfs(box_points[1], box_points[2], b1p, result ? rrcv : ggcv); + Debug_AddLineOfs(box_points[2], box_points[3], b1p, result ? rrcv : ggcv); + Debug_AddLineOfs(box_points[3], box_points[0], b1p, result ? rrcv : ggcv); + } + } + } + + if (result) + return 0; +#else + if (collide->ysize / 2 + 60 > ABS(ypos) && + xs * 2 > ABS(xd * cs - zd * sn) + xs && + zs * 2 > ABS(zd * cs + xd * sn) + zs) { return 0; } +#endif box_loop++; collide++; @@ -154,10 +258,9 @@ char CellEmpty(VECTOR *pPosition, int radius) ppco = GetNextPackedCop(&ci); pCellObject = UnpackCellObject(ppco, &ci.nearCell); + } - } while (true); - - return 0; + return 1; } From c1189801cfef9133101176b3e843a7c80e2e7e87 Mon Sep 17 00:00:00 2001 From: Ilya Shurumov Date: Fri, 9 Oct 2020 15:25:14 +0600 Subject: [PATCH 15/41] - fix crash in initOBox due to pinged out car - confused debug message only in debug build --- src_rebuild/GAME/C/CIV_AI.C | 5 +++++ src_rebuild/GAME/C/HANDLING.C | 21 ++++++++++++--------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src_rebuild/GAME/C/CIV_AI.C b/src_rebuild/GAME/C/CIV_AI.C index 74a64cfb..9d00beae 100644 --- a/src_rebuild/GAME/C/CIV_AI.C +++ b/src_rebuild/GAME/C/CIV_AI.C @@ -61,9 +61,14 @@ int test555 = 0; #define GET_NODE_ID(cp, node) int((node) - cp->ai.c.targetRoute) +#ifdef _DEBUG #define CIV_STATE_SET_CONFUSED(cp) \ printInfo("CIV confused: at %s, %d\n", __FUNCTION__, __LINE__);\ cp->ai.c.thrustState = 3; cp->ai.c.ctrlState = 7; +#else +#define CIV_STATE_SET_CONFUSED(cp) \ + cp->ai.c.thrustState = 3; cp->ai.c.ctrlState = 7; +#endif // decompiled code diff --git a/src_rebuild/GAME/C/HANDLING.C b/src_rebuild/GAME/C/HANDLING.C index 45e8209b..d6207643 100644 --- a/src_rebuild/GAME/C/HANDLING.C +++ b/src_rebuild/GAME/C/HANDLING.C @@ -1414,45 +1414,48 @@ void LongQuaternion2Matrix(long(*qua)[4], MATRIX *m) void initOBox(_CAR_DATA *cp) { SVECTOR boxDisp; + CAR_COSMETICS* car_cos; short length; gte_SetRotMatrix(&cp->hd.where); gte_SetTransMatrix(&cp->hd.where); - boxDisp.vx = -cp->ap.carCos->cog.vx; - boxDisp.vy = -cp->ap.carCos->cog.vy; - boxDisp.vz = -cp->ap.carCos->cog.vz; + car_cos = &car_cosmetics[cp->ap.model]; + + boxDisp.vx = -car_cos->cog.vx; + boxDisp.vy = -car_cos->cog.vy; + boxDisp.vz = -car_cos->cog.vz; gte_ldv0(&boxDisp); gte_rtv0tr(); if (cp->controlType == CONTROL_TYPE_PURSUER_AI) { - length = FixFloorSigned(cp->ap.carCos->colBox.vx * 14, 4); + length = FixFloorSigned(car_cos->colBox.vx * 14, 4); cp->hd.oBox.length[0] = length; } else { - length = cp->ap.carCos->colBox.vx; + length = car_cos->colBox.vx; cp->hd.oBox.length[0] = length; } gte_stlvnl(&cp->hd.oBox.location); VECTOR svx = { length, 0 ,0 }; - VECTOR svy = { 0, cp->ap.carCos->colBox.vy ,0 }; - VECTOR svz = { 0, 0 ,cp->ap.carCos->colBox.vz }; + VECTOR svy = { 0, car_cos->colBox.vy ,0 }; + VECTOR svz = { 0, 0 ,car_cos->colBox.vz }; gte_ldlvl(&svx); gte_rtir(); - cp->hd.oBox.length[1] = cp->ap.carCos->colBox.vy; + cp->hd.oBox.length[1] = car_cos->colBox.vy; gte_stsv(&cp->hd.oBox.radii[0]); gte_ldlvl(&svy); gte_rtir(); - cp->hd.oBox.length[2] = cp->ap.carCos->colBox.vz; + cp->hd.oBox.length[2] = car_cos->colBox.vz; gte_stsv(&cp->hd.oBox.radii[1]); gte_ldlvl(&svz); From f7d791aefb1ed3e079ed912a8fc1ce385028e349 Mon Sep 17 00:00:00 2001 From: Ilya Shurumov Date: Fri, 9 Oct 2020 15:45:24 +0600 Subject: [PATCH 16/41] - fix midget and overly fat pedestrians --- src_rebuild/GAME/C/MOTION_C.C | 178 +++++++++++++++++----------------- 1 file changed, 90 insertions(+), 88 deletions(-) diff --git a/src_rebuild/GAME/C/MOTION_C.C b/src_rebuild/GAME/C/MOTION_C.C index 540ff0ac..95998f54 100644 --- a/src_rebuild/GAME/C/MOTION_C.C +++ b/src_rebuild/GAME/C/MOTION_C.C @@ -359,7 +359,7 @@ int vStored = 0; // [D] void ProcessMotionLump(char *lump_ptr, int lump_size) { - if (ThisMotion < 24) + if (ThisMotion < 24) { int size = (lump_size + 3U & 0xfffffffc); @@ -546,14 +546,16 @@ void DrawBodySprite(PEDESTRIAN *pDrawingPed, int boneId, VERTTYPE v1[2], VERTTYP lVar2 = ratan2(y, x); if (bDoingShadow == 0) - iVar5 = gCurrentZ + (scr_z / 2); + iVar5 = gCurrentZ + (scr_z / 2); else - iVar5 = sz + (scr_z / 2); + iVar5 = sz + (scr_z / 2); iVar13 = (scr_z * 4096) / iVar5; + iVar13 = iVar13 * 25 >> 5; + if (bone == JOINT_1) - iVar13 = iVar13 + ((int)((uint)*(ushort *)((int)rcossin_tbl + (((int)(pDrawingPed->dir).vy + (int)camera_angle.vy) * 8 & 0x3ff8U) + 2) << 0x10) >> 0x16); + iVar13 = iVar13 + ((int)((uint)*(ushort *)((int)rcossin_tbl + (((int)(pDrawingPed->dir).vy + (int)camera_angle.vy) * 8 & 0x3ff8U) + 2) << 0x10) >> 0x16); if (pDrawingPed->type == PED_ACTION_JUMP) { @@ -792,7 +794,7 @@ void StoreVertexLists(void) { cTannerVNumbers[pBVar2->id] = -1; } - else if(*pBVar2->pModel != NULL) + else if (*pBVar2->pModel != NULL) { pMVar5 = *pBVar2->pModel; local_a2_76 = (SVECTOR *)pMVar5->vertices; @@ -827,7 +829,7 @@ void StoreVertexLists(void) do { local_t0_256 = pmJerichoModels[iVar7]; - + if (local_t0_256 != NULL) { local_a2_308 = (SVECTOR *)local_t0_256->vertices; @@ -959,7 +961,7 @@ void SetupTannerSkeleton(PEDESTRIAN *pDrawingPed) local_t0_244->vy = pBone[1].pParent->pvOrigPos->vy - pBone[1].pvOrigPos->vy; local_t0_244->vz = pBone[1].pParent->pvOrigPos->vz - pBone[1].pvOrigPos->vz; - if (pBone[1].id == JOINT_1) + if (pBone[1].id == JOINT_1) local_t0_244->vy -= bodyShiftValue; i--; @@ -986,7 +988,7 @@ void SetupTannerSkeleton(PEDESTRIAN *pDrawingPed) } while (-1 < i); #if 0 - // Draw T POSE + // Draw T POSE { extern void Debug_AddLine(VECTOR& pointA, VECTOR& pointB, CVECTOR& color); extern void Debug_AddLineOfs(VECTOR& pointA, VECTOR& pointB, VECTOR& ofs, CVECTOR& color); @@ -1237,19 +1239,19 @@ void newShowTanner(PEDESTRIAN *pDrawingPed) LVar1 = lRoutes[vvar1][1]; iVar5 = 1; - while (LVar1 != ROOT) + while (LVar1 != ROOT) { LVar1 = lRoutes[vvar1][iVar5]; uVar4 = (uint)LVar1; pBone = Skel + uVar4; if (pBone->id < 0x7f) { - uVar6 = lRoutes[vvar1][iVar5-1];// (uint)*(byte *)((int)MissionName37 + iVar5 + sy + 0x93); + uVar6 = lRoutes[vvar1][iVar5 - 1];// (uint)*(byte *)((int)MissionName37 + iVar5 + sy + 0x93); VECTOR_ARRAY_1f800020[pBone->id].vx = VECTOR_ARRAY_1f800020[uVar6].vx + Skel[uVar4].vCurrPos.vx; VECTOR_ARRAY_1f800020[pBone->id].vy = VECTOR_ARRAY_1f800020[uVar6].vy + Skel[uVar4].vCurrPos.vy; VECTOR_ARRAY_1f800020[pBone->id].vz = VECTOR_ARRAY_1f800020[uVar6].vz + Skel[uVar4].vCurrPos.vz; - - if ((pDrawingPed->pedType == TANNER_MODEL) && (pBone->id == HEAD)) + + if ((pDrawingPed->pedType == TANNER_MODEL) && (pBone->id == HEAD)) { iVar3 = VECTOR_ARRAY_1f800020[uVar6].vy - 94; pDrawingPed->head_pos = iVar3 / 3; @@ -1261,7 +1263,7 @@ void newShowTanner(PEDESTRIAN *pDrawingPed) mVerts = (SVECTOR *)model->vertices; iVar3 = 0; - if (model->num_vertices != 0) + if (model->num_vertices != 0) { do { iVar3 = iVar3 + 1; @@ -1275,7 +1277,7 @@ void newShowTanner(PEDESTRIAN *pDrawingPed) pBone->id = (LIMBS)(pBone->id | 0x80); } iVar5++; - + } vvar1++; sy = vvar1 * 8; @@ -1290,7 +1292,7 @@ void newShowTanner(PEDESTRIAN *pDrawingPed) sy = 20; do { uVar4 = (uint)pBone->id & 0x7f; - if (bDoingShadow == 0) + if (bDoingShadow == 0) { if (pBone->pModel != NULL) { @@ -1302,12 +1304,12 @@ void newShowTanner(PEDESTRIAN *pDrawingPed) RenderModel(*pBone->pModel, NULL, &v, vvar1, 0, 0); } } - else + else { if (((uVar4 != 5) && (uVar4 != 9)) && ((uVar4 != 0xd && ((((uVar4 != 1 && ((pBone->id & 0x7f) != 0)) && (uVar4 != 0x16)) && - ((uVar4 != 0xe && (uVar4 != 0x12)))))))) + ((uVar4 != 0xe && (uVar4 != 0x12)))))))) { uVar6 = pBone->pParent->id & 0x7f; @@ -1371,7 +1373,7 @@ void newShowTanner(PEDESTRIAN *pDrawingPed) } while (-1 < sy); } } - else + else { sy = 21; do { @@ -1406,7 +1408,7 @@ void newShowTanner(PEDESTRIAN *pDrawingPed) pBone = pBone + 1; } while (-1 < sy); - if (switch_detail_distance >> 2 < gCurrentZ) + if (switch_detail_distance >> 2 < gCurrentZ) { uVar4 = (uint)Skel[4].id & 0x7f; uVar6 = (uint)(Skel[4].pParent)->id & 0x7f; @@ -1432,7 +1434,7 @@ void newShowTanner(PEDESTRIAN *pDrawingPed) DrawBodySprite(pDrawingPed, Skel[4].id, v1_00, v2_00, z, z1); } - else + else { v1.vx = *(short *)&VECTOR_ARRAY_1f800020[(uint)Skel[4].id & 0x7f].vx; v1.vy = *(short *)&VECTOR_ARRAY_1f800020[(uint)Skel[4].id & 0x7f].vy; @@ -1491,25 +1493,25 @@ SVECTOR* GetModelVertPtr(PEDESTRIAN *pDrawingPed, int boneId, int modelType) switch (boneId) { - case 2: - startVertex = cJerichoVNumbers[0]; - break; - case 4: - startVertex = cJerichoVNumbers[1]; - break; - case 6: - startVertex = cJerichoVNumbers[2]; - break; - case 7: - startVertex = cJerichoVNumbers[3]; - break; - case 10: - startVertex = cJerichoVNumbers[4]; - break; - case 11: - startVertex = cJerichoVNumbers[5]; - default: - return vTannerList + cTannerVNumbers[boneId & 0x7f]; + case 2: + startVertex = cJerichoVNumbers[0]; + break; + case 4: + startVertex = cJerichoVNumbers[1]; + break; + case 6: + startVertex = cJerichoVNumbers[2]; + break; + case 7: + startVertex = cJerichoVNumbers[3]; + break; + case 10: + startVertex = cJerichoVNumbers[4]; + break; + case 11: + startVertex = cJerichoVNumbers[5]; + default: + return vTannerList + cTannerVNumbers[boneId & 0x7f]; } return vJerichoList + startVertex; @@ -1614,7 +1616,7 @@ void newRotateBones(PEDESTRIAN *pDrawingPed, BONE *poBone) MATRIX MATRIX_1f800000; MATRIX MATRIX_1f800020; MATRIX MATRIX_1f800040; - + SVECTOR SVECTOR_ARRAY_1f800060[2]; SVECTOR SVECTOR_ARRAY_1f800080[80]; VECTOR VECTOR_1f800070; @@ -1671,27 +1673,27 @@ void newRotateBones(PEDESTRIAN *pDrawingPed, BONE *poBone) iVar6 = 1; LVar2 = lRoutes[local_30][iVar6]; - while (LVar2 != ROOT) + while (LVar2 != ROOT) { uVar4 = (uint)LVar2; SVECTOR_ARRAY_1f800060[0].vx = Skel[uVar4].vOffset.vx; SVECTOR_ARRAY_1f800060[0].vy = Skel[uVar4].vOffset.vy; SVECTOR_ARRAY_1f800060[0].vz = Skel[uVar4].vOffset.vz; - if (bReverseYRotation == 0 || Skel[uVar4].pParent->id != ROOT) + if (bReverseYRotation == 0 || Skel[uVar4].pParent->id != ROOT) { SVECTOR_ARRAY_1f800060[1].vx = -Skel[uVar4].pParent->pvRotation->vx; SVECTOR_ARRAY_1f800060[1].vy = Skel[uVar4].pParent->pvRotation->vy; SVECTOR_ARRAY_1f800060[1].vz = Skel[uVar4].pParent->pvRotation->vz; } - else + else { SVECTOR_ARRAY_1f800060[1].vx = Skel[uVar4].pParent->pvRotation->vx; SVECTOR_ARRAY_1f800060[1].vy = -Skel[uVar4].pParent->pvRotation->vy; SVECTOR_ARRAY_1f800060[1].vz = Skel[uVar4].pParent->pvRotation->vz; } - if (LVar2 == HEAD) + if (LVar2 == HEAD) { SVECTOR_ARRAY_1f800060[1].vy -= pDrawingPed->head_rot; } @@ -1728,51 +1730,51 @@ void newRotateBones(PEDESTRIAN *pDrawingPed, BONE *poBone) LVar2 = Skel[uVar4].id; /**/ - if (((((LVar2 & 0x7f) == 4) || (pDrawingPed->pedType < OTHER_SPRITE)) && - (-1 < (int)((uint)LVar2 << 0x18))) && - ((Skel[uVar4].pModel != NULL && (verts != NULL)))) + if (((((LVar2 & 0x7f) == 4) || (pDrawingPed->pedType < OTHER_SPRITE)) && + (-1 < (int)((uint)LVar2 << 0x18))) && + ((Skel[uVar4].pModel != NULL && (verts != NULL)))) { - pMVar5 = *Skel[uVar4].pModel; - uVar9 = pMVar5->num_vertices; - uVar11 = (uint)uVar9; - local_s0_2092 = (SVECTOR *)pMVar5->vertices; - pSVar8 = SVECTOR_ARRAY_1f800080; - uVar10 = uVar11; + pMVar5 = *Skel[uVar4].pModel; + uVar9 = pMVar5->num_vertices; + uVar11 = (uint)uVar9; + local_s0_2092 = (SVECTOR *)pMVar5->vertices; + pSVar8 = SVECTOR_ARRAY_1f800080; + uVar10 = uVar11; - if (uVar9 != 0) + if (uVar9 != 0) { - do { - pSVar8->vx = verts->vx + SVECTOR_ARRAY_1f800060[0].vx; - pSVar8->vy = verts->vy + SVECTOR_ARRAY_1f800060[0].vy; - pSVar8->vz = verts->vz + SVECTOR_ARRAY_1f800060[0].vz; + do { + pSVar8->vx = verts->vx + SVECTOR_ARRAY_1f800060[0].vx; + pSVar8->vy = verts->vy + SVECTOR_ARRAY_1f800060[0].vy; + pSVar8->vz = verts->vz + SVECTOR_ARRAY_1f800060[0].vz; verts = verts + 1; uVar10 = uVar10 - 1; - pSVar8 = pSVar8 + 1; - } while (uVar10 != 0); - } + pSVar8 = pSVar8 + 1; + } while (uVar10 != 0); + } - verts = SVECTOR_ARRAY_1f800080; + verts = SVECTOR_ARRAY_1f800080; - if (uVar9 != 0) + if (uVar9 != 0) { - do { + do { gte_ldv0(verts); gte_rtv0(); gte_stlvnl(&VECTOR_1f800070); - local_s0_2092->vx = VECTOR_1f800070.vx; - local_s0_2092->vy = VECTOR_1f800070.vy; - local_s0_2092->vz = VECTOR_1f800070.vz; + local_s0_2092->vx = VECTOR_1f800070.vx; + local_s0_2092->vy = VECTOR_1f800070.vy; + local_s0_2092->vz = VECTOR_1f800070.vz; - local_s0_2092 = local_s0_2092 + 1; + local_s0_2092 = local_s0_2092 + 1; verts = verts + 1; uVar11 = uVar11 - 1; - } while (uVar11 != 0); - } - } + } while (uVar11 != 0); + } + } iVar6 = iVar6 + 1; LVar2 = lRoutes[local_30][iVar6]; @@ -1928,7 +1930,7 @@ void DrawCiv(PEDESTRIAN *pPed) iVar26 = 0; boneId = (uint)(pPed->frame1 >> 1); vert2 = vert1 + boneId * 0x1e; - uVar15 = pPed->head_pos;// (uint)(*(char *)((int)&pPed->flags + 1) >> 7); // [A] scale? height offset? + uVar15 = (uint)(*(char *)((int)&pPed->flags + 1) >> 7); // [A] scale? height offset? if ((pPed->frame1 & 1U) == 0) { @@ -1943,11 +1945,11 @@ void DrawCiv(PEDESTRIAN *pPed) vert2++; } while (0 < iVar13); } - else + else { if (pPed->frame1 < 30) vert1 += (boneId + 1) * 30; - + iVar13 = 30; do { // WTF? @@ -1959,7 +1961,7 @@ void DrawCiv(PEDESTRIAN *pPed) temp1.vz = vert1->vz; temp2.vz = vert2->vz; - + psrLerpData->vx = (temp1.vx + temp2.vx >> 1); psrLerpData->vy = (temp1.vy + temp2.vy >> uVar15 + 1); psrLerpData->vz = (temp1.vz + temp2.vz >> 1); @@ -2043,7 +2045,7 @@ void DrawCiv(PEDESTRIAN *pPed) iVar13 = 0xe; do { - if (iVar26 < 30) + if (iVar26 < 30) { gte_stsxy3(&plVar22[0], &plVar22[1], &plVar22[2]); gte_stsz3(&plVar23[0], &plVar23[1], &plVar23[2]); @@ -2093,7 +2095,7 @@ void DrawCiv(PEDESTRIAN *pPed) boneId = *piVar25; if ((boneId == 4) && (v1 = 1, lVar9 = LONG_ARRAY_1f800210[0], - LONG_ARRAY_1f800210[0] <= switch_detail_distance >> 1)) + LONG_ARRAY_1f800210[0] <= switch_detail_distance >> 1)) { local_38 = 1; } @@ -2108,7 +2110,7 @@ void DrawCiv(PEDESTRIAN *pPed) piVar25++; } while (-1 < iVar13); - if (local_38 != 0) + if (local_38 != 0) { bAllreadyRotated = 0; DoCivHead(pPed, SVECTOR_ARRAY_1f800090 + 5, SVECTOR_ARRAY_1f800090 + 4); @@ -2163,7 +2165,7 @@ void DrawCiv(PEDESTRIAN *pPed) // [D] void SetSkelModelPointers(int type) { - if (type == OTHER_MODEL) + if (type == OTHER_MODEL) { Skel[2].pModel = &pmJerichoModels[0]; Skel[4].pModel = &pmJerichoModels[1]; @@ -2260,7 +2262,7 @@ void DrawTanner(PEDESTRIAN *pPed) bDoingShadow = 1; v.vy = -camera_position.vy - MapHeight((VECTOR *)&pPed->position); - if (pPed->padId == 0) + if (pPed->padId == 0) { if (gTimeOfDay == 3) { @@ -2269,7 +2271,7 @@ void DrawTanner(PEDESTRIAN *pPed) cV.r = 12; TannerShadow(pPed, &v, moon_position + GameLevel, &cV, pPed->dir.vy); } - else + else { cV.b = 32; cV.g = 32; @@ -2372,7 +2374,7 @@ int DrawCharacter(PEDESTRIAN *pPed) cV.r = 12; TannerShadow(pPed, &v, moon_position + GameLevel, &cV, (pPed->dir).vy); } - else + else { cV.b = 32; cV.g = 32; @@ -2398,7 +2400,7 @@ int DrawCharacter(PEDESTRIAN *pPed) pos.vy = (0x1e - MapHeight(&pos)) - camera_position.vy; pos.vz = pos.vz - camera_position.vz; - if (uVar8 < 8) + if (uVar8 < 8) size = uVar8 | 0x50; else size = uVar2 * -2 + 0x60; @@ -2485,7 +2487,7 @@ void InitTannerShadow(void) uVar2 = (ushort)uVar5; do { - + rectTannerWindow.w = 64; rectTannerWindow.h = 128; rectTannerWindow.x = uVar1; @@ -2613,7 +2615,7 @@ void TannerShadow(PEDESTRIAN* pDrawingPed, VECTOR *pPedPos, SVECTOR *pLightPos, dr_env = (DR_ENV*)current->primptr; SetDrawEnv(dr_env, &drEnv); - + addPrim(current->ot + 0x107f, dr_env); current->primptr += sizeof(DR_ENV); @@ -2739,12 +2741,12 @@ void TannerShadow(PEDESTRIAN* pDrawingPed, VECTOR *pPedPos, SVECTOR *pLightPos, InitCamera(&player[0]); gte_SetGeomOffset(160, 128); - + SetDefDrawEnv(&drEnv, rectTannerWindow.x, rectTannerWindow.y, rectTannerWindow.w, rectTannerWindow.h); dr_env = (DR_ENV*)current->primptr; SetDrawEnv(dr_env, &drEnv); - + addPrim(current->ot + 0x107f, dr_env); current->primptr += sizeof(DR_ENV); #endif @@ -2878,7 +2880,7 @@ void DoCivHead(PEDESTRIAN *pPed, SVECTOR *vert1, SVECTOR *vert2) flags = 0x10; // set custom palette flag plotContext.clut = civ_clut[0][texturePedHead.texture_number][pPed->pallet & 0xf] << 0x10; } - + oldcombointensity = combointensity; if (gNight != 0) From aa00e8e050516a8bc67abe201c3c337ccf1d1b67 Mon Sep 17 00:00:00 2001 From: Ilya Shurumov Date: Fri, 9 Oct 2020 18:13:44 +0600 Subject: [PATCH 17/41] - hardcoded fix for vegas limo cosmetics - remove dummyCosmetics --- src_rebuild/GAME/C/BCOLLIDE.C | 33 +++++++++++++++++++++------------ src_rebuild/GAME/C/CAMERA.C | 4 +--- src_rebuild/GAME/C/COSMETIC.C | 21 ++++++++++++++++++++- src_rebuild/GAME/C/OBJCOLL.C | 2 +- src_rebuild/GAME/C/PEDEST.C | 1 - 5 files changed, 43 insertions(+), 18 deletions(-) diff --git a/src_rebuild/GAME/C/BCOLLIDE.C b/src_rebuild/GAME/C/BCOLLIDE.C index 64609aec..5d88a130 100644 --- a/src_rebuild/GAME/C/BCOLLIDE.C +++ b/src_rebuild/GAME/C/BCOLLIDE.C @@ -981,23 +981,15 @@ int CarBuildingCollision(_CAR_DATA *cp, BUILDING_BOX *building, CELL_OBJECT *cop tempwhere.vz = cp->hd.where.t[2]; debris_colour = GetDebrisColour(cp); - gte_SetRotMatrix(&cp->hd.where); - gte_SetTransMatrix(&cp->hd.where); - - boxDisp.vx = -car_cos->cog.vx; - boxDisp.vy = -car_cos->cog.vy; - boxDisp.vz = -car_cos->cog.vz; - - gte_ldv0(&boxDisp); - - gte_rtv0tr(); - - gte_stlvnl(&cd[0].x); cd[0].theta = cp->hd.direction; if (cp->controlType == CONTROL_TYPE_TANNERCOLLIDER) { + cd[0].x.vx = cp->hd.where.t[0]; + cd[0].x.vy = cp->hd.where.t[1]; + cd[0].x.vz = cp->hd.where.t[2]; + cd[0].vel.vx = FIXEDH(cp->st.n.linearVelocity[0]); cd[0].vel.vz = FIXEDH(cp->st.n.linearVelocity[2]); @@ -1009,6 +1001,10 @@ int CarBuildingCollision(_CAR_DATA *cp, BUILDING_BOX *building, CELL_OBJECT *cop } else if (cp->controlType == CONTROL_TYPE_CAMERACOLLIDER) { + cd[0].x.vx = cp->hd.where.t[0]; + cd[0].x.vy = cp->hd.where.t[1]; + cd[0].x.vz = cp->hd.where.t[2]; + cd[0].vel.vx = 0; cd[0].vel.vz = 0; cd[0].length[1] = 5; @@ -1016,6 +1012,19 @@ int CarBuildingCollision(_CAR_DATA *cp, BUILDING_BOX *building, CELL_OBJECT *cop } else { + gte_SetRotMatrix(&cp->hd.where); + gte_SetTransMatrix(&cp->hd.where); + + boxDisp.vx = -car_cos->cog.vx; + boxDisp.vy = -car_cos->cog.vy; + boxDisp.vz = -car_cos->cog.vz; + + gte_ldv0(&boxDisp); + + gte_rtv0tr(); + + gte_stlvnl(&cd[0].x); + cd[0].vel.vx = FIXEDH(cp->st.n.linearVelocity[0]); cd[0].vel.vz = FIXEDH(cp->st.n.linearVelocity[2]); diff --git a/src_rebuild/GAME/C/CAMERA.C b/src_rebuild/GAME/C/CAMERA.C index a0af6c1f..7cbaadec 100644 --- a/src_rebuild/GAME/C/CAMERA.C +++ b/src_rebuild/GAME/C/CAMERA.C @@ -728,9 +728,7 @@ void PlaceCameraFollowCar(_PLAYER *lp) gCameraDistance = maxCameraDist; - if (lp->cameraCarId < 0) - jcam->ap.carCos = &dummyCosmetics; - else + if (lp->cameraCarId >= 0) jcam->ap.carCos = car_data[lp->cameraCarId].ap.carCos; jcam->hd.direction = camAngle; diff --git a/src_rebuild/GAME/C/COSMETIC.C b/src_rebuild/GAME/C/COSMETIC.C index a6cf0994..eb2fe94d 100644 --- a/src_rebuild/GAME/C/COSMETIC.C +++ b/src_rebuild/GAME/C/COSMETIC.C @@ -23,7 +23,9 @@ char* CosmeticFiles[] = { }; CAR_COSMETICS car_cosmetics[MAX_CAR_MODELS]; -CAR_COSMETICS dummyCosmetics = { 0 }; + +// [A] temporary hardcoded bug fix +CAR_COSMETICS gVegasLimoCosmetic; // decompiled code // original method signature: @@ -130,6 +132,17 @@ void ProcessCosmeticsLump(char *lump_ptr, int lump_size) i++; } while (i < MAX_CAR_MODELS); + + // [A] fix vegas limo cosmetic bug in advance + if(GameLevel == 2) + { + offset = *(int*)(lump_ptr + 8 * 4); + + ptr = (lump_ptr + offset); + memcpy(&gVegasLimoCosmetic, ptr, sizeof(CAR_COSMETICS)); + + FixCarCos(&gVegasLimoCosmetic, model); + } } @@ -229,6 +242,12 @@ void AddReverseLight(_CAR_DATA *cp) void SetupSpecCosmetics(char *loadbuffer) { // [A] this is better + if(GameLevel == 2 && MissionHeader->residentModels[4] == 8) + { + memcpy(&car_cosmetics[4], &gVegasLimoCosmetic, sizeof(CAR_COSMETICS)); + return; + } + memcpy(&car_cosmetics[4], loadbuffer, sizeof(CAR_COSMETICS)); } diff --git a/src_rebuild/GAME/C/OBJCOLL.C b/src_rebuild/GAME/C/OBJCOLL.C index 306ab6de..2b6cf91b 100644 --- a/src_rebuild/GAME/C/OBJCOLL.C +++ b/src_rebuild/GAME/C/OBJCOLL.C @@ -1044,7 +1044,7 @@ void CheckScenaryCollisions(_CAR_DATA *cp) int lbody; int extraDist; - if (cp->controlType == CONTROL_TYPE_CAMERACOLLIDER && cp->ap.carCos == NULL) + if (cp->controlType == CONTROL_TYPE_CAMERACOLLIDER || cp->ap.carCos == NULL) lbody = 360; else lbody = cp->ap.carCos->colBox.vz; diff --git a/src_rebuild/GAME/C/PEDEST.C b/src_rebuild/GAME/C/PEDEST.C index d1de0250..93bab5d4 100644 --- a/src_rebuild/GAME/C/PEDEST.C +++ b/src_rebuild/GAME/C/PEDEST.C @@ -3403,7 +3403,6 @@ void TannerCollision(PEDESTRIAN *pPed) pcdTanner->id = 21; pcdTanner->controlType = 6; - pcdTanner->ap.carCos = &dummyCosmetics; pcdTanner->hd.direction = pPed->dir.vy - 0x800U & 0xfff; From a3f81aed0e1178afc103d5bbc9af2c24ab71810c Mon Sep 17 00:00:00 2001 From: Ilya Shurumov Date: Fri, 9 Oct 2020 22:12:14 +0600 Subject: [PATCH 18/41] - implement XA subtitles inside WAV files --- src_rebuild/GAME/C/CUTSCENE.C | 4 + src_rebuild/GAME/C/XAPLAY.C | 55 +++++++++- src_rebuild/GAME/C/XAPLAY.H | 1 + .../utils/audio_source/snd_wav_source.cpp | 100 +++++++++++++++++- .../utils/audio_source/snd_wav_source.h | 13 +++ src_rebuild/utils/riff.cpp | 5 +- src_rebuild/utils/riff.h | 4 + 7 files changed, 173 insertions(+), 9 deletions(-) diff --git a/src_rebuild/GAME/C/CUTSCENE.C b/src_rebuild/GAME/C/CUTSCENE.C index ebbc65e7..acb05715 100644 --- a/src_rebuild/GAME/C/CUTSCENE.C +++ b/src_rebuild/GAME/C/CUTSCENE.C @@ -246,6 +246,10 @@ void DrawInGameCutscene(void) { TILE *tile; +#ifndef PSX + PrintXASubtitles(); +#endif + if (gInGameCutsceneActive == 0 && gInGameCutsceneDelay == 0) return; diff --git a/src_rebuild/GAME/C/XAPLAY.C b/src_rebuild/GAME/C/XAPLAY.C index 699e3c30..5bd14b71 100644 --- a/src_rebuild/GAME/C/XAPLAY.C +++ b/src_rebuild/GAME/C/XAPLAY.C @@ -1,8 +1,11 @@ #include "DRIVER2.H" #include "XAPLAY.H" -#include "MAIN.H" + + +#include "CAMERA.H" +#include "FMVPLAY.H" #include "SOUND.H" -#include "SPOOL.H" +#include "PRES.H" #ifndef PSX @@ -11,9 +14,13 @@ #include "../utils/audio_source/snd_wav_cache.h" #include "AL/al.h" +#include "AL/alext.h" + +#include "LIBETC.H" const char* XANameFormat = "DRIVER2\\XA\\XABNK0%d.XA[%d].wav"; ALuint g_XASource = AL_NONE; +CSoundSource_WaveCache* g_wavData = NULL; CSoundSource_OpenALCache* g_XAWave = NULL; #else @@ -39,6 +46,37 @@ static CdlLOC pause_loc; static unsigned long buffer[8]; XA_TRACK XAMissionMessages[4]; +#ifndef PSX +int gXASubtitleTime = 0; + +void PrintXASubtitles() +{ + if (gSubtitles == 0) + return; + + if (gPlaying == 0 || g_wavData == NULL) + return; + + int curTime = (VSync(-1) - gXASubtitleTime) * 17; + + // find subtitles + for(int i = 0; i < g_wavData->m_numSubtitles; i++) + { + CUESubtitle_t* sub = &g_wavData->m_subtitles[i]; + + int subStartFrame = sub->sampleStart; + int subEndFrame = sub->sampleStart + sub->sampleLength; + + if(curTime >= subStartFrame && curTime <= subEndFrame) + { + SetTextColour(120, 120, 120); + PrintStringCentred(sub->text, 230); + } + } +} +#endif + + // decompiled code // original method signature: // void /*$ra*/ GetMissionXAData(int number /*$s0*/) @@ -227,6 +265,8 @@ void PrepareXA(void) { alGenSources(1, &g_XASource); alSourcei(g_XASource, AL_LOOPING, 0); + alSourcei(g_XASource, AL_SOURCE_RESAMPLER_SOFT, 2); // Use cubic resampler + alSourcei(g_XASource, AL_SOURCE_RELATIVE, AL_TRUE); if (g_XAWave) { @@ -297,10 +337,11 @@ void PlayXA(int num, int index) char fileName[250]; sprintf(fileName, XANameFormat, num+1, index); - CSoundSource_WaveCache wavData; - if (wavData.Load(fileName)) + g_wavData = new CSoundSource_WaveCache(); + + if (g_wavData->Load(fileName)) { - g_XAWave = new CSoundSource_OpenALCache(&wavData); + g_XAWave = new CSoundSource_OpenALCache(g_wavData); alSourcei(g_XASource, AL_BUFFER, g_XAWave->m_alBuffer); @@ -312,6 +353,7 @@ void PlayXA(int num, int index) gPlaying = 1; xa_prepared = 2; + gXASubtitleTime = VSync(-1); } #endif } @@ -400,6 +442,9 @@ void UnprepareXA(void) if (g_XAWave) { + delete g_wavData; + g_wavData = NULL; + delete g_XAWave; g_XAWave = NULL; } diff --git a/src_rebuild/GAME/C/XAPLAY.H b/src_rebuild/GAME/C/XAPLAY.H index ea86adc5..c48b064b 100644 --- a/src_rebuild/GAME/C/XAPLAY.H +++ b/src_rebuild/GAME/C/XAPLAY.H @@ -1,6 +1,7 @@ #ifndef XAPLAY_H #define XAPLAY_H +extern void PrintXASubtitles(); extern void GetMissionXAData(int number); // 0x00082EC0 diff --git a/src_rebuild/utils/audio_source/snd_wav_source.cpp b/src_rebuild/utils/audio_source/snd_wav_source.cpp index c1653f8c..70a2363f 100644 --- a/src_rebuild/utils/audio_source/snd_wav_source.cpp +++ b/src_rebuild/utils/audio_source/snd_wav_source.cpp @@ -1,12 +1,22 @@ #include "snd_wav_source.h" #include #include +#include //--------------------------------------------------------------------- CSoundSource_Wave::CSoundSource_Wave() : m_loopStart(0), m_loopEnd(0), m_numSamples(0) { + m_numSubtitles = 0; +} +CSoundSource_Wave::~CSoundSource_Wave() +{ + for(int i = 0; i < m_numSubtitles; i++) + { + free(m_subtitles[i].text); + } + } void CSoundSource_Wave::ParseChunk(CRIFF_Parser &chunk) @@ -19,6 +29,8 @@ void CSoundSource_Wave::ParseChunk(CRIFF_Parser &chunk) memcpy(namestr, name, 4); namestr[4] = 0; + //printf("chunk ID %s\n", namestr); + switch ( chunk.GetName() ) { case CHUNK_FMT: @@ -27,6 +39,9 @@ void CSoundSource_Wave::ParseChunk(CRIFF_Parser &chunk) case CHUNK_CUE: ParseCue( chunk ); break; + case CHUNK_LIST: + ParseList( chunk ); + break; case CHUNK_DATA: ParseData( chunk ); break; @@ -50,14 +65,93 @@ void CSoundSource_Wave::ParseFormat(CRIFF_Parser &chunk) void CSoundSource_Wave::ParseCue(CRIFF_Parser &chunk) { - wavcuehdr_t cue; + int count; + chunk.ReadChunk(&count, sizeof(int)); - chunk.ReadChunk( (u_char *)&cue, sizeof(wavcuehdr_t) ); - m_loopStart = cue.SampleOffset; + // now read all CUEs + for(int i = 0; i < count; i++) + { + wavcuehdr_t cue; + + chunk.ReadChunk( (u_char *)&cue, sizeof(wavcuehdr_t) ); + m_loopStart = cue.SampleOffset; + + //printf("CUE %d time: %d ms (%d)\n", i+1, sampleTimeMilliseconds, cue.SampleOffset); + + CUESubtitle_t& sub = m_subtitles[m_numSubtitles]; + sub.sampleStart = float(cue.SampleOffset) / float(m_format.frequency) * 1000.0f; + sub.sampleLength = 0; + sub.text = NULL; + m_numSubtitles++; + } // dont care about the rest } +struct wavltxthdr_t +{ + uint CueId; + uint SampleLen; + uint PurposeId; + ushort Country; + ushort Language; + ushort Dialect; + ushort CodePage; +}; + +void CSoundSource_Wave::ParseList(CRIFF_Parser &chunk) +{ + int adtl; + chunk.ReadChunk(&adtl, sizeof(int)); + + if(adtl == CHUNK_ADTLLIST) + { + int remainingSize = chunk.GetSize() -4; + + while(remainingSize > 0) + { + RIFFchunk_t listChunk; + + int read = chunk.ReadChunk(&listChunk, sizeof(listChunk)); + remainingSize -= read; + + char* name = (char*)&listChunk.Id; + + char namestr[5]; + memcpy(namestr, name, 4); + namestr[4] = 0; + + if(listChunk.Id == CHUNK_LTXT) + { + wavltxthdr_t ltxt; + int read = chunk.ReadChunk(<xt, sizeof(wavltxthdr_t)); + remainingSize -= read; + + m_subtitles[ltxt.CueId-1].sampleLength = float(ltxt.SampleLen) / float(m_format.frequency) * 1000.0f; + } + else if(listChunk.Id == CHUNK_LABEL) + { + char labelString[128]; + + int cueId; + int stringSize = listChunk.Size - 4 + (listChunk.Size & 1); + + int read = chunk.ReadChunk( &cueId, sizeof(int) ); + remainingSize -= read; + + m_subtitles[cueId - 1].text = (char*)malloc(stringSize); + + read = chunk.ReadChunk( m_subtitles[cueId - 1].text, stringSize ); + remainingSize -= read; + + + + //printf("Label cue = %d, size: %d, '%s'\n", cueId, stringSize, labelString); + } + } + } +} + void CSoundSource_Wave::ParseSample(CRIFF_Parser &chunk) { wavsamplehdr_t wsx; diff --git a/src_rebuild/utils/audio_source/snd_wav_source.h b/src_rebuild/utils/audio_source/snd_wav_source.h index f3b9c377..c6e00e04 100644 --- a/src_rebuild/utils/audio_source/snd_wav_source.h +++ b/src_rebuild/utils/audio_source/snd_wav_source.h @@ -7,14 +7,26 @@ //--------------------------------------------------------------------- +struct CUESubtitle_t +{ + int sampleStart; + int sampleLength; + + char* text; +}; + class CSoundSource_Wave : public ISoundSource { public: CSoundSource_Wave(); + virtual ~CSoundSource_Wave(); virtual soundFormat_t* GetFormat() { return &m_format; } virtual float GetLoopPosition(float flPosition); virtual int GetSampleCount() const { return m_numSamples; } + + CUESubtitle_t m_subtitles[128]; + int m_numSubtitles; protected: void ParseChunk(CRIFF_Parser &chunk); @@ -22,6 +34,7 @@ protected: virtual void ParseFormat(CRIFF_Parser &chunk); virtual void ParseCue(CRIFF_Parser &chunk); virtual void ParseSample(CRIFF_Parser &chunk); + virtual void ParseList(CRIFF_Parser &chunk); virtual void ParseData(CRIFF_Parser &chunk) = 0; soundFormat_t m_format; diff --git a/src_rebuild/utils/riff.cpp b/src_rebuild/utils/riff.cpp index 5b85d420..4fa2902d 100644 --- a/src_rebuild/utils/riff.cpp +++ b/src_rebuild/utils/riff.cpp @@ -94,12 +94,15 @@ int CRIFF_Parser::ReadChunk( void* pOutput, int maxLen ) int readCount = ReadData( pOutput, numToRead); + numToRead -= readCount; + /* if (numToRead < m_curChunk.Size) { m_pos += m_curChunk.Size - numToRead; + if (m_riff) fseek(m_riff, m_curChunk.Size - numToRead, SEEK_CUR); - } + }*/ return readCount; } diff --git a/src_rebuild/utils/riff.h b/src_rebuild/utils/riff.h index aa1aecfd..c081800e 100644 --- a/src_rebuild/utils/riff.h +++ b/src_rebuild/utils/riff.h @@ -13,6 +13,10 @@ #define CHUNK_CUE ((' ' << 24) | ('e' << 16) | ('u' << 8) | 'c' ) #define CHUNK_DATA (('a' << 24) | ('t' << 16) | ('a' << 8) | 'd' ) #define CHUNK_SAMPLE (('l' << 24) | ('p' << 16) | ('m' << 8) | 's' ) +#define CHUNK_LTXT (('t' << 24) | ('x' << 16) | ('t' << 8) | 'l' ) +#define CHUNK_LABEL (('l' << 24) | ('b' << 16) | ('a' << 8) | 'l' ) +#define CHUNK_LIST (('T' << 24) | ('S' << 16) | ('I' << 8) | 'L' ) +#define CHUNK_ADTLLIST (('l' << 24) | ('t' << 16) | ('d' << 8) | 'a' ) // RIFF WAVE FILE HEADERS typedef struct From 95b0583d2cb4468bfe1cf303c658c8e20db3cb8a Mon Sep 17 00:00:00 2001 From: Ilya Shurumov Date: Fri, 9 Oct 2020 23:00:39 +0600 Subject: [PATCH 19/41] - fix XA subtitles pause handling --- src_rebuild/GAME/C/XAPLAY.C | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src_rebuild/GAME/C/XAPLAY.C b/src_rebuild/GAME/C/XAPLAY.C index 5bd14b71..29957ecc 100644 --- a/src_rebuild/GAME/C/XAPLAY.C +++ b/src_rebuild/GAME/C/XAPLAY.C @@ -4,6 +4,7 @@ #include "CAMERA.H" #include "FMVPLAY.H" +#include "PAUSE.H" #include "SOUND.H" #include "PRES.H" @@ -48,10 +49,11 @@ XA_TRACK XAMissionMessages[4]; #ifndef PSX int gXASubtitleTime = 0; +int gXASubtitlePauseTime = 0; void PrintXASubtitles() { - if (gSubtitles == 0) + if (gSubtitles == 0 || pauseflag) return; if (gPlaying == 0 || g_wavData == NULL) @@ -70,7 +72,7 @@ void PrintXASubtitles() if(curTime >= subStartFrame && curTime <= subEndFrame) { SetTextColour(120, 120, 120); - PrintStringCentred(sub->text, 230); + PrintStringCentred(sub->text, 200); } } } @@ -353,6 +355,7 @@ void PlayXA(int num, int index) gPlaying = 1; xa_prepared = 2; + gXASubtitleTime = VSync(-1); } #endif @@ -595,6 +598,8 @@ void ResumeXA(void) alSourcef(g_XASource, AL_GAIN, float(vol) / 128.0f); alSourcePlay(g_XASource); + + gXASubtitleTime += VSync(-1) - gXASubtitlePauseTime; } #endif } @@ -648,6 +653,7 @@ void PauseXA(void) if (xa_prepared && gPlaying) { alSourcePause(g_XASource); + gXASubtitlePauseTime = VSync(-1); } #endif } From 3e14d7ab3580bdfa5fe0d54dc2cd435cdc467e02 Mon Sep 17 00:00:00 2001 From: Ilya Shurumov Date: Sat, 10 Oct 2020 02:13:31 +0600 Subject: [PATCH 20/41] - civ AI don't honk to tailed cars --- src_rebuild/GAME/C/CIV_AI.C | 5 +++-- src_rebuild/GAME/C/COP_AI.C | 6 +++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src_rebuild/GAME/C/CIV_AI.C b/src_rebuild/GAME/C/CIV_AI.C index 9d00beae..aa515529 100644 --- a/src_rebuild/GAME/C/CIV_AI.C +++ b/src_rebuild/GAME/C/CIV_AI.C @@ -24,6 +24,7 @@ #include "OBJCOLL.H" #include "INLINE_C.H" +#include "OVERLAY.H" unsigned char speedLimits[3] = { 56, 97, 138 }; @@ -4809,8 +4810,8 @@ void SetUpCivCollFlags(void) // do horns // horn to player and chased cars (except Steal the Ambulance) if (cp0->ai.c.thrustState != 3 && - (cp1->controlType == CONTROL_TYPE_PLAYER || (cp1->controlType == CONTROL_TYPE_CUTSCENE && gCurrentMissionNumber != 26) || - CAR_INDEX(cp1) == 20)) + (cp1->controlType == CONTROL_TYPE_PLAYER || cp1->controlType == CONTROL_TYPE_CUTSCENE && gCurrentMissionNumber != 26 && ProxyBar.active == 0 || + CAR_INDEX(cp1) == 20)) { int dont; int rnd; diff --git a/src_rebuild/GAME/C/COP_AI.C b/src_rebuild/GAME/C/COP_AI.C index 99918b41..9e152257 100644 --- a/src_rebuild/GAME/C/COP_AI.C +++ b/src_rebuild/GAME/C/COP_AI.C @@ -396,7 +396,7 @@ void ControlCops(void) int direction; int iVar5; -#if defined(COLLISION_DEBUG) // [A] lineClear debugging code - pls remove after fixing bugs +#if 0 // [A] lineClear debugging code - pls remove after fixing bugs extern int gShowCollisionDebug; if (gShowCollisionDebug == 3) { @@ -798,6 +798,8 @@ void CopControl1(_CAR_DATA *cp) cp->ai.p.frontLClear = CellAtPositionEmpty(&pos, 80); #ifdef COLLISION_DEBUG + extern int gShowCollisionDebug; + if (gShowCollisionDebug == 3) { extern void Debug_AddLine(VECTOR & pointA, VECTOR & pointB, CVECTOR & color); extern void Debug_AddLineOfs(VECTOR & pointA, VECTOR & pointB, VECTOR & ofs, CVECTOR & color); @@ -819,6 +821,8 @@ void CopControl1(_CAR_DATA *cp) cp->ai.p.frontRClear = CellAtPositionEmpty(&pos, 80); #ifdef COLLISION_DEBUG + extern int gShowCollisionDebug; + if (gShowCollisionDebug == 3) { extern void Debug_AddLine(VECTOR & pointA, VECTOR & pointB, CVECTOR & color); extern void Debug_AddLineOfs(VECTOR & pointA, VECTOR & pointB, VECTOR & ofs, CVECTOR & color); From d1266bdfbc3bb93da89869837a29109138e76cd3 Mon Sep 17 00:00:00 2001 From: Ilya Shurumov Date: Sat, 10 Oct 2020 02:13:49 +0600 Subject: [PATCH 21/41] - chase selection from debug menu --- src_rebuild/GAME/C/GLAUNCH.C | 6 +++--- src_rebuild/GAME/C/PAUSE.C | 8 ++++++-- src_rebuild/GAME/C/REPLAYS.C | 17 +++++++++++++++++ 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src_rebuild/GAME/C/GLAUNCH.C b/src_rebuild/GAME/C/GLAUNCH.C index d0ed5df2..f554f01e 100644 --- a/src_rebuild/GAME/C/GLAUNCH.C +++ b/src_rebuild/GAME/C/GLAUNCH.C @@ -137,7 +137,7 @@ int gLoadedReplay = 0; int gHaveStoredData = 0; int gLastChase = 0; -int gChaseNumber = -1; +int gChaseNumber = 0; int gRandomChase = 0; int gSubGameNumber = 0; @@ -595,7 +595,7 @@ void RunMissionLadder(int newgame) void GetRandomChase(void) { // [A] debug - if (gChaseNumber != -1) + if (gChaseNumber != 0) { gRandomChase = gChaseNumber; return; @@ -610,7 +610,7 @@ void GetRandomChase(void) if (gRandomChase == gLastChase) { do { - gRandomChase = (VSync(-1) + bump) % 0xd + 2; + gRandomChase = (VSync(-1) + bump) % 13 + 2; bump++; } while (gRandomChase == gLastChase); } diff --git a/src_rebuild/GAME/C/PAUSE.C b/src_rebuild/GAME/C/PAUSE.C index 08ed2b09..aba52bba 100644 --- a/src_rebuild/GAME/C/PAUSE.C +++ b/src_rebuild/GAME/C/PAUSE.C @@ -199,12 +199,16 @@ MENU_HEADER DebugJustForFunHeader = #ifdef CUTSCENE_RECORDER extern void NextCutsceneRecorderPlayer(int dir); extern char gCutsceneRecorderPauseText[64]; + +extern void NextChase(int dir); +extern char gCurrentChasePauseText[64]; #endif MENU_ITEM DebugOptionsItems[] = { -#if 0 // TODO: enable - { gCutsceneRecorderPauseText, 5u, 2u, (pauseFunc)&NextCutsceneRecorderPlayer, MENU_QUIT_NONE, NULL }, +#ifdef CUTSCENE_RECORDER + //{ gCutsceneRecorderPauseText, 5u, 2u, (pauseFunc)&NextCutsceneRecorderPlayer, MENU_QUIT_NONE, NULL }, + { gCurrentChasePauseText, 5u, 2u, (pauseFunc)&NextChase, MENU_QUIT_NONE, NULL }, #endif { "Back on Wheels", 3, 2, SetRightWayUp, MENU_QUIT_NONE, NULL}, { "Time of Day", 65, 2, NULL, MENU_QUIT_NONE, &DebugTimeOfDayHeader }, diff --git a/src_rebuild/GAME/C/REPLAYS.C b/src_rebuild/GAME/C/REPLAYS.C index 8cac7214..2b2b2ca8 100644 --- a/src_rebuild/GAME/C/REPLAYS.C +++ b/src_rebuild/GAME/C/REPLAYS.C @@ -294,6 +294,23 @@ int gCutsceneAsReplay = 0; int gCutsceneAsReplay_PlayerId = 0; int gCutsceneAsReplay_PlayerChanged = 0; char gCutsceneRecorderPauseText[64] = { 0 }; +char gCurrentChasePauseText[64] = { 0 }; + +void NextChase(int dir) +{ + if(dir > 0) + gChaseNumber++; + else if(dir < 0) + gChaseNumber--; + + if (gChaseNumber < 0) + gChaseNumber = 0; + + if (gChaseNumber > 15) + gChaseNumber = 15; + + sprintf(gCurrentChasePauseText, "Chase ID: %d", gChaseNumber); +} void NextCutsceneRecorderPlayer(int dir) { From ad1de1c1084a4b1a0d4342d9beda8d43c1367f21 Mon Sep 17 00:00:00 2001 From: Ilya Shurumov Date: Sun, 11 Oct 2020 02:09:34 +0600 Subject: [PATCH 22/41] - car lod distance improve --- src_rebuild/GAME/C/CARS.C | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src_rebuild/GAME/C/CARS.C b/src_rebuild/GAME/C/CARS.C index 3d423424..546c1f70 100644 --- a/src_rebuild/GAME/C/CARS.C +++ b/src_rebuild/GAME/C/CARS.C @@ -23,6 +23,11 @@ #include "INLINE_C.H" #include "LIBAPI.H" +#ifndef PSX +const int CAR_LOD_SWITCH_DISTANCE = 12500; +#else +const int CAR_LOD_SWITCH_DISTANCE = 5500; +#endif MATRIX light_matrix = { { { 4096, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 } }, { 0, 0, 0 } }; @@ -862,7 +867,7 @@ void DrawCar(_CAR_DATA *cp, int view) } // LOD switching - if (pos.vz < 5501 && gForceLowDetailCars == 0 || cp->controlType == CONTROL_TYPE_PLAYER) + if (pos.vz <= CAR_LOD_SWITCH_DISTANCE && gForceLowDetailCars == 0 || cp->controlType == CONTROL_TYPE_PLAYER) { int blackSmoke = 0; From 8a7b5bb27410aad94560484a9f37f451d33ab42f Mon Sep 17 00:00:00 2001 From: Ilya Shurumov Date: Sun, 11 Oct 2020 02:10:50 +0600 Subject: [PATCH 23/41] - fix main() - Release build --- src_rebuild/GAME/C/MAIN.C | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src_rebuild/GAME/C/MAIN.C b/src_rebuild/GAME/C/MAIN.C index 137fd739..bf7570b7 100644 --- a/src_rebuild/GAME/C/MAIN.C +++ b/src_rebuild/GAME/C/MAIN.C @@ -2579,8 +2579,9 @@ int redriver2_main(int argc, char** argv) i++; LaunchGame(); } + else #endif // _DEBUG_OPTIONS - else if (!_stricmp(argv[i], "-nofmv")) + if (!_stricmp(argv[i], "-nofmv")) { gNoFMV = 1; } From db15e79765946d9799e405d5b4fc9d55c188974b Mon Sep 17 00:00:00 2001 From: Ilya Shurumov Date: Sun, 11 Oct 2020 14:50:22 +0600 Subject: [PATCH 24/41] - fix incomplete road blocks --- src_rebuild/GAME/C/CIV_AI.C | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src_rebuild/GAME/C/CIV_AI.C b/src_rebuild/GAME/C/CIV_AI.C index aa515529..0301c559 100644 --- a/src_rebuild/GAME/C/CIV_AI.C +++ b/src_rebuild/GAME/C/CIV_AI.C @@ -6002,15 +6002,14 @@ void CreateRoadblock(void) GetNodePos(str, NULL, crv, distAlongSegment, NULL, (int*)&startPos.vx, (int*)&startPos.vz, 0); - laneNo = numLanes - 1; - GetNodePos(str, NULL, crv, distAlongSegment, NULL, (int*)&endPos, (int*)&endPos.vz, laneNo); + GetNodePos(str, NULL, crv, distAlongSegment, NULL, (int*)&endPos, (int*)&endPos.vz, numLanes - 1); dir2NextRow = ratan2(endPos.vx - startPos.vx, endPos.vz - startPos.vz); delta = 256; - while (delta < (numLanes-1) * 512) + while (delta < numLanes * 512) { - laneNo = (delta >> 10); + laneNo = (delta >> 9); currentPos.vx = startPos.vx + FIXEDH(delta * rcossin_tbl[(dir2NextRow & 0xfff) * 2]); currentPos.vz = startPos.vz + FIXEDH(delta * rcossin_tbl[(dir2NextRow & 0xfff) * 2 + 1]); @@ -6018,7 +6017,7 @@ void CreateRoadblock(void) if((str && ROAD_IS_AI_LANE(str, laneNo) || crv && ROAD_IS_AI_LANE(crv, laneNo)) && CellEmpty(¤tPos, lbody)) { - newSlot = CreateStationaryCivCar(dir2NextRow + (Random2(0) * 0x10001 >> (delta >> 9 & 0x1fU) & 0x3ffU) - 512, 0, 0, (long(*)[4]) & currentPos, externalCopModel, 0, 2); + newSlot = CreateStationaryCivCar(dir2NextRow + (Random2(0) * 0x10001 >> (laneNo) & 0x3ffU) - 512, 0, 0, (long(*)[4]) & currentPos, externalCopModel, 0, 2); if (newSlot == -1) break; From 554decc991475c1061e3ef90d3615687a8d25f97 Mon Sep 17 00:00:00 2001 From: Ilya Shurumov Date: Sun, 11 Oct 2020 16:19:12 +0600 Subject: [PATCH 25/41] - PEDEST.C refactoring progress --- src_rebuild/GAME/C/PEDEST.C | 1656 ++++++++++++++++------------------ src_rebuild/GAME/DR2LIMITS.H | 1 + 2 files changed, 774 insertions(+), 883 deletions(-) diff --git a/src_rebuild/GAME/C/PEDEST.C b/src_rebuild/GAME/C/PEDEST.C index 93bab5d4..c6fd0bee 100644 --- a/src_rebuild/GAME/C/PEDEST.C +++ b/src_rebuild/GAME/C/PEDEST.C @@ -33,20 +33,20 @@ MODEL* pmTannerModels[17] = { 0 }; MODEL* pmJerichoModels[6] = { 0 }; -void PedDoNothing(PEDESTRIAN *pPed); -void PedUserWalker(PEDESTRIAN *pPed); -void PedUserRunner(PEDESTRIAN *pPed); -void PedGetInCar(PEDESTRIAN *pPed); -void PedGetOutCar(PEDESTRIAN *pPed); -void PedCarryOutAnimation(PEDESTRIAN *pPed); -void CivPedDoNothing(PEDESTRIAN *pPed); -void CivPedWalk(PEDESTRIAN *pPed); -void CivPedSit(PEDESTRIAN *pPed); -void CivPedJump(PEDESTRIAN *pPed); -void PedPressButton(PEDESTRIAN *pPed); -void TannerSitDown(PEDESTRIAN *pPed); -void CopStand(PEDESTRIAN *pPed); -void CivGetIn(PEDESTRIAN *pPed); +void PedDoNothing(PEDESTRIAN* pPed); +void PedUserWalker(PEDESTRIAN* pPed); +void PedUserRunner(PEDESTRIAN* pPed); +void PedGetInCar(PEDESTRIAN* pPed); +void PedGetOutCar(PEDESTRIAN* pPed); +void PedCarryOutAnimation(PEDESTRIAN* pPed); +void CivPedDoNothing(PEDESTRIAN* pPed); +void CivPedWalk(PEDESTRIAN* pPed); +void CivPedSit(PEDESTRIAN* pPed); +void CivPedJump(PEDESTRIAN* pPed); +void PedPressButton(PEDESTRIAN* pPed); +void TannerSitDown(PEDESTRIAN* pPed); +void CopStand(PEDESTRIAN* pPed); +void CivGetIn(PEDESTRIAN* pPed); pedFunc fpPedPersonalityFunctions[] = { PedDoNothing, @@ -73,12 +73,9 @@ VECTOR tannerLookAngle = { 0, 0, 0, 0 }; const int tannerTurnMax = 16; const int tannerTurnStep = 4; -long force[4] = { 0x9000, 0, 0, 0 }; -long point[4] = { 0, 0, 90, 0 }; - int bKillTanner = 0; -SEATED_PEDESTRIANS *seated_pedestrian; // lump +SEATED_PEDESTRIANS* seated_pedestrian; // lump int seated_count; int maxSeated; static int numTannerPeds = 0; @@ -87,9 +84,9 @@ int pinginPedAngle = 0; PEDESTRIAN pedestrians[MAX_PEDESTRIANS]; -PEDESTRIAN *pUsedPeds = NULL; // linked list of pedestrians -PEDESTRIAN *pFreePeds = NULL; -PEDESTRIAN *pHold = NULL; +PEDESTRIAN* pUsedPeds = NULL; // linked list of pedestrians +PEDESTRIAN* pFreePeds = NULL; +PEDESTRIAN* pHold = NULL; int max_pedestrians; int num_pedestrians; @@ -141,28 +138,31 @@ int bPower = 0; int oldWeather = 0; int powerCounter = 0; -// [D] +// [D] [T] // Havana easter egg. void IHaveThePower(void) { - _CAR_DATA *cp; + _CAR_DATA* cp; + long force[4] = { 0x9000, 0, 0, 0 }; + long point[4] = { 0, 0, 90, 0 }; if (GameLevel != 1) return; - if (player[0].pos[0] > -231749 || player[0].pos[0] < -232147 || + if (player[0].pos[0] > -231749 || player[0].pos[0] < -232147 || player[0].pos[2] < -236229 || player[0].pos[2] > -235831) { // if player gets out the zone, restore weather back - if (bPower != 0) + if (bPower != 0) { bPower = 0; gWeather = oldWeather; } + return; } - if ((tannerPad & 0x20) != 0) + if (tannerPad & 0x20) { if (bPower == 0) { @@ -191,7 +191,7 @@ void IHaveThePower(void) } cp++; - } while (cp < &car_data[20]); + } while (cp < &car_data[MAX_CARS]); } if (powerCounter > 48) @@ -252,25 +252,32 @@ void IHaveThePower(void) /* end block 4 */ // End Line: 2398 -void ProcessTannerPad(PEDESTRIAN *pPed, ulong pad, char PadSteer, char use_analogue) +// [D] [T] +void ProcessTannerPad(PEDESTRIAN* pPed, ulong pad, char PadSteer, char use_analogue) { - PED_ACTION_TYPE PVar1; - int iVar2; - int iVar3; - int iVar4; - _sdPlane *SurfacePtr; - short surface; - uint uVar8; + _sdPlane* SurfacePtr; + int direction; VECTOR vec; VECTOR normal; VECTOR out; VECTOR tVec; - _sdPlane *plane; + _sdPlane* plane; + _PLAYER* lcp; + int padId; + + padId = ABS(pPed->padId); plane = NULL; - tannerPad = pad; - if (use_analogue) + lcp = &player[padId]; + + // don't move dead Tanner + if(lcp->dying != 0) + tannerPad = 0; + else + tannerPad = pad; + + if (use_analogue) { tannerPad = pad; @@ -284,71 +291,73 @@ void ProcessTannerPad(PEDESTRIAN *pPed, ulong pad, char PadSteer, char use_analo vec.vy = -pPed->position.vy; vec.vz = pPed->position.vz; - uVar8 = (int)pPed->dir.vy - 0x800U & 0xfff; - - tVec.vx = vec.vx + (rcossin_tbl[uVar8 * 2] * 5 >> 9); + direction = pPed->dir.vy - 0x800U & 0xfff; + + tVec.vx = vec.vx + (rcossin_tbl[direction * 2] * 5 >> 9); tVec.vy = vec.vy; - tVec.vz = vec.vz + (rcossin_tbl[uVar8 * 2 + 1] * 5 >> 9); + tVec.vz = vec.vz + (rcossin_tbl[direction * 2 + 1] * 5 >> 9); bStopTanner = 0; int mapheight[2]; - + mapheight[0] = -130 - MapHeight(&vec); mapheight[1] = -130 - MapHeight(&tVec); - int dist = mapheight[1] - mapheight[0]; + int dist = ABS(mapheight[1] - mapheight[0]); - if (dist < 0) - dist = mapheight[0] - mapheight[1]; - - if (dist < 1011) + // check slope + if (dist <= 1010) { SurfacePtr = sdGetCell(&tVec); - surface = -32; if (SurfacePtr != NULL) { - surface = SurfacePtr->surface; + dist = ABS(((SurfacePtr->b >> 2) - 2048 & 0xfff) - 2048); - uVar8 = ((int)((uint)(ushort)SurfacePtr->b << 0x10) >> 0x12) - 2048 & 0xfff; - dist = uVar8 - 2048; - - if (dist < 0) - dist = 2048 - uVar8; - - if (dist < 1101) + if (dist <= 1100) { - switch (surface) + switch (SurfacePtr->surface) { - case -32: - case 6: - case 9: - break; - default: - dist = -1; - break; + case -32: + break; + //case 6: // water. We allow to walk on water in Rio a little bit. Then he drowns + case 9: // water with fade out + default: + dist = -1; + break; } } } } + // can't walk in water if (dist != -1) bStopTanner = 1; - if ((pPed->type != PED_ACTION_SIT) && !bStopTanner) + if (pPed->type != PED_ACTION_SIT && !bStopTanner) pPed->position.vy = mapheight[0]; - if ((gInGameCutsceneActive == 0 || gCurrentMissionNumber != 23) || - ((gInGameCutsceneID != 0 || (CameraCnt != 0x1cb || ((pPed->pedType == TANNER_MODEL) || (ActiveCheats.cheat12 && (pPed->pedType == OTHER_MODEL))))))) + // "Car Bomb" cutscene + if (gInGameCutsceneActive && gCurrentMissionNumber == 23 && + gInGameCutsceneID == 0 && CameraCnt == 459 && pPed->pedType != TANNER_MODEL && + (!ActiveCheats.cheat12 || pPed->pedType != OTHER_MODEL)) { - if ((tannerPad & 0x10) != 0) + lcp->pPed = NULL; + lcp->playerType = 0; + + DestroyPedestrian(pPed); + return; + } + + // do actions + if (tannerPad & 0x10) + { + if (gTannerActionNeeded) { - if (gTannerActionNeeded) + // attempt to push a button + switch (pPed->type) { - // attempt to push a button - switch (pPed->type) - { case PED_ACTION_GETINCAR: case PED_ACTION_GETOUTCAR: // do not attempt @@ -357,13 +366,14 @@ void ProcessTannerPad(PEDESTRIAN *pPed, ulong pad, char PadSteer, char use_analo // hey, wait -- TANNER! SetupPressButton(pPed); break; - } } - else + } + else + { + // priority. Try to get into car first + // attempt to get into a car + switch (pPed->type) { - // attempt to get into a car - switch (pPed->type) - { case PED_ACTION_GETINCAR: case PED_ACTION_GETOUTCAR: // do not attempt @@ -371,13 +381,17 @@ void ProcessTannerPad(PEDESTRIAN *pPed, ulong pad, char PadSteer, char use_analo default: // enter the nearest car if possible if (!gCantDrive) + { DeActivatePlayerPedestrian(pPed); - break; - } + break; + } - // attempt to sit down - switch (pPed->type) - { + break; + } + + // attempt to sit down + switch (pPed->type) + { case PED_ACTION_GETINCAR: case PED_ACTION_GETOUTCAR: case PED_ACTION_SIT: @@ -386,56 +400,44 @@ void ProcessTannerPad(PEDESTRIAN *pPed, ulong pad, char PadSteer, char use_analo default: // sit his ass down if (FindTannerASeat(pPed) != NULL) + { SetupTannerSitDown(pPed); - } - } - } - - if (pPed != NULL) - { - if (pPed->fpAgitatedState != NULL) - (*pPed->fpAgitatedState)(pPed); - else - (*pPed->fpRestState)(pPed); - - if (player[0].cameraView == 2 && pPed->type != PED_ACTION_GETINCAR) - { - if (oldCamView != player[0].cameraView) - { - camAngle.vx = camera_angle.vx; - camAngle.vz = camera_angle.vz; - } - - camAngle.vy = player[0].headPos - player[0].dir & 0xfff; - TannerCameraHandler(pPed); - } - - oldCamView = player[0].cameraView; - TannerCollision(pPed); - - // sloped surfaces in chicago? - if (GameLevel == 0) - { - FindSurfaceD2((VECTOR *)player, &normal, &out, &plane); - - if (plane->surface != -1 && plane->surface < 0x20 && (plane->surface & 0x10U) != 0) - { - pPed->position.vx += (normal.vx >> 6); - pPed->position.vz += (normal.vz >> 6); - } + break; + } } } } - else + + if (pPed->fpAgitatedState != NULL) + (*pPed->fpAgitatedState)(pPed); + else + (*pPed->fpRestState)(pPed); + + if (lcp->cameraView == 2 && pPed->type != PED_ACTION_GETINCAR) { - iVar2 = pPed->padId; - if (iVar2 < 0) - iVar2 = -iVar2; + if (oldCamView != lcp->cameraView) + { + camAngle.vx = camera_angle.vx; + camAngle.vz = camera_angle.vz; + } - player[iVar2].pPed = NULL; - player[iVar2].playerType = 0; + camAngle.vy = lcp->headPos - player[0].dir & 0xfff; + TannerCameraHandler(pPed); + } - DestroyPedestrian(pPed); + oldCamView = lcp->cameraView; + TannerCollision(pPed); + + // chicago bridge slope + if (GameLevel == 0) + { + FindSurfaceD2((VECTOR*)lcp->pos, &normal, &out, &plane); + + if (plane->surface != -1 && plane->surface < 32 && (plane->surface & 0x10)) + { + pPed->position.vx += (normal.vx >> 6); + pPed->position.vz += (normal.vz >> 6); + } } } @@ -469,7 +471,7 @@ void ProcessTannerPad(PEDESTRIAN *pPed, ulong pad, char PadSteer, char use_analo /* WARNING: Unknown calling convention yet parameter storage is locked */ -// [D] +// [D] [T] void InitTanner(void) { pmTannerModels[0] = FindModelPtrWithName("TORSO"); @@ -535,19 +537,20 @@ void InitTanner(void) /* end block 4 */ // End Line: 11523 -// [D] -void SetTannerPosition(VECTOR *pVec) +// [D] [T] +void SetTannerPosition(VECTOR* pVec) { - PEDESTRIAN *pPed; + PEDESTRIAN* pPed; pPed = pUsedPeds; - while(pPed) + while (pPed) { - if ((pPed->pedType == TANNER_MODEL) || (ActiveCheats.cheat12 && (pPed->pedType == OTHER_MODEL))) + if (pPed->pedType == TANNER_MODEL || ActiveCheats.cheat12 && pPed->pedType == OTHER_MODEL) { pPed->position.vx = pVec->vx; pPed->position.vy = -pVec->vy; pPed->position.vz = pVec->vz; + player[0].pos[0] = pVec->vx; player[0].pos[1] = pVec->vy; player[0].pos[2] = pVec->vz; @@ -595,23 +598,22 @@ void SetTannerPosition(VECTOR *pVec) /* WARNING: Unknown calling convention yet parameter storage is locked */ -// [D] +// [D] [T] void InitPedestrians(void) { - short sVar1; - - SEATED_PEDESTRIANS *seatedptr; + int loop; + SEATED_PEDESTRIANS* seatedptr; memset(pedestrians, 0, sizeof(pedestrians)); DestroyPedestrians(); - PEDESTRIAN *lastPed = &pedestrians[0]; + PEDESTRIAN* lastPed = &pedestrians[0]; lastPed->pPrev = NULL; - for (int loop = 1; loop < MAX_PEDESTRIANS; loop++) + for (loop = 1; loop < MAX_PEDESTRIANS; loop++) { - PEDESTRIAN *currPed = &pedestrians[loop]; + PEDESTRIAN* currPed = &pedestrians[loop]; lastPed->pNext = currPed; currPed->pPrev = lastPed++; @@ -625,7 +627,7 @@ void InitPedestrians(void) seated_count = 0; seatedptr = seated_pedestrian; - if (seatedptr != NULL) + if (seatedptr != NULL) { while (seatedptr->rotation != 9999) { @@ -642,6 +644,7 @@ void InitPedestrians(void) pPlayerPed = NULL; seated_count = 0; ping_in_pedestrians = 1; + numCopPeds = 0; } @@ -674,16 +677,16 @@ void InitPedestrians(void) /* WARNING: Unknown calling convention yet parameter storage is locked */ -// [D] +// [D] [T] void DestroyPedestrians(void) { while (pUsedPeds) { - if ((pUsedPeds->pedType == TANNER_MODEL) || (ActiveCheats.cheat12 && (pUsedPeds->pedType == OTHER_MODEL))) + if (pUsedPeds->pedType == TANNER_MODEL || ActiveCheats.cheat12 && pUsedPeds->pedType == OTHER_MODEL) numTannerPeds--; DestroyPedestrian(pUsedPeds); - }; + } num_pedestrians = 0; } @@ -721,11 +724,11 @@ void DestroyPedestrians(void) /* WARNING: Unknown calling convention yet parameter storage is locked */ -// [D] +// [D] [T] void DestroyCivPedestrians(void) { - PEDESTRIAN *pPed; - PEDESTRIAN *pHPed; + PEDESTRIAN* pPed; + PEDESTRIAN* pHPed; pPed = pUsedPeds; while (pPed != NULL) @@ -774,11 +777,11 @@ void DestroyCivPedestrians(void) /* end block 3 */ // End Line: 8581 -// [D] -void DestroyPedestrian(PEDESTRIAN *pPed) +// [D] [T] +void DestroyPedestrian(PEDESTRIAN* pPed) { - if ((pPed->flags & 8U) != 0) - numCopPeds--; + if (pPed->flags & 8) + numCopPeds--; // or road block pedestrians pPed->flags = 0; pPed->dir.vz = 0; @@ -789,24 +792,24 @@ void DestroyPedestrian(PEDESTRIAN *pPed) { pUsedPeds = pPed->pNext; - if(pUsedPeds) // [A] is this valid? Or it was by Reflections? + if (pUsedPeds) // [A] is this valid? Or it was by Reflections? pUsedPeds->pPrev = NULL; pPed->pNext = pFreePeds; - if(pFreePeds) + if (pFreePeds) pFreePeds->pPrev = pPed; } - else + else { - if(pPed->pPrev) + if (pPed->pPrev) pPed->pPrev->pNext = pPed->pNext; if (pPed->pNext) pPed->pNext->pPrev = pPed->pPrev; pPed->pNext = pFreePeds; - if(pFreePeds) + if (pFreePeds) pFreePeds->pPrev = pPed; pPed->pPrev = NULL; } @@ -885,64 +888,56 @@ void DestroyPedestrian(PEDESTRIAN *pPed) /* WARNING: Type propagation algorithm not settling */ -// [D] -int ActivatePlayerPedestrian(_CAR_DATA *pCar, char *padId, int direction, long(*position)[4], PED_MODEL_TYPES playerType) +// [D] [T] +int ActivatePlayerPedestrian(_CAR_DATA* pCar, char* padId, int direction, long(*position)[4], PED_MODEL_TYPES playerType) { - int iVar3; + int wbody; int side; int dir; - PEDESTRIAN *pedptr; - long lVar5; + PEDESTRIAN* pedptr; int playerId; - long lVar7; - VECTOR *pos; + VECTOR* pos; VECTOR v; long y; long d; _PLAYER* lp; + int x, z; if (numTannerPeds > 7) return 0; - if (padId == NULL) + if (padId == NULL) { playerId = GetPlayerId(pCar); lp = &player[playerId]; } else { - iVar3 = (int)*padId; - - playerId = -iVar3; - - if (iVar3 > -1) - playerId = iVar3; + playerId = ABS(*padId); pedptr = pUsedPeds; - if (pUsedPeds != NULL) - { - do { - if (pedptr->padId == iVar3) - { - player[playerId].pPed = pedptr; - return 0; - } - pedptr = pedptr->pNext; - } while (pedptr != NULL); + while (pedptr != NULL) + { + if (ABS(pedptr->padId) == playerId) + { + player[playerId].pPed = pedptr; + return 0; + } + + pedptr = pedptr->pNext; } lp = &player[playerId]; } - int x, z; - - if (pCar == NULL) + if (pCar == NULL) { x = (*position)[0]; z = (*position)[2]; - iVar3 = 1; + wbody = 1; + d = direction; y = 0; } @@ -953,15 +948,16 @@ int ActivatePlayerPedestrian(_CAR_DATA *pCar, char *padId, int direction, long(* y = pCar->hd.where.t[1]; d = pCar->hd.direction; - iVar3 = car_cosmetics[pCar->ap.model].colBox.vx; + + wbody = car_cosmetics[pCar->ap.model].colBox.vx; } - iVar3 += 90; + wbody += 90; dir = d - 0x800; v.vy = y; - v.vx = x - FIXED(iVar3 * rcossin_tbl[(d & 0xfffU) * 2 + 1]); - v.vz = z + FIXED(iVar3 * rcossin_tbl[(d & 0xfffU) * 2]); + v.vx = x - FIXED(wbody * rcossin_tbl[(d & 0xfffU) * 2 + 1]); + v.vz = z + FIXED(wbody * rcossin_tbl[(d & 0xfffU) * 2]); side = 0; @@ -973,16 +969,12 @@ int ActivatePlayerPedestrian(_CAR_DATA *pCar, char *padId, int direction, long(* v.vy = y; - v.vx = x - FIXED(-iVar3 * rcossin_tbl[(d & 0xfffU) * 2 + 1]); - v.vz = z + FIXED(-iVar3 * rcossin_tbl[(d & 0xfffU) * 2]); + v.vx = x - FIXED(-wbody * rcossin_tbl[(d & 0xfffU) * 2 + 1]); + v.vz = z + FIXED(-wbody * rcossin_tbl[(d & 0xfffU) * 2]); - iVar3 = QuickBuildingCollisionCheck(&v, dir, 10, 10, 10); - - if (iVar3 != 0) + if (QuickBuildingCollisionCheck(&v, dir, 10, 10, 10) != 0) return 0; - - iVar3 = TannerCarCollisionCheck(&v, d, 1); - if (iVar3 != 0) + if (TannerCarCollisionCheck(&v, d, 1) != 0) return 0; } } @@ -998,16 +990,10 @@ int ActivatePlayerPedestrian(_CAR_DATA *pCar, char *padId, int direction, long(* else pedptr->padId = *padId; - if (pedptr == NULL) - { - pos = NULL; - while (FrameCnt != 0x78654321) - { - trap(0x400); - } - } + if (pedptr) + pos = (VECTOR*)&pedptr->position; else - pos = (VECTOR *)&pedptr->position; + pos = NULL; if (pCar == NULL) { @@ -1015,7 +1001,7 @@ int ActivatePlayerPedestrian(_CAR_DATA *pCar, char *padId, int direction, long(* pedptr->fpAgitatedState = NULL; pedptr->fpRestState = fpPedPersonalityFunctions[0]; } - else + else { pedptr->type = PED_ACTION_GETOUTCAR; pedptr->fpRestState = fpPedPersonalityFunctions[0]; @@ -1025,7 +1011,7 @@ int ActivatePlayerPedestrian(_CAR_DATA *pCar, char *padId, int direction, long(* pedptr->position.vx = v.vx; pedptr->position.vz = v.vz; - if (pCar != NULL) + if (pCar != NULL) pedptr->position.vy = (pCar->hd).where.t[1]; pedptr->position.vy = -130 - MapHeight(pos); @@ -1039,7 +1025,7 @@ int ActivatePlayerPedestrian(_CAR_DATA *pCar, char *padId, int direction, long(* pedptr->pedType = playerType; SetupPedestrian(pedptr); - if (pCar == NULL) + if (pCar == NULL) { lp->cameraView = 0; lp->headPos = 0; @@ -1058,26 +1044,27 @@ int ActivatePlayerPedestrian(_CAR_DATA *pCar, char *padId, int direction, long(* lp->pPed = pedptr; lp->onGrass = 0; lp->dir = d; - + pedptr->frame1 = 0; pedptr->speed = 0; if (playerType == OTHER_SPRITE) { - if (gCurrentMissionNumber == 9) + if (gCurrentMissionNumber == 9) { pedptr->pallet = 68; } - else + else { - lVar5 = Random2(0); - lVar7 = Random2(0); - - pedptr->pallet = lVar5 - (lVar5 / 3) * 3 + (lVar7 - (lVar7 / 3) * 3) * 16; + pedptr->pallet = ((Random2(0) % 3) + (Random2(0) % 3)) * 16; + + //rnd1 = Random2(0); + //rnd2 = Random2(0); + //pedptr->pallet = rnd1 - (rnd1 / 3) * 3 + (rnd2 - (rnd2 / 3) * 3) * 16; } } } - else + else { MakeTheCarShutUp(playerId); Start3DSoundVolPitch(-1, 6, 2, lp->pos[0], lp->pos[1], lp->pos[2], 0, 0x1000); @@ -1102,7 +1089,6 @@ int ActivatePlayerPedestrian(_CAR_DATA *pCar, char *padId, int direction, long(* if (gCurrentMissionNumber == 23 && playerType != TANNER_MODEL) { pedptr->doing_turn = 16; - pedptr->dir.vy = (pedptr->dir.vy - (tannerTurnMax + 16) * tannerTurnStep) + 294; } @@ -1144,10 +1130,10 @@ int ActivatePlayerPedestrian(_CAR_DATA *pCar, char *padId, int direction, long(* /* WARNING: Unknown calling convention yet parameter storage is locked */ -// [D] -PEDESTRIAN * CreatePedestrian(void) +// [D] [T] +PEDESTRIAN* CreatePedestrian(void) { - PEDESTRIAN *pNewPed; + PEDESTRIAN* pNewPed; pNewPed = pFreePeds; if (pFreePeds != NULL) @@ -1228,89 +1214,74 @@ PEDESTRIAN * CreatePedestrian(void) /* WARNING: Unknown calling convention yet parameter storage is locked */ -// [D] +// [D] [T] void PlaceRoadBlockCops(void) { - short sVar1; - int iVar2; - int iVar3; - uint uVar4; - _CAR_DATA **pp_Var5; - _CAR_DATA *p_Var6; - int a; - int iVar8; - _CAR_DATA *pCar; - int iVar9; - int iVar10; - _CAR_DATA *pCopCars[16]; - VECTOR vert; + int wbody; + int lbody; + int cs, sn; + uint dir; + _CAR_DATA* cp; + _CAR_DATA* pCar; + int i; + int numCops; + _CAR_DATA* pCopCars[16]; long disp[4]; - long dir[4]; - iVar10 = 0; - if (numCopPeds < 8) - { - p_Var6 = car_data; + if (numCopPeds >= 8) + return; - pp_Var5 = pCopCars; - do { - if ((p_Var6->controlFlags & 2) != 0) - { - *pp_Var5++ = p_Var6; - iVar10++; - } - p_Var6++; - } while (p_Var6 < car_data + MAX_CARS); + numCops = 0; + + cp = car_data; + do { + if (cp->controlFlags & CONTROL_FLAG_COP_SLEEPING) + pCopCars[numCops++] = cp; - if (iVar10 != 0 && 0 < iVar10) - { - iVar9 = 0; - a = 0; - do { - pCar = pCopCars[iVar9]; + cp++; + } while (cp < &car_data[MAX_CARS]); - a = (pCar->hd).direction; - sVar1 = car_cosmetics[pCar->ap.model].colBox.vx; - iVar2 = rsin(a); - iVar3 = rcos(a); + if (!numCops) + return; - disp[0] = pCar->hd.where.t[0] - player[0].pos[0]; - disp[1] = player[0].pos[1] - pCar->hd.where.t[1]; - disp[2] = pCar->hd.where.t[2] - player[0].pos[2]; + i = 0; + do { + pCar = pCopCars[i]; + + sn = rsin(pCar->hd.direction); + cs = rcos(pCar->hd.direction); - a = car_cosmetics[pCar->ap.model].colBox.vx + 400; - iVar8 = car_cosmetics[pCar->ap.model].colBox.vz - 120; + disp[0] = pCar->hd.where.t[0] - player[0].pos[0]; + disp[1] = player[0].pos[1] - pCar->hd.where.t[1]; + disp[2] = pCar->hd.where.t[2] - player[0].pos[2]; + + lbody = car_cosmetics[pCar->ap.model].colBox.vz - 120; + wbody = car_cosmetics[pCar->ap.model].colBox.vx + 400; - if (FIXED(iVar3 * 0x1000) * disp[0] - FIXED(iVar2 * 0x1000) * disp[2] + 0x800 < 0) - a = -a; + if (FIXED(cs * 0x1000) * disp[0] - FIXED(sn * 0x1000) * disp[2] + 0x800 < 0) + wbody = -wbody; - uVar4 = pCar->hd.direction + 0x800U & 0xfff; - iVar3 = (int)rcossin_tbl[uVar4 * 2 + 1]; - iVar2 = (int)rcossin_tbl[uVar4 * 2]; + dir = pCar->hd.direction + 0x800U & 0xfff; + cs = rcossin_tbl[dir * 2 + 1]; + sn = rcossin_tbl[dir * 2]; - disp[0] = pCar->hd.where.t[0] - (FIXED(a * iVar3) - FIXED(iVar8 * iVar2)); - disp[1] = -pCar->hd.where.t[1]; - disp[2] = pCar->hd.where.t[2] + FIXED(a * iVar2) + FIXED(iVar8 * iVar3); + disp[0] = pCar->hd.where.t[0] - (FIXED(wbody * cs) - FIXED(lbody * sn)); + disp[1] = -pCar->hd.where.t[1]; + disp[2] = pCar->hd.where.t[2] + FIXED(wbody * sn) + FIXED(lbody * cs); - if (CreatePedAtLocation((long(*)[4])disp, 12) != 0) - numCopPeds++; + if (CreatePedAtLocation((long(*)[4])disp, 12) != 0) + numCopPeds++; - iVar3 = (int)rcossin_tbl[uVar4 * 2 + 1]; - iVar2 = (int)rcossin_tbl[uVar4 * 2]; + disp[0] = pCar->hd.where.t[0] - (FIXED(wbody * cs) - FIXED(-lbody * sn)); + disp[1] = -pCar->hd.where.t[1]; + disp[2] = pCar->hd.where.t[2] + FIXED(wbody * sn) + FIXED(-lbody * cs); - disp[0] = pCar->hd.where.t[0] - (FIXED(a * iVar3) - FIXED(-iVar8 * iVar2)); - disp[1] = -pCar->hd.where.t[1]; - disp[2] = pCar->hd.where.t[2] + FIXED(a * iVar2) + FIXED(-iVar8 * iVar3); + if (CreatePedAtLocation((long(*)[4])disp, 13) != 0) + numCopPeds++; - if (CreatePedAtLocation((long(*)[4])disp, 13) != 0) - numCopPeds++; - - iVar9++; - a = iVar9 * 4; - } while (iVar9 < iVar10); - } - } + i++; + } while (i < numCops); } @@ -1333,17 +1304,12 @@ void PlaceRoadBlockCops(void) /* end block 2 */ // End Line: 4496 -// [D] +// [D] [T] int CreatePedAtLocation(long(*pPos)[4], int pedType) { - PEDESTRIAN *pPed; + PEDESTRIAN* pPed; - if (pedType - 0xcU < 2) - { - if (numCopPeds > 7) - return 0; - } - else if (num_pedestrians > 15) + if (num_pedestrians >= MAX_PLACED_PEDS) return 0; pPed = CreatePedestrian(); @@ -1363,38 +1329,31 @@ int CreatePedAtLocation(long(*pPos)[4], int pedType) pPed->type = (PED_ACTION_TYPE)pedType; pPed->flags = 0; - pedFunc pedRestState = fpPedPersonalityFunctions[12]; - - if (pedType == 8) + pPed->fpRestState = fpPedPersonalityFunctions[12]; + + if (pedType == 8) { pPed->flags = 0; - pedRestState = fpPedPersonalityFunctions[7]; + pPed->fpRestState = fpPedPersonalityFunctions[7]; } - else + else if (pedType >= 8 && pedType <= 13) { - if (pedType < 8 || pedType > 13 || pedType < 12) - goto LAB_0006f100; - pPed->flags = 8; pPed->pallet = 85; } - pPed->fpRestState = pedRestState; - -LAB_0006f100: - pPed->fpAgitatedState = NULL; SetupPedMotionData(pPed); - if (pPed->type == PED_ACTION_COPSTAND) + if (pPed->type == PED_ACTION_COPSTAND) { pPed->position.vy = -(*pPos)[1]; - pPed->position.vy = -98 - MapHeight((VECTOR *)&pPed->position); + pPed->position.vy = -98 - MapHeight((VECTOR*)&pPed->position); } else if (pPed->type == PED_ACTION_COPCROUCH) { pPed->position.vy = -(*pPos)[1]; - pPed->position.vy = -62 - MapHeight((VECTOR *)&pPed->position); + pPed->position.vy = -62 - MapHeight((VECTOR*)&pPed->position); } return 1; @@ -1460,54 +1419,44 @@ LAB_0006f100: /* WARNING: Unknown calling convention yet parameter storage is locked */ -int PedVisible(PEDESTRIAN *pPed, int bounding_sphere) -{ - VECTOR *pos = (VECTOR *)&pPed->position; - - if (PositionVisible(pos) && FrustrumCheck(pos, bounding_sphere) != -1) - return 1; - - return 0; -} - -int DrawPedestrian(PEDESTRIAN *pPed) -{ - switch (pPed->type) - { - case PED_ACTION_CIVWALK: - case PED_ACTION_CIVRUN: - case PED_ACTION_JUMP: - case PED_ACTION_CIVSIT: - case PED_ACTION_COPSTAND: - case PED_ACTION_COPCROUCH: - DrawCiv(pPed); - return 1; - } - - return DrawCharacter(pPed); -} - -// [D] +// [D] [T] void DrawAllPedestrians(void) { - PEDESTRIAN *pPed; - MATRIX mStore; + PEDESTRIAN* pPed; - gte_ReadRotMatrix(&mStore); + //MATRIX mStore; + //gte_ReadRotMatrix(&mStore); pPed = pUsedPeds; while (pPed != NULL) { - if (pPed->pedType > OTHER_MODEL && PedVisible(pPed, 60)) - DrawPedestrian(pPed); + if (PositionVisible((VECTOR*)&pPed->position) && + FrustrumCheck((VECTOR*)&pPed->position, 60) != -1) + { + if(pPed->pedType <= OTHER_MODEL) + { + if (!bKillTanner) + DrawTanner(pPed); + } + else if(pPed->pedType == OTHER_SPRITE) + { + DrawCharacter(pPed); + } + else + { + DrawCiv(pPed); + } + } pPed = pPed->pNext; } + /* + // THIS IS OLD AND PROBABLY NOT NEEDED gte_SetRotMatrix(&mStore); - + pPed = pUsedPeds; - while (pPed != NULL) + while (pPed != NULL) { if (pPed->pedType < OTHER_SPRITE && PedVisible(pPed, 60)) { @@ -1516,7 +1465,7 @@ void DrawAllPedestrians(void) } pPed = pPed->pNext; - } + }*/ } @@ -1556,10 +1505,10 @@ void DrawAllPedestrians(void) /* WARNING: Unknown calling convention yet parameter storage is locked */ -// [D] +// [D] [T] int TannerActionHappening(void) { - PEDESTRIAN *pPed = player[0].pPed; + PEDESTRIAN* pPed = player[0].pPed; if (pPed && pPed->type == PED_ACTION_PRESSBUTTON) return pPed->frame1 == 14; @@ -1616,12 +1565,12 @@ int TannerActionHappening(void) int bAvoidTanner = 0; int bAvoidBomb = -1; -// [D] +// [D] [T] void ControlPedestrians(void) { - _CAR_DATA *pCar; - PEDESTRIAN *pPed; - PEDESTRIAN *pPedNext; + _CAR_DATA* pCar; + PEDESTRIAN* pPed; + PEDESTRIAN* pPedNext; pPed = pUsedPeds; @@ -1635,7 +1584,7 @@ void ControlPedestrians(void) if (pPed->fpAgitatedState == NULL) (*pPed->fpRestState)(pPed); - else + else (*pPed->fpAgitatedState)(pPed); if (pPed->type != PED_ACTION_GETINCAR) @@ -1646,7 +1595,7 @@ void ControlPedestrians(void) SetupCivJump(pPed, pCar); } - if (bAvoidTanner == 0) + if (bAvoidTanner == 0) { if (bAvoidBomb != -1) { @@ -1654,7 +1603,7 @@ void ControlPedestrians(void) bAvoidBomb = -1; } } - else + else { SetupCivJump(pPed, NULL); bAvoidTanner = 0; @@ -1675,7 +1624,7 @@ void ControlPedestrians(void) DestroyPedestrian(pPed); pPed = pHold; } - else + else { pPed = pPed->pNext; } @@ -1698,12 +1647,11 @@ void ControlPedestrians(void) /* end block 2 */ // End Line: 20723 -// [D] -void SetupDoNowt(PEDESTRIAN *pPed) +// [D] [T] +void SetupDoNowt(PEDESTRIAN* pPed) { pPed->speed = 0; pPed->dir.vz = 0; - //pPed->doing_turn = 0; pPed->type = PED_ACTION_BACK; SetupPedMotionData(pPed); @@ -1722,8 +1670,8 @@ void SetupDoNowt(PEDESTRIAN *pPed) /* end block 1 */ // End Line: 20768 -// [D] -void SetupWalker(PEDESTRIAN *pPed) +// [D] [T] +void SetupWalker(PEDESTRIAN* pPed) { pPed->type = PED_ACTION_WALK; pPed->speed = 14; @@ -1743,8 +1691,8 @@ void SetupWalker(PEDESTRIAN *pPed) /* end block 1 */ // End Line: 20803 -// [D] -void SetupRunner(PEDESTRIAN *pPed) +// [D] [T] +void SetupRunner(PEDESTRIAN* pPed) { pPed->type = PED_ACTION_RUN; pPed->frame1 = 0; @@ -1765,8 +1713,8 @@ void SetupRunner(PEDESTRIAN *pPed) /* end block 1 */ // End Line: 20827 -// [D] -void SetupBack(PEDESTRIAN *pPed) +// [D] [T] +void SetupBack(PEDESTRIAN* pPed) { pPed->type = PED_ACTION_WALK; pPed->frame1 = 0; @@ -1814,29 +1762,24 @@ void SetupBack(PEDESTRIAN *pPed) /* end block 4 */ // End Line: 18694 -_CAR_DATA *pCivCarToGetIn = NULL; +_CAR_DATA* pCivCarToGetIn = NULL; -// [D] -void CivGetIn(PEDESTRIAN *pPed) // [A] UNUSED +// [D] [T] +void CivGetIn(PEDESTRIAN* pPed) // [A] UNUSED { - uint uVar2; - DRIVER2_CURVE *curve; - DRIVER2_STRAIGHT *straight; + uint padid; + DRIVER2_CURVE* curve; + DRIVER2_STRAIGHT* straight; straight = NULL; curve = NULL; InitCivState(pCivCarToGetIn, NULL); - uVar2 = *pCivCarToGetIn->ai.padid; - - if ((uVar2 & 0xffffe000) == 0 && (uVar2 & 0x1fff) < NumDriver2Straights && uVar2 > -1) - { - straight = Driver2StraightsPtr + uVar2; - } + + if (IS_STRAIGHT_SURFACE(pCivCarToGetIn->ai.c.currentRoad)) + straight = GET_STRAIGHT(pCivCarToGetIn->ai.c.currentRoad); else - { - curve = Driver2CurvesPtr + uVar2-0x4000; - } + curve = GET_CURVE(pCivCarToGetIn->ai.c.currentRoad); pCivCarToGetIn->ai.c.currentLane = CheckChangeLanes(straight, curve, pCivCarToGetIn->ai.c.targetRoute[0].distAlongSegment, pCivCarToGetIn, 0); @@ -1868,15 +1811,15 @@ void CivGetIn(PEDESTRIAN *pPed) // [A] UNUSED /* end block 3 */ // End Line: 4707 -// [D] -void CopStand(PEDESTRIAN *pPed) +// [D] [T] +void CopStand(PEDESTRIAN* pPed) { VECTOR v; v.vx = pPed->position.vx - player[0].pos[0]; v.vz = pPed->position.vz - player[0].pos[2]; pPed->frame1 = 0; - pPed->dir.vy = 0x400 - ratan2(v.vz, v.vx); + pPed->dir.vy = 1024 - ratan2(v.vz, v.vx); } @@ -1897,14 +1840,12 @@ void CopStand(PEDESTRIAN *pPed) int iAllowWatch = 0; -//int tannerTurn = 0; - -// [D] -void PedDoNothing(PEDESTRIAN *pPed) +// [D] [T] +void PedDoNothing(PEDESTRIAN* pPed) { pPed->speed = 0; - if ((pPed->flags & 0x10U) == 0) + if ((pPed->flags & 0x10) == 0) { SetupDoNowt(pPed); pPed->flags |= 0x10; @@ -1912,32 +1853,33 @@ void PedDoNothing(PEDESTRIAN *pPed) if (tannerPad & 0x1040) { + // run forward pPed->interest = 0; pPed->flags &= ~0x10; pPed->fpAgitatedState = fpPedPersonalityFunctions[2]; - - SetupRunner(pPed); + SetupRunner(pPed); } - else if (tannerPad & 0x4080) + else if (tannerPad & 0x4080) { + // walk back pPed->interest = 0; pPed->flags &= ~0x10; pPed->fpAgitatedState = fpPedPersonalityFunctions[1]; - + SetupBack(pPed); } else if (tannerPad & 0x2000) { pPed->interest = 0; - + pPed->doing_turn -= 2; - + if (pPed->doing_turn < -tannerTurnMax) pPed->doing_turn = -tannerTurnMax; pPed->dir.vy = pPed->dir.vy + 64 - (pPed->doing_turn + tannerTurnMax) * tannerTurnStep; - + if (pPed->frame1 == 0) pPed->frame1 = 15; else @@ -1956,7 +1898,7 @@ void PedDoNothing(PEDESTRIAN *pPed) pPed->dir.vy = pPed->dir.vy - 64 + (tannerTurnMax - pPed->doing_turn) * tannerTurnStep; - if (pPed->frame1 > 16) + if (pPed->frame1 > 16) pPed->frame1 = 0; pPed->head_rot = 0; @@ -1966,7 +1908,7 @@ void PedDoNothing(PEDESTRIAN *pPed) pPed->frame1 = 0; pPed->interest += 1; - if (pPed->doing_turn < 0) + if (pPed->doing_turn < 0) { pPed->doing_turn += 2; @@ -1978,20 +1920,20 @@ void PedDoNothing(PEDESTRIAN *pPed) { pPed->doing_turn -= 2; - if(pPed->doing_turn < 0) + if (pPed->doing_turn < 0) pPed->doing_turn = 0; } if (pPed->doing_turn != 0) { - if (pPed->doing_turn < 0) + if (pPed->doing_turn < 0) pPed->dir.vy = pPed->dir.vy + 64 - (pPed->doing_turn + tannerTurnMax) * tannerTurnStep; - else + else pPed->dir.vy = pPed->dir.vy - 64 + (tannerTurnMax - pPed->doing_turn) * tannerTurnStep; } } - - if (pPed->interest > 119) + + if (pPed->interest > 119) { pPed->frame1 = 0; pPed->type = PED_ACTION_TIME; @@ -2001,13 +1943,12 @@ void PedDoNothing(PEDESTRIAN *pPed) pPed->flags |= 0x10; pPed->fpAgitatedState = fpPedPersonalityFunctions[5]; pPed->interest = -2; - + if (pPed->type == PED_ACTION_TIME) iAllowWatch = 3; if (iAllowWatch != 0) iAllowWatch--; - } } @@ -2029,17 +1970,17 @@ void PedDoNothing(PEDESTRIAN *pPed) /* end block 2 */ // End Line: 5641 -// [D] -void PedUserRunner(PEDESTRIAN *pPed) +// [D] [T] +void PedUserRunner(PEDESTRIAN* pPed) { if ((pPed->flags & 0x10U) == 0) { SetupRunner(pPed); } - if (tannerPad & 0x1040) + if (tannerPad & 0x1040) { - if (bStopTanner == 0) + if (bStopTanner == 0) pPed->speed = 40 - (tannerDeathTimer >> 1); else pPed->speed = 0; @@ -2051,21 +1992,21 @@ void PedUserRunner(PEDESTRIAN *pPed) pPed->fpAgitatedState = NULL; pPed->flags &= ~0x10; } - - if (tannerPad & 0x2000) + + if (tannerPad & 0x2000) { - if (pPed->dir.vz > -80) + if (pPed->dir.vz > -80) pPed->dir.vz -= 20; - + pPed->doing_turn -= 2; - + if (pPed->doing_turn < -tannerTurnMax) pPed->doing_turn = -tannerTurnMax; pPed->head_rot = 0; pPed->dir.vy = pPed->dir.vy + 64 - (pPed->doing_turn + tannerTurnMax) * tannerTurnStep; } - else if (tannerPad & 0x8000) + else if (tannerPad & 0x8000) { if (pPed->dir.vz < 80) pPed->dir.vz += 20; @@ -2080,20 +2021,20 @@ void PedUserRunner(PEDESTRIAN *pPed) } else { - if (pPed->dir.vz < 0) + if (pPed->dir.vz < 0) pPed->dir.vz += 40; if (pPed->dir.vz > 0) pPed->dir.vz -= 40; - if (pPed->doing_turn < 0) + if (pPed->doing_turn < 0) { pPed->doing_turn += 2; - if (pPed->doing_turn > 0) + if (pPed->doing_turn > 0) pPed->doing_turn = 0; } - if(pPed->doing_turn > 0) + if (pPed->doing_turn > 0) { pPed->doing_turn -= 2; @@ -2132,15 +2073,19 @@ void PedUserRunner(PEDESTRIAN *pPed) /* end block 3 */ // End Line: 5279 -// [D] -void PedUserWalker(PEDESTRIAN *pPed) +// [D] [T] +void PedUserWalker(PEDESTRIAN* pPed) { - if ((pPed->flags & 0x10U) == 0) + if ((pPed->flags & 0x10) == 0) { SetupWalker(pPed); } - if ((tannerPad & 0x4080) == 0) + if (tannerPad & 0x4080) + { + pPed->speed = -10; + } + else { pPed->type = PED_ACTION_STOPPING; pPed->frame1 = 0; @@ -2148,18 +2093,14 @@ void PedUserWalker(PEDESTRIAN *pPed) pPed->fpAgitatedState = NULL; pPed->flags &= ~0x10; } - else - { - pPed->speed = -10; - } - if ((tannerPad & 0x2000) != 0) + if (tannerPad & 0x2000) { pPed->head_rot = 0; pPed->dir.vy += 20; } - if ((tannerPad & 0x8000) != 0) + if (tannerPad & 0x8000) { pPed->head_rot = 0; pPed->dir.vy -= 20; @@ -2188,11 +2129,11 @@ int iFreezeTimer = 0; int bFreezeAnimation = 0; int allreadydone = 0; -// [D] -void PedCarryOutAnimation(PEDESTRIAN *pPed) +// [D] [T] +void PedCarryOutAnimation(PEDESTRIAN* pPed) { pPed->speed = 0; - if (tannerPad != 0) + if (tannerPad != 0) { pPed->frame1 = 0; pPed->fpAgitatedState = NULL; @@ -2203,11 +2144,11 @@ void PedCarryOutAnimation(PEDESTRIAN *pPed) allreadydone = 0; } - if (bFreezeAnimation == 0) + if (bFreezeAnimation == 0) { AnimatePed(pPed); } - else + else { if (iFreezeTimer == 0) { @@ -2223,12 +2164,12 @@ void PedCarryOutAnimation(PEDESTRIAN *pPed) { if (pPed->frame1 > 14 && bFreezeAnimation == 0) { - if (pPed->type == PED_ACTION_TIME) + if (pPed->type == PED_ACTION_TIME) { bFreezeAnimation = 1; iFreezeTimer = 12; } - else + else { pPed->frame1 = 0; pPed->fpAgitatedState = NULL; @@ -2264,11 +2205,11 @@ void PedCarryOutAnimation(PEDESTRIAN *pPed) /* end block 2 */ // End Line: 5593 -_CAR_DATA *carToGetIn; +_CAR_DATA* carToGetIn; int bReverseYRotation = 0; -// [D] -void PedGetOutCar(PEDESTRIAN *pPed) +// [D] [T] +void PedGetOutCar(PEDESTRIAN* pPed) { int playerId; @@ -2329,16 +2270,14 @@ void PedGetOutCar(PEDESTRIAN *pPed) int lastCarCameraView = 0; -// [D] -void SetupGetOutCar(PEDESTRIAN *pPed, _CAR_DATA *pCar, int side) +// [D] [T] +void SetupGetOutCar(PEDESTRIAN* pPed, _CAR_DATA* pCar, int side) { - bool bVar1; - short sVar2; - int iVar3; - uint uVar4; - int iVar5; - int iVar6; - int iVar7; + bool entrySide; + short pedDir; + int sn, cs; + uint carDir; + int xOfs; int playerId; playerId = pPed->padId; @@ -2346,34 +2285,32 @@ void SetupGetOutCar(PEDESTRIAN *pPed, _CAR_DATA *pCar, int side) lastCarCameraView = player[playerId].cameraView; pPed->speed = 0; - iVar5 = pCar->hd.direction; - iVar6 = pCar->hd.direction; - iVar3 = rsin(iVar6); - sVar2 = rcos(iVar6); - iVar7 = 400; + sn = rsin(pCar->hd.direction); + cs = rcos(pCar->hd.direction); - bVar1 = -1 < sVar2 * (pCar->hd.where.t[0] - pPed->position.vx) - FIXED(iVar3 * 0x1000) * (pCar->hd.where.t[2] - pPed->position.vz) + 0x800; + entrySide = cs * (pCar->hd.where.t[0] - pPed->position.vx) - FIXED(sn * 0x1000) * (pCar->hd.where.t[2] - pPed->position.vz) + 0x800 > -1; - if (bVar1) - sVar2 = iVar6 - 0x400; + if (entrySide) + pPed->dir.vy = pCar->hd.direction - 1024; else - sVar2 = iVar6 + 0x400; + pPed->dir.vy = pCar->hd.direction + 1024; - bReverseYRotation = !bVar1; - pPed->dir.vy = sVar2; + bReverseYRotation = !entrySide; if (side == 1) - iVar7 = -400; + xOfs = -400; + else + xOfs = 400; - uVar4 = iVar5 + 0x800U & 0xfff; + carDir = pCar->hd.direction + 0x800U & 0xfff; if (NoPlayerControl == 0) { player[playerId].cameraView = 5; - player[playerId].cameraPos.vx = pCar->hd.where.t[0] - (FIXED(iVar7 * rcossin_tbl[uVar4 * 2 + 1]) - FIXED(rcossin_tbl[uVar4 * 2] * 800)); + player[playerId].cameraPos.vx = pCar->hd.where.t[0] - (FIXED(xOfs * rcossin_tbl[carDir * 2 + 1]) - FIXED(rcossin_tbl[carDir * 2] * 800)); player[playerId].cameraPos.vy = -200 - pCar->hd.where.t[1]; - player[playerId].cameraPos.vz = pCar->hd.where.t[2] + (FIXED(iVar7 * rcossin_tbl[uVar4 * 2]) + FIXED(rcossin_tbl[uVar4 * 2 + 1] * 800)); + player[playerId].cameraPos.vz = pCar->hd.where.t[2] + (FIXED(xOfs * rcossin_tbl[carDir * 2]) + FIXED(rcossin_tbl[carDir * 2 + 1] * 800)); } pPed->frame1 = 0; @@ -2435,14 +2372,14 @@ void SetupGetOutCar(PEDESTRIAN *pPed, _CAR_DATA *pCar, int side) /* end block 4 */ // End Line: 6526 -// [D] -void SetupGetInCar(PEDESTRIAN *pPed) +// [D] [T] +void SetupGetInCar(PEDESTRIAN* pPed) { - short sVar2; - int iVar3; - uint uVar4; - int iVar5; - int iVar6; + int sn, cs; + int carDir; + int xOfs; + int playerId; + int entrySide; long pos[4]; @@ -2450,50 +2387,50 @@ void SetupGetInCar(PEDESTRIAN *pPed) pPed->speed = 0; pPed->frame1 = 0; - iVar6 = carToGetIn->hd.direction; - iVar3 = rsin(iVar6); - sVar2 = rcos(iVar6); + playerId = pPed->padId; - if (sVar2 * (carToGetIn->hd.where.t[0] - pPed->position.vx) - FIXED(iVar3 * 0x1000) * (carToGetIn->hd.where.t[2] - pPed->position.vz) + 0x800 < 0) - iVar6 = iVar6 + 0x400; - else - iVar6 = iVar6 - 0x400; + sn = rsin(carToGetIn->hd.direction); + cs = rcos(carToGetIn->hd.direction); - iVar5 = 400; + entrySide = cs * (carToGetIn->hd.where.t[0] - pPed->position.vx) - FIXED(sn * 0x1000) * (carToGetIn->hd.where.t[2] - pPed->position.vz) + 0x800 < 0; + + if (entrySide) + pPed->dir.vy = carToGetIn->hd.direction + 0x400; + else + pPed->dir.vy = carToGetIn->hd.direction - 0x400; - pPed->dir.vy = iVar6; - iVar3 = carToGetIn->hd.direction; + if (pPed->dir.vy > carToGetIn->hd.direction) + xOfs = -400; + else + xOfs = 400; - if (iVar3 < iVar6) - iVar5 = -400; + carDir = carToGetIn->hd.direction + 0x800U & 0xfff; - uVar4 = iVar3 + 0x800U & 0xfff; - - if (NoPlayerControl == 0 && gInGameCutsceneActive == 0) + if (NoPlayerControl == 0 && gInGameCutsceneActive == 0) { - player[0].cameraView = 5; - player[0].cameraPos.vx = carToGetIn->hd.where.t[0] - (FIXED(iVar5 * rcossin_tbl[uVar4 * 2 + 1]) - FIXED(rcossin_tbl[uVar4 * 2] * 800)); - player[0].cameraPos.vy = -200 - carToGetIn->hd.where.t[1]; - player[0].cameraPos.vz = carToGetIn->hd.where.t[2] + (FIXED(iVar5 * rcossin_tbl[uVar4 * 2]) + FIXED(rcossin_tbl[uVar4 * 2 + 1] * 800)); + player[playerId].cameraView = 5; + player[playerId].cameraPos.vx = carToGetIn->hd.where.t[0] - (FIXED(xOfs * rcossin_tbl[carDir * 2 + 1]) - FIXED(rcossin_tbl[carDir * 2] * 800)); + player[playerId].cameraPos.vy = -200 - carToGetIn->hd.where.t[1]; + player[playerId].cameraPos.vz = carToGetIn->hd.where.t[2] + (FIXED(xOfs * rcossin_tbl[carDir * 2]) + FIXED(rcossin_tbl[carDir * 2 + 1] * 800)); } - if ((carToGetIn->controlFlags & 4) == 0) + if ((carToGetIn->controlFlags & CONTROL_FLAG_WAS_PARKED) == 0) { - if (carToGetIn->controlType == CONTROL_TYPE_CIV_AI && carToGetIn->ai.c.thrustState == 3 && carToGetIn->ai.c.ctrlState == 5) + if (carToGetIn->controlType == CONTROL_TYPE_CIV_AI && carToGetIn->ai.c.thrustState == 3 && carToGetIn->ai.c.ctrlState == 5) { - carToGetIn->controlFlags |= 4; + carToGetIn->controlFlags |= CONTROL_FLAG_WAS_PARKED; } - else + else { - pos[0] = player[0].pos[0]; - pos[1] = -player[0].pos[1]; - pos[2] = player[0].pos[2]; + pos[0] = player[playerId].pos[0]; + pos[1] = -player[playerId].pos[1]; + pos[2] = player[playerId].pos[2]; // HEY! CreatePedAtLocation(&pos, 8); Start3DSoundVolPitch(-1, 6, 5, pos[0], pos[1], pos[2], 0, 0x1000); - carToGetIn->controlFlags |= 4; + carToGetIn->controlFlags |= CONTROL_FLAG_WAS_PARKED; } } } @@ -2520,31 +2457,27 @@ void SetupGetInCar(PEDESTRIAN *pPed) /* end block 2 */ // End Line: 17841 -// [D] -void PedGetInCar(PEDESTRIAN *pPed) +// [D] [T] +void PedGetInCar(PEDESTRIAN* pPed) { - _CAR_DATA *newCar; int playerID; pPed->speed = 0; - if (pPed->frame1 < 0xf) + if (pPed->frame1 < 0xf) { AnimatePed(pPed); } - else + else { - playerID = (int)pPed->padId; - pPed->speed = 0; - newCar = carToGetIn; - pPed->fpAgitatedState = NULL; + playerID = ABS(pPed->padId); - if (playerID < 0) - playerID = -playerID; + pPed->speed = 0; + pPed->fpAgitatedState = NULL; pPed->flags &= ~0x10; - ChangePedPlayerToCar(playerID, newCar); + ChangePedPlayerToCar(playerID, carToGetIn); DestroyPedestrian(pPed); pPlayerPed = NULL; @@ -2568,8 +2501,8 @@ void PedGetInCar(PEDESTRIAN *pPed) /* end block 2 */ // End Line: 6053 -// [D] -void SetupPressButton(PEDESTRIAN *pPed) +// [D] [T] +void SetupPressButton(PEDESTRIAN* pPed) { pPed->type = PED_ACTION_PRESSBUTTON; SetupPedMotionData(pPed); @@ -2590,10 +2523,10 @@ void SetupPressButton(PEDESTRIAN *pPed) /* end block 1 */ // End Line: 18176 -// [D] -void PedPressButton(PEDESTRIAN *pPed) +// [D] [T] +void PedPressButton(PEDESTRIAN* pPed) { - if (pPed->frame1 < 0xf) + if (pPed->frame1 < 15) { AnimatePed(pPed); } @@ -2618,8 +2551,8 @@ void PedPressButton(PEDESTRIAN *pPed) /* end block 1 */ // End Line: 6121 -// [D] -void SetupTannerSitDown(PEDESTRIAN *pPed) +// [D] [T] +void SetupTannerSitDown(PEDESTRIAN* pPed) { pPed->type = PED_ACTION_SIT; SetupPedMotionData(pPed); @@ -2671,36 +2604,39 @@ void SetupTannerSitDown(PEDESTRIAN *pPed) /* WARNING: Removing unreachable block (ram,0x0006fde0) */ /* WARNING: Removing unreachable block (ram,0x0006fe8c) */ - - -// [D] -void TannerCameraHandler(PEDESTRIAN *pPed) +// [D] [T] +void TannerCameraHandler(PEDESTRIAN* pPed) { - int iVar1; - short sVar2; - int iVar3; + int value; + short extra; + int padSteer; + _PLAYER* lcp; - int padid = player[0].padid; + int padid; - camera_position.vy = pPed->head_pos - 28 - player[0].pos[1]; + padid = pPed->padId; + + lcp = &player[padid]; + + camera_position.vy = pPed->head_pos - 28 - lcp->pos[1]; if (Pads[padid].type == 4) { - iVar3 = Pads[padid].mapanalog[0]; + padSteer = Pads[padid].mapanalog[0]; - if (iVar3 < -32 || iVar3 > 32) + if (padSteer < -32 || padSteer > 32) { - iVar1 = iVar3; - - if (iVar3 < 0) - iVar1 = -iVar3; - - tannerLookAngle.vy = (iVar1 - 32) * 9; - - if (iVar3 < 0) - tannerLookAngle.vy = (iVar1 - 32) * -9; + if (padSteer < 0) + value = -padSteer; + else + value = padSteer; + + if (padSteer < 0) + tannerLookAngle.vy = (value - 32) * -9; + else + tannerLookAngle.vy = (value - 32) * 9; } - else + else { tannerLookAngle.vy = 0; } @@ -2712,42 +2648,40 @@ void TannerCameraHandler(PEDESTRIAN *pPed) else if (tannerLookAngle.vx < 33) tannerLookAngle.vx = 0; } - else + else { tannerLookAngle.vx = 0; tannerLookAngle.vy = 0; tannerLookAngle.vz = 0; } - if ((padd & 1U) == 0) + if (padd & 1) { - sVar2 = 0; - if ((padd & 2U) != 0) - { - sVar2 = -0x400; - } + if (padd & 2) + extra = 2048; + else + extra = 1024; } - else + else { - sVar2 = 0x400; - if ((padd & 2U) != 0) - { - sVar2 = 0x800; - } + if (padd & 2) + extra = -1024; + else + extra = 0; } - camera_position.vx = player[0].pos[0]; - camera_position.vz = player[0].pos[2]; + camera_position.vx = lcp->pos[0]; + camera_position.vz = lcp->pos[2]; camera_angle.vx = camAngle.vx + tannerLookAngle.vx; - camera_angle.vy = (camAngle.vy - tannerLookAngle.vy) + sVar2 & 0xfff; + camera_angle.vy = (camAngle.vy - tannerLookAngle.vy) + extra & 0xfff; camera_angle.vz = camAngle.vz + tannerLookAngle.vz; tracking_car = 0; - player[0].cameraPos.vx = player[0].pos[0]; - player[0].cameraPos.vy = camera_position.vy; - player[0].cameraPos.vz = player[0].pos[2]; + lcp->cameraPos.vx = lcp->pos[0]; + lcp->cameraPos.vy = camera_position.vy; + lcp->cameraPos.vz = lcp->pos[2]; } @@ -2776,7 +2710,7 @@ void TannerCameraHandler(PEDESTRIAN *pPed) // End Line: 7119 // [D] -void TannerSitDown(PEDESTRIAN *pPed) +void TannerSitDown(PEDESTRIAN* pPed) { int iVar2; @@ -2787,32 +2721,9 @@ void TannerSitDown(PEDESTRIAN *pPed) camAngle.vz = camera_angle.vz; } - if (pPed->frame1 == 15) - { - if ((pPed->flags & 4U) == 0) - { - oldCamView = player[pPed->padId].cameraView; - bFreezeAnimation = 1; - - /* - if (player[pPed->padId].cameraView == 2) - pPed->flags |= 4; - else - pPed->flags &= ~4; - */ - - if ((tannerPad & 0x10) == 0) - return; - - tracking_car = 1; - pPed->flags |= 4; // new reverse animation flag - bFreezeAnimation = 0; - - oldCamView = -1; - return; - } - - LAB_00070054: + // if sit down/standup animation playing + if (pPed->flags & 4) + { if (pPed->frame1 == 0) { pPed->frame1 = 0; @@ -2825,25 +2736,31 @@ void TannerSitDown(PEDESTRIAN *pPed) bFreezeAnimation = 0; pPed->flags &= ~4; - return; } - if ((pPed->flags & 4) != 0) - { - iVar2 = pPed->position.vy - 2; - goto LAB_000700b4; - } + pPed->position.vy -= 3; } - else + else { - if ((pPed->flags & 4) != 0) - goto LAB_00070054; - } + if (pPed->frame1 == 15) + { + oldCamView = player[pPed->padId].cameraView; + bFreezeAnimation = 1; - iVar2 = pPed->position.vy + 2; -LAB_000700b4: - pPed->position.vy = iVar2; + if (tannerPad & 0x10) + { + tracking_car = 1; + pPed->flags |= 4; // new reverse animation flag + bFreezeAnimation = 0; + + oldCamView = -1; + } + return; + } + + pPed->position.vy += 3; + } AnimatePed(pPed); } @@ -2904,15 +2821,10 @@ LAB_000700b4: /* end block 4 */ // End Line: 7286 -// [D] -void AnimatePed(PEDESTRIAN *pPed) +// [D] [T] +void AnimatePed(PEDESTRIAN* pPed) { - PED_ACTION_TYPE PVar2; - ushort uVar3; - int iVar5; - unsigned char bVar6; - uint uVar7; - long lVar8; + int dir; VECTOR vec; if (pauseflag) @@ -2922,65 +2834,61 @@ void AnimatePed(PEDESTRIAN *pPed) vec.vz = pPed->position.vz; vec.vy = -pPed->position.vy; - if (pPed->pedType == CIVILIAN && (pPed->flags & 0x8000U) != 0) + if(pPed->type != PED_ACTION_SIT) { - iVar5 = MapHeight(&vec); - lVar8 = -60 - iVar5; + if (pPed->pedType == CIVILIAN && (pPed->flags & 0x8000U) != 0) + pPed->position.vy = -60 - MapHeight(&vec); + else + pPed->position.vy = -130 - MapHeight(&vec); } - else - { - iVar5 = MapHeight(&vec); - lVar8 = -130 - iVar5; - } - - PVar2 = pPed->type; if (pPed->speed < 0) { - uVar3 = pPed->dir.vy; - pPed->position.vx = pPed->position.vx - FIXED(pPed->speed * rcossin_tbl[(uVar3 & 0xfff) * 2]); - iVar5 = pPed->position.vz - FIXED(pPed->speed * rcossin_tbl[(-uVar3 & 0xfffU) * 2 + 1]); // [A] is it valid? + dir = pPed->dir.vy; + pPed->position.vx -= FIXED(pPed->speed * rcossin_tbl[(dir & 0xfff) * 2]); + pPed->position.vz -= FIXED(pPed->speed * rcossin_tbl[(-dir & 0xfffU) * 2 + 1]); } else { - uVar7 = (int)pPed->dir.vy - 0x800U & 0xfff; - pPed->position.vx = pPed->position.vx + FIXED((int)pPed->speed * (int)rcossin_tbl[uVar7 * 2]); - iVar5 = pPed->position.vz + FIXED((int)pPed->speed * (int)rcossin_tbl[uVar7 * 2 + 1]); + dir = pPed->dir.vy - 0x800U & 0xfff; + pPed->position.vx += FIXED(pPed->speed * rcossin_tbl[dir * 2]); + pPed->position.vz += FIXED(pPed->speed * rcossin_tbl[dir * 2 + 1]); } - pPed->position.vz = iVar5; - - if (PVar2 != PED_ACTION_SIT && PVar2 != PED_ACTION_COPCROUCH && PVar2 != PED_ACTION_COPSTAND) + if (pPed->type != PED_ACTION_SIT && + pPed->type != PED_ACTION_COPCROUCH && + pPed->type != PED_ACTION_COPSTAND) { - pPed->position.vy = lVar8; pPed->velocity.vy = 10; } - if ((pPed->flags & 4) == 0)// || pPed->pedType != TANNER_MODEL) + if ((pPed->flags & 4) /*&& pPed->pedType == TANNER_MODEL*/) { - pPed->frame1++; - - if ((uint)pPed->type - 8 < 3) // [A] TODO: figure out what type it is to have extended frames - bVar6 = 31; - else - bVar6 = 16; - - if (pPed->frame1 >= bVar6) - pPed->frame1 = 0; - } - else - { - if (pPed->frame1 == 0) + if (pPed->frame1 == 0) pPed->frame1 = 15; pPed->frame1--; } - - if ((pPed->pedType == TANNER_MODEL || (ActiveCheats.cheat12 && (pPed->pedType == OTHER_MODEL))) && pPed->type < PED_ACTION_BACK) + else { - iVar5 = PedSurfaceType((VECTOR *)&pPed->position); + int numFrames; + pPed->frame1++; - if (iVar5 != 4 && iVar5 != 6 && iVar5 != 11 && iVar5 != 9) + if (pPed->type - 8U < 3) // [A] TODO: figure out what type it is to have extended frames + numFrames = 31; + else + numFrames = 16; + + if (pPed->frame1 >= numFrames) + pPed->frame1 = 0; + } + + if ((pPed->pedType == TANNER_MODEL || (ActiveCheats.cheat12 && pPed->pedType == OTHER_MODEL)) && pPed->type < PED_ACTION_BACK) + { + int surfId; + surfId = PedSurfaceType((VECTOR*)&pPed->position); + + if (surfId != 4 && surfId != 6 && surfId != 11 && surfId != 9) { if (pPed->frame1 == 3) Start3DSoundVolPitch(-1, 6, 0, pPed->position.vx, pPed->position.vy, pPed->position.vz, -5000, 0x1000); @@ -2992,24 +2900,12 @@ void AnimatePed(PEDESTRIAN *pPed) if (pPed->pedType != CIVILIAN) { - iVar5 = pPed->padId; + int padId; + padId = ABS(pPed->padId); - if (iVar5 < 0) - iVar5 = -iVar5; - - player[iVar5].pos[0] = pPed->position.vx; - iVar5 = pPed->padId; - - if (iVar5 < 0) - iVar5 = -iVar5; - - player[iVar5].pos[1] = -pPed->position.vy; - iVar5 = pPed->padId; - - if (iVar5 < 0) - iVar5 = -iVar5; - - player[iVar5].pos[2] = pPed->position.vz; + player[padId].pos[0] = pPed->position.vx; + player[padId].pos[1] = -pPed->position.vy; + player[padId].pos[2] = pPed->position.vz; } } @@ -3044,15 +2940,15 @@ void AnimatePed(PEDESTRIAN *pPed) /* end block 2 */ // End Line: 6715 -// [D] -void DeActivatePlayerPedestrian(PEDESTRIAN *pPed) +// [D] [T] +void DeActivatePlayerPedestrian(PEDESTRIAN* pPed) { - _CAR_DATA *cp; + _CAR_DATA* cp; int playerId; - int iVar2; + int getIn; int distToCarSq; - iVar2 = 0; + getIn = 0; playerId = pPed->padId; if (playerId < 0) @@ -3063,12 +2959,12 @@ void DeActivatePlayerPedestrian(PEDESTRIAN *pPed) if (!cp) return; - if (cp->ap.model == 4) - iVar2 = FindPointOfCollision(cp, pPed); + if (cp->ap.model == 4) + getIn = FindPointOfCollision(cp, pPed); else if (cp && TannerCanEnterCar(cp, distToCarSq)) - iVar2 = 1; + getIn = 1; - if (iVar2 != 0) + if (getIn != 0) { carToGetIn = cp; pPed->type = PED_ACTION_GETINCAR; @@ -3096,9 +2992,9 @@ void DeActivatePlayerPedestrian(PEDESTRIAN *pPed) /* end block 2 */ // End Line: 18901 -void CivPedDoNothing(PEDESTRIAN *pPed) +// [D] [T] +void CivPedDoNothing(PEDESTRIAN* pPed) { - return; } @@ -3121,8 +3017,8 @@ void CivPedDoNothing(PEDESTRIAN *pPed) /* end block 2 */ // End Line: 23048 -// [D] -void SetupCivPedRouteData(VECTOR *pPos) +// [D] [T] +void SetupCivPedRouteData(VECTOR* pPos) { VECTOR baseLoc; @@ -3231,132 +3127,121 @@ void SetupCivPedRouteData(VECTOR *pPos) // [D] void PingInPedestrians(void) { - bool bVar1; - PED_ACTION_TYPE PVar3; - long lVar5; - PEDESTRIAN *pPed; - int iVar6; - long lVar7; - int iVar8; - int step; + int bFound; + PEDESTRIAN* pPed; + long rnd; + int pingInDist; + int i; + int dx, dz; VECTOR randomLoc; VECTOR baseLoc; - VECTOR position; - VECTOR target; - bVar1 = false; - if (num_pedestrians < 15 && pFreePeds != NULL && pFreePeds->pNext != NULL) + if (num_pedestrians >= MAX_PLACED_PEDS || pFreePeds == NULL || pFreePeds->pNext == NULL) + return; + + baseLoc.vx = player[0].pos[0]; + baseLoc.vy = player[0].pos[1]; + baseLoc.vz = player[0].pos[2]; + + if (gWeather == 0 && FindSeated() != NULL) + return; + + for(i = 0; i < 50; i++) { - baseLoc.vx = player[0].pos[0]; - baseLoc.vy = player[0].pos[1]; - baseLoc.vz = player[0].pos[2]; + pinginPedAngle += 81; + + pingInDist = Random2(0) % 128 + 1536; + + randomLoc.vy = baseLoc.vy; + randomLoc.vx = baseLoc.vx + pingInDist * FIXEDH(rcossin_tbl[(pinginPedAngle & 0xfffU) * 2] * 8); + randomLoc.vz = baseLoc.vz + pingInDist * FIXEDH(rcossin_tbl[(pinginPedAngle & 0xfffU) * 2 + 1] * 8); - if (gWeather != 0 || FindSeated() == NULL) + randomLoc.vy = -MapHeight(&randomLoc); + + if (baseLoc.vy - 512 <= -randomLoc.vy && + baseLoc.vy + 512 >= -randomLoc.vy && + IsPavement(randomLoc.vx, randomLoc.vy, randomLoc.vz, NULL)) { - step = 0; - do { - lVar5 = Random2(0); - lVar7 = lVar5; + if (pUsedPeds != NULL) + { + pPed = pUsedPeds; - pinginPedAngle = pinginPedAngle + 0x51; - iVar8 = lVar5 - FixFloorSigned(lVar7, 7) * 128 + 0x600; - randomLoc.vy = baseLoc.vy; - randomLoc.vx = baseLoc.vx + iVar8 * FIXEDH((int)rcossin_tbl[(pinginPedAngle & 0xfffU) * 2] * 8); - randomLoc.vz = baseLoc.vz + iVar8 * FIXEDH((int)rcossin_tbl[(pinginPedAngle & 0xfffU) * 2 + 1] * 8); - iVar8 = MapHeight(&randomLoc); - randomLoc.vy = -iVar8; + dx = pPed->position.vx - randomLoc.vx; + dz = pPed->position.vz - randomLoc.vz; - if (((baseLoc.vy + -0x200 <= iVar8) && (iVar8 <= baseLoc.vy + 0x200)) && (iVar8 = IsPavement(randomLoc.vx, randomLoc.vy, randomLoc.vz, NULL), iVar8 != 0)) + bFound = 0; + + while (dx*dx + dz*dz > 15999999) { - bVar1 = true; - if (pUsedPeds == NULL) + pPed = pPed->pNext; + + if (pPed == NULL) { - LAB_0007068c: - if (!bVar1) - return; - - if (pFreePeds->pNext == NULL) - return; - - pPed = CreatePedestrian(); - pPed->flags = 0; - pPed->position.vx = randomLoc.vx; - pPed->position.vy = randomLoc.vy; - pPed->pedType = CIVILIAN; // [A] try :D - pPed->dir.vz = 0; - pPed->dir.vx = 0; - pPed->dir.vy = 0; - pPed->position.vz = randomLoc.vz; - baseLoc.vx = randomLoc.vx; - baseLoc.vy = (pPed->position).vy; - baseLoc.vz = (pPed->position).vz; - step = MapHeight(&baseLoc); - baseLoc.vy = -step; - - SetupCivPedRouteData(&baseLoc); - PedestrianActionInit_WalkToTarget(pPed); - - step = -28; - - PVar3 = PED_ACTION_CIVRUN; - - if (((pedestrian_roads.north != -28 && - (PVar3 = PED_ACTION_CIVRUN, pedestrian_roads.south != -28)) && - (PVar3 = PED_ACTION_CIVRUN, pedestrian_roads.east != -28)) && - (PVar3 = PED_ACTION_CIVWALK, pedestrian_roads.west == -28)) - { - PVar3 = PED_ACTION_CIVRUN; - } - - pPed->type = PVar3; - - if (pPed->type == PED_ACTION_CIVRUN) // [A] fix bug - pPed->speed = 30; - - lVar7 = Random2(-0x1c); - lVar5 = Random2(step); - pPed->pallet = lVar7 + (lVar7 / 5) * -5 + (lVar5 + (lVar5 / 5) * -5) * 16; - - - - SetupPedMotionData(pPed); - pPed->fpAgitatedState = NULL; - pPed->dir.vy = 0; - pPed->fpRestState = fpPedPersonalityFunctions[7]; - lVar7 = Random2(0); - - if ((lVar7 / 6) * 6 != lVar7 + -3) - return; - - pPed->flags = pPed->flags | 0x4000; - return; + bFound = 1; + break; } - iVar6 = pUsedPeds->position.vx - randomLoc.vx; - iVar8 = pUsedPeds->position.vz; - iVar6 = iVar6 * iVar6; - pPed = pUsedPeds; - - while (bVar1 = true, 15999999 < iVar6 + (iVar8 - randomLoc.vz) * (iVar8 - randomLoc.vz)) - { - pPed = pPed->pNext; - - if (pPed == NULL) - goto LAB_00070674; - - iVar6 = (pPed->position).vx - randomLoc.vx; - iVar6 = iVar6 * iVar6; - iVar8 = (pPed->position).vz; - } - bVar1 = false; + dx = pPed->position.vx - randomLoc.vx; + dz = pPed->position.vz - randomLoc.vz; } + } + else + { + bFound = 1; + } - LAB_00070674: - step = step + 1; - if ((49 < step) || (bVar1)) - goto LAB_0007068c; + if (!bFound) + return; - } while (true); + if (pFreePeds->pNext == NULL) + return; + + pPed = CreatePedestrian(); + + pPed->flags = 0; + pPed->position.vx = randomLoc.vx; + pPed->position.vy = randomLoc.vy; + pPed->pedType = CIVILIAN; + pPed->dir.vz = 0; + pPed->dir.vx = 0; + pPed->dir.vy = 0; + pPed->position.vz = randomLoc.vz; + + baseLoc.vx = randomLoc.vx; + baseLoc.vy = pPed->position.vy; + baseLoc.vz = pPed->position.vz; + + baseLoc.vy = -MapHeight(&baseLoc); + + SetupCivPedRouteData(&baseLoc); + PedestrianActionInit_WalkToTarget(pPed); + + pPed->type = PED_ACTION_CIVRUN; + + if (pedestrian_roads.north != -28 && + (pPed->type = PED_ACTION_CIVRUN, pedestrian_roads.south != -28) && + (pPed->type = PED_ACTION_CIVRUN, pedestrian_roads.east != -28) && + (pPed->type = PED_ACTION_CIVWALK, pedestrian_roads.west == -28)) + { + pPed->type = PED_ACTION_CIVRUN; + } + + // it might not be correct + pPed->pallet = (Random2(-28) % 5) + (Random2(-28) % 5) * 16; + + SetupPedMotionData(pPed); + + pPed->fpAgitatedState = NULL; + pPed->dir.vy = 0; + pPed->fpRestState = fpPedPersonalityFunctions[7]; + + rnd = Random2(0); + + if ((rnd / 6) * 6 != rnd - 3) + return; + + pPed->flags |= 0x4000; + return; } } } @@ -3389,11 +3274,13 @@ void PingInPedestrians(void) /* end block 4 */ // End Line: 21346 -_CAR_DATA *pcdTanner; -// [D] -void TannerCollision(PEDESTRIAN *pPed) + +// [D] [T] +void TannerCollision(PEDESTRIAN* pPed) { + _CAR_DATA* pcdTanner; + if (pPed->type == PED_ACTION_SIT) return; @@ -3420,7 +3307,7 @@ void TannerCollision(PEDESTRIAN *pPed) pcdTanner->st.n.linearVelocity[2] = 0; CheckScenaryCollisions(pcdTanner); - TannerCarCollisionCheck((VECTOR *)&pPed->position, pPed->dir.vy, 0); + TannerCarCollisionCheck((VECTOR*)&pPed->position, pPed->dir.vy, 0); pPed->position.vx = pcdTanner->hd.where.t[0]; pPed->position.vz = pcdTanner->hd.where.t[2]; @@ -3463,7 +3350,7 @@ void TannerCollision(PEDESTRIAN *pPed) // End Line: 8378 // [D] -int FindPointOfCollision(_CAR_DATA *pCar, PEDESTRIAN* pPed) +int FindPointOfCollision(_CAR_DATA* pCar, PEDESTRIAN* pPed) { int iVar1; uint uVar2; @@ -3474,6 +3361,9 @@ int FindPointOfCollision(_CAR_DATA *pCar, PEDESTRIAN* pPed) CDATA2D cd[2]; static CRET2D collisionResult; + CAR_COSMETICS* car_cos; + + car_cos = &car_cosmetics[pCar->ap.model]; cd[0].length[0] = 120; cd[0].length[1] = 12; @@ -3482,15 +3372,15 @@ int FindPointOfCollision(_CAR_DATA *pCar, PEDESTRIAN* pPed) cd[0].x.vz = pPed->position.vz; cd[0].theta = pPed->dir.vy - 0x800U & 0xfff; - cd[1].length[0] = car_cosmetics[pCar->ap.model].colBox.vz; - cd[1].length[1] = car_cosmetics[pCar->ap.model].colBox.vx; + cd[1].length[0] = car_cos->colBox.vz; + cd[1].length[1] = car_cos->colBox.vx; cd[1].x.vx = pCar->hd.where.t[0]; cd[1].x.vz = pCar->hd.where.t[2]; cd[1].theta = pCar->hd.direction; iVar1 = bcollided2d(cd, 1); - if (iVar1 != 0) + if (iVar1 != 0) { bFindCollisionPoint(cd, &collisionResult); @@ -3498,8 +3388,8 @@ int FindPointOfCollision(_CAR_DATA *pCar, PEDESTRIAN* pPed) extern int gShowCollisionDebug; if (gShowCollisionDebug) { - extern void Debug_AddLine(VECTOR& pointA, VECTOR& pointB, CVECTOR& color); - extern void Debug_AddLineOfs(VECTOR& pointA, VECTOR& pointB, VECTOR& ofs, CVECTOR& color); + extern void Debug_AddLine(VECTOR & pointA, VECTOR & pointB, CVECTOR & color); + extern void Debug_AddLineOfs(VECTOR & pointA, VECTOR & pointB, VECTOR & ofs, CVECTOR & color); CVECTOR bbcv = { 0, 0, 250 }; CVECTOR rrcv = { 250, 0, 0 }; @@ -3516,26 +3406,23 @@ int FindPointOfCollision(_CAR_DATA *pCar, PEDESTRIAN* pPed) } #endif - uVar2 = pCar->ap.model; - iVar6 = car_cosmetics[uVar2].colBox.vx; iVar4 = FIXED((collisionResult.hit.vx - cd[1].x.vx) * rcossin_tbl[(cd[1].theta & 0xfffU) * 2 + 1]) - FIXED((collisionResult.hit.vz - cd[1].x.vz) * rcossin_tbl[(cd[1].theta & 0xfffU) * 2]); - iVar5 = iVar6 + 96; - iVar3 = car_cosmetics[uVar2].colBox.vz; - iVar1 = FIXED((collisionResult.hit.vx - cd[1].x.vx) * rcossin_tbl[(cd[1].theta & 0xfffU) * 2]) + FIXED((collisionResult.hit.vz - cd[1].x.vz) * rcossin_tbl[(cd[1].theta & 0xfffU) * 2 + 1]); - iVar6 = iVar6 - 96; + iVar5 = car_cos->colBox.vx + 96; + iVar3 = car_cos->colBox.vz; + iVar6 = car_cos->colBox.vx - 96; - if ((iVar3 - 480 < iVar1) && (iVar1 < iVar3 - 200)) + if ((iVar3 - 480 < iVar1) && (iVar1 < iVar3 - 200)) { - if ((iVar6 < iVar4) && (iVar4 < iVar5)) + if ((iVar6 < iVar4) && (iVar4 < iVar5)) return 1; - if ((iVar4 < -iVar6) && (-iVar5 < iVar4)) + if ((iVar4 < -iVar6) && (-iVar5 < iVar4)) return 1; } } @@ -3628,7 +3515,7 @@ int FindPointOfCollision(_CAR_DATA *pCar, PEDESTRIAN* pPed) /* WARNING: Type propagation algorithm not settling */ // [D] -int TannerCarCollisionCheck(VECTOR *pPos, int dir, int bQuick) +int TannerCarCollisionCheck(VECTOR* pPos, int dir, int bQuick) { int iVar1; uint uVar2; @@ -3642,7 +3529,7 @@ int TannerCarCollisionCheck(VECTOR *pPos, int dir, int bQuick) int iVar10; int iVar11; int iVar12; - _CAR_DATA *cp1; + _CAR_DATA* cp1; int carLength; int dNewLBODY[2]; VECTOR velocity; @@ -3651,9 +3538,12 @@ int TannerCarCollisionCheck(VECTOR *pPos, int dir, int bQuick) long lever[4]; SVECTOR boxDisp; CAR_COSMETICS* car_cos; + _CAR_DATA* pcdTanner; CRET2D collisionResult; // offset 0x30 CDATA2D cd[2]; + + pcdTanner = &car_data[21]; cd[0].length[0] = 0x3c; cd[0].length[1] = 0x3c; @@ -3684,9 +3574,9 @@ int TannerCarCollisionCheck(VECTOR *pPos, int dir, int bQuick) gte_stlvnl(&cd[1].x); - if (cp1->controlType != CONTROL_TYPE_NONE) + if (cp1->controlType != CONTROL_TYPE_NONE) { - if (ABS(cp1->hd.where.t[1] + pPos->vy) < 500 && + if (ABS(cp1->hd.where.t[1] + pPos->vy) < 500 && bcollided2d(cd, 1)) { if (bQuick != 0) @@ -3696,17 +3586,17 @@ int TannerCarCollisionCheck(VECTOR *pPos, int dir, int bQuick) return 1; bFindCollisionPoint(cd, &collisionResult); - + iVar3 = -collisionResult.surfNormal.vz; iVar1 = -collisionResult.surfNormal.vx; - + iVar10 = pcdTanner->hd.where.t[2] + FIXEDH(collisionResult.penetration * iVar3); iVar12 = collisionResult.hit.vz - iVar10; collisionResult.hit.vy = pcdTanner->hd.where.t[1] + 0x3c; iVar9 = collisionResult.hit.vy - pcdTanner->hd.where.t[1]; iVar8 = pcdTanner->hd.where.t[0] + FIXEDH(collisionResult.penetration * iVar1); iVar11 = collisionResult.hit.vx - iVar8; - + collisionResult.surfNormal.vy = 0; iVar7 = FIXEDH(pcdTanner->st.n.angularVelocity[1] * iVar12 - pcdTanner->st.n.angularVelocity[2] * iVar9) + pcdTanner->st.n.linearVelocity[0]; @@ -3785,7 +3675,7 @@ int TannerCarCollisionCheck(VECTOR *pPos, int dir, int bQuick) // End Line: 24072 // [D] -int PingOutPed(PEDESTRIAN *pPed) +int PingOutPed(PEDESTRIAN* pPed) { int pz; int px; @@ -3846,7 +3736,7 @@ int PingOutPed(PEDESTRIAN *pPed) // End Line: 9331 // [D] -void SetupCivJump(PEDESTRIAN *pPed, _CAR_DATA *cp) +void SetupCivJump(PEDESTRIAN* pPed, _CAR_DATA* cp) { int iVar1; long lVar2; @@ -3877,22 +3767,22 @@ void SetupCivJump(PEDESTRIAN *pPed, _CAR_DATA *cp) pPed->fpAgitatedState = CivPedJump; SetupPedMotionData(pPed); - if (cp == NULL) + if (cp == NULL) { if (bAvoidTanner == 0) { lVar2 = ratan2(pPed->position.vx - explosion[bAvoidBomb].pos.vx, pPed->position.vz - explosion[bAvoidBomb].pos.vz); uVar4 = lVar2 - 0x800; } - else + else { scale = 0x400; // [A] fuck.... - if (FIXED(-((int)(player[0].pPed)->speed * (int)rcossin_tbl[((int)((player[0].pPed)->dir).vy - 0x800U & 0xfff) * 2 + 1])) * - (((player[0].pPed)->position).vx - (pPed->position).vx) + - FIXED((int)(player[0].pPed)->speed * (int)rcossin_tbl[((int)((player[0].pPed)->dir).vy - 0x800U & 0xfff) * 2]) * - (((player[0].pPed)->position).vz - (pPed->position).vz) + 0x800 < 0) + if (FIXED(-((int)(player[0].pPed)->speed * (int)rcossin_tbl[((int)((player[0].pPed)->dir).vy - 0x800U & 0xfff) * 2 + 1])) * + (((player[0].pPed)->position).vx - (pPed->position).vx) + + FIXED((int)(player[0].pPed)->speed * (int)rcossin_tbl[((int)((player[0].pPed)->dir).vy - 0x800U & 0xfff) * 2]) * + (((player[0].pPed)->position).vz - (pPed->position).vz) + 0x800 < 0) { scale = -0x400; } @@ -3912,7 +3802,7 @@ void SetupCivJump(PEDESTRIAN *pPed, _CAR_DATA *cp) lVar2 = ratan2(y, x); uVar4 = lVar2; } - else + else { lVar2 = ratan2((cp->st).n.linearVelocity[2], (cp->st).n.linearVelocity[0]); uVar4 = ((short)~(ushort)(iVar3 * x + iVar1 * y + 0x800 >> 0x1c) >> 0xf & 0x800U) - lVar2; @@ -3946,7 +3836,7 @@ void SetupCivJump(PEDESTRIAN *pPed, _CAR_DATA *cp) // End Line: 8095 // [D] -void CivPedJump(PEDESTRIAN *pPed) +void CivPedJump(PEDESTRIAN* pPed) { if (pPed->frame1 == 2) pPed->speed = pPed->speed << 1; @@ -3985,7 +3875,7 @@ void CivPedJump(PEDESTRIAN *pPed) // End Line: 24420 // [D] -void SetupCivPedWalk(PEDESTRIAN *pPed) +void SetupCivPedWalk(PEDESTRIAN* pPed) { pPed->flags |= 0x10; @@ -4028,7 +3918,7 @@ void SetupCivPedWalk(PEDESTRIAN *pPed) // End Line: 9678 // [D] -void CivPedWalk(PEDESTRIAN *pPed) +void CivPedWalk(PEDESTRIAN* pPed) { short sVar2; ushort uVar3; @@ -4041,7 +3931,7 @@ void CivPedWalk(PEDESTRIAN *pPed) iVar5 = pPed->speed; - if ((*(uint *)&pPed->speed & 0xffff00) == 0x90000) + if ((*(uint*)&pPed->speed & 0xffff00) == 0x90000) { sVar2 = pPed->dir.vy; uVar4 = pPed->dir.vy + 2048; @@ -4056,18 +3946,18 @@ void CivPedWalk(PEDESTRIAN *pPed) (pPed->position).vy, (pPed->position).vz + ((int)rcossin_tbl[(uVar4 & 0xfff) * 2 + 1] >> 5), pPed); - if (turn == 0) + if (turn == 0) { - if ((*(uint *)&pPed->speed & 0xffff00) == 0x90000) + if ((*(uint*)&pPed->speed & 0xffff00) == 0x90000) { uVar4 = (int)pPed->dir.vy + 0xa00U & 0xfff; turn = IsPavement( (pPed->position).vx + FIXED(rcossin_tbl[uVar4 * 2] * 0x80), (pPed->position).vy, (pPed->position).vz + FIXED(rcossin_tbl[uVar4 * 2 + 1] * 0x80), - (PEDESTRIAN *)0x0); + (PEDESTRIAN*)0x0); - if (turn == 0) + if (turn == 0) pPed->flags &= ~0x2000; else pPed->flags |= 0x2000; @@ -4075,15 +3965,15 @@ void CivPedWalk(PEDESTRIAN *pPed) turn = -128; - if ((pPed->flags & 0x2000U) != 0) + if ((pPed->flags & 0x2000U) != 0) turn = 128; - if (pPed->doing_turn < 32) + if (pPed->doing_turn < 32) { SetPedestrianTurn(pPed, turn); pPed->doing_turn++; } - else + else { uVar4 = pPed->dir.vy + 0x800U & 0xfff; pPed->velocity.vx = FIXED(iVar5 * rcossin_tbl[uVar4 * 2]); @@ -4107,7 +3997,7 @@ void CivPedWalk(PEDESTRIAN *pPed) } } } - else + else { pPed->speed = 0; pPed->dir.vy = sVar2 + pPed->head_rot; @@ -4145,7 +4035,7 @@ void CivPedWalk(PEDESTRIAN *pPed) // End Line: 20481 // [D] -void CivPedSit(PEDESTRIAN *pPed) +void CivPedSit(PEDESTRIAN* pPed) { pPed->frame1 = 0; } @@ -4182,7 +4072,7 @@ void CivPedSit(PEDESTRIAN *pPed) void HandlePedestrians(void) { - if (gInGameCutsceneActive == 0 && NumPlayers == 1) + if (gInGameCutsceneActive == 0 && NumPlayers == 1) { BuildCarCollisionBox(); ControlPedestrians(); @@ -4216,7 +4106,7 @@ void HandlePedestrians(void) // End Line: 8931 // [D] -void PedestrianActionInit_WalkToTarget(PEDESTRIAN *pPed) +void PedestrianActionInit_WalkToTarget(PEDESTRIAN* pPed) { int dir; dir = CalcPedestrianDirection(0, (pPed->position).vx, (pPed->position).vz, &pPed->target); @@ -4234,7 +4124,7 @@ void PedestrianActionInit_WalkToTarget(PEDESTRIAN *pPed) else if (dir == 8) pPed->dir.vy = 0x800; - CorrectPathPosition(pPed, (VECTOR *)&pPed->position); + CorrectPathPosition(pPed, (VECTOR*)&pPed->position); } } @@ -4274,7 +4164,7 @@ void PedestrianActionInit_WalkToTarget(PEDESTRIAN *pPed) // End Line: 10609 // [D] -void CorrectPathPosition(PEDESTRIAN *pedestrian, VECTOR *position) +void CorrectPathPosition(PEDESTRIAN* pedestrian, VECTOR* position) { return; } @@ -4316,7 +4206,7 @@ void CorrectPathPosition(PEDESTRIAN *pedestrian, VECTOR *position) // End Line: 10738 // [D] -int CalcPedestrianDirection(int last_dir, int wx, int wz, VECTOR *target) +int CalcPedestrianDirection(int last_dir, int wx, int wz, VECTOR* target) { long lVar1; int iVar2; @@ -4327,7 +4217,7 @@ int CalcPedestrianDirection(int last_dir, int wx, int wz, VECTOR *target) uVar5 = pedestrian_roads.west == -20; uVar4 = pedestrian_roads.west == -20; - if (pedestrian_roads.east == -20) + if (pedestrian_roads.east == -20) { uVar5 = uVar5 | 2; uVar4++; @@ -4347,7 +4237,7 @@ int CalcPedestrianDirection(int last_dir, int wx, int wz, VECTOR *target) uVar3 = uVar5 & last_dir; - if ((uVar3 == 0) && (uVar3 = uVar5, 1 < uVar4)) + if ((uVar3 == 0) && (uVar3 = uVar5, 1 < uVar4)) { lVar1 = Random2(0); uVar3 = 0x10; @@ -4357,10 +4247,10 @@ int CalcPedestrianDirection(int last_dir, int wx, int wz, VECTOR *target) iVar2 = lVar1 % uVar4 + 1; - while (iVar2 != 0) + while (iVar2 != 0) { uVar3 = (int)uVar3 >> 1; - if ((uVar5 & uVar3) != 0) + if ((uVar5 & uVar3) != 0) iVar2--; } @@ -4374,15 +4264,15 @@ int CalcPedestrianDirection(int last_dir, int wx, int wz, VECTOR *target) { iVar2 = uVar4 + 0x600; } - else + else { - if (2 < uVar3) + if (2 < uVar3) { - if (uVar3 == 4) + if (uVar3 == 4) { iVar2 = uVar5 + 0x600; } - else + else { iVar2 = uVar5 - 0x200; if (uVar3 != 8) @@ -4395,7 +4285,7 @@ int CalcPedestrianDirection(int last_dir, int wx, int wz, VECTOR *target) goto LAB_0007177c; } iVar2 = uVar4 - 0x200; - if (uVar3 != 1) + if (uVar3 != 1) goto LAB_0007177c; } target->vx = iVar2; @@ -4437,7 +4327,7 @@ LAB_0007177c: // End Line: 18855 // [D] [A] might be incorrect -int IsPavement(int x, int y, int z, PEDESTRIAN *pPed) +int IsPavement(int x, int y, int z, PEDESTRIAN* pPed) { int r; VECTOR v; @@ -4447,7 +4337,7 @@ int IsPavement(int x, int y, int z, PEDESTRIAN *pPed) v.vz = z; r = GetSurfaceIndex(&v); - if (r == -20) + if (r == -20) { return (RoadInCell(&v) != 0); } @@ -4494,7 +4384,7 @@ int IsPavement(int x, int y, int z, PEDESTRIAN *pPed) // End Line: 18489 // [D] -void SetPedestrianTurn(PEDESTRIAN *pedestrian, int turn) +void SetPedestrianTurn(PEDESTRIAN* pedestrian, int turn) { int uVar6; @@ -4554,14 +4444,14 @@ void SetPedestrianTurn(PEDESTRIAN *pedestrian, int turn) /* WARNING: Unknown calling convention yet parameter storage is locked */ // [D] -SEATED_PEDESTRIANS * FindSeated(void) +SEATED_PEDESTRIANS* FindSeated(void) { int iVar1; int iVar2; int iVar3; - SEATED_PEDESTRIANS *seatedptr; + SEATED_PEDESTRIANS* seatedptr; - if (seated_pedestrian) + if (seated_pedestrian) { if (seated_pedestrian->rotation == 9999) return NULL; @@ -4580,7 +4470,7 @@ SEATED_PEDESTRIANS * FindSeated(void) if (seatedptr->index == 0 && (iVar2 = FIXED(seatedptr->x - player[0].pos[0]), iVar1 = FIXED(seatedptr->z - player[0].pos[2]), - iVar3 = iVar3 + -1, (iVar2 * iVar2 + iVar1 * iVar1) - 0xbU < 0x1d)) + iVar3 = iVar3 + -1, (iVar2 * iVar2 + iVar1 * iVar1) - 0xbU < 0x1d)) { add_seated(seatedptr, seated_count); return seatedptr; @@ -4622,19 +4512,19 @@ SEATED_PEDESTRIANS * FindSeated(void) // End Line: 11494 // [D] -SEATED_PEDESTRIANS * FindTannerASeat(PEDESTRIAN *pPed) +SEATED_PEDESTRIANS* FindTannerASeat(PEDESTRIAN* pPed) { int iVar1; int iVar2; - SEATED_PEDESTRIANS *seatedptr; - SEATED_PEDESTRIANS *theOne; + SEATED_PEDESTRIANS* seatedptr; + SEATED_PEDESTRIANS* theOne; int iVar5; theOne = NULL; iVar5 = 0x1000; seated_count = 0; - if (seated_pedestrian->rotation != 9999) + if (seated_pedestrian->rotation != 9999) { seatedptr = seated_pedestrian; seated_count = 0; @@ -4652,7 +4542,7 @@ SEATED_PEDESTRIANS * FindTannerASeat(PEDESTRIAN *pPed) iVar2 = pPed->position.vz - seatedptr->z; if (((iVar1 < 900) && (iVar2 < 900)) && - (iVar1 = FIXED(iVar1 * iVar1 + iVar2 * iVar2), iVar1 < iVar5)) + (iVar1 = FIXED(iVar1 * iVar1 + iVar2 * iVar2), iVar1 < iVar5)) { theOne = seatedptr; iVar5 = iVar1; @@ -4662,7 +4552,7 @@ SEATED_PEDESTRIANS * FindTannerASeat(PEDESTRIAN *pPed) } while (seatedptr->rotation != 9999); } - if (iVar5 < 6 && theOne) + if (iVar5 < 6 && theOne) { pPed->dir.vy = theOne->rotation; pPed->position.vx = theOne->x; @@ -4706,9 +4596,9 @@ SEATED_PEDESTRIANS * FindTannerASeat(PEDESTRIAN *pPed) // End Line: 11597 // [D] -void add_seated(SEATED_PEDESTRIANS *seatedptr, int seat_index) +void add_seated(SEATED_PEDESTRIANS* seatedptr, int seat_index) { - PEDESTRIAN *pedptr; + PEDESTRIAN* pedptr; long lVar3; long lVar4; @@ -4729,7 +4619,7 @@ void add_seated(SEATED_PEDESTRIANS *seatedptr, int seat_index) pedptr->position.vx = seatedptr->x; pedptr->position.vz = seatedptr->z; pedptr->position.vy = player[0].pos[1]; - pedptr->position.vy = -75 - MapHeight((VECTOR *)&pedptr->position); + pedptr->position.vy = -75 - MapHeight((VECTOR*)&pedptr->position); pedptr->index = 1; pedptr->seat_index = (char)seat_index; pedptr->pedType = CIVILIAN; @@ -4743,7 +4633,7 @@ void add_seated(SEATED_PEDESTRIANS *seatedptr, int seat_index) pedptr->pallet = lVar3 + (lVar3 / 5) * -5 + (lVar4 + (lVar4 / 5) * -5) * 16; lVar3 = Random2(0); - if ((lVar3 / 6) * 6 == lVar3-3) + if ((lVar3 / 6) * 6 == lVar3 - 3) pedptr->flags |= 0x4000; } } @@ -4773,7 +4663,7 @@ CAR_COLLISION_BOX collision_box[8]; _CAR_DATA* collision_car_ptr[8]; // [D] -void set_coll_box(int index, _CAR_DATA *cp, int offset) +void set_coll_box(int index, _CAR_DATA* cp, int offset) { int iVar1; int iVar2; @@ -4787,17 +4677,17 @@ void set_coll_box(int index, _CAR_DATA *cp, int offset) iVar5 = 400; - if (player[0].horn.on != 0) + if (player[0].horn.on != 0) { iVar5 = 260; - if (cp != &car_data[player[0].playerCarId]) + if (cp != &car_data[player[0].playerCarId]) goto LAB_00071b00; iVar5 = 1200; } - if (cp != car_data + player[0].playerCarId) + if (cp != car_data + player[0].playerCarId) iVar5 = iVar5 - 140; LAB_00071b00: @@ -4868,13 +4758,13 @@ int collision_boxes_set; // [D] void BuildCarCollisionBox(void) { - CAR_COLLISION_BOX *pCVar1; - CAR_COLLISION_BOX *pCVar2; + CAR_COLLISION_BOX* pCVar1; + CAR_COLLISION_BOX* pCVar2; uint uVar3; int iVar4; int index; - _ExOBJECT *p_Var5; - _CAR_DATA *cp; + _ExOBJECT* p_Var5; + _CAR_DATA* cp; iVar4 = (int)player[0].playerCarId; @@ -4893,7 +4783,7 @@ void BuildCarCollisionBox(void) do { iVar4 = index; - if (cp != &car_data[player[0].playerCarId] && cp->controlType != CONTROL_TYPE_NONE) + if (cp != &car_data[player[0].playerCarId] && cp->controlType != CONTROL_TYPE_NONE) { iVar4 = index + 1; set_coll_box(index, cp, 8); @@ -4990,15 +4880,15 @@ void BuildCarCollisionBox(void) // End Line: 19532 // [D] -_CAR_DATA* CheckForCar(PEDESTRIAN *pedestrian) +_CAR_DATA* CheckForCar(PEDESTRIAN* pedestrian) { int iVar1; int iVar3; - CAR_COLLISION_BOX *cb; - _CAR_DATA **pp_Var4; + CAR_COLLISION_BOX* cb; + _CAR_DATA** pp_Var4; iVar3 = 0; - if (0 < collision_boxes_set) + if (0 < collision_boxes_set) { pp_Var4 = collision_car_ptr; cb = collision_box; @@ -5022,7 +4912,7 @@ _CAR_DATA* CheckForCar(PEDESTRIAN *pedestrian) bAvoidBomb = iVar1; - if (player[0].playerType == 2 && CheckForPlayerCar(pedestrian, &tanner_collision_box) != 0) + if (player[0].playerType == 2 && CheckForPlayerCar(pedestrian, &tanner_collision_box) != 0) bAvoidTanner = 1; return NULL; @@ -5045,7 +4935,7 @@ _CAR_DATA* CheckForCar(PEDESTRIAN *pedestrian) // End Line: 26724 // [D] -int CheckForPlayerCar(PEDESTRIAN *pedestrian, CAR_COLLISION_BOX *collision_box) +int CheckForPlayerCar(PEDESTRIAN* pedestrian, CAR_COLLISION_BOX* collision_box) { int iVar1; @@ -5097,9 +4987,9 @@ int CheckForPlayerCar(PEDESTRIAN *pedestrian, CAR_COLLISION_BOX *collision_box) int basic_car_interest; // [D] -void CalculatePedestrianInterest(PEDESTRIAN *pPed) +void CalculatePedestrianInterest(PEDESTRIAN* pPed) { - _CAR_DATA *pCar; + _CAR_DATA* pCar; int carId; int interest; VECTOR v1; @@ -5122,12 +5012,12 @@ void CalculatePedestrianInterest(PEDESTRIAN *pPed) int dist = (v2.vx + v2.vz); - if (dist < 6001) + if (dist < 6001) interest = 6000 - dist; - else + else interest = 0; - if (pPed->type == PED_ACTION_JUMP) + if (pPed->type == PED_ACTION_JUMP) { pPed->head_rot = pPed->dir.vy + ratan2(v1.vz, v1.vx) + 3072 & 0xfff; return; @@ -5175,9 +5065,9 @@ void CalculatePedestrianInterest(PEDESTRIAN *pPed) /* end block 4 */ // End Line: 19318 -int PedSurfaceType(VECTOR *ped_pos) +int PedSurfaceType(VECTOR* ped_pos) { - _sdPlane *sfc_ptr; + _sdPlane* sfc_ptr; sfc_ptr = sdGetCell(ped_pos); if (!sfc_ptr) @@ -5207,9 +5097,9 @@ int PedSurfaceType(VECTOR *ped_pos) /* end block 3 */ // End Line: 26953 -void ProcessChairLump(char *lump_file, int lump_size) +void ProcessChairLump(char* lump_file, int lump_size) { - seated_pedestrian = (SEATED_PEDESTRIANS *)lump_file; + seated_pedestrian = (SEATED_PEDESTRIANS*)lump_file; } diff --git a/src_rebuild/GAME/DR2LIMITS.H b/src_rebuild/GAME/DR2LIMITS.H index 1ae62ff0..78917b0c 100644 --- a/src_rebuild/GAME/DR2LIMITS.H +++ b/src_rebuild/GAME/DR2LIMITS.H @@ -7,6 +7,7 @@ #define MAX_CARS 20 #define MAX_CAR_MODELS 5 #define MAX_PEDESTRIANS 28 +#define MAX_PLACED_PEDS 15 #define MAX_TRAFFIC_CARS 19 #define MAX_EXPLOSION_OBJECTS 5 #define MAX_THROWN_BOMBS 5 From f16edd31c9daf91e522b418c66e921f7ea5a573b Mon Sep 17 00:00:00 2001 From: Ilya Shurumov Date: Sun, 11 Oct 2020 19:38:07 +0600 Subject: [PATCH 26/41] - complete refactoring PEDEST.C --- src_rebuild/GAME/C/PEDEST.C | 1887 +++++++++++++++++------------------ 1 file changed, 920 insertions(+), 967 deletions(-) diff --git a/src_rebuild/GAME/C/PEDEST.C b/src_rebuild/GAME/C/PEDEST.C index c6fd0bee..c04b7c34 100644 --- a/src_rebuild/GAME/C/PEDEST.C +++ b/src_rebuild/GAME/C/PEDEST.C @@ -272,7 +272,7 @@ void ProcessTannerPad(PEDESTRIAN* pPed, ulong pad, char PadSteer, char use_analo lcp = &player[padId]; // don't move dead Tanner - if(lcp->dying != 0) + if (lcp->dying != 0) tannerPad = 0; else tannerPad = pad; @@ -321,7 +321,7 @@ void ProcessTannerPad(PEDESTRIAN* pPed, ulong pad, char PadSteer, char use_analo { case -32: break; - //case 6: // water. We allow to walk on water in Rio a little bit. Then he drowns + //case 6: // water. We allow to walk on water in Rio a little bit. Then he drowns case 9: // water with fade out default: dist = -1; @@ -1057,7 +1057,7 @@ int ActivatePlayerPedestrian(_CAR_DATA* pCar, char* padId, int direction, long(* else { pedptr->pallet = ((Random2(0) % 3) + (Random2(0) % 3)) * 16; - + //rnd1 = Random2(0); //rnd2 = Random2(0); //pedptr->pallet = rnd1 - (rnd1 / 3) * 3 + (rnd2 - (rnd2 / 3) * 3) * 16; @@ -1232,7 +1232,7 @@ void PlaceRoadBlockCops(void) return; numCops = 0; - + cp = car_data; do { if (cp->controlFlags & CONTROL_FLAG_COP_SLEEPING) @@ -1248,14 +1248,14 @@ void PlaceRoadBlockCops(void) do { pCar = pCopCars[i]; - + sn = rsin(pCar->hd.direction); cs = rcos(pCar->hd.direction); disp[0] = pCar->hd.where.t[0] - player[0].pos[0]; disp[1] = player[0].pos[1] - pCar->hd.where.t[1]; disp[2] = pCar->hd.where.t[2] - player[0].pos[2]; - + lbody = car_cosmetics[pCar->ap.model].colBox.vz - 120; wbody = car_cosmetics[pCar->ap.model].colBox.vx + 400; @@ -1330,7 +1330,7 @@ int CreatePedAtLocation(long(*pPos)[4], int pedType) pPed->flags = 0; pPed->fpRestState = fpPedPersonalityFunctions[12]; - + if (pedType == 8) { pPed->flags = 0; @@ -1430,15 +1430,15 @@ void DrawAllPedestrians(void) pPed = pUsedPeds; while (pPed != NULL) { - if (PositionVisible((VECTOR*)&pPed->position) && + if (PositionVisible((VECTOR*)&pPed->position) && FrustrumCheck((VECTOR*)&pPed->position, 60) != -1) { - if(pPed->pedType <= OTHER_MODEL) + if (pPed->pedType <= OTHER_MODEL) { if (!bKillTanner) DrawTanner(pPed); } - else if(pPed->pedType == OTHER_SPRITE) + else if (pPed->pedType == OTHER_SPRITE) { DrawCharacter(pPed); } @@ -1454,7 +1454,7 @@ void DrawAllPedestrians(void) /* // THIS IS OLD AND PROBABLY NOT NEEDED gte_SetRotMatrix(&mStore); - + pPed = pUsedPeds; while (pPed != NULL) { @@ -2274,7 +2274,6 @@ int lastCarCameraView = 0; void SetupGetOutCar(PEDESTRIAN* pPed, _CAR_DATA* pCar, int side) { bool entrySide; - short pedDir; int sn, cs; uint carDir; int xOfs; @@ -2393,7 +2392,7 @@ void SetupGetInCar(PEDESTRIAN* pPed) cs = rcos(carToGetIn->hd.direction); entrySide = cs * (carToGetIn->hd.where.t[0] - pPed->position.vx) - FIXED(sn * 0x1000) * (carToGetIn->hd.where.t[2] - pPed->position.vz) + 0x800 < 0; - + if (entrySide) pPed->dir.vy = carToGetIn->hd.direction + 0x400; else @@ -2617,7 +2616,7 @@ void TannerCameraHandler(PEDESTRIAN* pPed) padid = pPed->padId; lcp = &player[padid]; - + camera_position.vy = pPed->head_pos - 28 - lcp->pos[1]; if (Pads[padid].type == 4) @@ -2630,7 +2629,7 @@ void TannerCameraHandler(PEDESTRIAN* pPed) value = -padSteer; else value = padSteer; - + if (padSteer < 0) tannerLookAngle.vy = (value - 32) * -9; else @@ -2709,11 +2708,9 @@ void TannerCameraHandler(PEDESTRIAN* pPed) /* end block 3 */ // End Line: 7119 -// [D] +// [D] [T] void TannerSitDown(PEDESTRIAN* pPed) { - int iVar2; - if (oldCamView != 2 && player[pPed->padId].cameraView == 2) { camAngle.vx = camera_angle.vx; @@ -2723,7 +2720,7 @@ void TannerSitDown(PEDESTRIAN* pPed) // if sit down/standup animation playing if (pPed->flags & 4) - { + { if (pPed->frame1 == 0) { pPed->frame1 = 0; @@ -2834,7 +2831,7 @@ void AnimatePed(PEDESTRIAN* pPed) vec.vz = pPed->position.vz; vec.vy = -pPed->position.vy; - if(pPed->type != PED_ACTION_SIT) + if (pPed->type != PED_ACTION_SIT) { if (pPed->pedType == CIVILIAN && (pPed->flags & 0x8000U) != 0) pPed->position.vy = -60 - MapHeight(&vec); @@ -2855,8 +2852,8 @@ void AnimatePed(PEDESTRIAN* pPed) pPed->position.vz += FIXED(pPed->speed * rcossin_tbl[dir * 2 + 1]); } - if (pPed->type != PED_ACTION_SIT && - pPed->type != PED_ACTION_COPCROUCH && + if (pPed->type != PED_ACTION_SIT && + pPed->type != PED_ACTION_COPCROUCH && pPed->type != PED_ACTION_COPSTAND) { pPed->velocity.vy = 10; @@ -3124,7 +3121,7 @@ void SetupCivPedRouteData(VECTOR* pPos) /* WARNING: Unknown calling convention yet parameter storage is locked */ -// [D] +// [D] [T] void PingInPedestrians(void) { int bFound; @@ -3146,20 +3143,20 @@ void PingInPedestrians(void) if (gWeather == 0 && FindSeated() != NULL) return; - for(i = 0; i < 50; i++) + for (i = 0; i < 50; i++) { pinginPedAngle += 81; - + pingInDist = Random2(0) % 128 + 1536; - + randomLoc.vy = baseLoc.vy; randomLoc.vx = baseLoc.vx + pingInDist * FIXEDH(rcossin_tbl[(pinginPedAngle & 0xfffU) * 2] * 8); randomLoc.vz = baseLoc.vz + pingInDist * FIXEDH(rcossin_tbl[(pinginPedAngle & 0xfffU) * 2 + 1] * 8); randomLoc.vy = -MapHeight(&randomLoc); - if (baseLoc.vy - 512 <= -randomLoc.vy && - baseLoc.vy + 512 >= -randomLoc.vy && + if (baseLoc.vy - 512 <= -randomLoc.vy && + baseLoc.vy + 512 >= -randomLoc.vy && IsPavement(randomLoc.vx, randomLoc.vy, randomLoc.vz, NULL)) { if (pUsedPeds != NULL) @@ -3171,7 +3168,7 @@ void PingInPedestrians(void) bFound = 0; - while (dx*dx + dz*dz > 15999999) + while (dx * dx + dz * dz > 15999999) { pPed = pPed->pNext; @@ -3197,7 +3194,7 @@ void PingInPedestrians(void) return; pPed = CreatePedestrian(); - + pPed->flags = 0; pPed->position.vx = randomLoc.vx; pPed->position.vy = randomLoc.vy; @@ -3206,7 +3203,7 @@ void PingInPedestrians(void) pPed->dir.vx = 0; pPed->dir.vy = 0; pPed->position.vz = randomLoc.vz; - + baseLoc.vx = randomLoc.vx; baseLoc.vy = pPed->position.vy; baseLoc.vz = pPed->position.vz; @@ -3230,11 +3227,11 @@ void PingInPedestrians(void) pPed->pallet = (Random2(-28) % 5) + (Random2(-28) % 5) * 16; SetupPedMotionData(pPed); - + pPed->fpAgitatedState = NULL; pPed->dir.vy = 0; pPed->fpRestState = fpPedPersonalityFunctions[7]; - + rnd = Random2(0); if ((rnd / 6) * 6 != rnd - 3) @@ -3349,15 +3346,14 @@ void TannerCollision(PEDESTRIAN* pPed) /* end block 3 */ // End Line: 8378 -// [D] +// [D] [T] int FindPointOfCollision(_CAR_DATA* pCar, PEDESTRIAN* pPed) { - int iVar1; - uint uVar2; - int iVar3; - int iVar4; - int iVar5; - int iVar6; + int dx, dz; + int minZ; + int maxZ; + int minX; + int maxX; CDATA2D cd[2]; static CRET2D collisionResult; @@ -3379,52 +3375,50 @@ int FindPointOfCollision(_CAR_DATA* pCar, PEDESTRIAN* pPed) cd[1].x.vz = pCar->hd.where.t[2]; cd[1].theta = pCar->hd.direction; - iVar1 = bcollided2d(cd, 1); - if (iVar1 != 0) - { - bFindCollisionPoint(cd, &collisionResult); + if (!bcollided2d(cd, 1)) + return 0; + + bFindCollisionPoint(cd, &collisionResult); #if defined(COLLISION_DEBUG) && !defined(PSX) - extern int gShowCollisionDebug; - if (gShowCollisionDebug) - { - extern void Debug_AddLine(VECTOR & pointA, VECTOR & pointB, CVECTOR & color); - extern void Debug_AddLineOfs(VECTOR & pointA, VECTOR & pointB, VECTOR & ofs, CVECTOR & color); + extern int gShowCollisionDebug; + if (gShowCollisionDebug) + { + extern void Debug_AddLine(VECTOR & pointA, VECTOR & pointB, CVECTOR & color); + extern void Debug_AddLineOfs(VECTOR & pointA, VECTOR & pointB, VECTOR & ofs, CVECTOR & color); - CVECTOR bbcv = { 0, 0, 250 }; - CVECTOR rrcv = { 250, 0, 0 }; - CVECTOR yycv = { 250, 250, 0 }; + CVECTOR bbcv = { 0, 0, 250 }; + CVECTOR rrcv = { 250, 0, 0 }; + CVECTOR yycv = { 250, 250, 0 }; - VECTOR _zero = { 0, 100, 0 }; - VECTOR up = { 0, 200, 0 }; + VECTOR _zero = { 0, 100, 0 }; + VECTOR up = { 0, 200, 0 }; - Debug_AddLineOfs(_zero, up, cd[0].x, rrcv); + Debug_AddLineOfs(_zero, up, cd[0].x, rrcv); - Debug_AddLineOfs(_zero, up, cd[1].x, yycv); + Debug_AddLineOfs(_zero, up, cd[1].x, yycv); - Debug_AddLineOfs(_zero, up, collisionResult.hit, bbcv); - } + Debug_AddLineOfs(_zero, up, collisionResult.hit, bbcv); + } #endif - iVar4 = FIXED((collisionResult.hit.vx - cd[1].x.vx) * rcossin_tbl[(cd[1].theta & 0xfffU) * 2 + 1]) - - FIXED((collisionResult.hit.vz - cd[1].x.vz) * rcossin_tbl[(cd[1].theta & 0xfffU) * 2]); + dx = FIXED((collisionResult.hit.vx - cd[1].x.vx) * rcossin_tbl[(cd[1].theta & 0xfffU) * 2 + 1]) - + FIXED((collisionResult.hit.vz - cd[1].x.vz) * rcossin_tbl[(cd[1].theta & 0xfffU) * 2]); - iVar1 = FIXED((collisionResult.hit.vx - cd[1].x.vx) * rcossin_tbl[(cd[1].theta & 0xfffU) * 2]) + - FIXED((collisionResult.hit.vz - cd[1].x.vz) * rcossin_tbl[(cd[1].theta & 0xfffU) * 2 + 1]); + dz = FIXED((collisionResult.hit.vx - cd[1].x.vx) * rcossin_tbl[(cd[1].theta & 0xfffU) * 2]) + + FIXED((collisionResult.hit.vz - cd[1].x.vz) * rcossin_tbl[(cd[1].theta & 0xfffU) * 2 + 1]); - iVar5 = car_cos->colBox.vx + 96; - iVar3 = car_cos->colBox.vz; - iVar6 = car_cos->colBox.vx - 96; + minX = car_cos->colBox.vx + 96; + maxX = car_cos->colBox.vx - 96; - if ((iVar3 - 480 < iVar1) && (iVar1 < iVar3 - 200)) - { - if ((iVar6 < iVar4) && (iVar4 < iVar5)) - return 1; + minZ = car_cos->colBox.vz - 480; + maxZ = car_cos->colBox.vz - 200; - if ((iVar4 < -iVar6) && (-iVar5 < iVar4)) - return 1; - } + if (dz > minZ && dz < maxZ && + (dx > maxX && dx < minX || dx < -maxX && dx > -minX)) + { + return 1; } return 0; @@ -3514,35 +3508,21 @@ int FindPointOfCollision(_CAR_DATA* pCar, PEDESTRIAN* pPed) /* WARNING: Removing unreachable block (ram,0x00070ec8) */ /* WARNING: Type propagation algorithm not settling */ -// [D] +// [D] [T] int TannerCarCollisionCheck(VECTOR* pPos, int dir, int bQuick) { - int iVar1; - uint uVar2; - int iVar3; - int iVar4; - int iVar5; - int iVar6; - int iVar7; - int iVar8; - int iVar9; - int iVar10; - int iVar11; - int iVar12; _CAR_DATA* cp1; - int carLength; - int dNewLBODY[2]; - VECTOR velocity; long pointVel[4]; long reaction[4]; long lever[4]; + int strikeVel; SVECTOR boxDisp; CAR_COSMETICS* car_cos; _CAR_DATA* pcdTanner; CRET2D collisionResult; // offset 0x30 CDATA2D cd[2]; - + pcdTanner = &car_data[21]; cd[0].length[0] = 0x3c; @@ -3574,72 +3554,65 @@ int TannerCarCollisionCheck(VECTOR* pPos, int dir, int bQuick) gte_stlvnl(&cd[1].x); - if (cp1->controlType != CONTROL_TYPE_NONE) + if (cp1->controlType != CONTROL_TYPE_NONE && + ABS(cp1->hd.where.t[1] + pPos->vy) < 500 && + bcollided2d(cd, 1)) { - if (ABS(cp1->hd.where.t[1] + pPos->vy) < 500 && - bcollided2d(cd, 1)) + if (bQuick != 0) + return 1; + + if (FIXEDH(cp1->hd.wheel_speed) > 50) + return 1; + + bFindCollisionPoint(cd, &collisionResult); + + collisionResult.surfNormal.vy = 0; + collisionResult.hit.vy = pcdTanner->hd.where.t[1] + 60; + + pcdTanner->hd.where.t[0] += FIXEDH(collisionResult.penetration * -collisionResult.surfNormal.vx); + pcdTanner->hd.where.t[2] += FIXEDH(collisionResult.penetration * -collisionResult.surfNormal.vz); + + lever[0] = collisionResult.hit.vx - pcdTanner->hd.where.t[0]; + lever[1] = collisionResult.hit.vy - pcdTanner->hd.where.t[1]; + lever[2] = collisionResult.hit.vz - pcdTanner->hd.where.t[2]; + + pointVel[0] = FIXEDH(pcdTanner->st.n.angularVelocity[1] * lever[2] - pcdTanner->st.n.angularVelocity[2] * lever[1]) + pcdTanner->st.n.linearVelocity[0]; + pointVel[2] = FIXEDH(pcdTanner->st.n.angularVelocity[0] * lever[1] - pcdTanner->st.n.angularVelocity[1] * lever[0]) + pcdTanner->st.n.linearVelocity[2]; + + strikeVel = FixFloorSigned(pointVel[0], 8) * FixFloorSigned(-collisionResult.surfNormal.vx, 4) + FixFloorSigned(pointVel[2], 8) * FixFloorSigned(-collisionResult.surfNormal.vz, 4); + + if (strikeVel < 0) { - if (bQuick != 0) - return 1; + int lever_dot_n; // $a0 + int displacementsquared; // $a1 + int denom; // $a0 + int twistRateY; - if (50 < FIXEDH(cp1->hd.wheel_speed)) - return 1; + twistRateY = car_cos->twistRateY; + + lever_dot_n = FIXEDH(lever[0] * -collisionResult.surfNormal.vx + lever[2] * -collisionResult.surfNormal.vz); + displacementsquared = FIXEDH(((lever[0] * lever[0] + lever[2] * lever[2]) - lever_dot_n * lever_dot_n) * twistRateY) + 0x1000; - bFindCollisionPoint(cd, &collisionResult); + if (-strikeVel < 0x7f001) + denom = (strikeVel * -0x1000) / displacementsquared; + else + denom = -strikeVel / displacementsquared << 0xc; - iVar3 = -collisionResult.surfNormal.vz; - iVar1 = -collisionResult.surfNormal.vx; + denom = FixFloorSigned(denom, 6); + + reaction[0] = denom * FixFloorSigned(-collisionResult.surfNormal.vx, 6); + reaction[2] = denom * FixFloorSigned(-collisionResult.surfNormal.vz, 6); + + pcdTanner->st.n.linearVelocity[0] += pcdTanner->st.n.linearVelocity[0] + reaction[0]; + pcdTanner->st.n.linearVelocity[2] += pcdTanner->st.n.linearVelocity[2] + reaction[2]; - iVar10 = pcdTanner->hd.where.t[2] + FIXEDH(collisionResult.penetration * iVar3); - iVar12 = collisionResult.hit.vz - iVar10; - collisionResult.hit.vy = pcdTanner->hd.where.t[1] + 0x3c; - iVar9 = collisionResult.hit.vy - pcdTanner->hd.where.t[1]; - iVar8 = pcdTanner->hd.where.t[0] + FIXEDH(collisionResult.penetration * iVar1); - iVar11 = collisionResult.hit.vx - iVar8; - - collisionResult.surfNormal.vy = 0; - - iVar7 = FIXEDH(pcdTanner->st.n.angularVelocity[1] * iVar12 - pcdTanner->st.n.angularVelocity[2] * iVar9) + pcdTanner->st.n.linearVelocity[0]; - iVar5 = FIXEDH(pcdTanner->st.n.angularVelocity[0] * iVar9 - pcdTanner->st.n.angularVelocity[1] * iVar11) + pcdTanner->st.n.linearVelocity[2]; - - iVar4 = iVar1; - iVar6 = iVar3; - - iVar5 = FixFloorSigned(iVar7, 8) * FixFloorSigned(iVar4, 4) + FixFloorSigned(iVar5, 8) * FixFloorSigned(iVar6, 4); - - if (iVar5 < 0) - { - iVar7 = FIXEDH(iVar11 * iVar1 + iVar12 * iVar3); - iVar7 = FIXEDH(((iVar11 * iVar11 + iVar12 * iVar12) - iVar7 * iVar7) * car_cosmetics[pcdTanner->ap.model].twistRateY) + 0x1000; - - if (-iVar5 < 0x7f001) - iVar5 = (iVar5 * -0x1000) / iVar7; - else - iVar5 = -iVar5 / iVar7 << 0xc; - - iVar7 = iVar1; - - iVar4 = FixFloorSigned(iVar5, 6) * FixFloorSigned(iVar7, 6); - iVar7 = iVar3; - - iVar5 = FixFloorSigned(iVar5, 6) * FixFloorSigned(iVar7, 6); - pcdTanner->st.n.linearVelocity[0] = pcdTanner->st.n.linearVelocity[0] + iVar4; - pcdTanner->st.n.linearVelocity[2] = pcdTanner->st.n.linearVelocity[2] + iVar5; - - pcdTanner->hd.aacc[2] = pcdTanner->hd.aacc[2] - FIXEDH(iVar9 * iVar4); - pcdTanner->hd.aacc[0] = pcdTanner->hd.aacc[0] + FIXEDH(iVar9 * iVar5); - - pcdTanner->hd.aacc[1] = (pcdTanner->hd.aacc[1] + FIXEDH(iVar12 * iVar4)) - FIXEDH(iVar11 * iVar5); - - collisionResult.hit.vy = -collisionResult.hit.vy; - } - - pcdTanner->hd.where.t[0] = iVar8 - FIXEDH(pcdTanner->st.n.linearVelocity[0]); - pcdTanner->hd.where.t[2] = iVar10 - FIXEDH(pcdTanner->st.n.linearVelocity[2]); - - collisionResult.surfNormal.vx = iVar1; - collisionResult.surfNormal.vz = iVar3; + pcdTanner->hd.aacc[2] -= FIXEDH(lever[1] * reaction[0]); + pcdTanner->hd.aacc[0] += FIXEDH(lever[1] * reaction[2]); + pcdTanner->hd.aacc[1] += FIXEDH(lever[2] * reaction[0]) - FIXEDH(lever[0] * reaction[2]); } + + pcdTanner->hd.where.t[0] -= FIXEDH(pcdTanner->st.n.linearVelocity[0]); + pcdTanner->hd.where.t[2] -= FIXEDH(pcdTanner->st.n.linearVelocity[2]); } cp1--; } while (cp1 >= car_data); @@ -3652,37 +3625,37 @@ int TannerCarCollisionCheck(VECTOR* pPos, int dir, int bQuick) // decompiled code // original method signature: // int /*$ra*/ PingOutPed(struct PEDESTRIAN *pPed /*$a2*/) - // line 3915, offset 0x000731f8 - /* begin block 1 */ - // Start line: 3916 - // Start offset: 0x000731F8 - // Variables: - // int px; // $a0 - // int pz; // $v1 - // int ps; // $a0 - /* end block 1 */ - // End offset: 0x00073270 - // End Line: 3938 +// line 3915, offset 0x000731f8 +/* begin block 1 */ +// Start line: 3916 +// Start offset: 0x000731F8 +// Variables: +// int px; // $a0 +// int pz; // $v1 +// int ps; // $a0 +/* end block 1 */ +// End offset: 0x00073270 +// End Line: 3938 - /* begin block 2 */ - // Start line: 23590 - /* end block 2 */ - // End Line: 23591 +/* begin block 2 */ +// Start line: 23590 +/* end block 2 */ +// End Line: 23591 - /* begin block 3 */ - // Start line: 24071 - /* end block 3 */ - // End Line: 24072 +/* begin block 3 */ +// Start line: 24071 +/* end block 3 */ +// End Line: 24072 -// [D] +// [D] [T] int PingOutPed(PEDESTRIAN* pPed) { int pz; int px; int ps; - px = (pPed->position).vx - player[0].pos[0]; - pz = (pPed->position).vz - player[0].pos[2]; + px = pPed->position.vx - player[0].pos[0]; + pz = pPed->position.vz - player[0].pos[2]; ps = px * px + pz * pz; @@ -3697,54 +3670,52 @@ int PingOutPed(PEDESTRIAN* pPed) // decompiled code // original method signature: // void /*$ra*/ SetupCivJump(struct PEDESTRIAN *pPed /*$s1*/, struct _CAR_DATA *cp /*$s0*/) - // line 3946, offset 0x00071054 - /* begin block 1 */ - // Start line: 3947 - // Start offset: 0x00071054 - // Variables: - // long disp[4]; // stack offset -48 - // long dir[4]; // stack offset -32 - // int angle; // $s0 +// line 3946, offset 0x00071054 +/* begin block 1 */ +// Start line: 3947 +// Start offset: 0x00071054 +// Variables: +// long disp[4]; // stack offset -48 +// long dir[4]; // stack offset -32 +// int angle; // $s0 - /* begin block 1.1 */ - // Start line: 3960 - // Start offset: 0x000710C0 - // Variables: - // short scale; // $a2 - /* end block 1.1 */ - // End offset: 0x000710E4 - // End Line: 3967 +/* begin block 1.1 */ +// Start line: 3960 +// Start offset: 0x000710C0 +// Variables: +// short scale; // $a2 +/* end block 1.1 */ +// End offset: 0x000710E4 +// End Line: 3967 - /* begin block 1.2 */ - // Start line: 4008 - // Start offset: 0x000711E8 - /* end block 1.2 */ - // End offset: 0x000712AC - // End Line: 4027 - /* end block 1 */ - // End offset: 0x00071324 - // End Line: 4040 +/* begin block 1.2 */ +// Start line: 4008 +// Start offset: 0x000711E8 +/* end block 1.2 */ +// End offset: 0x000712AC +// End Line: 4027 +/* end block 1 */ +// End offset: 0x00071324 +// End Line: 4040 - /* begin block 2 */ - // Start line: 9290 - /* end block 2 */ - // End Line: 9291 +/* begin block 2 */ +// Start line: 9290 +/* end block 2 */ +// End Line: 9291 - /* begin block 3 */ - // Start line: 9330 - /* end block 3 */ - // End Line: 9331 +/* begin block 3 */ +// Start line: 9330 +/* end block 3 */ +// End Line: 9331 -// [D] +// [D] [T] void SetupCivJump(PEDESTRIAN* pPed, _CAR_DATA* cp) { - int iVar1; - long lVar2; - int y; - int iVar3; + int dz; short scale; - int x; - ushort uVar4; + int dx; + short angle; + long dir[4]; if (pPed->type != PED_ACTION_JUMP) { @@ -3753,63 +3724,63 @@ void SetupCivJump(PEDESTRIAN* pPed, _CAR_DATA* cp) if (cp == &car_data[player[0].playerCarId]) { - scale = 0x1000; - if (player[0].horn.on != 0) scale = 0x800; + else + scale = 0x1000; NoteFelony(&felonyData, 1, scale); } } pPed->type = PED_ACTION_JUMP; - pPed->flags = pPed->flags | 0x10; + pPed->flags |= 0x10; pPed->fpAgitatedState = CivPedJump; + SetupPedMotionData(pPed); if (cp == NULL) { if (bAvoidTanner == 0) { - lVar2 = ratan2(pPed->position.vx - explosion[bAvoidBomb].pos.vx, pPed->position.vz - explosion[bAvoidBomb].pos.vz); - uVar4 = lVar2 - 0x800; + angle = ratan2(pPed->position.vx - explosion[bAvoidBomb].pos.vx, pPed->position.vz - explosion[bAvoidBomb].pos.vz) - 2048; } else { - scale = 0x400; + dx = player[0].pPed->position.vx - pPed->position.vx; + dz = player[0].pPed->position.vz - pPed->position.vz; + dir[0] = player[0].pPed->speed * rcossin_tbl[(player[0].pPed->dir.vy - 0x800U & 0xfff) * 2 + 1]; + dir[2] = player[0].pPed->speed * rcossin_tbl[(player[0].pPed->dir.vy - 0x800U & 0xfff) * 2]; + // [A] fuck.... - if (FIXED(-((int)(player[0].pPed)->speed * (int)rcossin_tbl[((int)((player[0].pPed)->dir).vy - 0x800U & 0xfff) * 2 + 1])) * - (((player[0].pPed)->position).vx - (pPed->position).vx) + - FIXED((int)(player[0].pPed)->speed * (int)rcossin_tbl[((int)((player[0].pPed)->dir).vy - 0x800U & 0xfff) * 2]) * - (((player[0].pPed)->position).vz - (pPed->position).vz) + 0x800 < 0) - { - scale = -0x400; - } + if (FIXED(-dir[0]) * dx + FIXED(dir[2]) * dz + 0x800 < 0) + angle = -1024; + else + angle = 1024; - uVar4 = scale + ((player[0].pPed)->dir).vy; + angle += player[0].pPed->dir.vy; } } else { - x = (cp->hd).where.t[0] - (pPed->position).vx; - iVar3 = (cp->st).n.linearVelocity[2]; - y = (cp->hd).where.t[2] - (pPed->position).vz; - iVar1 = -(cp->st).n.linearVelocity[0]; + dx = cp->hd.where.t[0] - pPed->position.vx; + dz = cp->hd.where.t[2] - pPed->position.vz; - if ((iVar3 == 0) && (iVar1 == 0)) + if (cp->st.n.linearVelocity[2] != 0 || cp->st.n.linearVelocity[0] != 0) { - lVar2 = ratan2(y, x); - uVar4 = lVar2; + int carVelDisp; + carVelDisp = (cp->st.n.linearVelocity[2] * dx - cp->st.n.linearVelocity[0] * dz + 2048); + + angle = ((short)~(ushort)(carVelDisp >> 0x1c) >> 0xf & 0x800U) - ratan2(cp->st.n.linearVelocity[2], cp->st.n.linearVelocity[0]); } else { - lVar2 = ratan2((cp->st).n.linearVelocity[2], (cp->st).n.linearVelocity[0]); - uVar4 = ((short)~(ushort)(iVar3 * x + iVar1 * y + 0x800 >> 0x1c) >> 0xf & 0x800U) - lVar2; + angle = ratan2(dz, dx);; } } - pPed->dir.vy = uVar4 & 0xfff; + pPed->dir.vy = angle & 0xfff; } @@ -3817,31 +3788,31 @@ void SetupCivJump(PEDESTRIAN* pPed, _CAR_DATA* cp) // decompiled code // original method signature: // void /*$ra*/ CivPedJump(struct PEDESTRIAN *pPed /*$s0*/) - // line 4047, offset 0x00072cf0 - /* begin block 1 */ - // Start line: 4048 - // Start offset: 0x00072CF0 - /* end block 1 */ - // End offset: 0x00072DA0 - // End Line: 4073 +// line 4047, offset 0x00072cf0 +/* begin block 1 */ +// Start line: 4048 +// Start offset: 0x00072CF0 +/* end block 1 */ +// End offset: 0x00072DA0 +// End Line: 4073 - /* begin block 2 */ - // Start line: 20349 - /* end block 2 */ - // End Line: 20350 +/* begin block 2 */ +// Start line: 20349 +/* end block 2 */ +// End Line: 20350 - /* begin block 3 */ - // Start line: 8094 - /* end block 3 */ - // End Line: 8095 +/* begin block 3 */ +// Start line: 8094 +/* end block 3 */ +// End Line: 8095 -// [D] +// [D] [T] void CivPedJump(PEDESTRIAN* pPed) { if (pPed->frame1 == 2) - pPed->speed = pPed->speed << 1; + pPed->speed *= 2; else if (pPed->frame1 == 14) - pPed->speed = pPed->speed >> 1; + pPed->speed /= 2; AnimatePed(pPed); @@ -3863,18 +3834,18 @@ void CivPedJump(PEDESTRIAN* pPed) // decompiled code // original method signature: // void /*$ra*/ SetupCivPedWalk(struct PEDESTRIAN *pPed /*$s0*/) - // line 4080, offset 0x00073270 - /* begin block 1 */ - // Start line: 24276 - /* end block 1 */ - // End Line: 24277 +// line 4080, offset 0x00073270 +/* begin block 1 */ +// Start line: 24276 +/* end block 1 */ +// End Line: 24277 - /* begin block 2 */ - // Start line: 24419 - /* end block 2 */ - // End Line: 24420 +/* begin block 2 */ +// Start line: 24419 +/* end block 2 */ +// End Line: 24420 -// [D] +// [D] [T] void SetupCivPedWalk(PEDESTRIAN* pPed) { pPed->flags |= 0x10; @@ -3885,6 +3856,7 @@ void SetupCivPedWalk(PEDESTRIAN* pPed) pPed->speed = 10; SetupPedMotionData(pPed); + pPed->frame1 = 0; } @@ -3893,80 +3865,68 @@ void SetupCivPedWalk(PEDESTRIAN* pPed) // decompiled code // original method signature: // void /*$ra*/ CivPedWalk(struct PEDESTRIAN *pPed /*$s0*/) - // line 4101, offset 0x00071324 - /* begin block 1 */ - // Start line: 4102 - // Start offset: 0x00071324 - // Variables: - // int turn; // $a1 - // int offset1; // $t0 - // int offset2; // $v1 - // int lookahead; // $s3 - // int speed; // $s1 - /* end block 1 */ - // End offset: 0x000715FC - // End Line: 4182 +// line 4101, offset 0x00071324 +/* begin block 1 */ +// Start line: 4102 +// Start offset: 0x00071324 +// Variables: +// int turn; // $a1 +// int offset1; // $t0 +// int offset2; // $v1 +// int lookahead; // $s3 +// int speed; // $s1 +/* end block 1 */ +// End offset: 0x000715FC +// End Line: 4182 - /* begin block 2 */ - // Start line: 9615 - /* end block 2 */ - // End Line: 9616 +/* begin block 2 */ +// Start line: 9615 +/* end block 2 */ +// End Line: 9616 - /* begin block 3 */ - // Start line: 9677 - /* end block 3 */ - // End Line: 9678 +/* begin block 3 */ +// Start line: 9677 +/* end block 3 */ +// End Line: 9678 -// [D] +// [D] [T] void CivPedWalk(PEDESTRIAN* pPed) { - short sVar2; - ushort uVar3; - uint uVar4; + int dir; int turn; - int iVar5; if ((pPed->flags & 0x10U) == 0) SetupCivPedWalk(pPed); - iVar5 = pPed->speed; + if (pPed->finished_turn == 9) + dir = pPed->dir.vy + 2048; + else + dir = pPed->dir.vy + 1850; - if ((*(uint*)&pPed->speed & 0xffff00) == 0x90000) - { - sVar2 = pPed->dir.vy; - uVar4 = pPed->dir.vy + 2048; - } - else { - sVar2 = pPed->dir.vy; - uVar4 = pPed->dir.vy + 1850; - } if ((pPed->flags & 2U) == 0) { - turn = IsPavement((pPed->position).vx + ((int)rcossin_tbl[(uVar4 & 0xfff) * 2] >> 5), - (pPed->position).vy, - (pPed->position).vz + ((int)rcossin_tbl[(uVar4 & 0xfff) * 2 + 1] >> 5), pPed); - - if (turn == 0) + if (IsPavement(pPed->position.vx + (rcossin_tbl[(dir & 0xfff) * 2] >> 5), + pPed->position.vy, + pPed->position.vz + (rcossin_tbl[(dir & 0xfff) * 2 + 1] >> 5), pPed) == 0) { - if ((*(uint*)&pPed->speed & 0xffff00) == 0x90000) + if (pPed->finished_turn == 9) { - uVar4 = (int)pPed->dir.vy + 0xa00U & 0xfff; - turn = IsPavement( - (pPed->position).vx + FIXED(rcossin_tbl[uVar4 * 2] * 0x80), - (pPed->position).vy, - (pPed->position).vz + FIXED(rcossin_tbl[uVar4 * 2 + 1] * 0x80), - (PEDESTRIAN*)0x0); + dir = pPed->dir.vy + 0xa00U & 0xfff; + + if (IsPavement( + pPed->position.vx + FIXED(rcossin_tbl[dir * 2] * 0x80), + pPed->position.vy, + pPed->position.vz + FIXED(rcossin_tbl[dir * 2 + 1] * 0x80), NULL) == 0) - if (turn == 0) pPed->flags &= ~0x2000; else pPed->flags |= 0x2000; } - turn = -128; - - if ((pPed->flags & 0x2000U) != 0) + if (pPed->flags & 0x2000) turn = 128; + else + turn = -128; if (pPed->doing_turn < 32) { @@ -3975,9 +3935,10 @@ void CivPedWalk(PEDESTRIAN* pPed) } else { - uVar4 = pPed->dir.vy + 0x800U & 0xfff; - pPed->velocity.vx = FIXED(iVar5 * rcossin_tbl[uVar4 * 2]); - pPed->velocity.vz = FIXED(iVar5 * rcossin_tbl[uVar4 * 2 + 1]); + dir = pPed->dir.vy + 0x800U & 0xfff; + + pPed->velocity.vx = FIXED(pPed->speed * rcossin_tbl[dir * 2]); + pPed->velocity.vz = FIXED(pPed->speed * rcossin_tbl[dir * 2 + 1]); } pPed->finished_turn = 0; } @@ -3987,20 +3948,21 @@ void CivPedWalk(PEDESTRIAN* pPed) if (pPed->finished_turn++ > 8) { - uVar3 = pPed->dir.vy + 0x200U & 0xfc00; - pPed->dir.vy = uVar3; - uVar4 = uVar3 + 0x800U & 0xfff; - pPed->velocity.vx = FIXED(iVar5 * rcossin_tbl[uVar4 * 2]); - sVar2 = rcossin_tbl[uVar4 * 2 + 1]; + pPed->dir.vy += 0x200U & 0xfc00; + + dir = pPed->dir.vy + 0x800U & 0xfff; + + pPed->velocity.vx = FIXED(pPed->speed * rcossin_tbl[dir * 2]); + pPed->velocity.vz = FIXED(pPed->speed * rcossin_tbl[dir * 2 + 1]); + pPed->finished_turn = 9; - pPed->velocity.vz = FIXED(iVar5 * sVar2); } } } else { pPed->speed = 0; - pPed->dir.vy = sVar2 + pPed->head_rot; + pPed->dir.vy += pPed->head_rot; } AnimatePed(pPed); @@ -4011,30 +3973,30 @@ void CivPedWalk(PEDESTRIAN* pPed) // decompiled code // original method signature: // void /*$ra*/ CivPedSit(struct PEDESTRIAN *pPed /*$a0*/) - // line 4190, offset 0x00072ce8 - /* begin block 1 */ - // Start line: 4192 - // Start offset: 0x00072CE8 - /* end block 1 */ - // End offset: 0x00072CF0 - // End Line: 4208 +// line 4190, offset 0x00072ce8 +/* begin block 1 */ +// Start line: 4192 +// Start offset: 0x00072CE8 +/* end block 1 */ +// End offset: 0x00072CF0 +// End Line: 4208 - /* begin block 2 */ - // Start line: 20475 - /* end block 2 */ - // End Line: 20476 +/* begin block 2 */ +// Start line: 20475 +/* end block 2 */ +// End Line: 20476 - /* begin block 3 */ - // Start line: 20476 - /* end block 3 */ - // End Line: 20477 +/* begin block 3 */ +// Start line: 20476 +/* end block 3 */ +// End Line: 20477 - /* begin block 4 */ - // Start line: 20480 - /* end block 4 */ - // End Line: 20481 +/* begin block 4 */ +// Start line: 20480 +/* end block 4 */ +// End Line: 20481 -// [D] +// [D] [T] void CivPedSit(PEDESTRIAN* pPed) { pPed->frame1 = 0; @@ -4045,39 +4007,40 @@ void CivPedSit(PEDESTRIAN* pPed) // decompiled code // original method signature: // void /*$ra*/ HandlePedestrians() - // line 4221, offset 0x0007211c - /* begin block 1 */ - // Start line: 4223 - // Start offset: 0x0007211C - /* end block 1 */ - // End offset: 0x0007215C - // End Line: 4457 +// line 4221, offset 0x0007211c +/* begin block 1 */ +// Start line: 4223 +// Start offset: 0x0007211C +/* end block 1 */ +// End offset: 0x0007215C +// End Line: 4457 - /* begin block 2 */ - // Start line: 13906 - /* end block 2 */ - // End Line: 13907 +/* begin block 2 */ +// Start line: 13906 +/* end block 2 */ +// End Line: 13907 - /* begin block 3 */ - // Start line: 13907 - /* end block 3 */ - // End Line: 13908 +/* begin block 3 */ +// Start line: 13907 +/* end block 3 */ +// End Line: 13908 - /* begin block 4 */ - // Start line: 13925 - /* end block 4 */ - // End Line: 13926 +/* begin block 4 */ +// Start line: 13925 +/* end block 4 */ +// End Line: 13926 /* WARNING: Unknown calling convention yet parameter storage is locked */ +// [D] [T] void HandlePedestrians(void) { - if (gInGameCutsceneActive == 0 && NumPlayers == 1) - { - BuildCarCollisionBox(); - ControlPedestrians(); - PingInPedestrians(); - } + if (gInGameCutsceneActive != 0 || NumPlayers != 1) + return; + + BuildCarCollisionBox(); + ControlPedestrians(); + PingInPedestrians(); } @@ -4085,47 +4048,47 @@ void HandlePedestrians(void) // decompiled code // original method signature: // void /*$ra*/ PedestrianActionInit_WalkToTarget(struct PEDESTRIAN *pPed /*$s0*/) - // line 4465, offset 0x0007283c - /* begin block 1 */ - // Start line: 4466 - // Start offset: 0x0007283C - // Variables: - // int dir; // $v1 - /* end block 1 */ - // End offset: 0x000728B8 - // End Line: 4496 +// line 4465, offset 0x0007283c +/* begin block 1 */ +// Start line: 4466 +// Start offset: 0x0007283C +// Variables: +// int dir; // $v1 +/* end block 1 */ +// End offset: 0x000728B8 +// End Line: 4496 - /* begin block 2 */ - // Start line: 18892 - /* end block 2 */ - // End Line: 18893 +/* begin block 2 */ +// Start line: 18892 +/* end block 2 */ +// End Line: 18893 - /* begin block 3 */ - // Start line: 8930 - /* end block 3 */ - // End Line: 8931 +/* begin block 3 */ +// Start line: 8930 +/* end block 3 */ +// End Line: 8931 -// [D] +// [D] [T] void PedestrianActionInit_WalkToTarget(PEDESTRIAN* pPed) { int dir; dir = CalcPedestrianDirection(0, (pPed->position).vx, (pPed->position).vz, &pPed->target); - if (dir != 0) - { - pPed->last_dir = dir; + if (dir == 0) + return; - if (dir == 1) - pPed->dir.vy = 0x400; - else if (dir == 2) - pPed->dir.vy = 0xc00; - else if (dir == 4) - pPed->dir.vy = 0; - else if (dir == 8) - pPed->dir.vy = 0x800; + pPed->last_dir = dir; - CorrectPathPosition(pPed, (VECTOR*)&pPed->position); - } + if (dir == 1) + pPed->dir.vy = 1024; + else if (dir == 2) + pPed->dir.vy = 3072; + else if (dir == 4) + pPed->dir.vy = 0; + else if (dir == 8) + pPed->dir.vy = 2048; + + CorrectPathPosition(pPed, (VECTOR*)&pPed->position); } @@ -4133,40 +4096,39 @@ void PedestrianActionInit_WalkToTarget(PEDESTRIAN* pPed) // decompiled code // original method signature: // void /*$ra*/ CorrectPathPosition(struct PEDESTRIAN *pedestrian /*$a0*/, struct VECTOR *position /*$a1*/) - // line 4508, offset 0x000715fc - /* begin block 1 */ - // Start line: 4510 - // Start offset: 0x000715FC - // Variables: - // struct VECTOR vec; // stack offset -16 - /* end block 1 */ - // End offset: 0x000715FC - // End Line: 4610 +// line 4508, offset 0x000715fc +/* begin block 1 */ +// Start line: 4510 +// Start offset: 0x000715FC +// Variables: +// struct VECTOR vec; // stack offset -16 +/* end block 1 */ +// End offset: 0x000715FC +// End Line: 4610 - /* begin block 2 */ - // Start line: 10180 - /* end block 2 */ - // End Line: 10181 +/* begin block 2 */ +// Start line: 10180 +/* end block 2 */ +// End Line: 10181 - /* begin block 3 */ - // Start line: 10507 - /* end block 3 */ - // End Line: 10508 +/* begin block 3 */ +// Start line: 10507 +/* end block 3 */ +// End Line: 10508 - /* begin block 4 */ - // Start line: 10508 - /* end block 4 */ - // End Line: 10509 +/* begin block 4 */ +// Start line: 10508 +/* end block 4 */ +// End Line: 10509 - /* begin block 5 */ - // Start line: 10608 - /* end block 5 */ - // End Line: 10609 +/* begin block 5 */ +// Start line: 10608 +/* end block 5 */ +// End Line: 10609 -// [D] +// [D] [T] void CorrectPathPosition(PEDESTRIAN* pedestrian, VECTOR* position) { - return; } @@ -4174,125 +4136,121 @@ void CorrectPathPosition(PEDESTRIAN* pedestrian, VECTOR* position) // decompiled code // original method signature: // int /*$ra*/ CalcPedestrianDirection(int last_dir /*$a0*/, int wx /*$s5*/, int wz /*$s6*/, struct VECTOR *target /*$s3*/) - // line 4619, offset 0x00071608 - /* begin block 1 */ - // Start line: 4620 - // Start offset: 0x00071608 - // Variables: - // int dir; // $s2 - // int num; // $s1 - // int rx; // $v1 - // int rz; // $a0 - // int mask; // $s0 +// line 4619, offset 0x00071608 +/* begin block 1 */ +// Start line: 4620 +// Start offset: 0x00071608 +// Variables: +// int dir; // $s2 +// int num; // $s1 +// int rx; // $v1 +// int rz; // $a0 +// int mask; // $s0 - /* begin block 1.1 */ - // Start line: 4669 - // Start offset: 0x000716C0 - /* end block 1.1 */ - // End offset: 0x0007170C - // End Line: 4681 - /* end block 1 */ - // End offset: 0x000717AC - // End Line: 4734 +/* begin block 1.1 */ +// Start line: 4669 +// Start offset: 0x000716C0 +/* end block 1.1 */ +// End offset: 0x0007170C +// End Line: 4681 +/* end block 1 */ +// End offset: 0x000717AC +// End Line: 4734 - /* begin block 2 */ - // Start line: 10729 - /* end block 2 */ - // End Line: 10730 +/* begin block 2 */ +// Start line: 10729 +/* end block 2 */ +// End Line: 10730 - /* begin block 3 */ - // Start line: 10737 - /* end block 3 */ - // End Line: 10738 +/* begin block 3 */ +// Start line: 10737 +/* end block 3 */ +// End Line: 10738 -// [D] +// [D] [T] int CalcPedestrianDirection(int last_dir, int wx, int wz, VECTOR* target) { - long lVar1; - int iVar2; - uint uVar3; - uint uVar4; - uint uVar5; - - uVar5 = pedestrian_roads.west == -20; - uVar4 = pedestrian_roads.west == -20; + int num; + int rx; + int rz; + int dir; + int mask; + int cnt; + + mask = pedestrian_roads.west == -20; + dir = mask; if (pedestrian_roads.east == -20) { - uVar5 = uVar5 | 2; - uVar4++; + mask |= 2; + dir++; } if (pedestrian_roads.north == -20) { - uVar5 = uVar5 | 4; - uVar4++; + mask |= 4; + dir++; } if (pedestrian_roads.south == -20) { - uVar5 = uVar5 | 8; - uVar4++; + mask |= 8; + dir++; } - uVar3 = uVar5 & last_dir; + num = mask & last_dir; - if ((uVar3 == 0) && (uVar3 = uVar5, 1 < uVar4)) + if (num == 0) { - lVar1 = Random2(0); - uVar3 = 0x10; - - if (uVar4 == 0) - trap(7); - - iVar2 = lVar1 % uVar4 + 1; - - while (iVar2 != 0) + if(dir > 1) { - uVar3 = (int)uVar3 >> 1; - if ((uVar5 & uVar3) != 0) - iVar2--; - } + num = 16; - uVar3 = uVar5 & uVar3; - } + cnt = Random2(0) % dir + 1; - uVar4 = wx & 0xfffffc00; - uVar5 = wz & 0xfffffc00; - - if (uVar3 == 2) - { - iVar2 = uVar4 + 0x600; - } - else - { - if (2 < uVar3) - { - if (uVar3 == 4) + while (cnt != 0) { - iVar2 = uVar5 + 0x600; - } - else - { - iVar2 = uVar5 - 0x200; - if (uVar3 != 8) - goto LAB_0007177c; + num >>= 1; + + if (mask & num) + cnt--; } - target->vx = uVar4 + 0x200; - target->vz = iVar2; - - goto LAB_0007177c; + num = mask & num; + } + else + { + num = mask; } - iVar2 = uVar4 - 0x200; - if (uVar3 != 1) - goto LAB_0007177c; } - target->vx = iVar2; - target->vz = uVar5 + 0x200; -LAB_0007177c: + + rx = wx & 0xfffffc00; + rz = wz & 0xfffffc00; + + if (num == 1) + { + target->vx = rx - 512; + target->vz = rz + 512; + } + else if (num == 2) + { + target->vx = rx + 1536; + target->vz = rz + 512; + } + else if (num == 4) + { + target->vx = rx + 512; + target->vz = rz + 1536; + } + else if (num == 8) + { + target->vx = rx + 512; + target->vz = rz - 512; + } + target->vy = 0; - return uVar3; + + return num; } @@ -4300,33 +4258,33 @@ LAB_0007177c: // decompiled code // original method signature: // int /*$ra*/ IsPavement(int x /*$a0*/, int y /*$a1*/, int z /*$a2*/, struct PEDESTRIAN *pPed /*$s0*/) - // line 4845, offset 0x000725b8 - /* begin block 1 */ - // Start line: 4846 - // Start offset: 0x000725B8 - // Variables: - // struct VECTOR vec; // stack offset -24 - // int r; // $v1 - /* end block 1 */ - // End offset: 0x00072644 - // End Line: 4917 +// line 4845, offset 0x000725b8 +/* begin block 1 */ +// Start line: 4846 +// Start offset: 0x000725B8 +// Variables: +// struct VECTOR vec; // stack offset -24 +// int r; // $v1 +/* end block 1 */ +// End offset: 0x00072644 +// End Line: 4917 - /* begin block 2 */ - // Start line: 18844 - /* end block 2 */ - // End Line: 18845 +/* begin block 2 */ +// Start line: 18844 +/* end block 2 */ +// End Line: 18845 - /* begin block 3 */ - // Start line: 9690 - /* end block 3 */ - // End Line: 9691 +/* begin block 3 */ +// Start line: 9690 +/* end block 3 */ +// End Line: 9691 - /* begin block 4 */ - // Start line: 18854 - /* end block 4 */ - // End Line: 18855 +/* begin block 4 */ +// Start line: 18854 +/* end block 4 */ +// End Line: 18855 -// [D] [A] might be incorrect +// [D] [T] int IsPavement(int x, int y, int z, PEDESTRIAN* pPed) { int r; @@ -4338,10 +4296,9 @@ int IsPavement(int x, int y, int z, PEDESTRIAN* pPed) r = GetSurfaceIndex(&v); if (r == -20) - { return (RoadInCell(&v) != 0); - } - else if (pPed) + + if (pPed) { if (r != -26 && r != -23 && r != -32) return 0; @@ -4357,46 +4314,51 @@ int IsPavement(int x, int y, int z, PEDESTRIAN* pPed) // decompiled code // original method signature: // void /*$ra*/ SetPedestrianTurn(struct PEDESTRIAN *pedestrian /*$a0*/, int turn /*$a1*/) - // line 4924, offset 0x00072500 - /* begin block 1 */ - // Start line: 4925 - // Start offset: 0x00072500 - // Variables: - // int dir; // $a2 - // int speed; // $v1 - /* end block 1 */ - // End offset: 0x00072584 - // End Line: 4935 +// line 4924, offset 0x00072500 +/* begin block 1 */ +// Start line: 4925 +// Start offset: 0x00072500 +// Variables: +// int dir; // $a2 +// int speed; // $v1 +/* end block 1 */ +// End offset: 0x00072584 +// End Line: 4935 - /* begin block 2 */ - // Start line: 15021 - /* end block 2 */ - // End Line: 15022 +/* begin block 2 */ +// Start line: 15021 +/* end block 2 */ +// End Line: 15022 - /* begin block 3 */ - // Start line: 18487 - /* end block 3 */ - // End Line: 18488 +/* begin block 3 */ +// Start line: 18487 +/* end block 3 */ +// End Line: 18488 - /* begin block 4 */ - // Start line: 18488 - /* end block 4 */ - // End Line: 18489 +/* begin block 4 */ +// Start line: 18488 +/* end block 4 */ +// End Line: 18489 -// [D] +// [D] [T] void SetPedestrianTurn(PEDESTRIAN* pedestrian, int turn) { - int uVar6; + int speed; + int dir; - pedestrian->dir.vy = pedestrian->dir.vy + turn & 0xfff; + dir = pedestrian->dir.vy + turn & 0xfff; - uVar6 = uVar6 + 0x800 & 0xfff; + pedestrian->dir.vy = dir; - pedestrian->position.vz = pedestrian->position.vz - pedestrian->velocity.vz; - pedestrian->position.vx = pedestrian->position.vx - pedestrian->velocity.vx; + dir += 0x800 & 0xfff; - pedestrian->velocity.vx = FIXED(pedestrian->speed * rcossin_tbl[uVar6 * 2]); - pedestrian->velocity.vz = FIXED(pedestrian->speed * rcossin_tbl[uVar6 * 2 + 1]); + pedestrian->position.vz -= pedestrian->velocity.vz; + pedestrian->position.vx -= pedestrian->velocity.vx; + + speed = pedestrian->speed; + + pedestrian->velocity.vx = FIXEDH(speed * rcossin_tbl[dir * 2]); + pedestrian->velocity.vz = FIXEDH(speed * rcossin_tbl[dir * 2 + 1]); } @@ -4404,80 +4366,88 @@ void SetPedestrianTurn(PEDESTRIAN* pedestrian, int turn) // decompiled code // original method signature: // struct SEATED_PEDESTRIANS * /*$ra*/ FindSeated() - // line 4943, offset 0x00072644 - /* begin block 1 */ - // Start line: 4945 - // Start offset: 0x00072644 - // Variables: - // struct SEATED_PEDESTRIANS *seatedptr; // $s0 +// line 4943, offset 0x00072644 +/* begin block 1 */ +// Start line: 4945 +// Start offset: 0x00072644 +// Variables: +// struct SEATED_PEDESTRIANS *seatedptr; // $s0 - /* begin block 1.1 */ - // Start line: 4950 - // Start offset: 0x0007266C - // Variables: - // int dx; // $v1 - // int dz; // $v0 - // int distsqr; // $v1 - // int count1; // $a2 - /* end block 1.1 */ - // End offset: 0x00072724 - // End Line: 4975 - /* end block 1 */ - // End offset: 0x00072738 - // End Line: 4977 +/* begin block 1.1 */ +// Start line: 4950 +// Start offset: 0x0007266C +// Variables: +// int dx; // $v1 +// int dz; // $v0 +// int distsqr; // $v1 +// int count1; // $a2 +/* end block 1.1 */ +// End offset: 0x00072724 +// End Line: 4975 +/* end block 1 */ +// End offset: 0x00072738 +// End Line: 4977 - /* begin block 2 */ - // Start line: 19027 - /* end block 2 */ - // End Line: 19028 +/* begin block 2 */ +// Start line: 19027 +/* end block 2 */ +// End Line: 19028 - /* begin block 3 */ - // Start line: 19054 - /* end block 3 */ - // End Line: 19055 +/* begin block 3 */ +// Start line: 19054 +/* end block 3 */ +// End Line: 19055 - /* begin block 4 */ - // Start line: 19055 - /* end block 4 */ - // End Line: 19056 +/* begin block 4 */ +// Start line: 19055 +/* end block 4 */ +// End Line: 19056 /* WARNING: Unknown calling convention yet parameter storage is locked */ -// [D] +// [D] [T] SEATED_PEDESTRIANS* FindSeated(void) { - int iVar1; - int iVar2; - int iVar3; + int dz; + int dx; + int count1; SEATED_PEDESTRIANS* seatedptr; - if (seated_pedestrian) + if (!seated_pedestrian) + return NULL; + + if (seated_pedestrian->rotation == 9999) + return NULL; + + count1 = 3; + + do { - if (seated_pedestrian->rotation == 9999) - return NULL; + seatedptr = seated_pedestrian + seated_count; + seated_count++; - iVar3 = 3; + if (seatedptr->rotation == 9999) + { + seated_count = 0; + seatedptr = seated_pedestrian; + } - do { - seatedptr = seated_pedestrian + seated_count; - seated_count++; + dx = FIXED(seatedptr->x - player[0].pos[0]); + dz = FIXED(seatedptr->z - player[0].pos[2]); - if (seatedptr->rotation == 9999) - { - seated_count = 0; - seatedptr = seated_pedestrian; - } - - if (seatedptr->index == 0 && - (iVar2 = FIXED(seatedptr->x - player[0].pos[0]), iVar1 = FIXED(seatedptr->z - player[0].pos[2]), - iVar3 = iVar3 + -1, (iVar2 * iVar2 + iVar1 * iVar1) - 0xbU < 0x1d)) + if (seatedptr->index == 0) + { + count1--; + + if((dx * dx + dz * dz) - 11U < 29) { add_seated(seatedptr, seated_count); return seatedptr; } + } + + } while (count1 != 0); - } while (iVar3 != 0); - } return NULL; } @@ -4486,73 +4456,72 @@ SEATED_PEDESTRIANS* FindSeated(void) // decompiled code // original method signature: // struct SEATED_PEDESTRIANS * /*$ra*/ FindTannerASeat(struct PEDESTRIAN *pPed /*$t4*/) - // line 4984, offset 0x000717ac - /* begin block 1 */ - // Start line: 4985 - // Start offset: 0x000717AC - // Variables: - // struct SEATED_PEDESTRIANS *seatedptr; // $a2 - // struct SEATED_PEDESTRIANS *theOne; // $t1 - // int dx; // $a0 - // int dz; // $v1 - // int distsqr; // $v0 - // int bestSqr; // $t2 - /* end block 1 */ - // End offset: 0x000718C8 - // End Line: 5023 +// line 4984, offset 0x000717ac +/* begin block 1 */ +// Start line: 4985 +// Start offset: 0x000717AC +// Variables: +// struct SEATED_PEDESTRIANS *seatedptr; // $a2 +// struct SEATED_PEDESTRIANS *theOne; // $t1 +// int dx; // $a0 +// int dz; // $v1 +// int distsqr; // $v0 +// int bestSqr; // $t2 +/* end block 1 */ +// End offset: 0x000718C8 +// End Line: 5023 - /* begin block 2 */ - // Start line: 11491 - /* end block 2 */ - // End Line: 11492 +/* begin block 2 */ +// Start line: 11491 +/* end block 2 */ +// End Line: 11492 - /* begin block 3 */ - // Start line: 11493 - /* end block 3 */ - // End Line: 11494 +/* begin block 3 */ +// Start line: 11493 +/* end block 3 */ +// End Line: 11494 -// [D] +// [D] [T] SEATED_PEDESTRIANS* FindTannerASeat(PEDESTRIAN* pPed) { - int iVar1; - int iVar2; + int dx, dz; + int distSqr; + int bestSqr; SEATED_PEDESTRIANS* seatedptr; SEATED_PEDESTRIANS* theOne; - int iVar5; - + theOne = NULL; - iVar5 = 0x1000; + bestSqr = 4096; seated_count = 0; if (seated_pedestrian->rotation != 9999) { seatedptr = seated_pedestrian; seated_count = 0; - iVar1 = 0; - do { - iVar1 = seatedptr->x - pPed->position.vx; + + do + { + dx = ABS(seatedptr->x - pPed->position.vx); + dz = ABS(seatedptr->z - pPed->position.vz); + seated_count++; - if (iVar1 < 0) - iVar1 = pPed->position.vx - seatedptr->x; - - iVar2 = seatedptr->z - pPed->position.vz; - - if (iVar2 < 0) - iVar2 = pPed->position.vz - seatedptr->z; - - if (((iVar1 < 900) && (iVar2 < 900)) && - (iVar1 = FIXED(iVar1 * iVar1 + iVar2 * iVar2), iVar1 < iVar5)) + if (dx < 900 && dz < 900) { - theOne = seatedptr; - iVar5 = iVar1; + distSqr = FIXED(dx * dx + dz * dz); + + if(distSqr < bestSqr) + { + theOne = seatedptr; + bestSqr = distSqr; + } } seatedptr++; } while (seatedptr->rotation != 9999); } - if (iVar5 < 6 && theOne) + if (bestSqr < 6 && theOne) { pPed->dir.vy = theOne->rotation; pPed->position.vx = theOne->x; @@ -4569,38 +4538,37 @@ SEATED_PEDESTRIANS* FindTannerASeat(PEDESTRIAN* pPed) // decompiled code // original method signature: // void /*$ra*/ add_seated(struct SEATED_PEDESTRIANS *seatedptr /*$s0*/, int seat_index /*$s2*/) - // line 5031, offset 0x000718c8 - /* begin block 1 */ - // Start line: 5032 - // Start offset: 0x000718C8 - // Variables: - // struct PEDESTRIAN *pedestrian; // $s1 - // int index; // $v0 - /* end block 1 */ - // End offset: 0x00071A44 - // End Line: 5076 +// line 5031, offset 0x000718c8 +/* begin block 1 */ +// Start line: 5032 +// Start offset: 0x000718C8 +// Variables: +// struct PEDESTRIAN *pedestrian; // $s1 +// int index; // $v0 +/* end block 1 */ +// End offset: 0x00071A44 +// End Line: 5076 - /* begin block 2 */ - // Start line: 11581 - /* end block 2 */ - // End Line: 11582 +/* begin block 2 */ +// Start line: 11581 +/* end block 2 */ +// End Line: 11582 - /* begin block 3 */ - // Start line: 11590 - /* end block 3 */ - // End Line: 11591 +/* begin block 3 */ +// Start line: 11590 +/* end block 3 */ +// End Line: 11591 - /* begin block 4 */ - // Start line: 11596 - /* end block 4 */ - // End Line: 11597 +/* begin block 4 */ +// Start line: 11596 +/* end block 4 */ +// End Line: 11597 -// [D] +// [D] [T] void add_seated(SEATED_PEDESTRIANS* seatedptr, int seat_index) { PEDESTRIAN* pedptr; - long lVar3; - long lVar4; + long rnd; if (num_pedestrians < 20) { @@ -4610,6 +4578,7 @@ void add_seated(SEATED_PEDESTRIANS* seatedptr, int seat_index) return; seatedptr->index = 2; + pedptr->type = PED_ACTION_CIVSIT; pedptr->speed = 0; pedptr->velocity.vx = 0; @@ -4619,21 +4588,22 @@ void add_seated(SEATED_PEDESTRIANS* seatedptr, int seat_index) pedptr->position.vx = seatedptr->x; pedptr->position.vz = seatedptr->z; pedptr->position.vy = player[0].pos[1]; + pedptr->position.vy = -75 - MapHeight((VECTOR*)&pedptr->position); + pedptr->index = 1; - pedptr->seat_index = (char)seat_index; + pedptr->seat_index = seat_index; pedptr->pedType = CIVILIAN; + SetupPedestrian(pedptr); pedptr->fpAgitatedState = NULL; pedptr->fpRestState = CivPedSit; - lVar3 = Random2(0); - lVar4 = Random2(0); - pedptr->pallet = lVar3 + (lVar3 / 5) * -5 + (lVar4 + (lVar4 / 5) * -5) * 16; - lVar3 = Random2(0); + pedptr->pallet = (Random2(0) % 5) + (Random2(0) % 5) * 16; + rnd = Random2(0); - if ((lVar3 / 6) * 6 == lVar3 - 3) + if ((rnd / 6) * 6 == rnd - 3) pedptr->flags |= 0x4000; } } @@ -4643,21 +4613,21 @@ void add_seated(SEATED_PEDESTRIANS* seatedptr, int seat_index) // decompiled code // original method signature: // void /*$ra*/ set_coll_box(int index /*$t2*/, struct _CAR_DATA *cp /*$t0*/, int offset /*$t3*/) - // line 5084, offset 0x00071a5c - /* begin block 1 */ - // Start line: 5085 - // Start offset: 0x00071A5C - // Variables: - // struct VECTOR BoxCentre; // stack offset -16 - // int boxsize; // $t1 - /* end block 1 */ - // End offset: 0x00071B74 - // End Line: 5110 +// line 5084, offset 0x00071a5c +/* begin block 1 */ +// Start line: 5085 +// Start offset: 0x00071A5C +// Variables: +// struct VECTOR BoxCentre; // stack offset -16 +// int boxsize; // $t1 +/* end block 1 */ +// End offset: 0x00071B74 +// End Line: 5110 - /* begin block 2 */ - // Start line: 11714 - /* end block 2 */ - // End Line: 11715 +/* begin block 2 */ +// Start line: 11714 +/* end block 2 */ +// End Line: 11715 CAR_COLLISION_BOX collision_box[8]; _CAR_DATA* collision_car_ptr[8]; @@ -4665,45 +4635,38 @@ _CAR_DATA* collision_car_ptr[8]; // [D] void set_coll_box(int index, _CAR_DATA* cp, int offset) { - int iVar1; - int iVar2; - int iVar3; - int iVar4; - int iVar5; + int isPlayerCar; + int boxSize; + VECTOR BoxCentre; - if (8 < index) + if (index >= 8) return; - iVar5 = 400; + boxSize = 400; - if (player[0].horn.on != 0) + isPlayerCar = (cp == &car_data[player[0].playerCarId]); + + if (player[0].horn.on) { - iVar5 = 260; - - if (cp != &car_data[player[0].playerCarId]) - goto LAB_00071b00; - - iVar5 = 1200; + if (isPlayerCar) + boxSize = 1200; + else + boxSize = 260; } - if (cp != car_data + player[0].playerCarId) - iVar5 = iVar5 - 140; - -LAB_00071b00: - iVar1 = cp->st.n.linearVelocity[0]; - iVar2 = cp->hd.where.t[0]; - iVar4 = cp->st.n.linearVelocity[2]; - iVar3 = cp->hd.where.t[2]; + if (!isPlayerCar) + boxSize -= 140; collision_car_ptr[index] = cp; - iVar2 = iVar2 + (iVar1 >> (offset & 0x1fU)); - iVar3 = iVar3 + (iVar4 >> (offset & 0x1fU)); - collision_box[index].min_x = iVar2 - iVar5; - collision_box[index].min_z = iVar3 - iVar5; - collision_box[index].max_x = iVar2 + iVar5; - collision_box[index].max_z = iVar3 + iVar5; + BoxCentre.vx = cp->hd.where.t[0] + (cp->st.n.linearVelocity[0] >> (offset & 0x1fU)); + BoxCentre.vz = cp->hd.where.t[2] + (cp->st.n.linearVelocity[2] >> (offset & 0x1fU)); + + collision_box[index].min_x = BoxCentre.vx - boxSize; + collision_box[index].min_z = BoxCentre.vz - boxSize; + collision_box[index].max_x = BoxCentre.vx + boxSize; + collision_box[index].max_z = BoxCentre.vz + boxSize; } @@ -4711,42 +4674,42 @@ LAB_00071b00: // decompiled code // original method signature: // void /*$ra*/ BuildCarCollisionBox() - // line 5118, offset 0x00071b7c - /* begin block 1 */ - // Start line: 5120 - // Start offset: 0x00071B7C - // Variables: - // struct _CAR_DATA *cp; // $s3 - // int count1; // $s4 - // int i; // $t1 +// line 5118, offset 0x00071b7c +/* begin block 1 */ +// Start line: 5120 +// Start offset: 0x00071B7C +// Variables: +// struct _CAR_DATA *cp; // $s3 +// int count1; // $s4 +// int i; // $t1 - /* begin block 1.1 */ - // Start line: 5146 - // Start offset: 0x00071CBC - // Variables: - // int x; // $a0 - // int z; // $a2 - /* end block 1.1 */ - // End offset: 0x00071D58 - // End Line: 5155 - /* end block 1 */ - // End offset: 0x00071E0C - // End Line: 5171 +/* begin block 1.1 */ +// Start line: 5146 +// Start offset: 0x00071CBC +// Variables: +// int x; // $a0 +// int z; // $a2 +/* end block 1.1 */ +// End offset: 0x00071D58 +// End Line: 5155 +/* end block 1 */ +// End offset: 0x00071E0C +// End Line: 5171 - /* begin block 2 */ - // Start line: 11805 - /* end block 2 */ - // End Line: 11806 +/* begin block 2 */ +// Start line: 11805 +/* end block 2 */ +// End Line: 11806 - /* begin block 3 */ - // Start line: 11806 - /* end block 3 */ - // End Line: 11807 +/* begin block 3 */ +// Start line: 11806 +/* end block 3 */ +// End Line: 11807 - /* begin block 4 */ - // Start line: 11808 - /* end block 4 */ - // End Line: 11809 +/* begin block 4 */ +// Start line: 11808 +/* end block 4 */ +// End Line: 11809 /* WARNING: Unknown calling convention yet parameter storage is locked */ @@ -4755,77 +4718,72 @@ CAR_COLLISION_BOX tanner_collision_box; int num_extra_boxes_set; int collision_boxes_set; -// [D] +// [D] [T] void BuildCarCollisionBox(void) { - CAR_COLLISION_BOX* pCVar1; - CAR_COLLISION_BOX* pCVar2; - uint uVar3; - int iVar4; + CAR_COLLISION_BOX* cbox; + int dir; + int vx, vz; int index; - _ExOBJECT* p_Var5; + _ExOBJECT* expl; _CAR_DATA* cp; - iVar4 = (int)player[0].playerCarId; - - if (iVar4 != -1) // [A] ASan bug fix + if (player[0].playerCarId != -1) // [A] ASan bug fix { - set_coll_box(0, car_data + iVar4, 8); - set_coll_box(1, car_data + iVar4, 9); + set_coll_box(0, &car_data[player[0].playerCarId], 8); + set_coll_box(1, &car_data[player[0].playerCarId], 9); } - iVar4 = 2; cp = car_data + (CameraCnt & 3); - index = iVar4; - if (cp < car_data + 20) + collision_boxes_set = 2; + + while (cp < car_data + MAX_CARS) { - do { - iVar4 = index; + if (cp != &car_data[player[0].playerCarId] && cp->controlType != CONTROL_TYPE_NONE) + { + set_coll_box(collision_boxes_set, cp, 8); + collision_boxes_set++; + } - if (cp != &car_data[player[0].playerCarId] && cp->controlType != CONTROL_TYPE_NONE) - { - iVar4 = index + 1; - set_coll_box(index, cp, 8); - } - - cp = cp + 4; // [A] WTF? - index = iVar4; - } while (cp < car_data + 20); + cp += 4; // [A] WTF? } if (player[0].playerType == 2) { - uVar3 = (int)player[0].pPed->dir.vy - 0x800U & 0xfff; + dir = player[0].pPed->dir.vy - 0x800U & 0xfff; - index = FIXED(player[0].pPed->speed * (int)rcossin_tbl[uVar3 * 2] * 4); - tanner_collision_box.min_x = ((player[0].pPed)->position).vx + index + -148; - tanner_collision_box.max_x = ((player[0].pPed)->position).vx + index + 148; - - index = FIXED(player[0].pPed->speed * (int)rcossin_tbl[uVar3 * 2 + 1] * 4); - tanner_collision_box.min_z = ((player[0].pPed)->position).vz + index + -148; - tanner_collision_box.max_z = ((player[0].pPed)->position).vz + index + 148; + vx = FIXED(player[0].pPed->speed * rcossin_tbl[dir * 2] * 4); + vz = FIXED(player[0].pPed->speed * rcossin_tbl[dir * 2 + 1] * 4); + + tanner_collision_box.min_x = player[0].pPed->position.vx + vx - 148; + tanner_collision_box.max_x = player[0].pPed->position.vx + vx + 148; + tanner_collision_box.min_z = player[0].pPed->position.vz + vz - 148; + tanner_collision_box.max_z = player[0].pPed->position.vz + vz + 148; } num_extra_boxes_set = 0; - p_Var5 = explosion; + expl = explosion; + index = 4; - collision_boxes_set = iVar4; - do { - if (0x7ff < p_Var5->time) { - iVar4 = (p_Var5->pos).vx; - extra_collision_boxes[num_extra_boxes_set].min_x = iVar4 - 1952; - extra_collision_boxes[num_extra_boxes_set].max_x = iVar4 + 1952; - pCVar1 = extra_collision_boxes + num_extra_boxes_set; - pCVar2 = extra_collision_boxes + num_extra_boxes_set; - iVar4 = (p_Var5->pos).vz; - num_extra_boxes_set = num_extra_boxes_set + 1; - pCVar1->min_z = iVar4 - 1952; - pCVar2->max_z = iVar4 + 1952; + do + { + if (expl->time >= 2048) + { + cbox = extra_collision_boxes + num_extra_boxes_set; + + cbox->min_x = expl->pos.vx - 1952; + cbox->max_x = expl->pos.vx + 1952; + + cbox->min_z = expl->pos.vz - 1952; + cbox->max_z = expl->pos.vz + 1952; + + num_extra_boxes_set++; } - index = index + -1; - p_Var5 = p_Var5 + 1; - } while (-1 < index); + + index--; + expl++; + } while (index > -1); } @@ -4833,84 +4791,79 @@ void BuildCarCollisionBox(void) // decompiled code // original method signature: // struct _CAR_DATA * /*$ra*/ CheckForCar(struct PEDESTRIAN *pedestrian /*$s3*/) - // line 5178, offset 0x00072738 - /* begin block 1 */ - // Start line: 5179 - // Start offset: 0x00072738 - // Variables: - // int count; // $s0 +// line 5178, offset 0x00072738 +/* begin block 1 */ +// Start line: 5179 +// Start offset: 0x00072738 +// Variables: +// int count; // $s0 - /* begin block 1.1 */ - // Start line: 5183 - // Start offset: 0x00072770 - /* end block 1.1 */ - // End offset: 0x00072790 - // End Line: 5204 +/* begin block 1.1 */ +// Start line: 5183 +// Start offset: 0x00072770 +/* end block 1.1 */ +// End offset: 0x00072790 +// End Line: 5204 - /* begin block 1.2 */ - // Start line: 5206 - // Start offset: 0x000727B4 - /* end block 1.2 */ - // End offset: 0x000727B4 - // End Line: 5213 +/* begin block 1.2 */ +// Start line: 5206 +// Start offset: 0x000727B4 +/* end block 1.2 */ +// End offset: 0x000727B4 +// End Line: 5213 - /* begin block 1.3 */ - // Start line: 5217 - // Start offset: 0x00072800 - /* end block 1.3 */ - // End offset: 0x0007281C - // End Line: 5221 - /* end block 1 */ - // End offset: 0x0007283C - // End Line: 5223 +/* begin block 1.3 */ +// Start line: 5217 +// Start offset: 0x00072800 +/* end block 1.3 */ +// End offset: 0x0007281C +// End Line: 5221 +/* end block 1 */ +// End offset: 0x0007283C +// End Line: 5223 - /* begin block 2 */ - // Start line: 19327 - /* end block 2 */ - // End Line: 19328 +/* begin block 2 */ +// Start line: 19327 +/* end block 2 */ +// End Line: 19328 - /* begin block 3 */ - // Start line: 19529 - /* end block 3 */ - // End Line: 19530 +/* begin block 3 */ +// Start line: 19529 +/* end block 3 */ +// End Line: 19530 - /* begin block 4 */ - // Start line: 19531 - /* end block 4 */ - // End Line: 19532 +/* begin block 4 */ +// Start line: 19531 +/* end block 4 */ +// End Line: 19532 -// [D] +// [D] [T] _CAR_DATA* CheckForCar(PEDESTRIAN* pedestrian) { - int iVar1; - int iVar3; - CAR_COLLISION_BOX* cb; - _CAR_DATA** pp_Var4; + int count; - iVar3 = 0; - if (0 < collision_boxes_set) + count = 0; + + while (count < collision_boxes_set) { - pp_Var4 = collision_car_ptr; - cb = collision_box; - do { - iVar3++; + if (CheckForPlayerCar(pedestrian, &collision_box[count]) != 0) + return collision_car_ptr[count]; - if (CheckForPlayerCar(pedestrian, cb) != 0) - return *pp_Var4; - - pp_Var4++; - cb++; - } while (iVar3 < collision_boxes_set); - } - iVar3 = 0; - - while ((iVar1 = bAvoidBomb, iVar3 < num_extra_boxes_set && - (iVar1 = iVar3, CheckForPlayerCar(pedestrian, extra_collision_boxes + iVar3) == 0))) - { - iVar3++; + count++; + } + + count = 0; + while (count < num_extra_boxes_set) + { + if (CheckForPlayerCar(pedestrian, &extra_collision_boxes[count])) + { + bAvoidBomb = count; + break; + } + + count++; } - bAvoidBomb = iVar1; if (player[0].playerType == 2 && CheckForPlayerCar(pedestrian, &tanner_collision_box) != 0) bAvoidTanner = 1; @@ -4923,30 +4876,28 @@ _CAR_DATA* CheckForCar(PEDESTRIAN* pedestrian) // decompiled code // original method signature: // int /*$ra*/ CheckForPlayerCar(struct PEDESTRIAN *pedestrian /*$a0*/, struct CAR_COLLISION_BOX *collision_box /*$a1*/) - // line 5231, offset 0x000732c0 - /* begin block 1 */ - // Start line: 26722 - /* end block 1 */ - // End Line: 26723 +// line 5231, offset 0x000732c0 +/* begin block 1 */ +// Start line: 26722 +/* end block 1 */ +// End Line: 26723 - /* begin block 2 */ - // Start line: 26723 - /* end block 2 */ - // End Line: 26724 +/* begin block 2 */ +// Start line: 26723 +/* end block 2 */ +// End Line: 26724 -// [D] +// [D] [T] int CheckForPlayerCar(PEDESTRIAN* pedestrian, CAR_COLLISION_BOX* collision_box) { - int iVar1; - - iVar1 = (pedestrian->position).vx; - if ((collision_box->min_x <= iVar1) && (iVar1 <= collision_box->max_x)) { - iVar1 = (pedestrian->position).vz; - if (collision_box->min_z <= iVar1) { - return (uint)(collision_box->max_z < iVar1) ^ 1; - } - return 0; + if (pedestrian->position.vx >= collision_box->min_x && + pedestrian->position.vx <= collision_box->max_x && + pedestrian->position.vz >= collision_box->min_z && + pedestrian->position.vz <= collision_box->max_z) + { + return 1; } + return 0; } @@ -4955,38 +4906,38 @@ int CheckForPlayerCar(PEDESTRIAN* pedestrian, CAR_COLLISION_BOX* collision_box) // decompiled code // original method signature: // void /*$ra*/ CalculatePedestrianInterest(struct PEDESTRIAN *pPed /*$s0*/) - // line 5249, offset 0x00071e0c - /* begin block 1 */ - // Start line: 5250 - // Start offset: 0x00071E0C - // Variables: - // int interest; // $a2 - // int dist; // $v1 - // struct _CAR_DATA *pCar; // $a2 - // struct VECTOR v1; // stack offset -40 - // struct VECTOR v2; // stack offset -24 - /* end block 1 */ - // End offset: 0x00071F44 - // End Line: 5318 +// line 5249, offset 0x00071e0c +/* begin block 1 */ +// Start line: 5250 +// Start offset: 0x00071E0C +// Variables: +// int interest; // $a2 +// int dist; // $v1 +// struct _CAR_DATA *pCar; // $a2 +// struct VECTOR v1; // stack offset -40 +// struct VECTOR v2; // stack offset -24 +/* end block 1 */ +// End offset: 0x00071F44 +// End Line: 5318 - /* begin block 2 */ - // Start line: 12043 - /* end block 2 */ - // End Line: 12044 +/* begin block 2 */ +// Start line: 12043 +/* end block 2 */ +// End Line: 12044 - /* begin block 3 */ - // Start line: 12122 - /* end block 3 */ - // End Line: 12123 +/* begin block 3 */ +// Start line: 12122 +/* end block 3 */ +// End Line: 12123 - /* begin block 4 */ - // Start line: 12128 - /* end block 4 */ - // End Line: 12129 +/* begin block 4 */ +// Start line: 12128 +/* end block 4 */ +// End Line: 12129 int basic_car_interest; -// [D] +// [D] [T] void CalculatePedestrianInterest(PEDESTRIAN* pPed) { _CAR_DATA* pCar; @@ -5040,31 +4991,32 @@ void CalculatePedestrianInterest(PEDESTRIAN* pPed) // decompiled code // original method signature: // int /*$ra*/ PedSurfaceType(struct VECTOR *ped_pos /*$a0*/) - // line 5325, offset 0x00072584 - /* begin block 1 */ - // Start line: 5330 - // Start offset: 0x00072584 - // Variables: - // struct _sdPlane *sfc_ptr; // $v0 - /* end block 1 */ - // End offset: 0x000725B8 - // End Line: 5335 +// line 5325, offset 0x00072584 +/* begin block 1 */ +// Start line: 5330 +// Start offset: 0x00072584 +// Variables: +// struct _sdPlane *sfc_ptr; // $v0 +/* end block 1 */ +// End offset: 0x000725B8 +// End Line: 5335 - /* begin block 2 */ - // Start line: 18922 - /* end block 2 */ - // End Line: 18923 +/* begin block 2 */ +// Start line: 18922 +/* end block 2 */ +// End Line: 18923 - /* begin block 3 */ - // Start line: 19313 - /* end block 3 */ - // End Line: 19314 +/* begin block 3 */ +// Start line: 19313 +/* end block 3 */ +// End Line: 19314 - /* begin block 4 */ - // Start line: 19317 - /* end block 4 */ - // End Line: 19318 +/* begin block 4 */ +// Start line: 19317 +/* end block 4 */ +// End Line: 19318 +// [D] [T] int PedSurfaceType(VECTOR* ped_pos) { _sdPlane* sfc_ptr; @@ -5081,22 +5033,23 @@ int PedSurfaceType(VECTOR* ped_pos) // decompiled code // original method signature: // void /*$ra*/ ProcessChairLump(char *lump_file /*$a0*/, int lump_size /*$a1*/) - // line 5344, offset 0x00073328 - /* begin block 1 */ - // Start line: 26847 - /* end block 1 */ - // End Line: 26848 +// line 5344, offset 0x00073328 +/* begin block 1 */ +// Start line: 26847 +/* end block 1 */ +// End Line: 26848 - /* begin block 2 */ - // Start line: 26951 - /* end block 2 */ - // End Line: 26952 +/* begin block 2 */ +// Start line: 26951 +/* end block 2 */ +// End Line: 26952 - /* begin block 3 */ - // Start line: 26952 - /* end block 3 */ - // End Line: 26953 +/* begin block 3 */ +// Start line: 26952 +/* end block 3 */ +// End Line: 26953 +// [D] [T] void ProcessChairLump(char* lump_file, int lump_size) { seated_pedestrian = (SEATED_PEDESTRIANS*)lump_file; From 8a311ac9e068e6f909241b83dbc1abf10cf7d48f Mon Sep 17 00:00:00 2001 From: Ilya Shurumov Date: Sun, 11 Oct 2020 20:02:13 +0600 Subject: [PATCH 27/41] - refactor PLAYERS.C --- src_rebuild/GAME/C/PLAYERS.C | 156 +++++++++++++++-------------------- 1 file changed, 66 insertions(+), 90 deletions(-) diff --git a/src_rebuild/GAME/C/PLAYERS.C b/src_rebuild/GAME/C/PLAYERS.C index b253091b..b585688b 100644 --- a/src_rebuild/GAME/C/PLAYERS.C +++ b/src_rebuild/GAME/C/PLAYERS.C @@ -37,7 +37,7 @@ PEDESTRIAN *pPlayerPed = NULL; _PLAYER player[8]; -// [D] +// [D] [T] void InitPlayer(_PLAYER *locPlayer, _CAR_DATA *cp, char carCtrlType, int direction, long(*startPos)[4], int externModel, int palette, char *padid) { int model; @@ -63,7 +63,8 @@ void InitPlayer(_PLAYER *locPlayer, _CAR_DATA *cp, char carCtrlType, int directi InitCar(cp, direction, startPos, carCtrlType, model, palette & 0xff, &locPlayer->padid); - cp->controlFlags |= 4; + cp->controlFlags |= CONTROL_FLAG_WAS_PARKED; + locPlayer->worldCentreCarId = cp->id; locPlayer->cameraView = 0;// (NumPlayers == 2) << 1; // [A] locPlayer->playerCarId = cp->id; @@ -71,6 +72,7 @@ void InitPlayer(_PLAYER *locPlayer, _CAR_DATA *cp, char carCtrlType, int directi locPlayer->spoolXZ = (VECTOR *)cp->hd.where.t; locPlayer->cameraCarId = cp->id; locPlayer->car_is_sounding = 0; + locPlayer->pos[1] = cp->hd.where.t[1]; } else @@ -82,6 +84,7 @@ void InitPlayer(_PLAYER *locPlayer, _CAR_DATA *cp, char carCtrlType, int directi locPlayer->playerCarId = -1; locPlayer->car_is_sounding = 2; locPlayer->cameraView = 0; + locPlayer->pos[1] = -pPlayerPed->position.vy; } @@ -122,7 +125,7 @@ void InitPlayer(_PLAYER *locPlayer, _CAR_DATA *cp, char carCtrlType, int directi /* end block 2 */ // End Line: 261 -// [D] +// [D] [T] void ChangeCarPlayerToPed(int playerID) { _CAR_DATA *lcp = &car_data[player[playerID].playerCarId]; @@ -205,25 +208,29 @@ void ChangeCarPlayerToPed(int playerID) extern int lastCarCameraView; +// [D] [T] void ChangePedPlayerToCar(int playerID, _CAR_DATA *newCar) { - bool bVar1; - char cVar2; - char bVar3; - bool bVar4; - uint uVar5; + int carParked; + int siren; int channel; - uint uVar6; - int channel_00; + int carSampleId; - _PLAYER *lPlayer = &player[playerID]; + _PLAYER* lPlayer; - bVar4 = false; - uVar5 = CarHasSiren(newCar->ap.model); + lPlayer = &player[playerID]; - if (((newCar->controlType != CONTROL_TYPE_CIV_AI && newCar->controlType != CONTROL_TYPE_CUTSCENE) || newCar->ai.c.thrustState != 3) || (newCar->ai.c.ctrlState != 7 && newCar->ai.c.ctrlState != 5)) + siren = CarHasSiren(newCar->ap.model); + + if (newCar->controlType == CONTROL_TYPE_CIV_AI && + newCar->ai.c.thrustState == 3 && (newCar->ai.c.ctrlState == 7 || newCar->ai.c.ctrlState == 5) || + newCar->controlType == CONTROL_TYPE_CUTSCENE) { - bVar4 = true; + carParked = 1; + } + else + { + carParked = 0; } lPlayer->playerType = 1; @@ -232,38 +239,32 @@ void ChangePedPlayerToCar(int playerID, _CAR_DATA *newCar) if (gInGameCutsceneActive == 0 && gInGameChaseActive == 0) { - cVar2 = newCar->id; lPlayer->spoolXZ = (VECTOR *)newCar->hd.where.t; - lPlayer->worldCentreCarId = cVar2; + lPlayer->worldCentreCarId = newCar->id; } lPlayer->cameraView = lastCarCameraView; - channel = 0x1000; - if (NoPlayerControl == 0) - { - channel = newCar->hd.direction + 0x600; - } + if (NoPlayerControl == 0) + lPlayer->cameraAngle = newCar->hd.direction + 1536; + else + lPlayer->cameraAngle = 4096; - lPlayer->cameraAngle = channel; lPlayer->headPos = 0; lPlayer->headTarget = 0; lPlayer->headTimer = 0; - //lPlayer->padid = 0; lPlayer->pPed = NULL; - - { - newCar->controlType = CONTROL_TYPE_PLAYER; - newCar->ai.padid = &lPlayer->padid; - newCar->hndType = 0; - if (playerID == 0) + newCar->controlType = CONTROL_TYPE_PLAYER; + newCar->ai.padid = &lPlayer->padid; + newCar->hndType = 0; + + if (playerID == 0) + { + if (gCurrentMissionNumber != 32 && MissionHeader->residentModels[newCar->ap.model] == 0) { - if (gCurrentMissionNumber != 32 && MissionHeader->residentModels[newCar->ap.model] == 0) - { - NoteFelony(&felonyData, 11, 4096); - } + NoteFelony(&felonyData, 11, 4096); } } @@ -274,61 +275,32 @@ void ChangePedPlayerToCar(int playerID, _CAR_DATA *newCar) // door close sound Start3DSoundVolPitch(-1, 6, 3, newCar->hd.where.t[0], newCar->hd.where.t[1], newCar->hd.where.t[2], 0, 0x1000); - bVar3 = newCar->ap.model; - if (bVar3 == 4) - uVar6 = ResidentModelsBodge(); - else if (bVar3 < 3) - uVar6 = newCar->ap.model; + if (newCar->ap.model == 4) + carSampleId = ResidentModelsBodge(); + else if (newCar->ap.model < 3) + carSampleId = newCar->ap.model; else - uVar6 = newCar->ap.model - 1; + carSampleId = newCar->ap.model - 1; - channel = 1; - if (playerID != 0) - channel = 4; + // start idle sound + channel = playerID == 0 ? 1 : 4; + Start3DSoundVolPitch(channel, 3, carSampleId * 3 + 1, newCar->hd.where.t[0], newCar->hd.where.t[1], newCar->hd.where.t[2], -10000, 0x1000); - // idle sound - Start3DSoundVolPitch(channel, 3, uVar6 * 3 + 1, newCar->hd.where.t[0], newCar->hd.where.t[1], newCar->hd.where.t[2], -10000, 0x1000); - bVar3 = newCar->ap.model; + // rev sound + channel = playerID == 0 ? 0 : 3; + Start3DSoundVolPitch(channel, 3, carSampleId * 3, newCar->hd.where.t[0], newCar->hd.where.t[1], newCar->hd.where.t[2], -10000, 0x1000); - if (bVar3 == 4) + if (siren != 0) { - channel_00 = ResidentModelsBodge(); - channel = channel_00 << 1; - } - else { - if (bVar3 < 3) - { - channel = newCar->ap.model * 3; - goto LAB_000737d4; - } - - channel_00 = newCar->ap.model - 1; - channel = channel_00 * 2; + channel = playerID == 0 ? 2 : 5; + Start3DSoundVolPitch(channel, (siren & 0xff00) >> 8, siren & 0xff, newCar->hd.where.t[0], newCar->hd.where.t[1], newCar->hd.where.t[2], -10000, 129); } - channel = channel + channel_00; - -LAB_000737d4: - channel_00 = 0; - if (playerID != 0) - channel_00 = 3; - - Start3DSoundVolPitch(channel_00, 3, channel, newCar->hd.where.t[0], newCar->hd.where.t[1], newCar->hd.where.t[2], -10000, 0x1000); - if (uVar5 != 0) - { - channel = 2; - - if (playerID != 0) - channel = 5; - - Start3DSoundVolPitch(channel, (uVar5 & 0xff00) >> 8, uVar5 & 0xff, newCar->hd.where.t[0], newCar->hd.where.t[1], newCar->hd.where.t[2], -10000, 0x81); - } - - if (bVar4) - HaveCarSoundStraightAway(playerID); - else + if (carParked) RequestSlightPauseBeforeCarSoundStarts(playerID); + else + HaveCarSoundStraightAway(playerID); } @@ -369,18 +341,18 @@ LAB_000737d4: /* WARNING: Unknown calling convention yet parameter storage is locked */ -// [D] +// [D] [T] void UpdatePlayers(void) { int carId; PEDESTRIAN *ped; _PLAYER *locPlayer; + _CAR_DATA* cp; pedestrianFelony = 0; locPlayer = player; - // [A] cycle might be wrong do { if (gInGameCutsceneActive == 0) locPlayer->playerType = (locPlayer->pPed != NULL) ? 2 : 1; @@ -389,19 +361,23 @@ void UpdatePlayers(void) { carId = locPlayer->playerCarId; - locPlayer->spoolXZ = (VECTOR *)car_data[locPlayer->worldCentreCarId].hd.where.t; + if(locPlayer->worldCentreCarId >= 0) + locPlayer->spoolXZ = (VECTOR *)car_data[locPlayer->worldCentreCarId].hd.where.t; if (carId >= 0) { - locPlayer->pos[0] = car_data[carId].hd.where.t[0]; - locPlayer->pos[1] = car_data[carId].hd.where.t[1]; - locPlayer->pos[2] = car_data[carId].hd.where.t[2]; - locPlayer->dir = car_data[carId].hd.direction; + cp = &car_data[carId]; + + locPlayer->pos[0] = cp->hd.where.t[0]; + locPlayer->pos[1] = cp->hd.where.t[1]; + locPlayer->pos[2] = cp->hd.where.t[2]; + locPlayer->dir = cp->hd.direction; } } else if (locPlayer->playerType == 2) { ped = locPlayer->pPed; + locPlayer->pos[0] = ped->position.vx; locPlayer->pos[1] = -ped->position.vy; locPlayer->pos[2] = ped->position.vz; @@ -428,7 +404,7 @@ void UpdatePlayers(void) /* end block 2 */ // End Line: 944 -// [D] +// [D] [T] void RequestSlightPauseBeforeCarSoundStarts(char player_id) { player[player_id].car_is_sounding = 2; @@ -448,7 +424,7 @@ void RequestSlightPauseBeforeCarSoundStarts(char player_id) /* end block 1 */ // End Line: 961 -// [D] +// [D] [T] void HaveCarSoundStraightAway(char player_id) { player[player_id].car_is_sounding = 0; @@ -466,7 +442,7 @@ void HaveCarSoundStraightAway(char player_id) /* end block 1 */ // End Line: 972 -// [D] +// [D] [T] void MakeTheCarShutUp(char player_id) { player[player_id].car_is_sounding = 1; From c01bfb24cb47c32274720c4b8a1c800a5ef1d185 Mon Sep 17 00:00:00 2001 From: Ilya Shurumov Date: Sun, 11 Oct 2020 22:14:20 +0600 Subject: [PATCH 28/41] - refactor MAIN.C --- src_rebuild/GAME/C/MAIN.C | 1768 ++++++++++++++++++------------------- 1 file changed, 835 insertions(+), 933 deletions(-) diff --git a/src_rebuild/GAME/C/MAIN.C b/src_rebuild/GAME/C/MAIN.C index bf7570b7..2acb4fd9 100644 --- a/src_rebuild/GAME/C/MAIN.C +++ b/src_rebuild/GAME/C/MAIN.C @@ -89,41 +89,41 @@ XZPAIR gStartPos = { 0 }; enum LevLumpType { // known lumps indexes - LUMP_MODELS = 1, // level models - LUMP_MAP = 2, // map info + LUMP_MODELS = 1, // level models + LUMP_MAP = 2, // map info - LUMP_TEXTURENAMES = 5, // texture name strings + LUMP_TEXTURENAMES = 5, // texture name strings - LUMP_ROADMAP = 7, // unused lump in Driver 2 - LUMP_ROADS = 8, // unused lump in Driver 2 - LUMP_JUNCTIONS = 9, // unused lump in Driver 2 - LUMP_ROADSURF = 10, // unused lump in Driver 2 + LUMP_ROADMAP = 7, // unused lump in Driver 2 + LUMP_ROADS = 8, // unused lump in Driver 2 + LUMP_JUNCTIONS = 9, // unused lump in Driver 2 + LUMP_ROADSURF = 10, // unused lump in Driver 2 - LUMP_MODELNAMES = 12, // model name strings + LUMP_MODELNAMES = 12, // model name strings - LUMP_ROADBOUNDS = 16, // unused lump in Driver 2 - LUMP_JUNCBOUNDS = 17, // unused lump in Driver 2 + LUMP_ROADBOUNDS = 16, // unused lump in Driver 2 + LUMP_JUNCBOUNDS = 17, // unused lump in Driver 2 - LUMP_SUBDIVISION = 20, - LUMP_LOWDETAILTABLE = 21, // LOD tables for models - LUMP_MOTIONCAPTURE = 22, // motion capture/animation data for peds and Tanner - LUMP_OVERLAYMAP = 24, // overlay map - LUMP_PALLET = 25, // car palettes - LUMP_SPOOLINFO = 26, // level region spooling - LUMP_CAR_MODELS = 28, // car models + LUMP_SUBDIVISION = 20, + LUMP_LOWDETAILTABLE = 21, // LOD tables for models + LUMP_MOTIONCAPTURE = 22, // motion capture/animation data for peds and Tanner + LUMP_OVERLAYMAP = 24, // overlay map + LUMP_PALLET = 25, // car palettes + LUMP_SPOOLINFO = 26, // level region spooling + LUMP_CAR_MODELS = 28, // car models - LUMP_CHAIR = 33, - LUMP_TEXTUREINFO = 34, // texture page info and details (atlases) + LUMP_CHAIR = 33, + LUMP_TEXTUREINFO = 34, // texture page info and details (atlases) - LUMP_LEVELDESC = 35, - LUMP_LEVELDATA = 36, - LUMP_LUMPDESC = 37, + LUMP_LEVELDESC = 35, + LUMP_LEVELDATA = 36, + LUMP_LUMPDESC = 37, - LUMP_STRAIGHTS2 = 40, // road straights (AI) - LUMP_CURVES2 = 41, + LUMP_STRAIGHTS2 = 40, // road straights (AI) + LUMP_CURVES2 = 41, - LUMP_JUNCTIONS2 = 42, // previously LUMP_JUNCTIONS2 - LUMP_JUNCTIONS2_NEW = 43, // Only appear in release Driver2 + LUMP_JUNCTIONS2 = 42, // previously LUMP_JUNCTIONS2 + LUMP_JUNCTIONS2_NEW = 43, // Only appear in release Driver2 }; int HitLeadCar = 0; @@ -214,56 +214,54 @@ extern SPEECH_QUEUE gSpeechQueue; bool gDriver1Level = false; bool gDemoLevel = false; -// [D] -void ProcessLumps(char *lump_ptr, int lump_size) +// [D] [T] +void ProcessLumps(char* lump_ptr, int lump_size) { int quit; int lump_type; - DRIVER2_JUNCTION *pDVar8; - ulong *puVar9; - int size; - int *ptr; + int seg_size; + int* ptr; int numLumps = -1; gDriver1Level = false; quit = false; do { - lump_type = *(int *)lump_ptr; - size = *(int *)(lump_ptr + 4); - ptr = (int *)(lump_ptr + 8); + lump_type = *(int*)lump_ptr; + seg_size = *(int*)(lump_ptr + 4); + ptr = (int*)(lump_ptr + 8); - if (lump_type == LUMP_LOWDETAILTABLE) + if (lump_type == LUMP_LOWDETAILTABLE) { - printf("LUMP_LOWDETAILTABLE: size: %d\n", size); - ProcessLowDetailTable((char *)ptr, size); + printf("LUMP_LOWDETAILTABLE: size: %d\n", seg_size); + ProcessLowDetailTable((char*)ptr, seg_size); } else if (lump_type == LUMP_CHAIR) { - printf("LUMP_CHAIR: size: %d\n", size); - ProcessChairLump((char *)ptr, size); + printf("LUMP_CHAIR: size: %d\n", seg_size); + ProcessChairLump((char*)ptr, seg_size); } else if (lump_type == LUMP_MOTIONCAPTURE) { - printf("LUMP_MOTIONCAPTURE: size: %d\n", size); - ProcessMotionLump((char *)ptr, size); + printf("LUMP_MOTIONCAPTURE: size: %d\n", seg_size); + ProcessMotionLump((char*)ptr, seg_size); gLoadedMotionCapture = 1; } else if (lump_type == LUMP_OVERLAYMAP) { - printf("LUMP_OVERLAYMAP: size: %d\n", size); - ProcessOverlayLump((char *)ptr, size); + printf("LUMP_OVERLAYMAP: size: %d\n", seg_size); + ProcessOverlayLump((char*)ptr, seg_size); gLoadedOverlay = 1; } else if (lump_type == LUMP_MAP) { - map_lump = (char *)ptr; + map_lump = (char*)ptr; } else if (lump_type == LUMP_SPOOLINFO) { - printf("LUMP_SPOOLINFO: size: %d\n", size); - ProcessSpoolInfoLump((char *)ptr, lump_size); + printf("LUMP_SPOOLINFO: size: %d\n", seg_size); + ProcessSpoolInfoLump((char*)ptr, lump_size); ProcessMapLump(map_lump, 0); // [A] I don't think it's used anymore @@ -274,41 +272,41 @@ void ProcessLumps(char *lump_ptr, int lump_size) // sdSelfModifyingCode ^ // (sdSelfModifyingCode ^ region_buffer_xor) & 0xc; } - else if (lump_type == LUMP_CURVES2) + else if (lump_type == LUMP_CURVES2) { - printf("LUMP_CURVES2: size: %d\n", size); - ProcessCurvesDriver2Lump((char *)ptr, size); + printf("LUMP_CURVES2: size: %d\n", seg_size); + ProcessCurvesDriver2Lump((char*)ptr, seg_size); } else if (lump_type == LUMP_TEXTURENAMES) { - printf("LUMP_TEXTURENAMES: size: %d\n", size); + printf("LUMP_TEXTURENAMES: size: %d\n", seg_size); texturename_buffer = (char*)ptr; } else if (lump_type == LUMP_PALLET) { - printf("LUMP_PALLET: size: %d\n", size); + printf("LUMP_PALLET: size: %d\n", seg_size); palette_lump = (char*)ptr; } - else if (lump_type == LUMP_TEXTUREINFO) + else if (lump_type == LUMP_TEXTUREINFO) { - printf("LUMP_TEXTUREINFO: size: %d\n", size); - ProcessTextureInfo((char *)ptr); + printf("LUMP_TEXTUREINFO: size: %d\n", seg_size); + ProcessTextureInfo((char*)ptr); } - else if (lump_type == LUMP_STRAIGHTS2) + else if (lump_type == LUMP_STRAIGHTS2) { - printf("LUMP_STRAIGHTS2: size: %d\n", size); - ProcessStraightsDriver2Lump((char *)ptr, size); + printf("LUMP_STRAIGHTS2: size: %d\n", seg_size); + ProcessStraightsDriver2Lump((char*)ptr, seg_size); } else if (lump_type == LUMP_JUNCTIONS2_NEW) { int cnt; - - printf("LUMP_JUNCTIONS2_NEW: size: %d\n", size); - ProcessJunctionsDriver2Lump((char *)ptr, size, 0); + + printf("LUMP_JUNCTIONS2_NEW: size: %d\n", seg_size); + ProcessJunctionsDriver2Lump((char*)ptr, seg_size, 0); // put junction flags if any cnt = 0; - + while (cnt < NumTempJunctions) { Driver2JunctionsPtr[cnt].flags = Driver2TempJunctionsPtr[cnt]; @@ -320,10 +318,10 @@ void ProcessLumps(char *lump_ptr, int lump_size) else if (lump_type == LUMP_JUNCTIONS2) { int cnt; - - printf("LUMP_JUNCTIONS2: size: %d\n", size); - ProcessJunctionsDriver2Lump((char *)ptr, size, 1); - + + printf("LUMP_JUNCTIONS2: size: %d\n", seg_size); + ProcessJunctionsDriver2Lump((char*)ptr, seg_size, 1); + // put junction flags if any cnt = 0; @@ -337,55 +335,55 @@ void ProcessLumps(char *lump_ptr, int lump_size) } else if (lump_type == LUMP_JUNCTIONS) { - printf("LUMP_JUNCTIONS: size: %d\n", size); - ProcessJunctionsLump((char *)ptr, size); + printf("LUMP_JUNCTIONS: size: %d\n", seg_size); + ProcessJunctionsLump((char*)ptr, seg_size); } else if (lump_type == LUMP_CAR_MODELS) { - printf("LUMP_CAR_MODELS: size: %d\n", size); + printf("LUMP_CAR_MODELS: size: %d\n", seg_size); car_models_lump = (char*)ptr; } else if (lump_type == LUMP_MODELS) { - printf("LUMP_MODELS: size: %d\n", size); - ProcessMDSLump((char *)ptr, size); + printf("LUMP_MODELS: size: %d\n", seg_size); + ProcessMDSLump((char*)ptr, seg_size); ProcessCarModelLump(car_models_lump, 0); InitModelNames(); SetUpEvents(1); } else if (lump_type == LUMP_ROADMAP) { - printf("LUMP_ROADMAP: size: %d\n", size); - NewProcessRoadMapLump(&roadMapLumpData, (char *)ptr); + printf("LUMP_ROADMAP: size: %d\n", seg_size); + NewProcessRoadMapLump(&roadMapLumpData, (char*)ptr); } else if (lump_type == LUMP_ROADS) { - printf("LUMP_ROADS: size: %d\n", size); - ProcessRoadsLump((char *)ptr, size); + printf("LUMP_ROADS: size: %d\n", seg_size); + ProcessRoadsLump((char*)ptr, seg_size); } else if (lump_type == LUMP_ROADBOUNDS) { - printf("LUMP_ROADBOUNDS: size: %d\n", size); - ProcessRoadBoundsLump((char *)ptr, size); + printf("LUMP_ROADBOUNDS: size: %d\n", seg_size); + ProcessRoadBoundsLump((char*)ptr, seg_size); } else if (lump_type == LUMP_JUNCBOUNDS) { - printf("LUMP_JUNCBOUNDS: size: %d\n", size); - ProcessJuncBoundsLump((char *)ptr, size); + printf("LUMP_JUNCBOUNDS: size: %d\n", seg_size); + ProcessJuncBoundsLump((char*)ptr, seg_size); } else if (lump_type == LUMP_SUBDIVISION) { - printf("LUMP_SUBDIVISION: size: %d\n", size); - ProcessSubDivisionLump((char *)ptr, size); + printf("LUMP_SUBDIVISION: size: %d\n", seg_size); + ProcessSubDivisionLump((char*)ptr, seg_size); } else if (lump_type == LUMP_ROADSURF) { - printf("LUMP_ROADSURF: size: %d\n", size); + printf("LUMP_ROADSURF: size: %d\n", seg_size); } else if (lump_type == LUMP_MODELNAMES) { - printf("LUMP_MODELNAMES: size: %d\n", size); - modelname_buffer = (char *)ptr; + printf("LUMP_MODELNAMES: size: %d\n", seg_size); + modelname_buffer = (char*)ptr; } else if (lump_type == 0xff) { @@ -401,11 +399,11 @@ void ProcessLumps(char *lump_ptr, int lump_size) continue; } - lump_size = size + 3; - lump_ptr = (char*)ptr + (lump_size & ~0x3); // aligned to 4-byte boundary + lump_ptr = (char*)ptr + ((seg_size + 3) & ~0x3); // aligned to 4-byte boundary - if (quit) + if (quit) return; + numLumps--; } while (numLumps != 0); } @@ -452,10 +450,10 @@ void ProcessLumps(char *lump_ptr, int lump_size) int SpoolLumpOffset; -// [D] +// [D] [T] void LoadGameLevel(void) { - char *malloc_lump; + char* malloc_lump; int nsectors; int sector; @@ -466,10 +464,10 @@ void LoadGameLevel(void) { if (gTimeOfDay == 3) SetCityType(CITYTYPE_NIGHT); - else + else SetCityType(CITYTYPE_DAY); } - else + else { if (gTimeOfDay == 3) SetCityType(CITYTYPE_MULTI_NIGHT); @@ -492,7 +490,7 @@ void LoadGameLevel(void) sector += nsectors; // CITYLUMP_DATA1 - load-time lump - ProcessLumps(_frontend_buffer+8, nsectors * CDSECTOR_SIZE); + ProcessLumps(_frontend_buffer + 8, nsectors * CDSECTOR_SIZE); // CITYLUMP_TPAGE is right next after DATA1 LoadPermanentTPages(§or); @@ -559,7 +557,7 @@ void LoadGameLevel(void) /* WARNING: Unknown calling convention yet parameter storage is locked */ -// [D] +// [D] [T] void InitModelNames(void) { gHubcapModelPtr = FindModelPtrWithName("HUBCAP1"); @@ -682,22 +680,24 @@ void InitModelNames(void) /* WARNING: Unknown calling convention yet parameter storage is locked */ -// [D] +// [D] [T] void GameInit(void) { long lVar1; - _PLAYER *p_Var2; - STREAM_SOURCE *pSVar3; + _PLAYER* p_Var2; + STREAM_SOURCE* pSVar3; int i; int iVar5; int iVar6; char padid; short totaldam; - if (NewLevel == 0) { + if (NewLevel == 0) + { SetPleaseWait(NULL); } - else { + else + { #ifdef PSX mallocptr = 0x137400; #else @@ -717,12 +717,14 @@ void GameInit(void) } gameinit = 1; + InitGameVariables(); InitEvents(); InitPadRecording(); InitSpeechQueue(&gSpeechQueue); - if (NewLevel != 0) { + if (NewLevel != 0) + { leadAIRequired = 0; leadAILoaded = 0; pathAILoaded = 0; @@ -730,16 +732,16 @@ void GameInit(void) LoadMission(gCurrentMissionNumber); - if (gCurrentMissionNumber == 38) + if (gCurrentMissionNumber == 38) MissionHeader->residentModels[4] = 9; - if (GameType == GAME_MISSION) + if (GameType == GAME_MISSION) SetupFadePolys(); - + if (NewLevel != 0) ShowLoadingScreen(LoadingScreenNames[GameLevel], 1, 36); - if (AttractMode != 0) + if (AttractMode != 0) { TriggerInGameCutscene(0); NoPlayerControl = 1; @@ -767,11 +769,11 @@ void GameInit(void) PauseSound(); ThisMotion = 0; - if (GameLevel == 1) + if (GameLevel == 1) { gMusicType = 1; - if ((gCurrentMissionNumber & 1U) != 0) + if ((gCurrentMissionNumber & 1U) != 0) gMusicType = 5; } else if (GameLevel == 0) @@ -785,37 +787,38 @@ void GameInit(void) { gMusicType = 0; - if ((gCurrentMissionNumber & 1U) == 0) + if ((gCurrentMissionNumber & 1U) == 0) gMusicType = 3; } - else if(GameLevel == 3) + else if (GameLevel == 3) { gMusicType = 4; - if((gCurrentMissionNumber & 1U) != 0) + if ((gCurrentMissionNumber & 1U) != 0) gMusicType = 7; } InitMusic(gMusicType); - if (NewLevel == 0) + if (NewLevel == 0) { - if (IconsLoaded == 0) + if (IconsLoaded == 0) ReloadIcons(); IconsLoaded = 1; SetUpEvents(0); } - else { + else + { LoadGameLevel(); IconsLoaded = 1; LoadSky(); LoadFont(NULL); } - ClearMem((char *)car_data, sizeof(car_data)); + ClearMem((char*)car_data, sizeof(car_data)); - player[0].spoolXZ = (VECTOR *)car_data[0].hd.where.t; + player[0].spoolXZ = (VECTOR*)car_data[0].hd.where.t; car_data[0].hd.where.t[0] = PlayerStartInfo[0]->position.vx; car_data[0].hd.where.t[2] = PlayerStartInfo[0]->position.vz; @@ -840,42 +843,40 @@ void GameInit(void) SpoolSYNC(); InitialiseCarHandling(); - ClearMem((char *)player, sizeof(player)); + ClearMem((char*)player, sizeof(player)); InitDrivingGames(); InitThrownBombs(); i = 0; - if (0 < numPlayersToCreate) + while (i < numPlayersToCreate) { - do { - pSVar3 = PlayerStartInfo[i]; - padid = -i; + pSVar3 = PlayerStartInfo[i]; + padid = -i; - if (i < NumPlayers) - padid = i; + if (i < NumPlayers) + padid = i; - gStartOnFoot = (pSVar3->type == 2); + gStartOnFoot = (pSVar3->type == 2); - InitPlayer(&player[i], &car_data[i], pSVar3->controlType, pSVar3->rotation, (long(*)[4])&pSVar3->position, pSVar3->model, pSVar3->palette, &padid); + InitPlayer(&player[i], &car_data[i], pSVar3->controlType, pSVar3->rotation, (long(*)[4]) & pSVar3->position, pSVar3->model, pSVar3->palette, &padid); - if (gStartOnFoot == 0) - { - car_data[i].ap.damage[0] = pSVar3->damage[0]; - car_data[i].ap.damage[1] = pSVar3->damage[1]; - car_data[i].ap.damage[2] = pSVar3->damage[2]; - car_data[i].ap.damage[3] = pSVar3->damage[3]; - car_data[i].ap.damage[4] = pSVar3->damage[4]; - car_data[i].ap.damage[5] = pSVar3->damage[5]; + if (gStartOnFoot == 0) + { + car_data[i].ap.damage[0] = pSVar3->damage[0]; + car_data[i].ap.damage[1] = pSVar3->damage[1]; + car_data[i].ap.damage[2] = pSVar3->damage[2]; + car_data[i].ap.damage[3] = pSVar3->damage[3]; + car_data[i].ap.damage[4] = pSVar3->damage[4]; + car_data[i].ap.damage[5] = pSVar3->damage[5]; - car_data[i].totalDamage = pSVar3->totaldamage; + car_data[i].totalDamage = pSVar3->totaldamage; - car_data[i].ap.needsDenting = 1; - } + car_data[i].ap.needsDenting = 1; + } - i++; - } while (i < numPlayersToCreate); - } + i++; + }; #ifdef CUTSCENE_RECORDER extern int gCutsceneAsReplay; @@ -888,52 +889,57 @@ void GameInit(void) #endif if (pathAILoaded != 0) + { InitCops(); + } InitCamera(&player[0]); - if (gLoadedOverlay != 0 && NoPlayerControl == 0) { + if (gLoadedOverlay != 0 && NoPlayerControl == 0) + { InitOverlays(); IconsLoaded = 0; } gSinkingTimer = 100; - gTimeInWater = 0x19; + gTimeInWater = 25; + InWater = 0; + gBobIndex = 0; SetupRain(); InitExObjects(); - if (NewLevel != 0) + if (NewLevel != 0) { MALLOC_BEGIN(); char* mem = D_MALLOC(1024); - tile_overflow_buffer = (ulong *)mem; - coplist = (CELL_OBJECT **)mem; + tile_overflow_buffer = (ulong*)mem; + coplist = (CELL_OBJECT**)mem; - pcoplist = (PACKED_CELL_OBJECT **)D_MALLOC(1024 + 256); + pcoplist = (PACKED_CELL_OBJECT**)D_MALLOC(1024 + 256); //transparent_buffer = D_MALLOC(256); // [A] unused MALLOC_END(); } - if (NoPlayerControl == 0) + if (NoPlayerControl == 0) { #ifdef CUTSCENE_RECORDER extern int gCutsceneAsReplay; - if(gCutsceneAsReplay == 0) + if (gCutsceneAsReplay == 0) #endif - DeleteAllCameras(); + DeleteAllCameras(); } - else + else { FindNextChange(CameraCnt); } FrAng = 0x200; - if (gWeather == 1) + if (gWeather == 1) wetness = 7000; - else + else wetness = 0; if (gTimeOfDay == 2) @@ -952,7 +958,7 @@ void GameInit(void) SetReverbState(0); - for(i = 0; i < 2; i++) + for (i = 0; i < 2; i++) { player[i].horn.request = 0; player[i].horn.time = 0; @@ -964,7 +970,7 @@ void GameInit(void) GetXAData(-1); SetXAVolume(0); - switch (gCurrentMissionNumber) + switch (gCurrentMissionNumber) { case 2: case 3: @@ -1139,22 +1145,19 @@ void StepSim(void) static char t2; // offset 0x5 static int oldsp; // offset 0x8 - char cVar1; - ushort uVar2; - short *psVar3; - int *piVar4; - //undefined3 extraout_var; + char padSteer; + short* playerFelony; int stream; - uint uVar5; - int *piVar6; - _CAR_DATA *cp; - _PLAYER *pl; - int i; + _CAR_DATA* cp; + _PLAYER* pl; + int i, j; int car; - if ((gTimeOfDay == 0) || (gTimeOfDay == 2)) { - DawnCount = DawnCount + 1; + if (gTimeOfDay == 0 || gTimeOfDay == 2) + { + DawnCount++; } + SetUpTrafficLightPhase(); MoveSmashable_object(); animate_garage_door(); @@ -1165,7 +1168,7 @@ void StepSim(void) num_active_cars = 0; - if ((NoPlayerControl != 0) && (ReplayParameterPtr->RecordingEnd + -2 < CameraCnt)) + if (NoPlayerControl != 0 && ReplayParameterPtr->RecordingEnd + -2 < CameraCnt) { ReleaseInGameCutscene(); pauseflag = 1; @@ -1175,46 +1178,41 @@ void StepSim(void) lead_pad = (ulong)controller_bits; - if ((int)player[0].playerCarId < 0) - { - psVar3 = &pedestrianFelony; - } - else - { - psVar3 = &car_data[(int)player[0].playerCarId].felonyRating; - } + if (player[0].playerCarId < 0) + playerFelony = &pedestrianFelony; + else + playerFelony = &car_data[player[0].playerCarId].felonyRating; // control cop roadblocks - if ((*psVar3 < 0x527) || (numRoadblockCars != 0)) + if (*playerFelony < 0x527 || numRoadblockCars != 0) { - LAB_00059c00: - if (roadblockCount == 0) - goto LAB_00059c1c; - } - else - { - if (roadblockCount == 0) + if (roadblockCount != 0) { - if (((copsAreInPursuit != 0) && (MissionHeader->residentModels[3] == 0)) && (gCurrentMissionNumber != 0x1a)) + roadblockCount--; + } + } + else + { + if (roadblockCount != 0) + { + roadblockCount--; + } + else + { + if (copsAreInPursuit != 0 && MissionHeader->residentModels[3] == 0 && gCurrentMissionNumber != 26) requestRoadblock = 1; - goto LAB_00059c00; + if (roadblockCount != 0) + roadblockCount--; } } - roadblockCount = roadblockCount + -1; - -LAB_00059c1c: // control civcars pingin/pingout - if ((requestStationaryCivCar == 1) || (requestRoadblock != 0)) + if (requestStationaryCivCar != 1 && requestRoadblock == 0) { - distFurthestCivCarSq = 0; - } - else - { - if (gInGameChaseActive == 0) + if (gInGameChaseActive == 0) { - if(numCivCars < maxCivCars && (NumPlayers == 1 || (NumPlayers == 2 && GameType == GAME_COPSANDROBBERS))) + if (numCivCars < maxCivCars && (NumPlayers == 1 || (NumPlayers == 2 && GameType == GAME_COPSANDROBBERS))) { // make 5 tries for (i = 0; i < 5; i++) @@ -1224,7 +1222,7 @@ LAB_00059c1c: } } } - else + else { // ping buffer used to spawn civ cars i = 0; @@ -1237,6 +1235,10 @@ LAB_00059c1c: SetUpCivCollFlags(); } + else + { + distFurthestCivCarSq = 0; + } numRoadblockCars = 0; numInactiveCars = 0; @@ -1245,158 +1247,146 @@ LAB_00059c1c: numCopCars = 0; numCivCars = 0; - if (true) + cp = car_data; + + // count cars + while (cp < &car_data[MAX_CARS]) { - cp = car_data; + if (cp->controlType == CONTROL_TYPE_CIV_AI) + { + numCivCars++; - do { - cVar1 = cp->controlType; - - if (cVar1 == 2) - { - numCivCars++; - - if ((cp->controlFlags & 1) != 0) - { - numCopCars++; - } - - if (((cp->controlFlags & 2) != 0) && (cp->ai.c.thrustState == 3)) - { - if (cp->ai.c.ctrlState == 5) - { - numParkedCars++; - } - - if ((cp->controlFlags & 2) != 0) - { - numRoadblockCars++; - } - } - } - else if (cVar1 == 3) - { + if (cp->controlFlags & CONTROL_FLAG_COP) numCopCars++; - if (cp->ai.p.dying == 0) - { - numActiveCops++; - } - } - else if (cVar1 == 0) - { - numInactiveCars++; - } + if (cp->ai.c.thrustState == 3 && cp->ai.c.ctrlState == 5) + numParkedCars++; - cp++; - } while (cp <= &car_data[21]); + if (cp->controlFlags & CONTROL_FLAG_COP_SLEEPING) + numRoadblockCars++; + } + else if (cp->controlType == CONTROL_TYPE_PURSUER_AI) + { + numCopCars++; + + if (cp->ai.p.dying == 0) + { + numActiveCops++; + } + } + else if (cp->controlType == CONTROL_TYPE_NONE) + { + numInactiveCars++; + } + + cp++; } if (numRoadblockCars != 0) roadblockCount = roadblockDelay; - if (requestStationaryCivCar == 0 && requestRoadblock != 0 && numRoadblockCars == 0 && maxCivCars - numCivCars > 4) + if (requestStationaryCivCar == 0 && requestRoadblock != 0 && numRoadblockCars == 0 && maxCivCars - numCivCars > 4) { CreateRoadblock(); } - - - if (gInGameCutsceneActive == 0) + if (gInGameCutsceneActive == 0) { CheckSpecialSpool(); } + // update cars cp = car_data; - while (cp < &car_data[20]) + while (cp < &car_data[MAX_CARS]) { - switch (cp->controlType) + switch (cp->controlType) { - case 1: - t0 = Pads[*cp->ai.padid].mapped; // [A] padid might be wrong - t1 = Pads[*cp->ai.padid].mapanalog[2]; - t2 = Pads[*cp->ai.padid].type & 4; + case 1: + t0 = Pads[*cp->ai.padid].mapped; // [A] padid might be wrong + t1 = Pads[*cp->ai.padid].mapanalog[2]; + t2 = Pads[*cp->ai.padid].type & 4; - if (NoPlayerControl == 0) - { - if (gStopPadReads != 0) + if (NoPlayerControl == 0) { - t0 = 0x80; + if (gStopPadReads != 0) + { + t0 = 0x80; - if (cp->hd.wheel_speed < 0x9001) - t0 = 0x10; + if (cp->hd.wheel_speed < 0x9001) + t0 = 0x10; - t1 = 0; - t2 = 1; + t1 = 0; + t2 = 1; + } + + cjpRecord(*cp->ai.padid, &t0, &t1, &t2); + } + else + { + cjpPlay(*cp->ai.padid, &t0, &t1, &t2); } - cjpRecord(*cp->ai.padid, &t0, &t1, &t2); - } - else - { - cjpPlay(*cp->ai.padid, &t0, &t1, &t2); - } - - ProcessCarPad(cp, t0, t1, t2); - break; - case 2: - CivControl(cp); - break; - case 3: - CopControl(cp); - break; - case 4: - t2 = 0; - t1 = 0; - t0 = 0; - - t0 = FreeRoamer(cp); - - if (t0 == 0) - { - cp->handbrake = 1; - cp->wheel_angle = 0; - } - else - { ProcessCarPad(cp, t0, t1, t2); - } + break; + case 2: + CivControl(cp); + break; + case 3: + CopControl(cp); + break; + case 4: + t2 = 0; + t1 = 0; + t0 = 0; - break; - case 7: -#ifdef CUTSCENE_RECORDER - extern int gCutsceneAsReplay; - extern int gCutsceneAsReplay_PlayerId; + t0 = FreeRoamer(cp); - if (gCutsceneAsReplay != 0 && NoPlayerControl == 0 && cp->id == gCutsceneAsReplay_PlayerId) - { - t0 = Pads[0].mapped; // [A] padid might be wrong - t1 = Pads[0].mapanalog[2]; - t2 = Pads[0].type & 4; - - if (gStopPadReads != 0) + if (t0 == 0) { - t0 = 0x80; - - if (cp->hd.wheel_speed < 0x9001) - t0 = 0x10; - - t1 = 0; - t2 = 1; + cp->handbrake = 1; + cp->wheel_angle = 0; + } + else + { + ProcessCarPad(cp, t0, t1, t2); } - cjpRecord(-*cp->ai.padid, &t0, &t1, &t2); - } - else + break; + case 7: +#ifdef CUTSCENE_RECORDER + extern int gCutsceneAsReplay; + extern int gCutsceneAsReplay_PlayerId; + + if (gCutsceneAsReplay != 0 && NoPlayerControl == 0 && cp->id == gCutsceneAsReplay_PlayerId) + { + t0 = Pads[0].mapped; // [A] padid might be wrong + t1 = Pads[0].mapanalog[2]; + t2 = Pads[0].type & 4; + + if (gStopPadReads != 0) + { + t0 = 0x80; + + if (cp->hd.wheel_speed <= 0x9000) + t0 = 0x10; + + t1 = 0; + t2 = 1; + } + + cjpRecord(-*cp->ai.padid, &t0, &t1, &t2); + } + else #endif - cjpPlay(-*cp->ai.padid, &t0, &t1, &t2); - ProcessCarPad(cp, t0, t1, t2); + cjpPlay(-*cp->ai.padid, &t0, &t1, &t2); + ProcessCarPad(cp, t0, t1, t2); } StepCarPhysics(cp); cp++; } + // Update players for (i = 0; i < 8; i++) { pl = &player[i]; @@ -1408,30 +1398,28 @@ LAB_00059c1c: if (stream < 0) { - stream = cjpPlay(-stream, &t0, &t1, &t2); - - if (stream != 0) + if (cjpPlay(-stream, &t0, &t1, &t2) != 0) ProcessTannerPad(pl->pPed, t0, t1, t2); } else { if (Pads[stream].type == 4) { - cVar1 = Pads[stream].mapanalog[3]; + padSteer = Pads[stream].mapanalog[3]; - if ((cVar1 < -64) && (-100 < cVar1)) + if (padSteer < -64 && padSteer > -100) { - Pads[stream].mapped = Pads[stream].mapped | 0x1008; + Pads[stream].mapped |= 0x1008; } - else if ((cVar1 < -100) && (127 < cVar1)) + else if (padSteer < -100 && padSteer > 127) { stream = pl->padid; - Pads[stream].mapped = Pads[stream].mapped | 0x1000; + Pads[stream].mapped |= 0x1000; } - else if (cVar1 > 32) + else if (padSteer > 32) { stream = pl->padid; - Pads[stream].mapped = Pads[stream].mapped | 0x4000; + Pads[stream].mapped |= 0x4000; } } @@ -1462,7 +1450,7 @@ LAB_00059c1c: } } - if (requestStationaryCivCar == 1 && (numCivCars < maxCivCars || (PingOutCar(car_data + furthestCivID), numCivCars < maxCivCars))) + if (requestStationaryCivCar == 1 && (numCivCars < maxCivCars || (PingOutCar(car_data + furthestCivID), numCivCars < maxCivCars))) { requestStationaryCivCar = 0; } @@ -1471,12 +1459,10 @@ LAB_00059c1c: { ControlCops(); - if(gLoadedMotionCapture) + if (gLoadedMotionCapture) HandlePedestrians(); } - i = 0; - GlobalTimeStep(); UpdatePlayers(); DoScenaryCollisions(); @@ -1486,41 +1472,42 @@ LAB_00059c1c: CameraCnt++; gBobIndex = gBobIndex + 0x3cU & 0xfff; - if (NumPlayers != 0) + + i = 0; + pl = player; + + // deal with car horns + while (i < NumPlayers) { - car = 0; - pl = player; - do { - if (pl->horn.on == 0) + int playerCarId; + + playerCarId = pl->playerCarId; + + if (playerCarId >= 0) + { + if (pl->horn.on == 0) { - LAB_0005a5b8: - stream = CarHasSiren(car_data[player[car].playerCarId].ap.model); - - if (stream == 0 && pl->pPed == NULL) + if (CarHasSiren(car_data[playerCarId].ap.model) == 0 && pl->pPed == NULL) { - stream = 2; - if (i != 0) - stream = 5; - + stream = i != 0 ? 5 : 2; StopChannel(stream); - player[car].horn.request = 0; - player[car].horn.time = 0; + + pl->horn.request = 0; + pl->horn.time = 0; } } - else + else { - uVar5 = 4; + int spuKeys; - if (i != 0) - uVar5 = 0x20; + if (i != 0) + spuKeys = 0x20; + else + spuKeys = 0x4; - stream = SpuGetKeyStatus(uVar5); - - if (stream == 0) + if (SpuGetKeyStatus(spuKeys) == 0) { - stream = CarHasSiren(car_data[pl->playerCarId].ap.model); - - if (stream == 0 && pl->pPed == NULL && pl->horn.request == 0) + if (CarHasSiren(car_data[pl->playerCarId].ap.model) == 0 && pl->pPed == NULL && pl->horn.request == 0) pl->horn.request = 1; pl->horn.time = 11; @@ -1528,81 +1515,81 @@ LAB_00059c1c: } - DealWithHorn(&player[car].horn.request, i); + DealWithHorn(&pl->horn.request, i); + } - car++; - i++; - pl++; - } while (i < NumPlayers); + i++; + pl++; } SoundTasks(); static int stupid_logic[4]; - if (gInGameCutsceneActive == 0 || gCurrentMissionNumber != 23 || gInGameCutsceneID != 0) + if (gInGameCutsceneActive == 0 || gCurrentMissionNumber != 23 || gInGameCutsceneID != 0) stupid_logic[0] = player[0].playerCarId; else stupid_logic[0] = 2; - i = 0; - piVar4 = stupid_logic; stupid_logic[1] = player[1].playerCarId; stupid_logic[2] = gThePlayerCar; stupid_logic[3] = leadCarId; - do { - car = i + 1; - if (car < 4) + while (i < 3) + { + j = i + 1; + while (j < 4) { - piVar6 = stupid_logic + car; - do { - if (*piVar4 == *piVar6) - *piVar6 = -1; + if (stupid_logic[i] == stupid_logic[j]) + stupid_logic[j] = -1; - car++; - piVar6++; - } while (car < 4); + j++; } - i = i + 1; - piVar4 = piVar4 + 1; - } while (i < 3); + i++; + } car = 0; i = 0; do { - stream = i; - - if ((stupid_logic[car] != -1) && SilenceThisCar(car) == 0) + if (stupid_logic[car] != -1 && SilenceThisCar(car) == 0) { - stream = i + 1; CheckCarEffects(&car_data[stupid_logic[car]], i); SwirlLeaves(&car_data[stupid_logic[car]]); + i++; } car++; - } while(car < 4 && (i = stream, stream < 2)); + } while (car < 4 && i < 2); - - - if ((gStopPadReads == 1) && (((lead_car != 0 && (saved_counter = saved_counter + 1, 0x14 < saved_counter)) && (saved_leadcar_pos == 0)))) + // save car positions + if (gStopPadReads == 1 && lead_car != 0) { - saved_leadcar_pos = gStopPadReads; - leadcar_pos.vx = car_data[lead_car].hd.where.t[0]; - leadcar_pos.vy = car_data[lead_car].hd.where.t[1]; - leadcar_pos.vz = car_data[lead_car].hd.where.t[2]; + saved_counter++; + + if (saved_counter > 20 && saved_leadcar_pos == 0) + { + leadcar_pos.vx = car_data[lead_car].hd.where.t[0]; + leadcar_pos.vy = car_data[lead_car].hd.where.t[1]; + leadcar_pos.vz = car_data[lead_car].hd.where.t[2]; + + saved_leadcar_pos = 1; + } } - if (gInGameCutsceneActive == 0 && - (((i = xa_timeout, XAPrepared() != 0 && (i = xa_timeout + -1, xa_timeout == 0)) || - (xa_timeout = i, xa_timeout == 0)))) + // XA playback timeout + if (gInGameCutsceneActive == 0 && XAPrepared()) { - StopXA(); - UnprepareXA(); - StartSpooling(); + xa_timeout--; + + if (xa_timeout == 0) + { + StopXA(); + UnprepareXA(); + StartSpooling(); + } } } @@ -1654,13 +1641,12 @@ LAB_00059c1c: /* WARNING: Unknown calling convention yet parameter storage is locked */ -// [D] +// [D] [T] void GameLoop(void) { - uint uVar1; - int iVar2; + int i; static POLY_FT3 buffer[2]; - static POLY_FT3 *null; + static POLY_FT3* null; if (NewLevel != 0) { @@ -1682,11 +1668,10 @@ void GameLoop(void) NoTextureMemory = 0; SpoolSYNC(); - if (CurrentGameMode != GAMEMODE_DIRECTOR) { - UnPauseSound(); - } - iVar2 = 4; + if (CurrentGameMode != GAMEMODE_DIRECTOR) + UnPauseSound(); + StartGameSounds(); SetMasterVolume(gMasterVolume); SetXMVolume(gMusicVolume); @@ -1694,17 +1679,19 @@ void GameLoop(void) InitControllers(); VSync(0); + i = 4; do { - iVar2 = iVar2 + -1; + ReadControllers(); VSync(0); - } while (-1 < iVar2); + i--; + } while (i >= 0); - while (game_over == 0) + while (game_over == 0) { StepGame(); - - if (FastForward == 0 || FrameCnt == (FrameCnt / 7) * 7) + + if (FastForward == 0 || FrameCnt == (FrameCnt / 7) * 7) { DrawGame(); } @@ -1729,7 +1716,7 @@ void GameLoop(void) CheckForPause(); } - if (NoPlayerControl == 0) + if (NoPlayerControl == 0) { ReplayParameterPtr->RecordingEnd = CameraCnt; } @@ -1739,7 +1726,7 @@ void GameLoop(void) StopAllChannels(); FreeXM(); - if (XAPrepared() != 0) + if (XAPrepared() != 0) { StopXA(); UnprepareXA(); @@ -1820,58 +1807,57 @@ void GameLoop(void) /* WARNING: Unknown calling convention yet parameter storage is locked */ -// [D] +// [D] [T] void StepGame(void) { - char cVar1; int iVar2; - uint uVar3; - unsigned char *puVar4; - _PLAYER *pPVar5; + int i; + unsigned char* puVar4; + _PLAYER* pl; - if (CameraCnt == 3) + if (CameraCnt == 3) { StartXM(0); } - if (doSpooling) + if (doSpooling) { CheckValidSpoolData(); ControlMap(); } - if (gTimeOfDay == 3) + if (gTimeOfDay == 3) PreLampStreak(); UpdatePadData(); - if (FrameCnt == 5) + if (FrameCnt == 5) SetDispMask(1); - if ((padd & 0x2000U) != 0 && (padd & 0x8000U) != 0) - padd = padd & 0x5fff; + if ((padd & 0x2000U) && (padd & 0x8000U)) + padd &= ~0xA000; - uVar3 = NumPlayers; + i = NumPlayers; controller_bits = padd; - if (NumPlayers != 0) + pl = player; + while (i >= 0) { - pPVar5 = player; - do { - if (pPVar5->horn.time == 0 || pPVar5->horn.on == 0) - pPVar5->horn.time = 0; - else - pPVar5->horn.time--; + if (pl->horn.time == 0 || pl->horn.on == 0) + pl->horn.time = 0; + else + pl->horn.time--; - uVar3--; - pPVar5++; - } while (uVar3 != 0); + i--; + pl++; } ModifyCamera(); lis_pos = camera_position; - if ((gTimeInWater == 0) || (gSinkingTimer < 100)) + // pause state update + // DRIVER 1 leftover + /*if (gTimeInWater == 0 || gSinkingTimer < 100) { gStopPadReads = 1; TargetCar = 0; @@ -1879,92 +1865,69 @@ void StepGame(void) gSinkingTimer--; gCameraAngle = gCameraAngle - 0x16U & 0xfff; - if (gCameraDistance < 1000) + if (gCameraDistance < 1000) { - gCameraMaxDistance = gCameraMaxDistance + 8; - gCameraDistance = gCameraDistance + 8; + gCameraMaxDistance += 8; + gCameraDistance += 8; } - if (-1000 < CameraPos.vy) { - CameraPos.vy = CameraPos.vy + -8; - } + if (CameraPos.vy > -1000) + CameraPos.vy -= 8; - if (gSinkingTimer < 0) { + if (gSinkingTimer < 0) EnablePause(PAUSEMODE_GAMEOVER); - } - } + }*/ - if (gTimeOfDay == 1) + // update colours of ambience + if (gTimeOfDay == 0) + { + NightAmbient = (DawnCount >> 7) + 26; + gLightsOn = (DawnCount < 4000); + + if (NightAmbient > 96) + NightAmbient = 96; + } + else if (gTimeOfDay == 1) { gLightsOn = 0; - iVar2 = 0x4e; - if (1 < gWeather - 1U) - iVar2 = 0x80; - - goto LAB_0005aea0; + if (gWeather - 1U > 1) + NightAmbient = 128; + else + NightAmbient = 78; } - - if (gTimeOfDay < 2) + else if (gTimeOfDay == 2) { - if (gTimeOfDay == 0) + if (DawnCount < 3000) { - NightAmbient = (DawnCount >> 7) + 0x1a; - gLightsOn = (DawnCount < 4000); - iVar2 = 0x60; - if (0x60 < NightAmbient) goto LAB_0005aea0; + gLightsOn = 0; } + else + { + gLightsOn = 1; + + for (i = 0; i < MAX_CARS; i++) + { + if (lightsOnDelay[i] > 0) + lightsOnDelay[i]--; + } + } + + if (gWeather - 1U < 2) + NightAmbient = 78 - (DawnCount >> 7); + else + NightAmbient = 96 - (DawnCount >> 5); + + if (NightAmbient < 45) + NightAmbient = 45; } - else + else if (gTimeOfDay == 3) { - if (gTimeOfDay == 2) - { - if (DawnCount < 3000) - { - gLightsOn = 0; - } - else - { - gLightsOn = 1; - puVar4 = lightsOnDelay; - do { - if (*puVar4 != 0) - *puVar4 = *puVar4 - 1; - - puVar4++; - } while (puVar4 < lightsOnDelay + sizeof(lightsOnDelay)); - } - - NightAmbient = 0x4e; - - if (gWeather - 1U < 2) - { - iVar2 = DawnCount >> 7; - } - else - { - NightAmbient = 0x60; - iVar2 = DawnCount >> 5; - } - - NightAmbient = NightAmbient - iVar2; - iVar2 = 0x2d; - - if (NightAmbient < 0x2d) - goto LAB_0005aea0; - } - else - { - if (gTimeOfDay == 3) - { - gLightsOn = 1; - iVar2 = 0x80; - LAB_0005aea0: - NightAmbient = iVar2; - } - } + gLightsOn = 1; + NightAmbient = 128; } - if ((gWeather != 0) && (gWeather == 1)) + + if (gWeather != 0 && gWeather == 1) { DoLightning(); DoThunder(); @@ -1977,119 +1940,114 @@ void StepGame(void) combointensity = NightAmbient | NightAmbient << 8 | NightAmbient << 0x10; - if ((NoPlayerControl != 0) && (AttractMode == 0)) + if (NoPlayerControl != 0 && AttractMode == 0) ShowReplayOptions(); - - if ((FastForward != 0) && (uVar3 = CameraCnt & 0x1f, CameraCnt < ReplayParameterPtr->RecordingEnd-1)) - { - if (0xf < uVar3) - uVar3 = 0x20 - uVar3; - SetTextColour((uVar3 & 0x1f) << 3, 0, 0); + // process fast forward + if (FastForward != 0 && CameraCnt < ReplayParameterPtr->RecordingEnd - 1) + { + int color; + color = CameraCnt & 0x1f; + + if (color > 15) + color = 32 - color; + + SetTextColour((color & 0x1f) << 3, 0, 0); PrintStringFeature("Fast forward", 100, 0x1e, 0x1000, 0x1000, 0); } - if (AttractMode == 0 && pauseflag == 0) + // check for pause mode + if (AttractMode == 0 && pauseflag == 0) { - //if (NoPlayerControl == 0) + if (FrameCnt > 2) { - if (2 < FrameCnt) + if (NumPlayers == 1) { - if (NumPlayers == 1) + if (paddp == 0x800 && bMissionTitleFade == 0) // [A] && gInGameCutsceneActive == 0) // allow pausing during cutscene { - if (paddp == 0x800 && bMissionTitleFade == 0) // [A] && gInGameCutsceneActive == 0) // allow pausing during cutscene - { - EnablePause(PAUSEMODE_PAUSE); - } - } - else if (paddp == 0x800) - { - EnablePause(PAUSEMODE_PAUSEP1); - } - else if (NumPlayers == 2 && (Pads[1].dirnew & 0x800) != 0) - { - EnablePause(PAUSEMODE_PAUSEP2); + EnablePause(PAUSEMODE_PAUSE); } } - goto LAB_0005b0a8; + else if (paddp == 0x800) + { + EnablePause(PAUSEMODE_PAUSEP1); + } + else if (NumPlayers == 2 && (Pads[1].dirnew & 0x800) != 0) + { + EnablePause(PAUSEMODE_PAUSEP2); + } } } - else - { - LAB_0005b0a8: - if (NoPlayerControl == 0) - { - if (pad_connected < 1 && FrameCnt > 2 && bMissionTitleFade == 0 && gInGameCutsceneActive == 0) - { - pauseflag = 1; - PauseSound(); - } - if (NoPlayerControl == 0 && NoTextureMemory != 0) - NoTextureMemory--; + if (NoPlayerControl == 0) + { + if (pad_connected < 1 && FrameCnt > 2 && bMissionTitleFade == 0 && gInGameCutsceneActive == 0) + { + pauseflag = 1; + PauseSound(); } + + if (NoPlayerControl == 0 && NoTextureMemory != 0) + NoTextureMemory--; } CameraChanged = 0; old_camera_change = camera_change; - if (pauseflag == 0 && NoPlayerControl != 0) + // do camera changes + if (pauseflag == 0 && NoPlayerControl != 0) { - if (gInGameCutsceneActive == 0) - { + if (gInGameCutsceneActive != 0) + camera_change = CutsceneCameraChange(CameraCnt); + else camera_change = CheckCameraChange(CameraCnt); - goto LAB_0005b1e0; - } } - else { - if (gInGameCutsceneActive == 0) - { + else + { + if (gInGameCutsceneActive != 0) + camera_change = CutsceneCameraChange(CameraCnt); + else camera_change = 0; - goto LAB_0005b1e0; - } } - camera_change = CutsceneCameraChange(CameraCnt); -LAB_0005b1e0: - - - if (pauseflag == 0) + // step physics engine + if (pauseflag == 0) { StepSim(); if (gDieWithFade != 0) - { - gDieWithFade = gDieWithFade + 1; - } - if (paused != 0) + gDieWithFade++; + + if (paused != 0) { CamerasSaved = 1; paused = 0; } } - else + else { - if (NoPlayerControl == 0 && AttractMode == 0 && game_over == 0) + if (NoPlayerControl == 0 && AttractMode == 0 && game_over == 0) { if (pad_connected < 1) EnablePause(PAUSEMODE_PADERROR); - else + else EnablePause(PAUSEMODE_PAUSE); } paused = 1; } - if (NoPlayerControl != 0 && AttractMode == 0) + if (NoPlayerControl != 0 && AttractMode == 0) ControlReplay(); - - if (gRightWayUp != 0) + + // player flip cheat + if (gRightWayUp != 0) { TempBuildHandlingMatrix(car_data + player[0].playerCarId, 0); gRightWayUp = 0; } - if (AttractMode != 0 && (paddp != 0 || ReplayParameterPtr->RecordingEnd <= CameraCnt)) + if (AttractMode != 0 && (paddp != 0 || ReplayParameterPtr->RecordingEnd <= CameraCnt)) EndGame(GAMEMODE_QUIT); UpdatePlayerInformation(); @@ -2150,21 +2108,22 @@ LAB_0005b1e0: int ObjectDrawnValue = 0; int ObjectDrawnCounter = 0; +// [D] [T] void DrawGame(void) { - if(gSkipInGameCutscene) + if (gSkipInGameCutscene) { ClearCurrentDrawBuffers(); return; } - + static unsigned long frame = 0; - if ((NumPlayers == 1) || (NoPlayerControl != 0)) + if (NumPlayers == 1 || NoPlayerControl != 0) { ObjectDrawnValue = FrameCnt; DrawPauseMenus(); - + RenderGame2(0); ObjectDrawnCounter++; @@ -2174,7 +2133,7 @@ void DrawGame(void) SwapDrawBuffers(); } - else + else { ObjectDrawnValue = FrameCnt; RenderGame2(0); @@ -2225,7 +2184,7 @@ void DrawGame(void) static int WantPause = 0; static PAUSEMODE PauseMode = PAUSEMODE_PAUSE; -// [D] +// [D] [T] void EndGame(GAMEMODE mode) { WantedGameMode = mode; @@ -2291,10 +2250,10 @@ void EnablePause(PAUSEMODE mode) /* WARNING: Unknown calling convention yet parameter storage is locked */ -// [D] +// [D] [T] void CheckForPause(void) { - if (gDieWithFade > 15 && (quick_replay != 0 || NoPlayerControl == 0)) + if (gDieWithFade > 15 && (quick_replay != 0 || NoPlayerControl == 0)) { PauseMode = PAUSEMODE_GAMEOVER; WantPause = 1; @@ -2315,7 +2274,7 @@ void CheckForPause(void) } } -// [D] +// [D] [T] This is really a Psy-Q function void SsSetSerialVol(short s_num, short voll, short volr) { SpuCommonAttr attr; @@ -2409,33 +2368,33 @@ void PrintCommandLineArguments() #endif " -nointro : disable intro screens\n" " -nofmv : disable all FMVs\n"; - + SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, "REDRIVER 2 command line arguments", argumentsMessage, NULL); } #endif -// [D] +// [D] [T] #ifdef PSX int main(void) #else int redriver2_main(int argc, char** argv) #endif // PSX { - char *PALScreenNames[4] = { // [A] don't show publisher logo + char* PALScreenNames[4] = { // [A] don't show publisher logo // "GFX\\SPLASH2.TIM", // "GFX\\SPLASH3.TIM", "GFX\\SPLASH1P.TIM", NULL }; - char *NTSCScreenNames[4] = { // [A] don't show publisher logo + char* NTSCScreenNames[4] = { // [A] don't show publisher logo // "GFX\\SPLASH2.TIM", // "GFX\\SPLASH3.TIM", "GFX\\SPLASH1N.TIM", NULL }; - char *OPMScreenNames[4] = { // [A] don't show publisher logo + char* OPMScreenNames[4] = { // [A] don't show publisher logo //"GFX\\OPM1.TIM", "GFX\\OPM2.TIM", "GFX\\OPM3.TIM", @@ -2466,7 +2425,7 @@ int redriver2_main(int argc, char** argv) InitSound(); #ifndef PSX - if(argc <= 1) + if (argc <= 1) #endif { //PlayFMV(99); // [A] don't show publisher logo @@ -2516,10 +2475,10 @@ int redriver2_main(int argc, char** argv) return -1; } - gStartPos.x = atoi(argv[i+1]); - gStartPos.z = atoi(argv[i+2]); + gStartPos.x = atoi(argv[i + 1]); + gStartPos.z = atoi(argv[i + 2]); - i+=2; + i += 2; } else if (!_stricmp(argv[i], "-playercar")) { @@ -2581,42 +2540,87 @@ int redriver2_main(int argc, char** argv) } else #endif // _DEBUG_OPTIONS - if (!_stricmp(argv[i], "-nofmv")) - { - gNoFMV = 1; - } - else if (!_stricmp(argv[i], "-nointro")) - { - // do nothing. All command line features use it - } - else if (!_stricmp(argv[i], "-replay")) - { - if (argc-i < 2) + if (!_stricmp(argv[i], "-nofmv")) { - printError("-replay missing argument!"); - return -1; + gNoFMV = 1; } - - SetFEDrawMode(); - - gInFrontend = 0; - AttractMode = 0; - - char nameStr[512]; - sprintf(nameStr, "%s", argv[i+1]); - - FILE* fp = fopen(nameStr, "rb"); - if (fp) + else if (!_stricmp(argv[i], "-nointro")) { - int replay_size = 0; - fseek(fp, 0, SEEK_END); - replay_size = ftell(fp); - fseek(fp, 0, SEEK_SET); + // do nothing. All command line features use it + } + else if (!_stricmp(argv[i], "-replay")) + { + if (argc - i < 2) + { + printError("-replay missing argument!"); + return -1; + } - fread(_other_buffer, replay_size, 1, fp); - fclose(fp); + SetFEDrawMode(); - if (LoadReplayFromBuffer(_other_buffer)) + gInFrontend = 0; + AttractMode = 0; + + char nameStr[512]; + sprintf(nameStr, "%s", argv[i + 1]); + + FILE* fp = fopen(nameStr, "rb"); + if (fp) + { + int replay_size = 0; + fseek(fp, 0, SEEK_END); + replay_size = ftell(fp); + fseek(fp, 0, SEEK_SET); + + fread(_other_buffer, replay_size, 1, fp); + fclose(fp); + + if (LoadReplayFromBuffer(_other_buffer)) + { + CurrentGameMode = GAMEMODE_REPLAY; + gLoadedReplay = 1; + + LaunchGame(); + + gLoadedReplay = 0; + } + else + { + printError("Error loading replay file '%s'!\n", nameStr); + } + } + else + { + printError("Cannot open replay '%s'!\n", nameStr); + return -1; + } + i++; + } +#ifdef CUTSCENE_RECORDER + else if (!_stricmp(argv[i], "-recordcutscene")) + { + if (argc - i < 3) + { + printWarning("Example: -recordcutscene "); + return 0; + } + + SetFEDrawMode(); + + gInFrontend = 0; + AttractMode = 0; + + int subindx = atoi(argv[i + 2]); + + extern int LoadCutsceneAsReplay(int subindex); + extern int gCutsceneAsReplay; + extern int gCutsceneAsReplay_PlayerId; + + gCutsceneAsReplay = atoi(argv[i + 1]); // acts as cutscene mission + gCurrentMissionNumber = atoi(argv[i + 3]); // acts as base mission. Some mission requires other base + gCutsceneAsReplay_PlayerId = 0; + + if (LoadCutsceneAsReplay(subindx)) { CurrentGameMode = GAMEMODE_REPLAY; gLoadedReplay = 1; @@ -2625,61 +2629,16 @@ int redriver2_main(int argc, char** argv) gLoadedReplay = 0; } - else - { - printError("Error loading replay file '%s'!\n", nameStr); - } + gCutsceneAsReplay = 0; + return 1; } +#endif else { - printError("Cannot open replay '%s'!\n", nameStr); - return -1; + if (!commandLinePropsShown) + PrintCommandLineArguments(); + commandLinePropsShown = 1; } - i++; - } -#ifdef CUTSCENE_RECORDER - else if (!_stricmp(argv[i], "-recordcutscene")) - { - if (argc-i < 3) - { - printWarning("Example: -recordcutscene "); - return 0; - } - - SetFEDrawMode(); - - gInFrontend = 0; - AttractMode = 0; - - int subindx = atoi(argv[i+2]); - - extern int LoadCutsceneAsReplay(int subindex); - extern int gCutsceneAsReplay; - extern int gCutsceneAsReplay_PlayerId; - - gCutsceneAsReplay = atoi(argv[i + 1]); // acts as cutscene mission - gCurrentMissionNumber = atoi(argv[i + 3]); // acts as base mission. Some mission requires other base - gCutsceneAsReplay_PlayerId = 0; - - if (LoadCutsceneAsReplay(subindx)) - { - CurrentGameMode = GAMEMODE_REPLAY; - gLoadedReplay = 1; - - LaunchGame(); - - gLoadedReplay = 0; - } - gCutsceneAsReplay = 0; - return 1; - } -#endif - else - { - if(!commandLinePropsShown) - PrintCommandLineArguments(); - commandLinePropsShown = 1; - } } #endif // PSX @@ -2712,7 +2671,7 @@ int redriver2_main(int argc, char** argv) /* end block 3 */ // End Line: 11398 -// [D] +// [D] [T] void FadeScreen(int end_value) { int tmp2 = pauseflag; @@ -2767,142 +2726,97 @@ void FadeScreen(int end_value) /* WARNING: Unknown calling convention yet parameter storage is locked */ -// [D] +// [D] [T] void UpdatePlayerInformation(void) { - short *psVar1; - int iVar2; - unsigned char *pbVar3; - WHEEL *pWVar4; - int iVar5; - int iVar6; - int iVar7; - int iVar8; - _CAR_DATA *cp; + short* playerFelony; + WHEEL* wheel; + int i, j; + int wheelsInWater; + _CAR_DATA* cp; cp = NULL; + PlayerDamageBar.max = MaxPlayerDamage[0]; Player2DamageBar.max = MaxPlayerDamage[1]; if (player[0].playerCarId < 0) - psVar1 = &pedestrianFelony; + playerFelony = &pedestrianFelony; else - psVar1 = &car_data[player[0].playerCarId].felonyRating; + playerFelony = &car_data[player[0].playerCarId].felonyRating; - if (gPlayerImmune != 0) - *psVar1 = 0; + if (gPlayerImmune != 0) + *playerFelony = 0; - FelonyBar.position = *psVar1; - if (NumPlayers != 0) + FelonyBar.position = *playerFelony; + + i = 0; + while (i < NumPlayers) { - iVar2 = 0; - iVar8 = 0; - do { + if (player[i].playerType == 1) + { + cp = &car_data[player[i].playerCarId]; - if (player[iVar8].playerType == 1) + if (gInvincibleCar != 0) { - iVar2 = player[iVar8].playerCarId; - cp = &car_data[iVar2]; + cp->totalDamage = 0; + ClearMem((char*)cp->ap.damage, sizeof(cp->ap.damage)); + } - if (gInvincibleCar != 0) + wheelsInWater = 0; + + j = 0; + wheel = cp->hd.wheel; + + do { + if ((wheel->surface & 0x7) == 1) { - cp->totalDamage = 0; - ClearMem((char *)cp->ap.damage, 0xc); - } - - iVar6 = 0; - iVar7 = iVar8 + 1; - pWVar4 = cp->hd.wheel; - iVar5 = 3; - - do { - if ((pWVar4->surface & 7) == 1) + if (wheel->susCompression == 0) { - if (pWVar4->susCompression == 0) + if (cp->hd.where.t[1] < -1000 && gDieWithFade == 0) { - if (cp->hd.where.t[1] < -1000 && gDieWithFade == 0) - { - gDieWithFade = pWVar4->surface & 7; - } - } - else - { - iVar6++; + gDieWithFade = wheel->surface & 7; } } - - pWVar4++; - iVar5--; - } while (-1 < iVar5); - - if (iVar6 == 4) // apply water damage - cp->totalDamage += MaxPlayerDamage[iVar8] / 80; - - if (MaxPlayerDamage[iVar8] < cp->totalDamage) - cp->totalDamage = MaxPlayerDamage[iVar8]; - - if (iVar8 == 0) - PlayerDamageBar.position = cp->totalDamage; - else - Player2DamageBar.position = cp->totalDamage; - } - else - { - iVar7 = iVar8 + 1; - if (iVar8 == 0) - { - PlayerDamageBar.position = 0; - iVar7 = 1; + else + { + wheelsInWater++; + } } - else - { - Player2DamageBar.position = 0; - } - } - if (((0x1df < gCurrentMissionNumber) && - (((gCurrentMissionNumber < 0x1e2 || - ((gCurrentMissionNumber < 0x1e6 && (0x1e3 < gCurrentMissionNumber)))) && - (cp->hd.where.t[1] < -750)))) && (gDieWithFade == 0)) - { - gDieWithFade = 1; - } + wheel++; + j++; + } while (j < 4); - iVar2 = iVar7 << 3; - iVar8 = iVar7; - } while (iVar7 < NumPlayers); + if (wheelsInWater == 4) // apply water damage + cp->totalDamage += MaxPlayerDamage[i] / 80; + + if (cp->totalDamage > MaxPlayerDamage[i]) + cp->totalDamage = MaxPlayerDamage[i]; + + if (i == 0) + PlayerDamageBar.position = cp->totalDamage; + else + Player2DamageBar.position = cp->totalDamage; + } + else + { + if (i == 0) + PlayerDamageBar.position = 0; + else + Player2DamageBar.position = 0; + } + + // die with fade on mountain race track + if ((gCurrentMissionNumber > 479 && gCurrentMissionNumber < 482 || + gCurrentMissionNumber > 483 && gCurrentMissionNumber < 486) && + cp->hd.where.t[1] < -750 && gDieWithFade == 0) + { + gDieWithFade = 1; + } + + i++; } - - - // [A] - test - /* - int surface_index = GetSurfaceIndex((VECTOR*)player[0].pos); - - if (IS_ROAD_SURFACE(surface_index)) - printWarning("------- road idx: %d\n", (surface_index & 0x1fffU)); - - if (IS_CURVED_SURFACE(surface_index)) - { - DRIVER2_CURVE* crv = GET_CURVE(surface_index); - - printWarning("CURVE\nlanes: %d\n", crv->NumLanes, crv->NumLanes); - } - else if (IS_STRAIGHT_SURFACE(surface_index)) - { - DRIVER2_STRAIGHT* str = GET_STRAIGHT(surface_index); - - printWarning("STRAIGHT\nlanes: %d (s: %d s2: %d, ail: %d), conn: %d %d %d %d, lanedirs: %d, ailanes: %d\n", - str->NumLanes & 0xF, str->NumLanes & 0x40, str->NumLanes & 0x80, str->AILanes, str->ConnectIdx[0], str->ConnectIdx[1], str->ConnectIdx[2], str->ConnectIdx[3], str->LaneDirs); - str->NumLanes |= 0x80; - - } - else if (IS_JUNCTION_SURFACE(surface_index)) - { - DRIVER2_JUNCTION* junc = GET_JUNCTION(surface_index); - - printWarning("JUNCTION\nexits: %d %d %d %d, flags: %d\n", junc->ExitIdx[0], junc->ExitIdx[1], junc->ExitIdx[2], junc->ExitIdx[3], junc->flags); - } - */ } // decompiled code @@ -2966,20 +2880,16 @@ void UpdatePlayerInformation(void) int CurrentPlayerView = 0; -// [D] +// [D] [T] void RenderGame2(int view) { - int iVar2; - POLY_F4 *poly; - uint uVar3; - unsigned char uVar4; - char *pcVar5; - _PLAYER *pPVar6; - int iVar7; + POLY_F4* poly; + int fadeColour; + int i; int notInDreaAndStevesEvilLair; CurrentPlayerView = view; - InitCamera((_PLAYER *)(player + view)); + InitCamera((_PLAYER*)(player + view)); #ifndef PSX int screenW, screenH; @@ -3014,54 +2924,56 @@ void RenderGame2(int view) SetupDrawMapPSX(); - if (gLoadedMotionCapture != 0) + if (gLoadedMotionCapture != 0) DrawAllPedestrians(); + // do a lot of stuff DisplayMissionTitle(); DrawInGameCutscene(); + DrawEvents(1); + Set_Inv_CameraMatrix(); SetCameraVector(); SetupDrawMapPSX(); DrawDrivingGames(); DrawThrownBombs(); AddGroundDebris(); + DrawEvents(0); - current->ot = current->ot + 10; + current->ot += 10; DrawSmashable_sprites(); HandleDebris(); - current->ot = current->ot + -10; + current->ot -= 10; DrawAllExplosions(); - if (AttractMode != 0) + if (AttractMode != 0) { - uVar3 = CameraCnt & 0x1f; + int colour; + colour = CameraCnt & 0x1f; - if (0xf < uVar3) - uVar3 = 0x20 - uVar3; + if (colour > 15) + colour = 32 - colour; - SetTextColour((uVar3 & 0x1f) << 3, 0, 0); - PrintString("DEMO", 0x23, 0xf); + SetTextColour((colour & 0x1f) << 3, 0, 0); + PrintString("DEMO", 32, 15); } - pPVar6 = player; - iVar7 = 2; - + i = 0; do { - if (pPVar6->playerCarId != -1 && - CarHasSiren(car_data[pPVar6->playerCarId].ap.model) != 0 && - pPVar6->horn.on != 0) + if (player[i].playerCarId >= 0 && + CarHasSiren(car_data[player[i].playerCarId].ap.model) != 0 && + player[i].horn.on != 0) { - AddCopCarLight(car_data + pPVar6->playerCarId); + AddCopCarLight(&car_data[player[i].playerCarId]); } - - iVar7--; - pPVar6++; - } while (-1 < iVar7); + + i++; + } while (i < 2); if (gLoadedOverlay != 0) DisplayOverlays(); @@ -3071,21 +2983,22 @@ void RenderGame2(int view) if (FastForward == 0 && NumPlayers == 1) DrawLensFlare(); - uVar4 = (unsigned char)(gDieWithFade << 4); - - if (gDieWithFade != 0) + // Retro calls this BSOD... + if (gDieWithFade != 0) { - if (0xff < gDieWithFade << 4) - uVar4 = -1; + fadeColour = (gDieWithFade << 4); - poly = (POLY_F4 *)current->primptr; + if (gDieWithFade << 4 > 255) + fadeColour = 255; + + poly = (POLY_F4*)current->primptr; setPolyF4(poly); setSemiTrans(poly, 1); - poly->r0 = uVar4; - poly->g0 = uVar4; - poly->b0 = uVar4; + poly->r0 = fadeColour; + poly->g0 = fadeColour; + poly->b0 = fadeColour; #ifdef PSX setXYWH(poly, 0, 0, 320, 256); @@ -3111,16 +3024,21 @@ void RenderGame2(int view) current->primptr += sizeof(POLY_FT3); } - notInDreaAndStevesEvilLair = Havana3DOcclusion(DrawMapPSX, (int *)&ObjectDrawnValue); + notInDreaAndStevesEvilLair = Havana3DOcclusion(DrawMapPSX, (int*)&ObjectDrawnValue); ScaleCamera(); - if ((notInDreaAndStevesEvilLair != 0) && (DrawSkyDome(), 40000 < (int)(current->primtab + -(int)(current->primptr- PRIMTAB_SIZE)))) + if (notInDreaAndStevesEvilLair != 0) { - DoWeather(gWeather); + DrawSkyDome(); + + if (current->primtab - (current->primptr - PRIMTAB_SIZE) > 40000) + { + DoWeather(gWeather); + } } - if (37000 < (int)(current->primtab + -(int)(current->primptr - PRIMTAB_SIZE))) + if (current->primtab - (current->primptr - PRIMTAB_SIZE) > 37000) { DrawTyreTracks(); } @@ -3194,7 +3112,7 @@ void RenderGame2(int view) /* WARNING: Unknown calling convention yet parameter storage is locked */ -// [D] +// [D] [T] void RenderGame(void) { UpdatePadData(); @@ -3232,14 +3150,14 @@ void RenderGame(void) /* WARNING: Unknown calling convention yet parameter storage is locked */ -// [D] +// [D] [T] void InitGameVariables(void) { InitDebris(); InitTyreTracks(); TargetCar = 0; - if (NewLevel != 0) + if (NewLevel != 0) { gLoadedOverlay = 0; gLoadedMotionCapture = 0; @@ -3268,7 +3186,7 @@ void InitGameVariables(void) FrameCnt = 0; CameraCnt = 0; - ClearMem((char *)&lightsOnDelay, sizeof(lightsOnDelay)); + ClearMem((char*)&lightsOnDelay, sizeof(lightsOnDelay)); PlayerStartInfo[0] = &ReplayStreams[0].SourceType; @@ -3277,7 +3195,7 @@ void InitGameVariables(void) if (gCutsceneAsReplay == 0) { #endif - ClearMem((char *)PlayerStartInfo[0], sizeof(STREAM_SOURCE)); + ClearMem((char*)PlayerStartInfo[0], sizeof(STREAM_SOURCE)); PlayerStartInfo[0]->type = 1; PlayerStartInfo[0]->model = defaultPlayerModel[0]; @@ -3296,14 +3214,14 @@ void InitGameVariables(void) if (NumPlayers == 2) { PlayerStartInfo[1] = &ReplayStreams[1].SourceType; - ClearMem((char *)PlayerStartInfo[1], sizeof(STREAM_SOURCE)); + ClearMem((char*)PlayerStartInfo[1], sizeof(STREAM_SOURCE)); PlayerStartInfo[1]->type = 1; PlayerStartInfo[1]->model = defaultPlayerModel[1]; PlayerStartInfo[1]->palette = defaultPlayerPalette; PlayerStartInfo[1]->controlType = CONTROL_TYPE_PLAYER; PlayerStartInfo[1]->flags = 0; - + PlayerStartInfo[1]->rotation = levelstartpos[GameLevel][1]; PlayerStartInfo[1]->position.vy = 0; @@ -3363,23 +3281,22 @@ void InitGameVariables(void) /* end block 3 */ // End Line: 11383 -void DealWithHorn(char *hr, int i) +// [D] [T] +void DealWithHorn(char* hr, int i) { unsigned char bVar1; int channel; int modelId; _CAR_DATA* car; + int horn; - channel = player[i].playerCarId; car = &car_data[player[i].playerCarId]; - bVar1 = *hr; - - if (bVar1 == 0) + if (*hr == 0) { return; } - else if (bVar1 == 1) + else if (*hr == 1) { channel = 2; @@ -3388,21 +3305,16 @@ void DealWithHorn(char *hr, int i) StopChannel(channel); } - else if (bVar1 == 2) + else if (*hr == 2) { - bVar1 = car->ap.model; - - if (bVar1 == 4) + if (car->ap.model == 4) modelId = ResidentModelsBodge(); - else if (bVar1 < 3) + else if (car->ap.model < 3) modelId = car->ap.model; else modelId = car->ap.model - 1; - channel = 2; - - if (i != 0) - channel = 5; + channel = i != 0 ? 5 : 2; Start3DSoundVolPitch(channel, 3, modelId * 3 + 2, car->hd.where.t[0], @@ -3410,25 +3322,22 @@ void DealWithHorn(char *hr, int i) car->hd.where.t[2], -10000, 0x1000); - if ((1 < NumPlayers) && (NoPlayerControl == 0)) + if (NumPlayers > 1 && NoPlayerControl == 0) { channel = 2; if (i != 0) channel = 5; - SetPlayerOwnsChannel(channel, (char)i); + SetPlayerOwnsChannel(channel, i); } - channel = 2; - if (i != 0) - channel = 5; + channel = i != 0 ? 5 : 2; - SetChannelPosition3(channel, (VECTOR *)car->hd.where.t, car->st.n.linearVelocity, -2000, i * 8 + 0x1000, 0); + SetChannelPosition3(channel, (VECTOR*)car->hd.where.t, car->st.n.linearVelocity, -2000, i * 8 + 0x1000, 0); } - int horn = *hr + 1 & 0xff; - *hr = (u_char)horn - (((u_char)((long long)horn * 0xaaaaaaab >> 0x20) & 0xfe) + (horn / 3)); + *hr = (*hr + 1) % 3; } @@ -3467,136 +3376,129 @@ void DealWithHorn(char *hr, int i) /* end block 3 */ // End Line: 11431 -// [D] -int Havana3DOcclusion(occlFunc func, int *param) +// [D] [T] [A] Has bugs - some rooms not drawn properly +int Havana3DOcclusion(occlFunc func, int* param) { - bool bVar1; int loop; int draw; - int iVar3; - int iVar4; + int otAltered; int outside; outside = 1; - if ((((GameLevel != 1) || (-0x68fdc < camera_position.vx)) || (camera_position.vx < -0x75416)) - || ((-0x1b8ae < camera_position.vz || (camera_position.vz < -0x20cb3)))) + if (GameLevel == 1 && + camera_position.vx <= -0x68fdc && camera_position.vx >= -0x75416 && + camera_position.vz <= -0x1b8ae && camera_position.vz >= -0x20cb3) { - (*func)(param); - return 1; - } - - draw = 0; - - if (camera_position.vy < 0x1bf) - { - draw = 16; - - if (-469500 < camera_position.vx) - draw = 17; - } - else - { - outside = 0; - - if (((camera_position.vx < -0x6e9e5) && (-0x6fa01 < camera_position.vx)) && - ((camera_position.vz < -0x1e201 && - ((-0x1f205 < camera_position.vz && (camera_position.vy < 0xf73)))))) + draw = 10; + + if (camera_position.vy < 0x1bf) { - if (camera_position.vy < 0x4dd) + if (camera_position.vx > -0x729fc) + draw = 17; + else + draw = 16; + } + else + { + outside = 0; + + if (camera_position.vx < -0x6e9e5 && camera_position.vx > -0x6fa01 && + camera_position.vz < -0x1e201 && camera_position.vz > -0x1f205 && + camera_position.vy < 0xf73) { - LAB_0005c2b4: - draw = 15; - } - else - { - bVar1 = camera_position.vy < 0xc00; - if (camera_position.vy < 0x7d1) + if (camera_position.vy < 0x4dd) + { + draw = 15; + } + else if (camera_position.vy < 0x7d1) { draw = 14; } - else + else if (camera_position.vy < 0xc00) { - LAB_0005c2d8: - if (bVar1) + draw = 13; + } + } + else + { + if (camera_position.vy < 0x6c2) + { + draw = 15; + } + else + { + draw = 14; + + if (camera_position.vy < 0x834 && camera_position.vx < -0x73609) { draw = 13; } + else + { + if ((camera_position.vy > 0xbff && camera_position.vx > -0x6fa01 || + (draw = 12, camera_position.vz < -0x1f9db)) && + (draw = 10, camera_position.vz < -0x1f9dc)) + { + draw = 11; + } + } } } } - else + + events.camera = 1; + + loop = draw - 1; + + if (loop < 10) + loop = 10; + + otAltered = 0; + + while (true) { - if (camera_position.vy < 0x6c2) - goto LAB_0005c2b4; - - draw = 14; - - if (camera_position.vy < 0x834) + if (draw + 1 < loop) { - bVar1 = camera_position.vx < -0x73609; - goto LAB_0005c2d8; + events.camera = 0; + return outside; } - - if ((((0xbff < camera_position.vy) && (-0x6fa01 < camera_position.vx)) || - (draw = 12, camera_position.vz < -0x1f9db)) && - (draw = 10, camera_position.vz < -0x1f9dc)) + + if (loop == 0x10) + break; + + if (draw != loop) { - draw = 11; + otAltered = 200; } + + events.draw = loop; + current->ot += otAltered; + + (*func)(param); + + if (otAltered != 0) + { + current->ot -= otAltered; + otAltered = 0; + } + loop++; + } - } - if(draw > 14) - (*func)(param); - - events.camera = 1; - - loop = draw-1; - - if (loop < 10) - loop = 10; - - iVar3 = 0; - - while (true) - { - if (draw + 1 < loop) + events.camera = 0; + + if (draw == 0xf && camera_position.vx > -0x6fd11) { events.camera = 0; return outside; } - - if (loop == 16) - break; - - if (draw != loop) - { - iVar3 = 200; - } - - events.draw = loop; - current->ot += iVar3; + (*func)(param); - - iVar4 = iVar3; - if (iVar3 != 0) - { - iVar4 = 0; - current->ot -= iVar3;// *0x3fffffff; - } - - loop++; - iVar3 = iVar4; - } - - events.camera = 0; - if ((draw == 15) && (-458001 < camera_position.vx)) - { - events.camera = 0; - return outside; + return 1; } + (*func)(param); return 1; } From f5b79605825543ad975c6025d3030aa8672dd516 Mon Sep 17 00:00:00 2001 From: Ilya Shurumov Date: Sun, 11 Oct 2020 22:14:45 +0600 Subject: [PATCH 29/41] - update AI.C --- src_rebuild/GAME/C/AI.C | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/src_rebuild/GAME/C/AI.C b/src_rebuild/GAME/C/AI.C index 90736d4f..9e7ba784 100644 --- a/src_rebuild/GAME/C/AI.C +++ b/src_rebuild/GAME/C/AI.C @@ -71,33 +71,24 @@ void StoreGameFlags(void) // [D] [T] int TannerCanEnterCar(_CAR_DATA *cp, int distToCarSq) { - int speed; int carRange; - if ((cp->controlFlags & 1) != 0) + if (cp->controlFlags & CONTROL_FLAG_COP) gCopCarTheftAttempted = 1; - if ((cp->controlType == CONTROL_TYPE_CIV_AI || cp->controlType == CONTROL_TYPE_CUTSCENE) && - (cp->controlFlags & 1) == 0 && - (cp->controlFlags & 2) == 0 && + (cp->controlFlags & CONTROL_FLAG_COP) == 0 && + (cp->controlFlags & CONTROL_FLAG_COP_SLEEPING) == 0 && cp->hd.where.m[1][1] > 99) // not flipped over { - speed = FIXEDH(cp->hd.wheel_speed); - - if (speed < 0) - speed = -speed; - - if (speed < 3) + if (ABS(FIXEDH(cp->hd.wheel_speed)) < 3) { carRange = car_cosmetics[cp->ap.model].colBox.vx * 2; if (carRange > 5000) carRange = 5000; - carRange *= carRange; - - return (carRange < distToCarSq) ^ 1; + return (carRange*carRange < distToCarSq) ^ 1; } } @@ -132,9 +123,8 @@ int TannerCanEnterCar(_CAR_DATA *cp, int distToCarSq) // [D] int TannerStuckInCar(int doSpeedCheck, int player_id) { - short *psVar1; + short *playerFelony; int speed; - int iVar3; _CAR_DATA *cp; _PLAYER* lp; @@ -146,15 +136,15 @@ int TannerStuckInCar(int doSpeedCheck, int player_id) { if (lp->playerCarId < 0) { - psVar1 = &pedestrianFelony; + playerFelony = &pedestrianFelony; } else { cp = &car_data[lp->playerCarId]; - psVar1 = &cp->felonyRating; + playerFelony = &cp->felonyRating; } - if ((*psVar1 < 0x293 || player_position_known < 1) && + if ((*playerFelony < 0x293 || player_position_known < 1) && cp && (cp->hd.wheel[1].surface & 7) != 1 && (cp->hd.wheel[3].surface & 7) != 1) From ee8c87c10c8f9308b27a95364f462c3e9d7df6b7 Mon Sep 17 00:00:00 2001 From: Ilya Shurumov Date: Mon, 12 Oct 2020 01:58:33 +0600 Subject: [PATCH 30/41] - [EMU] add real GTE operations to ApplyMatrix* --- src_rebuild/EMULATOR/INLINE_C.H | 13 +++++++++ src_rebuild/EMULATOR/LIBGTE.C | 51 ++++++++++++++++++++++++++++----- 2 files changed, 57 insertions(+), 7 deletions(-) diff --git a/src_rebuild/EMULATOR/INLINE_C.H b/src_rebuild/EMULATOR/INLINE_C.H index 890c35dd..80cee88b 100644 --- a/src_rebuild/EMULATOR/INLINE_C.H +++ b/src_rebuild/EMULATOR/INLINE_C.H @@ -142,6 +142,10 @@ extern int docop2(int op); #define gte_ldrgb( r0 ) \ MTC2(*(uint*)((char*)r0), 6); +// mtc2 8 +#define gte_lddp( r0 ) \ + MTC2(*(uint*)r0, 8); + #if defined(PGXP) // swc2 14 @@ -298,6 +302,15 @@ extern int docop2(int op); gte_rtir(); \ gte_stclmv((char*)r3+4); } +#define gte_LoadAverage12(r1,r2,r3,r4,r5) \ + { gte_lddp(r3); \ + gte_ldlvl(r1); \ + gte_gpf12(); \ + gte_lddp(r4); \ + gte_ldlvl(r2); \ + gte_gpl12(); \ + gte_stlvl(r5); } + // FIXME: there is lack of some macros // please refer to official Psy-Q PSX SDK headers // and this: https://github.com/ogamespec/pops-gte/blob/master/docs/gte.txt diff --git a/src_rebuild/EMULATOR/LIBGTE.C b/src_rebuild/EMULATOR/LIBGTE.C index 4e706e47..f4ca043f 100644 --- a/src_rebuild/EMULATOR/LIBGTE.C +++ b/src_rebuild/EMULATOR/LIBGTE.C @@ -1226,7 +1226,7 @@ long RotAverageNclip4(struct SVECTOR* v0, struct SVECTOR* v1, struct SVECTOR* v2 MATRIX* MulMatrix0(MATRIX* m0, MATRIX* m1, MATRIX* m2) { -#if 0 +#if 1 gte_MulMatrix0(m0, m1, m2); #else /* ‚±‚ê‚Å‚àm0==m2‚ÌŽžƒ„ƒoƒC */ @@ -1311,42 +1311,75 @@ void SetFarColor(long rfc, long gfc, long bfc) VECTOR* ApplyMatrix(MATRIX* m, SVECTOR* v0, VECTOR* v1) { - APPLYMATRIX(m, v0, v1) - return v1; +#if 0 + gte_SetRotMatrix(m); + gte_ldv0(v0); + gte_rtv0(); + gte_stlvl(v1); +#else + APPLYMATRIX(m, v0, v1); +#endif + return v1; } VECTOR* ApplyRotMatrix(SVECTOR* v0, VECTOR* v1) { +#if 0 + gte_ldv0(v0); + gte_rtv0(); + gte_stsv(v1); +#else MATRIX temp; gte_ReadRotMatrix(&temp); MATRIX* m = &temp; APPLYMATRIX(m, v0, v1); +#endif return v1; } VECTOR* ApplyRotMatrixLV(VECTOR* v0, VECTOR* v1) { +#if 0 + gte_ldv0(v0); + gte_rtv0(); + gte_stlvl(v1); +#else MATRIX temp; gte_ReadRotMatrix(&temp); MATRIX* m = &temp; APPLYMATRIX(m, v0, v1); +#endif return v1; } SVECTOR* ApplyMatrixSV(MATRIX* m, SVECTOR* v0, SVECTOR* v1) { - APPLYMATRIX(m, v0, v1) - return v1; +#if 0 + gte_SetRotMatrix(m); + gte_ldv0(v0); + gte_rtv0(); + gte_stsv(v1); +#else + APPLYMATRIX(m, v0, v1); +#endif + return v1; } VECTOR* ApplyMatrixLV(MATRIX* m, VECTOR* v0, VECTOR* v1) { - APPLYMATRIX(m, v0, v1) - return v1; +#if 0 + gte_SetRotMatrix(m); + gte_ldv0(v0); + gte_rtv0(); + gte_stlvl(v1); +#else + APPLYMATRIX(m, v0, v1); +#endif + return v1; } MATRIX* RotMatrix(struct SVECTOR* r, MATRIX* m) @@ -1523,6 +1556,9 @@ MATRIX* RotMatrixZ(long r, MATRIX* m) MATRIX* RotMatrixZYX_gte(SVECTOR* r, MATRIX* m) { +#if 0 + // by disassembly there is two gte_LoadAverage12 calls +#else // FIXME: make a proper function m->m[0][0] = 0x1000; m->m[0][1] = 0; @@ -1539,6 +1575,7 @@ MATRIX* RotMatrixZYX_gte(SVECTOR* r, MATRIX* m) RotMatrixX(r->vx, m); RotMatrixY(r->vy, m); RotMatrixZ(r->vz, m); +#endif return m; } From 95c99842a7b22c14b00a49433567635cfaed2f96 Mon Sep 17 00:00:00 2001 From: Ilya Shurumov Date: Mon, 12 Oct 2020 01:58:53 +0600 Subject: [PATCH 31/41] - DRAW.C refactoring progress --- src_rebuild/GAME/C/DRAW.C | 1162 +++++++++++-------------------------- 1 file changed, 352 insertions(+), 810 deletions(-) diff --git a/src_rebuild/GAME/C/DRAW.C b/src_rebuild/GAME/C/DRAW.C index ddf8a25a..e0851659 100644 --- a/src_rebuild/GAME/C/DRAW.C +++ b/src_rebuild/GAME/C/DRAW.C @@ -20,13 +20,13 @@ #include MATRIX aspect = -{ - { - { 6553, 0, 0 }, - { 0, 4096, 0 }, - { 0, 0, 4096 } - }, - { 0, 0, 0 } +{ + { + { 6553, 0, 0 }, + { 0, 4096, 0 }, + { 0, 0, 4096 } + }, + { 0, 0, 0 } }; MATRIX identity = @@ -94,8 +94,7 @@ MATRIX inv_camera_matrix; MATRIX face_camera; MATRIX2 CompoundMatrix[64]; - -uint farClip2Player = 0x8ca0; +uint farClip2Player = 36000; static int treecount = 0; int numSpritesFound = 0; @@ -112,9 +111,9 @@ int buildingsFound = 0; CELL_OBJECT* model_object_ptrs[512]; CELL_OBJECT* anim_obj_buffer[20]; -unsigned long *tile_overflow_buffer; +unsigned long* tile_overflow_buffer; -PACKED_CELL_OBJECT *spriteList[75]; +PACKED_CELL_OBJECT* spriteList[75]; #ifndef PSX OUT_CELL_FILE_HEADER cell_header; @@ -158,70 +157,20 @@ _pct plotContext; MVERTEX MVERTEX_ARRAY_1f800228[5][5]; // [D] [A] -void addSubdivSpriteShadow(POLYFT4*src, SVECTOR *verts, int z) +void addSubdivSpriteShadow(POLYFT4* src, SVECTOR* verts, int z) { - uint puVar1; - uint uVar2; - uint uVar3; - uint uVar4; int m; m = 4; - uVar3 = *(uint *)&src->v0; plotContext.colour = 0x2e000000; + plotContext.flags = 0x2; + plotContext.clut = texture_cluts[src->texture_set][src->texture_id] << 0x10; + plotContext.tpage = texture_pages[src->texture_set] << 0x10; + if (z > 3200) + m = 1; //2; - plotContext.clut = texture_cluts[src->texture_set][src->texture_id];// << 0x10; - plotContext.tpage = (texture_pages[src->texture_set]);// << 0x10; - - if (3200 < z) - m = 2; - -#if 1 // [A] this is temporary code to draw shadow sprites - { - gte_ldv3(&verts[src->v0], &verts[src->v1], &verts[src->v2]); - - gte_rtpt(); - - int ZZ; - gte_stopz(&ZZ); - - gte_avsz3(); - - int Z; - gte_stotz(&Z); - - if (0 < Z && ZZ < 0) - { - POLY_FT4* poly = (POLY_FT4*)plotContext.primptr; - - *(uint*)&poly->r0 = plotContext.colour; - - setPolyFT4(poly); - setSemiTrans(poly, 1); - - poly->clut = plotContext.clut; - poly->tpage = plotContext.tpage; - - gte_stsxy3(&poly->x0, &poly->x1, &poly->x3); - - gte_ldv0(&verts[src->v3]); - gte_rtps(); - - gte_stsxy(&poly->x2); - - *(u_short*)&poly->u0 = *(u_short*)&src->uv1; - *(u_short*)&poly->u1 = *(u_short*)&src->uv0; - *(u_short*)&poly->u2 = *(u_short*)&src->uv2; - *(u_short*)&poly->u3 = *(u_short*)&src->uv3; - - addPrim(plotContext.ot + (Z >> 1) , poly); - - plotContext.primptr += sizeof(POLY_FT4); - } - } -#else plotContext.ot += 28; copyVector(&MVERTEX_ARRAY_1f800228[0][0], &verts[src->v0]); @@ -238,11 +187,8 @@ void addSubdivSpriteShadow(POLYFT4*src, SVECTOR *verts, int z) makeMesh((MVERTEX(*)[5][5])MVERTEX_ARRAY_1f800228, m, m); drawMesh((MVERTEX(*)[5][5])MVERTEX_ARRAY_1f800228, m, m, &plotContext); - + plotContext.ot -= 28; -#endif - - } @@ -340,35 +286,25 @@ void addSubdivSpriteShadow(POLYFT4*src, SVECTOR *verts, int z) MATRIX shadowMatrix; - -// [D] [A] +// [D] [T] [A] void DrawSprites(int numFound) { - ushort *puVar1; - short sVar2; - short *psVar3; + int i; int z; - uint *puVar4; - uint *puVar5; uint spriteColour; + uint lightdd; unsigned char lightLevel; - MATRIX *pMVar7; - MATRIX *pMVar8; - uint uVar9; - int iVar10; - uint uVar11; - int iVar12; - MODEL *model; - PACKED_CELL_OBJECT *pco; - PACKED_CELL_OBJECT **local_40; - int local_38; - int local_2c; + MODEL* model; + PACKED_CELL_OBJECT* pco; + PACKED_CELL_OBJECT** list; + int numShadows; + int count; - z = FIXEDH(camera_matrix.m[2][0] * day_vectors[GameLevel].vx) + + lightdd = FIXEDH(camera_matrix.m[2][0] * day_vectors[GameLevel].vx) + FIXEDH(camera_matrix.m[2][1] * day_vectors[GameLevel].vy) + FIXEDH(camera_matrix.m[2][2] * day_vectors[GameLevel].vz) + 0x1000 * 0xc00; - lightLevel = (z >> 0x12) + 0x20U & 0xff; + lightLevel = (lightdd >> 0x12) + 0x20U & 0xff; if (gWeather > 0 && gTimeOfDay == 1) { @@ -385,97 +321,93 @@ void DrawSprites(int numFound) } else if (gTimeOfDay == 3) { - if(GameLevel == 0) - lightLevel = lightLevel * 2; // [A] level bug - Chicago trees lit wrong + if (GameLevel == 0) + lightLevel *= 2; // [A] level bug - Chicago trees lit wrong else - lightLevel = lightLevel / 3; + lightLevel /= 3; } - spriteColour = lightLevel << 0x10 | lightLevel << 8 | 0x2c000000 | lightLevel; - - pMVar8 = &inv_camera_matrix; - pMVar7 = &shadowMatrix; - z = 2; + i = 2; do { - shadowMatrix.m[z][0] = inv_camera_matrix.m[z][2]; - shadowMatrix.m[z][1] = -inv_camera_matrix.m[z][0]; - shadowMatrix.m[z][2] = inv_camera_matrix.m[z][0]; - z--; - } while (-1 < z); + shadowMatrix.m[i][0] = inv_camera_matrix.m[i][2]; + shadowMatrix.m[i][1] = -inv_camera_matrix.m[i][0]; + shadowMatrix.m[i][2] = inv_camera_matrix.m[i][0]; + i--; + } while (i >= 0); + - local_38 = 0; plotContext.primptr = current->primptr; plotContext.ptexture_pages = (ushort(*)[128])texture_pages; plotContext.ptexture_cluts = (ushort(*)[128][32])texture_cluts; plotContext.ot = current->ot; - local_40 = spriteList; + list = spriteList; plotContext.colour = spriteColour; plotContext.current = current; - local_2c = numFound - 1; - while (local_2c != -1) + numShadows = 0; + count = numFound - 1; + + while (count != -1) { - pco = *local_40; - local_40++; + pco = *list; + list++; int modelnumber = (pco->value >> 6) | (pco->pos.vy & 1) << 10; model = modelpointers[modelnumber]; plotContext.colour = spriteColour; - if ((pco->value & 0x3f) == 0x3f || (gTimeOfDay == 3 && modelnumber == 945)) // [A] Vegas tree fix + if ((pco->value & 0x3f) == 63 || (gTimeOfDay == 3 && modelnumber == 945)) // [A] Vegas tree fix plotContext.colour = 0x2c808080; plotContext.scribble[0] = pco->pos.vx; plotContext.scribble[1] = (pco->pos.vy << 0x10) >> 0x11; plotContext.scribble[2] = pco->pos.vz; - z = Apply_InvCameraMatrixAndSetMatrix((VECTOR_NOPAD *)plotContext.scribble, (MATRIX2 *)&face_camera); -#if 0 - if(z < 1001) - { - uVar11 = (uint)model->num_polys; - iVar10 = model->poly_block; - iVar12 = model->vertices; + z = Apply_InvCameraMatrixAndSetMatrix((VECTOR_NOPAD*)plotContext.scribble, (MATRIX2*)&face_camera); - while (uVar11 = uVar11 - 1, uVar11 != 0xffffffff) + if (z < 1000) + { + POLYFT4* src; + SVECTOR* verts; + int numPolys; + + numPolys = (uint)model->num_polys; + src = (POLYFT4*)model->poly_block; + verts = (SVECTOR*)model->vertices; + + plotContext.flags |= 4; + + while (numPolys--, numPolys >= 0) { - UNIMPLEMENTED(); - /* - uVar9 = *(uint *)(iVar10 + 4); - plotContext.clut =(uint)(ushort)texture_cluts[(uint)*(unsigned char *)(iVar10 + 1) * 0x20 + (uint)*(unsigned char *)(iVar10 + 2)] << 0x10; - puVar4 = (uint *)((uVar9 & 0xff) * 8 + iVar12); - plotContext.tpage = (uint)(ushort)texture_pages[(uint)*(unsigned char *)(iVar10 + 1)] << 0x10; - MVERTEX_ARRAY_1f800228[0]_0_4_ = *puVar4; - puVar5 = (uint *)((uVar9 >> 5 & 0x7f8) + iVar12); - MVERTEX_ARRAY_1f800228[0]._4_4_ = - puVar4[1] & 0xffff | (uint)*(ushort *)(iVar10 + 8) << 0x10; - MVERTEX_ARRAY_1f800228[4]._0_4_ = *puVar5; - puVar4 = (uint *)((uVar9 >> 0x18) * 8 + iVar12); - MVERTEX_ARRAY_1f800228[4]._4_4_ = - puVar5[1] & 0xffff | (uint)*(ushort *)(iVar10 + 10) << 0x10; - MVERTEX_ARRAY_1f800228[20]._0_4_ = *puVar4; - puVar5 = (uint *)((uVar9 >> 0xd & 0x7f8) + iVar12); - MVERTEX_ARRAY_1f800228[20]._4_4_ = - puVar4[1] & 0xffff | (uint)*(ushort *)(iVar10 + 0xe) << 0x10; - MVERTEX_ARRAY_1f800228[24]._0_4_ = *puVar5; - puVar1 = (ushort *)(iVar10 + 0xc); - iVar10 = iVar10 + 0x14; - MVERTEX_ARRAY_1f800228[24]._4_4_ = puVar5[1] & 0xffff | (uint)*puVar1 << 0x10; + plotContext.clut = texture_cluts[src->texture_set][src->texture_id] << 0x10; + plotContext.tpage = texture_pages[src->texture_set] << 0x10; + + copyVector(&MVERTEX_ARRAY_1f800228[0][0], &verts[src->v0]); + MVERTEX_ARRAY_1f800228[0][0].uv.val = *(ushort*)&src->uv0; + + copyVector(&MVERTEX_ARRAY_1f800228[0][1], &verts[src->v1]); + MVERTEX_ARRAY_1f800228[0][1].uv.val = *(ushort*)&src->uv1; + + copyVector(&MVERTEX_ARRAY_1f800228[0][2], &verts[src->v3]); + MVERTEX_ARRAY_1f800228[0][2].uv.val = *(ushort*)&src->uv3; + + copyVector(&MVERTEX_ARRAY_1f800228[0][3], &verts[src->v2]); + MVERTEX_ARRAY_1f800228[0][3].uv.val = *(ushort*)&src->uv2; makeMesh((MVERTEX(*)[5][5])MVERTEX_ARRAY_1f800228, 4, 4); - drawMesh((MVERTEX(*)[5][5])MVERTEX_ARRAY_1f800228, 4, 4, (_pct *)&plotContext); - */ + drawMesh((MVERTEX(*)[5][5])MVERTEX_ARRAY_1f800228, 4, 4, &plotContext); + + src++; } + + plotContext.flags &= ~4; } - else -#else - if (z > 0) -#endif + else { plotContext.ot -= 133; @@ -484,21 +416,20 @@ void DrawSprites(int numFound) plotContext.ot += 133; } - local_2c--; + count--; - if ((((wetness == 0) && (gTimeOfDay != 3)) && ((pco->value & 0x20) == 0)) && - ((z < 7000 && (local_38 = local_38 + 1, local_38 < 0x28)))) + if (wetness == 0 && gTimeOfDay != 3 && (pco->value & 0x20) == 0 && z < 7000 && numShadows < 40) { gte_SetRotMatrix(&shadowMatrix); - addSubdivSpriteShadow((POLYFT4*)model->poly_block, (SVECTOR *)model->vertices, z); + addSubdivSpriteShadow((POLYFT4*)model->poly_block, (SVECTOR*)model->vertices, z); if (model->num_polys == 2) - { - addSubdivSpriteShadow((POLYFT4*)(model->poly_block + sizeof(POLYFT4)), (SVECTOR *)model->vertices, z); - } + addSubdivSpriteShadow((POLYFT4*)(model->poly_block + sizeof(POLYFT4)), (SVECTOR*)model->vertices, z); gte_SetRotMatrix(&face_camera); + + numShadows++; } } current->primptr = plotContext.primptr; @@ -717,27 +648,17 @@ void DrawSprites(int numFound) // End Line: 1981 // [D] -void DrawMapPSX(int *comp_val) +void DrawMapPSX(int* comp_val) { ushort uVar1; - CELL_OBJECT *pCVar2; - uint uVar4; - PACKED_CELL_OBJECT *ppco; - CELL_OBJECT **ppCVar6; + PACKED_CELL_OBJECT* ppco; int iVar7; - PACKED_CELL_OBJECT **ppPVar8; uint uVar9; int cellx; int cellz; - CELL_OBJECT *cop; - //undefined4 uVar10; - long lVar11; - //undefined4 uVar12; - long lVar13; - //undefined4 uVar14; - long lVar15; - MODEL *model; + CELL_OBJECT* cop; + MODEL* model; int iVar19; int iVar20; uint backPlane; @@ -746,7 +667,7 @@ void DrawMapPSX(int *comp_val) VECTOR newpos; int camx; int camz; - char *PVS_ptr; + char* PVS_ptr; int tiles_found; int other_models_found; int rightcos; @@ -757,30 +678,33 @@ void DrawMapPSX(int *comp_val) int backsin; int rightPlane; int leftPlane; - uint farClipLimit; - + int farClipLimit; + int backAng; + int leftAng; + int rightAng; + int local_34; int anim_objs; - backPlane = 0x1800; // backPlane - rightPlane = -0x1800; - leftPlane = 0x1800; + backPlane = 6144; + rightPlane = -6144; + leftPlane = 6144; - iVar7 = (int)camera_angle.vy; farClipLimit = 80000; - uVar9 = iVar7 - FrAng & 0xfff; - uVar4 = iVar7 + FrAng & 0xfff; - rightcos = (int)rcossin_tbl[uVar9 * 2 + 1]; - rightsin = (int)rcossin_tbl[uVar9 * 2]; + rightAng = camera_angle.vy - FrAng & 0xfff; + leftAng = camera_angle.vy + FrAng & 0xfff; + backAng = camera_angle.vy + 0x400U & 0xfff; - uVar9 = iVar7 + 0x400U & 0xfff; - leftcos = (int)rcossin_tbl[uVar4 * 2 + 1]; - leftsin = (int)rcossin_tbl[uVar4 * 2]; - backcos = (int)rcossin_tbl[uVar9 * 2 + 1]; - backsin = (int)rcossin_tbl[uVar9 * 2]; + rightcos = rcossin_tbl[rightAng * 2 + 1]; + rightsin = rcossin_tbl[rightAng * 2]; - if (NumPlayers == 2) + leftcos = rcossin_tbl[leftAng * 2 + 1]; + leftsin = rcossin_tbl[leftAng * 2]; + backcos = rcossin_tbl[backAng * 2 + 1]; + backsin = rcossin_tbl[backAng * 2]; + + if (NumPlayers == 2) { farClipLimit = farClip2Player; } @@ -805,32 +729,33 @@ void DrawMapPSX(int *comp_val) ClearCopUsage(); + PVS_ptr = CurrentPVS + 220; + iVar20 = 0; iVar19 = 0; - PVS_ptr = CurrentPVS + 220; uVar4 = 0; - if (NumPlayers == 2) + if (NumPlayers == 2) uVar9 = goFaster & 31 | 1; else uVar9 = goFaster & 31; local_34 = (gDrawDistance >> uVar9) - 1; // [A] - do + do { while (true) { while (true) { - if (local_34 == -1) + if (local_34 == -1) { if (numSpritesFound != 0) { DrawSprites(numSpritesFound); } - if (tiles_found != 0) + if (tiles_found != 0) { DrawTILES(tiles_found); } @@ -866,18 +791,18 @@ void DrawMapPSX(int *comp_val) cellz = iVar20; - if (iVar20 < 0) + if (iVar20 < 0) cellz = -iVar20; local_34--; - if (cellx + cellz < 16) // < 16) + if (cellx + cellz < 16) { cellx = camx + iVar19; cellz = camz + iVar20; - if( rightPlane < 0 && - leftPlane > 0 && + if (rightPlane < 0 && + leftPlane > 0 && backPlane < farClipLimit && // check planes cellx > -1 && cellx < cells_across && // check cell ranges cellz > -1 && cellz < cells_down && @@ -887,72 +812,16 @@ void DrawMapPSX(int *comp_val) while (ppco != NULL) { - model = modelpointers[(ppco->value >> 6) | ((uint)(ppco->pos).vy & 1) << 10]; + model = modelpointers[(ppco->value >> 6) | ((ppco->pos).vy & 1) << 10]; if (FrustrumCheck16(ppco, model->bounding_sphere) != -1) { - uVar1 = model->shape_flags; - - if ((uVar1 & 0x4000) == 0) - { - uVar9 = (uint)ppco->value & 0x3f; - - if ((ppco->value & 0xf) != 0) - { - if ((int)CompoundMatrix[uVar9].computed != current_object_computed_value) - { - CompoundMatrix[uVar9].computed = (short)current_object_computed_value; - - gte_ReadRotMatrix(&mRotStore); - - gte_sttr(mRotStore.t); - - MulMatrix0(&inv_camera_matrix, (MATRIX *)(matrixtable + uVar9), (MATRIX *)(CompoundMatrix + uVar9)); - - gte_SetRotMatrix(&mRotStore); - //TRX = pMVar3->t[0]; - //TRY = pMVar3->t[1]; ?? - //TRZ = pMVar3->t[2]; - } - } - - if (((uVar1 & 0x480) == 0) && ((model->flags2 & 0xc000) == 0)) - { - cop = UnpackCellObject(ppco, &ci.nearCell); - - - if (((model->flags2 & 1) != 0) && (anim_objs < 20)) - { - anim_obj_buffer[anim_objs++] = cop; - } - - if (other_models_found < 192) - model_object_ptrs[other_models_found++] = cop; - } - else - { - if (((model->flags2 & 0x80) != 0) && (alleycount++, alleycount == 13)) - { - cop = UnpackCellObject(ppco, &ci.nearCell); - ground_debris[groundDebrisIndex++] = *cop; - groundDebrisIndex = groundDebrisIndex % 16; - - alleycount = 0; - } - - if (tiles_found < 0x100) - { - *(PACKED_CELL_OBJECT **)(tile_overflow_buffer + tiles_found) = ppco; - tiles_found++; - } - } - } - else + if (model->shape_flags & 0x4000) { if (numSpritesFound < 75) spriteList[numSpritesFound++] = ppco; - if (((model->flags2 & 1) != 0) && (anim_objs < 20)) + if ((model->flags2 & 1) && anim_objs < 20) { cop = UnpackCellObject(ppco, &ci.nearCell); @@ -962,10 +831,66 @@ void DrawMapPSX(int *comp_val) if (((model->flags2 & 0x2000) != 0) && (uVar9 = treecount & 0xf, treecount++, uVar9 == 0)) { cop = UnpackCellObject(ppco, &ci.nearCell); + ground_debris[groundDebrisIndex++] = *cop; groundDebrisIndex = groundDebrisIndex % 16; } } + else + { + uVar9 = ppco->value & 0x3f; + + if ((ppco->value & 0xf) != 0) + { + if (CompoundMatrix[uVar9].computed != current_object_computed_value) + { + CompoundMatrix[uVar9].computed = current_object_computed_value; + + gte_ReadRotMatrix(&mRotStore); + + gte_sttr(mRotStore.t); + + MulMatrix0(&inv_camera_matrix, (MATRIX*)(matrixtable + uVar9), (MATRIX*)(CompoundMatrix + uVar9)); + + gte_SetRotMatrix(&mRotStore); + } + } + + if ((model->shape_flags & 0x480) || (model->flags2 & 0xc000)) + { + if(model->flags2 & 0x80) + { + alleycount++; + + if (alleycount == 13) + { + cop = UnpackCellObject(ppco, &ci.nearCell); + ground_debris[groundDebrisIndex++] = *cop; + groundDebrisIndex = groundDebrisIndex % 16; + + alleycount = 0; + } + } + + if (tiles_found < 256) + { + *(PACKED_CELL_OBJECT**)(tile_overflow_buffer + tiles_found) = ppco; + tiles_found++; + } + } + else + { + cop = UnpackCellObject(ppco, &ci.nearCell); + + if ((model->flags2 & 1) && (anim_objs < 20)) + { + anim_obj_buffer[anim_objs++] = cop; + } + + if (other_models_found < 192) + model_object_ptrs[other_models_found++] = cop; + } + } } ppco = GetNextPackedCop(&ci); @@ -973,7 +898,7 @@ void DrawMapPSX(int *comp_val) } } - if (uVar4 != 1) + if (uVar4 != 1) break; leftPlane += leftsin; @@ -997,8 +922,8 @@ void DrawMapPSX(int *comp_val) rightPlane += rightcos; iVar19++; - - if (iVar19 + iVar20 == 1) + + if (iVar19 + iVar20 == 1) uVar4 = 1; } else @@ -1023,7 +948,7 @@ void DrawMapPSX(int *comp_val) backPlane -= backcos; rightPlane -= rightcos; - if (iVar19 + iVar20 == 0) + if (iVar19 + iVar20 == 0) uVar4 = 3; } while (true); } @@ -1065,20 +990,21 @@ void DrawMapPSX(int *comp_val) /* end block 4 */ // End Line: 2710 -// [D] +// [D] [T] void SetupPlaneColours(ulong ambient) { unsigned long r; unsigned long g; unsigned long b; - if ((gWeather - 1U > 1) && gTimeOfDay != 0 && gTimeOfDay != 2) + if ((gWeather - 1U > 1) && gTimeOfDay != 0 && gTimeOfDay != 2) { - if (gTimeOfDay == 1) + if (gTimeOfDay == 1) { b = ambient & 0xff; g = ambient >> 8 & 0xff; r = ambient >> 0x10 & 0xff; + planeColours[1] = (r * 0x78 >> 7) << 0x10 | (g * 0x78 >> 7) << 8 | b * 0x78 >> 7; planeColours[2] = (r * 0x67 >> 7) << 0x10 | (g * 0x67 >> 7) << 8 | b * 0x67 >> 7; planeColours[3] = (r * 0xd >> 5) << 0x10 | (g * 0xd >> 5) << 8 | b * 0xd >> 5; @@ -1162,10 +1088,10 @@ void SetupPlaneColours(ulong ambient) /* WARNING: Unknown calling convention yet parameter storage is locked */ -// [D] +// [D] [T] void SetupDrawMapPSX(void) { - int region_x1; + int region_x1; int region_z1; int current_barrel_region_x1; int current_barrel_region_z1; @@ -1184,7 +1110,7 @@ void SetupDrawMapPSX(void) GetPVSRegionCell2( current_barrel_region_x1 + current_barrel_region_z1 * 2, region_x1 + region_z1 * cells_across / 32, - (current_cell_z % 32) * 32 + (current_cell_x % 32), + (current_cell_z % 32) * 32 + (current_cell_x % 32), CurrentPVS); for (theta = 0; theta < 64; theta++) @@ -1221,27 +1147,30 @@ void SetupDrawMapPSX(void) MATRIX frustrum_matrix; -// [D] +// [D] [T] void InitFrustrumMatrix(void) { - int iVar1; - uint a; - - frustrum_matrix.m[0][1] = 0; - frustrum_matrix.m[0][0] = rcossin_tbl[(-(int)camera_angle.vy & 0xfffU) * 2]; - iVar1 = rcos(-(int)camera_angle.vy); - frustrum_matrix.m[0][2] = (short)iVar1; - frustrum_matrix.m[1][1] = 0; - a = (FrAng + -0x400) - (int)camera_angle.vy; - frustrum_matrix.m[1][0] = rcossin_tbl[(a & 0xfff) * 2]; - iVar1 = rcos(a); - frustrum_matrix.m[1][2] = (short)iVar1; - frustrum_matrix.m[2][1] = 0; - a = -(FrAng + -0x400) - (int)camera_angle.vy; - frustrum_matrix.m[2][0] = rcossin_tbl[(a & 0xfff) * 2]; - iVar1 = rcos(a); - frustrum_matrix.m[2][2] = (short)iVar1; - frustrum_matrix.t[0] = -0x50; + int iVar1; + int a; + + a = -camera_angle.vy; + + frustrum_matrix.m[0][1] = 0; + frustrum_matrix.m[0][0] = rcossin_tbl[(a & 0xfffU) * 2]; + frustrum_matrix.m[0][2] = rcossin_tbl[(a & 0xfffU) * 2 + 1]; + + a = (FrAng - 1024) - camera_angle.vy; + + frustrum_matrix.m[1][1] = 0; + frustrum_matrix.m[1][0] = rcossin_tbl[(a & 0xfff) * 2]; + frustrum_matrix.m[1][2] = rcossin_tbl[(a & 0xfff) * 2 + 1]; + + a = -(FrAng - 1024) - camera_angle.vy; + + frustrum_matrix.m[2][1] = 0; + frustrum_matrix.m[2][0] = rcossin_tbl[(a & 0xfff) * 2]; + frustrum_matrix.m[2][2] = rcossin_tbl[(a & 0xfff) * 2 + 1]; + frustrum_matrix.t[0] = -80; } @@ -1267,9 +1196,7 @@ void InitFrustrumMatrix(void) /* WARNING: Unknown calling convention yet parameter storage is locked */ -// TODO: INLINE_C or GTEMAC - -// [D] +// [D] [T] void SetFrustrumMatrix(void) { gte_SetLightMatrix(&frustrum_matrix); @@ -1291,7 +1218,7 @@ void SetFrustrumMatrix(void) /* WARNING: Unknown calling convention yet parameter storage is locked */ -// [D] +// [D] [T] void Set_Inv_CameraMatrix(void) { gte_SetColorMatrix(&inv_camera_matrix); @@ -1332,11 +1259,10 @@ void Set_Inv_CameraMatrix(void) /* WARNING: Unknown calling convention yet parameter storage is locked */ -// [D] [A] +// [D] [T] [A] void CalcObjectRotationMatrices(void) { int i; - MATRIX mat; int angle; MATRIX* m; @@ -1378,10 +1304,10 @@ void CalcObjectRotationMatrices(void) /* end block 3 */ // End Line: 5024 -// [D] -void PlotMDL_less_than_128(MODEL *model) +// [D] [T] +void PlotMDL_less_than_128(MODEL* model) { - RenderModel(model, (MATRIX *)0x0, (VECTOR *)0x0, 0, 0, 0); + RenderModel(model, (MATRIX*)0x0, (VECTOR*)0x0, 0, 0, 0); } @@ -1412,17 +1338,17 @@ void PlotMDL_less_than_128(MODEL *model) // End Line: 3358 -// [D] -void ProcessMapLump(char *lump_ptr, int lump_size) +// [D] [T] +void ProcessMapLump(char* lump_ptr, int lump_size) { #ifdef PSX - cells_across = *(int *)lump_ptr; - cells_down = *(int *)(lump_ptr + 4); - num_regions = *(int *)(lump_ptr + 0xc); + cells_across = *(int*)lump_ptr; + cells_down = *(int*)(lump_ptr + 4); + num_regions = *(int*)(lump_ptr + 0xc); view_dist = 10; pvs_square = 21; - pvs_square_sq = 21*21; + pvs_square_sq = 21 * 21; units_across_halved = cells_across / 2 << 0xb; units_down_halved = cells_down / 2 << 0xb; @@ -1442,13 +1368,13 @@ void ProcessMapLump(char *lump_ptr, int lump_size) trap(0x400); } } - num_straddlers = *(int *)(lump_ptr + 0x2c); - if (*(int *)(lump_ptr + 8) != 0x800) { + num_straddlers = *(int*)(lump_ptr + 0x2c); + if (*(int*)(lump_ptr + 8) != 0x800) { while (FrameCnt != 0x78654321) { trap(0x400); } } - if (*(int *)(lump_ptr + 0x10) != 0x20) { + if (*(int*)(lump_ptr + 0x10) != 0x20) { while (FrameCnt != 0x78654321) { trap(0x400); } @@ -1572,137 +1498,98 @@ void ProcessMapLump(char *lump_ptr, int lump_size) int gForceLowDetailCars = 0; int num_cars_drawn = 0; -// [A] +// [D] [T] void DrawAllTheCars(int view) { static int car_distance[20]; // offset 0x0 - static int temp; // offset 0x0 + int dx, dz; + int dist; + int i, j; + _CAR_DATA* cp; + int num_cars_to_draw; + int spacefree; + _CAR_DATA* cars_to_draw[20]; - long lVar1; - long lVar2; - int iVar3; - int iVar4; - int iVar5; - int *puVar6; - _CAR_DATA **pp_Var7; - _CAR_DATA *p_Var8; - int iVar9; - int *piVar10; - int iVar11; - _CAR_DATA *cars_to_draw[20]; - - lVar2 = camera_position.vz; - lVar1 = camera_position.vx; - p_Var8 = car_data + 18; num_cars_drawn = 0; - iVar11 = 0; + num_cars_to_draw = 0; - - piVar10 = car_distance; - iVar9 = iVar11; + cp = car_data + MAX_CARS - 1; do { - iVar11 = iVar9; - - if ((p_Var8->controlType != CONTROL_TYPE_NONE) && PositionVisible((VECTOR *)p_Var8->hd.where.t)) + if (cp->controlType != CONTROL_TYPE_NONE && + PositionVisible((VECTOR*)cp->hd.where.t)) { // XZ distance estimation - iVar3 = p_Var8->hd.where.t[0]; - iVar5 = lVar1 - iVar3; + dx = ABS(camera_position.vx - cp->hd.where.t[0]); + dz = ABS(camera_position.vz - cp->hd.where.t[2]); - if (iVar5 < 0) - iVar5 = iVar3 - lVar1; - - iVar3 = p_Var8->hd.where.t[2]; - iVar4 = lVar2 - iVar3; - - if (iVar4 < 0) - iVar4 = iVar3 - lVar2; - - if (iVar5 < iVar4) - iVar3 = iVar4 + iVar5 / 2; + if (dx < dz) + dist = dz + dx / 2; else - iVar3 = iVar5 + iVar4 / 2; + dist = dx + dz / 2; - if (iVar3 < 16000) + if (dist < 16000) { - *piVar10 = iVar5 + iVar4; - piVar10 = piVar10 + 1; - iVar11 = iVar9 + 1; - cars_to_draw[iVar9] = p_Var8; + car_distance[num_cars_to_draw] = dx + dz; + cars_to_draw[num_cars_to_draw] = cp; + num_cars_to_draw++; } } - p_Var8 = p_Var8 + -1; - iVar9 = iVar11; + cp--; + } while (cp >= car_data); - } while (p_Var8 >= car_data); - - if (iVar11 != 0) + if (num_cars_to_draw != 0) { gForceLowDetailCars = 0; - if (1 < iVar11) + // sort cars by distance + if (num_cars_to_draw > 1) { - iVar9 = 1; + i = 1; do { - p_Var8 = cars_to_draw[iVar9]; - iVar3 = car_distance[iVar9]; + cp = cars_to_draw[i]; + dist = car_distance[i]; - iVar5 = iVar9 + 1; + j = i - 1; - if (iVar9 != 0) + while (dist < car_distance[j]) { - if (iVar3 < car_distance[iVar9 + -1]) - { - pp_Var7 = cars_to_draw + iVar9; - puVar6 = &car_distance[iVar9]; - iVar4 = iVar9 + -1; + car_distance[i] = car_distance[j]; + cars_to_draw[i] = cars_to_draw[j]; - do { - iVar9 = iVar4; - *puVar6 = puVar6[-1]; - *pp_Var7 = pp_Var7[-1]; - pp_Var7 = pp_Var7 + -1; - if (iVar9 == 0) break; - piVar10 = puVar6 + -2; - puVar6 = puVar6 + -1; - iVar4 = iVar9 + -1; - } while (iVar3 < *piVar10); - } + if (j == 0) + break; + + j--; } + + cars_to_draw[i] = cp; + car_distance[i] = dist; - cars_to_draw[iVar9] = p_Var8; - car_distance[iVar9] = iVar3; - iVar9 = iVar5; - - } while (iVar5 < iVar11); + i++; + } while (i < num_cars_to_draw); } - iVar9 = 0; + i = 0; + spacefree = (num_cars_to_draw - 1) * 2000; - if (0 < iVar11) + while (i < num_cars_to_draw) { - iVar3 = (iVar11 + -1) * 2000; + // Don't exceed draw buffers + if ((int)(current->primtab + (-3000 - (int)(current->primptr - PRIMTAB_SIZE))) < 5800) + return; - do { - // Don't exceed draw buffers - if ((int)(current->primtab + (-3000 - (int)(current->primptr- PRIMTAB_SIZE))) < 5800) - return; + // make cars look uglier + if ((int)(current->primtab + (-3000 - (int)(current->primptr - PRIMTAB_SIZE)) - spacefree) < 5800) + gForceLowDetailCars = 1; - // try reducing detail level - // this looks really ugly - if ((int)(current->primtab + (-3000 - (int)(current->primptr- PRIMTAB_SIZE)) + -iVar3) < 5800) - gForceLowDetailCars = 1; + if (cars_to_draw[i]->controlType == CONTROL_TYPE_PLAYER) + gForceLowDetailCars = 0; - if (cars_to_draw[iVar9]->controlType == CONTROL_TYPE_PLAYER) - gForceLowDetailCars = 0; - - DrawCar(cars_to_draw[iVar9], view); - - iVar9 = iVar9 + 1; - iVar3 = iVar3 + -2000; - - } while (iVar9 < iVar11); + DrawCar(cars_to_draw[i], view); + + spacefree -= 2000; + i++; } } } @@ -1819,11 +1706,9 @@ void DrawAllTheCars(int view) /* WARNING: Globals starting with '_' overlap smaller symbols at the same address */ -// [D] [A] custom -void PlotBuildingModelSubdivNxN(MODEL *model, int rot, _pct *pc, int n) +// [D] [T] [A] custom +void PlotBuildingModelSubdivNxN(MODEL* model, int rot, _pct* pc, int n) { -#if 1 // [A] new fully rewritten routine - // FIXME: still bugged - see tops of barrels at "Caine's Compound" int opz; @@ -1832,7 +1717,6 @@ void PlotBuildingModelSubdivNxN(MODEL *model, int rot, _pct *pc, int n) PL_POLYFT4* polys; int i; int r; - uint polyVar; u_char temp; u_char ptype; POLY_FT4* prims; @@ -1845,7 +1729,7 @@ void PlotBuildingModelSubdivNxN(MODEL *model, int rot, _pct *pc, int n) polys = (PL_POLYFT4*)model->poly_block; - if ((pc->flags & 1U) != 0) + if ((pc->flags & 1U) != 0) combointensity |= 0x2000000; i = model->num_polys; @@ -1884,12 +1768,12 @@ void PlotBuildingModelSubdivNxN(MODEL *model, int rot, _pct *pc, int n) r = rot; - if(pc->flags & 0x6) + if (pc->flags & 0x6) { if (opz < 0) r = rot + 32 & 63; - if(pc->flags & 0x4) + if (pc->flags & 0x4) opz = 1; // no culling else opz = -opz; // front face @@ -1942,7 +1826,7 @@ void PlotBuildingModelSubdivNxN(MODEL *model, int rot, _pct *pc, int n) // retrieve first three verts gte_stsxy3(&prims->x0, &prims->x1, &prims->x2); - + // translate 4th vert and get OT Z value gte_ldv0(&srcVerts[polys->v2]); gte_rtps(); @@ -2001,338 +1885,6 @@ void PlotBuildingModelSubdivNxN(MODEL *model, int rot, _pct *pc, int n) if ((pc->flags & 1U) != 0) combointensity &= ~0x2000000; - -#else // decompiled routine - - unsigned char uVar1; - UV_INFO UVar2; - UV_INFO UVar3; - int in_zero; - int in_at; - int iVar4; - SVECTOR *pSVar5; - int *puVar6; - uint uVar7; - ulong uVar8; - SVECTOR *local_v1_404; - int iVar9; - SVECTOR *pSVar10; - int iVar11; - int iVar12; - int iVar13; - uint uVar14; - uint uVar15; - uint uVar16; - int uVar17; - POLY_FT4 *local_t2_1500; - uint uVar18; - PL_POLYFT4 *polys; - ushort *vidx; - SVECTOR *verts; - uint uVar19; - uint uVar20; - int Z; - - verts = (SVECTOR *)model->vertices; - uVar20 = 0xffffffff; - pc->ot = pc->current->ot; - pc->primptr = pc->current->primptr; - - if ((pc->flags & 1U) != 0) { - combointensity = combointensity | 0x2000000; - in_at = 0xb0000; - } - - iVar4 = rot >> 3; - uVar19 = (uint)model->num_polys; - polys = (PL_POLYFT4 *)model->poly_block; - do { - while (true) - { - uVar19 = uVar19 - 1; - if (uVar19 == 0xffffffff) - { - pc->current->primptr = pc->primptr; - if ((pc->flags & 1U) != 0) - combointensity = combointensity & 0xfdffffff; - - return; - } - uVar18 = *(uint *)polys; - - if ((uVar18 & 1) == 0) { - uVar1 = (polys->uv2).v; - (polys->uv3).u = (polys->uv2).u; - (polys->uv3).v = uVar1; - polys->id = polys->id ^ 1; - uVar18 = *(uint *)polys; - polys->v3 = polys->v2; - } - - uVar7 = uVar18 & 0x1f; - - if ((uVar7 == 0xb) || (uVar7 == 0x15)) - break; - - polys = (PL_POLYFT4 *)(&polys->id + pc->polySizes[uVar7]); - } - vidx = *(ushort **)&polys->v0; - uVar8 = uVar18 >> 0x18; - - if (uVar7 == 0x15) - { - pc->colour = combointensity & 0x2ffffffU | 0x2c000000; - } - else - { - if ((uVar8 & 0x80) == 0) - { - rot = (int)vidx; - uVar8 = normalIndex(verts, (uint)vidx); - polys->th = (unsigned char)uVar8; - } - - pc->colour = pc->f4colourTable[iVar4 * 4 - uVar8 & 0x1f]; - } - - pSVar10 = verts + ((uint)vidx & 0xff); - local_v1_404 = (SVECTOR *)((int)&verts->vx + ((uint)vidx >> 5 & 0x7f8)); - pSVar5 = verts + ((uint)vidx >> 0x18); - puVar6 = (int*)((int)&verts->vx + ((uint)vidx >> 0xd & 0x7f8)); - - gte_ldv3(pSVar10, local_v1_404, pSVar5); - gte_rtpt(); - - if (((uVar20 ^ uVar18) & 0xffff00) != 0) - { - uVar20 = uVar18 >> 8 & 0xff; - rot = (int)(*pc->ptexture_pages + uVar20); - - pc->tpage = (uint)*(ushort *)rot << 0x10; - - if ((pc->flags & 16U) == 0) // [A] custom palette flag - pc->clut = (uint)*(ushort *)((int)*pc->ptexture_cluts + (uVar18 >> 0xf & 0x1fe) + uVar20 * 0x40) << 0x10; - - uVar20 = uVar18; - } - - gte_nclip(); - - uint DAT_1f800208; - uint DAT_1f80020c; - uint DAT_1f800210; - - gte_stsxy3(&DAT_1f800208, &DAT_1f80020c, &DAT_1f800210); - - //if (((0x13f < DAT_1f800208) && (0x13f < DAT_1f80020c)) && (0x13f < DAT_1f800210)) - //{ - // if (DAT_1f80020c << 0x10 < 0) - // { - // DAT_1f800208 = DAT_1f800208 ^ 1; - // } - // if (DAT_1f800208 != 0) - // goto LAB_00040d6c; - - // if (DAT_1f800210 << 0x10 < 0) - // { - // if (DAT_1f80020c != 1) - // goto LAB_00040d6c; - // } - // else - // { - // if (DAT_1f80020c != 0) - // goto LAB_00040d6c; - // } - - // goto LAB_00041140; - //} - - LAB_00040d6c: - ushort DAT_1f80020a = (ushort)((uint)DAT_1f800208 >> 0x10); - ushort DAT_1f80020e; - - //if((DAT_1f80020a < 0x100) || (DAT_1f80020e = (ushort)((uint)DAT_1f80020c >> 0x10), DAT_1f80020e < 0x100)) - { - LAB_00040e34: - - gte_stsz3(&pc->scribble[0], &pc->scribble[1], &pc->scribble[2]); - - iVar13 = pc->scribble[1]; - iVar11 = pc->scribble[2]; - if (iVar13 < pc->scribble[2]) - iVar11 = iVar13; - - iVar12 = pc->scribble[0]; - if (iVar12 < iVar11) - iVar11 = iVar12; - - iVar9 = pc->scribble[2]; - if (pc->scribble[2] < iVar13) - iVar9 = iVar13; - - rot = iVar9 - iVar11; - if (iVar9 < iVar12) - rot = iVar12 - iVar11; - - gte_stopz(&iVar13); - Z = iVar13; - - if (((pc->flags & 6U) != 0) && (Z = 1, (pc->flags & 4U) == 0)) - Z = -iVar13; - - if (Z > 0) - { - if ((n == 0) || (rot << 2 <= iVar11 + -0xfa)) - { - local_t2_1500 = (POLY_FT4 *)pc->primptr; - - gte_ldv0(puVar6); - - gte_rtps(); - gte_avsz4(); - - UVar2 = polys->uv3; - - gte_stotz(&iVar11); - - rot = 0xff0000; - if (0 < iVar11) - { - rot = 0xffffff; - UVar3 = polys->uv2; - uVar14 = *(uint *)&polys->uv0; - uVar15 = pc->clut; - uVar16 = pc->tpage; - uVar18 = pc->ot[iVar11 >> 1]; - - setPolyFT4(local_t2_1500); - addPrim(pc->ot + (iVar11 >> 1), local_t2_1500); - - //pc->ot[iVar11 >> 1] = (uint)local_t2_1500 & 0xffffff; - - //local_t2_1500->tag = uVar18 & 0xffffff | 0x9000000; - - uVar17 = DAT_1f800208; - *(uint *)&local_t2_1500->u0 = uVar14 & 0xffff | uVar15; - *(uint *)&local_t2_1500->x0 = uVar17; - - gte_stsxy3(&local_t2_1500->x1, &local_t2_1500->x2, &local_t2_1500->x3); - *(uint *)&local_t2_1500->u1 = uVar14 >> 0x10 | uVar16; - *(uint *)&local_t2_1500->u2 = (uint)(ushort)&UVar2; - *(uint *)&local_t2_1500->u3 = (uint)(ushort)&UVar3; - - local_t2_1500->u0 = polys->uv0.u; - local_t2_1500->v0 = polys->uv0.v; - - local_t2_1500->u1 = polys->uv1.u; - local_t2_1500->v1 = polys->uv1.v; - - local_t2_1500->u2 = polys->uv3.u; - local_t2_1500->v2 = polys->uv3.v; - - local_t2_1500->u3 = polys->uv2.u; - local_t2_1500->v3 = polys->uv2.v; - - *(ulong *)&local_t2_1500->r0 = pc->colour; - - pc->primptr = (char*)(local_t2_1500 + 1); - } - } - else - { - SVECTOR* v0 = pSVar10; - SVECTOR* v1 = local_v1_404; - SVECTOR* v2 = pSVar5; - SVECTOR* v3 = (SVECTOR*)puVar6; - - copyVector(&MVERTEX_ARRAY_1f800228[0][0], v0); - MVERTEX_ARRAY_1f800228[0][0].uv.val = *(ushort*)&polys->uv0; - - copyVector(&MVERTEX_ARRAY_1f800228[0][1], v1); - MVERTEX_ARRAY_1f800228[0][1].uv.val = *(ushort*)&polys->uv1; - - copyVector(&MVERTEX_ARRAY_1f800228[0][2], v2); - MVERTEX_ARRAY_1f800228[0][2].uv.val = *(ushort*)&polys->uv3; - - copyVector(&MVERTEX_ARRAY_1f800228[0][3], v3); - MVERTEX_ARRAY_1f800228[0][3].uv.val = *(ushort*)&polys->uv2; - - makeMesh((MVERTEX(*)[5][5])MVERTEX_ARRAY_1f800228, rot, rot); - drawMesh((MVERTEX(*)[5][5])MVERTEX_ARRAY_1f800228, rot, rot, pc); - - /* - iVar13 = rot << 1; - rot = n; - if ((n == 1) && (rot = (int)(ushort *)0x2, iVar11 + -0x96 < iVar13)) - rot = 0x4; - MVERTEX_ARRAY_1f800228[0]._0_4_ = *(undefined4 *)(verts + ((uint)vidx & 0xff)); - MVERTEX_ARRAY_1f800228[0]._4_4_ = - *(uint *)&verts[(uint)vidx & 0xff].vz & 0xffff | - (uint)(ushort)local_s1_1728->uv0 << 0x10; - uVar17 = *(undefined4 *)&verts[(uint)vidx >> 8 & 0xff].vz; - *(undefined4 *)(MVERTEX_ARRAY_1f800228 + rot) = - *(undefined4 *)(verts + ((uint)vidx >> 8 & 0xff)); - *(undefined4 *)&MVERTEX_ARRAY_1f800228[rot].vz = uVar17; - *(UV_INFO *)&MVERTEX_ARRAY_1f800228[rot].uv = local_s1_1728->uv1; - uVar17 = *(undefined4 *)&verts[(uint)vidx >> 0x18].vz; - *(undefined4 *)(MVERTEX_ARRAY_1f800228 + rot * 5) = - *(undefined4 *)(verts + ((uint)vidx >> 0x18)); - *(undefined4 *)&MVERTEX_ARRAY_1f800228[rot * 5].vz = uVar17; - puVar6 = (undefined4 *)((int)&verts->vx + ((uint)vidx >> 0xd & 0x7f8)); - *(UV_INFO *)&MVERTEX_ARRAY_1f800228[rot * 5].uv = local_s1_1728->uv3; - uVar17 = puVar6[1]; - *(undefined4 *)(MVERTEX_ARRAY_1f800228 + rot * 6) = *puVar6; - *(undefined4 *)&MVERTEX_ARRAY_1f800228[rot * 6].vz = uVar17; - *(UV_INFO *)&MVERTEX_ARRAY_1f800228[rot * 6].uv = local_s1_1728->uv2; - makeMesh((MVERTEX(*)[5][5])MVERTEX_ARRAY_1f800228, rot, rot); - drawMesh((MVERTEX(*)[5][5])MVERTEX_ARRAY_1f800228, rot, rot, pc); - */ - } - } - } - /* else - { - - DAT_1f800210._2_2_ = (ushort)((uint)DAT_1f800210 >> 0x10); - rot = (DAT_1f800210._2_2_); - if (DAT_1f800210._2_2_ < 0x100) goto LAB_00040e34; - iVar11 = (int)(short)DAT_1f80020a; - if (((int)(short)DAT_1f80020e - iVar11) + (int)(short)DAT_1f800210._2_2_ + 8U < 0x110) - goto LAB_00040e34; - if (-1 < (int)(short)DAT_1f80020e) - { - if (iVar11 == 0) - goto LAB_00040dfc; - goto LAB_00040e34; - } - if (iVar11 != 1) - goto LAB_00040e34;*/ - /* LAB_00040dfc: - - if ((int)((uint)DAT_1f800210._2_2_ << 0x10) < 0) - { - if (DAT_1f80020e != 1) - goto LAB_00040e34; - } - else - { - if (DAT_1f80020e != 0) - goto LAB_00040e34; - } - - }*/ - - LAB_00041140: - if (uVar7 == 0x15) - { - polys = (PL_POLYFT4 *)&polys[1].v0; // 0x14 - } - else - { - polys = polys + 1; - } - } while (true); -#endif } @@ -2390,21 +1942,21 @@ void PlotBuildingModelSubdivNxN(MODEL *model, int rot, _pct *pc, int n) /* end block 3 */ // End Line: 5026 -// [D] -int DrawAllBuildings(CELL_OBJECT **objects, int num_buildings, DB *disp) +// [D] [T] +int DrawAllBuildings(CELL_OBJECT** objects, int num_buildings, DB* disp) { int mat; int zbias; int drawlimit; - MODEL *model; + MODEL* model; OTTYPE* savedOT; - CELL_OBJECT *cop; + CELL_OBJECT* cop; int i; int prev_mat; prev_mat = -1; - for (i = 0; i < 8; i++ ) + for (i = 0; i < 8; i++) { plotContext.f4colourTable[i * 4 + 0] = planeColours[i] | 0x2C000000; plotContext.f4colourTable[i * 4 + 1] = planeColours[0] | 0x2C000000; @@ -2422,16 +1974,16 @@ int DrawAllBuildings(CELL_OBJECT **objects, int num_buildings, DB *disp) i = 0; - while(i < num_buildings) + while (i < num_buildings) { - cop = (CELL_OBJECT *)*objects; + cop = (CELL_OBJECT*)*objects; mat = cop->yang; - if (prev_mat == mat) + if (prev_mat == mat) { Apply_InvCameraMatrixSetTrans(&cop->pos); } - else + else { Apply_InvCameraMatrixAndSetMatrix(&cop->pos, &CompoundMatrix[mat]); prev_mat = mat; @@ -2513,8 +2065,8 @@ int DrawAllBuildings(CELL_OBJECT **objects, int num_buildings, DB *disp) /* end block 4 */ // End Line: 5556 -// [D] -void RenderModel(MODEL *model, MATRIX *matrix, VECTOR *pos, int zBias, int flags, int subdiv) +// [D] [T] +void RenderModel(MODEL* model, MATRIX* matrix, VECTOR* pos, int zBias, int flags, int subdiv) { OTTYPE* savedOT = current->ot; @@ -2547,7 +2099,7 @@ void RenderModel(MODEL *model, MATRIX *matrix, VECTOR *pos, int zBias, int flags plotContext.flags = flags; plotContext.current = current; - if (56000 < (current->primtab-(current->primptr - PRIMTAB_SIZE))) + if (56000 < (current->primtab - (current->primptr - PRIMTAB_SIZE))) PlotBuildingModelSubdivNxN(model, 0, &plotContext, subdiv); current->ot = savedOT; @@ -2598,84 +2150,74 @@ void RenderModel(MODEL *model, MATRIX *matrix, VECTOR *pos, int zBias, int flags /* end block 4 */ // End Line: 5772 -// [D] -ulong normalIndex(SVECTOR *verts, uint vidx) +// [D] [T] +ulong normalIndex(SVECTOR* verts, uint vidx) { - int iVar1; - uint uVar2; - uint uVar3; - SVECTOR *v0; - int iVar4; - int iVar5; - SVECTOR *v2; - int iVar6; - SVECTOR *v1; - int iVar7; - int iVar8; - int iVar9; - int iVar10; - + SVECTOR* v0; + SVECTOR* v1; + SVECTOR* v2; + int ny; + int y; + int th23; + int x; + + int nz; + int nx; SVECTOR p; SVECTOR q; - v1 = (SVECTOR *)((int)&verts->vx + (vidx >> 5 & 0x7f8)); v0 = verts + (vidx & 0xff); - v2 = (SVECTOR *)((int)&verts->vx + (vidx >> 0xd & 0x7f8)); + v1 = verts + (vidx >> 8 & 0xff); + v2 = verts + (vidx >> 16 & 0xff); - iVar10 = (uint)(ushort)v2->vz - (uint)(ushort)v0->vz; - iVar8 = (int)(((uint)(ushort)v1->vy - (uint)(ushort)v0->vy) * 0x10000) >> 0x10; - iVar7 = (uint)(ushort)v1->vz - (uint)(ushort)v0->vz; - iVar1 = (int)(((uint)(ushort)v2->vy - (uint)(ushort)v0->vy) * 0x10000) >> 0x10; - iVar5 = (uint)(ushort)v1->vx - (uint)(ushort)v0->vx; - iVar4 = (uint)(ushort)v2->vx - (uint)(ushort)v0->vx; + p.vz = v1->vz - v0->vz; + q.vz = v2->vz - v0->vz; + + p.vy = v1->vy - v0->vy; + q.vy = v2->vy - v0->vy; - iVar9 = iVar8 * (iVar10 * 0x10000 >> 0x10) - (iVar7 * 0x10000 >> 0x10) * iVar1; - iVar1 = (iVar5 * 0x10000 >> 0x10) * iVar1 - iVar8 * (iVar4 * 0x10000 >> 0x10); - iVar6 = iVar9 + (iVar1 >> 3); - iVar8 = iVar1 - (iVar6 >> 2); - iVar6 = iVar6 + (iVar8 >> 3); + p.vx = v1->vx - v0->vx; + q.vx = v2->vx - v0->vx; - if (iVar6 < iVar8) + nx = p.vy * q.vz - p.vz * q.vy; + nz = p.vx * q.vy - p.vy * q.vx; + + x = nx + (nz >> 3); + y = nz - (x >> 2); + + x += (y >> 3); + + if (x < y) { - if (iVar6 + iVar8 < 1) - { - uVar2 = 4; - - if (iVar8 < 0) - uVar2 = 5; - } - else - { - uVar2 = 2; - if (iVar6 < 0) - uVar2 = 3; - } + if (x + y < 1) + th23 = y < 0 ? 5 : 4; + else + th23 = x < 0 ? 3 : 2; } else { - uVar2 = (0 < iVar8); - - if ((iVar6 + iVar8 < 1) && (uVar2 = 7, iVar6 < 0)) - uVar2 = 6; + if (x + y < 1) + th23 = x < 0 ? 6 : 7; + else + th23 = 0 < y ? 1 : 0; } + + th23 *= 4; - uVar2 = uVar2 * 4; - iVar4 = (int)(short)iVar7 * (int)(short)iVar4 - (int)(short)iVar5 * (int)(short)iVar10; + ny = p.vz * q.vx - p.vx * q.vz; - if (iVar9 < 0) - iVar9 = -iVar9; + nx = ABS(nx); + nz = ABS(nz); + + if (nx + nz < ny) + th23 += 1; - if (iVar1 < 0) - iVar1 = -iVar1; + if (nx + nz < -ny) + th23 = th23 & 0x1f | 2; + else + th23 = th23 & 0x1f; - if (iVar9 + iVar1 < iVar4) - uVar2 = uVar2 + 1; - - uVar3 = uVar2 & 0x1f; - if (iVar9 + iVar1 < -iVar4) - uVar3 = uVar2 & 0x1f | 2; - - return uVar3 | 0x80; + return th23 | 0x80; } From ff8ab8575fdee4889fb1166d19242f358a8528d0 Mon Sep 17 00:00:00 2001 From: Ilya Shurumov Date: Mon, 12 Oct 2020 22:53:30 +0600 Subject: [PATCH 32/41] - refactor DRAW.C --- src_rebuild/GAME/C/DRAW.C | 436 ++++++++++++++++++-------------------- 1 file changed, 209 insertions(+), 227 deletions(-) diff --git a/src_rebuild/GAME/C/DRAW.C b/src_rebuild/GAME/C/DRAW.C index e0851659..866ff044 100644 --- a/src_rebuild/GAME/C/DRAW.C +++ b/src_rebuild/GAME/C/DRAW.C @@ -154,15 +154,15 @@ _pct plotContext; /* end block 3 */ // End Line: 1306 -MVERTEX MVERTEX_ARRAY_1f800228[5][5]; - -// [D] [A] +// [D] [T] [A] void addSubdivSpriteShadow(POLYFT4* src, SVECTOR* verts, int z) { int m; m = 4; + MVERTEX subdiVerts[5][5]; + plotContext.colour = 0x2e000000; plotContext.flags = 0x2; plotContext.clut = texture_cluts[src->texture_set][src->texture_id] << 0x10; @@ -173,20 +173,20 @@ void addSubdivSpriteShadow(POLYFT4* src, SVECTOR* verts, int z) plotContext.ot += 28; - copyVector(&MVERTEX_ARRAY_1f800228[0][0], &verts[src->v0]); - MVERTEX_ARRAY_1f800228[0][0].uv.val = *(ushort*)&src->uv0; + copyVector(&subdiVerts[0][0], &verts[src->v0]); + subdiVerts[0][0].uv.val = *(ushort*)&src->uv0; - copyVector(&MVERTEX_ARRAY_1f800228[0][1], &verts[src->v1]); - MVERTEX_ARRAY_1f800228[0][1].uv.val = *(ushort*)&src->uv1; + copyVector(&subdiVerts[0][1], &verts[src->v1]); + subdiVerts[0][1].uv.val = *(ushort*)&src->uv1; - copyVector(&MVERTEX_ARRAY_1f800228[0][2], &verts[src->v3]); - MVERTEX_ARRAY_1f800228[0][2].uv.val = *(ushort*)&src->uv3; + copyVector(&subdiVerts[0][2], &verts[src->v3]); + subdiVerts[0][2].uv.val = *(ushort*)&src->uv3; - copyVector(&MVERTEX_ARRAY_1f800228[0][3], &verts[src->v2]); - MVERTEX_ARRAY_1f800228[0][3].uv.val = *(ushort*)&src->uv2; + copyVector(&subdiVerts[0][3], &verts[src->v2]); + subdiVerts[0][3].uv.val = *(ushort*)&src->uv2; - makeMesh((MVERTEX(*)[5][5])MVERTEX_ARRAY_1f800228, m, m); - drawMesh((MVERTEX(*)[5][5])MVERTEX_ARRAY_1f800228, m, m, &plotContext); + makeMesh((MVERTEX(*)[5][5])subdiVerts, m, m); + drawMesh((MVERTEX(*)[5][5])subdiVerts, m, m, &plotContext); plotContext.ot -= 28; } @@ -300,6 +300,8 @@ void DrawSprites(int numFound) int numShadows; int count; + MVERTEX subdiVerts[5][5]; + lightdd = FIXEDH(camera_matrix.m[2][0] * day_vectors[GameLevel].vx) + FIXEDH(camera_matrix.m[2][1] * day_vectors[GameLevel].vy) + FIXEDH(camera_matrix.m[2][2] * day_vectors[GameLevel].vz) + 0x1000 * 0xc00; @@ -387,20 +389,20 @@ void DrawSprites(int numFound) plotContext.clut = texture_cluts[src->texture_set][src->texture_id] << 0x10; plotContext.tpage = texture_pages[src->texture_set] << 0x10; - copyVector(&MVERTEX_ARRAY_1f800228[0][0], &verts[src->v0]); - MVERTEX_ARRAY_1f800228[0][0].uv.val = *(ushort*)&src->uv0; + copyVector(&subdiVerts[0][0], &verts[src->v0]); + subdiVerts[0][0].uv.val = *(ushort*)&src->uv0; - copyVector(&MVERTEX_ARRAY_1f800228[0][1], &verts[src->v1]); - MVERTEX_ARRAY_1f800228[0][1].uv.val = *(ushort*)&src->uv1; + copyVector(&subdiVerts[0][1], &verts[src->v1]); + subdiVerts[0][1].uv.val = *(ushort*)&src->uv1; - copyVector(&MVERTEX_ARRAY_1f800228[0][2], &verts[src->v3]); - MVERTEX_ARRAY_1f800228[0][2].uv.val = *(ushort*)&src->uv3; + copyVector(&subdiVerts[0][2], &verts[src->v3]); + subdiVerts[0][2].uv.val = *(ushort*)&src->uv3; - copyVector(&MVERTEX_ARRAY_1f800228[0][3], &verts[src->v2]); - MVERTEX_ARRAY_1f800228[0][3].uv.val = *(ushort*)&src->uv2; + copyVector(&subdiVerts[0][3], &verts[src->v2]); + subdiVerts[0][3].uv.val = *(ushort*)&src->uv2; - makeMesh((MVERTEX(*)[5][5])MVERTEX_ARRAY_1f800228, 4, 4); - drawMesh((MVERTEX(*)[5][5])MVERTEX_ARRAY_1f800228, 4, 4, &plotContext); + makeMesh((MVERTEX(*)[5][5])subdiVerts, 4, 4); + drawMesh((MVERTEX(*)[5][5])subdiVerts, 4, 4, &plotContext); src++; } @@ -647,26 +649,24 @@ void DrawSprites(int numFound) /* end block 4 */ // End Line: 1981 -// [D] +// [D] [T] void DrawMapPSX(int* comp_val) { - ushort uVar1; - uint uVar4; + int dir; PACKED_CELL_OBJECT* ppco; - int iVar7; - uint uVar9; + int distScale; int cellx; int cellz; CELL_OBJECT* cop; MODEL* model; - int iVar19; - int iVar20; - uint backPlane; + int hloop; + int vloop; + int backPlane; CELL_ITERATOR ci; MATRIX mRotStore; VECTOR newpos; - int camx; - int camz; + int cellxpos; + int cellzpos; char* PVS_ptr; int tiles_found; int other_models_found; @@ -682,8 +682,7 @@ void DrawMapPSX(int* comp_val) int backAng; int leftAng; int rightAng; - - int local_34; + int i; int anim_objs; backPlane = 6144; @@ -692,6 +691,7 @@ void DrawMapPSX(int* comp_val) farClipLimit = 80000; + // setup planes rightAng = camera_angle.vy - FrAng & 0xfff; leftAng = camera_angle.vy + FrAng & 0xfff; backAng = camera_angle.vy + 0x400U & 0xfff; @@ -724,233 +724,216 @@ void DrawMapPSX(int* comp_val) setupYet = 0; } - camz = current_cell_z; - camx = current_cell_x; + cellzpos = current_cell_z; + cellxpos = current_cell_x; + // clean cell cache ClearCopUsage(); PVS_ptr = CurrentPVS + 220; - iVar20 = 0; - iVar19 = 0; - uVar4 = 0; + vloop = 0; + hloop = 0; + dir = 0; if (NumPlayers == 2) - uVar9 = goFaster & 31 | 1; + distScale = goFaster & 31 | 1; else - uVar9 = goFaster & 31; + distScale = goFaster & 31; - local_34 = (gDrawDistance >> uVar9) - 1; // [A] + i = (gDrawDistance >> distScale) - 1; // [A] - do - { - while (true) + // walk through all cells + while (i >= 0) + { + if (ABS(hloop) + ABS(vloop) < 16) { - while (true) + cellx = cellxpos + hloop; + cellz = cellzpos + vloop; + + if (rightPlane < 0 && + leftPlane > 0 && + backPlane < farClipLimit && // check planes + cellx > -1 && cellx < cells_across && // check cell ranges + cellz > -1 && cellz < cells_down && + PVS_ptr[hloop]) // check PVS table // [A] please enable after PVSDecode will work properly { - if (local_34 == -1) + ppco = GetFirstPackedCop(cellx, cellz, &ci, 1); + + // walk each cell object in cell + while (ppco != NULL) { - if (numSpritesFound != 0) + model = modelpointers[(ppco->value >> 6) | ((ppco->pos).vy & 1) << 10]; + + if (FrustrumCheck16(ppco, model->bounding_sphere) != -1) { - DrawSprites(numSpritesFound); - } - - if (tiles_found != 0) - { - DrawTILES(tiles_found); - } - - if (other_models_found != 0) - { - SetupPlaneColours(combointensity); - DrawAllBuildings((CELL_OBJECT**)model_object_ptrs, other_models_found, current); - } - - while (anim_objs > 0) - { - anim_objs--; - cop = anim_obj_buffer[anim_objs]; - - newpos.vx = cop->pos.vx - camera_position.vx; - newpos.vy = cop->pos.vy - camera_position.vy; - newpos.vz = cop->pos.vz - camera_position.vz; - Apply_Inv_CameraMatrix(&newpos); - - gte_SetRotMatrix(&matrixtable[cop->yang]); - DrawAnimatingObject(modelpointers[cop->type], cop, &newpos); - } - - buildingsFound = other_models_found; - - return; - } - - cellx = iVar19; - if (iVar19 < 0) - cellx = -iVar19; - - cellz = iVar20; - - if (iVar20 < 0) - cellz = -iVar20; - - local_34--; - - if (cellx + cellz < 16) - { - cellx = camx + iVar19; - cellz = camz + iVar20; - - if (rightPlane < 0 && - leftPlane > 0 && - backPlane < farClipLimit && // check planes - cellx > -1 && cellx < cells_across && // check cell ranges - cellz > -1 && cellz < cells_down && - PVS_ptr[iVar19]) // check PVS table // [A] please enable after PVSDecode will work properly - { - ppco = GetFirstPackedCop(cellx, cellz, &ci, 1); - - while (ppco != NULL) + if (model->shape_flags & 0x4000) { - model = modelpointers[(ppco->value >> 6) | ((ppco->pos).vy & 1) << 10]; + if (numSpritesFound < 75) + spriteList[numSpritesFound++] = ppco; - if (FrustrumCheck16(ppco, model->bounding_sphere) != -1) + if ((model->flags2 & 1) && anim_objs < 20) { - if (model->shape_flags & 0x4000) + cop = UnpackCellObject(ppco, &ci.nearCell); + + anim_obj_buffer[anim_objs++] = cop; + } + + if(model->flags2 & 0x2000) + { + if (treecount == 0) { - if (numSpritesFound < 75) - spriteList[numSpritesFound++] = ppco; + cop = UnpackCellObject(ppco, &ci.nearCell); - if ((model->flags2 & 1) && anim_objs < 20) - { - cop = UnpackCellObject(ppco, &ci.nearCell); - - anim_obj_buffer[anim_objs++] = cop; - } - - if (((model->flags2 & 0x2000) != 0) && (uVar9 = treecount & 0xf, treecount++, uVar9 == 0)) - { - cop = UnpackCellObject(ppco, &ci.nearCell); - - ground_debris[groundDebrisIndex++] = *cop; - groundDebrisIndex = groundDebrisIndex % 16; - } + ground_debris[groundDebrisIndex++] = *cop; + groundDebrisIndex = groundDebrisIndex % 16; } - else + + treecount = (treecount+1) & 0xf; + } + } + else + { + int modelNumber; + modelNumber = ppco->value & 0x3f; + + if (modelNumber > 0) + { + MATRIX2* cmat; + cmat = &CompoundMatrix[modelNumber]; + + if (cmat->computed != current_object_computed_value) { - uVar9 = ppco->value & 0x3f; + cmat->computed = current_object_computed_value; - if ((ppco->value & 0xf) != 0) - { - if (CompoundMatrix[uVar9].computed != current_object_computed_value) - { - CompoundMatrix[uVar9].computed = current_object_computed_value; + gte_ReadRotMatrix(&mRotStore); - gte_ReadRotMatrix(&mRotStore); + gte_sttr(mRotStore.t); - gte_sttr(mRotStore.t); + MulMatrix0(&inv_camera_matrix, (MATRIX*)&matrixtable[modelNumber], (MATRIX*)cmat); - MulMatrix0(&inv_camera_matrix, (MATRIX*)(matrixtable + uVar9), (MATRIX*)(CompoundMatrix + uVar9)); - - gte_SetRotMatrix(&mRotStore); - } - } - - if ((model->shape_flags & 0x480) || (model->flags2 & 0xc000)) - { - if(model->flags2 & 0x80) - { - alleycount++; - - if (alleycount == 13) - { - cop = UnpackCellObject(ppco, &ci.nearCell); - ground_debris[groundDebrisIndex++] = *cop; - groundDebrisIndex = groundDebrisIndex % 16; - - alleycount = 0; - } - } - - if (tiles_found < 256) - { - *(PACKED_CELL_OBJECT**)(tile_overflow_buffer + tiles_found) = ppco; - tiles_found++; - } - } - else - { - cop = UnpackCellObject(ppco, &ci.nearCell); - - if ((model->flags2 & 1) && (anim_objs < 20)) - { - anim_obj_buffer[anim_objs++] = cop; - } - - if (other_models_found < 192) - model_object_ptrs[other_models_found++] = cop; - } + gte_SetRotMatrix(&mRotStore); } } - ppco = GetNextPackedCop(&ci); + if ((model->shape_flags & 0x480) || (model->flags2 & 0xc000)) + { + if(model->flags2 & 0x80) + { + alleycount++; + + if (alleycount == 13) + { + cop = UnpackCellObject(ppco, &ci.nearCell); + ground_debris[groundDebrisIndex++] = *cop; + groundDebrisIndex = groundDebrisIndex % 16; + + alleycount = 0; + } + } + + if (tiles_found < 256) + { + *(PACKED_CELL_OBJECT**)(tile_overflow_buffer + tiles_found) = ppco; + tiles_found++; + } + } + else + { + cop = UnpackCellObject(ppco, &ci.nearCell); + + if ((model->flags2 & 1) && anim_objs < 20) + { + anim_obj_buffer[anim_objs++] = cop; + } + + if (other_models_found < 192) + model_object_ptrs[other_models_found++] = cop; + } } } + + ppco = GetNextPackedCop(&ci); } - - if (uVar4 != 1) - break; - - leftPlane += leftsin; - backPlane += backsin; - rightPlane += rightsin; - iVar20++; - - PVS_ptr += pvs_square; - - if (iVar19 == iVar20) - uVar4 = 2; - } - - if (1 < uVar4) - break; - - if (uVar4 == 0) - { - leftPlane += leftcos; - backPlane += backcos; - rightPlane += rightcos; - - iVar19++; - - if (iVar19 + iVar20 == 1) - uVar4 = 1; - } - else - { - LAB_0004004c: - leftPlane -= leftsin; - backPlane -= backsin; - rightPlane -= rightsin; - iVar20--; - PVS_ptr -= pvs_square; - - if (iVar19 == iVar20) - uVar4 = 0; } } - if (uVar4 != 2) - goto LAB_0004004c; + if (dir == 0) + { + leftPlane += leftcos; + backPlane += backcos; + rightPlane += rightcos; - iVar19--; - leftPlane -= leftcos; - backPlane -= backcos; - rightPlane -= rightcos; + hloop++; - if (iVar19 + iVar20 == 0) - uVar4 = 3; - } while (true); + if (hloop + vloop == 1) + dir = 1; + } + else if (dir == 1) + { + leftPlane += leftsin; + backPlane += backsin; + rightPlane += rightsin; + vloop++; + + PVS_ptr += pvs_square; + + if (hloop == vloop) + dir = 2; + } + else if (dir == 2) + { + hloop--; + leftPlane -= leftcos; + backPlane -= backcos; + rightPlane -= rightcos; + + if (hloop + vloop == 0) + dir = 3; + } + else + { + leftPlane -= leftsin; + backPlane -= backsin; + rightPlane -= rightsin; + vloop--; + + PVS_ptr -= pvs_square; + + if (hloop == vloop) + dir = 0; + } + + i--; + } + + if (numSpritesFound != 0) + DrawSprites(numSpritesFound); + + if (tiles_found != 0) + DrawTILES(tiles_found); + + if (other_models_found != 0) + { + SetupPlaneColours(combointensity); + DrawAllBuildings((CELL_OBJECT**)model_object_ptrs, other_models_found, current); + } + + while (anim_objs > 0) + { + anim_objs--; + cop = anim_obj_buffer[anim_objs]; + + newpos.vx = cop->pos.vx - camera_position.vx; + newpos.vy = cop->pos.vy - camera_position.vy; + newpos.vz = cop->pos.vz - camera_position.vz; + Apply_Inv_CameraMatrix(&newpos); + + gte_SetRotMatrix(&matrixtable[cop->yang]); + DrawAnimatingObject(modelpointers[cop->type], cop, &newpos); + } + + buildingsFound = other_models_found; } // decompiled code @@ -1150,7 +1133,6 @@ MATRIX frustrum_matrix; // [D] [T] void InitFrustrumMatrix(void) { - int iVar1; int a; a = -camera_angle.vy; From 348ece829431369814c3055c750f488ff80f989c Mon Sep 17 00:00:00 2001 From: Ilya Shurumov Date: Mon, 12 Oct 2020 22:53:58 +0600 Subject: [PATCH 33/41] - [EMU] PSX-correct ApplyRotMatrixLV --- src_rebuild/EMULATOR/LIBGTE.C | 139 +++++++++++++++++++++------------- 1 file changed, 87 insertions(+), 52 deletions(-) diff --git a/src_rebuild/EMULATOR/LIBGTE.C b/src_rebuild/EMULATOR/LIBGTE.C index f4ca043f..c0ec98d4 100644 --- a/src_rebuild/EMULATOR/LIBGTE.C +++ b/src_rebuild/EMULATOR/LIBGTE.C @@ -1315,7 +1315,7 @@ VECTOR* ApplyMatrix(MATRIX* m, SVECTOR* v0, VECTOR* v1) gte_SetRotMatrix(m); gte_ldv0(v0); gte_rtv0(); - gte_stlvl(v1); + gte_stlvnl(v1); #else APPLYMATRIX(m, v0, v1); #endif @@ -1341,10 +1341,76 @@ VECTOR* ApplyRotMatrix(SVECTOR* v0, VECTOR* v1) VECTOR* ApplyRotMatrixLV(VECTOR* v0, VECTOR* v1) { -#if 0 - gte_ldv0(v0); - gte_rtv0(); - gte_stlvl(v1); +#if 1 + // correct Psy-Q implementation + VECTOR tmpHI; + VECTOR tmpLO; + + tmpHI.vx = v0->vx; + tmpHI.vy = v0->vy; + tmpHI.vz = v0->vz; + + if (tmpHI.vx < 0) + { + tmpLO.vx = -(-tmpHI.vx >> 0xf); + tmpHI.vx = -(-tmpHI.vx & 0x7fff); + } + else + { + tmpLO.vx = tmpHI.vx >> 0xf; + tmpHI.vx = tmpHI.vx & 0x7fff; + } + + if (tmpHI.vy < 0) + { + tmpLO.vy = -(-tmpHI.vy >> 0xf); + tmpHI.vy = -(-tmpHI.vy & 0x7fff); + } + else + { + tmpLO.vy = tmpHI.vy >> 0xf; + tmpHI.vy = tmpHI.vy & 0x7fff; + } + + if (tmpHI.vz < 0) + { + tmpLO.vz = -(-tmpHI.vz >> 0xf); + tmpHI.vz = -(-tmpHI.vz & 0x7fff); + } + else + { + tmpLO.vz = tmpHI.vz >> 0xf; + tmpHI.vz = tmpHI.vz & 0x7fff; + } + + gte_ldlvl(&tmpLO); + docop2(0x41E012); // gte_rtir_sf0 ? + + gte_stlvnl(&tmpLO); + gte_ldlvl(&tmpHI); + gte_rtir(); + + if (tmpLO.vx < 0) + tmpLO.vx = tmpLO.vx * 8; + else + tmpLO.vx = tmpLO.vx << 3; + + if (tmpLO.vy < 0) + tmpLO.vy = tmpLO.vy * 8; + else + tmpLO.vy = tmpLO.vy << 3; + + if (tmpLO.vz < 0) + tmpLO.vz = tmpLO.vz * 8; + else + tmpLO.vz = tmpLO.vz << 3; + + gte_stlvnl(&tmpHI); + + v1->vx = tmpHI.vx + tmpLO.vx; + v1->vy = tmpHI.vy + tmpLO.vy; + v1->vz = tmpHI.vz + tmpLO.vz; + #else MATRIX temp; gte_ReadRotMatrix(&temp); @@ -1358,7 +1424,8 @@ VECTOR* ApplyRotMatrixLV(VECTOR* v0, VECTOR* v1) SVECTOR* ApplyMatrixSV(MATRIX* m, SVECTOR* v0, SVECTOR* v1) { -#if 0 +#if 1 + // correct Psy-Q implementation gte_SetRotMatrix(m); gte_ldv0(v0); gte_rtv0(); @@ -1375,7 +1442,7 @@ VECTOR* ApplyMatrixLV(MATRIX* m, VECTOR* v0, VECTOR* v1) gte_SetRotMatrix(m); gte_ldv0(v0); gte_rtv0(); - gte_stlvl(v1); + gte_stlvnl(v1); #else APPLYMATRIX(m, v0, v1); #endif @@ -1422,7 +1489,7 @@ MATRIX* RotMatrixYXZ(struct SVECTOR* r, MATRIX* m) int iVar1; int iVar2; short sVar3; - uint uVar4; + int uVar4; int iVar5; int iVar6; int iVar7; @@ -1430,31 +1497,31 @@ MATRIX* RotMatrixYXZ(struct SVECTOR* r, MATRIX* m) uVar4 = (r->vx); - if ((int)uVar4 < 0) + if (uVar4 < 0) { iVar6 = *(int*)(rcossin_tbl + (-uVar4 & 0xfff) * 2); - sVar3 = (short)iVar6; - iVar5 = -(int)sVar3; + sVar3 = iVar6; + iVar5 = -sVar3; } else { iVar6 = *(int*)(rcossin_tbl + (uVar4 & 0xfff) * 2); - iVar5 = (int)(short)iVar6; - sVar3 = -(short)iVar6; + iVar5 = iVar6; + sVar3 = -iVar6; } iVar6 = iVar6 >> 0x10; uVar4 = (r->vy); - if ((int)uVar4 < 0) + if (uVar4 < 0) { iVar7 = *(int*)(rcossin_tbl + (-uVar4 & 0xfff) * 2); - iVar1 = -(int)(short)iVar7; + iVar1 = -iVar7; } else { iVar7 = *(int*)(rcossin_tbl + (uVar4 & 0xfff) * 2); - iVar1 = (int)(short)iVar7; + iVar1 = iVar7; } iVar7 = iVar7 >> 0x10; @@ -1464,17 +1531,17 @@ MATRIX* RotMatrixYXZ(struct SVECTOR* r, MATRIX* m) m->m[0][2] = FIXED(iVar1 * iVar6); sVar3 = FIXED(iVar7 * iVar6); - if ((int)uVar4 < 0) + if (uVar4 < 0) { m->m[2][2] = sVar3; iVar8 = *(int*)(rcossin_tbl + (-uVar4 & 0xfff) * 2); - iVar2 = -(int)(short)iVar8; + iVar2 = -iVar8; } else { m->m[2][2] = sVar3; iVar8 = *(int*)(rcossin_tbl + (uVar4 & 0xfff) * 2); - iVar2 = (int)(short)iVar8; + iVar2 = iVar8; } iVar8 = iVar8 >> 0x10; @@ -1557,7 +1624,7 @@ MATRIX* RotMatrixZ(long r, MATRIX* m) MATRIX* RotMatrixZYX_gte(SVECTOR* r, MATRIX* m) { #if 0 - // by disassembly there is two gte_LoadAverage12 calls + // TODO:... #else // FIXME: make a proper function m->m[0][0] = 0x1000; @@ -1621,52 +1688,20 @@ void SetFogNear(long a, long h) SetDQB(20971520); } -int isin(int x) -{ - -#define qN 10 -#define qA 12 -#define B 19900 -#define C 3516 - - int c, x2, y; - - c = x << (30 - qN); // Semi-circle info into carry. - x -= 1 << qN; // sine -> cosine calc - - x = x << (31 - qN); // Mask with PI - x = x >> (31 - qN); // Note: SIGNED shift! (to qN) - - x = x * x >> (2 * qN - 14); // x=x^2 To Q14 - - y = B - (x * C >> 14); // B - x^2*C - y = (1 << qA) - (x * y >> 16); // A - x^2*(B-x^2*C) - - return c >= 0 ? y : -y; -} - int rsin(int a) { -#if 0 - return isin(a); -#else if (a < 0) return -rcossin_tbl[(-a & 0xfffU) * 2]; return rcossin_tbl[(a & 0xfffU) * 2]; -#endif } int rcos(int a) { -#if 0 - return isin(a + 1024); -#else if (a < 0) return rcossin_tbl[(-a & 0xfffU) * 2 + 1]; return rcossin_tbl[(a & 0xfffU) * 2 + 1]; -#endif } long ratan2(long y, long x) From 25d8b897a83f25ad3fa9a78444f1b694827c7bfe Mon Sep 17 00:00:00 2001 From: Ilya Shurumov Date: Tue, 13 Oct 2020 22:48:51 +0600 Subject: [PATCH 34/41] - refactor COP_AI.C --- src_rebuild/GAME/C/COP_AI.C | 840 ++++++++++++++++-------------------- 1 file changed, 365 insertions(+), 475 deletions(-) diff --git a/src_rebuild/GAME/C/COP_AI.C b/src_rebuild/GAME/C/COP_AI.C index 9e152257..f0670012 100644 --- a/src_rebuild/GAME/C/COP_AI.C +++ b/src_rebuild/GAME/C/COP_AI.C @@ -21,19 +21,8 @@ COP_DATA gCopData = { 0, 0, 0, 2048, 0, 4096, 2048, 3000000, { 0, 0, 0, 0, 0 } }; -int speed1[] = { 0xCB, 0xD2, 0xD9 }; -int speed2[] = { 0xEE, 0x10A, 0x126 }; - -unsigned char sqtbl[] = { - 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, - 0x81, 0x81, 0x81, 0x82, 0x82, 0x83, 0x83, 0x83, 0x84, - 0x84, 0x85, 0x86, 0x86, 0x87, 0x88, 0x88, 0x89, 0x8A, - 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, 0x90, 0x90, 0x91, - 0x92, 0x93, 0x94, 0x95, 0x96, 0x98, 0x99, 0x9A, 0x9B, - 0x9C, 0x9D, 0x9E, 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA6, - 0xA7, 0xA8, 0xAA, 0xAB, 0xAC, 0xAE, 0xAF, 0xB0, 0xB2, - 0xB3, 0xB5 -}; +int speed1[] = { 203, 210, 217 }; +int speed2[] = { 238, 266, 294 }; int CopsCanSeePlayer = 0; short pedestrianFelony = 0; @@ -42,7 +31,7 @@ int numRoadblockCars = 0; int roadblockCount = 0; int copsAreInPursuit = 0; int requestRoadblock = 0; -int roadblockDelay = 0xfa; +int roadblockDelay = 250; int roadblockDelayDiff[3] = { 1500, 1000, 800 }; int requestCopCar = 0; int cop_respawn_timer = 0; @@ -83,7 +72,7 @@ int OutOfSightCount = 0; /* end block 2 */ // End Line: 1155 -// [D] +// [D] [T] void InitCopState(_CAR_DATA *cp, char *extraData) { ClearMem((char *)&cp->ai.p, sizeof(COP)); @@ -157,7 +146,7 @@ extern int distanceReturnedLog[8]; extern int distLogIndex; extern int lastDistanceFound; -// [D] +// [D] [T] void WibbleDownTheRoad(VECTOR *from, int distance, VECTOR *to) { int val; @@ -254,7 +243,7 @@ void WibbleDownTheRoad(VECTOR *from, int distance, VECTOR *to) /* WARNING: Unknown calling convention yet parameter storage is locked */ -// [D] +// [D] [T] void InitCops(void) { targetVehicle = &car_data[0]; @@ -288,6 +277,7 @@ void InitCops(void) gCopRespawnTime = 0; gCopDesiredSpeedScale = 4596; gCopMaxPowerScale = 4596; + gCopData.autoMaxPowerScaleLimit = 1024; gCopData.autoDesiredSpeedScaleLimit = 1024; } @@ -295,8 +285,8 @@ void InitCops(void) { gCopRespawnTime = 320; - if (gCurrentMissionNumber < 0x28) - gCopRespawnTime = gCurrentMissionNumber * -4 + 0x140; + if (gCurrentMissionNumber < 40) + gCopRespawnTime = gCurrentMissionNumber * -4 + 320; } LastHeading = -1; @@ -386,15 +376,13 @@ void InitCops(void) /* WARNING: Globals starting with '_' overlap smaller symbols at the same address */ /* WARNING: Unknown calling convention yet parameter storage is locked */ -// [D] +// [D] [T] void ControlCops(void) { - char cVar1; - long lVar2; - long lVar3; - short *psVar4; - int direction; - int iVar5; + short *playerFelony; + int heading; + int phrase; + int copsWereInPursuit; #if 0 // [A] lineClear debugging code - pls remove after fixing bugs extern int gShowCollisionDebug; @@ -428,14 +416,14 @@ void ControlCops(void) player_position_known = 0; CopsCanSeePlayer = 0; requestCopCar = 0; - direction = copsAreInPursuit; + copsWereInPursuit = copsAreInPursuit; } else { - if (-1 < player[0].playerCarId) + if (player[0].playerCarId > -1) targetVehicle = car_data + player[0].playerCarId; - if (0 < player_position_known) + if (player_position_known > 0) { lastKnownPosition.vx = player[0].pos[0]; lastKnownPosition.vy = player[0].pos[1]; @@ -444,67 +432,56 @@ void ControlCops(void) } UpdateCopMap(); - direction = LastHeading; + heading = LastHeading; if (first_offence == 0 && CopsCanSeePlayer != 0 && numActiveCops != 0) { if (player[0].playerCarId < 0) - { - psVar4 = &pedestrianFelony; - } + playerFelony = &pedestrianFelony; else + playerFelony = &car_data[player[0].playerCarId].felonyRating; + + if (*playerFelony > 658 && TimeSinceLastSpeech > 720 && targetVehicle->hd.speed > 20) { - psVar4 = &car_data[player[0].playerCarId].felonyRating; - } - - if (658 < *psVar4 && 720 < TimeSinceLastSpeech && 20 < targetVehicle->hd.speed) - { - cVar1 = GetCarDirectionOfTravel(targetVehicle); - - direction = cVar1; - lVar2 = Random2(1); - - if (direction != LastHeading) + int rnd; + heading = GetCarDirectionOfTravel(targetVehicle); + + if (heading != LastHeading) { - iVar5 = MaxPlayerDamage[0] * 3; - - if (iVar5 >> 2 < car_data[player[0].playerCarId].totalDamage) - { - lVar3 = lVar2; - iVar5 = (lVar3 >> 2) * -4; - } + rnd = Random2(1); + + if ((MaxPlayerDamage[0] * 3) / 4 < car_data[player[0].playerCarId].totalDamage) + phrase = rnd % 4; else - { - iVar5 = (lVar2 / 3) * -3; - } + phrase = rnd % 3; - iVar5 = lVar2 + iVar5; + phrase = rnd + phrase; - if (first_offence == 0 && last_cop_phrase != iVar5 && (720 < TimeSinceLastSpeech)) + if (first_offence == 0 && last_cop_phrase != phrase && TimeSinceLastSpeech > 720) { - if (iVar5 < 3) + if (phrase < 3) { - CopSay(iVar5 + 0xf, direction); - last_cop_phrase = iVar5; + CopSay(phrase + 15, heading); + last_cop_phrase = phrase; } else { CopSay(6, 0); - last_cop_phrase = iVar5; + last_cop_phrase = phrase; } } } } } - LastHeading = direction; + LastHeading = heading; if (player[0].playerCarId < 0) - psVar4 = &pedestrianFelony; + playerFelony = &pedestrianFelony; else - psVar4 = &car_data[(int)player[0].playerCarId].felonyRating; + playerFelony = &car_data[(int)player[0].playerCarId].felonyRating; - if (gCopData.autoBatterPlayerTrigger <= *psVar4) + if (gCopData.autoBatterPlayerTrigger <= *playerFelony) gBatterPlayer = 1; ControlCopDetection(); @@ -513,37 +490,39 @@ void ControlCops(void) ControlNumberOfCops(); - direction = 0; + copsWereInPursuit = 0; - if (0 < player_position_known) + if (player_position_known > 0) { if (player[0].playerCarId < 0) - psVar4 = &pedestrianFelony; + playerFelony = &pedestrianFelony; else - psVar4 = &car_data[(int)player[0].playerCarId].felonyRating; + playerFelony = &car_data[player[0].playerCarId].felonyRating; - if (0x292 < *psVar4) - { - direction = 1; - } + if (*playerFelony > 0x292) + copsWereInPursuit = 1; } - if (direction != 0) + if (copsWereInPursuit != 0) { if (copsAreInPursuit == 0) Pads[0].alarmShakeCounter = 12; - if ((direction != 0) && (copsAreInPursuit = direction, FunkUpDaBGMTunez(1), direction = copsAreInPursuit, first_offence != 0)) + copsAreInPursuit = 1; + + FunkUpDaBGMTunez(1); + + if(first_offence != 0) { CopSay(9, 0); first_offence = 0; said_picked_up = 1; - direction = copsAreInPursuit; - } + } } } - copsAreInPursuit = direction; + + copsAreInPursuit = copsWereInPursuit; } @@ -569,7 +548,7 @@ void ControlCops(void) /* end block 3 */ // End Line: 1649 -// [D] +// [D] [T] void CopControl(_CAR_DATA *cp) { CopControl1(cp); @@ -718,30 +697,23 @@ VECTOR targetPoint = { 0,0,0 }; // [D] void CopControl1(_CAR_DATA *cp) { - short sVar2; int targetFound; - char cVar4; - int iVar5; - long lVar6; + int steeringFac; int dist; - int* piVar8; - short* psVar9; - int uVar10; - int iVar11; - int uVar12; - short sVar13; + short* playerFelony; + int steerDif; int dz; int plcrspd; - int iVar14; int dx; - int dvx; - int dvz; + int dvx, dvz, idvx, idvz; int desiredSteerAngle; int x; int z; int currentSpeed; + int slidevel; + int maxPower; + int speedDif; VECTOR pos; - VECTOR doordir; iVectNT path[2]; AIZone targetZone; @@ -752,13 +724,14 @@ void CopControl1(_CAR_DATA *cp) if (CopsAllowed == 0) { - LAB_0002e048: cp->thrust = 0; cp->handbrake = 1; + return; } - if (cp->ai.p.dying != 0 || (27000 < cp->totalDamage && gCopData.immortal == 0)) + if (cp->ai.p.dying != 0 || + cp->totalDamage > 27000 && gCopData.immortal == 0) { cp->thrust = 0; @@ -774,20 +747,16 @@ void CopControl1(_CAR_DATA *cp) if (gStopCops.radius != 0) { - iVar5 = cp->hd.where.t[0]; - dx = iVar5 - gStopCops.pos.vx; + dx = ABS(cp->hd.where.t[0] - gStopCops.pos.vx); + dz = ABS(cp->hd.where.t[2] - gStopCops.pos.vz); - if (dx < 0) - dx = gStopCops.pos.vx - iVar5; - - iVar5 = cp->hd.where.t[2]; - dz = iVar5 - gStopCops.pos.vz; - - if (dz < 0) - dz = gStopCops.pos.vz - iVar5; - - if ((dx + dz < gStopCops.radius * 3 >> 1) && (SquareRoot0(dx * dx + dz * dz) < gStopCops.radius)) - goto LAB_0002e048; + if (dx + dz < gStopCops.radius * 3 / 2 && + SquareRoot0(dx * dx + dz * dz) < gStopCops.radius) + { + cp->thrust = 0; + cp->handbrake = 1; + return; + } } if ((CameraCnt & 7U) == 0) @@ -795,6 +764,7 @@ void CopControl1(_CAR_DATA *cp) pos.vx = cp->hd.where.t[0] + FIXEDH(cp->hd.where.m[0][2] * 400 - cp->hd.where.m[0][0] * 150); pos.vy = cp->hd.where.t[1] + FIXEDH(cp->hd.where.m[1][2] * 400 - cp->hd.where.m[1][0] * 150); pos.vz = cp->hd.where.t[2] + FIXEDH(cp->hd.where.m[2][2] * 400 - cp->hd.where.m[2][0] * 150); + cp->ai.p.frontLClear = CellAtPositionEmpty(&pos, 80); #ifdef COLLISION_DEBUG @@ -818,6 +788,7 @@ void CopControl1(_CAR_DATA *cp) pos.vx = cp->hd.where.t[0] + FIXEDH(cp->hd.where.m[0][2] * 400 + cp->hd.where.m[0][0] * 150); pos.vy = cp->hd.where.t[1] + FIXEDH(cp->hd.where.m[1][2] * 400 + cp->hd.where.m[1][0] * 150); pos.vz = cp->hd.where.t[2] + FIXEDH(cp->hd.where.m[2][2] * 400 + cp->hd.where.m[2][0] * 150); + cp->ai.p.frontRClear = CellAtPositionEmpty(&pos, 80); #ifdef COLLISION_DEBUG @@ -844,17 +815,10 @@ void CopControl1(_CAR_DATA *cp) pathStraight = 0; - dvx = targetVehicle->st.n.linearVelocity[0] - cp->st.n.linearVelocity[0]; - dvz = targetVehicle->st.n.linearVelocity[2] - cp->st.n.linearVelocity[2]; - if (cp->hd.speed < 6 && cp->ai.p.desiredSpeed != 0) - { cp->ai.p.stuckTimer++; - } else - { cp->ai.p.stuckTimer = 0; - } if (cp->ai.p.stuckTimer > 10 && cp->ai.p.recoveryTimer == 0) { @@ -870,51 +834,49 @@ void CopControl1(_CAR_DATA *cp) cp->ai.p.stuckTimer = 0; } + dvx = targetVehicle->st.n.linearVelocity[0] - cp->st.n.linearVelocity[0]; + dvz = targetVehicle->st.n.linearVelocity[2] - cp->st.n.linearVelocity[2]; + dist = FindCost(x, z, dvx, dvz); + cp->ai.p.close_pursuit = (dist < 2800); + targetFound = 0; if (cp->ai.p.recoveryTimer < 1) { if (dist < 8400) { - iVar11 = FIXEDH(dvx); - dvx = FIXEDH(dvz); - dvz = iVar11 * iVar11 + dvx * dvx + 1; - dvx = ((x - targetVehicle->hd.where.t[0]) * iVar11 - (targetVehicle->hd.where.t[2] - z) * dvx) / dvz; + int dd; + + dx = x - targetVehicle->hd.where.t[0]; + dz = targetVehicle->hd.where.t[2] - z; + + idvx = FIXEDH(dvx); + idvz = FIXEDH(dvz); + + dd = (dx * idvx - dz * idvz) / (idvx * idvx + idvz * idvz + 1); if (gBatterPlayer == 0) - { - dvz = dvx * 3; - dvx = dvz >> 2; + dd = dd * 3 / 4; - if (dvz < 0) - dvx = dvz + 3 >> 2; + if (dd < 0) + dd = 0; + else if (dd > 60) + dd = 60; - } - - if (dvx < 0) - dvx = 0; - else if (dvx > 60) - dvx = 60; - - dvz = targetVehicle->hd.where.t[0] + FIXEDH(targetVehicle->st.n.linearVelocity[0] * dvx); - dvx = targetVehicle->hd.where.t[2] + FIXEDH(targetVehicle->st.n.linearVelocity[2] * dvx); + dvz = targetVehicle->hd.where.t[0] + FIXEDH(targetVehicle->st.n.linearVelocity[0] * dd); + dvx = targetVehicle->hd.where.t[2] + FIXEDH(targetVehicle->st.n.linearVelocity[2] * dd); if (gBatterPlayer == 0) { - iVar11 = (int)targetVehicle->hd.where.m[0][2] * 5; - CarTail.vx = dvz - (iVar11 >> 7); - - dvz = (int)targetVehicle->hd.where.m[2][2] * 5; - CarTail.vz = dvx - (dvz >> 7); + CarTail.vx = dvz - (targetVehicle->hd.where.m[0][2] * 5 >> 7); + CarTail.vz = dvx - (targetVehicle->hd.where.m[2][2] * 5 >> 7); } else { - iVar11 = (int)targetVehicle->hd.where.m[0][0] * 5; - CarTail.vx = dvz + (iVar11 >> 8); - dvz = (int)targetVehicle->hd.where.m[2][0] * 5; - CarTail.vz = dvx + (dvz >> 8); + CarTail.vx = dvz + (targetVehicle->hd.where.m[0][0] * 5 >> 8); + CarTail.vz = dvx + (targetVehicle->hd.where.m[2][0] * 5 >> 8); } } else @@ -962,102 +924,88 @@ void CopControl1(_CAR_DATA *cp) } if (gTimeInWater == 0) - { targetFound = 0; - } - - /* - zoneFrnt = 0, - zoneBack = 1, - zoneLeft = 2, - zoneRght = 3, - */ if (targetFound) { - dvz = FIXEDH(cp->hd.where.m[0][0] * cp->st.n.linearVelocity[0] + cp->hd.where.m[2][0] * cp->st.n.linearVelocity[2]); - dvx = FIXEDH((x - targetPoint.vx) * cp->hd.where.m[2][0] + (targetPoint.vz - z) * cp->hd.where.m[0][0]); - iVar5 = FIXEDH((targetPoint.vx - x) * cp->hd.where.m[0][0] + (targetPoint.vz - z) * cp->hd.where.m[2][0]) - dvz / 140; + slidevel = FIXEDH(cp->hd.where.m[0][0] * cp->st.n.linearVelocity[0] + cp->hd.where.m[2][0] * cp->st.n.linearVelocity[2]); - if (iVar5 < 1) + path[1].t = dvx = FIXEDH((x - targetPoint.vx) * cp->hd.where.m[2][0] + (targetPoint.vz - z) * cp->hd.where.m[0][0]); + path[1].n = steeringFac = FIXEDH((targetPoint.vx - x) * cp->hd.where.m[0][0] + (targetPoint.vz - z) * cp->hd.where.m[2][0]) - slidevel / 140; + + if (path[1].n < 1) { - if ((iVar5 * -2 < dvx) && (cp->ai.p.frontLClear != 0)) - goto LAB_0002e728; - - targetZone = zoneLeft; - targetFound = -iVar5 < (dvx << 2); - LAB_0002e708: - if (targetFound && cp->ai.p.close_pursuit != 0) + if (path[1].n * -2 >= path[1].t || cp->ai.p.frontLClear == 0) { - targetZone = zoneBack; + targetZone = zoneLeft; + targetFound = -path[1].n < (path[1].t << 2); + + if (targetFound && cp->ai.p.close_pursuit != 0) + targetZone = zoneBack; } + else + targetZone = zoneFrnt; } else { - if ((dvx <= iVar5 * 2) || (cp->ai.p.frontRClear == 0)) + if (path[1].n * 2 >= path[1].t || cp->ai.p.frontRClear == 0) { targetZone = zoneRght; - targetFound = iVar5 < (dvx << 2); - goto LAB_0002e708; + targetFound = path[1].n < (path[1].t << 2); + + if (targetFound && cp->ai.p.close_pursuit != 0) + targetZone = zoneBack; } - - LAB_0002e728: - targetZone = zoneFrnt; + else + targetZone = zoneFrnt; } - uVar12 = iVar5 + dvz / 140; + steerDif = path[1].n + slidevel / 140; if (targetZone == zoneFrnt) - { + { if (pathStraight == 0) - piVar8 = speed1; + cp->ai.p.desiredSpeed = speed1[gCopDifficultyLevel]; else - piVar8 = speed2; - - cp->ai.p.desiredSpeed = *(short*)(piVar8 + gCopDifficultyLevel); + cp->ai.p.desiredSpeed = speed2[gCopDifficultyLevel]; if (player[0].playerCarId < 0) - psVar9 = &pedestrianFelony; + playerFelony = &pedestrianFelony; else - psVar9 = &car_data[player[0].playerCarId].felonyRating; + playerFelony = &car_data[player[0].playerCarId].felonyRating; if (gCopData.cutOffDistance < cp->ai.p.DistanceToPlayer) - { - iVar5 = gCopData.cutOffPowerScale; - } + maxPower = gCopData.cutOffPowerScale; else - { - iVar5 = gCopDesiredSpeedScale; - } + maxPower = gCopDesiredSpeedScale; - cp->ai.p.desiredSpeed = FIXEDH(cp->ai.p.desiredSpeed * (iVar5 + FIXEDH(*psVar9 * gCopData.autoDesiredSpeedScaleLimit))); + cp->ai.p.desiredSpeed = FIXEDH(cp->ai.p.desiredSpeed * (maxPower + FIXEDH(*playerFelony * gCopData.autoDesiredSpeedScaleLimit))); if (gPuppyDogCop != 0 && cp->ai.p.close_pursuit != 0) { - iVar5 = targetVehicle->hd.speed + 10; - - if (dist <= 4000) + plcrspd = targetVehicle->hd.speed + 10; + + if (dist > 4000) { - cp->ai.p.desiredSpeed = iVar5; + speedDif = (cp->ai.p.desiredSpeed - plcrspd) * (dist - 4000); + cp->ai.p.desiredSpeed = plcrspd + speedDif / 4000; } else { - iVar14 = (cp->ai.p.desiredSpeed - iVar5) * (dist - 4000); - cp->ai.p.desiredSpeed = iVar5 + iVar14 / 4000;// ((short)((unsigned long long)((long long)iVar14 * 0x10624dd3) >> 0x28) - (short)(iVar14 >> 0x1f)); // [A] can be invalid + cp->ai.p.desiredSpeed = plcrspd; } } - desiredSteerAngle = (uVar12 * 512) / dvx; + desiredSteerAngle = (steerDif * 512) / path[1].t; } else if (targetZone == zoneBack) { cp->ai.p.desiredSpeed = -70; - desiredSteerAngle = 284; - - if ((uVar12 ^ currentSpeed) < 0) - { + + if ((steerDif ^ currentSpeed) < 0) desiredSteerAngle = -284; - } + else + desiredSteerAngle = 284; } else { @@ -1073,12 +1021,10 @@ void CopControl1(_CAR_DATA *cp) cp->wheelspin = 1; } - desiredSteerAngle = 512; - - if ((uVar12 ^ currentSpeed) < 0) - { + if ((steerDif ^ currentSpeed) < 0) desiredSteerAngle = -512; - } + else + desiredSteerAngle = 512; } } else if (cp->ai.p.recoveryTimer < 1) @@ -1087,6 +1033,7 @@ void CopControl1(_CAR_DATA *cp) desiredSteerAngle = 0; } + // calculate the desired speed if (dist < 4096 && cp->ai.p.desiredSpeed > 0 && gBatterPlayer == 0) { plcrspd = targetVehicle->hd.speed - 20; @@ -1097,52 +1044,50 @@ void CopControl1(_CAR_DATA *cp) cp->ai.p.desiredSpeed = FIXEDH(dist * cp->ai.p.desiredSpeed + (4096 - dist) * plcrspd); } - iVar5 = (gCopDifficultyLevel + 8) * 0x400; + // calculate acceleration + maxPower = steeringFac = (gCopDifficultyLevel + 8) * 0x400; currentSpeed = cp->ai.p.desiredSpeed - currentSpeed; if (pathStraight != 0) - iVar5 += (gCopDifficultyLevel + 4) * 0x400; + maxPower += (gCopDifficultyLevel + 4) * 0x400; - if ((int)player[0].playerCarId < 0) - psVar9 = &pedestrianFelony; + if (player[0].playerCarId < 0) + playerFelony = &pedestrianFelony; else - psVar9 = &car_data[(int)player[0].playerCarId].felonyRating; + playerFelony = &car_data[player[0].playerCarId].felonyRating; - iVar5 = FIXEDH(iVar5 * (gCopMaxPowerScale + FIXEDH(*psVar9 * gCopData.autoMaxPowerScaleLimit))); - sVar13 = iVar5; + maxPower = FIXEDH(maxPower * (gCopMaxPowerScale + FIXEDH(*playerFelony * gCopData.autoMaxPowerScaleLimit))); if (currentSpeed < -50) - cp->thrust = -sVar13; + cp->thrust = -maxPower; else if (currentSpeed > 50) - cp->thrust = sVar13; + cp->thrust = maxPower; else - cp->thrust = (currentSpeed * iVar5) / 50; + cp->thrust = (currentSpeed * maxPower) / 50; - iVar5 = cp->hd.speed; - - if (iVar5 < 48) - cp->thrust = (cp->thrust * (iVar5 + 80) >> 7); + if (cp->hd.speed < 48) + cp->thrust = (cp->thrust * (cp->hd.speed + 80) >> 7); if (handlingType[cp->hndType].fourWheelDrive == 1) - cp->thrust = cp->thrust >> 1; + cp->thrust /= 2; - cp->thrust = ((cp->thrust * 7) / 10); + cp->thrust = (cp->thrust * 7) / 10; - iVar5 = ((desiredSteerAngle + 0x800U & 0xfff) - 0x800) - (int)cp->wheel_angle; - sVar13 = (short)iVar5; + // calculate steering and direction + steeringFac = ((desiredSteerAngle + 0x800U & 0xfff) - 0x800) - cp->wheel_angle; - if (iVar5 < -200) - sVar13 = -200; - else if (200 < iVar5) - sVar13 = 200; + if (steeringFac < -200) + steeringFac = -200; + else if (steeringFac > 200) + steeringFac = 200; - cp->wheel_angle = cp->wheel_angle + sVar13; + cp->wheel_angle += steeringFac; if (cp->ai.p.justPinged == 1) { cp->hd.direction = getHeadingToPlayer(cp->hd.where.t[0], cp->hd.where.t[1], cp->hd.where.t[2]); - TempBuildHandlingMatrix((_CAR_DATA*)cp, 0); + cp->ai.p.justPinged = 0; } } @@ -1181,35 +1126,40 @@ void CopControl1(_CAR_DATA *cp) /* end block 4 */ // End Line: 4803 -// [D] +// [D] [T] int FindCost(int x, int z, int dvx, int dvz) { - int iVar1; + static unsigned char sqtbl[] = { + 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, + 0x81, 0x81, 0x81, 0x82, 0x82, 0x83, 0x83, 0x83, 0x84, + 0x84, 0x85, 0x86, 0x86, 0x87, 0x88, 0x88, 0x89, 0x8A, + 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, 0x90, 0x90, 0x91, + 0x92, 0x93, 0x94, 0x95, 0x96, 0x98, 0x99, 0x9A, 0x9B, + 0x9C, 0x9D, 0x9E, 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA6, + 0xA7, 0xA8, 0xAA, 0xAB, 0xAC, 0xAE, 0xAF, 0xB0, 0xB2, + 0xB3, 0xB5 + }; - x = x - (targetVehicle->hd.where.t[0] + (dvx >> 8)); + int tx, tz, dx, dz; + int d; - if (x < 0) - x = -x; + tx = (targetVehicle->hd.where.t[0] + (dvx / 256)); + tz = (targetVehicle->hd.where.t[2] + (dvz / 256)); - z = z - (targetVehicle->hd.where.t[2] + (dvz >> 8)); + dx = ABS(x - tx); + dz = ABS(z - tz); - if (z < 0) - z = -z; - - iVar1 = z; - - if (x < z) + // swap + if (dz > dx) { - iVar1 = x; - x = z; + d = dx; + + dx = dz; + dz = d; } - if (x != 0) - { - x = x * sqtbl[(iVar1 << 6) / x]; - - return x >> 7; - } + if (dx != 0) + return (dx * sqtbl[(dz * 64) / dx]) / 128; return 0; } @@ -1245,28 +1195,24 @@ int FindCost(int x, int z, int dvx, int dvz) /* end block 4 */ // End Line: 4379 -// [D] +// [D] [T] void InitCopData(COP_DATA *pCopData) { - short *psVar1; - int iVar2; - int iVar3; + short *pTrigger; + int trigger; - psVar1 = pCopData->trigger; - iVar3 = 0; + pTrigger = pCopData->trigger; + trigger = 0; - if (psVar1 < pCopData->trigger + 4) + while (pTrigger < pCopData->trigger + 4) { - iVar2 = 0x3330000; - do { - *psVar1 = iVar3; - iVar3 = iVar2 >> 0x10; - psVar1++; - iVar2 += 0x3330000; - } while (psVar1 < pCopData->trigger + 4); + *pTrigger = trigger; + pTrigger++; + + trigger += 0x333; } - *psVar1 = 0x7fff; + *pTrigger = 0x7fff; said_picked_up = 0; } @@ -1302,17 +1248,17 @@ void InitCopData(COP_DATA *pCopData) /* WARNING: Unknown calling convention yet parameter storage is locked */ -// [D] +// [D] [T] void UpdateCopSightData(void) { - short *psVar1; + short *playerFelony; if (player[0].playerCarId < 0) - psVar1 = &pedestrianFelony; + playerFelony = &pedestrianFelony; else - psVar1 = &car_data[player[0].playerCarId].felonyRating; + playerFelony = &car_data[player[0].playerCarId].felonyRating; - if (*psVar1 < 0x293) + if (*playerFelony < 0x293) { copSightData.surroundViewDistance = 0xaa0; copSightData.frontViewDistance = 0x1e8c; @@ -1486,16 +1432,12 @@ void UpdateCopSightData(void) // [D] void ControlCopDetection(void) { - unsigned char uVar1; - bool bVar2; - char cVar3; - short sVar4; - int y; - short *psVar5; - long lVar6; - - int x; - int iVar7; + bool spotted; + int dz; + short *playerFelony; + long distanceToPlayer; + int heading; + int dx; _CAR_DATA *cp; VECTOR vec; VECTOR delta; @@ -1508,80 +1450,60 @@ void ControlCopDetection(void) GetVisSetAtPosition(&vec, CopWorkMem, &ccx, &ccz); if (player[0].playerCarId < 0) - psVar5 = &pedestrianFelony; + playerFelony = &pedestrianFelony; else - psVar5 = &car_data[player[0].playerCarId].felonyRating; + playerFelony = &car_data[player[0].playerCarId].felonyRating; - bVar2 = 0x292 < *psVar5; + if (*playerFelony > 0x292) + { + copSightData.surroundViewDistance = 5440; + copSightData.frontViewDistance = 16320; + copSightData.frontViewAngle = 1024; + } + else + { + copSightData.surroundViewDistance = 2720; + copSightData.frontViewDistance = 7820; + copSightData.frontViewAngle = 512; + } - copSightData.surroundViewDistance = 0xaa0; - - if (bVar2) - copSightData.surroundViewDistance = 0x1540; - - copSightData.frontViewDistance = 0x1e8c; - - if (bVar2) - copSightData.frontViewDistance = 0x3fc0; - - copSightData.frontViewAngle = 0x200; - - if (bVar2) - copSightData.frontViewAngle = 0x400; - - - bVar2 = player_position_known < 1; - player_position_known = 2; - - if (bVar2) + if (player_position_known < 1) player_position_known = 1; + else + player_position_known = 2; CopsCanSeePlayer = 0; - if (player[0].playerType != 2 && -1 < player[0].playerCarId) + // if player is not on foot - check his visibility + if (player[0].playerType != 2 && + player[0].playerCarId > -1) { if (numRoadblockCars != 0) { - x = roadblockLoc.vx - player[0].pos[0]; - if (x < 0) - x = -x; + dx = ABS(roadblockLoc.vx - vec.vx); + dz = ABS(roadblockLoc.vz - vec.vz); - y = roadblockLoc.vz - player[0].pos[2]; - if (y < 0) - y = -y; - - if (((x >> 8) * (x >> 8) + (y >> 8) * (y >> 8) < 0x668) && newPositionVisible(&roadblockLoc, CopWorkMem, ccx, ccz) != 0) + if (((dx >> 8) * (dx >> 8) + (dz >> 8) * (dz >> 8) < 0x668) && + newPositionVisible(&roadblockLoc, CopWorkMem, ccx, ccz) != 0) CopsCanSeePlayer = 1; } if (CopsCanSeePlayer == 0) { - cp = &car_data[19]; + cp = &car_data[MAX_CARS-1]; while (car_data <= cp) { if (cp->controlType == 3 && cp->ai.p.dying == 0 || cp->controlFlags & CONTROL_FLAG_COP) { - vec.vx = cp->hd.where.t[0]; - vec.vz = cp->hd.where.t[2]; - y = cp->hd.where.t[0]; - x = y - player[0].pos[0]; + dx = ABS(cp->hd.where.t[0] - vec.vx); + dz = ABS(cp->hd.where.t[2] - vec.vz); - if (x < 0) - x = player[0].pos[0] - y; - - iVar7 = cp->hd.where.t[2]; - y = iVar7 - player[0].pos[2]; - - if (y < 0) - y = player[0].pos[2] - iVar7; - - lVar6 = SquareRoot0(x * x + y * y); - + distanceToPlayer = SquareRoot0(dx * dx + dz * dz); if (cp->controlType == 3) { - cp->ai.p.DistanceToPlayer = lVar6; + cp->ai.p.DistanceToPlayer = distanceToPlayer; if(cp->ai.p.close_pursuit != 0) { @@ -1592,37 +1514,29 @@ void ControlCopDetection(void) if (newPositionVisible(&vec, CopWorkMem, ccx, ccz) != 0) { - if (lVar6 < copSightData.surroundViewDistance) + spotted = false; + + if (distanceToPlayer < copSightData.surroundViewDistance) { - LAB_0002f030: - bVar2 = true; + spotted = true; } - else + else if (distanceToPlayer < copSightData.frontViewDistance) { - bVar2 = false; - if (lVar6 < copSightData.frontViewDistance) + int theta; + + dz = vec.vx - cp->hd.where.t[0]; + dx = vec.vz - cp->hd.where.t[2]; + + theta = ABS(ratan2(dz, dx) - cp->hd.direction); + + if (theta < copSightData.frontViewAngle || + theta < copSightData.frontViewAngle + 512) { - y = targetVehicle->hd.where.t[0] - cp->hd.where.t[0]; - x = targetVehicle->hd.where.t[2] - cp->hd.where.t[2]; - - lVar6 = ratan2(y, x); - - if (lVar6 - cp->hd.direction < 0) - { - lVar6 = ratan2(y, x); - x = cp->hd.direction - lVar6; - } - else - { - lVar6 = ratan2(y, x); - x = lVar6 - cp->hd.direction; - } - - if ((x < copSightData.frontViewAngle) || (bVar2 = false, x < copSightData.frontViewAngle + 0x200)) - goto LAB_0002f030; + spotted = true; } } - if (bVar2) + + if (spotted) { CopsCanSeePlayer = 1; break; @@ -1634,55 +1548,47 @@ void ControlCopDetection(void) } } - if (numActiveCops == 0 && OutOfSightCount < 0x100 && 8 < CameraCnt) + if (numActiveCops == 0 && OutOfSightCount < 256 && CameraCnt > 8) { - OutOfSightCount = 0x100; + OutOfSightCount = 256; } + // if cops can't see player - get out of pursued state if (CopsCanSeePlayer == 0) { - x = OutOfSightCount + 1; - - if (0xff < OutOfSightCount) + if (OutOfSightCount <= 255) { - if (OutOfSightCount == 0x100) + OutOfSightCount++; + } + else if (OutOfSightCount == 256) + { + player_position_known = -1; + OutOfSightCount = 257; + + if (player[0].playerCarId < 0) + playerFelony = &pedestrianFelony; + else + playerFelony = &car_data[player[0].playerCarId].felonyRating; + + if (*playerFelony > 0x292 && first_offence == 0) { - player_position_known = -1; - OutOfSightCount = 0x101; - - if (player[0].playerCarId < 0) - psVar5 = &pedestrianFelony; - else - psVar5 = &car_data[player[0].playerCarId].felonyRating; - - x = OutOfSightCount; - - if ((0x292 < *psVar5) && (first_offence == '\0')) - { - CopSay(0xc, 0); - FunkUpDaBGMTunez(0); - - x = OutOfSightCount; - } - } - else - { - player_position_known = 0; - x = OutOfSightCount; + CopSay(12, 0); + FunkUpDaBGMTunez(0); } } + else + { + player_position_known = 0; + } } else { OutOfSightCount = 0; - x = OutOfSightCount; } - OutOfSightCount = x; - if (player_position_known < 1) { - cp = &car_data[19]; + cp = &car_data[MAX_CARS-1]; do { if (cp->controlType == CONTROL_TYPE_PURSUER_AI) @@ -1704,36 +1610,34 @@ void ControlCopDetection(void) } while (car_data <= cp); } - x = player_position_known; - - if ((player_position_known == 1) && (first_offence == 0)) + if (player_position_known == 1 && first_offence == 0) { - lVar6 = Random2(2); - cVar3 = GetCarDirectionOfTravel(car_data + player[0].playerCarId); + heading = GetCarDirectionOfTravel(&car_data[player[0].playerCarId]); - CopSay(lVar6 % 2 + 10, cVar3); + CopSay(Random2(2) % 2 + 10, heading); - said_picked_up = x; + said_picked_up = player_position_known; - LastHeading = cVar3; + LastHeading = heading; } - if (CopsCanSeePlayer == 0) - said_picked_up = 0; - - else if ((first_offence == 0) && (said_picked_up == 0)) + if (CopsCanSeePlayer == 0) { - lVar6 = Random2(2); + said_picked_up = 0; + } + else if (first_offence == 0 && said_picked_up == 0) + { + int rnd; + rnd = Random2(2); - x = GetCarDirectionOfTravel(&car_data[player[0].playerCarId]); + heading = GetCarDirectionOfTravel(&car_data[player[0].playerCarId]); - if ((lVar6 == (lVar6 / 5) * 5) && (x != LastHeading)) - CopSay(lVar6 % 2 + 10, x); + if ((rnd == (rnd / 5) * 5) && (dx != LastHeading)) + CopSay(rnd % 2 + 10, heading); said_picked_up = 1; - LastHeading = x; + LastHeading = heading; } - return; } @@ -1768,17 +1672,17 @@ void ControlCopDetection(void) /* end block 3 */ // End Line: 4655 -// [D] +// [D] [T] void PassiveCopTasks(_CAR_DATA *cp) { - short *psVar2; + short *playerFelony; if (player[0].playerCarId < 0) - psVar2 = &pedestrianFelony; + playerFelony = &pedestrianFelony; else - psVar2 = &car_data[player[0].playerCarId].felonyRating; + playerFelony = &car_data[player[0].playerCarId].felonyRating; - if (*psVar2 < 0x293) + if (*playerFelony < 0x293) return; if (player_position_known < 1) @@ -1791,26 +1695,15 @@ void PassiveCopTasks(_CAR_DATA *cp) cp->ai.p.justPinged = 1; - if (gCopDifficultyLevel == 1) - { + if (gCopDifficultyLevel == 2) + cp->hndType = 4; + else if (gCopDifficultyLevel == 1) cp->hndType = 3; - } - else - { + else if (gCopDifficultyLevel == 0) + cp->hndType = 2; + else cp->hndType = 4; - if (gCopDifficultyLevel < 2) - { - if (gCopDifficultyLevel != 0) - { - cp->hndType = 4; - goto LAB_0002f7c4; - } - cp->hndType = 2; - } - } - -LAB_0002f7c4: cp->ai.p.justPinged = 0; numCivCars--; numActiveCops++; @@ -1900,92 +1793,89 @@ LAB_0002f7c4: /* WARNING: Unknown calling convention yet parameter storage is locked */ -// [D] +// [D] [T] void ControlNumberOfCops(void) { - short sVar1; - short *psVar2; - short *psVar3; - uint uVar4; - _CAR_DATA *p_Var5; - int iVar6; - uint uVar7; - int iVar8; + short *pTrigger; + short *playerFelony; + int tempDist; + _CAR_DATA *lcp; + int respawnTime; + int num_closer; + int cutOffDistance; + int numWantedCops; - psVar2 = gCopData.trigger; - iVar8 = 0; + pTrigger = gCopData.trigger; + numWantedCops = 0; - while (true) + while( true ) { - sVar1 = *psVar2; - psVar2++; - if (player[0].playerCarId < 0) - psVar3 = &pedestrianFelony; - else - psVar3 = &car_data[player[0].playerCarId].felonyRating; + playerFelony = &pedestrianFelony; + else + playerFelony = &car_data[player[0].playerCarId].felonyRating; - if (*psVar3 < sVar1) + if (*playerFelony < *pTrigger) break; - iVar8++; + pTrigger++; + numWantedCops++; } - iVar6 = gMinimumCops; + if (numWantedCops < gMinimumCops) + numWantedCops = gMinimumCops; - if ((iVar8 < gMinimumCops) || (iVar6 = maxCopCars, maxCopCars < iVar8)) + if (numWantedCops > maxCopCars) + numWantedCops = maxCopCars; + + if (numCopCars < numWantedCops && gDontPingInCops == 0) { - iVar8 = iVar6; - } - if (numCopCars < iVar8 && gDontPingInCops == 0) - { - iVar8 = gCopRespawnTime; + respawnTime = gCopRespawnTime; + + if (Roadblock.status == 2) + respawnTime = Roadblock.copRespawnTime; - if (Roadblock.status == 2) - iVar8 = Roadblock.copRespawnTime; - - if (player[0].playerCarId < 0) - psVar2 = &pedestrianFelony; - else - psVar2 = &car_data[(int)player[0].playerCarId].felonyRating; - - - if (iVar8 * FIXEDH(0x1000 - FIXEDH(*psVar2 * gCopData.autoRespawnScaleLimit)) < cop_respawn_timer + 1) + if (respawnTime * FIXED(4096 - FIXED(*playerFelony * gCopData.autoRespawnScaleLimit)) < cop_respawn_timer + 1) + { requestCopCar = 1; + } cop_respawn_timer++; return; } - if (numCopCars <= iVar8) + if (numCopCars <= numWantedCops) { gCopData.cutOffDistance = 0x7fffffff; cop_respawn_timer = 0; return; } - + gCopData.cutOffDistance = 0x7fffffff; do { - uVar7 = 0; - p_Var5 = car_data; - iVar6 = 0; + cutOffDistance = 0; + lcp = car_data; + num_closer = 0; - if (true) { - do { - if (p_Var5->controlType == CONTROL_TYPE_PURSUER_AI) + do { + if (lcp->controlType == CONTROL_TYPE_PURSUER_AI) + { + tempDist = lcp->ai.p.DistanceToPlayer; + + if (tempDist < gCopData.cutOffDistance) { - uVar4 = p_Var5->ai.p.DistanceToPlayer; - if ((uVar4 < gCopData.cutOffDistance) && (iVar6 = iVar6 + 1, uVar7 < uVar4)) - { - uVar7 = uVar4; - } + if(cutOffDistance < tempDist) + cutOffDistance = tempDist; + + num_closer++; } - p_Var5++; - } while (p_Var5 < &car_data[20]); - } - gCopData.cutOffDistance = uVar7; - } while (iVar8 < iVar6); + } + lcp++; + } while (lcp < car_data + MAX_CARS); + + gCopData.cutOffDistance = cutOffDistance; + } while (numWantedCops < num_closer); cop_respawn_timer = 0; } From 5ee58b06a220b531bad20a38a366c0a1872b233d Mon Sep 17 00:00:00 2001 From: Ilya Shurumov Date: Tue, 13 Oct 2020 22:49:21 +0600 Subject: [PATCH 35/41] - fix Tanner turn animation --- src_rebuild/GAME/C/MOTION_C.C | 4 ++++ src_rebuild/GAME/C/PEDEST.C | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src_rebuild/GAME/C/MOTION_C.C b/src_rebuild/GAME/C/MOTION_C.C index 95998f54..b404c6b7 100644 --- a/src_rebuild/GAME/C/MOTION_C.C +++ b/src_rebuild/GAME/C/MOTION_C.C @@ -711,6 +711,10 @@ void DrawBodySprite(PEDESTRIAN *pDrawingPed, int boneId, VERTTYPE v1[2], VERTTYP prims->b0 = combointensity & 0xFF; } +#ifndef PSX + prims->pgxp_index = 0xFFFF; +#endif + if (bDoingShadow == 0) { x = sz + sy >> 4; diff --git a/src_rebuild/GAME/C/PEDEST.C b/src_rebuild/GAME/C/PEDEST.C index c04b7c34..88ad9e53 100644 --- a/src_rebuild/GAME/C/PEDEST.C +++ b/src_rebuild/GAME/C/PEDEST.C @@ -1898,8 +1898,10 @@ void PedDoNothing(PEDESTRIAN* pPed) pPed->dir.vy = pPed->dir.vy - 64 + (tannerTurnMax - pPed->doing_turn) * tannerTurnStep; - if (pPed->frame1 > 16) + if (pPed->frame1 > 14) pPed->frame1 = 0; + else + pPed->frame1++; pPed->head_rot = 0; } From 93678a9a5e0f08f7a63a79da5d893f266aa403cc Mon Sep 17 00:00:00 2001 From: Ilya Shurumov Date: Tue, 13 Oct 2020 22:49:49 +0600 Subject: [PATCH 36/41] - fix road block car touching --- src_rebuild/GAME/C/HANDLING.C | 82 +++++++++++++++++------------------ 1 file changed, 40 insertions(+), 42 deletions(-) diff --git a/src_rebuild/GAME/C/HANDLING.C b/src_rebuild/GAME/C/HANDLING.C index d6207643..ba4fba5e 100644 --- a/src_rebuild/GAME/C/HANDLING.C +++ b/src_rebuild/GAME/C/HANDLING.C @@ -956,7 +956,7 @@ void GlobalTimeStep(void) if (c1->controlType == CONTROL_TYPE_PLAYER && IS_ROADBLOCK_CAR(cp)) { InitCopState(cp, NULL); - c1->ai.p.justPinged = 0; + cp->ai.p.justPinged = 0; } } @@ -1993,14 +1993,18 @@ void ProcessCarPad(_CAR_DATA *cp, ulong pad, char PadSteer, char use_analogue) cp->hd.autoBrake = 90; // handle burnouts or handbrake - if ((pad & 0x10) == 0) + if (pad & 0x10) + { + cp->handbrake = 1; + } + else { cp->handbrake = 0; - if ((pad & 0x20) == 0) - cp->wheelspin = 0; - else + if (pad & 0x20) cp->wheelspin = 1; + else + cp->wheelspin = 0; // continue without burnout if (cp->wheelspin != 0 && cp->hd.wheel_speed > 0x6e958) @@ -2009,37 +2013,14 @@ void ProcessCarPad(_CAR_DATA *cp, ulong pad, char PadSteer, char use_analogue) pad |= 0x40; } } - else - { - cp->handbrake = 1; - } // handle steering if (use_analogue == 0) { - if ((pad & 4) == 0) - { - // regular steer - if((pad & 0x2000) != 0) - { - cp->wheel_angle += 32; - - if (cp->wheel_angle > 352) - cp->wheel_angle = 352; - } - - if ((pad & 0x8000) != 0) - { - cp->wheel_angle -= 32; - - if (cp->wheel_angle < -352) - cp->wheel_angle = -352; - } - } - else + if (pad & 0x4) { // fast steer - if ((pad & 0x2000) != 0) + if (pad & 0x2000) { cp->wheel_angle += 64; @@ -2047,7 +2028,7 @@ void ProcessCarPad(_CAR_DATA *cp, ulong pad, char PadSteer, char use_analogue) cp->wheel_angle = 511; } - if ((pad & 0x8000) != 0) + if (pad & 0x8000) { cp->wheel_angle -= 64; @@ -2055,24 +2036,43 @@ void ProcessCarPad(_CAR_DATA *cp, ulong pad, char PadSteer, char use_analogue) cp->wheel_angle = -511; } } + else + { + // regular steer + if(pad & 0x2000) + { + cp->wheel_angle += 32; - if ((pad & 0xa000) != 0) + if (cp->wheel_angle > 352) + cp->wheel_angle = 352; + } + + if (pad & 0x8000) + { + cp->wheel_angle -= 32; + + if (cp->wheel_angle < -352) + cp->wheel_angle = -352; + } + } + + if (pad & 0xa000) cp->hd.autoBrake++; else cp->hd.autoBrake = 0; } else { - if ((pad & 4) == 0) - { - int_steer *= (int_steer * int_steer) / 80; - analog_angle = ((long long)int_steer * 0x66666667) >> 32; // int_steer * 0.4 - } - else + if (pad & 0x4) { int_steer *= (int_steer * int_steer) / 60; analog_angle = ((long long)int_steer * 0x88888889) >> 32; // int_steer * 0.6 } + else + { + int_steer *= (int_steer * int_steer) / 80; + analog_angle = ((long long)int_steer * 0x66666667) >> 32; // int_steer * 0.4 + } analog_angle = (analog_angle >> 5) - (int_steer >> 0x1f); @@ -2099,7 +2099,7 @@ void ProcessCarPad(_CAR_DATA *cp, ulong pad, char PadSteer, char use_analogue) if (gTimeInWater != 0) { - if ((pad & 0x80) != 0) + if (pad & 0x80) { int rws; @@ -2113,7 +2113,7 @@ void ProcessCarPad(_CAR_DATA *cp, ulong pad, char PadSteer, char use_analogue) cp->thrust = FIXEDH(cp->ap.carCos->powerRatio * rws); } - else if ((pad & 0x40) != 0) + else if (pad & 0x40) { if (cp->hndType == 5) { @@ -2151,8 +2151,6 @@ void ProcessCarPad(_CAR_DATA *cp, ulong pad, char PadSteer, char use_analogue) _CAR_DATA* tp; int targetCarId, cx, cz, chase_square_dist; - targetCarId = -1; - if (player[0].playerCarId == cp->id) targetCarId = player[0].targetCarId; else if (player[1].playerCarId == cp->id) From b357ad4b9550ce354f29fe686afd2857b2de6ff4 Mon Sep 17 00:00:00 2001 From: Ilya Shurumov Date: Wed, 14 Oct 2020 00:24:56 +0600 Subject: [PATCH 37/41] - refactor PRES.C --- src_rebuild/GAME/C/PRES.C | 571 +++++++++++++++++--------------------- 1 file changed, 258 insertions(+), 313 deletions(-) diff --git a/src_rebuild/GAME/C/PRES.C b/src_rebuild/GAME/C/PRES.C index 57004e69..7ef024a2 100644 --- a/src_rebuild/GAME/C/PRES.C +++ b/src_rebuild/GAME/C/PRES.C @@ -65,7 +65,7 @@ OUT_FONTINFO fontinfo[128]; /* end block 3 */ // End Line: 1310 -// [D] +// [D] [T] void SetTextColour(unsigned char Red, unsigned char Green, unsigned char Blue) { gFontColour.r = Red; @@ -108,34 +108,29 @@ void SetTextColour(unsigned char Red, unsigned char Green, unsigned char Blue) /* end block 3 */ // End Line: 1344 -// [D] +// [D] [T] int StringWidth(char *pString) { - char bVar1; - char *pbVar2; - int iVar3; + char let; + int w; - iVar3 = 0; - bVar1 = *pString; - pbVar2 = (pString + 1); - while (bVar1 != 0) { - if (bVar1 == 0x20) { - iVar3 = iVar3 + 4; - } - else { - if (((uint)bVar1 + 0x80 & 0xff) < 0xb) { - iVar3 = iVar3 + 0x18; - } - else { - if (AsciiTable[(uint)bVar1] != 0xff) { - iVar3 = iVar3 + (uint)fontinfo[AsciiTable[(uint)bVar1]].width; - } - } - } - bVar1 = *pbVar2; - pbVar2 = pbVar2 + 1; + w = 0; + + while (true) + { + let = *pString++; + if (!let) + break; + + if (let == 32) + w += 4; + else if ((let + 128 & 0xff) < 11) + w += 24; + else if (AsciiTable[let] != 0xff) + w += fontinfo[AsciiTable[let]].width; } - return iVar3; + + return w; } @@ -175,29 +170,26 @@ int StringWidth(char *pString) /* end block 4 */ // End Line: 1424 -// [D] +// [D] [T] int OutputString(char *pString, int formatting, int x, int y, int xw, int r, int g, int b) { - int iVar1; + int xpos; - SetTextColour((unsigned char)r, (unsigned char)g, (unsigned char)b); + SetTextColour(r, g, b); - if ((formatting & 1U) == 0) { - if ((formatting & 2U) == 0) { - if ((formatting & 4U) != 0) { - iVar1 = StringWidth(pString); - PrintString(pString, x - iVar1, y); - } - } - else { - iVar1 = StringWidth(pString); - x = (x + (xw - iVar1 >> 1)) * 0x10000 >> 0x10; - PrintString(pString, x, y); - } - } - else { + if (formatting & 1) + { PrintString(pString, x, y); } + else if (formatting & 2) + { + xpos = (xw - StringWidth(pString)) / 2; + PrintString(pString, x + xpos, y); + } + else if (formatting & 4) + { + PrintString(pString, x - StringWidth(pString), y); + } return x; } @@ -218,13 +210,10 @@ int OutputString(char *pString, int formatting, int x, int y, int xw, int r, int /* end block 2 */ // End Line: 1526 -// [D] +// [D] [T] void PrintStringRightAligned(char *pString, int x, int y) { - int iVar1; - - iVar1 = StringWidth(pString); - PrintString(pString, x - iVar1, y); + PrintString(pString, x - StringWidth(pString), y); } @@ -245,13 +234,10 @@ void PrintStringRightAligned(char *pString, int x, int y) /* end block 2 */ // End Line: 1554 -// [D] +// [D] [T void PrintStringCentred(char *pString, short y) { - int iVar1; - - iVar1 = StringWidth(pString); - PrintString(pString, (0x140 - iVar1) * 0x8000 >> 0x10, y); + PrintString(pString, (320 - StringWidth(pString)) / 2, y); } @@ -282,54 +268,56 @@ void PrintStringCentred(char *pString, short y) /* end block 3 */ // End Line: 723 -// [D] +// [D] [T] void LoadFont(char *buffer) { - int *piVar1; - char *pcVar2; - u_long *puVar3; - int iVar4; - int iVar5; - int iVar6; - int *addr; - RECT16 rect; + int i; + ushort *clut; + int nchars; + char *file; + RECT16 dest; fontclutpos.x = 976; fontclutpos.y = 256; fontclutpos.w = 16; fontclutpos.h = 1; - //addr = (int *)&DAT_0011b400; // [A] FIXME: this font address might be used somewhere else - addr = (int*)_frontend_buffer; - if (buffer != NULL) { - addr = (int *)buffer; - } - Loadfile("GFX\\FONT2.FNT", (char *)addr); - iVar6 = *addr; - memcpy(fontinfo, addr + 1, iVar6 * 8); - addr = addr + 1 + iVar6 * 2; - pcVar2 = AsciiTable; + + if (buffer != NULL) + file = buffer; + else + file = _frontend_buffer; // 0x11b400; // [A] FIXME: this font address might be used somewhere else - memcpy(AsciiTable, addr, 256); + Loadfile("GFX\\FONT2.FNT",file); + nchars = *(int *)file; - fontclutid = GetClut((int)fontclutpos.x, (int)fontclutpos.y); - iVar6 = 0xf; - puVar3 = (u_long *)(addr + 0x40); + // copy character info + memcpy(fontinfo,file + 4,nchars * 8); + + file += sizeof(int) + nchars * 8; + memcpy(AsciiTable, file, 256); + + fontclutid = GetClut(fontclutpos.x,fontclutpos.y); + + i = 0; + clut = (ushort*)(file + 0x100); do { - iVar6 = iVar6 + -1; - *(ushort *)puVar3 = *(ushort *)puVar3 & 0x7fff; - puVar3 = (u_long *)((int)puVar3 + 2); - } while (-1 < iVar6); - *(ushort *)((int)addr + 0x102) = *(ushort *)((int)addr + 0x102) | 0x8000; - *(ushort *)(addr + 0x41) = *(ushort *)(addr + 0x41) | 0x8000; - LoadImage(&fontclutpos, (u_long *)(addr + 0x40)); - rect.x = 960; - rect.y = 466; - rect.w = 64; - rect.h = 46; - fonttpage = GetTPage(0, 0, 960, 466); - LoadImage(&rect, (u_long *)(addr + 0x48)); + *clut++ &= 0x7fff; + i++; + } while(i < 16); + + clut[1] |= 0x8000; + clut[2] |= 0x8000; + + dest.x = 960; + dest.y = 466; + dest.w = 64; + dest.h = 46; + + fonttpage = GetTPage(0,0,0x3c0,0x1d2); + LoadImage(&fontclutpos, (u_long *)(file + 0x100)); + LoadImage(&dest, (u_long *)(file + 0x120)); + DrawSync(0); - return; } @@ -362,16 +350,17 @@ void LoadFont(char *buffer) /* end block 4 */ // End Line: 1697 -// [D] +// [D] [T] void StoreClut2(ulong *pDest, int x, int y) { - RECT16 local_10; + RECT16 rect; - local_10.x = (short)x; - local_10.y = (short)y; - local_10.w = 0x10; - local_10.h = 1; - StoreImage2(&local_10, pDest); + rect.x = x; + rect.y = y; + rect.w = 16; + rect.h = 1; + + StoreImage2(&rect, pDest); } @@ -403,42 +392,36 @@ void StoreClut2(ulong *pDest, int x, int y) /* end block 3 */ // End Line: 1741 -// [D] +// [D] [T] void SetCLUT16Flags(ushort clutID, ushort mask, char transparent) { -#ifdef PSX - ushort uVar1; - ushort *puVar2; - uint uVar3; ushort *pCurrent; - int x; + int ctr; + int x, y; ushort buffer[16]; - x = ((uint)clutID & 0x3f) << 4; + x = (clutID & 0x3f) << 4; + y = (clutID >> 6); - StoreClut2((ulong *)buffer, x, (uint)(clutID >> 6)); + StoreClut2((ulong *)buffer,x,y); - pCurrent = buffer + transparent; - uVar3 = 1; + pCurrent = buffer; + ctr = 1; - // [A] - while ((pCurrent - buffer) < 16) + while (pCurrent < &buffer[16]) { - if (((int)(uint)mask >> (uVar3 & 0x1f) & 1U) == 0) - { - uVar1 = *pCurrent & 0x7fff; - } - else - { - uVar1 = *pCurrent | 0x8000; - } + if (mask >> (ctr & 1U) == 0) + *pCurrent &= 0x7fff; + else + *pCurrent |= 0x8000; - *pCurrent++ = uVar1; - uVar3 = uVar3 + 1 & 0xff; + buffer[transparent] = 0; + + pCurrent++; + ctr++; } - LoadClut2((u_long*)buffer, x, (uint)(clutID >> 6)); -#endif // PSX + LoadClut2((u_long*)buffer, x,y); } @@ -478,110 +461,94 @@ void SetCLUT16Flags(ushort clutID, ushort mask, char transparent) // MAP.C ???? extern int gShowMap; -// [D] +// [D] [T] int PrintString(char *string, int x, int y) { u_char chr; - char bVar1; - unsigned char uVar2; - int iVar3; - short sVar4; - DB *pDVar5; - int x_00; - char *pcVar6; - uint uVar7; + int width; + uint index; SPRT *font; - char *pbVar8; int showMap = gShowMap; - x_00 = -1; - if (current != NULL) + if (current == NULL) + return -1; + + font = (SPRT *)current->primptr; + + if (showMap != 0) + font = (SPRT *)SetFontTPage(font); + + chr = *string++; + width = x; + + while (chr != 0) { - font = (SPRT *)current->primptr; - - if (showMap != 0) - font = (SPRT *)SetFontTPage(font); - - chr = *string; - pbVar8 = (string + 1); - x_00 = x; - while (chr != 0) + if (chr == 32) { - if (chr == 0x20) - { - x_00 = x_00 + 4; - } + width += 4; + } + else if (chr < 32 || chr > 138 || chr < 128) + { + if (AsciiTable[chr] == 0xff) + index = AsciiTable[63]; else - { - if (chr < 0x20 || 0x8a < chr || chr < 0x80) - { - bVar1 = AsciiTable[chr]; - if (AsciiTable[chr] == 0xff) - bVar1 = AsciiTable[63]; + index = AsciiTable[chr]; - uVar7 = (uint)bVar1; - chr = fontinfo[uVar7].width; + chr = fontinfo[index].width; - setSprt(font); + setSprt(font); #ifdef PSX - setSemiTrans(font, 1); + setSemiTrans(font, 1); #endif - //*(undefined *)((int)&font->tag + 3) = 4; - //font->code = 'f'; + font->r0 = gFontColour.r; + font->g0 = gFontColour.g; + font->b0 = gFontColour.b; + + font->x0 = width; + font->y0 = fontinfo[index].offy + y; + font->u0 = fontinfo[index].x; + font->v0 = fontinfo[index].y - 46; + + font->w = chr; + font->h = fontinfo[index].height; + + font->clut = fontclutid; - font->r0 = gFontColour.r; - font->g0 = gFontColour.g; - uVar2 = gFontColour.b; - font->x0 = (short)x_00; - font->b0 = uVar2; - font->y0 = (short)fontinfo[uVar7].offy + (short)y; - font->u0 = fontinfo[uVar7].x; - uVar2 = fontinfo[uVar7].y; - font->w = (ushort)chr; - font->v0 = uVar2 - 46; - sVar4 = fontclutid; - - font->h = (ushort)fontinfo[uVar7].height; - font->clut = sVar4; - pDVar5 = current; - - if (showMap == 0) - { - addPrim(current->ot, font); - } - else - { - DrawPrim(font); - } - - font = font + 1; - x_00 = x_00 + (uint)chr; - } - else - { - if (showMap == 0) - font = (SPRT *)SetFontTPage(font); - - font = (SPRT *)DrawButton(chr, font, x_00, y); - x_00 = x_00 + 0x18; - - if (showMap != 0) - font = (SPRT *)SetFontTPage(font); - } + if (showMap == 0) + { + addPrim(current->ot, font); } - chr = *pbVar8; - pbVar8 = pbVar8 + 1; + else + { + DrawPrim(font); + } + + font++; + width += chr; + } + else + { + if (showMap == 0) + font = (SPRT *)SetFontTPage(font); + + font = (SPRT *)DrawButton(chr, font, width, y); + width += 24; + + if (showMap != 0) + font = (SPRT *)SetFontTPage(font); } - if (showMap == 0) - current->primptr = (char *)SetFontTPage(font); - else - DrawSync(0); + chr = *string++; } - return x_00; + if (showMap == 0) + current->primptr = (char *)SetFontTPage(font); + else + DrawSync(0); + + return width; } @@ -624,64 +591,49 @@ int PrintString(char *string, int x, int y) /* end block 3 */ // End Line: 1130 -// [D] +// [D] [T] short PrintDigit(int x, int y, char *string) { - char bVar1; - char bVar2; - unsigned char uVar3; - DB *pDVar4; - short sVar5; - uint uVar6; - ulong *puVar7; + FONT_DIGIT* pDigit; + char chr; + short width; + int index; SPRT *font; - int iVar8; - char cVar9; + int fixedWidth; + char vOff, h; - sVar5 = (short)x; - bVar1 = *string; + width = x; + chr = *string++; - while (bVar1 != 0) + font = (SPRT *)current->primptr; + + while (chr != 0) { - bVar1 = *string; - string++; + if (chr == 58) + index = 11; + else if (chr == 47) + index = 10; + else + index = chr - 48 & 0xff; - if (bVar1 == 0x3a) + pDigit = &fontDigit[index]; + + if (chr == 58) + fixedWidth = 8; + else + fixedWidth = 16; + + if (index < 6) { - uVar6 = 0xb; - } - else if (bVar1 == 0x2f) - { - uVar6 = 10; + vOff = 0; + h = 28; } else { - uVar6 = (uint)bVar1 - 0x30 & 0xff; + vOff = 28; + h = 31; } - bVar2 = fontDigit[uVar6].width; - iVar8 = 0x10; - - if (bVar1 == 0x3a) - { - iVar8 = 8; - } - - cVar9 = '\0'; - - if (uVar6 < 6) - { - sVar5 = 0x1c; - } - else - { - cVar9 = '\x1c'; - sVar5 = 0x1f; - } - - font = (SPRT *)current->primptr; - current->primptr += sizeof(SPRT); - setSprt(font); #ifdef PSX setSemiTrans(font, 1); @@ -691,27 +643,28 @@ short PrintDigit(int x, int y, char *string) font->g0 = gFontColour.g; font->b0 = gFontColour.b; - font->x0 = (short)x + (short)((int)(iVar8 - (uint)bVar2) >> 1); - font->y0 = (short)y; + font->x0 = width + (fixedWidth - pDigit->width) / 2; + font->y0 = y; - font->u0 = digit_texture.coords.u0 + fontDigit[uVar6].xOffset; - font->v0 = cVar9 + digit_texture.coords.v0; + font->u0 = digit_texture.coords.u0 + pDigit->xOffset; + font->v0 = vOff + digit_texture.coords.v0; + + font->w = pDigit->width; + font->h = h; - font->w = (ushort)bVar2; - font->h = sVar5; - - pDVar4 = current; font->clut = digit_texture.clutid; addPrim(current->ot, font); - x = x + iVar8; - sVar5 = (short)x; + width += fixedWidth; - bVar1 = *string; - font = font + 1; + font++; + + chr = *string++; } + current->primptr = (char*)font; + POLY_FT3* null = (POLY_FT3*)current->primptr; setPolyFT3(null); #ifdef PSX @@ -729,9 +682,7 @@ short PrintDigit(int x, int y, char *string) addPrim(current->ot, null); current->primptr += sizeof(POLY_FT3); - pDVar4 = current; - - return sVar5; + return width; } @@ -755,13 +706,10 @@ short PrintDigit(int x, int y, char *string) /* end block 3 */ // End Line: 2128 -// [D] +// [D] [T] int PrintStringFeature(char *string, int x, int y, int w, int h, int transparent) { - int iVar1; - - iVar1 = PrintString(string, x, y); - return iVar1; + return PrintString(string, x, y); } @@ -802,7 +750,7 @@ int PrintStringFeature(char *string, int x, int y, int w, int h, int transparent /* end block 4 */ // End Line: 1388 -// [D] [A] +// [D] [T] void PrintStringBoxed(char *string, int ix, int iy) { SPRT *font; @@ -815,60 +763,57 @@ void PrintStringBoxed(char *string, int ix, int iy) font = (SPRT *)current->primptr; - if (*string != 0) + wordcount = 1; + + x = ix; + y = iy; + + while (*string) { - wordcount = 1; - - x = ix; - y = iy; + string = GetNextWord(string, word); - do + if (x + StringWidth(word) > 308 && (wordcount != 1 || *string != 0)) { - string = GetNextWord(string, word); + x = ix; + y += 14; + } - if ((x + StringWidth(word)) > 308 && (wordcount != 1 || (*string != 0))) + wpt = word; + + char c = 0; + + while ((c = *wpt++) != 0) + { + if (c == ' ') { - x = ix; - y += 14; + x += 4; } - - wpt = word; - - char c = 0; - - while ((c = *wpt++) != 0) + else { - if (c == ' ') + index = AsciiTable[c]; + + if (index != -1) { - x += 4; - } - else - { - index = AsciiTable[c]; + OUT_FONTINFO *pFontInfo = &fontinfo[index]; - if (index != -1) - { - OUT_FONTINFO *pFontInfo = &fontinfo[index]; + setSprt(font); - setSprt(font); + setRGB0(font, gFontColour.r, gFontColour.g, gFontColour.b); + setXY0(font, x, y + pFontInfo->offy); + setUV0(font, pFontInfo->x, pFontInfo->y - 46); + setWH(font, pFontInfo->width, pFontInfo->height); + + font->clut = fontclutid; - setRGB0(font, gFontColour.r, gFontColour.g, gFontColour.b); - setXY0(font, x, y + pFontInfo->offy); - setUV0(font, pFontInfo->x, pFontInfo->y - 46); - setWH(font, pFontInfo->width, pFontInfo->height); - - font->clut = fontclutid; + addPrim(current->ot, font); + font++; - addPrim(current->ot, font); - font++; - - x += pFontInfo->width; - } + x += pFontInfo->width; } } + } - wordcount++; - } while (*string != 0); + wordcount++; } POLY_FT3* null = (POLY_FT3*)font; @@ -929,7 +874,7 @@ void PrintStringBoxed(char *string, int ix, int iy) /* WARNING: Unknown calling convention yet parameter storage is locked */ -// [D] +// [D] [T] void InitButtonTextures(void) { int i; @@ -1003,7 +948,7 @@ int PrintScaledString(int y, char *string, int scale) { c = *string - '0'; - if (*string == 0x20) // space + if (*string == 32) // space { width = (scale / 4); } @@ -1091,7 +1036,7 @@ int PrintScaledString(int y, char *string, int scale) /* end block 4 */ // End Line: 2506 -// [D] +// [D] [T] char * GetNextWord(char *string, char *word) { char c = *string; @@ -1138,7 +1083,7 @@ char * GetNextWord(char *string, char *word) /* end block 3 */ // End Line: 1834 -// [D] +// [D] [T] void* DrawButton(unsigned char button, void *prim, int x, int y) { TEXTURE_DETAILS *btn; @@ -1212,7 +1157,7 @@ void* DrawButton(unsigned char button, void *prim, int x, int y) /* end block 3 */ // End Line: 2621 -// [D] +// [D] [T] void* SetFontTPage(void *prim) { POLY_FT3* null = (POLY_FT3*)prim; From da44ee75c70bf763aedf84f5a68ad73cb1b28390 Mon Sep 17 00:00:00 2001 From: Ilya Shurumov Date: Wed, 14 Oct 2020 00:43:20 +0600 Subject: [PATCH 38/41] - refactor REPLAYS.C --- src_rebuild/GAME/C/REPLAYS.C | 129 ++++++++++++++++------------------- 1 file changed, 59 insertions(+), 70 deletions(-) diff --git a/src_rebuild/GAME/C/REPLAYS.C b/src_rebuild/GAME/C/REPLAYS.C index 2b2b2ca8..4f9ea890 100644 --- a/src_rebuild/GAME/C/REPLAYS.C +++ b/src_rebuild/GAME/C/REPLAYS.C @@ -72,14 +72,13 @@ int way_distance = 0; /* WARNING: Unknown calling convention yet parameter storage is locked */ -// [D] +// [D] [T] void InitPadRecording(void) { - char *pcVar1; - char *pcVar2; + char *bufferEnd; + int remain; int i; - REPLAY_STREAM *stream; gOutOfTape = 0; @@ -99,14 +98,13 @@ void InitPadRecording(void) replayptr = (char*)(PingBuffer + 400); - pcVar1 = ReplayStart; - pcVar2 = replayptr-0x3444; - - int cutsceneSize = CalcInGameCutsceneSize(); + // FIXME: is that correct? + bufferEnd = replayptr-13380; + remain = (uint)ReplayStart - (uint)bufferEnd - CalcInGameCutsceneSize(); for (i = 0; i < NumPlayers; i++) { - AllocateReplayStream(&ReplayStreams[i], ((int)(pcVar1 + (-cutsceneSize - (int)pcVar2)) / sizeof(PADRECORD)) / NumPlayers); + AllocateReplayStream(&ReplayStreams[i], remain / sizeof(PADRECORD) / NumPlayers); NumReplayStreams++; } @@ -156,7 +154,8 @@ void InitPadRecording(void) // Start line: 1348 /* end block 3 */ // End Line: 1349 -// [D] + +// [D] [T] int SaveReplayToBuffer(char *buffer) { REPLAY_STREAM_HEADER *sheader; @@ -375,7 +374,7 @@ int LoadCutsceneAsReplay(int subindex) } #endif // CUTSCENE_RECORDER -// [D] +// [D] [T] int LoadReplayFromBuffer(char *buffer) { REPLAY_SAVE_HEADER *header; @@ -530,7 +529,7 @@ int LoadReplayFromBuffer(char *buffer) /* end block 3 */ // End Line: 2119 -// [D] +// [D] [T] int LoadAttractReplay(int mission) { char filename[32]; @@ -572,7 +571,7 @@ int LoadAttractReplay(int mission) /* end block 3 */ // End Line: 2365 -// [D] +// [D] [T] char GetPingInfo(char *cookieCount) { char retCarId; @@ -637,41 +636,36 @@ char GetPingInfo(char *cookieCount) /* end block 5 */ // End Line: 2833 -// [D] +// [D] [T] int valid_region(int x, int z) { - int iVar1; - int iVar2; + XYPAIR region_coords; - iVar1 = (x >> 0x10) + regions_across / 2; - iVar2 = (z >> 0x10) + regions_down / 2; + int region; - if (-1 < iVar1) { - if (regions_across < iVar1) - return 0; + region_coords.x = (x >> 16) + regions_across / 2; + region_coords.y = (z >> 16) + regions_down / 2; - if (-1 < iVar2) + if (region_coords.x >= 0 && region_coords.x <= regions_across && + region_coords.y >= 0 && region_coords.y <= regions_down) + { + region = region_coords.x + region_coords.y * regions_across; + + if (region != regions_unpacked[0]) { - if (regions_down < iVar2) + if (region == regions_unpacked[1]) + return region + 1; + + if (region == regions_unpacked[2]) + return region + 1; + + if (region != regions_unpacked[3]) return 0; - - iVar1 = iVar1 + iVar2 * regions_across; - - if (iVar1 != regions_unpacked[0]) - { - if (iVar1 == regions_unpacked[1]) - return iVar1 + 1; - - if (iVar1 == regions_unpacked[2]) - return iVar1 + 1; - - if (iVar1 != regions_unpacked[3]) - return 0; - } - - return iVar1 + 1; } + + return region + 1; } + return 0; } @@ -702,7 +696,7 @@ int valid_region(int x, int z) /* end block 3 */ // End Line: 2932 -// [D] +// [D] [T] int cjpPlay(int stream, ulong *ppad, char *psteer, char *ptype) { int ret; @@ -762,18 +756,15 @@ int cjpPlay(int stream, ulong *ppad, char *psteer, char *ptype) char ReplayMode = 0; -// [D] +// [D] [T] void cjpRecord(int stream, ulong *ppad, char *psteer, char *ptype) { - int iVar2; - int iVar3; + int tmp; int t1; ulong t0; if (stream > -1 && stream < NumReplayStreams) { - iVar3 = (int)*psteer; - RecordWaypoint(); if ((*ptype & 4U) == 0) @@ -782,19 +773,19 @@ void cjpRecord(int stream, ulong *ppad, char *psteer, char *ptype) } else { - if (iVar3 < -45) + if (*psteer < -45) { - iVar2 = -45 - iVar3 >> 0x1f; - t1 = (((-45 - iVar3) / 6 + iVar2 >> 1) - iVar2) + 1; + tmp = -45 - *psteer >> 0x1f; // [A] still need to figure out this + t1 = (((-45 - *psteer) / 6 + tmp >> 1) - tmp) + 1; } - else if (iVar3 < 46) + else if (*psteer < 46) { t1 = 8; } else { - iVar2 = iVar3 - 45 >> 0x1f; - t1 = (((iVar3 - 45) / 6 + iVar2 >> 1) - iVar2) + 9; + tmp = *psteer - 45 >> 0x1f; // [A] still need to figure out this + t1 = (((*psteer - 45) / 6 + tmp >> 1) - tmp) + 9; } } @@ -858,14 +849,14 @@ void cjpRecord(int stream, ulong *ppad, char *psteer, char *ptype) /* end block 4 */ // End Line: 3418 -// [D] +// [D] [T] void AllocateReplayStream(REPLAY_STREAM *stream, int maxpad) { stream->playbackrun = 0; stream->length = 0; if(CurrentGameMode != GAMEMODE_DIRECTOR && CurrentGameMode != GAMEMODE_REPLAY) - stream->padCount = 0; + stream->padCount = 0; stream->InitialPadRecordBuffer = (PADRECORD*)replayptr; stream->PadRecordBuffer = (PADRECORD*)replayptr; @@ -909,7 +900,7 @@ void AllocateReplayStream(REPLAY_STREAM *stream, int maxpad) /* end block 3 */ // End Line: 3467 -// [D] +// [D] [T] int Get(int stream, ulong *pt0) { REPLAY_STREAM* rstream; @@ -979,7 +970,7 @@ int Get(int stream, ulong *pt0) /* end block 5 */ // End Line: 3545 -// [D] +// [D] [T] int Put(int stream, ulong *pt0) { REPLAY_STREAM *rstream; @@ -1046,25 +1037,23 @@ int Put(int stream, ulong *pt0) /* WARNING: Unknown calling convention yet parameter storage is locked */ -// [D] +// [D] [T] void RecordWaypoint(void) { - if (TimeToWay == 0) + if (TimeToWay > 0) { - if (PlayerWaypoints < 150) - { - PlayerWaypoints++; - - TimeToWay = way_distance; - - PlayerWayRecordPtr->x = (player[0].pos[0] >> 10); - PlayerWayRecordPtr->y = (player[0].pos[2] >> 10); - - PlayerWayRecordPtr++; - } - + TimeToWay--; return; } - TimeToWay--; + if (PlayerWaypoints < 150) + { + TimeToWay = way_distance; + + PlayerWayRecordPtr->x = (player[0].pos[0] >> 10); + PlayerWayRecordPtr->y = (player[0].pos[2] >> 10); + + PlayerWayRecordPtr++; + PlayerWaypoints++; + } } From 22f5bb3fc6275e8230de9a6fc21184ebb0072db6 Mon Sep 17 00:00:00 2001 From: Ilya Shurumov Date: Wed, 14 Oct 2020 00:53:26 +0600 Subject: [PATCH 39/41] - check SCORES.C --- src_rebuild/GAME/C/SCORES.C | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src_rebuild/GAME/C/SCORES.C b/src_rebuild/GAME/C/SCORES.C index 087f7b0a..b10f01cb 100644 --- a/src_rebuild/GAME/C/SCORES.C +++ b/src_rebuild/GAME/C/SCORES.C @@ -39,7 +39,7 @@ SCORE_TABLES ScoreTables; PLAYER_SCORE gPlayerScore; -// [D] +// [D] [T] void InitialiseScoreTables(void) { int i, j; @@ -100,7 +100,7 @@ void InitialiseScoreTables(void) /* end block 4 */ // End Line: 204 -// [D] +// [D] [T] int OnScoreTable(SCORE_ENTRY **tablept) { int position; @@ -168,7 +168,7 @@ int OnScoreTable(SCORE_ENTRY **tablept) /* end block 4 */ // End Line: 302 -// [D] +// [D] [T] void AddScoreToTable(SCORE_ENTRY *table, int entry) { int i; @@ -218,7 +218,7 @@ void AddScoreToTable(SCORE_ENTRY *table, int entry) /* end block 4 */ // End Line: 365 -// [D] +// [D] [T] int CheckGetawayPlacing(SCORE_ENTRY *table) { int i; @@ -266,7 +266,7 @@ int CheckGetawayPlacing(SCORE_ENTRY *table) /* end block 4 */ // End Line: 422 -// [D] +// [D] [T] int CheckTrailblazerPlacing(SCORE_ENTRY *table) { int i; @@ -286,7 +286,7 @@ int CheckTrailblazerPlacing(SCORE_ENTRY *table) } } - else if ((table->items == -1) || (table->items < gPlayerScore.items)) + else if (table->items == -1 || table->items < gPlayerScore.items) { return i; } @@ -330,7 +330,7 @@ int CheckTrailblazerPlacing(SCORE_ENTRY *table) /* end block 4 */ // End Line: 491 -// [D] +// [D] [T] int CheckCheckpointPlacing(SCORE_ENTRY *table) { int i; @@ -377,7 +377,7 @@ int CheckCheckpointPlacing(SCORE_ENTRY *table) /* end block 4 */ // End Line: 546 -// [D] +// [D] [T] int CheckSurvivalPlacing(SCORE_ENTRY *table) { int i; @@ -423,7 +423,7 @@ int CheckSurvivalPlacing(SCORE_ENTRY *table) /* end block 4 */ // End Line: 587 -// [D] +// [D] [T] void ResetTable(SCORE_ENTRY *table) { int i; From f7e6b703b12d964e40d48268bb07226b2c6fd83e Mon Sep 17 00:00:00 2001 From: Ilya Shurumov Date: Wed, 14 Oct 2020 01:00:52 +0600 Subject: [PATCH 40/41] - bump version to 2.5 --- src_rebuild/GAME/VERSION.H | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src_rebuild/GAME/VERSION.H b/src_rebuild/GAME/VERSION.H index b1d0acad..c26f2cc8 100644 --- a/src_rebuild/GAME/VERSION.H +++ b/src_rebuild/GAME/VERSION.H @@ -1,7 +1,7 @@ #ifndef VERSION_H #define VERSION_H -#define GAME_VERSION_N "2.0 alpha" +#define GAME_VERSION_N "2.5 alpha" #define GAME_TITLE "REDRIVER2" #define GAME_VERSION GAME_TITLE " " GAME_VERSION_N From 53f3ae23a99fba90a23248060ac3ca95dbfc2e15 Mon Sep 17 00:00:00 2001 From: Ilya Shurumov Date: Wed, 14 Oct 2020 01:24:09 +0600 Subject: [PATCH 41/41] - enable AppVeyor artifacts back --- appveyor.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 324d5ae0..4f13da76 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -58,12 +58,12 @@ before_build: - cmd: premake5 vs2019 - cmd: ren "%JPEG_DIR%\jconfig.vc" "jconfig.h" -#artifacts: -# - path: src_rebuild\bin\%configuration%\*.zip -# name: Binaries +artifacts: + - path: src_rebuild\bin\%configuration%\*.zip + name: Binaries -#after_build: -# - cmd: cd %project_folder%\bin\%configuration% -# - 7z a REDRIVER2.zip ".\*" +after_build: + - cmd: cd %project_folder%\bin\%configuration% + - 7z a REDRIVER2.zip ".\*" #build: off