mirror of
https://github.com/1dot13/source.git
synced 2026-07-22 13:40:22 +02:00
Added missing #includes Added LUA scripting and console Changed the way tracers are visualized, so they work more like real tracers instead of a light fountain Fixed signedness of many grid variables used in GetMouseMapPos calls Fixed enemy weapon choosing: Sometimes a mortar is chosen but later rejected, but the grenade class was not reset. Caused assertion failure Added checks so enemies don't try to chuck RPG grenades with their hands Now possible to shoot a someone in the head if he's in water Fixed InitSightArrays to also clear soldier interrupt duel points. This was causing an assertion failure elsewhere in the code because the interrupt list still had soldiers on it sometimes when this function was called. Soldiers are much less willing to forfeit their turn over an attempt to use more APs than they have Removed early setting of muzzle flash. This would allow enemies to get an interrupt before you even fired. Fixed item dropping by AI. If AI tried to drop something while standing it would cause deadlock Change to greatly speed up closing the sector inventory window in an unloaded sector Added conditional compile flag to always give robot weapon ready advantage, even for 360 degree sighting Check builddefines.h for the conditional flags. Of greatest interest might be LUA_CONSOLE. This will cause the game to bring up a command console when run. However this console is severely lacking in many areas. If anybody knows of an open-source terminal/console that could be used instead, it would be appreciated. The existing console does bad things when you try to close it, and since it counts as a separate app, it pauses the game while it has focus. LUA scripting is very limited, basically just proof of concept. There is one global variable, the Soldiers array. An array index gives you the soldier in that slot in the currently loaded sector. The soldier has a few things that can be accessed: name (short name); fullname (long name); grid (current grid #, can be changed); walkto(grid) (function to walk to another grid); runto(grid) (function to run to another grid) git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@924 3b4a5df2-a311-0410-b5c6-a8a6f20db521
296 lines
8.2 KiB
C++
296 lines
8.2 KiB
C++
#ifdef PRECOMPILEDHEADERS
|
|
#include "Tactical All.h"
|
|
#else
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include "wcheck.h"
|
|
#include "stdlib.h"
|
|
#include "debug.h"
|
|
#include "soldier control.h"
|
|
#include "weapons.h"
|
|
#include "cursor control.h"
|
|
#include "cursors.h"
|
|
#include "soldier find.h"
|
|
#include "isometric utils.h"
|
|
#include "renderworld.h"
|
|
#include "render dirty.h"
|
|
#include "interface.h"
|
|
#include "spread burst.h"
|
|
#include "points.h"
|
|
#endif
|
|
|
|
|
|
BURST_LOCATIONS gsBurstLocations[ MAX_BURST_LOCATIONS ];
|
|
INT8 gbNumBurstLocations = 0;
|
|
|
|
extern BOOLEAN gfBeginBurstSpreadTracking;
|
|
|
|
|
|
void ResetBurstLocations( )
|
|
{
|
|
gbNumBurstLocations = 0;
|
|
}
|
|
|
|
|
|
void InternalAccumulateBurstLocation( INT16 sGridNo )
|
|
{
|
|
INT32 cnt;
|
|
if ( gbNumBurstLocations < MAX_BURST_LOCATIONS )
|
|
{
|
|
// Check if it already exists!
|
|
for ( cnt = 0; cnt < gbNumBurstLocations; cnt++ )
|
|
{
|
|
if ( gsBurstLocations[ cnt ].sGridNo == sGridNo )
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
|
|
gsBurstLocations[ gbNumBurstLocations ].sGridNo = sGridNo;
|
|
|
|
// Get cell X, Y from mouse...
|
|
GetMouseWorldCoords( &( gsBurstLocations[ gbNumBurstLocations ].sX ), &( gsBurstLocations[ gbNumBurstLocations ].sY ) );
|
|
|
|
gbNumBurstLocations++;
|
|
}
|
|
}
|
|
|
|
//Madd: to add a bit more usefulness to spread fire, I'm making it so that
|
|
//it will automatically latch onto enemies within iSearchRange tiles of the mouse drag.
|
|
void AccumulateBurstLocation( INT16 sGridNo )
|
|
{
|
|
SOLDIERTYPE* pTarget;
|
|
int iSearchRange = 2; // number of tiles beside the mouse drag to look at
|
|
INT16 sMaxLeft, sMaxRight, sMaxUp, sMaxDown, sXOffset, sYOffset, sAdjacentGridNo;
|
|
BOOLEAN foundTarget = FALSE;
|
|
|
|
//first see if we can find a guy standing right on the spot
|
|
pTarget = SimpleFindSoldier(sGridNo,0);
|
|
if (!pTarget)
|
|
pTarget = SimpleFindSoldier(sGridNo, 1); //try on a roof
|
|
|
|
if (pTarget)
|
|
{
|
|
InternalAccumulateBurstLocation(sGridNo);
|
|
foundTarget = TRUE;
|
|
}
|
|
//let's now look around this square - maybe there are some adjacent enemies we can latch onto
|
|
|
|
// stay away from the edges
|
|
|
|
// determine maximum horizontal limits
|
|
sMaxLeft = min( iSearchRange, (sGridNo % MAXCOL));
|
|
sMaxRight = min( iSearchRange, MAXCOL - ((sGridNo % MAXCOL) + 1));
|
|
|
|
// determine maximum vertical limits
|
|
sMaxUp = min( iSearchRange, (sGridNo / MAXROW));
|
|
sMaxDown = min( iSearchRange, MAXROW - ((sGridNo / MAXROW) + 1));
|
|
|
|
// reset the "reachable" flags in the region we're looking at
|
|
for (sYOffset = -sMaxUp; sYOffset <= sMaxDown; sYOffset++)
|
|
{
|
|
for (sXOffset = -sMaxLeft; sXOffset <= sMaxRight; sXOffset++)
|
|
{
|
|
sAdjacentGridNo = sGridNo + sXOffset + (MAXCOL * sYOffset);
|
|
if ( !(sAdjacentGridNo >=0 && sAdjacentGridNo < WORLD_MAX) )
|
|
{
|
|
continue;
|
|
}
|
|
|
|
pTarget = SimpleFindSoldier(sAdjacentGridNo,0); // look for a guy in that gridno
|
|
|
|
if (!pTarget)
|
|
pTarget = SimpleFindSoldier(sAdjacentGridNo, 1); //try on a roof
|
|
|
|
if (pTarget)
|
|
{
|
|
InternalAccumulateBurstLocation(sAdjacentGridNo); //there's somebody there! let's latch onto him
|
|
foundTarget = TRUE;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
if ( !foundTarget )
|
|
{
|
|
//didn't find anyone nearby, but we should target this space anyway to prevent players from abusing this feature
|
|
InternalAccumulateBurstLocation(sGridNo);
|
|
}
|
|
}
|
|
|
|
|
|
void PickBurstLocations( SOLDIERTYPE *pSoldier )
|
|
{
|
|
UINT8 ubShotsPerBurst;
|
|
FLOAT dAccululator = 0;
|
|
FLOAT dStep = 0;
|
|
INT32 cnt;
|
|
UINT8 ubLocationNum;
|
|
|
|
// OK, using the # of locations, spread them evenly between our current weapon shots per burst value
|
|
|
|
// Get shots per burst
|
|
//DIGICRAB: Burst UnCap
|
|
//if we fire more than MAX_BURST_SPREAD_TARGETS bullets, make sure there's no buffer overflow
|
|
if(pSoldier->bDoAutofire)
|
|
{
|
|
INT16 sAPCosts;
|
|
|
|
if ( pSoldier->bDoAutofire <= gbNumBurstLocations )
|
|
{
|
|
pSoldier->bDoAutofire = 1;
|
|
do
|
|
{
|
|
pSoldier->bDoAutofire++;
|
|
sAPCosts = CalcTotalAPsToAttack( pSoldier, gsBurstLocations[0].sGridNo, TRUE, 0);
|
|
}
|
|
while(EnoughPoints( pSoldier, sAPCosts, 0, FALSE ) && pSoldier->inv[ pSoldier->ubAttackingHand ].ubGunShotsLeft >= pSoldier->bDoAutofire && gbNumBurstLocations >= pSoldier->bDoAutofire);
|
|
pSoldier->bDoAutofire--;
|
|
|
|
ubShotsPerBurst = __min(pSoldier->bDoAutofire,MAX_BURST_SPREAD_TARGETS);
|
|
}
|
|
else if ( gbNumBurstLocations > 0 )
|
|
ubShotsPerBurst = pSoldier->bDoAutofire / gbNumBurstLocations;
|
|
|
|
}
|
|
else
|
|
{
|
|
if ( pSoldier->bWeaponMode == WM_ATTACHED_GL_BURST )
|
|
ubShotsPerBurst = __min(Weapon[GetAttachedGrenadeLauncher(&pSoldier->inv[HANDPOS])].ubShotsPerBurst,MAX_BURST_SPREAD_TARGETS);
|
|
else
|
|
ubShotsPerBurst = __min(GetShotsPerBurst(&pSoldier->inv[ HANDPOS ]),MAX_BURST_SPREAD_TARGETS);
|
|
}
|
|
|
|
// Use # gridnos accululated and # burst shots to determine accululator
|
|
dStep = gbNumBurstLocations / (FLOAT)ubShotsPerBurst;
|
|
|
|
//Loop through our shots!
|
|
for ( cnt = 0; cnt < ubShotsPerBurst; cnt++ )
|
|
{
|
|
// Get index into list
|
|
ubLocationNum = (UINT8)( dAccululator );
|
|
|
|
// Add to merc location
|
|
pSoldier->sSpreadLocations[ cnt ] = gsBurstLocations[ ubLocationNum ].sGridNo;
|
|
DebugMsg(TOPIC_JA2,DBG_LEVEL_3,String("PickBurstLocations: loc#%d = %d", cnt, pSoldier->sSpreadLocations[ cnt ]));
|
|
// Acculuate index value
|
|
dAccululator += dStep;
|
|
}
|
|
|
|
// OK, they have been added
|
|
}
|
|
|
|
void AIPickBurstLocations( SOLDIERTYPE *pSoldier, INT8 bTargets, SOLDIERTYPE *pTargets[5] )
|
|
{
|
|
UINT8 ubShotsPerBurst;
|
|
FLOAT dAccululator = 0;
|
|
FLOAT dStep = 0;
|
|
INT32 cnt;
|
|
UINT8 ubLocationNum;
|
|
|
|
// OK, using the # of locations, spread them evenly between our current weapon shots per burst value
|
|
|
|
// Get shots per burst
|
|
//DIGICRAB: Burst UnCap
|
|
//if we fire more than MAX_BURST_SPREAD_TARGETS bullets, make sure there's no buffer overflow
|
|
if(pSoldier->bDoAutofire)
|
|
ubShotsPerBurst = __min(pSoldier->bDoAutofire,MAX_BURST_SPREAD_TARGETS);
|
|
else
|
|
ubShotsPerBurst = __min(GetShotsPerBurst (&pSoldier->inv[ HANDPOS ]),MAX_BURST_SPREAD_TARGETS);
|
|
|
|
if ( ubShotsPerBurst <= 0 )
|
|
ubShotsPerBurst = 1;
|
|
|
|
// Use # gridnos accululated and # burst shots to determine accululator
|
|
//dStep = gbNumBurstLocations / (FLOAT)ubShotsPerBurst;
|
|
// CJC: tweak!
|
|
dStep = bTargets / (FLOAT)ubShotsPerBurst;
|
|
|
|
//Loop through our shots!
|
|
for ( cnt = 0; cnt < ubShotsPerBurst; cnt++ )
|
|
{
|
|
// Get index into list
|
|
ubLocationNum = (UINT8)( dAccululator );
|
|
|
|
// Add to merc location
|
|
pSoldier->sSpreadLocations[ cnt ] = pTargets[ubLocationNum]->sGridNo;
|
|
|
|
// Acculuate index value
|
|
dAccululator += dStep;
|
|
}
|
|
|
|
// OK, they have been added
|
|
}
|
|
|
|
|
|
extern HVOBJECT GetCursorFileVideoObject( UINT32 uiCursorFile );
|
|
|
|
|
|
void RenderAccumulatedBurstLocations( )
|
|
{
|
|
INT32 cnt;
|
|
INT16 sGridNo;
|
|
HVOBJECT hVObject;
|
|
|
|
if ( !gfBeginBurstSpreadTracking )
|
|
{
|
|
return;
|
|
}
|
|
|
|
if ( gbNumBurstLocations == 0 )
|
|
{
|
|
return;
|
|
}
|
|
|
|
// Loop through each location...
|
|
GetVideoObject( &hVObject, guiBURSTACCUM );
|
|
|
|
// If on screen, render
|
|
|
|
// Check if it already exists!
|
|
for ( cnt = 0; cnt < gbNumBurstLocations; cnt++ )
|
|
{
|
|
sGridNo = gsBurstLocations[ cnt ].sGridNo;
|
|
|
|
if ( GridNoOnScreen( sGridNo ) )
|
|
{
|
|
FLOAT dOffsetX, dOffsetY;
|
|
FLOAT dTempX_S, dTempY_S;
|
|
INT16 sXPos, sYPos;
|
|
INT32 iBack;
|
|
|
|
dOffsetX = (FLOAT)( gsBurstLocations[ cnt ].sX - gsRenderCenterX );
|
|
dOffsetY = (FLOAT)( gsBurstLocations[ cnt ].sY - gsRenderCenterY );
|
|
|
|
// Calculate guy's position
|
|
FloatFromCellToScreenCoordinates( dOffsetX, dOffsetY, &dTempX_S, &dTempY_S );
|
|
|
|
sXPos = ( ( gsVIEWPORT_END_X - gsVIEWPORT_START_X ) /2 ) + (INT16)dTempX_S;
|
|
sYPos = ( ( gsVIEWPORT_END_Y - gsVIEWPORT_START_Y ) /2 ) + (INT16)dTempY_S - gpWorldLevelData[ sGridNo ].sHeight;
|
|
|
|
// Adjust for offset position on screen
|
|
sXPos -= gsRenderWorldOffsetX;
|
|
sYPos -= gsRenderWorldOffsetY;
|
|
|
|
// Adjust for render height
|
|
sYPos += gsRenderHeight;
|
|
|
|
//sScreenY -= gpWorldLevelData[ sGridNo ].sHeight;
|
|
|
|
// Center circle!
|
|
//sXPos -= 10;
|
|
//sYPos -= 10;
|
|
|
|
iBack = RegisterBackgroundRect( BGND_FLAG_SINGLE, NULL, sXPos, sYPos, (INT16)(sXPos +40 ), (INT16)(sYPos + 40 ) );
|
|
if ( iBack != -1 )
|
|
{
|
|
SetBackgroundRectFilled( iBack );
|
|
}
|
|
|
|
BltVideoObject( FRAME_BUFFER, hVObject, 1, sXPos, sYPos, VO_BLT_SRCTRANSPARENCY, NULL );
|
|
}
|
|
}
|
|
}
|
|
|
|
|