diff --git a/game/localplayer/IsoEngine.cpp b/game/localplayer/IsoEngine.cpp index c0f2411..8df83c7 100644 --- a/game/localplayer/IsoEngine.cpp +++ b/game/localplayer/IsoEngine.cpp @@ -27,26 +27,17 @@ // knowledge of the CeCILL license and that you accept its terms. // PORT STATUS (see /memories/repo/cevo-evo-game.md for the full writeup): -// this is BATCH 1 of a multi-batch port of IsoEngine.pas (1782 lines). Done: -// class skeleton (every method declared in IsoEngine.h), lifecycle -// (create/destroy/reset/setOutput/setPaintBounds), the pure-geometry -// helpers (poleTile/connection4/connection8/oceanConnection/isShoreTile), -// the simple output primitives (fillRect/textOut/bitBltBitmapOutput/sprite/ -// terrainSprite), line/shading primitives (clippedLine/paintGrid/cityGrid/ -// makeDark/shadeOutside), attack state (attackBegin/Effect/End), and -// CitiesPictures::prepare(). NOT YET PORTED (left declared-only in the -// header, safe since nothing calls IsoMap yet - Term.pas isn't ported): -// applyTileSize()/reduceTerrainIconsSize() (the ~280-line dithered-patch -// asset preparation), paintLandOcean/paintShore/paintTileExtraTerrain -// (terrain-transition rendering), paintTileObjects/1/2/3, paintUnit, -// paintCity, paintBorder, showSpacePort, nameCity, and the top-level -// paint() dispatcher. setTileSize() is a placeholder (just stores the -// value) until applyTileSize() exists - calling the real Pascal chain -// (TileSize setter -> ApplyTileSize) would need that method defined first. +// IsoEngine.pas (1782 lines) is now FULLY PORTED across 3 batches: class +// skeleton/lifecycle/geometry/output primitives/attack state (batch 1), +// asset preparation (applyTileSize/reduceTerrainIconsSize) and the full +// terrain/unit/city/border paint pipeline (batch 2), and the top-level +// paint() dispatcher that ties it all together per visible map rectangle +// (batch 3). #include "IsoEngine.h" #include "Dpi/DpiPixelPointer.h" +#include "Global.h" namespace Cevo { namespace IsoEngine { @@ -59,7 +50,38 @@ ClientTools::MapOptions mapOptions = 0; namespace { InitEnemyModelEvent onInitEnemyModel; -} + +constexpr int ShoreDither = fGrass; + +// sprite indexes +constexpr int spRow2 = 2 * TerrainIconCols + 6; +constexpr int spBlink1 = 1 * TerrainIconCols + 8; +constexpr int spBlink2 = 2 * TerrainIconCols + 8; +constexpr int spPrefStartPos = 1 * TerrainIconCols; +constexpr int spStartPos = 2 * TerrainIconCols; +constexpr int spPlain = 2 * TerrainIconCols + 7; +constexpr int spForest = 3 * TerrainIconCols; +constexpr int spRoad = 9 * TerrainIconCols; +constexpr int spRailRoad = 10 * TerrainIconCols; +constexpr int spCanal = 11 * TerrainIconCols; +constexpr int spIrrigation = 12 * TerrainIconCols; +constexpr int spFarmLand = 12 * TerrainIconCols + 1; +constexpr int spMine = 12 * TerrainIconCols + 2; +constexpr int spFortFront = 12 * TerrainIconCols + 3; +constexpr int spBase = 12 * TerrainIconCols + 4; +constexpr int spSpacePort = 12 * TerrainIconCols + 5; +constexpr int spPollution = 12 * TerrainIconCols + 6; +constexpr int spFortBack = 12 * TerrainIconCols + 7; +constexpr int spMinerals = 12 * TerrainIconCols + 8; +constexpr int spRiver = 13 * TerrainIconCols; +constexpr int spRiverMouths = 15 * TerrainIconCols; +constexpr int spGrid = 15 * TerrainIconCols + 6; +constexpr int spJungle = 18 * TerrainIconCols; +constexpr int spCanalMouths = 20 * TerrainIconCols; + +// IsoEngine.pas's own `IsoMapCache: array[TTileSize] of TIsoMapCache;`. +std::array, 3> g_isoMapCache; +} // namespace bool isJungle(int y) { @@ -87,6 +109,7 @@ IsoMapCache::IsoMapCache() landPatch.image().fill(0); oceanPatch.image().fill(0); borders.image().fill(0); + terrainSpriteSize.resize(static_cast(TerrainIconLines * TerrainIconCols)); citiesPictures = std::make_unique(); } @@ -113,9 +136,7 @@ IsoMap::IsoMap() m_attLoc = -1; m_defLoc = -1; m_adviceLoc = -1; - // NOTE: the original's constructor also does `TileSize := DefaultTileSize` - // here, which triggers ApplyTileSize() (asset loading) - deferred to - // batch 2, see the file banner comment above. + applyTileSize(DefaultTileSize); } IsoMap::~IsoMap() = default; @@ -145,9 +166,9 @@ void IsoMap::setPaintBounds(int left, int top, int right, int bottom) void IsoMap::setTileSize(TileSize value) { - // Placeholder until applyTileSize() (batch 2) exists; just remembers - // the requested size instead of (re)loading its terrain/city assets. - m_tileSize = value; + if (m_tileSize == value) + return; + applyTileSize(value); } void IsoMap::fillRect(int x, int y, int width, int height, QColor color) @@ -212,6 +233,233 @@ void IsoMap::terrainSprite(int xDst, int yDst, int grix, bool pureBlack) bitBltBitmap(*m_output, xDst, yDst, width, height, hGrTerrain->data, xSrc, ySrc, RasterOp::Paint); } +void IsoMap::reduceTerrainIconsSize() +{ + const QImage &mask = hGrTerrain->mask.image(); + auto pixelBlue = [&](int x, int y) { return qBlue(mask.pixel(x, y)); }; + + for (int ySrc = 0; ySrc < TerrainIconLines; ++ySrc) { + for (int xSrc = 0; xSrc < TerrainIconCols; ++xSrc) { + const int i = ySrc * TerrainIconCols + xSrc; + SpriteBounds &b = (*terrainSpriteSize)[static_cast(i)]; + const int rowBase = 1 + ySrc * (yyt * 3 + 1); + const int colBase = xSrc * (xxt * 2 + 1); + bool border; + + b.left = 0; + do { + border = true; + for (int y = 0; y < yyt * 3; ++y) + if (pixelBlue(1 + colBase + b.left, rowBase + y) == 0) + border = false; + if (border) + ++b.left; + } while (border && b.left != xxt * 2 - 1); + + b.top = 0; + do { + border = true; + for (int x = 0; x < xxt * 2; ++x) + if (pixelBlue(1 + colBase + x, rowBase + b.top) == 0) + border = false; + if (border) + ++b.top; + } while (border && b.top != yyt * 3 - 1); + + b.right = xxt * 2; + do { + border = true; + for (int y = 0; y < yyt * 3; ++y) + if (pixelBlue(colBase + b.right, rowBase + y) == 0) + border = false; + if (border) + --b.right; + } while (border && b.right != b.left); + + b.bottom = yyt * 3; + do { + border = true; + for (int x = 0; x < xxt * 2; ++x) + if (pixelBlue(1 + colBase + x, rowBase + b.bottom - 1) == 0) + border = false; + if (border) + --b.bottom; + } while (border && b.bottom != b.top); + } + } +} + +void IsoMap::applyTileSize(TileSize value) +{ + m_tileSize = value; + xxt = TileSizes[static_cast(value)].x(); + yyt = TileSizes[static_cast(value)].y(); + + auto &cache = g_isoMapCache[static_cast(value)]; + if (cache) { + cache->assignToIsoMap(*this); + return; + } + cache = std::make_unique(); + + QString fileName = QStringLiteral("Terrain%1x%2").arg(xxt * 2).arg(yyt * 2) + PngExt; + cache->hGrTerrain = loadGraphicSet(fileName); + if (!cache->hGrTerrain) + throw std::runtime_error((fileName + QStringLiteral(" not found.")).toStdString()); + + fileName = QStringLiteral("Cities%1x%2").arg(xxt * 2).arg(yyt * 2) + PngExt; + cache->hGrCities = loadGraphicSet(fileName); + if (!cache->hGrCities) + throw std::runtime_error((fileName + QStringLiteral(" not found.")).toStdString()); + + cache->assignToIsoMap(*this); + + m_citiesPictures->prepare(hGrCities, xxt, yyt); + + // prepare dithered ground tiles + Dpi::Bitmap &landPatch = *m_landPatch; + Dpi::Bitmap &oceanPatch = *m_oceanPatch; + landPatch.canvas().brush().setColor(Qt::black); + landPatch.setSize(xxt * 18, yyt * 9); + landPatch.canvas().fillRect(QRect(0, 0, landPatch.width(), landPatch.height())); + oceanPatch.canvas().brush().setColor(Qt::black); + oceanPatch.setSize(xxt * 8, yyt * 4); + oceanPatch.canvas().fillRect(QRect(0, 0, oceanPatch.width(), oceanPatch.height())); + + Dpi::Bitmap landMore(xxt * 18, yyt * 9); + landMore.canvas().brush().setColor(Qt::black); + landMore.canvas().fillRect(QRect(0, 0, landMore.width(), landMore.height())); + Dpi::Bitmap oceanMore(xxt * 8, yyt * 4); + oceanMore.canvas().brush().setColor(Qt::black); + oceanMore.canvas().fillRect(QRect(0, 0, oceanMore.width(), oceanMore.height())); + Dpi::Bitmap ditherMask(xxt * 2, yyt * 2); + ditherMask.canvas().fillRect(QRect(0, 0, ditherMask.width(), ditherMask.height())); + bitBltBitmap(ditherMask, 0, 0, xxt * 2, yyt * 2, hGrTerrain->mask, 1 + 7 * (xxt * 2 + 1), + 1 + yyt + 15 * (yyt * 3 + 1), RasterOp::And); + + for (int x = -1; x <= 6; ++x) { + int xSrc, ySrc; + if (x == -1) { xSrc = ShoreDither * (xxt * 2 + 1) + 1; ySrc = 1 + yyt; } + else if (x == 6) { xSrc = 1 + (xxt * 2 + 1) * 2; ySrc = 1 + yyt + (yyt * 3 + 1) * 2; } + else { xSrc = (x + 2) * (xxt * 2 + 1) + 1; ySrc = 1 + yyt; } + for (int y = -1; y <= 6; ++y) + bitBltBitmap(landPatch, (x + 2) * (xxt * 2), (y + 2) * yyt, xxt * 2, yyt, hGrTerrain->data, xSrc, ySrc, + RasterOp::Copy); + for (int y = -2; y <= 6; ++y) + bitBltBitmap(landPatch, (x + 2) * (xxt * 2), (y + 2) * yyt, xxt, yyt, hGrTerrain->data, xSrc + xxt, + ySrc + yyt, RasterOp::Paint); + for (int y = -2; y <= 6; ++y) + bitBltBitmap(landPatch, (x + 2) * (xxt * 2) + xxt, (y + 2) * yyt, xxt, yyt, hGrTerrain->data, xSrc, + ySrc + yyt, RasterOp::Paint); + for (int y = -2; y <= 6; ++y) + bitBltBitmap(landPatch, (x + 2) * (xxt * 2), (y + 2) * yyt, xxt, yyt, ditherMask, xxt, yyt, + RasterOp::And); + for (int y = -2; y <= 6; ++y) + bitBltBitmap(landPatch, (x + 2) * (xxt * 2) + xxt, (y + 2) * yyt, xxt, yyt, ditherMask, 0, yyt, + RasterOp::And); + } + + for (int y = -1; y <= 6; ++y) { + int xSrc, ySrc; + if (y == -1) { xSrc = ShoreDither * (xxt * 2 + 1) + 1; ySrc = 1 + yyt; } + else if (y == 6) { xSrc = 1 + 2 * (xxt * 2 + 1); ySrc = 1 + yyt + 2 * (yyt * 3 + 1); } + else { xSrc = (y + 2) * (xxt * 2 + 1) + 1; ySrc = 1 + yyt; } + for (int x = -2; x <= 6; ++x) + bitBltBitmap(landMore, (x + 2) * (xxt * 2), (y + 2) * yyt, xxt * 2, yyt, hGrTerrain->data, xSrc, ySrc, + RasterOp::Copy); + bitBltBitmap(landMore, xxt * 2, (y + 2) * yyt, xxt, yyt, hGrTerrain->data, xSrc + xxt, ySrc + yyt, + RasterOp::Paint); + for (int x = 0; x <= 7; ++x) + bitBltBitmap(landMore, (x + 2) * (xxt * 2) - xxt, (y + 2) * yyt, xxt * 2, yyt, hGrTerrain->data, xSrc, + ySrc + yyt, RasterOp::Paint); + for (int x = -2; x <= 6; ++x) + bitBltBitmap(landMore, (x + 2) * (xxt * 2), (y + 2) * yyt, xxt * 2, yyt, ditherMask, 0, 0, + RasterOp::And); + } + + for (int x = 0; x <= 3; ++x) { + for (int y = 0; y <= 3; ++y) { + int xSrc; + if (x == 1 && y == 1) xSrc = 1; + else xSrc = (x % 2) * (xxt * 2 + 1) + 1; + const int ySrc = 1 + yyt; + if ((x >= 1) == (y >= 2)) + bitBltBitmap(oceanPatch, x * (xxt * 2), y * yyt, xxt * 2, yyt, hGrTerrain->data, xSrc, ySrc, + RasterOp::Copy); + if (x >= 1 && (y < 2 || x >= 2)) { + bitBltBitmap(oceanPatch, x * (xxt * 2), y * yyt, xxt, yyt, hGrTerrain->data, xSrc + xxt, ySrc + yyt, + RasterOp::Paint); + bitBltBitmap(oceanPatch, x * (xxt * 2) + xxt, y * yyt, xxt, yyt, hGrTerrain->data, xSrc, ySrc + yyt, + RasterOp::Paint); + } + bitBltBitmap(oceanPatch, x * (xxt * 2), y * yyt, xxt, yyt, ditherMask, xxt, yyt, RasterOp::And); + bitBltBitmap(oceanPatch, x * (xxt * 2) + xxt, y * yyt, xxt, yyt, ditherMask, 0, yyt, RasterOp::And); + } + } + + for (int y = 0; y <= 3; ++y) { + for (int x = 0; x <= 3; ++x) { + int xSrc; + if (x == 1 && y == 1) xSrc = 1; + else xSrc = (y % 2) * (xxt * 2 + 1) + 1; + const int ySrc = 1 + yyt; + if (x < 1 || y >= 2) + bitBltBitmap(oceanMore, x * (xxt * 2), y * yyt, xxt * 2, yyt, hGrTerrain->data, xSrc, ySrc, + RasterOp::Copy); + if ((x == 1 && y < 2) || (x >= 2 && y >= 1)) { + bitBltBitmap(oceanMore, x * (xxt * 2), y * yyt, xxt, yyt, hGrTerrain->data, xSrc + xxt, ySrc + yyt, + RasterOp::Paint); + bitBltBitmap(oceanMore, x * (xxt * 2) + xxt, y * yyt, xxt, yyt, hGrTerrain->data, xSrc, ySrc + yyt, + RasterOp::Paint); + } + bitBltBitmap(oceanMore, x * (xxt * 2), y * yyt, xxt * 2, yyt, ditherMask, 0, 0, RasterOp::And); + } + } + + bitBltBitmap(ditherMask, 0, 0, xxt * 2, yyt * 2, ditherMask, 0, 0, RasterOp::Invert); // invert dither mask + bitBltBitmap(ditherMask, 0, 0, xxt * 2, yyt * 2, hGrTerrain->mask, 1, 1 + yyt, RasterOp::Paint); + + for (int x = -1; x <= 6; ++x) + for (int y = -2; y <= 6; ++y) + bitBltBitmap(landPatch, (x + 2) * (xxt * 2), (y + 2) * yyt, xxt * 2, yyt, ditherMask, 0, 0, + RasterOp::And); + + for (int y = -1; y <= 6; ++y) + for (int x = -2; x <= 7; ++x) + bitBltBitmap(landMore, (x + 2) * (xxt * 2) - xxt, (y + 2) * yyt, xxt * 2, yyt, ditherMask, 0, yyt, + RasterOp::And); + + bitBltBitmap(landPatch, 0, 0, (xxt * 2) * 9, yyt * 9, landMore, 0, 0, RasterOp::Paint); + + for (int x = 0; x <= 3; ++x) + for (int y = 0; y <= 3; ++y) + bitBltBitmap(oceanPatch, x * (xxt * 2), y * yyt, xxt * 2, yyt, ditherMask, 0, 0, RasterOp::And); + + for (int y = 0; y <= 3; ++y) + for (int x = 0; x <= 4; ++x) + bitBltBitmap(oceanMore, x * (xxt * 2) - xxt, y * yyt, xxt * 2, yyt, ditherMask, 0, yyt, RasterOp::And); + + bitBltBitmap(oceanPatch, 0, 0, (xxt * 2) * 4, yyt * 4, oceanMore, 0, 0, RasterOp::Paint); + + ditherMask.canvas().brush().setColor(Qt::white); + ditherMask.canvas().fillRect(QRect(0, 0, xxt * 2, yyt)); + bitBltBitmap(ditherMask, 0, 0, xxt * 2, yyt, hGrTerrain->mask, 1, 1 + yyt, RasterOp::Copy); + + for (int x = 0; x <= 6; ++x) + bitBltBitmap(landPatch, (x + 2) * (xxt * 2), yyt, xxt * 2, yyt, ditherMask, 0, 0, RasterOp::And); + bitBltBitmap(ditherMask, 0, 0, xxt * 2, yyt, ditherMask, 0, 0, RasterOp::Invert); + + for (int y = 0; y <= 6; ++y) + bitBltBitmap(landPatch, xxt * 2, (y + 2) * yyt, xxt * 2, yyt, ditherMask, 0, 0, RasterOp::And); + + reduceTerrainIconsSize(); + + Dpi::Bitmap &borders = *m_borders; + borders.setSize(xxt * 2, (yyt * 2) * nPl); + borders.canvas().fillRect(QRect(0, 0, borders.width(), borders.height())); + *m_bordersOk = 0; +} + int IsoMap::poleTile(int loc) const { // virtual pole tile int result = fUNKNOWN; @@ -452,5 +700,688 @@ void IsoMap::attackEnd() m_defLoc = -1; } +void IsoMap::paintUnit(int x, int y, const TUnitInfo &unitInfo, int status) +{ + if (unitInfo.Owner != ClientTools::me && unitInfo.emix == 0xFFFF) + return; + + Tribes::Tribe &owner = *Tribes::tribe[unitInfo.Owner]; + const int mixShow = unitInfo.Job == jCity ? -1 : unitInfo.mix; + if (!owner.modelPictureAt(mixShow).hGr && onInitEnemyModel) { + if (!onInitEnemyModel(unitInfo.emix)) + return; + } + const int xsh = owner.modelPictureAt(mixShow).xShield; + const int ysh = owner.modelPictureAt(mixShow).yShield; + + int j; + if (status & usStay) + j = 19; + else if (status & usRecover) + j = 16; + else if ((status & (usGoto | usEnhance)) == (usGoto | usEnhance)) + j = 18; + else if (status & usEnhance) + j = 17; + else if (status & usGoto) + j = 20; + else if (unitInfo.Job == jCity) + j = jNone; + else + j = unitInfo.Job; + + if (unitInfo.Flags & unMulti) + sprite(owner.symHGr, x + xsh - 1 + 4, y + ysh - 2, 14, 12, 33 + owner.symPix % 10 * 65, + 1 + owner.symPix / 10 * 49); + sprite(owner.symHGr, x + xsh - 1, y + ysh - 2, 14, 12, 18 + owner.symPix % 10 * 65, 1 + owner.symPix / 10 * 49); + fillRect(x + xsh, y + ysh + 5, 1 + unitInfo.Health * 11 / 100, 3, + colorFromDelphi(ClientTools::colorOfHealth(unitInfo.Health))); + + if (j > 0) { + const int xGr = 121 + j % 7 * 9; + const int yGr = 1 + j / 7 * 9; + bitBltBitmapOutput(HGrSystem->mask, x + xsh + 3, y + ysh + 9, 8, 8, xGr, yGr, RasterOp::And); + sprite(HGrSystem, x + xsh + 2, y + ysh + 8, 8, 8, xGr, yGr); + } + + const Tribes::ModelPicture &mp = owner.modelPictureAt(mixShow); + sprite(mp.hGr, x, y, 64, 48, mp.pix % 10 * 65 + 1, mp.pix / 10 * 49 + 1); + + if (unitInfo.Flags & unFortified) + sprite(Tribes::hGrStdUnits, x, y, xxu * 2, yyu * 2, 1 + 6 * (xxu * 2 + 1), 1); +} + +void IsoMap::paintCity(int x, int y, const TCityInfo &cityInfo, bool accessory) +{ + const int age = ClientTools::getAge(cityInfo.Owner); + int xGr; + if (cityInfo.Size < 5) xGr = 0; + else if (cityInfo.Size < 9) xGr = 1; + else if (cityInfo.Size < 13) xGr = 2; + else xGr = 3; + + Tribes::Tribe &owner = *Tribes::tribe[cityInfo.Owner]; + owner.initAge(age); + if (age < 2) { + GraphicSet *cHGr = owner.cHGr; + const int cpix = owner.cPix; + const QRgb markRgb = colorFromDelphi(0x00FFFF).rgb() & 0xFFFFFFu; + const bool hasShieldMarker = + cHGr && + (static_cast(cHGr->data.image().pixel((xGr + 4) * 65, cpix * 49 + 48)) & 0xFFFFFFu) == markRgb; + if ((cityInfo.Flags & ciWalled) == 0 || hasShieldMarker) + sprite(cHGr, x - xxc, y - 2 * yyc, xxc * 2, yyc * 3, xGr * (xxc * 2 + 1) + 1, 1 + cpix * (yyc * 3 + 1)); + if (cityInfo.Flags & ciWalled) + sprite(cHGr, x - xxc, y - 2 * yyc, xxc * 2, yyc * 3, (xGr + 4) * (xxc * 2 + 1) + 1, + 1 + cpix * (yyc * 3 + 1)); + } else { + if (cityInfo.Flags & ciWalled) + sprite(hGrCities, x - xxt, y - 2 * yyt, 2 * xxt, 3 * yyt, (xGr + 4) * (2 * xxt + 1) + 1, + 1 + (age - 2) * (3 * yyt + 1)); + else + sprite(hGrCities, x - xxt, y - 2 * yyt, 2 * xxt, 3 * yyt, xGr * (2 * xxt + 1) + 1, + 1 + (age - 2) * (3 * yyt + 1)); + } + + if (!accessory) + return; + + if (ClientTools::myMap[cityInfo.Loc] & fObserved) { + int xShield, yShield; + if (age < 2) { + const Tribes::CityPicture &cpic = owner.cityPicture[static_cast(xGr)]; + xShield = x - xxc + cpic.xShield; + yShield = y - 2 * yyc + cpic.yShield; + } else { + const Tribes::CityPicture &cpic = m_citiesPictures->picture(age, xGr); + xShield = x - xxt + cpic.xShield; + yShield = y - 2 * yyt + cpic.yShield; + } + const QString s = QString::number(cityInfo.Size); + const int labelLength = m_output->canvas().textWidth(s); + fillRect(xShield, yShield, labelLength + 4, 16, Qt::black); + QColor labelTextColor; + if ((ClientTools::myMap[cityInfo.Loc] & (fUnit | fObserved)) == fObserved) { + labelTextColor = owner.color; + } else { + fillRect(xShield + 1, yShield + 1, labelLength + 2, 14, owner.color); + labelTextColor = Qt::black; + } + textOut(xShield + 2, yShield - 1, labelTextColor, s); + } +} + +void IsoMap::paintLandOcean(int x, int y, int loc, int nx, int ny) +{ + const int lx = ClientTools::g.lx; + const int ly = ClientTools::g.ly; + for (int dy = 0; dy <= ny + 1; ++dy) { + if (!(loc + dy * lx >= 0 && loc + (dy - 3) * lx < lx * ly)) + continue; + for (int dx = 0; dx <= nx; ++dx) { + const int aLoc = ClientTools::dLoc(loc, dx - ((dy + dx) & 1), dy - 2); + const int bLoc = ClientTools::dLoc(loc, dx - ((dy + dx + 1) & 1), dy - 1); + int aTer, bTer; + if (aLoc < 0 || aLoc >= lx * ly) + aTer = poleTile(aLoc) & fTerrain; + else + aTer = static_cast(ClientTools::myMap[aLoc] & fTerrain); + if (bLoc < 0 || bLoc >= lx * ly) + bTer = poleTile(bLoc) & fTerrain; + else + bTer = static_cast(ClientTools::myMap[bLoc] & fTerrain); + + if (aTer == fUNKNOWN && bTer == fUNKNOWN) + continue; + + if ((aTer < fGrass || aTer == fUNKNOWN) && (bTer < fGrass || bTer == fUNKNOWN)) { + int aix, bix; + if (aTer == fUNKNOWN) aix = 0; + else if (isShoreTile(aLoc)) aix = aTer == fOcean ? -1 : 1; + else aix = aTer + 2; + if (bTer == fUNKNOWN) bix = 0; + else if (isShoreTile(bLoc)) bix = bTer == fOcean ? -1 : 1; + else bix = bTer + 2; + + if (aix > 1 || bix > 1) { + if (aix == -1) { + if (bix == fOcean + 2) { aix = 0; bix = 0; } + else { aix = 0; bix = 1; } + } else if (bix == -1) { + if (aix == fOcean + 2) { aix = 1; bix = 1; } + else { aix = 1; bix = 0; } + } + bitBltBitmapOutput(*m_oceanPatch, x + dx * xxt, y + dy * yyt, xxt, yyt, + aix * (xxt * 2) + ((dx + dy + 1) & 1) * xxt, bix * yyt, RasterOp::Copy); + } + } else { + int aix, bix; + if (aTer == fUNKNOWN) aix = 0; + else if (aLoc >= 0 && aLoc < lx * ly && (ClientTools::myMap[aLoc] & fDeadLands)) aix = -2; + else if (aTer == fOcean) aix = -1; + else if (aTer == fShore) aix = 1; + else if (aTer >= fForest) aix = 8; + else aix = aTer; + if (bTer == fUNKNOWN) bix = 0; + else if (bLoc >= 0 && bLoc < lx * ly && (ClientTools::myMap[bLoc] & fDeadLands)) bix = -2; + else if (bTer == fOcean) bix = -1; + else if (bTer == fShore) bix = 1; + else if (bTer >= fForest) bix = 8; + else bix = bTer; + + if (aix == -2 && bix == -2) { aix = fDesert; bix = fDesert; } + else if (aix == -2) aix = bix < 2 ? 8 : bix; + else if (bix == -2) bix = aix < 2 ? 8 : aix; + + if (aix == -1) + bitBltBitmapOutput(hGrTerrain->data, x + dx * xxt, y + dy * yyt, xxt, yyt, + 1 + 6 * (xxt * 2 + 1) + ((dx + dy + 1) & 1) * xxt, 1 + yyt, RasterOp::Copy); + else if (bix == -1) + bitBltBitmapOutput(hGrTerrain->data, x + dx * xxt, y + dy * yyt, xxt, yyt, + 1 + 6 * (xxt * 2 + 1) + xxt - ((dx + dy + 1) & 1) * xxt, 1 + yyt * 2, + RasterOp::Copy); + else + bitBltBitmapOutput(*m_landPatch, x + dx * xxt, y + dy * yyt, xxt, yyt, + aix * (xxt * 2) + ((dx + dy + 1) & 1) * xxt, bix * yyt, RasterOp::Copy); + } + } + } +} + +void IsoMap::paintShore(int x, int y, int loc) +{ + if (y <= m_top - yyt * 2 || y > m_bottom || x <= m_left - xxt * 2 || x > m_right) + return; + const int lx = ClientTools::g.lx; + const int ly = ClientTools::g.ly; + if (loc < 0 || loc >= lx * ly) + return; + const std::uint32_t tile = ClientTools::myMap[loc]; + if ((tile & fTerrain) >= static_cast(fGrass)) + return; + int conn = oceanConnection(loc); + if (conn == 0) + return; + const int terrain = static_cast(tile & fTerrain); + + bitBltBitmapOutput(hGrTerrain->data, x + xxt / 2, y, xxt, yyt, + 1 + ((conn >> 6) + ((conn & 1) << 2)) * (xxt * 2 + 1), + 1 + yyt + (16 + terrain) * (yyt * 3 + 1), RasterOp::Paint); + bitBltBitmapOutput(hGrTerrain->data, x + xxt, y + yyt / 2, xxt, yyt, 1 + (conn & 7) * (xxt * 2 + 1) + xxt, + 1 + yyt * 2 + (16 + terrain) * (yyt * 3 + 1), RasterOp::Paint); + bitBltBitmapOutput(hGrTerrain->data, x + xxt / 2, y + yyt, xxt, yyt, + 1 + ((conn >> 2) & 7) * (xxt * 2 + 1) + xxt, 1 + yyt + (16 + terrain) * (yyt * 3 + 1), + RasterOp::Paint); + bitBltBitmapOutput(hGrTerrain->data, x, y + yyt / 2, xxt, yyt, 1 + ((conn >> 4) & 7) * (xxt * 2 + 1), + 1 + yyt * 2 + (16 + terrain) * (yyt * 3 + 1), RasterOp::Paint); + + conn = connection4(loc, fTerrain, fUNKNOWN); // dither to black + if (conn & 1) + bitBltBitmapOutput(hGrTerrain->mask, x + xxt, y, xxt, yyt, 1 + 7 * (xxt * 2 + 1) + xxt, + 1 + yyt + 15 * (yyt * 3 + 1), RasterOp::And); + if (conn & 2) + bitBltBitmapOutput(hGrTerrain->mask, x + xxt, y + yyt, xxt, yyt, 1 + 7 * (xxt * 2 + 1) + xxt, + 1 + yyt * 2 + 15 * (yyt * 3 + 1), RasterOp::And); + if (conn & 4) + bitBltBitmapOutput(hGrTerrain->mask, x, y + yyt, xxt, yyt, 1 + 7 * (xxt * 2 + 1), + 1 + yyt * 2 + 15 * (yyt * 3 + 1), RasterOp::And); + if (conn & 8) + bitBltBitmapOutput(hGrTerrain->mask, x, y, xxt, yyt, 1 + 7 * (xxt * 2 + 1), 1 + yyt + 15 * (yyt * 3 + 1), + RasterOp::And); +} + +void IsoMap::paintTileExtraTerrain(int x, int y, int loc) +{ + const int lx = ClientTools::g.lx; + const int ly = ClientTools::g.ly; + if (loc < 0 || loc >= lx * ly || y <= -yyt * 2 || y > m_output->height() || x <= -xxt * 2 || + x > m_output->width()) + return; + const std::uint32_t tile = ClientTools::myMap[loc]; + const int terrain = static_cast(tile & fTerrain); + + if (terrain == fForest) { + const int yLoc = loc / lx; + const int yGr = isJungle(yLoc) ? spJungle : spForest; + int conn = connection4(loc, fTerrain, terrain); + if (yLoc == (ly - 2) / 4 || ly - 1 - yLoc == (ly + 2) / 4) + conn &= ~6; // no connection to south + else if (yLoc == (ly + 2) / 4 || ly - 1 - yLoc == (ly - 2) / 4) + conn &= ~9; // no connection to north + terrainSprite(x, y, yGr + conn % 8 + (conn / 8) * TerrainIconCols); + } else if (terrain == fHills || terrain == fMountains) { + // (fForest already handled above - unreachable here in the original too) + const int yGr = 3 + 2 * (terrain - fForest); + const int conn = connection4(loc, fTerrain, terrain); + terrainSprite(x, y, conn % 8 + (yGr + conn / 8) * TerrainIconCols); + } else if (tile & fDeadLands) { + terrainSprite(x, y, spRow2); + } + + if (m_showObjects) { + if ((tile & fTerImp) == static_cast(tiFarm)) + terrainSprite(x, y, spFarmLand); + else if ((tile & fTerImp) == static_cast(tiIrrigation)) + terrainSprite(x, y, spIrrigation); + } + + if (tile & fRiver) { + const int conn = connection4(loc, fRiver, fRiver) | connection4(loc, fTerrain, fShore) | + connection4(loc, fTerrain, fUNKNOWN); + terrainSprite(x, y, spRiver + conn % 8 + (conn / 8) * TerrainIconCols); + } + + if (terrain < fGrass) { + int conn = connection4(loc, fRiver, fRiver); + for (int dir = 0; dir < 4; ++dir) + if (conn & (1 << dir)) + terrainSprite(x, y, spRiverMouths + dir); + if (m_showObjects) { + conn = connection8(loc, fCanal); + for (int dir = 0; dir < 8; ++dir) + if (conn & (1 << dir)) + terrainSprite(x, y, spCanalMouths + 1 + dir); + } + } + + if (m_showObjects) { + if ((tile & fCanal) || (tile & fCity)) { + int conn = connection8(loc, fCanal | fCity); + if (tile & fCanal) + conn |= (0xFF - oceanConnection(loc)); + if (conn == 0) { + if (tile & fCanal) + terrainSprite(x, y, spCanal); + } else { + for (int dir = 0; dir < 8; ++dir) + if ((1 << dir) & conn) + terrainSprite(x, y, spCanal + 1 + dir); + } + } + + int rrConn = 0; + if (tile & (fRR | fCity)) + rrConn = connection8(loc, fRR | fCity); + + if (tile & (fRoad | fRR | fCity)) { + const int conn = connection8(loc, fRoad | fRR | fCity) & ~rrConn; + if (conn == 0 && (tile & (fRR | fCity)) == 0) + terrainSprite(x, y, spRoad); + else if (conn > 0) + for (int dir = 0; dir < 8; ++dir) + if ((1 << dir) & conn) + terrainSprite(x, y, spRoad + 1 + dir); + } + + if ((tile & fRR) && rrConn == 0) + terrainSprite(x, y, spRailRoad); + else if (rrConn > 0) { + for (int dir = 0; dir < 8; ++dir) + if ((1 << dir) & rrConn) + terrainSprite(x, y, spRailRoad + 1 + dir); + } + } +} + +void IsoMap::paintTileObjects(int nx, int ny, int x, int y, int loc, int cityLoc, int cityOwner, bool useBlink, + int radius, bool inside) +{ + auto shouldPaint = [&](int aLoc) { + if (radius < 0) + return true; + const int d = ClientTools::distance(aLoc, cityLoc); + return inside ? d <= radius : d > radius; + }; + + for (int dy = -2; dy <= ny + 1; ++dy) + for (int dx = -2; dx <= nx + 1; ++dx) + if (((dx + dy) & 1) == 0) { + const int aLoc = ClientTools::dLoc(loc, dx, dy); + if (shouldPaint(aLoc)) + paintTileObjects1(x + xxt * dx, y + yyt + yyt * dy, aLoc, cityLoc, cityOwner, useBlink); + } + + for (int dy = -2; dy <= ny + 1; ++dy) + for (int dx = -2; dx <= nx + 1; ++dx) + if (((dx + dy) & 1) == 0) { + const int aLoc = ClientTools::dLoc(loc, dx, dy); + if (shouldPaint(aLoc)) + paintTileObjects2(x + xxt * dx, y + yyt + yyt * dy, aLoc, cityLoc, cityOwner, useBlink); + } + + if (radius >= 0) + unshareBitmap(*m_output); + + for (int dy = -2; dy <= ny + 1; ++dy) + for (int dx = -2; dx <= nx + 1; ++dx) + if (((dx + dy) & 1) == 0) { + const int aLoc = ClientTools::dLoc(loc, dx, dy); + if (shouldPaint(aLoc)) + paintTileObjects3(x + xxt * dx, y + yyt + yyt * dy, aLoc, cityLoc, cityOwner, useBlink); + } +} + +void IsoMap::nameCity(int x, int y, int loc) +{ + const int lx = ClientTools::g.lx; + const int ly = ClientTools::g.ly; + const int behindLoc = loc - 2 * lx; + if (!m_showCityNames || ClientTools::hasMapOption(mapOptions, ClientTools::moEditMode) || behindLoc < 0 || + behindLoc >= lx * ly || (ClientTools::myMap[behindLoc] & fCity) == 0) + return; + + int cix; + TCityInfo cityInfo{}; + ClientTools::getCityInfo(behindLoc, cix, cityInfo); + const bool isCapital = (cityInfo.Flags & ciCapital) != 0; + const QString s = Tribes::cityName(cityInfo.ID); + const int w = m_output->canvas().textWidth(s); + const int xs = x + xxt - (w + 1) / 2; + if (isCapital) + m_output->canvas().font().setUnderline(true); + textOut(xs + 1, y - 9, Qt::black, s); + textOut(xs, y - 10, Qt::white, s); + if (isCapital) + m_output->canvas().font().setUnderline(false); +} + +void IsoMap::paintBorder(int x, int y, int loc, int tile) +{ + const int lx = ClientTools::g.lx; + const int ly = ClientTools::g.ly; + if (!m_showBorder || loc < 0 || loc >= lx * ly || (tile & fTerrain) == fUNKNOWN) + return; + const int p1 = (*ClientTools::myRO->Territory)[loc]; + if (p1 < 0 || !(m_showMyBorder || p1 != ClientTools::me)) + return; + + if ((*m_bordersOk & (1 << p1)) == 0) { + unshareBitmap(*m_borders); + bitBltBitmap(*m_borders, 0, p1 * (yyt * 2), xxt * 2, yyt * 2, hGrTerrain->data, 1 + 8 * (xxt * 2 + 1), + 1 + yyt + 16 * (yyt * 3 + 1)); + bitmapReplaceColor(*m_borders, 0, p1 * (yyt * 2), xxt * 2, yyt * 2, colorFromDelphi(0x636363), + Tribes::tribe[static_cast(p1)]->color); + *m_bordersOk |= (1 << p1); + } + + for (int dy = 0; dy <= 1; ++dy) { + for (int dx = 0; dx <= 1; ++dx) { + const int loc1 = ClientTools::dLoc(loc, dx * 2 - 1, dy * 2 - 1); + int p2; + if (loc1 < 0 || loc1 >= lx * ly) + p2 = -1; + else if ((ClientTools::myMap[loc1] & fTerrain) == static_cast(fUNKNOWN)) + p2 = p1; + else + p2 = (*ClientTools::myRO->Territory)[loc1]; + if (p2 != p1) { + bitBltBitmapOutput(hGrTerrain->mask, x + dx * xxt, y + dy * yyt, xxt, yyt, + 1 + 8 * (xxt * 2 + 1) + dx * xxt, 1 + yyt + 16 * (yyt * 3 + 1) + dy * yyt, + RasterOp::And); + bitBltBitmapOutput(*m_borders, x + dx * xxt, y + dy * yyt, xxt, yyt, dx * xxt, + p1 * (yyt * 2) + dy * yyt, RasterOp::Paint); + } + } + } +} + +void IsoMap::showSpacePort(int x, int y, int tile, const TCityInfo &cityInfo) +{ + if (m_showObjects && !ClientTools::hasMapOption(mapOptions, ClientTools::moEditMode) && + (static_cast(tile) & fCity) && (cityInfo.Flags & ciSpacePort)) + terrainSprite(x + xxt, y - 6, spSpacePort); +} + +void IsoMap::paintTileObjects1(int x, int y, int loc, int cityLoc, int cityOwner, bool useBlink) +{ + Q_UNUSED(cityLoc); + Q_UNUSED(cityOwner); + Q_UNUSED(useBlink); + const int lx = ClientTools::g.lx; + const int ly = ClientTools::g.ly; + const std::uint32_t tile = + (loc < 0 || loc >= lx * ly) ? static_cast(poleTile(loc)) : ClientTools::myMap[loc]; + + TCityInfo cityInfo{}; + if (m_showObjects && !ClientTools::hasMapOption(mapOptions, ClientTools::moEditMode) && (tile & fCity)) { + int cix; + ClientTools::getCityInfo(loc, cix, cityInfo); + } + + if (y <= m_top - yyt * 2 || y > m_bottom || x <= m_left - xxt * 2 || x > m_right) { + nameCity(x, y, loc); + showSpacePort(x, y, static_cast(tile), cityInfo); + return; + } + if ((tile & fTerrain) == static_cast(fUNKNOWN)) { + nameCity(x, y, loc); + showSpacePort(x, y, static_cast(tile), cityInfo); + return; + } + + if (!(m_fogOfWar && (tile & fObserved) == 0)) + paintBorder(x, y, loc, static_cast(tile)); + + if (loc >= 0 && loc < lx * ly && loc == m_adviceLoc) + terrainSprite(x, y, spPlain); + + if (loc >= 0 && loc < lx * ly && (tile & fSpecial)) { + const int dy = loc / lx; + const int specialCol = static_cast(tile & fTerrain); + const int specialRow = static_cast((tile & fSpecial) >> 5); + if (specialCol < fForest) + terrainSprite(x, y, specialCol + specialRow * TerrainIconCols); + else if (specialCol == fForest && isJungle(dy)) + terrainSprite(x, y, spJungle - 1 + specialRow * TerrainIconCols); + else + terrainSprite(x, y, spForest - 1 + ((specialCol - fForest) * 2 + specialRow) * TerrainIconCols); + } + + if (m_showObjects) { + if ((tile & fTerImp) == static_cast(tiMine)) + terrainSprite(x, y, spMine); + if ((tile & fTerImp) == static_cast(tiBase)) + terrainSprite(x, y, spBase); + if (tile & fPoll) + terrainSprite(x, y, spPollution); + if ((tile & fTerImp) == static_cast(tiFort)) { + terrainSprite(x, y, spFortBack); + if ((tile & fObserved) == 0) + terrainSprite(x, y, spFortFront); + } + } + if (tile & fDeadLands) + terrainSprite(x, y, spMinerals + static_cast((tile >> 25) & 3) * TerrainIconCols); +} + +void IsoMap::paintTileObjects2(int x, int y, int loc, int cityLoc, int cityOwner, bool useBlink) +{ + Q_UNUSED(cityLoc); + Q_UNUSED(cityOwner); + Q_UNUSED(useBlink); + const int lx = ClientTools::g.lx; + const int ly = ClientTools::g.ly; + const std::uint32_t tile = + (loc < 0 || loc >= lx * ly) ? static_cast(poleTile(loc)) : ClientTools::myMap[loc]; + + bool fog; + if (ClientTools::hasMapOption(mapOptions, ClientTools::moEditMode)) + fog = loc < 0 || loc >= lx * ly; + else if (m_showGrWall) + fog = (tile & fGrWall) == 0; + else + fog = m_fogOfWar && (tile & fObserved) == 0; + + if (fog && m_showObjects) { + if (loc < -lx) + sprite(hGrTerrain, x, y + yyt, xxt * 2, yyt, 1 + 6 * (xxt * 2 + 1), 1 + yyt * 2 + 15 * (yyt * 3 + 1)); + else if (loc >= lx * (ly + 1)) + sprite(hGrTerrain, x, y, xxt * 2, yyt, 1 + 6 * (xxt * 2 + 1), 1 + yyt + 15 * (yyt * 3 + 1)); + else + terrainSprite(x, y, spGrid, xxt != 33); + } +} + +void IsoMap::paintTileObjects3(int x, int y, int loc, int cityLoc, int cityOwner, bool useBlink) +{ + const int lx = ClientTools::g.lx; + const int ly = ClientTools::g.ly; + const std::uint32_t tile = + (loc < 0 || loc >= lx * ly) ? static_cast(poleTile(loc)) : ClientTools::myMap[loc]; + + TCityInfo cityInfo{}; + if (m_showObjects && !ClientTools::hasMapOption(mapOptions, ClientTools::moEditMode) && (tile & fCity)) { + int cix; + ClientTools::getCityInfo(loc, cix, cityInfo); + } + + if (m_fogOfWar && (tile & fObserved) == 0) + paintBorder(x, y, loc, static_cast(tile)); + + // paint goto destination mark + if (destinationMarkOn && cityOwner < 0 && unFocus >= 0 && (ClientTools::myUn[unFocus].Status & usGoto)) { + const int destination = ClientTools::myUn[unFocus].Status >> 16; + if (destination == loc && destination != ClientTools::myUn[unFocus].Loc) { + if (!useBlink || blinkOn) + terrainSprite(x, y, spBlink1); + else + terrainSprite(x, y, spBlink2); + } + } + + if (ClientTools::hasMapOption(mapOptions, ClientTools::moEditMode)) { + if (tile & fPrefStartPos) + terrainSprite(x, y, spPrefStartPos); + else if (tile & fStartPos) + terrainSprite(x, y, spStartPos); + } else if (m_showObjects) { + nameCity(x, y, loc); + showSpacePort(x, y, static_cast(tile), cityInfo); + if (tile & fCity) + paintCity(x + xxt, y + yyt, cityInfo, cityOwner < 0); + + const bool unitVisible = + (tile & fUnit) && loc != m_attLoc && (loc != m_defLoc || m_defHealth != 0) && + (cityOwner >= 0 || unFocus < 0 || !useBlink || blinkOn || loc != ClientTools::myUn[unFocus].Loc) && + ((tile & fCity) != static_cast(fCity) || loc == m_defLoc || + ((!useBlink || blinkOn) && unFocus >= 0 && loc == ClientTools::myUn[unFocus].Loc)); + + if (unitVisible) { + int uix; + TUnitInfo unitInfo{}; + ClientTools::getUnitInfo(loc, uix, unitInfo); + if (loc == m_defLoc && m_defHealth >= 0) + unitInfo.Health = static_cast(m_defHealth); + if (unitInfo.Owner != cityOwner && + !(cityOwner == ClientTools::me && ClientTools::myRO->Treaty[unitInfo.Owner] == trAlliance)) { + if (unFocus >= 0 && loc == ClientTools::myUn[unFocus].Loc) { + const std::uint16_t multi = unitInfo.Flags & unMulti; + MakeUnitInfo(ClientTools::me, ClientTools::myUn[unFocus], unitInfo); + unitInfo.Flags = static_cast(unitInfo.Flags | multi); + paintUnit(x + (xxt - xxu), y + (yyt - yyuAnchor), unitInfo, ClientTools::myUn[unFocus].Status); + } else if (unitInfo.Owner == ClientTools::me) { + if (clientMode == cMovieTurn) + paintUnit(x + (xxt - xxu), y + (yyt - yyuAnchor), unitInfo, 0); + else + paintUnit(x + (xxt - xxu), y + (yyt - yyuAnchor), unitInfo, ClientTools::myUn[uix].Status); + } else { + paintUnit(x + (xxt - xxu), y + (yyt - yyuAnchor), unitInfo, 0); + } + } + } else if (tile & fHiddenUnit) { + sprite(Tribes::hGrStdUnits, x + (xxt - xxu), y + (yyt - yyuAnchor), xxu * 2, yyu * 2, + 1 + 5 * (xxu * 2 + 1), 1); + } else if (tile & fStealthUnit) { + sprite(Tribes::hGrStdUnits, x + (xxt - xxu), y + (yyt - yyuAnchor), xxu * 2, yyu * 2, + 1 + 5 * (xxu * 2 + 1), 1 + 1 * (yyu * 2 + 1)); + } + } + + if (m_showObjects && (tile & fTerImp) == static_cast(tiFort) && (tile & fObserved)) + terrainSprite(x, y, spFortFront); + + if (loc >= 0 && loc < lx * ly) { + if (m_showLoc) + textOut(x + xxt - 16, y + yyt - 9, colorFromDelphi(0xFFFF00), QString::number(loc)); + else if (m_showDebug && m_debugMap && m_debugMap[loc] != 0) + textOut(x + xxt - 16, y + yyt - 9, colorFromDelphi(0x00E0FF), QString::number(m_debugMap[loc])); + } +} + +void IsoMap::paint(int x, int y, int loc, int nx, int ny, int cityLoc, int cityOwner, bool useBlink, + bool cityAllowClick) +{ + const int lx = ClientTools::g.lx; + const int ly = ClientTools::g.ly; + + m_fogOfWar = true; + m_showLoc = ClientTools::hasMapOption(mapOptions, ClientTools::moLocCodes); + m_showDebug = pDebugMap >= 0; + m_showObjects = cityOwner >= 0 || !ClientTools::hasMapOption(mapOptions, ClientTools::moBareTerrain); + m_showCityNames = + m_showObjects && cityOwner < 0 && ClientTools::hasMapOption(mapOptions, ClientTools::moCityNames); + m_showBorder = true; + m_showMyBorder = cityOwner < 0; + m_showGrWall = cityOwner < 0 && ClientTools::hasMapOption(mapOptions, ClientTools::moGreatWall); + if (m_showDebug) + ClientTools::server(sGetDebugMap, ClientTools::me, pDebugMap, &m_debugMap); + else + m_debugMap = nullptr; + + Dpi::Canvas &canvas = m_output->canvas(); + m_realTop = y - ((loc + 12345 * lx) / lx - 12345) * yyt; + m_realBottom = y + (ly - ((loc + 12345 * lx) / lx - 12345) + 3) * yyt; + canvas.brush().setColor(QColor(0x10, 0x10, 0x10)); // EmptySpaceColor + if (m_realTop > m_top) + canvas.fillRect(QRect(m_left, m_top, m_right - m_left, m_realTop - m_top)); + else + m_realTop = m_top; + if (m_realBottom < m_bottom) + canvas.fillRect(QRect(m_left, m_realBottom, m_right - m_left, m_bottom - m_realBottom)); + else + m_realBottom = m_bottom; + canvas.brush().setColor(Qt::black); + canvas.fillRect(QRect(m_left, m_realTop, m_right - m_left, m_realBottom - m_realTop)); + canvas.brush().setStyle(Qt::NoBrush); + + paintLandOcean(x, y, loc, nx, ny); + + for (int dy = -2; dy <= ny + 1; ++dy) + for (int dx = -1; dx <= nx; ++dx) + if (((dx + dy) & 1) == 0) + paintShore(x + xxt * dx, y + yyt + yyt * dy, ClientTools::dLoc(loc, dx, dy)); + + for (int dy = -2; dy <= ny + 1; ++dy) + for (int dx = -1; dx <= nx; ++dx) + if (((dx + dy) & 1) == 0) + paintTileExtraTerrain(x + xxt * dx, y + yyt + yyt * dy, ClientTools::dLoc(loc, dx, dy)); + + unshareBitmap(*m_output); + + if (cityOwner >= 0) { + // paint objects outside radius + paintTileObjects(nx, ny, x, y, loc, cityLoc, cityOwner, useBlink, 5, false); + + const int dx = ((cityLoc % lx * 2 + (cityLoc / lx & 1)) - + ((loc + 666 * lx) % lx * 2 + ((loc + 666 * lx) / lx & 1)) + 3 * lx) % + (2 * lx) - + lx; + const int dy = cityLoc / lx - (loc + 666 * lx) / lx + 666; + const int xm = x + (dx + 1) * xxt; + const int ym = y + (dy + 1) * yyt + yyt; + shadeOutside(m_left, m_top, m_right - m_left, m_bottom - m_top, xm, ym); + cityGrid(xm, ym, cityAllowClick); + + // paint objects inside radius + paintTileObjects(nx, ny, x, y, loc, cityLoc, cityOwner, useBlink, 5, true); + } else { + if (m_showLoc || ClientTools::hasMapOption(mapOptions, ClientTools::moEditMode) || + ClientTools::hasMapOption(mapOptions, ClientTools::moGrid)) + paintGrid(x, y, nx, ny); + + paintTileObjects(nx, ny, x, y, loc, cityLoc, cityOwner, useBlink); + } +} + } // namespace IsoEngine } // namespace Cevo diff --git a/game/localplayer/IsoEngine.h b/game/localplayer/IsoEngine.h index dbc60eb..b4d41e2 100644 --- a/game/localplayer/IsoEngine.h +++ b/game/localplayer/IsoEngine.h @@ -59,6 +59,16 @@ constexpr int TerrainIconCols = 9; constexpr int xxu = 32; constexpr int yyu = 24; constexpr int yyuAnchor = 32; +constexpr int xxc = 32; // half of age<2 city slot size x +constexpr int yyc = 16; // half of age<2 city slot size y + +// Term.pas's `TUn.Status` bit flags needed by PaintUnit()/PaintTileObjects3() +// - borrowed here the same way as xxu/yyu above (Term.pas itself isn't +// ported yet). +constexpr int usStay = 0x01; +constexpr int usGoto = 0x04; +constexpr int usEnhance = 0x08; +constexpr int usRecover = 0x10; using InitEnemyModelEvent = std::function; enum class TileSize { Small, Medium, Big };