raze/source/sw/src/game.cpp

981 lines
23 KiB
C++
Raw Normal View History

//-------------------------------------------------------------------------
/*
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
*/
//-------------------------------------------------------------------------
#include "ns.h"
#define MAIN
#define QUIET
#include "build.h"
#include "baselayer.h"
2019-12-29 16:04:38 +00:00
#include "baselayer.h"
#include "names2.h"
#include "panel.h"
#include "game.h"
#include "interp.h"
#include "interpso.h"
#include "tags.h"
#include "sector.h"
#include "sprite.h"
#include "weapon.h"
#include "player.h"
#include "lists.h"
#include "network.h"
#include "pal.h"
#include "mytypes.h"
#include "menus.h"
#include "gamecontrol.h"
#include "misc.h"
#include "misc.h"
#include "break.h"
#include "light.h"
2020-08-05 22:18:45 +00:00
#include "misc.h"
#include "jsector.h"
#include "common.h"
#include "gameconfigfile.h"
2019-11-01 07:24:10 +00:00
#include "printf.h"
#include "m_argv.h"
2019-11-30 09:07:25 +00:00
#include "debugbreak.h"
#include "menu.h"
#include "raze_music.h"
#include "statistics.h"
#include "gstrings.h"
#include "mapinfo.h"
#include "v_video.h"
#include "raze_sound.h"
#include "secrets.h"
#include "screenjob.h"
#include "inputstate.h"
#include "gamestate.h"
//#include "crc32.h"
CVAR(Bool, sw_ninjahack, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG);
CVAR(Bool, sw_darts, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG);
BEGIN_SW_NS
void Logo(const CompletionFunc& completion);
2020-08-16 19:55:26 +00:00
void StatScreen(int FinishAnim, CompletionFunc completion);
void getinput(SW_PACKET*, SWBOOL);
void pClearSpriteList(PLAYERp pp);
extern int sw_snd_scratch;
int GameVersion = 20;
Revert "SW: Improve main game loop." This reverts commit e878c5bab8bc15e00e7a999a018f59ba4980505c. Revert "SW: Use Q16.16 for horiz." This reverts commit f07a0ae01ef8340c4b32c2b110bcb1431ae93c4f. Revert "SW: Use Q16.16 for angle." This reverts commit 1ecc74c2ecd8bb310c0099249ce148a28a73e26a. Revert "SW: Minor repairs for Q16.16 implementation." This reverts commit d78d046bad6c1679fff32efaa98bc6b4478d20eb. Revert "SW: Process input at frame rate." This reverts commit c162014dab5433dff2c5c3e5397178c992e1e761. Revert "SW: Amendments to accommodate changes in master." This reverts commit eaa51138add0d83568fafb79bc9afa35fe67a64f. Revert "SW: Fix incorrectly declared function input type." This reverts commit 1cdd5b08d82a88eb57013e78a34e4ef9e0796d34. Revert "SW: Amend scaleAdjustmentToInterval() with correct value for SW." This reverts commit d4dd737cd54e5c30c41a339fba6cefad696f3a42. Revert "SW: Refinements to new input code." This reverts commit 5ebc65a1fb19f86c2add664470108002a0078945. Revert "SW: Adjust look and snap up/down keys and slightly tune PLAYER_TURN_AMOUNT." This reverts commit 2852536dbf50f4cab58a158083b8c6e2de6ac1dd. Revert "SW: Get PLAYER_TURN_SCALE to be just right." This reverts commit 4630c8a0b7a24819e04a14a64efff5d4b36271cf. Revert "SW: Make map follow mode work better." This reverts commit 8e94c48eff599078364a7b0a7b94750cd40daf28. Revert "SW: Remove line accidentally left from 'MoveScrollMode2D()'." This reverts commit 5db8047b413548d3ef02d08d1d581c303a3d5907. Revert "Fix multiplayer desync after the change to q16 angle and horiz." This reverts commit 3bc46078b833e27fab42eaa77a0f5071c35dd584. Revert "SW: Revert commented out horiz->q16horiz renames in DSPRINTF strings" This reverts commit 537313f620dc98a832d862aff86a78e0b3b3cb23. Revert "sw/src/draw.cpp:drawscreen: We can set the pp->si* fields just once," This reverts commit d2e9595980c283d62de28f029b5f6394bf2522ff. Revert "sw/src/game.cpp:LoadLevel: Rename q16ang -> ang" This reverts commit a178961a3eed2522147f60d7265bb2d08f4a0bfe. Revert "SW: Minor tweaks." This reverts commit 377ba68344e34495638c6fa7685ff78c9a0ed6f8. Revert "SW: Further refine turning and optimise horizon adjustment." This reverts commit 039022d9ac476cc784e47633bfbac039a965f217. Revert "SW: Don't process input at frame rate if ScrollMode2D is true." This reverts commit 1aa1e62c4d4dc1fff24201ff8eaebcccef6d7646. Revert "SW: Use a bit more Q16.16 in places." This reverts commit 40ca656f38de5d941cf5deac440eeafa965df3bd. Revert "SW: Use the old interpolation path in drawscreen if player is dead" This reverts commit 2d734664259e47b999fe989b924ecaa0a97bb109. Revert "SW: Smooth out 180 degree turn landing and replace some fix16_min/max with fix16_clamp." This reverts commit 0996e87f7991490d70fba9e5b525e7c7404ce637. Revert "Change Next/Previous Weapon button handling for Shadow Warrior." This reverts commit f6b8ca6a223923b0ec5665aedacd729391ea1d4d. Revert "SW: Make "Center_View" key return smoothly." This reverts commit 23c401fbc28845a7ecb1ad9b29d0e72781b052b5. Revert "SW: Use the old interpolation path in drawscreen if player is dead" This reverts commit 43ec16eb5576124bed3699943bb70b9ea943bd93. Revert "Interpolation fixes for SW:" This reverts commit ac8a7ecfbdfbe9152a8ead605723c1d18eca7798. Revert "SW: Reset the number of interpolations on level load" This reverts commit 04bf8499e72fd48e1e6e7487d743b38a2a206a14. Revert "Another change modifying saved game format in SW:" This reverts commit e80888523ea62df60c69b098236f6af1f994177a. Revert "SW: Interpolate sector objects in non-demo, single player games." This reverts commit 996ab77cf47b5eeb142d6c93e7b307418f3b53a6. Revert "- fixed merge errors in SW." This reverts commit b8cfa94568b85e4ed51c558f09734ede794ad988. Revert "- fix interpolation stutters when opening console for SW." This reverts commit 99fdbfb6cb62bd02d91f4b2d95339cbd918c71fa. Revert "- reset buttonMap button states after returning from pause for SW (stops keys acting stuck down if down prior to pausing)." This reverts commit 693b6955dac84b13fc5de91aee29364c3be6e526. Revert "SW: fix stupid input scaling bug" This reverts commit 1c79e6e17c0028e650f525db6cdbd1b38095708e. Revert "SW: Make vehicle input better." This reverts commit 670a53c402f08ac0aecd721f8c5cf1543f699250. Revert "SW: Change fix16_from_float() to fix16_from_int() that was changed in 4630c8a0b7a24819e04a14a64efff5d4b36271cf but should have been reverted in 377ba68344e34495638c6fa7685ff78c9a0ed6f8." This reverts commit 423c9da071844bdfb716d39e1cd2cf103727a37c. Revert "SW: Remove ScrollMode2D extern boolean and move into PLAYERp struct." This reverts commit 31eb55c1fa69bfe90c09ce9611e0d32445341284.
2020-05-19 11:44:52 +00:00
int Follow_posx=0,Follow_posy=0;
2020-08-16 19:55:26 +00:00
SWBOOL NoMeters = false;
SWBOOL FinishAnim = 0;
2020-08-16 19:55:26 +00:00
SWBOOL ReloadPrompt = false;
SWBOOL NewGame = false;
SWBOOL SavegameLoaded = false;
//Miscellaneous variables
2020-08-16 19:55:26 +00:00
SWBOOL FinishedLevel = false;
short screenpeek = 0;
SWBOOL PedanticMode;
SWBOOL LocationInfo = 0;
Revert "SW: Improve main game loop." This reverts commit e878c5bab8bc15e00e7a999a018f59ba4980505c. Revert "SW: Use Q16.16 for horiz." This reverts commit f07a0ae01ef8340c4b32c2b110bcb1431ae93c4f. Revert "SW: Use Q16.16 for angle." This reverts commit 1ecc74c2ecd8bb310c0099249ce148a28a73e26a. Revert "SW: Minor repairs for Q16.16 implementation." This reverts commit d78d046bad6c1679fff32efaa98bc6b4478d20eb. Revert "SW: Process input at frame rate." This reverts commit c162014dab5433dff2c5c3e5397178c992e1e761. Revert "SW: Amendments to accommodate changes in master." This reverts commit eaa51138add0d83568fafb79bc9afa35fe67a64f. Revert "SW: Fix incorrectly declared function input type." This reverts commit 1cdd5b08d82a88eb57013e78a34e4ef9e0796d34. Revert "SW: Amend scaleAdjustmentToInterval() with correct value for SW." This reverts commit d4dd737cd54e5c30c41a339fba6cefad696f3a42. Revert "SW: Refinements to new input code." This reverts commit 5ebc65a1fb19f86c2add664470108002a0078945. Revert "SW: Adjust look and snap up/down keys and slightly tune PLAYER_TURN_AMOUNT." This reverts commit 2852536dbf50f4cab58a158083b8c6e2de6ac1dd. Revert "SW: Get PLAYER_TURN_SCALE to be just right." This reverts commit 4630c8a0b7a24819e04a14a64efff5d4b36271cf. Revert "SW: Make map follow mode work better." This reverts commit 8e94c48eff599078364a7b0a7b94750cd40daf28. Revert "SW: Remove line accidentally left from 'MoveScrollMode2D()'." This reverts commit 5db8047b413548d3ef02d08d1d581c303a3d5907. Revert "Fix multiplayer desync after the change to q16 angle and horiz." This reverts commit 3bc46078b833e27fab42eaa77a0f5071c35dd584. Revert "SW: Revert commented out horiz->q16horiz renames in DSPRINTF strings" This reverts commit 537313f620dc98a832d862aff86a78e0b3b3cb23. Revert "sw/src/draw.cpp:drawscreen: We can set the pp->si* fields just once," This reverts commit d2e9595980c283d62de28f029b5f6394bf2522ff. Revert "sw/src/game.cpp:LoadLevel: Rename q16ang -> ang" This reverts commit a178961a3eed2522147f60d7265bb2d08f4a0bfe. Revert "SW: Minor tweaks." This reverts commit 377ba68344e34495638c6fa7685ff78c9a0ed6f8. Revert "SW: Further refine turning and optimise horizon adjustment." This reverts commit 039022d9ac476cc784e47633bfbac039a965f217. Revert "SW: Don't process input at frame rate if ScrollMode2D is true." This reverts commit 1aa1e62c4d4dc1fff24201ff8eaebcccef6d7646. Revert "SW: Use a bit more Q16.16 in places." This reverts commit 40ca656f38de5d941cf5deac440eeafa965df3bd. Revert "SW: Use the old interpolation path in drawscreen if player is dead" This reverts commit 2d734664259e47b999fe989b924ecaa0a97bb109. Revert "SW: Smooth out 180 degree turn landing and replace some fix16_min/max with fix16_clamp." This reverts commit 0996e87f7991490d70fba9e5b525e7c7404ce637. Revert "Change Next/Previous Weapon button handling for Shadow Warrior." This reverts commit f6b8ca6a223923b0ec5665aedacd729391ea1d4d. Revert "SW: Make "Center_View" key return smoothly." This reverts commit 23c401fbc28845a7ecb1ad9b29d0e72781b052b5. Revert "SW: Use the old interpolation path in drawscreen if player is dead" This reverts commit 43ec16eb5576124bed3699943bb70b9ea943bd93. Revert "Interpolation fixes for SW:" This reverts commit ac8a7ecfbdfbe9152a8ead605723c1d18eca7798. Revert "SW: Reset the number of interpolations on level load" This reverts commit 04bf8499e72fd48e1e6e7487d743b38a2a206a14. Revert "Another change modifying saved game format in SW:" This reverts commit e80888523ea62df60c69b098236f6af1f994177a. Revert "SW: Interpolate sector objects in non-demo, single player games." This reverts commit 996ab77cf47b5eeb142d6c93e7b307418f3b53a6. Revert "- fixed merge errors in SW." This reverts commit b8cfa94568b85e4ed51c558f09734ede794ad988. Revert "- fix interpolation stutters when opening console for SW." This reverts commit 99fdbfb6cb62bd02d91f4b2d95339cbd918c71fa. Revert "- reset buttonMap button states after returning from pause for SW (stops keys acting stuck down if down prior to pausing)." This reverts commit 693b6955dac84b13fc5de91aee29364c3be6e526. Revert "SW: fix stupid input scaling bug" This reverts commit 1c79e6e17c0028e650f525db6cdbd1b38095708e. Revert "SW: Make vehicle input better." This reverts commit 670a53c402f08ac0aecd721f8c5cf1543f699250. Revert "SW: Change fix16_from_float() to fix16_from_int() that was changed in 4630c8a0b7a24819e04a14a64efff5d4b36271cf but should have been reverted in 377ba68344e34495638c6fa7685ff78c9a0ed6f8." This reverts commit 423c9da071844bdfb716d39e1cd2cf103727a37c. Revert "SW: Remove ScrollMode2D extern boolean and move into PLAYERp struct." This reverts commit 31eb55c1fa69bfe90c09ce9611e0d32445341284.
2020-05-19 11:44:52 +00:00
void drawoverheadmap(int cposx, int cposy, int czoom, short cang);
SWBOOL PreCaching = TRUE;
2020-08-16 19:55:26 +00:00
int GodMode = false;
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
TRUE, // SpawnMarkers Markers
2020-08-16 19:55:26 +00:00
false, // TeamPlay
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;
SWBOOL FrameAdvanceTics = 3;
2020-08-16 19:55:26 +00:00
SWBOOL DebugOperate = false;
void LoadingLevelScreen(void);
uint8_t FakeMultiNumPlayers;
int totalsynctics;
MapRecord* NextLevel = nullptr;
2020-08-16 19:55:26 +00:00
SWBOOL ExitLevel = false;
int OrigCommPlayers=0;
extern uint8_t CommPlayers;
extern SWBOOL CommEnabled;
extern int bufferjitter;
2020-08-16 19:55:26 +00:00
SWBOOL CameraTestMode = false;
char ds[645]; // debug string
extern short NormalVisibility;
2020-08-16 19:55:26 +00:00
SWBOOL CommandSetup = false;
char buffer[80], ch;
uint8_t DebugPrintColor = 255;
FString ThemeSongs[6];
int ThemeTrack[6];
/// L O C A L P R O T O T Y P E S /////////////////////////////////////////////////////////
void SybexScreen(void);
/////////////////////////////////////////////////////////////////////////////////////////////
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
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",
"SendMessage",
"Shrink_Screen",
"Enlarge_Screen",
"Show_Opponents_Weapon",
"See_Coop_View",
"Mouse_Aiming",
"Dpad_Select",
"Dpad_Aiming",
"Last_Weapon",
"Alt_Weapon",
"Third_Person_View",
"Toggle_Crouch", // This is the last one used by EDuke32"",
};
void GameInterface::app_init()
{
GameTicRate = 40;
InitCheats();
buttonMap.SetButtons(actions, NUM_ACTIONS);
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();
registerinputcommands();
engineInit();
auto pal = fileSystem.LoadFile("3drealms.pal", 0);
if (pal.Size() >= 768)
{
for (auto& c : pal)
c <<= 2;
paletteSetColorTable(DREALMSPAL, pal.Data(), true, true);
}
timerInit(120);
InitPalette();
// sets numplayers, connecthead, connectpoint2, myconnectindex
numplayers = 1; myconnectindex = 0;
connecthead = 0; connectpoint2[0] = -1;
if (SW_SHAREWARE && numplayers > 4)
{
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.");
}
TileFiles.LoadArtSet("tiles%03d.art");
InitFonts();
2020-08-16 08:40:20 +00:00
//Connect();
SortBreakInfo();
parallaxtype = 1;
SW_InitMultiPsky();
memset(Track, 0, sizeof(Track));
memset(Player, 0, sizeof(Player));
for (int i = 0; i < MAX_SW_PLAYERS; i++)
INITLIST(&Player[i].PanelSpriteList);
LoadKVXFromScript("swvoxfil.txt"); // Load voxels from script file
LoadPLockFromScript("swplock.txt"); // Get Parental Lock setup info
LoadCustomInfoFromScript("engine/swcustom.txt"); // load the internal definitions. These also apply to the shareware version.
if (!SW_SHAREWARE)
LoadCustomInfoFromScript("swcustom.txt"); // Load user customisation information
if (!loaddefinitionsfile(G_DefFile())) Printf("Definitions file loaded.\n");
userConfig.AddDefs.reset();
enginePostInit();
videoInit();
InitFX();
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void StartMenu()
{
M_StartControlPanel(false);
if (SW_SHAREWARE && FinishAnim)
{
// go to ordering menu only if shareware
M_SetMenu(NAME_CreditsMenu);
}
else
{
M_SetMenu(NAME_Mainmenu);
}
FinishAnim = 0;
gamestate = GS_MENUSCREEN;
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void DrawMenuLevelScreen(void)
{
const int TITLE_PIC = 2324;
twod->ClearScreen();
totalclocklock = gameclock;
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);
}
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void InitLevelGlobals(void)
{
ChopTics = 0;
automapMode = am_off;
zoom = 768;
PlayerGravity = 24;
wait_active_check_offset = 0;
PlaxCeilGlobZadjust = PlaxFloorGlobZadjust = Z(500);
2020-08-16 19:55:26 +00:00
FinishedLevel = false;
AnimCnt = 0;
2020-08-16 19:55:26 +00:00
left_foot = false;
screenpeek = myconnectindex;
numinterpolations = short_numinterpolations = 0;
gNet.TimeLimitClock = gNet.TimeLimit;
2020-08-16 19:55:26 +00:00
serpwasseen = false;
sumowasseen = false;
zillawasseen = false;
memset(BossSpriteNum,-1,sizeof(BossSpriteNum));
2020-08-15 20:31:44 +00:00
PedanticMode = false;
}
//---------------------------------------------------------------------------
//
// GLOBAL RESETS NOT DONE for LOAD GAME
//
//---------------------------------------------------------------------------
void InitLevelGlobals2(void)
{
InitTimingVars();
TotalKillable = 0;
Bunny_Count = 0;
FinishAnim = 0;
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2020-08-16 19:55:26 +00:00
void InitLevel(void)
{
Terminate3DSounds();
// A few IMPORTANT GLOBAL RESETS
InitLevelGlobals();
Mus_Stop();
auto maprec = NextLevel;
NextLevel = nullptr;
if (!maprec) maprec = currentLevel;
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);
Player[0].q16ang = fix16_from_int(ang);
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;
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
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)
{
//SendVersion(GameVersion);
//waitforeverybody();
Mus_Stop();
DoTheCache();
// auto aim / auto run / etc
InitPlayerGameSettings();
// send packets with player info
InitNetPlayerOptions();
// Initialize Game part of network code (When ready2send != 0)
InitNetVars();
if (currentLevel)
{
PlaySong(currentLevel->labelName, currentLevel->music, currentLevel->cdSongId);
}
InitPrediction(&Player[myconnectindex]);
waitforeverybody();
//CheckVersion(GameVersion);
// IMPORTANT - MUST be right before game loop AFTER waitforeverybody
InitTimingVars();
if (snd_ambience)
StartAmbientSound();
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2020-08-16 19:55:26 +00:00
void TerminateLevel(void)
{
videoFadePalette(0, 0, 0, 0);
2020-08-16 14:00:40 +00:00
if (!currentLevel) return;
int i, nexti, stat, pnum, ndx;
2020-08-16 19:55:26 +00:00
SECT_USERp* sectu;
// 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));
StopFX();
2020-08-16 19:55:26 +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++)
{
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);
pp->cookieTime = 0;
memset(pp->cookieQuote, 0, sizeof(pp->cookieQuote));
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-08-16 19:55:26 +00:00
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2020-08-16 19:55:26 +00:00
void MoveTicker(void)
{
int pnum;
2020-08-15 20:31:44 +00:00
2020-08-16 19:55:26 +00:00
//getpackets();
2020-08-16 19:55:26 +00:00
if (PredictionOn && CommEnabled)
{
2020-08-16 19:55:26 +00:00
while (predictmovefifoplc < Player[myconnectindex].movefifoend)
{
DoPrediction(ppp);
}
}
2020-08-16 19:55:26 +00:00
//While you have new input packets to process...
if (!CommEnabled)
bufferjitter = 0;
2020-08-16 19:55:26 +00:00
while (Player[myconnectindex].movefifoend - movefifoplc > bufferjitter)
{
//Make sure you have at least 1 packet from everyone else
for (pnum = connecthead; pnum >= 0; pnum = connectpoint2[pnum])
{
if (movefifoplc == Player[pnum].movefifoend)
{
break;
}
}
2020-08-16 19:55:26 +00:00
//Pnum is >= 0 only if last loop was broken, meaning a player wasn't caught up
if (pnum >= 0)
break;
2020-08-16 19:55:26 +00:00
domovethings();
}
}
2020-08-16 19:55:26 +00:00
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void EndOfLevel()
{
2020-08-16 19:55:26 +00:00
STAT_Update(false);
2020-08-16 19:55:26 +00:00
// for good measure do this
ready2send = 0;
waitforeverybody();
if (FinishedLevel)
{
//ResetPalette(mpp);
FinishedLevel = false;
2020-08-16 19:55:26 +00:00
COVER_SetReverb(0); // Reset reverb
Player[myconnectindex].Reverb = 0;
StopSound();
soundEngine->UpdateSounds(gameclock);
2020-08-16 21:00:05 +00:00
// NextLevel must be null while the intermission is running, but we still need the value for later
auto localNextLevel = NextLevel;
NextLevel = nullptr;
if (FinishAnim == ANIM_SUMO && localNextLevel == nullptr) // next level hasn't been set for this.
localNextLevel = FindMapByLevelNum(currentLevel->levelNumber + 1);
2020-08-16 21:00:05 +00:00
StatScreen(FinishAnim, [=](bool)
2020-08-16 19:55:26 +00:00
{
2020-08-16 21:00:05 +00:00
NextLevel = localNextLevel;
2020-08-16 19:55:26 +00:00
TerminateLevel();
if (NextLevel == nullptr)
{
STAT_Update(true);
PlaySong(nullptr, ThemeSongs[0], ThemeTrack[0]);
StartMenu();
}
else gamestate = GS_LEVEL;
});
}
2020-08-16 19:55:26 +00:00
else
{
2020-08-16 19:55:26 +00:00
TerminateLevel();
}
2020-08-16 19:55:26 +00:00
}
2020-08-16 19:55:26 +00:00
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2020-08-16 19:55:26 +00:00
void GameTicker(void)
{
if (!ExitLevel)
{
if (SavegameLoaded)
{
InitLevelGlobals();
SavegameLoaded = false;
// contains what is needed from calls below
if (snd_ambience)
StartAmbientSound();
// crappy little hack to prevent play clock from being overwritten
// for load games
int SavePlayClock = PlayClock;
InitTimingVars();
PlayClock = SavePlayClock;
ExitLevel = false;
}
else if (NextLevel)
{
InitLevel();
InitRunLevel();
ExitLevel = false;
}
ready2send = 1;
int const currentTic = I_GetTime();
gameclock = I_GetBuildTime();
if (paused)
{
buttonMap.ResetButtonStates();
smoothratio = MaxSmoothRatio;
}
else
{
while (ready2send && currentTic - lastTic >= 1)
{
lastTic = currentTic;
UpdateInputs();
MoveTicker();
}
smoothratio = I_GetTimeFrac() * MaxSmoothRatio;
// Get input again to update q16ang/q16horiz.
if (!PedanticMode)
getinput(&loc, TRUE);
}
drawscreen(Player + screenpeek, smoothratio);
ready2send = 0;
}
2020-08-16 19:55:26 +00:00
if (ExitLevel)
{
ExitLevel = false;
EndOfLevel();
}
}
2020-08-16 19:55:26 +00:00
void GameInterface::RunGameFrame()
{
try
{
// if the menu initiazed a new game or loaded a savegame, switch to play mode.
if (SavegameLoaded || NextLevel) gamestate = GS_LEVEL;
handleevents();
updatePauseStatus();
D_ProcessEvents();
DoUpdateSounds();
switch (gamestate)
{
default:
case GS_STARTUP:
I_ResetTime();
lastTic = -1;
gameclock = 0;
if (userConfig.CommandMap.IsNotEmpty())
{
}
else
{
if (!userConfig.nologo) Logo([](bool) { StartMenu(); });
else StartMenu();
}
break;
case GS_MENUSCREEN:
case GS_FULLCONSOLE:
DrawMenuLevelScreen();
break;
case GS_LEVEL:
GameTicker();
break;
case GS_INTERMISSION:
case GS_INTRO:
RunScreenJobFrame(); // This handles continuation through its completion callback.
break;
}
}
catch (CRecoverableError&)
{
// Make sure we do not leave the game in an unstable state
TerminateLevel();
NextLevel = nullptr;
SavegameLoaded = false;
ExitLevel = false;
FinishAnim = 0;
FinishedLevel = false;
throw;
}
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
int RandomRange(int range)
{
uint32_t rand_num;
uint32_t value;
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);
if (value >= (uint32_t)range)
value = range - 1;
return value;
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
int StdRandomRange(int range)
{
uint32_t rand_num;
uint32_t value;
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
if (value >= (uint32_t)range)
value = range - 1;
return value;
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
#include "saveable.h"
saveable_module saveable_build{};
void Saveable_Init_Dynamic()
{
static saveable_data saveable_build_data[] =
{
{sector, MAXSECTORS*sizeof(sectortype)},
{sprite, MAXSPRITES*sizeof(spritetype)},
{wall, MAXWALLS*sizeof(walltype)},
};
saveable_build.data = saveable_build_data;
saveable_build.numdata = NUM_SAVEABLE_ITEMS(saveable_build_data);
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
ReservedSpace GameInterface::GetReservedScreenSpace(int viewsize)
{
return { 0, 48 };
}
2020-08-13 16:19:44 +00:00
::GameInterface* CreateInterface()
{
return new GameInterface;
}
GameStats GameInterface::getStats()
{
PLAYERp pp = Player + myconnectindex;
return { pp->Kills, TotalKillable, pp->SecretsFound, LevelSecrets, PlayClock / 120, 0 };
}
void GameInterface::FreeGameData()
{
TerminateLevel();
}
END_SW_NS