-
Notifications
You must be signed in to change notification settings - Fork 32
Unjam function added to reload hotkey #583
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
93043cb
655bbfe
4cc9dd6
d131138
a680d1b
0241130
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3872,13 +3872,113 @@ BOOLEAN AutoReload( SOLDIERTYPE * pSoldier, bool aReloadEvenIfNotEmpty ) | |
| { | ||
| OBJECTTYPE *pObj, *pObj2; | ||
| INT8 bSlot; | ||
| INT16 bAPCost; | ||
| INT16 bAPCost; | ||
| BOOLEAN fRet = FALSE; | ||
|
|
||
| CHECKF( pSoldier ); | ||
|
|
||
| // Flugente: check for underbarrel weapons and use that object if necessary | ||
| pObj = pSoldier->GetUsedWeapon( &(pSoldier->inv[HANDPOS]) ); | ||
| if (pSoldier->IsValidSecondHandShotForReloadingPurposes()) //check for valid second hand weapon for reloading purposes (something that doesn't use ammo) | ||
| { | ||
| pObj2 = pSoldier->GetUsedWeapon( &(pSoldier->inv[SECONDHANDPOS]) ); | ||
| } | ||
| else | ||
| { | ||
| pObj2 = NULL; | ||
| } | ||
| // Greysa: Check if weapon is jammed and unjam it first | ||
| if ((*pObj)[0]->data.gun.bGunAmmoStatus < 0 || ((pObj2 != NULL) && (*pObj2)[0]->data.gun.bGunAmmoStatus < 0)) | ||
| { | ||
| if ((*pObj)[0]->data.gun.bGunAmmoStatus < 0) | ||
| { | ||
| //borrowed from Weapons.cpp | ||
| if (EnoughPoints(pSoldier, APBPConstants[AP_UNJAM], APBPConstants[BP_UNJAM], FALSE)) | ||
| { | ||
| DeductPoints(pSoldier, APBPConstants[AP_UNJAM], APBPConstants[BP_UNJAM]); | ||
|
|
||
| INT8 bChanceMod; | ||
|
|
||
| if (Weapon[pObj->usItem].EasyUnjam) | ||
| bChanceMod = 100; | ||
| else | ||
| bChanceMod = (INT8)(GetReliability(pObj) * 4); | ||
|
|
||
| int iResult = SkillCheck(pSoldier, UNJAM_GUN_CHECK, bChanceMod); | ||
|
|
||
| if (iResult > 0) | ||
| { | ||
| // yay! unjammed the gun | ||
| (*pObj)[0]->data.gun.bGunAmmoStatus *= -1; | ||
|
|
||
| // MECHANICAL/DEXTERITY GAIN: Unjammed a gun | ||
|
|
||
| if (bChanceMod < 100) // don't give exp for unjamming an easily unjammable gun | ||
| { | ||
| StatChange(pSoldier, MECHANAMT, 5, FALSE); | ||
| StatChange(pSoldier, DEXTAMT, 5, FALSE); | ||
| } | ||
|
|
||
| DirtyMercPanelInterface(pSoldier, DIRTYLEVEL2); | ||
| PlayJA2Sample(Weapon[Item[pObj->usItem].ubClassIndex].ManualReloadSound, RATE_11025, SoundVolume(HIGHVOLUME, pSoldier->sGridNo), 1, SoundDir(pSoldier->sGridNo)); | ||
| ScreenMsg(FONT_MCOLOR_LTYELLOW, MSG_INTERFACE, Message[STR_UNJAMMED], pSoldier->GetName(), ItemNames[pObj->usItem]); | ||
| // merc voice feedback? | ||
| } | ||
| else | ||
| { | ||
| ScreenMsg(FONT_MCOLOR_LTYELLOW, MSG_INTERFACE, Message[STR_FAILED_UNJAM], pSoldier->GetName(), ItemNames[pObj->usItem]); | ||
| } | ||
| } | ||
| else | ||
| { | ||
| ScreenMsg(FONT_MCOLOR_LTYELLOW, MSG_INTERFACE, Message[STR_NO_AP_NO_UNJAM], pSoldier->GetName(), ItemNames[pObj->usItem]); | ||
| } | ||
| } | ||
| if ((pObj2 != NULL) && (*pObj2)[0]->data.gun.bGunAmmoStatus < 0) | ||
| { | ||
| if (EnoughPoints(pSoldier, APBPConstants[AP_UNJAM], APBPConstants[BP_UNJAM], FALSE)) | ||
| { | ||
| DeductPoints(pSoldier, APBPConstants[AP_UNJAM], APBPConstants[BP_UNJAM]); | ||
|
|
||
| INT8 bChanceMod; | ||
|
|
||
| if (Weapon[pObj2->usItem].EasyUnjam) | ||
| bChanceMod = 100; | ||
| else | ||
| bChanceMod = (INT8)(GetReliability(pObj2) * 4); | ||
|
|
||
| int iResult = SkillCheck(pSoldier, UNJAM_GUN_CHECK, bChanceMod); | ||
|
|
||
| if (iResult > 0) | ||
| { | ||
| // yay! unjammed the gun | ||
| (*pObj2)[0]->data.gun.bGunAmmoStatus *= -1; | ||
|
|
||
| // MECHANICAL/DEXTERITY GAIN: Unjammed a gun | ||
|
|
||
| if (bChanceMod < 100) // don't give exp for unjamming an easily unjammable gun | ||
| { | ||
| StatChange(pSoldier, MECHANAMT, 5, FALSE); | ||
| StatChange(pSoldier, DEXTAMT, 5, FALSE); | ||
| } | ||
|
|
||
| DirtyMercPanelInterface(pSoldier, DIRTYLEVEL2); | ||
| PlayJA2Sample(Weapon[Item[pObj2->usItem].ubClassIndex].ManualReloadSound, RATE_11025, SoundVolume(HIGHVOLUME, pSoldier->sGridNo), 1, SoundDir(pSoldier->sGridNo)); | ||
| ScreenMsg(FONT_MCOLOR_LTYELLOW, MSG_INTERFACE, Message[STR_UNJAMMED], pSoldier->GetName(), ItemNames[pObj2->usItem]); | ||
| // merc voice feedback? | ||
| } | ||
| else | ||
| { | ||
| ScreenMsg(FONT_MCOLOR_LTYELLOW, MSG_INTERFACE, Message[STR_FAILED_UNJAM], pSoldier->GetName(), ItemNames[pObj2->usItem]); | ||
| } | ||
| } | ||
| else | ||
| { | ||
| ScreenMsg(FONT_MCOLOR_LTYELLOW, MSG_INTERFACE, Message[STR_NO_AP_NO_UNJAM], pSoldier->GetName(), ItemNames[pObj2->usItem]); | ||
| } | ||
| } | ||
| return FALSE; // Greysa: We want to skip reloading if we attempted to unjam, regardless of outcome. Return value doesn't seem to matter as there doesn't seem to be any actual checks on the returned value. I picked FALSE as actual reload hasn't occurred | ||
| } | ||
|
|
||
| //<SB> manual recharge | ||
| if ((*pObj)[0]->data.gun.ubGunShotsLeft && !((*pObj)[0]->data.gun.ubGunState & GS_CARTRIDGE_IN_CHAMBER) ) | ||
|
|
@@ -3915,9 +4015,9 @@ BOOLEAN AutoReload( SOLDIERTYPE * pSoldier, bool aReloadEvenIfNotEmpty ) | |
|
|
||
| PlayJA2Sample( Weapon[ Item[pObj->usItem].ubClassIndex ].ManualReloadSound, RATE_11025, SoundVolume( HIGHVOLUME, pSoldier->sGridNo ), 1, SoundDir( pSoldier->sGridNo ) ); | ||
|
|
||
| if ( pSoldier->IsValidSecondHandShot( ) ) | ||
| if (pObj2 != NULL)//( pSoldier->IsValidSecondHandShot( ) ) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Delete the commented out code. No need to clutter the codebase with commented out code, unless there's a good reason to do so. |
||
| { | ||
| pObj2 = &(pSoldier->inv[SECONDHANDPOS]); | ||
| //pObj2 = &(pSoldier->inv[SECONDHANDPOS]); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
|
|
||
| if ((*pObj2)[0]->data.gun.ubGunShotsLeft && !((*pObj2)[0]->data.gun.ubGunState & GS_CARTRIDGE_IN_CHAMBER) ) | ||
| { | ||
|
|
@@ -3930,9 +4030,9 @@ BOOLEAN AutoReload( SOLDIERTYPE * pSoldier, bool aReloadEvenIfNotEmpty ) | |
| } | ||
| else | ||
| { | ||
| if ( pSoldier->IsValidSecondHandShot( ) ) | ||
| if (pObj2 != NULL)//( pSoldier->IsValidSecondHandShot( ) ) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
| { | ||
| pObj2 = &(pSoldier->inv[SECONDHANDPOS]); | ||
| //pObj2 = &(pSoldier->inv[SECONDHANDPOS]); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here as well |
||
|
|
||
| if ((*pObj2)[0]->data.gun.ubGunShotsLeft && !((*pObj2)[0]->data.gun.ubGunState & GS_CARTRIDGE_IN_CHAMBER) ) | ||
| { | ||
|
|
@@ -3989,21 +4089,21 @@ BOOLEAN AutoReload( SOLDIERTYPE * pSoldier, bool aReloadEvenIfNotEmpty ) | |
| // if we are valid for two-pistol shooting (reloading) and we have enough APs still | ||
| // then do a reload of both guns! | ||
| // Flugente: only reload if it's empty, or we really want to | ||
| if ( pSoldier->IsValidSecondHandShotForReloadingPurposes() | ||
| if ( pObj2 != NULL //pSoldier->IsValidSecondHandShotForReloadingPurposes() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove commented out code |
||
| && ( aReloadEvenIfNotEmpty || !EnoughAmmo( pSoldier, FALSE, SECONDHANDPOS ) ) ) | ||
| { | ||
| // Flugente: check for underbarrel weapons and use that object if necessary | ||
| pObj = pSoldier->GetUsedWeapon( &( pSoldier->inv[SECONDHANDPOS] ) ); | ||
| //pObj2 = pSoldier->GetUsedWeapon( &( pSoldier->inv[SECONDHANDPOS] ) ); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove instead of commenting out |
||
|
|
||
| bSlot = FindAmmoToReload( pSoldier, SECONDHANDPOS, NO_SLOT ); | ||
| if ( bSlot != NO_SLOT ) | ||
| { | ||
| // ce would reload using this ammo! | ||
| bAPCost = GetAPsToReloadGunWithAmmo( pSoldier, pObj, &( pSoldier->inv[bSlot] ) ); | ||
| bAPCost = GetAPsToReloadGunWithAmmo( pSoldier, pObj2, &( pSoldier->inv[bSlot] ) ); | ||
| if ( EnoughPoints( pSoldier, (INT16)bAPCost, 0, FALSE ) ) | ||
| { | ||
| // reload the 2nd gun too | ||
| fRet = ReloadGun( pSoldier, pObj, &( pSoldier->inv[bSlot] ) ); | ||
| fRet = ReloadGun( pSoldier, pObj2, &( pSoldier->inv[bSlot] ) ); | ||
| } | ||
| else | ||
| { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initialize pObj2 to null and then you only need to have the if {} block without else {}. Not strictly necessary, but I do find that more readable and c++ being what it is, initializing values is a good habit to have :)