Skip to content

Commit

Permalink
Replaced some more raw values with enums
Browse files Browse the repository at this point in the history
  • Loading branch information
mmatyas committed Apr 3, 2024
1 parent 1c76125 commit 069a012
Show file tree
Hide file tree
Showing 15 changed files with 115 additions and 82 deletions.
10 changes: 5 additions & 5 deletions src/common/GameModeSettings.cpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
#include "GameModeSettings.h"

ClassicGameModeSettings::ClassicGameModeSettings()
: style(0) //Respawn on death
: style(DeathStyle::Respawn) //Respawn on death
, scoring(0) //All kills will score
{}

FragGameModeSettings::FragGameModeSettings()
: style(0) //Respawn on death
: style(DeathStyle::Respawn) //Respawn on death
, scoring(0) //All kills will score
{}

TimeGameModeSettings::TimeGameModeSettings()
: style(0) //Respawn on death
: style(DeathStyle::Respawn) //Respawn on death
, scoring(0) //All kills will score
, percentextratime(10) //10% chance of a heart spawning
{}

JailGameModeSettings::JailGameModeSettings()
: style(1) //defaults to color jail play
: style(JailStyle::Owned) //defaults to color jail play
, tagfree(true) //players on same team can free player by touching
, timetofree(1240) //20 seconds of jail
, percentkey(30) //30% chance of a key spawning
Expand Down Expand Up @@ -74,7 +74,7 @@ TagGameModeSettings::TagGameModeSettings()

StarGameModeSettings::StarGameModeSettings()
: time(30) //default to 30 seconds
, shine(0) //default to hot potato (ztar)
, shine(StarStyle::Ztar) //default to hot potato (ztar)
, percentextratime(10) //10 percent chance of an extra time poweurp spawning
{}

Expand Down
11 changes: 6 additions & 5 deletions src/common/GameModeSettings.h
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
#ifndef GAMEMODESETTINGS_H
#define GAMEMODESETTINGS_H

#include "GameplayStyles.h"
#include "GlobalConstants.h"
#include "MatchTypes.h"

struct ClassicGameModeSettings {
short style; //on kill, either respawn the player or shield them and let them keep playing
DeathStyle style; //on kill, either respawn the player or shield them and let them keep playing
short scoring; //When to credit a score, all kills or push kills only (sumo mode)

ClassicGameModeSettings();
};

struct FragGameModeSettings {
short style; //on kill, either respawn the player or shield them and let them keep playing
DeathStyle style; //on kill, either respawn the player or shield them and let them keep playing
short scoring; //When to credit a score, all kills or push kills only (sumo mode)

FragGameModeSettings();
};

struct TimeGameModeSettings {
short style; //on kill, either respawn the player or shield them and let them keep playing
DeathStyle style; //on kill, either respawn the player or shield them and let them keep playing
short scoring; //When to credit a score, all kills or push kills only (sumo mode)
short percentextratime; //percent chance a stopwatch with extra game time will spawn

TimeGameModeSettings();
};

struct JailGameModeSettings {
short style; //Style of play: classic, owned, free for all
JailStyle style; //Style of play: classic, owned, free for all
bool tagfree; //Free jailed player by tagging on same team
short timetofree; //Time it takes for a jailed player to be freed
short percentkey; //percent chance a jail key will spawn
Expand Down Expand Up @@ -84,7 +85,7 @@ struct TagGameModeSettings {

struct StarGameModeSettings {
short time; //Time to get rid or keep star
short shine; //If we are playing shine mode vs. ztar vs. stars mode
StarStyle shine; //If we are playing shine mode vs. ztar vs. stars mode
short percentextratime; //percent chance a stopwatch with extra game time will spawn

StarGameModeSettings();
Expand Down
21 changes: 21 additions & 0 deletions src/common/GameplayStyles.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,24 @@ enum class TournamentControlStyle : unsigned char {
RandomLoser,
RoundRobin,
};


enum class DeathStyle : unsigned char {
Respawn,
Shield,
};


enum class JailStyle : unsigned char {
Classic,
Owned,
FreeForAll,
};


enum class StarStyle : unsigned char {
Ztar,
Shine,
Multi,
Random,
};
3 changes: 3 additions & 0 deletions src/common/ui/MI_SelectField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,3 +381,6 @@ template class MI_SelectField<SpawnStyle>;
#include "GameplayStyles.h"
template class MI_SelectField<TeamCollisionStyle>;
template class MI_SelectField<TournamentControlStyle>;
template class MI_SelectField<DeathStyle>;
template class MI_SelectField<JailStyle>;
template class MI_SelectField<StarStyle>;
4 changes: 2 additions & 2 deletions src/smw/gamemodes/Classic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ PlayerKillType CGM_Classic::playerkilledplayer(CPlayer &inflictor, CPlayer &othe
}
}

if (game_values.gamemode->gamemode == game_mode_classic && game_values.gamemodesettings.classic.style == 1) {
if (game_values.gamemode->gamemode == game_mode_classic && game_values.gamemodesettings.classic.style == DeathStyle::Shield) {
ifSoundOnPlay(rm->sfx_powerdown);
other.Shield().reset();
return PlayerKillType::NonKill;
Expand Down Expand Up @@ -116,7 +116,7 @@ PlayerKillType CGM_Classic::playerkilledself(CPlayer &player, KillStyle style)
}
}

if (game_values.gamemode->gamemode == game_mode_classic && game_values.gamemodesettings.classic.style == 1) {
if (game_values.gamemode->gamemode == game_mode_classic && game_values.gamemodesettings.classic.style == DeathStyle::Shield) {
ifSoundOnPlay(rm->sfx_powerdown);
player.Shield().reset();
return PlayerKillType::NonKill;
Expand Down
4 changes: 2 additions & 2 deletions src/smw/gamemodes/Frag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ PlayerKillType CGM_Frag::playerkilledplayer(CPlayer &inflictor, CPlayer &other,

PlayerKillType iRet = CheckWinner(&inflictor);

if (game_values.gamemode->gamemode == game_mode_frag && game_values.gamemodesettings.frag.style == 1) {
if (game_values.gamemode->gamemode == game_mode_frag && game_values.gamemodesettings.frag.style == DeathStyle::Shield) {
ifSoundOnPlay(rm->sfx_powerdown);
other.Shield().reset();
return PlayerKillType::NonKill;
Expand All @@ -50,7 +50,7 @@ PlayerKillType CGM_Frag::playerkilledself(CPlayer &player, KillStyle style)
if (!gameover) {
player.Score().AdjustScore(-1);

if (game_values.gamemode->gamemode == game_mode_frag && game_values.gamemodesettings.frag.style == 1) {
if (game_values.gamemode->gamemode == game_mode_frag && game_values.gamemodesettings.frag.style == DeathStyle::Shield) {
ifSoundOnPlay(rm->sfx_powerdown);
player.Shield().reset();
return PlayerKillType::NonKill;
Expand Down
4 changes: 2 additions & 2 deletions src/smw/gamemodes/Jail.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ PlayerKillType CGM_Jail::playerkilledplayer(CPlayer &inflictor, CPlayer &other,
other.Jail().lockInBy(inflictor);

//Apply rules for "Classic" jail
if (game_values.gamemodesettings.jail.style == 0) {
if (game_values.gamemodesettings.jail.style == JailStyle::Classic) {
short jailedteams[4];

short i;
Expand Down Expand Up @@ -91,7 +91,7 @@ PlayerKillType CGM_Jail::playerkilledplayer(CPlayer &inflictor, CPlayer &other,
}
}
//Apply rules for "Owned" jail
else if (game_values.gamemodesettings.jail.style == 1) {
else if (game_values.gamemodesettings.jail.style == JailStyle::Owned) {
short jailedteams[4] = {-1, -1, -1, -1};

//Figure out which teams have been jailed
Expand Down
38 changes: 17 additions & 21 deletions src/smw/gamemodes/Star.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ CGM_Star::CGM_Star() : CGM_TimeLimit()
goal = 5;
gamemode = game_mode_star;
SetupModeStrings("Star", "Lives", 1);
iCurrentModeType = 0;
iCurrentModeType = StarStyle::Ztar;
};

void CGM_Star::init()
Expand All @@ -38,12 +38,9 @@ void CGM_Star::init()

gameClock.Init(game_values.gamemodesettings.star.time < 1 ? 30 : game_values.gamemodesettings.star.time, true);

if (game_values.gamemodesettings.star.shine < 0 || game_values.gamemodesettings.star.shine > 3)
game_values.gamemodesettings.star.shine = 0;

iCurrentModeType = game_values.gamemodesettings.star.shine;
if (iCurrentModeType == 3)
iCurrentModeType = RANDOM_INT(3);
if (iCurrentModeType == StarStyle::Random)
iCurrentModeType = static_cast<StarStyle>(RANDOM_INT(3));

fReverseScoring = goal == -1;

Expand Down Expand Up @@ -77,7 +74,7 @@ void CGM_Star::SetupMode()
}

//If multi star, add more stars
if (iCurrentModeType == 2) {
if (iCurrentModeType == StarStyle::Multi) {
CPlayer * players[4];
short iNumPlayers = GetScoreRankedPlayerList(players, fReverseScoring);

Expand All @@ -89,9 +86,9 @@ void CGM_Star::SetupMode()
objectcontainer[1].add(starItem[iStar]);
}
} else { //otherwise, add just a single star
starPlayer[0] = GetHighestScorePlayer(!fReverseScoring && iCurrentModeType == 0);
starPlayer[0] = GetHighestScorePlayer(!fReverseScoring && iCurrentModeType == StarStyle::Ztar);

starItem[0] = new CO_Star(&rm->spr_star, iCurrentModeType == 0 ? 0 : 1, 0);
starItem[0] = new CO_Star(&rm->spr_star, iCurrentModeType == StarStyle::Ztar ? 0 : 1, 0);
objectcontainer[1].add(starItem[0]);
}
}
Expand All @@ -104,7 +101,7 @@ void CGM_Star::think()
}

//Make sure there is a star player(s)
if (iCurrentModeType == 2) {
if (iCurrentModeType == StarStyle::Multi) {
for (short iStar1 = 0; iStar1 < list_players_cnt - 1; iStar1++) {
//If we're missing a star player, then reassign them all
if (!starPlayer[iStar1]) {
Expand All @@ -122,7 +119,7 @@ void CGM_Star::think()
}
} else {
if (!starPlayer[0]) {
starPlayer[0] = GetHighestScorePlayer(!fReverseScoring && !game_values.gamemodesettings.star.shine);
starPlayer[0] = GetHighestScorePlayer(!fReverseScoring && game_values.gamemodesettings.star.shine == StarStyle::Ztar);
starItem[0]->placeStar();
}
}
Expand All @@ -138,7 +135,7 @@ void CGM_Star::think()
gameClock.SetTime(game_values.gamemodesettings.star.time < 1 ? 30 : game_values.gamemodesettings.star.time);
ifSoundOnPlay(rm->sfx_thunder);

if (iCurrentModeType == 0) {
if (iCurrentModeType == StarStyle::Ztar) {
if (score[starPlayer[0]->getTeamID()]->score > 1 || fReverseScoring)
starPlayer[0]->KillPlayerMapHazard(true, KillStyle::Environment, false);

Expand All @@ -155,7 +152,7 @@ void CGM_Star::think()

starPlayer[0] = GetHighestScorePlayer(!fReverseScoring);
starItem[0]->placeStar();
} else if (iCurrentModeType == 1) {
} else if (iCurrentModeType == StarStyle::Shine) {
for (short iPlayer = 0; iPlayer < list_players_cnt; iPlayer++) {
if (starPlayer[0]->getTeamID() == list_players[iPlayer]->getTeamID())
continue;
Expand All @@ -182,7 +179,7 @@ void CGM_Star::think()

starPlayer[0] = GetHighestScorePlayer(false);
starItem[0]->placeStar();
} else if (iCurrentModeType == 2) {
} else if (iCurrentModeType == StarStyle::Multi) {
for (short iPlayer = 0; iPlayer < list_players_cnt; iPlayer++) {
bool fFound = false;
for (short iStar = 0; iStar < list_players_cnt - 1; iStar++) {
Expand All @@ -208,14 +205,14 @@ void CGM_Star::think()
fDisplayTimer = !RemoveTeam(list_players[iPlayer]->getTeamID());

//Don't setup the mode if this is a random game because it will be setup below
if (game_values.gamemodesettings.star.shine != 3) {
if (game_values.gamemodesettings.star.shine != StarStyle::Random) {
SetupMode();
fNeedRebalance = false;
}
}
}

if (game_values.gamemodesettings.star.shine != 3 && fNeedRebalance) {
if (game_values.gamemodesettings.star.shine != StarStyle::Random && fNeedRebalance) {
CPlayer * players[4];
short iNumPlayers = GetScoreRankedPlayerList(players, fReverseScoring);

Expand Down Expand Up @@ -253,9 +250,8 @@ void CGM_Star::think()
}

//If random game, then choose a new game type
if (game_values.gamemodesettings.star.shine == 3 && fDisplayTimer) {
#pragma warning ("neagix: This should be 4, possibly?")
iCurrentModeType = RANDOM_INT(3);
if (game_values.gamemodesettings.star.shine == StarStyle::Random && fDisplayTimer) {
iCurrentModeType = static_cast<StarStyle>(RANDOM_INT(3));
SetupMode();
}
}
Expand Down Expand Up @@ -311,11 +307,11 @@ CPlayer * CGM_Star::swapplayer(short id, CPlayer * player)

starPlayer[id] = player;

if (iCurrentModeType == 2)
if (iCurrentModeType == StarStyle::Multi)
starItem[id]->setPlayerColor(starPlayer[id]->getColorID());

if (starItem[id]->getType() == 1)
eyecandy[2].add(new EC_GravText(&rm->game_font_large, player->centerX(), player->bottomY(), iCurrentModeType == 2 ? "Star Get!" : "Shine Get!", -VELJUMP*1.5));
eyecandy[2].add(new EC_GravText(&rm->game_font_large, player->centerX(), player->bottomY(), iCurrentModeType == StarStyle::Multi ? "Star Get!" : "Shine Get!", -VELJUMP*1.5));
else
eyecandy[2].add(new EC_GravText(&rm->game_font_large, player->centerX(), player->bottomY(), "Ztarred!", -VELJUMP*1.5));

Expand Down
5 changes: 3 additions & 2 deletions src/smw/gamemodes/Star.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "TimeLimit.h"
#include "GameplayStyles.h"

class CO_Star;

Expand All @@ -27,7 +28,7 @@ class CGM_Star : public CGM_TimeLimit
return starPlayer[id];
}

short getcurrentmodetype() {
StarStyle getcurrentmodetype() const {
return iCurrentModeType;
}

Expand All @@ -42,6 +43,6 @@ class CGM_Star : public CGM_TimeLimit

CO_Star * starItem[3];
CPlayer * starPlayer[3];
short iCurrentModeType;
StarStyle iCurrentModeType;
bool fDisplayTimer;
};
2 changes: 1 addition & 1 deletion src/smw/gamemodes/TimeLimit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ PlayerKillType CGM_TimeLimit::playerkilledplayer(CPlayer &inflictor, CPlayer &ot
inflictor.Score().AdjustScore(1);
}

if (game_values.gamemode->gamemode == game_mode_timelimit && game_values.gamemodesettings.time.style == 1) {
if (game_values.gamemode->gamemode == game_mode_timelimit && game_values.gamemodesettings.time.style == DeathStyle::Shield) {
ifSoundOnPlay(rm->sfx_powerdown);
other.Shield().reset();
return PlayerKillType::NonKill;
Expand Down
Loading

0 comments on commit 069a012

Please sign in to comment.