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

Method GetVariable

src/newgrf_roadstop.cpp:72–219  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

70}
71
72uint32_t RoadStopScopeResolver::GetVariable(uint8_t variable, [[maybe_unused]] uint32_t parameter, bool &available) const
73{
74 auto get_road_type_variable = [&](RoadTramType rtt) -> uint32_t {
75 RoadType rt;
76 if (this->tile == INVALID_TILE) {
77 rt = (GetRoadTramType(this->roadtype) == rtt) ? this->roadtype : INVALID_ROADTYPE;
78 } else {
79 rt = GetRoadType(this->tile, rtt);
80 }
81 if (rt == INVALID_ROADTYPE) {
82 return 0xFFFFFFFF;
83 } else {
84 return GetReverseRoadTypeTranslation(rt, this->roadstopspec->grf_prop.grffile);
85 }
86 };
87
88 switch (variable) {
89 /* View/rotation */
90 case 0x40: return this->view;
91
92 /* Stop type: 0: bus, 1: truck, 2: waypoint */
93 case 0x41:
94 if (this->type == StationType::Bus) return 0;
95 if (this->type == StationType::Truck) return 1;
96 return 2;
97
98 /* Terrain type */
99 case 0x42: return this->tile == INVALID_TILE ? 0 : (GetTileSlope(this->tile) << 8 | GetTerrainType(this->tile, TCX_NORMAL));
100
101 /* Road type */
102 case 0x43: return get_road_type_variable(RTT_ROAD);
103
104 /* Tram type */
105 case 0x44: return get_road_type_variable(RTT_TRAM);
106
107 /* Town zone and Manhattan distance of closest town */
108 case 0x45: {
109 if (this->tile == INVALID_TILE) return to_underlying(HouseZone::TownEdge) << 16;
110 const Town *t = (this->st == nullptr) ? ClosestTownFromTile(this->tile, UINT_MAX) : this->st->town;
111 return t != nullptr ? (to_underlying(GetTownRadiusGroup(t, this->tile)) << 16 | ClampTo<uint16_t>(DistanceManhattan(this->tile, t->xy))) : to_underlying(HouseZone::TownEdge) << 16;
112 }
113
114 /* Get square of Euclidean distance of closest town */
115 case 0x46: {
116 if (this->tile == INVALID_TILE) return 0;
117 const Town *t = (this->st == nullptr) ? ClosestTownFromTile(this->tile, UINT_MAX) : this->st->town;
118 return t != nullptr ? DistanceSquare(this->tile, t->xy) : 0;
119 }
120
121 /* Company information */
122 case 0x47: return GetCompanyInfo(this->st == nullptr ? _current_company : this->st->owner);
123
124 /* Animation frame */
125 case 0x49: return this->tile == INVALID_TILE ? 0 : this->st->GetRoadStopAnimationFrame(this->tile);
126
127 /* Misc info */
128 case 0x50: {
129 uint32_t result = 0;

Callers

nothing calls this directly

Calls 15

GetRoadTramTypeFunction · 0.85
GetRoadTypeFunction · 0.85
GetTileSlopeFunction · 0.85
GetTerrainTypeFunction · 0.85
to_underlyingFunction · 0.85
ClosestTownFromTileFunction · 0.85
GetTownRadiusGroupFunction · 0.85
DistanceManhattanFunction · 0.85
DistanceSquareFunction · 0.85
GetCompanyInfoFunction · 0.85
SetBitFunction · 0.85

Tested by

no test coverage detected