From 02b1068d7745cf3883a4c7d3b5371d531b9b4aeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1ty=C3=A1s=20Mustoha?= Date: Thu, 4 Apr 2024 17:15:23 +0200 Subject: [PATCH] Replaced some more raw values with enums --- src/common/GameValues.cpp | 12 +++++----- src/common/GameValues.h | 4 ++-- src/common/GameplayStyles.h | 17 +++++++++++++ src/common/ui/MI_SelectField.cpp | 2 ++ src/smw/menu/options/GameplayOptionsMenu.cpp | 22 ++++++++--------- src/smw/menu/options/GameplayOptionsMenu.h | 5 ++-- src/smw/player_components/PlayerShield.cpp | 4 ++-- .../player_components/PlayerWarpStatus.cpp | 24 ++++++++++++------- 8 files changed, 59 insertions(+), 31 deletions(-) diff --git a/src/common/GameValues.cpp b/src/common/GameValues.cpp index c1fe5be69..73ff05db8 100644 --- a/src/common/GameValues.cpp +++ b/src/common/GameValues.cpp @@ -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 @@ -278,7 +278,7 @@ void CGameValues::ReadBinaryConfig() { startmodedisplay = options.read_u8(); shieldtime = options.read_i16(); - shieldstyle = options.read_i16(); + shieldstyle = static_cast(options.read_i16()); itemrespawntime = options.read_i16(); hiddenblockrespawn = options.read_i16(); fireballttl = options.read_i16(); @@ -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(options.read_i16()); warplocktime = options.read_i16(); suicidetime = options.read_i16(); @@ -416,7 +416,7 @@ void CGameValues::WriteConfig() options.write_u8(startmodedisplay); options.write_i16(shieldtime); - options.write_i16(shieldstyle); + options.write_i16(static_cast(shieldstyle)); options.write_i16(itemrespawntime); options.write_i16(hiddenblockrespawn); options.write_i16(fireballttl); @@ -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(warplockstyle)); options.write_i16(warplocktime); options.write_i16(suicidetime); diff --git a/src/common/GameValues.h b/src/common/GameValues.h index d2608438a..f4ad82fb5 100644 --- a/src/common/GameValues.h +++ b/src/common/GameValues.h @@ -130,7 +130,7 @@ class CGameConfig { short boomeranglife; short boomeranglimit; short cpudifficulty; - short warplockstyle; + WarpLockStyle warplockstyle; short warplocktime; short hammerttl; short hammerdelay; @@ -162,7 +162,7 @@ class CGameConfig { ScoreboardStyle scoreboardstyle; bool screencrunch; short shieldtime; - short shieldstyle; + ShieldStyle shieldstyle; bool showwinningcrown; short skinids[4]; short wandlimit; diff --git a/src/common/GameplayStyles.h b/src/common/GameplayStyles.h index a0c0b9509..935774654 100644 --- a/src/common/GameplayStyles.h +++ b/src/common/GameplayStyles.h @@ -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, +}; diff --git a/src/common/ui/MI_SelectField.cpp b/src/common/ui/MI_SelectField.cpp index 3c50e65d4..853f57c24 100644 --- a/src/common/ui/MI_SelectField.cpp +++ b/src/common/ui/MI_SelectField.cpp @@ -383,4 +383,6 @@ template class MI_SelectField; template class MI_SelectField; template class MI_SelectField; template class MI_SelectField; +template class MI_SelectField; template class MI_SelectField; +template class MI_SelectField; diff --git a/src/smw/menu/options/GameplayOptionsMenu.cpp b/src/smw/menu/options/GameplayOptionsMenu.cpp index d3a13ca14..928f36010 100644 --- a/src/smw/menu/options/GameplayOptionsMenu.cpp +++ b/src/smw/menu/options/GameplayOptionsMenu.cpp @@ -39,11 +39,11 @@ UI_GameplayOptionsMenu::UI_GameplayOptionsMenu() miRespawnField->setOutputPtr(&game_values.respawn); miRespawnField->setCurrentValue(game_values.respawn); - miShieldStyleField = new MI_SelectField(&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(&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); @@ -87,12 +87,12 @@ UI_GameplayOptionsMenu::UI_GameplayOptionsMenu() miSuicideTimeField->setOutputPtr(&game_values.suicidetime); miSuicideTimeField->setCurrentValue(game_values.suicidetime); - miWarpLockStyleField = new MI_SelectField(&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(&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); diff --git a/src/smw/menu/options/GameplayOptionsMenu.h b/src/smw/menu/options/GameplayOptionsMenu.h index c86f4146c..5822a4a18 100644 --- a/src/smw/menu/options/GameplayOptionsMenu.h +++ b/src/smw/menu/options/GameplayOptionsMenu.h @@ -1,5 +1,6 @@ #pragma once +#include "GameplayStyles.h" #include "uimenu.h" class MI_Button; @@ -17,11 +18,11 @@ class UI_GameplayOptionsMenu : public UI_Menu { private: MI_SelectField* miRespawnField; - MI_SelectField* miShieldStyleField; + MI_SelectField* miShieldStyleField; MI_SelectField* miShieldTimeField; MI_SelectField* miBoundsTimeField; MI_SelectField* miSuicideTimeField; - MI_SelectField* miWarpLockStyleField; + MI_SelectField* miWarpLockStyleField; MI_SelectField* miWarpLockTimeField; MI_SelectField* miBotsField; MI_SelectField* miPointSpeedField; diff --git a/src/smw/player_components/PlayerShield.cpp b/src/smw/player_components/PlayerShield.cpp index 9f4a02225..c339f54d9 100644 --- a/src/smw/player_components/PlayerShield.cpp +++ b/src/smw/player_components/PlayerShield.cpp @@ -14,7 +14,7 @@ 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; } @@ -22,7 +22,7 @@ void PlayerShield::reset() 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; } diff --git a/src/smw/player_components/PlayerWarpStatus.cpp b/src/smw/player_components/PlayerWarpStatus.cpp index c280fcc5f..fea072e0f 100644 --- a/src/smw/player_components/PlayerWarpStatus.cpp +++ b/src/smw/player_components/PlayerWarpStatus.cpp @@ -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); @@ -224,7 +232,7 @@ 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(); } @@ -232,7 +240,7 @@ void PlayerWarpStatus::chooseWarpExit(CPlayer& player) //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; } }