From 6d8e11931a43fde5e64706b181b76f6aac5710a9 Mon Sep 17 00:00:00 2001 From: Shadooow Date: Wed, 27 Oct 2021 00:21:47 +0000 Subject: [PATCH] fixed negative value passed into PreRandom that could cause game to crash git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@9198 3b4a5df2-a311-0410-b5c6-a8a6f20db521 --- Strategic/Auto Resolve.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/Strategic/Auto Resolve.cpp b/Strategic/Auto Resolve.cpp index 536530e7..5b575060 100644 --- a/Strategic/Auto Resolve.cpp +++ b/Strategic/Auto Resolve.cpp @@ -4598,7 +4598,7 @@ void AttackTarget( SOLDIERCELL *pAttacker, SOLDIERCELL *pTarget ) ubLocation = AIM_SHOT_TORSO; - ubAccuracy = (UINT8)((usAttack - usDefence + PreRandom( usDefence - pTarget->usDefence )) / 10); + //ubAccuracy = (UINT8)((usAttack - usDefence + PreRandom( usDefence - pTarget->usDefence )) / 10); ///////////////////////////////////////////////////////////////////////////////////////////////////////////// // SANDRO - increased mercs' offense/deffense rating @@ -4672,7 +4672,7 @@ void AttackTarget( SOLDIERCELL *pAttacker, SOLDIERCELL *pTarget ) else ubLocation = AIM_SHOT_TORSO; - ubAccuracy = (UINT8)((usAttack - usDefence + PreRandom( usDefence - pTarget->usDefence )) / 10); + //ubAccuracy = (UINT8)((usAttack - usDefence + PreRandom( usDefence - pTarget->usDefence )) / 10); ///////////////////////////////////////////////////////////////////////////////////////////////////////////// // SANDRO - increased mercs' offense/deffense rating @@ -4709,8 +4709,13 @@ void AttackTarget( SOLDIERCELL *pAttacker, SOLDIERCELL *pTarget ) ubLocation = AIM_SHOT_LEGS; else ubLocation = AIM_SHOT_TORSO; + + if (usDefence >= pTarget->usDefence) + iRandom = PreRandom(usDefence - pTarget->usDefence); + else + iRandom = -PreRandom(pTarget->usDefence - usDefence); - ubAccuracy = (UINT8)((usAttack - usDefence + PreRandom( usDefence - pTarget->usDefence ) )/10); + ubAccuracy = (UINT8)((usAttack - usDefence + iRandom)/10); // HEADROCK HAM 5: Added argument iImpact = BulletImpact( pAttacker->pSoldier, NULL, pTarget->pSoldier, ubLocation, ubImpact, ubAccuracy, NULL ); ///////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -4746,7 +4751,12 @@ void AttackTarget( SOLDIERCELL *pAttacker, SOLDIERCELL *pTarget ) return; } - ubAccuracy = (UINT8)((usAttack - usDefence + PreRandom( usDefence - pTarget->usDefence ) )/10); + if (usDefence >= pTarget->usDefence) + iRandom = PreRandom(usDefence - pTarget->usDefence); + else + iRandom = -PreRandom(pTarget->usDefence - usDefence); + + ubAccuracy = (UINT8)((usAttack - usDefence + iRandom)/10); //Determine attacking weapon. pAttacker->pSoldier->usAttackingWeapon = 0;