From e86b24821c9150be84a921bd3d4d148d13472b59 Mon Sep 17 00:00:00 2001 From: Flugente Date: Thu, 19 May 2016 21:58:07 +0000 Subject: [PATCH] sped up reload function git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@8225 3b4a5df2-a311-0410-b5c6-a8a6f20db521 --- Tactical/Turn Based Input.cpp | 40 ++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/Tactical/Turn Based Input.cpp b/Tactical/Turn Based Input.cpp index 446371923..f201b6339 100644 --- a/Tactical/Turn Based Input.cpp +++ b/Tactical/Turn Based Input.cpp @@ -7637,11 +7637,14 @@ void HandleTBReloadAll( void ) UINT32 invsize = pTeamSoldier->inv.size(); for (UINT32 bLoop2 = 0; bLoop2 < invsize; ++bLoop2) { - if ( (Item[pTeamSoldier->inv[bLoop2].usItem].usItemClass & IC_GUN) || (Item[pTeamSoldier->inv[bLoop2].usItem].usItemClass == IC_LAUNCHER) ) + if ( (Item[pTeamSoldier->inv[bLoop2].usItem].usItemClass & (IC_GUN | IC_LAUNCHER)) ) { pGun = &(pTeamSoldier->inv[bLoop2]); + + UINT16 gunmagsize = GetMagSize( pGun ); + //if magazine is not full - if ( (*pGun)[0]->data.gun.ubGunShotsLeft < GetMagSize( pGun ) ) + if ( (*pGun)[0]->data.gun.ubGunShotsLeft < gunmagsize ) { // Search for ammo in sector for ( UINT32 uiLoop = 0; uiLoop < guiNumWorldItems; ++uiLoop ) @@ -7664,13 +7667,17 @@ void HandleTBReloadAll( void ) { RemoveItemFromPool( gWorldItems[ uiLoop ].sGridNo, uiLoop, gWorldItems[ uiLoop ].ubLevel ); } + + // if gun is full, we can stop this + if ( (*pGun)[0]->data.gun.ubGunShotsLeft >= gunmagsize ) + break; } } } } } //CHRISL: if not enough ammo in sector, reload using ammo carried in inventory - if ( (*pGun)[0]->data.gun.ubGunShotsLeft < GetMagSize( pGun ) ) + if ( (*pGun)[0]->data.gun.ubGunShotsLeft < gunmagsize ) { AutoReload( pTeamSoldier ); } @@ -7766,10 +7773,14 @@ void HandleTBReloadAll( void ) } } } + if (IsWeaponAttached(pGun, IC_GUN)) { OBJECTTYPE *pGun2 = FindAttachedWeapon(pGun, IC_GUN); - if ( (*pGun2)[0]->data.gun.ubGunShotsLeft < GetMagSize( pGun2 ) ) + + UINT16 gunmagsize2 = GetMagSize( pGun2 ); + + if ( (*pGun2)[0]->data.gun.ubGunShotsLeft < gunmagsize2 ) { // Search for ammo in sector for ( UINT32 uiLoop = 0; uiLoop < guiNumWorldItems; ++uiLoop ) @@ -7792,13 +7803,18 @@ void HandleTBReloadAll( void ) { RemoveItemFromPool( gWorldItems[ uiLoop ].sGridNo, uiLoop, gWorldItems[ uiLoop ].ubLevel ); } + + // if gun is full, we can stop this + if ( (*pGun2)[0]->data.gun.ubGunShotsLeft >= gunmagsize2 ) + break; } } } } } + //CHRISL: if not enough ammo in sector, reload using ammo carried in inventory - if ( (*pGun2)[0]->data.gun.ubGunShotsLeft < GetMagSize( pGun2 ) ) + if ( (*pGun2)[0]->data.gun.ubGunShotsLeft < gunmagsize2 ) { AutoReload( pTeamSoldier ); } @@ -7818,7 +7834,7 @@ void HandleTBReloadAll( void ) { if ( OK_CONTROLLABLE_MERC( pTeamSoldier ) && pTeamSoldier->bAssignment == CurrentSquad( ) && !AM_A_ROBOT( pTeamSoldier ) ) { - if ( (Item[pTeamSoldier->inv[HANDPOS].usItem].usItemClass & IC_GUN) || (Item[pTeamSoldier->inv[HANDPOS].usItem].usItemClass == IC_LAUNCHER) ) + if ( (Item[pTeamSoldier->inv[HANDPOS].usItem].usItemClass & (IC_GUN | IC_LAUNCHER) ) ) { if ( ( gTacticalStatus.uiFlags & INCOMBAT ) ) { @@ -7837,11 +7853,14 @@ void HandleTBReloadAll( void ) UINT32 invsize = pTeamSoldier->inv.size(); for (UINT32 bLoop2 = 0; bLoop2 < invsize; ++bLoop2) { - if ( (Item[pTeamSoldier->inv[bLoop2].usItem].usItemClass & IC_GUN) || (Item[pTeamSoldier->inv[bLoop2].usItem].usItemClass == IC_LAUNCHER) ) + if ( (Item[pTeamSoldier->inv[bLoop2].usItem].usItemClass & (IC_GUNinv[bLoop2]); + + UINT16 gunmagsize = GetMagSize( pGun ); + //if magazine is not full - if ( (*pGun)[0]->data.gun.ubGunShotsLeft < GetMagSize( pGun ) ) + if ( (*pGun)[0]->data.gun.ubGunShotsLeft < gunmagsize ) { // Search for ammo in soldier inventory for ( UINT32 uiLoop = 0; uiLoop < invsize; ++uiLoop ) @@ -7859,6 +7878,10 @@ void HandleTBReloadAll( void ) fCharacterInfoPanelDirty = TRUE; fInterfacePanelDirty = DIRTYLEVEL2; + + // if gun is full, we can stop this + if ( (*pGun)[0]->data.gun.ubGunShotsLeft >= gunmagsize ) + break; } } } @@ -7872,6 +7895,7 @@ void HandleTBReloadAll( void ) } } } + void HandleTBShowCover( void ) { ToggleEnemyView();