Changeset - r27271:e0993573a0ba
[Not reviewed]
master
0 10 0
Rubidium - 19 months ago 2023-04-29 07:25:51
rubidium@openttd.org
Codechange: replace ClampToI32/U16 with ClampTo<int32_t/uint16_t>
10 files changed with 67 insertions and 98 deletions:
0 comments (0 inline, 0 general)
src/build_vehicle_gui.cpp
Show inline comments
 
@@ -191,13 +191,13 @@ static bool EngineReliabilitySorter(cons
 
 * @return for descending order: returns true if a < b. Vice versa for ascending order
 
 */
 
static bool EngineCostSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
 
{
 
	Money va = Engine::Get(a.engine_id)->GetCost();
 
	Money vb = Engine::Get(b.engine_id)->GetCost();
 
	int r = ClampToI32(va - vb);
 
	int r = ClampTo<int32_t>(va - vb);
 

	
 
	/* Use EngineID to sort instead since we want consistent sorting */
 
	if (r == 0) return EngineNumberSorter(a, b);
 
	return _engine_sort_direction ? r > 0 : r < 0;
 
}
 

	
 
@@ -259,13 +259,13 @@ static bool EngineTractiveEffortSorter(c
 
 * @return for descending order: returns true if a < b. Vice versa for ascending order
 
 */
 
static bool EngineRunningCostSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
 
{
 
	Money va = Engine::Get(a.engine_id)->GetRunningCost();
 
	Money vb = Engine::Get(b.engine_id)->GetRunningCost();
 
	int r = ClampToI32(va - vb);
 
	int r = ClampTo<int32_t>(va - vb);
 

	
 
	/* Use EngineID to sort instead since we want consistent sorting */
 
	if (r == 0) return EngineNumberSorter(a, b);
 
	return _engine_sort_direction ? r > 0 : r < 0;
 
}
 

	
src/core/math_func.hpp
Show inline comments
 
@@ -187,43 +187,12 @@ constexpr To ClampTo(From value)
 

	
 
	/* The input and output are unsigned, just clamp at the high side. */
 
	return static_cast<To>(std::min<BiggerType>(value, std::numeric_limits<To>::max()));
 
}
 

	
 
/**
 
 * Reduce a signed 64-bit int to a signed 32-bit one
 
 *
 
 * This function clamps a 64-bit integer to a 32-bit integer.
 
 * If the 64-bit value is smaller than the smallest 32-bit integer
 
 * value 0x80000000 this value is returned (the left one bit is the sign bit).
 
 * If the 64-bit value is greater than the greatest 32-bit integer value 0x7FFFFFFF
 
 * this value is returned. In all other cases the 64-bit value 'fits' in a
 
 * 32-bits integer field and so the value is casted to int32 and returned.
 
 *
 
 * @param a The 64-bit value to clamps
 
 * @return The 64-bit value reduced to a 32-bit value
 
 * @see Clamp(int, int, int)
 
 */
 
static inline int32 ClampToI32(const int64 a)
 
{
 
	return ClampTo<int32>(a);
 
}
 

	
 
/**
 
 * Reduce an unsigned 64-bit int to an unsigned 16-bit one
 
 *
 
 * @param a The 64-bit value to clamp
 
 * @return The 64-bit value reduced to a 16-bit value
 
 * @see ClampU(uint, uint, uint)
 
 */
 
static inline uint16 ClampToU16(const uint64 a)
 
{
 
	return ClampTo<uint16>(a);
 
}
 

	
 
/**
 
 * Returns the (absolute) difference between two (scalar) variables
 
 *
 
 * @param a The first scalar
 
 * @param b The second scalar
 
 * @return The absolute difference between the given scalars
 
 */
src/ground_vehicle.cpp
Show inline comments
 
@@ -172,16 +172,16 @@ int GroundVehicle<T, Type>::GetAccelerat
 

	
 
		/* When we accelerate, make sure we always keep doing that, even when
 
		 * the excess force is more than the mass. Otherwise a vehicle going
 
		 * down hill will never slow down enough, and a vehicle that came up
 
		 * a hill will never speed up enough to (eventually) get back to the
 
		 * same (maximum) speed. */
 
		int accel = ClampToI32((force - resistance) / (mass * 4));
 
		int accel = ClampTo<int32_t>((force - resistance) / (mass * 4));
 
		return force < resistance ? std::min(-1, accel) : std::max(1, accel);
 
	} else {
 
		return ClampToI32(std::min<int64>(-force - resistance, -10000) / mass);
 
		return ClampTo<int32_t>(std::min<int64>(-force - resistance, -10000) / mass);
 
	}
 
}
 

	
 
/**
 
 * Check whether the whole vehicle chain is in the depot.
 
 * @return true if and only if the whole chain is in the depot.
src/newgrf_engine.cpp
Show inline comments
 
@@ -516,13 +516,13 @@ static uint32 VehicleGetVariable(Vehicle
 
		case 0x44: // Aircraft information
 
			if (v->type != VEH_AIRCRAFT || !Aircraft::From(v)->IsNormalAircraft()) return UINT_MAX;
 

	
 
			{
 
				const Vehicle *w = v->Next();
 
				assert(w != nullptr);
 
				uint16 altitude = ClampToU16(v->z_pos - w->z_pos); // Aircraft height - shadow height
 
				uint16 altitude = ClampTo<uint16_t>(v->z_pos - w->z_pos); // Aircraft height - shadow height
 
				byte airporttype = ATP_TTDP_LARGE;
 

	
 
				const Station *st = GetTargetAirportIfValid(Aircraft::From(v));
 

	
 
				if (st != nullptr && st->airport.tile != INVALID_TILE) {
 
					airporttype = st->airport.GetSpec()->ttd_airport_type;
 
@@ -817,20 +817,20 @@ static uint32 VehicleGetVariable(Vehicle
 
		case 0x36: return v->subspeed;
 
		case 0x37: return v->acceleration;
 
		case 0x38: break; // not implemented
 
		case 0x39: return v->cargo_type;
 
		case 0x3A: return v->cargo_cap;
 
		case 0x3B: return GB(v->cargo_cap, 8, 8);
 
		case 0x3C: return ClampToU16(v->cargo.StoredCount());
 
		case 0x3D: return GB(ClampToU16(v->cargo.StoredCount()), 8, 8);
 
		case 0x3C: return ClampTo<uint16_t>(v->cargo.StoredCount());
 
		case 0x3D: return GB(ClampTo<uint16_t>(v->cargo.StoredCount()), 8, 8);
 
		case 0x3E: return v->cargo.Source();
 
		case 0x3F: return ClampU(v->cargo.DaysInTransit(), 0, 0xFF);
 
		case 0x40: return ClampToU16(v->age);
 
		case 0x41: return GB(ClampToU16(v->age), 8, 8);
 
		case 0x42: return ClampToU16(v->max_age);
 
		case 0x43: return GB(ClampToU16(v->max_age), 8, 8);
 
		case 0x40: return ClampTo<uint16_t>(v->age);
 
		case 0x41: return GB(ClampTo<uint16_t>(v->age), 8, 8);
 
		case 0x42: return ClampTo<uint16_t>(v->max_age);
 
		case 0x43: return GB(ClampTo<uint16_t>(v->max_age), 8, 8);
 
		case 0x44: return Clamp(v->build_year, ORIGINAL_BASE_YEAR, ORIGINAL_MAX_YEAR) - ORIGINAL_BASE_YEAR;
 
		case 0x45: return v->unitnumber;
 
		case 0x46: return v->GetEngine()->grf_prop.local_id;
 
		case 0x47: return GB(v->GetEngine()->grf_prop.local_id, 8, 8);
 
		case 0x48:
 
			if (v->type != VEH_TRAIN || v->spritenum != 0xFD) return v->spritenum;
 
@@ -842,26 +842,26 @@ static uint32 VehicleGetVariable(Vehicle
 
		case 0x4C: return v->breakdown_delay;
 
		case 0x4D: return v->breakdown_chance;
 
		case 0x4E: return v->reliability;
 
		case 0x4F: return GB(v->reliability, 8, 8);
 
		case 0x50: return v->reliability_spd_dec;
 
		case 0x51: return GB(v->reliability_spd_dec, 8, 8);
 
		case 0x52: return ClampToI32(v->GetDisplayProfitThisYear());
 
		case 0x53: return GB(ClampToI32(v->GetDisplayProfitThisYear()),  8, 24);
 
		case 0x54: return GB(ClampToI32(v->GetDisplayProfitThisYear()), 16, 16);
 
		case 0x55: return GB(ClampToI32(v->GetDisplayProfitThisYear()), 24,  8);
 
		case 0x56: return ClampToI32(v->GetDisplayProfitLastYear());
 
		case 0x57: return GB(ClampToI32(v->GetDisplayProfitLastYear()),  8, 24);
 
		case 0x58: return GB(ClampToI32(v->GetDisplayProfitLastYear()), 16, 16);
 
		case 0x59: return GB(ClampToI32(v->GetDisplayProfitLastYear()), 24,  8);
 
		case 0x52: return ClampTo<int32_t>(v->GetDisplayProfitThisYear());
 
		case 0x53: return GB(ClampTo<int32_t>(v->GetDisplayProfitThisYear()),  8, 24);
 
		case 0x54: return GB(ClampTo<int32_t>(v->GetDisplayProfitThisYear()), 16, 16);
 
		case 0x55: return GB(ClampTo<int32_t>(v->GetDisplayProfitThisYear()), 24,  8);
 
		case 0x56: return ClampTo<int32_t>(v->GetDisplayProfitLastYear());
 
		case 0x57: return GB(ClampTo<int32_t>(v->GetDisplayProfitLastYear()),  8, 24);
 
		case 0x58: return GB(ClampTo<int32_t>(v->GetDisplayProfitLastYear()), 16, 16);
 
		case 0x59: return GB(ClampTo<int32_t>(v->GetDisplayProfitLastYear()), 24,  8);
 
		case 0x5A: return v->Next() == nullptr ? INVALID_VEHICLE : v->Next()->index;
 
		case 0x5B: break; // not implemented
 
		case 0x5C: return ClampToI32(v->value);
 
		case 0x5D: return GB(ClampToI32(v->value),  8, 24);
 
		case 0x5E: return GB(ClampToI32(v->value), 16, 16);
 
		case 0x5F: return GB(ClampToI32(v->value), 24,  8);
 
		case 0x5C: return ClampTo<int32_t>(v->value);
 
		case 0x5D: return GB(ClampTo<int32_t>(v->value),  8, 24);
 
		case 0x5E: return GB(ClampTo<int32_t>(v->value), 16, 16);
 
		case 0x5F: return GB(ClampTo<int32_t>(v->value), 24,  8);
 
		case 0x60: break; // not implemented
 
		case 0x61: break; // not implemented
 
		case 0x62: break; // vehicle specific, see below
 
		case 0x63: break; // not implemented
 
		case 0x64: break; // vehicle specific, see below
 
		case 0x65: break; // vehicle specific, see below
src/newgrf_town.cpp
Show inline comments
 
@@ -43,27 +43,27 @@
 
			return 0;
 
		}
 

	
 
		/* Town properties */
 
		case 0x80: return this->t->xy;
 
		case 0x81: return GB(this->t->xy, 8, 8);
 
		case 0x82: return ClampToU16(this->t->cache.population);
 
		case 0x83: return GB(ClampToU16(this->t->cache.population), 8, 8);
 
		case 0x82: return ClampTo<uint16_t>(this->t->cache.population);
 
		case 0x83: return GB(ClampTo<uint16_t>(this->t->cache.population), 8, 8);
 
		case 0x8A: return this->t->grow_counter / TOWN_GROWTH_TICKS;
 
		case 0x92: return this->t->flags;  // In original game, 0x92 and 0x93 are really one word. Since flags is a byte, this is to adjust
 
		case 0x93: return 0;
 
		case 0x94: return ClampToU16(this->t->cache.squared_town_zone_radius[0]);
 
		case 0x95: return GB(ClampToU16(this->t->cache.squared_town_zone_radius[0]), 8, 8);
 
		case 0x96: return ClampToU16(this->t->cache.squared_town_zone_radius[1]);
 
		case 0x97: return GB(ClampToU16(this->t->cache.squared_town_zone_radius[1]), 8, 8);
 
		case 0x98: return ClampToU16(this->t->cache.squared_town_zone_radius[2]);
 
		case 0x99: return GB(ClampToU16(this->t->cache.squared_town_zone_radius[2]), 8, 8);
 
		case 0x9A: return ClampToU16(this->t->cache.squared_town_zone_radius[3]);
 
		case 0x9B: return GB(ClampToU16(this->t->cache.squared_town_zone_radius[3]), 8, 8);
 
		case 0x9C: return ClampToU16(this->t->cache.squared_town_zone_radius[4]);
 
		case 0x9D: return GB(ClampToU16(this->t->cache.squared_town_zone_radius[4]), 8, 8);
 
		case 0x94: return ClampTo<uint16_t>(this->t->cache.squared_town_zone_radius[0]);
 
		case 0x95: return GB(ClampTo<uint16_t>(this->t->cache.squared_town_zone_radius[0]), 8, 8);
 
		case 0x96: return ClampTo<uint16_t>(this->t->cache.squared_town_zone_radius[1]);
 
		case 0x97: return GB(ClampTo<uint16_t>(this->t->cache.squared_town_zone_radius[1]), 8, 8);
 
		case 0x98: return ClampTo<uint16_t>(this->t->cache.squared_town_zone_radius[2]);
 
		case 0x99: return GB(ClampTo<uint16_t>(this->t->cache.squared_town_zone_radius[2]), 8, 8);
 
		case 0x9A: return ClampTo<uint16_t>(this->t->cache.squared_town_zone_radius[3]);
 
		case 0x9B: return GB(ClampTo<uint16_t>(this->t->cache.squared_town_zone_radius[3]), 8, 8);
 
		case 0x9C: return ClampTo<uint16_t>(this->t->cache.squared_town_zone_radius[4]);
 
		case 0x9D: return GB(ClampTo<uint16_t>(this->t->cache.squared_town_zone_radius[4]), 8, 8);
 
		case 0x9E: return this->t->ratings[0];
 
		case 0x9F: return GB(this->t->ratings[0], 8, 8);
 
		case 0xA0: return this->t->ratings[1];
 
		case 0xA1: return GB(this->t->ratings[1], 8, 8);
 
		case 0xA2: return this->t->ratings[2];
 
		case 0xA3: return GB(this->t->ratings[2], 8, 8);
 
@@ -76,30 +76,30 @@
 
		case 0xAA: return this->t->ratings[6];
 
		case 0xAB: return GB(this->t->ratings[6], 8, 8);
 
		case 0xAC: return this->t->ratings[7];
 
		case 0xAD: return GB(this->t->ratings[7], 8, 8);
 
		case 0xAE: return this->t->have_ratings;
 
		case 0xB2: return this->t->statues;
 
		case 0xB6: return ClampToU16(this->t->cache.num_houses);
 
		case 0xB6: return ClampTo<uint16_t>(this->t->cache.num_houses);
 
		case 0xB9: return this->t->growth_rate / TOWN_GROWTH_TICKS;
 
		case 0xBA: return ClampToU16(this->t->supplied[CT_PASSENGERS].new_max);
 
		case 0xBB: return GB(ClampToU16(this->t->supplied[CT_PASSENGERS].new_max), 8, 8);
 
		case 0xBC: return ClampToU16(this->t->supplied[CT_MAIL].new_max);
 
		case 0xBD: return GB(ClampToU16(this->t->supplied[CT_MAIL].new_max), 8, 8);
 
		case 0xBE: return ClampToU16(this->t->supplied[CT_PASSENGERS].new_act);
 
		case 0xBF: return GB(ClampToU16(this->t->supplied[CT_PASSENGERS].new_act), 8, 8);
 
		case 0xC0: return ClampToU16(this->t->supplied[CT_MAIL].new_act);
 
		case 0xC1: return GB(ClampToU16(this->t->supplied[CT_MAIL].new_act), 8, 8);
 
		case 0xC2: return ClampToU16(this->t->supplied[CT_PASSENGERS].old_max);
 
		case 0xC3: return GB(ClampToU16(this->t->supplied[CT_PASSENGERS].old_max), 8, 8);
 
		case 0xC4: return ClampToU16(this->t->supplied[CT_MAIL].old_max);
 
		case 0xC5: return GB(ClampToU16(this->t->supplied[CT_MAIL].old_max), 8, 8);
 
		case 0xC6: return ClampToU16(this->t->supplied[CT_PASSENGERS].old_act);
 
		case 0xC7: return GB(ClampToU16(this->t->supplied[CT_PASSENGERS].old_act), 8, 8);
 
		case 0xC8: return ClampToU16(this->t->supplied[CT_MAIL].old_act);
 
		case 0xC9: return GB(ClampToU16(this->t->supplied[CT_MAIL].old_act), 8, 8);
 
		case 0xBA: return ClampTo<uint16_t>(this->t->supplied[CT_PASSENGERS].new_max);
 
		case 0xBB: return GB(ClampTo<uint16_t>(this->t->supplied[CT_PASSENGERS].new_max), 8, 8);
 
		case 0xBC: return ClampTo<uint16_t>(this->t->supplied[CT_MAIL].new_max);
 
		case 0xBD: return GB(ClampTo<uint16_t>(this->t->supplied[CT_MAIL].new_max), 8, 8);
 
		case 0xBE: return ClampTo<uint16_t>(this->t->supplied[CT_PASSENGERS].new_act);
 
		case 0xBF: return GB(ClampTo<uint16_t>(this->t->supplied[CT_PASSENGERS].new_act), 8, 8);
 
		case 0xC0: return ClampTo<uint16_t>(this->t->supplied[CT_MAIL].new_act);
 
		case 0xC1: return GB(ClampTo<uint16_t>(this->t->supplied[CT_MAIL].new_act), 8, 8);
 
		case 0xC2: return ClampTo<uint16_t>(this->t->supplied[CT_PASSENGERS].old_max);
 
		case 0xC3: return GB(ClampTo<uint16_t>(this->t->supplied[CT_PASSENGERS].old_max), 8, 8);
 
		case 0xC4: return ClampTo<uint16_t>(this->t->supplied[CT_MAIL].old_max);
 
		case 0xC5: return GB(ClampTo<uint16_t>(this->t->supplied[CT_MAIL].old_max), 8, 8);
 
		case 0xC6: return ClampTo<uint16_t>(this->t->supplied[CT_PASSENGERS].old_act);
 
		case 0xC7: return GB(ClampTo<uint16_t>(this->t->supplied[CT_PASSENGERS].old_act), 8, 8);
 
		case 0xC8: return ClampTo<uint16_t>(this->t->supplied[CT_MAIL].old_act);
 
		case 0xC9: return GB(ClampTo<uint16_t>(this->t->supplied[CT_MAIL].old_act), 8, 8);
 
		case 0xCA: return this->t->GetPercentTransported(CT_PASSENGERS);
 
		case 0xCB: return this->t->GetPercentTransported(CT_MAIL);
 
		case 0xCC: return this->t->received[TE_FOOD].new_act;
 
		case 0xCD: return GB(this->t->received[TE_FOOD].new_act, 8, 8);
 
		case 0xCE: return this->t->received[TE_WATER].new_act;
 
		case 0xCF: return GB(this->t->received[TE_WATER].new_act, 8, 8);
src/script/script_info.cpp
Show inline comments
 
@@ -143,48 +143,48 @@ SQInteger ScriptInfo::AddSetting(HSQUIRR
 
			config.description = stredup(sqdescription);
 
			StrMakeValidInPlace(const_cast<char *>(config.description));
 
			items |= 0x002;
 
		} else if (strcmp(key, "min_value") == 0) {
 
			SQInteger res;
 
			if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR;
 
			config.min_value = ClampToI32(res);
 
			config.min_value = ClampTo<int32_t>(res);
 
			items |= 0x004;
 
		} else if (strcmp(key, "max_value") == 0) {
 
			SQInteger res;
 
			if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR;
 
			config.max_value = ClampToI32(res);
 
			config.max_value = ClampTo<int32_t>(res);
 
			items |= 0x008;
 
		} else if (strcmp(key, "easy_value") == 0) {
 
			SQInteger res;
 
			if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR;
 
			config.easy_value = ClampToI32(res);
 
			config.easy_value = ClampTo<int32_t>(res);
 
			items |= 0x010;
 
		} else if (strcmp(key, "medium_value") == 0) {
 
			SQInteger res;
 
			if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR;
 
			config.medium_value = ClampToI32(res);
 
			config.medium_value = ClampTo<int32_t>(res);
 
			items |= 0x020;
 
		} else if (strcmp(key, "hard_value") == 0) {
 
			SQInteger res;
 
			if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR;
 
			config.hard_value = ClampToI32(res);
 
			config.hard_value = ClampTo<int32_t>(res);
 
			items |= 0x040;
 
		} else if (strcmp(key, "random_deviation") == 0) {
 
			SQInteger res;
 
			if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR;
 
			config.random_deviation = ClampToI32(abs(res));
 
			config.random_deviation = ClampTo<int32_t>(abs(res));
 
			items |= 0x200;
 
		} else if (strcmp(key, "custom_value") == 0) {
 
			SQInteger res;
 
			if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR;
 
			config.custom_value = ClampToI32(res);
 
			config.custom_value = ClampTo<int32_t>(res);
 
			items |= 0x080;
 
		} else if (strcmp(key, "step_size") == 0) {
 
			SQInteger res;
 
			if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR;
 
			config.step_size = ClampToI32(res);
 
			config.step_size = ClampTo<int32_t>(res);
 
		} else if (strcmp(key, "flags") == 0) {
 
			SQInteger res;
 
			if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR;
 
			config.flags = (ScriptConfigFlags)res;
 
			items |= 0x100;
 
		} else {
src/settings_gui.cpp
Show inline comments
 
@@ -2431,13 +2431,13 @@ struct GameSettingsWindow : Window {
 
		if (!StrEmpty(str)) {
 
			long long llvalue = atoll(str);
 

	
 
			/* Save the correct currency-translated value */
 
			if (sd->flags & SF_GUI_CURRENCY) llvalue /= _currency->rate;
 

	
 
			value = (int32)ClampToI32(llvalue);
 
			value = ClampTo<int32_t>(llvalue);
 
		} else {
 
			value = sd->def;
 
		}
 

	
 
		SetSettingValue(this->valuewindow_entry->setting, value);
 
		this->SetDirty();
src/strgen/strgen.cpp
Show inline comments
 
@@ -96,13 +96,13 @@ struct FileStringReader : StringReader {
 
	{
 
		fclose(this->fh);
 
	}
 

	
 
	char *ReadLine(char *buffer, const char *last) override
 
	{
 
		return fgets(buffer, ClampToU16(last - buffer + 1), this->fh);
 
		return fgets(buffer, ClampTo<uint16_t>(last - buffer + 1), this->fh);
 
	}
 

	
 
	void HandlePragma(char *str) override;
 

	
 
	void ParseFile() override
 
	{
src/town_cmd.cpp
Show inline comments
 
@@ -2954,13 +2954,13 @@ CommandCost CmdExpandTown(DoCommandFlag 
 
	Town *t = Town::GetIfValid(town_id);
 
	if (t == nullptr) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		/* The more houses, the faster we grow */
 
		if (grow_amount == 0) {
 
			uint amount = RandomRange(ClampToU16(t->cache.num_houses / 10)) + 3;
 
			uint amount = RandomRange(ClampTo<uint16_t>(t->cache.num_houses / 10)) + 3;
 
			t->cache.num_houses += amount;
 
			UpdateTownRadius(t);
 

	
 
			uint n = amount * 10;
 
			do GrowTown(t); while (--n);
 

	
src/vehicle_gui.cpp
Show inline comments
 
@@ -1356,20 +1356,20 @@ static bool VehicleAgeSorter(const Vehic
 
	return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
 
}
 

	
 
/** Sort vehicles by this year profit */
 
static bool VehicleProfitThisYearSorter(const Vehicle * const &a, const Vehicle * const &b)
 
{
 
	int r = ClampToI32(a->GetDisplayProfitThisYear() - b->GetDisplayProfitThisYear());
 
	int r = ClampTo<int32_t>(a->GetDisplayProfitThisYear() - b->GetDisplayProfitThisYear());
 
	return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
 
}
 

	
 
/** Sort vehicles by last year profit */
 
static bool VehicleProfitLastYearSorter(const Vehicle * const &a, const Vehicle * const &b)
 
{
 
	int r = ClampToI32(a->GetDisplayProfitLastYear() - b->GetDisplayProfitLastYear());
 
	int r = ClampTo<int32_t>(a->GetDisplayProfitLastYear() - b->GetDisplayProfitLastYear());
 
	return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
 
}
 

	
 
/** Sort vehicles by their cargo */
 
static bool VehicleCargoSorter(const Vehicle * const &a, const Vehicle * const &b)
 
{
 
@@ -1416,13 +1416,13 @@ static bool VehicleValueSorter(const Veh
 
	const Vehicle *u;
 
	Money diff = 0;
 

	
 
	for (u = a; u != nullptr; u = u->Next()) diff += u->value;
 
	for (u = b; u != nullptr; u = u->Next()) diff -= u->value;
 

	
 
	int r = ClampToI32(diff);
 
	int r = ClampTo<int32_t>(diff);
 
	return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
 
}
 

	
 
/** Sort vehicles by their length */
 
static bool VehicleLengthSorter(const Vehicle * const &a, const Vehicle * const &b)
 
{
 
@@ -1430,13 +1430,13 @@ static bool VehicleLengthSorter(const Ve
 
	return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
 
}
 

	
 
/** Sort vehicles by the time they can still live */
 
static bool VehicleTimeToLiveSorter(const Vehicle * const &a, const Vehicle * const &b)
 
{
 
	int r = ClampToI32((a->max_age - a->age) - (b->max_age - b->age));
 
	int r = ClampTo<int32_t>((a->max_age - a->age) - (b->max_age - b->age));
 
	return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
 
}
 

	
 
/** Sort vehicles by the timetable delay */
 
static bool VehicleTimetableDelaySorter(const Vehicle * const &a, const Vehicle * const &b)
 
{
0 comments (0 inline, 0 general)