180 lines
6.5 KiB
C++
180 lines
6.5 KiB
C++
// 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.
|
|
|
|
// --- City --- (see Cevo/Database.h)
|
|
|
|
#include "Cevo/Database.h"
|
|
#include "DatabaseInternal.h"
|
|
|
|
#include <cassert>
|
|
|
|
namespace Cevo {
|
|
namespace Database {
|
|
|
|
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<std::size_t>(radius[static_cast<std::size_t>(v21)])] = -1;
|
|
realMap[city.Loc] &= ~static_cast<std::uint32_t>(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<std::size_t>(v21)];
|
|
assert(loc1 >= 0 && loc1 < mapSize && usedByCity[static_cast<std::size_t>(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<std::size_t>(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
|