From 3a34de9b7bd96dc914103dbdf64a92d6f56b0dd5 Mon Sep 17 00:00:00 2001 From: Ilya Shurumov Date: Tue, 4 May 2021 22:36:05 +0600 Subject: [PATCH] - chase recorder - auto delete cars after hard collision --- src_rebuild/Game/C/civ_ai.c | 25 +++++++------------ src_rebuild/Game/C/felony.c | 7 ++++++ src_rebuild/Game/C/main.c | 30 +++++++++-------------- src_rebuild/Game/C/replays.c | 47 +++++++++++++++++++++++++++--------- 4 files changed, 63 insertions(+), 46 deletions(-) diff --git a/src_rebuild/Game/C/civ_ai.c b/src_rebuild/Game/C/civ_ai.c index 121be4ba..fd5e0cd9 100644 --- a/src_rebuild/Game/C/civ_ai.c +++ b/src_rebuild/Game/C/civ_ai.c @@ -2927,16 +2927,14 @@ void SetUpCivCollFlags(void) dont = 0; - i = 0; - do { + for (i = 0; i < 2; i++) + { if (horncarflag[i] == cp0) { dont = 1; break; } - - i++; - } while (i < 2); + } if (dont) { @@ -2944,8 +2942,8 @@ void SetUpCivCollFlags(void) continue; } - i = 0; - do { + for (i = 0; i < 2; i++) + { if (hornchanflag[i] == 0) { int sample; @@ -2972,9 +2970,7 @@ void SetUpCivCollFlags(void) channels[hornchanflag[i]].time += rnd - (rnd / 30) * 30; break; } - - i++; - } while (i < 2); + } } } @@ -2985,8 +2981,8 @@ void SetUpCivCollFlags(void) } // clear on timeout - i = 0; - do { + for (i = 0; i < 2; i++) + { if (hornchanflag[i] != 0 && channels[hornchanflag[i]].time == 0) { horncarflag[i] = NULL; @@ -2994,10 +2990,7 @@ void SetUpCivCollFlags(void) SpuSetVoiceAR(0, 35); } - - i++; - - } while (i < 2); + } } // [D] [T] diff --git a/src_rebuild/Game/C/felony.c b/src_rebuild/Game/C/felony.c index 78d9045b..d4e1b525 100644 --- a/src_rebuild/Game/C/felony.c +++ b/src_rebuild/Game/C/felony.c @@ -432,6 +432,13 @@ void CarHitByPlayer(CAR_DATA *victim, int howHard) { char type; +#ifdef CUTSCENE_RECORDER + extern void InvalidatePing(int carId); + + if(howHard > 60000) + InvalidatePing(victim->id); +#endif + if (howHard > 0 && victim->controlType != CONTROL_TYPE_PURSUER_AI) { if ((victim->controlFlags & 1) == 0) diff --git a/src_rebuild/Game/C/main.c b/src_rebuild/Game/C/main.c index 07346234..4aadff68 100644 --- a/src_rebuild/Game/C/main.c +++ b/src_rebuild/Game/C/main.c @@ -937,26 +937,20 @@ void StepSim(void) // control civcars pingin/pingout if (requestStationaryCivCar != 1 && requestRoadblock == 0) { - if (gInGameChaseActive == 0) + if (gInGameChaseActive) { - if (numCivCars < maxCivCars && (NumPlayers == 1 || (NumPlayers == 2 && GameType == GAME_COPSANDROBBERS))) - { - // make 5 tries - for (i = 0; i < 5; i++) - { - if (PingInCivCar(15900)) - break; - } - } - } - else - { - // ping buffer used to spawn civ cars - i = 0; - while (i < 10 && PingBufferPos < 400 && PingBuffer[PingBufferPos].frame <= (CameraCnt - frameStart & 0xffffU)) - { + // it will use ping buffer + // checks are done internally + for (i = 0; i < 10; i++) PingInCivCar(15900); - i++; + } + else if (numCivCars < maxCivCars && (NumPlayers == 1 || (NumPlayers == 2 && GameType == GAME_COPSANDROBBERS))) + { + // make 5 tries + for (i = 0; i < 5; i++) + { + if (PingInCivCar(15900)) + break; } } diff --git a/src_rebuild/Game/C/replays.c b/src_rebuild/Game/C/replays.c index 3142f520..ae33d3ce 100644 --- a/src_rebuild/Game/C/replays.c +++ b/src_rebuild/Game/C/replays.c @@ -9,6 +9,7 @@ #include "mission.h" #include "director.h" #include "camera.h" +#include "cars.h" #include "civ_ai.h" #include "state.h" @@ -563,24 +564,21 @@ char GetPingInfo(char *cookieCount) retCarId = -1; - pp = PingBuffer + PingBufferPos; - - if (PingBuffer != NULL && PingBufferPos < MAX_REPLAY_PINGS) + if (PingBuffer && PingBufferPos < MAX_REPLAY_PINGS) { - if (pp->frame != 0xffff) + pp = &PingBuffer[PingBufferPos]; + + // accept only valid car pings + if (pp->frame != 0xFFFF) { - if ((CameraCnt - frameStart & 0xffffU) < pp->frame) + if (CameraCnt - frameStart < pp->frame) return -1; retCarId = pp->carId; *cookieCount = pp->cookieCount; + } - PingBufferPos++; - } - else - { - printInfo("-1 frame!\n"); - } + PingBufferPos++; return retCarId; } @@ -604,7 +602,7 @@ int StorePingInfo(int cookieCount, int carId) if(PingBuffer != NULL && PingBufferPos < MAX_REPLAY_PINGS) { packet = &PingBuffer[PingBufferPos++]; - packet->frame = (CameraCnt - frameStart & 0xffffU); + packet->frame = CameraCnt - frameStart; packet->carId = carId; packet->cookieCount = cookieCount; @@ -615,6 +613,31 @@ int StorePingInfo(int cookieCount, int carId) return 0; } +#ifdef CUTSCENE_RECORDER +void InvalidatePing(int carId) +{ + int pos; + + if (gCutsceneAsReplay == 0) + return; + + pos = PingBufferPos; + + while(pos >= 0) + { + pos--; + if (PingBuffer[pos].carId == carId) + { + printWarning("Removing ping at %d\n", PingBuffer[pos].frame); + PingBuffer[pos].carId = -1; + + PingOutCar(&car_data[carId]); + break; + } + } +} +#endif + // [A] returns 1 if can use ping buffer int IsPingInfoAvailable() {