Skip to content

Commit

Permalink
- Add skill CCMD to return player's current skill, while also being…
Browse files Browse the repository at this point in the history
… able to set skill for next game.

* Fixes #332.
  • Loading branch information
mjr4077au committed Jul 20, 2021
1 parent 77630dc commit 33845c4
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 0 deletions.
56 changes: 56 additions & 0 deletions source/core/cheats.cpp
Expand Up @@ -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 <newskill>: returns the current skill level, and optionally sets the skill level for the next game.\n");
}
}
else
{
Printf("Currently not in a game.\n");
}
}
1 change: 1 addition & 0 deletions source/core/gamestruct.h
Expand Up @@ -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()
{
Expand Down
6 changes: 6 additions & 0 deletions source/games/blood/src/blood.cpp
Expand Up @@ -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])
Expand Down
1 change: 1 addition & 0 deletions source/games/blood/src/blood.h
Expand Up @@ -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;
};
Expand Down
1 change: 1 addition & 0 deletions source/games/duke/src/duke3d.h
Expand Up @@ -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;

};

Expand Down
5 changes: 5 additions & 0 deletions source/games/duke/src/game.cpp
Expand Up @@ -272,6 +272,11 @@ void GameInterface::loadPalette()
genspriteremaps();
}

int GameInterface::GetCurrentSkill()
{
return ud.player_skill - 1;
}

//---------------------------------------------------------------------------
//
// set up the game module's state
Expand Down
1 change: 1 addition & 0 deletions source/games/exhumed/src/exhumed.h
Expand Up @@ -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;
};
Expand Down
5 changes: 5 additions & 0 deletions source/games/exhumed/src/gameloop.cpp
Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions source/games/sw/src/game.cpp
Expand Up @@ -580,6 +580,17 @@ void GameInterface::NewGame(MapRecord *map, int skill, bool)
//
//---------------------------------------------------------------------------

int GameInterface::GetCurrentSkill()
{
return Skill;
}

//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------

void GameInterface::Ticker(void)
{
int i;
Expand Down
1 change: 1 addition & 0 deletions source/games/sw/src/game.h
Expand Up @@ -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;
Expand Down

2 comments on commit 33845c4

@coelckers
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For future proofing this needs to run skill changing through the network protocol.

@mjr4077au
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For future proofing this needs to run skill changing through the network protocol.

I might be wrong, but I think it's already network-safe since funcs like ChangeLevel() which are taking g_nextskill as a variable already write it via the network:

void ChangeLevel(MapRecord* map, int skill)
{
	Net_WriteByte(DEM_CHANGEMAP);
	Net_WriteByte(skill);
	Net_WriteString(map? map->labelName : nullptr);
}
CCMD(restartmap)
{
	if (gamestate != GS_LEVEL || currentLevel == nullptr)
	{
		Printf("Must be in a game to restart a level.\n");
		return;
	}
	ChangeLevel(currentLevel, g_nextskill);
}

Please sign in to comment.