Files
c-evo-evo/game/include/Cevo/Database.h
T
2026-10-22 18:11:04 +02:00

97 lines
3.9 KiB
C++

// This file is part of cevo-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
#include "Cevo/Protocol.h"
#include <array>
#include <cstdint>
namespace Cevo {
namespace Database {
// Equivalent of Database.pas's global `var` state and free functions. Kept
// as flat global state/free functions - matching the original's own
// architecture (a single shared-state game server module) - rather than
// wrapped in a class/singleton that wasn't asked for and would be a large,
// separate refactor.
//
// Database.pas is ~4080 lines with heavy dependencies on Protocol.pas's big
// gameplay structs (TPlayerContext, TModel, TCity, TUn, ...) - all already
// available via Cevo/Protocol.h (see game/CMakeLists.txt: cevogame links
// cevoai to reuse its exact port of those shared structs/constants, since
// perso/cevo/Protocol.pas and the AI-facing "AI Template/Protocol.pas"
// define them identically). Ported INCREMENTALLY regardless: this only
// covers globals/functions actually consumed by whichever caller (Database
// itself, CityProcessing, ...) has been ported so far. Add more here only
// once a new batch needs them.
//
// `rw[p].City`/`.Un`/`.Model` are pointer-to-array fields (TCityList* etc.)
// that stay null until Database's InitGame-equivalent (not ported yet)
// allocates them - dereference as `(*rw[p].City)[cix]`, or cache a decayed
// `TCity *city = *rw[p].City;` first if indexing repeatedly (same idiom
// ai/src/CustomAI.cpp already uses for `myCity`).
extern int lx;
extern int ly;
extern int mapSize; // = lx * ly
using Vicinity8Loc = std::array<int, 8>;
using Vicinity21Loc = std::array<int, 28>;
// player data
extern std::array<TPlayerContext, nPl> rw;
// map data
extern std::array<std::uint32_t, lxmax * lymax> realMap;
extern std::array<std::int8_t, lxmax * lymax> occupant; // occupying player for each tile
extern std::array<std::int8_t, lxmax * lymax> zocMap;
extern std::array<std::int32_t, lxmax * lymax> usedByCity; // -1 if not exploited
// Equivalent of Database.pas's MaskD().
void maskD(std::uint32_t *x, int count, std::uint32_t mask);
// --- Location Navigation ---
// Relative location, dx in hor and dy in ver direction from loc. Returns -1
// if the result would fall outside the map.
int dLoc(int loc, int dx, int dy);
void dxdy(int loc0, int loc1, int &dx, int &dy);
int distance(int loc0, int loc1);
void v8ToLoc(int loc0, Vicinity8Loc &vicinityLoc);
void v21ToLoc(int loc0, Vicinity21Loc &vicinityLoc);
// --- Map Creation ---
void calculatePrimitive();
bool mapGeneratorAvailable();
} // namespace Database
} // namespace Cevo