mirror of
https://github.com/1dot13/source.git
synced 2026-07-22 13:40:22 +02:00
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
This commit is contained in:
@@ -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 );
|
||||
|
||||
@@ -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 )
|
||||
|
||||
+14
-20
@@ -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;
|
||||
}
|
||||
|
||||
+1
-3
@@ -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 );
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user