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,110 @@
|
||||
#pragma once
|
||||
|
||||
#include "Cevo/Barbarina.h"
|
||||
|
||||
#include <array>
|
||||
|
||||
namespace Cevo {
|
||||
|
||||
constexpr int nAIModelCat = 4;
|
||||
constexpr int mctNone = -1;
|
||||
constexpr int mctGroundDefender = 0;
|
||||
constexpr int mctGroundAttacker = 1;
|
||||
constexpr int mctTransport = 2;
|
||||
constexpr int mctCruiser = 3;
|
||||
|
||||
constexpr int nRequestedTechs = 48;
|
||||
|
||||
enum class Suggestion { Contact, Peace, Friendly };
|
||||
|
||||
// Raw per-nation scratch memory the host allocates (rwDataSize bytes) and
|
||||
// hands back via TPlayerContext::Data - reinterpreted in place, NOT
|
||||
// constructed, so these fields must NOT rely on default member
|
||||
// initializers (see setDataDefaults(), which is what actually initializes
|
||||
// a fresh block on cmNewGame, mirroring the original's SetDataDefaults).
|
||||
struct TPersistentData {
|
||||
int LastResearchTech;
|
||||
int BehaviorFlags;
|
||||
int TheologyPartner;
|
||||
std::int16_t RejectTurn[3][16]; // [Suggestion][0..15]
|
||||
int RequestedTechs[nRequestedTechs]; // ad + p shl 8 + Turn shl 16
|
||||
};
|
||||
|
||||
// C++ equivalent of AI.pas's TAI: the actual StdAI decision heuristics
|
||||
// (research strategy, terraforming/settlers, production, combat/patrol,
|
||||
// diplomacy), built on top of Barbarina's "barbarian mode" personality.
|
||||
// This is the final/top-level AI class a StdAI plugin module instantiates.
|
||||
class AI : public Barbarina {
|
||||
public:
|
||||
explicit AI(int nation);
|
||||
|
||||
void setDataDefaults() override;
|
||||
|
||||
protected:
|
||||
TPersistentData *data = nullptr;
|
||||
int warNations = 0, bombardingNations = 0;
|
||||
int mixSettlers = 0, mixCaravan = 0, mixTownGuard = 0, mixSlaves = 0, mixMilitia = 0, mixCruiser = 0;
|
||||
int oceanWithShip = 0;
|
||||
enum class AINegoCause { Routine, CheckBarbarina };
|
||||
AINegoCause negoCause = AINegoCause::Routine;
|
||||
std::array<int, maxCOD> settlerSurplus{};
|
||||
std::array<int, maxCOD> uixPatrol{};
|
||||
|
||||
// Hides Barbarina's own continentPresence/oceanPresence (same name
|
||||
// collision as the original Pascal: TAI declares its own, separate from
|
||||
// TBarbarina's private fields).
|
||||
std::array<int, maxCOD> continentPresence{};
|
||||
std::array<int, maxCOD> oceanPresence{};
|
||||
std::array<std::array<int, mctGroundAttacker - mctGroundDefender + 1>, maxCOD> unitLack{};
|
||||
|
||||
std::array<int, nPl> totalPopulation{};
|
||||
std::array<std::array<int, maxCOD>, nPl> continentPopulation{};
|
||||
std::array<int, maxCOD> districtPopulation{};
|
||||
|
||||
std::array<int, nMmax> modelCat{};
|
||||
std::array<int, nMmax> modelQuality{};
|
||||
std::array<int, nAIModelCat> modelBestQuality{};
|
||||
|
||||
std::array<int, nAdv> advanceValue{};
|
||||
bool advanceValuesSet = false;
|
||||
|
||||
void doTurn() override;
|
||||
void doNegotiation() override;
|
||||
int chooseResearchAdvance() override;
|
||||
int chooseStealAdvance() override;
|
||||
int chooseGovernment() override;
|
||||
bool wantNegotiation(int nation, NegoTime negoTime) override;
|
||||
bool onNegoRejected_CancelTreaty() override;
|
||||
|
||||
void findBestTrade(int nation, int &adWanted, int &adGiveAway);
|
||||
void checkGender();
|
||||
// Hides Barbarina::analyzeMap()/ToolAI::analyzeMap() - calls
|
||||
// Barbarina::analyzeMap() first (matches the original's `inherited;`).
|
||||
// NOTE: ToolAI::analyzeMap() (Formation[]/District[] computation) is
|
||||
// NEVER called anywhere in the original class hierarchy either - see
|
||||
// AI.cpp's comment on this for a confirmed-via-source-grep explanation
|
||||
// (genuine dead code / latent bug in upstream StdAI, ported faithfully).
|
||||
void analyzeMap();
|
||||
void collectModelCatStat();
|
||||
// Hides Barbarina::attackAndPatrol() - a completely different algorithm.
|
||||
void attackAndPatrol();
|
||||
void moveUnitsHome();
|
||||
void checkAttack(int uix);
|
||||
void patrol(int uix);
|
||||
// Hides Barbarina::barbarina_SetCityProduction() (different method name,
|
||||
// no actual collision, but still TAI's own top-level production logic).
|
||||
void setCityProduction();
|
||||
void setAdvanceValues();
|
||||
bool havePort() const;
|
||||
|
||||
void rateModel(const TModelInfo &mi, int &category, int &quality) const;
|
||||
void rateMyModel(int mix, int &category, int &quality) const;
|
||||
bool isBetterModel(const TModelInfo &mi) const;
|
||||
|
||||
void tileWorkPlan(int loc, int cix, int &value, int &nextJob, int &totalWork);
|
||||
void processSettlers();
|
||||
|
||||
int mostWanted(int nation, int adGiveAway) const;
|
||||
};
|
||||
|
||||
} // namespace Cevo
|
||||
@@ -0,0 +1,84 @@
|
||||
#pragma once
|
||||
|
||||
#include "Cevo/ToolAI.h"
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
|
||||
namespace Cevo {
|
||||
|
||||
constexpr int nModelCategory = 4;
|
||||
constexpr int ctGroundSlow = 0;
|
||||
constexpr int ctGroundFast = 1;
|
||||
constexpr int ctSeaTrans = 2;
|
||||
constexpr int ctSeaArt = 3;
|
||||
|
||||
constexpr int maxCOD = 256;
|
||||
constexpr int maxModern = 16;
|
||||
// maximum number of modern resources of one type being managed (for
|
||||
// designed maps only, number is 2 in standard game)
|
||||
|
||||
struct ColonyShipPlanPart {
|
||||
int cixProducing = -1;
|
||||
int LocResource[maxModern] = {};
|
||||
int nLocResource = 0;
|
||||
int LocFoundCity[maxModern] = {};
|
||||
int nLocFoundCity = 0;
|
||||
};
|
||||
using TColonyShipPlan = std::array<ColonyShipPlanPart, nShipPart>;
|
||||
|
||||
// C++ equivalent of Barbarina.pas's TBarbarina: the "barbarian" AI
|
||||
// personality StdAI's TAI is built directly on top of (required base class,
|
||||
// not an optional/alternate mode).
|
||||
class Barbarina : public ToolAI {
|
||||
public:
|
||||
explicit Barbarina(int nation);
|
||||
|
||||
protected:
|
||||
TColonyShipPlan ColonyShipPlan;
|
||||
|
||||
bool barbarina_GoHidden() const; // whether we should prepare for barbarina mode
|
||||
bool barbarina_Go() const; // whether we should switch to barbarina mode now
|
||||
void barbarina_DoTurn();
|
||||
void barbarina_SetCityProduction();
|
||||
int barbarina_ChooseResearchAdvance();
|
||||
bool barbarina_WantCheckNegotiation(int nation) const;
|
||||
void barbarina_DoCheckNegotiation();
|
||||
bool barbarina_WantNegotiation(int nation, NegoTime negoTime);
|
||||
void barbarina_DoNegotiation();
|
||||
void makeColonyShipPlan();
|
||||
// Hides (not overrides) ToolAI::analyzeMap(), matching the original's
|
||||
// method hiding - TBarbarina.AnalyzeMap computes continent/ocean
|
||||
// *presence* given Formation/District already populated; its own
|
||||
// `// inherited;` is commented out in the original too. Protected (not
|
||||
// private) so AI::analyzeMap() can call Barbarina::analyzeMap()
|
||||
// explicitly, mirroring the original's `inherited;`.
|
||||
void analyzeMap();
|
||||
|
||||
private:
|
||||
int turnOfMapAnalysis = -1;
|
||||
int neighbours = 0;
|
||||
std::array<int, maxCOD> continentPresence{};
|
||||
std::array<int, maxCOD> oceanPresence{};
|
||||
std::array<int, maxCOD> continentSize{};
|
||||
std::array<int, maxCOD> oceanSize{};
|
||||
std::array<int, nModelCategory> mixBest{};
|
||||
enum class NegoCauseKind { CancelTreaty };
|
||||
NegoCauseKind negoCause = NegoCauseKind::CancelTreaty;
|
||||
|
||||
bool isModelAvailable(int rmix) const;
|
||||
void findBestModels();
|
||||
void rateAttack(int uix);
|
||||
bool doAttack(int uix, int attackLoc);
|
||||
bool processMove(int uix);
|
||||
void attackAndPatrol();
|
||||
|
||||
static constexpr int neumax = 4096;
|
||||
static std::array<bool, nUmax> moved;
|
||||
static std::array<std::uint8_t, lxmax * lymax> unitPresence;
|
||||
static std::array<std::int16_t, lxmax * lymax> euixMap;
|
||||
static std::array<std::int16_t, neumax> uixAttack;
|
||||
static std::array<int, neumax> attackScore;
|
||||
};
|
||||
|
||||
} // namespace Cevo
|
||||
Reference in new issue
Block a user