From 6a24e04bbcec3509296234c5242fcc86a82a6819 Mon Sep 17 00:00:00 2001 From: MaddMugsy Date: Sat, 14 Apr 2012 21:11:25 +0000 Subject: [PATCH] Fixed a potential crash when a merc dies. Finally fixed CalcMaxTossRange so that it pulls the correct grenade launcher item instead of just the first one, thereby allowing more than one range value per set of launcher items that launch the same grenades. git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@5211 3b4a5df2-a311-0410-b5c6-a8a6f20db521 --- Tactical/Rotting Corpses.cpp | 2 +- Tactical/Weapons.cpp | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Tactical/Rotting Corpses.cpp b/Tactical/Rotting Corpses.cpp index 321edae4..a15ced57 100644 --- a/Tactical/Rotting Corpses.cpp +++ b/Tactical/Rotting Corpses.cpp @@ -566,7 +566,7 @@ INT32 AddRottingCorpse( ROTTING_CORPSE_DEFINITION *pCorpseDef ) if ( pCorpse->pAniTile == NULL ) { pCorpse->fActivated = FALSE; - return( -1 ); + return( -1 ); } // Set flag and index values diff --git a/Tactical/Weapons.cpp b/Tactical/Weapons.cpp index 94a8ceca..2666e14e 100644 --- a/Tactical/Weapons.cpp +++ b/Tactical/Weapons.cpp @@ -10325,7 +10325,23 @@ INT32 CalcMaxTossRange( SOLDIERTYPE * pSoldier, UINT16 usItem, BOOLEAN fArmed ) // if item's fired mechanically // ATE: If we are sent in a LAUNCHABLE, get the LAUCNHER, and sub ONLY if we are armed... - usSubItem = GetLauncherFromLaunchable( usItem ); + //MM: this only works if every launcher for a given launchable has the same range!! + //usSubItem = GetLauncherFromLaunchable( usItem ); + //MM: So instead, let's look at the soldier's hand, and check his gun for an underbarrel GL + if ( fArmed ) + { + OBJECTTYPE *pObj = NULL; + pObj = pSoldier->GetUsedWeapon( &pSoldier->inv[pSoldier->ubAttackingHand] ); + if ( pObj != NULL ) + { + if (Item[pObj->usItem].usItemClass == IC_LAUNCHER) + usSubItem = pObj->usItem; + else if (Item[pObj->usItem].usItemClass == IC_GUN) + { + usSubItem = GetAttachedGrenadeLauncher(pObj); + } + } + } if ( fArmed && usSubItem != NOTHING ) {