From 6773e620cf3ba9b976eac8b8050ffc5042e3ce49 Mon Sep 17 00:00:00 2001 From: Geoffray Levasseur Date: Tue, 3 Nov 2026 16:36:46 +0100 Subject: [PATCH] added cityscreen with deps --- CMakeLists.txt | 3 + game/localplayer/CityScreen.cpp | 1454 +++++++++++++++++++++++++++++++ game/localplayer/CityScreen.h | 128 +++ game/localplayer/CityScreen.ui | 231 +++++ game/localplayer/Term.cpp | 63 ++ game/localplayer/Term.h | 52 ++ 6 files changed, 1931 insertions(+) create mode 100644 game/localplayer/CityScreen.cpp create mode 100644 game/localplayer/CityScreen.h create mode 100644 game/localplayer/CityScreen.ui diff --git a/CMakeLists.txt b/CMakeLists.txt index ed7565e..f4eb559 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -157,6 +157,9 @@ set(PROJECT_SOURCES game/localplayer/MessgEx.cpp game/localplayer/MessgEx.h game/localplayer/MessgEx.ui + game/localplayer/CityScreen.cpp + game/localplayer/CityScreen.h + game/localplayer/CityScreen.ui ${TS_FILES} ) diff --git a/game/localplayer/CityScreen.cpp b/game/localplayer/CityScreen.cpp new file mode 100644 index 0000000..8982f74 --- /dev/null +++ b/game/localplayer/CityScreen.cpp @@ -0,0 +1,1454 @@ +// 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. + +#include "CityScreen.h" +#include "ui_CityScreen.h" + +#include "Cevo/CevoScreenTools.h" +#include "Cevo/CevoTexture.h" +#include "ClientTools.h" +#include "Global.h" +#include "Help.h" +#include "Term.h" +#include "Tribes.h" + +#include +#include +#include +#include +#include + +#include +#include + +namespace Cevo { +namespace CityScreen { + +namespace { + +constexpr int wBar = 106; +constexpr int xDiv = 400; +constexpr int xService = 296; +constexpr int xmArea = 197; +constexpr int ymArea = 170; +constexpr int xView = 326; +constexpr int yView = 275; +constexpr int dxBar = wBar + 12; +constexpr int dyBar = 39; +constexpr int xHapp = 404; +constexpr int yHapp = 9; +constexpr int xFood = 404; +constexpr int yFood = yHapp + 3 * dyBar + 6; +constexpr int xProd = 404; +constexpr int yProd = yFood + 3 * dyBar + 6; +constexpr int xTrade = 404; +constexpr int yTrade = yProd + 2 * dyBar + 22; +constexpr int xPoll = xmArea - 186; +constexpr int yPoll = ymArea + 64; +constexpr int xmOpt = 40; +constexpr int ymOpt = ymArea + 96 + 34; +constexpr int xSmallMap = 271; +constexpr int ySmallMap = 339; +constexpr int wSmallMap = 98; +constexpr int hSmallMap = 74; +constexpr int xSupport = xSmallMap; +constexpr int ySupport = ySmallMap + hSmallMap + 2; +constexpr int wSupport = 64; +constexpr int hSupport = 18; +constexpr int xZoomMap = 34; +constexpr int yZoomMap = 338; +constexpr int wZoomMap = 228; +constexpr int hZoomMap = 124; +constexpr int wZoomEnvironment = 68; +constexpr int CaptionX = 42; +constexpr int CaptionY = 7; + +// ImpPosition[28..nImp-1]: position of each improvement's status dot in the +// small city-map's improvement grid (-1: not shown there). +constexpr std::array ImpPosition = { + -1, 21, 6, 1, 7, 14, 8, 18, 10, 11, 5, 13, 29, 2, 24, 25, 28, 27, + 27, 27, 26, 8, 10, 3, 17, 15, 19, 23, 22, 20, 8, -1, 4, 16, 21, -1, + -1, 9, -1, -1, -1, -1, +}; + +// Phrases/Phrases2 (StringTables.pas) aren't ported; disclosed +// plain-English placeholders for this dialog's own flat-key text. +QString phrase(const QString &key) +{ + static const QHash table = { + {QStringLiteral("BTN_OK"), QStringLiteral("OK")}, + {QStringLiteral("BTN_BUY"), QStringLiteral("Buy")}, + {QStringLiteral("SUPUNITS"), QStringLiteral("Supported units")}, + {QStringLiteral("LUX"), QStringLiteral("Luxury")}, + {QStringLiteral("UNREST"), QStringLiteral("Unrest")}, + {QStringLiteral("HAPPINESSDEMAND"), QStringLiteral("Demand")}, + {QStringLiteral("HAPPINESSPLUS"), QStringLiteral("Content")}, + {QStringLiteral("HAPPINESS"), QStringLiteral("Happiness")}, + {QStringLiteral("CONTROL"), QStringLiteral("Martial law")}, + {QStringLiteral("FAITH"), QStringLiteral("Faith")}, + {QStringLiteral("LACK"), QStringLiteral("Lack")}, + {QStringLiteral("FOOD"), QStringLiteral("Food")}, + {QStringLiteral("DEMAND"), QStringLiteral("Demand")}, + {QStringLiteral("SUPPORT"), QStringLiteral("Support")}, + {QStringLiteral("PROFIT"), QStringLiteral("Profit")}, + {QStringLiteral("SURPLUS"), QStringLiteral("Surplus")}, + {QStringLiteral("STORAGE"), QStringLiteral("Storage")}, + {QStringLiteral("MATERIAL"), QStringLiteral("Material")}, + {QStringLiteral("PROD"), QStringLiteral("Production")}, + {QStringLiteral("POLL"), QStringLiteral("Pollution")}, + {QStringLiteral("TRADE"), QStringLiteral("Trade")}, + {QStringLiteral("CORR"), QStringLiteral("Corruption")}, + {QStringLiteral("TAX"), QStringLiteral("Tax")}, + {QStringLiteral("SCIENCE"), QStringLiteral("Science")}, + {QStringLiteral("READY"), QStringLiteral("Already completed.")}, + {QStringLiteral("NOMONEY"), QStringLiteral("Not enough money (%1 needed, %2 available).")}, + {QStringLiteral("BUY"), QStringLiteral("Buy for %1 gold?")}, + {QStringLiteral("NOCHANGEINANARCHY"), QStringLiteral("Cannot change city management in anarchy.")}, + {QStringLiteral("NOSELLAGAIN"), QStringLiteral("Cannot sell %1 again this turn.")}, + {QStringLiteral("OUTOFCONTROL"), QStringLiteral("%1 is out of our control.")}, + {QStringLiteral("SELL"), QStringLiteral("Sell %1?")}, + {QStringLiteral("DISPOSE"), QStringLiteral("Dispose of %1?")}, + {QStringLiteral("SPDESTRUCTQUERY"), QStringLiteral("This will destroy the space ship parts built so far.")}, + {QStringLiteral("CITYMANAGEOFF"), QStringLiteral("Turn off city management?")}, + {QStringLiteral("DOUBLESTATEIMP"), + QStringLiteral("%1 is already being built in %2.")}, + {QStringLiteral("LOSEMAT"), QStringLiteral("This will lose %1/%2 production material.")}, + {QStringLiteral("LOSEMAT3"), QStringLiteral("This will lose production material.")}, + {QStringLiteral("EMIGRATE"), QStringLiteral("City is too small; found a new city instead?")}, + }; + const auto it = table.find(key); + return it != table.end() ? *it : key; +} + +QString impName(int iix) +{ + return QStringLiteral("Improvement #%1").arg(iix); +} + +QString modelName(int cOwner, int mix) +{ + return Tribes::tribe[static_cast(cOwner)]->modelNameAt(mix); +} + +QString governmentName(int gov) +{ + return QStringLiteral("Government #%1").arg(gov); +} + +// TODO: Sound.pas (Play()/Sounds[] item lookup) isn't ported - no-op. +void play(const QString &) {} + +} // namespace + +CityDlg::CityDlg(QWidget *parent) : BufferedDrawDlg(parent), ui(new Ui::CityDlg) +{ + ui->setupUi(this); + redTex.image(); // ensure Texture's lazily-constructed image exists + barTex.image(); + noMap = std::make_unique(); + areaMap = std::make_unique(); + areaMap->setOutput(&offscreen); + areaMap->setPaintBounds(xmArea - 192, ymArea - 96 - 32, xmArea + 192, ymArea + 96); + reset(); + prodHint = false; + restoreUnFocus = -1; + openSoundEvent = -1; + agePrepared = -2; + optimizeCixTileChange = -1; + + ui->closeBtn->setCaption(phrase(QStringLiteral("BTN_OK"))); + ui->buyBtn->setToolTip(phrase(QStringLiteral("BTN_BUY"))); + ui->supportArea->setToolTip(phrase(QStringLiteral("SUPUNITS"))); + + back.setTransparent(false); + back.setSize(width(), height()); + back.canvas().begin(); + back.canvas().fillRect(QRect(0, 0, back.width(), back.height())); + back.canvas().end(); + + tmpl.loadFromFile(getGraphicsDir() + QStringLiteral("/City") + PngExt); + cityMapTemplate.loadFromFile(getGraphicsDir() + QStringLiteral("/BigCityMap") + PngExt); + smallCityMapTemplate.loadFromFile(getGraphicsDir() + QStringLiteral("/SmallCityMap") + PngExt); + + smallCityMap.setSize(wSmallMap, hSmallMap); + smallCityMap.canvas().begin(); + smallCityMap.canvas().fillRect(QRect(0, 0, smallCityMap.width(), smallCityMap.height())); + smallCityMap.canvas().end(); + + zoomCityMap.setSize(wZoomMap, hZoomMap); + zoomCityMap.canvas().begin(); + zoomCityMap.canvas().fillRect(QRect(0, 0, zoomCityMap.width(), zoomCityMap.height())); + zoomCityMap.canvas().end(); + + ui->closeBtn->onClick = [this] { close(); }; + ui->buyBtn->onClick = [this] { buyClick(); }; + ui->nextCityBtn->onClick = [this] { changeCity(+1); }; + ui->prevCityBtn->onClick = [this] { changeCity(-1); }; + ui->pageUpBtn->onClick = [this] { + if (page > 0) { + --page; + smartUpdateContent(); + } + }; + ui->pageDownBtn->onClick = [this] { + if (page < pageCount - 1) { + ++page; + smartUpdateContent(); + } + }; + + timer1 = new QTimer(this); + timer1->setInterval(50); + connect(timer1, &QTimer::timeout, this, [this] { + if (!prodHint) + return; + blinkTime = (blinkTime + 1) % 12; + QPainter painter(this); + Dpi::Canvas canvas; + canvas.bind(&painter); + if (blinkTime == 0) { + canvas.copyRect(QRect(xView + 5, yView + 1, 64, 2), back.canvas(), QRect(xView + 5, yView + 1, 64, 2)); + canvas.copyRect(QRect(xView + 5, yView + 3, 2, 42), back.canvas(), QRect(xView + 5, yView + 3, 2, 42)); + canvas.copyRect(QRect(xView + 5 + 62, yView + 3, 2, 42), back.canvas(), + QRect(xView + 5 + 62, yView + 3, 2, 42)); + frame(canvas, xView + 9 - 1, yView + 5 - 1, xView + 9 + xSizeBig, yView + 5 + ySizeBig, + colorFromDelphi(0xB0B0B0), colorFromDelphi(0xFFFFFF)); + rframe(canvas, xView + 9 - 2, yView + 5 - 2, xView + 9 + xSizeBig + 1, yView + 5 + ySizeBig + 1, + colorFromDelphi(0xFFFFFF), colorFromDelphi(0xB0B0B0)); + canvas.brush().setStyle(Qt::SolidPattern); + canvas.brush().setColor(Qt::black); + canvas.fillRect(QRect(xView + 9, yView + 5, 72 - 8 - 9 + 1, 40)); + canvas.brush().setStyle(Qt::NoBrush); + } else if (blinkTime == 6) { + if (allowChange && (c.Status & 7) != 0) { + if (bigImp) + frameImage(canvas, *bigImp, xView + 9, yView + 5, xSizeBig, ySizeBig, + ((c.Status & 7) - 1 + 3) * xSizeBig, 0, true); + } else if ((c.Project0 & cpImp) == 0) { + if (bigImp) + canvas.copyRect(QRect(xView + 9, yView + 5, xSizeBig, ySizeBig), bigImp->canvas(), + QRect(0, 0, xSizeBig, ySizeBig)); + const Tribes::ModelPicture &mp = + Tribes::tribe[static_cast(cOwner)]->modelPictureAt(c.Project0 & cpIndex); + if (mp.hGr) + sprite(canvas, *mp.hGr, xView + 5, yView + 1, 64, 44, mp.pix % 10 * 65 + 1, + mp.pix / 10 * 49 + 1); + } else { + Term::impImage(canvas, xView + 9, yView + 5, c.Project0 & cpIndex, cGov, true); + } + } + canvas.unbind(); + }); + + onShow = [this] { + blinkTime = 5; + if (cix >= 0) { // own city + c = ClientTools::myCity[cix]; + cOwner = ClientTools::me; + cGov = ClientTools::myRO->Government; + prodHint = cGov != gAnarchy && + (happened & (chProduction | chFounded | chCaptured | Term::chAllImpsMade)) != 0; + ClientTools::server(sGetCityAreaInfo, ClientTools::me, cix, &cityAreaInfo); + ui->nextCityBtn->setVisible(windowMode() == WindowMode::Persistent); + ui->prevCityBtn->setVisible(windowMode() == WindowMode::Persistent); + } else { // enemy city + smallMapMode = SmallMapMode::Improvements; + TGetCityData getCityData{}; + ClientTools::server(sGetCity, ClientTools::me, cLoc, &getCityData); + c = getCityData.C; + cOwner = getCityData.Owner; + cGov = ClientTools::myRO->EnemyReport[cOwner]->Government; + happened = static_cast(c.Flags) & 0x7FFFFFFFu; + prodHint = false; + ClientTools::server(sGetEnemyCityAreaInfo, ClientTools::me, cLoc, &cityAreaInfo); + + if ((c.Project & cpImp) == 0) { + emix = ClientTools::myRO->nEnemyModel - 1; + while (emix > 0 && + ((*ClientTools::myRO->EnemyModel)[emix].Owner != cOwner || + (*ClientTools::myRO->EnemyModel)[emix].mix != (c.Project & cpIndex))) + --emix; + if (!Tribes::tribe[static_cast(cOwner)]->modelPictureAt(c.Project & cpIndex).hGr) + IsoEngine::invokeInitEnemyModel(emix); + } + + ui->nextCityBtn->setVisible(false); + ui->prevCityBtn->setVisible(false); + } + page = 0; + + if (c.Size < 5) + sizeClass = 0; + else if (c.Size < 9) + sizeClass = 1; + else if (c.Size < 13) + sizeClass = 2; + else + sizeClass = 3; + + isPort = false; + for (int dx = -2; dx <= 2 && !isPort; ++dx) + for (int dy = -2; dy <= 2 && !isPort; ++dy) + if (std::abs(dx) + std::abs(dy) == 2) { + const int loc1 = ClientTools::dLoc(cLoc, dx, dy); + if (loc1 >= 0 && loc1 < ClientTools::g.lx * ClientTools::g.ly && + (ClientTools::myMap[loc1] & fTerrain) < fGrass) + isPort = true; + } + + if (windowMode() == WindowMode::Modal) + centerToScreen(); + + setWindowTitle(Tribes::cityName(c.ID)); + + initSmallCityMap(); + initZoomCityMap(); + openSoundEvent = -1; + offscreenPaint(); + timer1->start(); + }; +} + +CityDlg::~CityDlg() +{ + delete ui; +} + +void CityDlg::reset() +{ + smallMapMode = SmallMapMode::Improvements; + zoomArea = 1; +} + +void CityDlg::checkAge() +{ + if (!MainTexture) + return; + if (MainTexture->age() != agePrepared) { + agePrepared = MainTexture->age(); + unshareBitmap(back); + back.canvas().begin(); + bitBltBitmap(back, 0, 0, width(), height(), MainTexture->image(), 0, 0); + back.canvas().end(); + imageOpB(back, tmpl, 0, 0, 0, 0, width(), height()); + } +} + +void CityDlg::initSmallCityMap() +{ + if (cix >= 0) + c = ClientTools::myCity[cix]; + int cli1 = cliPlains; + switch (ClientTools::myMap[cLoc] & fTerrain) { + case fPrairie: + cli1 = cliPrairie; + break; + case fHills: + cli1 = cliHills; + break; + case fTundra: + cli1 = cliTundra; + break; + default: + cli1 = cliPlains; + break; + } + if (!Colors) + return; + QImage &palette = Colors->image(); + const QColor color0 = palette.pixelColor(clkAge0 + Term::age, cliRoad); + QColor color1 = palette.pixelColor(clkCity, cli1); + QColor color2 = palette.pixelColor(clkAge0 + Term::age, cliHouse); + + smallCityMap.canvas().begin(); + smallCityMap.canvas().fillRect(QRect(0, 0, smallCityMap.width(), smallCityMap.height())); + smallCityMap.canvas().end(); + bitBltBitmap(smallCityMap, 0, 0, 83, hSmallMap, smallCityMapTemplate, 83 * sizeClass, 0); + if (isPort) { + bitBltBitmap(smallCityMap, 83, 0, 15, hSmallMap, smallCityMapTemplate, 332 + 15, 0); + imageOpCCC(smallCityMap, 0, 0, 83, hSmallMap, colorToDelphi(color0), colorToDelphi(color1), + colorToDelphi(color2)); + color2 = palette.pixelColor(clkCity, cliWater); + imageOpCCC(smallCityMap, 83, 0, 15, hSmallMap, colorToDelphi(color0), colorToDelphi(color1), + colorToDelphi(color2)); + } else { + bitBltBitmap(smallCityMap, 83, 0, 15, hSmallMap, smallCityMapTemplate, 332, 0); + imageOpCCC(smallCityMap, 0, 0, wSmallMap, hSmallMap, colorToDelphi(color0), colorToDelphi(color1), + colorToDelphi(color2)); + } + + Dpi::Canvas &canvas = smallCityMap.canvas(); + canvas.begin(); + canvas.brush().setStyle(Qt::SolidPattern); + canvas.brush().setColor(palette.pixelColor(clkAge0 + Term::age, cliImp)); + int i = 0; + for (i = 0; i <= 29; ++i) { + bool drawn = false; + for (int iix = nWonder; iix < nImp && !drawn; ++iix) + if (ImpPosition[static_cast(iix - 28)] == i && c.Built[iix] > 0) { + canvas.fillRect(QRect(5 + 16 * (i % 3) + 48 * (i / 18), 3 + 12 * (i % 18 / 3), + 8, 8)); + drawn = true; + } + } + i = 30; + for (int iix = 0; iix <= nImp && i < 36; ++iix) + if (c.Built[iix] > 0 && + (iix < nWonder || ImpPosition[static_cast(iix - 28)] < 0)) { + canvas.fillRect(QRect(5 + 16 * (i % 3) + 48 * (i / 18), 3 + 12 * (i % 18 / 3), 8, 8)); + ++i; + } + if ((c.Project & cpImp) != 0) { + const int iix = c.Project & cpIndex; + if (iix != imTrGoods) { + if (iix >= nWonder && ImpPosition[static_cast(iix - 28)] >= 0) + i = ImpPosition[static_cast(iix - 28)]; + if (i < 36) { + canvas.brush().setColor(palette.pixelColor(clkAge0 + Term::age, cliImpProject)); + canvas.fillRect(QRect(5 + 16 * (i % 3) + 48 * (i / 18), 3 + 12 * (i % 18 / 3), 8, 8)); + } + } + } + canvas.brush().setStyle(Qt::NoBrush); + canvas.end(); +} + +void CityDlg::initZoomCityMap() +{ + unshareBitmap(zoomCityMap); + zoomCityMap.canvas().begin(); + bitBltBitmap(zoomCityMap, 0, 0, wZoomMap, hZoomMap, back, xZoomMap, yZoomMap); + if (smallMapMode == SmallMapMode::Improvements) { + if (zoomArea < 3) { + imageOpB(zoomCityMap, cityMapTemplate, 0, 0, 376 * sizeClass, 112 * zoomArea, wZoomMap, hZoomMap); + } else { + imageOpB(zoomCityMap, cityMapTemplate, 0, 0, 376 * sizeClass + 216, 112 * (zoomArea - 3), + wZoomMap - wZoomEnvironment, hZoomMap); + imageOpB(zoomCityMap, cityMapTemplate, wZoomMap - wZoomEnvironment, 0, + 1504 + wZoomEnvironment * (isPort ? 1 : 0), 112 * (zoomArea - 3), wZoomEnvironment, hZoomMap); + } + } + zoomCityMap.canvas().end(); +} + +void CityDlg::fillBar(int x, int y, int pos, int growth, int max, int kind, bool indicateComplete) +{ + barTex.assign(*MainTexture); + if (kind == 3 && HGrSystem) { + const QColor c0 = HGrSystem->data.image().pixelColor(104, 36); + barTex.colorBevelLight = c0; + barTex.colorBevelShade = c0; + } + paintRelativeProgressBar(offscreen.canvas(), kind, x - 3, y, wBar - 4, pos, growth, max, indicateComplete, barTex); +} + +void CityDlg::paintResources(int x, int y, int loc, bool add4Happy) +{ + TTileInfo tileInfo{}; + if (ClientTools::server(sGetCityTileInfo, ClientTools::me, loc, &tileInfo) != eOK) { + Q_ASSERT(cix < 0); + return; + } + int total = tileInfo.Food + tileInfo.Prod + tileInfo.Trade; + const bool rare = (ClientTools::myMap[loc] & 0x06000000u) != 0; + if (rare) + ++total; + if (add4Happy) + total += 4; + int d = 1; + if (total > 1) + d = (areaMap->xxt - 11) / (total - 1); + if (d < 1) + d = 1; + if (d > 4) + d = 4; + for (int i = 0; i < total; ++i) { + int yGr = 115; + int xGr; + if (add4Happy && i >= total - 4) { + xGr = 132; + yGr = 126; + } else if (rare && i == total - 1) { + xGr = 66 + 110; + } else if (i >= tileInfo.Food + tileInfo.Prod) { + xGr = 66 + 44; + } else if (i >= tileInfo.Prod) { + xGr = 66; + } else { + xGr = 66 + 22; + } + if (HGrSystem) + sprite(offscreen.canvas(), *HGrSystem, x + areaMap->xxt - 5 + d * (2 * i + 1 - total), y + areaMap->yyt - 5, + 10, 10, xGr, yGr); + } +} + +void CityDlg::offscreenPaint() +{ + BufferedDrawDlg::offscreenPaint(); + if (!MainTexture || !bigImp || !HGrSystem || !HGrSystem2) + return; + + if (cix >= 0) + c = ClientTools::myCity[cix]; + report.HypoTiles = -1; + report.HypoTaxRate = -1; + report.HypoLuxuryRate = -1; + if (cix >= 0) + ClientTools::server(sGetCityReportNew, ClientTools::me, cix, &report); // own city + else + ClientTools::server(sGetEnemyCityReportNew, ClientTools::me, cLoc, &report); // enemy city + int trueFood = c.Food; + int trueProd = c.Prod; + int truePoll = c.Pollution; + if (Term::supervising || cix < 0) { // normalize city from after-turn state + trueFood -= report.FoodSurplus; + if (trueFood < 0) + trueFood = 0; + trueProd -= report.Production; + if (trueProd < 0) + trueProd = 0; + truePoll -= report.AddPollution; + if (truePoll < 0) + truePoll = 0; + } + const bool isCityAlive = cGov != gAnarchy && (c.Flags & chCaptured) == 0; + if (!isCityAlive) + report.Working = c.Size; + + redTex.assign(*MainTexture); + redTex.colorBevelLight = colorFromDelphi(0x0000FF); + redTex.colorBevelShade = colorFromDelphi(0x000000); + redTex.colorTextLight = colorFromDelphi(0x000000); + redTex.colorTextShade = colorFromDelphi(0x0000FF); + + Dpi::Canvas &canvas = offscreen.canvas(); + canvas.begin(); + canvas.copyRect(QRect(0, 0, 640, 480), back.canvas(), QRect(0, 0, 640, 480)); + + // Show city size and name + canvas.font().assign(UniFont[static_cast(FontType::Caption)]); + QString s = windowTitle(); + const int ellipsisWidth = canvas.textWidth(QStringLiteral("...")); + if (s.length() > 1 && canvas.textWidth(s) > ui->prevCityBtn->x() - CaptionX) { + while (s.length() > 1 && canvas.textWidth(s) > ui->prevCityBtn->x() - CaptionX - ellipsisWidth) + s.chop(1); + s += QStringLiteral("..."); + } + risedTextOut(canvas, CaptionX, CaptionY, s); + { // city size + canvas.brush().setStyle(Qt::SolidPattern); + canvas.brush().setColor(Qt::black); + canvas.fillRect(QRect(8 + 1, 7 + 1, 28, 25)); + canvas.brush().setColor(Qt::white); + canvas.fillRect(QRect(8, 7, 28, 25)); + canvas.brush().setStyle(Qt::NoBrush); + canvas.font().setColor(Qt::black); + const QString sizeText = QString::number(c.Size); + canvas.textOut(8 + 14 - canvas.textWidth(sizeText) / 2, 7, sizeText); + } + canvas.font().assign(UniFont[static_cast(FontType::Small)]); + + if (!isCityAlive) { + makeRed(offscreen, 18, 280, 298, 40); + s = cGov == gAnarchy ? governmentName(gAnarchy) : phrase(QStringLiteral("CITYEVENT_CAPTURED")); + risedTextOut(canvas, 167 - biColorTextWidth(canvas, s) / 2, ymOpt - 9, s); + } else if (allowChange) { + const int optiType = c.Status >> 4 & 0x0F; + sprite(canvas, *HGrSystem2, xmOpt - 32, ymOpt - 32, 64, 64, 1 + optiType % 3 * 64, 217 + optiType / 3 * 64); + + int messageCount = 0; + for (int i = 0; i <= 31; ++i) + if ((happened & ~static_cast(chCaptured)) & (1u << i)) + ++messageCount; + if (messageCount > 3) + messageCount = 3; + if (messageCount > 0) { + makeBlue(offscreen, 74, 280, 242, 40); + int line = 0; + auto checkMessage = [&](int flag) { + if ((happened & static_cast(flag)) == 0 || line >= messageCount) + return; + int i = 0; + std::uint32_t test = 1; + while (test < static_cast(flag)) { + ++i; + test += test; + } + if (allowChange && openSoundEvent == -1) { + const QString soundItem = Term::CityEventSoundItem[static_cast(i)]; + if (flag == chProduction || !soundItem.isEmpty()) + openSoundEvent = i; + } + const QString text = Term::cityEventName(i); + risedTextOut(canvas, xmOpt + 40, ymOpt - 1 - 8 * messageCount + 16 * line, text); + ++line; + }; + for (int i = 0; i < Term::nCityEventPriority && line < messageCount; ++i) + checkMessage(Term::CityEventPriority[static_cast(i)]); + } else { + s = QStringLiteral("City management: #%1").arg(optiType); + const int j = s.indexOf(QLatin1Char('\\')); + if (j < 0) { + loweredTextOut(canvas, -1, *MainTexture, xmOpt + 40, ymOpt - 9, s); + } else { + loweredTextOut(canvas, -1, *MainTexture, xmOpt + 40, ymOpt - 17, s.left(j)); + loweredTextOut(canvas, -1, *MainTexture, xmOpt + 40, ymOpt - 1, s.mid(j + 1)); + } + } + } + + { + IsoEngine::IsoMap &map = *areaMap; + const int rx = (192 + map.xxt * 2 - 1) / (map.xxt * 2); + const int ry = (96 + map.yyt * 2 - 1) / (map.yyt * 2); + map.paint(xmArea - map.xxt * 2 * rx, ymArea - map.yyt * 2 * ry - 3 * map.yyt, + ClientTools::dLoc(cLoc, -2 * rx + 1, -2 * ry - 1), 4 * rx - 1, 4 * ry + 1, cLoc, cOwner, false, + allowChange && isCityAlive && (c.Status & Term::csResourceWeightsMask) == 0); + canvas.copyRect(QRect(xmArea + 102, 42, 90, 33), back.canvas(), QRect(xmArea + 102, 42, 90, 33)); + + if (isCityAlive) + for (int dy = -3; dy <= 3; ++dy) + for (int dx = -3; dx <= 3; ++dx) + if (((dx + dy) & 1) == 0 && dx * dx * dy * dy < 81) { + const int loc1 = ClientTools::dLoc(cLoc, dx, dy); + const int av = cityAreaInfo.Available[(dy + 3) * 4 + ((dx + 3) >> 1)]; + if ((av == faNotAvailable || av == faTreaty || av == faInvalid) && + (loc1 < 0 || loc1 >= ClientTools::g.lx * ClientTools::g.ly || + (ClientTools::myMap[loc1] & fCity) == 0)) + sprite(canvas, *map.hGrTerrain, xmArea - map.xxt + map.xxt * dx, ymArea - map.yyt + map.yyt * dy, + map.xxt * 2, map.yyt * 2, 1 + 5 * (map.xxt * 2 + 1), + 1 + map.yyt + 15 * (map.yyt * 3 + 1)); + if ((1u << ((dy + 3) * 4 + ((dx + 3) >> 1)) & c.Tiles) != 0) + paintResources(xmArea - map.xxt + map.xxt * dx, ymArea - map.yyt + map.yyt * dy, loc1, + dx == 0 && dy == 0); + } + } + + int d = 0; + if (report.Working > 1) + d = (xService - (xmArea - 192) - 8 - 32) / (report.Working - 1); + if (d > 28) + d = 28; + for (int i = report.Working - 1; i >= 0; --i) { + const int xGr = isCityAlive ? 29 : 141; + bitBltBitmap(offscreen, xmArea - 192 + 5 + i * d, ymArea - 96 - 29, 27, 30, HGrSystem->mask, xGr, 171, + RasterOp::And); + sprite(canvas, *HGrSystem, xmArea - 192 + 4 + i * d, ymArea - 96 - 30, 27, 30, xGr, 171); + } + d = 0; + if (c.Size - report.Working > 1) + d = (xmArea + 192 - xService - 32) / (c.Size - report.Working - 1); + if (d > 28) + d = 28; + for (int i = 0; i < c.Size - report.Working; ++i) { + const int xGr = 1 + 112; + bitBltBitmap(offscreen, xmArea + 192 - 27 + 1 - i * d, 29 + 1, 27, 30, HGrSystem->mask, xGr, 171, + RasterOp::And); + sprite(canvas, *HGrSystem, xmArea + 192 - 27 - i * d, 29, 27, 30, xGr, 171); + sprite(canvas, *HGrSystem, xmArea + 192 - 27 + 4 - i * d, 29 + 32, 10, 10, 121, 126); + sprite(canvas, *HGrSystem, xmArea + 192 - 27 + 13 - i * d, 29 + 32, 10, 10, 121, 126); + } + + QString prName = + (c.Project & cpImp) == 0 ? modelName(cOwner, c.Project & cpIndex) : impName(c.Project & cpIndex); + int prCost = report.ProjectCost; + + // happiness section + if (isCityAlive) { + if (cGov == gFundamentalism) { + countBar(offscreen, xHapp, yHapp + dyBar, wBar, 17, phrase(QStringLiteral("FAITH")), + report.CollectedControl, *MainTexture); + } else { + countBar(offscreen, xHapp, yHapp + dyBar, wBar, 17, phrase(QStringLiteral("HAPPINESS")), report.Morale, + *MainTexture); + countBar(offscreen, xHapp, yHapp + 2 * dyBar, wBar, 16, phrase(QStringLiteral("CONTROL")), + report.CollectedControl, *MainTexture); + } + countBar(offscreen, xHapp, yHapp, wBar, 8, phrase(QStringLiteral("LUX")), report.Luxury, *MainTexture); + countBar(offscreen, xHapp + dxBar, yHapp, wBar, 19, phrase(QStringLiteral("UNREST")), 2 * report.Deployed, + *MainTexture); + countBar(offscreen, xHapp + dxBar, yHapp + dyBar, wBar, 17, phrase(QStringLiteral("HAPPINESSDEMAND")), + c.Size, *MainTexture); + if (report.HappinessBalance >= 0) { + countBar(offscreen, xHapp + dxBar, yHapp + 2 * dyBar, wBar, 17, phrase(QStringLiteral("HAPPINESSPLUS")), + report.HappinessBalance, *MainTexture); + } else { + makeRed(offscreen, xHapp + dxBar - 6, yHapp + 2 * dyBar, wBar + 10, 38); + countBar(offscreen, xHapp + dxBar, yHapp + 2 * dyBar, wBar, 18, phrase(QStringLiteral("LACK")), + -report.HappinessBalance, redTex); + } + } + + // food section + if (isCityAlive) { + countBar(offscreen, xFood, yFood + dyBar / 2, wBar, 0, phrase(QStringLiteral("FOOD")), report.CollectedFood, + *MainTexture); + countBar(offscreen, xFood + dxBar, yFood + dyBar, wBar, 0, phrase(QStringLiteral("DEMAND")), 2 * c.Size, + *MainTexture); + countBar(offscreen, xFood + dxBar, yFood, wBar, 0, phrase(QStringLiteral("SUPPORT")), report.FoodSupport, + *MainTexture); + if (report.FoodSurplus >= 0) { + if (cGov == gFuture || (c.Size >= NeedAqueductSize && report.FoodSurplus < 2)) + countBar(offscreen, xFood + dxBar, yFood + 2 * dyBar, wBar, 6, phrase(QStringLiteral("PROFIT")), + report.FoodSurplus, *MainTexture); + else + countBar(offscreen, xFood + dxBar, yFood + 2 * dyBar, wBar, 0, phrase(QStringLiteral("SURPLUS")), + report.FoodSurplus, *MainTexture); + } else { + makeRed(offscreen, xFood + dxBar - 6, yFood + 2 * dyBar, wBar + 10, 38); + countBar(offscreen, xFood + dxBar, yFood + 2 * dyBar, wBar, 1, phrase(QStringLiteral("LACK")), + -report.FoodSurplus, redTex); + } + } + const bool canGrow = c.Size < MaxCitySize && cGov != gFuture && report.FoodSurplus > 0 && + (c.Size < NeedAqueductSize || (c.Built[imAqueduct] == 1 && c.Size < NeedSewerSize) || + c.Built[imSewer] == 1); + fillBar(xFood + 3, yFood + 102, trueFood, ClientTools::cutCityFoodSurplus(report.FoodSurplus, isCityAlive, cGov, c.Size), + report.Storage, 1, canGrow); + loweredTextOut(canvas, -1, *MainTexture, xFood + 3 - 5, yFood + 102 - 20, + QStringLiteral("%1/%2").arg(trueFood).arg(report.Storage)); + loweredTextOut(canvas, -1, *MainTexture, xFood - 2, yFood + 66, phrase(QStringLiteral("STORAGE"))); + + // production section + if (isCityAlive) { + countBar(offscreen, xProd, yProd, wBar, 2, phrase(QStringLiteral("MATERIAL")), report.CollectedMaterial, + *MainTexture); + countBar(offscreen, xProd + dxBar, yProd, wBar, 2, phrase(QStringLiteral("SUPPORT")), report.MaterialSupport, + *MainTexture); + if (report.Production >= 0) { + if ((c.Project & (cpImp + cpIndex)) == cpImp + imTrGoods) + countBar(offscreen, xProd + dxBar, yProd + dyBar + 16, wBar, 6, phrase(QStringLiteral("PROFIT")), + report.Production, *MainTexture); + else + countBar(offscreen, xProd + dxBar, yProd + dyBar + 16, wBar, 2, phrase(QStringLiteral("PROD")), + report.Production, *MainTexture); + } else { + makeRed(offscreen, xProd + dxBar - 6, yProd + dyBar + 17, wBar + 10, 38); + countBar(offscreen, xProd + dxBar, yProd + dyBar + 16, wBar, 3, phrase(QStringLiteral("LACK")), + -report.Production, redTex); + } + } + if ((c.Project & (cpImp + cpIndex)) != cpImp + imTrGoods) { + int prod = report.Production; + if (prod < 0 || !isCityAlive) + prod = 0; + fillBar(xProd + 3, yProd + 16 + 63, trueProd, prod, prCost, 4, true); + loweredTextOut(canvas, -1, *MainTexture, xProd + 3 - 5, yProd + 16 + 43, + QStringLiteral("%1/%2").arg(trueProd).arg(prCost)); + if (biColorTextWidth(canvas, prName) > wBar + dxBar) { + do { + prName.chop(1); + } while (biColorTextWidth(canvas, prName) > wBar + dxBar); + prName += QLatin1Char('.'); + } + } + risedTextOut(canvas, xProd - 2, yProd + 36, prName); + + // pollution section + if (isCityAlive && report.AddPollution > 0) { + fillBar(xPoll + 3, yPoll + 20, truePoll, report.AddPollution, MaxPollution, 3, true); + risedTextOut(canvas, xPoll + 3 - 5, yPoll + 20 - 20, phrase(QStringLiteral("POLL"))); + } + + // trade section + if (isCityAlive && report.CollectedTrade > 0) { + countBar(offscreen, xTrade, yTrade + dyBar / 2, wBar, 4, phrase(QStringLiteral("TRADE")), + report.CollectedTrade, *MainTexture); + countBar(offscreen, xTrade + dxBar, yTrade + 2 * dyBar, wBar, 5, phrase(QStringLiteral("CORR")), + report.Corruption, *MainTexture); + countBar(offscreen, xTrade + dxBar, yTrade, wBar, 6, phrase(QStringLiteral("TAX")), report.Tax, *MainTexture); + countBar(offscreen, xTrade + dxBar, yTrade + dyBar, wBar, 12, phrase(QStringLiteral("SCIENCE")), + report.Science, *MainTexture); + } + + // small map + canvas.copyRect(QRect(xSmallMap, ySmallMap, wSmallMap, hSmallMap), smallCityMap.canvas(), + QRect(0, 0, wSmallMap, hSmallMap)); + if (smallMapMode == SmallMapMode::Improvements) + frame(canvas, xSmallMap + 48 * (zoomArea / 3), ySmallMap + 24 * (zoomArea % 3), + xSmallMap + 48 * (zoomArea / 3) + 49, ySmallMap + 24 * (zoomArea % 3) + 25, MainTexture->colorMark, + MainTexture->colorMark); + frame(canvas, xSmallMap - 1, ySmallMap - 1, xSmallMap + wSmallMap, ySmallMap + hSmallMap, + colorFromDelphi(0xB0B0B0), colorFromDelphi(0xFFFFFF)); + rframe(canvas, xSmallMap - 2, ySmallMap - 2, xSmallMap + wSmallMap + 1, ySmallMap + hSmallMap + 1, + colorFromDelphi(0xFFFFFF), colorFromDelphi(0xB0B0B0)); + + frame(canvas, xSupport - 1, ySupport - 1, xSupport + wSupport, ySupport + hSupport, colorFromDelphi(0xB0B0B0), + colorFromDelphi(0xFFFFFF)); + rframe(canvas, xSupport - 2, ySupport - 2, xSupport + wSupport + 1, ySupport + hSupport + 1, + colorFromDelphi(0xFFFFFF), colorFromDelphi(0xB0B0B0)); + int x = xSupport + wSupport / 2; + int y = ySupport + hSupport / 2; + if (smallMapMode == SmallMapMode::SupportedUnits) { + canvas.brush().setStyle(Qt::SolidPattern); + canvas.brush().setColor(MainTexture->colorMark); + canvas.fillRect(QRect(x - 27, y - 6, 54, 12)); + canvas.brush().setStyle(Qt::NoBrush); + } + sprite(canvas, *HGrSystem, x - 16, y - 5, 10, 10, 88, 115); + sprite(canvas, *HGrSystem, x - 5, y - 5, 10, 10, 66, 115); + sprite(canvas, *HGrSystem, x + 6, y - 5, 10, 10, 154, 126); + + canvas.copyRect(QRect(xZoomMap, yZoomMap, wZoomMap, hZoomMap), zoomCityMap.canvas(), + QRect(0, 0, wZoomMap, hZoomMap)); + + for (int i = 0; i <= 5; ++i) + imix[static_cast(i)] = -1; + if (smallMapMode == SmallMapMode::Improvements) { + if (zoomArea == 5) { + int cnt = 0; + for (int iix = 0; iix < nImp; ++iix) + if ((iix < nWonder || ImpPosition[static_cast(iix - 28)] < 0) && c.Built[iix] > 0) { + const int i = cnt - page * 6; + if (i >= 0 && i < 6) + imix[static_cast(i)] = iix; + ++cnt; + } + pageCount = (cnt + 5) / 6; + } else { + for (int iix = nWonder; iix < nImp; ++iix) { + const int i = ImpPosition[static_cast(iix - 28)] - 6 * zoomArea; + if (i >= 0 && i < 6 && c.Built[iix] > 0) + imix[static_cast(i)] = iix; + } + pageCount = 0; + } + int happyGain = 0; + for (int i = 0; i <= 5; ++i) + if (imix[static_cast(i)] >= 0) { + const int iix = imix[static_cast(i)]; + x = xZoomMap + 14 + 72 * (i % 3); + y = yZoomMap + 14 + 56 * (i / 3); + Term::impImage(canvas, x, y, iix, cGov, allowChange && IsoEngine::clientMode < scContact); + if (isCityAlive) { + if (iix == imColosseum) { + sprite(canvas, *HGrSystem, x + 46, y, 14, 14, 82, 100); + } else { + happyGain = 0; + if (iix <= 27 || iix == imTemple) + happyGain = 2; + else if (iix == imTheater) + happyGain = 4; + else if (iix == imCathedral) + happyGain = ClientTools::myRO->Wonder[woBach].EffectiveOwner == cOwner ? 6 : 4; + int gainStep = 10; + if (happyGain > 1) { + gainStep = 30 / (happyGain - 1); + if (gainStep > 10) + gainStep = 10; + } + for (int j = 0; j < happyGain; ++j) + sprite(canvas, *HGrSystem, x + 50, y + gainStep * j, 10, 10, 132, 126); + } + for (int j = 0; j < Imp[iix].Maint; ++j) + sprite(canvas, *HGrSystem, x - 4, y + 29 - 3 * j, 10, 10, 132, 115); + } + } + ui->imp0Area->setToolTip(imix[0] >= 0 ? impName(imix[0]) : QString()); + ui->imp1Area->setToolTip(imix[1] >= 0 ? impName(imix[1]) : QString()); + ui->imp2Area->setToolTip(imix[2] >= 0 ? impName(imix[2]) : QString()); + ui->imp3Area->setToolTip(imix[3] >= 0 ? impName(imix[3]) : QString()); + ui->imp4Area->setToolTip(imix[4] >= 0 ? impName(imix[4]) : QString()); + ui->imp5Area->setToolTip(imix[5] >= 0 ? impName(imix[5]) : QString()); + } else { // smSupportedUnits + loweredTextOut(canvas, -1, *MainTexture, xZoomMap + 6, yZoomMap + 2, phrase(QStringLiteral("SUPUNITS"))); + int freeSupp = c.Size * SupportFree[cGov] >> 1; + int cnt = 0; + for (int i = 0; i < ClientTools::myRO->nUn; ++i) + if (ClientTools::myUn[i].Loc >= 0 && ClientTools::myUn[i].Home == cix) { + const TModel &model = ClientTools::myModel[ClientTools::myUn[i].mix]; + Q_UNUSED(model); + TUnitReport unitReport{}; + ClientTools::server(sGetUnitReport, ClientTools::me, i, &unitReport); + if (cnt >= 6 * page && cnt < 6 * (page + 1)) { + imix[static_cast(cnt - 6 * page)] = i; + x = (cnt - 6 * page) % 3 * 64 + xZoomMap; + y = (cnt - 6 * page) / 3 * 52 + yZoomMap + 20; + TUnitInfo unitInfo{}; + MakeUnitInfo(ClientTools::me, ClientTools::myUn[i], unitInfo); + noMap->setOutput(&offscreen); + noMap->paintUnit(x, y, unitInfo, ClientTools::myUn[i].Status); + + for (int j = 0; j < unitReport.FoodSupport; ++j) + sprite(canvas, *HGrSystem, x + 38 + 11 * j, y + 40, 10, 10, 66, 115); + for (int j = 0; j < unitReport.ProdSupport; ++j) { + if (freeSupp > 0 && (unitReport.ReportFlags & urfAlwaysSupport) == 0) { + sprite(canvas, *HGrSystem, x + 16 - 11 * j, y + 40, 10, 10, 143, 115); + --freeSupp; + } else { + sprite(canvas, *HGrSystem, x + 16 - 11 * j, y + 40, 10, 10, 88, 115); + } + } + if (unitReport.ReportFlags & urfDeployed) + for (int j = 0; j <= 1; ++j) + sprite(canvas, *HGrSystem, x + 27 + 11 * j, y + 40, 10, 10, 154, 126); + } else { + freeSupp -= unitReport.ProdSupport; + } + ++cnt; + } + pageCount = (cnt + 5) / 6; + ui->imp0Area->setToolTip(QString()); + ui->imp1Area->setToolTip(QString()); + ui->imp2Area->setToolTip(QString()); + ui->imp3Area->setToolTip(QString()); + ui->imp4Area->setToolTip(QString()); + ui->imp5Area->setToolTip(QString()); + } + ui->pageUpBtn->setVisible(pageCount > 1); + ui->pageDownBtn->setVisible(pageCount > 1); + + { // display project now + dLine(canvas, xView + 9 + xSizeBig, xProd + 2 * wBar + 10, yProd + dyBar + 16, colorFromDelphi(0xFFFFFF), + colorFromDelphi(0xB0B0B0)); + if (prodHint) { + frame(canvas, xView + 9 - 1, yView + 5 - 1, xView + 9 + xSizeBig, yView + 5 + ySizeBig, + colorFromDelphi(0xB0B0B0), colorFromDelphi(0xFFFFFF)); + rframe(canvas, xView + 9 - 2, yView + 5 - 2, xView + 9 + xSizeBig + 1, yView + 5 + ySizeBig + 1, + colorFromDelphi(0xFFFFFF), colorFromDelphi(0xB0B0B0)); + canvas.brush().setStyle(Qt::SolidPattern); + canvas.brush().setColor(Qt::black); + canvas.fillRect(QRect(xView + 9, yView + 5, 72 - 8 - 9 + 1, 40)); + canvas.brush().setStyle(Qt::NoBrush); + } else if (allowChange && (c.Status & 7) != 0) { // city type autobuild + frameImage(canvas, *bigImp, xView + 9, yView + 5, xSizeBig, ySizeBig, ((c.Status & 7) - 1 + 3) * xSizeBig, + 0, cix >= 0 && IsoEngine::clientMode < scContact); + } else if ((c.Project & cpImp) == 0) { // project is unit + frameImage(canvas, *bigImp, xView + 9, yView + 5, xSizeBig, ySizeBig, 0, 0, + allowChange && IsoEngine::clientMode < scContact); + const Tribes::ModelPicture &mp = + Tribes::tribe[static_cast(cOwner)]->modelPictureAt(c.Project & cpIndex); + if (mp.hGr) + sprite(canvas, *mp.hGr, xView + 5, yView + 1, 64, 44, mp.pix % 10 * 65 + 1, mp.pix / 10 * 49 + 1); + } else { // project is building + const int paintiix = prodHint ? (c.Project0 & cpIndex) : (c.Project & cpIndex); + Term::impImage(canvas, xView + 9, yView + 5, paintiix, cGov, allowChange && IsoEngine::clientMode < scContact); + } + } + + if (allowChange && IsoEngine::clientMode < scContact) { + const int r = ClientTools::server(sBuyCityProject - sExecute, ClientTools::me, cix, nullptr); + ui->buyBtn->setVisible(r == eOK || r == eViolation); + } else { + ui->buyBtn->setVisible(false); + } + + canvas.end(); + markUsedOffscreen(width(), height()); +} + +void CityDlg::showNewContent(WindowMode newMode, int loc, std::uint32_t showEvent) +{ + if (ClientTools::myMap[loc] & fOwned) { // own city + cix = ClientTools::myRO->nCity - 1; + while (cix >= 0 && ClientTools::myCity[cix].Loc != loc) + --cix; + Q_ASSERT(cix >= 0); + if (optimizeCixTileChange >= 0) { + const std::uint32_t released = + optimizeTilesBeforeChange & ~ClientTools::myCity[optimizeCixTileChange].Tiles; + if (released != 0) { + ClientTools::cityOptimizer_ReleaseCityTiles(optimizeCixTileChange, static_cast(released)); + if (windowMode() != WindowMode::Modal) + Term::mainScreenUpdateViews(false); + } + } + optimizeCixTileChange = cix; + optimizeTilesBeforeChange = ClientTools::myCity[cix].Tiles; + } else { + cix = -1; + } + allowChange = !Term::supervising && cix >= 0; + cLoc = loc; + happened = showEvent; + BufferedDrawDlg::showNewContent(newMode); +} + +void CityDlg::closeEvent(QCloseEvent *event) +{ + timer1->stop(); + prodHint = false; + // MarkCityLoc := -1; -- no consumer has been ported yet, see repo memory. + if (optimizeCixTileChange >= 0) { + const std::uint32_t released = + optimizeTilesBeforeChange & ~ClientTools::myCity[optimizeCixTileChange].Tiles; + if (released != 0) { + ClientTools::cityOptimizer_ReleaseCityTiles(optimizeCixTileChange, static_cast(released)); + if (windowMode() != WindowMode::Modal) + Term::mainScreenUpdateViews(false); + } + optimizeCixTileChange = -1; + } + if (closeAction != CityCloseAction::None) + Term::mainScreenCityClosed(restoreUnFocus, closeAction == CityCloseAction::StepFocus, false); + restoreUnFocus = -1; + BufferedDrawDlg::closeEvent(event); +} + +void CityDlg::keyPressEvent(QKeyEvent *event) +{ + const int key = event->key(); + if (key == Qt::Key_P) { + if (prodHint) { + prodHint = false; + smartUpdateContent(); + } + chooseProject(); + } else if (key == Qt::Key_Return || key == Qt::Key_Enter) { + close(); + } else if (key == Qt::Key_Up && cix >= 0 && windowMode() == WindowMode::Persistent) { + changeCity(-1); + } else if (key == Qt::Key_Down && cix >= 0 && windowMode() == WindowMode::Persistent) { + changeCity(+1); + } else { + BufferedDrawDlg::keyPressEvent(event); + } +} + +void CityDlg::paintEvent(QPaintEvent *event) +{ + BufferedDrawDlg::paintEvent(event); + if (openSoundEvent >= 0) + QTimer::singleShot(0, this, [this] { onPlaySound(); }); +} + +void CityDlg::onPlaySound() +{ + if ((1 << openSoundEvent) == chProduction) { + if ((c.Project0 & cpImp) != 0) { + if ((c.Project0 & cpIndex) >= 28) { + if (Imp[c.Project0 & cpIndex].Kind == ikShipPart) + play(QStringLiteral("SHIP_BUILT")); + else + play(QStringLiteral("CITY_IMPCOMPLETE")); + } + } else { + play(QStringLiteral("CITY_UNITCOMPLETE")); + } + } else if (openSoundEvent >= 0) { + play(Term::CityEventSoundItem[static_cast(openSoundEvent)]); + } + openSoundEvent = -2; +} + +void CityDlg::changeCity(int d) +{ + int cixNew = cix; + do { + cixNew = (cixNew + ClientTools::myRO->nCity + d) % ClientTools::myRO->nCity; + } while (ClientTools::myCity[cixNew].Loc < 0 && cixNew != cix); + if (cixNew != cix) + Term::mainScreenZoomToCity(ClientTools::myCity[cixNew].Loc, false, 0); +} + +void CityDlg::changeResourceWeights(int resourceWeights) +{ + Q_ASSERT(!Term::supervising); + Q_ASSERT(cix >= 0); + ClientTools::myCity[cix].Status = + (ClientTools::myCity[cix].Status & ~Term::csResourceWeightsMask) | (resourceWeights << 4); + c.Status = ClientTools::myCity[cix].Status; + if (resourceWeights > 0) { + TCityTileAdviceData advice{}; + advice.ResourceWeights = ClientTools::OfferedResourceWeights[resourceWeights]; + ClientTools::server(sGetCityTileAdvice, ClientTools::me, cix, &advice); + if (advice.Tiles != ClientTools::myCity[cix].Tiles) + ClientTools::server(sSetCityTiles, ClientTools::me, cix, &advice.Tiles); + } +} + +void CityDlg::buyClick() +{ + if (cix < 0 || IsoEngine::clientMode >= scContact) + return; + auto *dlg = Term::mainScreenMessgExDlg(); + if (!dlg) + return; + const TCity &city = ClientTools::myCity[cix]; + int cost = report.ProjectCost; + int nextProd = report.Production; + if (nextProd < 0) + nextProd = 0; + cost = cost - city.Prod - nextProd; + if (ClientTools::myRO->Wonder[woMich].EffectiveOwner == ClientTools::me && (city.Project & cpImp) != 0) + cost *= 2; + else + cost *= 4; + if (cost <= 0 && report.HappinessBalance >= 0) { + dlg->messageText = phrase(QStringLiteral("READY")); + dlg->kind = MessageKind::Ok; + } else if (cost > ClientTools::myRO->Money) { + dlg->openSound = QStringLiteral("MSG_DEFAULT"); + dlg->messageText = phrase(QStringLiteral("NOMONEY")).arg(cost).arg(ClientTools::myRO->Money); + dlg->kind = MessageKind::Ok; + } else { + dlg->messageText = phrase(QStringLiteral("BUY")).arg(cost); + dlg->kind = MessageKind::YesNo; + } + const MessageKind queriedKind = dlg->kind; + const Dpi::ModalResult result = dlg->showModal(); + if (queriedKind == MessageKind::YesNo && result == Dpi::ModalResult::Ok) { + if (ClientTools::server(sBuyCityProject, ClientTools::me, cix, nullptr) >= rExecuted) { + play(QStringLiteral("CITY_BUYPROJECT")); + smartUpdateContent(); + if (windowMode() != WindowMode::Modal) + Term::mainScreenUpdateViews(false); + } + } +} + +void CityDlg::chooseProject() +{ + enum class ProjectKind { Select, TrGoods, Un, Caravan, Imp, Wonder, Ship, Invalid }; + auto projectType = [](int project) { + if (project & cpCompleted) + return ProjectKind::Select; + if ((project & (cpImp + cpIndex)) == cpImp + imTrGoods) + return ProjectKind::TrGoods; + if ((project & cpImp) == 0) + return ClientTools::myModel[project & cpIndex].Kind == mkCaravan ? ProjectKind::Caravan : ProjectKind::Un; + if ((project & cpIndex) >= nImp) + return ProjectKind::Invalid; + if (Imp[project & cpIndex].Kind == ikWonder) + return ProjectKind::Wonder; + if (Imp[project & cpIndex].Kind == ikShipPart) + return ProjectKind::Ship; + return ProjectKind::Imp; + }; + + Q_ASSERT(!Term::supervising); + const int result = Term::modalSelectDlgShowCityProject(cix); + if (result == -1) + return; + + if (result & Term::cpType) { + ClientTools::myCity[cix].Status = (ClientTools::myCity[cix].Status & ~7) | (1 + (result & cpIndex)); + ClientTools::autoBuild(cix, Term::myData->impOrder[result & cpIndex]); + } else { + int newProject = result; + bool queryOk = true; + if ((newProject & cpImp) != 0 && (newProject & cpIndex) >= 28 && + ClientTools::myRO->NatBuilt[newProject & cpIndex] > 0) { + if (auto *dlg = Term::mainScreenMessgExDlg()) { + int cix1 = ClientTools::myRO->nCity - 1; + while (cix1 >= 0 && ClientTools::myCity[cix1].Built[newProject & cpIndex] == 0) + --cix1; + dlg->messageText = phrase(QStringLiteral("DOUBLESTATEIMP")) + .arg(impName(newProject & cpIndex)) + .arg(Tribes::cityName(ClientTools::myCity[cix1].ID)); + dlg->openSound = QStringLiteral("MSG_DEFAULT"); + dlg->kind = MessageKind::OkCancel; + dlg->iconKind = MessgEx::MessageIconKind::Imp; + dlg->iconIndex = newProject & cpIndex; + queryOk = dlg->showModal() == Dpi::ModalResult::Ok; + } + } + if (!queryOk) + return; + + if (ClientTools::myCity[cix].Prod > 0) { + const ProjectKind pt0 = projectType(ClientTools::myCity[cix].Project0); + const ProjectKind pt1 = projectType(newProject); + if (pt0 != ProjectKind::Select && pt1 != ProjectKind::TrGoods) { + if ((newProject & (cpImp | cpIndex)) != (ClientTools::myCity[cix].Project0 & (cpImp | cpIndex))) { + if (pt1 == ProjectKind::TrGoods || pt1 == ProjectKind::Ship || + (pt1 != pt0 && pt0 != ProjectKind::Caravan)) { + queryOk = MessgEx::simpleQuery(MessageKind::OkCancel, + phrase(QStringLiteral("LOSEMAT")) + .arg(ClientTools::myCity[cix].Prod0) + .arg(ClientTools::myCity[cix].Prod0), + QStringLiteral("MSG_DEFAULT")) == Dpi::ModalResult::Ok; + } else if ((ClientTools::myCity[cix].Project & (cpImp | cpIndex)) == + (ClientTools::myCity[cix].Project0 & (cpImp | cpIndex))) { + queryOk = MessgEx::simpleQuery(MessageKind::OkCancel, phrase(QStringLiteral("LOSEMAT3")), + QStringLiteral("MSG_DEFAULT")) == Dpi::ModalResult::Ok; + } + } + } + } + if (!queryOk) + return; + + const int oldMoney = ClientTools::myRO->Money; + ClientTools::myCity[cix].Status &= ~7; + if ((newProject & cpImp) == 0 && + ((ClientTools::myCity[cix].Size < 4 && ClientTools::myModel[newProject & cpIndex].Kind == mkSettler) || + (ClientTools::myCity[cix].Size < 3 && + (ClientTools::myModel[newProject & cpIndex].Kind == mkSlaves || + (newProject & cpConscripts) != 0)))) { + if (MessgEx::simpleQuery(MessageKind::YesNo, phrase(QStringLiteral("EMIGRATE")), + QStringLiteral("MSG_DEFAULT")) != Dpi::ModalResult::Ok) + newProject |= cpDisbandCity; + } + ClientTools::server(sSetCityProject, ClientTools::me, cix, &newProject); + c.Project = ClientTools::myCity[cix].Project; + if (ClientTools::myRO->Money > oldMoney) + play(QStringLiteral("CITY_SELLIMP")); + } + ClientTools::cityOptimizer_CityChange(cix); + if (windowMode() != WindowMode::Modal) + Term::mainScreenUpdateViews(false); + initSmallCityMap(); + smartUpdateContent(); +} + +void CityDlg::mousePressEvent(QMouseEvent *event) +{ + const int x = event->position().toPoint().x(); + const int y = event->position().toPoint().y(); + const bool shift = event->modifiers() & Qt::ShiftModifier; + + if (event->button() == Qt::LeftButton && x >= xSmallMap && x < xSmallMap + wSmallMap && y >= ySmallMap && + y < ySmallMap + hSmallMap) { + smallMapMode = SmallMapMode::Improvements; + zoomArea = (y - ySmallMap) * 3 / hSmallMap + 3 * ((x - xSmallMap) * 2 / wSmallMap); + page = 0; + initZoomCityMap(); + smartUpdateContent(); + return; + } + if (event->button() == Qt::LeftButton && x >= xSupport && x < xSupport + wSupport && y >= ySupport && + y < ySupport + hSupport) { + smallMapMode = SmallMapMode::SupportedUnits; + page = 0; + initZoomCityMap(); + smartUpdateContent(); + return; + } + if (!allowChange) + return; + + if (event->button() == Qt::RightButton) { + if (x >= CaptionX && y >= CaptionY && x <= ui->prevCityBtn->x() && + y <= ui->nextCityBtn->y() + ui->nextCityBtn->height()) { + if (Term::listDlgRenameCity(cix)) { + smartUpdateContent(); + Term::mainScreenRepaintAll(); + } + } + return; + } + if (event->button() != Qt::LeftButton) + return; + + if (IsoEngine::clientMode < scContact && x >= xView && y >= yView && x < xView + 73 && y < yView + 50) { + if (cGov == gAnarchy) { + if (auto *dlg = Term::mainScreenMessgExDlg()) { + dlg->messageText = phrase(QStringLiteral("NOCHANGEINANARCHY")); + dlg->kind = MessageKind::Ok; + dlg->showModal(); + } + } else { + if (prodHint) { + prodHint = false; + smartUpdateContent(); + } + chooseProject(); + } + } else if (smallMapMode == SmallMapMode::Improvements && x >= xZoomMap && x < xZoomMap + wZoomMap && + y >= yZoomMap && y < yZoomMap + hZoomMap) { + int i = 5; + while (i >= 0 && !(x >= xZoomMap + 14 + 72 * (i % 3) && x < xZoomMap + 14 + 56 + 72 * (i % 3) && + y >= yZoomMap + 14 + 56 * (i / 3) && y < yZoomMap + 14 + 40 + 56 * (i / 3))) + --i; + if (i >= 0) { + const int iix = imix[static_cast(i)]; + if (iix >= 0) { + if (shift) { + Help::showNewContent(windowModeMakePersistent(windowMode()), Help::LinkCategory::Imp, iix); + } else if (IsoEngine::clientMode < scContact) { + if (auto *dlg = Term::mainScreenMessgExDlg()) { + dlg->iconKind = MessgEx::MessageIconKind::Imp; + dlg->iconIndex = iix; + if (iix == imPalace || Imp[iix].Kind == ikWonder) { + dlg->messageText = impName(iix); + if (iix == woOracle) + dlg->messageText += QStringLiteral("\n") + + phrase(QStringLiteral("ORACLEINCOME")) + .arg(ClientTools::myRO->OracleIncome); + dlg->kind = MessageKind::Ok; + dlg->showModal(); + } else { + const int sellResult = + ClientTools::server(sSellCityImprovement - sExecute, ClientTools::me, cix, nullptr); + if (sellResult < rExecuted) { + dlg->messageText = + phrase(sellResult == eOnlyOnce ? QStringLiteral("NOSELLAGAIN") + : QStringLiteral("OUTOFCONTROL")) + .arg(impName(iix)); + dlg->kind = MessageKind::Ok; + dlg->showModal(); + } else { + bool rebuild; + int newIix = iix; + if (ClientTools::server(sRebuildCityImprovement - sExecute, ClientTools::me, cix, + nullptr) < rExecuted) { + rebuild = false; + dlg->messageText = phrase(QStringLiteral("SELL")).arg(impName(iix)); + if (iix == imSpacePort) { + const auto &ship = ClientTools::myRO->Ship[ClientTools::me]; + if (ship.Parts[0] + ship.Parts[1] + ship.Parts[2] > 0) + dlg->messageText += + QStringLiteral(" ") + phrase(QStringLiteral("SPDESTRUCTQUERY")); + } + dlg->kind = MessageKind::YesNo; + if (dlg->showModal() != Dpi::ModalResult::Ok) + newIix = -1; + } else { + rebuild = true; + dlg->messageText = phrase(QStringLiteral("DISPOSE")).arg(impName(iix)); + if (iix == imSpacePort) { + const auto &ship = ClientTools::myRO->Ship[ClientTools::me]; + if (ship.Parts[0] + ship.Parts[1] + ship.Parts[2] > 0) + dlg->messageText += + QStringLiteral(" ") + phrase(QStringLiteral("SPDESTRUCTQUERY")); + } + dlg->kind = MessageKind::YesNo; + if (dlg->showModal() != Dpi::ModalResult::Ok) + newIix = -1; + } + if (newIix >= 0) { + if (rebuild) { + play(QStringLiteral("CITY_REBUILDIMP")); + ClientTools::server(sRebuildCityImprovement, ClientTools::me, cix, &newIix); + } else { + play(QStringLiteral("CITY_SELLIMP")); + ClientTools::server(sSellCityImprovement, ClientTools::me, cix, &newIix); + } + ClientTools::cityOptimizer_CityChange(cix); + initSmallCityMap(); + smartUpdateContent(); + if (windowMode() != WindowMode::Modal) + Term::mainScreenUpdateViews(false); + } + } + } + } + } + } + } + } else if (smallMapMode == SmallMapMode::SupportedUnits && x >= xZoomMap && x < xZoomMap + wZoomMap && + y >= yZoomMap && y < yZoomMap + hZoomMap) { + int i = 5; + while (i >= 0 && !(x >= xZoomMap + 64 * (i % 3) && x < xZoomMap + 64 + 64 * (i % 3) && + y >= yZoomMap + 20 + 48 * (i / 3) && y < yZoomMap + 20 + 52 + 48 * (i / 3))) + --i; + if (i >= 0 && imix[static_cast(i)] >= 0) { + if (!shift && cix >= 0 && IsoEngine::clientMode < scContact && windowMode() != WindowMode::Modal) { + closeAction = CityCloseAction::None; + const int uix = imix[static_cast(i)]; + close(); + Term::mainScreenCityClosed(uix, false, true); + } + } + } else if (x >= xmArea - 192 && x < xmArea + 192 && y >= ymArea - 96 && y < ymArea + 96) { + const int tileX = areaMap->xxt; + const int tileY = areaMap->yyt; + const int qx = + (4000 * tileX * tileY + (x - xmArea) * (tileY * 2) + (y - ymArea + tileY) * (tileX * 2)) / + (tileX * tileY * 4) - + 1000; + const int qy = + (4000 * tileX * tileY + (y - ymArea + tileY) * (tileX * 2) - (x - xmArea) * (tileY * 2)) / + (tileX * tileY * 4) - + 1000; + const int dx = qx - qy; + const int dy = qx + qy; + if (dx >= -3 && dx <= 3 && dy >= -3 && dy <= 3 && dx * dx * dy * dy < 81 && (dx != 0 || dy != 0)) { + if (shift) { // terrain help + const int loc1 = ClientTools::dLoc(cLoc, dx, dy); + if (loc1 >= 0 && loc1 < ClientTools::g.lx * ClientTools::g.ly) + Term::helpOnTerrain(loc1, windowModeMakePersistent(windowMode())); + } else if (IsoEngine::clientMode < scContact && cGov != gAnarchy && (c.Flags & chCaptured) == 0) { + // toggle exploitation + Q_ASSERT(!Term::supervising); + if ((c.Status & Term::csResourceWeightsMask) != 0) { + if (auto *dlg = Term::mainScreenMessgExDlg()) { + dlg->messageText = phrase(QStringLiteral("CITYMANAGEOFF")); + dlg->openSound = QStringLiteral("MSG_DEFAULT"); + dlg->kind = MessageKind::OkCancel; + dlg->iconKind = MessgEx::MessageIconKind::FullControl; + const Dpi::ModalResult result = dlg->showModal(); + if (result == Dpi::ModalResult::Ok) { + ClientTools::myCity[cix].Status &= ~Term::csResourceWeightsMask; + c.Status = ClientTools::myCity[cix].Status; + smartUpdateContent(); + } + } + return; + } + const int fix = (dy + 3) * 4 + ((dx + 3) >> 1); + std::uint32_t newTiles = ClientTools::myCity[cix].Tiles ^ (1u << fix); + if (ClientTools::server(sSetCityTiles, ClientTools::me, cix, &newTiles) >= rExecuted) { + smartUpdateContent(); + if (windowMode() != WindowMode::Modal) + Term::mainScreenUpdateViews(false); + } + } + } + } else if (IsoEngine::clientMode < scContact && cGov != gAnarchy && (c.Flags & chCaptured) == 0 && + x >= xmOpt - 32 && x < xmOpt + 32 && y >= ymOpt - 32 && y < ymOpt + 32) { + const int clickRadius = (x - xmOpt) * (x - xmOpt) + (y - ymOpt) * (y - ymOpt); + if (clickRadius <= 32 * 32) { + int i; + if (clickRadius < 16 * 16) { // inner area clicked + if ((c.Status & Term::csResourceWeightsMask) != 0) + i = (c.Status >> 4 & 0x0F) % 5 + 1; // rotate except off + else + i = 3; // rwGrowth + } else { + const int angle = static_cast( + std::atan2(static_cast(x - xmOpt), static_cast(ymOpt - y)) * 180.0 / M_PI); + if (angle >= -25 - 52 * 2 && angle <= -26 - 52) + i = 1; + else if (angle >= -25 - 52 && angle <= -26) + i = 2; + else if (angle >= -25 && angle <= 25) + i = 3; + else if (angle >= 26 && angle <= 25 + 52) + i = 4; + else if (angle >= 26 + 52 && angle <= 25 + 52 * 2) + i = 5; + else if ((angle >= 180 - 26 && angle <= 180) || (angle >= -180 && angle <= -180 + 26)) + i = 0; + else + i = -1; + } + if (i >= 0) { + changeResourceWeights(i); + smartUpdateContent(); + if (windowMode() != WindowMode::Modal) + Term::mainScreenUpdateViews(false); + } + } + } +} + +} // namespace CityScreen +} // namespace Cevo diff --git a/game/localplayer/CityScreen.h b/game/localplayer/CityScreen.h new file mode 100644 index 0000000..c073330 --- /dev/null +++ b/game/localplayer/CityScreen.h @@ -0,0 +1,128 @@ +// 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/CevoBaseWin.h" +#include "Cevo/CevoTexture.h" +#include "Cevo/Protocol.h" +#include "IsoEngine.h" + +#include + +#include +#include +#include + +QT_BEGIN_NAMESPACE +namespace Ui { +class CityDlg; +} +QT_END_NAMESPACE + +namespace Cevo { +namespace CityScreen { + +enum class CityCloseAction { None, RestoreFocus, StepFocus }; +enum class SmallMapMode { SupportedUnits, Improvements }; + +// TCityDlg equivalent: the city management screen (build-order, resource +// tiles, happiness/food/production/trade bars, small improvement map). +class CityDlg : public BufferedDrawDlg { + Q_OBJECT +public: + explicit CityDlg(QWidget *parent = nullptr); + ~CityDlg() override; + + void offscreenPaint() override; + // Equivalent of ShowNewContent(NewMode, Loc, ShowEvent) - Loc may be an + // own city (MyMap[Loc] has fOwned) or an enemy city. + void showNewContent(WindowMode newMode, int loc, std::uint32_t showEvent); + void reset(); + void checkAge(); + + int restoreUnFocus = -1; + CityCloseAction closeAction = CityCloseAction::None; + +protected: + void closeEvent(QCloseEvent *event) override; + void mousePressEvent(QMouseEvent *event) override; + void keyPressEvent(QKeyEvent *event) override; + void paintEvent(QPaintEvent *event) override; + +private: + void initSmallCityMap(); + void initZoomCityMap(); + void chooseProject(); + void changeCity(int d); + void changeResourceWeights(int resourceWeights); + void onPlaySound(); + void fillBar(int x, int y, int pos, int growth, int max, int kind, bool indicateComplete); + void paintResources(int x, int y, int loc, bool add4Happy); + void buyClick(); + + TCity c{}; + TCityReportNew report{}; + int cOwner = 0; + int cGov = 0; + int emix = -1; // enemy model index of produced unit + int cix = -1; + int cLoc = 0; + SmallMapMode smallMapMode = SmallMapMode::Improvements; + int zoomArea = 1; + int page = 0; + int pageCount = 0; + int blinkTime = 0; + int openSoundEvent = -1; + int sizeClass = 0; + int agePrepared = -2; + int optimizeCixTileChange = -1; + std::uint32_t optimizeTilesBeforeChange = 0; + std::uint32_t happened = 0; + std::array imix{}; + TCityAreaInfo cityAreaInfo{}; + std::unique_ptr areaMap; + std::unique_ptr noMap; + Dpi::Bitmap cityMapTemplate; + Dpi::Bitmap smallCityMapTemplate; + Dpi::Bitmap back; + Dpi::Bitmap smallCityMap; + Dpi::Bitmap zoomCityMap; + Dpi::Bitmap tmpl; + bool isPort = false; + bool prodHint = false; + bool allowChange = false; + Texture redTex; + Texture barTex; + QTimer *timer1; + + Ui::CityDlg *ui; +}; + +} // namespace CityScreen +} // namespace Cevo diff --git a/game/localplayer/CityScreen.ui b/game/localplayer/CityScreen.ui new file mode 100644 index 0000000..4369bac --- /dev/null +++ b/game/localplayer/CityScreen.ui @@ -0,0 +1,231 @@ + + + + CityDlg + + + + 0 + 0 + 640 + 480 + + + + C-evo + + + + + 335 + 447 + 100 + 25 + + + + + + + 270 + 6 + 12 + 12 + + + + + + + 270 + 18 + 12 + 12 + + + + + + + 245 + 390 + 12 + 12 + + + + + + + 245 + 402 + 12 + 12 + + + + + + + 495 + 317 + 12 + 12 + + + + + + + 335 + 280 + 56 + 40 + + + + + + + 11 + 271 + 57 + 57 + + + + + + + 192 + 352 + 56 + 40 + + + + + + + 120 + 408 + 56 + 40 + + + + + + + 48 + 352 + 56 + 40 + + + + + + + 48 + 408 + 56 + 40 + + + + + + + 192 + 408 + 56 + 40 + + + + + + + 120 + 352 + 56 + 40 + + + + + + + 13 + 49 + 278 + 26 + + + + + + + 303 + 30 + 82 + 41 + + + + + + + 271 + 415 + 64 + 18 + + + + + + + Cevo::ButtonA + QWidget +
Cevo/CevoButtonA.h
+
+ + Cevo::ButtonC + QWidget +
Cevo/CevoButtonC.h
+
+ + Cevo::Area + QWidget +
Cevo/CevoArea.h
+
+
+ +
diff --git a/game/localplayer/Term.cpp b/game/localplayer/Term.cpp index bc3ac49..13e9e94 100644 --- a/game/localplayer/Term.cpp +++ b/game/localplayer/Term.cpp @@ -29,6 +29,8 @@ #include "Term.h" #include "Global.h" +#include "Help.h" +#include "IsoEngine.h" #include "Tribes.h" namespace Cevo { @@ -102,9 +104,70 @@ void initMyModel(int mix, bool final) } int gameMode = 0; +int age = 0; std::array lostArmy{}; int nLostArmy = 0; std::function initAllEnemyModels = [] {}; +const std::array CityEventPriority = { + chDisorder, chImprovementLost, chUnitLost, chAllImpsMade, + chProduction, chOldWonder, chNoSettlerProd, chPopDecrease, + chProductionSabotaged, chNoGrowthWarning, chPollution, chTypeDel, + chFounded, chSiege, chAfterCapture, chPopIncrease, +}; + +const std::array CityEventSoundItem = { + QStringLiteral("CITY_DISORDER"), QStringLiteral(""), + QStringLiteral("CITY_POPPLUS"), QStringLiteral("CITY_POPMINUS"), + QStringLiteral("CITY_UNITLOST"), QStringLiteral("CITY_IMPLOST"), + QStringLiteral("CITY_SABOTAGE"), QStringLiteral("CITY_GROWTHNEEDSIMP"), + QStringLiteral("CITY_POLLUTION"), QStringLiteral("CITY_SIEGE"), + QStringLiteral("CITY_WONDEREX"), QStringLiteral("CITY_EMDELAY"), + QStringLiteral("CITY_FOUNDED"), QStringLiteral("CITY_FOUNDED"), + QStringLiteral(""), QStringLiteral("CITY_INVALIDTYPE"), +}; + +QString cityEventName(int i) +{ + // TODO: needs Phrases/Phrases2 (StringTables.pas not ported) - plain + // English fallback descriptions per event index. + static const std::array fallback = { + QStringLiteral("Civil disorder"), QStringLiteral("Population grows"), + QStringLiteral("Population declines"), QStringLiteral("Unit lost"), + QStringLiteral("Improvement lost"), QStringLiteral("Production sabotaged"), + QStringLiteral("No growth without aqueduct/sewer"), QStringLiteral("Pollution"), + QStringLiteral("City under siege"), QStringLiteral("Wonder obsolete"), + QStringLiteral("Settler production delayed"), QStringLiteral("City founded"), + QStringLiteral("City founded"), QStringLiteral(""), + QStringLiteral("All improvements built"), QStringLiteral(""), + }; + if (i == 14) // chAllImpsMade + return fallback[14]; + if (i >= 0 && i < static_cast(fallback.size())) + return fallback[static_cast(i)]; + return QString(); +} + +void helpOnTerrain(int loc, WindowMode newMode) +{ + if (ClientTools::myMap[loc] & fDeadLands) { + Help::showNewContent(newMode, Help::LinkCategory::Ter, 3 * 12); + } else if ((ClientTools::myMap[loc] & fTerrain) == fForest && + IsoEngine::isJungle(loc / ClientTools::g.lx)) { + Help::showNewContent(newMode, Help::LinkCategory::Ter, fJungle + (ClientTools::myMap[loc] >> 5 & 3) * 12); + } else { + Help::showNewContent(newMode, Help::LinkCategory::Ter, + (ClientTools::myMap[loc] & fTerrain) + (ClientTools::myMap[loc] >> 5 & 3) * 12); + } +} + +std::function mainScreenZoomToCity = [](int, bool, int) { return false; }; +std::function mainScreenCityClosed = [](int, bool, bool) {}; +std::function mainScreenUpdateViews = [](bool) {}; +std::function mainScreenRepaintAll = [] {}; +std::function modalSelectDlgShowCityProject = [](int) { return -1; }; +std::function listDlgRenameCity = [](int) { return false; }; +std::function mainScreenMessgExDlg = [] { return static_cast(nullptr); }; + } // namespace Term } // namespace Cevo diff --git a/game/localplayer/Term.h b/game/localplayer/Term.h index a83d667..68111a9 100644 --- a/game/localplayer/Term.h +++ b/game/localplayer/Term.h @@ -28,9 +28,11 @@ #pragma once +#include "Cevo/CevoBaseWin.h" #include "Cevo/CevoScreenTools.h" #include "Cevo/Protocol.h" #include "ClientTools.h" +#include "MessgEx.h" #include @@ -141,6 +143,11 @@ void initMyModel(int mix, bool final); // different Pascal unit) - don't conflate the two. extern int gameMode; +// Term.pas's `Age: Integer;` (the local player's current era - used as a +// palette-row offset into ScreenTools.pas's `Colors` matrix, e.g. +// `clkAge0 + Age`). Stays 0 until Term.pas is ported and updates it. +extern int age; + // Term.pas's layout constant (MidPanelHeight - TopBarHeight) div 2; the // two panel-size constants it derives from belong to Term's not-yet-ported // main window layout, so only the resulting fixed value is pre-seeded here. @@ -157,5 +164,50 @@ extern int nLostArmy; // draw them. Injection point (default no-op) until Term.pas is ported. extern std::function initAllEnemyModels; +// Term.pas's own "city status flags"/additional "city happened flags" +// constants (distinct from Protocol.pas's chXxx flags in ai/Protocol.h). +constexpr int csTypeMask = 0x0007; +constexpr int csToldDelay = 0x0008; +constexpr int csResourceWeightsMask = 0x00F0; +constexpr int csToldBombard = 0x0100; +constexpr int chAllImpsMade = 0x4000; +constexpr int chTypeDel = 0x8000; + +// Term.pas's CityEventPriority[]/CityEventSoundItem[]/CityEventName(): the +// city-event-message table shown by CityScreen.pas's "messages" panel. +constexpr int nCityEventPriority = 16; +extern const std::array CityEventPriority; +extern const std::array CityEventSoundItem; +// TODO: needs Phrases/Phrases2 (StringTables.pas not ported) - falls back +// to a plain English description per event index. +QString cityEventName(int i); + +// Term.pas's HelpOnTerrain(): opens the help dialog on the terrain-info +// page matching the given map tile (including the fJungle pseudo-terrain +// substitution for forest tiles growing on a jungle-climate row). +constexpr int fJungle = 8; // Help.pas's pseudo-terrain id for jungle-grown forest. +void helpOnTerrain(int loc, WindowMode newMode); + +// Term.pas's `MainScreen: TMainScreen` instance isn't ported; these mirror +// its ZoomToCity()/CityClosed()/UpdateViews()/RepaintAll() methods plus +// ModalSelectDlg/ListDlg dialog access as injection points other screens +// can call into once Term.pas/Select.pas exist. Default to safe no-ops. +extern std::function mainScreenZoomToCity; +extern std::function mainScreenCityClosed; +extern std::function mainScreenUpdateViews; +extern std::function mainScreenRepaintAll; +// Mirrors `MainScreen.ModalSelectDlg.ShowNewContent_CityProject(wmModal, +// cix)` + reading back `.Result` - returns -1 (cancelled) by default. +extern std::function modalSelectDlgShowCityProject; +// Select.pas's own `cpType = $10000` bit (set in ModalSelectDlg.Result when +// the user picked a city-type autobuild preset rather than a single +// project) - distinct from Protocol.pas's cpXxx bits in ai/Protocol.h. +constexpr int cpType = 0x10000; +// Mirrors `MainScreen.ListDlg.RenameCity(cix)` - returns false by default. +extern std::function listDlgRenameCity; +// Mirrors `MainScreen.MessgExDlg` dialog access - returns nullptr by +// default until Term.pas creates a real instance. +extern std::function mainScreenMessgExDlg; + } // namespace Term } // namespace Cevo