111 lines
4.1 KiB
C++
111 lines
4.1 KiB
C++
#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
|