179 lines
7.2 KiB
C++
179 lines
7.2 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.
|
|
|
|
#pragma once
|
|
|
|
// GameServer.pas's own implementation-section-private (`unit`-local)
|
|
// globals and helpers, shared across the GameServer.<Section>.cpp
|
|
// translation units that GameServer.cpp is now split into. Not part of the
|
|
// public GameServer.h API - include this only from GameServer*.cpp files.
|
|
// Before the split these lived in (two) anonymous namespaces inside one
|
|
// .cpp (true C++ internal linkage, matching Pascal's interface/
|
|
// implementation visibility split); now that they're needed from several
|
|
// translation units, they're plain (externally linked) GameServer::
|
|
// symbols instead - still private by convention, just no longer enforced
|
|
// by the compiler. Every global below is defined in GameServer.cpp.
|
|
|
|
#include "GameServer.h"
|
|
|
|
#include "Cevo/CmdList.h"
|
|
#include "Cevo/UnitProcessing.h"
|
|
|
|
#include <QByteArray>
|
|
#include <QString>
|
|
|
|
#include <array>
|
|
#include <cstdint>
|
|
#include <vector>
|
|
|
|
namespace Cevo {
|
|
namespace GameServer {
|
|
|
|
extern NotifyFunction notify;
|
|
|
|
// Equivalent of Pascal's unit-level private `bix: TBrains` ("brain of the
|
|
// players") - renamed to avoid colliding with the pervasive `bix`
|
|
// parameter/loop-variable name used for brain *indices* elsewhere in the
|
|
// original (e.g. InitBrain(bix: TBrain), CallClient(bix, Command, ...)).
|
|
extern std::array<Brain *, nPl> playerBrain;
|
|
|
|
extern bool previewElevation;
|
|
|
|
// Remaining unit-level private state (GameServer.pas's own big private
|
|
// `var` block).
|
|
extern int maxTurn;
|
|
extern int pTurn;
|
|
extern int gWinner;
|
|
extern int gColdWarStart;
|
|
extern int pDipActive;
|
|
extern int pContacted;
|
|
extern TOffer lastOffer;
|
|
extern int uixSelectedTransport;
|
|
extern int spyMission;
|
|
extern bool winOnAlone;
|
|
extern bool autoSaveExists;
|
|
extern CmdListState autoSaveState;
|
|
extern std::array<void *, nPl> savedData;
|
|
extern std::array<void *, nPl> debugMap;
|
|
extern std::array<int, nPl> originalDataVersion;
|
|
extern std::array<int, nPl> devModelTurn; // turn of last sCreateDevModel call (comment name is stale in the original too)
|
|
extern std::array<QString, nPl> aiInfo;
|
|
extern QString aiCredits;
|
|
// Persistent byte-buffer caches for sGetAIInfo/sGetAICredits, which hand
|
|
// out a raw const char* into AIInfo[]/AICredits (valid until the next such
|
|
// call - same "valid until next mutating call" convention already used
|
|
// for CmdList::get's data pointer).
|
|
extern QByteArray aiInfoUtf8Cache;
|
|
extern QByteArray aiCreditsUtf8Cache;
|
|
extern QString mapFileName; // name of map to use, empty for random
|
|
extern QString logFileName;
|
|
extern QString savePath; // directory of the file for saving the current game
|
|
extern int lastEndClientCommand;
|
|
extern int ccCommand;
|
|
extern int ccPlayer;
|
|
extern std::array<int, 15> ccData;
|
|
extern double lastClientTime;
|
|
extern int gStealFrom;
|
|
extern int zocTile;
|
|
|
|
// GameServer.pas's own local ProjectType() result constants (Server()'s
|
|
// sSetCityProject handling only - not a shared Protocol.h concept).
|
|
constexpr int ptSelect = 0;
|
|
constexpr int ptTrGoods = 1;
|
|
constexpr int ptUn = 2;
|
|
constexpr int ptCaravan = 3;
|
|
constexpr int ptImp = 4;
|
|
constexpr int ptWonder = 6;
|
|
constexpr int ptShip = 7;
|
|
constexpr int ptInvalid = 8;
|
|
|
|
extern int loadTurn; // turn where to stop loading
|
|
extern int nLogOpened; // nLog of opened book
|
|
extern bool movieStopped;
|
|
extern bool loadOK;
|
|
// SavedTiles[cix] - a single shared scratch array (not per-player): only
|
|
// RW[pTurn]'s cities are ever "in focus" at a time, matching the original.
|
|
extern std::array<std::uint32_t, nCmax> savedTiles;
|
|
// Predefined map snapshot (only non-empty when Database::landMass == 0) -
|
|
// a disclosed std::vector-based simplification of the original's
|
|
// GetMem/FreeMem(MapField) raw pointer.
|
|
extern std::vector<std::uint32_t> mapField;
|
|
// Stat[st][p][turn] equivalent - std::vector instead of GetMem/FreeMem.
|
|
extern std::array<std::array<std::vector<std::int32_t>, nPl>, nStat> stat;
|
|
|
|
// Server() is the ~1600-line client-to-server command dispatcher, defined
|
|
// in GameServer.Server.cpp - the single biggest piece of GameServer.pas.
|
|
int CEVO_ABI_CALL server(int command, int player, int subject, void *data);
|
|
|
|
// --- GameServer.ClientCallPlumbing.cpp ---
|
|
QString getAiDir();
|
|
void notifyEvent(NotifyId id, int index = 0);
|
|
void insertTerritoryUpdateCommands();
|
|
void callPlayer(int command, int p, void *data);
|
|
void callAllPlayers(int command, void *data);
|
|
void callClient(int brainIndex, int command, void *data);
|
|
void putMessage(int level, const QString &text);
|
|
void changeClientWhenDone(int command, int player, const void *data, int dataSize);
|
|
void forceClientDeactivation();
|
|
void inform(int p);
|
|
void logChanges();
|
|
void noLogChanges();
|
|
bool hasChanges(int p);
|
|
void initBrain(Brain &brain);
|
|
|
|
// --- GameServer.Lifecycle.cpp ---
|
|
void saveGame(const QString &fileName, bool autoSave);
|
|
void startGame();
|
|
void endGame();
|
|
void generateStat(int p);
|
|
void logCityTileChanges();
|
|
void noLogCityTileChanges();
|
|
bool hasCityTileChanges();
|
|
|
|
// --- GameServer.TurnProcessing.cpp ---
|
|
void beforeTurn0();
|
|
void destroySpacePortTellPlayers(int p, int pCapturer);
|
|
void destroyCityTellPlayers(int p, int cix, bool saveUnits);
|
|
void changeCityOwnerTellPlayers(int pOld, int cixOld, int pNew);
|
|
void checkWin(int p);
|
|
void beforeTurn();
|
|
void afterTurn();
|
|
void nextPlayerImpl();
|
|
|
|
// --- GameServer.MoveAndCombat.cpp ---
|
|
int executeMove(int p, int uix, int toLoc, UnitProcessing::TMoveInfo &moveInfo, TShowMove showMove);
|
|
void ensureBattleHistoryCapacity(TPlayerContext &player);
|
|
void writeBattleHistory(int toLoc, int fromLoc, int attacker, int defender, int mixAttacker, int mixDefender,
|
|
bool attackerLost, bool defenderLost);
|
|
int executeAttack(int p, int uix, int toLoc, UnitProcessing::TMoveInfo &moveInfo, TShowMove showMove);
|
|
int moveUnit(int p, int uix, int dx, int dy, bool testOnly);
|
|
int countPrice(const TOffer &offer, std::uint32_t priceType);
|
|
|
|
} // namespace GameServer
|
|
} // namespace Cevo
|