Files
source/Tactical/Handle UI Plan.cpp
T
Overhaul dd0d6ea66d Fixed appearance of save game corruption when a game with different inventory set is loaded. Note that such games can still cause odd behavior and CTD's
Fixed old-style behavior when creating a soldier struct (caused memory corruption and leaks)
Fixed soldiers unable to fire if an error happened while firing the off-hand weapon
Fix animation system problems with soldiers interrupted while changing stance, such as twitching and not being able to navigate around obstacles
Prevent splitting money while an item is in the hand, which would result in losing the original item
Fix reverse of X,Y when checking visibility through a roof, which could make soldiers falsely visible/invisible
Prevent militia from simply waiting on the border when enemies are known to be in the sector
Fix stack overflow for soldier inventory debug display
Optimized A* pathing and cleaned up VS2K5 specific code
AI can now use all climb points for climbable buildings, not just a random few
Fix to not allow flat roof butted against slanted roof to be identified as a climb point
Prevent soldiers who cause an interrupt from a special action from continuing on their path after being interrupted
Prevent soldiers who enter or leave deep water from moving a space too far and turning back
Prevent soldiers from trying to crouch while in shallow water
Make soldier turn in the closest direction when he must get up from prone and turn then fall back to prone
Allow a soldier to swat for a tile before returning to prone if unable to return to prone immediately after a turn
Fix civilians that should show up in a sector, missing because of others that aren't
Fix a memset on a C++ class
Place Skyrider in a sector near his helecopter once available and the helicopter is present
Fix soldier corruption if too many shots burst-spread into too few tiles
Include both first and last tile in spread when some locations must be skipped
Fix to shoot at last location in burst
Fix to remove other previous spread locations when calculating a new spread
Fix to reload or rechamber off-hand when necessary, such as having a pistol shotgun in that hand


git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@1532 3b4a5df2-a311-0410-b5c6-a8a6f20db521
2007-10-20 08:09:03 +00:00

309 lines
8.8 KiB
C++

#ifdef PRECOMPILEDHEADERS
#include "Tactical All.h"
#else
#include "Handle UI Plan.h"
#include "overhead.h"
#include "Isometric Utils.h"
#include "pathai.h"
#include "Handle UI.h"
#include "points.h"
#include "weapons.h"
#include "renderworld.h"
#include "Animation Control.h"
#include "message.h"
#include "soldier create.h"
#include "interface.h"
#endif
UINT8 gubNumUIPlannedMoves = 0;
SOLDIERTYPE *gpUIPlannedSoldier = NULL;
SOLDIERTYPE *gpUIStartPlannedSoldier = NULL;
BOOLEAN gfInUIPlanMode = FALSE;
void SelectPausedFireAnimation( SOLDIERTYPE *pSoldier );
BOOLEAN BeginUIPlan( SOLDIERTYPE *pSoldier )
{
gubNumUIPlannedMoves = 0;
gpUIPlannedSoldier = pSoldier;
gpUIStartPlannedSoldier = pSoldier;
gfInUIPlanMode = TRUE;
gfPlotNewMovement = TRUE;
ScreenMsg( FONT_MCOLOR_LTYELLOW, MSG_INTERFACE, L"Entering Planning Mode" );
return( TRUE );
}
BOOLEAN AddUIPlan( UINT16 sGridNo, UINT8 ubPlanID )
{
SOLDIERTYPE *pPlanSoldier;
INT16 sXPos, sYPos;
INT16 sAPCost = 0;
INT8 bDirection;
INT32 iLoop;
SOLDIERCREATE_STRUCT MercCreateStruct;
UINT8 ubNewIndex;
// Depeding on stance and direction facing, add guy!
// If we have a planned action here, ignore!
// If not OK Dest, ignore!
if ( !NewOKDestination( gpUIPlannedSoldier, sGridNo, FALSE, (INT8)gsInterfaceLevel ) )
{
return( FALSE );
}
if ( ubPlanID == UIPLAN_ACTION_MOVETO )
{
// Calculate cost to move here
sAPCost = PlotPath( gpUIPlannedSoldier, sGridNo, COPYROUTE, NO_PLOT, TEMPORARY, (UINT16) gpUIPlannedSoldier->usUIMovementMode, NOT_STEALTH, FORWARD, gpUIPlannedSoldier->bActionPoints );
// Adjust for running if we are not already running
if ( gpUIPlannedSoldier->usUIMovementMode == RUNNING )
{
sAPCost += AP_START_RUN_COST;
}
if ( EnoughPoints( gpUIPlannedSoldier, sAPCost, 0, FALSE ) )
{
memset( &MercCreateStruct, 0, sizeof( MercCreateStruct ) );
MercCreateStruct.bTeam = SOLDIER_CREATE_AUTO_TEAM;
MercCreateStruct.ubProfile = NO_PROFILE;
MercCreateStruct.fPlayerPlan = TRUE;
MercCreateStruct.bBodyType = gpUIPlannedSoldier->ubBodyType;
MercCreateStruct.sInsertionGridNo = sGridNo;
// Get Grid Corrdinates of mouse
if ( TacticalCreateSoldier( &MercCreateStruct, &ubNewIndex ) )
{
// Get pointer to soldier
GetSoldier( &pPlanSoldier, (UINT16)ubNewIndex );
pPlanSoldier->sPlannedTargetX = -1;
pPlanSoldier->sPlannedTargetY = -1;
// Compare OPPLISTS!
// Set ones we don't know about but do now back to old ( ie no new guys )
for (iLoop = 0; iLoop < MAX_NUM_SOLDIERS; iLoop++ )
{
if ( gpUIPlannedSoldier->bOppList[ iLoop ] < 0 )
{
pPlanSoldier->bOppList[ iLoop ] = gpUIPlannedSoldier->bOppList[ iLoop ];
}
}
// Get XY from Gridno
ConvertGridNoToCenterCellXY( sGridNo, &sXPos, &sYPos );
EVENT_SetSoldierPosition( pPlanSoldier, sXPos, sYPos );
EVENT_SetSoldierDestination( pPlanSoldier, (UINT8) sGridNo ); // Hopefully this code is never used anymore because the second param is now direction, not grid
pPlanSoldier->bVisible = 1;
pPlanSoldier->usUIMovementMode = gpUIPlannedSoldier->usUIMovementMode;
pPlanSoldier->bActionPoints = gpUIPlannedSoldier->bActionPoints - sAPCost;
pPlanSoldier->ubPlannedUIAPCost = (UINT8)pPlanSoldier->bActionPoints;
// Get direction
bDirection = (INT8)gpUIPlannedSoldier->usPathingData[ gpUIPlannedSoldier->usPathDataSize - 1 ];
// Set direction
pPlanSoldier->ubDirection = bDirection;
pPlanSoldier->bDesiredDirection = bDirection;
// Set walking animation
ChangeSoldierState( pPlanSoldier, pPlanSoldier->usUIMovementMode, 0, FALSE );
// Change selected soldier
gusSelectedSoldier = (UINT16)pPlanSoldier->ubID;
// Change global planned mode to this guy!
gpUIPlannedSoldier = pPlanSoldier;
gubNumUIPlannedMoves++;
gfPlotNewMovement = TRUE;
ScreenMsg( FONT_MCOLOR_LTYELLOW, MSG_INTERFACE, L"Adding Merc Move to Plan" );
}
}
else
{
ScreenMsg( FONT_MCOLOR_LTYELLOW, MSG_INTERFACE, L"Merc will not have enough action points" );
}
}
else if ( ubPlanID == UIPLAN_ACTION_FIRE )
{
sAPCost = CalcTotalAPsToAttack( gpUIPlannedSoldier, sGridNo, TRUE, (INT8)(gpUIPlannedSoldier->bShownAimTime ) );
// Get XY from Gridno
ConvertGridNoToCenterCellXY( sGridNo, &sXPos, &sYPos );
// If this is a player guy, show message about no APS
if ( EnoughPoints( gpUIPlannedSoldier, sAPCost, 0, FALSE ) )
{
// CHECK IF WE ARE A PLANNED SOLDIER OR NOT< IF SO< CREATE!
if ( gpUIPlannedSoldier->ubID < MAX_NUM_SOLDIERS )
{
memset( &MercCreateStruct, 0, sizeof( MercCreateStruct ) );
MercCreateStruct.bTeam = SOLDIER_CREATE_AUTO_TEAM;
MercCreateStruct.ubProfile = NO_PROFILE;
MercCreateStruct.fPlayerPlan = TRUE;
MercCreateStruct.bBodyType = gpUIPlannedSoldier->ubBodyType;
MercCreateStruct.sInsertionGridNo = sGridNo;
// Get Grid Corrdinates of mouse
if ( TacticalCreateSoldier( &MercCreateStruct, &ubNewIndex ) )
{
// Get pointer to soldier
GetSoldier( &pPlanSoldier, (UINT16)ubNewIndex );
pPlanSoldier->sPlannedTargetX = -1;
pPlanSoldier->sPlannedTargetY = -1;
// Compare OPPLISTS!
// Set ones we don't know about but do now back to old ( ie no new guys )
for (iLoop = 0; iLoop < MAX_NUM_SOLDIERS; iLoop++ )
{
if ( gpUIPlannedSoldier->bOppList[ iLoop ] < 0 )
{
pPlanSoldier->bOppList[ iLoop ] = gpUIPlannedSoldier->bOppList[ iLoop ];
}
}
EVENT_SetSoldierPosition( pPlanSoldier, gpUIPlannedSoldier->dXPos, gpUIPlannedSoldier->dYPos );
EVENT_SetSoldierDestination( pPlanSoldier, (UINT8) gpUIPlannedSoldier->sGridNo );
pPlanSoldier->bVisible = 1;
pPlanSoldier->usUIMovementMode = gpUIPlannedSoldier->usUIMovementMode;
pPlanSoldier->bActionPoints = gpUIPlannedSoldier->bActionPoints - sAPCost;
pPlanSoldier->ubPlannedUIAPCost = (UINT8)pPlanSoldier->bActionPoints;
// Get direction
bDirection = (INT8)gpUIPlannedSoldier->usPathingData[ gpUIPlannedSoldier->usPathDataSize - 1 ];
// Set direction
pPlanSoldier->ubDirection = bDirection;
pPlanSoldier->bDesiredDirection = bDirection;
// Set walking animation
ChangeSoldierState( pPlanSoldier, pPlanSoldier->usUIMovementMode, 0, FALSE );
// Change selected soldier
gusSelectedSoldier = (UINT16)pPlanSoldier->ubID;
// Change global planned mode to this guy!
gpUIPlannedSoldier = pPlanSoldier;
gubNumUIPlannedMoves++;
}
}
gpUIPlannedSoldier->bActionPoints = gpUIPlannedSoldier->bActionPoints - sAPCost;
gpUIPlannedSoldier->ubPlannedUIAPCost = (UINT8)gpUIPlannedSoldier->bActionPoints;
// Get direction from gridno
bDirection = (INT8)GetDirectionFromGridNo( sGridNo, gpUIPlannedSoldier );
// Set direction
gpUIPlannedSoldier->ubDirection = bDirection;
gpUIPlannedSoldier->bDesiredDirection = bDirection;
// Set to shooting animation
SelectPausedFireAnimation( gpUIPlannedSoldier );
gpUIPlannedSoldier->sPlannedTargetX = sXPos;
gpUIPlannedSoldier->sPlannedTargetY = sYPos;
ScreenMsg( FONT_MCOLOR_LTYELLOW, MSG_INTERFACE, L"Adding Merc Shoot to Plan" );
}
else
{
ScreenMsg( FONT_MCOLOR_LTYELLOW, MSG_INTERFACE, L"Merc will not have enough action points" );
}
}
return( TRUE );
}
void EndUIPlan( )
{
int cnt;
SOLDIERTYPE *pSoldier;
// Zero out any planned soldiers
for( cnt = MAX_NUM_SOLDIERS; cnt < TOTAL_SOLDIERS; cnt++ )
{
pSoldier = MercPtrs[ cnt ];
if ( pSoldier->bActive )
{
if ( pSoldier->sPlannedTargetX != -1 )
{
SetRenderFlags(RENDER_FLAG_FULL );
}
TacticalRemoveSoldier( pSoldier->ubID );
}
}
gfInUIPlanMode = FALSE;
gusSelectedSoldier = gpUIStartPlannedSoldier->ubID;
gfPlotNewMovement = TRUE;
ScreenMsg( FONT_MCOLOR_LTYELLOW, MSG_INTERFACE, L"Leaving Planning Mode" );
}
BOOLEAN InUIPlanMode( )
{
return( gfInUIPlanMode );
}
void SelectPausedFireAnimation( SOLDIERTYPE *pSoldier )
{
// Determine which animation to do...depending on stance and gun in hand...
switch ( gAnimControl[ pSoldier->usAnimState ].ubEndHeight )
{
case ANIM_STAND:
if ( pSoldier->bDoBurst > 0 )
{
ChangeSoldierState( pSoldier, STANDING_BURST, 2 , FALSE );
}
else
{
ChangeSoldierState( pSoldier, SHOOT_RIFLE_STAND, 2 , FALSE );
}
break;
case ANIM_PRONE:
ChangeSoldierState( pSoldier, SHOOT_RIFLE_PRONE, 2 , FALSE );
break;
case ANIM_CROUCH:
ChangeSoldierState( pSoldier, SHOOT_RIFLE_CROUCH, 2 , FALSE );
break;
}
}