Update to 14.0-beta1
This commit is contained in:
+92
-91
@@ -14,9 +14,10 @@
|
||||
#include "company_func.h"
|
||||
#include "newgrf_cargo.h"
|
||||
#include "newgrf_spritegroup.h"
|
||||
#include "date_func.h"
|
||||
#include "timer/timer_game_calendar.h"
|
||||
#include "vehicle_func.h"
|
||||
#include "core/random_func.hpp"
|
||||
#include "core/container_func.hpp"
|
||||
#include "aircraft.h"
|
||||
#include "station_base.h"
|
||||
#include "company_base.h"
|
||||
@@ -30,7 +31,7 @@ void SetWagonOverrideSprites(EngineID engine, CargoID cargo, const SpriteGroup *
|
||||
{
|
||||
Engine *e = Engine::Get(engine);
|
||||
|
||||
assert(cargo < NUM_CARGO + 2); // Include CT_DEFAULT and CT_PURCHASE pseudo cargoes.
|
||||
assert(cargo < NUM_CARGO + 2); // Include SpriteGroupCargo::SG_DEFAULT and SpriteGroupCargo::SG_PURCHASE pseudo cargoes.
|
||||
|
||||
WagonOverride *wo = &e->overrides.emplace_back();
|
||||
wo->group = group;
|
||||
@@ -43,7 +44,7 @@ const SpriteGroup *GetWagonOverrideSpriteSet(EngineID engine, CargoID cargo, Eng
|
||||
const Engine *e = Engine::Get(engine);
|
||||
|
||||
for (const WagonOverride &wo : e->overrides) {
|
||||
if (wo.cargo != cargo && wo.cargo != CT_DEFAULT) continue;
|
||||
if (wo.cargo != cargo && wo.cargo != SpriteGroupCargo::SG_DEFAULT) continue;
|
||||
if (std::find(wo.engines.begin(), wo.engines.end(), overriding_engine) != wo.engines.end()) return wo.group;
|
||||
}
|
||||
return nullptr;
|
||||
@@ -55,7 +56,7 @@ void SetCustomEngineSprites(EngineID engine, byte cargo, const SpriteGroup *grou
|
||||
assert(cargo < lengthof(e->grf_prop.spritegroup));
|
||||
|
||||
if (e->grf_prop.spritegroup[cargo] != nullptr) {
|
||||
grfmsg(6, "SetCustomEngineSprites: engine %d cargo %d already has group -- replacing", engine, cargo);
|
||||
GrfMsg(6, "SetCustomEngineSprites: engine {} cargo {} already has group -- replacing", engine, cargo);
|
||||
}
|
||||
e->grf_prop.spritegroup[cargo] = group;
|
||||
}
|
||||
@@ -135,7 +136,7 @@ static byte MapAircraftMovementState(const Aircraft *v)
|
||||
if (st == nullptr) return AMS_TTDP_FLIGHT_TO_TOWER;
|
||||
|
||||
const AirportFTAClass *afc = st->airport.GetFTA();
|
||||
uint16 amdflag = afc->MovingData(v->pos)->flag;
|
||||
uint16_t amdflag = afc->MovingData(v->pos)->flag;
|
||||
|
||||
switch (v->state) {
|
||||
case HANGAR:
|
||||
@@ -303,12 +304,12 @@ static byte MapAircraftMovementAction(const Aircraft *v)
|
||||
}
|
||||
|
||||
|
||||
/* virtual */ uint32 VehicleScopeResolver::GetRandomBits() const
|
||||
/* virtual */ uint32_t VehicleScopeResolver::GetRandomBits() const
|
||||
{
|
||||
return this->v == nullptr ? 0 : this->v->random_bits;
|
||||
}
|
||||
|
||||
/* virtual */ uint32 VehicleScopeResolver::GetTriggers() const
|
||||
/* virtual */ uint32_t VehicleScopeResolver::GetTriggers() const
|
||||
{
|
||||
return this->v == nullptr ? 0 : this->v->waiting_triggers;
|
||||
}
|
||||
@@ -320,7 +321,7 @@ static byte MapAircraftMovementAction(const Aircraft *v)
|
||||
case VSG_SCOPE_SELF: return &this->self_scope;
|
||||
case VSG_SCOPE_PARENT: return &this->parent_scope;
|
||||
case VSG_SCOPE_RELATIVE: {
|
||||
int32 count = GB(relative, 0, 4);
|
||||
int32_t count = GB(relative, 0, 4);
|
||||
if (this->self_scope.v != nullptr && (relative != this->cached_relative_count || count == 0)) {
|
||||
/* Note: This caching only works as long as the VSG_SCOPE_RELATIVE cannot be used in
|
||||
* VarAct2 with procedure calls. */
|
||||
@@ -392,7 +393,7 @@ static const Livery *LiveryHelper(EngineID engine, const Vehicle *v)
|
||||
* with the same 'engine type'.
|
||||
* @return the position in the chain from front and tail and chain length.
|
||||
*/
|
||||
static uint32 PositionHelper(const Vehicle *v, bool consecutive)
|
||||
static uint32_t PositionHelper(const Vehicle *v, bool consecutive)
|
||||
{
|
||||
const Vehicle *u;
|
||||
byte chain_before = 0;
|
||||
@@ -411,7 +412,7 @@ static uint32 PositionHelper(const Vehicle *v, bool consecutive)
|
||||
return chain_before | chain_after << 8 | (chain_before + chain_after + consecutive) << 16;
|
||||
}
|
||||
|
||||
static uint32 VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *object, byte variable, uint32 parameter, bool *available)
|
||||
static uint32_t VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *object, byte variable, uint32_t parameter, bool *available)
|
||||
{
|
||||
/* Calculated vehicle parameters */
|
||||
switch (variable) {
|
||||
@@ -434,19 +435,11 @@ static uint32 VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *object,
|
||||
|
||||
case 0x42: { // Consist cargo information
|
||||
if (!HasBit(v->grf_cache.cache_valid, NCVV_CONSIST_CARGO_INFORMATION)) {
|
||||
const Vehicle *u;
|
||||
std::array<uint8_t, NUM_CARGO> common_cargoes{};
|
||||
byte cargo_classes = 0;
|
||||
uint8 common_cargoes[NUM_CARGO];
|
||||
uint8 common_subtypes[256];
|
||||
byte user_def_data = 0;
|
||||
CargoID common_cargo_type = CT_INVALID;
|
||||
uint8 common_subtype = 0xFF; // Return 0xFF if nothing is carried
|
||||
|
||||
/* Reset our arrays */
|
||||
memset(common_cargoes, 0, sizeof(common_cargoes));
|
||||
memset(common_subtypes, 0, sizeof(common_subtypes));
|
||||
|
||||
for (u = v; u != nullptr; u = u->Next()) {
|
||||
for (const Vehicle *u = v; u != nullptr; u = u->Next()) {
|
||||
if (v->type == VEH_TRAIN) user_def_data |= Train::From(u)->tcache.user_def_data;
|
||||
|
||||
/* Skip empty engines */
|
||||
@@ -457,16 +450,13 @@ static uint32 VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *object,
|
||||
}
|
||||
|
||||
/* Pick the most common cargo type */
|
||||
uint common_cargo_best_amount = 0;
|
||||
for (CargoID cargo = 0; cargo < NUM_CARGO; cargo++) {
|
||||
if (common_cargoes[cargo] > common_cargo_best_amount) {
|
||||
common_cargo_best_amount = common_cargoes[cargo];
|
||||
common_cargo_type = cargo;
|
||||
}
|
||||
}
|
||||
auto cargo_it = std::max_element(std::begin(common_cargoes), std::end(common_cargoes));
|
||||
/* Return INVALID_CARGO if nothing is carried */
|
||||
CargoID common_cargo_type = (*cargo_it == 0) ? INVALID_CARGO : static_cast<CargoID>(std::distance(std::begin(common_cargoes), cargo_it));
|
||||
|
||||
/* Count subcargo types of common_cargo_type */
|
||||
for (u = v; u != nullptr; u = u->Next()) {
|
||||
std::array<uint8_t, UINT8_MAX + 1> common_subtypes{};
|
||||
for (const Vehicle *u = v; u != nullptr; u = u->Next()) {
|
||||
/* Skip empty engines and engines not carrying common_cargo_type */
|
||||
if (u->cargo_type != common_cargo_type || !u->GetEngine()->CanCarryCargo()) continue;
|
||||
|
||||
@@ -474,13 +464,9 @@ static uint32 VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *object,
|
||||
}
|
||||
|
||||
/* Pick the most common subcargo type*/
|
||||
uint common_subtype_best_amount = 0;
|
||||
for (uint i = 0; i < lengthof(common_subtypes); i++) {
|
||||
if (common_subtypes[i] > common_subtype_best_amount) {
|
||||
common_subtype_best_amount = common_subtypes[i];
|
||||
common_subtype = i;
|
||||
}
|
||||
}
|
||||
auto subtype_it = std::max_element(std::begin(common_subtypes), std::end(common_subtypes));
|
||||
/* Return UINT8_MAX if nothing is carried */
|
||||
uint8_t common_subtype = (*subtype_it == 0) ? UINT8_MAX : static_cast<uint8_t>(std::distance(std::begin(common_subtypes), subtype_it));
|
||||
|
||||
/* Note: We have to store the untranslated cargotype in the cache as the cache can be read by different NewGRFs,
|
||||
* which will need different translations */
|
||||
@@ -500,7 +486,7 @@ static uint32 VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *object,
|
||||
* And this is only done by CheckCaches().
|
||||
*/
|
||||
const GRFFile *grffile = object->ro.grffile;
|
||||
uint8 common_bitnum = (common_cargo_type == CT_INVALID) ? 0xFF :
|
||||
uint8_t common_bitnum = (common_cargo_type == INVALID_CARGO) ? 0xFF :
|
||||
(grffile == nullptr || grffile->grf_version < 8) ? CargoSpec::Get(common_cargo_type)->bitnum : grffile->cargo_map[common_cargo_type];
|
||||
|
||||
return (v->grf_cache.consist_cargo_information & 0xFFFF00FF) | common_bitnum << 8;
|
||||
@@ -518,7 +504,8 @@ static uint32 VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *object,
|
||||
|
||||
{
|
||||
const Vehicle *w = v->Next();
|
||||
uint16 altitude = ClampToU16(v->z_pos - w->z_pos); // Aircraft height - shadow height
|
||||
assert(w != nullptr);
|
||||
uint16_t 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));
|
||||
@@ -527,7 +514,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
|
||||
@@ -570,13 +557,13 @@ static uint32 VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *object,
|
||||
}
|
||||
|
||||
case 0x48: return v->GetEngine()->flags; // Vehicle Type Info
|
||||
case 0x49: return v->build_year;
|
||||
case 0x49: return v->build_year.base();
|
||||
|
||||
case 0x4A:
|
||||
switch (v->type) {
|
||||
case VEH_TRAIN: {
|
||||
RailType rt = GetTileRailType(v->tile);
|
||||
const RailtypeInfo *rti = GetRailTypeInfo(rt);
|
||||
const RailTypeInfo *rti = GetRailTypeInfo(rt);
|
||||
return ((rti->flags & RTFB_CATENARY) ? 0x200 : 0) |
|
||||
(HasPowerOnRail(Train::From(v)->railtype, rt) ? 0x100 : 0) |
|
||||
GetReverseRailTypeTranslation(rt, object->ro.grffile);
|
||||
@@ -595,7 +582,7 @@ static uint32 VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *object,
|
||||
}
|
||||
|
||||
case 0x4B: // Long date of last service
|
||||
return v->date_of_last_service;
|
||||
return v->date_of_last_service_newgrf.base();
|
||||
|
||||
case 0x4C: // Current maximum speed in NewGRF units
|
||||
if (!v->IsPrimaryVehicle()) return 0;
|
||||
@@ -634,7 +621,7 @@ static uint32 VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *object,
|
||||
if (object->ro.callback == CBID_NO_CALLBACK || object->ro.callback == CBID_RANDOM_TRIGGER || object->ro.callback == CBID_TRAIN_ALLOW_WAGON_ATTACH ||
|
||||
object->ro.callback == CBID_VEHICLE_START_STOP_CHECK || object->ro.callback == CBID_VEHICLE_32DAY_CALLBACK || object->ro.callback == CBID_VEHICLE_COLOUR_MAPPING ||
|
||||
object->ro.callback == CBID_VEHICLE_SPAWN_VISUAL_EFFECT) {
|
||||
Vehicle *u = v->Move((int32)GetRegister(0x10F));
|
||||
Vehicle *u = v->Move((int32_t)GetRegister(0x10F));
|
||||
if (u == nullptr) return 0; // available, but zero
|
||||
|
||||
if (parameter == 0x5F) {
|
||||
@@ -657,12 +644,12 @@ static uint32 VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *object,
|
||||
*/
|
||||
if (!v->IsGroundVehicle()) return 0;
|
||||
|
||||
const Vehicle *u = v->Move((int8)parameter);
|
||||
const Vehicle *u = v->Move((int8_t)parameter);
|
||||
if (u == nullptr) return 0;
|
||||
|
||||
/* Get direction difference. */
|
||||
bool prev = (int8)parameter < 0;
|
||||
uint32 ret = prev ? DirDifference(u->direction, v->direction) : DirDifference(v->direction, u->direction);
|
||||
bool prev = (int8_t)parameter < 0;
|
||||
uint32_t ret = prev ? DirDifference(u->direction, v->direction) : DirDifference(v->direction, u->direction);
|
||||
if (ret > DIRDIFF_REVERSE) ret |= 0x08;
|
||||
|
||||
if (u->vehstatus & VS_HIDDEN) ret |= 0x80;
|
||||
@@ -707,7 +694,7 @@ static uint32 VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *object,
|
||||
|
||||
case 0xFE:
|
||||
case 0xFF: {
|
||||
uint16 modflags = 0;
|
||||
uint16_t modflags = 0;
|
||||
|
||||
if (v->type == VEH_TRAIN) {
|
||||
const Train *t = Train::From(v);
|
||||
@@ -765,8 +752,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_newgrf - CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR);
|
||||
case 0x13: return GB(ClampTo<uint16_t>(v->date_of_last_service_newgrf - CalendarTime::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;
|
||||
@@ -819,15 +806,15 @@ static uint32 VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *object,
|
||||
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 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 0x44: return Clamp(v->build_year, ORIGINAL_BASE_YEAR, ORIGINAL_MAX_YEAR) - ORIGINAL_BASE_YEAR;
|
||||
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.GetFirstStation();
|
||||
case 0x3F: return ClampTo<uint8_t>(v->cargo.PeriodsInTransit());
|
||||
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, CalendarTime::ORIGINAL_BASE_YEAR, CalendarTime::ORIGINAL_MAX_YEAR) - CalendarTime::ORIGINAL_BASE_YEAR).base();
|
||||
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);
|
||||
@@ -844,20 +831,20 @@ static uint32 VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *object,
|
||||
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
|
||||
@@ -952,7 +939,7 @@ static uint32 VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *object,
|
||||
return UINT_MAX;
|
||||
}
|
||||
|
||||
/* virtual */ uint32 VehicleScopeResolver::GetVariable(byte variable, uint32 parameter, bool *available) const
|
||||
/* virtual */ uint32_t VehicleScopeResolver::GetVariable(byte variable, [[maybe_unused]] uint32_t parameter, bool *available) const
|
||||
{
|
||||
if (this->v == nullptr) {
|
||||
/* Vehicle does not exist, so we're in a purchase list */
|
||||
@@ -962,7 +949,7 @@ static uint32 VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *object,
|
||||
case 0x47: { // Vehicle cargo info
|
||||
const Engine *e = Engine::Get(this->self_type);
|
||||
CargoID cargo_type = e->GetDefaultCargoType();
|
||||
if (cargo_type != CT_INVALID) {
|
||||
if (IsValidCargoID(cargo_type)) {
|
||||
const CargoSpec *cs = CargoSpec::Get(cargo_type);
|
||||
return (cs->classes << 16) | (cs->weight << 8) | this->ro.grffile->cargo_map[cargo_type];
|
||||
} else {
|
||||
@@ -970,11 +957,11 @@ static uint32 VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *object,
|
||||
}
|
||||
}
|
||||
case 0x48: return Engine::Get(this->self_type)->flags; // Vehicle Type Info
|
||||
case 0x49: return _cur_year; // 'Long' format build year
|
||||
case 0x4B: return _date; // Long date of last service
|
||||
case 0x92: return Clamp(_date - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 0xFFFF); // Date of last service
|
||||
case 0x93: return GB(Clamp(_date - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 0xFFFF), 8, 8);
|
||||
case 0xC4: return Clamp(_cur_year, ORIGINAL_BASE_YEAR, ORIGINAL_MAX_YEAR) - ORIGINAL_BASE_YEAR; // Build year
|
||||
case 0x49: return TimerGameCalendar::year.base(); // 'Long' format build year
|
||||
case 0x4B: return TimerGameCalendar::date.base(); // Long date of last service
|
||||
case 0x92: return ClampTo<uint16_t>(TimerGameCalendar::date - CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR); // Date of last service
|
||||
case 0x93: return GB(ClampTo<uint16_t>(TimerGameCalendar::date - CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR), 8, 8);
|
||||
case 0xC4: return (Clamp(TimerGameCalendar::year, CalendarTime::ORIGINAL_BASE_YEAR, CalendarTime::ORIGINAL_MAX_YEAR) - CalendarTime::ORIGINAL_BASE_YEAR).base(); // 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);
|
||||
case 0xDA: return INVALID_VEHICLE; // Next vehicle
|
||||
@@ -1005,7 +992,7 @@ static uint32 VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *object,
|
||||
|
||||
if (totalsets == 0) return nullptr;
|
||||
|
||||
uint set = (v->cargo.StoredCount() * totalsets) / std::max<uint16>(1u, v->cargo_cap);
|
||||
uint set = (v->cargo.StoredCount() * totalsets) / std::max<uint16_t>(1u, v->cargo_cap);
|
||||
set = std::min(set, totalsets - 1);
|
||||
|
||||
return in_motion ? group->loaded[set] : group->loading[set];
|
||||
@@ -1022,7 +1009,7 @@ GrfSpecFeature VehicleResolverObject::GetFeature() const
|
||||
}
|
||||
}
|
||||
|
||||
uint32 VehicleResolverObject::GetDebugID() const
|
||||
uint32_t VehicleResolverObject::GetDebugID() const
|
||||
{
|
||||
return Engine::Get(this->self_scope.self_type)->grf_prop.local_id;
|
||||
}
|
||||
@@ -1049,7 +1036,7 @@ static const GRFFile *GetEngineGrfFile(EngineID engine_type)
|
||||
* @param callback_param2 Second parameter (var 18) of the callback.
|
||||
*/
|
||||
VehicleResolverObject::VehicleResolverObject(EngineID engine_type, const Vehicle *v, WagonOverride wagon_override, bool rotor_in_gui,
|
||||
CallbackID callback, uint32 callback_param1, uint32 callback_param2)
|
||||
CallbackID callback, uint32_t callback_param1, uint32_t callback_param2)
|
||||
: ResolverObject(GetEngineGrfFile(engine_type), callback, callback_param1, callback_param2),
|
||||
self_scope(*this, engine_type, v, rotor_in_gui),
|
||||
parent_scope(*this, engine_type, ((v != nullptr) ? v->First() : v), rotor_in_gui),
|
||||
@@ -1057,7 +1044,7 @@ VehicleResolverObject::VehicleResolverObject(EngineID engine_type, const Vehicle
|
||||
cached_relative_count(0)
|
||||
{
|
||||
if (wagon_override == WO_SELF) {
|
||||
this->root_spritegroup = GetWagonOverrideSpriteSet(engine_type, CT_DEFAULT, engine_type);
|
||||
this->root_spritegroup = GetWagonOverrideSpriteSet(engine_type, SpriteGroupCargo::SG_DEFAULT, engine_type);
|
||||
} else {
|
||||
if (wagon_override != WO_NONE && v != nullptr && v->IsGroundVehicle()) {
|
||||
assert(v->engine_type == engine_type); // overrides make little sense with fake scopes
|
||||
@@ -1074,9 +1061,9 @@ VehicleResolverObject::VehicleResolverObject(EngineID engine_type, const Vehicle
|
||||
|
||||
if (this->root_spritegroup == nullptr) {
|
||||
const Engine *e = Engine::Get(engine_type);
|
||||
CargoID cargo = v != nullptr ? v->cargo_type : CT_PURCHASE;
|
||||
CargoID cargo = v != nullptr ? v->cargo_type : SpriteGroupCargo::SG_PURCHASE;
|
||||
assert(cargo < lengthof(e->grf_prop.spritegroup));
|
||||
this->root_spritegroup = e->grf_prop.spritegroup[cargo] != nullptr ? e->grf_prop.spritegroup[cargo] : e->grf_prop.spritegroup[CT_DEFAULT];
|
||||
this->root_spritegroup = e->grf_prop.spritegroup[cargo] != nullptr ? e->grf_prop.spritegroup[cargo] : e->grf_prop.spritegroup[SpriteGroupCargo::SG_DEFAULT];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1094,7 +1081,7 @@ void GetCustomEngineSprite(EngineID engine, const Vehicle *v, Direction directio
|
||||
object.ResetState();
|
||||
object.callback_param1 = image_type | (stack << 8);
|
||||
const SpriteGroup *group = object.Resolve();
|
||||
uint32 reg100 = sprite_stack ? GetRegister(0x100) : 0;
|
||||
uint32_t reg100 = sprite_stack ? GetRegister(0x100) : 0;
|
||||
if (group != nullptr && group->GetNumResults() != 0) {
|
||||
result->seq[result->count].sprite = group->GetResult() + (direction % group->GetNumResults());
|
||||
result->seq[result->count].pal = GB(reg100, 0, 16); // zero means default recolouring
|
||||
@@ -1128,7 +1115,7 @@ void GetRotorOverrideSprite(EngineID engine, const struct Aircraft *v, EngineIma
|
||||
object.ResetState();
|
||||
object.callback_param1 = image_type | (stack << 8);
|
||||
const SpriteGroup *group = object.Resolve();
|
||||
uint32 reg100 = sprite_stack ? GetRegister(0x100) : 0;
|
||||
uint32_t reg100 = sprite_stack ? GetRegister(0x100) : 0;
|
||||
if (group != nullptr && group->GetNumResults() != 0) {
|
||||
result->seq[result->count].sprite = group->GetResult() + (rotor_pos % group->GetNumResults());
|
||||
result->seq[result->count].pal = GB(reg100, 0, 16); // zero means default recolouring
|
||||
@@ -1159,7 +1146,7 @@ bool UsesWagonOverride(const Vehicle *v)
|
||||
* @param v The vehicle to evaluate the callback for, or nullptr if it doesn't exist yet
|
||||
* @return The value the callback returned, or CALLBACK_FAILED if it failed
|
||||
*/
|
||||
uint16 GetVehicleCallback(CallbackID callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v)
|
||||
uint16_t GetVehicleCallback(CallbackID callback, uint32_t param1, uint32_t param2, EngineID engine, const Vehicle *v)
|
||||
{
|
||||
VehicleResolverObject object(engine, v, VehicleResolverObject::WO_UNCACHED, false, callback, param1, param2);
|
||||
return object.ResolveCallback();
|
||||
@@ -1175,7 +1162,7 @@ uint16 GetVehicleCallback(CallbackID callback, uint32 param1, uint32 param2, Eng
|
||||
* @param parent The vehicle to use for parent scope
|
||||
* @return The value the callback returned, or CALLBACK_FAILED if it failed
|
||||
*/
|
||||
uint16 GetVehicleCallbackParent(CallbackID callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v, const Vehicle *parent)
|
||||
uint16_t GetVehicleCallbackParent(CallbackID callback, uint32_t param1, uint32_t param2, EngineID engine, const Vehicle *v, const Vehicle *parent)
|
||||
{
|
||||
VehicleResolverObject object(engine, v, VehicleResolverObject::WO_NONE, false, callback, param1, param2);
|
||||
object.parent_scope.SetVehicle(parent);
|
||||
@@ -1192,11 +1179,11 @@ int GetVehicleProperty(const Vehicle *v, PropertyID property, int orig_value, bo
|
||||
|
||||
int GetEngineProperty(EngineID engine, PropertyID property, int orig_value, const Vehicle *v, bool is_signed)
|
||||
{
|
||||
uint16 callback = GetVehicleCallback(CBID_VEHICLE_MODIFY_PROPERTY, property, 0, engine, v);
|
||||
uint16_t callback = GetVehicleCallback(CBID_VEHICLE_MODIFY_PROPERTY, property, 0, engine, v);
|
||||
if (callback != CALLBACK_FAILED) {
|
||||
if (is_signed) {
|
||||
/* Sign extend 15 bit integer */
|
||||
return static_cast<int16>(callback << 1) / 2;
|
||||
return static_cast<int16_t>(callback << 1) / 2;
|
||||
} else {
|
||||
return callback;
|
||||
}
|
||||
@@ -1205,8 +1192,22 @@ int GetEngineProperty(EngineID engine, PropertyID property, int orig_value, cons
|
||||
return orig_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for vehicle build probablity type.
|
||||
* @param v Vehicle whose build probability to test.
|
||||
* @param type Build probability type to test for.
|
||||
* @returns True iff the probability result says so.
|
||||
*/
|
||||
bool TestVehicleBuildProbability(Vehicle *v, EngineID engine, BuildProbabilityType type)
|
||||
{
|
||||
uint16_t p = GetVehicleCallback(CBID_VEHICLE_BUILD_PROBABILITY, std::underlying_type<BuildProbabilityType>::type(type), 0, engine, v);
|
||||
if (p == CALLBACK_FAILED) return false;
|
||||
|
||||
static void DoTriggerVehicle(Vehicle *v, VehicleTrigger trigger, byte base_random_bits, bool first)
|
||||
const uint16_t PROBABILITY_RANGE = 100;
|
||||
return p + RandomRange(PROBABILITY_RANGE) >= PROBABILITY_RANGE;
|
||||
}
|
||||
|
||||
static void DoTriggerVehicle(Vehicle *v, VehicleTrigger trigger, uint16_t base_random_bits, bool first)
|
||||
{
|
||||
/* We can't trigger a non-existent vehicle... */
|
||||
assert(v != nullptr);
|
||||
@@ -1222,8 +1223,8 @@ static void DoTriggerVehicle(Vehicle *v, VehicleTrigger trigger, byte base_rando
|
||||
v->waiting_triggers = object.GetRemainingTriggers();
|
||||
|
||||
/* Rerandomise bits. Scopes other than SELF are invalid for rerandomisation. For bug-to-bug-compatibility with TTDP we ignore the scope. */
|
||||
byte new_random_bits = Random();
|
||||
uint32 reseed = object.GetReseedSum();
|
||||
uint16_t new_random_bits = Random();
|
||||
uint32_t reseed = object.GetReseedSum();
|
||||
v->random_bits &= ~reseed;
|
||||
v->random_bits |= (first ? new_random_bits : base_random_bits) & reseed;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user