summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/aircraft_cmd.cpp2
-rw-r--r--src/depot_gui.cpp15
-rw-r--r--src/disaster_cmd.cpp2
-rw-r--r--src/economy.cpp2
-rw-r--r--src/graph_gui.cpp4
-rw-r--r--src/industry_gui.cpp2
-rw-r--r--src/macros.h6
-rw-r--r--src/main_gui.cpp2
-rw-r--r--src/newgrf_engine.cpp2
-rw-r--r--src/newgrf_spritegroup.cpp4
-rw-r--r--src/settings.cpp2
-rw-r--r--src/settings_gui.cpp5
-rw-r--r--src/station.h5
-rw-r--r--src/station_cmd.cpp4
-rw-r--r--src/tgp.cpp8
-rw-r--r--src/train_cmd.cpp2
-rw-r--r--src/train_gui.cpp4
-rw-r--r--src/unmovable_cmd.cpp4
-rw-r--r--src/viewport.cpp4
19 files changed, 40 insertions, 39 deletions
diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp
index 16c4edfab..b694d7247 100644
--- a/src/aircraft_cmd.cpp
+++ b/src/aircraft_cmd.cpp
@@ -1066,7 +1066,7 @@ static bool AircraftController(Vehicle *v)
if (curz > z) {
z++;
} else {
- int t = max(1, dist - 4);
+ int t = max(1U, dist - 4);
z -= ((z - curz) + t - 1) / t;
if (z < curz) z = curz;
diff --git a/src/depot_gui.cpp b/src/depot_gui.cpp
index d929696b8..395ef99e6 100644
--- a/src/depot_gui.cpp
+++ b/src/depot_gui.cpp
@@ -194,7 +194,8 @@ static void DrawDepotWindow(Window *w)
{
Vehicle **vl = WP(w, depot_d).vehicle_list;
TileIndex tile = w->window_number;
- int x, y, i, hnum, max;
+ int x, y, i, maxval;
+ uint16 hnum;
uint16 num = WP(w, depot_d).engine_count;
/* Set the row and number of boxes in each row based on the number of boxes drawn in the matrix */
@@ -218,7 +219,7 @@ static void DrawDepotWindow(Window *w)
hnum = 8;
for (num = 0; num < WP(w, depot_d).engine_count; num++) {
const Vehicle *v = vl[num];
- hnum = maxu(hnum, v->u.rail.cached_total_length);
+ hnum = max(hnum, v->u.rail.cached_total_length);
}
/* Always have 1 empty row, so people can change the setting of the train */
SetVScrollCount(w, WP(w, depot_d).engine_count + WP(w, depot_d).wagon_count + 1);
@@ -240,22 +241,22 @@ static void DrawDepotWindow(Window *w)
DrawWindowWidgets(w);
num = w->vscroll.pos * boxes_in_each_row;
- max = min(WP(w, depot_d).engine_count, num + (rows_in_display * boxes_in_each_row));
+ maxval = min(WP(w, depot_d).engine_count, num + (rows_in_display * boxes_in_each_row));
- for (x = 2, y = 15; num < max; y += w->resize.step_height, x = 2) { // Draw the rows
+ for (x = 2, y = 15; num < maxval; y += w->resize.step_height, x = 2) { // Draw the rows
byte i;
- for (i = 0; i < boxes_in_each_row && num < max; i++, num++, x += w->resize.step_width) {
+ for (i = 0; i < boxes_in_each_row && num < maxval; i++, num++, x += w->resize.step_width) {
/* Draw all vehicles in the current row */
const Vehicle *v = vl[num];
DrawVehicleInDepot(w, v, x, y);
}
}
- max = min(WP(w, depot_d).engine_count + WP(w, depot_d).wagon_count, (w->vscroll.pos * boxes_in_each_row) + (rows_in_display * boxes_in_each_row));
+ maxval = min(WP(w, depot_d).engine_count + WP(w, depot_d).wagon_count, (w->vscroll.pos * boxes_in_each_row) + (rows_in_display * boxes_in_each_row));
/* draw the train wagons, that do not have an engine in front */
- for (; num < max; num++, y += 14) {
+ for (; num < maxval; num++, y += 14) {
const Vehicle *v = WP(w, depot_d).wagon_list[num - WP(w, depot_d).engine_count];
const Vehicle *u;
diff --git a/src/disaster_cmd.cpp b/src/disaster_cmd.cpp
index f018149f2..9472771ca 100644
--- a/src/disaster_cmd.cpp
+++ b/src/disaster_cmd.cpp
@@ -134,7 +134,7 @@ static void SetDisasterVehiclePos(Vehicle *v, int x, int y, byte z)
BeginVehicleMove(u);
u->x_pos = x;
- u->y_pos = y - 1 - (max(z - GetSlopeZ(safe_x, safe_y), 0) >> 3);
+ u->y_pos = y - 1 - (max(z - GetSlopeZ(safe_x, safe_y), 0U) >> 3);
safe_y = clamp(u->y_pos, 0, MapMaxY() * TILE_SIZE);
u->z_pos = GetSlopeZ(safe_x, safe_y);
u->direction = v->direction;
diff --git a/src/economy.cpp b/src/economy.cpp
index 402fc9cec..452ee746e 100644
--- a/src/economy.cpp
+++ b/src/economy.cpp
@@ -85,7 +85,7 @@ int64 CalculateCompanyValue(const Player* p)
value += p->money64 - p->current_loan; // add real money value
- return max64(value, 1);
+ return max(value, 1LL);
}
// if update is set to true, the economy is updated with this score
diff --git a/src/graph_gui.cpp b/src/graph_gui.cpp
index 96d0f9f7a..3528e71e0 100644
--- a/src/graph_gui.cpp
+++ b/src/graph_gui.cpp
@@ -119,7 +119,7 @@ static void DrawGraph(const GraphDrawer *gw)
col_ptr = row_ptr;
do {
if (*col_ptr != INVALID_VALUE) {
- mx = max64(mx, *col_ptr);
+ mx = max((uint64)mx, *col_ptr);
}
} while (col_ptr++, --num_x);
}
@@ -306,7 +306,7 @@ static void SetupGraphDrawerForPlayers(GraphDrawer *gd)
{
const Player* p;
uint excludebits = _legend_excludebits;
- int nums;
+ byte nums;
int mo,yr;
// Exclude the players which aren't valid
diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp
index 7247036a4..0fb98bc2c 100644
--- a/src/industry_gui.cpp
+++ b/src/industry_gui.cpp
@@ -366,7 +366,7 @@ static void IndustryViewWndProc(Window *w, WindowEvent *e)
/* Clicked buttons, decrease or increase production */
if (x < 15) {
if (isProductionMinimum(i, line)) return;
- i->production_rate[line] = maxu(i->production_rate[line] / 2, 1);
+ i->production_rate[line] = max(i->production_rate[line] / 2, 1);
} else {
if (isProductionMaximum(i, line)) return;
i->production_rate[line] = minu(i->production_rate[line] * 2, 255);
diff --git a/src/macros.h b/src/macros.h
index 644f178af..07011f14c 100644
--- a/src/macros.h
+++ b/src/macros.h
@@ -20,13 +20,11 @@
#undef max
#endif
-static inline int max(int a, int b) { if (a >= b) return a; return b; }
-static inline double dmax(double a, double b) { if (a >= b) return a; return b; }
-static inline uint64 max64(uint64 a, uint64 b) { if (a >= b) return a; return b; }
+template <typename T> T max(T a, T b) { return a >= b ? a : b; }
+
static inline int min(int a, int b) { if (a <= b) return a; return b; }
static inline uint minu(uint a, uint b) { if (a <= b) return a; return b; }
-static inline uint maxu(uint a, uint b) { if (a >= b) return a; return b; }
static inline int clamp(int a, int min, int max)
diff --git a/src/main_gui.cpp b/src/main_gui.cpp
index 556a8feb4..9b34cda56 100644
--- a/src/main_gui.cpp
+++ b/src/main_gui.cpp
@@ -1054,7 +1054,7 @@ void ZoomInOrOutToCursorWindow(bool in, Window *w)
static void CommonRaiseLowerBigLand(TileIndex tile, int mode)
{
int sizex, sizey;
- byte h;
+ uint h;
_generating_world = true; // used to create green terraformed land
diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp
index 5b0fa5179..58f1e43b6 100644
--- a/src/newgrf_engine.cpp
+++ b/src/newgrf_engine.cpp
@@ -832,7 +832,7 @@ static const SpriteGroup *VehicleResolveReal(const ResolverObject *object, const
} else if (v->cargo_count == 0 || totalsets == 2) {
set = 0;
} else {
- set = v->cargo_count * (totalsets - 2) / max(1, v->cargo_cap) + 1;
+ set = v->cargo_count * (totalsets - 2) / max((uint16)1, v->cargo_cap) + 1;
}
return in_motion ? group->g.real.loaded[set] : group->g.real.loading[set];
diff --git a/src/newgrf_spritegroup.cpp b/src/newgrf_spritegroup.cpp
index dd212935c..db23fb708 100644
--- a/src/newgrf_spritegroup.cpp
+++ b/src/newgrf_spritegroup.cpp
@@ -114,8 +114,8 @@ static U EvalAdjustT(const DeterministicSpriteGroupAdjust *adjust, U last_value,
switch (adjust->operation) {
case DSGA_OP_ADD: return last_value + value;
case DSGA_OP_SUB: return last_value - value;
- case DSGA_OP_SMIN: return min(last_value, value);
- case DSGA_OP_SMAX: return max(last_value, value);
+ case DSGA_OP_SMIN: return min((S)last_value, (S)value);
+ case DSGA_OP_SMAX: return max((S)last_value, (S)value);
case DSGA_OP_UMIN: return min((U)last_value, (U)value);
case DSGA_OP_UMAX: return max((U)last_value, (U)value);
case DSGA_OP_SDIV: return last_value / value;
diff --git a/src/settings.cpp b/src/settings.cpp
index 447f87d13..e6dd5514f 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -234,7 +234,7 @@ static IniFile *ini_load(const char *filename)
uint pos;
// add to comment
if (ns > a) {
- a = max(a, 128);
+ a = max(a, 128U);
do a*=2; while (a < ns);
ReallocT(&comment, comment_alloc = a);
}
diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp
index d3d5dcbf6..e3253f460 100644
--- a/src/settings_gui.cpp
+++ b/src/settings_gui.cpp
@@ -437,7 +437,7 @@ static void GameDifficultyWndProc(Window *w, WindowEvent *e)
const GameSettingData *info;
int x, y;
uint btn, dis;
- int val;
+ int16 val;
// Don't allow clients to make any changes
if (_networking && !_network_server)
@@ -473,7 +473,8 @@ static void GameDifficultyWndProc(Window *w, WindowEvent *e)
SETBIT(_difficulty_click_b, btn);
} else {
// Decrease button clicked
- val = max(val - info->step, info->min);
+ val -= info->step;
+ val = max(val, info->min);
SETBIT(_difficulty_click_a, btn);
}
diff --git a/src/station.h b/src/station.h
index 4e2bebc9a..a253b979f 100644
--- a/src/station.h
+++ b/src/station.h
@@ -119,7 +119,8 @@ enum {
HVOT_BUOY = 1 << 6
};
-enum {
+typedef enum CatchmentAeras {
+ CA_NONE = 0,
CA_BUS = 3,
CA_TRUCK = 3,
CA_AIR_OILPAD = 3,
@@ -134,7 +135,7 @@ enum {
CA_AIR_HELIDEPOT = 4,
CA_AIR_INTERCON = 10,
CA_AIR_HELISTATION = 4,
-};
+} CatchmentAera;
void ModifyStationRatingAround(TileIndex tile, PlayerID owner, int amount, uint radius);
diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp
index adca43cbe..e94da91da 100644
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -200,7 +200,7 @@ RoadStop *AllocateRoadStop(void)
* radius that is available within the station */
static uint FindCatchmentRadius(const Station* st)
{
- uint ret = 0;
+ CatchmentAera ret = CA_NONE;
if (st->bus_stops != NULL) ret = max(ret, CA_BUS);
if (st->truck_stops != NULL) ret = max(ret, CA_TRUCK);
@@ -2525,7 +2525,7 @@ static void UpdateStationRating(Station *st)
if (rating <= 127 && waiting != 0) {
uint32 r = Random();
if ( (uint)rating <= (r & 0x7F) ) {
- waiting = max(waiting - ((r >> 8)&3) - 1, 0);
+ waiting = max(waiting - ((r >> 8)&3) - 1, 0U);
waiting_changed = true;
}
}
diff --git a/src/tgp.cpp b/src/tgp.cpp
index 897aad3bf..491562cd3 100644
--- a/src/tgp.cpp
+++ b/src/tgp.cpp
@@ -536,7 +536,7 @@ static void HeightMapCoastLines(void)
for (y = 0; y <= _height_map.size_y; y++) {
/* Top right */
max_x = myabs((perlin_coast_noise_2D(_height_map.size_y - y, y, 0.9, 53) + 0.25) * 5 + (perlin_coast_noise_2D(y, y, 0.35, 179) + 1) * 12);
- max_x = dmax((smallest_size * smallest_size / 16) + max_x, (smallest_size * smallest_size / 16) + margin - max_x);
+ max_x = max((smallest_size * smallest_size / 16) + max_x, (smallest_size * smallest_size / 16) + margin - max_x);
if (smallest_size < 8 && max_x > 5) max_x /= 1.5;
for (x = 0; x < max_x; x++) {
HeightMapXY(x, y) = 0;
@@ -544,7 +544,7 @@ static void HeightMapCoastLines(void)
/* Bottom left */
max_x = myabs((perlin_coast_noise_2D(_height_map.size_y - y, y, 0.85, 101) + 0.3) * 6 + (perlin_coast_noise_2D(y, y, 0.45, 67) + 0.75) * 8);
- max_x = dmax((smallest_size * smallest_size / 16) + max_x, (smallest_size * smallest_size / 16) + margin - max_x);
+ max_x = max((smallest_size * smallest_size / 16) + max_x, (smallest_size * smallest_size / 16) + margin - max_x);
if (smallest_size < 8 && max_x > 5) max_x /= 1.5;
for (x = _height_map.size_x; x > (_height_map.size_x - 1 - max_x); x--) {
HeightMapXY(x, y) = 0;
@@ -555,7 +555,7 @@ static void HeightMapCoastLines(void)
for (x = 0; x <= _height_map.size_x; x++) {
/* Top left */
max_y = myabs((perlin_coast_noise_2D(x, _height_map.size_y / 2, 0.9, 167) + 0.4) * 5 + (perlin_coast_noise_2D(x, _height_map.size_y / 3, 0.4, 211) + 0.7) * 9);
- max_y = dmax((smallest_size * smallest_size / 16) + max_y, (smallest_size * smallest_size / 16) + margin - max_y);
+ max_y = max((smallest_size * smallest_size / 16) + max_y, (smallest_size * smallest_size / 16) + margin - max_y);
if (smallest_size < 8 && max_y > 5) max_y /= 1.5;
for (y = 0; y < max_y; y++) {
HeightMapXY(x, y) = 0;
@@ -564,7 +564,7 @@ static void HeightMapCoastLines(void)
/* Bottom right */
max_y = myabs((perlin_coast_noise_2D(x, _height_map.size_y / 3, 0.85, 71) + 0.25) * 6 + (perlin_coast_noise_2D(x, _height_map.size_y / 3, 0.35, 193) + 0.75) * 12);
- max_y = dmax((smallest_size * smallest_size / 16) + max_y, (smallest_size * smallest_size / 16) + margin - max_y);
+ max_y = max((smallest_size * smallest_size / 16) + max_y, (smallest_size * smallest_size / 16) + margin - max_y);
if (smallest_size < 8 && max_y > 5) max_y /= 1.5;
for (y = _height_map.size_y; y > (_height_map.size_y - 1 - max_y); y--) {
HeightMapXY(x, y) = 0;
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index 431455ba0..c551d1872 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -365,7 +365,7 @@ static int GetTrainAcceleration(Vehicle *v, bool mode)
if (IsTileType(v->tile, MP_STATION) && IsFrontEngine(v)) {
if (TrainShouldStop(v, v->tile)) {
- uint station_length = GetPlatformLength(v->tile, DirToDiagDir(v->direction));
+ int station_length = GetPlatformLength(v->tile, DirToDiagDir(v->direction));
int delta_v;
max_speed = 120;
diff --git a/src/train_gui.cpp b/src/train_gui.cpp
index 7a5176c80..42a9e8361 100644
--- a/src/train_gui.cpp
+++ b/src/train_gui.cpp
@@ -166,8 +166,8 @@ static int CDECL TrainEnginePowerVsRunningCostSorter(const void *a, const void *
* Because of this, the return value have to be reversed as well and we return b - a instead of a - b.
* Another thing is that both power and running costs should be doubled for multiheaded engines.
* Since it would be multipling with 2 in both numerator and denumerator, it will even themselves out and we skip checking for multiheaded. */
- int va = (rvi_a->running_cost_base * _price.running_rail[rvi_a->running_cost_class]) / max(1, rvi_a->power);
- int vb = (rvi_b->running_cost_base * _price.running_rail[rvi_b->running_cost_class]) / max(1, rvi_b->power);
+ int va = (rvi_a->running_cost_base * _price.running_rail[rvi_a->running_cost_class]) / max((uint16)1, rvi_a->power);
+ int vb = (rvi_b->running_cost_base * _price.running_rail[rvi_b->running_cost_class]) / max((uint16)1, rvi_b->power);
int r = vb - va;
return _internal_sort_order ? -r : r;
diff --git a/src/unmovable_cmd.cpp b/src/unmovable_cmd.cpp
index 58ff9291f..bc63a8523 100644
--- a/src/unmovable_cmd.cpp
+++ b/src/unmovable_cmd.cpp
@@ -234,13 +234,13 @@ static void GetAcceptedCargo_Unmovable(TileIndex tile, AcceptedCargo ac)
// Top town building generates 10, so to make HQ interesting, the top
// type makes 20.
- ac[CT_PASSENGERS] = max(1, level);
+ ac[CT_PASSENGERS] = max(1U, level);
// Top town building generates 4, HQ can make up to 8. The
// proportion passengers:mail is different because such a huge
// commercial building generates unusually high amount of mail
// correspondence per physical visitor.
- ac[CT_MAIL] = max(1, level / 2);
+ ac[CT_MAIL] = max(1U, level / 2);
}
diff --git a/src/viewport.cpp b/src/viewport.cpp
index 10670c361..85d4493b1 100644
--- a/src/viewport.cpp
+++ b/src/viewport.cpp
@@ -2091,7 +2091,7 @@ static int CalcHeightdiff(HighLightStyle style, uint distance, TileIndex start_t
assert(style_t < lengthof(heightdiff_line_by_dir) - 13);
h0 = TileHeight(TILE_ADD(start_tile, ToTileIndexDiff(heightdiff_line_by_dir[style_t])));
ht = TileHeight(TILE_ADD(start_tile, ToTileIndexDiff(heightdiff_line_by_dir[style_t + 1])));
- h0 = maxu(h0, ht);
+ h0 = max(h0, ht);
/* Use lookup table for end-tile based on HighLightStyle direction
* flip around side (lower/upper, left/right) based on distance */
@@ -2099,7 +2099,7 @@ static int CalcHeightdiff(HighLightStyle style, uint distance, TileIndex start_t
assert(style_t < lengthof(heightdiff_line_by_dir) - 13);
h1 = TileHeight(TILE_ADD(end_tile, ToTileIndexDiff(heightdiff_line_by_dir[12 + style_t])));
ht = TileHeight(TILE_ADD(end_tile, ToTileIndexDiff(heightdiff_line_by_dir[12 + style_t + 1])));
- h1 = maxu(h1, ht);
+ h1 = max(h1, ht);
} break;
}