MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / GetVariable

Method GetVariable

src/newgrf_engine.cpp:972–1009  ·  view source on GitHub ↗

virtual */

Source from the content-addressed store, hash-verified

970}
971
972/* virtual */ uint32_t VehicleScopeResolver::GetVariable(uint8_t variable, [[maybe_unused]] uint32_t parameter, bool &available) const
973{
974 if (this->v == nullptr) {
975 /* Vehicle does not exist, so we're in a purchase list */
976 switch (variable) {
977 case 0x43: return GetCompanyInfo(_current_company, LiveryHelper(this->self_type, nullptr)); // Owner information
978 case 0x46: return 0; // Motion counter
979 case 0x47: { // Vehicle cargo info
980 const Engine *e = Engine::Get(this->self_type);
981 CargoType cargo_type = e->GetDefaultCargoType();
982 if (IsValidCargoType(cargo_type)) {
983 const CargoSpec *cs = CargoSpec::Get(cargo_type);
984 return (cs->classes.base() << 16) | (cs->weight << 8) | this->ro.grffile->cargo_map[cargo_type];
985 } else {
986 return 0x000000FF;
987 }
988 }
989 case 0x48: return Engine::Get(this->self_type)->flags.base(); // Vehicle Type Info
990 case 0x49: return TimerGameCalendar::year.base(); // 'Long' format build year
991 case 0x4B: return TimerGameCalendar::date.base(); // Long date of last service
992
993 case 0x7A: return GetBadgeVariableResult(*this->ro.grffile, Engine::Get(this->self_type)->badges, parameter);
994
995 case 0x92: return ClampTo<uint16_t>(TimerGameCalendar::date - CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR); // Date of last service
996 case 0x93: return GB(ClampTo<uint16_t>(TimerGameCalendar::date - CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR), 8, 8);
997 case 0xC4: return (Clamp(TimerGameCalendar::year, CalendarTime::ORIGINAL_BASE_YEAR, CalendarTime::ORIGINAL_MAX_YEAR) - CalendarTime::ORIGINAL_BASE_YEAR).base(); // Build year
998 case 0xC6: return Engine::Get(this->self_type)->grf_prop.local_id;
999 case 0xC7: return GB(Engine::Get(this->self_type)->grf_prop.local_id, 8, 8);
1000 case 0xDA: return VehicleID::Invalid().base(); // Next vehicle
1001 case 0xF2: return 0; // Cargo subtype
1002 }
1003
1004 available = false;
1005 return UINT_MAX;
1006 }
1007
1008 return VehicleGetVariable(const_cast<Vehicle*>(this->v), this, variable, parameter, available);
1009}
1010
1011
1012/* virtual */ const SpriteGroup *VehicleResolverObject::ResolveReal(const RealSpriteGroup &group) const

Callers 1

FillNewGRFVehicleCacheFunction · 0.45

Calls 10

GetCompanyInfoFunction · 0.85
LiveryHelperFunction · 0.85
IsValidCargoTypeFunction · 0.85
GetBadgeVariableResultFunction · 0.85
GBFunction · 0.85
ClampFunction · 0.85
InvalidFunction · 0.85
VehicleGetVariableFunction · 0.85
GetDefaultCargoTypeMethod · 0.80
baseMethod · 0.45

Tested by

no test coverage detected