raze/source/games/sw/src/game.cpp

735 lines
17 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 "names2.h"
#include "panel.h"
#include "game.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"
2020-09-06 10:44:58 +00:00
#include "automap.h"
#include "statusbar.h"
#include "texturemanager.h"
#include "st_start.h"
#include "i_interface.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 "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 "razemenu.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 "d_net.h"
#include "v_draw.h"
#include "interpolate.h"
//#include "crc32.h"
CVAR(Bool, sw_ninjahack, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_SERVERINFO);
CVAR(Bool, sw_darts, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG);
CVAR(Bool, sw_bunnyrockets, false, CVAR_SERVERINFO | CVAR_CHEAT); // This is a cheat, so don't save.
BEGIN_SW_NS
void pClearSpriteList(PLAYERp pp);
extern int sw_snd_scratch;
int GameVersion = 20;
2020-09-09 18:32:24 +00:00
bool NoMeters = false;
int FinishAnim = 0;
2020-09-09 18:32:24 +00:00
bool ReloadPrompt = false;
bool NewGame = false;
//Miscellaneous variables
2020-09-09 18:32:24 +00:00
bool FinishedLevel = false;
short screenpeek = 0;
2020-08-16 19:55:26 +00:00
int GodMode = false;
short Skill = 2;
2021-11-21 20:47:37 +00:00
int 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-09-09 18:32:24 +00:00
bool PlayerTrackingMode = false;
bool SlowMode = false;
2020-09-09 18:32:24 +00:00
bool DebugOperate = false;
void LoadingLevelScreen(void);
uint8_t FakeMultiNumPlayers;
int totalsynctics;
int OrigCommPlayers=0;
extern uint8_t CommPlayers;
2020-09-09 18:32:24 +00:00
extern bool CommEnabled;
2020-09-09 18:32:24 +00:00
bool CameraTestMode = false;
char ds[645]; // debug string
extern short NormalVisibility;
2020-09-09 18:32:24 +00:00
bool 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 /////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
#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
void GameInterface::LoadGameTextures()
{
LoadKVXFromScript("swvoxfil.txt"); // Load voxels from script file
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void GameInterface::app_init()
{
GameTicRate = TICS_PER_SEC / synctics;
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();
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.");
}
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);
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
SetTileNames();
userConfig.AddDefs.reset();
InitFX();
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void GameInterface::DrawBackground(void)
{
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);
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void InitLevelGlobals(void)
{
ChopTics = 0;
automapMode = am_off;
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;
ClearInterpolations();
gNet.TimeLimitClock = gNet.TimeLimit;
for (auto& b : bosswasseen) b = false;
2021-11-02 23:19:48 +00:00
memset(BossSpriteNum,0,sizeof(BossSpriteNum));
}
//---------------------------------------------------------------------------
//
// GLOBAL RESETS NOT DONE for LOAD GAME
//
//---------------------------------------------------------------------------
void InitLevelGlobals2(void)
{
InitTimingVars();
TotalKillable = 0;
Bunny_Count = 0;
FinishAnim = false;
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void InitLevel(MapRecord *maprec)
{
2020-08-16 19:55:26 +00:00
Terminate3DSounds();
2020-08-16 19:55:26 +00:00
// A few IMPORTANT GLOBAL RESETS
InitLevelGlobals();
Mus_Stop();
2020-08-16 19:55:26 +00:00
if (!maprec)
{
2020-08-16 19:55:26 +00:00
I_Error("Attempt to start game without level");
return;
}
2020-08-16 19:55:26 +00:00
InitLevelGlobals2();
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);
}
2020-08-16 19:55:26 +00:00
memset(puser, 0, sizeof(puser));
}
2020-08-16 19:55:26 +00:00
int16_t ang;
currentLevel = maprec;
engineLoadBoard(maprec->fileName, SW_SHAREWARE ? 1 : 0, &Player[0].pos, &ang, &Player[0].cursectnum);
2020-08-16 19:55:26 +00:00
SECRET_SetMapName(currentLevel->DisplayName(), currentLevel->name);
STAT_NewLevel(currentLevel->fileName);
Player[0].angle.ang = buildang(ang);
2020-08-16 19:55:26 +00:00
if (sector[0].extra != -1)
{
2020-08-16 19:55:26 +00:00
NormalVisibility = g_visibility = sector[0].extra;
sector[0].extra = 0;
}
2020-08-16 19:55:26 +00:00
else
NormalVisibility = g_visibility;
2020-08-16 19:55:26 +00:00
//
// Do Player stuff first
//
2020-08-16 19:55:26 +00:00
InitAllPlayers();
2020-08-16 19:55:26 +00:00
QueueReset();
PreMapCombineFloors();
InitMultiPlayerInfo();
InitAllPlayerSprites();
2020-08-16 19:55:26 +00:00
//
// Do setup for sprite, track, panel, sector, etc
//
2020-08-16 19:55:26 +00:00
// Set levels up
InitTimingVars();
2020-08-16 19:55:26 +00:00
SpriteSetup();
SpriteSetupPost(); // post processing - already gone once through the loop
InitLighting();
2020-08-16 19:55:26 +00:00
TrackSetup();
2020-08-16 19:55:26 +00:00
PlayerPanelSetup();
SectorSetup();
JS_InitMirrors();
2020-08-16 19:55:26 +00:00
PlaceSectorObjectsOnTracks();
PlaceActorsOnTracks();
PostSetupSectorObject();
SetupMirrorTiles();
CollectPortals();
2020-08-16 19:55:26 +00:00
// reset NewGame
NewGame = false;
setLevelStarted(maprec);
}
2020-08-16 19:55:26 +00:00
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void InitRunLevel(void)
{
Mus_Stop();
DoTheCache();
// send packets with player info
InitNetPlayerOptions();
// Initialize Game part of network code
InitNetVars();
if (currentLevel)
{
PlaySong(currentLevel->music, currentLevel->cdSongId);
}
InitPrediction(&Player[myconnectindex]);
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;
2020-10-15 15:45:07 +00:00
int i, stat, pnum, ndx;
// Free any track points
for (ndx = 0; ndx < MAX_TRACKS; ndx++)
{
Track[ndx].FreeTrackPoints();
}
// Clear the tracks
memset(Track, 0, sizeof(Track));
StopFX();
// 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())
{
2021-10-31 22:10:59 +00:00
if (actor->hasU()) puser[pnum].CopyFromUser(actor->u());
}
}
// Kill User memory and delete sprites
2021-10-31 22:10:59 +00:00
SWSpriteIterator it;
while (auto actor = it.Next())
{
2021-10-31 22:10:59 +00:00
KillActor(actor);
}
TRAVERSE_CONNECT(pnum)
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
{
2021-11-20 22:42:01 +00:00
PLAYERp pp = &Player[pnum];
// Free panel sprites for players
pClearSpriteList(pp);
pp->cookieTime = 0;
memset(pp->cookieQuote, 0, sizeof(pp->cookieQuote));
pp->DoPlayerAction = nullptr;
pp->actor = nullptr;
2020-04-11 07:17:59 +00:00
2021-11-01 18:16:36 +00:00
pp->PlayerUnderActor = nullptr;
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
memset(pp->HasKey, 0, sizeof(pp->HasKey));
//pp->WpnFlags = 0;
pp->CurWpn = nullptr;
memset(pp->Wpn, 0, sizeof(pp->Wpn));
memset(pp->InventoryTics, 0, sizeof(pp->InventoryTics));
2021-11-01 21:17:41 +00:00
pp->KillerActor = nullptr;;
INITLIST(&pp->PanelSpriteList);
}
}
2020-03-29 11:01:11 +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);
}
}
void GameInterface::LevelCompleted(MapRecord* map, int skill)
{
//ResetPalette(mpp);
COVER_SetReverb(0); // Reset reverb
Player[myconnectindex].Reverb = 0;
StopSound();
STAT_Update(map == nullptr);
2020-04-11 07:17:59 +00:00
SummaryInfo info{};
2021-05-16 08:25:56 +00:00
info.kills = Player[screenpeek].Kills;
info.maxkills = TotalKillable;
2021-05-16 08:25:56 +00:00
info.secrets = Player[screenpeek].SecretsFound;
info.maxsecrets = LevelSecrets;
info.time = PlayClock / 120;
ShowIntermission(currentLevel, map, &info, [=](bool)
{
if (map == nullptr)
{
FinishAnim = false;
PlaySong(ThemeSongs[0], ThemeTrack[0]);
if (isShareware())
{
PlayOrderSound();
gameaction = ga_creditsmenu;
}
else gameaction = ga_mainmenu;
}
else gameaction = ga_nextlevel;
});
}
2020-08-16 19:55:26 +00:00
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void GameInterface::NextLevel(MapRecord *map, int skill)
{
if (skill != -1) Skill = skill;
ShadowWarrior::NewGame = false;
InitLevel(map);
InitRunLevel();
}
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
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
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 GameInterface::NewGame(MapRecord *map, int skill, bool)
{
if (skill != -1) Skill = skill;
ShadowWarrior::NewGame = true;
InitLevel(map);
InitRunLevel();
gameaction = ga_level;
2020-08-16 19:55:26 +00:00
}
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
2020-08-16 19:55:26 +00:00
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
int GameInterface::GetCurrentSkill()
{
return Skill;
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void GameInterface::Ticker(void)
{
int i;
TRAVERSE_CONNECT(i)
{
auto pp = Player + i;
pp->lastinput = pp->input;
pp->input = playercmds[i].ucmd;
if (pp->lastinput.actions & SB_CENTERVIEW) pp->input.actions |= SB_CENTERVIEW;
}
domovethings();
r_NoInterpolate = paused;
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void GameInterface::Render()
{
if (paused)
{
smoothratio = MaxSmoothRatio;
}
else
{
smoothratio = !cl_interpolate || cl_capfps ? MaxSmoothRatio : I_GetTimeFrac() * MaxSmoothRatio;
}
drawtime.Reset();
drawtime.Clock();
drawscreen(Player + screenpeek, smoothratio);
drawtime.Unclock();
}
void GameInterface::Startup()
{
PlayLogos(ga_mainmenunostopsound, ga_mainmenu, false);
}
void GameInterface::ErrorCleanup()
{
// Make sure we do not leave the game in an unstable state
TerminateLevel();
FinishAnim = false;
}
void GameInterface::ExitFromMenu()
{
endoomName = !isShareware() ? "swreg.bin" : "shadsw.bin";
ST_Endoom();
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
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
2021-10-31 22:10:59 +00:00
value = (rand_num << 14) / ((65535U << 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;
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
ReservedSpace GameInterface::GetReservedScreenSpace(int viewsize)
{
return { 0, 48 };
}
::GameInterface* CreateInterface()
{
return new GameInterface;
}
GameStats GameInterface::getStats()
{
PLAYERp pp = Player + myconnectindex;
return { pp->Kills, TotalKillable, pp->SecretsFound, LevelSecrets, PlayClock / 120, 0 };
}
void GameInterface::FreeLevelData()
{
TerminateLevel();
::GameInterface::FreeLevelData();
}
2021-04-11 11:38:23 +00:00
int GameInterface::Voxelize(int sprnum)
{
2021-04-11 11:38:23 +00:00
return (aVoxelArray[sprnum].Voxel);
}
END_SW_NS