From fd2ce0321e35138d1c84c3ae819e8978b4b55e95 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 4 Sep 2020 21:15:15 +0200 Subject: [PATCH] - transitioned SW to level change event system --- source/blood/src/blood.cpp | 2 +- source/games/duke/src/gameloop.cpp | 2 +- source/sw/src/cheats.cpp | 28 ++---- source/sw/src/d_menu.cpp | 6 +- source/sw/src/game.cpp | 148 +++++++++++------------------ source/sw/src/game.h | 8 +- source/sw/src/menus.cpp | 3 - source/sw/src/osdcmds.cpp | 68 ------------- source/sw/src/player.cpp | 28 +++--- source/sw/src/sector.cpp | 16 ++-- source/sw/src/weapon.cpp | 4 +- 11 files changed, 88 insertions(+), 225 deletions(-) diff --git a/source/blood/src/blood.cpp b/source/blood/src/blood.cpp index de5578ecc..688e63615 100644 --- a/source/blood/src/blood.cpp +++ b/source/blood/src/blood.cpp @@ -250,7 +250,7 @@ void NewLevel(MapRecord *sng, int skill) { auto completion = [=](bool = false) { - gGameOptions.nDifficulty = skill; + if (skill != -1) gGameOptions.nDifficulty = skill; gSkill = skill; cheatReset(); StartLevel(sng); diff --git a/source/games/duke/src/gameloop.cpp b/source/games/duke/src/gameloop.cpp index 96f37eac4..fd392eb17 100644 --- a/source/games/duke/src/gameloop.cpp +++ b/source/games/duke/src/gameloop.cpp @@ -164,7 +164,7 @@ void GameInterface::Render() void GameInterface::NextLevel(MapRecord* map, int skill) { - ud.m_player_skill = skill + 1; + if (skill != -1) ud.m_player_skill = skill + 1; int res = enterlevel(map, 0); if (res) gameaction = ga_startup; } diff --git a/source/sw/src/cheats.cpp b/source/sw/src/cheats.cpp index b7ff95197..1da0750fb 100644 --- a/source/sw/src/cheats.cpp +++ b/source/sw/src/cheats.cpp @@ -54,15 +54,7 @@ void KeysCheat(PLAYERp pp, const char *cheat_string); static PLAYERp checkCheat(cheatseq_t* c) { - if (CommEnabled) - return nullptr; - - if (Skill >= 3 && (!c || !c->DontCheck) && !sv_cheats) - { - PutStringInfo(&Player[screenpeek], GStrings("TXTS_TOOSKILLFUL")); - return nullptr; - } - + if (::CheckCheatmode(true, true)) return nullptr; return &Player[screenpeek]; } @@ -104,8 +96,7 @@ const char *GameInterface::GenericCheat(int player, int cheat) bool RestartCheat(cheatseq_t* c) { if (!checkCheat(c)) return false; - ExitLevel = TRUE; - return true; + DeferedStartGame(currentLevel, -1); } bool RoomCheat(cheatseq_t* c) @@ -118,8 +109,8 @@ bool NextCheat(cheatseq_t* c) { if (!checkCheat(c)) return false; if (!currentLevel) return true; - NextLevel = FindMapByLevelNum(currentLevel->levelNumber + 1); - if (NextLevel) ExitLevel = TRUE; + auto map = FindMapByLevelNum(currentLevel->levelNumber + 1); + if (map) DeferedStartGame(map, -1); return true; } @@ -127,8 +118,8 @@ bool PrevCheat(cheatseq_t* c) { if (!checkCheat(c)) return false; if (!currentLevel) return true; - NextLevel = FindMapByLevelNum(currentLevel->levelNumber - 1); - if (NextLevel) ExitLevel = TRUE; + auto map = FindMapByLevelNum(currentLevel->levelNumber - 1); + if (map) DeferedStartGame(map, -1); return true; } @@ -162,12 +153,7 @@ bool WarpCheat(cheatseq_t* c) if (TEST(pp->Flags, PF_DEAD)) return true; - - NextLevel = maprec; - ExitLevel = TRUE; - - sprintf(ds, "%s %s", GStrings("TXT_ENTERING"), maprec->DisplayName()); - PutStringInfo(pp, ds); + DeferedStartGame(maprec, -1); return true; } diff --git a/source/sw/src/d_menu.cpp b/source/sw/src/d_menu.cpp index aacc6b222..938ff6929 100644 --- a/source/sw/src/d_menu.cpp +++ b/source/sw/src/d_menu.cpp @@ -188,8 +188,6 @@ void GameInterface::MenuClosed() { } -extern SWBOOL ExitLevel, NewGame; - bool GameInterface::CanSave() { return (gamestate == GS_LEVEL && !CommEnabled && numplayers ==1 && /*!DemoMode &&*/ !TEST(Player[myconnectindex].Flags, PF_DEAD)); @@ -200,9 +198,7 @@ void GameInterface::StartGame(FNewGameStartup& gs) PLAYERp pp = Player + screenpeek; int handle = 0; int zero = 0; - - // always assumed that a demo is playing - + MapRecord* map; if (gs.Episode >= 1) map = FindMapByLevelNum(5); diff --git a/source/sw/src/game.cpp b/source/sw/src/game.cpp index a7295696e..d4adff654 100644 --- a/source/sw/src/game.cpp +++ b/source/sw/src/game.cpp @@ -139,8 +139,6 @@ uint8_t FakeMultiNumPlayers; int totalsynctics; -MapRecord* NextLevel = nullptr; -SWBOOL ExitLevel = false; int OrigCommPlayers=0; extern uint8_t CommPlayers; extern SWBOOL CommEnabled; @@ -245,28 +243,6 @@ void GameInterface::app_init() // //--------------------------------------------------------------------------- -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 GameInterface::DrawBackground(void) { const int TITLE_PIC = 2324; @@ -329,7 +305,7 @@ void InitLevelGlobals2(void) // //--------------------------------------------------------------------------- -void InitLevel(void) +void InitLevel(MapRecord *maprec) { Terminate3DSounds(); @@ -338,9 +314,6 @@ void InitLevel(void) Mus_Stop(); - auto maprec = NextLevel; - NextLevel = nullptr; - if (!maprec) maprec = currentLevel; if (!maprec) { I_Error("Attempt to start game without level"); @@ -593,47 +566,54 @@ void TerminateLevel(void) JS_UnInitLockouts(); } -//--------------------------------------------------------------------------- -// -// -// -//--------------------------------------------------------------------------- -void EndOfLevel() +void GameInterface::LevelCompleted(MapRecord *map, int skill) { - STAT_Update(false); + //ResetPalette(mpp); + COVER_SetReverb(0); // Reset reverb + Player[myconnectindex].Reverb = 0; + StopSound(); - if (FinishedLevel) - { - //ResetPalette(mpp); - FinishedLevel = false; - COVER_SetReverb(0); // Reset reverb - Player[myconnectindex].Reverb = 0; - StopSound(); - // 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); + StatScreen(FinishAnim, [=](bool) + { + if (map == nullptr) + { + STAT_Update(true); + FinishAnim = 0; + PlaySong(nullptr, ThemeSongs[0], ThemeTrack[0]); + if (SW_SHAREWARE) gameaction = ga_creditsmenu; + else gameaction = ga_mainmenu; + } + else gameaction = ga_nextlevel; + }); - StatScreen(FinishAnim, [=](bool) - { - NextLevel = localNextLevel; - TerminateLevel(); - if (NextLevel == nullptr) - { - STAT_Update(true); - PlaySong(nullptr, ThemeSongs[0], ThemeTrack[0]); - StartMenu(); - } - else gamestate = GS_LEVEL; - }); - } - else - { - TerminateLevel(); - } +} +//--------------------------------------------------------------------------- +// +// +// +//--------------------------------------------------------------------------- +void GameInterface::NextLevel(MapRecord *map, int skill) +{ + if (skill != -1) Skill = skill; + ShadowWarrior::NewGame = false; + InitLevel(map); + InitRunLevel(); +} + +//--------------------------------------------------------------------------- +// +// +// +//--------------------------------------------------------------------------- + +void GameInterface::NewGame(MapRecord *map, int skill) +{ + if (skill != -1) Skill = skill; + ShadowWarrior::NewGame = true; + InitLevel(map); + InitRunLevel(); } //--------------------------------------------------------------------------- @@ -644,24 +624,14 @@ void EndOfLevel() void GameInterface::Ticker(void) { - if (!ExitLevel) - { - if (SavegameLoaded) - { - InitLevelGlobals(); - SavegameLoaded = false; - // contains what is needed from calls below - if (snd_ambience) - StartAmbientSound(); - ExitLevel = false; - } - else if (ShadowWarrior::NextLevel) - { - InitLevel(); - InitRunLevel(); - ExitLevel = false; - } - } + if (SavegameLoaded) + { + InitLevelGlobals(); + SavegameLoaded = false; + // contains what is needed from calls below + if (snd_ambience) + StartAmbientSound(); + } int i; TRAVERSE_CONNECT(i) @@ -673,13 +643,6 @@ void GameInterface::Ticker(void) domovethings(); r_NoInterpolate = paused; - - if (ExitLevel) - { - ExitLevel = false; - EndOfLevel(); - } - } //--------------------------------------------------------------------------- @@ -713,8 +676,8 @@ void GameInterface::Startup() } else { - if (!userConfig.nologo) Logo([](bool) { StartMenu(); }); - else StartMenu(); + if (!userConfig.nologo) Logo([](bool) { gameaction = ga_mainmenu; }); + else gameaction = ga_mainmenu; } } @@ -723,11 +686,8 @@ void GameInterface::ErrorCleanup() { // Make sure we do not leave the game in an unstable state TerminateLevel(); - ShadowWarrior::NextLevel = nullptr; SavegameLoaded = false; - ExitLevel = false; FinishAnim = 0; - FinishedLevel = false; } //--------------------------------------------------------------------------- // diff --git a/source/sw/src/game.h b/source/sw/src/game.h index a7f41dfc8..5a5e529d4 100644 --- a/source/sw/src/game.h +++ b/source/sw/src/game.h @@ -1989,13 +1989,8 @@ void DoSoundSpotMatch(short match, short sound_num, short sound_type); /////////////////////////////////////////////////////////////////////////////////////////// extern SWBOOL NewGame; -extern SWBOOL ExitLevel, FinishedLevel; -extern SWBOOL Warping; extern uint8_t CommPlayers; extern SWBOOL CommEnabled; -extern MapRecord* NextLevel; -extern short Episode; - extern int LastFrameTics; extern char ds[]; extern short Skill; @@ -2223,6 +2218,9 @@ struct GameInterface : ::GameInterface void Startup() override; const char *CheckCheatMode() override; const char* GenericCheat(int player, int cheat) override; + void LevelCompleted(MapRecord *map, int skill) override; + void NextLevel(MapRecord *map, int skill) override; + void NewGame(MapRecord *map, int skill) override; GameStats getStats() override; diff --git a/source/sw/src/menus.cpp b/source/sw/src/menus.cpp index 524cc3802..c223080e3 100644 --- a/source/sw/src/menus.cpp +++ b/source/sw/src/menus.cpp @@ -51,9 +51,6 @@ Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms BEGIN_SW_NS -extern SWBOOL ExitLevel, NewGame; - - ////////////////////////////////////////////////////////////////////////////// // Fades from 100% to 62.5% somewhat quickly, diff --git a/source/sw/src/osdcmds.cpp b/source/sw/src/osdcmds.cpp index c95d285fd..71a3d3aff 100644 --- a/source/sw/src/osdcmds.cpp +++ b/source/sw/src/osdcmds.cpp @@ -49,71 +49,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. BEGIN_SW_NS -static void levelwarp(MapRecord *maprec) -{ - if (CommEnabled) - return; - - auto pp = &Player[myconnectindex]; - if (Skill >= 3) - { - PutStringInfo(pp, GStrings("TXTS_TOOSKILLFUL")); - return; - } - - if (TEST(pp->Flags, PF_DEAD)) - return; - - NextLevel = maprec; - ExitLevel = TRUE; - if (gamestate == GS_MENUSCREEN || gamestate == GS_FULLCONSOLE) NewGame = true; - - sprintf(ds, "%s %s", GStrings("TXT_ENTERING"), maprec->DisplayName()); - PutStringInfo(pp, ds); -} - - -static int osdcmd_map(CCmdFuncPtr parm) -{ - if (parm->numparms != 1) - { - return CCMD_SHOWHELP; - } - FString mapname = parm->parms[0]; - FString mapfilename = mapname; - DefaultExtension(mapfilename, ".map"); - - if (!fileSystem.FileExists(mapfilename)) - { - Printf(TEXTCOLOR_RED "map: file \"%s\" not found.\n", mapfilename.GetChars()); - return CCMD_OK; - } - - // Check if the map is already defined. - auto maprec = FindMapByName(mapname); - if (maprec) levelwarp(maprec); - else - { - maprec = SetupUserMap(mapfilename); - if (maprec) levelwarp(maprec); - } - return CCMD_OK; -} - -int osdcmd_restartmap(CCmdFuncPtr) -{ - C_DoCommand("activatecheat lwstart"); - return CCMD_OK; -} - -int osdcmd_levelwarp(CCmdFuncPtr parm) -{ - if (parm->numparms != 1) return CCMD_SHOWHELP; - auto maprec = FindMapByLevelNum(atoi(parm->parms[0])); - if (maprec) levelwarp(maprec); - return CCMD_OK; -} - static int osdcmd_warptocoords(CCmdFuncPtr parm) { if (parm->numparms < 3 || parm->numparms > 5) @@ -225,10 +160,7 @@ static int osdcmd_noop(CCmdFuncPtr parm) int32_t registerosdcommands(void) { - C_RegisterFunction("map","map : loads the given map", osdcmd_map); C_RegisterFunction("mirror_debug", "mirror [mirrornum]: print mirror debug info", osdcmd_mirror); - C_RegisterFunction("levelwarp", "levelwarp : warp to level", osdcmd_levelwarp); - C_RegisterFunction("restartmap", "restartmap: restarts the current map", osdcmd_restartmap); C_RegisterFunction("warptocoords","warptocoords [x] [y] [z] [ang] (optional) [horiz] (optional): warps the player to the specified coordinates",osdcmd_warptocoords); C_RegisterFunction("third_person_view", "Switch to third person view", osdcmd_third_person_view); C_RegisterFunction("coop_view", "Switch player to view from in coop", osdcmd_coop_view); diff --git a/source/sw/src/player.cpp b/source/sw/src/player.cpp index 9222546ec..869a41ddb 100644 --- a/source/sw/src/player.cpp +++ b/source/sw/src/player.cpp @@ -81,7 +81,8 @@ USER puser[MAX_SW_PLAYERS_REG]; //int16_t gNet.MultiGameType = MULTI_GAME_NONE; SWBOOL NightVision = FALSE; -extern SWBOOL FinishedLevel; +extern SWBOOL FinishAnim; + //#define PLAYER_TURN_SCALE (8) #define PLAYER_TURN_SCALE (12) @@ -6660,10 +6661,7 @@ void DoPlayerDeathCheckKeys(PLAYERp pp) } else { - ExitLevel = TRUE; - NewGame = true; - NextLevel = currentLevel; - + DeferedStartGame(currentLevel, -1); } DoPlayerFireOutDeath(pp); @@ -7481,9 +7479,6 @@ void MultiPlayLimits(void) PLAYERp pp; SWBOOL Done = FALSE; - if (ExitLevel) - return; - if (gNet.MultiGameType != MULTI_GAME_COMMBAT) return; @@ -7511,14 +7506,11 @@ void MultiPlayLimits(void) { gNet.TimeLimitClock = gNet.TimeLimit; - NextLevel = nullptr; + MapRecord *next = nullptr; // do not increment if level is 23 thru 28 (should be done smarter.) if (currentLevel->levelNumber <= 22) - NextLevel = FindMapByLevelNum(currentLevel->levelNumber + 1); - if (!NextLevel) NextLevel = currentLevel; - - ExitLevel = TRUE; - FinishedLevel = TRUE; + next = FindMapByLevelNum(currentLevel->levelNumber + 1); + ChangeLevel(next, -1); } } @@ -7681,8 +7673,12 @@ domovethings(void) if ((FinishTimer -= synctics) <= 0) { FinishTimer = 0; - ExitLevel = TRUE; - FinishedLevel = TRUE; + MapRecord *map = nullptr; + if (FinishAnim == ANIM_SUMO) + { + map = FindMapByLevelNum(currentLevel->levelNumber+1); + } + ChangeLevel(map, -1); } } } diff --git a/source/sw/src/sector.cpp b/source/sw/src/sector.cpp index d27e12949..8524953c4 100644 --- a/source/sw/src/sector.cpp +++ b/source/sw/src/sector.cpp @@ -1905,12 +1905,12 @@ OperateSprite(short SpriteNum, short player_is_operating) PlaySound(DIGI_BIGSWITCH, sp, v3df_none); + MapRecord *map; if (sp->hitag) - NextLevel = FindMapByLevelNum(sp->hitag); + map = FindMapByLevelNum(sp->hitag); else - NextLevel = FindMapByLevelNum(currentLevel->levelNumber + 1); - ExitLevel = TRUE; - FinishedLevel = TRUE; + map = FindMapByLevelNum(currentLevel->levelNumber + 1); + ChangeLevel(map, -1); return TRUE; } @@ -2108,12 +2108,12 @@ OperateTripTrigger(PLAYERp pp) // same tag for sector as for switch case TAG_LEVEL_EXIT_SWITCH: { + MapRecord *map; if (sectp->hitag) - NextLevel = FindMapByLevelNum(sectp->hitag); + map = FindMapByLevelNum(sectp->hitag); else - NextLevel = FindMapByLevelNum(currentLevel->levelNumber + 1); - ExitLevel = TRUE; - FinishedLevel = TRUE; + map = FindMapByLevelNum(currentLevel->levelNumber + 1); + ChangeLevel(map, -1); break; } diff --git a/source/sw/src/weapon.cpp b/source/sw/src/weapon.cpp index 939c7a896..1250485ab 100644 --- a/source/sw/src/weapon.cpp +++ b/source/sw/src/weapon.cpp @@ -5322,7 +5322,6 @@ ActorHealth(short SpriteNum, short amt) SPRITEp sp = &sprite[SpriteNum]; USERp u = User[SpriteNum]; extern SWBOOL FinishAnim; - extern SWBOOL FinishedLevel; if (u->ID == TRASHCAN && amt > -75) { @@ -5338,9 +5337,8 @@ ActorHealth(short SpriteNum, short amt) { if (u->Health < u->MaxHealth/2) { - ExitLevel = TRUE; FinishAnim = ANIM_SERP; - FinishedLevel = TRUE; + ChangeLevel(nullptr, -1); return TRUE; } }