2012-12-19 17:54:10 +03:00
/*
2017-07-13 10:26:03 +02:00
* CBattleInfoCallback . h , part of VCMI engine
2012-12-19 17:54:10 +03:00
*
* 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
*
*/
2017-06-24 15:51:07 +02:00
# pragma once
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 <vcmi/spells/Magic.h>
2017-06-24 15:51:07 +02:00
# include "CCallbackBase.h"
# include "ReachabilityInfo.h"
# include "BattleAttackInfo.h"
2012-12-19 17:54:10 +03:00
2022-07-26 15:07:42 +02:00
VCMI_LIB_NAMESPACE_BEGIN
2012-08-26 12:07:48 +03:00
class CGHeroInstance ;
class CStack ;
2015-09-28 15:06:26 +02:00
class ISpellCaster ;
2023-04-12 15:20:40 +02:00
class SpellCastEnvironment ;
2012-08-26 12:07:48 +03:00
class CSpell ;
struct CObstacleInstance ;
2012-09-20 19:55:21 +03:00
class IBonusBearer ;
2016-09-09 19:30:36 +02:00
class CRandomGenerator ;
2023-03-25 00:48:14 +02:00
class PossiblePlayerBattleAction ;
2012-08-26 12:07:48 +03: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
namespace spells
{
class Caster ;
class Spell ;
}
2012-08-26 12:07:48 +03:00
struct DLL_LINKAGE AttackableTiles
{
std : : set < BattleHex > hostileCreaturePositions ;
std : : set < BattleHex > friendlyCreaturePositions ; //for Dragon Breath
template < typename Handler > void serialize ( Handler & h , const int version )
{
2017-07-31 15:35:42 +02:00
h & hostileCreaturePositions ;
h & friendlyCreaturePositions ;
2012-08-26 12:07:48 +03:00
}
} ;
2019-05-04 05:42:55 +02:00
struct DLL_LINKAGE BattleClientInterfaceData
{
2023-03-25 00:48:14 +02:00
std : : vector < SpellID > creatureSpellsToCast ;
2019-05-04 05:42:55 +02:00
ui8 tacticsMode ;
} ;
2012-08-26 12:07:48 +03:00
class DLL_LINKAGE CBattleInfoCallback : public virtual CBattleInfoEssentials
{
public :
enum ERandomSpell
{
RANDOM_GENIE , RANDOM_AIMED
} ;
2017-07-20 06:08:49 +02:00
2023-04-16 19:42:56 +02:00
std : : optional < int > battleIsFinished ( ) const override ; //return none if battle is ongoing; otherwise the victorious side (0/1) or 2 if it is a draw
2013-09-29 23:54:29 +03: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
std : : vector < std : : shared_ptr < const CObstacleInstance > > battleGetAllObstaclesOnPos ( BattleHex tile , bool onlyBlocking = true ) const override ;
2023-03-27 15:11:17 +02:00
std : : vector < std : : shared_ptr < const CObstacleInstance > > getAllAffectedObstaclesByStack ( const battle : : Unit * unit , const std : : set < BattleHex > & passed ) const override ;
2023-04-12 15:20:40 +02:00
//Handle obstacle damage here, requires SpellCastEnvironment
bool handleObstacleTriggersForUnit ( SpellCastEnvironment & spellEnv , const battle : : Unit & unit , const std : : set < BattleHex > & passed = { } ) const ;
2017-07-01 17:59:53 +02:00
2017-07-20 06:08:49 +02:00
const CStack * battleGetStackByPos ( BattleHex pos , bool onlyAlive = true ) const ;
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 * battleGetUnitByPos ( BattleHex pos , bool onlyAlive = true ) const override ;
2017-07-20 06:08:49 +02:00
///returns all alive units excluding turrets
battle : : Units battleAliveUnits ( ) const ;
///returns all alive units from particular side excluding turrets
battle : : Units battleAliveUnits ( ui8 side ) const ;
void battleGetTurnOrder ( std : : vector < battle : : Units > & out , const size_t maxUnits , const int maxTurns , const int turn = 0 , int8_t lastMoved = - 1 ) const ;
///returns reachable hexes (valid movement destinations), DOES contain stack current position
2023-04-22 21:24:03 +02:00
std : : vector < BattleHex > battleGetAvailableHexes ( const battle : : Unit * unit , bool obtainMovementRange , bool addOccupiable , std : : vector < BattleHex > * attackable ) const ;
2017-07-20 06:08:49 +02:00
///returns reachable hexes (valid movement destinations), DOES contain stack current position (lite version)
2023-04-22 21:24:03 +02:00
std : : vector < BattleHex > battleGetAvailableHexes ( const battle : : Unit * unit , bool obtainMovementRange ) const ;
2017-07-20 06:08:49 +02:00
2023-04-22 21:24:03 +02:00
std : : vector < BattleHex > battleGetAvailableHexes ( const ReachabilityInfo & cache , const battle : : Unit * unit , bool obtainMovementRange ) const ;
2012-08-26 12:07:48 +03:00
2023-02-15 00:44:59 +02:00
int battleGetSurrenderCost ( const PlayerColor & Player ) const ; //returns cost of surrendering battle, -1 if surrendering is not possible
2017-07-20 06:08:49 +02:00
ReachabilityInfo : : TDistances battleGetDistances ( const battle : : Unit * unit , BattleHex assumedPosition ) const ;
2023-04-12 00:52:12 +02:00
std : : set < BattleHex > battleGetAttackedHexes ( const battle : : Unit * attacker , BattleHex destinationTile , BattleHex attackerPos = BattleHex : : INVALID ) const ;
2023-01-12 18:07:40 +02:00
bool isEnemyUnitWithinSpecifiedRange ( BattleHex attackerPosition , const battle : : Unit * defenderUnit , unsigned int range ) const ;
2016-02-28 04:10:20 +02:00
2023-04-12 00:52:12 +02:00
bool battleCanAttack ( const battle : : Unit * stack , const battle : : Unit * target , BattleHex dest ) const ; //determines if stack with given ID can attack target at the selected destination
2017-07-20 06:08:49 +02:00
bool battleCanShoot ( const battle : : Unit * attacker , BattleHex dest ) const ; //determines if stack with given ID shoot at the selected destination
2019-06-28 20:05:25 +02:00
bool battleCanShoot ( const battle : : Unit * attacker ) const ; //determines if stack with given ID shoot in principle
2017-07-20 06:08:49 +02:00
bool battleIsUnitBlocked ( const battle : : Unit * unit ) const ; //returns true if there is neighboring enemy stack
std : : set < const battle : : Unit * > battleAdjacentUnits ( const battle : : Unit * unit ) const ;
2016-02-28 04:10:20 +02:00
2023-03-24 17:17:17 +02:00
DamageEstimation calculateDmgRange ( const BattleAttackInfo & info ) const ;
2012-08-26 12:07:48 +03:00
2023-01-14 19:01:53 +02:00
/// estimates damage dealt by attacker to defender;
/// only non-random bonuses are considered in estimation
/// returns pair <min dmg, max dmg>
2023-03-24 17:17:17 +02:00
DamageEstimation battleEstimateDamage ( const BattleAttackInfo & bai , DamageEstimation * retaliationDmg = nullptr ) const ;
DamageEstimation battleEstimateDamage ( const battle : : Unit * attacker , const battle : : Unit * defender , BattleHex attackerPosition , DamageEstimation * retaliationDmg = nullptr ) const ;
DamageEstimation battleEstimateDamage ( const battle : : Unit * attacker , const battle : : Unit * defender , int movementDistance , DamageEstimation * retaliationDmg = nullptr ) const ;
2017-07-20 06:08:49 +02:00
2023-04-12 15:19:34 +02:00
bool battleHasPenaltyOnLine ( BattleHex from , BattleHex dest , bool checkWall , bool checkMoat ) const ;
2017-07-20 06:08:49 +02:00
bool battleHasDistancePenalty ( const IBonusBearer * shooter , BattleHex shooterPosition , BattleHex destHex ) const ;
bool battleHasWallPenalty ( const IBonusBearer * shooter , BattleHex shooterPosition , BattleHex destHex ) const ;
bool battleHasShootingPenalty ( const battle : : Unit * shooter , BattleHex destHex ) const ;
2013-08-06 14:20:28 +03:00
2023-01-13 00:35:58 +02:00
BattleHex wallPartToBattleHex ( EWallPart part ) const ;
EWallPart battleHexToWallPart ( BattleHex hex ) const ; //returns part of destructible wall / gate / keep under given hex or -1 if not found
bool isWallPartPotentiallyAttackable ( EWallPart wallPart ) const ; // returns true if the wall part is potentially attackable (independent of wall state), false if not
2023-02-21 01:47:40 +02:00
bool isWallPartAttackable ( EWallPart wallPart ) const ; // returns true if the wall part is actually attackable, false if not
2013-12-08 20:54:13 +03:00
std : : vector < BattleHex > getAttackableBattleHexes ( ) const ;
2012-08-26 12:07:48 +03:00
2017-09-06 00:03:32 +02:00
si8 battleMinSpellLevel ( ui8 side ) const ; //calculates maximum spell level possible to be cast on battlefield - takes into account artifacts of both heroes; if no effects are set, 0 is returned
2015-09-16 17:28:14 +02:00
si8 battleMaxSpellLevel ( ui8 side ) const ; //calculates minimum spell level possible to be cast on battlefield - takes into account artifacts of both heroes; if no effects are set, 0 is returned
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
int32_t battleGetSpellCost ( const spells : : Spell * sp , const CGHeroInstance * caster ) const ; //returns cost of given spell
2017-07-20 06:08:49 +02:00
ESpellCastProblem : : ESpellCastProblem battleCanCastSpell ( const spells : : Caster * caster , spells : : Mode mode ) const ; //returns true if there are no general issues preventing from casting a spell
2012-08-26 12:07:48 +03:00
2016-09-09 19:30:36 +02:00
SpellID battleGetRandomStackSpell ( CRandomGenerator & rand , const CStack * stack , ERandomSpell mode ) const ;
SpellID getRandomBeneficialSpell ( CRandomGenerator & rand , const CStack * subject ) const ;
SpellID getRandomCastedSpell ( CRandomGenerator & rand , const CStack * caster ) const ; //called at the beginning of turn for Faerie Dragon
2012-08-26 12:07:48 +03:00
2019-05-04 05:42:55 +02:00
std : : vector < PossiblePlayerBattleAction > getClientActionsForStack ( const CStack * stack , const BattleClientInterfaceData & data ) ;
PossiblePlayerBattleAction getCasterAction ( const CSpell * spell , const spells : : Caster * caster , spells : : Mode mode ) const ;
2012-08-26 12:07:48 +03:00
//convenience methods using the ones above
2017-06-26 18:50:35 +02:00
bool isInTacticRange ( BattleHex dest ) const ;
2012-08-26 12:07:48 +03:00
si8 battleGetTacticDist ( ) const ; //returns tactic distance for calling player or 0 if this player is not in tactic phase (for ALL_KNOWING actual distance for tactic side)
2019-06-28 20:05:25 +02:00
AttackableTiles getPotentiallyAttackableHexes ( const battle : : Unit * attacker , BattleHex destinationTile , BattleHex attackerPos ) const ; //TODO: apply rotation to two-hex attacker
AttackableTiles getPotentiallyShootableHexes ( const battle : : Unit * attacker , BattleHex destinationTile , BattleHex attackerPos ) const ;
std : : vector < const battle : : Unit * > getAttackedBattleUnits ( const battle : : Unit * attacker , BattleHex destinationTile , bool rangedAttack , BattleHex attackerPos = BattleHex : : INVALID ) const ; //calculates range of multi-hex attacks
2017-09-04 23:32:24 +02:00
std : : set < const CStack * > getAttackedCreatures ( const CStack * attacker , BattleHex destinationTile , bool rangedAttack , BattleHex attackerPos = BattleHex : : INVALID ) const ; //calculates range of multi-hex attacks
2023-02-15 00:44:59 +02:00
bool isToReverse ( const battle : : Unit * attacker , const battle : : Unit * defender ) const ; //determines if attacker standing at attackerHex should reverse in order to attack defender
2012-08-26 12:07:48 +03:00
2017-07-20 06:08:49 +02:00
ReachabilityInfo getReachability ( const battle : : Unit * unit ) const ;
2017-06-26 18:50:35 +02:00
ReachabilityInfo getReachability ( const ReachabilityInfo : : Parameters & params ) const ;
2012-08-26 12:07:48 +03:00
AccessibilityInfo getAccesibility ( ) const ;
2017-07-20 06:08:49 +02:00
AccessibilityInfo getAccesibility ( const battle : : Unit * stack ) const ; //Hexes ocupied by stack will be marked as accessible.
2017-06-26 18:50:35 +02:00
AccessibilityInfo getAccesibility ( const std : : vector < BattleHex > & accessibleHexes ) const ; //given hexes will be marked as accessible
2017-07-20 06:08:49 +02:00
std : : pair < const battle : : Unit * , BattleHex > getNearestStack ( const battle : : Unit * closest ) const ;
2023-02-15 00:44:59 +02:00
BattleHex getAvaliableHex ( const CreatureID & creID , ui8 side , int initialPos = - 1 ) const ; //find place for adding new stack
2012-08-26 12:07:48 +03:00
protected :
2017-06-26 18:50:35 +02:00
ReachabilityInfo getFlyingReachability ( const ReachabilityInfo : : Parameters & params ) const ;
ReachabilityInfo makeBFS ( const AccessibilityInfo & accessibility , const ReachabilityInfo : : Parameters & params ) const ;
2020-11-21 22:57:01 +02:00
bool isInObstacle ( BattleHex hex , const std : : set < BattleHex > & obstacles , const ReachabilityInfo : : Parameters & params ) const ;
2012-08-26 12:07:48 +03:00
std : : set < BattleHex > getStoppers ( BattlePerspective : : BattlePerspective whichSidePerspective ) const ; //get hexes with stopping obstacles (quicksands)
} ;
2022-07-26 15:07:42 +02:00
VCMI_LIB_NAMESPACE_END