From f65719e8011fe278d42e0bdf781e6f826380ae28 Mon Sep 17 00:00:00 2001 From: Kriplo Date: Fri, 27 Sep 2013 22:03:42 +0000 Subject: [PATCH] Brief: //dnl ch72 - Fixing bad APs deduction when using hand grenades, mortars, rocket launchers, grenade launchers and attached grenade launchers from different stances and need turn to your target. Details: - Add APs cost for stance change and turnover for mortar and rocket launchers. - Rocket launchers cannot be fire from prone any more as there are no animation for that stance. - Attached grenade launchers now take raise gun cost for launcher instead for gun. - No more problems with APs for grenades from different stances and turnover, add proper costs for crouch too as someone add animation for that. - Fix wrong APs deduction for grenade launcher from prone and turnover in general. - Fix incorrect values for APs cost under throwing/launching cursor. git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@6447 3b4a5df2-a311-0410-b5c6-a8a6f20db521 --- Tactical/Handle Items.cpp | 8 ++-- Tactical/Points.cpp | 91 +++++++++++++++++++++++++----------- Tactical/Points.h | 2 +- Tactical/Soldier Ani.cpp | 7 ++- Tactical/Soldier Control.cpp | 23 +++++++-- Tactical/Weapons.cpp | 8 +++- 6 files changed, 100 insertions(+), 39 deletions(-) diff --git a/Tactical/Handle Items.cpp b/Tactical/Handle Items.cpp index 11e50cc5f..53b9b9ef8 100644 --- a/Tactical/Handle Items.cpp +++ b/Tactical/Handle Items.cpp @@ -1651,7 +1651,7 @@ INT32 HandleItem( SOLDIERTYPE *pSoldier, INT32 sGridNo, INT8 bLevel, UINT16 usHa return( ITEM_HANDLE_NOROOM ); } - pSoldier->flags.fDontChargeAPsForStanceChange = TRUE; + //pSoldier->flags.fDontChargeAPsForStanceChange = TRUE;//dnl ch72 270913 no reason why not charge for stance change } else if ( Item[usHandItem].grenadelauncher )//usHandItem == GLAUNCHER || usHandItem == UNDER_GLAUNCHER ) { @@ -1699,10 +1699,10 @@ INT32 HandleItem( SOLDIERTYPE *pSoldier, INT32 sGridNo, INT8 bLevel, UINT16 usHa // gTacticalStatus.ubAttackBusyCount++; DebugAttackBusy( "Weapon fire\n"); - + //dnl ch72 180913 decision is to charge for turning which was disabled in v1.12 also will turn off both options because is bad to charge APs before stance or turning really occurs // ATE: Don't charge turning... - pSoldier->flags.fDontChargeTurningAPs = TRUE; - pSoldier->flags.fDontChargeAPsForStanceChange = TRUE; + //pSoldier->flags.fDontChargeTurningAPs = TRUE; + //pSoldier->flags.fDontChargeAPsForStanceChange = TRUE; FireWeapon( pSoldier, sTargetGridNo ); } diff --git a/Tactical/Points.cpp b/Tactical/Points.cpp index 79492b004..d9be59033 100644 --- a/Tactical/Points.cpp +++ b/Tactical/Points.cpp @@ -2087,25 +2087,33 @@ void GetAPChargeForShootOrStabWRTGunRaises( SOLDIERTYPE *pSoldier, INT32 sGridNo (*pfChargeRaise ) = fAddingRaiseGunCost; } -UINT16 CalculateTurningCost(SOLDIERTYPE *pSoldier, UINT16 usItem, BOOLEAN fAddingTurningCost) +UINT16 CalculateTurningCost(SOLDIERTYPE *pSoldier, UINT16 usItem, BOOLEAN fAddingTurningCost, INT8 bDesiredHeight)//dnl ch72 190913 { - UINT16 usTurningCost = 0; + UINT16 usTrueAnimState, usTurningCost = 0; - if ( fAddingTurningCost ) + if(fAddingTurningCost) { - if ( Item[ usItem ].usItemClass == IC_THROWING_KNIFE ) + usTrueAnimState = pSoldier->usAnimState; + switch(bDesiredHeight) { - // SANDRO - Athletics trait check added - if (HAS_SKILL_TRAIT( pSoldier, MARTIAL_ARTS_NT ) && gGameOptions.fNewTraitSystem ) - usTurningCost = max( 1, (INT16)((APBPConstants[AP_LOOK_STANDING] * (100 - gSkillTraitValues.ubMAApsTurnAroundReduction * NUM_SKILL_TRAITS( pSoldier, MARTIAL_ARTS_NT ))/100) + 0.5)); - else - usTurningCost = APBPConstants[AP_LOOK_STANDING]; + case ANIM_STAND: + pSoldier->usAnimState = STANDING; + break; + case ANIM_CROUCH: + pSoldier->usAnimState = CROUCHING; + break; + case ANIM_PRONE: + pSoldier->usAnimState = PRONE; + break; + default: + break; } - else - usTurningCost = GetAPsToLook( pSoldier ); + if(Item[usItem].usItemClass == IC_THROWING_KNIFE) + pSoldier->usAnimState = STANDING; + usTurningCost = GetAPsToLook(pSoldier); + pSoldier->usAnimState = usTrueAnimState; } - - return usTurningCost; + return(usTurningCost); } UINT16 CalculateRaiseGunCost(SOLDIERTYPE *pSoldier, BOOLEAN fAddingRaiseGunCost, INT32 iTargetGridNum, INT16 bAimTime ) @@ -2334,6 +2342,13 @@ INT16 MinAPsToShootOrStab(SOLDIERTYPE *pSoldier, INT32 sGridNo, INT16 bAimTime, bAPCost += GetAPsToChangeStance( pSoldier, ANIM_STAND ); } } + else if(Item[usItem].rocketlauncher || Item[usItem].grenadelauncher || Item[usItem].mortar)//dnl ch72 260913 move this here from bottom, need to change as rocketlaucher could be fired from crouch too + { + if(gAnimControl[pSoldier->usAnimState].ubEndHeight == ANIM_PRONE || Item[usItem].mortar && gAnimControl[pSoldier->usAnimState].ubEndHeight == ANIM_STAND) + bAPCost += GetAPsToChangeStance(pSoldier, ANIM_CROUCH); + else + bAPCost += GetAPsToChangeStance(pSoldier, gAnimControl[pSoldier->usAnimState].ubEndHeight); + } } if ( AM_A_ROBOT( pSoldier ) || TANK( pSoldier ) || ubForceRaiseGunCost == 2 )//dnl ch64 300813 robots and tanks cannot do this //dnl ch69 150913 need option to override raise gun cost @@ -2346,7 +2361,17 @@ INT16 MinAPsToShootOrStab(SOLDIERTYPE *pSoldier, INT32 sGridNo, INT16 bAimTime, { // Buggler: actual melee ap deduction for turning applies only when target is 1 tile away if ( !( ( Item[ usUBItem ].usItemClass == IC_PUNCH || Item[ usUBItem ].usItemClass == IC_BLADE ) && usRange > 1 ) ) - usTurningCost = CalculateTurningCost(pSoldier, usItem, fAddingTurningCost); + { + if(Item[usItem].rocketlauncher || Item[usItem].grenadelauncher || Item[usItem].mortar)//dnl ch72 260913 + { + if(gAnimControl[pSoldier->usAnimState].ubEndHeight == ANIM_PRONE || Item[usItem].mortar && gAnimControl[pSoldier->usAnimState].ubEndHeight == ANIM_STAND) + usTurningCost = CalculateTurningCost(pSoldier, usItem, fAddingTurningCost, ANIM_CROUCH); + else + usTurningCost = CalculateTurningCost(pSoldier, usItem, fAddingTurningCost); + } + else + usTurningCost = CalculateTurningCost(pSoldier, usItem, fAddingTurningCost); + } } //Calculate usRaiseGunCost @@ -2389,12 +2414,6 @@ INT16 MinAPsToShootOrStab(SOLDIERTYPE *pSoldier, INT32 sGridNo, INT16 bAimTime, if ( bAPCost < 1 ) bAPCost = 1; - if ( Item[(*pObjUsed).usItem].rocketlauncher ) - { - bAPCost += GetAPsToChangeStance( pSoldier, ANIM_STAND ); - } - - return bAPCost; } @@ -3188,7 +3207,10 @@ INT16 GetAPsToReadyWeapon( SOLDIERTYPE *pSoldier, UINT16 usAnimState ) UINT16 usItem; UINT8 ubReadyAPs = 0; - usItem = pSoldier->inv[ HANDPOS ].usItem; + if(pSoldier->bWeaponMode == WM_ATTACHED_GL || pSoldier->bWeaponMode == WM_ATTACHED_GL_BURST || pSoldier->bWeaponMode == WM_ATTACHED_GL_AUTO)//dnl ch72 250913 + usItem = GetAttachedGrenadeLauncher(&pSoldier->inv[HANDPOS]); + else + usItem = pSoldier->inv[HANDPOS].usItem; // If this is a dwel pistol anim // ATE: What was I thinking, hooking into animations like this.... @@ -3525,6 +3547,7 @@ INT16 MinAPsToThrow( SOLDIERTYPE *pSoldier, INT32 sGridNo, UINT8 ubAddTurningCos INT32 iFullAPs; INT32 iAPCost = APBPConstants[AP_MIN_AIM_ATTACK]; UINT16 usInHand; +#if 0//dnl ch72 180913 UINT16 usTargID; UINT32 uiMercFlags; UINT8 ubDirection; @@ -3532,9 +3555,10 @@ INT16 MinAPsToThrow( SOLDIERTYPE *pSoldier, INT32 sGridNo, UINT8 ubAddTurningCos if(pSoldier->bWeaponMode == WM_ATTACHED_GL || pSoldier->bWeaponMode == WM_ATTACHED_GL_BURST || pSoldier->bWeaponMode == WM_ATTACHED_GL_AUTO)//dnl ch63 240813 usInHand = GetAttachedGrenadeLauncher(&pSoldier->inv[HANDPOS]); else +#endif // make sure the guy's actually got a throwable item in his hand! usInHand = pSoldier->inv[HANDPOS].usItem; - +#if 0//dnl ch72 180913 this goes down because of new trait system if ( ( !(Item[ usInHand ].usItemClass & IC_GRENADE) && !(Item[ usInHand ].usItemClass & IC_LAUNCHER)) ) { @@ -3552,7 +3576,7 @@ INT16 MinAPsToThrow( SOLDIERTYPE *pSoldier, INT32 sGridNo, UINT8 ubAddTurningCos return(0); } } - + if (!TileIsOutOfBounds(sGridNo)) { // Given a gridno here, check if we are on a guy - if so - get his gridno @@ -3589,7 +3613,7 @@ INT16 MinAPsToThrow( SOLDIERTYPE *pSoldier, INT32 sGridNo, UINT8 ubAddTurningCos //} //iAPCost += GetAPsToChangeStance( pSoldier, ANIM_STAND ); // moved lower - SANDRO - +#endif // Calculate default top & bottom of the magic "aiming" formula) @@ -3606,7 +3630,6 @@ INT16 MinAPsToThrow( SOLDIERTYPE *pSoldier, INT32 sGridNo, UINT8 ubAddTurningCos //else iBottom = ( TOSSES_PER_10TURNS * (50 + ( pSoldier->stats.bDexterity / 2 ) ) / 10 ); - // add minimum aiming time to the overall minimum AP_cost // This here ROUNDS UP fractions of 0.5 or higher using integer math // This works because 'top' is 2x what it really should be throughout @@ -3627,7 +3650,22 @@ INT16 MinAPsToThrow( SOLDIERTYPE *pSoldier, INT32 sGridNo, UINT8 ubAddTurningCos } } - iAPCost += GetAPsToChangeStance( pSoldier, ANIM_STAND ); // moved from above - SANDRO + // moved from above - SANDRO + //dnl ch72 180913 someone create throwing grenades from crouch so ANIM_STAND is not only stance for throwing, and as throwing object disappears from our hand when is thrown we need to determine desired height for turning cost + if(ubAddTurningCost && !TileIsOutOfBounds(sGridNo) && GetDirectionFromGridNo(sGridNo, pSoldier) != pSoldier->ubDirection) + ubAddTurningCost = TRUE; + else + ubAddTurningCost = FALSE; + if(gAnimControl[pSoldier->usAnimState].ubEndHeight == ANIM_PRONE) + { + iAPCost += GetAPsToChangeStance(pSoldier, ANIM_CROUCH); + iAPCost += CalculateTurningCost(pSoldier, usInHand, ubAddTurningCost, ANIM_CROUCH); + } + else + { + iAPCost += GetAPsToChangeStance(pSoldier, gAnimControl[pSoldier->usAnimState].ubEndHeight); + iAPCost += CalculateTurningCost(pSoldier, usInHand, ubAddTurningCost); + } // the minimum AP cost of ANY throw can NEVER be more than merc has APs! if ( iAPCost > iFullAPs ) @@ -3637,7 +3675,6 @@ INT16 MinAPsToThrow( SOLDIERTYPE *pSoldier, INT32 sGridNo, UINT8 ubAddTurningCos if ( iAPCost < 1 ) iAPCost = 1; - return ( (INT16)iAPCost ); } diff --git a/Tactical/Points.h b/Tactical/Points.h index cac545a4f..9caba7d84 100644 --- a/Tactical/Points.h +++ b/Tactical/Points.h @@ -295,7 +295,7 @@ INT16 MinAPsToAttack(SOLDIERTYPE *pSoldier, INT32 sGridNo, UINT8 ubAddTurningCos INT16 MinPtsToMove(SOLDIERTYPE *pSoldier); INT8 MinAPsToStartMovement( SOLDIERTYPE * pSoldier, UINT16 usMovementMode ); INT8 PtsToMoveDirection(SOLDIERTYPE *pSoldier, INT8 bDirection ); -UINT16 CalculateTurningCost(SOLDIERTYPE *pSoldier, UINT16 usItem, BOOLEAN fAddingTurningCost); +UINT16 CalculateTurningCost(SOLDIERTYPE *pSoldier, UINT16 usItem, BOOLEAN fAddingTurningCost, INT8 bDesiredHeight=0);//dnl ch72 190913 UINT16 CalculateRaiseGunCost(SOLDIERTYPE *pSoldier, BOOLEAN fAddingRaiseGunCost, INT32 iTargetGridNum, INT16 bAimTime ); INT16 MinAPsToShootOrStab(SOLDIERTYPE *pSoldier, INT32 sGridNo, INT16 bAimTime, UINT8 ubAddTurningCost, UINT8 ubForceRaiseGunCost = 0 ); BOOLEAN EnoughAmmo( SOLDIERTYPE *pSoldier, BOOLEAN fDisplay, INT8 bInvPos ); diff --git a/Tactical/Soldier Ani.cpp b/Tactical/Soldier Ani.cpp index dfd06ece5..bb1b9ca92 100644 --- a/Tactical/Soldier Ani.cpp +++ b/Tactical/Soldier Ani.cpp @@ -4342,7 +4342,12 @@ BOOLEAN CheckForImproperFireGunEnd( SOLDIERTYPE *pSoldier ) return( FALSE ); } - OBJECTTYPE* pObjHand = pSoldier->GetUsedWeapon( &pSoldier->inv[ HANDPOS ] ); + //dnl ch72 260913 + OBJECTTYPE *pObjHand; + if(pSoldier->bWeaponMode == WM_ATTACHED_GL || pSoldier->bWeaponMode == WM_ATTACHED_GL_BURST || pSoldier->bWeaponMode == WM_ATTACHED_GL_AUTO) + pObjHand = FindAttachment_GrenadeLauncher(&pSoldier->inv[HANDPOS]); + else + pObjHand = pSoldier->GetUsedWeapon(&pSoldier->inv[HANDPOS]); // Check single hand for jammed status, ( or ammo is out.. ) if ( (*pObjHand)[0]->data.gun.bGunAmmoStatus < 0 || (*pObjHand)[0]->data.gun.ubGunShotsLeft == 0 ) diff --git a/Tactical/Soldier Control.cpp b/Tactical/Soldier Control.cpp index d652cb7d5..2fd7349c5 100644 --- a/Tactical/Soldier Control.cpp +++ b/Tactical/Soldier Control.cpp @@ -4908,6 +4908,18 @@ void SOLDIERTYPE::EVENT_FireSoldierWeapon( INT32 sTargetGridNo ) // Convert our grid-not into an XY ConvertGridNoToXY( sTargetGridNo, &sTargetXPos, &sTargetYPos ); + //dnl ch72 2509134 + UINT16 usItem; + if(this->bWeaponMode == WM_ATTACHED_GL || this->bWeaponMode == WM_ATTACHED_GL_BURST || this->bWeaponMode == WM_ATTACHED_GL_AUTO) + usItem = GetAttachedGrenadeLauncher(&this->inv[HANDPOS]); + else + usItem = this->inv[HANDPOS].usItem; + if(Item[usItem].rocketlauncher || Item[usItem].grenadelauncher || Item[usItem].mortar) + { + if(gAnimControl[this->usAnimState].ubEndHeight == ANIM_PRONE || Item[usItem].mortar && gAnimControl[this->usAnimState].ubEndHeight == ANIM_STAND) + SendChangeSoldierStanceEvent(this, ANIM_CROUCH); + fDoFireRightAway = TRUE; + } // Change to fire animation // Ready weapon @@ -4960,6 +4972,7 @@ void SOLDIERTYPE::EVENT_FireSoldierWeapon( INT32 sTargetGridNo ) } else { +#if 0//dnl ch72 250913 move this above as need to be done before calling SoldierReadyWeapon // IF WE ARE IN REAl-TIME, FIRE IMMEDIATELY! if ( ( ( gTacticalStatus.uiFlags & REALTIME ) || !( gTacticalStatus.uiFlags & INCOMBAT ) ) ) { @@ -4978,7 +4991,7 @@ void SOLDIERTYPE::EVENT_FireSoldierWeapon( INT32 sTargetGridNo ) fDoFireRightAway = TRUE; // break; //} - +#endif if ( fDoFireRightAway ) { // Set to true so we don't get toasted twice for APs.. @@ -5391,15 +5404,17 @@ BOOLEAN SOLDIERTYPE::InternalSoldierReadyWeapon( UINT8 sFacingDir, BOOLEAN fEndR { usAnimState = this->usAnimState; } - + //dnl ch72 270913 ugly but fast fix for not charging turning APs as there is no fire ready animation for mortars and rocket launchers + UINT16 usItem = this->inv[HANDPOS].usItem; + if(Item[usItem].rocketlauncher || Item[usItem].mortar) + usForceAnimState = this->usAnimState; EVENT_InternalSetSoldierDesiredDirection( this, sFacingDir, FALSE, usAnimState ); - + usForceAnimState = INVALID_ANIMATION; // Check if facing dir is different from ours and change direction if so! //if ( sFacingDir != this->ubDirection ) //{ // DeductPoints( this, APBPConstants[AP_CHANGE_FACING], 0 ); //}// - } return( fReturnVal ); diff --git a/Tactical/Weapons.cpp b/Tactical/Weapons.cpp index 1a0c5d049..7212538d1 100644 --- a/Tactical/Weapons.cpp +++ b/Tactical/Weapons.cpp @@ -3824,7 +3824,7 @@ BOOLEAN UseThrown( SOLDIERTYPE *pSoldier, INT32 sTargetGridNo ) INT8 bLoop; UINT8 ubTargetID; SOLDIERTYPE * pTargetSoldier; - INT16 sAPCost = 0; + //INT16 sAPCost = 0;//dnl ch72 180913 uiHitChance = CalcThrownChanceToHit( pSoldier, sTargetGridNo, pSoldier->aiData.bAimTime, AIM_SHOT_TORSO ); @@ -3923,6 +3923,7 @@ BOOLEAN UseThrown( SOLDIERTYPE *pSoldier, INT32 sTargetGridNo ) CalculateLaunchItemParamsForThrow( pSoldier, sTargetGridNo, pSoldier->bTargetLevel, (INT16)(pSoldier->bTargetLevel * 256 ), &(pSoldier->inv[ HANDPOS ] ), (INT8)(uiDiceRoll - uiHitChance), THROW_ARM_ITEM, 0 ); +#if 0//dnl ch72 180913 bad idea to charge APs before stance and turn really occurs, this was not here in v1.12 //AXP 25.03.2007: Cleaned up throwing AP costs. Now only turning + stance change AP // costs are deducted. Final throw cost is deducted on creating the grenade object if ( (UINT8)GetDirectionFromGridNo( sTargetGridNo, pSoldier ) != pSoldier->ubDirection ) @@ -3932,7 +3933,10 @@ BOOLEAN UseThrown( SOLDIERTYPE *pSoldier, INT32 sTargetGridNo ) HandleSoldierThrowItem( pSoldier, pSoldier->sTargetGridNo ); DeductPoints( pSoldier, sAPCost, 0, AFTERSHOT_INTERRUPT ); pSoldier->inv[ HANDPOS ].RemoveObjectsFromStack(1); - +#else + HandleSoldierThrowItem(pSoldier, pSoldier->sTargetGridNo); + pSoldier->inv[HANDPOS].RemoveObjectsFromStack(1); +#endif /* // Madd: Next 2 lines added: Deduct points!