Files
source/TileEngine/Shade Table Util.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

220 lines
6.7 KiB
C++

#include "builddefines.h"
#ifdef PRECOMPILEDHEADERS
#include "TileEngine All.h"
#else
#include <stdio.h>
#include "types.h"
#include "lighting.h"
#include "Shade Table Util.h"
#include "video.h"
#include "WorldDat.h"
#include "Fileman.h"
#endif
#define SHADE_TABLE_DIR "ShadeTables"
extern CHAR8 TileSurfaceFilenames[NUMBEROFTILETYPES][32]; // symbol already declared globally in worlddef.cpp (jonathanl)
BOOLEAN gfForceBuildShadeTables = FALSE;
#ifdef JA2TESTVERSION
extern UINT32 uiNumTablesSaved;
extern UINT32 uiNumTablesLoaded;
#endif
void DetermineRGBDistributionSettings()
{
STRING512 DataDir;
STRING512 ExecDir;
STRING512 ShadeTableDir;
UINT32 uiRBitMask, uiGBitMask, uiBBitMask;
UINT32 uiPrevRBitMask, uiPrevGBitMask, uiPrevBBitMask;
UINT32 uiNumBytesRead;
HWFILE hfile;
BOOLEAN fSaveRGBDist = FALSE;
BOOLEAN fCleanShadeTable = FALSE;
BOOLEAN fLoadedPrevRGBDist = FALSE;
// Snap: save current directory
GetFileManCurrentDirectory( DataDir );
//First, determine if we have a file saved. If not, then this is the first time, and
//all shade tables will have to be built and saved to disk. This can be time consuming, adding up to
//3-4 seconds to the time of a map load.
GetExecutableDirectory( ExecDir );
sprintf( ShadeTableDir, "%s\\%s", DataDir, SHADE_TABLE_DIR );
//Check to make sure we have a ShadeTable directory. If we don't create one!
if( !SetFileManCurrentDirectory( ShadeTableDir ) )
{
if( !MakeFileManDirectory( ShadeTableDir ) )
{
AssertMsg( 0, "ShadeTable directory doesn't exist, and couldn't create one!" );
}
if( !SetFileManCurrentDirectory( ShadeTableDir ) )
{
AssertMsg( 0, "Couldn't access the newly created ShadeTable directory." );
}
fSaveRGBDist = TRUE;
}
if( !fSaveRGBDist )
{ //Load the previous RGBDist and determine if it is the same one
if( !FileExists( "RGBDist.dat" ) || FileExists( "ResetShadeTables.txt" ) )
{ //Can't find the RGBDist.dat file. The directory exists, but the file doesn't, which
//means the user deleted the file manually. Now, set it up to create a new one.
fSaveRGBDist = TRUE;
fCleanShadeTable = TRUE;
}
else
{
hfile = FileOpen( "RGBDist.dat", FILE_ACCESS_READ, FALSE );
if( !hfile )
{
AssertMsg( 0, "Couldn't open RGBDist.dat, even though it exists!" );
}
FileRead( hfile, &uiPrevRBitMask, sizeof( UINT32 ), &uiNumBytesRead );
FileRead( hfile, &uiPrevGBitMask, sizeof( UINT32 ), &uiNumBytesRead );
FileRead( hfile, &uiPrevBBitMask, sizeof( UINT32 ), &uiNumBytesRead );
fLoadedPrevRGBDist = TRUE;
FileClose( hfile );
}
}
if( !GetPrimaryRGBDistributionMasks( &uiRBitMask, &uiGBitMask, &uiBBitMask ) )
{
AssertMsg( 0, "Failed to extract the current RGB distribution masks." );
}
if( fLoadedPrevRGBDist )
{
if( uiRBitMask != uiPrevRBitMask || uiGBitMask != uiPrevGBitMask || uiBBitMask != uiPrevBBitMask )
{ //The user has changed modes since the last time he has played JA2. This essentially can only happen if:
//1) The video card has been changed since the last run of JA2.
//2) Certain video cards have different RGB distributions in different operating systems such as
// the Millenium card using Windows NT or Windows 95
//3) The user has physically modified the RGBDist.dat file.
fSaveRGBDist = TRUE;
fCleanShadeTable = TRUE;
}
}
if( fCleanShadeTable )
{ //This means that we are going to remove all of the current shade tables, if any exist, and
//start fresh.
EraseDirectory( ShadeTableDir );
}
if( fSaveRGBDist )
{ //The RGB distribution is going to be saved in a tiny file for future reference. As long as the
//RGB distribution never changes, the shade table will grow until eventually, all tilesets are loaded,
//shadetables generated and saved in this directory.
hfile = FileOpen( "RGBDist.dat", FILE_ACCESS_WRITE | FILE_CREATE_ALWAYS, FALSE );
if( !hfile )
{
AssertMsg( 0, "Couldn't create RGBDist.dat for writing!" );
}
FileWrite( hfile, &uiRBitMask, sizeof( UINT32 ), &uiNumBytesRead );
FileWrite( hfile, &uiGBitMask, sizeof( UINT32 ), &uiNumBytesRead );
FileWrite( hfile, &uiBBitMask, sizeof( UINT32 ), &uiNumBytesRead );
FileClose( hfile );
}
// Snap: Restore the data directory once we are finished.
SetFileManCurrentDirectory( DataDir );
//We're done, so restore the executable directory to JA2\Data.
//sprintf( DataDir, "%s\\Data", ExecDir );
//SetFileManCurrentDirectory( DataDir );
}
BOOLEAN LoadShadeTable( HVOBJECT pObj, UINT32 uiTileTypeIndex )
{
HWFILE hfile;
INT32 i;
UINT32 uiNumBytesRead;
CHAR8 ShadeFileName[ 100 ];
CHAR8 *ptr;
//ASSUMPTIONS:
//We are assuming that the uiTileTypeIndex is referring to the correct file
//stored in the TileSurfaceFilenames[]. If it isn't, then that is a huge problem
//and should be fixed. Also assumes that the directory is set to Data\ShadeTables.
strcpy( ShadeFileName, TileSurfaceFilenames[ uiTileTypeIndex ] );
ptr = strstr( ShadeFileName, "." );
if( !ptr )
{
return FALSE;
}
ptr++;
sprintf( ptr, "sha" );
hfile = FileOpen( ShadeFileName, FILE_ACCESS_READ, FALSE );
if( !hfile )
{ //File doesn't exist, so generate it
FileClose( hfile );
return FALSE;
}
//MISSING: Compare time stamps.
for( i = 0; i < 16; i++ )
{
pObj->pShades[ i ] = (UINT16 *) MemAlloc( 512 );
Assert( pObj->pShades[ i ] );
FileRead( hfile, pObj->pShades[ i ], 512, &uiNumBytesRead );
}
//The file exists, now make sure the
FileClose( hfile );
#ifdef JA2TESTVERSION
uiNumTablesLoaded++;
#endif
return TRUE;
}
BOOLEAN SaveShadeTable( HVOBJECT pObj, UINT32 uiTileTypeIndex )
{
HWFILE hfile;
INT32 i;
UINT32 uiNumBytesWritten;
CHAR8 ShadeFileName[ 100 ];
CHAR8 *ptr;
#ifdef JA2TESTVERSION
uiNumTablesSaved++;
#endif
//ASSUMPTIONS:
//We are assuming that the uiTileTypeIndex is referring to the correct file
//stored in the TileSurfaceFilenames[]. If it isn't, then that is a huge problem
//and should be fixed. Also assumes that the directory is set to Data\ShadeTables.
strcpy( ShadeFileName, TileSurfaceFilenames[ uiTileTypeIndex ] );
ptr = strstr( ShadeFileName, "." );
if( !ptr )
{
return FALSE;
}
ptr++;
sprintf( ptr, "sha" );
hfile = FileOpen( ShadeFileName, FILE_ACCESS_WRITE | FILE_CREATE_ALWAYS, FALSE );
if( !hfile )
{
FileClose( hfile );
AssertMsg( 0, String( "Can't create %s", ShadeFileName ) );
return FALSE;
}
for( i = 0; i < 16; i++ )
{
FileWrite( hfile, pObj->pShades[ i ], 512, &uiNumBytesWritten );
}
FileClose( hfile );
return TRUE;
}
BOOLEAN DeleteShadeTableDir( )
{
return( RemoveFileManDirectory( SHADE_TABLE_DIR, TRUE ) );
}