Merge pull request #21818 from Harry-Hopkinson/refactor-constant-notation

Refactor constant notation in Chat.h and Peep.h
This commit is contained in:
Michael Steenbeek 2024-04-21 00:14:44 +02:00 committed by GitHub
commit 3d05fce68e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 22 additions and 22 deletions

View File

@ -978,10 +978,10 @@ static StringId window_cheats_page_titles[] = {
CheatsSet(CheatType::SetGuestParameter, GUEST_PARAMETER_HAPPINESS, 0);
break;
case WIDX_GUEST_ENERGY_MAX:
CheatsSet(CheatType::SetGuestParameter, GUEST_PARAMETER_ENERGY, PEEP_MAX_ENERGY);
CheatsSet(CheatType::SetGuestParameter, GUEST_PARAMETER_ENERGY, kPeepMaxEnergy);
break;
case WIDX_GUEST_ENERGY_MIN:
CheatsSet(CheatType::SetGuestParameter, GUEST_PARAMETER_ENERGY, PEEP_MIN_ENERGY);
CheatsSet(CheatType::SetGuestParameter, GUEST_PARAMETER_ENERGY, kPeepMinEnergy);
break;
case WIDX_GUEST_HUNGER_MAX:
CheatsSet(CheatType::SetGuestParameter, GUEST_PARAMETER_HUNGER, 0);

View File

@ -1101,7 +1101,7 @@ static_assert(_guestWindowPageWidgets.size() == WINDOW_GUEST_PAGE_COUNT);
screenCoords.y += LIST_ROW_HEIGHT;
DrawTextBasic(dpi, screenCoords, STR_GUEST_STAT_ENERGY_LABEL);
int32_t energy = NormalizeGuestStatValue(peep->Energy - PEEP_MIN_ENERGY, PEEP_MAX_ENERGY - PEEP_MIN_ENERGY, 10);
int32_t energy = NormalizeGuestStatValue(peep->Energy - kPeepMinEnergy, kPeepMaxEnergy - kPeepMinEnergy, 10);
barColour = COLOUR_BRIGHT_GREEN;
barBlink = energy < 50;
StatsBarsDraw(energy, screenCoords, dpi, barColour, barBlink);

View File

@ -104,7 +104,7 @@ static Widget _windowServerStartWidgets[] = {
WindowStartTextbox(*this, widgetIndex, STR_STRING, _description, MAX_SERVER_DESCRIPTION_LENGTH);
break;
case WIDX_GREETING_INPUT:
WindowStartTextbox(*this, widgetIndex, STR_STRING, _greeting, CHAT_INPUT_SIZE);
WindowStartTextbox(*this, widgetIndex, STR_STRING, _greeting, kChatInputSize);
break;
case WIDX_PASSWORD_INPUT:
WindowStartTextbox(*this, widgetIndex, STR_STRING, _password, 32);
@ -259,7 +259,7 @@ static Widget _windowServerStartWidgets[] = {
char _port[7];
char _name[65];
char _description[MAX_SERVER_DESCRIPTION_LENGTH];
char _greeting[CHAT_INPUT_SIZE];
char _greeting[kChatInputSize];
char _password[33];
static void ScenarioSelectCallback(const utf8* path)
{

View File

@ -353,7 +353,7 @@ ParametersRange CheatSetAction::GetParameterRange(CheatType cheatType) const
{ 0, kPeepMaxHappiness } };
case GUEST_PARAMETER_ENERGY:
return { { GUEST_PARAMETER_HAPPINESS, GUEST_PARAMETER_PREFERRED_RIDE_INTENSITY },
{ PEEP_MIN_ENERGY, PEEP_MAX_ENERGY } };
{ kPeepMinEnergy, kPeepMaxEnergy } };
case GUEST_PARAMETER_HUNGER:
return { { GUEST_PARAMETER_HAPPINESS, GUEST_PARAMETER_PREFERRED_RIDE_INTENSITY }, { 0, kPeepMaxHunger } };
case GUEST_PARAMETER_THIRST:

View File

@ -838,16 +838,16 @@ void Guest::Loc68FA89()
}
else
{
newEnergy = std::min(PEEP_MAX_ENERGY_TARGET, newEnergy + 4);
newEnergy = std::min<uint16_t>(kPeepMaxEnergyTarget, newEnergy + 4);
if (newEnergy > newTargetEnergy)
newEnergy = newTargetEnergy;
}
if (newEnergy < PEEP_MIN_ENERGY)
newEnergy = PEEP_MIN_ENERGY;
if (newEnergy < kPeepMinEnergy)
newEnergy = kPeepMinEnergy;
/* Previous code here suggested maximum energy is 128. */
newEnergy = std::min(static_cast<uint8_t>(PEEP_MAX_ENERGY), newEnergy);
newEnergy = std::min(kPeepMaxEnergy, newEnergy);
if (newEnergy != Energy)
{
@ -3035,7 +3035,7 @@ static void PeepUpdateHunger(Guest* peep)
{
peep->Hunger -= 2;
peep->EnergyTarget = std::min(peep->EnergyTarget + 2, PEEP_MAX_ENERGY_TARGET);
peep->EnergyTarget = std::min<uint16_t>(peep->EnergyTarget + 2, kPeepMaxEnergyTarget);
peep->Toilet = std::min(peep->Toilet + 1, 255);
}
}

View File

@ -21,9 +21,9 @@
#include <array>
#include <optional>
#define PEEP_MIN_ENERGY 32
#define PEEP_MAX_ENERGY 128
#define PEEP_MAX_ENERGY_TARGET 255 // Oddly, this differs from max energy!
constexpr uint8_t kPeepMinEnergy = 32;
constexpr uint8_t kPeepMaxEnergy = 128;
constexpr uint8_t kPeepMaxEnergyTarget = 255; // Oddly, this differs from max energy!
constexpr auto PEEP_CLEARANCE_HEIGHT = 4 * COORDS_Z_STEP;

View File

@ -53,7 +53,7 @@ bool ChatAvailable()
void ChatOpen()
{
gChatOpen = true;
_chatTextInputSession = ContextStartTextInput(_chatCurrentLine, CHAT_MAX_MESSAGE_LENGTH);
_chatTextInputSession = ContextStartTextInput(_chatCurrentLine, kChatMaxMessageLength);
}
void ChatClose()
@ -97,7 +97,7 @@ void ChatDraw(DrawPixelInfo& dpi, uint8_t chatBackgroundColor)
}
_chatLeft = 10;
_chatRight = std::min((ContextGetWidth() - 10), CHAT_MAX_WINDOW_WIDTH);
_chatRight = std::min<int16_t>((ContextGetWidth() - 10), kChatMaxWindowWidth);
_chatWidth = _chatRight - _chatLeft;
_chatBottom = ContextGetHeight() - 45;
_chatTop = _chatBottom - 10;
@ -158,7 +158,7 @@ void ChatDraw(DrawPixelInfo& dpi, uint8_t chatBackgroundColor)
int32_t stringHeight = 0;
// Draw chat history
for (size_t i = 0; i < CHAT_HISTORY_SIZE; i++, screenCoords.y -= stringHeight)
for (size_t i = 0; i < kChatHistorySize; i++, screenCoords.y -= stringHeight)
{
if (i >= _chatHistory.size())
break;
@ -220,7 +220,7 @@ void ChatAddHistory(std::string_view s)
std::string buffer = timeBuffer;
buffer += s;
if (_chatHistory.size() >= CHAT_HISTORY_SIZE)
if (_chatHistory.size() >= kChatHistorySize)
{
_chatHistory.pop_back();
_chatHistoryTime.pop_back();

View File

@ -14,10 +14,10 @@
#include <string_view>
#define CHAT_HISTORY_SIZE 10
#define CHAT_INPUT_SIZE 1024
#define CHAT_MAX_MESSAGE_LENGTH 200
#define CHAT_MAX_WINDOW_WIDTH 600
constexpr int8_t kChatHistorySize = 10;
constexpr int16_t kChatInputSize = 1024;
constexpr uint8_t kChatMaxMessageLength = 200;
constexpr int16_t kChatMaxWindowWidth = 600;
struct DrawPixelInfo;
struct ScreenCoordsXY;