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 "baselayer.h"
2019-08-31 09:08:38 +00:00
# include "common.h"
2019-08-26 03:59:14 +00:00
# include "engine.h"
# include "exhumed.h"
# include "sequence.h"
# include "names.h"
# include "menu.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-04-11 21:38:30 +00:00
# include "core/menu/menu.h"
2019-08-26 03:59:14 +00:00
2019-11-22 23:11:37 +00:00
BEGIN_PS_NS
2019-08-27 06:08:18 +00:00
extern const char * s_buildRev ;
extern const char * s_buildTimestamp ;
2019-08-31 09:08:38 +00:00
2019-08-26 03:59:14 +00:00
void FinishLevel ( ) ;
2020-08-18 07:52:08 +00:00
void uploadCinemaPalettes ( ) ;
2020-08-18 08:28:19 +00:00
int32_t registerosdcommands ( void ) ;
2019-08-26 03:59:14 +00:00
int htimer = 0 ;
/* these are XORed in the original game executable then XORed back to normal when the game first starts. Here they are normally */
2019-11-20 16:21:32 +00:00
const char * gString [ ] =
2019-08-26 03:59:14 +00:00
{
2019-08-27 06:08:18 +00:00
" CINEMAS " ,
" THE ANCIENT EGYPTIAN CITY " ,
" OF KARNAK HAS BEEN SEIZED " ,
" BY UNKNOWN POWERS, AND GREAT " ,
" TURMOIL IS SPREADING INTO " ,
" NEIGHBORING LANDS, POSING " ,
" A GRAVE THREAT TO PLANET " ,
" EARTH. MILITANT FORCES FROM " ,
" ALL PARTS OF THE GLOBE HAVE " ,
" ENTERED THE KARNAK VALLEY, " ,
" BUT NONE HAVE RETURNED. THE " ,
" ONLY KNOWN INFORMATION " ,
" REGARDING THIS CRISIS CAME " ,
" FROM A DYING KARNAK VILLAGER " ,
" WHO MANAGED TO WANDER OUT OF " ,
" THE VALLEY TO SAFETY. " ,
" 'THEY'VE STOLEN THE GREAT " ,
" KING'S MUMMY...', MURMURED " ,
" THE DYING VILLAGER, BUT THE " ,
" VILLAGER DIED BEFORE HE " ,
" COULD SAY MORE. WITH NO " ,
" OTHER OPTIONS, WORLD " ,
" LEADERS HAVE CHOSEN TO DROP " ,
" YOU INTO THE VALLEY VIA " ,
" HELICOPTER IN AN ATTEMPT " ,
" TO FIND AND DESTROY THE " ,
" THREATENING FORCES AND " ,
" RESOLVE THE MYSTERY THAT " ,
" HAS ENGULFED THIS ONCE " ,
" PEACEFUL LAND. FLYING AT " ,
" HIGH ALTITUDE TO AVOID " ,
" BEING SHOT DOWN LIKE OTHERS " ,
" BEFORE YOU, YOUR COPTER " ,
" MYSTERIOUSLY EXPLODES IN THE " ,
" AIR AS YOU BARELY ESCAPE, " ,
" WITH NO POSSIBLE CONTACT " ,
" WITH THE OUTSIDE WORLD. " ,
" SCARED AS HELL, YOU DESCEND " ,
" INTO THE HEART OF KARNAK... " ,
" HOME TO THE CELEBRATED " ,
" BURIAL CRYPT OF THE GREAT " ,
" KING RAMSES. " ,
" END " ,
" AN EVIL FORCE KNOWN AS THE " ,
" KILMAAT HAS BESIEGED THE " ,
" SANCTITY OF MY PALACE AND " ,
" IS PULLING AT THE VERY " ,
" TENDRILS OF MY EXISTENCE. " ,
" THESE FORCES INTEND TO " ,
" ENSLAVE ME BY REANIMATING " ,
" MY PRESERVED CORPSE. I HAVE " ,
" PROTECTED MY CORPSE WITH A " ,
" GENETIC KEY. IF YOU ARE " ,
" UNSUCCESSFUL I CANNOT " ,
" PROTECT CIVILIZATION, AND " ,
" CHAOS WILL PREVAIL. I AM " ,
" BEING TORN BETWEEN WORLDS " ,
" AND THIS INSIDIOUS " ,
" EXPERIMENT MUST BE STOPPED. " ,
" END " ,
" I HAVE HIDDEN A MYSTICAL " ,
" GAUNTLET AT EL KAB THAT WILL " ,
" CHANNEL MY ENERGY THROUGH " ,
" YOUR HANDS. FIND THE " ,
" GAUNTLET AND CROSS THE ASWAN " ,
" HIGH DAM TO DEFEAT THE EVIL " ,
" BEAST SET. " ,
" END " ,
" SET WAS A FORMIDABLE FOE. " ,
" NO MORTAL HAS EVEN CONQUERED " ,
" THEIR OWN FEAR, MUCH LESS " ,
" ENTERED MORTAL BATTLE AND " ,
" TAKEN HIS LIFE. " ,
" END " ,
" YOU'VE MADE IT HALFWAY TOWARD " ,
" FULLFILLING YOUR DESTINY. " ,
" THE KILMAAT ARE GROWING " ,
" RESTLESS WITH YOUR PROGRESS. " ,
" SEEK OUT A TEMPLE IN THIS " ,
" CITADEL WHERE I WILL PROVIDE " ,
" MORE INFORMATION " ,
" END " ,
" THE KILMAAT RACE HAS " ,
" CONTINUED THEIR MONSTEROUS " ,
" ANIMAL-HUMAN EXPERIMENTS IN " ,
" AN EFFORT TO SOLVE THE KEY OF " ,
" ANIMATING MY CORPSE. THE " ,
" VICTORY DEFEATING SET DIDN'T " ,
" SLOW YOU DOWN AS MUCH AS " ,
" THEY HAD PLANNED. THEY ARE " ,
" ACTIVELY ROBBING A SLAVE " ,
" GIRL OF HER LIFE TO CREATE " ,
" ANOTHER MONSTEROUS " ,
" ABOMINATION, COMBINING HUMAN " ,
" AND INSECT INTENT ON SLAYING " ,
" YOU. PREPARE YOURSELF FOR " ,
" BATTLE AS SHE WILL BE WAITING " ,
" FOR YOU AT THE LUXOR TEMPLE. " ,
" END " ,
" YOU'VE DONE WELL TO DEFEAT " ,
" SELKIS. YOU HAVE DISTRACTED " ,
" THE KILMAAT WITH YOUR " ,
" PRESENCE AND THEY HAVE " ,
" TEMPORARILY ABANDONED " ,
" ANIMATION OF MY CORPSE. " ,
" THE ALIEN QUEEN KILMAATIKHAN " ,
" HAS A PERSONAL VENDETTA " ,
" AGAINST YOU. ARROGANCE IS " ,
" HER WEAKNESS, AND IF YOU CAN " ,
" DEFEAT KILMAATIKHAN, THE " ,
" BATTLE WILL BE WON. " ,
" END " ,
" THE KILMAAT HAVE BEEN " ,
" DESTROYED. UNFORTUNATELY, " ,
" YOUR RECKLESSNESS HAS " ,
" DESTROYED THE EARTH AND ALL " ,
" OF ITS INHABITANTS. ALL THAT " ,
" REMAINS IS A SMOLDERING HUNK " ,
" OF ROCK. " ,
" END " ,
" THE KILMAAT HAVE BEEN " ,
" DEFEATED AND YOU SINGLE " ,
" HANDEDLY SAVED THE EARTH " ,
" FROM DESTRUCTION. " ,
" " ,
" " ,
" " ,
" YOUR BRAVERY AND HEROISM " ,
" ARE LEGENDARY. " ,
" END " ,
" ITEMS " ,
" LIFE BLOOD " ,
" LIFE " ,
" VENOM " ,
" YOU'RE LOSING YOUR GRIP " ,
" FULL LIFE " ,
" INVINCIBILITY " ,
" INVISIBILITY " ,
" TORCH " ,
" SOBEK MASK " ,
" INCREASED WEAPON POWER! " ,
" THE MAP! " ,
" AN EXTRA LIFE! " ,
" .357 MAGNUM! " ,
" GRENADE " ,
" M-60 " ,
" FLAME THROWER! " ,
" COBRA STAFF! " ,
" THE EYE OF RAH GAUNTLET! " ,
" SPEED LOADER " ,
" AMMO " ,
" FUEL " ,
" COBRA! " ,
" RAW ENERGY " ,
" POWER KEY " ,
" TIME KEY " ,
" WAR KEY " ,
" EARTH KEY " ,
" MAGIC " ,
" LOCATION PRESERVED " ,
" COPYRIGHT " ,
" LOBOTOMY SOFTWARE, INC. " ,
" 3D ENGINE BY 3D REALMS " ,
" " ,
" LASTLEVEL " ,
" INCOMING MESSAGE " ,
" " ,
" OUR LATEST SCANS SHOW " ,
" THAT THE ALIEN CRAFT IS " ,
" POWERING UP, APPARENTLY " ,
" IN AN EFFORT TO LEAVE. " ,
" THE BAD NEWS IS THAT THEY " ,
" SEEM TO HAVE LEFT A DEVICE " ,
" BEHIND, AND ALL EVIDENCE " ,
" SAYS ITS GOING TO BLOW A " ,
" BIG HOLE IN OUR FINE PLANET. " ,
" A SQUAD IS TRYING TO DISMANTLE " ,
" IT RIGHT NOW, BUT NO LUCK SO " ,
" FAR, AND TIME IS RUNNING OUT. " ,
" " ,
" GET ABOARD THAT CRAFT NOW " ,
" BEFORE IT LEAVES, THEN FIND " ,
" AND SHOOT ALL THE ENERGY " ,
" TOWERS TO GAIN ACCESS TO THE " ,
" CONTROL ROOM. THERE YOU NEED TO " ,
" TAKE OUT THE CONTROL PANELS AND " ,
" THE CENTRAL POWER SOURCE. THIS " ,
" IS THE BIG ONE BUDDY, BEST OF " ,
" LUCK... FOR ALL OF US. " ,
" " ,
" " ,
" CREDITS " ,
" EXHUMED " ,
" " ,
" EXECUTIVE PRODUCERS " ,
" " ,
" BRIAN MCNEELY " ,
" PAUL LANGE " ,
" " ,
" GAME CONCEPT " ,
" " ,
" PAUL LANGE " ,
" " ,
" GAME DESIGN " ,
" " ,
" BRIAN MCNEELY " ,
" " ,
" ADDITIONAL DESIGN " ,
" " ,
" PAUL KNUTZEN " ,
" PAUL LANGE " ,
" JOHN VAN DEUSEN " ,
" KURT PFEIFER " ,
" DOMINICK MEISSNER " ,
" DANE EMERSON " ,
" " ,
" GAME PROGRAMMING " ,
" " ,
" KURT PFEIFER " ,
" JOHN YUILL " ,
" " ,
" ADDITIONAL PROGRAMMING " ,
" " ,
" PAUL HAUGERUD " ,
" " ,
" ADDITIONAL TECHNICAL SUPPORT " ,
" " ,
" JOHN YUILL " ,
" PAUL HAUGERUD " ,
" JEFF BLAZIER " ,
" " ,
" LEVEL DESIGN " ,
" " ,
" PAUL KNUTZEN " ,
" " ,
" ADDITIONAL LEVELS " ,
" " ,
" BRIAN MCNEELY " ,
" " ,
" MONSTERS AND WEAPONS " ,
" " ,
" JOHN VAN DEUSEN " ,
" " ,
" ARTISTS " ,
" " ,
" BRIAN MCNEELY " ,
" PAUL KNUTZEN " ,
" JOHN VAN DEUSEN " ,
" TROY JACOBSON " ,
" KEVIN CHUNG " ,
" ERIC KLOKSTAD " ,
" RICHARD NICHOLS " ,
" JOE KRESOJA " ,
" JASON WIGGIN " ,
" " ,
" MUSIC AND SOUND EFFECTS " ,
" " ,
" SCOTT BRANSTON " ,
" " ,
" PRODUCT TESTING " ,
" " ,
" DOMINICK MEISSNER " ,
" TOM KRISTENSEN " ,
" JASON WIGGIN " ,
" MARK COATES " ,
" " ,
" INSTRUCTION MANUAL " ,
" " ,
" TOM KRISTENSEN " ,
" " ,
" SPECIAL THANKS " ,
" " ,
" JACQUI LYONS " ,
" MARJACQ MICRO, LTD. " ,
" MIKE BROWN " ,
" IAN MATHIAS " ,
" CHERYL LUSCHEI " ,
" 3D REALMS " ,
" KENNETH SILVERMAN " ,
" GREG MALONE " ,
" MILES DESIGN " ,
" REDMOND AM/PM MINI MART " ,
" 7-11 DOUBLE GULP " ,
" " ,
" THANKS FOR PLAYING " ,
" " ,
" THE END " ,
" " ,
" GUESS YOURE STUCK HERE " ,
" UNTIL THE SONG ENDS " ,
" " ,
" MAYBE THIS IS A GOOD " ,
" TIME TO THINK ABOUT ALL " ,
" THE THINGS YOU CAN DO " ,
" AFTER THE MUSIC IS OVER. " ,
" " ,
" OR YOU COULD JUST STARE " ,
" AT THIS SCREEN " ,
" " ,
" AND WATCH THESE MESSAGES " ,
" GO BY... " ,
" " ,
" ...AND WONDER JUST HOW LONG " ,
" WE WILL DRAG THIS OUT... " ,
" " ,
" AND BELIEVE ME, WE CAN DRAG " ,
" IT OUT FOR QUITE A WHILE. " ,
" " ,
" SHOULD BE OVER SOON... " ,
" " ,
" ANY MOMENT NOW... " ,
" " ,
" " ,
" " ,
" SEE YA " ,
" " ,
" END " ,
" PASSWORDS " ,
" HOLLY " ,
" KIMBERLY " ,
" LOBOCOP " ,
" LOBODEITY " ,
" LOBOLITE " ,
" LOBOPICK " ,
" LOBOSLIP " ,
" LOBOSNAKE " ,
" LOBOSPHERE " ,
" LOBOSWAG " ,
" LOBOXY " ,
" " ,
" PASSINFO " ,
" " ,
" HI SWEETIE, I LOVE YOU " ,
" " ,
" " ,
" FLASHES TOGGLED " ,
" " ,
" " ,
" " ,
2020-06-09 23:08:47 +00:00
" FULL MAP " ,
" " ,
2019-08-27 06:08:18 +00:00
" " ,
" " ,
" EOF " ,
" " ,
2019-08-26 03:59:14 +00:00
} ;
2019-10-31 17:22:12 +00:00
//////////
enum gametokens
{
T_INCLUDE = 0 ,
T_INTERFACE = 0 ,
T_LOADGRP = 1 ,
T_MODE = 1 ,
T_CACHESIZE = 2 ,
T_ALLOW = 2 ,
T_NOAUTOLOAD ,
T_INCLUDEDEFAULT ,
T_SOUND ,
T_FILE ,
T_CUTSCENE ,
T_ANIMSOUNDS ,
T_NOFLOORPALRANGE ,
T_ID ,
T_MINPITCH ,
T_MAXPITCH ,
T_PRIORITY ,
T_TYPE ,
T_DISTANCE ,
T_VOLUME ,
T_DELAY ,
T_RENAMEFILE ,
T_GLOBALGAMEFLAGS ,
T_ASPECT ,
T_FORCEFILTER ,
T_FORCENOFILTER ,
T_TEXTUREFILTER ,
T_NEWGAMECHOICES ,
T_CHOICE ,
T_NAME ,
T_LOCKED ,
T_HIDDEN ,
T_USERCONTENT ,
} ;
2020-04-04 04:31:27 +00:00
PlayerInput localInput ;
2019-10-31 17:22:12 +00:00
////////
2020-08-18 07:52:08 +00:00
void ResetEngine ( )
{
EraseScreen ( - 1 ) ;
resettiming ( ) ;
totalclock = 0 ;
ototalclock = totalclock ;
localclock = ( int ) totalclock ;
numframes = 0 ;
}
void InstallEngine ( )
{
// initgroupfile("stuff.dat");
TileFiles . LoadArtSet ( " tiles%03d.art " ) ;
// TEMP
//nScreenWidth *= 2;
//nScreenHeight *= 2;
2020-08-18 08:28:19 +00:00
bHiRes = true ;
2020-08-18 07:52:08 +00:00
// TEMP
if ( engineInit ( ) )
{
G_FatalEngineError ( ) ;
}
uploadCinemaPalettes ( ) ;
LoadPaletteLookups ( ) ;
videoInit ( ) ;
enginecompatibility_mode = ENGINECOMPATIBILITY_19950829 ;
}
void RemoveEngine ( )
{
engineUnInit ( ) ;
}
2019-11-24 15:34:23 +00:00
const uint32_t kSpiritX = 106 ;
const uint32_t kSpiritY = 97 ;
2019-08-26 03:59:14 +00:00
short cPupData [ 300 ] ;
//int worktile[97 * 106] = { 0 };
2019-11-24 15:34:23 +00:00
uint8_t * Worktile ;
const uint32_t WorktileSize = kSpiritX * 2 * kSpiritY * 2 ;
2019-08-26 03:59:14 +00:00
int lHeadStartClock ;
short * pPupData ;
int lNextStateChange ;
int nPixels ;
int nHeadTimeStart ;
short curx [ 97 * 106 ] ;
short cury [ 97 * 106 ] ;
2019-08-31 07:47:15 +00:00
int8_t destvelx [ 97 * 106 ] ;
int8_t destvely [ 97 * 106 ] ;
uint8_t pixelval [ 97 * 106 ] ;
int8_t origy [ 97 * 106 ] ;
int8_t origx [ 97 * 106 ] ;
int8_t velx [ 97 * 106 ] ;
int8_t vely [ 97 * 106 ] ;
2019-08-26 03:59:14 +00:00
short nMouthTile ;
short nPupData = 0 ;
short word_964E8 = 0 ;
short word_964EA = 0 ;
short word_964EC = 10 ;
short nSpiritRepeatX ;
short nSpiritRepeatY ;
short nPixelsToShow ;
void CopyTileToBitmap ( short nSrcTile , short nDestTile , int xPos , int yPos ) ;
void DoTitle ( ) ;
// void TestSaveLoad();
void EraseScreen ( int nVal ) ;
void LoadStatus ( ) ;
int FindGString ( const char * str ) ;
void MySetView ( int x1 , int y1 , int x2 , int y2 ) ;
void mysetbrightness ( char al ) ;
void FadeIn ( ) ;
char sHollyStr [ 40 ] ;
short nFontFirstChar ;
short nBackgroundPic ;
short nShadowPic ;
short nCreaturesLeft = 0 ;
short nFreeze ;
short bFullScreen ;
short nSnakeCam = - 1 ;
short nBestLevel ;
short nSpiritSprite ;
short nLocalSpr ;
short levelnew = 1 ;
int nNetPlayerCount = 0 ;
short nClockVal ;
short fps ;
short nRedTicks ;
short lastlevel ;
2019-08-31 11:44:02 +00:00
volatile short bInMove ;
2019-08-26 03:59:14 +00:00
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 nHeadStage ;
short nCfgNetPlayers = 0 ;
FILE * vcrfp = NULL ;
short nTalkTime = 0 ;
short forcelevel = - 1 ;
int lLocalButtons = 0 ;
int lLocalCodes = 0 ;
2020-08-18 08:28:19 +00:00
short bHiRes = false ;
short bCoordinates = false ;
2019-08-26 03:59:14 +00:00
int nNetTime = - 1 ;
short nCodeMin = 0 ;
short nCodeMax = 0 ;
short nCodeIndex = 0 ;
short levelnum = - 1 ;
2019-08-27 06:08:18 +00:00
//short nScreenWidth = 320;
//short nScreenHeight = 200;
2019-08-26 03:59:14 +00:00
int moveframes ;
int flash ;
int localclock ;
int totalmoves ;
short nCurBodyNum = 0 ;
short nBodyTotal = 0 ;
short textpages ;
short lastfps ;
2019-11-18 20:31:08 +00:00
short nMapMode = 0 ;
2020-08-18 08:28:19 +00:00
short bNoCreatures = false ;
2019-08-26 03:59:14 +00:00
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 ;
short screensize ;
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 ;
short bHolly = false ;
2019-08-26 03:59:14 +00:00
short nItemTextIndex ;
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
short wConsoleNode ; // TODO - move me into network file
2019-11-14 16:08:50 +00:00
ClockTicks tclocks , tclocks2 ;
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-31 07:47:15 +00:00
void timerhandler ( )
{
2019-12-27 19:05:58 +00:00
UpdateSounds ( ) ;
2019-08-27 06:08:18 +00:00
scan_char + + ;
if ( scan_char = = kTimerTicks )
{
scan_char = 0 ;
lastfps = fps ;
fps = 0 ;
}
2019-11-28 20:40:17 +00:00
if ( ! bInMove ) {
2020-07-14 12:00:27 +00:00
C_RunDelayedCommands ( ) ;
2019-11-28 20:40:17 +00:00
}
2019-08-26 03:59:14 +00:00
}
2020-03-01 15:32:41 +00:00
extern int MenuExitCondition ;
2019-08-31 15:04:06 +00:00
void HandleAsync ( )
{
2020-03-01 15:32:41 +00:00
MenuExitCondition = - 2 ;
2019-08-31 15:04:06 +00:00
handleevents ( ) ;
2020-03-01 15:32:41 +00:00
2019-08-31 15:04:06 +00:00
}
2019-08-26 03:59:14 +00:00
int MyGetStringWidth ( const char * str )
{
2019-08-27 06:08:18 +00:00
int nLen = strlen ( str ) ;
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
int nWidth = 0 ;
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
for ( int i = 0 ; i < nLen ; i + + )
{
int nPic = seq_GetSeqPicnum ( kSeqFont2 , 0 , str [ i ] - 32 ) ;
nWidth + = tilesiz [ nPic ] . x + 1 ;
}
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
return nWidth ;
2019-08-26 03:59:14 +00:00
}
void UpdateScreenSize ( )
{
2019-10-29 14:17:15 +00:00
int xsize = xdim - scale ( screensize * 16 , xdim , 320 ) ;
int ysize = scale ( ydim , xsize , xdim ) ;
int y1 = ( ( ydim > > 1 ) - ( ysize > > 1 ) ) ;
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
MySetView (
2019-10-29 14:17:15 +00:00
( xdim > > 1 ) - ( xsize > > 1 ) ,
2019-08-27 06:08:18 +00:00
y1 ,
2019-10-29 14:17:15 +00:00
( xdim > > 1 ) - ( xsize > > 1 ) + xsize - 1 ,
( y1 + ysize - 1 ) ) ;
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
RefreshStatus ( ) ;
2019-08-26 03:59:14 +00:00
}
void ResetPassword ( )
{
2019-08-27 06:08:18 +00:00
nCodeMin = nFirstPassword ;
nCodeIndex = 0 ;
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
nCodeMax = ( nFirstPassword + nPasswordCount ) - 1 ;
2019-08-26 03:59:14 +00:00
}
void DoPassword ( int nPassword )
{
2019-08-27 06:08:18 +00:00
if ( nNetPlayerCount ) {
return ;
}
const char * str = gString [ nFirstPassInfo + nPassword ] ;
if ( str [ 0 ] ! = ' \0 ' ) {
StatusMessage ( 750 , str ) ;
}
switch ( nPassword )
{
case 0 :
{
if ( ! nNetPlayerCount ) {
2020-08-18 08:28:19 +00:00
bHolly = true ;
2019-08-27 06:08:18 +00:00
}
break ;
}
2020-06-09 23:08:47 +00:00
case 1 : // KIMBERLY
{
break ;
}
2019-08-27 06:08:18 +00:00
case 2 : // LOBOCOP
{
2020-01-06 21:03:16 +00:00
lLocalCodes | = kButtonCheatGuns ;
2019-08-27 06:08:18 +00:00
break ;
}
case 3 : // LOBODEITY
{
2020-01-06 21:03:16 +00:00
lLocalCodes | = kButtonCheatGodMode ;
2019-08-27 06:08:18 +00:00
break ;
}
2020-06-09 23:08:47 +00:00
case 4 : // LOBOLITE
2019-08-27 06:08:18 +00:00
{
2020-08-18 08:28:19 +00:00
if ( bDoFlashes = = false )
2020-06-09 23:08:47 +00:00
{
2020-08-18 08:28:19 +00:00
bDoFlashes = true ;
2019-08-27 06:08:18 +00:00
}
else {
2020-08-18 08:28:19 +00:00
bDoFlashes = false ;
2019-08-27 06:08:18 +00:00
}
break ;
}
2020-06-09 23:08:47 +00:00
case 5 : // LOBOPICK
2019-08-27 06:08:18 +00:00
{
2020-01-06 21:03:16 +00:00
lLocalCodes | = kButtonCheatKeys ;
2019-08-27 06:08:18 +00:00
break ;
}
2020-06-09 23:08:47 +00:00
case 6 : // LOBOSLIP
2019-08-27 06:08:18 +00:00
{
if ( ! nNetPlayerCount )
{
2020-08-18 08:28:19 +00:00
if ( bSlipMode = = false )
2019-08-27 06:08:18 +00:00
{
2020-08-18 08:28:19 +00:00
bSlipMode = true ;
2020-06-09 23:08:47 +00:00
StatusMessage ( 300 , " Slip mode ON " ) ;
2019-08-27 06:08:18 +00:00
}
else {
2020-08-18 08:28:19 +00:00
bSlipMode = false ;
2020-06-09 23:08:47 +00:00
StatusMessage ( 300 , " Slip mode OFF " ) ;
2019-08-27 06:08:18 +00:00
}
}
break ;
}
2020-06-09 23:08:47 +00:00
case 7 : // LOBOSNAKE
2019-08-27 06:08:18 +00:00
{
if ( ! nNetPlayerCount )
{
2020-08-18 08:28:19 +00:00
if ( bSnakeCam = = false )
2020-06-09 23:08:47 +00:00
{
2020-08-18 08:28:19 +00:00
bSnakeCam = true ;
2020-06-09 23:08:47 +00:00
StatusMessage ( 750 , " SNAKE CAM ENABLED " ) ;
2019-08-27 06:08:18 +00:00
}
2020-06-09 23:08:47 +00:00
else
{
2020-08-18 08:28:19 +00:00
bSnakeCam = false ;
2020-06-09 23:08:47 +00:00
StatusMessage ( 750 , " SNAKE CAM DISABLED " ) ;
2019-08-27 06:08:18 +00:00
}
}
break ;
}
2020-06-09 23:08:47 +00:00
case 8 : // LOBOSPHERE
2019-08-27 06:08:18 +00:00
{
GrabMap ( ) ;
2020-08-18 08:28:19 +00:00
bShowTowers = true ;
2019-08-27 06:08:18 +00:00
break ;
}
2020-06-09 23:08:47 +00:00
case 9 : // LOBOSWAG
2019-08-27 06:08:18 +00:00
{
2020-06-09 23:08:47 +00:00
lLocalCodes | = kButtonCheatItems ;
2019-08-27 06:08:18 +00:00
break ;
}
2020-06-09 23:08:47 +00:00
case 10 : // LOBOXY
2019-08-27 06:08:18 +00:00
{
2020-08-18 08:28:19 +00:00
if ( bCoordinates = = false ) {
bCoordinates = true ;
2019-08-27 06:08:18 +00:00
}
else {
2020-08-18 08:28:19 +00:00
bCoordinates = false ;
2019-08-27 06:08:18 +00:00
}
break ;
}
default :
return ;
}
2019-08-26 03:59:14 +00:00
}
void mysetbrightness ( char nBrightness )
{
2019-08-27 06:08:18 +00:00
g_visibility = 2048 - ( nBrightness < < 9 ) ;
2019-08-26 03:59:14 +00:00
}
2020-01-05 19:20:33 +00:00
// Replicate original DOS EXE behaviour when pointer is null
static const char * safeStrtok ( char * s , const char * d )
{
const char * r = strtok ( s , d ) ;
return r ? r : " " ;
}
2020-01-22 15:14:01 +00:00
void CheckKeys ( )
{
if ( buttonMap . ButtonDown ( gamefunc_Enlarge_Screen ) )
{
2019-11-24 09:03:19 +00:00
buttonMap . ClearButton ( gamefunc_Enlarge_Screen ) ;
2020-08-19 18:38:36 +00:00
if ( ! nMapMode ) G_ChangeHudLayout ( 1 ) ;
2019-08-27 06:08:18 +00:00
}
2019-11-24 09:03:19 +00:00
if ( buttonMap . ButtonDown ( gamefunc_Shrink_Screen ) )
2019-08-27 06:08:18 +00:00
{
2019-11-24 09:03:19 +00:00
buttonMap . ClearButton ( gamefunc_Shrink_Screen ) ;
2020-08-19 18:38:36 +00:00
if ( ! nMapMode ) G_ChangeHudLayout ( - 1 ) ;
2019-08-27 06:08:18 +00:00
}
// go to 3rd person view?
2019-11-24 09:03:19 +00:00
if ( buttonMap . ButtonDown ( gamefunc_Third_Person_View ) )
2019-08-27 06:08:18 +00:00
{
if ( ! nFreeze )
{
if ( bCamera ) {
2020-08-18 08:28:19 +00:00
bCamera = false ;
2019-08-27 06:08:18 +00:00
}
else {
2020-08-18 08:28:19 +00:00
bCamera = true ;
2019-08-27 06:08:18 +00:00
}
if ( bCamera )
GrabPalette ( ) ;
}
2019-11-24 09:03:19 +00:00
buttonMap . ClearButton ( gamefunc_Third_Person_View ) ;
return ;
2019-08-27 06:08:18 +00:00
}
2020-05-29 01:15:01 +00:00
if ( paused )
2019-08-27 06:08:18 +00:00
{
return ;
}
// Handle cheat codes
2019-11-24 09:03:19 +00:00
if ( ! bInDemo & & inputState . keyBufferWaiting ( ) )
2019-08-27 06:08:18 +00:00
{
2019-11-24 09:03:19 +00:00
char ch = inputState . keyGetChar ( ) ;
2019-08-27 06:08:18 +00:00
if ( bHolly )
{
if ( ch )
{
2019-12-02 16:34:59 +00:00
size_t nStringLen = strlen ( sHollyStr ) ;
2019-08-27 06:08:18 +00:00
if ( ch = = asc_Enter )
{
2020-01-05 19:20:33 +00:00
const char * pToken = safeStrtok ( sHollyStr , " " ) ;
2019-08-27 06:08:18 +00:00
2020-01-05 19:20:33 +00:00
if ( ! strcmp ( pToken , " GOTO " ) )
2019-10-28 19:14:54 +00:00
{
// move player to X, Y coordinates
2019-08-27 06:08:18 +00:00
int nSprite = PlayerList [ 0 ] . nSprite ;
2020-01-05 19:20:33 +00:00
pToken = safeStrtok ( NULL , " , " ) ;
2019-08-27 06:08:18 +00:00
sprite [ nSprite ] . x = atoi ( pToken ) ;
2020-01-05 19:20:33 +00:00
pToken = safeStrtok ( NULL , " , " ) ;
2019-08-27 06:08:18 +00:00
sprite [ nSprite ] . y = atoi ( pToken ) ;
setsprite ( nSprite , & sprite [ nSprite ] . pos ) ;
sprite [ nSprite ] . z = sector [ sprite [ nSprite ] . sectnum ] . floorz ;
}
else if ( ! strcmp ( pToken , " LEVEL " ) )
{
2020-01-05 19:20:33 +00:00
pToken = safeStrtok ( NULL , " " ) ;
levelnew = atoi ( pToken ) ;
2019-08-27 06:08:18 +00:00
}
else if ( ! strcmp ( pToken , " DOORS " ) )
{
for ( int i = 0 ; i < kMaxChannels ; i + + )
{
// CHECKME - does this toggle?
if ( sRunChannels [ i ] . c = = 0 ) {
runlist_ChangeChannel ( i , 1 ) ;
}
else {
runlist_ChangeChannel ( i , 0 ) ;
}
}
}
else if ( ! strcmp ( pToken , " EXIT " ) )
{
FinishLevel ( ) ;
}
else if ( ! strcmp ( pToken , " CREATURE " ) )
{
// i = nNetPlayerCount;
if ( ! nNetPlayerCount )
{
2020-01-05 19:20:33 +00:00
pToken = safeStrtok ( NULL , " " ) ;
2019-08-27 06:08:18 +00:00
switch ( atoi ( pToken ) )
{
// TODO - enums?
case 0 :
2020-08-18 08:28:19 +00:00
BuildAnubis ( - 1 , initx , inity , sector [ initsect ] . floorz , initsect , inita , false ) ;
2019-08-27 06:08:18 +00:00
break ;
case 1 :
BuildSpider ( - 1 , initx , inity , sector [ initsect ] . floorz , initsect , inita ) ;
break ;
case 2 :
BuildMummy ( - 1 , initx , inity , sector [ initsect ] . floorz , initsect , inita ) ;
break ;
case 3 :
BuildFish ( - 1 , initx , inity , initz + eyelevel [ nLocalPlayer ] , initsect , inita ) ;
break ;
case 4 :
BuildLion ( - 1 , initx , inity , sector [ initsect ] . floorz , initsect , inita ) ;
break ;
case 5 :
BuildLava ( - 1 , initx , inity , sector [ initsect ] . floorz , initsect , inita , nNetPlayerCount ) ;
break ;
case 6 :
BuildRex ( - 1 , initx , inity , sector [ initsect ] . floorz , initsect , inita , nNetPlayerCount ) ;
break ;
case 7 :
BuildSet ( - 1 , initx , inity , sector [ initsect ] . floorz , initsect , inita , nNetPlayerCount ) ;
break ;
case 8 :
BuildQueen ( - 1 , initx , inity , sector [ initsect ] . floorz , initsect , inita , nNetPlayerCount ) ;
break ;
case 9 :
BuildRoach ( 0 , - 1 , initx , inity , sector [ initsect ] . floorz , initsect , inita ) ;
break ;
case 10 :
BuildRoach ( 1 , - 1 , initx , inity , sector [ initsect ] . floorz , initsect , inita ) ;
break ;
case 11 :
BuildWasp ( - 1 , initx , inity , sector [ initsect ] . floorz - 25600 , initsect , inita ) ;
break ;
case 12 :
BuildScorp ( - 1 , initx , inity , sector [ initsect ] . floorz , initsect , inita , nNetPlayerCount ) ;
break ;
case 13 :
BuildRat ( - 1 , initx , inity , sector [ initsect ] . floorz , initsect , inita ) ;
break ;
default :
break ;
}
}
}
else
{
if ( nStringLen = = 0 )
{
2020-08-18 08:28:19 +00:00
bHolly = false ;
2019-08-27 06:08:18 +00:00
StatusMessage ( 1 , " " ) ;
}
else
{
for ( int i = 0 ; i < nPasswordCount ; + + i )
{
if ( ! strcmp ( sHollyStr , gString [ i + nFirstPassword ] ) )
{
DoPassword ( i ) ;
break ;
}
}
}
}
sHollyStr [ 0 ] = ' \0 ' ;
}
else if ( ch = = asc_BackSpace )
{
if ( nStringLen ! = 0 ) {
sHollyStr [ nStringLen - 1 ] = ' \0 ' ;
}
}
else if ( nStringLen < ( sizeof ( sHollyStr ) - 1 ) ) // do we have room to add a char and null terminator?
{
sHollyStr [ nStringLen ] = toupper ( ch ) ;
sHollyStr [ nStringLen + 1 ] = ' \0 ' ;
}
}
else
{
2019-11-24 09:03:19 +00:00
inputState . keyGetChar ( ) ; //???
2019-08-27 06:08:18 +00:00
}
}
if ( isalpha ( ch ) )
{
ch = toupper ( ch ) ;
int ecx = nCodeMin ;
int ebx = nCodeMin ;
int edx = nCodeMin - 1 ;
while ( ebx < = nCodeMax )
{
if ( ch = = gString [ ecx ] [ nCodeIndex ] )
{
nCodeMin = ebx ;
nCodeIndex + + ;
if ( gString [ ecx ] [ nCodeIndex ] = = 0 )
{
ebx - = nFirstPassword ;
DoPassword ( ebx ) ;
ResetPassword ( ) ;
}
break ;
}
else if ( gString [ ecx ] [ nCodeIndex ] < ch )
{
nCodeMin = ebx + 1 ;
}
else if ( gString [ ecx ] [ nCodeIndex ] > ch )
{
nCodeMax = edx ;
}
ecx + + ;
edx + + ;
ebx + + ;
}
if ( nCodeMin > nCodeMax ) {
ResetPassword ( ) ;
}
}
}
2019-08-26 03:59:14 +00:00
}
void DoCredits ( )
{
2019-08-27 06:08:18 +00:00
NoClip ( ) ;
2019-08-26 03:59:14 +00:00
2019-11-28 20:40:17 +00:00
playCDtrack ( 19 , false ) ;
2019-08-26 03:59:14 +00:00
2020-03-10 00:38:33 +00:00
int nSecretSkipKeyCount = 0 ;
2019-08-26 03:59:14 +00:00
2019-11-26 14:44:01 +00:00
if ( videoGetRenderMode ( ) = = REND_CLASSIC )
2019-08-27 06:08:18 +00:00
FadeOut ( 0 ) ;
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
int nCreditsIndex = FindGString ( " CREDITS " ) ;
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
while ( strcmp ( gString [ nCreditsIndex ] , " END " ) ! = 0 )
{
EraseScreen ( overscanindex ) ;
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
int nStart = nCreditsIndex ;
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
// skip blanks
while ( strlen ( gString [ nCreditsIndex ] ) ! = 0 ) {
nCreditsIndex + + ;
}
2019-08-26 03:59:14 +00:00
2019-11-26 14:44:01 +00:00
int y = 100 - ( ( 10 * ( nCreditsIndex - nStart - 1 ) ) / 2 ) ;
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
for ( int i = nStart ; i < nCreditsIndex ; i + + )
{
2019-11-26 14:44:01 +00:00
int nWidth = MyGetStringWidth ( gString [ i ] ) ;
myprintext ( ( 320 - nWidth ) / 2 , y , gString [ i ] , 0 ) ;
2019-08-27 06:08:18 +00:00
y + = 10 ;
}
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
videoNextPage ( ) ;
2019-11-26 14:44:01 +00:00
nCreditsIndex + + ;
if ( videoGetRenderMode ( ) = = REND_CLASSIC )
2019-08-27 06:08:18 +00:00
FadeIn ( ) ;
2019-08-26 03:59:14 +00:00
2019-11-26 14:44:01 +00:00
int nDuration = ( int ) totalclock + 600 ;
while ( ( int ) totalclock < = nDuration )
2019-08-27 06:08:18 +00:00
{
2020-03-10 00:38:33 +00:00
HandleAsync ( ) ;
2019-11-24 09:03:19 +00:00
if ( inputState . GetKeyStatus ( sc_F12 ) )
2019-08-27 06:08:18 +00:00
{
2020-03-10 00:38:33 +00:00
nSecretSkipKeyCount + + ;
2019-08-26 03:59:14 +00:00
2019-11-24 09:03:19 +00:00
inputState . ClearKeyStatus ( sc_F12 ) ;
2019-08-26 03:59:14 +00:00
2020-03-10 00:38:33 +00:00
if ( nSecretSkipKeyCount > 5 ) {
2019-08-27 06:08:18 +00:00
return ;
}
}
}
2019-08-26 03:59:14 +00:00
2019-11-26 14:44:01 +00:00
if ( videoGetRenderMode ( ) = = REND_CLASSIC )
2019-08-27 06:08:18 +00:00
FadeOut ( 0 ) ;
}
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
while ( CDplaying ( ) )
{
2020-03-10 00:38:33 +00:00
HandleAsync ( ) ;
2019-11-24 09:03:19 +00:00
inputState . keyGetChar ( ) ;
2019-08-27 06:08:18 +00:00
}
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
Clip ( ) ;
2019-08-26 03:59:14 +00:00
}
void FinishLevel ( )
{
2019-08-27 06:08:18 +00:00
if ( levelnum > nBestLevel ) {
nBestLevel = levelnum - 1 ;
}
levelnew = levelnum + 1 ;
StopAllSounds ( ) ;
2020-08-18 08:28:19 +00:00
bCamera = false ;
2019-11-18 20:31:08 +00:00
nMapMode = 0 ;
2019-08-27 06:08:18 +00:00
if ( levelnum ! = kMap20 )
{
EraseScreen ( 4 ) ;
2020-02-23 19:40:45 +00:00
PlayLocalSound ( StaticSound [ 59 ] , 0 , true , CHANF_UI ) ;
2019-08-27 06:08:18 +00:00
videoNextPage ( ) ;
WaitTicks ( 12 ) ;
WaitVBL ( ) ;
RefreshBackground ( ) ;
RefreshStatus ( ) ;
2019-11-03 17:20:05 +00:00
DrawView ( 65536 ) ;
2019-08-26 03:59:14 +00:00
videoNextPage ( ) ;
2019-08-27 06:08:18 +00:00
}
FadeOut ( 1 ) ;
EraseScreen ( overscanindex ) ;
if ( levelnum = = 0 )
{
nPlayerLives [ 0 ] = 0 ;
levelnew = 100 ;
}
else
{
DoAfterCinemaScene ( levelnum ) ;
if ( levelnum = = kMap20 )
{
DoCredits ( ) ;
nPlayerLives [ 0 ] = 0 ;
}
}
2019-08-26 03:59:14 +00:00
}
2019-12-02 19:28:02 +00:00
EDUKE32_STATIC_ASSERT ( sizeof ( demo_header ) = = 75 ) ;
EDUKE32_STATIC_ASSERT ( sizeof ( demo_input ) = = 36 ) ;
2019-08-26 03:59:14 +00:00
void WritePlaybackInputs ( )
{
2019-08-27 06:08:18 +00:00
fwrite ( & moveframes , sizeof ( moveframes ) , 1 , vcrfp ) ;
fwrite ( & sPlayerInput [ nLocalPlayer ] , sizeof ( PlayerInput ) , 1 , vcrfp ) ;
2019-08-26 03:59:14 +00:00
}
2019-08-31 07:47:15 +00:00
uint8_t ReadPlaybackInputs ( )
2019-08-26 03:59:14 +00:00
{
2019-12-02 19:28:02 +00:00
demo_input input ;
if ( fread ( & input , 1 , sizeof ( input ) , vcrfp ) )
2019-08-27 06:08:18 +00:00
{
2019-12-02 19:28:02 +00:00
moveframes = input . moveframes ;
sPlayerInput [ nLocalPlayer ] . xVel = input . xVel ;
sPlayerInput [ nLocalPlayer ] . yVel = input . yVel ;
sPlayerInput [ nLocalPlayer ] . nAngle = fix16_from_int ( input . nAngle < < 2 ) ;
sPlayerInput [ nLocalPlayer ] . buttons = input . buttons ;
sPlayerInput [ nLocalPlayer ] . nTarget = input . nTarget ;
sPlayerInput [ nLocalPlayer ] . horizon = fix16_from_int ( input . horizon ) ;
sPlayerInput [ nLocalPlayer ] . nItem = input . nItem ;
sPlayerInput [ nLocalPlayer ] . h = input . h ;
sPlayerInput [ nLocalPlayer ] . i = input . i ;
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
besttarget = sPlayerInput [ nLocalPlayer ] . nTarget ;
Ra [ nLocalPlayer ] . nTarget = besttarget ;
2020-08-18 08:28:19 +00:00
return true ;
2019-08-27 06:08:18 +00:00
}
else
{
fclose ( vcrfp ) ;
vcrfp = NULL ;
2020-08-18 08:28:19 +00:00
bPlayback = false ;
return false ;
2019-08-27 06:08:18 +00:00
}
2019-08-26 03:59:14 +00:00
}
void SetHiRes ( )
{
2019-08-27 06:08:18 +00:00
//nScreenWidth = 640;
//nScreenHeight = 400;
2020-08-18 08:28:19 +00:00
bHiRes = true ;
2019-08-26 03:59:14 +00:00
}
void DoClockBeep ( )
{
2019-08-27 06:08:18 +00:00
for ( int i = headspritestat [ 407 ] ; i ! = - 1 ; i = nextspritestat [ i ] ) {
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 ;
}
for ( int i = headspritestat [ 405 ] ; i ! = - 1 ; i = nextspritestat [ i ] )
{
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 LockEnergyTiles ( )
{
2019-08-27 06:08:18 +00:00
// old loadtilelockmode = 1;
tileLoad ( kTile3603 ) ;
2019-08-26 03:59:14 +00:00
tileLoad ( kEnergy1 ) ;
tileLoad ( kEnergy2 ) ;
2019-08-27 06:08:18 +00:00
// old loadtilelockmode = 0;
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
}
2019-08-31 09:08:38 +00:00
void M32RunScript ( const char * s ) { UNREFERENCED_PARAMETER ( s ) ; }
void app_crashhandler ( void )
{
ShutDown ( ) ;
}
void G_Polymer_UnInit ( void ) { }
2019-11-03 17:20:05 +00:00
static inline int32_t calc_smoothratio ( ClockTicks totalclk , ClockTicks ototalclk )
{
2020-05-29 01:15:01 +00:00
if ( bRecord | | bPlayback | | nFreeze ! = 0 | | bCamera | | paused )
2019-11-03 17:20:05 +00:00
return 65536 ;
2020-02-02 09:27:47 +00:00
return CalcSmoothRatio ( totalclk , ototalclk , 30 ) ;
2019-11-03 17:20:05 +00:00
}
2019-11-15 06:48:40 +00:00
# define LOW_FPS ((videoGetRenderMode() == REND_CLASSIC) ? 35 : 50)
# define SLOW_FRAME_TIME 20
# if defined GEKKO
# define FPS_YOFFSET 16
# else
# define FPS_YOFFSET 0
# endif
2019-12-25 23:21:04 +00:00
FString GameInterface : : statFPS ( )
2019-11-15 06:48:40 +00:00
{
2019-12-25 23:21:04 +00:00
FString out ;
2019-11-15 06:48:40 +00:00
static int32_t frameCount ;
static double cumulativeFrameDelay ;
static double lastFrameTime ;
2019-12-02 16:34:59 +00:00
static float lastFPS ; // , minFPS = std::numeric_limits<float>::max(), maxFPS;
//static double minGameUpdate = std::numeric_limits<double>::max(), maxGameUpdate;
2019-11-15 06:48:40 +00:00
double frameTime = timerGetHiTicks ( ) ;
double frameDelay = frameTime - lastFrameTime ;
cumulativeFrameDelay + = frameDelay ;
if ( frameDelay > = 0 )
{
2019-12-25 23:21:04 +00:00
out . Format ( " %.1f ms, %5.1f fps " , frameDelay , lastFPS ) ;
2019-11-15 06:48:40 +00:00
if ( cumulativeFrameDelay > = 1000.0 )
{
lastFPS = 1000.f * frameCount / cumulativeFrameDelay ;
// g_frameRate = Blrintf(lastFPS);
frameCount = 0 ;
cumulativeFrameDelay = 0.0 ;
}
frameCount + + ;
}
lastFrameTime = frameTime ;
2019-12-25 23:21:04 +00:00
return out ;
2019-11-15 06:48:40 +00:00
}
2019-11-03 17:20:05 +00:00
static void GameDisplay ( void )
{
// End Section B
SetView1 ( ) ;
if ( levelnum = = kMap20 )
{
LockEnergyTiles ( ) ;
DoEnergyTile ( ) ;
DrawClock ( ) ;
}
auto smoothRatio = calc_smoothratio ( totalclock , tclocks ) ;
DrawView ( smoothRatio ) ;
2020-05-29 01:15:01 +00:00
if ( paused & & ! M_Active ( ) )
2019-11-14 16:08:50 +00:00
{
int nLen = MyGetStringWidth ( " PAUSED " ) ;
myprintext ( ( 320 - nLen ) / 2 , 100 , " PAUSED " , 0 ) ;
}
2019-11-03 17:20:05 +00:00
videoNextPage ( ) ;
}
static void GameMove ( void )
{
FixPalette ( ) ;
if ( levelnum = = kMap20 )
{
if ( lCountDown < = 0 )
{
for ( int i = 0 ; i < nTotalPlayers ; i + + ) {
nPlayerLives [ i ] = 0 ;
}
DoFailedFinalScene ( ) ;
levelnew = 100 ;
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 + + ;
moveframes - - ;
}
2019-11-13 19:15:07 +00:00
# if defined(_WIN32) && defined(DEBUGGINGAIDS)
// See FILENAME_CASE_CHECK in cache1d.c
static int32_t check_filename_casing ( void )
{
return 1 ;
}
# endif
2019-11-03 17:20:05 +00:00
int32_t r_maxfpsoffset = 0 ;
2019-12-14 00:33:26 +00:00
void PatchDemoStrings ( )
{
if ( ! ISDEMOVER )
return ;
if ( EXHUMED ) {
gString [ 60 ] = " PICK UP A COPY OF EXHUMED " ;
}
else {
gString [ 60 ] = " PICK UP A COPY OF POWERSLAVE " ;
}
gString [ 61 ] = " TODAY TO CONTINUE THE ADVENTURE! " ;
gString [ 62 ] = " MORE LEVELS, NASTIER CREATURES " ;
gString [ 63 ] = " AND THE EVIL DOINGS OF THE " ;
gString [ 64 ] = " KILMAAT AWAIT YOU IN THE FULL " ;
gString [ 65 ] = " VERSION OF THE GAME. " ;
gString [ 66 ] = " TWENTY LEVELS, PLUS 12 NETWORK " ;
gString [ 67 ] = " PLAY LEVELS CAN BE YOURS! " ;
gString [ 68 ] = " END " ;
}
void ExitGame ( )
{
if ( bRecord ) {
fclose ( vcrfp ) ;
}
ShutDown ( ) ;
2020-04-11 21:50:43 +00:00
throw CExitEvent ( 0 ) ;
2019-12-14 00:33:26 +00:00
}
2019-11-18 20:31:08 +00:00
static int32_t nonsharedtimer ;
2019-11-24 12:59:36 +00:00
void CheckCommandLine ( int argc , char const * const * argv , int & doTitle )
2019-08-26 03:59:14 +00:00
{
2019-11-24 12:59:36 +00:00
// Check for any command line arguments
for ( int i = 1 ; i < argc ; i + + )
{
const char * pChar = argv [ i ] ;
2019-08-31 09:08:38 +00:00
2019-11-24 12:59:36 +00:00
if ( * pChar = = ' / ' )
{
pChar + + ;
//strlwr(pChar);
2019-08-31 09:08:38 +00:00
2019-11-24 12:59:36 +00:00
if ( Bstrcasecmp ( pChar , " nocreatures " ) = = 0 ) {
2020-08-18 08:28:19 +00:00
bNoCreatures = true ;
2019-08-27 06:08:18 +00:00
}
2019-08-31 09:08:38 +00:00
else if ( Bstrcasecmp ( pChar , " record " ) = = 0 )
2019-08-27 06:08:18 +00:00
{
if ( ! bPlayback )
{
vcrfp = fopen ( " data.vcr " , " wb+ " ) ;
if ( vcrfp ! = NULL ) {
2020-08-18 08:28:19 +00:00
bRecord = true ;
2019-08-27 06:08:18 +00:00
}
else {
DebugOut ( " Can't open data file for recording \n " ) ;
}
}
}
2019-08-31 09:08:38 +00:00
else if ( Bstrcasecmp ( pChar , " playback " ) = = 0 )
2019-08-27 06:08:18 +00:00
{
if ( ! bRecord )
{
vcrfp = fopen ( " data.vcr " , " rb " ) ;
if ( vcrfp ! = NULL ) {
2020-08-18 08:28:19 +00:00
bPlayback = true ;
doTitle = false ;
2019-08-27 06:08:18 +00:00
}
else {
DebugOut ( " Can't open data file 'data.vcr' for reading \n " ) ;
}
}
}
2019-08-31 09:08:38 +00:00
else if ( Bstrcasecmp ( pChar , " network " ) = = 0 )
2019-08-27 06:08:18 +00:00
{
nNetPlayerCount = - 1 ;
forcelevel = levelnew ;
2020-08-18 08:28:19 +00:00
bModemPlay = false ;
2019-08-27 06:08:18 +00:00
2020-08-18 08:28:19 +00:00
doTitle = false ;
2019-08-27 06:08:18 +00:00
}
else
{
char c = tolower ( * pChar ) ;
switch ( c )
{
case ' h ' :
SetHiRes ( ) ;
break ;
2019-11-13 21:34:11 +00:00
#if 0
2019-08-27 06:08:18 +00:00
case ' s ' :
socket = atoi ( pChar + 1 ) ;
break ;
2019-11-13 21:34:11 +00:00
# endif
2019-08-27 06:08:18 +00:00
case ' t ' :
nNetTime = atoi ( pChar + 1 ) ;
if ( nNetTime < 0 ) {
nNetTime = 0 ;
}
else {
nNetTime = nNetTime * 1800 ;
}
break ;
case ' c ' :
{
2019-11-14 10:27:34 +00:00
break ;
2019-08-27 06:08:18 +00:00
}
default :
{
if ( isdigit ( c ) )
{
levelnew = atoi ( pChar ) ;
forcelevel = levelnew ;
2020-08-18 08:28:19 +00:00
doTitle = false ;
2019-08-27 06:08:18 +00:00
2020-04-11 21:45:45 +00:00
Printf ( " Jumping to level %d... \n " , levelnew ) ;
2019-08-27 06:08:18 +00:00
}
break ;
}
}
}
}
}
2019-11-24 12:59:36 +00:00
}
2020-04-11 22:10:39 +00:00
static const char * actions [ ] =
{
" Move_Forward " ,
" Move_Backward " ,
" Turn_Left " ,
" Turn_Right " ,
" Strafe " ,
" Fire " ,
" Open " ,
" Run " ,
" Alt_Fire " , // Duke3D", Blood
" Jump " ,
" Crouch " ,
" Look_Up " ,
" Look_Down " ,
" Look_Left " ,
" Look_Right " ,
" Strafe_Left " ,
" Strafe_Right " ,
" Aim_Up " ,
" Aim_Down " ,
" Weapon_1 " ,
" Weapon_2 " ,
" Weapon_3 " ,
" Weapon_4 " ,
" Weapon_5 " ,
" Weapon_6 " ,
" Weapon_7 " ,
" Weapon_8 " ,
" Weapon_9 " ,
" Weapon_10 " ,
" Inventory " ,
" Inventory_Left " ,
" Inventory_Right " ,
" TurnAround " ,
" SendMessage " ,
" Map " ,
" Shrink_Screen " ,
" Enlarge_Screen " ,
" Center_View " ,
" Holster_Weapon " ,
" Show_Opponents_Weapon " ,
" Map_Follow_Mode " ,
" See_Coop_View " ,
" Mouse_Aiming " ,
" Toggle_Crosshair " ,
" Next_Weapon " ,
" Previous_Weapon " ,
" Dpad_Select " ,
" Dpad_Aiming " ,
" Last_Weapon " ,
" Alt_Weapon " ,
" Third_Person_View " ,
" Toggle_Crouch " , // This is the last one used by EDuke32.
" Zoom_In " , // Map controls should not pollute the global button namespace.
" Zoom_Out " ,
} ;
2019-12-27 19:05:58 +00:00
2020-08-18 07:52:08 +00:00
void InitTimer ( )
{
htimer = 1 ;
timerInit ( kTimerTicks ) ;
timerSetCallback ( timerhandler ) ;
}
2019-12-12 23:19:34 +00:00
int GameInterface : : app_main ( )
2019-11-24 12:59:36 +00:00
{
int i ;
//int esi = 1;
//int edi = esi;
2020-08-18 08:28:19 +00:00
int doTitle = true ; // REVERT true;
int stopTitle = false ;
2019-11-24 12:59:36 +00:00
levelnew = 1 ;
2020-04-11 22:10:39 +00:00
buttonMap . SetButtons ( actions , NUM_ACTIONS ) ;
2020-02-29 11:55:12 +00:00
help_disabled = true ;
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 + + )
{
auto mi = & mapList [ i ] ;
mi - > fileName . Format ( " LEV%d.MAP " , i ) ;
mi - > labelName . Format ( " LEV%d " , i ) ;
mi - > name . Format ( " $TXT_EX_MAP%02d " , i ) ;
int nTrack = i ;
if ( nTrack ! = 0 ) nTrack - - ;
mi - > cdSongId = ( nTrack % 8 ) + 11 ;
}
2020-08-18 08:28:19 +00:00
// REVERT - change back to true
// short bDoTitle = false;
2019-11-24 12:59:36 +00:00
wConsoleNode = 0 ;
int nMenu = 0 ; // TEMP
2019-08-27 06:08:18 +00:00
if ( nNetPlayerCount & & forcelevel = = - 1 ) {
forcelevel = 1 ;
}
2019-08-31 09:08:38 +00:00
2019-12-14 00:33:26 +00:00
PatchDemoStrings ( ) ;
2019-08-27 06:08:18 +00:00
// loc_115F5:
nItemTextIndex = FindGString ( " ITEMS " ) ;
nFirstPassword = FindGString ( " PASSWORDS " ) ;
nFirstPassInfo = FindGString ( " PASSINFO " ) ;
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
// count the number of passwords available
2019-08-31 14:07:47 +00:00
for ( nPasswordCount = 0 ; strlen ( gString [ nFirstPassword + nPasswordCount ] ) ! = 0 ; nPasswordCount + + )
2019-08-27 06:08:18 +00:00
{
}
ResetPassword ( ) ;
2019-10-12 21:09:55 +00:00
// GetCurPal(NULL);
2019-08-27 06:08:18 +00:00
2020-04-11 21:45:45 +00:00
Printf ( " Initializing OSD... \n " ) ;
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 ;
}
// loc_116A5:
2019-11-13 21:34:11 +00:00
#if 0
2019-08-27 06:08:18 +00:00
if ( nNetPlayerCount )
{
InitInput ( ) ;
forcelevel = nStartLevel ;
nNetTime = 1800 * nTimeLimit ;
if ( nNetTime = = 0 ) {
nNetTime = - 1 ;
}
}
2019-11-13 21:34:11 +00:00
# endif
2019-08-27 06:08:18 +00:00
// temp - moving InstallEngine(); before FadeOut as we use nextpage() in FadeOut
InstallEngine ( ) ;
2019-11-21 12:51:27 +00:00
const char * defsfile = G_DefFile ( ) ;
uint32_t stime = timerGetTicks ( ) ;
if ( ! loaddefinitionsfile ( defsfile ) )
{
uint32_t etime = timerGetTicks ( ) ;
2020-04-11 21:45:45 +00:00
Printf ( " Definitions file \" %s \" loaded in %d ms. \n " , defsfile , etime - stime ) ;
2019-11-21 12:51:27 +00:00
}
2020-02-01 22:05:43 +00:00
enginePostInit ( ) ;
2019-08-31 14:07:47 +00:00
2019-08-27 06:08:18 +00:00
InitView ( ) ;
2019-09-19 13:38:28 +00:00
InitFX ( ) ;
2019-08-27 06:08:18 +00:00
seq_LoadSequences ( ) ;
InitStatus ( ) ;
InitTimer ( ) ;
for ( i = 0 ; i < kMaxPlayers ; i + + ) {
nPlayerLives [ i ] = kDefaultLives ;
}
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
nBestLevel = 0 ;
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
UpdateScreenSize ( ) ;
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
EraseScreen ( overscanindex ) ;
ResetEngine ( ) ;
EraseScreen ( overscanindex ) ;
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
ResetView ( ) ;
GrabPalette ( ) ;
2019-08-26 03:59:14 +00:00
2019-08-31 14:07:47 +00:00
if ( doTitle )
2019-08-27 06:08:18 +00:00
{
2019-08-31 14:07:47 +00:00
while ( ! stopTitle )
2019-08-27 06:08:18 +00:00
{
DoTitle ( ) ;
2020-08-18 08:28:19 +00:00
stopTitle = true ;
2019-08-27 06:08:18 +00:00
}
}
// loc_11811:
if ( forcelevel > - 1 )
{
levelnew = forcelevel ;
2019-08-31 14:07:47 +00:00
goto STARTGAME1 ;
2019-08-27 06:08:18 +00:00
}
2019-08-31 14:07:47 +00:00
// no forcelevel specified...
2019-12-02 17:05:02 +00:00
if ( bPlayback )
2019-08-27 06:08:18 +00:00
{
2019-12-02 17:05:02 +00:00
goto STARTGAME1 ;
2019-08-27 06:08:18 +00:00
}
2019-08-31 14:07:47 +00:00
MENU :
SavePosition = - 1 ;
2019-11-22 08:13:27 +00:00
nMenu = menu_Menu ( 0 ) ;
2019-08-31 14:07:47 +00:00
switch ( nMenu )
{
case - 1 :
goto MENU ;
case 0 :
goto EXITGAME ;
case 3 :
forcelevel = 0 ;
goto STARTGAME2 ;
2019-12-27 16:07:09 +00:00
case 6 :
goto GAMELOOP ;
2019-08-31 14:07:47 +00:00
case 9 :
vcrfp = fopen ( " demo.vcr " , " rb " ) ;
if ( vcrfp = = NULL ) {
goto MENU ;
}
InitRandom ( ) ;
2020-08-18 08:28:19 +00:00
bInDemo = true ;
bPlayback = true ;
2019-08-31 14:07:47 +00:00
2020-01-01 10:35:47 +00:00
inputState . ClearAllInput ( ) ;
2019-08-31 14:07:47 +00:00
break ;
}
STARTGAME1 :
2019-08-27 06:08:18 +00:00
levelnew = 1 ;
levelnum = 1 ;
if ( ! nNetPlayerCount ) {
FadeOut ( 0 ) ;
}
2019-08-31 14:07:47 +00:00
STARTGAME2 :
2019-08-26 03:59:14 +00:00
2020-08-18 08:28:19 +00:00
bCamera = false ;
2019-08-27 06:08:18 +00:00
ClearCinemaSeen ( ) ;
PlayerCount = 0 ;
lastlevel = - 1 ;
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
for ( i = 0 ; i < nTotalPlayers ; i + + )
{
int nPlayer = GrabPlayer ( ) ;
if ( nPlayer < 0 ) {
2019-11-24 09:03:19 +00:00
I_Error ( " Can't create local player \n " ) ;
2019-08-27 06:08:18 +00:00
}
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
InitPlayerInventory ( nPlayer ) ;
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
if ( i = = wConsoleNode ) {
PlayerList [ nPlayer ] . someNetVal = - 3 ;
}
else {
PlayerList [ nPlayer ] . someNetVal = - 4 ;
}
}
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
nNetMoves = 0 ;
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
if ( bPlayback )
{
2019-12-02 19:28:02 +00:00
menu_GameLoad2 ( vcrfp , true ) ;
2019-08-27 06:08:18 +00:00
levelnew = GameStats . nMap ;
levelnum = GameStats . nMap ;
forcelevel = GameStats . nMap ;
}
2019-08-31 14:07:47 +00:00
if ( forcelevel > - 1 )
2019-08-27 06:08:18 +00:00
{
2019-08-31 14:07:47 +00:00
// YELLOW SECTION
levelnew = forcelevel ;
2019-08-27 06:08:18 +00:00
UpdateInputs ( ) ;
2019-08-31 14:07:47 +00:00
forcelevel = - 1 ;
2019-08-27 06:08:18 +00:00
if ( bRecord & & ! bInDemo ) {
menu_GameSave2 ( vcrfp ) ;
}
2019-08-31 14:07:47 +00:00
goto LOOP3 ;
2019-08-27 06:08:18 +00:00
}
2019-08-26 03:59:14 +00:00
2019-08-31 14:07:47 +00:00
// PINK SECTION
2019-08-27 06:08:18 +00:00
UpdateInputs ( ) ;
2019-08-31 14:07:47 +00:00
nNetMoves = 1 ;
2019-08-26 03:59:14 +00:00
2019-08-31 14:07:47 +00:00
if ( nMenu = = 2 )
{
levelnew = 1 ;
levelnum = 1 ;
levelnew = menu_GameLoad ( SavePosition ) ;
lastlevel = - 1 ;
}
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
if ( bRecord & & ! bInDemo ) {
menu_GameSave2 ( vcrfp ) ;
}
2019-08-26 03:59:14 +00:00
2019-08-31 14:07:47 +00:00
nBestLevel = levelnew - 1 ;
LOOP1 :
if ( nPlayerLives [ nLocalPlayer ] < = 0 ) {
goto MENU ;
}
if ( levelnew > 99 ) {
goto EXITGAME ;
}
if ( ! bInDemo & & levelnew > nBestLevel & & levelnew ! = 0 & & levelnew < = kMap20 & & SavePosition > - 1 ) {
menu_GameSave ( SavePosition ) ;
}
LOOP2 :
if ( ! nNetPlayerCount & & ! bPlayback & & levelnew > 0 & & levelnew < = kMap20 ) {
levelnew = showmap ( levelnum , levelnew , nBestLevel ) ;
}
2019-08-26 03:59:14 +00:00
2019-08-31 14:07:47 +00:00
if ( levelnew > nBestLevel ) {
nBestLevel = levelnew ;
}
LOOP3 :
2019-08-27 06:08:18 +00:00
while ( levelnew ! = - 1 )
{
// BLUE
if ( CDplaying ( ) ) {
fadecdaudio ( ) ;
}
if ( levelnew = = kMap20 )
{
lCountDown = 81000 ;
nAlarmTicks = 30 ;
nRedTicks = 0 ;
nClockVal = 0 ;
nEnergyTowers = 0 ;
}
if ( ! LoadLevel ( levelnew ) ) {
// TODO "Can't load level %d...\n", nMap;
2019-08-31 14:07:47 +00:00
goto EXITGAME ;
2019-08-27 06:08:18 +00:00
}
2019-08-31 14:07:47 +00:00
levelnew = - 1 ;
2019-08-27 06:08:18 +00:00
}
2020-06-10 20:35:29 +00:00
/* don't restore mid level savepoint if re-entering just completed level
2019-08-31 14:07:47 +00:00
if ( nNetPlayerCount = = 0 & & lastlevel = = levelnum )
2019-08-27 06:08:18 +00:00
{
2019-08-31 14:07:47 +00:00
RestoreSavePoint ( nLocalPlayer , & initx , & inity , & initz , & initsect , & inita ) ;
}
2020-06-10 20:35:29 +00:00
*/
2019-08-31 14:07:47 +00:00
lastlevel = levelnum ;
2019-08-27 06:08:18 +00:00
2019-08-31 14:07:47 +00:00
for ( i = 0 ; i < nTotalPlayers ; i + + )
{
SetSavePoint ( i , initx , inity , initz , initsect , inita ) ;
RestartPlayer ( i ) ;
InitPlayerKeys ( i ) ;
}
2019-08-27 06:08:18 +00:00
2019-08-31 14:07:47 +00:00
UpdateScreenSize ( ) ;
fps = 0 ;
lastfps = 0 ;
InitStatus ( ) ;
ResetView ( ) ;
ResetEngine ( ) ;
totalmoves = 0 ;
GrabPalette ( ) ;
ResetMoveFifo ( ) ;
moveframes = 0 ;
2020-08-18 08:28:19 +00:00
bInMove = false ;
2019-11-03 17:20:05 +00:00
tclocks = totalclock ;
2019-08-31 14:07:47 +00:00
nPlayerDAng = 0 ;
lPlayerXVel = 0 ;
lPlayerYVel = 0 ;
movefifopos = movefifoend ;
2019-11-28 20:40:17 +00:00
2019-08-31 14:07:47 +00:00
RefreshStatus ( ) ;
2019-08-27 06:08:18 +00:00
2019-08-31 14:07:47 +00:00
//int edi = totalclock;
2019-11-03 17:20:05 +00:00
tclocks2 = totalclock ;
2019-08-31 14:07:47 +00:00
// Game Loop
2019-12-27 16:07:09 +00:00
GAMELOOP :
2019-08-31 14:07:47 +00:00
while ( 1 )
{
if ( levelnew > = 0 )
2019-08-31 15:04:06 +00:00
{
2019-08-31 14:07:47 +00:00
goto LOOP1 ;
2019-08-31 15:04:06 +00:00
}
HandleAsync ( ) ;
2020-07-14 12:00:27 +00:00
C_RunDelayedCommands ( ) ;
2019-11-28 20:40:17 +00:00
2019-08-31 14:07:47 +00:00
// Section B
2019-11-28 20:40:17 +00:00
if ( ! CDplaying ( ) & & ! nFreeze & & ! nNetPlayerCount )
2019-08-31 14:07:47 +00:00
{
int nTrack = levelnum ;
if ( nTrack ! = 0 ) {
nTrack - - ;
}
2019-08-26 03:59:14 +00:00
2019-11-28 20:40:17 +00:00
playCDtrack ( ( nTrack % 8 ) + 11 , true ) ;
2019-08-27 06:08:18 +00:00
}
2019-08-26 03:59:14 +00:00
// TODO CONTROL_GetButtonInput();
2020-05-29 01:15:01 +00:00
updatePauseStatus ( ) ;
2019-08-31 14:07:47 +00:00
CheckKeys ( ) ;
2019-08-27 06:08:18 +00:00
2019-11-03 17:20:05 +00:00
if ( bRecord | | bPlayback )
{
2020-08-18 08:28:19 +00:00
bInMove = true ;
2019-08-27 06:08:18 +00:00
2019-11-03 17:20:05 +00:00
moveframes = ( ( int ) totalclock - ( int ) tclocks2 ) / 4 ;
2019-08-27 06:08:18 +00:00
2019-11-03 17:20:05 +00:00
if ( moveframes > 4 )
moveframes = 4 ;
2019-08-27 06:08:18 +00:00
2019-11-03 17:20:05 +00:00
if ( moveframes ! = 0 )
tclocks2 = totalclock ;
2019-08-27 06:08:18 +00:00
2019-11-03 17:20:05 +00:00
if ( bPlayback )
2019-08-27 06:08:18 +00:00
{
2019-11-03 17:20:05 +00:00
// YELLOW
2019-12-02 19:28:02 +00:00
if ( ( ( bInDemo & & inputState . keyBufferWaiting ( ) ) | | ! ReadPlaybackInputs ( ) ) & & inputState . keyGetChar ( ) )
2019-11-03 17:20:05 +00:00
{
2020-01-01 10:35:47 +00:00
inputState . ClearAllInput ( ) ;
2019-08-27 06:08:18 +00:00
2020-08-18 08:28:19 +00:00
bPlayback = false ;
bInDemo = false ;
2019-08-27 06:08:18 +00:00
2019-11-03 17:20:05 +00:00
if ( vcrfp ) {
fclose ( vcrfp ) ;
}
2019-08-31 14:07:47 +00:00
2019-11-03 17:20:05 +00:00
goto MENU ;
}
2019-08-27 06:08:18 +00:00
}
2019-11-03 17:20:05 +00:00
else if ( bRecord | | moveframes )
{
GetLocalInput ( ) ;
2019-08-27 06:08:18 +00:00
2019-11-03 17:20:05 +00:00
sPlayerInput [ nLocalPlayer ] . xVel = lPlayerXVel ;
sPlayerInput [ nLocalPlayer ] . yVel = lPlayerYVel ;
sPlayerInput [ nLocalPlayer ] . buttons = lLocalButtons | lLocalCodes ;
sPlayerInput [ nLocalPlayer ] . nAngle = nPlayerDAng ;
sPlayerInput [ nLocalPlayer ] . nTarget = besttarget ;
2019-08-27 06:08:18 +00:00
2019-11-03 17:20:05 +00:00
Ra [ nLocalPlayer ] . nTarget = besttarget ;
2019-08-27 06:08:18 +00:00
2019-11-03 17:20:05 +00:00
lLocalCodes = 0 ;
nPlayerDAng = 0 ;
2019-08-27 06:08:18 +00:00
2020-04-04 07:47:55 +00:00
sPlayerInput [ nLocalPlayer ] . horizon = PlayerList [ nLocalPlayer ] . q16horiz ;
2019-11-03 17:20:05 +00:00
}
2019-08-27 06:08:18 +00:00
2019-11-03 17:20:05 +00:00
// loc_11F72:
if ( bRecord & & ! bInDemo ) {
WritePlaybackInputs ( ) ;
2019-08-27 06:08:18 +00:00
}
2019-11-03 17:20:05 +00:00
if ( nNetPlayerCount )
2019-08-27 06:08:18 +00:00
{
2019-11-03 17:20:05 +00:00
if ( moveframes )
2019-08-27 06:08:18 +00:00
{
2019-11-03 17:20:05 +00:00
UpdateInputs ( ) ;
moveframes = nNetMoveFrames ;
2019-08-27 06:08:18 +00:00
}
}
2019-11-03 17:20:05 +00:00
else
2019-08-27 06:08:18 +00:00
{
2019-11-03 17:20:05 +00:00
// loc_11FBC:
2020-05-29 01:15:01 +00:00
while ( paused )
2019-08-27 06:08:18 +00:00
{
2020-07-15 16:10:31 +00:00
updatePauseStatus ( ) ;
2019-08-31 14:07:47 +00:00
}
2019-11-03 17:20:05 +00:00
}
2019-08-27 06:08:18 +00:00
2019-11-03 17:20:05 +00:00
// loc_11FEE:
tclocks + = moveframes * 4 ;
while ( moveframes & & levelnew < 0 )
{
GameMove ( ) ;
// if (nNetTime > 0)
// {
// nNetTime--;
2019-11-20 16:21:32 +00:00
//
2019-11-03 17:20:05 +00:00
// if (!nNetTime) {
// nFreeze = 3;
// }
// }
// else if (nNetTime == 0)
// {
2019-11-24 09:03:19 +00:00
// if (buttonMap.ButtonDown(gamefunc_Open))
2019-11-03 17:20:05 +00:00
// {
2019-11-24 09:03:19 +00:00
// buttonMap.ClearButton(gamefunc_Open);
2019-11-03 17:20:05 +00:00
// goto MENU2;
// }
// }
}
2019-08-27 06:08:18 +00:00
2020-08-18 08:28:19 +00:00
bInMove = false ;
2019-08-27 06:08:18 +00:00
2019-11-03 17:20:05 +00:00
// END YELLOW SECTION
2019-08-27 06:08:18 +00:00
2019-11-03 17:20:05 +00:00
// loc_12149:
2019-12-02 19:34:52 +00:00
if ( bInDemo | | bPlayback )
2019-11-03 17:20:05 +00:00
{
while ( tclocks > totalclock ) { HandleAsync ( ) ; }
tclocks = totalclock ;
2019-08-31 14:07:47 +00:00
}
2019-08-27 06:08:18 +00:00
2019-11-03 17:20:05 +00:00
if ( G_FPSLimit ( ) )
2019-08-31 14:07:47 +00:00
{
2019-11-03 17:20:05 +00:00
GameDisplay ( ) ;
2019-08-31 14:07:47 +00:00
}
2019-11-03 17:20:05 +00:00
}
else
{
2020-08-18 08:28:19 +00:00
bInMove = true ;
2020-04-04 04:31:27 +00:00
2020-05-29 01:15:01 +00:00
if ( paused )
2019-08-31 14:07:47 +00:00
{
2020-05-06 23:39:48 +00:00
tclocks = totalclock - 4 ;
2020-05-06 17:38:51 +00:00
buttonMap . ResetButtonStates ( ) ;
2020-04-04 04:31:27 +00:00
}
else
{
while ( ( totalclock - ototalclock ) > = 1 | | ! bInMove )
2019-11-22 15:57:42 +00:00
{
2020-04-04 04:31:27 +00:00
ototalclock = ototalclock + 1 ;
2019-08-31 14:07:47 +00:00
2020-04-04 04:31:27 +00:00
if ( ! ( ( int ) ototalclock & 3 ) & & moveframes < 4 )
moveframes + + ;
2019-08-31 14:07:47 +00:00
2019-11-22 15:57:42 +00:00
GetLocalInput ( ) ;
2020-04-04 04:31:27 +00:00
PlayerInterruptKeys ( ) ;
nPlayerDAng = fix16_sadd ( nPlayerDAng , localInput . nAngle ) ;
inita & = kAngleMask ;
lPlayerXVel + = localInput . yVel * Cos ( inita ) + localInput . xVel * Sin ( inita ) ;
lPlayerYVel + = localInput . yVel * Sin ( inita ) - localInput . xVel * Cos ( inita ) ;
lPlayerXVel - = ( lPlayerXVel > > 5 ) + ( lPlayerXVel > > 6 ) ;
lPlayerYVel - = ( lPlayerYVel > > 5 ) + ( lPlayerYVel > > 6 ) ;
2019-08-31 14:07:47 +00:00
2019-11-22 15:57:42 +00:00
sPlayerInput [ nLocalPlayer ] . xVel = lPlayerXVel ;
sPlayerInput [ nLocalPlayer ] . yVel = lPlayerYVel ;
sPlayerInput [ nLocalPlayer ] . buttons = lLocalButtons | lLocalCodes ;
sPlayerInput [ nLocalPlayer ] . nAngle = nPlayerDAng ;
sPlayerInput [ nLocalPlayer ] . nTarget = besttarget ;
2019-11-03 17:20:05 +00:00
2019-11-22 15:57:42 +00:00
Ra [ nLocalPlayer ] . nTarget = besttarget ;
2019-11-03 17:20:05 +00:00
2019-11-22 15:57:42 +00:00
lLocalCodes = 0 ;
nPlayerDAng = 0 ;
2020-04-04 07:47:55 +00:00
sPlayerInput [ nLocalPlayer ] . horizon = PlayerList [ nLocalPlayer ] . q16horiz ;
2019-11-22 15:57:42 +00:00
2020-04-04 04:31:27 +00:00
while ( levelnew < 0 & & totalclock > = tclocks + 4 )
2019-11-22 15:57:42 +00:00
{
// timerUpdate();
tclocks + = 4 ;
GameMove ( ) ;
// timerUpdate();
2020-04-04 04:31:27 +00:00
}
}
2020-02-01 23:10:18 +00:00
}
2020-08-18 08:28:19 +00:00
bInMove = false ;
2019-08-27 06:08:18 +00:00
2020-04-04 04:31:27 +00:00
PlayerInterruptKeys ( ) ;
2019-08-27 06:08:18 +00:00
2019-11-03 17:20:05 +00:00
if ( G_FPSLimit ( ) )
{
GameDisplay ( ) ;
}
}
2019-08-31 14:07:47 +00:00
if ( ! bInDemo )
{
2020-03-01 15:32:41 +00:00
nMenu = MenuExitCondition ;
if ( nMenu ! = - 2 )
2019-08-31 14:07:47 +00:00
{
2020-03-01 15:32:41 +00:00
MenuExitCondition = - 2 ;
2019-11-03 17:20:05 +00:00
// MENU2:
2020-08-18 08:28:19 +00:00
bInMove = true ;
2019-08-27 06:08:18 +00:00
2019-08-31 14:07:47 +00:00
switch ( nMenu )
2019-08-27 06:08:18 +00:00
{
2019-08-31 14:07:47 +00:00
case 0 :
goto EXITGAME ;
case 1 :
goto STARTGAME1 ;
case 2 :
levelnum = levelnew = menu_GameLoad ( SavePosition ) ;
lastlevel = - 1 ;
nBestLevel = levelnew - 1 ;
goto LOOP2 ;
2019-12-29 15:35:51 +00:00
case 3 :
2020-03-01 15:32:41 +00:00
forcelevel = 0 ;
2019-12-29 15:35:51 +00:00
goto STARTGAME2 ;
2019-12-27 16:07:09 +00:00
case 6 :
goto GAMELOOP ;
2019-08-27 06:08:18 +00:00
}
2019-11-13 18:26:29 +00:00
totalclock = ototalclock = tclocks ;
2020-08-18 08:28:19 +00:00
bInMove = false ;
2019-08-31 14:07:47 +00:00
RefreshStatus ( ) ;
2019-08-27 06:08:18 +00:00
}
2019-11-24 09:03:19 +00:00
else if ( buttonMap . ButtonDown ( gamefunc_Map ) ) // e.g. TAB (to show 2D map)
2019-08-31 14:07:47 +00:00
{
2019-11-24 09:03:19 +00:00
buttonMap . ClearButton ( gamefunc_Map ) ;
2019-08-27 06:08:18 +00:00
2019-08-31 14:07:47 +00:00
if ( ! nFreeze ) {
2019-11-18 20:31:08 +00:00
nMapMode = ( nMapMode + 1 ) % 3 ;
2019-08-31 14:07:47 +00:00
}
}
2019-11-20 16:21:32 +00:00
2019-11-18 20:31:08 +00:00
if ( nMapMode ! = 0 )
2019-08-27 06:08:18 +00:00
{
2019-11-18 20:31:08 +00:00
int const timerOffset = ( ( int ) totalclock - nonsharedtimer ) ;
nonsharedtimer + = timerOffset ;
2019-08-31 14:07:47 +00:00
2019-11-24 09:03:19 +00:00
if ( buttonMap . ButtonDown ( gamefunc_Zoom_In ) )
2019-11-18 20:31:08 +00:00
lMapZoom + = mulscale6 ( timerOffset , max < int > ( lMapZoom , 256 ) ) ;
2019-11-24 09:03:19 +00:00
if ( buttonMap . ButtonDown ( gamefunc_Zoom_Out ) )
2019-11-18 20:31:08 +00:00
lMapZoom - = mulscale6 ( timerOffset , max < int > ( lMapZoom , 256 ) ) ;
lMapZoom = clamp ( lMapZoom , 48 , 2048 ) ;
2019-08-27 06:08:18 +00:00
}
2019-08-31 14:07:47 +00:00
if ( PlayerList [ nLocalPlayer ] . nHealth > 0 )
2019-08-27 06:08:18 +00:00
{
2019-11-24 09:03:19 +00:00
if ( buttonMap . ButtonDown ( gamefunc_Inventory_Left ) )
2019-08-27 06:08:18 +00:00
{
SetPrevItem ( nLocalPlayer ) ;
2019-11-24 09:03:19 +00:00
buttonMap . ClearButton ( gamefunc_Inventory_Left ) ;
2019-08-27 06:08:18 +00:00
}
2019-11-24 09:03:19 +00:00
if ( buttonMap . ButtonDown ( gamefunc_Inventory_Right ) )
2019-08-27 06:08:18 +00:00
{
SetNextItem ( nLocalPlayer ) ;
2019-11-24 09:03:19 +00:00
buttonMap . ClearButton ( gamefunc_Inventory_Right ) ;
2019-08-27 06:08:18 +00:00
}
2019-11-24 09:03:19 +00:00
if ( buttonMap . ButtonDown ( gamefunc_Inventory ) )
2019-08-27 06:08:18 +00:00
{
UseCurItem ( nLocalPlayer ) ;
2019-11-24 09:03:19 +00:00
buttonMap . ClearButton ( gamefunc_Inventory ) ;
2019-08-27 06:08:18 +00:00
}
}
2019-10-28 19:14:54 +00:00
else {
2019-08-31 14:07:47 +00:00
SetAirFrame ( ) ;
2019-10-28 19:14:54 +00:00
}
2019-08-27 06:08:18 +00:00
}
2019-08-31 14:07:47 +00:00
if ( record_mode = = 3 & & movefifopos = = movefifoend ) {
2019-08-27 06:08:18 +00:00
levelnew = 0 ;
}
2019-08-31 14:07:47 +00:00
fps + + ;
2019-08-27 06:08:18 +00:00
}
2019-08-31 14:07:47 +00:00
EXITGAME :
2019-08-27 06:08:18 +00:00
2019-12-14 00:33:26 +00:00
ExitGame ( ) ;
2019-08-27 06:08:18 +00:00
return 0 ;
2019-08-26 03:59:14 +00:00
}
void mychangespritesect ( int nSprite , int nSector )
{
2019-08-27 06:08:18 +00:00
DoKenTest ( ) ;
changespritesect ( nSprite , nSector ) ;
DoKenTest ( ) ;
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
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 KeyFn1 ( )
{
2019-08-27 06:08:18 +00:00
menu_DoPlasma ( ) ;
overwritesprite ( 160 , 100 , kSkullHead , 0 , 3 , kPalNormal ) ;
overwritesprite ( 161 , 130 , kSkullJaw , 0 , 3 , kPalNormal ) ;
videoNextPage ( ) ;
2019-08-26 03:59:14 +00:00
}
2020-05-23 12:36:35 +00:00
extern int currentCinemaPalette ;
2019-08-26 03:59:14 +00:00
void DoGameOverScene ( )
{
2019-08-27 06:08:18 +00:00
FadeOut ( 0 ) ;
2020-01-01 10:35:47 +00:00
inputState . ClearAllInput ( ) ;
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
NoClip ( ) ;
2020-05-23 12:36:35 +00:00
overwritesprite ( 0 , 0 , kTile3591 , 0 , 2 , kPalNormal , 16 ) ;
2019-08-27 06:08:18 +00:00
Clip ( ) ;
2019-08-26 03:59:14 +00:00
videoNextPage ( ) ;
2019-08-27 06:08:18 +00:00
CinemaFadeIn ( ) ;
2019-09-21 15:47:55 +00:00
PlayGameOverSound ( ) ;
2019-08-27 06:08:18 +00:00
WaitAnyKey ( 3 ) ;
FadeOut ( 0 ) ;
2019-08-26 03:59:14 +00:00
}
void DoTitle ( )
{
2020-02-04 21:45:10 +00:00
short skullDurations [ ] = { 6 , 25 , 43 , 50 , 68 , 78 , 101 , 111 , 134 , 158 , 173 , 230 , 6000 } ;
2019-08-27 06:08:18 +00:00
videoSetViewableArea ( 0 , 0 , xdim - 1 , ydim - 1 ) ;
2019-08-26 03:59:14 +00:00
2020-06-12 21:06:11 +00:00
auto showscreen = [ ] ( int tile )
{
auto start = I_msTime ( ) ;
int shade = numshades ;
uint64_t span ;
inputState . ClearAllInput ( ) ;
do
{
2020-06-12 22:08:47 +00:00
twod - > ClearScreen ( ) ;
2020-06-12 21:06:11 +00:00
overwritesprite ( 0 , 0 , tile , shade , 2 , kPalNormal ) ;
2020-06-17 14:30:46 +00:00
HandleAsync ( ) ;
2020-06-12 21:06:11 +00:00
videoNextPage ( ) ;
auto now = I_msTime ( ) ;
span = now - start ;
if ( span < 1000 ) shade = Scale ( 1000 - span , numshades , 1000 ) ;
else if ( span < 2000 ) shade = 0 ;
else shade = Scale ( span - 2000 , numshades , 1000 ) ;
if ( inputState . CheckAllInput ( ) ) break ;
} while ( span < 3000 ) ;
} ;
showscreen ( EXHUMED ? kTileBMGLogo : kTilePIELogo ) ;
2019-08-27 06:08:18 +00:00
int nScreenTile = seq_GetSeqPicnum ( kSeqScreens , 0 , 0 ) ;
2020-06-12 21:06:11 +00:00
showscreen ( nScreenTile ) ;
2020-01-01 10:35:47 +00:00
inputState . ClearAllInput ( ) ;
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
PlayMovie ( " book.mov " ) ;
2019-08-26 03:59:14 +00:00
2019-11-20 18:13:34 +00:00
if ( videoGetRenderMode ( ) = = REND_CLASSIC )
FadeOut ( 0 ) ;
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
GrabPalette ( ) ;
2019-08-26 03:59:14 +00:00
2020-02-23 19:40:45 +00:00
PlayLocalSound ( StaticSound [ 59 ] , 0 , true , CHANF_UI ) ;
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
EraseScreen ( 4 ) ;
2019-08-26 03:59:14 +00:00
2019-11-28 20:40:17 +00:00
playCDtrack ( 19 , true ) ;
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
videoNextPage ( ) ;
FadeIn ( ) ;
WaitVBL ( ) ;
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
int String_Copyright = FindGString ( " COPYRIGHT " ) ;
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
const char * a = gString [ String_Copyright ] ;
const char * b = gString [ String_Copyright + 1 ] ;
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
menu_DoPlasma ( ) ;
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
int nTile = kSkullHead ;
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
overwritesprite ( 160 , 100 , kSkullHead , 0 , 3 , kPalNormal ) ;
overwritesprite ( 161 , 130 , kSkullJaw , 0 , 3 , kPalNormal ) ;
videoNextPage ( ) ;
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
WaitNoKey ( 2 , KeyFn1 ) ;
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
if ( time ( 0 ) & 0xF ) {
2019-09-21 15:47:55 +00:00
PlayGameOverSound ( ) ;
2019-08-27 06:08:18 +00:00
}
else {
2020-02-23 19:40:45 +00:00
PlayLocalSound ( StaticSound [ 61 ] , 0 , false , CHANF_UI ) ;
2019-08-27 06:08:18 +00:00
}
2019-08-26 03:59:14 +00:00
2019-09-06 05:18:12 +00:00
int nStartTime = ( int ) totalclock ;
2019-08-27 06:08:18 +00:00
int nCount = 0 ;
2020-02-04 21:45:10 +00:00
int var_18 = ( int ) totalclock + skullDurations [ 0 ] ;
2019-08-27 06:08:18 +00:00
int var_4 = 0 ;
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
int esi = 130 ;
2019-08-26 03:59:14 +00:00
2020-02-04 21:45:10 +00:00
2019-08-26 03:59:14 +00:00
2020-01-01 10:35:47 +00:00
inputState . ClearAllInput ( ) ;
2019-08-27 06:08:18 +00:00
while ( LocalSoundPlaying ( ) )
{
2019-08-31 15:04:06 +00:00
HandleAsync ( ) ;
2019-12-27 16:07:09 +00:00
if ( inputState . CheckAllInput ( ) ) break ;
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
menu_DoPlasma ( ) ;
overwritesprite ( 160 , 100 , nTile , 0 , 3 , kPalNormal ) ;
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
int nStringWidth = MyGetStringWidth ( a ) ;
2019-08-26 03:59:14 +00:00
2019-11-23 17:26:10 +00:00
int y = 200 - 24 ;
myprintext ( ( 320 / 2 - nStringWidth / 2 ) , y , a , 0 ) ;
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
nStringWidth = MyGetStringWidth ( b ) ;
2019-08-26 03:59:14 +00:00
2019-11-23 17:26:10 +00:00
y = 200 - 16 ;
myprintext ( ( 320 / 2 - nStringWidth / 2 ) , y , b , 0 ) ;
2019-08-26 03:59:14 +00:00
2019-09-06 05:18:12 +00:00
if ( ( int ) totalclock > var_18 )
2019-08-27 06:08:18 +00:00
{
nCount + + ;
2019-08-26 03:59:14 +00:00
2019-12-27 16:07:09 +00:00
if ( nCount > 12 ) break ;
2020-02-04 21:45:10 +00:00
var_18 = nStartTime + skullDurations [ nCount ] ;
2019-08-27 06:08:18 +00:00
var_4 = var_4 = = 0 ;
}
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
short nTile = kSkullJaw ;
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
if ( var_4 )
{
if ( esi > = 135 ) {
nTile = kTile3583 ;
}
else {
esi + = 5 ;
}
}
else if ( esi < = 130 )
{
esi = 130 ;
}
else
{
esi - = 2 ;
}
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
y = 0 ;
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
if ( nTile = = kTile3583 )
{
y = 131 ;
}
else
{
y = esi ;
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
if ( y > 135 ) {
y = 135 ;
}
}
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
overwritesprite ( 161 , y , nTile , 0 , 3 , kPalNormal ) ;
videoNextPage ( ) ;
}
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
WaitNoKey ( 1 , KeyFn1 ) ;
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
videoSetViewableArea ( nViewLeft , nViewTop , nViewRight , nViewBottom ) ;
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
tileInvalidate ( nDestTile , - 1 , - 1 ) ;
2019-08-26 03:59:14 +00:00
}
int CopyCharToBitmap ( char nChar , int nTile , int xPos , int yPos )
{
2019-08-27 06:08:18 +00:00
if ( nChar = = ' ' ) {
return 4 ;
}
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
nChar = toupper ( nChar ) ;
int nFontTile = seq_GetSeqPicnum ( kSeqFont2 , 0 , nChar - 32 ) + 102 ;
CopyTileToBitmap ( nFontTile , nTile , xPos , yPos ) ;
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
return tilesiz [ nFontTile ] . x + 1 ;
2019-08-26 03:59:14 +00:00
}
// Note: strings passed should be uppercase
2020-05-23 12:36:35 +00:00
int myprintext ( int x , int y , const char * str , int shade , int basepal )
2019-08-26 03:59:14 +00:00
{
2019-08-27 06:08:18 +00:00
if ( y < - 15 | | y > = 200 )
return x ;
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
const char * c = str ;
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
while ( * c ! = ' \0 ' )
{
int nTile = seq_GetSeqPicnum ( kSeqFont2 , 0 , ( * c ) - 32 ) ;
2020-05-23 12:36:35 +00:00
overwritesprite ( x , y , nTile , shade , 2 , kPalNormal , basepal ) ;
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
int tileWidth = tilesiz [ nTile ] . x ;
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
x + = tileWidth + 1 ;
c + + ;
}
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
return x ;
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
}
void InitSpiritHead ( )
{
2019-08-27 06:08:18 +00:00
char filename [ 20 ] ;
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
nPixels = 0 ;
2019-08-26 03:59:14 +00:00
2019-11-24 22:23:33 +00:00
nSpiritRepeatX = sprite [ nSpiritSprite ] . xrepeat ;
nSpiritRepeatY = sprite [ nSpiritSprite ] . yrepeat ;
tileLoad ( kTileRamsesNormal ) ; // Ramses Normal Head
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
for ( int i = 0 ; i < kMaxSprites ; i + + )
{
if ( sprite [ i ] . statnum )
{
sprite [ i ] . cstat | = 0x8000 ;
}
}
2019-08-26 03:59:14 +00:00
2019-11-24 12:59:36 +00:00
auto pTile = tilePtr ( kTileRamsesNormal ) ; // Ramses Normal Head
auto pGold = tilePtr ( kTileRamsesGold ) ;
2019-08-27 06:08:18 +00:00
for ( int x = 0 ; x < 97 ; x + + )
{
for ( int y = 0 ; y < 106 ; y + + )
{
2020-04-11 22:04:02 +00:00
if ( * pTile ! = TRANSPARENT_INDEX )
2019-08-27 06:08:18 +00:00
{
2019-11-24 12:59:36 +00:00
pixelval [ nPixels ] = * ( pGold + x * 106 + y ) ;
2019-08-27 06:08:18 +00:00
origx [ nPixels ] = x - 48 ;
origy [ nPixels ] = y - 53 ;
curx [ nPixels ] = 0 ;
cury [ nPixels ] = 0 ;
vely [ nPixels ] = 0 ;
velx [ nPixels ] = 0 ;
destvelx [ nPixels ] = RandomSize ( 2 ) + 1 ;
if ( curx [ nPixels ] > 0 ) {
destvelx [ nPixels ] = - destvelx [ nPixels ] ;
}
destvely [ nPixels ] = RandomSize ( 2 ) + 1 ;
if ( cury [ nPixels ] > 0 ) {
destvely [ nPixels ] = - destvely [ nPixels ] ;
}
nPixels + + ;
}
pTile + + ;
}
}
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
sprite [ nSpiritSprite ] . yrepeat = 140 ;
sprite [ nSpiritSprite ] . xrepeat = 140 ;
sprite [ nSpiritSprite ] . picnum = kTileRamsesWorkTile ;
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
nHeadStage = 0 ;
2019-11-20 16:21:32 +00:00
2019-08-27 06:08:18 +00:00
// work tile is twice as big as the normal head size
2019-11-24 15:37:31 +00:00
Worktile = TileFiles . tileCreate ( kTileRamsesWorkTile , kSpiritX * 2 , kSpiritY * 2 ) ;
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
sprite [ nSpiritSprite ] . cstat & = 0x7FFF ;
2019-08-26 03:59:14 +00:00
2019-09-06 05:18:12 +00:00
nHeadTimeStart = ( int ) totalclock ;
2019-08-26 03:59:14 +00:00
2020-04-11 22:04:02 +00:00
memset ( Worktile , TRANSPARENT_INDEX , WorktileSize ) ;
2019-11-05 06:15:21 +00:00
tileInvalidate ( kTileRamsesWorkTile , - 1 , - 1 ) ;
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
nPixelsToShow = 0 ;
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
fadecdaudio ( ) ;
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
int nTrack ;
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
if ( levelnum = = 1 )
{
nTrack = 3 ;
}
else
{
nTrack = 7 ;
}
2019-08-26 03:59:14 +00:00
2019-11-28 20:40:17 +00:00
bSubTitles = playCDtrack ( nTrack , false ) = = 0 ;
2019-11-20 16:21:32 +00:00
2019-08-27 06:08:18 +00:00
StartSwirlies ( ) ;
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
sprintf ( filename , " LEV%d.PUP " , levelnum ) ;
2019-09-06 05:18:12 +00:00
lNextStateChange = ( int ) totalclock ;
lHeadStartClock = ( int ) totalclock ;
2019-08-26 03:59:14 +00:00
2020-04-11 21:54:33 +00:00
auto headfd = fileSystem . OpenFileReader ( filename ) ; // 512??
2019-11-24 12:59:36 +00:00
if ( ! headfd . isOpen ( ) )
{
memset ( cPupData , 0 , sizeof ( cPupData ) ) ;
}
else
{
nPupData = headfd . Read ( cPupData , sizeof ( cPupData ) ) ;
pPupData = cPupData ;
}
2019-08-27 06:08:18 +00:00
nMouthTile = 0 ;
nTalkTime = 1 ;
2019-08-26 03:59:14 +00:00
}
void DimSector ( short nSector )
{
short startwall = sector [ nSector ] . wallptr ;
short nWalls = sector [ nSector ] . wallnum ;
2019-11-20 16:21:32 +00:00
2019-08-26 03:59:14 +00:00
for ( int i = 0 ; i < nWalls ; i + + )
{
if ( wall [ startwall + i ] . shade < 40 ) {
wall [ startwall + i ] . shade + + ;
}
}
2019-11-20 16:21:32 +00:00
2019-08-26 03:59:14 +00:00
if ( sector [ nSector ] . floorshade < 40 ) {
sector [ nSector ] . floorshade + + ;
}
2019-11-20 16:21:32 +00:00
2019-08-26 03:59:14 +00:00
if ( sector [ nSector ] . ceilingshade < 40 ) {
sector [ nSector ] . ceilingshade + + ;
}
}
void CopyHeadToWorkTile ( short nTile )
{
2019-11-24 12:59:36 +00:00
const uint8_t * pSrc = tilePtr ( nTile ) ;
2019-11-24 15:34:23 +00:00
uint8_t * pDest = & Worktile [ 212 * 49 + 53 ] ;
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
for ( int i = 0 ; i < 97 ; i + + )
{
memcpy ( pDest , pSrc , 106 ) ;
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
pDest + = 212 ;
pSrc + = 106 ;
}
2019-08-26 03:59:14 +00:00
}
int DoSpiritHead ( )
{
2019-08-27 06:08:18 +00:00
static short word_964E6 = 0 ;
2020-04-04 07:47:55 +00:00
PlayerList [ 0 ] . q16horiz = fix16_sadd ( PlayerList [ 0 ] . q16horiz , fix16_sdiv ( fix16_ssub ( nDestVertPan [ 0 ] , PlayerList [ 0 ] . q16horiz ) , fix16_from_int ( 4 ) ) ) ;
2019-08-27 06:08:18 +00:00
2019-11-05 06:15:21 +00:00
tileInvalidate ( kTileRamsesWorkTile , - 1 , - 1 ) ;
2019-08-27 06:08:18 +00:00
if ( nHeadStage < 2 )
{
2020-04-11 22:04:02 +00:00
memset ( Worktile , TRANSPARENT_INDEX , WorktileSize ) ;
2019-08-27 06:08:18 +00:00
}
if ( nHeadStage < 2 | | nHeadStage ! = 5 )
{
2019-09-06 05:18:12 +00:00
nPixelsToShow = ( ( int ) totalclock - nHeadTimeStart ) * 15 ;
2019-08-27 06:08:18 +00:00
if ( nPixelsToShow > nPixels ) {
nPixelsToShow = nPixels ;
}
if ( nHeadStage < 3 )
{
UpdateSwirlies ( ) ;
if ( sprite [ nSpiritSprite ] . shade > - 127 ) {
sprite [ nSpiritSprite ] . shade - - ;
}
word_964E6 - - ;
if ( word_964E6 < 0 )
{
DimSector ( sprite [ nSpiritSprite ] . sectnum ) ;
word_964E6 = 5 ;
}
if ( ! nHeadStage )
{
2019-09-06 05:18:12 +00:00
if ( ( ( int ) totalclock - nHeadTimeStart ) > 480 )
2019-08-27 06:08:18 +00:00
{
nHeadStage = 1 ;
2019-09-06 05:18:12 +00:00
nHeadTimeStart = ( int ) totalclock + 480 ;
2019-08-27 06:08:18 +00:00
}
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
for ( int i = 0 ; i < nPixelsToShow ; i + + )
{
if ( destvely [ i ] > = 0 )
{
vely [ i ] + + ;
if ( vely [ i ] > = destvely [ i ] )
{
destvely [ i ] = - ( RandomSize ( 2 ) + 1 ) ;
}
}
else
{
vely [ i ] - - ;
if ( vely [ i ] < = destvely [ i ] )
{
destvely [ i ] = RandomSize ( 2 ) + 1 ;
}
}
// loc_13541
if ( destvelx [ i ] > = 0 )
{
velx [ i ] + + ;
if ( velx [ i ] > = destvelx [ i ] )
{
destvelx [ i ] = - ( RandomSize ( 2 ) + 1 ) ;
}
}
else
{
velx [ i ] - - ;
if ( velx [ i ] < = destvelx [ i ] )
{
destvelx [ i ] = RandomSize ( 2 ) + 1 ;
}
}
int esi = vely [ i ] + ( cury [ i ] > > 8 ) ;
if ( esi < 106 )
{
if ( esi < - 105 )
{
vely [ i ] = 0 ;
esi = 0 ;
}
}
else
{
vely [ i ] = 0 ;
esi = 0 ;
}
int ebx = velx [ i ] + ( curx [ i ] > > 8 ) ;
if ( ebx < 97 )
{
if ( ebx < - 96 )
{
velx [ i ] = 0 ;
ebx = 0 ;
}
}
else
{
velx [ i ] = 0 ;
ebx = 0 ;
}
2019-08-31 10:36:26 +00:00
curx [ i ] = ebx * 256 ;
cury [ i ] = esi * 256 ;
2019-08-27 06:08:18 +00:00
esi + = ( ebx + 97 ) * 212 ;
2019-08-26 03:59:14 +00:00
2019-11-24 15:34:23 +00:00
Worktile [ 106 + esi ] = pixelval [ i ] ;
2019-08-27 06:08:18 +00:00
}
return 1 ;
}
else
{
if ( nHeadStage ! = 1 ) {
return 1 ;
}
2019-08-31 07:47:15 +00:00
uint8_t nXRepeat = sprite [ nSpiritSprite ] . xrepeat ;
2019-08-27 06:08:18 +00:00
if ( nXRepeat > nSpiritRepeatX )
{
sprite [ nSpiritSprite ] . xrepeat - = 2 ;
nXRepeat = sprite [ nSpiritSprite ] . xrepeat ;
if ( nXRepeat < nSpiritRepeatX )
{
sprite [ nSpiritSprite ] . xrepeat = nSpiritRepeatX ;
}
}
2019-08-31 07:47:15 +00:00
uint8_t nYRepeat = sprite [ nSpiritSprite ] . yrepeat ;
2019-08-27 06:08:18 +00:00
if ( nYRepeat > nSpiritRepeatY )
{
sprite [ nSpiritSprite ] . yrepeat - = 2 ;
nYRepeat = sprite [ nSpiritSprite ] . yrepeat ;
if ( nYRepeat < nSpiritRepeatY )
{
sprite [ nSpiritSprite ] . yrepeat = nSpiritRepeatY ;
}
}
int esi = 0 ;
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
for ( int i = 0 ; i < nPixels ; i + + )
{
int eax = ( origx [ i ] < < 8 ) - curx [ i ] ;
int ecx = eax ;
if ( eax )
{
if ( eax < 0 ) {
eax = - eax ;
}
if ( eax < 8 )
{
curx [ i ] = origx [ i ] < < 8 ;
ecx = 0 ;
}
else {
ecx > > = 3 ;
}
}
else
{
ecx > > = 3 ;
}
int var_1C = ( origy [ i ] < < 8 ) - cury [ i ] ;
int ebp = var_1C ;
if ( var_1C )
{
eax = ebp ;
if ( eax < 0 ) {
eax = - eax ;
}
if ( eax < 8 )
{
cury [ i ] = origy [ i ] < < 8 ;
var_1C = 0 ;
}
else
{
var_1C > > = 3 ;
}
}
else
{
var_1C > > = 3 ;
}
if ( var_1C | | ecx )
{
curx [ i ] + = ecx ;
cury [ i ] + = var_1C ;
esi + + ;
}
ecx = ( ( ( curx [ i ] > > 8 ) + 97 ) * 212 ) + ( cury [ i ] > > 8 ) ;
2019-08-26 03:59:14 +00:00
2019-11-24 15:34:23 +00:00
Worktile [ 106 + ecx ] = pixelval [ i ] ;
2019-08-27 06:08:18 +00:00
}
2019-09-06 05:18:12 +00:00
if ( ( ( int ) totalclock - lHeadStartClock ) > 600 ) {
2019-08-27 06:08:18 +00:00
CopyHeadToWorkTile ( kTileRamsesGold ) ;
}
int eax = ( ( nPixels < < 4 ) - nPixels ) / 16 ;
if ( esi < eax )
{
2019-09-21 15:47:55 +00:00
SoundBigEntrance ( ) ;
2019-08-27 06:08:18 +00:00
AddGlow ( sprite [ nSpiritSprite ] . sectnum , 20 ) ;
AddFlash (
sprite [ nSpiritSprite ] . sectnum ,
sprite [ nSpiritSprite ] . x ,
sprite [ nSpiritSprite ] . y ,
sprite [ nSpiritSprite ] . z ,
128 ) ;
nHeadStage = 3 ;
2019-10-12 21:09:55 +00:00
TintPalette ( 255 , 255 , 255 ) ;
2019-08-27 06:08:18 +00:00
CopyHeadToWorkTile ( kTileRamsesNormal ) ;
}
return 1 ;
}
}
else
{
FixPalette ( ) ;
if ( ! nPalDiff )
{
nFreeze = 2 ;
nHeadStage + + ;
}
return 0 ;
}
}
else
{
2019-09-06 05:18:12 +00:00
if ( lNextStateChange < = ( int ) totalclock )
2019-08-27 06:08:18 +00:00
{
if ( nPupData )
{
short nPupVal = * pPupData ;
pPupData + + ;
nPupData - = 2 ;
if ( nPupData > 0 )
{
lNextStateChange = ( nPupVal + lHeadStartClock ) - 10 ;
nTalkTime = ! nTalkTime ;
}
else
{
nTalkTime = 0 ;
nPupData = 0 ;
}
}
else if ( ! bSubTitles )
{
if ( ! CDplaying ( ) )
{
levelnew = levelnum + 1 ;
fadecdaudio ( ) ;
}
}
}
word_964E8 - - ;
if ( word_964E8 < = 0 )
{
word_964EA = RandomBit ( ) * 2 ;
word_964E8 = RandomSize ( 5 ) + 4 ;
}
int ebx = 592 ;
word_964EC - - ;
if ( word_964EC < 3 )
{
ebx = 593 ;
if ( word_964EC < = 0 ) {
word_964EC = RandomSize ( 6 ) + 4 ;
}
}
ebx + = word_964EA ;
2019-11-24 15:34:23 +00:00
uint8_t * pDest = & Worktile [ 10441 ] ;
2019-11-24 12:59:36 +00:00
const uint8_t * pSrc = tilePtr ( ebx ) ;
2019-08-27 06:08:18 +00:00
for ( int i = 0 ; i < 97 ; i + + )
{
memcpy ( pDest , pSrc , 106 ) ;
2019-11-20 16:21:32 +00:00
2019-08-27 06:08:18 +00:00
pDest + = 212 ;
pSrc + = 106 ;
}
if ( nTalkTime )
{
if ( nMouthTile < 2 ) {
nMouthTile + + ;
}
}
else if ( nMouthTile ! = 0 )
{
nMouthTile - - ;
}
if ( nMouthTile )
{
short nTileSizeX = tilesiz [ nMouthTile + 598 ] . x ;
short nTileSizeY = tilesiz [ nMouthTile + 598 ] . y ;
2019-08-26 03:59:14 +00:00
2019-11-24 15:34:23 +00:00
uint8_t * pDest = & Worktile [ 212 * ( 97 - nTileSizeX / 2 ) ] + ( 159 - nTileSizeY ) ;
2019-11-24 12:59:36 +00:00
const uint8_t * pSrc = tilePtr ( nMouthTile + 598 ) ;
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
while ( nTileSizeX > 0 )
{
memcpy ( pDest , pSrc , nTileSizeY ) ;
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
nTileSizeX - - ;
pDest + = 212 ;
pSrc + = nTileSizeY ;
}
}
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
return 1 ;
}
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
// TEMP FIXME - temporary return value. what to return here? 1?
2019-08-26 03:59:14 +00:00
2019-08-27 06:08:18 +00:00
return 0 ;
2019-08-26 03:59:14 +00:00
}
2019-12-12 23:19:34 +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-16 00:55:50 +00:00
#if 0
2020-01-01 08:49:06 +00:00
void GameInterface : : UpdateScreenSize ( )
{
2020-08-16 00:55:50 +00:00
if ( hud_size = = 8 )
{
if ( ! bFullScreen )
{
bFullScreen = true ;
screensize = 0 ;
UnMaskStatus ( ) ;
}
}
else
{
screensize = ( 7 - clamp ( * hud_size , 0 , 7 ) ) * 2 ;
bFullScreen = false ;
Powerslave : : UpdateScreenSize ( ) ;
}
2020-01-01 08:49:06 +00:00
}
2020-08-16 00:55:50 +00:00
# endif
2020-01-01 08:49:06 +00:00
2019-12-27 09:52:40 +00:00
2019-12-12 23:19:34 +00:00
: : GameInterface * CreateInterface ( )
{
return new GameInterface ;
}
2019-12-26 21:00:04 +00:00
//short lastlevel;
//short forcelevel = -1;
//int lLocalCodes = 0;
//int flash;
//short textpages;
// This is only the static global data.
static SavegameHelper sgh ( " exhumed " ,
SA ( cPupData ) ,
SV ( nPupData ) ,
SV ( nPixels ) ,
SA ( curx ) ,
SA ( cury ) ,
SA ( destvelx ) ,
SA ( destvely ) ,
SA ( pixelval ) ,
SA ( origy ) ,
SA ( origx ) ,
SA ( velx ) ,
SA ( vely ) ,
SV ( nMouthTile ) ,
SV ( nSpiritSprite ) ,
SV ( word_964E8 ) ,
SV ( word_964EA ) ,
SV ( word_964EC ) ,
SV ( nSpiritRepeatX ) ,
SV ( nSpiritRepeatY ) ,
SV ( nPixelsToShow ) ,
SV ( nCreaturesLeft ) , // todo: also maintain a total counter.
SV ( nFreeze ) ,
SV ( nSnakeCam ) ,
SV ( nLocalSpr ) ,
SV ( levelnew ) ,
SV ( nClockVal ) , // kTile3603
SV ( nRedTicks ) ,
SV ( nAlarmTicks ) ,
SV ( nButtonColor ) ,
SV ( nEnergyChan ) ,
SV ( lCountDown ) ,
SV ( nEnergyTowers ) ,
SV ( nHeadStage ) ,
SV ( nTalkTime ) ,
SV ( levelnum ) ,
SV ( moveframes ) ,
SV ( totalmoves ) ,
SV ( nCurBodyNum ) ,
SV ( nBodyTotal ) ,
SV ( bSnakeCam ) ,
SV ( bSlipMode ) ,
2019-12-26 22:17:11 +00:00
SV ( lHeadStartClock ) ,
SV ( lNextStateChange ) ,
SV ( nHeadTimeStart ) ,
SV ( localclock ) ,
SV ( tclocks ) ,
SV ( tclocks2 ) ,
SV ( totalclock ) ,
2019-12-26 21:00:04 +00:00
nullptr ) ;
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
2019-12-12 23:19:34 +00:00
2019-11-22 23:11:37 +00:00
END_PS_NS