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

Method GetNewGRFVariable

src/newgrf_station.cpp:412–471  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

410}
411
412uint32_t Station::GetNewGRFVariable(const ResolverObject &object, uint8_t variable, uint8_t parameter, bool &available) const
413{
414 switch (variable) {
415 case 0x48: { // Accepted cargo types
416 uint32_t value = GetAcceptanceMask(this);
417 return value;
418 }
419
420 case 0x8A: return this->had_vehicle_of_type;
421 case 0xF1: return (this->airport.tile != INVALID_TILE) ? this->airport.GetSpec()->ttd_airport_type : ATP_TTDP_LARGE;
422 case 0xF2: return (this->truck_stops != nullptr) ? this->truck_stops->status.base() : 0;
423 case 0xF3: return (this->bus_stops != nullptr) ? this->bus_stops->status.base() : 0;
424 case 0xF6: return this->airport.blocks.base();
425 case 0xF7: return GB(this->airport.blocks.base(), 8, 8);
426 }
427
428 /* Handle cargo variables with parameter, 0x60 to 0x65 and 0x69 */
429 if ((variable >= 0x60 && variable <= 0x65) || variable == 0x69) {
430 CargoType cargo = GetCargoTranslation(parameter, object.grffile);
431
432 if (!IsValidCargoType(cargo)) {
433 switch (variable) {
434 case 0x62: return 0xFFFFFFFF;
435 case 0x64: return 0xFF00;
436 default: return 0;
437 }
438 }
439 const GoodsEntry *ge = &this->goods[cargo];
440
441 switch (variable) {
442 case 0x60: return std::min(ge->TotalCount(), 4095u);
443 case 0x61: return ge->HasVehicleEverTriedLoading() ? ge->time_since_pickup : 0;
444 case 0x62: return ge->HasRating() ? ge->rating : 0xFFFFFFFF;
445 case 0x63: return ge->HasData() ? ge->GetData().cargo.PeriodsInTransit() : 0;
446 case 0x64: return ge->HasVehicleEverTriedLoading() ? ge->last_speed | (ge->last_age << 8) : 0xFF00;
447 case 0x65: return ge->status.Test(GoodsEntry::State::Acceptance) ? (1U << 3) : 0;
448 case 0x69: return ge->ConvertState();
449 }
450 }
451
452 /* Handle cargo variables (deprecated) */
453 if (variable >= 0x8C && variable <= 0xEC) {
454 const GoodsEntry *g = &this->goods[GB(variable - 0x8C, 3, 4)];
455 switch (GB(variable - 0x8C, 0, 3)) {
456 case 0: return g->TotalCount();
457 case 1: return GB(std::min(g->TotalCount(), 4095u), 0, 4) | (g->status.Test(GoodsEntry::State::Acceptance) ? (1U << 7) : 0);
458 case 2: return g->time_since_pickup;
459 case 3: return g->rating;
460 case 4: return (g->HasData() ? g->GetData().cargo.GetFirstStation() : StationID::Invalid()).base();
461 case 5: return g->HasData() ? g->GetData().cargo.PeriodsInTransit() : 0;
462 case 6: return g->last_speed;
463 case 7: return g->last_age;
464 }
465 }
466
467 Debug(grf, 1, "Unhandled station variable 0x{:X}", variable);
468
469 available = false;

Callers 3

GetVariableMethod · 0.80
GetVariableMethod · 0.80
GetVariableMethod · 0.80

Calls 15

GetAcceptanceMaskFunction · 0.85
GBFunction · 0.85
GetCargoTranslationFunction · 0.85
IsValidCargoTypeFunction · 0.85
InvalidFunction · 0.85
HasRatingMethod · 0.80
PeriodsInTransitMethod · 0.80
TestMethod · 0.80
ConvertStateMethod · 0.80
GetSpecMethod · 0.45
baseMethod · 0.45

Tested by

no test coverage detected