implemented first batch of the isoengine
This commit is contained in:
1 parent
e39691c5cc
commit
84eea05553
3 files changed
+687
No files matched your search
@@ -124,6 +124,8 @@ set(PROJECT_SOURCES
|
||||
game/localplayer/Diagram.ui
|
||||
game/localplayer/Diplomacy.cpp
|
||||
game/localplayer/Diplomacy.h
|
||||
game/localplayer/IsoEngine.cpp
|
||||
game/localplayer/IsoEngine.h
|
||||
game/localplayer/Tribes.cpp
|
||||
game/localplayer/Tribes.h
|
||||
${TS_FILES}
|
||||
|
||||
@@ -0,0 +1,456 @@
|
||||
// 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):
|
||||
// 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.
|
||||
|
||||
#include "IsoEngine.h"
|
||||
|
||||
#include "Dpi/DpiPixelPointer.h"
|
||||
|
||||
namespace Cevo {
|
||||
namespace IsoEngine {
|
||||
|
||||
int unFocus = -1;
|
||||
bool blinkOn = false;
|
||||
bool destinationMarkOn = false;
|
||||
int clientMode = 0;
|
||||
ClientTools::MapOptions mapOptions = 0;
|
||||
|
||||
namespace {
|
||||
InitEnemyModelEvent onInitEnemyModel;
|
||||
}
|
||||
|
||||
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);
|
||||
citiesPictures = std::make_unique<CitiesPictures>();
|
||||
}
|
||||
|
||||
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;
|
||||
// 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.
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
// Placeholder until applyTileSize() (batch 2) exists; just remembers
|
||||
// the requested size instead of (re)loading its terrain/city assets.
|
||||
m_tileSize = 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<std::size_t>(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);
|
||||
}
|
||||
|
||||
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<double>(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<int>(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;
|
||||
}
|
||||
|
||||
} // namespace IsoEngine
|
||||
} // namespace Cevo
|
||||
@@ -0,0 +1,229 @@
|
||||
// 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.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Cevo/CevoGraphicSet.h"
|
||||
#include "Cevo/CevoScreenTools.h"
|
||||
#include "Cevo/Protocol.h"
|
||||
#include "ClientTools.h"
|
||||
#include "Tribes.h"
|
||||
|
||||
#include <QPoint>
|
||||
#include <QRect>
|
||||
#include <QString>
|
||||
|
||||
#include <array>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
namespace Dpi {
|
||||
class PixelPointer;
|
||||
}
|
||||
|
||||
namespace Cevo {
|
||||
namespace IsoEngine {
|
||||
|
||||
constexpr int TerrainIconLines = 21;
|
||||
constexpr int TerrainIconCols = 9;
|
||||
|
||||
// Term.pas's own unit-sprite-slot geometry constants (pure pixel sizes, not
|
||||
// live Term.pas state) - borrowed directly here since only this file uses
|
||||
// them.
|
||||
constexpr int xxu = 32;
|
||||
constexpr int yyu = 24;
|
||||
constexpr int yyuAnchor = 32;
|
||||
|
||||
using InitEnemyModelEvent = std::function<bool(int emix)>;
|
||||
enum class TileSize { Small, Medium, Big };
|
||||
constexpr TileSize DefaultTileSize = TileSize::Medium;
|
||||
// TileSizes[TileSize]: half-tile (x,y) pixel size for Small/Medium/Big.
|
||||
constexpr QPoint TileSizes[3] = { QPoint(33, 16), QPoint(48, 24), QPoint(72, 36) };
|
||||
|
||||
// TRect equivalent for TerrainSpriteSize: plain left/top/right/bottom edges
|
||||
// (NOT QRect, whose right()/bottom() are off-by-one from a direct edge
|
||||
// value unless constructed carefully - the original reads/writes these as
|
||||
// bare edges, so a plain struct avoids that whole pitfall).
|
||||
struct SpriteBounds {
|
||||
int left = 0;
|
||||
int top = 0;
|
||||
int right = 0;
|
||||
int bottom = 0;
|
||||
};
|
||||
using TerrainSpriteSizeList = std::vector<SpriteBounds>;
|
||||
|
||||
// A handful of Term.pas globals IsoMap::paint()/paintTileObjects3() reads
|
||||
// every frame (selected unit, blink phase, goto-destination display,
|
||||
// "movie replay" mode) - mirrored here as externs, to be kept in sync by
|
||||
// Term.cpp once Term.pas is ported. Defaulted to "nothing selected".
|
||||
extern int unFocus; // index into myUn[], -1 if none
|
||||
extern bool blinkOn;
|
||||
extern bool destinationMarkOn;
|
||||
extern int clientMode;
|
||||
constexpr int cMovieTurn = -1; // placeholder until Term.pas defines its real ClientMode enum
|
||||
|
||||
// IsoEngine.pas's own `var MapOptions: TMapOptions;` (the TYPE itself,
|
||||
// MapOption/MapOptions, is declared in ClientTools.h since that's where the
|
||||
// original Pascal unit put it).
|
||||
extern ClientTools::MapOptions mapOptions;
|
||||
|
||||
// TCitiesPictures equivalent: shield-label positions for age 2/3 city
|
||||
// sprites, indexed by (age, size).
|
||||
class CitiesPictures {
|
||||
public:
|
||||
void prepare(GraphicSet *hGrCities, int xxt, int yyt);
|
||||
Tribes::CityPicture &picture(int age, int size)
|
||||
{
|
||||
return m_pictures[static_cast<std::size_t>(age - 2)][static_cast<std::size_t>(size)];
|
||||
}
|
||||
|
||||
private:
|
||||
std::array<std::array<Tribes::CityPicture, 4>, 2> m_pictures{};
|
||||
};
|
||||
|
||||
class IsoMap;
|
||||
|
||||
// TIsoMapCache equivalent: the per-TileSize prepared assets (dithered
|
||||
// ground patches, border overlay, reduced terrain-sprite bounds, city
|
||||
// shield positions) shared by every IsoMap at that TileSize. assignToIsoMap()
|
||||
// mirrors Pascal's reference semantics - IsoMap's bitmap fields point
|
||||
// directly AT this cache's bitmaps (shared, not copied).
|
||||
class IsoMapCache {
|
||||
public:
|
||||
IsoMapCache();
|
||||
~IsoMapCache();
|
||||
IsoMapCache(const IsoMapCache &) = delete;
|
||||
IsoMapCache &operator=(const IsoMapCache &) = delete;
|
||||
|
||||
void assignToIsoMap(IsoMap &isoMap);
|
||||
|
||||
Dpi::Bitmap landPatch;
|
||||
Dpi::Bitmap oceanPatch;
|
||||
Dpi::Bitmap borders;
|
||||
int bordersOk = 0;
|
||||
TerrainSpriteSizeList terrainSpriteSize;
|
||||
GraphicSet *hGrTerrain = nullptr;
|
||||
GraphicSet *hGrCities = nullptr;
|
||||
std::unique_ptr<CitiesPictures> citiesPictures;
|
||||
};
|
||||
|
||||
// TIsoMap equivalent: renders the isometric map (terrain, borders, cities,
|
||||
// units) into an externally-owned output Dpi::Bitmap.
|
||||
class IsoMap {
|
||||
public:
|
||||
IsoMap();
|
||||
~IsoMap();
|
||||
IsoMap(const IsoMap &) = delete;
|
||||
IsoMap &operator=(const IsoMap &) = delete;
|
||||
|
||||
void reset();
|
||||
void setOutput(Dpi::Bitmap *output);
|
||||
void setPaintBounds(int left, int top, int right, int bottom);
|
||||
void paint(int x, int y, int loc, int nx, int ny, int cityLoc, int cityOwner, bool useBlink = false,
|
||||
bool cityAllowClick = false);
|
||||
void paintUnit(int x, int y, const TUnitInfo &unitInfo, int status);
|
||||
void paintCity(int x, int y, const TCityInfo &cityInfo, bool accessory = true);
|
||||
void bitBltBitmapOutput(Dpi::Bitmap &src, int x, int y, int width, int height, int xSrc, int ySrc,
|
||||
Cevo::RasterOp rop = Cevo::RasterOp::Copy);
|
||||
void attackBegin(const TShowMove &showMove);
|
||||
void attackEffect(const TShowMove &showMove);
|
||||
void attackEnd();
|
||||
void reduceTerrainIconsSize();
|
||||
|
||||
TileSize tileSize() const { return m_tileSize; }
|
||||
void setTileSize(TileSize value);
|
||||
int adviceLoc() const { return m_adviceLoc; }
|
||||
void setAdviceLoc(int value) { m_adviceLoc = value; }
|
||||
|
||||
int xxt = 0; // half of tile size x/y
|
||||
int yyt = 0;
|
||||
TerrainSpriteSizeList *terrainSpriteSize = nullptr;
|
||||
GraphicSet *hGrTerrain = nullptr;
|
||||
GraphicSet *hGrCities = nullptr;
|
||||
int pDebugMap = -1; // -1 for off
|
||||
|
||||
private:
|
||||
friend class IsoMapCache;
|
||||
|
||||
void cityGrid(int xm, int ym, bool cityAllowClick);
|
||||
void clippedLine(int x, int y, int dx0, int dy0, bool mirror);
|
||||
bool isShoreTile(int loc) const;
|
||||
void makeDark(Dpi::PixelPointer &line, int length);
|
||||
void nameCity(int x, int y, int loc);
|
||||
void paintBorder(int x, int y, int loc, int tile);
|
||||
int poleTile(int loc) const;
|
||||
void shadeOutside(int x0, int y0, int width, int height, int xm, int ym);
|
||||
void showSpacePort(int x, int y, int tile, const TCityInfo &cityInfo);
|
||||
int connection4(int loc, std::uint32_t mask, std::uint32_t value) const;
|
||||
int connection8(int loc, std::uint32_t mask) const;
|
||||
int oceanConnection(int loc) const;
|
||||
void paintLandOcean(int x, int y, int loc, int nx, int ny);
|
||||
void paintShore(int x, int y, int loc);
|
||||
void paintTileExtraTerrain(int x, int y, int loc);
|
||||
void paintTileObjects(int nx, int ny, int x, int y, int loc, int cityLoc, int cityOwner, bool useBlink,
|
||||
int radius = -1, bool inside = false);
|
||||
void paintTileObjects1(int x, int y, int loc, int cityLoc, int cityOwner, bool useBlink);
|
||||
void paintTileObjects2(int x, int y, int loc, int cityLoc, int cityOwner, bool useBlink);
|
||||
void paintTileObjects3(int x, int y, int loc, int cityLoc, int cityOwner, bool useBlink);
|
||||
void paintGrid(int x, int y, int nx, int ny);
|
||||
void fillRect(int x, int y, int width, int height, QColor color);
|
||||
void textOut(int x, int y, QColor color, const QString &s);
|
||||
void sprite(GraphicSet *hGr, int xDst, int yDst, int width, int height, int xGr, int yGr);
|
||||
void terrainSprite(int xDst, int yDst, int grix, bool pureBlack = false);
|
||||
void applyTileSize(TileSize value);
|
||||
|
||||
TileSize m_tileSize = DefaultTileSize;
|
||||
Dpi::Bitmap *m_output = nullptr;
|
||||
int m_left = 0, m_top = 0, m_right = 0, m_bottom = 0;
|
||||
int m_realTop = 0, m_realBottom = 0;
|
||||
int m_attLoc = -1;
|
||||
int m_defLoc = -1;
|
||||
int m_defHealth = 0;
|
||||
int m_adviceLoc = -1;
|
||||
Dpi::Bitmap *m_landPatch = nullptr;
|
||||
Dpi::Bitmap *m_oceanPatch = nullptr;
|
||||
Dpi::Bitmap *m_borders = nullptr;
|
||||
int *m_bordersOk = nullptr;
|
||||
CitiesPictures *m_citiesPictures = nullptr;
|
||||
bool m_showLoc = false;
|
||||
bool m_showCityNames = false;
|
||||
bool m_showObjects = false;
|
||||
bool m_showBorder = false;
|
||||
bool m_showMyBorder = false;
|
||||
bool m_showGrWall = false;
|
||||
bool m_showDebug = false;
|
||||
bool m_fogOfWar = false;
|
||||
std::uint32_t *m_debugMap = nullptr; // Server(sGetDebugMap,...) result, set by paint()/read by paintTileObjects3()
|
||||
};
|
||||
|
||||
bool isJungle(int y);
|
||||
void init(InitEnemyModelEvent initEnemyModelHandler);
|
||||
|
||||
} // namespace IsoEngine
|
||||
} // namespace Cevo
|
||||
Reference in new issue
Block a user