diff --git a/src/automap.cc b/src/automap.cc index 6df1686..6542970 100644 --- a/src/automap.cc +++ b/src/automap.cc @@ -22,6 +22,8 @@ #include #include +#include + // 0x41ADE0 const int _defam[AUTOMAP_MAP_COUNT][ELEVATION_COUNT] = { { -1, -1, -1 }, @@ -1070,7 +1072,7 @@ int _copy_file_data(File* stream1, File* stream2, int length) // NOTE: Original code is slightly different, but does the same thing. while (length != 0) { - int chunkLength = min(length, 0xFFFF); + int chunkLength = std::min(length, 0xFFFF); if (fileRead(buffer, chunkLength, 1, stream1) != 1) { break; diff --git a/src/autorun.h b/src/autorun.h index ba84d7e..46ecd03 100644 --- a/src/autorun.h +++ b/src/autorun.h @@ -2,6 +2,7 @@ #define AUTORUN_H #define WIN32_LEAN_AND_MEAN +#define NOMINMAX #include extern HANDLE gInterplayGenericAutorunMutex; diff --git a/src/color.cc b/src/color.cc index a98b8a2..bac5c2d 100644 --- a/src/color.cc +++ b/src/color.cc @@ -5,6 +5,8 @@ #include #include +#include + // 0x50F930 char _aColor_cNoError[] = "color.c: No errors\n"; @@ -552,7 +554,7 @@ void colorSetBrightness(double value) for (int i = 0; i < 64; i++) { double value = pow(i, gBrightness); - _currentGammaTable[i] = (unsigned char)min(max(value, 0.0), 63.0); + _currentGammaTable[i] = (unsigned char)std::clamp(value, 0.0, 63.0); } _setSystemPalette(_systemCmap); diff --git a/src/dbox.cc b/src/dbox.cc index c4c315a..6600724 100644 --- a/src/dbox.cc +++ b/src/dbox.cc @@ -16,6 +16,8 @@ #include #include +#include + // 0x5108C8 const int gDialogBoxBackgroundFrmIds[DIALOG_TYPE_COUNT] = { 218, // MEDIALOG.FRM - Medium generic dialog box @@ -107,7 +109,7 @@ int showDialogBox(const char* title, const char** body, int bodyLength, int x, i int linesCount = 0; for (int index = 0; index < bodyLength; index++) { // NOTE: Calls [fontGetStringWidth] twice because of [max] macro. - maximumLineWidth = max(fontGetStringWidth(body[index]), maximumLineWidth); + maximumLineWidth = std::max(fontGetStringWidth(body[index]), maximumLineWidth); linesCount++; } diff --git a/src/file_find.h b/src/file_find.h index 90e497e..2bba6ed 100644 --- a/src/file_find.h +++ b/src/file_find.h @@ -3,6 +3,7 @@ #if defined(_WIN32) #define WIN32_LEAN_AND_MEAN +#define NOMINMAX #include #else #include diff --git a/src/game_sound.h b/src/game_sound.h index 00be6c8..0bbc598 100644 --- a/src/game_sound.h +++ b/src/game_sound.h @@ -6,6 +6,7 @@ #include "sound.h" #define WIN32_LEAN_AND_MEAN +#define NOMINMAX #include typedef enum WeaponSoundEffect { diff --git a/src/inventory.cc b/src/inventory.cc index 5dd1393..8d3c5e5 100644 --- a/src/inventory.cc +++ b/src/inventory.cc @@ -38,6 +38,8 @@ #include #include +#include + #define INVENTORY_LARGE_SLOT_WIDTH 90 #define INVENTORY_LARGE_SLOT_HEIGHT 61 @@ -1381,7 +1383,7 @@ void _display_body(int fid, int inventoryWindowType) unsigned char* frameData = artGetFrameData(art, frame, rotation); int framePitch = artGetWidth(art, frame, rotation); - int frameWidth = min(framePitch, INVENTORY_BODY_VIEW_WIDTH); + int frameWidth = std::min(framePitch, INVENTORY_BODY_VIEW_WIDTH); int frameHeight = artGetHeight(art, frame, rotation); if (frameHeight > INVENTORY_BODY_VIEW_HEIGHT) { @@ -3633,7 +3635,7 @@ int inventoryOpenLooting(Object* a1, Object* a2) if (!isCaughtStealing) { if (stealingXp > 0) { if (!objectIsPartyMember(a2)) { - stealingXp = min(300 - skillGetValue(a1, SKILL_STEAL), stealingXp); + stealingXp = std::min(300 - skillGetValue(a1, SKILL_STEAL), stealingXp); debugPrint("\n[[[%d]]]", 300 - skillGetValue(a1, SKILL_STEAL)); // You gain %d experience points for successfully using your Steal skill. diff --git a/src/loadsave.cc b/src/loadsave.cc index 9cec59a..a67d93f 100644 --- a/src/loadsave.cc +++ b/src/loadsave.cc @@ -45,6 +45,8 @@ #include #include +#include + #define LS_WINDOW_WIDTH 640 #define LS_WINDOW_HEIGHT 480 @@ -2389,7 +2391,7 @@ int _copy_file(const char* a1, const char* a2) } while (length != 0) { - chunk_length = min(length, 0xFFFF); + chunk_length = std::min(length, 0xFFFF); if (fileRead(buf, chunk_length, 1, stream1) != 1) { break; diff --git a/src/options.cc b/src/options.cc index 7819dfc..3e6d983 100644 --- a/src/options.cc +++ b/src/options.cc @@ -25,6 +25,8 @@ #include #include +#include + #define PREFERENCES_WINDOW_WIDTH 640 #define PREFERENCES_WINDOW_HEIGHT 480 @@ -919,32 +921,32 @@ void preferencesSetDefaults(bool a1) // 0x4931F8 void _JustUpdate_() { - gPreferencesGameDifficulty1 = min(max(gPreferencesGameDifficulty1, 0), 2); - gPreferencesCombatDifficulty1 = min(max(gPreferencesCombatDifficulty1, 0), 2); - gPreferencesViolenceLevel1 = min(max(gPreferencesViolenceLevel1, 0), 3); - gPreferencesTargetHighlight1 = min(max(gPreferencesTargetHighlight1, 0), 2); - gPreferencesCombatMessages1 = min(max(gPreferencesCombatMessages1, 0), 1); - gPreferencesCombatLooks1 = min(max(gPreferencesCombatLooks1, 0), 1); - gPreferencesCombatTaunts1 = min(max(gPreferencesCombatTaunts1, 0), 1); - gPreferencesLanguageFilter1 = min(max(gPreferencesLanguageFilter1, 0), 1); - gPreferencesRunning1 = min(max(gPreferencesRunning1, 0), 1); - gPreferencesSubtitles1 = min(max(gPreferencesSubtitles1, 0), 1); - gPreferencesItemHighlight1 = min(max(gPreferencesItemHighlight1, 0), 1); - gPreferencesCombatSpeed1 = min(max(gPreferencesCombatSpeed1, 0), 50); - gPreferencesPlayerSpeedup1 = min(max(gPreferencesPlayerSpeedup1, 0), 1); - gPreferencesTextBaseDelay1 = min(max(gPreferencesTextBaseDelay1, 1.0), 6.0); - gPreferencesMasterVolume1 = min(max(gPreferencesMasterVolume1, 0), VOLUME_MAX); - gPreferencesMusicVolume1 = min(max(gPreferencesMusicVolume1, 0), VOLUME_MAX); - gPreferencesSoundEffectsVolume1 = min(max(gPreferencesSoundEffectsVolume1, 0), VOLUME_MAX); - gPreferencesSpeechVolume1 = min(max(gPreferencesSpeechVolume1, 0), VOLUME_MAX); - gPreferencesBrightness1 = min(max(gPreferencesBrightness1, 1.0), 1.17999267578125); - gPreferencesMouseSensitivity1 = min(max(gPreferencesMouseSensitivity1, 1.0), 2.5); + gPreferencesGameDifficulty1 = std::clamp(gPreferencesGameDifficulty1, 0, 2); + gPreferencesCombatDifficulty1 = std::clamp(gPreferencesCombatDifficulty1, 0, 2); + gPreferencesViolenceLevel1 = std::clamp(gPreferencesViolenceLevel1, 0, 3); + gPreferencesTargetHighlight1 = std::clamp(gPreferencesTargetHighlight1, 0, 2); + gPreferencesCombatMessages1 = std::clamp(gPreferencesCombatMessages1, 0, 1); + gPreferencesCombatLooks1 = std::clamp(gPreferencesCombatLooks1, 0, 1); + gPreferencesCombatTaunts1 = std::clamp(gPreferencesCombatTaunts1, 0, 1); + gPreferencesLanguageFilter1 = std::clamp(gPreferencesLanguageFilter1, 0, 1); + gPreferencesRunning1 = std::clamp(gPreferencesRunning1, 0, 1); + gPreferencesSubtitles1 = std::clamp(gPreferencesSubtitles1, 0, 1); + gPreferencesItemHighlight1 = std::clamp(gPreferencesItemHighlight1, 0, 1); + gPreferencesCombatSpeed1 = std::clamp(gPreferencesCombatSpeed1, 0, 50); + gPreferencesPlayerSpeedup1 = std::clamp(gPreferencesPlayerSpeedup1, 0, 1); + gPreferencesTextBaseDelay1 = std::clamp(gPreferencesTextBaseDelay1, 6.0, 10.0); + gPreferencesMasterVolume1 = std::clamp(gPreferencesMasterVolume1, 0, VOLUME_MAX); + gPreferencesMusicVolume1 = std::clamp(gPreferencesMusicVolume1, 0, VOLUME_MAX); + gPreferencesSoundEffectsVolume1 = std::clamp(gPreferencesSoundEffectsVolume1, 0, VOLUME_MAX); + gPreferencesSpeechVolume1 = std::clamp(gPreferencesSpeechVolume1, 0, VOLUME_MAX); + gPreferencesBrightness1 = std::clamp(gPreferencesBrightness1, 1.0, 1.17999267578125); + gPreferencesMouseSensitivity1 = std::clamp(gPreferencesMouseSensitivity1, 1.0, 2.5); textObjectsSetBaseDelay(gPreferencesTextBaseDelay1); gameMouseLoadItemHighlight(); double textLineDelay = (gPreferencesTextBaseDelay1 + (-1.0)) * 0.2 * 2.0; - textLineDelay = min(max(textLineDelay, 0.0), 2.0); + textLineDelay = std::clamp(textLineDelay, 0.0, 2.0); textObjectsSetLineDelay(textLineDelay); aiMessageListReloadIfNeeded(); @@ -1065,7 +1067,7 @@ void _UpdateThing(int index) case PREF_COMBAT_SPEED: if (1) { double value = *meta->valuePtr; - value = min(max(value, 0.0), 50.0); + value = std::clamp(value, 0.0, 50.0); int x = (int)((value - meta->minValue) * 219.0 / (meta->maxValue - meta->minValue) + 384.0); blitBufferToBufferTrans(gPreferencesWindowFrmData[PREFERENCES_WINDOW_FRM_KNOB_OFF], 21, 12, 21, gPreferencesWindowBuffer + 640 * meta->knobY + x, 640); @@ -1073,13 +1075,13 @@ void _UpdateThing(int index) break; case PREF_TEXT_BASE_DELAY: if (1) { - gPreferencesTextBaseDelay1 = min(max(gPreferencesTextBaseDelay1, 1.0), 6.0); + gPreferencesTextBaseDelay1 = std::clamp(gPreferencesTextBaseDelay1, 1.0, 6.0); int x = (int)((6.0 - gPreferencesTextBaseDelay1) * 43.8 + 384.0); blitBufferToBufferTrans(gPreferencesWindowFrmData[PREFERENCES_WINDOW_FRM_KNOB_OFF], 21, 12, 21, gPreferencesWindowBuffer + 640 * meta->knobY + x, 640); double value = (gPreferencesTextBaseDelay1 - 1.0) * 0.2 * 2.0; - value = min(max(value, 0.0), 2.0); + value = std::clamp(value, 0.0, 2.0); textObjectsSetBaseDelay(gPreferencesTextBaseDelay1); textObjectsSetLineDelay(value); @@ -1091,7 +1093,7 @@ void _UpdateThing(int index) case PREF_SPEECH_VOLUME: if (1) { double value = *meta->valuePtr; - value = min(max(value, meta->minValue), meta->maxValue); + value = std::clamp(value, meta->minValue, meta->maxValue); int x = (int)((value - meta->minValue) * 219.0 / (meta->maxValue - meta->minValue) + 384.0); blitBufferToBufferTrans(gPreferencesWindowFrmData[PREFERENCES_WINDOW_FRM_KNOB_OFF], 21, 12, 21, gPreferencesWindowBuffer + 640 * meta->knobY + x, 640); @@ -1114,7 +1116,7 @@ void _UpdateThing(int index) break; case PREF_BRIGHTNESS: if (1) { - gPreferencesBrightness1 = min(max(gPreferencesBrightness1, 1.0), 1.17999267578125); + gPreferencesBrightness1 = std::clamp(gPreferencesBrightness1, 1.0, 1.17999267578125); int x = (int)((gPreferencesBrightness1 - meta->minValue) * (219.0 / (meta->maxValue - meta->minValue)) + 384.0); blitBufferToBufferTrans(gPreferencesWindowFrmData[PREFERENCES_WINDOW_FRM_KNOB_OFF], 21, 12, 21, gPreferencesWindowBuffer + 640 * meta->knobY + x, 640); @@ -1124,7 +1126,7 @@ void _UpdateThing(int index) break; case PREF_MOUSE_SENSITIVIY: if (1) { - gPreferencesMouseSensitivity1 = min(max(gPreferencesMouseSensitivity1, 1.0), 2.5); + gPreferencesMouseSensitivity1 = std::clamp(gPreferencesMouseSensitivity1, 1.0, 2.5); int x = (int)((gPreferencesMouseSensitivity1 - meta->minValue) * (219.0 / (meta->maxValue - meta->minValue)) + 384.0); blitBufferToBufferTrans(gPreferencesWindowFrmData[PREFERENCES_WINDOW_FRM_KNOB_OFF], 21, 12, 21, gPreferencesWindowBuffer + 640 * meta->knobY + x, 640); diff --git a/src/sound.cc b/src/sound.cc index 56f3fdc..00ec98f 100644 --- a/src/sound.cc +++ b/src/sound.cc @@ -9,6 +9,8 @@ #include #include +#include + // 0x51D478 STRUCT_51D478* _fadeHead = NULL; @@ -1069,7 +1071,7 @@ int _soundVolumeHMItoDirectSound(int volume) if (volume != 0) { normalizedVolume = -1000.0 * log2(32767.0 / volume); - normalizedVolume = max(min(normalizedVolume, 0.0), -10000.0); + normalizedVolume = std::clamp(normalizedVolume, -10000.0, 0.0); } else { normalizedVolume = -10000.0; } diff --git a/src/stat.cc b/src/stat.cc index 84bde62..f08ca84 100644 --- a/src/stat.cc +++ b/src/stat.cc @@ -21,6 +21,8 @@ #include +#include + // 0x51D53C StatDescription gStatDescriptions[STAT_COUNT] = { { NULL, NULL, 0, PRIMARY_STAT_MIN, PRIMARY_STAT_MAX, 5 }, @@ -345,7 +347,7 @@ int critterGetStat(Object* critter, int stat) } } - value = min(max(value, gStatDescriptions[stat].minimumValue), gStatDescriptions[stat].maximumValue); + value = std::clamp(value, gStatDescriptions[stat].minimumValue, gStatDescriptions[stat].maximumValue); } else { switch (stat) { case STAT_CURRENT_HIT_POINTS: @@ -546,10 +548,10 @@ void critterUpdateDerivedStats(Object* critter) data->baseStats[STAT_MAXIMUM_HIT_POINTS] = critterGetBaseStatWithTraitModifier(critter, STAT_STRENGTH) + critterGetBaseStatWithTraitModifier(critter, STAT_ENDURANCE) * 2 + 15; data->baseStats[STAT_MAXIMUM_ACTION_POINTS] = agility / 2 + 5; data->baseStats[STAT_ARMOR_CLASS] = agility; - data->baseStats[STAT_MELEE_DAMAGE] = max(strength - 5, 1); + data->baseStats[STAT_MELEE_DAMAGE] = std::max(strength - 5, 1); data->baseStats[STAT_CARRY_WEIGHT] = 25 * strength + 25; data->baseStats[STAT_SEQUENCE] = 2 * perception; - data->baseStats[STAT_HEALING_RATE] = max(endurance / 3, 1); + data->baseStats[STAT_HEALING_RATE] = std::max(endurance / 3, 1); data->baseStats[STAT_CRITICAL_CHANCE] = luck; data->baseStats[STAT_BETTER_CRITICALS] = 0; data->baseStats[STAT_RADIATION_RESISTANCE] = 2 * endurance; diff --git a/src/win32.h b/src/win32.h index 076d34a..45056cd 100644 --- a/src/win32.h +++ b/src/win32.h @@ -2,6 +2,7 @@ #define WIN32_H #define WIN32_LEAN_AND_MEAN +#define NOMINMAX #include #include diff --git a/src/window_manager.cc b/src/window_manager.cc index 47c2b5f..e4d55b5 100644 --- a/src/window_manager.cc +++ b/src/window_manager.cc @@ -12,6 +12,8 @@ #include +#include + // 0x50FA30 char _path_patches[] = ""; @@ -781,10 +783,10 @@ void _GNW_win_refresh(Window* window, Rect* rect, unsigned char* a3) v26->next = NULL; - v26->rect.left = max(window->rect.left, rect->left); - v26->rect.top = max(window->rect.top, rect->top); - v26->rect.right = min(window->rect.right, rect->right); - v26->rect.bottom = min(window->rect.bottom, rect->bottom); + v26->rect.left = std::max(window->rect.left, rect->left); + v26->rect.top = std::max(window->rect.top, rect->top); + v26->rect.right = std::min(window->rect.right, rect->right); + v26->rect.bottom = std::min(window->rect.bottom, rect->bottom); if (v26->rect.right >= v26->rect.left && v26->rect.bottom >= v26->rect.top) { if (a3) { diff --git a/src/window_manager.h b/src/window_manager.h index e1da1ec..0504dfd 100644 --- a/src/window_manager.h +++ b/src/window_manager.h @@ -6,6 +6,7 @@ #include #define WIN32_LEAN_AND_MEAN +#define NOMINMAX #include #define MAX_WINDOW_COUNT (50) diff --git a/src/window_manager_private.cc b/src/window_manager_private.cc index 3fd493b..6e2a423 100644 --- a/src/window_manager_private.cc +++ b/src/window_manager_private.cc @@ -8,6 +8,8 @@ #include #include +#include + // 0x51E414 int _wd = -1; @@ -210,7 +212,7 @@ int _calc_max_field_chars_wcursor(int a1, int a2) internal_free(str); - return max(len1, len2) + 1; + return std::max(len1, len2) + 1; } // 0x4DD3EC