From 33845c4a23b7edbc282ce248fe4db174d7e34d08 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Tue, 20 Jul 2021 18:50:46 +1000 Subject: [PATCH] - Add `skill` CCMD to return player's current skill, while also being able to set skill for next game. * Fixes #332. --- source/core/cheats.cpp | 56 +++++++++++++++++++++++++++ source/core/gamestruct.h | 1 + source/games/blood/src/blood.cpp | 6 +++ source/games/blood/src/blood.h | 1 + source/games/duke/src/duke3d.h | 1 + source/games/duke/src/game.cpp | 5 +++ source/games/exhumed/src/exhumed.h | 1 + source/games/exhumed/src/gameloop.cpp | 5 +++ source/games/sw/src/game.cpp | 11 ++++++ source/games/sw/src/game.h | 1 + 10 files changed, 88 insertions(+) diff --git a/source/core/cheats.cpp b/source/core/cheats.cpp index 455b6e04a..1be698f9b 100644 --- a/source/core/cheats.cpp +++ b/source/core/cheats.cpp @@ -495,3 +495,59 @@ CCMD(endofgame) STAT_Update(true); ChangeLevel(nullptr, -1); } + +//--------------------------------------------------------------------------- +// +// +// +//--------------------------------------------------------------------------- + +CCMD(skill) +{ + if (gamestate == GS_LEVEL) + { + auto argsCount = argv.argc(); + + if (argsCount < 2) + { + auto currentSkill = gi->GetCurrentSkill(); + if (currentSkill >= 0) + { + Printf("Current skill is %d (%s)\n", currentSkill, GStrings.localize(gSkillNames[currentSkill])); + } + else if (currentSkill == -1) + { + Printf("Current skill is not set (%d)\n"); + } + else if (currentSkill == -2) + { + Printf("This game has no skill settings.\n"); + } + else + { + Printf("Current skill is an unknown/unsupported value (%d)\n"); + } + } + else if (argsCount == 2) + { + auto newSkill = atoi(argv[1]); + if (newSkill >= 0 and newSkill < MAXSKILLS) + { + g_nextskill = newSkill; + Printf("Skill will be changed for next game.\n"); + } + else + { + Printf("Please specify a skill level between 0 and %d\n", MAXSKILLS - 1); + } + } + else if (argsCount > 2) + { + Printf(PRINT_BOLD, "skill : returns the current skill level, and optionally sets the skill level for the next game.\n"); + } + } + else + { + Printf("Currently not in a game.\n"); + } +} diff --git a/source/core/gamestruct.h b/source/core/gamestruct.h index c78ae6359..5b864412b 100644 --- a/source/core/gamestruct.h +++ b/source/core/gamestruct.h @@ -121,6 +121,7 @@ struct GameInterface virtual bool GetGeoEffect(GeoEffect* eff, int viewsector) { return false; } virtual int Voxelize(int sprnum) { return -1; } virtual void AddExcludedEpisode(FString episode) {} + virtual int GetCurrentSkill() { return -1; } virtual FString statFPS() { diff --git a/source/games/blood/src/blood.cpp b/source/games/blood/src/blood.cpp index de3f9ed04..5099b170f 100644 --- a/source/games/blood/src/blood.cpp +++ b/source/games/blood/src/blood.cpp @@ -241,6 +241,12 @@ void GameInterface::NextLevel(MapRecord *map, int skill) NewLevel(map, skill, false); } +int GameInterface::GetCurrentSkill() +{ + return gGameOptions.nDifficulty; +} + + void GameInterface::Ticker() { for (int i = connecthead; i >= 0; i = connectpoint2[i]) diff --git a/source/games/blood/src/blood.h b/source/games/blood/src/blood.h index 093d96b66..69b92a1e2 100644 --- a/source/games/blood/src/blood.h +++ b/source/games/blood/src/blood.h @@ -149,6 +149,7 @@ struct GameInterface : public ::GameInterface void EnterPortal(spritetype* viewer, int type) override; void LeavePortal(spritetype* viewer, int type) override; void LoadGameTextures() override; + int GetCurrentSkill() override; GameStats getStats() override; }; diff --git a/source/games/duke/src/duke3d.h b/source/games/duke/src/duke3d.h index 9ec04fe09..8e8f4dfd2 100644 --- a/source/games/duke/src/duke3d.h +++ b/source/games/duke/src/duke3d.h @@ -68,6 +68,7 @@ struct GameInterface : public ::GameInterface void LeavePortal(spritetype* viewer, int type) override; bool GetGeoEffect(GeoEffect* eff, int viewsector) override; void AddExcludedEpisode(FString episode) override; + int GetCurrentSkill() override; }; diff --git a/source/games/duke/src/game.cpp b/source/games/duke/src/game.cpp index 3a23f8f2f..354ad43a3 100644 --- a/source/games/duke/src/game.cpp +++ b/source/games/duke/src/game.cpp @@ -272,6 +272,11 @@ void GameInterface::loadPalette() genspriteremaps(); } +int GameInterface::GetCurrentSkill() +{ + return ud.player_skill - 1; +} + //--------------------------------------------------------------------------- // // set up the game module's state diff --git a/source/games/exhumed/src/exhumed.h b/source/games/exhumed/src/exhumed.h index 1ad629dca..80a9d665c 100644 --- a/source/games/exhumed/src/exhumed.h +++ b/source/games/exhumed/src/exhumed.h @@ -248,6 +248,7 @@ struct GameInterface : public ::GameInterface int chaseCamY(binangle ang) { return -ang.bsin() / 12; } int chaseCamZ(fixedhoriz horiz) { return horiz.asq16() / 384; } void processSprites(spritetype* tsprite, int& spritesortcnt, int viewx, int viewy, int viewz, binangle viewang, double smoothRatio) override; + int GetCurrentSkill() override; ::GameStats getStats() override; }; diff --git a/source/games/exhumed/src/gameloop.cpp b/source/games/exhumed/src/gameloop.cpp index 2b95c1b95..0df2ce4ce 100644 --- a/source/games/exhumed/src/gameloop.cpp +++ b/source/games/exhumed/src/gameloop.cpp @@ -141,6 +141,11 @@ void GameInterface::NewGame(MapRecord *map, int skill, bool frommenu) gameaction = ga_level; } +int GameInterface::GetCurrentSkill() +{ + return -2; +} + int selectedlevelnew; DEFINE_ACTION_FUNCTION(DMapScreen, SetNextLevel) diff --git a/source/games/sw/src/game.cpp b/source/games/sw/src/game.cpp index 2818182b0..564421b15 100644 --- a/source/games/sw/src/game.cpp +++ b/source/games/sw/src/game.cpp @@ -580,6 +580,17 @@ void GameInterface::NewGame(MapRecord *map, int skill, bool) // //--------------------------------------------------------------------------- +int GameInterface::GetCurrentSkill() +{ + return Skill; +} + +//--------------------------------------------------------------------------- +// +// +// +//--------------------------------------------------------------------------- + void GameInterface::Ticker(void) { int i; diff --git a/source/games/sw/src/game.h b/source/games/sw/src/game.h index 8c515e487..752fc11da 100644 --- a/source/games/sw/src/game.h +++ b/source/games/sw/src/game.h @@ -2274,6 +2274,7 @@ struct GameInterface : public ::GameInterface void LeavePortal(spritetype* viewer, int type) override; int Voxelize(int sprnum); void ExitFromMenu() override; + int GetCurrentSkill() override; GameStats getStats() override;