// 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.
.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 #include 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 rw{}; std::array difficulty{}; std::array serverVersion{}; std::array resourceMask{}; std::array processClientData{}; std::array discovered{}; std::array researched{}; std::array lastValidStat{}; std::array nTech{}; int gAlive = 0; int gWatching = 0; int gAI = 0; int gTurn = 0; int gTestFlags = 0; std::array founded{}; int invalidTreatyMap = 0; int gInitialized = 0; int peaceEnded = 0; int saveMapCenterLoc = 0; std::array startLoc{}; std::array startLoc2{}; std::array gWonder{}; std::array grWallContinent{}; std::array gShip{}; std::array, nPl>, nPl> rwemix{}; std::array, nPl>, nPl> destroyed{}; std::array realMap{}; std::array continent{}; std::array occupant{}; 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{}; // 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 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(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(reinterpret_cast(data)), player, lObserveUnhidden, true, false); } else if (command == sIntBuyMaterial) { TCity &city = (*rw[player].City)[subject]; const auto cost = static_cast(reinterpret_cast(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(data); for (int i = 0; i < offer.nDeliver; ++i) payPrice(player, subject, offer.Price[static_cast(i)], true); for (int i = 0; i < offer.nCost; ++i) payPrice(subject, player, offer.Price[static_cast(offer.nDeliver + i)], true); for (int i = 0; i < offer.nDeliver + offer.nCost; ++i) { if (offer.Price[static_cast(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