Skip to content

Commit

Permalink
Codechange: replace some min/clamp constructs to ClampTo
Browse files Browse the repository at this point in the history
  • Loading branch information
rubidium42 committed May 6, 2023
1 parent 19ec4e8 commit fb856e1
Show file tree
Hide file tree
Showing 18 changed files with 59 additions and 60 deletions.
8 changes: 4 additions & 4 deletions src/economy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,7 @@ Money GetTransportedGoodsIncome(uint num_pieces, uint dist, uint16 transit_days,

/* Use callback to calculate cargo profit, if available */
if (HasBit(cs->callback_mask, CBM_CARGO_PROFIT_CALC)) {
uint32 var18 = std::min(dist, 0xFFFFu) | (std::min(num_pieces, 0xFFu) << 16) | (std::min<uint16>(transit_days, 0xFFu) << 24);
uint32 var18 = ClampTo<uint16_t>(dist) | (ClampTo<uint8_t>(num_pieces) << 16) | (ClampTo<uint8_t>(transit_days) << 24);
uint16 callback = GetCargoCallback(CBID_CARGO_PROFIT_CALC, 0, var18, cs);
if (callback != CALLBACK_FAILED) {
int result = GB(callback, 0, 14);
Expand Down Expand Up @@ -1126,7 +1126,7 @@ static void TriggerIndustryProduction(Industry *i)
if (cargo_waiting == 0) continue;

for (uint ci_out = 0; ci_out < lengthof(i->produced_cargo_waiting); ci_out++) {
i->produced_cargo_waiting[ci_out] = std::min(i->produced_cargo_waiting[ci_out] + (cargo_waiting * indspec->input_cargo_multiplier[ci_in][ci_out] / 256), 0xFFFFu);
i->produced_cargo_waiting[ci_out] = ClampTo<uint16_t>(i->produced_cargo_waiting[ci_out] + (cargo_waiting * indspec->input_cargo_multiplier[ci_in][ci_out] / 256));
}

i->incoming_cargo_waiting[ci_in] = 0;
Expand Down Expand Up @@ -1728,8 +1728,8 @@ static void LoadUnloadVehicle(Vehicle *front)
}

/* if last speed is 0, we treat that as if no vehicle has ever visited the station. */
ge->last_speed = std::min(t, 255);
ge->last_age = std::min(TimerGameCalendar::year - front->build_year, 255);
ge->last_speed = ClampTo<uint8_t>(t);
ge->last_age = ClampTo<uint8_t>(TimerGameCalendar::year - front->build_year);

assert(v->cargo_cap >= v->cargo.StoredCount());
/* Capacity available for loading more cargo. */
Expand Down
2 changes: 1 addition & 1 deletion src/highscore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ void SaveToHighScore()
for (i = 0; i < SP_SAVED_HIGHSCORE_END; i++) {
for (hs = _highscore_table[i]; hs != endof(_highscore_table[i]); hs++) {
/* First character is a command character, so strlen will fail on that */
byte length = std::min(sizeof(hs->company), StrEmpty(hs->company) ? 0 : strlen(&hs->company[1]) + 1);
byte length = ClampTo<byte>(std::min(sizeof(hs->company), StrEmpty(hs->company) ? 0 : strlen(&hs->company[1]) + 1));

if (fwrite(&length, sizeof(length), 1, fp) != 1 || // write away string length
fwrite(hs->company, length, 1, fp) > 1 || // Yes... could be 0 bytes too
Expand Down
12 changes: 6 additions & 6 deletions src/industry_cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ static bool TransportIndustryGoods(TileIndex tile)
bool moved_cargo = false;

for (uint j = 0; j < lengthof(i->produced_cargo_waiting); j++) {
uint cw = std::min<uint>(i->produced_cargo_waiting[j], 255u);
uint cw = ClampTo<uint8_t>(i->produced_cargo_waiting[j]);
if (cw > indspec->minimal_cargo && i->produced_cargo[j] != CT_INVALID) {
i->produced_cargo_waiting[j] -= cw;

Expand Down Expand Up @@ -1141,7 +1141,7 @@ static void ChopLumberMillTrees(Industry *i)

TileIndex tile = i->location.tile;
if (CircularTileSearch(&tile, 40, SearchLumberMillTrees, nullptr)) { // 40x40 tiles to search.
i->produced_cargo_waiting[0] = std::min(0xffff, i->produced_cargo_waiting[0] + 45); // Found a tree, add according value to waiting cargo.
i->produced_cargo_waiting[0] = ClampTo<uint16_t>(i->produced_cargo_waiting[0] + 45); // Found a tree, add according value to waiting cargo.
}
}

Expand Down Expand Up @@ -1173,7 +1173,7 @@ static void ProduceIndustryGoods(Industry *i)

IndustryBehaviour indbehav = indsp->behaviour;
for (size_t j = 0; j < lengthof(i->produced_cargo_waiting); j++) {
i->produced_cargo_waiting[j] = std::min(0xffff, i->produced_cargo_waiting[j] + i->production_rate[j]);
i->produced_cargo_waiting[j] = ClampTo<uint16_t>(i->produced_cargo_waiting[j] + i->production_rate[j]);
}

if ((indbehav & INDUSTRYBEH_PLANT_FIELDS) != 0) {
Expand Down Expand Up @@ -1784,7 +1784,7 @@ static void DoCreateNewIndustry(Industry *i, TileIndex tile, IndustryType type,
/* Randomize inital production if non-original economy is used and there are no production related callbacks. */
if (!indspec->UsesOriginalEconomy()) {
for (size_t ci = 0; ci < lengthof(i->production_rate); ci++) {
i->production_rate[ci] = std::min((RandomRange(256) + 128) * i->production_rate[ci] >> 8, 255u);
i->production_rate[ci] = ClampTo<byte>((RandomRange(256) + 128) * i->production_rate[ci] >> 8);
}
}

Expand Down Expand Up @@ -2422,7 +2422,7 @@ static void UpdateIndustryStatistics(Industry *i)
byte pct = 0;
if (i->this_month_production[j] != 0) {
i->last_prod_year = TimerGameCalendar::year;
pct = std::min(i->this_month_transported[j] * 256 / i->this_month_production[j], 255);
pct = ClampTo<byte>(i->this_month_transported[j] * 256 / i->this_month_production[j]);
}
i->last_month_pct_transported[j] = pct;

Expand All @@ -2446,7 +2446,7 @@ void Industry::RecomputeProductionMultipliers()

/* Rates are rounded up, so e.g. oilrig always produces some passengers */
for (size_t i = 0; i < lengthof(this->production_rate); i++) {
this->production_rate[i] = std::min(CeilDiv(indspec->production_rate[i] * this->prod_level, PRODLEVEL_DEFAULT), 0xFFu);
this->production_rate[i] = ClampTo<byte>(CeilDiv(indspec->production_rate[i] * this->prod_level, PRODLEVEL_DEFAULT));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/industry_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,7 @@ class IndustryViewWindow : public Window
if (i->production_rate[line - IL_RATE1] >= 255) return;
/* a zero production industry is unlikely to give anything but zero, so push it a little bit */
int new_prod = i->production_rate[line - IL_RATE1] == 0 ? 1 : i->production_rate[line - IL_RATE1] * 2;
i->production_rate[line - IL_RATE1] = std::min<uint>(new_prod, 255);
i->production_rate[line - IL_RATE1] = ClampTo<byte>(new_prod);
}
break;

Expand Down
2 changes: 1 addition & 1 deletion src/newgrf_airport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ void AirportOverrideManager::SetEntitySpec(AirportSpec *as)
case 0x7C: return (this->st->airport.psa != nullptr) ? this->st->airport.psa->GetValue(parameter) : 0;

case 0xF0: return this->st->facilities;
case 0xFA: return Clamp(this->st->build_date - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 65535);
case 0xFA: return ClampTo<uint16_t>(this->st->build_date - DAYS_TILL_ORIGINAL_BASE_YEAR);
}

return this->st->GetNewGRFVariable(this->ro, variable, parameter, available);
Expand Down
2 changes: 1 addition & 1 deletion src/newgrf_commons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ uint32 GetNearbyTileInformation(TileIndex tile, bool grf_version8)
/* Return 0 if the tile is a land tile */
byte terrain_type = (HasTileWaterClass(tile) ? (GetWaterClass(tile) + 1) & 3 : 0) << 5 | GetTerrainType(tile) << 2 | (tile_type == MP_WATER ? 1 : 0) << 1;
if (grf_version8) z /= TILE_HEIGHT;
return tile_type << 24 | Clamp(z, 0, 0xFF) << 16 | terrain_type << 8 | tileh;
return tile_type << 24 | ClampTo<uint8_t>(z) << 16 | terrain_type << 8 | tileh;
}

/**
Expand Down
12 changes: 6 additions & 6 deletions src/newgrf_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ static uint32 VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *object,
airporttype = st->airport.GetSpec()->ttd_airport_type;
}

return (Clamp(altitude, 0, 0xFF) << 8) | airporttype;
return (ClampTo<uint8_t>(altitude) << 8) | airporttype;
}

case 0x45: { // Curvature info
Expand Down Expand Up @@ -766,8 +766,8 @@ static uint32 VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *object,
}
return (variable - 0x80) == 0x10 ? ticks : GB(ticks, 8, 8);
}
case 0x12: return Clamp(v->date_of_last_service - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 0xFFFF);
case 0x13: return GB(Clamp(v->date_of_last_service - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 0xFFFF), 8, 8);
case 0x12: return ClampTo<uint16_t>(v->date_of_last_service - DAYS_TILL_ORIGINAL_BASE_YEAR);
case 0x13: return GB(ClampTo<uint16_t>(v->date_of_last_service - DAYS_TILL_ORIGINAL_BASE_YEAR), 8, 8);
case 0x14: return v->GetServiceInterval();
case 0x15: return GB(v->GetServiceInterval(), 8, 8);
case 0x16: return v->last_station_visited;
Expand Down Expand Up @@ -823,7 +823,7 @@ static uint32 VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *object,
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 0x3F: return ClampTo<uint8_t>(v->cargo.DaysInTransit());
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);
Expand Down Expand Up @@ -973,8 +973,8 @@ static uint32 VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *object,
case 0x48: return Engine::Get(this->self_type)->flags; // Vehicle Type Info
case 0x49: return TimerGameCalendar::year; // 'Long' format build year
case 0x4B: return TimerGameCalendar::date; // Long date of last service
case 0x92: return Clamp(TimerGameCalendar::date - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 0xFFFF); // Date of last service
case 0x93: return GB(Clamp(TimerGameCalendar::date - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 0xFFFF), 8, 8);
case 0x92: return ClampTo<uint16_t>(TimerGameCalendar::date - DAYS_TILL_ORIGINAL_BASE_YEAR); // Date of last service
case 0x93: return GB(ClampTo<uint16_t>(TimerGameCalendar::date - DAYS_TILL_ORIGINAL_BASE_YEAR), 8, 8);
case 0xC4: return Clamp(TimerGameCalendar::year, ORIGINAL_BASE_YEAR, ORIGINAL_MAX_YEAR) - ORIGINAL_BASE_YEAR; // Build year
case 0xC6: return Engine::Get(this->self_type)->grf_prop.local_id;
case 0xC7: return GB(Engine::Get(this->self_type)->grf_prop.local_id, 8, 8);
Expand Down
9 changes: 4 additions & 5 deletions src/newgrf_house.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,12 @@ void DecreaseBuildingCount(Town *t, HouseID house_id)

static uint32 GetNumHouses(HouseID house_id, const Town *town)
{
uint8 map_id_count, town_id_count, map_class_count, town_class_count;
HouseClassID class_id = HouseSpec::Get(house_id)->class_id;

map_id_count = ClampU(_building_counts.id_count[house_id], 0, 255);
map_class_count = ClampU(_building_counts.class_count[class_id], 0, 255);
town_id_count = ClampU(town->cache.building_counts.id_count[house_id], 0, 255);
town_class_count = ClampU(town->cache.building_counts.class_count[class_id], 0, 255);
uint8_t map_id_count = ClampTo<uint8_t>(_building_counts.id_count[house_id]);
uint8_t map_class_count = ClampTo<uint8_t>(_building_counts.class_count[class_id]);
uint8_t town_id_count = ClampTo<uint8_t>(town->cache.building_counts.id_count[house_id]);
uint8_t town_class_count = ClampTo<uint8_t>(town->cache.building_counts.class_count[class_id]);

return map_class_count << 24 | town_class_count << 16 | map_id_count << 8 | town_id_count;
}
Expand Down
28 changes: 14 additions & 14 deletions src/newgrf_industries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ static uint32 GetCountAndDistanceOfClosestInstance(byte param_setID, byte layout
/* If the filter is 0, it could be because none was specified as well as being really a 0.
* In either case, just do the regular var67 */
closest_dist = GetClosestIndustry(current->location.tile, ind_index, current);
count = std::min<uint>(Industry::GetIndustryTypeCount(ind_index), UINT8_MAX); // clamp to 8 bit
count = ClampTo<byte>(Industry::GetIndustryTypeCount(ind_index));
} else {
/* Count only those who match the same industry type and layout filter
* Unfortunately, we have to do it manually */
Expand Down Expand Up @@ -181,16 +181,16 @@ static uint32 GetCountAndDistanceOfClosestInstance(byte param_setID, byte layout
case 0x88: return GetTownRadiusGroup(this->industry->town, this->tile);

/* Manhattan distance of the closest town */
case 0x89: return std::min(DistanceManhattan(this->industry->town->xy, this->tile), 255u);
case 0x89: return ClampTo<uint8_t>(DistanceManhattan(this->industry->town->xy, this->tile));

/* Lowest height of the tile */
case 0x8A: return Clamp(GetTileZ(this->tile) * (this->ro.grffile->grf_version >= 8 ? 1 : TILE_HEIGHT), 0, 0xFF);
case 0x8A: return ClampTo<uint8_t>(GetTileZ(this->tile) * (this->ro.grffile->grf_version >= 8 ? 1 : TILE_HEIGHT));

/* Distance to the nearest water/land tile */
case 0x8B: return GetClosestWaterDistance(this->tile, (GetIndustrySpec(this->industry->type)->behaviour & INDUSTRYBEH_BUILT_ONWATER) == 0);

/* Square of Euclidian distance from town */
case 0x8D: return std::min(DistanceSquare(this->industry->town->xy, this->tile), 65535u);
case 0x8D: return ClampTo<uint16_t>(DistanceSquare(this->industry->town->xy, this->tile));

/* 32 random bits */
case 0x8F: return this->random_bits;
Expand All @@ -214,9 +214,9 @@ static uint32 GetCountAndDistanceOfClosestInstance(byte param_setID, byte layout
if (HasBit(callback, CBM_IND_PRODUCTION_CARGO_ARRIVAL) || HasBit(callback, CBM_IND_PRODUCTION_256_TICKS)) {
if ((indspec->behaviour & INDUSTRYBEH_PROD_MULTI_HNDLING) != 0) {
if (this->industry->prod_level == 0) return 0;
return std::min<uint16>(this->industry->incoming_cargo_waiting[variable - 0x40] / this->industry->prod_level, 0xFFFFu);
return ClampTo<uint16>(this->industry->incoming_cargo_waiting[variable - 0x40] / this->industry->prod_level);
} else {
return std::min<uint16>(this->industry->incoming_cargo_waiting[variable - 0x40], 0xFFFFu);
return ClampTo<uint16>(this->industry->incoming_cargo_waiting[variable - 0x40]);
}
} else {
return 0;
Expand Down Expand Up @@ -285,7 +285,7 @@ static uint32 GetCountAndDistanceOfClosestInstance(byte param_setID, byte layout
case 0x65: {
if (this->tile == INVALID_TILE) break;
TileIndex tile = GetNearbyTile(parameter, this->tile, true);
return GetTownRadiusGroup(this->industry->town, tile) << 16 | std::min(DistanceManhattan(tile, this->industry->town->xy), 0xFFFFu);
return GetTownRadiusGroup(this->industry->town, tile) << 16 | ClampTo<uint16_t>(DistanceManhattan(tile, this->industry->town->xy));
}
/* Get square of Euclidian distance of closest town */
case 0x66: {
Expand Down Expand Up @@ -396,16 +396,16 @@ static uint32 GetCountAndDistanceOfClosestInstance(byte param_setID, byte layout
case 0xA6: return indspec->grf_prop.local_id;
case 0xA7: return this->industry->founder;
case 0xA8: return this->industry->random_colour;
case 0xA9: return Clamp(this->industry->last_prod_year - ORIGINAL_BASE_YEAR, 0, 255);
case 0xA9: return ClampTo<uint8_t>(this->industry->last_prod_year - ORIGINAL_BASE_YEAR);
case 0xAA: return this->industry->counter;
case 0xAB: return GB(this->industry->counter, 8, 8);
case 0xAC: return this->industry->was_cargo_delivered;

case 0xB0: return Clamp(this->industry->construction_date - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 65535); // Date when built since 1920 (in days)
case 0xB0: return ClampTo<uint16_t>(this->industry->construction_date - DAYS_TILL_ORIGINAL_BASE_YEAR); // Date when built since 1920 (in days)
case 0xB3: return this->industry->construction_type; // Construction type
case 0xB4: {
TimerGameCalendar::Date *latest = std::max_element(this->industry->last_cargo_accepted_at, endof(this->industry->last_cargo_accepted_at));
return Clamp((*latest) - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 65535); // Date last cargo accepted since 1920 (in days)
return ClampTo<uint16_t>((*latest) - DAYS_TILL_ORIGINAL_BASE_YEAR); // Date last cargo accepted since 1920 (in days)
}
}

Expand Down Expand Up @@ -643,22 +643,22 @@ void IndustryProductionCallback(Industry *ind, int reason)
if (group->version < 2) {
/* Callback parameters map directly to industry cargo slot indices */
for (uint i = 0; i < group->num_input; i++) {
ind->incoming_cargo_waiting[i] = Clamp(ind->incoming_cargo_waiting[i] - DerefIndProd(group->subtract_input[i], deref) * multiplier, 0, 0xFFFF);
ind->incoming_cargo_waiting[i] = ClampTo<uint16_t>(ind->incoming_cargo_waiting[i] - DerefIndProd(group->subtract_input[i], deref) * multiplier);
}
for (uint i = 0; i < group->num_output; i++) {
ind->produced_cargo_waiting[i] = Clamp(ind->produced_cargo_waiting[i] + std::max(DerefIndProd(group->add_output[i], deref), 0) * multiplier, 0, 0xFFFF);
ind->produced_cargo_waiting[i] = ClampTo<uint16_t>(ind->produced_cargo_waiting[i] + std::max(DerefIndProd(group->add_output[i], deref), 0) * multiplier);
}
} else {
/* Callback receives list of cargos to apply for, which need to have their cargo slots in industry looked up */
for (uint i = 0; i < group->num_input; i++) {
int cargo_index = ind->GetCargoAcceptedIndex(group->cargo_input[i]);
if (cargo_index < 0) continue;
ind->incoming_cargo_waiting[cargo_index] = Clamp(ind->incoming_cargo_waiting[cargo_index] - DerefIndProd(group->subtract_input[i], deref) * multiplier, 0, 0xFFFF);
ind->incoming_cargo_waiting[cargo_index] = ClampTo<uint16_t>(ind->incoming_cargo_waiting[cargo_index] - DerefIndProd(group->subtract_input[i], deref) * multiplier);
}
for (uint i = 0; i < group->num_output; i++) {
int cargo_index = ind->GetCargoProducedIndex(group->cargo_output[i]);
if (cargo_index < 0) continue;
ind->produced_cargo_waiting[cargo_index] = Clamp(ind->produced_cargo_waiting[cargo_index] + std::max(DerefIndProd(group->add_output[i], deref), 0) * multiplier, 0, 0xFFFF);
ind->produced_cargo_waiting[cargo_index] = ClampTo<uint16_t>(ind->produced_cargo_waiting[cargo_index] + std::max(DerefIndProd(group->add_output[i], deref), 0) * multiplier);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/newgrf_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ static uint32 GetCountAndDistanceOfClosestInstance(byte local_id, uint32 grfid,
/* If the object type is invalid, there is none and the closest is far away. */
if (idx >= NUM_OBJECTS) return 0 | 0xFFFF;

return Object::GetTypeCount(idx) << 16 | std::min(GetClosestObject(tile, idx, current), 0xFFFFu);
return Object::GetTypeCount(idx) << 16 | ClampTo<uint16_t>(GetClosestObject(tile, idx, current));
}

/** Used by the resolver to get values for feature 0F deterministic spritegroups. */
Expand Down Expand Up @@ -324,7 +324,7 @@ static uint32 GetCountAndDistanceOfClosestInstance(byte local_id, uint32 grfid,
case 0x44: return GetTileOwner(this->tile);

/* Get town zone and Manhattan distance of closest town */
case 0x45: return GetTownRadiusGroup(t, this->tile) << 16 | std::min(DistanceManhattan(this->tile, t->xy), 0xFFFFu);
case 0x45: return GetTownRadiusGroup(t, this->tile) << 16 | ClampTo<uint16_t>(DistanceManhattan(this->tile, t->xy));

/* Get square of Euclidian distance of closest town */
case 0x46: return DistanceSquare(this->tile, t->xy);
Expand Down
4 changes: 2 additions & 2 deletions src/newgrf_roadstop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ uint32 RoadStopScopeResolver::GetVariable(byte variable, uint32 parameter, bool
case 0x45: {
if (this->tile == INVALID_TILE) return HZB_TOWN_EDGE << 16;
const Town *t = (this->st == nullptr) ? ClosestTownFromTile(this->tile, UINT_MAX) : this->st->town;
return t != nullptr ? (GetTownRadiusGroup(t, this->tile) << 16 | std::min(DistanceManhattan(this->tile, t->xy), 0xFFFFu)) : HZB_TOWN_EDGE << 16;
return t != nullptr ? (GetTownRadiusGroup(t, this->tile) << 16 | ClampTo<uint16_t>(DistanceManhattan(this->tile, t->xy))) : HZB_TOWN_EDGE << 16;
}

/* Get square of Euclidian distance of closest town */
Expand Down Expand Up @@ -176,7 +176,7 @@ uint32 RoadStopScopeResolver::GetVariable(byte variable, uint32 parameter, bool

case 0xF0: return this->st == nullptr ? 0 : this->st->facilities; // facilities

case 0xFA: return Clamp((this->st == nullptr ? TimerGameCalendar::date : this->st->build_date) - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 65535); // build date
case 0xFA: return ClampTo<uint16_t>((this->st == nullptr ? TimerGameCalendar::date : this->st->build_date) - DAYS_TILL_ORIGINAL_BASE_YEAR); // build date
}

if (this->st != nullptr) return this->st->GetNewGRFVariable(this->ro, variable, parameter, available);
Expand Down
4 changes: 2 additions & 2 deletions src/newgrf_station.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ TownScopeResolver *StationResolverObject::GetTown()
}
break;

case 0xFA: return Clamp(TimerGameCalendar::date - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 65535); // Build date, clamped to a 16 bit value
case 0xFA: return ClampTo<uint16_t>(TimerGameCalendar::date - DAYS_TILL_ORIGINAL_BASE_YEAR); // Build date, clamped to a 16 bit value
}

*available = false;
Expand Down Expand Up @@ -384,7 +384,7 @@ TownScopeResolver *StationResolverObject::GetTown()
case 0x84: return this->st->string_id;
case 0x86: return 0;
case 0xF0: return this->st->facilities;
case 0xFA: return Clamp(this->st->build_date - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 65535);
case 0xFA: return ClampTo<uint16_t>(this->st->build_date - DAYS_TILL_ORIGINAL_BASE_YEAR);
}

return this->st->GetNewGRFVariable(this->ro, variable, parameter, available);
Expand Down

0 comments on commit fb856e1

Please sign in to comment.