// 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 #include #include #include #include #include #include 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; 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 }; 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; // 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(age - 2)][static_cast(size)]; } private: std::array, 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; }; // 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