2023-10-19 16:19:09 +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 "IBattleInfoCallback.h"
2024-08-11 22:22:35 +02:00
# include "BattleSide.h"
2023-10-19 16:19:09 +02:00
VCMI_LIB_NAMESPACE_BEGIN
class CGTownInstance ;
class CGHeroInstance ;
class CStack ;
class IBonusBearer ;
struct InfoAboutHero ;
2024-08-28 21:33:56 +02:00
struct TownFortifications ;
2023-10-19 16:19:09 +02:00
class CArmedInstance ;
using TStacks = std : : vector < const CStack * > ;
using TStackFilter = std : : function < bool ( const CStack * ) > ;
class DLL_LINKAGE CBattleInfoEssentials : public IBattleInfoCallback
{
protected :
2024-08-11 22:22:35 +02:00
bool battleDoWeKnowAbout ( BattleSide side ) const ;
2023-10-19 16:19:09 +02:00
public :
enum EStackOwnership
{
ONLY_MINE , ONLY_ENEMY , MINE_AND_ENEMY
} ;
bool duringBattle ( ) const ;
2024-08-11 22:22:35 +02:00
BattleSide battleGetMySide ( ) const ;
2023-10-19 16:19:09 +02:00
const IBonusBearer * getBonusBearer ( ) const override ;
TerrainId battleTerrainType ( ) const override ;
BattleField battleGetBattlefieldType ( ) const override ;
2024-08-11 22:22:35 +02:00
int32_t battleGetEnchanterCounter ( BattleSide side ) const ;
2023-10-19 16:19:09 +02:00
2024-08-11 22:22:35 +02:00
std : : vector < std : : shared_ptr < const CObstacleInstance > > battleGetAllObstacles ( std : : optional < BattleSide > perspective = std : : nullopt ) const ; //returns all obstacles on the battlefield
2023-10-19 16:19:09 +02:00
std : : shared_ptr < const CObstacleInstance > battleGetObstacleByID ( uint32_t ID ) const ;
/** @brief Main method for getting battle stacks
* returns also turrets and removed stacks
* @ param predicate Functor that shall return true for desired stack
* @ return filtered stacks
*
*/
2023-11-18 19:43:11 +02:00
TStacks battleGetStacksIf ( const TStackFilter & predicate ) const ; //deprecated
battle : : Units battleGetUnitsIf ( const battle : : UnitFilter & predicate ) const override ;
2023-10-19 16:19:09 +02:00
const battle : : Unit * battleGetUnitByID ( uint32_t ID ) const override ;
const battle : : Unit * battleActiveUnit ( ) const override ;
uint32_t battleNextUnitId ( ) const override ;
2024-08-11 22:22:35 +02:00
bool battleHasNativeStack ( BattleSide side ) const ;
2023-10-19 16:19:09 +02:00
const CGTownInstance * battleGetDefendedTown ( ) const ; //returns defended town if current battle is a siege, nullptr instead
si8 battleTacticDist ( ) const override ; //returns tactic distance in current tactics phase; 0 if not in tactics phase
2024-08-11 22:22:35 +02:00
BattleSide battleGetTacticsSide ( ) const override ; //returns which side is in tactics phase, undefined if none (?)
2023-10-19 16:19:09 +02:00
bool battleCanFlee ( const PlayerColor & player ) const ;
bool battleCanSurrender ( const PlayerColor & player ) const ;
2024-08-11 22:22:35 +02:00
static BattleSide otherSide ( BattleSide side ) ;
2023-10-19 16:19:09 +02:00
PlayerColor otherPlayer ( const PlayerColor & player ) const ;
2024-08-11 22:22:35 +02:00
BattleSide playerToSide ( const PlayerColor & player ) const ;
PlayerColor sideToPlayer ( BattleSide side ) const ;
2023-10-19 16:19:09 +02:00
bool playerHasAccessToHeroInfo ( const PlayerColor & player , const CGHeroInstance * h ) const ;
2024-08-28 21:33:56 +02:00
TownFortifications battleGetFortifications ( ) const ;
2024-08-11 22:22:35 +02:00
bool battleHasHero ( BattleSide side ) const ;
uint32_t battleCastSpells ( BattleSide side ) const ; //how many spells has given side cast
const CGHeroInstance * battleGetFightingHero ( BattleSide side ) const ; //deprecated for players callback, easy to get wrong
const CArmedInstance * battleGetArmyObject ( BattleSide side ) const ;
InfoAboutHero battleGetHeroInfo ( BattleSide side ) const ;
2023-10-19 16:19:09 +02:00
// 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
EWallState battleGetWallState ( EWallPart partOfWall ) const ;
EGateState battleGetGateState ( ) const ;
bool battleIsGatePassable ( ) 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
2024-08-11 22:22:35 +02:00
bool battleIsObstacleVisibleForSide ( const CObstacleInstance & coi , BattleSide side ) const ;
2023-10-19 16:19:09 +02:00
///returns player that controls given stack; mind control included
PlayerColor battleGetOwner ( const battle : : Unit * unit ) const ;
///returns hero that controls given stack; nullptr if none; mind control included
const CGHeroInstance * battleGetOwnerHero ( const battle : : Unit * unit ) const ;
///check that stacks are controlled by same|other player(s) depending on positiveness
///mind control included
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 ;
} ;
VCMI_LIB_NAMESPACE_END