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

Method GetVariable

src/newgrf_town.cpp:27–132  ·  view source on GitHub ↗

virtual */

Source from the content-addressed store, hash-verified

25}
26
27/* virtual */ uint32_t TownScopeResolver::GetVariable(uint8_t variable, [[maybe_unused]] uint32_t parameter, bool &available) const
28{
29 if (this->t == nullptr) {
30 available = false;
31 return UINT_MAX;
32 }
33
34 switch (variable) {
35 /* Larger towns */
36 case 0x40:
37 if (_settings_game.economy.larger_towns == 0) return 2;
38 if (this->t->larger_town) return 1;
39 return 0;
40
41 /* Town index */
42 case 0x41: return this->t->index.base();
43
44 /* Get a variable from the persistent storage */
45 case 0x7C: {
46 /* Check the persistent storage for the GrfID stored in register 100h. */
47 uint32_t grfid = static_cast<uint32_t>(this->ro.GetRegister(0x100));
48 if (grfid == 0xFFFFFFFF) {
49 if (this->ro.grffile == nullptr) return 0;
50 grfid = this->ro.grffile->grfid;
51 }
52
53 for (auto &it : this->t->psa_list) {
54 if (it->grfid == grfid) return it->GetValue(parameter);
55 }
56
57 return 0;
58 }
59
60 /* Town properties */
61 case 0x80: return this->t->xy.base();
62 case 0x81: return GB(this->t->xy.base(), 8, 8);
63 case 0x82: return ClampTo<uint16_t>(this->t->cache.population);
64 case 0x83: return GB(ClampTo<uint16_t>(this->t->cache.population), 8, 8);
65 case 0x8A: return this->t->grow_counter / Ticks::TOWN_GROWTH_TICKS;
66 case 0x92: return this->t->flags.base(); // In original game, 0x92 and 0x93 are one word.
67 case 0x93: return 0;
68 case 0x94: return ClampTo<uint16_t>(this->t->cache.squared_town_zone_radius[to_underlying(HouseZone::TownEdge)]);
69 case 0x95: return GB(ClampTo<uint16_t>(this->t->cache.squared_town_zone_radius[to_underlying(HouseZone::TownEdge)]), 8, 8);
70 case 0x96: return ClampTo<uint16_t>(this->t->cache.squared_town_zone_radius[to_underlying(HouseZone::TownOutskirt)]);
71 case 0x97: return GB(ClampTo<uint16_t>(this->t->cache.squared_town_zone_radius[to_underlying(HouseZone::TownOutskirt)]), 8, 8);
72 case 0x98: return ClampTo<uint16_t>(this->t->cache.squared_town_zone_radius[to_underlying(HouseZone::TownOuterSuburb)]);
73 case 0x99: return GB(ClampTo<uint16_t>(this->t->cache.squared_town_zone_radius[to_underlying(HouseZone::TownOuterSuburb)]), 8, 8);
74 case 0x9A: return ClampTo<uint16_t>(this->t->cache.squared_town_zone_radius[to_underlying(HouseZone::TownInnerSuburb)]);
75 case 0x9B: return GB(ClampTo<uint16_t>(this->t->cache.squared_town_zone_radius[to_underlying(HouseZone::TownInnerSuburb)]), 8, 8);
76 case 0x9C: return ClampTo<uint16_t>(this->t->cache.squared_town_zone_radius[to_underlying(HouseZone::TownCentre)]);
77 case 0x9D: return GB(ClampTo<uint16_t>(this->t->cache.squared_town_zone_radius[to_underlying(HouseZone::TownCentre)]), 8, 8);
78 case 0x9E: return this->t->ratings[0];
79 case 0x9F: return GB(this->t->ratings[0], 8, 8);
80 case 0xA0: return this->t->ratings[1];
81 case 0xA1: return GB(this->t->ratings[1], 8, 8);
82 case 0xA2: return this->t->ratings[2];
83 case 0xA3: return GB(this->t->ratings[2], 8, 8);
84 case 0xA4: return this->t->ratings[3];

Callers 12

ResolveMethod · 0.45
ResolveMethod · 0.45
ResolveMethod · 0.45
ResolveMethod · 0.45
ResolveMethod · 0.45
ResolveMethod · 0.45
ResolveMethod · 0.45
ResolveMethod · 0.45
ResolveMethod · 0.45
ResolveMethod · 0.45
ResolveMethod · 0.45
ResolveMethod · 0.45

Calls 8

GBFunction · 0.85
to_underlyingFunction · 0.85
TownHistoryHelperFunction · 0.85
GetCargoTypeByLabelFunction · 0.85
GetRegisterMethod · 0.80
GetPercentTransportedMethod · 0.80
baseMethod · 0.45
GetValueMethod · 0.45

Tested by

no test coverage detected