initial port for Cevo game in C++ (libs)
This commit is contained in:
commit
8436242032
375 files changed
+46282
No files matched your search
@@ -0,0 +1,122 @@
|
||||
#pragma once
|
||||
|
||||
#include "Cevo/CustomAI.h"
|
||||
#include "Cevo/Pile.h"
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
|
||||
namespace Cevo {
|
||||
|
||||
// no-formation sentinel values (Formation[]/map analysis)
|
||||
constexpr int nfUndiscovered = -1;
|
||||
constexpr int nfPole = -2;
|
||||
constexpr int nfPeace = -3;
|
||||
|
||||
// return codes of checkStep()
|
||||
constexpr int csOk = 0; // step is valid, timeAfterStep has been calculated
|
||||
constexpr int csForbiddenTile = 1; // unit can not move onto this tile
|
||||
constexpr int csForbiddenStep = 2; // (ZoC unit only) unit can not do this step because of ZoC violation
|
||||
constexpr int csCheckTerritory = 3; // move within other nation's territory shortly after peace
|
||||
|
||||
constexpr int mxAdjacent = 0x00000001; // unit_MoveEx option
|
||||
|
||||
struct GroupTransportPlan {
|
||||
int LoadLoc = -1;
|
||||
int uixTransport = 0;
|
||||
int nLoad = 0;
|
||||
int TurnsEmpty = 0;
|
||||
int TurnsLoaded = 0;
|
||||
int uixLoad[16] = {};
|
||||
};
|
||||
|
||||
// Total number of prerequisites for each advance; computed once at process
|
||||
// startup (mirrors ToolAI.pas's SetAdvancedness(), run from its
|
||||
// `initialization` section).
|
||||
extern const std::array<int, nAdv> Advancedness;
|
||||
|
||||
// C++ equivalent of ToolAI.pas's TToolAI: map analysis, job assignment,
|
||||
// pathfinding and sea-transport planning helpers built on top of CustomAI's
|
||||
// raw Server-call wrappers.
|
||||
//
|
||||
// Like the original, the scratch state below (formation/district/cityResult,
|
||||
// job-assignment and sea-transport working buffers, the Pile instance) is
|
||||
// process-shared (static), not per-nation: AI turn processing is strictly
|
||||
// sequential (one nation's DoTurn() completes before another's starts), so
|
||||
// the original reused unit-level globals instead of per-instance buffers.
|
||||
class ToolAI : public CustomAI {
|
||||
public:
|
||||
using CustomAI::CustomAI;
|
||||
|
||||
protected:
|
||||
int centerOfEmpire() const; // tile that is in the middle of all own cities
|
||||
|
||||
// Exact difference of income and maintenance cost for a single city;
|
||||
// positive = income higher than maintenance. cityReport must have been
|
||||
// prepared (city_GetReport/city_GetHypoReport) before calling this.
|
||||
int cityTaxBalance(int cix, const TCityReport &cityReport) const;
|
||||
// Exact total tax and science income; tax is reduced by maintenance (so
|
||||
// might be negative). Luxury not supported.
|
||||
void sumCities(int taxRate, int &taxSum, int &scienceSum) const;
|
||||
|
||||
void optimizeCityTiles() const; // obsolete; use city_OptimizeTiles instead
|
||||
void getCityProdPotential(); // fills cityResult[cix] with production potential
|
||||
void getCityTradePotential(); // fills cityResult[cix] with trade potential
|
||||
|
||||
// Settler job assignment: initialize, add jobs/units, then go; assigns
|
||||
// each job to one settler, moves the settlers and makes them work.
|
||||
void jobAssignment_Initialize();
|
||||
void jobAssignment_AddJob(int loc, int job, int score);
|
||||
void jobAssignment_AddUnit(int uix);
|
||||
void jobAssignment_Go();
|
||||
bool jobAssignment_GotJob(int uix) const;
|
||||
|
||||
void analyzeMap(); // calculates formations (continents/oceans) and districts
|
||||
|
||||
// Forecast a single unit move between adjacent tiles. fromTile/toTile
|
||||
// must be Map[FromLoc]/Map[ToLoc] (not location codes). crossCorner=1 for
|
||||
// long moves crossing the tile corner, 0 for short ones that don't.
|
||||
int checkStep(int moveStyle, int timeBeforeStep, int crossCorner, int &timeAfterStep, int &recoverTurns,
|
||||
std::uint32_t fromTile, std::uint32_t toTile, bool isCapture) const;
|
||||
int getMyMoveStyle(int mix, int health) const;
|
||||
int unit_MoveEx(int uix, int toLoc, int options = 0);
|
||||
|
||||
// Sea transport, obligatory call order: beginInitialize; [addLoad/
|
||||
// addTransport/addDestination]*; endInitialize; [makeGroupPlan]*.
|
||||
void seaTransport_BeginInitialize();
|
||||
void seaTransport_EndInitialize();
|
||||
void seaTransport_AddLoad(int uix);
|
||||
void seaTransport_AddTransport(int uix);
|
||||
void seaTransport_AddDestination(int loc);
|
||||
bool seaTransport_MakeGroupPlan(GroupTransportPlan &transportPlan);
|
||||
|
||||
int currentMStrength(int domain) const;
|
||||
|
||||
static int nContinent, nOcean, nDistrict;
|
||||
// water: ocean index, land: continent index, sorted by size; territory
|
||||
// unpassable due to peace treaty divides a continent.
|
||||
static std::array<int, lxmax * lymax> formation;
|
||||
// index of coherent own territory, sorted by size.
|
||||
static std::array<int, lxmax * lymax> district;
|
||||
static std::array<int, nCmax> cityResult;
|
||||
// Shared single-instance priority queue (mirrors Pile.pas being its own
|
||||
// unit used directly by both ToolAI.pas and Barbarina.pas); protected so
|
||||
// Barbarina can use it for its own pathfinding (attack/patrol scoring).
|
||||
static Pile pile;
|
||||
|
||||
private:
|
||||
// JobAssignment state
|
||||
static int maxScore;
|
||||
static std::array<std::uint8_t, lxmax * lymax> tileJob;
|
||||
static std::array<std::uint8_t, lxmax * lymax> tileJobScore;
|
||||
static std::array<int, nUmax> jobLocOfSettler; // ToAssign sentinel = find job
|
||||
|
||||
// SeaTransport state
|
||||
static int transportMoveStyle, transportCapacity, nTransportLoad;
|
||||
static bool initComplete, haveDestinations;
|
||||
static std::array<int, nUmax> uixTransportLoad;
|
||||
static std::array<int, nUmax> transportAvailable;
|
||||
static std::array<std::int8_t, lxmax * lymax> turnsAfterLoad;
|
||||
};
|
||||
|
||||
} // namespace Cevo
|
||||
Reference in new issue
Block a user