// This file is part of c-evo-evo. // // This software is governed by the CeCILL license under French law and // abiding by the rules of distribution of free software. You can use, // modify and/or redistribute the software under the terms of the CeCILL // license as circulated by CEA, CNRS and INRIA at the following URL // "http://www.cecill.info". // // As a counterpart to the access to the source code and rights to copy, // modify and redistribute granted by the license, users are provided only // with a limited warranty and the software's author, the holder of the // economic rights, and the successive licensors have only limited // liability. // // In this respect, the user's attention is drawn to the risks associated // with loading, using, modifying and/or developing or reproducing the // software by the user in light of its specific status of free software, // that may mean that it is complicated to manipulate, and that also // therefore means that it is reserved for developers and experienced // professionals having in-depth computer knowledge. Users are therefore // encouraged to load and test the software's suitability as regards their // requirements in conditions enabling the security of their systems and/or // data to be ensured and, more generally, to use and operate it in the // same conditions as regards security. // // The fact that you are presently reading this means that you have had // knowledge of the CeCILL license and that you accept its terms. // PORT STATUS (see /memories/repo/cevo-evo-game.md for the full writeup): // 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 { int unFocus = -1; bool blinkOn = false; bool destinationMarkOn = false; int clientMode = 0; 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) { return y > (ClientTools::g.ly - 2) / 4 && ClientTools::g.ly - 1 - y > (ClientTools::g.ly - 2) / 4; } void init(InitEnemyModelEvent initEnemyModelHandler) { onInitEnemyModel = std::move(initEnemyModelHandler); } void CitiesPictures::prepare(GraphicSet *hGrCities, int xxt, int yyt) { for (int age = 2; age <= 3; ++age) { for (int size = 0; size <= 3; ++size) { Tribes::CityPicture &pic = picture(age, size); Tribes::findPosition(hGrCities, size * (xxt * 2 + 1), (age - 2) * (yyt * 3 + 1), xxt * 2 - 1, yyt * 3 - 1, colorFromDelphi(0x00FFFF), pic.xShield, pic.yShield); } } } IsoMapCache::IsoMapCache() { landPatch.image().fill(0); oceanPatch.image().fill(0); borders.image().fill(0); terrainSpriteSize.resize(static_cast(TerrainIconLines * TerrainIconCols)); citiesPictures = std::make_unique(); } IsoMapCache::~IsoMapCache() = default; void IsoMapCache::assignToIsoMap(IsoMap &isoMap) { isoMap.hGrTerrain = hGrTerrain; isoMap.hGrCities = hGrCities; isoMap.m_borders = &borders; isoMap.m_bordersOk = &bordersOk; isoMap.m_landPatch = &landPatch; isoMap.m_oceanPatch = &oceanPatch; isoMap.terrainSpriteSize = &terrainSpriteSize; isoMap.m_citiesPictures = citiesPictures.get(); } IsoMap::IsoMap() { m_left = 0; m_top = 0; m_right = 0; m_bottom = 0; m_attLoc = -1; m_defLoc = -1; m_adviceLoc = -1; applyTileSize(DefaultTileSize); } IsoMap::~IsoMap() = default; void IsoMap::reset() { if (m_bordersOk) *m_bordersOk = 0; } void IsoMap::setOutput(Dpi::Bitmap *output) { m_output = output; m_left = 0; m_top = 0; m_right = output->width(); m_bottom = output->height(); } void IsoMap::setPaintBounds(int left, int top, int right, int bottom) { m_left = left; m_top = top; m_right = right; m_bottom = bottom; } void IsoMap::setTileSize(TileSize value) { if (m_tileSize == value) return; applyTileSize(value); } void IsoMap::fillRect(int x, int y, int width, int height, QColor color) { if (x < m_left) { width -= (m_left - x); x = m_left; } if (y < m_top) { height -= (m_top - y); y = m_top; } if (x + width >= m_right) width = m_right - x; if (y + height >= m_bottom) height = m_bottom - y; if (width <= 0 || height <= 0) return; Dpi::Canvas &canvas = m_output->canvas(); canvas.brush().setColor(color); canvas.fillRect(QRect(x, y, width, height)); canvas.brush().setStyle(Qt::NoBrush); } void IsoMap::textOut(int x, int y, QColor color, const QString &s) { Dpi::Canvas &canvas = m_output->canvas(); canvas.font().setColor(color); canvas.textOut(x, y, s); } void IsoMap::bitBltBitmapOutput(Dpi::Bitmap &src, int x, int y, int width, int height, int xSrc, int ySrc, RasterOp rop) { if (x < m_left) { width -= (m_left - x); xSrc += (m_left - x); x = m_left; } if (y < m_top) { height -= (m_top - y); ySrc += (m_top - y); y = m_top; } if (x + width >= m_right) width = m_right - x; if (y + height >= m_bottom) height = m_bottom - y; if (width <= 0 || height <= 0) return; bitBltBitmap(*m_output, x, y, width, height, src, xSrc, ySrc, rop); } void IsoMap::sprite(GraphicSet *hGr, int xDst, int yDst, int width, int height, int xGr, int yGr) { bitBltBitmapOutput(hGr->mask, xDst, yDst, width, height, xGr, yGr, RasterOp::And); bitBltBitmapOutput(hGr->data, xDst, yDst, width, height, xGr, yGr, RasterOp::Paint); } void IsoMap::terrainSprite(int xDst, int yDst, int grix, bool pureBlack) { const SpriteBounds &bounds = (*terrainSpriteSize)[static_cast(grix)]; int width = bounds.right - bounds.left; int height = bounds.bottom - bounds.top; int xSrc = 1 + grix % TerrainIconCols * (xxt * 2 + 1) + bounds.left; int ySrc = 1 + grix / TerrainIconCols * (yyt * 3 + 1) + bounds.top; xDst += bounds.left; yDst = yDst - yyt + bounds.top; if (xDst < m_left) { width -= (m_left - xDst); xSrc += (m_left - xDst); xDst = m_left; } if (yDst < m_top) { height -= (m_top - yDst); ySrc += (m_top - yDst); yDst = m_top; } if (xDst + width >= m_right) width = m_right - xDst; if (yDst + height >= m_bottom) height = m_bottom - yDst; if (width <= 0 || height <= 0) return; bitBltBitmap(*m_output, xDst, yDst, width, height, hGrTerrain->mask, xSrc, ySrc, RasterOp::And); if (!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; const int lx = ClientTools::g.lx; const int ly = ClientTools::g.ly; if (loc < -2 * lx) { // off both poles } else if (loc < -lx) { if ((ClientTools::myMap[ClientTools::dLoc(loc, 0, 2)] & fTerrain) != fUNKNOWN && (ClientTools::myMap[ClientTools::dLoc(loc, -2, 2)] & fTerrain) != fUNKNOWN && (ClientTools::myMap[ClientTools::dLoc(loc, 2, 2)] & fTerrain) != fUNKNOWN) result = fArctic; if ((ClientTools::myMap[ClientTools::dLoc(loc, 0, 2)] & fObserved) != 0 && (ClientTools::myMap[ClientTools::dLoc(loc, -2, 2)] & fObserved) != 0 && (ClientTools::myMap[ClientTools::dLoc(loc, 2, 2)] & fObserved) != 0) result |= fObserved; } else if (loc < 0) { if ((ClientTools::myMap[ClientTools::dLoc(loc, -1, 1)] & fTerrain) != fUNKNOWN && (ClientTools::myMap[ClientTools::dLoc(loc, 1, 1)] & fTerrain) != fUNKNOWN) result = fArctic; if ((ClientTools::myMap[ClientTools::dLoc(loc, -1, 1)] & fObserved) != 0 && (ClientTools::myMap[ClientTools::dLoc(loc, 1, 1)] & fObserved) != 0) result |= fObserved; } else if (loc < lx * (ly + 1)) { if ((ClientTools::myMap[ClientTools::dLoc(loc, -1, -1)] & fTerrain) != fUNKNOWN && (ClientTools::myMap[ClientTools::dLoc(loc, 1, -1)] & fTerrain) != fUNKNOWN) result = fArctic; if ((ClientTools::myMap[ClientTools::dLoc(loc, -1, -1)] & fObserved) != 0 && (ClientTools::myMap[ClientTools::dLoc(loc, 1, -1)] & fObserved) != 0) result |= fObserved; } else if (loc < lx * (ly + 2)) { if ((ClientTools::myMap[ClientTools::dLoc(loc, 0, -2)] & fTerrain) != fUNKNOWN && (ClientTools::myMap[ClientTools::dLoc(loc, -2, -2)] & fTerrain) != fUNKNOWN && (ClientTools::myMap[ClientTools::dLoc(loc, 2, -2)] & fTerrain) != fUNKNOWN) result = fArctic; if ((ClientTools::myMap[ClientTools::dLoc(loc, 0, -2)] & fObserved) != 0 && (ClientTools::myMap[ClientTools::dLoc(loc, -2, -2)] & fObserved) != 0 && (ClientTools::myMap[ClientTools::dLoc(loc, 2, -2)] & fObserved) != 0) result |= fObserved; } return result; } namespace { constexpr int Dirx[8] = { 1, 2, 1, 0, -1, -2, -1, 0 }; constexpr int Diry[8] = { -1, 0, 1, 2, 1, 0, -1, -2 }; } // namespace int IsoMap::connection4(int loc, std::uint32_t mask, std::uint32_t value) const { int result = 0; const int lx = ClientTools::g.lx; const int ly = ClientTools::g.ly; if (ClientTools::dLoc(loc, 1, -1) >= 0) { if ((ClientTools::myMap[ClientTools::dLoc(loc, 1, -1)] & mask) == value) result += 1; if ((ClientTools::myMap[ClientTools::dLoc(loc, -1, -1)] & mask) == value) result += 8; } if (ClientTools::dLoc(loc, 1, 1) < lx * ly) { if ((ClientTools::myMap[ClientTools::dLoc(loc, 1, 1)] & mask) == value) result += 2; if ((ClientTools::myMap[ClientTools::dLoc(loc, -1, 1)] & mask) == value) result += 4; } return result; } int IsoMap::connection8(int loc, std::uint32_t mask) const { int result = 0; const int lx = ClientTools::g.lx; const int ly = ClientTools::g.ly; for (int dir = 0; dir < 8; ++dir) { const int connLoc = ClientTools::dLoc(loc, Dirx[dir], Diry[dir]); if (connLoc >= 0 && connLoc < lx * ly && (ClientTools::myMap[connLoc] & mask) != 0) result += 1 << dir; } return result; } int IsoMap::oceanConnection(int loc) const { int result = 0; const int lx = ClientTools::g.lx; const int ly = ClientTools::g.ly; for (int dir = 0; dir < 8; ++dir) { const int connLoc = ClientTools::dLoc(loc, Dirx[dir], Diry[dir]); if (connLoc < 0 || connLoc >= lx * ly || ((ClientTools::myMap[connLoc] - 2) & fTerrain) < 13) result += 1 << dir; } return result; } bool IsoMap::isShoreTile(int loc) const { const int lx = ClientTools::g.lx; const int ly = ClientTools::g.ly; for (int dir = 0; dir < 8; ++dir) { const int connLoc = ClientTools::dLoc(loc, Dirx[dir], Diry[dir]); if (connLoc < 0 || connLoc >= lx * ly || ((ClientTools::myMap[connLoc] - 2) & fTerrain) < 13) return true; } return false; } void IsoMap::makeDark(Dpi::PixelPointer &line, int length) { for (int i = 0; i < length; ++i) { const QRgb c = line.pixelARGB(); line.setPixelARGB(qRgb((qRed(c) >> 1) & 0x7F, (qGreen(c) >> 1) & 0x7F, (qBlue(c) >> 1) & 0x7F)); line.nextPixel(); } } void IsoMap::shadeOutside(int x0, int y0, int width, int height, int xm, int ym) { constexpr double rShade = 3.75; Dpi::PixelPointer line(&m_output->image(), x0, y0); for (int y = 0; y < height; ++y) { const double yN = static_cast(y + y0 - ym) / yyt; if (std::abs(yN) < rShade) { // Darken left and right parts of the ellipse. const double wN = std::sqrt(rShade * rShade - yN * yN); const int wBright = static_cast(wN * xxt + 0.5); line.setX(0); makeDark(line, xm - wBright); line.setX(xm + wBright); makeDark(line, width - xm - wBright); } else { // Darken the entire line. line.setX(0); makeDark(line, width); } line.nextLine(); } } void IsoMap::clippedLine(int x, int y, int dx0, int dy0, bool mirror) { Dpi::Canvas &canvas = m_output->canvas(); const int dxmin = (m_left - x) / xxt; const int dymin = (m_realTop - y) / yyt; const int dxmax = (m_right - x - 1) / xxt + 1; const int dymax = (m_realBottom - y - 1) / yyt + 1; int n = dymax - dy0; if (mirror) { if (dx0 - dxmin < n) n = dx0 - dxmin; if (dx0 > dxmax) { n -= (dx0 - dxmax); dy0 += (dx0 - dxmax); dx0 = dxmax; } if (dy0 < dymin) { n -= (dymin - dy0); dx0 -= (dymin - dy0); dy0 = dymin; } } else { if (dxmax - dx0 < n) n = dxmax - dx0; if (dx0 < dxmin) { n -= (dxmin - dx0); dy0 += (dxmin - dx0); dx0 = dxmin; } if (dy0 < dymin) { n -= (dymin - dy0); dx0 += (dymin - dy0); dy0 = dymin; } } if (n <= 0) return; int x0, x1; if (mirror) { x0 = x + dx0 * xxt - 1; x1 = x + (dx0 - n) * xxt - 1; } else { x0 = x + dx0 * xxt; x1 = x + (dx0 + n) * xxt; } canvas.moveTo(x0, y + dy0 * yyt); canvas.lineTo(x1, y + (dy0 + n) * yyt); } void IsoMap::paintGrid(int x, int y, int nx, int ny) { Dpi::Canvas &canvas = m_output->canvas(); canvas.pen().setColor(Qt::black); for (int i = 0; i <= nx / 2; ++i) clippedLine(x, y, i * 2, 0, false); for (int i = 1; i <= (nx + 1) / 2; ++i) clippedLine(x, y, i * 2, 0, true); for (int i = 0; i <= ny / 2; ++i) { clippedLine(x, y, 0, 2 * i + 2, false); clippedLine(x, y, nx + 1, 2 * i + 1 + (nx & 1), true); } } void IsoMap::cityGrid(int xm, int ym, bool cityAllowClick) { Dpi::Canvas &canvas = m_output->canvas(); canvas.pen().setColor(cityAllowClick ? QColor(Qt::white) : QColor(Qt::black)); canvas.pen().setWidth(1); for (int i = 0; i <= 3; ++i) { canvas.moveTo(xm - xxt * (4 - i), ym + yyt * (1 + i)); canvas.lineTo(xm + xxt * (1 + i), ym - yyt * (4 - i)); canvas.moveTo(xm - xxt * (4 - i), ym - yyt * (1 + i)); canvas.lineTo(xm + xxt * (1 + i), ym + yyt * (4 - i)); } canvas.moveTo(xm - xxt * 4, ym + yyt * 1); canvas.lineTo(xm - xxt * 1, ym + yyt * 4); canvas.moveTo(xm + xxt * 1, ym + yyt * 4); canvas.lineTo(xm + xxt * 4, ym + yyt * 1); canvas.moveTo(xm - xxt * 4, ym - yyt * 1); canvas.lineTo(xm - xxt * 1, ym - yyt * 4); canvas.moveTo(xm + xxt * 1, ym - yyt * 4); canvas.lineTo(xm + xxt * 4, ym - yyt * 1); } void IsoMap::attackBegin(const TShowMove &showMove) { m_attLoc = showMove.FromLoc; m_defLoc = ClientTools::dLoc(m_attLoc, showMove.dx, showMove.dy); m_defHealth = -1; } void IsoMap::attackEffect(const TShowMove &showMove) { m_defHealth = showMove.EndHealthDef; } void IsoMap::attackEnd() { m_attLoc = -1; 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