virtual */
| 163 | } |
| 164 | |
| 165 | /* virtual */ uint32_t IndustriesScopeResolver::GetVariable(uint8_t variable, [[maybe_unused]] uint32_t parameter, bool &available) const |
| 166 | { |
| 167 | if (this->ro.callback == CBID_INDUSTRY_LOCATION) { |
| 168 | /* Variables available during construction check. */ |
| 169 | |
| 170 | switch (variable) { |
| 171 | case 0x7A: return GetBadgeVariableResult(*this->ro.grffile, GetIndustrySpec(this->type)->badges, parameter); |
| 172 | |
| 173 | case 0x80: return this->tile.base(); |
| 174 | case 0x81: return GB(this->tile.base(), 8, 8); |
| 175 | |
| 176 | /* Pointer to the town the industry is associated with */ |
| 177 | case 0x82: return this->industry->town->index.base(); |
| 178 | case 0x83: |
| 179 | case 0x84: |
| 180 | case 0x85: Debug(grf, 0, "NewGRFs shouldn't be doing pointer magic"); break; // not supported |
| 181 | |
| 182 | /* Number of the layout */ |
| 183 | case 0x86: return this->industry->selected_layout; |
| 184 | |
| 185 | /* Ground type */ |
| 186 | case 0x87: return GetTerrainType(this->tile); |
| 187 | |
| 188 | /* Town zone */ |
| 189 | case 0x88: return to_underlying(GetTownRadiusGroup(this->industry->town, this->tile)); |
| 190 | |
| 191 | /* Manhattan distance of the closest town */ |
| 192 | case 0x89: return ClampTo<uint8_t>(DistanceManhattan(this->industry->town->xy, this->tile)); |
| 193 | |
| 194 | /* Lowest height of the tile */ |
| 195 | case 0x8A: return ClampTo<uint8_t>(GetTileZ(this->tile) * (this->ro.grffile->grf_version >= 8 ? 1 : TILE_HEIGHT)); |
| 196 | |
| 197 | /* Distance to the nearest water/land tile */ |
| 198 | case 0x8B: return GetClosestWaterDistance(this->tile, !GetIndustrySpec(this->industry->type)->behaviour.Test(IndustryBehaviour::BuiltOnWater)); |
| 199 | |
| 200 | /* Square of Euclidean distance from town */ |
| 201 | case 0x8D: return ClampTo<uint16_t>(DistanceSquare(this->industry->town->xy, this->tile)); |
| 202 | |
| 203 | /* 32 random bits */ |
| 204 | case 0x8F: return this->random_bits; |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | const IndustrySpec *indspec = GetIndustrySpec(this->type); |
| 209 | |
| 210 | if (this->industry == nullptr) { |
| 211 | Debug(grf, 1, "Unhandled variable 0x{:X} (no available industry) in callback 0x{:x}", variable, this->ro.callback); |
| 212 | |
| 213 | available = false; |
| 214 | return UINT_MAX; |
| 215 | } |
| 216 | |
| 217 | switch (variable) { |
| 218 | case 0x40: |
| 219 | case 0x41: |
| 220 | case 0x42: { // waiting cargo, but only if those two callback flags are set |
| 221 | IndustryCallbackMasks callback = indspec->callback_mask; |
| 222 | if (callback.Any({IndustryCallbackMask::ProductionCargoArrival, IndustryCallbackMask::Production256Ticks})) { |
nothing calls this directly
no test coverage detected