Skip to content

Commit

Permalink
Implement setMapPixelsVehicles
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronVanGeffen committed Apr 14, 2024
1 parent ba81281 commit 1c3ac17
Showing 1 changed file with 86 additions and 5 deletions.
91 changes: 86 additions & 5 deletions src/OpenLoco/src/Windows/MapWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ namespace OpenLoco::Ui::Windows::MapWindow
self.setSize(kMinWindowSize, kMaxWindowSize);
}

// 0x0046C5E5
static void setMapPixelsOverall(PaletteIndex_t* mapPtr, Pos2 pos, Pos2 delta)
{
for (auto rowCountLeft = kMapColumns; rowCountLeft > 0; rowCountLeft--)
Expand Down Expand Up @@ -394,6 +395,86 @@ namespace OpenLoco::Ui::Windows::MapWindow
_dword_F253AC = std::clamp<coord_t>(_dword_F253AC + 1, 0, kMapColumns);
}

// 0x0046C873
static void setMapPixelsVehicles(PaletteIndex_t* mapPtr, Pos2 pos, Pos2 delta)
{
for (auto rowCountLeft = kMapColumns; rowCountLeft > 0; rowCountLeft--)
{
// Coords shouldn't be at map edge
if (!(pos.x > 0 && pos.y > 0 && pos.x < kMapWidth - kTileSize && pos.y < kMapHeight - kTileSize))
{
pos += delta;
mapPtr += 769; // scrollview width?
continue;
}

PaletteIndex_t colourAl{}, colourAh{}, colourDl{}, colourDh{};
auto tile = TileManager::get(pos);
for (auto& el : tile)
{
switch (el.type())
{
case ElementType::surface: // 0x00
{
auto* surfaceEl = el.as<SurfaceElement>();
if (surfaceEl == nullptr)
continue;

if (surfaceEl->water() == 0)
{
const auto* landObj = ObjectManager::get<LandObject>(surfaceEl->terrain());
const auto* landImage = Gfx::getG1Element(landObj->mapPixelImage);
colourAl = colourAh = landImage->offset[0];
}
else
{
const auto* waterObj = ObjectManager::get<WaterObject>();
const auto* waterImage = Gfx::getG1Element(waterObj->mapPixelImage);
colourAl = colourAh = waterImage->offset[0];
}

colourDl = colourDh = colourAl;
break;
}

case ElementType::track: // 0x04
case ElementType::station: // 0x08
case ElementType::road: // 0x1C
if (!el.isGhost() && !el.isAiAllocated())
{
colourDl = colourAl = PaletteIndex::index_0C; // ax, dx
colourAh = colourAl;
colourDh = colourDl;
}
break;

case ElementType::building: // 0x10
case ElementType::industry: // 0x20
if (!el.isGhost())
{
colourDl = colourAl = PaletteIndex::index_3C; // ax, dx
colourAh = colourAl;
colourDh = colourDh;

Check failure on line 457 in src/OpenLoco/src/Windows/MapWindow.cpp

View workflow job for this annotation

GitHub Actions / clang-tidy-check

clang-tidy: error

explicitly assigning value of variable of type 'OpenLoco::PaletteIndex_t' (aka 'unsigned char') to itself [clang-diagnostic-self-assign]

Check failure on line 457 in src/OpenLoco/src/Windows/MapWindow.cpp

View workflow job for this annotation

GitHub Actions / Ubuntu jammy clang++ i686

explicitly assigning value of variable of type 'OpenLoco::PaletteIndex_t' (aka 'unsigned char') to itself [-Werror,-Wself-assign]

Check failure on line 457 in src/OpenLoco/src/Windows/MapWindow.cpp

View workflow job for this annotation

GitHub Actions / Ubuntu mantic clang++ i686

explicitly assigning value of variable of type 'PaletteIndex_t' (aka 'unsigned char') to itself [-Werror,-Wself-assign]
}
break;

default:
break;
};
}

mapPtr[0] = colourDl;
mapPtr[1] = colourDh;
mapPtr[0x90000] = colourAl;
mapPtr[0x90001] = colourAh;

pos += delta;
mapPtr += 769; // scrollview width?
}

_dword_F253AC = std::clamp<coord_t>(_dword_F253AC + 1, 0, kMapColumns);
}

// 0x0046C544
static void setMapPixels(const Window& self)
{
Expand Down Expand Up @@ -431,11 +512,11 @@ namespace OpenLoco::Ui::Windows::MapWindow

switch (self.currentTab)
{
case 0: setMapPixelsOverall(mapPtr, pos, delta); return; // call(0x0046C5E5, regs); return; // overall
case 1: call(0x0046C873, regs); return; // vehicles
case 2: call(0x0046C9A8, regs); return; // industries
case 3: call(0x0046CB68, regs); return; // routes
case 4: call(0x0046C5E5, regs); return; // ownership
case 0: setMapPixelsOverall(mapPtr, pos, delta); return;
case 1: setMapPixelsVehicles(mapPtr, pos, delta); return;
case 2: call(0x0046C9A8, regs); return; // industries
case 3: call(0x0046CB68, regs); return; // routes
case 4: call(0x0046C5E5, regs); return; // ownership
}
}

Expand Down

0 comments on commit 1c3ac17

Please sign in to comment.