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
2012-08-26 12:07:48 +03:00
class CGHeroInstance ;
class CStack ;
2015-09-28 15:06:26 +02:00
class ISpellCaster ;
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 ;
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 scripting
{
class Context ;
class Pool ;
class Script ;
}
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
enum class PossiblePlayerBattleAction // actions performed at l-click
{
INVALID = - 1 , CREATURE_INFO ,
MOVE_TACTICS , CHOOSE_TACTICS_STACK ,
MOVE_STACK , ATTACK , WALK_AND_ATTACK , ATTACK_AND_RETURN , SHOOT , //OPEN_GATE, //we can open castle gate during siege
NO_LOCATION , ANY_LOCATION , OBSTACLE , TELEPORT , SACRIFICE , RANDOM_GENIE_SPELL ,
FREE_LOCATION , //used with Force Field and Fire Wall - all tiles affected by spell must be free
CATAPULT , HEAL , RISE_DEMONS ,
AIMED_SPELL_CREATURE
} ;
struct DLL_LINKAGE BattleClientInterfaceData
{
si32 creatureSpellToCast ;
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
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
boost : : 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 ;
std : : vector < std : : shared_ptr < const CObstacleInstance > > getAllAffectedObstaclesByStack ( const battle : : Unit * unit ) const override ;
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
std : : vector < BattleHex > battleGetAvailableHexes ( const battle : : Unit * unit , bool addOccupiable , std : : vector < BattleHex > * attackable ) const ;
///returns reachable hexes (valid movement destinations), DOES contain stack current position (lite version)
std : : vector < BattleHex > battleGetAvailableHexes ( const battle : : Unit * unit ) const ;
std : : vector < BattleHex > battleGetAvailableHexes ( const ReachabilityInfo & cache , const battle : : Unit * unit ) const ;
2012-08-26 12:07:48 +03:00
2013-03-03 20:06:03 +03:00
int battleGetSurrenderCost ( 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 ;
2012-08-26 12:07:48 +03:00
std : : set < BattleHex > battleGetAttackedHexes ( const CStack * attacker , BattleHex destinationTile , BattleHex attackerPos = BattleHex : : INVALID ) const ;
2016-02-28 04:10:20 +02:00
2015-04-09 21:49:11 +02:00
bool battleCanAttack ( const CStack * stack , const CStack * 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
2017-06-26 18:50:35 +02:00
TDmgRange calculateDmgRange ( const BattleAttackInfo & info ) const ; //charge - number of hexes travelled before attack (for champion's jousting); returns pair <min dmg, max dmg>
2012-08-26 12:07:48 +03:00
2017-07-20 06:08:49 +02:00
TDmgRange battleEstimateDamage ( const BattleAttackInfo & bai , TDmgRange * retaliationDmg = nullptr ) const ; //estimates damage dealt by attacker to defender; it may be not precise especially when stack has randomly working bonuses; returns pair <min dmg, max dmg>
TDmgRange battleEstimateDamage ( const CStack * attacker , const CStack * defender , TDmgRange * retaliationDmg = nullptr ) const ; //estimates damage dealt by attacker to defender; it may be not precise especially when stack has randomly working bonuses; returns pair <min dmg, max dmg>
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
2013-12-08 20:54:13 +03:00
BattleHex wallPartToBattleHex ( EWallPart : : EWallPart part ) const ;
EWallPart : : EWallPart battleHexToWallPart ( BattleHex hex ) const ; //returns part of destructible wall / gate / keep under given hex or -1 if not found
bool isWallPartPotentiallyAttackable ( EWallPart : : EWallPart wallPart ) const ; // returns true if the wall part is potentially attackable (independent of wall state), false if not
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
2017-07-20 06:08:49 +02:00
si8 battleCanTeleportTo ( const battle : : Unit * stack , BattleHex destHex , int telportLevel ) const ; //checks if teleportation of given stack to given position can take place
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
2012-11-29 18:02:55 +03:00
bool isToReverse ( BattleHex hexFrom , BattleHex hexTo , bool curDir /*if true, creature is in attacker's direction*/ , bool toDoubleWide , bool toDir ) const ; //determines if creature should be reversed (it stands on hexFrom and should 'see' hexTo)
bool isToReverseHlp ( BattleHex hexFrom , BattleHex hexTo , bool curDir ) const ; //helper for isToReverse
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 ;
BattleHex getAvaliableHex ( 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)
} ;