MCPcopy Create free account
hub / github.com/OpenLoco/OpenLoco / getAvailableCompatibleMods

Function getAvailableCompatibleMods

src/OpenLoco/src/Objects/ObjectUtils.cpp:276–351  ·  view source on GitHub ↗

0x004781C5, 0x004A693D

Source from the content-addressed store, hash-verified

274
275 // 0x004781C5, 0x004A693D
276 std::array<uint8_t, kMaxMods> getAvailableCompatibleMods(uint8_t trackType, TransportMode transportMode, CompanyId companyId)
277 {
278 if (transportMode == TransportMode::road)
279 {
280 trackType &= ~(1 << 7);
281 }
282
283 std::array<uint8_t, 4> modList = { 0xFF, 0xFF, 0xFF, 0xFF };
284 auto flags = 0;
285
286 for (uint8_t vehicle = 0; vehicle < ObjectManager::getMaxObjects(ObjectType::vehicle); vehicle++)
287 {
288 auto vehicleObj = ObjectManager::get<VehicleObject>(vehicle);
289
290 if (vehicleObj == nullptr)
291 {
292 continue;
293 }
294
295 if (vehicleObj->mode != transportMode)
296 {
297 continue;
298 }
299
300 if (trackType != vehicleObj->trackType)
301 {
302 continue;
303 }
304
305 auto company = CompanyManager::get(companyId);
306
307 if (!company->isVehicleIndexUnlocked(vehicle))
308 {
309 continue;
310 }
311
312 for (auto i = 0; i < vehicleObj->numTrackExtras; i++)
313 {
314 flags |= 1ULL << vehicleObj->requiredTrackExtras[i];
315 }
316
317 if (!vehicleObj->hasFlags(VehicleObjectFlags::rackRail))
318 {
319 continue;
320 }
321
322 flags |= 1ULL << vehicleObj->rackRailType;
323 }
324
325 if (transportMode == TransportMode::road)
326 {
327 auto roadObj = ObjectManager::get<RoadObject>(trackType);
328
329 for (auto i = 0; i < roadObj->numMods; i++)
330 {
331 if (flags & (1 << roadObj->mods[i]))
332 {
333 modList[i] = roadObj->mods[i];

Callers 5

openAtTrackFunction · 0.85
openAtRoadFunction · 0.85
sub_4A3A50Function · 0.85

Calls 4

getMaxObjectsFunction · 0.85
getFunction · 0.50
hasFlagsMethod · 0.45

Tested by

no test coverage detected