From 49018d85ec4b5de8fb732c2d03c997ee7be3b8f9 Mon Sep 17 00:00:00 2001 From: Flugente Date: Sun, 16 Jun 2013 16:40:15 +0000 Subject: [PATCH] improved multiturn action cost handling git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@6126 3b4a5df2-a311-0410-b5c6-a8a6f20db521 --- Tactical/Handle Items.cpp | 6 +-- Tactical/Handle UI.cpp | 2 +- Tactical/Points.cpp | 34 ++++++--------- Tactical/Points.h | 4 +- Tactical/Soldier Control.cpp | 82 +++++++++++++++++++++++++----------- 5 files changed, 76 insertions(+), 52 deletions(-) diff --git a/Tactical/Handle Items.cpp b/Tactical/Handle Items.cpp index 1d600e9e..d5a5170f 100644 --- a/Tactical/Handle Items.cpp +++ b/Tactical/Handle Items.cpp @@ -1138,7 +1138,7 @@ INT32 HandleItem( SOLDIERTYPE *pSoldier, INT32 sGridNo, INT8 bLevel, UINT16 usHa // if we have an empty sandbag in our hands, we also need to have a shovel in our second hand, otherwise we can't fill it if ( HasItemFlag(usHandItem, (EMPTY_SANDBAG)) ) { - sAPCost = GetAPsToFillSandbag( pSoldier ); + sAPCost = GetAPsForMultiTurnAction( pSoldier, MTA_FILL_SANDBAG ); // check if we have a shovel in our second hand OBJECTTYPE* pShovelObj = &(pSoldier->inv[SECONDHANDPOS]); @@ -1158,7 +1158,7 @@ INT32 HandleItem( SOLDIERTYPE *pSoldier, INT32 sGridNo, INT8 bLevel, UINT16 usHa // if we have a shovel in our hands, the targeted gridno must be a fortification (debris will do for this check) else if ( HasItemFlag(usHandItem, (SHOVEL)) ) { - sAPCost = GetAPsToRemoveFortification( pSoldier ); + sAPCost = GetAPsForMultiTurnAction( pSoldier, MTA_REMOVE_FORTIFY ); STRUCTURE* pStruct = FindStructure(sGridNo, STRUCTURE_GENERIC); @@ -1169,7 +1169,7 @@ INT32 HandleItem( SOLDIERTYPE *pSoldier, INT32 sGridNo, INT8 bLevel, UINT16 usHa } else { - sAPCost = GetAPsToBuildFortification( pSoldier ); + sAPCost = GetAPsForMultiTurnAction( pSoldier, MTA_FORTIFY ); } sActionGridNo = FindAdjacentGridEx( pSoldier, sGridNo, &ubDirection, &sAdjustedGridNo, TRUE, FALSE ); diff --git a/Tactical/Handle UI.cpp b/Tactical/Handle UI.cpp index e3d48475..807f45d8 100644 --- a/Tactical/Handle UI.cpp +++ b/Tactical/Handle UI.cpp @@ -4118,7 +4118,7 @@ INT8 DrawUIMovementPath( SOLDIERTYPE *pSoldier, INT32 usMapPos, UINT32 uiFlags ) sActionGridNo = usMapPos; } - sAPCost = GetAPsToBuildFortification( pSoldier ); + sAPCost = GetAPsForMultiTurnAction( pSoldier, MTA_FORTIFY ); sAPCost += UIPlotPath( pSoldier, sActionGridNo, NO_COPYROUTE, fPlot, TEMPORARY, (UINT16)pSoldier->usUIMovementMode, NOT_STEALTH, FORWARD, pSoldier->bActionPoints); if ( sActionGridNo != pSoldier->sGridNo ) diff --git a/Tactical/Points.cpp b/Tactical/Points.cpp index 0a583f8b..22fa3cb8 100644 --- a/Tactical/Points.cpp +++ b/Tactical/Points.cpp @@ -3724,29 +3724,23 @@ INT16 GetAPsToApplyItem( SOLDIERTYPE *pSoldier, INT32 usMapPos ) return sAPCost; } -INT16 GetAPsToBuildFortification( SOLDIERTYPE *pSoldier ) +// added by Flugente +INT16 GetAPsForMultiTurnAction( SOLDIERTYPE *pSoldier, UINT8 usActionType ) { INT16 sAPCost = 0; - - sAPCost += APBPConstants[AP_FORTIFICATION]; - return sAPCost; -} - -INT16 GetAPsToRemoveFortification( SOLDIERTYPE *pSoldier ) -{ - INT16 sAPCost = 0; - - sAPCost += APBPConstants[AP_REMOVE_FORTIFICATION]; - - return sAPCost; -} - -INT16 GetAPsToFillSandbag( SOLDIERTYPE *pSoldier ) -{ - INT16 sAPCost = 0; - - sAPCost += APBPConstants[AP_FILL_SANDBAG]; + switch ( usActionType ) + { + case MTA_FORTIFY: + sAPCost += APBPConstants[AP_FORTIFICATION]; + break; + case MTA_REMOVE_FORTIFY: + sAPCost += APBPConstants[AP_REMOVE_FORTIFICATION]; + break; + case MTA_FILL_SANDBAG: + sAPCost += APBPConstants[AP_FILL_SANDBAG]; + break; + } return sAPCost; } diff --git a/Tactical/Points.h b/Tactical/Points.h index 940c637f..cac545a4 100644 --- a/Tactical/Points.h +++ b/Tactical/Points.h @@ -358,9 +358,7 @@ INT16 GetBPsTouseJar( SOLDIERTYPE *pSoldier ); INT16 GetAPsToHandcuff( SOLDIERTYPE *pSoldier, INT32 usMapPos ); // added by Flugente INT16 GetAPsToApplyItem( SOLDIERTYPE *pSoldier, INT32 usMapPos ); // added by Flugente -INT16 GetAPsToBuildFortification( SOLDIERTYPE *pSoldier ); // added by Flugente -INT16 GetAPsToRemoveFortification( SOLDIERTYPE *pSoldier ); // added by Flugente -INT16 GetAPsToFillSandbag( SOLDIERTYPE *pSoldier ); // added by Flugente +INT16 GetAPsForMultiTurnAction( SOLDIERTYPE *pSoldier, UINT8 usActionType ); // added by Flugente INT16 GetAPsToJumpOver( SOLDIERTYPE *pSoldier ); diff --git a/Tactical/Soldier Control.cpp b/Tactical/Soldier Control.cpp index 1a3515eb..b49cd635 100644 --- a/Tactical/Soldier Control.cpp +++ b/Tactical/Soldier Control.cpp @@ -15574,9 +15574,20 @@ UINT8 SOLDIERTYPE::GetMultiTurnAction() void SOLDIERTYPE::StartMultiTurnAction(UINT8 usActionType) { // check wether we can perform any action at all - if ( !this->bActive || !this->bInSector || this->stats.bLife < OKLIFE || TileIsOutOfBounds(this->sGridNo) || this->pathing.bLevel != 0 || gAnimControl[ this->usAnimState ].ubEndHeight == ANIM_PRONE || gAnimControl[ this->usAnimState ].ubEndHeight == ANIM_STAND || this->bCollapsed ) + if ( !this->bActive || !this->bInSector || this->stats.bLife < OKLIFE || TileIsOutOfBounds(this->sGridNo) || this->bCollapsed ) return; + // wether an action is possible or not depends on action itself (there are actions without a gridno) + switch( usMultiTurnAction ) + { + case MTA_FORTIFY: + case MTA_REMOVE_FORTIFY: + case MTA_FILL_SANDBAG: + if ( this->pathing.bLevel != 0 || gAnimControl[ this->usAnimState ].ubEndHeight == ANIM_PRONE || gAnimControl[ this->usAnimState ].ubEndHeight == ANIM_STAND ) + return; + break; + } + // if we already perform a multi-turn action, overwrite it if ( GetMultiTurnAction() > MTA_NONE ) CancelMultiTurnAction(FALSE); @@ -15588,18 +15599,7 @@ void SOLDIERTYPE::StartMultiTurnAction(UINT8 usActionType) sMTActionGridNo = NewGridNo( this->sGridNo, DirectionInc( this->ubDirection ) ); // for now, adding and removing a structure has the same AP cost - that might change in the future - switch( usMultiTurnAction ) - { - case MTA_FORTIFY: - bOverTurnAPS = GetAPsToBuildFortification( this ); - break; - case MTA_REMOVE_FORTIFY: - bOverTurnAPS = GetAPsToRemoveFortification( this ); - break; - case MTA_FILL_SANDBAG: - bOverTurnAPS = GetAPsToFillSandbag( this ); - break; - } + bOverTurnAPS = GetAPsForMultiTurnAction( this, usMultiTurnAction); // immediately starting the action would leave us without APs, thus removing the benefit of multi-turn actions (ability to do something else while performing a longer action) // for this reason, we only do this when we are not in combat @@ -15626,12 +15626,32 @@ BOOLEAN SOLDIERTYPE::UpdateMultiTurnAction() return FALSE; // check wether we can perform any action at all - if ( !this->bActive || !this->bInSector || this->stats.bLife < OKLIFE || TileIsOutOfBounds(this->sGridNo) || TileIsOutOfBounds(this->sMTActionGridNo) || this->pathing.bLevel != 0 || gAnimControl[ this->usAnimState ].ubEndHeight == ANIM_PRONE || gAnimControl[ this->usAnimState ].ubEndHeight == ANIM_STAND || this->bCollapsed ) + if ( !this->bActive || !this->bInSector || this->stats.bLife < OKLIFE || TileIsOutOfBounds(this->sGridNo) || this->bCollapsed ) { CancelMultiTurnAction(FALSE); return FALSE; } + // wether an action is possible or not depends on action itself (there are actions without a gridno) + switch( usMultiTurnAction ) + { + case MTA_FORTIFY: + case MTA_REMOVE_FORTIFY: + case MTA_FILL_SANDBAG: + if ( this->pathing.bLevel != 0 || gAnimControl[ this->usAnimState ].ubEndHeight == ANIM_PRONE || gAnimControl[ this->usAnimState ].ubEndHeight == ANIM_STAND ) + { + CancelMultiTurnAction(FALSE); + return FALSE; + } + break; + default: // default: exit + { + CancelMultiTurnAction(FALSE); + return FALSE; + } + break; + } + // check wether our selected action can still be performed BOOLEAN fActionStillValid = TRUE; @@ -15641,8 +15661,11 @@ BOOLEAN SOLDIERTYPE::UpdateMultiTurnAction() fActionStillValid = FALSE; // error if the gridno we started working on is not the gridno we are currently looking at - if ( this->sMTActionGridNo != NewGridNo( this->sGridNo, DirectionInc( this->ubDirection ) ) ) - fActionStillValid = FALSE; + if ( usMultiTurnAction == MTA_FORTIFY || usMultiTurnAction == MTA_REMOVE_FORTIFY || usMultiTurnAction == MTA_FILL_SANDBAG ) + { + if ( this->sMTActionGridNo != NewGridNo( this->sGridNo, DirectionInc( this->ubDirection ) ) ) + fActionStillValid = FALSE; + } if ( !fActionStillValid ) { @@ -15659,7 +15682,7 @@ BOOLEAN SOLDIERTYPE::UpdateMultiTurnAction() { case MTA_FORTIFY: { - entireapcost = GetAPsToBuildFortification( this ); + entireapcost = GetAPsForMultiTurnAction( this, MTA_FORTIFY ); entirebpcost = APBPConstants[BP_FORTIFICATION]; if ( !IsFortificationPossibleAtGridNo( this->sMTActionGridNo ) ) @@ -15670,7 +15693,7 @@ BOOLEAN SOLDIERTYPE::UpdateMultiTurnAction() break; case MTA_REMOVE_FORTIFY: { - entireapcost = GetAPsToRemoveFortification( this ); + entireapcost = GetAPsForMultiTurnAction( this, MTA_REMOVE_FORTIFY ); entirebpcost = APBPConstants[BP_REMOVE_FORTIFICATION]; if ( !HasItemFlag(this->inv[ HANDPOS ].usItem, (SHOVEL)) ) @@ -15680,7 +15703,7 @@ BOOLEAN SOLDIERTYPE::UpdateMultiTurnAction() case MTA_FILL_SANDBAG: { - entireapcost = GetAPsToFillSandbag( this ); + entireapcost = GetAPsForMultiTurnAction( this, MTA_FILL_SANDBAG ); entirebpcost = APBPConstants[BP_FILL_SANDBAG]; if ( !HasItemFlag(this->inv[ HANDPOS ].usItem, EMPTY_SANDBAG) ) @@ -15715,13 +15738,22 @@ BOOLEAN SOLDIERTYPE::UpdateMultiTurnAction() else { // refresh animations - if (!is_networked) - this->EVENT_InitNewSoldierAnim( CUTTING_FENCE, 0 , FALSE ); - else - this->ChangeSoldierState( CUTTING_FENCE, 0, 0 ); + switch( usMultiTurnAction ) + { + case MTA_FORTIFY: + case MTA_REMOVE_FORTIFY: + case MTA_FILL_SANDBAG: + { + if (!is_networked) + this->EVENT_InitNewSoldierAnim( CUTTING_FENCE, 0 , FALSE ); + else + this->ChangeSoldierState( CUTTING_FENCE, 0, 0 ); - // as setting the new animation costs APBPConstants[AP_USEWIRECUTTERS] APs every time, account for that - this->bActionPoints += APBPConstants[AP_USEWIRECUTTERS]; + // as setting the new animation costs APBPConstants[AP_USEWIRECUTTERS] APs every time, account for that + this->bActionPoints += APBPConstants[AP_USEWIRECUTTERS]; + } + break; + } } // if we can afford it, do it now