From 66f4fb5ea62776f4e2d4280f826c3a3c438d311b Mon Sep 17 00:00:00 2001 From: Asdow <20314541+Asdow@users.noreply.github.com> Date: Wed, 24 Jan 2024 00:29:28 +0200 Subject: [PATCH 1/2] User center insertion point for merc arrival instead of initial arrival gridno that is meant only for the very first helidrop arrival at the start of a game. --- Ja2/gamescreen.cpp | 7 +++++++ Strategic/strategicmap.cpp | 27 +++++++++++---------------- Tactical/Merc Hiring.cpp | 21 +++++++++++++-------- 3 files changed, 31 insertions(+), 24 deletions(-) diff --git a/Ja2/gamescreen.cpp b/Ja2/gamescreen.cpp index 28fd812d0..ba3ceb80a 100644 --- a/Ja2/gamescreen.cpp +++ b/Ja2/gamescreen.cpp @@ -628,7 +628,14 @@ UINT32 MainGameScreenHandle(void) InternalLocateGridNo( gGameUBOptions.LOCATEGRIDNO, TRUE ); } #else + if (gfFirstHeliRun) + { InternalLocateGridNo( gGameExternalOptions.iInitialMercArrivalLocation, TRUE ); + } + else + { + InternalLocateGridNo(gMapInformation.sCenterGridNo, TRUE); + } #endif // Flugente: we might have reloaded the game, so we are currently not dropping mercs out of a helicopter gfIngagedInDrop = FALSE; diff --git a/Strategic/strategicmap.cpp b/Strategic/strategicmap.cpp index f194853a9..5708dfc71 100644 --- a/Strategic/strategicmap.cpp +++ b/Strategic/strategicmap.cpp @@ -3382,27 +3382,22 @@ void UpdateMercInSector( SOLDIERTYPE *pSoldier, INT16 sSectorX, INT16 sSectorY, break; case INSERTION_CODE_ARRIVING_GAME: - // Are we in Omerta! - if ( sSectorX == gWorldSectorX && gWorldSectorX == 9 && sSectorY == gWorldSectorY && gWorldSectorY == 1 && bSectorZ == gbWorldSectorZ && gbWorldSectorZ == 0 ) - { - // TODO.WANNE: Hardcoded grid number - // Try another location and walk into map - pSoldier->sInsertionGridNo = 4379;//dnl!!! - } - else - { #ifdef JA2UB - //pSoldier->ubStrategicInsertionCode = INSERTION_CODE_NORTH; - //pSoldier->sInsertionGridNo = gMapInformation.sNorthGridNo; - pSoldier->ubStrategicInsertionCode = INSERTION_CODE_GRIDNO; - pSoldier->sInsertionGridNo = gGameUBOptions.LOCATEGRIDNO; + pSoldier->ubStrategicInsertionCode = INSERTION_CODE_GRIDNO; + pSoldier->sInsertionGridNo = gGameUBOptions.LOCATEGRIDNO; #else - //pSoldier->ubStrategicInsertionCode = INSERTION_CODE_NORTH; - //pSoldier->sInsertionGridNo = gMapInformation.sNorthGridNo; + extern BOOLEAN gfFirstHeliRun; + if (gfFirstHeliRun) + { pSoldier->ubStrategicInsertionCode = INSERTION_CODE_GRIDNO; pSoldier->sInsertionGridNo = gGameExternalOptions.iInitialMercArrivalLocation; -#endif } + else + { + pSoldier->ubStrategicInsertionCode = INSERTION_CODE_CENTER; + pSoldier->sInsertionGridNo = gMapInformation.sCenterGridNo; + } +#endif break; case INSERTION_CODE_CHOPPER: // Try another location and walk into map diff --git a/Tactical/Merc Hiring.cpp b/Tactical/Merc Hiring.cpp index 002926c7c..24e98b63e 100644 --- a/Tactical/Merc Hiring.cpp +++ b/Tactical/Merc Hiring.cpp @@ -50,6 +50,7 @@ #include "DynamicDialogue.h"// added by Flugente #include "Dialogue Control.h" // added by Flugente #include "connect.h" +#include "Map Information.h" #ifdef JA2UB #include "Soldier Control.h" @@ -534,16 +535,23 @@ void MercArrivesCallback( UINT8 ubSoldierID ) #ifdef JA2UB if ( pSoldier->ubStrategicInsertionCode != INSERTION_CODE_CHOPPER && pSoldier->sSectorX == gGameExternalOptions.ubDefaultArrivalSectorX && pSoldier->sSectorY == gGameExternalOptions.ubDefaultArrivalSectorY && gGameUBOptions.InGameHeli == TRUE ) #else - if ( pSoldier->ubStrategicInsertionCode != INSERTION_CODE_CHOPPER && pSoldier->sSectorX == gGameExternalOptions.ubDefaultArrivalSectorX && pSoldier->sSectorY == gGameExternalOptions.ubDefaultArrivalSectorY ) + if (pSoldier->ubStrategicInsertionCode != INSERTION_CODE_CHOPPER ) #endif { gfTacticalDoHeliRun = TRUE; - SetHelicopterDroppoint(gGameExternalOptions.iInitialMercArrivalLocation); + if (gfFirstHeliRun) + { + SetHelicopterDroppoint(gGameExternalOptions.iInitialMercArrivalLocation); + } + else + { + SetHelicopterDroppoint(gMapInformation.sCenterGridNo); + } // OK, If we are in mapscreen, get out... if ( guiCurrentScreen == MAP_SCREEN ) { - // ATE: Make sure the current one is selected! + // ATE: Make sure the current one is selected! ChangeSelectedMapSector( gWorldSectorX, gWorldSectorY, 0 ); RequestTriggerExitFromMapscreen( MAP_EXIT_TO_TACTICAL ); @@ -554,17 +562,14 @@ void MercArrivesCallback( UINT8 ubSoldierID ) UpdateMercInSector( pSoldier, pSoldier->sSectorX, pSoldier->sSectorY, pSoldier->bSectorZ ); } + // Strategic map arrival to a sector that's not loaded else { - // OK, otherwise, set them in north area, so once we load again, they are here. #ifdef JA2UB - //pSoldier->ubStrategicInsertionCode = INSERTION_CODE_NORTH; pSoldier->ubStrategicInsertionCode = INSERTION_CODE_GRIDNO; pSoldier->usStrategicInsertionData = gGameUBOptions.LOCATEGRIDNO; #else - //pSoldier->ubStrategicInsertionCode = INSERTION_CODE_NORTH; - pSoldier->ubStrategicInsertionCode = INSERTION_CODE_GRIDNO; - pSoldier->usStrategicInsertionData = gGameExternalOptions.iInitialMercArrivalLocation; + pSoldier->ubStrategicInsertionCode = INSERTION_CODE_CENTER; #endif } From a190d34076e4423159e117e2aa6a3db157442cd2 Mon Sep 17 00:00:00 2001 From: Asdow <20314541+Asdow@users.noreply.github.com> Date: Wed, 24 Jan 2024 00:30:54 +0200 Subject: [PATCH 2/2] Prevent possible nullptr dereference --- Tactical/Merc Entering.cpp | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/Tactical/Merc Entering.cpp b/Tactical/Merc Entering.cpp index 53e74b169..39dc0e7db 100644 --- a/Tactical/Merc Entering.cpp +++ b/Tactical/Merc Entering.cpp @@ -1038,27 +1038,28 @@ UINT8 SpawnAirDropElite( INT32 sGridNo ) // Flugente hack pSoldier = TacticalCreateEliteEnemy( ); + if ( pSoldier == nullptr) + { + return NOBODY; + } //Add soldier strategic info, so it doesn't break the counters! - if ( pSoldier ) + if ( !gbWorldSectorZ ) { - if ( !gbWorldSectorZ ) + SECTORINFO *pSector = &SectorInfo[SECTOR( gWorldSectorX, gWorldSectorY )]; + switch ( pSoldier->ubSoldierClass ) { - SECTORINFO *pSector = &SectorInfo[SECTOR( gWorldSectorX, gWorldSectorY )]; - switch ( pSoldier->ubSoldierClass ) - { - case SOLDIER_CLASS_ADMINISTRATOR: pSector->ubNumAdmins++; pSector->ubAdminsInBattle++; break; - case SOLDIER_CLASS_ARMY: pSector->ubNumTroops++; pSector->ubTroopsInBattle++; break; - case SOLDIER_CLASS_ELITE: pSector->ubNumElites++; pSector->ubElitesInBattle++; break; - } + case SOLDIER_CLASS_ADMINISTRATOR: pSector->ubNumAdmins++; pSector->ubAdminsInBattle++; break; + case SOLDIER_CLASS_ARMY: pSector->ubNumTroops++; pSector->ubTroopsInBattle++; break; + case SOLDIER_CLASS_ELITE: pSector->ubNumElites++; pSector->ubElitesInBattle++; break; } - - pSoldier->ubStrategicInsertionCode = INSERTION_CODE_CHOPPER; - pSoldier->usStrategicInsertionData = sGridNo; // required, otherwise soldiers will spawn in map before jumping out of the heli - UpdateMercInSector( pSoldier, gWorldSectorX, gWorldSectorY, gbWorldSectorZ ); - //AllTeamsLookForAll( NO_INTERRUPTS ); } + pSoldier->ubStrategicInsertionCode = INSERTION_CODE_CHOPPER; + pSoldier->usStrategicInsertionData = sGridNo; // required, otherwise soldiers will spawn in map before jumping out of the heli + UpdateMercInSector( pSoldier, gWorldSectorX, gWorldSectorY, gbWorldSectorZ ); + //AllTeamsLookForAll( NO_INTERRUPTS ); + return pSoldier->ubID; }