2017-06-24 15:51:07 +02:00
/*
* CBattleInfoEssentials . 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 "CCallbackBase.h"
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
# include "IBattleInfoCallback.h"
2017-06-24 15:51:07 +02:00
2022-07-26 15:07:42 +02:00
VCMI_LIB_NAMESPACE_BEGIN
2017-06-24 15:51:07 +02:00
class CGTownInstance ;
class CGHeroInstance ;
class CStack ;
class IBonusBearer ;
struct InfoAboutHero ;
class CArmedInstance ;
2023-02-15 00:44:59 +02:00
using TStacks = std : : vector < const CStack * > ;
using TStackFilter = std : : function < bool ( const CStack * ) > ;
2017-06-24 15:51:07 +02:00
namespace BattlePerspective
{
2017-06-26 18:50:35 +02:00
enum BattlePerspective
{
INVALID = - 2 ,
ALL_KNOWING = - 1 ,
LEFT_SIDE ,
RIGHT_SIDE
} ;
2017-06-24 15:51:07 +02:00
}
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
class DLL_LINKAGE CBattleInfoEssentials : public virtual CCallbackBase , public IBattleInfoCallback
2017-06-24 15:51:07 +02:00
{
protected :
bool battleDoWeKnowAbout ( ui8 side ) const ;
2017-07-20 06:08:49 +02:00
2017-06-24 15:51:07 +02:00
public :
enum EStackOwnership
{
ONLY_MINE , ONLY_ENEMY , MINE_AND_ENEMY
} ;
BattlePerspective : : BattlePerspective battleGetMySide ( ) const ;
2017-07-20 06:08:49 +02:00
const IBonusBearer * getBattleNode ( ) const ;
2017-06-24 15:51:07 +02:00
2022-09-29 11:44:46 +02:00
TerrainId battleTerrainType ( ) const override ;
2022-06-22 10:41:02 +02:00
BattleField battleGetBattlefieldType ( ) const override ;
2017-07-20 06:08:49 +02:00
int32_t battleGetEnchanterCounter ( ui8 side ) const ;
2017-06-24 15:51:07 +02:00
std : : vector < std : : shared_ptr < const CObstacleInstance > > battleGetAllObstacles ( boost : : optional < BattlePerspective : : BattlePerspective > perspective = boost : : none ) const ; //returns all obstacles on the battlefield
2017-07-20 06:08:49 +02:00
std : : shared_ptr < const CObstacleInstance > battleGetObstacleByID ( uint32_t ID ) const ;
2017-06-24 15:51:07 +02:00
/** @brief Main method for getting battle stacks
2017-07-20 06:08:49 +02:00
* returns also turrets and removed stacks
2017-06-24 15:51:07 +02:00
* @ param predicate Functor that shall return true for desired stack
* @ return filtered stacks
*
*/
2017-07-20 06:08:49 +02:00
TStacks battleGetStacksIf ( TStackFilter predicate ) const ; //deprecated
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
battle : : Units battleGetUnitsIf ( battle : : UnitFilter predicate ) const override ;
2017-07-20 06:08:49 +02:00
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
const battle : : Unit * battleGetUnitByID ( uint32_t ID ) const override ;
const battle : : Unit * battleActiveUnit ( ) const override ;
2017-07-20 06:08:49 +02:00
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
uint32_t battleNextUnitId ( ) const override ;
2017-06-24 15:51:07 +02:00
bool battleHasNativeStack ( ui8 side ) const ;
const CGTownInstance * battleGetDefendedTown ( ) const ; //returns defended town if current battle is a siege, nullptr instead
2017-07-20 06:08:49 +02:00
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
si8 battleTacticDist ( ) const override ; //returns tactic distance in current tactics phase; 0 if not in tactics phase
si8 battleGetTacticsSide ( ) const override ; //returns which side is in tactics phase, undefined if none (?)
2023-02-15 00:44:59 +02:00
bool battleCanFlee ( const PlayerColor & player ) const ;
bool battleCanSurrender ( const PlayerColor & player ) const ;
2017-07-20 06:08:49 +02:00
2017-07-01 10:34:00 +02:00
ui8 otherSide ( ui8 side ) const ;
2023-02-15 00:44:59 +02:00
PlayerColor otherPlayer ( const PlayerColor & player ) const ;
2017-07-20 06:08:49 +02:00
2023-02-15 00:44:59 +02:00
BattleSideOpt playerToSide ( const PlayerColor & player ) const ;
2017-07-20 06:08:49 +02:00
PlayerColor sideToPlayer ( ui8 side ) const ;
2023-02-15 00:44:59 +02:00
bool playerHasAccessToHeroInfo ( const PlayerColor & player , const CGHeroInstance * h ) const ;
2017-06-24 15:51:07 +02:00
ui8 battleGetSiegeLevel ( ) const ; //returns 0 when there is no siege, 1 if fort, 2 is citadel, 3 is castle
bool battleHasHero ( ui8 side ) const ;
2017-07-20 06:08:49 +02:00
uint32_t battleCastSpells ( ui8 side ) const ; //how many spells has given side cast
const CGHeroInstance * battleGetFightingHero ( ui8 side ) const ; //deprecated for players callback, easy to get wrong
2017-06-24 15:51:07 +02:00
const CArmedInstance * battleGetArmyObject ( ui8 side ) const ;
InfoAboutHero battleGetHeroInfo ( ui8 side ) const ;
// for determining state of a part of the wall; format: parameter [0] - keep, [1] - bottom tower, [2] - bottom wall,
// [3] - below gate, [4] - over gate, [5] - upper wall, [6] - uppert tower, [7] - gate; returned value: 1 - intact, 2 - damaged, 3 - destroyed; 0 - no battle
2023-01-13 00:35:58 +02:00
EWallState battleGetWallState ( EWallPart partOfWall ) const ;
2017-06-24 15:51:07 +02:00
EGateState battleGetGateState ( ) const ;
//helpers
///returns all stacks, alive or dead or undead or mechanical :)
TStacks battleGetAllStacks ( bool includeTurrets = false ) const ;
const CStack * battleGetStackByID ( int ID , bool onlyAlive = true ) const ; //returns stack info by given ID
bool battleIsObstacleVisibleForSide ( const CObstacleInstance & coi , BattlePerspective : : BattlePerspective side ) const ;
///returns player that controls given stack; mind control included
2017-07-20 06:08:49 +02:00
PlayerColor battleGetOwner ( const battle : : Unit * unit ) const ;
2017-06-24 15:51:07 +02:00
///returns hero that controls given stack; nullptr if none; mind control included
2017-07-20 06:08:49 +02:00
const CGHeroInstance * battleGetOwnerHero ( const battle : : Unit * unit ) const ;
2017-06-24 15:51:07 +02:00
///check that stacks are controlled by same|other player(s) depending on positiveness
///mind control included
2017-07-20 06:08:49 +02:00
bool battleMatchOwner ( const battle : : Unit * attacker , const battle : : Unit * defender , const boost : : logic : : tribool positivness = false ) const ;
bool battleMatchOwner ( const PlayerColor & attacker , const battle : : Unit * defender , const boost : : logic : : tribool positivness = false ) const ;
2017-06-24 15:51:07 +02:00
} ;
2022-07-26 15:07:42 +02:00
VCMI_LIB_NAMESPACE_END