Fix: when using scope modes and underbarrel weapons, NCTH functions searched underbarrel gun instead of main gun for attachments, resulting in no boni

git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@5990 3b4a5df2-a311-0410-b5c6-a8a6f20db521
This commit is contained in:
Flugente
2013-04-08 22:29:26 +00:00
parent a466e7348a
commit cc8fe02d98
2 changed files with 25 additions and 11 deletions
+14 -7
View File
@@ -12590,15 +12590,22 @@ FLOAT GetScopeMagnificationFactor( SOLDIERTYPE *pSoldier, OBJECTTYPE * pObj, FLO
FLOAT GetBestScopeMagnificationFactor( SOLDIERTYPE *pSoldier, OBJECTTYPE * pObj, FLOAT uiRange )
{
// Flugente: if this weapon is an underbarrel weapon, use the 'carrier' weapon instead
OBJECTTYPE* pObjUsed = pObj;
if ( pObj == pSoldier->GetUsedWeapon( &pSoldier->inv[pSoldier->ubAttackingHand] ) )
{
pObjUsed = &pSoldier->inv[pSoldier->ubAttackingHand];
}
// Flugente: if scope modes are allowed, player team uses them
if ( gGameExternalOptions.fScopeModes && pSoldier && pSoldier->bTeam == gbPlayerNum && pObj->exists() == true && Item[pObj->usItem].usItemClass == IC_GUN )
if ( gGameExternalOptions.fScopeModes && pSoldier && pSoldier->bTeam == gbPlayerNum && pObjUsed->exists() == true && Item[pObjUsed->usItem].usItemClass == IC_GUN )
{
// Flugente: check for scope mode
std::map<INT8, OBJECTTYPE*> ObjList;
GetScopeLists(pObj, ObjList);
GetScopeLists(pObjUsed, ObjList);
// only use scope mode if gun is in hand, otherwise an error might occur!
if ( (&pSoldier->inv[HANDPOS]) == pObj && ObjList[pSoldier->bScopeMode] != NULL && pSoldier->bScopeMode != USE_ALT_WEAPON_HOLD )
if ( (&pSoldier->inv[HANDPOS]) == pObjUsed && ObjList[pSoldier->bScopeMode] != NULL && pSoldier->bScopeMode != USE_ALT_WEAPON_HOLD )
// now apply the bonus from the scope we use
return max(1.0f, Item[ObjList[pSoldier->bScopeMode]->usItem].scopemagfactor);
else
@@ -12611,8 +12618,8 @@ FLOAT GetBestScopeMagnificationFactor( SOLDIERTYPE *pSoldier, OBJECTTYPE * pObj,
FLOAT ActualCurrentFactor = 0.0;
INT32 iCurrentTotalPenalty = 0;
INT32 iBestTotalPenalty = 0;
FLOAT rangeModifier = GetScopeRangeMultiplier(pSoldier, pObj, uiRange);
FLOAT iProjectionFactor = CalcProjectionFactor(pSoldier, pObj, uiRange, 1);
FLOAT rangeModifier = GetScopeRangeMultiplier(pSoldier, pObjUsed, uiRange);
FLOAT iProjectionFactor = CalcProjectionFactor(pSoldier, pObjUsed, uiRange, 1);
if (TargetMagFactor <= 1.0f)
{
@@ -12623,7 +12630,7 @@ FLOAT GetBestScopeMagnificationFactor( SOLDIERTYPE *pSoldier, OBJECTTYPE * pObj,
if ( pObj->exists() == true && UsingNewCTHSystem() == true )
{
// Real Scope Magnification Factor from the item
CurrentFactor = __max(1.0f, Item[pObj->usItem].scopemagfactor);
CurrentFactor = __max(1.0f, Item[pObjUsed->usItem].scopemagfactor);
if (CurrentFactor > 1.0f)
{
@@ -12651,7 +12658,7 @@ FLOAT GetBestScopeMagnificationFactor( SOLDIERTYPE *pSoldier, OBJECTTYPE * pObj,
// Now perform the same process for each scope installed on the item. The difference is, we also compare to
// BestTotalPenalty to find the scope that gives the least penalty compared to its bonus.
for (attachmentList::iterator iter = (*pObj)[0]->attachments.begin(); iter != (*pObj)[0]->attachments.end(); ++iter)
for (attachmentList::iterator iter = (*pObjUsed)[0]->attachments.begin(); iter != (*pObjUsed)[0]->attachments.end(); ++iter)
{
if (iter->exists() && Item[iter->usItem].scopemagfactor > 1.0f)
{
+11 -4
View File
@@ -7803,19 +7803,26 @@ FLOAT CalcProjectionFactor( SOLDIERTYPE *pShooter, OBJECTTYPE *pWeapon, FLOAT d2
if (ubAimTime > 0)
{
// Flugente: if this weapon is an underbarrel weapon, use the 'carrier' weapon instead
OBJECTTYPE* pObjUsed = pWeapon;
if ( pWeapon == pShooter->GetUsedWeapon( &pShooter->inv[pShooter->ubAttackingHand] ) )
{
pObjUsed = &pShooter->inv[pShooter->ubAttackingHand];
}
// Flugente: if scope modes are allowed, player team uses them
if ( gGameExternalOptions.fScopeModes && pShooter && pShooter->bTeam == gbPlayerNum && pWeapon->exists() == true && Item[pWeapon->usItem].usItemClass == IC_GUN )
if ( gGameExternalOptions.fScopeModes && pShooter && pShooter->bTeam == gbPlayerNum && pObjUsed->exists() == true && Item[pObjUsed->usItem].usItemClass == IC_GUN )
{
// Flugente: check for scope mode
std::map<INT8, OBJECTTYPE*> ObjList;
GetScopeLists(pWeapon, ObjList);
GetScopeLists(pObjUsed, ObjList);
// only use scope mode if gun is in hand, otherwise an error might occur!
if ( (&pShooter->inv[HANDPOS]) == pWeapon && ObjList[pShooter->bScopeMode] != NULL && pShooter->bScopeMode != USE_ALT_WEAPON_HOLD )
if ( (&pShooter->inv[HANDPOS]) == pObjUsed && ObjList[pShooter->bScopeMode] != NULL && pShooter->bScopeMode != USE_ALT_WEAPON_HOLD )
iProjectionFactor = Item[ObjList[pShooter->bScopeMode]->usItem].projectionfactor;
}
else
iProjectionFactor = GetProjectionFactor( pWeapon );
iProjectionFactor = GetProjectionFactor( pObjUsed );
if (floor(iTargetMagFactor*10) > floor(iProjectionFactor*10.001))
{