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

+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