Codechange: Remove min/max functions in favour of STL variants (#8502)
This commit is contained in:
@@ -10,7 +10,6 @@
|
||||
#include "stdafx.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <algorithm>
|
||||
|
||||
#include "debug.h"
|
||||
#include "fileio_func.h"
|
||||
@@ -663,7 +662,7 @@ static Engine *GetNewEngine(const GRFFile *file, VehicleType type, uint16 intern
|
||||
scope_grfid, // Note: this is INVALID_GRFID if dynamic_engines is disabled, so no reservation
|
||||
internal_id,
|
||||
type,
|
||||
static_cast<uint8>(min(internal_id, _engine_counts[type])) // substitute_id == _engine_counts[subtype] means "no substitute"
|
||||
std::min<uint8>(internal_id, _engine_counts[type]) // substitute_id == _engine_counts[subtype] means "no substitute"
|
||||
});
|
||||
|
||||
if (engine_pool_size != Engine::GetPoolSize()) {
|
||||
@@ -2460,7 +2459,7 @@ static ChangeInfoResult TownHouseChangeInfo(uint hid, int numinfo, int prop, Byt
|
||||
}
|
||||
|
||||
case 0x16: // Periodic refresh multiplier
|
||||
housespec->processing_time = min(buf->ReadByte(), 63);
|
||||
housespec->processing_time = std::min<byte>(buf->ReadByte(), 63u);
|
||||
break;
|
||||
|
||||
case 0x17: // Four random colours to use
|
||||
@@ -2642,7 +2641,7 @@ static ChangeInfoResult GlobalVarChangeInfo(uint gvid, int numinfo, int prop, By
|
||||
uint price = gvid + i;
|
||||
|
||||
if (price < PR_END) {
|
||||
_cur.grffile->price_base_multipliers[price] = min<int>(factor - 8, MAX_PRICE_MODIFIER);
|
||||
_cur.grffile->price_base_multipliers[price] = std::min<int>(factor - 8, MAX_PRICE_MODIFIER);
|
||||
} else {
|
||||
grfmsg(1, "GlobalVarChangeInfo: Price %d out of range, ignoring", price);
|
||||
}
|
||||
@@ -3029,7 +3028,7 @@ static ChangeInfoResult CargoChangeInfo(uint cid, int numinfo, int prop, ByteRea
|
||||
break;
|
||||
|
||||
case 0x1D: // Vehicle capacity muliplier
|
||||
cs->multiplier = max<uint16>(1u, buf->ReadWord());
|
||||
cs->multiplier = std::max<uint16>(1u, buf->ReadWord());
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -3911,11 +3910,11 @@ static ChangeInfoResult AirportChangeInfo(uint airport, int numinfo, int prop, B
|
||||
}
|
||||
|
||||
if (as->rotation[j] == DIR_E || as->rotation[j] == DIR_W) {
|
||||
as->size_x = max<byte>(as->size_x, att[k].ti.y + 1);
|
||||
as->size_y = max<byte>(as->size_y, att[k].ti.x + 1);
|
||||
as->size_x = std::max<byte>(as->size_x, att[k].ti.y + 1);
|
||||
as->size_y = std::max<byte>(as->size_y, att[k].ti.x + 1);
|
||||
} else {
|
||||
as->size_x = max<byte>(as->size_x, att[k].ti.x + 1);
|
||||
as->size_y = max<byte>(as->size_y, att[k].ti.y + 1);
|
||||
as->size_x = std::max<byte>(as->size_x, att[k].ti.x + 1);
|
||||
as->size_y = std::max<byte>(as->size_y, att[k].ti.y + 1);
|
||||
}
|
||||
}
|
||||
tile_table[j] = CallocT<AirportTileTable>(size);
|
||||
@@ -5197,7 +5196,7 @@ static void NewSpriteGroup(ByteReader *buf)
|
||||
case GSF_AIRPORTTILES:
|
||||
case GSF_OBJECTS:
|
||||
case GSF_INDUSTRYTILES: {
|
||||
byte num_building_sprites = max((uint8)1, type);
|
||||
byte num_building_sprites = std::max((uint8)1, type);
|
||||
|
||||
assert(TileLayoutSpriteGroup::CanAllocateItem());
|
||||
TileLayoutSpriteGroup *group = new TileLayoutSpriteGroup();
|
||||
@@ -6072,7 +6071,7 @@ static uint16 SanitizeSpriteOffset(uint16& num, uint16 offset, int max_sprites,
|
||||
if (offset + num > max_sprites) {
|
||||
grfmsg(4, "GraphicsNew: %s sprite overflow, truncating...", name);
|
||||
uint orig_num = num;
|
||||
num = max(max_sprites - offset, 0);
|
||||
num = std::max(max_sprites - offset, 0);
|
||||
return orig_num - num;
|
||||
}
|
||||
|
||||
@@ -6233,7 +6232,7 @@ bool GetGlobalVariable(byte param, uint32 *value, const GRFFile *grffile)
|
||||
{
|
||||
switch (param) {
|
||||
case 0x00: // current date
|
||||
*value = max(_date - DAYS_TILL_ORIGINAL_BASE_YEAR, 0);
|
||||
*value = std::max(_date - DAYS_TILL_ORIGINAL_BASE_YEAR, 0);
|
||||
return true;
|
||||
|
||||
case 0x01: // current year
|
||||
@@ -6954,7 +6953,7 @@ static uint32 GetPatchVariable(uint8 param)
|
||||
{
|
||||
switch (param) {
|
||||
/* start year - 1920 */
|
||||
case 0x0B: return max(_settings_game.game_creation.starting_year, ORIGINAL_BASE_YEAR) - ORIGINAL_BASE_YEAR;
|
||||
case 0x0B: return std::max(_settings_game.game_creation.starting_year, ORIGINAL_BASE_YEAR) - ORIGINAL_BASE_YEAR;
|
||||
|
||||
/* freight trains weight factor */
|
||||
case 0x0E: return _settings_game.vehicle.freight_trains;
|
||||
@@ -6993,7 +6992,7 @@ static uint32 GetPatchVariable(uint8 param)
|
||||
byte map_bits = 0;
|
||||
byte log_X = MapLogX() - 6; // subtraction is required to make the minimal size (64) zero based
|
||||
byte log_Y = MapLogY() - 6;
|
||||
byte max_edge = max(log_X, log_Y);
|
||||
byte max_edge = std::max(log_X, log_Y);
|
||||
|
||||
if (log_X == log_Y) { // we have a squared map, since both edges are identical
|
||||
SetBit(map_bits, 0);
|
||||
@@ -7001,7 +7000,7 @@ static uint32 GetPatchVariable(uint8 param)
|
||||
if (max_edge == log_Y) SetBit(map_bits, 1); // edge Y been the biggest, mark it
|
||||
}
|
||||
|
||||
return (map_bits << 24) | (min(log_X, log_Y) << 20) | (max_edge << 16) |
|
||||
return (map_bits << 24) | (std::min(log_X, log_Y) << 20) | (max_edge << 16) |
|
||||
(log_X << 12) | (log_Y << 8) | (log_X + log_Y);
|
||||
}
|
||||
|
||||
@@ -7825,7 +7824,7 @@ static bool ChangeGRFNumUsedParams(size_t len, ByteReader *buf)
|
||||
grfmsg(2, "StaticGRFInfo: expected only 1 byte for 'INFO'->'NPAR' but got " PRINTF_SIZE ", ignoring this field", len);
|
||||
buf->Skip(len);
|
||||
} else {
|
||||
_cur.grfconfig->num_valid_params = min(buf->ReadByte(), lengthof(_cur.grfconfig->param));
|
||||
_cur.grfconfig->num_valid_params = std::min<byte>(buf->ReadByte(), lengthof(_cur.grfconfig->param));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -7979,8 +7978,8 @@ static bool ChangeGRFParamMask(size_t len, ByteReader *buf)
|
||||
buf->Skip(len - 1);
|
||||
} else {
|
||||
_cur_parameter->param_nr = param_nr;
|
||||
if (len >= 2) _cur_parameter->first_bit = min(buf->ReadByte(), 31);
|
||||
if (len >= 3) _cur_parameter->num_bit = min(buf->ReadByte(), 32 - _cur_parameter->first_bit);
|
||||
if (len >= 2) _cur_parameter->first_bit = std::min<byte>(buf->ReadByte(), 31);
|
||||
if (len >= 3) _cur_parameter->num_bit = std::min<byte>(buf->ReadByte(), 32 - _cur_parameter->first_bit);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user