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

Function assignRouteColours

src/OpenLoco/src/Ui/Windows/MapWindow.cpp:2322–2403  ·  view source on GitHub ↗

0x0046CED0

Source from the content-addressed store, hash-verified

2320
2321 // 0x0046CED0
2322 static void assignRouteColours()
2323 {
2324 uint32_t availableColours = 0x7FFFFFFF;
2325
2326 // First, assign water colour
2327 {
2328 auto waterObj = ObjectManager::get<WaterObject>();
2329
2330 auto waterPixel = Gfx::getG1Element(waterObj->mapPixelImage)->offset[0];
2331 availableColours = checkIndustryColours(waterPixel, availableColours);
2332
2333 waterPixel = Gfx::getG1Element(waterObj->mapPixelImage)->offset[1];
2334 availableColours = checkIndustryColours(waterPixel, availableColours);
2335 }
2336
2337 // Then, assign surface texture colours
2338 for (auto i = 0U; i < ObjectManager::getMaxObjects(ObjectType::land); i++)
2339 {
2340 auto landObj = ObjectManager::get<LandObject>(i);
2341 if (landObj == nullptr)
2342 {
2343 continue;
2344 }
2345
2346 auto landPixel = Gfx::getG1Element(landObj->mapPixelImage)->offset[0];
2347 availableColours = checkIndustryColours(landPixel, availableColours);
2348
2349 landPixel = Gfx::getG1Element(landObj->mapPixelImage)->offset[1];
2350 availableColours = checkIndustryColours(landPixel, availableColours);
2351 }
2352
2353 availableColours = checkIndustryColours(PaletteIndex::mutedDarkRed2, availableColours);
2354 availableColours = checkIndustryColours(PaletteIndex::orange8, availableColours);
2355 availableColours = checkIndustryColours(PaletteIndex::pink9, availableColours);
2356 availableColours = checkIndustryColours(PaletteIndex::blue9, availableColours);
2357 availableColours = checkIndustryColours(PaletteIndex::black0, availableColours);
2358 availableColours = checkIndustryColours(PaletteIndex::blackB, availableColours);
2359
2360 auto availableTracks = companyGetAvailableRailTracks(CompanyManager::getControllingId());
2361 auto availableRoads = companyGetAvailableRoads(CompanyManager::getControllingId());
2362
2363 auto i = 0U;
2364 auto assignColour = [&i, &availableColours](uint8_t id) {
2365 _routeToObjectIdMap[i] = id;
2366 auto freeColour = std::max(0, Numerics::bitScanForward(availableColours));
2367 availableColours &= ~(1U << freeColour);
2368
2369 auto colour = kIndustryColours[freeColour];
2370 _routeColours[i] = colour;
2371
2372 if (id & (1U << 7))
2373 {
2374 _roadColours[id & ~(1U << 7)] = colour;
2375 }
2376 else
2377 {
2378 _trackColours[id] = colour;
2379 }

Callers 1

openFunction · 0.85

Calls 7

getG1ElementFunction · 0.85
checkIndustryColoursFunction · 0.85
getMaxObjectsFunction · 0.85
getControllingIdFunction · 0.85
companyGetAvailableRoadsFunction · 0.85
bitScanForwardFunction · 0.85

Tested by

no test coverage detected