171 lines
7.3 KiB
C++
171 lines
7.3 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.
|
|
|
|
// Database.pas's global `var` state, MaskD(), and IntServer() - the parts
|
|
// declared in Cevo/Database.h before any `// --- Section ---` marker. Every
|
|
// other function now lives in one Database.<Section>.cpp per header
|
|
// section (Database.LocationNavigation.cpp, Database.MapCreation.cpp, ...,
|
|
// Database.City.cpp) - split out of what used to be one large Database.cpp,
|
|
// since (unlike the original Pascal unit) C++ has no trouble spreading a
|
|
// single namespace's definitions across several translation units. Private
|
|
// (Pascal implementation-section-only) helpers/globals needed by more than
|
|
// one of those section files now live in DatabaseInternal.h instead of an
|
|
// anonymous namespace (anonymous-namespace internal linkage can't be shared
|
|
// across translation units).
|
|
|
|
#include "Cevo/Database.h"
|
|
#include "DatabaseInternal.h"
|
|
|
|
#include <cassert>
|
|
#include <cstring>
|
|
|
|
namespace Cevo {
|
|
namespace Database {
|
|
|
|
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;
|
|
|
|
std::array<TPlayerContext, nPl> rw{};
|
|
std::array<int, nPl> difficulty{};
|
|
std::array<int, nPl> serverVersion{};
|
|
std::array<std::uint32_t, nPl> resourceMask{};
|
|
std::array<bool, nPl> processClientData{};
|
|
std::array<int, nPl> discovered{};
|
|
std::array<int, nPl> researched{};
|
|
std::array<int, nPl> lastValidStat{};
|
|
std::array<int, nPl> nTech{};
|
|
int gAlive = 0;
|
|
int gWatching = 0;
|
|
int gAI = 0;
|
|
int gTurn = 0;
|
|
int gTestFlags = 0;
|
|
std::array<int, nPl> founded{};
|
|
int invalidTreatyMap = 0;
|
|
int gInitialized = 0;
|
|
int peaceEnded = 0;
|
|
int saveMapCenterLoc = 0;
|
|
std::array<int, nPl> startLoc{};
|
|
std::array<int, nPl> startLoc2{};
|
|
std::array<TWonderInfo, nWonder> gWonder{};
|
|
std::array<int, nPl> grWallContinent{};
|
|
std::array<TShipInfo, nPl> gShip{};
|
|
std::array<std::array<std::array<std::int16_t, nMmax>, nPl>, nPl> rwemix{};
|
|
std::array<std::array<std::array<std::int16_t, nMmax>, nPl>, nPl> destroyed{};
|
|
|
|
std::array<std::uint32_t, lxmax * lymax> realMap{};
|
|
std::array<int, lxmax * lymax> continent{};
|
|
std::array<std::int8_t, lxmax * lymax> occupant{};
|
|
std::array<std::int8_t, lxmax * lymax> zocMap{};
|
|
std::array<std::int32_t, lxmax * lymax> usedByCity{};
|
|
std::array<std::uint32_t, lxmax * lymax> observeLevel{};
|
|
|
|
// Equivalent of Database.pas's `TerritoryCount: array[0..nPl]` - public since
|
|
// GameServer::generateStat() needs read access (index nPl means "no owner").
|
|
std::array<int, nPl + 1> 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). See DatabaseInternal.h.
|
|
std::array<std::uint32_t, 8> borderChanges{};
|
|
|
|
void maskD(std::uint32_t *x, int count, std::uint32_t mask)
|
|
{
|
|
for (int i = 0; i < count; ++i)
|
|
x[i] &= mask;
|
|
}
|
|
|
|
void intServer(int command, int player, int subject, const void *data)
|
|
{
|
|
if (mode == moPlaying)
|
|
cl.put(command, player, subject, data);
|
|
|
|
if (command == sIntTellAboutNation) {
|
|
introduceEnemy(player, subject);
|
|
} else if (command >= sIntTellAboutModel && command <= sIntTellAboutModel + ((nPl - 1) << 4)) {
|
|
const int p1 = (command - sIntTellAboutModel) >> 4; // told player
|
|
assert(player >= 0 && player < nPl);
|
|
assert(subject >= 0 && subject < rw[player].nModel);
|
|
TPlayerContext &toldPlayer = rw[p1];
|
|
MakeModelInfo(player, subject, (*rw[player].Model)[subject], (*toldPlayer.EnemyModel)[toldPlayer.nEnemyModel]);
|
|
rwemix[p1][player][subject] = static_cast<std::int16_t>(toldPlayer.nEnemyModel);
|
|
++toldPlayer.nEnemyModel;
|
|
assert(toldPlayer.nEnemyModel < nemmax);
|
|
} else if (command == sIntExpandTerritory) {
|
|
if (mode < moPlaying) {
|
|
std::memcpy(borderChanges.data(), data, sizeof(borderChanges));
|
|
expandTerritory((*rw[player].City)[subject].Loc);
|
|
}
|
|
} else if (command == sIntHaveContact) {
|
|
assert(rw[player].Treaty[subject] > trNoContact);
|
|
rw[player].EnemyReport[subject]->TurnOfContact = gTurn;
|
|
rw[subject].EnemyReport[player]->TurnOfContact = gTurn;
|
|
} else if (command == sIntCancelTreaty) {
|
|
cancelTreaty(player, subject);
|
|
} else if (command == sIntDiscoverZOC) {
|
|
discover9(static_cast<int>(reinterpret_cast<std::intptr_t>(data)), player, lObserveUnhidden, true, false);
|
|
} else if (command == sIntBuyMaterial) {
|
|
TCity &city = (*rw[player].City)[subject];
|
|
const auto cost = static_cast<int>(reinterpret_cast<std::intptr_t>(data));
|
|
rw[player].Money -= cost;
|
|
if (gWonder[woMich].EffectiveOwner == player && (city.Project & cpImp))
|
|
city.Prod += cost / 2;
|
|
else
|
|
city.Prod += cost / 4;
|
|
if ((city.Project0 & ~cpAuto) != (city.Project & ~cpAuto))
|
|
city.Project0 = city.Project;
|
|
city.Prod0 = city.Prod;
|
|
} else if (command >= sIntPayPrices && command <= sIntPayPrices + 12) {
|
|
const auto &offer = *static_cast<const TOffer *>(data);
|
|
for (int i = 0; i < offer.nDeliver; ++i)
|
|
payPrice(player, subject, offer.Price[static_cast<std::size_t>(i)], true);
|
|
for (int i = 0; i < offer.nCost; ++i)
|
|
payPrice(subject, player, offer.Price[static_cast<std::size_t>(offer.nDeliver + i)], true);
|
|
for (int i = 0; i < offer.nDeliver + offer.nCost; ++i) {
|
|
if (offer.Price[static_cast<std::size_t>(i)] == opTreaty + trAlliance) {
|
|
// add view area of allied player
|
|
discoverViewAreas(player);
|
|
discoverViewAreas(subject);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
// Other sIntXxx cases (sIntSetDevModel/sIntSetXxxStatus) are NOT
|
|
// implemented yet - each is only needed by LoadGame's command replay of
|
|
// a client's own already-applied local changes, not by Server()'s own
|
|
// command dispatch - lower priority than the above. See repo memory.
|
|
}
|
|
|
|
} // namespace Database
|
|
} // namespace Cevo
|