mirror of
https://github.com/1dot13/source.git
synced 2026-07-22 13:40:22 +02:00
Made direction variables more consistent as unsigned chars. Several function prototypes updated for this. Many memory leaks plugged: External options, video overlays, laptop file lists, tactical message queue, strategic pathing, autobandage, merc hiring, detailed placements, crate in Drassen, tactical placement New functions and attributes for soldiers in LUA (still for debugging at best): Soldier.APs (current APs), Soldier.changestance (changes stance, uses game heights) File catalog ignores .SVN directories (game load speedup) Fix CTD in mouse regions JA2 window now refuses to move to negative coords Checks to prevent DirectX-related infinite loops due to minimizing and task switching Invading enemies should now appear on the borders even when reinforcements disabled in .ini Suppression should no longer work on mercs in medium water Infant/Young creatures use restored spit instead of Molotov Creatures begin with their 'guns' (spit) 'locked and loaded' (cartridge in chamber) Further fix to AXP and AlaarDB's weapon ready check: Now 'firing' is always counted as 'ready'. Prevent mercs from falling and flying back through obstacles Check whether battle group is even set before testing its location for battle setup Burst spread locations now limited to 6, the limit within the soldier struct Extra burst spread locations zeroed out so that they aren't used unless necessary Spread code now only shoots at locations in the spread, and will shoot at all 6 Only mercs in the sector where autobandage happens will be made to stand up after it's done Throwing a grenade at the tail of the plane in Drassen should not result in a CTD Reset attack busy count when loading a new sector git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@1347 3b4a5df2-a311-0410-b5c6-a8a6f20db521
309 lines
8.7 KiB
C++
309 lines
8.7 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, 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++;
|
|
|
|
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, 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;
|
|
|
|
}
|
|
|
|
}
|