2019-11-20 16:21:32 +00:00
//-------------------------------------------------------------------------
/*
Copyright ( C ) 2010 - 2019 EDuke32 developers and contributors
Copyright ( C ) 2019 sirlemonhead , Nuke . YKT
This file is part of PCExhumed .
PCExhumed is free software ; you can redistribute it and / or
modify it under the terms of the GNU General Public License version 2
as published by the Free Software Foundation .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE .
See the GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program ; if not , write to the Free Software
Foundation , Inc . , 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 , USA .
*/
//-------------------------------------------------------------------------
2019-11-22 23:11:37 +00:00
# include "ns.h"
2019-08-26 03:59:14 +00:00
# include "compat.h"
# include "engine.h"
# include "exhumed.h"
# include "sequence.h"
# include "names.h"
# include "player.h"
2019-11-24 09:03:19 +00:00
# include "ps_input.h"
2019-08-26 03:59:14 +00:00
# include "sound.h"
# include "view.h"
# include "status.h"
# include "version.h"
2020-08-18 07:52:08 +00:00
# include "aistuff.h"
2019-12-27 09:52:40 +00:00
# include "mapinfo.h"
2019-08-26 03:59:14 +00:00
# include <string.h>
# include <cstdio> // for printf
# include <cstdlib>
# include <stdarg.h>
# include <ctype.h>
# include <time.h>
# include <assert.h>
2019-12-12 23:19:34 +00:00
# include "gamecvars.h"
2019-12-26 22:17:11 +00:00
# include "savegamehelp.h"
2019-12-27 19:05:58 +00:00
# include "c_dispatch.h"
2020-04-12 06:09:38 +00:00
# include "raze_sound.h"
2020-08-20 19:05:14 +00:00
# include "gamestate.h"
# include "screenjob.h"
2020-08-22 19:13:11 +00:00
# include "c_console.h"
# include "cheathandler.h"
2020-08-26 22:53:35 +00:00
# include "inputstate.h"
2020-09-02 22:29:17 +00:00
# include "d_protocol.h"
2020-10-06 20:35:25 +00:00
# include "texturemanager.h"
2020-10-04 16:31:48 +00:00
# include "razemenu.h"
2020-10-13 19:38:24 +00:00
# include "v_draw.h"
2019-08-26 03:59:14 +00:00
2019-11-22 23:11:37 +00:00
BEGIN_PS_NS
2020-09-11 18:56:46 +00:00
static MapRecord * NextMap ;
2019-08-31 09:08:38 +00:00
2020-08-18 07:52:08 +00:00
void uploadCinemaPalettes ( ) ;
2020-08-18 08:28:19 +00:00
int32_t registerosdcommands ( void ) ;
2020-08-19 22:55:31 +00:00
void InitFonts ( ) ;
2020-09-02 22:41:32 +00:00
void InitCheats ( ) ;
2019-08-26 03:59:14 +00:00
2020-09-04 19:59:38 +00:00
int EndLevel = 0 ;
2019-08-26 03:59:14 +00:00
2019-10-31 17:22:12 +00:00
2020-08-26 15:12:48 +00:00
InputPacket localInput ;
2019-10-31 17:22:12 +00:00
////////
2020-08-18 07:52:08 +00:00
void ResetEngine ( )
{
EraseScreen ( - 1 ) ;
resettiming ( ) ;
}
void InstallEngine ( )
{
TileFiles . LoadArtSet ( " tiles%03d.art " ) ;
if ( engineInit ( ) )
{
G_FatalEngineError ( ) ;
}
uploadCinemaPalettes ( ) ;
LoadPaletteLookups ( ) ;
}
void RemoveEngine ( )
{
engineUnInit ( ) ;
}
2019-08-26 03:59:14 +00:00
void CopyTileToBitmap ( short nSrcTile , short nDestTile , int xPos , int yPos ) ;
// void TestSaveLoad();
void EraseScreen ( int nVal ) ;
void LoadStatus ( ) ;
void MySetView ( int x1 , int y1 , int x2 , int y2 ) ;
char sHollyStr [ 40 ] ;
short nFontFirstChar ;
short nBackgroundPic ;
short nShadowPic ;
2020-08-23 12:39:14 +00:00
short nCreaturesKilled = 0 , nCreaturesTotal = 0 ;
int leveltime ;
2019-08-26 03:59:14 +00:00
short nFreeze ;
short nSnakeCam = - 1 ;
short nLocalSpr ;
int nNetPlayerCount = 0 ;
short nClockVal ;
short nRedTicks ;
short nAlarmTicks ;
short nButtonColor ;
short nEnergyChan ;
2020-08-18 08:28:19 +00:00
short bModemPlay = false ;
2019-08-26 03:59:14 +00:00
int lCountDown = 0 ;
short nEnergyTowers = 0 ;
short nCfgNetPlayers = 0 ;
FILE * vcrfp = NULL ;
int lLocalCodes = 0 ;
2020-08-18 08:28:19 +00:00
short bCoordinates = false ;
2019-08-26 03:59:14 +00:00
int nNetTime = - 1 ;
short nCodeMin = 0 ;
short nCodeMax = 0 ;
short nCodeIndex = 0 ;
2019-08-27 06:08:18 +00:00
//short nScreenWidth = 320;
//short nScreenHeight = 200;
2019-08-26 03:59:14 +00:00
int flash ;
int totalmoves ;
short nCurBodyNum = 0 ;
short nBodyTotal = 0 ;
short lastfps ;
short nTotalPlayers = 1 ;
2019-11-13 21:34:11 +00:00
// TODO: Rename this (or make it static) so it doesn't conflict with library function
//short socket = 0;
2019-08-26 03:59:14 +00:00
short nFirstPassword = 0 ;
short nFirstPassInfo = 0 ;
short nPasswordCount = 0 ;
2020-08-18 08:28:19 +00:00
short bSnakeCam = false ;
short bRecord = false ;
short bPlayback = false ;
short bInDemo = false ;
short bSlipMode = false ;
short bDoFlashes = true ;
2019-08-26 03:59:14 +00:00
2020-08-19 22:55:31 +00:00
short besttarget ;
2019-08-26 03:59:14 +00:00
short scan_char = 0 ;
int nStartLevel ;
int nTimeLimit ;
2019-10-27 16:36:25 +00:00
int bVanilla = 0 ;
2019-08-26 03:59:14 +00:00
void DebugOut ( const char * fmt , . . . )
{
# ifdef _DEBUG
2019-08-27 06:08:18 +00:00
va_list args ;
2019-08-26 03:59:14 +00:00
va_start ( args , fmt ) ;
2019-11-24 09:03:19 +00:00
VPrintf ( PRINT_HIGH , fmt , args ) ;
2019-08-26 03:59:14 +00:00
# endif
}
2019-08-27 06:08:18 +00:00
void ShutDown ( void )
{
StopCD ( ) ;
RemoveEngine ( ) ;
2019-12-25 22:37:16 +00:00
//UnInitFX();
2019-08-27 06:08:18 +00:00
}
2019-08-26 03:59:14 +00:00
void DoClockBeep ( )
{
2020-10-15 17:10:51 +00:00
int i ;
StatIterator it ( 407 ) ;
while ( ( i = it . NextIndex ( ) ) > = 0 )
{
2019-09-21 15:47:55 +00:00
PlayFX2 ( StaticSound [ kSound74 ] , i ) ;
2019-08-27 06:08:18 +00:00
}
2019-08-26 03:59:14 +00:00
}
void DoRedAlert ( int nVal )
{
2019-08-27 06:08:18 +00:00
if ( nVal )
{
nAlarmTicks = 69 ;
nRedTicks = 30 ;
}
2020-10-15 17:10:51 +00:00
int i ;
StatIterator it ( 405 ) ;
while ( ( i = it . NextIndex ( ) ) > = 0 )
2019-08-27 06:08:18 +00:00
{
if ( nVal )
{
2019-09-21 15:47:55 +00:00
PlayFXAtXYZ ( StaticSound [ kSoundAlarm ] , sprite [ i ] . x , sprite [ i ] . y , sprite [ i ] . z , sprite [ i ] . sectnum ) ;
2019-08-27 06:08:18 +00:00
AddFlash ( sprite [ i ] . sectnum , sprite [ i ] . x , sprite [ i ] . y , sprite [ i ] . z , 192 ) ;
}
}
2019-08-26 03:59:14 +00:00
}
void DrawClock ( )
{
2019-08-27 06:08:18 +00:00
int ebp = 49 ;
2019-08-26 03:59:14 +00:00
2019-11-24 12:59:36 +00:00
auto pixels = TileFiles . tileMakeWritable ( kTile3603 ) ;
2019-08-26 03:59:14 +00:00
2020-04-11 22:04:02 +00:00
memset ( pixels , TRANSPARENT_INDEX , 4096 ) ;
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
if ( lCountDown / 30 ! = nClockVal )
{
nClockVal = lCountDown / 30 ;
DoClockBeep ( ) ;
}
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
int nVal = nClockVal ;
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
while ( nVal )
{
int v2 = nVal & 0xF ;
2020-02-04 21:45:10 +00:00
int yPos = 32 - tilesiz [ v2 + kClockSymbol1 ] . y / 2 ;
2019-08-26 03:59:14 +00:00
2020-02-04 21:45:10 +00:00
CopyTileToBitmap ( v2 + kClockSymbol1 , kTile3603 , ebp - tilesiz [ v2 + kClockSymbol1 ] . x / 2 , yPos ) ;
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
ebp - = 15 ;
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
nVal / = 16 ;
}
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
DoEnergyTile ( ) ;
2019-08-26 03:59:14 +00:00
}
2020-08-25 22:49:25 +00:00
double calc_smoothratio ( )
2019-11-03 17:20:05 +00:00
{
2020-05-29 01:15:01 +00:00
if ( bRecord | | bPlayback | | nFreeze ! = 0 | | bCamera | | paused )
2020-08-25 22:49:25 +00:00
return MaxSmoothRatio ;
2020-02-02 09:27:47 +00:00
2020-08-25 22:49:25 +00:00
return I_GetTimeFrac ( ) * MaxSmoothRatio ;
2019-11-03 17:20:05 +00:00
}
2020-08-22 20:40:22 +00:00
void GameMove ( void )
2019-11-03 17:20:05 +00:00
{
FixPalette ( ) ;
2020-08-23 14:24:54 +00:00
if ( currentLevel - > levelNumber = = kMap20 )
2019-11-03 17:20:05 +00:00
{
if ( lCountDown < = 0 )
{
2020-08-23 10:26:52 +00:00
DoGameOverScene ( true ) ;
2019-11-03 17:20:05 +00:00
return ;
}
// Pink section
lCountDown - - ;
DrawClock ( ) ;
if ( nRedTicks )
{
nRedTicks - - ;
if ( nRedTicks < = 0 ) {
DoRedAlert ( 0 ) ;
}
2019-11-18 22:15:48 +00:00
}
2019-11-03 17:20:05 +00:00
2019-11-18 22:15:48 +00:00
nAlarmTicks - - ;
nButtonColor - - ;
2019-11-03 17:20:05 +00:00
2019-11-18 22:15:48 +00:00
if ( nAlarmTicks < = 0 ) {
DoRedAlert ( 1 ) ;
2019-11-03 17:20:05 +00:00
}
}
// YELLOW SECTION
MoveThings ( ) ;
2019-11-08 16:55:26 +00:00
obobangle = bobangle ;
2019-11-03 17:20:05 +00:00
if ( totalvel [ nLocalPlayer ] = = 0 )
{
bobangle = 0 ;
}
else
{
bobangle + = 56 ;
bobangle & = kAngleMask ;
}
2019-11-03 17:32:02 +00:00
UpdateCreepySounds ( ) ;
2019-11-03 17:20:05 +00:00
// loc_120E9:
totalmoves + + ;
}
2020-08-26 22:53:35 +00:00
static int SelectAltWeapon ( int weap2 )
{
// todo
return 0 ;
}
2020-08-23 05:49:58 +00:00
2020-08-25 22:49:25 +00:00
2020-09-02 20:55:57 +00:00
void GameInterface : : Ticker ( )
{
2020-09-04 19:59:38 +00:00
if ( paused )
{
r_NoInterpolate = true ;
}
else if ( EndLevel = = 0 )
2020-08-23 05:49:58 +00:00
{
2020-09-02 20:55:57 +00:00
inita & = kAngleMask ;
2020-08-28 07:07:36 +00:00
2020-09-02 20:55:57 +00:00
for ( int i = 0 ; i < 4 ; i + + )
2020-08-23 07:11:32 +00:00
{
2020-09-02 20:55:57 +00:00
lPlayerXVel + = localInput . fvel * Cos ( inita ) + localInput . svel * Sin ( inita ) ;
lPlayerYVel + = localInput . fvel * Sin ( inita ) - localInput . svel * Cos ( inita ) ;
lPlayerXVel - = ( lPlayerXVel > > 5 ) + ( lPlayerXVel > > 6 ) ;
lPlayerYVel - = ( lPlayerYVel > > 5 ) + ( lPlayerYVel > > 6 ) ;
}
2020-08-23 05:49:58 +00:00
2020-09-02 20:55:57 +00:00
if ( localInput . actions & SB_INVPREV )
{
int nItem = nPlayerItem [ nLocalPlayer ] ;
2020-08-23 05:49:58 +00:00
2020-09-02 20:55:57 +00:00
int i ;
for ( i = 6 ; i > 0 ; i - - )
2020-08-27 20:19:24 +00:00
{
2020-09-02 20:55:57 +00:00
nItem - - ;
if ( nItem < 0 ) nItem = 5 ;
2020-08-27 20:19:24 +00:00
2020-09-02 20:55:57 +00:00
if ( PlayerList [ nLocalPlayer ] . items [ nItem ] ! = 0 )
break ;
2020-08-27 20:19:24 +00:00
}
2020-09-02 20:55:57 +00:00
if ( i > 0 ) SetPlayerItem ( nLocalPlayer , nItem ) ;
}
2020-08-27 20:19:24 +00:00
2020-09-02 20:55:57 +00:00
if ( localInput . actions & SB_INVNEXT )
{
int nItem = nPlayerItem [ nLocalPlayer ] ;
2020-08-27 20:19:24 +00:00
2020-09-02 20:55:57 +00:00
int i ;
for ( i = 6 ; i > 0 ; i - - )
{
nItem + + ;
if ( nItem = = 6 ) nItem = 0 ;
2020-08-27 20:19:24 +00:00
2020-09-02 20:55:57 +00:00
if ( PlayerList [ nLocalPlayer ] . items [ nItem ] ! = 0 )
break ;
2020-08-27 20:19:24 +00:00
}
2020-09-02 20:55:57 +00:00
if ( i > 0 ) SetPlayerItem ( nLocalPlayer , nItem ) ;
}
if ( localInput . actions & SB_INVUSE )
{
if ( nPlayerItem [ nLocalPlayer ] ! = - 1 )
2020-08-27 20:19:24 +00:00
{
2020-09-02 20:55:57 +00:00
localInput . setItemUsed ( nPlayerItem [ nLocalPlayer ] ) ;
2020-08-27 20:19:24 +00:00
}
2020-09-02 20:55:57 +00:00
}
2020-08-27 20:19:24 +00:00
2020-09-02 20:55:57 +00:00
for ( int i = 0 ; i < 6 ; i + + )
{
if ( localInput . isItemUsed ( i ) )
2020-08-27 19:25:09 +00:00
{
2020-09-02 20:55:57 +00:00
localInput . clearItemUsed ( i ) ;
if ( PlayerList [ nLocalPlayer ] . items [ i ] > 0 )
2020-08-27 19:25:09 +00:00
{
2020-09-02 20:55:57 +00:00
if ( nItemMagic [ i ] < = PlayerList [ nLocalPlayer ] . nMagic )
2020-08-27 19:25:09 +00:00
{
2020-09-02 20:55:57 +00:00
sPlayerInput [ nLocalPlayer ] . nItem = i ;
break ;
2020-08-27 19:25:09 +00:00
}
}
}
2020-09-02 20:55:57 +00:00
}
2020-08-27 19:25:09 +00:00
2020-10-12 11:31:57 +00:00
auto currWeap = PlayerList [ nLocalPlayer ] . nCurrentWeapon ;
int weap2 = localInput . getNewWeapon ( ) ;
if ( weap2 = = WeaponSel_Next )
{
2020-10-22 08:29:31 +00:00
auto newWeap = currWeap = = 6 ? 0 : currWeap + 1 ;
2020-11-06 12:25:55 +00:00
while ( ! ( nPlayerWeapons [ nLocalPlayer ] & ( 1 < < newWeap ) ) | | ( nPlayerWeapons [ nLocalPlayer ] & ( 1 < < newWeap ) & & PlayerList [ nLocalPlayer ] . nAmmo [ newWeap ] = = 0 ) )
2020-10-22 08:29:31 +00:00
{
newWeap + + ;
}
localInput . setNewWeapon ( newWeap + 1 ) ;
2020-10-12 11:31:57 +00:00
}
else if ( weap2 = = WeaponSel_Prev )
{
2020-10-22 08:29:31 +00:00
auto newWeap = currWeap = = 0 ? 6 : currWeap - 1 ;
2020-11-06 12:25:55 +00:00
while ( ! ( nPlayerWeapons [ nLocalPlayer ] & ( 1 < < newWeap ) ) | | ( nPlayerWeapons [ nLocalPlayer ] & ( 1 < < newWeap ) & & PlayerList [ nLocalPlayer ] . nAmmo [ newWeap ] = = 0 ) )
2020-10-22 08:29:31 +00:00
{
newWeap - - ;
}
localInput . setNewWeapon ( newWeap + 1 ) ;
2020-10-12 11:31:57 +00:00
}
else if ( weap2 = = WeaponSel_Alt )
{
weap2 = SelectAltWeapon ( weap2 ) ;
}
2020-09-02 20:55:57 +00:00
// make weapon selection persist until it gets used up.
int weap = sPlayerInput [ nLocalPlayer ] . getNewWeapon ( ) ;
if ( weap2 < = 0 | | weap2 > 7 ) sPlayerInput [ nLocalPlayer ] . SetNewWeapon ( weap ) ;
2020-08-27 19:25:09 +00:00
2020-09-21 08:36:04 +00:00
auto oldactions = sPlayerInput [ nLocalPlayer ] . actions ;
sPlayerInput [ nLocalPlayer ] . actions = localInput . actions ;
2020-10-12 11:31:57 +00:00
if ( oldactions & SB_CENTERVIEW ) sPlayerInput [ nLocalPlayer ] . actions | = SB_CENTERVIEW ;
2020-09-21 08:36:04 +00:00
2020-10-12 11:31:57 +00:00
sPlayerInput [ nLocalPlayer ] . xVel = lPlayerXVel ;
sPlayerInput [ nLocalPlayer ] . yVel = lPlayerYVel ;
sPlayerInput [ nLocalPlayer ] . buttons = lLocalCodes ;
sPlayerInput [ nLocalPlayer ] . nTarget = besttarget ;
2020-10-08 03:47:30 +00:00
sPlayerInput [ nLocalPlayer ] . nAngle = localInput . avel ;
2020-10-07 07:22:07 +00:00
sPlayerInput [ nLocalPlayer ] . pan = localInput . horz ;
2020-09-21 09:28:39 +00:00
2020-09-02 20:55:57 +00:00
Ra [ nLocalPlayer ] . nTarget = besttarget ;
2020-08-23 05:49:58 +00:00
2020-09-02 20:55:57 +00:00
lLocalCodes = 0 ;
leveltime + + ;
2020-09-05 20:39:27 +00:00
if ( leveltime = = 2 ) gameaction = ga_autosave ; // let the game run for 1 frame before saving.
2020-09-02 20:55:57 +00:00
GameMove ( ) ;
r_NoInterpolate = false ;
}
2020-09-04 19:59:38 +00:00
else
{
// Wait for the end of level sound to play out, but stop updating the playsim.
2020-09-11 18:56:46 +00:00
if ( EndLevel = = 13 )
PlayLocalSound ( StaticSound [ 59 ] , 0 , true , CHANF_UI ) ;
if ( EndLevel > 1 ) EndLevel - - ;
2020-09-14 20:31:15 +00:00
r_NoInterpolate = true ;
2020-09-11 18:56:46 +00:00
int flash = 7 - abs ( EndLevel - 7 ) ;
videoTintBlood ( flash * 30 , flash * 30 , flash * 30 ) ;
if ( EndLevel = = 1 )
{
if ( ! soundEngine - > GetSoundPlayingInfo ( SOURCE_None , nullptr , StaticSound [ 59 ] + 1 ) )
{
videoTintBlood ( 0 , 0 , 0 ) ;
CompleteLevel ( NextMap ) ;
NextMap = nullptr ;
EndLevel = 0 ;
}
}
2020-09-04 19:59:38 +00:00
}
2020-09-02 20:55:57 +00:00
}
2020-08-23 05:49:58 +00:00
2020-09-11 18:56:46 +00:00
void LevelFinished ( )
{
NextMap = currentLevel - > levelNumber = = 20 ? nullptr : FindMapByLevelNum ( currentLevel - > levelNumber + 1 ) ; // todo: Use the map record for progression
EndLevel = 13 ;
}
2019-12-14 00:33:26 +00:00
void ExitGame ( )
{
ShutDown ( ) ;
2020-04-11 21:50:43 +00:00
throw CExitEvent ( 0 ) ;
2019-12-14 00:33:26 +00:00
}
2020-10-06 20:35:25 +00:00
# define x(a, b) registerName(#a, b);
static void SetTileNames ( )
{
auto registerName = [ ] ( const char * name , int index )
{
TexMan . AddAlias ( name , tileGetTexture ( index ) ) ;
} ;
# include "namelist.h"
}
# undef x
2020-08-23 15:47:05 +00:00
void GameInterface : : app_init ( )
2019-11-24 12:59:36 +00:00
{
int i ;
//int esi = 1;
//int edi = esi;
2020-10-04 16:31:48 +00:00
#if 0
2020-02-29 11:55:12 +00:00
help_disabled = true ;
2020-10-04 16:31:48 +00:00
# endif
2019-12-27 09:52:40 +00:00
// Create the global level table. Parts of the engine need it, even though the game itself does not.
for ( int i = 0 ; i < = 32 ; i + + )
{
2020-08-23 10:26:52 +00:00
auto mi = AllocateMap ( ) ;
2019-12-27 09:52:40 +00:00
mi - > fileName . Format ( " LEV%d.MAP " , i ) ;
mi - > labelName . Format ( " LEV%d " , i ) ;
mi - > name . Format ( " $TXT_EX_MAP%02d " , i ) ;
2020-08-23 10:26:52 +00:00
mi - > levelNumber = i ;
2019-12-27 09:52:40 +00:00
int nTrack = i ;
if ( nTrack ! = 0 ) nTrack - - ;
mi - > cdSongId = ( nTrack % 8 ) + 11 ;
}
2020-09-02 22:41:32 +00:00
InitCheats ( ) ;
2019-08-31 09:08:38 +00:00
registerosdcommands ( ) ;
2019-08-27 06:08:18 +00:00
if ( nNetPlayerCount = = - 1 )
{
nNetPlayerCount = nCfgNetPlayers - 1 ;
nTotalPlayers + = nNetPlayerCount ;
}
// temp - moving InstallEngine(); before FadeOut as we use nextpage() in FadeOut
InstallEngine ( ) ;
2020-09-16 14:42:44 +00:00
LoadDefinitions ( ) ;
2020-11-10 20:34:49 +00:00
InitFonts ( ) ;
2020-10-06 20:35:25 +00:00
SetTileNames ( ) ;
2019-08-27 06:08:18 +00:00
2020-09-01 22:36:49 +00:00
TileFiles . SetBackup ( ) ;
2019-11-21 12:51:27 +00:00
2019-09-19 13:38:28 +00:00
InitFX ( ) ;
2019-08-27 06:08:18 +00:00
seq_LoadSequences ( ) ;
InitStatus ( ) ;
2020-08-30 10:49:21 +00:00
2019-08-27 06:08:18 +00:00
for ( i = 0 ; i < kMaxPlayers ; i + + ) {
nPlayerLives [ i ] = kDefaultLives ;
}
2020-08-30 10:49:21 +00:00
resettiming ( ) ;
2019-08-27 06:08:18 +00:00
GrabPalette ( ) ;
2020-08-30 10:49:21 +00:00
enginecompatibility_mode = ENGINECOMPATIBILITY_19950829 ;
2019-08-26 03:59:14 +00:00
}
void mychangespritesect ( int nSprite , int nSector )
{
2019-08-27 06:08:18 +00:00
changespritesect ( nSprite , nSector ) ;
2019-08-26 03:59:14 +00:00
}
void mydeletesprite ( int nSprite )
{
2019-08-27 06:08:18 +00:00
if ( nSprite < 0 | | nSprite > kMaxSprites ) {
2019-11-24 09:03:19 +00:00
I_Error ( " bad sprite value %d handed to mydeletesprite " , nSprite ) ;
2019-08-27 06:08:18 +00:00
}
2019-08-26 03:59:14 +00:00
2020-10-28 23:08:06 +00:00
FVector3 pos = GetSoundPos ( & sprite [ nSprite ] . pos ) ;
soundEngine - > RelinkSound ( SOURCE_Actor , & sprite [ nSprite ] , nullptr , & pos ) ;
2019-08-27 06:08:18 +00:00
deletesprite ( nSprite ) ;
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
if ( nSprite = = besttarget ) {
besttarget = - 1 ;
}
2019-08-26 03:59:14 +00:00
}
void CopyTileToBitmap ( short nSrcTile , short nDestTile , int xPos , int yPos )
{
2019-08-27 06:08:18 +00:00
int nOffs = tilesiz [ nDestTile ] . y * xPos ;
2019-11-24 12:59:36 +00:00
auto pixels = TileFiles . tileMakeWritable ( nDestTile ) ;
uint8_t * pDest = pixels + nOffs + yPos ;
2019-08-31 07:47:15 +00:00
uint8_t * pDestB = pDest ;
2019-08-27 06:08:18 +00:00
tileLoad ( nSrcTile ) ;
int destYSize = tilesiz [ nDestTile ] . y ;
int srcYSize = tilesiz [ nSrcTile ] . y ;
2019-11-20 16:21:32 +00:00
2019-11-24 12:59:36 +00:00
const uint8_t * pSrc = tilePtr ( nSrcTile ) ;
2019-11-20 16:21:32 +00:00
2019-08-27 06:08:18 +00:00
for ( int x = 0 ; x < tilesiz [ nSrcTile ] . x ; x + + )
{
pDest + = destYSize ;
for ( int y = 0 ; y < srcYSize ; y + + )
{
2019-08-31 07:47:15 +00:00
uint8_t val = * pSrc ;
2020-04-11 22:04:02 +00:00
if ( val ! = TRANSPARENT_INDEX ) {
2019-08-27 06:08:18 +00:00
* pDestB = val ;
}
pDestB + + ;
pSrc + + ;
}
// reset pDestB
pDestB = pDest ;
}
2019-11-05 06:15:21 +00:00
2020-08-22 16:12:19 +00:00
TileFiles . InvalidateTile ( nDestTile ) ;
2019-08-26 03:59:14 +00:00
}
void EraseScreen ( int nVal )
{
2020-04-12 05:44:55 +00:00
// There's no other values than 0 ever coming through here.
2020-06-12 18:52:01 +00:00
twod - > ClearScreen ( ) ;
2019-08-26 03:59:14 +00:00
}
2019-12-26 18:41:42 +00:00
bool GameInterface : : CanSave ( )
{
2020-05-29 01:15:01 +00:00
return ! bRecord & & ! bPlayback & & ! paused & & ! bInDemo & & nTotalPlayers = = 1 ;
2019-12-26 18:41:42 +00:00
}
2019-12-27 09:52:40 +00:00
2020-08-23 12:39:14 +00:00
: : GameStats GameInterface : : getStats ( )
{
return { nCreaturesKilled , nCreaturesTotal , 0 , 0 , leveltime / 30 , 0 } ;
}
2019-12-12 23:19:34 +00:00
: : GameInterface * CreateInterface ( )
{
return new GameInterface ;
}
2019-12-26 21:00:04 +00:00
// This is only the static global data.
2020-10-11 09:33:28 +00:00
static SavegameHelper sghexhumed ( " exhumed " ,
2020-08-19 22:55:31 +00:00
SV ( besttarget ) ,
2020-08-23 12:39:14 +00:00
SV ( nCreaturesTotal ) ,
SV ( nCreaturesKilled ) ,
2019-12-26 21:00:04 +00:00
SV ( nFreeze ) ,
SV ( nSnakeCam ) ,
SV ( nLocalSpr ) ,
SV ( nClockVal ) , // kTile3603
SV ( nRedTicks ) ,
SV ( nAlarmTicks ) ,
SV ( nButtonColor ) ,
SV ( nEnergyChan ) ,
SV ( lCountDown ) ,
SV ( nEnergyTowers ) ,
SV ( totalmoves ) ,
SV ( nCurBodyNum ) ,
SV ( nBodyTotal ) ,
SV ( bSnakeCam ) ,
SV ( bSlipMode ) ,
2020-08-23 12:39:14 +00:00
SV ( leveltime ) ,
2019-12-26 21:00:04 +00:00
nullptr ) ;
2020-08-22 19:39:14 +00:00
extern short cPupData [ 300 ] ;
extern uint8_t * Worktile ;
extern int lHeadStartClock ;
extern short * pPupData ;
2019-12-26 21:00:04 +00:00
2019-12-26 22:17:11 +00:00
void SaveTextureState ( )
{
auto fw = WriteSavegameChunk ( " texture " ) ;
int pupOffset = pPupData ? int ( pPupData - cPupData ) : - 1 ;
2019-12-27 09:52:40 +00:00
// There is really no good way to restore these tiles, so it's probably best to save them as well, so that they can be reloaded with the exact state they were left in
2019-12-26 22:17:11 +00:00
fw - > Write ( & pupOffset , 4 ) ;
uint8_t loaded = ! ! Worktile ;
fw - > Write ( & loaded , 1 ) ;
if ( Worktile ) fw - > Write ( Worktile , WorktileSize ) ;
auto pixels = TileFiles . tileMakeWritable ( kTile3603 ) ;
fw - > Write ( pixels , tilesiz [ kTile3603 ] . x * tilesiz [ kTile3603 ] . y ) ;
2019-12-27 09:52:40 +00:00
pixels = TileFiles . tileMakeWritable ( kEnergy1 ) ;
fw - > Write ( pixels , tilesiz [ kEnergy1 ] . x * tilesiz [ kEnergy1 ] . y ) ;
pixels = TileFiles . tileMakeWritable ( kEnergy2 ) ;
fw - > Write ( pixels , tilesiz [ kEnergy2 ] . x * tilesiz [ kEnergy2 ] . y ) ;
2019-12-26 22:17:11 +00:00
}
void LoadTextureState ( )
{
auto fr = ReadSavegameChunk ( " texture " ) ;
int pofs ;
fr . Read ( & pofs , 4 ) ;
pPupData = pofs = = - 1 ? nullptr : cPupData + pofs ;
uint8_t loaded ;
fr . Read ( & loaded , 1 ) ;
if ( loaded )
{
Worktile = TileFiles . tileCreate ( kTileRamsesWorkTile , kSpiritX * 2 , kSpiritY * 2 ) ;
fr . Read ( Worktile , WorktileSize ) ;
}
auto pixels = TileFiles . tileMakeWritable ( kTile3603 ) ;
fr . Read ( pixels , tilesiz [ kTile3603 ] . x * tilesiz [ kTile3603 ] . y ) ;
2019-12-27 09:52:40 +00:00
pixels = TileFiles . tileMakeWritable ( kEnergy1 ) ;
fr . Read ( pixels , tilesiz [ kEnergy1 ] . x * tilesiz [ kEnergy1 ] . y ) ;
pixels = TileFiles . tileMakeWritable ( kEnergy2 ) ;
fr . Read ( pixels , tilesiz [ kEnergy2 ] . x * tilesiz [ kEnergy2 ] . y ) ;
2019-12-26 22:17:11 +00:00
TileFiles . InvalidateTile ( kTileRamsesWorkTile ) ;
TileFiles . InvalidateTile ( kTile3603 ) ;
2019-12-27 09:52:40 +00:00
TileFiles . InvalidateTile ( kEnergy1 ) ;
TileFiles . InvalidateTile ( kEnergy2 ) ;
2019-12-26 22:17:11 +00:00
}
2019-12-26 21:00:04 +00:00
2020-09-11 18:56:46 +00:00
CCMD ( endit )
{
LevelFinished ( ) ;
}
2019-11-22 23:11:37 +00:00
END_PS_NS