Files
source/TileEngine/Tile Cache.cpp
T
Overhaul 7a27e7105d New attack busy system
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
2007-06-09 09:01:04 +00:00

383 lines
8.4 KiB
C++

#include "builddefines.h"
#ifdef PRECOMPILEDHEADERS
#include "TileEngine All.h"
#else
#include <stdio.h>
#include <string.h>
#include "wcheck.h"
#include "stdlib.h"
#include "debug.h"
#include "tiledef.h"
#include "Animation Cache.h"
#include "Animation Data.h"
#include "Animation Control.h"
#include "sys globals.h"
#include "Debug Control.h"
#include "tile surface.h"
#include "tile cache.h"
#include "fileman.h"
#endif
UINT32 guiNumTileCacheStructs = 0;
UINT32 guiMaxTileCacheSize = 50;
UINT32 guiCurTileCacheSize = 0;
INT32 giDefaultStructIndex = -1;
TILE_CACHE_ELEMENT *gpTileCache = NULL;
TILE_CACHE_STRUCT *gpTileCacheStructInfo = NULL;
BOOLEAN InitTileCache( )
{
UINT32 cnt;
GETFILESTRUCT FileInfo;
INT16 sFiles = 0;
gpTileCache = (TILE_CACHE_ELEMENT *)MemAlloc( sizeof( TILE_CACHE_ELEMENT ) * guiMaxTileCacheSize );
// Zero entries
for ( cnt = 0; cnt < guiMaxTileCacheSize; cnt++ )
{
gpTileCache[ cnt ].pImagery = NULL;
gpTileCache[ cnt ].sStructRefID = -1;
}
guiCurTileCacheSize = 0;
// OK, look for JSD files in the tile cache directory and
// load any we find....
if( GetFileFirst("TILECACHE\\*.jsd", &FileInfo) )
{
while( GetFileNext(&FileInfo) )
{
sFiles++;
}
GetFileClose(&FileInfo);
}
// Allocate memory...
if ( sFiles > 0 )
{
cnt = 0;
guiNumTileCacheStructs = sFiles;
gpTileCacheStructInfo = (TILE_CACHE_STRUCT *)MemAlloc( sizeof( TILE_CACHE_STRUCT ) * sFiles );
// Loop through and set filenames
if( GetFileFirst("TILECACHE\\*.jsd", &FileInfo) )
{
while( GetFileNext(&FileInfo) )
{
sprintf( gpTileCacheStructInfo[ cnt ].Filename, "TILECACHE\\%s", FileInfo.zFileName );
// Get root name
GetRootName( gpTileCacheStructInfo[ cnt ].zRootName, gpTileCacheStructInfo[ cnt ].Filename );
// Load struc data....
gpTileCacheStructInfo[ cnt ].pStructureFileRef = LoadStructureFile( gpTileCacheStructInfo[ cnt ].Filename );
#ifdef JA2TESTVERSION
if ( gpTileCacheStructInfo[ cnt ].pStructureFileRef == NULL )
{
SET_ERROR( "Cannot load tilecache JSD: %s", gpTileCacheStructInfo[ cnt ].Filename );
}
#endif
if ( _stricmp( gpTileCacheStructInfo[ cnt ].zRootName, "l_dead1" ) == 0 )
{
giDefaultStructIndex = cnt;
}
cnt++;
}
GetFileClose(&FileInfo);
}
}
return( TRUE );
}
void DeleteTileCache( )
{
UINT32 cnt;
// Allocate entries
if ( gpTileCache != NULL )
{
// Loop through and delete any entries
for ( cnt = 0; cnt < guiMaxTileCacheSize; cnt++ )
{
if ( gpTileCache[ cnt ].pImagery != NULL )
{
DeleteTileSurface( gpTileCache[ cnt ].pImagery );
}
}
MemFree( gpTileCache );
}
if ( gpTileCacheStructInfo != NULL )
{
MemFree( gpTileCacheStructInfo );
}
guiCurTileCacheSize = 0;
}
INT16 FindCacheStructDataIndex( STR8 cFilename )
{
UINT32 cnt;
for ( cnt = 0; cnt < guiNumTileCacheStructs; cnt++ )
{
if ( _stricmp( gpTileCacheStructInfo[ cnt ].zRootName, cFilename ) == 0 )
{
return( (INT16)cnt );
}
}
return( -1 );
}
INT32 GetCachedTile( const STR8 cFilename )
{
UINT32 cnt;
UINT32 ubLowestIndex = 0;
INT16 sMostHits = (INT16)15000;
// Check to see if surface exists already
for ( cnt = 0; cnt < guiCurTileCacheSize; cnt++ )
{
if ( gpTileCache[ cnt ].pImagery != NULL )
{
if ( _stricmp( gpTileCache[ cnt ].zName, cFilename ) == 0 )
{
// Found surface, return
gpTileCache[ cnt ].sHits++;
return( (INT32)cnt );
}
}
}
// Check if max size has been reached
if ( guiCurTileCacheSize == guiMaxTileCacheSize )
{
// cache out least used file
for ( cnt = 0; cnt < guiCurTileCacheSize; cnt++ )
{
if ( gpTileCache[ cnt ].sHits < sMostHits )
{
sMostHits = gpTileCache[ cnt ].sHits;
ubLowestIndex = cnt;
}
}
// Bump off lowest index
DeleteTileSurface( gpTileCache[ ubLowestIndex ].pImagery );
// Decrement
gpTileCache[ ubLowestIndex ].sHits = 0;
gpTileCache[ ubLowestIndex ].pImagery = NULL;
gpTileCache[ ubLowestIndex ].sStructRefID = -1;
}
// If here, Insert at an empty slot
// Find an empty slot
for ( cnt = 0; cnt < guiMaxTileCacheSize; cnt++ )
{
if ( gpTileCache[ cnt ].pImagery == NULL )
{
// Insert here
gpTileCache[ cnt ].pImagery = LoadTileSurface( cFilename );
if ( gpTileCache[ cnt ].pImagery == NULL )
{
return( -1 );
}
strcpy( gpTileCache[ cnt ].zName, cFilename );
gpTileCache[ cnt ].sHits = 1;
// Get root name
GetRootName( gpTileCache[ cnt ].zRootName, cFilename );
gpTileCache[ cnt ].sStructRefID = FindCacheStructDataIndex( gpTileCache[ cnt ].zRootName );
// ATE: Add z-strip info
if ( gpTileCache[ cnt ].sStructRefID != -1 )
{
AddZStripInfoToVObject( gpTileCache[ cnt ].pImagery->vo, gpTileCacheStructInfo[ gpTileCache[ cnt ].sStructRefID ].pStructureFileRef, TRUE, 0 );
}
if ( gpTileCache[ cnt ].pImagery->pAuxData != NULL )
{
gpTileCache[ cnt ].ubNumFrames = gpTileCache[ cnt ].pImagery-> pAuxData->ubNumberOfFrames;
}
else
{
gpTileCache[ cnt ].ubNumFrames = 1;
}
// Has our cache size increased?
if ( cnt >= guiCurTileCacheSize )
{
guiCurTileCacheSize = cnt + 1;;
}
return( cnt );
}
}
// Can't find one!
return( -1 );
}
BOOLEAN RemoveCachedTile( INT32 iCachedTile )
{
UINT32 cnt;
// Find tile
for ( cnt = 0; cnt < guiCurTileCacheSize; cnt++ )
{
if ( gpTileCache[ cnt ].pImagery != NULL )
{
if ( cnt == (UINT32)iCachedTile )
{
// Found surface, decrement hits
gpTileCache[ cnt ].sHits--;
// Are we at zero?
if ( gpTileCache[ cnt ].sHits == 0 )
{
DeleteTileSurface( gpTileCache[ cnt ].pImagery );
gpTileCache[ cnt ].pImagery = NULL;
gpTileCache[ cnt ].sStructRefID = -1;
return( TRUE );;
}
}
}
}
return( FALSE );
}
HVOBJECT GetCachedTileVideoObject( INT32 iIndex )
{
if ( iIndex == -1 )
{
return( NULL );
}
if ( gpTileCache[ iIndex ].pImagery == NULL )
{
return( NULL );
}
return( gpTileCache[ iIndex ].pImagery->vo );
}
STRUCTURE_FILE_REF *GetCachedTileStructureRef( INT32 iIndex )
{
if ( iIndex == -1 )
{
return( NULL );
}
if ( gpTileCache[ iIndex ].sStructRefID == -1 )
{
return( NULL );
}
return( gpTileCacheStructInfo[ gpTileCache[ iIndex ].sStructRefID ].pStructureFileRef );
}
STRUCTURE_FILE_REF *GetCachedTileStructureRefFromFilename( const STR8 cFilename )
{
INT16 sStructDataIndex;
// Given filename, look for index
sStructDataIndex = FindCacheStructDataIndex( cFilename );
if ( sStructDataIndex == -1 )
{
return( NULL );
}
return( gpTileCacheStructInfo[ sStructDataIndex ].pStructureFileRef );
}
void CheckForAndAddTileCacheStructInfo( LEVELNODE *pNode, INT16 sGridNo, UINT16 usIndex, UINT16 usSubIndex )
{
STRUCTURE_FILE_REF *pStructureFileRef;
pStructureFileRef = GetCachedTileStructureRef( usIndex );
if ( pStructureFileRef != NULL)
{
if ( !AddStructureToWorld( sGridNo, 0, &( pStructureFileRef->pDBStructureRef[ usSubIndex ] ), pNode ) )
{
if ( giDefaultStructIndex != -1 )
{
pStructureFileRef = gpTileCacheStructInfo[ giDefaultStructIndex ].pStructureFileRef;
if ( pStructureFileRef != NULL)
{
AddStructureToWorld( sGridNo, 0, &( pStructureFileRef->pDBStructureRef[ usSubIndex ] ), pNode );
}
}
}
}
}
void CheckForAndDeleteTileCacheStructInfo( LEVELNODE *pNode, UINT16 usIndex )
{
STRUCTURE_FILE_REF *pStructureFileRef;
if ( usIndex >= TILE_CACHE_START_INDEX )
{
pStructureFileRef = GetCachedTileStructureRef( ( usIndex - TILE_CACHE_START_INDEX ) );
if ( pStructureFileRef != NULL)
{
DeleteStructureFromWorld( pNode->pStructureData );
}
}
}
void GetRootName( STR8 pDestStr, const STR8 pSrcStr )
{
// Remove path and extension
CHAR8 cTempFilename[ 120 ];
STR cEndOfName;
// Remove path
strcpy( cTempFilename, pSrcStr );
cEndOfName = strrchr( cTempFilename, '\\' );
if (cEndOfName != NULL)
{
cEndOfName++;
strcpy( pDestStr, cEndOfName );
}
else
{
strcpy( pDestStr, cTempFilename );
}
// Now remove extension...
cEndOfName = strchr( pDestStr, '.' );
if (cEndOfName != NULL)
{
*cEndOfName = '\0';
}
}