2017-07-20 06:08:49 +02:00
/*
* Unit . 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
2023-04-27 15:10:33 +02:00
# include <vcmi/Creature.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 <vcmi/spells/Caster.h>
2023-05-01 19:29:53 +02:00
# include "../bonuses/Bonus.h"
2023-04-30 18:13:55 +02:00
# include "../bonuses/IBonusBearer.h"
2017-07-20 06:08:49 +02:00
# include "IUnitInfo.h"
# include "BattleHex.h"
2022-07-26 15:07:42 +02:00
VCMI_LIB_NAMESPACE_BEGIN
2023-06-18 11:18:25 +02:00
enum class EMetaText : uint8_t ;
2023-06-17 22:52:42 +02:00
class MetaString ;
2017-07-20 06:08:49 +02:00
class JsonNode ;
class JsonSerializeFormat ;
namespace battle
{
2023-02-25 00:54:48 +02:00
2023-03-01 17:35:20 +02:00
namespace BattlePhases
2023-02-25 00:54:48 +02:00
{
2023-03-01 17:35:20 +02:00
enum Type
{
SIEGE , // turrets/catapult,
NORMAL , // normal (unmoved) creatures, other war machines,
WAIT_MORALE , // waited creatures that had morale,
WAIT , // rest of waited creatures
NUMBER_OF_PHASES // number of phases.
} ;
}
2023-02-25 00:54:48 +02:00
2024-06-09 23:54:20 +02:00
// Healed HP (also drained life) and resurrected units info
struct HealInfo
{
2024-06-11 16:47:23 +02:00
HealInfo ( ) = default ;
2024-06-09 23:54:20 +02:00
HealInfo ( int64_t healedHP , int32_t resurrected )
: healedHealthPoints ( healedHP ) , resurrectedCount ( resurrected )
{ }
2024-06-11 16:47:23 +02:00
int64_t healedHealthPoints = 0 ;
int32_t resurrectedCount = 0 ;
2024-06-09 23:54:20 +02:00
2024-06-11 16:47:23 +02:00
HealInfo & operator + = ( const HealInfo & other )
2024-06-09 23:54:20 +02:00
{
healedHealthPoints + = other . healedHealthPoints ;
resurrectedCount + = other . resurrectedCount ;
return * this ;
}
} ;
2017-07-20 06:08:49 +02:00
class CUnitState ;
2023-04-30 17:21:02 +02:00
class DLL_LINKAGE Unit : public IUnitInfo , public spells : : Caster , public virtual IBonusBearer , public ACreature
2017-07-20 06:08:49 +02:00
{
public :
virtual ~ Unit ( ) ;
virtual bool doubleWide ( ) const = 0 ;
virtual int32_t creatureIndex ( ) const = 0 ;
virtual CreatureID creatureId ( ) const = 0 ;
virtual int32_t creatureLevel ( ) const = 0 ;
virtual int32_t creatureCost ( ) const = 0 ;
virtual int32_t creatureIconIndex ( ) const = 0 ;
virtual bool ableToRetaliate ( ) const = 0 ;
virtual bool alive ( ) const = 0 ;
virtual bool isGhost ( ) const = 0 ;
2022-12-16 18:34:35 +02:00
virtual bool isFrozen ( ) const = 0 ;
2017-07-20 06:08:49 +02:00
bool isDead ( ) const ;
bool isTurret ( ) const ;
virtual bool isValidTarget ( bool allowDead = false ) const = 0 ; //non-turret non-ghost stacks (can be attacked or be object of magic effect)
virtual bool isClone ( ) const = 0 ;
virtual bool hasClone ( ) const = 0 ;
virtual bool canCast ( ) const = 0 ;
virtual bool isCaster ( ) const = 0 ;
virtual bool canShoot ( ) const = 0 ;
virtual bool isShooter ( ) const = 0 ;
2023-03-24 17:17:17 +02:00
/// returns initial size of this unit
2017-07-20 06:08:49 +02:00
virtual int32_t getCount ( ) const = 0 ;
2023-03-24 17:17:17 +02:00
/// returns remaining health of first unit
2017-07-20 06:08:49 +02:00
virtual int32_t getFirstHPleft ( ) const = 0 ;
2023-03-24 17:17:17 +02:00
/// returns total amount of killed in this unit
2017-07-20 06:08:49 +02:00
virtual int32_t getKilled ( ) const = 0 ;
2023-03-24 17:17:17 +02:00
/// returns total health that unit still has
2017-07-20 06:08:49 +02:00
virtual int64_t getAvailableHealth ( ) const = 0 ;
2023-03-24 17:17:17 +02:00
/// returns total health that unit had initially
2017-07-20 06:08:49 +02:00
virtual int64_t getTotalHealth ( ) const = 0 ;
virtual int getTotalAttacks ( bool ranged ) const = 0 ;
virtual BattleHex getPosition ( ) const = 0 ;
virtual void setPosition ( BattleHex hex ) = 0 ;
virtual int32_t getInitiative ( int turn = 0 ) const = 0 ;
virtual bool canMove ( int turn = 0 ) const = 0 ; //if stack can move
virtual bool defended ( int turn = 0 ) const = 0 ;
virtual bool moved ( int turn = 0 ) const = 0 ; //if stack was already moved this turn
virtual bool willMove ( int turn = 0 ) const = 0 ; //if stack has remaining move this turn
virtual bool waited ( int turn = 0 ) const = 0 ;
virtual std : : shared_ptr < Unit > acquire ( ) const = 0 ;
virtual std : : shared_ptr < CUnitState > acquireState ( ) const = 0 ;
2023-03-01 17:35:20 +02:00
virtual BattlePhases : : Type battleQueuePhase ( int turn ) const = 0 ;
2017-07-20 06:08:49 +02:00
virtual std : : string getDescription ( ) const ;
std : : vector < BattleHex > getSurroundingHexes ( BattleHex assumedPosition = BattleHex : : INVALID ) const ; // get six or 8 surrounding hexes depending on creature size
2020-11-28 17:11:33 +02:00
std : : vector < BattleHex > getAttackableHexes ( const Unit * attacker ) const ;
2017-07-20 06:08:49 +02:00
static std : : vector < BattleHex > getSurroundingHexes ( BattleHex position , bool twoHex , ui8 side ) ;
bool coversPos ( BattleHex position ) const ; //checks also if unit is double-wide
std : : vector < BattleHex > getHexes ( ) const ; //up to two occupied hexes, starting from front
std : : vector < BattleHex > getHexes ( BattleHex assumedPos ) const ; //up to two occupied hexes, starting from front
static std : : vector < BattleHex > getHexes ( BattleHex assumedPos , bool twoHex , ui8 side ) ;
BattleHex occupiedHex ( ) const ; //returns number of occupied hex (not the position) if stack is double wide; otherwise -1
BattleHex occupiedHex ( BattleHex assumedPos ) const ; //returns number of occupied hex (not the position) if stack is double wide and would stand on assumedPos; otherwise -1
static BattleHex occupiedHex ( BattleHex assumedPos , bool twoHex , ui8 side ) ;
///MetaStrings
2023-06-18 11:18:25 +02:00
void addText ( MetaString & text , EMetaText type , int32_t serial , const boost : : logic : : tribool & plural = boost : : logic : : indeterminate ) const ;
2017-07-20 06:08:49 +02:00
void addNameReplacement ( MetaString & text , const boost : : logic : : tribool & plural = boost : : logic : : indeterminate ) const ;
std : : string formatGeneralMessage ( const int32_t baseTextId ) const ;
int getRawSurrenderCost ( ) const ;
2023-04-09 03:03:47 +02:00
//IConstBonusProvider
2023-04-05 17:56:28 +02:00
const IBonusBearer * getBonusBearer ( ) const override ;
2017-07-20 06:08:49 +02:00
//NOTE: save could possibly be const, but this requires heavy changes to Json serialization,
//also this method should be called only after modifying object
virtual void save ( JsonNode & data ) = 0 ;
virtual void load ( const JsonNode & data ) = 0 ;
virtual void damage ( int64_t & amount ) = 0 ;
2024-06-09 23:54:20 +02:00
virtual HealInfo heal ( int64_t & amount , EHealLevel level , EHealPower power ) = 0 ;
2017-07-20 06:08:49 +02:00
} ;
class DLL_LINKAGE UnitInfo
{
public :
2023-02-15 00:44:59 +02:00
uint32_t id = 0 ;
TQuantity count = 0 ;
2017-07-20 06:08:49 +02:00
CreatureID type ;
2023-02-15 00:44:59 +02:00
ui8 side = 0 ;
2017-07-20 06:08:49 +02:00
BattleHex position ;
2023-02-15 00:44:59 +02:00
bool summoned = false ;
2017-07-20 06:08:49 +02:00
void serializeJson ( JsonSerializeFormat & handler ) ;
void save ( JsonNode & data ) ;
void load ( uint32_t id_ , const JsonNode & data ) ;
} ;
}
2022-07-26 15:07:42 +02:00
VCMI_LIB_NAMESPACE_END