2015-05-19 21:54:34 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
/*
|
|
|
|
Copyright (C) 1997, 2005 - 3D Realms Entertainment
|
|
|
|
|
|
|
|
This file is part of Shadow Warrior version 1.2
|
|
|
|
|
|
|
|
Shadow Warrior is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
Original Source: 1997 - Frank Maddin and Jim Norwood
|
|
|
|
Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms
|
|
|
|
*/
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
2019-10-09 16:09:05 +00:00
|
|
|
#include "ns.h"
|
2015-05-19 21:54:34 +00:00
|
|
|
|
|
|
|
#define MAIN
|
|
|
|
#define QUIET
|
|
|
|
#include "build.h"
|
|
|
|
#include "names2.h"
|
|
|
|
#include "panel.h"
|
|
|
|
#include "game.h"
|
2020-04-13 21:13:38 +00:00
|
|
|
#include "interp.h"
|
2020-05-01 11:29:12 +00:00
|
|
|
#include "interpso.h"
|
2015-05-19 21:54:34 +00:00
|
|
|
#include "tags.h"
|
|
|
|
#include "sector.h"
|
|
|
|
#include "sprite.h"
|
|
|
|
#include "weapon.h"
|
|
|
|
#include "player.h"
|
|
|
|
#include "lists.h"
|
2019-03-21 02:24:19 +00:00
|
|
|
#include "network.h"
|
2015-05-19 21:54:34 +00:00
|
|
|
#include "pal.h"
|
2019-12-24 12:21:36 +00:00
|
|
|
|
2015-05-19 21:54:34 +00:00
|
|
|
|
|
|
|
#include "mytypes.h"
|
|
|
|
|
|
|
|
#include "menus.h"
|
|
|
|
|
2019-10-25 22:32:49 +00:00
|
|
|
#include "gamecontrol.h"
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2020-08-05 15:07:19 +00:00
|
|
|
#include "misc.h"
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2020-08-05 15:07:19 +00:00
|
|
|
#include "misc.h"
|
2015-05-19 21:54:34 +00:00
|
|
|
#include "break.h"
|
|
|
|
#include "light.h"
|
2020-08-05 22:18:45 +00:00
|
|
|
#include "misc.h"
|
2015-05-19 21:54:34 +00:00
|
|
|
#include "jsector.h"
|
|
|
|
|
2015-05-19 22:07:18 +00:00
|
|
|
#include "common.h"
|
2019-10-27 15:53:00 +00:00
|
|
|
#include "gameconfigfile.h"
|
2019-11-01 07:24:10 +00:00
|
|
|
#include "printf.h"
|
2019-11-01 18:25:42 +00:00
|
|
|
#include "m_argv.h"
|
2019-11-30 09:07:25 +00:00
|
|
|
#include "debugbreak.h"
|
2020-06-14 16:57:55 +00:00
|
|
|
#include "menu.h"
|
2020-04-12 06:07:48 +00:00
|
|
|
#include "raze_music.h"
|
2019-12-08 23:55:30 +00:00
|
|
|
#include "statistics.h"
|
2019-12-09 20:19:05 +00:00
|
|
|
#include "gstrings.h"
|
2019-12-11 01:01:11 +00:00
|
|
|
#include "mapinfo.h"
|
2020-04-28 21:11:33 +00:00
|
|
|
#include "v_video.h"
|
2020-04-12 06:09:38 +00:00
|
|
|
#include "raze_sound.h"
|
2020-02-22 07:56:36 +00:00
|
|
|
#include "secrets.h"
|
2015-05-19 22:05:20 +00:00
|
|
|
|
2020-08-15 08:55:21 +00:00
|
|
|
#include "screenjob.h"
|
|
|
|
#include "inputstate.h"
|
|
|
|
#include "gamestate.h"
|
2020-09-02 18:56:09 +00:00
|
|
|
#include "d_net.h"
|
2020-01-23 10:50:12 +00:00
|
|
|
|
2019-10-09 17:58:09 +00:00
|
|
|
//#include "crc32.h"
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2020-09-02 23:32:51 +00:00
|
|
|
CVAR(Bool, sw_ninjahack, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_SERVERINFO);
|
2020-08-05 15:07:19 +00:00
|
|
|
CVAR(Bool, sw_darts, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG);
|
2020-09-02 23:32:51 +00:00
|
|
|
CVAR(Bool, sw_bunnyrockets, false, CVAR_SERVERINFO | CVAR_CHEAT); // This is a cheat, so don't save.
|
2020-08-05 15:07:19 +00:00
|
|
|
|
2019-10-09 16:09:05 +00:00
|
|
|
BEGIN_SW_NS
|
|
|
|
|
2020-08-16 18:10:26 +00:00
|
|
|
void Logo(const CompletionFunc& completion);
|
2020-08-16 19:55:26 +00:00
|
|
|
void StatScreen(int FinishAnim, CompletionFunc completion);
|
2020-08-26 15:12:48 +00:00
|
|
|
void getinput(InputPacket*, SWBOOL);
|
2020-08-16 18:10:26 +00:00
|
|
|
|
|
|
|
|
2019-10-09 17:58:09 +00:00
|
|
|
void pClearSpriteList(PLAYERp pp);
|
|
|
|
|
2020-02-02 07:53:10 +00:00
|
|
|
extern int sw_snd_scratch;
|
|
|
|
|
2020-07-13 20:20:14 +00:00
|
|
|
int GameVersion = 20;
|
2019-12-22 10:21:05 +00:00
|
|
|
|
2020-05-19 11:44:52 +00:00
|
|
|
int Follow_posx=0,Follow_posy=0;
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2020-08-16 19:55:26 +00:00
|
|
|
SWBOOL NoMeters = false;
|
2015-05-19 21:58:29 +00:00
|
|
|
SWBOOL FinishAnim = 0;
|
2020-08-16 19:55:26 +00:00
|
|
|
SWBOOL ReloadPrompt = false;
|
|
|
|
SWBOOL NewGame = false;
|
|
|
|
SWBOOL SavegameLoaded = false;
|
2015-05-19 21:54:34 +00:00
|
|
|
//Miscellaneous variables
|
2020-08-16 19:55:26 +00:00
|
|
|
SWBOOL FinishedLevel = false;
|
2015-05-19 21:54:34 +00:00
|
|
|
short screenpeek = 0;
|
|
|
|
|
2020-05-19 11:44:52 +00:00
|
|
|
void drawoverheadmap(int cposx, int cposy, int czoom, short cang);
|
2015-05-19 22:10:03 +00:00
|
|
|
SWBOOL PreCaching = TRUE;
|
2020-08-16 19:55:26 +00:00
|
|
|
int GodMode = false;
|
2015-05-19 21:54:34 +00:00
|
|
|
short Skill = 2;
|
|
|
|
short TotalKillable;
|
|
|
|
|
|
|
|
const GAME_SET gs_defaults =
|
|
|
|
{
|
|
|
|
// Network game settings
|
|
|
|
0, // GameType
|
|
|
|
0, // Monsters
|
2020-08-16 19:55:26 +00:00
|
|
|
false, // HurtTeammate
|
2015-05-19 21:54:34 +00:00
|
|
|
TRUE, // SpawnMarkers Markers
|
2020-08-16 19:55:26 +00:00
|
|
|
false, // TeamPlay
|
2015-05-19 21:54:34 +00:00
|
|
|
0, // Kill Limit
|
|
|
|
0, // Time Limit
|
|
|
|
0, // Color
|
|
|
|
TRUE, // nuke
|
|
|
|
};
|
|
|
|
GAME_SET gs;
|
|
|
|
|
2020-08-16 19:55:26 +00:00
|
|
|
SWBOOL PlayerTrackingMode = false;
|
|
|
|
SWBOOL SlowMode = false;
|
2015-05-19 21:58:29 +00:00
|
|
|
SWBOOL FrameAdvanceTics = 3;
|
|
|
|
|
2020-08-16 19:55:26 +00:00
|
|
|
SWBOOL DebugOperate = false;
|
2020-03-07 13:51:49 +00:00
|
|
|
void LoadingLevelScreen(void);
|
2015-05-19 21:58:29 +00:00
|
|
|
|
|
|
|
uint8_t FakeMultiNumPlayers;
|
2015-05-19 21:54:34 +00:00
|
|
|
|
|
|
|
int totalsynctics;
|
|
|
|
|
2020-08-15 13:29:47 +00:00
|
|
|
int OrigCommPlayers=0;
|
2015-05-19 21:58:29 +00:00
|
|
|
extern uint8_t CommPlayers;
|
|
|
|
extern SWBOOL CommEnabled;
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2020-08-16 19:55:26 +00:00
|
|
|
SWBOOL CameraTestMode = false;
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2019-11-17 17:02:17 +00:00
|
|
|
char ds[645]; // debug string
|
2015-05-19 21:54:34 +00:00
|
|
|
|
|
|
|
extern short NormalVisibility;
|
2020-08-16 19:55:26 +00:00
|
|
|
SWBOOL CommandSetup = false;
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2020-08-16 09:42:13 +00:00
|
|
|
char buffer[80], ch;
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2015-05-19 21:58:29 +00:00
|
|
|
uint8_t DebugPrintColor = 255;
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2020-08-16 16:18:56 +00:00
|
|
|
FString ThemeSongs[6];
|
|
|
|
int ThemeTrack[6];
|
2015-05-19 21:54:34 +00:00
|
|
|
|
|
|
|
/// L O C A L P R O T O T Y P E S /////////////////////////////////////////////////////////
|
2015-05-19 21:58:29 +00:00
|
|
|
void SybexScreen(void);
|
2015-05-19 21:54:34 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2020-08-16 16:18:56 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2020-08-23 15:47:05 +00:00
|
|
|
void GameInterface::app_init()
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
2020-08-23 15:47:05 +00:00
|
|
|
GameTicRate = 40;
|
2020-08-16 17:11:04 +00:00
|
|
|
InitCheats();
|
|
|
|
automapping = 1;
|
|
|
|
|
|
|
|
gs = gs_defaults;
|
|
|
|
|
|
|
|
for (int i = 0; i < MAX_SW_PLAYERS; i++)
|
|
|
|
INITLIST(&Player[i].PanelSpriteList);
|
|
|
|
|
|
|
|
DebugOperate = TRUE;
|
|
|
|
enginecompatibility_mode = ENGINECOMPATIBILITY_19961112;
|
|
|
|
|
|
|
|
if (SW_SHAREWARE)
|
|
|
|
Printf("SHADOW WARRIOR(tm) Version 1.2 (Shareware Version)\n");
|
|
|
|
else
|
|
|
|
Printf("SHADOW WARRIOR(tm) Version 1.2\n");
|
|
|
|
|
|
|
|
if (sw_snd_scratch == 0) // This is always 0 at this point - this check is only here to prevent whole program optimization from eliminating the variable.
|
|
|
|
Printf("Copyright (c) 1997 3D Realms Entertainment\n");
|
|
|
|
|
|
|
|
registerosdcommands();
|
|
|
|
|
2020-02-01 22:05:43 +00:00
|
|
|
engineInit();
|
2020-08-16 16:18:56 +00:00
|
|
|
auto pal = fileSystem.LoadFile("3drealms.pal", 0);
|
|
|
|
if (pal.Size() >= 768)
|
2020-04-12 05:50:24 +00:00
|
|
|
{
|
2020-08-16 16:18:56 +00:00
|
|
|
for (auto& c : pal)
|
|
|
|
c <<= 2;
|
2020-04-12 05:50:24 +00:00
|
|
|
|
2020-08-16 16:18:56 +00:00
|
|
|
paletteSetColorTable(DREALMSPAL, pal.Data(), true, true);
|
2020-04-12 05:50:24 +00:00
|
|
|
}
|
2015-05-19 21:54:34 +00:00
|
|
|
InitPalette();
|
|
|
|
// sets numplayers, connecthead, connectpoint2, myconnectindex
|
|
|
|
|
2019-11-19 21:35:52 +00:00
|
|
|
numplayers = 1; myconnectindex = 0;
|
|
|
|
connecthead = 0; connectpoint2[0] = -1;
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2020-08-16 16:18:56 +00:00
|
|
|
if (SW_SHAREWARE && numplayers > 4)
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
2020-08-16 16:18:56 +00:00
|
|
|
I_FatalError("To play a Network game with more than 4 players you must purchase "
|
|
|
|
"the full version. Read the Ordering Info screens for details.");
|
2015-05-19 21:54:34 +00:00
|
|
|
}
|
|
|
|
|
2020-08-15 14:41:08 +00:00
|
|
|
TileFiles.LoadArtSet("tiles%03d.art");
|
2020-08-15 18:29:13 +00:00
|
|
|
InitFonts();
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2020-08-16 08:40:20 +00:00
|
|
|
//Connect();
|
2015-05-19 21:54:34 +00:00
|
|
|
SortBreakInfo();
|
|
|
|
parallaxtype = 1;
|
2015-05-19 22:05:20 +00:00
|
|
|
SW_InitMultiPsky();
|
2015-05-19 21:54:34 +00:00
|
|
|
|
|
|
|
memset(Track, 0, sizeof(Track));
|
|
|
|
memset(Player, 0, sizeof(Player));
|
2020-08-16 16:18:56 +00:00
|
|
|
for (int i = 0; i < MAX_SW_PLAYERS; i++)
|
2015-05-19 21:54:34 +00:00
|
|
|
INITLIST(&Player[i].PanelSpriteList);
|
|
|
|
|
|
|
|
LoadKVXFromScript("swvoxfil.txt"); // Load voxels from script file
|
|
|
|
LoadPLockFromScript("swplock.txt"); // Get Parental Lock setup info
|
2019-12-26 13:04:53 +00:00
|
|
|
LoadCustomInfoFromScript("engine/swcustom.txt"); // load the internal definitions. These also apply to the shareware version.
|
2015-05-19 21:54:34 +00:00
|
|
|
if (!SW_SHAREWARE)
|
|
|
|
LoadCustomInfoFromScript("swcustom.txt"); // Load user customisation information
|
2019-12-08 23:33:14 +00:00
|
|
|
|
2020-08-26 18:19:54 +00:00
|
|
|
if (!loaddefinitionsfile(G_DefFile())) Printf(PRINT_NONOTIFY, "Definitions file loaded.\n");
|
2020-09-01 22:36:49 +00:00
|
|
|
TileFiles.SetBackup();
|
|
|
|
userConfig.AddDefs.reset();
|
2020-08-16 16:18:56 +00:00
|
|
|
InitFX();
|
2015-05-19 21:54:34 +00:00
|
|
|
}
|
|
|
|
|
2020-08-16 16:18:56 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2020-09-02 18:56:09 +00:00
|
|
|
void GameInterface::DrawBackground(void)
|
2020-08-16 18:10:26 +00:00
|
|
|
{
|
|
|
|
const int TITLE_PIC = 2324;
|
|
|
|
twod->ClearScreen();
|
|
|
|
DrawTexture(twod, tileGetTexture(TITLE_PIC), 0, 0, DTA_FullscreenEx, FSMode_ScaleToFit43, DTA_LegacyRenderStyle, STYLE_Normal,
|
|
|
|
DTA_Color, shadeToLight(20), TAG_DONE);
|
|
|
|
|
|
|
|
if (CommEnabled)
|
|
|
|
{
|
2020-08-16 19:55:26 +00:00
|
|
|
MNU_DrawString(160, 170, "Lo Wang is waiting for other players...", 1, 16, 0);
|
|
|
|
MNU_DrawString(160, 180, "They are afraid!", 1, 16, 0);
|
2020-08-16 16:18:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2020-08-16 16:18:56 +00:00
|
|
|
void InitLevelGlobals(void)
|
|
|
|
{
|
2015-05-19 21:54:34 +00:00
|
|
|
ChopTics = 0;
|
2020-08-24 17:36:17 +00:00
|
|
|
automapMode = am_off;
|
2020-09-02 16:59:56 +00:00
|
|
|
zoom = 768 / 2;
|
2015-05-19 21:54:34 +00:00
|
|
|
PlayerGravity = 24;
|
|
|
|
wait_active_check_offset = 0;
|
|
|
|
PlaxCeilGlobZadjust = PlaxFloorGlobZadjust = Z(500);
|
2020-08-16 19:55:26 +00:00
|
|
|
FinishedLevel = false;
|
2015-05-19 21:54:34 +00:00
|
|
|
AnimCnt = 0;
|
2020-08-16 19:55:26 +00:00
|
|
|
left_foot = false;
|
2015-05-19 21:54:34 +00:00
|
|
|
screenpeek = myconnectindex;
|
2020-04-13 21:13:38 +00:00
|
|
|
numinterpolations = short_numinterpolations = 0;
|
2015-05-19 21:54:34 +00:00
|
|
|
|
|
|
|
gNet.TimeLimitClock = gNet.TimeLimit;
|
|
|
|
|
2020-08-16 19:55:26 +00:00
|
|
|
serpwasseen = false;
|
|
|
|
sumowasseen = false;
|
|
|
|
zillawasseen = false;
|
2015-05-19 21:54:34 +00:00
|
|
|
memset(BossSpriteNum,-1,sizeof(BossSpriteNum));
|
|
|
|
}
|
|
|
|
|
2020-08-16 16:18:56 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// GLOBAL RESETS NOT DONE for LOAD GAME
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2015-05-19 21:58:29 +00:00
|
|
|
void InitLevelGlobals2(void)
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
|
|
|
InitTimingVars();
|
|
|
|
TotalKillable = 0;
|
|
|
|
Bunny_Count = 0;
|
2020-07-13 20:20:14 +00:00
|
|
|
FinishAnim = 0;
|
2015-05-19 21:54:34 +00:00
|
|
|
}
|
|
|
|
|
2020-08-16 16:18:56 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2020-09-04 19:15:15 +00:00
|
|
|
void InitLevel(MapRecord *maprec)
|
2020-08-16 19:55:26 +00:00
|
|
|
{
|
|
|
|
Terminate3DSounds();
|
|
|
|
|
|
|
|
// A few IMPORTANT GLOBAL RESETS
|
|
|
|
InitLevelGlobals();
|
|
|
|
|
|
|
|
Mus_Stop();
|
|
|
|
|
|
|
|
if (!maprec)
|
|
|
|
{
|
|
|
|
I_Error("Attempt to start game without level");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
InitLevelGlobals2();
|
|
|
|
|
|
|
|
if (NewGame)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < MAX_SW_PLAYERS; i++)
|
|
|
|
{
|
|
|
|
// don't jack with the playerreadyflag
|
|
|
|
int ready_bak = Player[i].playerreadyflag;
|
|
|
|
int ver_bak = Player[i].PlayerVersion;
|
|
|
|
memset(&Player[i], 0, sizeof(Player[i]));
|
|
|
|
Player[i].playerreadyflag = ready_bak;
|
|
|
|
Player[i].PlayerVersion = ver_bak;
|
|
|
|
INITLIST(&Player[i].PanelSpriteList);
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(puser, 0, sizeof(puser));
|
|
|
|
}
|
|
|
|
|
|
|
|
int16_t ang;
|
|
|
|
if (engineLoadBoard(maprec->fileName, SW_SHAREWARE ? 1 : 0, (vec3_t*)&Player[0], &ang, &Player[0].cursectnum) == -1)
|
|
|
|
{
|
|
|
|
I_Error("Map not found: %s", maprec->fileName.GetChars());
|
|
|
|
}
|
|
|
|
currentLevel = maprec;
|
|
|
|
SECRET_SetMapName(currentLevel->DisplayName(), currentLevel->name);
|
|
|
|
STAT_NewLevel(currentLevel->fileName);
|
2020-09-01 13:00:35 +00:00
|
|
|
Player[0].q16ang = IntToFixed(ang);
|
2020-08-16 19:55:26 +00:00
|
|
|
|
|
|
|
SetupPreCache();
|
|
|
|
|
|
|
|
if (sector[0].extra != -1)
|
|
|
|
{
|
|
|
|
NormalVisibility = g_visibility = sector[0].extra;
|
|
|
|
sector[0].extra = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
NormalVisibility = g_visibility;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Do Player stuff first
|
|
|
|
//
|
|
|
|
|
|
|
|
InitAllPlayers();
|
|
|
|
|
|
|
|
QueueReset();
|
|
|
|
PreMapCombineFloors();
|
|
|
|
InitMultiPlayerInfo();
|
|
|
|
InitAllPlayerSprites();
|
|
|
|
|
|
|
|
//
|
|
|
|
// Do setup for sprite, track, panel, sector, etc
|
|
|
|
//
|
|
|
|
|
|
|
|
// Set levels up
|
|
|
|
InitTimingVars();
|
|
|
|
|
|
|
|
SpriteSetup();
|
|
|
|
SpriteSetupPost(); // post processing - already gone once through the loop
|
|
|
|
InitLighting();
|
|
|
|
|
|
|
|
TrackSetup();
|
|
|
|
|
|
|
|
PlayerPanelSetup();
|
|
|
|
SectorSetup();
|
|
|
|
JS_InitMirrors();
|
|
|
|
JS_InitLockouts(); // Setup the lockout linked lists
|
|
|
|
JS_ToggleLockouts(); // Init lockouts on/off
|
|
|
|
|
|
|
|
PlaceSectorObjectsOnTracks();
|
|
|
|
PlaceActorsOnTracks();
|
|
|
|
PostSetupSectorObject();
|
|
|
|
SetupMirrorTiles();
|
|
|
|
initlava();
|
|
|
|
|
|
|
|
// reset NewGame
|
|
|
|
NewGame = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2020-08-16 16:18:56 +00:00
|
|
|
void InitPlayerGameSettings(void)
|
|
|
|
{
|
|
|
|
int pnum;
|
|
|
|
|
|
|
|
if (CommEnabled)
|
|
|
|
{
|
|
|
|
// everyone gets the same Auto Aim
|
|
|
|
TRAVERSE_CONNECT(pnum)
|
|
|
|
{
|
|
|
|
if (gNet.AutoAim)
|
|
|
|
SET(Player[pnum].Flags, PF_AUTO_AIM);
|
|
|
|
else
|
|
|
|
RESET(Player[pnum].Flags, PF_AUTO_AIM);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (cl_autoaim)
|
|
|
|
SET(Player[myconnectindex].Flags, PF_AUTO_AIM);
|
|
|
|
else
|
|
|
|
RESET(Player[myconnectindex].Flags, PF_AUTO_AIM);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void InitRunLevel(void)
|
|
|
|
{
|
|
|
|
Mus_Stop();
|
|
|
|
|
|
|
|
DoTheCache();
|
|
|
|
|
|
|
|
// auto aim / auto run / etc
|
|
|
|
InitPlayerGameSettings();
|
|
|
|
|
|
|
|
// send packets with player info
|
|
|
|
InitNetPlayerOptions();
|
|
|
|
|
2020-09-04 18:48:29 +00:00
|
|
|
// Initialize Game part of network code
|
2020-08-16 16:18:56 +00:00
|
|
|
InitNetVars();
|
|
|
|
|
|
|
|
if (currentLevel)
|
|
|
|
{
|
|
|
|
PlaySong(currentLevel->labelName, currentLevel->music, currentLevel->cdSongId);
|
|
|
|
}
|
|
|
|
|
|
|
|
InitPrediction(&Player[myconnectindex]);
|
|
|
|
|
|
|
|
InitTimingVars();
|
|
|
|
|
|
|
|
if (snd_ambience)
|
|
|
|
StartAmbientSound();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2020-08-16 19:55:26 +00:00
|
|
|
void TerminateLevel(void)
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
2020-08-19 15:31:05 +00:00
|
|
|
videoFadePalette(0, 0, 0, 0);
|
2020-08-16 14:00:40 +00:00
|
|
|
if (!currentLevel) return;
|
|
|
|
|
2015-05-19 21:54:34 +00:00
|
|
|
int i, nexti, stat, pnum, ndx;
|
2020-08-16 19:55:26 +00:00
|
|
|
SECT_USERp* sectu;
|
2015-05-19 21:54:34 +00:00
|
|
|
|
|
|
|
// Free any track points
|
|
|
|
for (ndx = 0; ndx < MAX_TRACKS; ndx++)
|
|
|
|
{
|
|
|
|
if (Track[ndx].TrackPoint)
|
|
|
|
{
|
|
|
|
FreeMem(Track[ndx].TrackPoint);
|
|
|
|
// !JIM! I added null assigner
|
|
|
|
Track[ndx].TrackPoint = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clear the tracks
|
|
|
|
memset(Track, 0, sizeof(Track));
|
|
|
|
|
2020-02-11 06:35:28 +00:00
|
|
|
StopFX();
|
2020-08-16 19:55:26 +00:00
|
|
|
|
2015-05-19 21:54:34 +00:00
|
|
|
// Clear all anims and any memory associated with them
|
|
|
|
// Clear before killing sprites - save a little time
|
|
|
|
//AnimClear();
|
|
|
|
|
|
|
|
for (stat = STAT_PLAYER0; stat < STAT_PLAYER0 + numplayers; stat++)
|
|
|
|
{
|
|
|
|
|
|
|
|
pnum = stat - STAT_PLAYER0;
|
|
|
|
|
|
|
|
TRAVERSE_SPRITE_STAT(headspritestat[stat], i, nexti)
|
|
|
|
{
|
|
|
|
if (User[i])
|
|
|
|
memcpy(&puser[pnum], User[i], sizeof(USER));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Kill User memory and delete sprites
|
|
|
|
// for (stat = 0; stat < STAT_ALL; stat++)
|
|
|
|
for (stat = 0; stat < MAXSTATUS; stat++)
|
|
|
|
{
|
|
|
|
TRAVERSE_SPRITE_STAT(headspritestat[stat], i, nexti)
|
|
|
|
{
|
|
|
|
KillSprite(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Free SectUser memory
|
|
|
|
for (sectu = &SectUser[0];
|
2020-08-16 19:55:26 +00:00
|
|
|
sectu < &SectUser[MAXSECTORS];
|
|
|
|
sectu++)
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
|
|
|
if (*sectu)
|
|
|
|
{
|
|
|
|
FreeMem(*sectu);
|
|
|
|
*sectu = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//memset(&User[0], 0, sizeof(User));
|
|
|
|
memset(&SectUser[0], 0, sizeof(SectUser));
|
|
|
|
|
|
|
|
TRAVERSE_CONNECT(pnum)
|
|
|
|
{
|
|
|
|
PLAYERp pp = Player + pnum;
|
|
|
|
|
|
|
|
// Free panel sprites for players
|
|
|
|
pClearSpriteList(pp);
|
|
|
|
|
2020-08-17 20:05:14 +00:00
|
|
|
pp->cookieTime = 0;
|
|
|
|
memset(pp->cookieQuote, 0, sizeof(pp->cookieQuote));
|
2015-05-19 21:54:34 +00:00
|
|
|
pp->DoPlayerAction = NULL;
|
|
|
|
|
|
|
|
pp->SpriteP = NULL;
|
|
|
|
pp->PlayerSprite = -1;
|
|
|
|
|
|
|
|
pp->UnderSpriteP = NULL;
|
|
|
|
pp->PlayerUnderSprite = -1;
|
|
|
|
|
|
|
|
memset(pp->HasKey, 0, sizeof(pp->HasKey));
|
|
|
|
|
|
|
|
//pp->WpnFlags = 0;
|
|
|
|
pp->CurWpn = NULL;
|
|
|
|
|
|
|
|
memset(pp->Wpn, 0, sizeof(pp->Wpn));
|
|
|
|
memset(pp->InventoryTics, 0, sizeof(pp->InventoryTics));
|
|
|
|
|
|
|
|
pp->Killer = -1;
|
|
|
|
|
|
|
|
INITLIST(&pp->PanelSpriteList);
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_UnInitLockouts();
|
|
|
|
}
|
|
|
|
|
2020-09-04 19:15:15 +00:00
|
|
|
|
|
|
|
void GameInterface::LevelCompleted(MapRecord *map, int skill)
|
|
|
|
{
|
|
|
|
//ResetPalette(mpp);
|
|
|
|
COVER_SetReverb(0); // Reset reverb
|
|
|
|
Player[myconnectindex].Reverb = 0;
|
|
|
|
StopSound();
|
|
|
|
|
|
|
|
StatScreen(FinishAnim, [=](bool)
|
|
|
|
{
|
|
|
|
if (map == nullptr)
|
|
|
|
{
|
|
|
|
STAT_Update(true);
|
|
|
|
FinishAnim = 0;
|
|
|
|
PlaySong(nullptr, ThemeSongs[0], ThemeTrack[0]);
|
|
|
|
if (SW_SHAREWARE) gameaction = ga_creditsmenu;
|
|
|
|
else gameaction = ga_mainmenu;
|
|
|
|
}
|
|
|
|
else gameaction = ga_nextlevel;
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
2020-08-16 19:55:26 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2020-09-04 19:15:15 +00:00
|
|
|
void GameInterface::NextLevel(MapRecord *map, int skill)
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
2020-09-04 19:15:15 +00:00
|
|
|
if (skill != -1) Skill = skill;
|
|
|
|
ShadowWarrior::NewGame = false;
|
|
|
|
InitLevel(map);
|
|
|
|
InitRunLevel();
|
|
|
|
}
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2020-09-04 19:15:15 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2020-09-04 19:15:15 +00:00
|
|
|
void GameInterface::NewGame(MapRecord *map, int skill)
|
|
|
|
{
|
|
|
|
if (skill != -1) Skill = skill;
|
|
|
|
ShadowWarrior::NewGame = true;
|
|
|
|
InitLevel(map);
|
|
|
|
InitRunLevel();
|
2020-08-16 19:55:26 +00:00
|
|
|
}
|
2020-08-16 17:11:04 +00:00
|
|
|
|
2020-08-16 19:55:26 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2020-09-02 18:56:09 +00:00
|
|
|
void GameInterface::Ticker(void)
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
2020-09-04 19:15:15 +00:00
|
|
|
if (SavegameLoaded)
|
|
|
|
{
|
|
|
|
InitLevelGlobals();
|
|
|
|
SavegameLoaded = false;
|
|
|
|
// contains what is needed from calls below
|
|
|
|
if (snd_ambience)
|
|
|
|
StartAmbientSound();
|
|
|
|
}
|
2020-08-16 17:11:04 +00:00
|
|
|
|
2020-09-02 18:56:09 +00:00
|
|
|
int i;
|
|
|
|
TRAVERSE_CONNECT(i)
|
|
|
|
{
|
|
|
|
auto pp = Player + i;
|
|
|
|
pp->lastinput = pp->input;
|
|
|
|
pp->input = playercmds[i].ucmd;
|
|
|
|
}
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2020-09-02 18:56:09 +00:00
|
|
|
domovethings();
|
|
|
|
r_NoInterpolate = paused;
|
2015-05-19 21:54:34 +00:00
|
|
|
}
|
|
|
|
|
2020-09-02 18:56:09 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
2020-08-16 19:55:26 +00:00
|
|
|
|
2020-09-02 18:56:09 +00:00
|
|
|
void GameInterface::Render()
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
2020-09-02 18:56:09 +00:00
|
|
|
if (paused)
|
2020-08-16 18:10:26 +00:00
|
|
|
{
|
2020-09-02 18:56:09 +00:00
|
|
|
smoothratio = MaxSmoothRatio;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
smoothratio = I_GetTimeFrac() * MaxSmoothRatio;
|
|
|
|
}
|
2020-08-16 18:10:26 +00:00
|
|
|
|
2020-09-02 18:56:09 +00:00
|
|
|
drawtime.Reset();
|
|
|
|
drawtime.Clock();
|
|
|
|
drawscreen(Player + screenpeek, smoothratio);
|
|
|
|
drawtime.Unclock();
|
|
|
|
}
|
2020-08-16 18:10:26 +00:00
|
|
|
|
|
|
|
|
2020-09-02 18:56:09 +00:00
|
|
|
void GameInterface::Startup()
|
|
|
|
{
|
|
|
|
if (userConfig.CommandMap.IsNotEmpty())
|
|
|
|
{
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-09-04 19:15:15 +00:00
|
|
|
if (!userConfig.nologo) Logo([](bool) { gameaction = ga_mainmenu; });
|
|
|
|
else gameaction = ga_mainmenu;
|
2020-08-16 18:10:26 +00:00
|
|
|
}
|
2015-05-19 21:54:34 +00:00
|
|
|
}
|
|
|
|
|
2020-08-29 22:55:49 +00:00
|
|
|
|
|
|
|
void GameInterface::ErrorCleanup()
|
|
|
|
{
|
|
|
|
// Make sure we do not leave the game in an unstable state
|
|
|
|
TerminateLevel();
|
|
|
|
SavegameLoaded = false;
|
|
|
|
FinishAnim = 0;
|
|
|
|
}
|
2020-08-16 17:11:04 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2019-11-17 17:02:17 +00:00
|
|
|
int RandomRange(int range)
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
2015-05-19 21:58:29 +00:00
|
|
|
uint32_t rand_num;
|
|
|
|
uint32_t value;
|
2015-05-19 21:54:34 +00:00
|
|
|
|
|
|
|
if (range <= 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
rand_num = RANDOM();
|
|
|
|
|
|
|
|
if (rand_num == 65535U)
|
|
|
|
rand_num--;
|
|
|
|
|
|
|
|
// shift values to give more precision
|
|
|
|
value = (rand_num << 14) / ((65535UL << 14) / range);
|
|
|
|
|
2015-05-19 21:58:29 +00:00
|
|
|
if (value >= (uint32_t)range)
|
2015-05-19 21:54:34 +00:00
|
|
|
value = range - 1;
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2020-08-16 17:11:04 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2019-11-17 17:02:17 +00:00
|
|
|
int StdRandomRange(int range)
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
2015-05-19 21:58:29 +00:00
|
|
|
uint32_t rand_num;
|
|
|
|
uint32_t value;
|
2015-05-19 21:54:34 +00:00
|
|
|
|
|
|
|
if (range <= 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
rand_num = STD_RANDOM();
|
|
|
|
|
|
|
|
if (rand_num == RAND_MAX)
|
|
|
|
rand_num--;
|
|
|
|
|
|
|
|
// shift values to give more precision
|
|
|
|
#if (RAND_MAX > 0x7fff)
|
|
|
|
value = rand_num / (((int)RAND_MAX) / range);
|
|
|
|
#else
|
|
|
|
value = (rand_num << 14) / ((((int)RAND_MAX) << 14) / range);
|
|
|
|
#endif
|
|
|
|
|
2015-05-19 21:58:29 +00:00
|
|
|
if (value >= (uint32_t)range)
|
2015-05-19 21:54:34 +00:00
|
|
|
value = range - 1;
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2020-08-16 17:11:04 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2015-05-19 21:54:34 +00:00
|
|
|
#include "saveable.h"
|
|
|
|
|
2019-11-28 23:22:01 +00:00
|
|
|
saveable_module saveable_build{};
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2019-11-28 23:22:01 +00:00
|
|
|
void Saveable_Init_Dynamic()
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
2019-11-28 23:22:01 +00:00
|
|
|
static saveable_data saveable_build_data[] =
|
|
|
|
{
|
|
|
|
{sector, MAXSECTORS*sizeof(sectortype)},
|
|
|
|
{sprite, MAXSPRITES*sizeof(spritetype)},
|
|
|
|
{wall, MAXWALLS*sizeof(walltype)},
|
|
|
|
};
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2019-11-28 23:22:01 +00:00
|
|
|
saveable_build.data = saveable_build_data;
|
|
|
|
saveable_build.numdata = NUM_SAVEABLE_ITEMS(saveable_build_data);
|
|
|
|
}
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2020-08-16 17:11:04 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2020-08-16 00:55:50 +00:00
|
|
|
ReservedSpace GameInterface::GetReservedScreenSpace(int viewsize)
|
2019-12-07 20:39:17 +00:00
|
|
|
{
|
2020-08-16 00:55:50 +00:00
|
|
|
return { 0, 48 };
|
2019-12-07 20:39:17 +00:00
|
|
|
}
|
2020-08-13 16:19:44 +00:00
|
|
|
|
2019-11-03 11:32:58 +00:00
|
|
|
::GameInterface* CreateInterface()
|
2019-11-06 18:22:14 +00:00
|
|
|
{
|
2019-11-03 11:32:58 +00:00
|
|
|
return new GameInterface;
|
2019-11-06 18:22:14 +00:00
|
|
|
}
|
|
|
|
|
2019-12-08 23:55:30 +00:00
|
|
|
GameStats GameInterface::getStats()
|
2019-11-03 11:32:58 +00:00
|
|
|
{
|
2019-12-08 23:55:30 +00:00
|
|
|
PLAYERp pp = Player + myconnectindex;
|
|
|
|
return { pp->Kills, TotalKillable, pp->SecretsFound, LevelSecrets, PlayClock / 120, 0 };
|
2019-11-03 11:32:58 +00:00
|
|
|
}
|
|
|
|
|
2019-12-25 10:26:19 +00:00
|
|
|
void GameInterface::FreeGameData()
|
|
|
|
{
|
|
|
|
TerminateLevel();
|
|
|
|
}
|
|
|
|
|
2020-09-03 21:10:28 +00:00
|
|
|
void GameInterface::FreeLevelData()
|
|
|
|
{
|
|
|
|
TerminateLevel();
|
|
|
|
::GameInterface::FreeLevelData();
|
|
|
|
}
|
|
|
|
|
2019-10-09 16:09:05 +00:00
|
|
|
END_SW_NS
|