- transitioned SW to level change event system

This commit is contained in:
Christoph Oelckers 2020-09-04 21:15:15 +02:00
parent b8d2d626ca
commit fd2ce0321e
11 changed files with 88 additions and 225 deletions

View file

@ -250,7 +250,7 @@ void NewLevel(MapRecord *sng, int skill)
{ {
auto completion = [=](bool = false) auto completion = [=](bool = false)
{ {
gGameOptions.nDifficulty = skill; if (skill != -1) gGameOptions.nDifficulty = skill;
gSkill = skill; gSkill = skill;
cheatReset(); cheatReset();
StartLevel(sng); StartLevel(sng);

View file

@ -164,7 +164,7 @@ void GameInterface::Render()
void GameInterface::NextLevel(MapRecord* map, int skill) 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); int res = enterlevel(map, 0);
if (res) gameaction = ga_startup; if (res) gameaction = ga_startup;
} }

View file

@ -54,15 +54,7 @@ void KeysCheat(PLAYERp pp, const char *cheat_string);
static PLAYERp checkCheat(cheatseq_t* c) static PLAYERp checkCheat(cheatseq_t* c)
{ {
if (CommEnabled) if (::CheckCheatmode(true, true)) return nullptr;
return nullptr;
if (Skill >= 3 && (!c || !c->DontCheck) && !sv_cheats)
{
PutStringInfo(&Player[screenpeek], GStrings("TXTS_TOOSKILLFUL"));
return nullptr;
}
return &Player[screenpeek]; return &Player[screenpeek];
} }
@ -104,8 +96,7 @@ const char *GameInterface::GenericCheat(int player, int cheat)
bool RestartCheat(cheatseq_t* c) bool RestartCheat(cheatseq_t* c)
{ {
if (!checkCheat(c)) return false; if (!checkCheat(c)) return false;
ExitLevel = TRUE; DeferedStartGame(currentLevel, -1);
return true;
} }
bool RoomCheat(cheatseq_t* c) bool RoomCheat(cheatseq_t* c)
@ -118,8 +109,8 @@ bool NextCheat(cheatseq_t* c)
{ {
if (!checkCheat(c)) return false; if (!checkCheat(c)) return false;
if (!currentLevel) return true; if (!currentLevel) return true;
NextLevel = FindMapByLevelNum(currentLevel->levelNumber + 1); auto map = FindMapByLevelNum(currentLevel->levelNumber + 1);
if (NextLevel) ExitLevel = TRUE; if (map) DeferedStartGame(map, -1);
return true; return true;
} }
@ -127,8 +118,8 @@ bool PrevCheat(cheatseq_t* c)
{ {
if (!checkCheat(c)) return false; if (!checkCheat(c)) return false;
if (!currentLevel) return true; if (!currentLevel) return true;
NextLevel = FindMapByLevelNum(currentLevel->levelNumber - 1); auto map = FindMapByLevelNum(currentLevel->levelNumber - 1);
if (NextLevel) ExitLevel = TRUE; if (map) DeferedStartGame(map, -1);
return true; return true;
} }
@ -162,12 +153,7 @@ bool WarpCheat(cheatseq_t* c)
if (TEST(pp->Flags, PF_DEAD)) if (TEST(pp->Flags, PF_DEAD))
return true; return true;
DeferedStartGame(maprec, -1);
NextLevel = maprec;
ExitLevel = TRUE;
sprintf(ds, "%s %s", GStrings("TXT_ENTERING"), maprec->DisplayName());
PutStringInfo(pp, ds);
return true; return true;
} }

View file

@ -188,8 +188,6 @@ void GameInterface::MenuClosed()
{ {
} }
extern SWBOOL ExitLevel, NewGame;
bool GameInterface::CanSave() bool GameInterface::CanSave()
{ {
return (gamestate == GS_LEVEL && !CommEnabled && numplayers ==1 && /*!DemoMode &&*/ !TEST(Player[myconnectindex].Flags, PF_DEAD)); 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; PLAYERp pp = Player + screenpeek;
int handle = 0; int handle = 0;
int zero = 0; int zero = 0;
// always assumed that a demo is playing
MapRecord* map; MapRecord* map;
if (gs.Episode >= 1) if (gs.Episode >= 1)
map = FindMapByLevelNum(5); map = FindMapByLevelNum(5);

View file

@ -139,8 +139,6 @@ uint8_t FakeMultiNumPlayers;
int totalsynctics; int totalsynctics;
MapRecord* NextLevel = nullptr;
SWBOOL ExitLevel = false;
int OrigCommPlayers=0; int OrigCommPlayers=0;
extern uint8_t CommPlayers; extern uint8_t CommPlayers;
extern SWBOOL CommEnabled; 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) void GameInterface::DrawBackground(void)
{ {
const int TITLE_PIC = 2324; const int TITLE_PIC = 2324;
@ -329,7 +305,7 @@ void InitLevelGlobals2(void)
// //
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void InitLevel(void) void InitLevel(MapRecord *maprec)
{ {
Terminate3DSounds(); Terminate3DSounds();
@ -338,9 +314,6 @@ void InitLevel(void)
Mus_Stop(); Mus_Stop();
auto maprec = NextLevel;
NextLevel = nullptr;
if (!maprec) maprec = currentLevel;
if (!maprec) if (!maprec)
{ {
I_Error("Attempt to start game without level"); I_Error("Attempt to start game without level");
@ -593,47 +566,54 @@ void TerminateLevel(void)
JS_UnInitLockouts(); 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) StatScreen(FinishAnim, [=](bool)
{ {
//ResetPalette(mpp); if (map == nullptr)
FinishedLevel = false; {
COVER_SetReverb(0); // Reset reverb STAT_Update(true);
Player[myconnectindex].Reverb = 0; FinishAnim = 0;
StopSound(); PlaySong(nullptr, ThemeSongs[0], ThemeTrack[0]);
// NextLevel must be null while the intermission is running, but we still need the value for later if (SW_SHAREWARE) gameaction = ga_creditsmenu;
auto localNextLevel = NextLevel; else gameaction = ga_mainmenu;
NextLevel = nullptr; }
if (FinishAnim == ANIM_SUMO && localNextLevel == nullptr) // next level hasn't been set for this. else gameaction = ga_nextlevel;
localNextLevel = FindMapByLevelNum(currentLevel->levelNumber + 1); });
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) void GameInterface::Ticker(void)
{ {
if (!ExitLevel) if (SavegameLoaded)
{ {
if (SavegameLoaded) InitLevelGlobals();
{ SavegameLoaded = false;
InitLevelGlobals(); // contains what is needed from calls below
SavegameLoaded = false; if (snd_ambience)
// contains what is needed from calls below StartAmbientSound();
if (snd_ambience) }
StartAmbientSound();
ExitLevel = false;
}
else if (ShadowWarrior::NextLevel)
{
InitLevel();
InitRunLevel();
ExitLevel = false;
}
}
int i; int i;
TRAVERSE_CONNECT(i) TRAVERSE_CONNECT(i)
@ -673,13 +643,6 @@ void GameInterface::Ticker(void)
domovethings(); domovethings();
r_NoInterpolate = paused; r_NoInterpolate = paused;
if (ExitLevel)
{
ExitLevel = false;
EndOfLevel();
}
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
@ -713,8 +676,8 @@ void GameInterface::Startup()
} }
else else
{ {
if (!userConfig.nologo) Logo([](bool) { StartMenu(); }); if (!userConfig.nologo) Logo([](bool) { gameaction = ga_mainmenu; });
else StartMenu(); else gameaction = ga_mainmenu;
} }
} }
@ -723,11 +686,8 @@ void GameInterface::ErrorCleanup()
{ {
// Make sure we do not leave the game in an unstable state // Make sure we do not leave the game in an unstable state
TerminateLevel(); TerminateLevel();
ShadowWarrior::NextLevel = nullptr;
SavegameLoaded = false; SavegameLoaded = false;
ExitLevel = false;
FinishAnim = 0; FinishAnim = 0;
FinishedLevel = false;
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// //

View file

@ -1989,13 +1989,8 @@ void DoSoundSpotMatch(short match, short sound_num, short sound_type);
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
extern SWBOOL NewGame; extern SWBOOL NewGame;
extern SWBOOL ExitLevel, FinishedLevel;
extern SWBOOL Warping;
extern uint8_t CommPlayers; extern uint8_t CommPlayers;
extern SWBOOL CommEnabled; extern SWBOOL CommEnabled;
extern MapRecord* NextLevel;
extern short Episode;
extern int LastFrameTics; extern int LastFrameTics;
extern char ds[]; extern char ds[];
extern short Skill; extern short Skill;
@ -2223,6 +2218,9 @@ struct GameInterface : ::GameInterface
void Startup() override; void Startup() override;
const char *CheckCheatMode() override; const char *CheckCheatMode() override;
const char* GenericCheat(int player, int cheat) 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; GameStats getStats() override;

View file

@ -51,9 +51,6 @@ Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms
BEGIN_SW_NS BEGIN_SW_NS
extern SWBOOL ExitLevel, NewGame;
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// Fades from 100% to 62.5% somewhat quickly, // Fades from 100% to 62.5% somewhat quickly,

View file

@ -49,71 +49,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
BEGIN_SW_NS 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) static int osdcmd_warptocoords(CCmdFuncPtr parm)
{ {
if (parm->numparms < 3 || parm->numparms > 5) if (parm->numparms < 3 || parm->numparms > 5)
@ -225,10 +160,7 @@ static int osdcmd_noop(CCmdFuncPtr parm)
int32_t registerosdcommands(void) int32_t registerosdcommands(void)
{ {
C_RegisterFunction("map","map <mapfile>: loads the given map", osdcmd_map);
C_RegisterFunction("mirror_debug", "mirror [mirrornum]: print mirror debug info", osdcmd_mirror); C_RegisterFunction("mirror_debug", "mirror [mirrornum]: print mirror debug info", osdcmd_mirror);
C_RegisterFunction("levelwarp", "levelwarp <num>: 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("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("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); C_RegisterFunction("coop_view", "Switch player to view from in coop", osdcmd_coop_view);

View file

@ -81,7 +81,8 @@ USER puser[MAX_SW_PLAYERS_REG];
//int16_t gNet.MultiGameType = MULTI_GAME_NONE; //int16_t gNet.MultiGameType = MULTI_GAME_NONE;
SWBOOL NightVision = FALSE; SWBOOL NightVision = FALSE;
extern SWBOOL FinishedLevel; extern SWBOOL FinishAnim;
//#define PLAYER_TURN_SCALE (8) //#define PLAYER_TURN_SCALE (8)
#define PLAYER_TURN_SCALE (12) #define PLAYER_TURN_SCALE (12)
@ -6660,10 +6661,7 @@ void DoPlayerDeathCheckKeys(PLAYERp pp)
} }
else else
{ {
ExitLevel = TRUE; DeferedStartGame(currentLevel, -1);
NewGame = true;
NextLevel = currentLevel;
} }
DoPlayerFireOutDeath(pp); DoPlayerFireOutDeath(pp);
@ -7481,9 +7479,6 @@ void MultiPlayLimits(void)
PLAYERp pp; PLAYERp pp;
SWBOOL Done = FALSE; SWBOOL Done = FALSE;
if (ExitLevel)
return;
if (gNet.MultiGameType != MULTI_GAME_COMMBAT) if (gNet.MultiGameType != MULTI_GAME_COMMBAT)
return; return;
@ -7511,14 +7506,11 @@ void MultiPlayLimits(void)
{ {
gNet.TimeLimitClock = gNet.TimeLimit; gNet.TimeLimitClock = gNet.TimeLimit;
NextLevel = nullptr; MapRecord *next = nullptr;
// do not increment if level is 23 thru 28 (should be done smarter.) // do not increment if level is 23 thru 28 (should be done smarter.)
if (currentLevel->levelNumber <= 22) if (currentLevel->levelNumber <= 22)
NextLevel = FindMapByLevelNum(currentLevel->levelNumber + 1); next = FindMapByLevelNum(currentLevel->levelNumber + 1);
if (!NextLevel) NextLevel = currentLevel; ChangeLevel(next, -1);
ExitLevel = TRUE;
FinishedLevel = TRUE;
} }
} }
@ -7681,8 +7673,12 @@ domovethings(void)
if ((FinishTimer -= synctics) <= 0) if ((FinishTimer -= synctics) <= 0)
{ {
FinishTimer = 0; FinishTimer = 0;
ExitLevel = TRUE; MapRecord *map = nullptr;
FinishedLevel = TRUE; if (FinishAnim == ANIM_SUMO)
{
map = FindMapByLevelNum(currentLevel->levelNumber+1);
}
ChangeLevel(map, -1);
} }
} }
} }

View file

@ -1905,12 +1905,12 @@ OperateSprite(short SpriteNum, short player_is_operating)
PlaySound(DIGI_BIGSWITCH, sp, v3df_none); PlaySound(DIGI_BIGSWITCH, sp, v3df_none);
MapRecord *map;
if (sp->hitag) if (sp->hitag)
NextLevel = FindMapByLevelNum(sp->hitag); map = FindMapByLevelNum(sp->hitag);
else else
NextLevel = FindMapByLevelNum(currentLevel->levelNumber + 1); map = FindMapByLevelNum(currentLevel->levelNumber + 1);
ExitLevel = TRUE; ChangeLevel(map, -1);
FinishedLevel = TRUE;
return TRUE; return TRUE;
} }
@ -2108,12 +2108,12 @@ OperateTripTrigger(PLAYERp pp)
// same tag for sector as for switch // same tag for sector as for switch
case TAG_LEVEL_EXIT_SWITCH: case TAG_LEVEL_EXIT_SWITCH:
{ {
MapRecord *map;
if (sectp->hitag) if (sectp->hitag)
NextLevel = FindMapByLevelNum(sectp->hitag); map = FindMapByLevelNum(sectp->hitag);
else else
NextLevel = FindMapByLevelNum(currentLevel->levelNumber + 1); map = FindMapByLevelNum(currentLevel->levelNumber + 1);
ExitLevel = TRUE; ChangeLevel(map, -1);
FinishedLevel = TRUE;
break; break;
} }

View file

@ -5322,7 +5322,6 @@ ActorHealth(short SpriteNum, short amt)
SPRITEp sp = &sprite[SpriteNum]; SPRITEp sp = &sprite[SpriteNum];
USERp u = User[SpriteNum]; USERp u = User[SpriteNum];
extern SWBOOL FinishAnim; extern SWBOOL FinishAnim;
extern SWBOOL FinishedLevel;
if (u->ID == TRASHCAN && amt > -75) if (u->ID == TRASHCAN && amt > -75)
{ {
@ -5338,9 +5337,8 @@ ActorHealth(short SpriteNum, short amt)
{ {
if (u->Health < u->MaxHealth/2) if (u->Health < u->MaxHealth/2)
{ {
ExitLevel = TRUE;
FinishAnim = ANIM_SERP; FinishAnim = ANIM_SERP;
FinishedLevel = TRUE; ChangeLevel(nullptr, -1);
return TRUE; return TRUE;
} }
} }