// 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/CevoScreenTools.h" #include "Cevo/Protocol.h" #include "ClientTools.h" #include "MessgEx.h" #include "NatStat.h" #include "Select.h" #include "Tribes.h" #include #include #include #include #include #include #include namespace Cevo { namespace Term { // PORT STATUS: Term.pas itself (~7500 lines, the main game screen) is NOT // ported - it needs ~14 other LocalPlayer dialogs that don't exist yet // (see /memories/repo/cevo-evo-game.md for the port order). This file only // pre-seeds the handful of Term.pas globals/constants/helpers that the // LEAF dialogs (CityType, ...) need from it; real Term.pas content gets // added into this same namespace/file set once its turn comes. constexpr int nCityType = 4; // Term.pas's own pseudo-advance ids (adjacent to Protocol.pas's adMilitary // = 0x800) used by the tech-selection dialog (Select.pas). constexpr int adNone = 0x801; constexpr int adFar = 0x802; constexpr int adNexus = 0x803; // icons.bmp properties: lines of system icons before improvements start. constexpr int xSizeSmall = 36; constexpr int ySizeSmall = 20; constexpr int SystemIconLines = 2; // TModel.Status bit flags. constexpr int msObsolete = 0x1; constexpr int msAllowConscripts = 0x2; // Client exclusive commands (relayed by the server to the other clients). constexpr int cSetTribe = 0x9000; constexpr int cSetNewModelPicture = 0x9100; constexpr int cSetModelName = 0x9110; constexpr int cSetModelPicture = 0x9120; constexpr int cSetSlaveIndex = 0x9131; constexpr int cSetCityName = 0x9200; // TUn.Status bit flags not already in IsoEngine.h. constexpr int usWaiting = 0x02; constexpr int usToldNoReturn = 0x100; constexpr int usPersistent = 0x01 | 0x04 | 0x08 | 0x10 | static_cast(0xFFFF0000u); // Index of the slaves/no-slaves pictures in StdUnits. constexpr int pixSlaves = 0; constexpr int pixNoSlaves = 1; // Term.pas's `MainScreen.mNames.Checked` (menu checkbox: show real model // names vs. generic "Model #n" names) - defaults to the more useful true. extern bool mainScreenNamesChecked; // Term.pas's `Buffer: TBitmap` - a shared general-purpose scratch bitmap; // callers must setSize() it themselves before use (no central owner // resizes it yet since Term.pas's own usage isn't ported). extern Dpi::Bitmap buffer; // Term.pas's `TPersistentData` (per-player persisted client-side settings, // e.g. city build-order preferences) - only the fields some leaf dialog // needs are ported so far; add more as needed. struct PersistentData { int farTech = 0; int toldAge = 0; int toldModels = 0; int toldAlive = 0; int toldContact = 0; int toldOwnCredibility = 0; int coldWarStart = 0; int peaceEvaHappened = 0; ClientTools::TEnhancementJobs enhancementJobs{}; std::array impOrder{}; std::array toldWonders{}; std::array toldTech{}; }; // Term.pas's `MyData: ^TPersistentData;` - null until a real game/turn is // active (set by Term.pas's InitTurn(), not yet ported). extern PersistentData *myData; // Term.pas's `SmallImp: TBitmap;` (icons.bmp sprite sheet, small size) - // populated by Term.pas's asset loading, not yet ported. extern Dpi::Bitmap *smallImp; // Equivalent of Term.pas's ImpImage(): draws an improvement/wonder icon // from bigImp, substituting the age-specific palace graphic for imPalace. void impImage(Dpi::Canvas &canvas, int x, int y, int iix, int government = -1, bool isControl = false); // Term.pas's `OptionChecked: TSaveOptions;` (user-configurable UI options). extern ClientTools::SaveOptions optionChecked; // Term.pas's `Supervising: Boolean;` (true when controlling player 0 is // just observing rather than playing a nation). extern bool supervising; // Term.pas's `TDipMem` (per-nation negotiation session memory). struct DipMemEntry { int pContact = -1; // Nego.pas's own negotiation-session bookkeeping (added for Nego.pas). int formerTreaty = trNone; int sentCommand = 0; TOffer sentOffer{}; // TPriceSet = set of $00..$FF (price-category bytes, i.e. opXxx >> 24). std::bitset<256> deliveredPrices; std::bitset<256> receivedPrices; }; extern std::array dipMem; // Term.pas's `ReceivedOffer: TOffer;` (the opponent's current negotiation // offer, as last received from the server). extern TOffer receivedOffer; // Term.pas's RoughCredibility(): buckets a 0..100 credibility value into a // 4-level rating (0..3) for display. int roughCredibility(int credibility); // ScreenTools.pas's TurnToString(): turnToYear() formatted as " BC"/"AD // " (or the plain turn number if `generateNames` is off). Lives here // rather than in the widget-layer CevoScreenTools.h since it needs // Global::generateNames (a game-layer symbol widget/ mustn't depend on). QString turnToString(int turn); // Term.pas's `MainScreen: TMainScreen` instance isn't ported; these mirror // its DipCall()/ContactRefused() methods as injection points other leaf // dialogs can call into once Term.pas/Nego.pas exist. Default to safe // no-ops (DipCall "not executed", ContactRefused "not refused") so callers // relying on them just see "nothing happened" rather than crashing. extern std::function mainScreenDipCall; extern std::function mainScreenContactRefused; // Term.pas's ChooseModelPicture()/InitMyModel(): assigns a visual "picture" // to a developed/enemy unit model. Simplified - always takes the // "non-original tribe" path (dispatches straight through // Tribe::setModelPicture()) since the network cSet*ModelPicture command // plumbing isn't ported, and the mkSlaves (Code==74) special case isn't // handled either (narrow edge case, not reached by anything ported so far). void chooseModelPicture(int p, int mix, int code, int hash, int turn, bool forceNew, bool final); void initMyModel(int mix, bool final); // Term.pas's `GameMode: Integer;` (cNewGame/cLoadGame/cMovie/... - which // top-level mode the client is running in). NOT the same thing as // Database::GameMode (a different, server-side enum of the same name in a // 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 `CityRepMask: Cardinal;` (user-configurable "which city // events to report" bitmask, persisted via QSettings in the original - // not wired to settings here yet, just the documented default value). extern std::uint32_t cityRepMask; // Term.pas's `AdvIcon: array[0..nAdv-1] of Integer;` (per-advance icon // index into SmallImp/HGrSystem, computed by a Term.pas init routine not // yet ported) - stays -1 ("no icon assigned yet") for every entry until // Term.pas is ported; harmless if read before that (just selects an // arbitrary/wrong icon, not a crash - same "pre-seed stays default" policy // as lostArmy[]/nLostArmy). extern std::array advIcon; // Term.pas's layout constants (main window layout, now that TMainScreen // itself is being ported for real). constexpr int TopBarHeight = 41; constexpr int PanelHeight = 168; constexpr int MidPanelHeight = 120; // (MidPanelHeight - TopBarHeight) div 2 = (120 - 41) div 2 = 39. constexpr int MapCenterUp = (MidPanelHeight - TopBarHeight) / 2; constexpr int Overlap = PanelHeight - MidPanelHeight; constexpr int LeftPanelWidth = 70; constexpr int LxmaxXxx = 130; constexpr int YTroop = PanelHeight - 83; constexpr int XPalace = 66; constexpr int YPalace = 24; constexpr int XUnitText = 80; constexpr int BlinkOnTime = 12; constexpr int BlinkOffTime = 6; constexpr int EmptySpaceColor = 0x101010; // ProcessRect options. constexpr int prPaint = 0x0001; constexpr int prAutoBounds = 0x0002; constexpr int prInvalidate = 0x0004; // MoveUnit options. constexpr int muAutoNoWait = 0x0001; constexpr int muAutoNext = 0x0002; constexpr int muNoSuicideCheck = 0x0004; enum class PaintLocTempStyle { Normal, Blink }; // Terrain brushes of the map editor. constexpr std::array BrushTypes = { fPrefStartPos, fStartPos, fShore, fGrass, fTundra, fPrairie, fDesert, fSwamp, fForest, fHills, fMountains, fArctic, fDeadLands, fDeadLands | fCobalt, fDeadLands | fUranium, fDeadLands | fMercury, fRiver, fRoad, fRR, fCanal, tiIrrigation, tiFarm, tiMine, fPoll, tiFort, tiBase }; // FocusOnLoc options. constexpr int flRepaintPanel = 0x0001; constexpr int flImmUpdate = 0x0002; // Term.pas's `MapOptionChecked`: map display options chosen by the user // (default: city names). extern ClientTools::MapOptions mapOptionChecked; // Term.pas's `UnStartLoc`: location where the focused unit started its turn. extern int unStartLoc; // Sets Term::clientMode and the copy IsoEngine reads. void setClientMode(int value); // Term.pas's `LostArmy`/`nLostArmy` (model-indexed lost-unit counts shown // by MessgEx.pas's "army destroyed" report) - stay all-zero until Term.pas // itself is ported and populates them for real. extern std::array lostArmy; extern int nLostArmy; // Term.pas's InitAllEnemyModels()/InitEnemyModel(): resolves a picture for // every known enemy unit model so MessgEx.pas's "enemy army" report can // draw them. bool initEnemyModel(int emix); void 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; // Term.pas's CityEventName(): the description of city event index i. 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; // Mirrors `MainScreen.ModalSelectDlg`/`MainScreen.NatStatDlg` dialog // access (the general, non-city-project form - see also // modalSelectDlgShowCityProject above for the city-project-only variant). extern std::function mainScreenModalSelectDlg; extern std::function mainScreenNatStatDlg; // Mirrors `MainScreen.OfferCall(var Offer: TOffer): Integer` - returns // eInvalid by default. extern std::function mainScreenOfferCall; // Term.pas's TTribeInfo/TCityNameInfo/TModelNameInfo: payloads of the // client exclusive commands. pack() yields the wire layout (int32 + Pascal // ShortString: length byte then bytes), commandDataSize() is the size to // pass to commandWithData(). struct TribeInfo { int trix = 0; QString fileName; QByteArray pack() const; std::uint8_t commandDataSize() const; }; struct CityNameInfo { int id = 0; QString newName; QByteArray pack() const; std::uint8_t commandDataSize() const; }; struct ModelNameInfo { int mix = 0; QString newName; QByteArray pack() const; std::uint8_t commandDataSize() const; }; // Wire layout of Tribes::ModelPictureInfo (4 int32 + ShortString). QByteArray packModelPictureInfo(const Tribes::ModelPictureInfo &info); Tribes::ModelPictureInfo unpackModelPictureInfo(const void *data); // Inverses of TribeInfo/CityNameInfo/ModelNameInfo::pack(). TribeInfo unpackTribeInfo(const void *data); CityNameInfo unpackCityNameInfo(const void *data); ModelNameInfo unpackModelNameInfo(const void *data); // Term.pas's `ClientMode`: the command (cTurn, cResume, scContact, ...) the // client is currently serving, -1 when idle. extern int clientMode; // Term.pas's `TribeOriginal`: whether tribe p comes from the original // (non-network-relayed) game rather than being created for a movie/viewer. extern std::array tribeOriginal; // Term.pas's `ToldSlavery` (1 once slavery has been announced). extern int toldSlavery; QString attackSound(int code); int alignUp(int value, int alignment); // Term.pas's InitSmallImp(): builds smallImp by scaling down bigImp. void initSmallImp(); // Clears the "low fuel warning" flag of an aircraft that made it back. void checkToldNoReturn(int uix); // Loads the tribe file and registers the tribe's standard model pictures. bool createTribe(int p, QString fileName, bool original); void tellNewContacts(); void tellNewModels(); // Term.pas's InitModule() `AdvIcon` table setup (the icon displayed with each advance). void initAdvIcons(); // Term.pas's `UnusedTribeFiles` (name + colour of every tribe file not yet in play). struct UnusedTribe { QString fileName; QColor color; }; extern std::vector unusedTribeFiles; // Term.pas's `TribeNames` (display name + colour of the tribes a player can // pick from, filled right before the tribe selection list is shown). struct TribeNameEntry { QString name; QColor color; }; extern std::vector tribeNames; // Term.pas's `TaxSum`/`ScienceSum: Integer;` (aggregate tax/science totals // across all owned cities, refreshed by MainScreen::updateViews()). extern int taxSum; extern int scienceSum; // Term.pas's `TMainScreen` - the main game window; see // Term.MainScreen.h/.cpp for the real class (kept out of this // widely-included pre-seed header to avoid pulling in every dialog // header transitively - consumers that only need the global instance // pointer can use this forward declaration). class MainScreen; extern MainScreen *mainScreen; } // namespace Term } // namespace Cevo