1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-22 22:13:35 +02:00
vcmi/lib/CGameInterface.h

172 lines
6.7 KiB
C++
Raw Normal View History

/*
* CGameInterface.h, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#pragma once
#include "battle/AutocombatPreferences.h"
#include "battle/BattleAction.h"
#include "IGameEventsReceiver.h"
#include "spells/ViewSpellInt.h"
class CBattleCallback;
class CCallback;
VCMI_LIB_NAMESPACE_BEGIN
using boost::logic::tribool;
class Environment;
class ICallback;
class CGlobalAI;
struct Component;
struct TryMoveHero;
class CGHeroInstance;
class CGTownInstance;
class CGObjectInstance;
class CGBlackMarket;
class CGDwelling;
class CCreatureSet;
class CArmedInstance;
class IShipyard;
2010-05-18 10:01:54 +03:00
class IMarket;
struct BattleResult;
struct BattleAttack;
struct BattleStackAttacked;
struct BattleSpellCast;
struct SetStackEffect;
struct Bonus;
struct PackageApplied;
struct SetObjectProperty;
2009-09-01 16:54:13 +03:00
struct CatapultAttack;
struct StackLocation;
class CStackInstance;
class CCommanderInstance;
class CStack;
class CCreature;
class CLoadFile;
class CSaveFile;
class BinaryDeserializer;
class BinarySerializer;
2022-10-14 10:24:29 +02:00
class BattleStateInfo;
struct ArtifactLocation;
2022-10-14 10:24:29 +02:00
class BattleStateInfoForRetreat;
#if SCRIPTING_ENABLED
namespace scripting
{
class Module;
}
#endif
using TTeleportExitsList = std::vector<std::pair<ObjectInstanceID, int3>>;
class DLL_LINKAGE CBattleGameInterface : public IBattleEventsReceiver
{
public:
bool human;
2013-03-03 20:06:03 +03:00
PlayerColor playerID;
std::string dllName;
virtual ~CBattleGameInterface() {};
virtual void initBattleInterface(std::shared_ptr<Environment> ENV, std::shared_ptr<CBattleCallback> CB){};
virtual void initBattleInterface(std::shared_ptr<Environment> ENV, std::shared_ptr<CBattleCallback> CB, AutocombatPreferences autocombatPreferences){};
//battle call-ins
virtual void activeStack(const CStack * stack)=0; //called when it's turn of that stack
2023-07-18 20:43:53 +02:00
virtual void yourTacticPhase(int distance)=0; //called when interface has opportunity to use Tactics skill -> use cb->battleMakeTacticAction from this function
};
/// Central class for managing human player / AI interface logic
class DLL_LINKAGE CGameInterface : public CBattleGameInterface, public IGameEventsReceiver
{
public:
virtual ~CGameInterface() = default;
virtual void initGameInterface(std::shared_ptr<Environment> ENV, std::shared_ptr<CCallback> CB){};
virtual void yourTurn(){}; //called AFTER playerStartsTurn(player)
//pskill is gained primary skill, interface has to choose one of given skills and call callback with selection id
virtual void heroGotLevel(const CGHeroInstance *hero, PrimarySkill::PrimarySkill pskill, std::vector<SecondarySkill> &skills, QueryID queryID)=0;
2022-10-14 10:24:29 +02:00
virtual void commanderGotLevel (const CCommanderInstance * commander, std::vector<ui32> skills, QueryID queryID)=0;
// Show a dialog, player must take decision. If selection then he has to choose between one of given components,
// if cancel he is allowed to not choose. After making choice, CCallback::selectionMade should be called
// with number of selected component (1 - n) or 0 for cancel (if allowed) and askID.
virtual void showBlockingDialog(const std::string &text, const std::vector<Component> &components, QueryID askID, const int soundID, bool selection, bool cancel) = 0;
// all stacks operations between these objects become allowed, interface has to call onEnd when done
virtual void showGarrisonDialog(const CArmedInstance *up, const CGHeroInstance *down, bool removableUnits, QueryID queryID) = 0;
virtual void showTeleportDialog(TeleportChannelID channel, TTeleportExitsList exits, bool impassable, QueryID askID) = 0;
virtual void showMapObjectSelectDialog(QueryID askID, const Component & icon, const MetaString & title, const MetaString & description, const std::vector<ObjectInstanceID> & objects) = 0;
virtual void finish(){}; //if for some reason we want to end
2016-08-30 04:13:45 +02:00
virtual void showWorldViewEx(const std::vector<ObjectPosInfo> & objectPositions, bool showTerrain){};
2023-04-16 19:42:56 +02:00
virtual std::optional<BattleAction> makeSurrenderRetreatDecision(const BattleStateInfoForRetreat & battleState)
2022-10-14 10:24:29 +02:00
{
2023-04-16 19:42:56 +02:00
return std::nullopt;
2022-10-14 10:24:29 +02:00
}
virtual void saveGame(BinarySerializer & h, const int version) = 0;
virtual void loadGame(BinaryDeserializer & h, const int version) = 0;
};
class DLL_LINKAGE CDynLibHandler
{
public:
2023-03-13 23:26:44 +02:00
static std::shared_ptr<CGlobalAI> getNewAI(const std::string & dllname);
static std::shared_ptr<CBattleGameInterface> getNewBattleAI(const std::string & dllname);
#if SCRIPTING_ENABLED
static std::shared_ptr<scripting::Module> getNewScriptingModule(const boost::filesystem::path & dllname);
#endif
};
class DLL_LINKAGE CGlobalAI : public CGameInterface // AI class (to derivate)
{
public:
std::shared_ptr<Environment> env;
CGlobalAI();
};
//class to be inherited by adventure-only AIs, it cedes battle actions to given battle-AI
class DLL_LINKAGE CAdventureAI : public CGlobalAI
{
public:
2023-03-13 23:26:44 +02:00
CAdventureAI() = default;
std::shared_ptr<CBattleGameInterface> battleAI;
std::shared_ptr<CBattleCallback> cbc;
virtual std::string getBattleAIName() const = 0; //has to return name of the battle AI to be used
//battle interface
virtual void activeStack(const CStack * stack) override;
virtual void yourTacticPhase(int distance) override;
virtual void battleNewRound(int round) override;
virtual void battleCatapultAttacked(const CatapultAttack & ca) override;
virtual void battleStart(const CCreatureSet *army1, const CCreatureSet *army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2, bool side, bool replayAllowed) override;
virtual void battleStacksAttacked(const std::vector<BattleStackAttacked> & bsa, bool ranged) override;
virtual void actionStarted(const BattleAction &action) override;
virtual void battleNewRoundFirst(int round) override;
virtual void actionFinished(const BattleAction &action) override;
virtual void battleStacksEffectsSet(const SetStackEffect & sse) override;
Spells configuration version 2 (effect-based) * Indirect spell effects loading * Json serializer improvements * spell->canBeCastAt do not allow useless cast for any spell * Added proxy caster class for spell-created obstacles * Handle damage from spell-created obstacles inside mechanics * Experimental GameState integration/regression tests * Ignore mod settings and load only "vcmi" mod when running tests * fixed https://bugs.vcmi.eu/view.php?id=2765 (with tests) * Huge improvements of BattleAI regarding spell casts * AI can cast almost any combat spell except TELEPORT, SACRIFICE and obstacle placement spells. * Possible fix for https://bugs.vcmi.eu/view.php?id=1811 * CStack factored out to several classes * [Battle] Allowed RETURN_AFTER_STRIKE effect on server side to be optional * [Battle] Allowed BattleAction have multiple destinations * [Spells] Converted limit|immunity to target condition * [Spells] Use partial configuration reload for backward compatibility handling * [Tests] Started tests for CUnitState * Partial fixes of fire shield effect * [Battle] Do HP calculations in 64 bits * [BattleAI] Use threading for spell cast evaluation * [BattleAI] Made AI be able to evaluate modified turn order (on hypothetical battle state) * Implemented https://bugs.vcmi.eu/view.php?id=2811 * plug rare freeze when hypnotized unit shots vertically * Correctly apply ONLY_MELEE_FIGHT / ONLY_DISTANCE_FIGHT for unit damage, attack & defense * [BattleAI] Try to not waste a cast if battle is actually won already * Extended JsonSerializeFormat API * fixed https://bugs.vcmi.eu/view.php?id=2847 * Any unit effect can be now chained (not only damage like Chain Lightning) ** only damage effect for now actually uses "chainFactor" * Possible quick fix for https://bugs.vcmi.eu/view.php?id=2860
2017-07-20 06:08:49 +02:00
virtual void battleObstaclesChanged(const std::vector<ObstacleChanges> & obstacles) override;
virtual void battleStackMoved(const CStack * stack, std::vector<BattleHex> dest, int distance, bool teleport) override;
virtual void battleAttack(const BattleAttack *ba) override;
virtual void battleSpellCast(const BattleSpellCast *sc) override;
2023-04-06 17:34:07 +02:00
virtual void battleEnd(const BattleResult *br, QueryID queryID) override;
virtual void battleUnitsChanged(const std::vector<UnitChanges> & units) override;
virtual void saveGame(BinarySerializer & h, const int version) override;
virtual void loadGame(BinaryDeserializer & h, const int version) override;
};
VCMI_LIB_NAMESPACE_END