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 4, 2024
1 parent 6510593 commit 02b1068
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 31 deletions.
12 changes: 6 additions & 6 deletions src/common/GameValues.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,14 @@ void CGameValues::init()
teamcolors = true;
cputurn = -1;
shieldtime = 62;
shieldstyle = 2;
shieldstyle = ShieldStyle::SoftWithStomp;
musicvolume = 128;
soundvolume = 128;
respawn = 2;
itemrespawntime = 1860; //default item respawn is 30 seconds (30 * 62 fps)
hiddenblockrespawn = 1860; //default item respawn is 30 seconds
outofboundstime = 5;
warplockstyle = 1; // Lock Warp Exit Only
warplockstyle = WarpLockStyle::ExitOnly; // Lock Warp Exit Only
warplocktime = 186; // 3 seconds
#ifdef _DEBUG
suicidetime = 0; // Turn off suicide kills for debug
Expand Down Expand Up @@ -278,7 +278,7 @@ void CGameValues::ReadBinaryConfig() {
startmodedisplay = options.read_u8();

shieldtime = options.read_i16();
shieldstyle = options.read_i16();
shieldstyle = static_cast<ShieldStyle>(options.read_i16());
itemrespawntime = options.read_i16();
hiddenblockrespawn = options.read_i16();
fireballttl = options.read_i16();
Expand All @@ -303,7 +303,7 @@ void CGameValues::ReadBinaryConfig() {
redblockttl = options.read_i16();
grayblockttl = options.read_i16();
storedpowerupdelay = options.read_i16();
warplockstyle = options.read_i16();
warplockstyle = static_cast<WarpLockStyle>(options.read_i16());
warplocktime = options.read_i16();
suicidetime = options.read_i16();

Expand Down Expand Up @@ -416,7 +416,7 @@ void CGameValues::WriteConfig()
options.write_u8(startmodedisplay);

options.write_i16(shieldtime);
options.write_i16(shieldstyle);
options.write_i16(static_cast<short>(shieldstyle));
options.write_i16(itemrespawntime);
options.write_i16(hiddenblockrespawn);
options.write_i16(fireballttl);
Expand All @@ -441,7 +441,7 @@ void CGameValues::WriteConfig()
options.write_i16(redblockttl);
options.write_i16(grayblockttl);
options.write_i16(storedpowerupdelay);
options.write_i16(warplockstyle);
options.write_i16(static_cast<short>(warplockstyle));
options.write_i16(warplocktime);
options.write_i16(suicidetime);

Expand Down
4 changes: 2 additions & 2 deletions src/common/GameValues.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class CGameConfig {
short boomeranglife;
short boomeranglimit;
short cpudifficulty;
short warplockstyle;
WarpLockStyle warplockstyle;
short warplocktime;
short hammerttl;
short hammerdelay;
Expand Down Expand Up @@ -162,7 +162,7 @@ class CGameConfig {
ScoreboardStyle scoreboardstyle;
bool screencrunch;
short shieldtime;
short shieldstyle;
ShieldStyle shieldstyle;
bool showwinningcrown;
short skinids[4];
short wandlimit;
Expand Down
17 changes: 17 additions & 0 deletions src/common/GameplayStyles.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,26 @@ enum class JailStyle : unsigned char {
};


enum class ShieldStyle : unsigned char {
NoShield,
Soft,
SoftWithStomp,
Hard,
};


enum class StarStyle : unsigned char {
Ztar,
Shine,
Multi,
Random,
};


enum class WarpLockStyle : unsigned char {
EntranceOnly,
ExitOnly,
EntranceAndExit,
EntireConnection,
AllWarps,
};
2 changes: 2 additions & 0 deletions src/common/ui/MI_SelectField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,4 +383,6 @@ template class MI_SelectField<TeamCollisionStyle>;
template class MI_SelectField<TournamentControlStyle>;
template class MI_SelectField<DeathStyle>;
template class MI_SelectField<JailStyle>;
template class MI_SelectField<ShieldStyle>;
template class MI_SelectField<StarStyle>;
template class MI_SelectField<WarpLockStyle>;
22 changes: 11 additions & 11 deletions src/smw/menu/options/GameplayOptionsMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ UI_GameplayOptionsMenu::UI_GameplayOptionsMenu()
miRespawnField->setOutputPtr(&game_values.respawn);
miRespawnField->setCurrentValue(game_values.respawn);

miShieldStyleField = new MI_SelectField<short>(&rm->spr_selectfield, 70, 80, "Shield Style", 500, 220);
miShieldStyleField->add("No Shield", 0);
miShieldStyleField->add("Soft", 1);
miShieldStyleField->add("Soft with Stomp", 2);
miShieldStyleField->add("Hard", 3);
miShieldStyleField = new MI_SelectField<ShieldStyle>(&rm->spr_selectfield, 70, 80, "Shield Style", 500, 220);
miShieldStyleField->add("No Shield", ShieldStyle::NoShield);
miShieldStyleField->add("Soft", ShieldStyle::Soft);
miShieldStyleField->add("Soft with Stomp", ShieldStyle::SoftWithStomp);
miShieldStyleField->add("Hard", ShieldStyle::Hard);
miShieldStyleField->setOutputPtr(&game_values.shieldstyle);
miShieldStyleField->setCurrentValue(game_values.shieldstyle);

Expand Down Expand Up @@ -87,12 +87,12 @@ UI_GameplayOptionsMenu::UI_GameplayOptionsMenu()
miSuicideTimeField->setOutputPtr(&game_values.suicidetime);
miSuicideTimeField->setCurrentValue(game_values.suicidetime);

miWarpLockStyleField = new MI_SelectField<short>(&rm->spr_selectfield, 70, 240, "Warp Lock Style", 500, 220);
miWarpLockStyleField->add("Entrance Only", 0);
miWarpLockStyleField->add("Exit Only", 1);
miWarpLockStyleField->add("Entrance and Exit", 2);
miWarpLockStyleField->add("Entire Connection", 3);
miWarpLockStyleField->add("All Warps", 4);
miWarpLockStyleField = new MI_SelectField<WarpLockStyle>(&rm->spr_selectfield, 70, 240, "Warp Lock Style", 500, 220);
miWarpLockStyleField->add("Entrance Only", WarpLockStyle::EntranceOnly);
miWarpLockStyleField->add("Exit Only", WarpLockStyle::ExitOnly);
miWarpLockStyleField->add("Entrance and Exit", WarpLockStyle::EntranceAndExit);
miWarpLockStyleField->add("Entire Connection", WarpLockStyle::EntireConnection);
miWarpLockStyleField->add("All Warps", WarpLockStyle::AllWarps);
miWarpLockStyleField->setOutputPtr(&game_values.warplockstyle);
miWarpLockStyleField->setCurrentValue(game_values.warplockstyle);

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

#include "GameplayStyles.h"
#include "uimenu.h"

class MI_Button;
Expand All @@ -17,11 +18,11 @@ class UI_GameplayOptionsMenu : public UI_Menu {

private:
MI_SelectField<short>* miRespawnField;
MI_SelectField<short>* miShieldStyleField;
MI_SelectField<ShieldStyle>* miShieldStyleField;
MI_SelectField<short>* miShieldTimeField;
MI_SelectField<short>* miBoundsTimeField;
MI_SelectField<short>* miSuicideTimeField;
MI_SelectField<short>* miWarpLockStyleField;
MI_SelectField<WarpLockStyle>* miWarpLockStyleField;
MI_SelectField<short>* miWarpLockTimeField;
MI_SelectField<short>* miBotsField;
MI_SelectField<short>* miPointSpeedField;
Expand Down
4 changes: 2 additions & 2 deletions src/smw/player_components/PlayerShield.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ void PlayerShield::reset()
timer = game_values.shieldtime;
type = (PlayerShieldType)game_values.shieldstyle;
}
} else if (game_values.shieldstyle > 0) {
} else if (game_values.shieldstyle != ShieldStyle::NoShield) {
timer = game_values.shieldtime;
type = (PlayerShieldType)game_values.shieldstyle;
}
}

void PlayerShield::turn_on()
{
type = game_values.shieldstyle > 0 ? (PlayerShieldType)game_values.shieldstyle : SOFT;
type = game_values.shieldstyle != ShieldStyle::NoShield ? (PlayerShieldType)game_values.shieldstyle : SOFT;
timer = 60;
}

Expand Down
24 changes: 16 additions & 8 deletions src/smw/player_components/PlayerWarpStatus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,20 @@ void PlayerWarpStatus::enterWarp(CPlayer& player, Warp* warp)
warpid = warp->id;

if (game_values.warplocktime > 0) {
if (game_values.warplockstyle == 0 || game_values.warplockstyle == 2) //Lock the entrance
g_map->warpexits[warp->id].locktimer = game_values.warplocktime;
else if (game_values.warplockstyle == 3) //Lock the connection
g_map->lockconnection(warpconnection);
else if (game_values.warplockstyle == 4) //Lock all warps
g_map->lockconnection(-1);
switch (game_values.warplockstyle) {
case WarpLockStyle::EntranceOnly:
case WarpLockStyle::EntranceAndExit:
g_map->warpexits[warp->id].locktimer = game_values.warplocktime;
break;
case WarpLockStyle::EntireConnection:
g_map->lockconnection(warpconnection);
break;
case WarpLockStyle::AllWarps:
g_map->lockconnection(-1);
break;
default:
break;
}
}

ifSoundOnPlay(rm->sfx_pipe);
Expand Down Expand Up @@ -224,15 +232,15 @@ void PlayerWarpStatus::chooseWarpExit(CPlayer& player)
}

//Make player shielded when exiting the warp (if that option is turned on)
if (game_values.shieldstyle > 0) {
if (game_values.shieldstyle != ShieldStyle::NoShield) {
if (!player.isShielded() || player.shield.time_left() < game_values.shieldtime) {
player.shield.reset();
}
}

//Lock the warp (if that option is turned on)
if (game_values.warplocktime > 0) {
if (game_values.warplockstyle == 1 || game_values.warplockstyle == 2) //Lock the warp exit
if (game_values.warplockstyle == WarpLockStyle::ExitOnly || game_values.warplockstyle == WarpLockStyle::EntranceAndExit) //Lock the warp exit
exit->locktimer = game_values.warplocktime;
}
}

0 comments on commit 02b1068

Please sign in to comment.