- 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)
{
gGameOptions.nDifficulty = skill;
if (skill != -1) gGameOptions.nDifficulty = skill;
gSkill = skill;
cheatReset();
StartLevel(sng);

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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));
@ -201,8 +199,6 @@ void GameInterface::StartGame(FNewGameStartup& gs)
int handle = 0;
int zero = 0;
// always assumed that a demo is playing
MapRecord* map;
if (gs.Episode >= 1)
map = FindMapByLevelNum(5);

View file

@ -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;
}
//---------------------------------------------------------------------------
//

View file

@ -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;

View file

@ -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,

View file

@ -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 <mapfile>: loads the given map", osdcmd_map);
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("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);

View file

@ -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);
}
}
}

View file

@ -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;
}

View file

@ -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;
}
}