city processing

This commit is contained in:
Geoffray Levasseur committed 2026-10-27 11:57:29 +01:00
1 parent b9cfa2393f
commit 18bf340dee
5 files changed
+2524 -14

No files matched your search

+44 -8
View File
@@ -33,14 +33,17 @@
namespace Cevo {
namespace CityProcessing {
// Equivalent of CityProcessing.pas (~1743 lines). PORTED INCREMENTALLY: this
// is only its "Reporting" section's two simplest functions so far - every
// other function in the original (GetCityReport/GetCityReportNew and
// everything in "Internal Tile Picking"/"Turn Processing") additionally
// needs GetTileInfo/GetUnitReport/Strongest (Database.pas functions not
// ported yet) plus several more Database.pas globals (GWonder, Difficulty,
// ServerVersion, ...) and gameplay data tables (Imp[], CorrLevel[],
// SupportFree[], ...). Add more here only once those are ported too.
// Equivalent of CityProcessing.pas (~1743 lines). FULLY PORTED. Its
// private implementation-section helpers (DetermineCityProdProcessing/
// DetermineCityTradeProcessing/BoostProd/SplitTrade/GetProjectCost/
// GetSmallCityReport/NextBest/NextWorst/NextPoll, plus the ProdProcessing/
// TradeProcessing/CityReportEx support structs) live in an anonymous
// namespace in CityProcessing.cpp, matching the original's own visibility
// (not part of its interface section either).
// CityTurn() needed a large prerequisite chain in Database.pas (Map
// Processing, most of Map Revealing, Tech Related Functions, a slice of
// Diplomacy, plus the SpecialModel[]/SpecialModelPreq[] tables) - see repo
// memory for the full list of what got ported to unblock it.
// Equivalent of CityProcessing.pas's GetCityAreaInfo().
void getCityAreaInfo(int p, int loc, TCityAreaInfo &cityAreaInfo);
@@ -48,5 +51,38 @@ void getCityAreaInfo(int p, int loc, TCityAreaInfo &cityAreaInfo);
// Equivalent of CityProcessing.pas's CanCityGrow().
bool canCityGrow(int p, int cix);
// Equivalent of CityProcessing.pas's GetCityReport()/GetCityReportNew().
int getCityReport(int p, int cix, TCityReport &cityReport);
int getCityReportNew(int p, int cix, TCityReportNew &cityReportNew);
// Equivalent of CityProcessing.pas's AddBestCityTile().
bool addBestCityTile(int p, int cix);
// Equivalent of CityProcessing.pas's CityGrowth()/CityShrink()/Pollute().
void cityGrowth(int p, int cix);
void cityShrink(int p, int cix);
void pollute(int p, int cix);
// Equivalent of CityProcessing.pas's PayCityMaintenance()/CollectCityResources().
void payCityMaintenance(int p, int cix);
void collectCityResources(int p, int cix);
// Equivalent of CityProcessing.pas's CityTurn(). Return value: whether the
// city keeps existing.
bool cityTurn(int p, int cix);
// Equivalent of CityProcessing.pas's SetCityTiles().
int setCityTiles(int p, int cix, int newTiles, bool testOnly = false);
// Equivalent of CityProcessing.pas's GetCityTileAdvice(): brute-force search
// over all "take N best tiles from each resource hierarchy" combinations to
// recommend the tile selection maximizing a weighted food/prod/tax/science
// value formula (weights packed into advice.ResourceWeights on input).
void getCityTileAdvice(int p, int cix, TCityTileAdviceData &advice);
// Equivalent of CityProcessing.pas's InitGame()/ReleaseGame().
void initGame();
void releaseGame();
} // namespace CityProcessing
} // namespace Cevo
+115
View File
@@ -28,6 +28,7 @@
#pragma once
#include "Cevo/CmdList.h"
#include "Cevo/Protocol.h"
#include <array>
@@ -58,6 +59,26 @@ namespace Database {
// `TCity *city = *rw[p].City;` first if indexing repeatedly (same idiom
// ai/src/CustomAI.cpp already uses for `myCity`).
// Observe levels (Database.pas's own constants, not Protocol.pas's).
constexpr int lNoObserve = 0;
constexpr int lObserveUnhidden = 1;
constexpr int lObserveAll = 2;
constexpr int lObserveSuper = 3;
// Database.pas's own constant (not Protocol.pas's).
constexpr int CityOwnTile = 13;
constexpr int nemmax = 1024;
constexpr int necmax = 1024;
constexpr int neumax = 4096;
// Equivalent of Database.pas's TGameMode - ordinal comparisons (</>) match
// the original's enum declaration order.
enum GameMode { moLoading_Fast, moLoading, moMovie, moPlaying };
extern GameMode mode;
// Equivalent of Database.pas's `CL: TCmdList` - the live command log.
extern CmdList cl;
extern int lx;
extern int ly;
extern int mapSize; // = lx * ly
@@ -67,16 +88,44 @@ using Vicinity21Loc = std::array<int, 28>;
// player data
extern std::array<TPlayerContext, nPl> rw;
extern std::array<int, nPl> difficulty;
extern std::array<int, nPl> serverVersion;
extern std::array<std::uint32_t, nPl> resourceMask;
extern std::array<bool, nPl> processClientData;
extern std::array<int, nPl> discovered; // number of tiles discovered
extern std::array<int, nPl> lastValidStat;
extern std::array<int, nPl> nTech; // number of known techs
extern int gAlive; // players alive; bitset of 1 shl p
extern int gWatching;
extern int gAI;
extern int gTurn; // current turn
extern int gTestFlags;
extern std::array<TWonderInfo, nWonder> gWonder;
extern std::array<int, nPl> grWallContinent; // continent id the Great Wall was built on, -1 if none
extern std::array<TShipInfo, nPl> gShip;
// [p1,p2,mix] -> index of p2's model mix in p1's enemy model list
extern std::array<std::array<std::array<std::int16_t, nMmax>, nPl>, nPl> rwemix;
// [p1,p2,mix] -> number of p2's units with model mix that p1 has destroyed
extern std::array<std::array<std::array<std::int16_t, nMmax>, nPl>, nPl> destroyed;
// map data
extern std::array<std::uint32_t, lxmax * lymax> realMap;
extern std::array<int, lxmax * lymax> continent; // continent id for each tile
extern std::array<std::int8_t, lxmax * lymax> occupant; // occupying player for each tile
extern std::array<std::int8_t, lxmax * lymax> zocMap;
extern std::array<std::int32_t, lxmax * lymax> usedByCity; // -1 if not exploited
extern std::array<std::uint32_t, lxmax * lymax> observeLevel; // observe level of player p in bits 2*p, 2*p+1
// Equivalent of Database.pas's MaskD().
void maskD(std::uint32_t *x, int count, std::uint32_t mask);
// Equivalent of Database.pas's IntServer(): dispatches internal server
// notifications (sIntXxx command codes) and records them to the command
// log. Declared here (used by several Map Revealing functions below) but
// only implemented once its own dependency chain (IntroduceEnemy,
// CancelTreaty, ...) exists - see Database.cpp for current coverage.
void intServer(int command, int player, int subject, const void *data);
// --- Location Navigation ---
// Relative location, dx in hor and dy in ver direction from loc. Returns -1
@@ -92,5 +141,71 @@ void v21ToLoc(int loc0, Vicinity21Loc &vicinityLoc);
void calculatePrimitive();
bool mapGeneratorAvailable();
// --- Tech Related Functions ---
int techBaseCost(int nTech, int diff);
// Sets a model's Flags (ZOC/civil/double-support) from its other fields.
void setModelFlags(TModel &m);
// Grants player p any SpecialModel[] not yet available that pre unlocks.
void checkSpecialModels(int p, int pre);
// GWonder[wonder].EffectiveOwner must already be set before calling this.
void checkExpiration(int wonder);
// --- Map Revealing ---
// cix>=0: known city index of player p (internal use only).
// cix=-1: search city, player unknown, only if permission for p.
// cix=-2: don't search city, don't calculate city benefits, just government.
int getTileInfo(int p, int cix, int loc, TTileInfo &info);
// Finds the strongest defender at loc.
void strongest(int loc, int &uix, int &strength, int &bonus, int &cnt);
int unitSpeed(int p, int mix, int health);
void getUnitReport(int p, int uix, TUnitReport &unitReport);
void tellAboutModel(int p, int taOwner, int tamix);
int emixSafe(int p, int taOwner, int tamix);
int getUnitStack(int p, int loc);
void makeCityInfo(int p, int cix, TCityInfo &ci);
// euix = -2: full discover. euix = -1: unit and city only, append to
// EnemyUn. euix >= 0: unit and city only, replace EnemyUn[euix].
bool discoverTile(int loc, int p, int pTell, int level, bool enableContact, int euix = -2);
bool discover9(int loc, int p, int level, bool tellAllied, bool enableContact);
bool discover21(int loc, int p, int adjacentLevel, bool tellAllied, bool enableContact);
// Player p discovers the complete playground (for the supervisor).
void discoverAll(int p, int level);
// Discovers unit and city view areas.
void discoverViewAreas(int p);
// Updates maps and enemy units of all players after a unit change.
void updateUnitMap(int loc, bool cityChange = false);
// Sets p to the supposed owner before the call.
void searchCity(int loc, int &p, int &cix);
// --- Map Processing ---
void createUnit(int p, int mix);
void placeUnit(int p, int uix);
void freeUnit(int p, int uix);
// loc or master should be set after call. Enemy >=0 counts the unit as lost
// to that player (use only from inside sMoveUnit if attack).
void removeUnit(int p, int uix, int enemy = -1);
void removeUnitUpdateMap(int p, int uix);
// --- Diplomacy ---
void introduceEnemy(int p1, int p2);
int techCost(int p);
void giveCivilReport(int p, int pAbout);
void giveMilReport(int p, int pAbout);
} // namespace Database
} // namespace Cevo