From cefa9cfcc164505eeb5db25b626b973930c6dfad Mon Sep 17 00:00:00 2001 From: Flugente Date: Tue, 14 May 2013 21:11:24 +0000 Subject: [PATCH] Fix: when using scope modes with NCTH, non-internal projection factor from lasers was ignored. git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@6078 3b4a5df2-a311-0410-b5c6-a8a6f20db521 --- Tactical/Items.cpp | 32 ++++++++++++++++++++++++++++++++ Tactical/Items.h | 3 +++ Tactical/LOS.cpp | 10 +++------- 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/Tactical/Items.cpp b/Tactical/Items.cpp index e75ff6a6..e6245213 100644 --- a/Tactical/Items.cpp +++ b/Tactical/Items.cpp @@ -12729,6 +12729,38 @@ FLOAT GetProjectionFactor( OBJECTTYPE * pObj ) return( BestFactor ); } +// Flugente: projection factor while using scope modes excludes those factors coming from not-used scopes and sights +FLOAT GetScopeModeProjectionFactor( SOLDIERTYPE *pSoldier, OBJECTTYPE * pObj ) +{ + if ( !gGameExternalOptions.fScopeModes || !pSoldier || pSoldier->bTeam != gbPlayerNum || !pObj || !pObj->exists() || Item[pObj->usItem].usItemClass != IC_GUN ) + return GetProjectionFactor(pObj); + + if ( !UsingNewCTHSystem() || pSoldier->bScopeMode == USE_ALT_WEAPON_HOLD ) + return 1.0; + + // Flugente: check for scope mode + std::map ObjList; + GetScopeLists(pObj, ObjList); + + FLOAT BestFactor = 1.0; + + BestFactor = __max((FLOAT)Item[pObj->usItem].projectionfactor, 1.0f); + + for (attachmentList::iterator iter = (*pObj)[0]->attachments.begin(); iter != (*pObj)[0]->attachments.end(); ++iter) + { + if (iter->exists()) + { + // if attachment is scope/sight and not used, ignore it! + if ( IsAttachmentClass(iter->usItem, AC_SCOPE|AC_SIGHT|AC_IRONSIGHT ) && iter->usItem != ObjList[pSoldier->bScopeMode]->usItem ) + continue; + + BestFactor = __max(BestFactor, Item[iter->usItem].projectionfactor); + } + } + + return( BestFactor ); +} + FLOAT GetScopeRangeMultiplier( SOLDIERTYPE *pSoldier, OBJECTTYPE *pObj, FLOAT d2DDistance ) { FLOAT iScopeFactor = 0; diff --git a/Tactical/Items.h b/Tactical/Items.h index be24d27c..92e8191b 100644 --- a/Tactical/Items.h +++ b/Tactical/Items.h @@ -417,6 +417,9 @@ FLOAT GetHighestScopeMagnificationFactor( OBJECTTYPE *pObj ); FLOAT GetScopeMagnificationFactor( SOLDIERTYPE *pSoldier, OBJECTTYPE *pObj, FLOAT uiRange ); FLOAT GetBestScopeMagnificationFactor( SOLDIERTYPE *pSoldier, OBJECTTYPE *pObj, FLOAT uiRange ); FLOAT GetProjectionFactor( OBJECTTYPE *pObj ); +// Flugente: projection factor while using scope modes excludes those factors coming from not-used scopes and sights +FLOAT GetScopeModeProjectionFactor( SOLDIERTYPE *pSoldier, OBJECTTYPE * pObj ); + FLOAT GetScopeRangeMultiplier( SOLDIERTYPE *pSoldier, OBJECTTYPE *pObj, FLOAT d2DDistance ); INT32 GetGunAccuracy( OBJECTTYPE *pObj ); INT32 GetAccuracyModifier( OBJECTTYPE *pObj ); diff --git a/Tactical/LOS.cpp b/Tactical/LOS.cpp index d12be1a3..e96fb0be 100644 --- a/Tactical/LOS.cpp +++ b/Tactical/LOS.cpp @@ -7813,13 +7813,9 @@ FLOAT CalcProjectionFactor( SOLDIERTYPE *pShooter, OBJECTTYPE *pWeapon, FLOAT d2 // Flugente: if scope modes are allowed, player team uses them if ( gGameExternalOptions.fScopeModes && pShooter && pShooter->bTeam == gbPlayerNum && pObjUsed->exists() == true && Item[pObjUsed->usItem].usItemClass == IC_GUN ) { - // Flugente: check for scope mode - std::map ObjList; - GetScopeLists(pObjUsed, ObjList); - - // only use scope mode if gun is in hand, otherwise an error might occur! - if ( (&pShooter->inv[HANDPOS]) == pObjUsed && ObjList[pShooter->bScopeMode] != NULL && pShooter->bScopeMode != USE_ALT_WEAPON_HOLD ) - iProjectionFactor = Item[ObjList[pShooter->bScopeMode]->usItem].projectionfactor; + // we calculate the projection factor of the item, but EXCLUDE those factors coming from scopes/sights we are not using at the moment. This means that factors from lasers + // count, but from reflex sights only if we are using the specific sight + iProjectionFactor = GetScopeModeProjectionFactor(pShooter, pObjUsed); } else iProjectionFactor = GetProjectionFactor( pObjUsed );