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-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"
|
2020-09-06 10:44:58 +00:00
|
|
|
#include "automap.h"
|
2020-09-08 16:28:41 +00:00
|
|
|
#include "statusbar.h"
|
2020-10-06 19:35:26 +00:00
|
|
|
#include "texturemanager.h"
|
2021-05-31 21:16:52 +00:00
|
|
|
#include "st_start.h"
|
|
|
|
#include "i_interface.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"
|
|
|
|
|
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-10-04 16:31:48 +00:00
|
|
|
#include "razemenu.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
|
|
|
|
2021-05-21 23:34:00 +00:00
|
|
|
#include "screenjob_.h"
|
2020-08-15 08:55:21 +00:00
|
|
|
#include "inputstate.h"
|
|
|
|
#include "gamestate.h"
|
2020-09-02 18:56:09 +00:00
|
|
|
#include "d_net.h"
|
2020-10-04 16:31:48 +00:00
|
|
|
#include "v_draw.h"
|
2020-11-26 17:05:49 +00:00
|
|
|
#include "interpolate.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.
|
2019-04-08 06:28:54 +00:00
|
|
|
|
2019-10-09 16:09:05 +00:00
|
|
|
BEGIN_SW_NS
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2019-10-09 17:58:09 +00:00
|
|
|
void pClearSpriteList(PLAYERp pp);
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2020-02-02 07:53:10 +00:00
|
|
|
extern int sw_snd_scratch;
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2020-07-13 20:20:14 +00:00
|
|
|
int GameVersion = 20;
|
2019-12-22 10:21:05 +00:00
|
|
|
|
2020-09-09 18:32:24 +00:00
|
|
|
bool NoMeters = false;
|
2020-09-09 18:28:05 +00:00
|
|
|
int FinishAnim = 0;
|
2020-09-09 18:32:24 +00:00
|
|
|
bool ReloadPrompt = false;
|
|
|
|
bool NewGame = false;
|
2015-05-19 21:54:34 +00:00
|
|
|
//Miscellaneous variables
|
2020-09-09 18:32:24 +00:00
|
|
|
bool FinishedLevel = false;
|
2015-05-19 21:54:34 +00:00
|
|
|
short screenpeek = 0;
|
|
|
|
|
2020-08-16 19:55:26 +00:00
|
|
|
int GodMode = false;
|
2015-05-19 21:54:34 +00:00
|
|
|
short Skill = 2;
|
2021-11-21 20:47:37 +00:00
|
|
|
int TotalKillable;
|
2015-05-19 21:54:34 +00:00
|
|
|
|
|
|
|
const GAME_SET gs_defaults =
|
|
|
|
{
|
|
|
|
// Network game settings
|
|
|
|
0, // GameType
|
|
|
|
0, // Monsters
|
2020-08-16 19:55:26 +00:00
|
|
|
false, // HurtTeammate
|
2020-09-09 17:52:52 +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
|
2020-09-09 17:52:52 +00:00
|
|
|
true, // nuke
|
2015-05-19 21:54:34 +00:00
|
|
|
};
|
|
|
|
GAME_SET gs;
|
|
|
|
|
2020-09-09 18:32:24 +00:00
|
|
|
bool PlayerTrackingMode = false;
|
|
|
|
bool SlowMode = false;
|
2015-05-19 21:58:29 +00:00
|
|
|
|
2020-09-09 18:32:24 +00:00
|
|
|
bool 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;
|
2020-09-09 18:32:24 +00:00
|
|
|
extern bool CommEnabled;
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2020-09-09 18:32:24 +00:00
|
|
|
bool 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-09-09 18:32:24 +00:00
|
|
|
bool 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 /////////////////////////////////////////////////////////
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2020-10-06 19:35:26 +00:00
|
|
|
#define x(a, b) registerName(#a, b);
|
|
|
|
static void SetTileNames()
|
|
|
|
{
|
|
|
|
auto registerName = [](const char* name, int index)
|
|
|
|
{
|
|
|
|
TexMan.AddAlias(name, tileGetTexture(index));
|
|
|
|
};
|
|
|
|
#include "namelist.h"
|
|
|
|
}
|
|
|
|
#undef x
|
|
|
|
|
2021-06-01 09:05:26 +00:00
|
|
|
void GameInterface::LoadGameTextures()
|
|
|
|
{
|
|
|
|
LoadKVXFromScript("swvoxfil.txt"); // Load voxels from script file
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2021-11-28 23:40:42 +00:00
|
|
|
GameTicRate = TICS_PER_SEC / synctics;
|
2020-08-16 17:11:04 +00:00
|
|
|
InitCheats();
|
|
|
|
automapping = 1;
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2020-08-16 17:11:04 +00:00
|
|
|
gs = gs_defaults;
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2020-08-16 17:11:04 +00:00
|
|
|
for (int i = 0; i < MAX_SW_PLAYERS; i++)
|
|
|
|
INITLIST(&Player[i].PanelSpriteList);
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2020-09-09 17:52:52 +00:00
|
|
|
DebugOperate = true;
|
2020-08-16 17:11:04 +00:00
|
|
|
enginecompatibility_mode = ENGINECOMPATIBILITY_19961112;
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2020-08-16 17:11:04 +00:00
|
|
|
if (SW_SHAREWARE)
|
|
|
|
Printf("SHADOW WARRIOR(tm) Version 1.2 (Shareware Version)\n");
|
|
|
|
else
|
|
|
|
Printf("SHADOW WARRIOR(tm) Version 1.2\n");
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2020-08-16 17:11:04 +00:00
|
|
|
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");
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2020-08-16 17:11:04 +00:00
|
|
|
registerosdcommands();
|
2015-05-19 21:54:34 +00:00
|
|
|
|
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-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);
|
|
|
|
|
2021-11-14 12:33:35 +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-10-06 20:01:20 +00:00
|
|
|
SetTileNames();
|
2020-09-16 17:28:51 +00:00
|
|
|
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)
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
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);
|
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-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;
|
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-11-26 17:05:49 +00:00
|
|
|
ClearInterpolations();
|
2015-05-19 21:54:34 +00:00
|
|
|
|
|
|
|
gNet.TimeLimitClock = gNet.TimeLimit;
|
|
|
|
|
2021-05-02 15:35:25 +00:00
|
|
|
|
|
|
|
for (auto& b : bosswasseen) b = false;
|
2021-11-02 23:19:48 +00:00
|
|
|
memset(BossSpriteNum,0,sizeof(BossSpriteNum));
|
2015-05-19 21:54:34 +00:00
|
|
|
}
|
|
|
|
|
2020-08-16 16:18:56 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// GLOBAL RESETS NOT DONE for LOAD GAME
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
2015-05-19 21:54:34 +00:00
|
|
|
|
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-09-09 18:28:05 +00:00
|
|
|
FinishAnim = false;
|
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)
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
2020-08-16 19:55:26 +00:00
|
|
|
Terminate3DSounds();
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2020-08-16 19:55:26 +00:00
|
|
|
// A few IMPORTANT GLOBAL RESETS
|
|
|
|
InitLevelGlobals();
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2020-09-16 17:28:51 +00:00
|
|
|
Mus_Stop();
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2020-08-16 19:55:26 +00:00
|
|
|
if (!maprec)
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
2020-08-16 19:55:26 +00:00
|
|
|
I_Error("Attempt to start game without level");
|
|
|
|
return;
|
2020-09-16 17:28:51 +00:00
|
|
|
}
|
2020-08-16 19:55:26 +00:00
|
|
|
InitLevelGlobals2();
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2020-09-16 17:28:51 +00:00
|
|
|
if (NewGame)
|
|
|
|
{
|
2020-08-16 19:55:26 +00:00
|
|
|
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);
|
|
|
|
}
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2020-08-16 19:55:26 +00:00
|
|
|
memset(puser, 0, sizeof(puser));
|
2020-09-16 17:28:51 +00:00
|
|
|
}
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2020-08-16 19:55:26 +00:00
|
|
|
int16_t ang;
|
|
|
|
currentLevel = maprec;
|
2021-11-07 19:14:44 +00:00
|
|
|
engineLoadBoard(maprec->fileName, SW_SHAREWARE ? 1 : 0, &Player[0].pos, &ang, &Player[0].cursectnum);
|
2020-11-22 18:47:20 +00:00
|
|
|
|
2020-08-16 19:55:26 +00:00
|
|
|
SECRET_SetMapName(currentLevel->DisplayName(), currentLevel->name);
|
|
|
|
STAT_NewLevel(currentLevel->fileName);
|
2020-10-08 03:23:29 +00:00
|
|
|
Player[0].angle.ang = buildang(ang);
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2020-08-16 19:55:26 +00:00
|
|
|
if (sector[0].extra != -1)
|
2019-12-26 06:27:29 +00:00
|
|
|
{
|
2020-08-16 19:55:26 +00:00
|
|
|
NormalVisibility = g_visibility = sector[0].extra;
|
|
|
|
sector[0].extra = 0;
|
2019-12-26 06:27:29 +00:00
|
|
|
}
|
2020-08-16 19:55:26 +00:00
|
|
|
else
|
|
|
|
NormalVisibility = g_visibility;
|
2019-12-26 06:27:29 +00:00
|
|
|
|
2020-08-16 19:55:26 +00:00
|
|
|
//
|
|
|
|
// Do Player stuff first
|
|
|
|
//
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2020-08-16 19:55:26 +00:00
|
|
|
InitAllPlayers();
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2020-08-16 19:55:26 +00:00
|
|
|
QueueReset();
|
|
|
|
PreMapCombineFloors();
|
|
|
|
InitMultiPlayerInfo();
|
|
|
|
InitAllPlayerSprites();
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2020-08-16 19:55:26 +00:00
|
|
|
//
|
|
|
|
// Do setup for sprite, track, panel, sector, etc
|
|
|
|
//
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2020-08-16 19:55:26 +00:00
|
|
|
// Set levels up
|
|
|
|
InitTimingVars();
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2020-08-16 19:55:26 +00:00
|
|
|
SpriteSetup();
|
|
|
|
SpriteSetupPost(); // post processing - already gone once through the loop
|
|
|
|
InitLighting();
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2020-08-16 19:55:26 +00:00
|
|
|
TrackSetup();
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2020-08-16 19:55:26 +00:00
|
|
|
PlayerPanelSetup();
|
|
|
|
SectorSetup();
|
|
|
|
JS_InitMirrors();
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2020-08-16 19:55:26 +00:00
|
|
|
PlaceSectorObjectsOnTracks();
|
|
|
|
PlaceActorsOnTracks();
|
|
|
|
PostSetupSectorObject();
|
|
|
|
SetupMirrorTiles();
|
2021-03-25 20:21:48 +00:00
|
|
|
CollectPortals();
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2020-08-16 19:55:26 +00:00
|
|
|
// reset NewGame
|
|
|
|
NewGame = false;
|
2020-09-08 16:28:41 +00:00
|
|
|
setLevelStarted(maprec);
|
2015-05-19 21:54:34 +00:00
|
|
|
}
|
|
|
|
|
2020-08-16 19:55:26 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2020-08-16 16:18:56 +00:00
|
|
|
void InitRunLevel(void)
|
|
|
|
{
|
|
|
|
Mus_Stop();
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2020-08-16 16:18:56 +00:00
|
|
|
DoTheCache();
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2020-08-16 16:18:56 +00:00
|
|
|
// send packets with player info
|
|
|
|
InitNetPlayerOptions();
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2020-09-04 18:48:29 +00:00
|
|
|
// Initialize Game part of network code
|
2020-08-16 16:18:56 +00:00
|
|
|
InitNetVars();
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2020-08-16 16:18:56 +00:00
|
|
|
if (currentLevel)
|
|
|
|
{
|
2021-05-11 23:58:42 +00:00
|
|
|
PlaySong(currentLevel->music, currentLevel->cdSongId);
|
2020-08-16 16:18:56 +00:00
|
|
|
}
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2020-08-16 16:18:56 +00:00
|
|
|
InitPrediction(&Player[myconnectindex]);
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2020-08-16 16:18:56 +00:00
|
|
|
InitTimingVars();
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2020-08-16 16:18:56 +00:00
|
|
|
if (snd_ambience)
|
|
|
|
StartAmbientSound();
|
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-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
|
|
|
|
2020-10-15 15:45:07 +00:00
|
|
|
int i, stat, pnum, ndx;
|
2015-05-19 21:54:34 +00:00
|
|
|
|
|
|
|
// Free any track points
|
|
|
|
for (ndx = 0; ndx < MAX_TRACKS; ndx++)
|
|
|
|
{
|
2020-12-01 15:53:29 +00:00
|
|
|
Track[ndx].FreeTrackPoints();
|
2015-05-19 21:54:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Clear the tracks
|
|
|
|
memset(Track, 0, sizeof(Track));
|
|
|
|
|
2020-02-11 06:35:28 +00:00
|
|
|
StopFX();
|
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;
|
|
|
|
|
2021-10-31 22:10:59 +00:00
|
|
|
SWStatIterator it(stat);
|
|
|
|
if (auto actor = it.Next())
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
2021-10-31 22:10:59 +00:00
|
|
|
if (actor->hasU()) puser[pnum].CopyFromUser(actor->u());
|
2015-05-19 21:54:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Kill User memory and delete sprites
|
2021-10-31 22:10:59 +00:00
|
|
|
SWSpriteIterator it;
|
|
|
|
while (auto actor = it.Next())
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
2021-10-31 22:10:59 +00:00
|
|
|
KillActor(actor);
|
2015-05-19 21:54:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TRAVERSE_CONNECT(pnum)
|
2020-05-19 11:44:52 +00:00
|
|
|
{
|
2021-11-20 22:42:01 +00:00
|
|
|
PLAYERp pp = &Player[pnum];
|
2020-04-01 10:30:54 +00:00
|
|
|
|
2015-05-19 21:54:34 +00:00
|
|
|
// 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));
|
2021-07-10 12:25:18 +00:00
|
|
|
pp->DoPlayerAction = nullptr;
|
2020-04-01 10:30:54 +00:00
|
|
|
|
2021-11-06 09:24:11 +00:00
|
|
|
pp->actor = nullptr;
|
2020-04-11 07:17:59 +00:00
|
|
|
|
2021-11-01 18:16:36 +00:00
|
|
|
pp->PlayerUnderActor = nullptr;
|
2020-05-19 11:44:52 +00:00
|
|
|
|
2015-05-19 21:54:34 +00:00
|
|
|
memset(pp->HasKey, 0, sizeof(pp->HasKey));
|
2019-11-26 08:24:19 +00:00
|
|
|
|
2015-05-19 21:54:34 +00:00
|
|
|
//pp->WpnFlags = 0;
|
2021-07-10 12:25:18 +00:00
|
|
|
pp->CurWpn = nullptr;
|
2019-11-26 08:24:19 +00:00
|
|
|
|
2015-05-19 21:54:34 +00:00
|
|
|
memset(pp->Wpn, 0, sizeof(pp->Wpn));
|
|
|
|
memset(pp->InventoryTics, 0, sizeof(pp->InventoryTics));
|
2019-11-26 08:24:19 +00:00
|
|
|
|
2021-11-01 21:17:41 +00:00
|
|
|
pp->KillerActor = nullptr;;
|
2019-11-26 08:24:19 +00:00
|
|
|
|
2015-05-19 21:54:34 +00:00
|
|
|
INITLIST(&pp->PanelSpriteList);
|
|
|
|
}
|
|
|
|
}
|
2020-04-05 11:37:34 +00:00
|
|
|
|
2020-03-29 11:01:11 +00:00
|
|
|
|
2020-10-10 08:11:22 +00:00
|
|
|
static bool DidOrderSound;
|
|
|
|
static int zero = 0;
|
|
|
|
|
|
|
|
static void PlayOrderSound()
|
|
|
|
{
|
|
|
|
if (!DidOrderSound)
|
|
|
|
{
|
|
|
|
DidOrderSound = true;
|
|
|
|
int choose_snd = STD_RANDOM_RANGE(1000);
|
|
|
|
if (choose_snd > 500)
|
|
|
|
PlaySound(DIGI_WANGORDER1, v3df_dontpan, CHAN_BODY, CHANF_UI);
|
|
|
|
else
|
|
|
|
PlaySound(DIGI_WANGORDER2, v3df_dontpan, CHAN_BODY, CHANF_UI);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-04-29 14:10:04 +00:00
|
|
|
void GameInterface::LevelCompleted(MapRecord* map, int skill)
|
2020-09-04 19:15:15 +00:00
|
|
|
{
|
2021-04-29 14:10:04 +00:00
|
|
|
//ResetPalette(mpp);
|
|
|
|
COVER_SetReverb(0); // Reset reverb
|
|
|
|
Player[myconnectindex].Reverb = 0;
|
|
|
|
StopSound();
|
2020-12-13 20:41:04 +00:00
|
|
|
STAT_Update(map == nullptr);
|
2020-04-11 07:17:59 +00:00
|
|
|
|
2021-04-29 14:10:04 +00:00
|
|
|
SummaryInfo info{};
|
|
|
|
|
2021-05-16 08:25:56 +00:00
|
|
|
info.kills = Player[screenpeek].Kills;
|
2021-04-29 14:10:04 +00:00
|
|
|
info.maxkills = TotalKillable;
|
2021-05-16 08:25:56 +00:00
|
|
|
info.secrets = Player[screenpeek].SecretsFound;
|
2021-04-29 14:10:04 +00:00
|
|
|
info.maxsecrets = LevelSecrets;
|
|
|
|
info.time = PlayClock / 120;
|
|
|
|
|
|
|
|
ShowIntermission(currentLevel, map, &info, [=](bool)
|
|
|
|
{
|
2020-12-13 20:41:04 +00:00
|
|
|
if (map == nullptr)
|
2021-04-29 14:10:04 +00:00
|
|
|
{
|
|
|
|
FinishAnim = false;
|
2021-05-11 23:58:42 +00:00
|
|
|
PlaySong(ThemeSongs[0], ThemeTrack[0]);
|
2021-04-29 14:10:04 +00:00
|
|
|
if (isShareware())
|
2020-10-10 08:11:22 +00:00
|
|
|
{
|
|
|
|
PlayOrderSound();
|
|
|
|
gameaction = ga_creditsmenu;
|
|
|
|
}
|
2021-04-29 14:10:04 +00:00
|
|
|
else gameaction = ga_mainmenu;
|
|
|
|
}
|
|
|
|
else gameaction = ga_nextlevel;
|
|
|
|
});
|
2020-09-04 19:15:15 +00:00
|
|
|
}
|
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();
|
|
|
|
}
|
2020-05-19 11:44:52 +00:00
|
|
|
|
2020-09-04 19:15:15 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
2020-05-19 11:44:52 +00:00
|
|
|
|
2021-04-15 16:50:48 +00:00
|
|
|
void GameInterface::NewGame(MapRecord *map, int skill, bool)
|
2020-09-04 19:15:15 +00:00
|
|
|
{
|
|
|
|
if (skill != -1) Skill = skill;
|
|
|
|
ShadowWarrior::NewGame = true;
|
|
|
|
InitLevel(map);
|
|
|
|
InitRunLevel();
|
2021-04-29 14:10:04 +00:00
|
|
|
gameaction = ga_level;
|
2020-08-16 19:55:26 +00:00
|
|
|
}
|
2020-05-19 11:44:52 +00:00
|
|
|
|
2020-08-16 19:55:26 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2021-07-20 08:50:46 +00:00
|
|
|
int GameInterface::GetCurrentSkill()
|
|
|
|
{
|
|
|
|
return Skill;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2020-09-02 18:56:09 +00:00
|
|
|
void GameInterface::Ticker(void)
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
2020-09-02 18:56:09 +00:00
|
|
|
int i;
|
|
|
|
TRAVERSE_CONNECT(i)
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
2020-09-02 18:56:09 +00:00
|
|
|
auto pp = Player + i;
|
|
|
|
pp->lastinput = pp->input;
|
|
|
|
pp->input = playercmds[i].ucmd;
|
2020-09-20 10:01:05 +00:00
|
|
|
if (pp->lastinput.actions & SB_CENTERVIEW) pp->input.actions |= SB_CENTERVIEW;
|
2020-09-16 17:28:51 +00:00
|
|
|
}
|
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
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2020-09-02 18:56:09 +00:00
|
|
|
void GameInterface::Render()
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
2020-09-16 17:28:51 +00:00
|
|
|
if (paused)
|
|
|
|
{
|
2020-09-02 18:56:09 +00:00
|
|
|
smoothratio = MaxSmoothRatio;
|
2020-09-16 17:28:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-11-28 23:40:42 +00:00
|
|
|
smoothratio = !cl_interpolate || cl_capfps ? MaxSmoothRatio : I_GetTimeFrac() * MaxSmoothRatio;
|
2020-09-16 17:28:51 +00:00
|
|
|
}
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2020-09-02 18:56:09 +00:00
|
|
|
drawtime.Reset();
|
|
|
|
drawtime.Clock();
|
|
|
|
drawscreen(Player + screenpeek, smoothratio);
|
|
|
|
drawtime.Unclock();
|
2015-05-19 21:54:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-02 18:56:09 +00:00
|
|
|
void GameInterface::Startup()
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
2021-04-27 18:04:11 +00:00
|
|
|
PlayLogos(ga_mainmenunostopsound, ga_mainmenu, false);
|
2015-05-19 21:54:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-29 22:55:49 +00:00
|
|
|
void GameInterface::ErrorCleanup()
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
2020-08-29 22:55:49 +00:00
|
|
|
// Make sure we do not leave the game in an unstable state
|
|
|
|
TerminateLevel();
|
2020-09-09 18:28:05 +00:00
|
|
|
FinishAnim = false;
|
2015-05-19 21:54:34 +00:00
|
|
|
}
|
2021-05-31 21:16:52 +00:00
|
|
|
|
|
|
|
void GameInterface::ExitFromMenu()
|
|
|
|
{
|
|
|
|
endoomName = !isShareware() ? "swreg.bin" : "shadsw.bin";
|
|
|
|
ST_Endoom();
|
|
|
|
}
|
|
|
|
|
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
|
2021-10-31 22:10:59 +00:00
|
|
|
value = (rand_num << 14) / ((65535U << 14) / range);
|
2015-05-19 21:54:34 +00:00
|
|
|
|
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
|
|
|
|
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
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
2019-04-08 06:27:15 +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
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2020-09-03 21:10:28 +00:00
|
|
|
void GameInterface::FreeLevelData()
|
2020-01-01 08:49:06 +00:00
|
|
|
{
|
2020-09-03 21:10:28 +00:00
|
|
|
TerminateLevel();
|
|
|
|
::GameInterface::FreeLevelData();
|
2019-12-24 12:21:36 +00:00
|
|
|
}
|
2019-12-08 23:55:30 +00:00
|
|
|
|
2021-04-11 11:38:23 +00:00
|
|
|
int GameInterface::Voxelize(int sprnum)
|
2021-04-03 19:40:16 +00:00
|
|
|
{
|
2021-04-11 11:38:23 +00:00
|
|
|
return (aVoxelArray[sprnum].Voxel);
|
2021-04-03 19:40:16 +00:00
|
|
|
}
|
|
|
|
|
2019-10-09 16:09:05 +00:00
|
|
|
END_SW_NS
|