From 192898fb62433235477bf34a52a389974b40c2a4 Mon Sep 17 00:00:00 2001 From: Geoffray Levasseur Date: Tue, 27 Oct 2026 16:22:49 +0100 Subject: [PATCH] prepare gameserver implementation --- game/include/Cevo/Database.h | 48 ++++ game/src/Database.cpp | 531 ++++++++++++++++++++++++++++++++++- 2 files changed, 576 insertions(+), 3 deletions(-) diff --git a/game/include/Cevo/Database.h b/game/include/Cevo/Database.h index 694f7e7..619aa59 100644 --- a/game/include/Cevo/Database.h +++ b/game/include/Cevo/Database.h @@ -89,6 +89,7 @@ extern int lx; extern int ly; extern int mapSize; // = lx * ly extern int rnd; // world map randseed +extern int landMass; // 0 = predefined map, >0 = random map generation target extern std::int32_t delphiRandSeed; int delphiRandom(int max); // Delphi/Borland-compatible LCG, result in [0, max) @@ -105,6 +106,7 @@ extern std::array discovered; // number of tiles discovered extern std::array researched; extern std::array lastValidStat; extern std::array nTech; // number of known techs +extern std::array territoryCount; // index nPl means "no owner" extern int gAlive; // players alive; bitset of 1 shl p extern int gWatching; extern int gAI; @@ -173,6 +175,16 @@ void checkSpecialModels(int p, int pre); // GWonder[wonder].EffectiveOwner must already be set before calling this. void checkExpiration(int wonder); +// Marks an advance as seen (known exists, not yet researched) - used by +// the Great Library wonder effect. +void seeTech(int p, int ad); +// Applies the full effects of player p completing research of advance ad +// (tech counters, key-tech disclosure, special models, wonder expiration). +void discoverTech(int p, int ad); +// Promotes RW[p].DevModel (set by a completed sResetModel) into the +// player's real model list. +void enableDevModel(int p); + // --- Map Revealing --- // cix>=0: known city index of player p (internal use only). @@ -221,6 +233,10 @@ void removeUnitUpdateMap(int p, int uix); void removeDomainUnits(int d, int p, int loc); void foundCity(int p, int foundLoc); +// Removes dead (Loc < 0) entries from a player's Un/City/EnemyCity lists, +// fixing up cross-references (Un::Master/Home) to the indices that move. +void compactLists(int p); + // Database.pas's own formula function (originally in Protocol.pas), used // only by actualSpecialTile() to recompute hidden special-resource bits // after a terrain change (ClearTerrain/AfforestTerrain/TransTerrain jobs). @@ -230,6 +246,16 @@ std::uint32_t actualSpecialTile(int loc); // Applies a completed terrain improvement job's effect to the map. void completeJob(int p, int loc, int job); +// --- Map Editor --- + +// Converts a tile to ocean if it has no grass-or-better neighbor, to shore +// otherwise; returns true if the terrain type actually changed. +bool checkShore(int loc); +// Applies map-editor sanity rules (dead lands/canal/irrigation/mine +// clearing, automatic special resources, automatic shore tiles) and writes +// the result to realMap. +void editTile(int loc, std::uint32_t newTile); + // --- Territory Calculation --- // OriginLoc: only changes in CountryRadius around this location possible, @@ -242,12 +268,27 @@ void logCheckBorders(int p, int cix, int playerLosingCity = -1); // recalculate fPeace flags for the whole map void recalcPeaceMap(int p); +// recalculate fInEnemyZoC flags for the whole map +void recalcMapZoC(int p); + // --- Diplomacy --- void introduceEnemy(int p1, int p2); int techCost(int p); void giveCivilReport(int p, int pAbout); void giveMilReport(int p, int pAbout); +// Copies pAbout's civil/military report as known by pSender into pTarget's +// enemy-report of pAbout, if newer. Returns true if anything changed. +bool copyCivilReport(int pSender, int pTarget, int pAbout); +bool copyMilReport(int pSender, int pTarget, int pAbout); +// Grants pTarget a copy of pSender's model mix, unless an equivalent model +// (per IsSameModel) is already known. +void copyModel(int pSender, int pTarget, int mix); +// Copies every tile pSender has observed more recently than pTarget has. +void copyMap(int pSender, int pTarget); +// Executes a spy unit's mission against pCity's city cix; returns a +// mission-specific result bitset (only meaningful for smStealForeignReports). +std::uint32_t doSpyMission(int p, int pCity, int cix, int mission); void showPrice(int pSender, int pTarget, std::uint32_t price); bool payPrice(int pSender, int pTarget, std::uint32_t price, bool execute); // Side effect: sets peaceEnded to the bitset of players with whom a peace @@ -272,5 +313,12 @@ void findContinents(); void predefinedStartPositions(int human); void releaseGame(); +// --- City --- + +// Removes a city (SaveUnits: true transfers supported units to the +// nearest remaining city instead of destroying them). +void destroyCity(int p, int cix, bool saveUnits); +void changeCityOwner(int pOld, int cixOld, int pNew); + } // namespace Database } // namespace Cevo diff --git a/game/src/Database.cpp b/game/src/Database.cpp index fd484e7..54e425c 100644 --- a/game/src/Database.cpp +++ b/game/src/Database.cpp @@ -42,6 +42,7 @@ int lx = 0; int ly = 0; int mapSize = 0; int rnd = 0; +int landMass = 0; std::int32_t delphiRandSeed = 0; GameMode mode = moLoading_Fast; CmdList cl; @@ -80,6 +81,10 @@ std::array zocMap{}; std::array usedByCity{}; std::array observeLevel{}; +// Equivalent of Database.pas's `TerritoryCount: array[0..nPl]` - public since +// GameServer::generateStat() needs read access (index nPl means "no owner"). +std::array territoryCount{}; + namespace { // Equivalent of Database.pas's private (implementation-section) `Primitive` // global - not exposed in the header, matching the original's own @@ -90,9 +95,6 @@ int primitive = 0; // (number of units built, used to assign unique per-player unit IDs). std::array unBuilt{}; -// Equivalent of Database.pas's private `TerritoryCount: array[0..nPl]`. -std::array territoryCount{}; - // Equivalent of Database.pas's private `BorderChanges` (sIntExpandTerritory // and $F == 8 packed Cardinal words, 4 bits per tile in the CountryRadius // area around a city). @@ -554,6 +556,79 @@ void checkExpiration(int wonder) } } +void seeTech(int p, int ad) +{ + rw[p].Tech[ad] = tsSeen; + ++researched[p]; +} + +namespace { +void tellAboutKeyTech(int p, int source, int ad) +{ + for (int i = 1; i <= 3; ++i) + if (ad == AgePreq[i]) + for (int p1 = 0; p1 < nPl; ++p1) + if (p1 != p && ((gAlive | gWatching) & (1 << p1))) + rw[p1].EnemyReport[p]->Tech[ad] = static_cast(source); +} +} // namespace + +void discoverTech(int p, int ad) +{ + TPlayerContext &player = rw[p]; + if (IsFutureTech(ad)) { + if (player.Tech[ad] < tsApplicable) + player.Tech[ad] = 1; + else + ++player.Tech[ad]; + if (ad != futResearchTechnology) + nTech[p] += 2; + researched[p] += 8; + return; + } + + if (player.Tech[ad] == tsSeen) { + ++nTech[p]; + ++researched[p]; + } else { + nTech[p] += 2; + researched[p] += 2; + } + player.Tech[ad] = tsResearched; + tellAboutKeyTech(p, tsResearched, ad); + checkSpecialModels(p, ad); + if (ad == adScience) + resourceMask[p] |= fSpecial2; + if (ad == adMassProduction) + resourceMask[p] |= fModern; + + for (int i = 0; i < nWonder; ++i) { // check whether wonders expired + if (gWonder[i].EffectiveOwner != gWonder[woEiffel].EffectiveOwner && Imp[i].Expiration == ad) { + gWonder[i].EffectiveOwner = -1; + if (i == woPyramids) + freeSlaves(); + } + } +} + +void enableDevModel(int p) +{ + TPlayerContext &player = rw[p]; + if (player.nModel >= nMmax) + return; + TModel *model = *player.Model; + model[player.nModel] = player.DevModel; + TModel &newModel = model[player.nModel]; + newModel.Status = 0; + newModel.SavedStatus = 0; + newModel.IntroTurn = static_cast(gTurn); + newModel.Built = 0; + newModel.Lost = 0; + newModel.ID = static_cast((p << 12) + player.nModel); + ++player.nModel; + ++researched[p]; +} + void createUnit(int p, int mix) { TPlayerContext &player = rw[p]; @@ -674,6 +749,54 @@ void removeDomainUnits(int d, int p, int loc) removeUnit(p, uix); } +void compactLists(int p) +{ + TPlayerContext &player = rw[p]; + TUn *un = *player.Un; + TCity *city = *player.City; + TCityInfo *enemyCity = *player.EnemyCity; + + // compact unit list + int uix = 0; + while (uix < player.nUn) { + if (un[uix].Loc < 0) { + --player.nUn; + un[uix] = un[player.nUn]; // replace removed unit by last + if (un[uix].TroopLoad > 0 || un[uix].AirLoad > 0) + for (int uix1 = 0; uix1 < player.nUn; ++uix1) + if (un[uix1].Master == player.nUn) // index of last unit changes + un[uix1].Master = uix; + } else { + ++uix; + } + } + + // compact city list + int cix = 0; + while (cix < player.nCity) { + if (city[cix].Loc < 0) { + --player.nCity; + city[cix] = city[player.nCity]; // replace city by last + for (int uix1 = 0; uix1 < player.nUn; ++uix1) + if (un[uix1].Home == player.nCity) // index of last city changes + un[uix1].Home = cix; + } else { + ++cix; + } + } + + // compact enemy city list + cix = 0; + while (cix < player.nEnemyCity) { + if (enemyCity[cix].Loc < 0) { + --player.nEnemyCity; + enemyCity[cix] = enemyCity[player.nEnemyCity]; // replace city by last + } else { + ++cix; + } + } +} + int specialTile(int loc, int terrType, int lx) { if (terrType == fOcean) @@ -833,6 +956,72 @@ void completeJob(int p, int loc, int job) } } +bool checkShore(int loc) +{ + const std::uint32_t oldTile = realMap[loc]; + if ((oldTile & fTerrain) >= static_cast(fGrass)) + return false; + realMap[loc] = (realMap[loc] & ~static_cast(fTerrain)) | static_cast(fOcean); + Vicinity21Loc radius; + v21ToLoc(loc, radius); + for (int v21 = 1; v21 <= 26; ++v21) { + const int loc1 = radius[static_cast(v21)]; + if (loc1 >= 0 && loc1 < mapSize && (realMap[loc1] & fTerrain) >= static_cast(fGrass) && + (realMap[loc1] & fTerrain) != static_cast(fArctic)) + realMap[loc] = (realMap[loc] & ~static_cast(fTerrain)) | static_cast(fShore); + } + return ((realMap[loc] ^ oldTile) & fTerrain) != 0; +} + +void editTile(int loc, std::uint32_t newTile) +{ + if (newTile & fDeadLands) + newTile = (newTile & (fDeadLands | fModern | fRiver)) | fDesert; + switch (newTile & fTerrain) { + case fOcean: + case fShore: + newTile &= (fTerrain | fSpecial); + break; + case fMountains: + case fArctic: + newTile &= ~static_cast(fRiver); + break; + default: + break; + } + const TerrainInfo &terrain = Terrain[newTile & fTerrain]; + if (terrain.ClearTerrain >= 0 || terrain.AfforestTerrain >= 0 || terrain.TransTerrain >= 0) + newTile |= fSpecial; // only automatic special resources for transformable tiles + if (newTile & fRR) + newTile &= ~static_cast(fRoad); + if (((terrTypeCanalableMask >> (newTile & fTerrain)) & 1) == 0) + newTile &= ~static_cast(fCanal); + if (Terrain[newTile & fTerrain].IrrEff == 0) { + newTile &= ~static_cast(fPrefStartPos | fStartPos); + if ((newTile & fTerImp) == tiIrrigation || (newTile & fTerImp) == tiFarm) + newTile &= ~static_cast(fTerImp); + } + if (Terrain[newTile & fTerrain].MineEff == 0 && (newTile & fTerImp) == tiMine) + newTile &= ~static_cast(fTerImp); + + realMap[loc] = newTile; + if ((newTile & fSpecial) == fSpecial) // standard special resource distribution + realMap[loc] = (realMap[loc] & ~static_cast(fSpecial)) | (actualSpecialTile(loc) << 5); + + // automatic shore tiles + Vicinity21Loc radius; + v21ToLoc(loc, radius); + for (int v21 = 1; v21 <= 26; ++v21) { + const int loc1 = radius[static_cast(v21)]; + if (loc1 >= 0 && loc1 < mapSize) { + if (checkShore(loc1)) + realMap[loc1] = (realMap[loc1] & ~static_cast(fSpecial)) | (actualSpecialTile(loc1) << 5); + realMap[loc1] |= (0xFu << 27); + (*rw[0].Map)[loc1] = (realMap[loc1] & 0x07FFFFFFu) | fObserved; + } + } +} + void introduceEnemy(int p1, int p2) { rw[p1].Treaty[p2] = trNone; @@ -881,6 +1070,178 @@ void giveMilReport(int p, int pAbout) ++report.UnCount[un[uix].mix]; } +bool copyCivilReport(int pSender, int pTarget, int pAbout) +{ + bool result = false; + if (rw[pTarget].Treaty[pAbout] == trNoContact) + introduceEnemy(pTarget, pAbout); + TEnemyReport &rSender = *rw[pSender].EnemyReport[pAbout]; + TEnemyReport &rTarget = *rw[pTarget].EnemyReport[pAbout]; + if (rSender.TurnOfCivilReport > rTarget.TurnOfCivilReport) { // only if newer than current information + rTarget.TurnOfCivilReport = rSender.TurnOfCivilReport; + std::memcpy(rTarget.Treaty, rSender.Treaty, sizeof(rTarget.Treaty)); + rTarget.Government = rSender.Government; + rTarget.Money = rSender.Money; + rTarget.ResearchTech = rSender.ResearchTech; + rTarget.ResearchDone = rSender.ResearchDone; + result = true; + } + for (int i = 0; i < nAdv; ++i) + if (rTarget.Tech[i] < rSender.Tech[i]) { + rTarget.Tech[i] = rSender.Tech[i]; + result = true; + } + return result; +} + +bool copyMilReport(int pSender, int pTarget, int pAbout) +{ + bool result = false; + if (rw[pTarget].Treaty[pAbout] == trNoContact) + introduceEnemy(pTarget, pAbout); + TEnemyReport &rSender = *rw[pSender].EnemyReport[pAbout]; + TEnemyReport &rTarget = *rw[pTarget].EnemyReport[pAbout]; + if (rSender.TurnOfMilReport > rTarget.TurnOfMilReport) { // only if newer than current information + rTarget.TurnOfMilReport = rSender.TurnOfMilReport; + rTarget.nModelCounted = rSender.nModelCounted; + std::memcpy(rTarget.UnCount, rSender.UnCount, + sizeof(std::uint16_t) * static_cast(rSender.nModelCounted)); + for (int mix = 0; mix < rTarget.nModelCounted; ++mix) + tellAboutModel(pTarget, pAbout, mix); + result = true; + } + return result; +} + +void copyModel(int pSender, int pTarget, int mix) +{ + // only if target doesn't already have a model like this + bool ok = rw[pTarget].nModel < nMmax; + TModelInfo miSender{}; + MakeModelInfo(pSender, mix, (*rw[pSender].Model)[mix], miSender); + for (int i = 0; i < rw[pTarget].nModel && ok; ++i) { + TModelInfo miTarget{}; + MakeModelInfo(pTarget, i, (*rw[pTarget].Model)[i], miTarget); + if (IsSameModel(miSender, miTarget)) + ok = false; + } + if (ok) { + TModel &newModel = (*rw[pTarget].Model)[rw[pTarget].nModel]; + newModel = (*rw[pSender].Model)[mix]; + newModel.IntroTurn = static_cast(gTurn); + if (newModel.Kind == mkSelfDeveloped) + newModel.Kind = mkEnemyDeveloped; + newModel.Status = 0; + newModel.SavedStatus = 0; + newModel.Built = 0; + newModel.Lost = 0; + ++rw[pTarget].nModel; + ++researched[pTarget]; + tellAboutModel(pSender, pTarget, rw[pTarget].nModel - 1); + } +} + +void copyMap(int pSender, int pTarget) +{ + TPlayerContext &sender = rw[pSender]; + TPlayerContext &target = rw[pTarget]; + const std::int16_t *senderObserved = *sender.MapObservedLast; + std::int16_t *targetObserved = *target.MapObservedLast; + const std::uint32_t *senderMap = *sender.Map; + std::uint32_t *targetMap = *target.Map; + const std::int8_t *senderTerritory = *sender.Territory; + std::int8_t *targetTerritory = *target.Territory; + TCityInfo *senderEnemyCity = *sender.EnemyCity; + TCityInfo *targetEnemyCity = *target.EnemyCity; + const TCity *senderCity = *sender.City; + + for (int loc = 0; loc < mapSize; ++loc) { + if (senderObserved[loc] <= targetObserved[loc]) + continue; + std::uint32_t tile = senderMap[loc]; + if (tile & fCity) { + int i = 0; + while (i < target.nEnemyCity && targetEnemyCity[i].Loc != loc) + ++i; + if (i == target.nEnemyCity) { + ++target.nEnemyCity; + assert(target.nEnemyCity < necmax); + targetEnemyCity[i].Status = 0; + targetEnemyCity[i].SavedStatus = 0; + } + if (tile & fOwned) { // city owned by sender -- create new info + int cix = sender.nCity - 1; + while (cix >= 0 && senderCity[cix].Loc != loc) + --cix; + makeCityInfo(pSender, cix, targetEnemyCity[i]); + } else { // city not owned by sender -- copy old info + int cix = sender.nEnemyCity - 1; + while (cix >= 0 && senderEnemyCity[cix].Loc != loc) + --cix; + targetEnemyCity[i] = senderEnemyCity[cix]; + } + } else if (targetMap[loc] & fCity) { // remove enemycity + for (int cix = 0; cix < target.nEnemyCity; ++cix) + if (targetEnemyCity[cix].Loc == loc) + targetEnemyCity[cix].Loc = -1; + } + + tile &= (~static_cast(fSpecial | fModern) | resourceMask[pTarget]); + tile |= (targetMap[loc] & fModern); + if ((tile & fTerrain) == (targetMap[loc] & fTerrain)) + tile |= (targetMap[loc] & fSpecial); + + if ((targetMap[loc] & fTerrain) == static_cast(fUNKNOWN)) + ++discovered[pTarget]; + targetMap[loc] = (targetMap[loc] & fInEnemyZoC) // always preserve this flag! + | (tile & ~static_cast(fUnit | fHiddenUnit | fStealthUnit | fObserved | + fSpiedOut | fOwned | fInEnemyZoC | fOwnZoCUnit | + fPeace | fGrWall)); + // (the original re-assigns Territory unconditionally right after an + // equivalent if-guarded assignment - the guard was a no-op once its + // only other effect, a BorderHelper update, had been commented out) + targetTerritory[loc] = senderTerritory[loc]; + targetObserved[loc] = senderObserved[loc]; + } +} + +std::uint32_t doSpyMission(int p, int pCity, int cix, int mission) +{ + std::uint32_t result = 0; + switch (mission) { + case smSabotageProd: + (*rw[pCity].City)[cix].Flags |= chProductionSabotaged; + break; + case smStealMap: + copyMap(pCity, p); + recalcPeaceMap(p); + break; + case smStealCivilReport: + if (rw[p].Treaty[pCity] == trNoContact) + introduceEnemy(p, pCity); + giveCivilReport(p, pCity); + break; + case smStealMilReport: + if (rw[p].Treaty[pCity] == trNoContact) + introduceEnemy(p, pCity); + giveMilReport(p, pCity); + break; + case smStealForeignReports: + for (int p1 = 0; p1 < nPl; ++p1) { + if (p1 != p && p1 != pCity && rw[pCity].EnemyReport[p1]) { + if (rw[pCity].EnemyReport[p1]->TurnOfCivilReport >= 0 && copyCivilReport(pCity, p, p1)) + result |= (1u << (2 * p1)); + if (rw[pCity].EnemyReport[p1]->TurnOfMilReport >= 0 && copyMilReport(pCity, p, p1)) + result |= (2u << (2 * p1)); + } + } + break; + default: + break; + } + return result; +} + void intServer(int command, int player, int subject, const void *data) { if (mode == moPlaying) @@ -1301,6 +1662,31 @@ void updateUnitMap(int loc, bool cityChange) } } +void recalcMapZoC(int p) +{ + if (mode == moLoading_Fast) + return; + maskD(*rw[p].Map, mapSize, ~static_cast(fInEnemyZoC)); + const int observeMask = 3 << (2 * p); + std::uint32_t *map = *rw[p].Map; + for (int loc = 0; loc < mapSize; ++loc) { + if (zocMap[loc] > 0 && (observeLevel[loc] & observeMask)) { + const int p1 = occupant[loc]; + assert(p1 != nPl); + if (p1 != p && rw[p].Treaty[p1] < trAlliance) { + // this non-allied enemy ZoC unit is known to this player -- set flags! + Vicinity8Loc adjacent; + v8ToLoc(loc, adjacent); + for (int v8 = 0; v8 < 8; ++v8) { + const int loc1 = adjacent[static_cast(v8)]; + if (loc1 >= 0 && loc1 < mapSize) + map[loc1] |= fInEnemyZoC; + } + } + } + } +} + void recalcPeaceMap(int p) { if (mode != moPlaying) @@ -1769,5 +2155,144 @@ void releaseGame() gInitialized = 0; } +namespace { + +void stealCity(int p, int cix, bool saveUnits) +{ + TCity &city = (*rw[p].City)[cix]; + for (int i = 0; i < nWonder; ++i) { + if (city.Built[i] == 1) { + gWonder[i].EffectiveOwner = -1; + if (i == woPyramids) + freeSlaves(); + if (i == woEiffel) // deactivate expired wonders + for (int j = 0; j < nWonder; ++j) + if (gWonder[j].EffectiveOwner == p) + checkExpiration(j); + } + } + for (int i = nWonder; i < nImp; ++i) { + if (Imp[i].Kind != ikCommon && city.Built[i] > 0) { // destroy national projects + rw[p].NatBuilt[i] = 0; + if (i == imGrWall) + grWallContinent[p] = -1; + } + } + + TUn *un = *rw[p].Un; + for (int uix1 = 0; uix1 < rw[p].nUn; ++uix1) { + if (un[uix1].Loc >= 0 && un[uix1].Home == cix) { + if (saveUnits) { // support units by nearest other city + int nearest = -1; + for (int cix1 = 0; cix1 < rw[p].nCity; ++cix1) { + const TCity &c1 = (*rw[p].City)[cix1]; + if (cix1 != cix && c1.Loc >= 0 && + (nearest < 0 || distance(c1.Loc, un[uix1].Loc) < + distance((*rw[p].City)[nearest].Loc, un[uix1].Loc))) + nearest = cix1; + } + un[uix1].Home = nearest; + } else { + removeUnit(p, uix1); // destroy supported units + } + } + } +} + +} // namespace + +void destroyCity(int p, int cix, bool saveUnits) +{ + stealCity(p, cix, saveUnits); + TCity &city = (*rw[p].City)[cix]; + for (int i = 0; i < nWonder; ++i) + if (city.Built[i] > 0) + gWonder[i].CityID = WonderDestroyed; + Vicinity21Loc radius; + v21ToLoc(city.Loc, radius); + for (int v21 = 1; v21 <= 26; ++v21) + if ((1u << v21) & city.Tiles) + usedByCity[static_cast(radius[static_cast(v21)])] = -1; + realMap[city.Loc] &= ~static_cast(fCity); + city.Loc = -1; +} + +void changeCityOwner(int pOld, int cixOld, int pNew) +{ + ++rw[pNew].nCity; + (*rw[pNew].City)[rw[pNew].nCity - 1] = (*rw[pOld].City)[cixOld]; + stealCity(pOld, cixOld, false); + (*rw[pOld].City)[cixOld].Loc = -1; + + TCity &city = (*rw[pNew].City)[rw[pNew].nCity - 1]; + city.Food = 0; + city.Project = cpImp + imTrGoods; + city.Prod = 0; + city.Project0 = city.Project; + city.Prod0 = 0; + city.Status = 0; + city.SavedStatus = 0; + city.N1 = 0; + + // check for siege + Vicinity21Loc radius; + v21ToLoc(city.Loc, radius); + for (int v21 = 1; v21 <= 26; ++v21) { + if ((city.Tiles & (1u << v21) & ~(1u << CityOwnTile)) != 0) { + const int loc1 = radius[static_cast(v21)]; + assert(loc1 >= 0 && loc1 < mapSize && usedByCity[static_cast(loc1)] == city.Loc); + if (zocMap[loc1] > 0 && occupant[loc1] != pNew && rw[pNew].Treaty[occupant[loc1]] < trAlliance) { + // tile can't remain exploited + city.Tiles &= ~(1u << v21); + usedByCity[static_cast(loc1)] = -1; + } + // don't check for siege by peace territory here, because territory + // might not be up to date -- done in turn beginning anyway + } + } + city.Built[imTownHall] = 0; + city.Built[imCourt] = 0; + for (int i = nWonder; i < nImp; ++i) + if (Imp[i].Kind != ikCommon) + city.Built[i] = 0; // destroy national projects + for (int i = 0; i < nWonder; ++i) { + if (city.Built[i] == 1) { // new wonder owner! + gWonder[i].EffectiveOwner = pNew; + if (i == woEiffel) { // reactivate expired wonders + for (int j = 0; j < nWonder; ++j) + if (Imp[j].Expiration >= 0) + for (int cix1 = 0; cix1 < rw[pNew].nCity; ++cix1) + if ((*rw[pNew].City)[cix1].Built[j] == 1) + gWonder[j].EffectiveOwner = pNew; + } else { + checkExpiration(i); + } + switch (i) { + case woLighthouse: + checkSpecialModels(pNew, preLighthouse); + break; + case woLeo: + checkSpecialModels(pNew, preLeo); + break; + case woPyramids: + checkSpecialModels(pNew, preBuilder); + break; + default: + break; + } + } + } + + // remove city from enemy cities - not done by Discover, because fCity still set! + int cix1 = rw[pNew].nEnemyCity - 1; + TCityInfo *enemyCity = *rw[pNew].EnemyCity; + while (cix1 >= 0 && enemyCity[cix1].Loc != city.Loc) + --cix1; + assert(cix1 >= 0); + enemyCity[cix1].Loc = -1; + + changeTerritory(city.Loc, pNew); +} + } // namespace Database } // namespace Cevo