2017-07-20 06:08:49 +02:00
|
|
|
/*
|
|
|
|
* CUnitState.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 "Unit.h"
|
2023-04-30 14:49:26 +02:00
|
|
|
#include "../bonuses/CBonusProxy.h"
|
2017-07-20 06:08:49 +02:00
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
class JsonSerializeFormat;
|
|
|
|
class UnitChanges;
|
|
|
|
|
|
|
|
namespace vstd
|
|
|
|
{
|
|
|
|
class RNG;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace battle
|
|
|
|
{
|
|
|
|
class CUnitState;
|
|
|
|
|
|
|
|
class DLL_LINKAGE CAmmo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit CAmmo(const battle::Unit * Owner, CSelector totalSelector);
|
|
|
|
|
|
|
|
//only copy construction is allowed for acquire(), serializeJson should be used for any other "assignment"
|
2023-02-15 00:44:59 +02:00
|
|
|
CAmmo(const CAmmo & other) = default;
|
2017-07-20 06:08:49 +02:00
|
|
|
CAmmo(CAmmo && other) = delete;
|
|
|
|
|
|
|
|
CAmmo & operator=(const CAmmo & other);
|
|
|
|
CAmmo & operator=(CAmmo && other) = delete;
|
|
|
|
|
|
|
|
int32_t available() const;
|
|
|
|
bool canUse(int32_t amount = 1) const;
|
|
|
|
virtual bool isLimited() const;
|
|
|
|
virtual void reset();
|
|
|
|
virtual int32_t total() const;
|
|
|
|
virtual void use(int32_t amount = 1);
|
|
|
|
|
|
|
|
virtual void serializeJson(JsonSerializeFormat & handler);
|
|
|
|
protected:
|
|
|
|
int32_t used;
|
|
|
|
const battle::Unit * owner;
|
|
|
|
CBonusProxy totalProxy;
|
|
|
|
};
|
|
|
|
|
|
|
|
class DLL_LINKAGE CShots : public CAmmo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit CShots(const battle::Unit * Owner);
|
2023-02-15 00:44:59 +02:00
|
|
|
CShots(const CShots & other) = default;
|
2017-07-20 06:08:49 +02:00
|
|
|
CShots & operator=(const CShots & other);
|
|
|
|
bool isLimited() const override;
|
|
|
|
int32_t total() const override;
|
|
|
|
|
|
|
|
void setEnv(const IUnitEnvironment * env_);
|
|
|
|
private:
|
|
|
|
const IUnitEnvironment * env;
|
|
|
|
|
|
|
|
CCheckProxy shooter;
|
|
|
|
};
|
|
|
|
|
|
|
|
class DLL_LINKAGE CCasts : public CAmmo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit CCasts(const battle::Unit * Owner);
|
2023-02-15 00:44:59 +02:00
|
|
|
CCasts(const CCasts & other) = default;
|
|
|
|
CCasts & operator=(const CCasts & other) = default;
|
2017-07-20 06:08:49 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class DLL_LINKAGE CRetaliations : public CAmmo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit CRetaliations(const battle::Unit * Owner);
|
2023-02-15 00:44:59 +02:00
|
|
|
CRetaliations(const CRetaliations & other) = default;
|
|
|
|
CRetaliations & operator=(const CRetaliations & other) = default;
|
2017-07-20 06:08:49 +02:00
|
|
|
bool isLimited() const override;
|
|
|
|
int32_t total() const override;
|
|
|
|
void reset() override;
|
|
|
|
|
|
|
|
void serializeJson(JsonSerializeFormat & handler) override;
|
|
|
|
private:
|
|
|
|
mutable int32_t totalCache;
|
|
|
|
|
|
|
|
CCheckProxy noRetaliation;
|
|
|
|
CCheckProxy unlimited;
|
|
|
|
};
|
|
|
|
|
|
|
|
class DLL_LINKAGE CHealth
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit CHealth(const battle::Unit * Owner);
|
2023-02-15 00:44:59 +02:00
|
|
|
CHealth(const CHealth & other) = default;
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
CHealth & operator=(const CHealth & other);
|
|
|
|
|
|
|
|
void init();
|
|
|
|
void reset();
|
|
|
|
|
|
|
|
void damage(int64_t & amount);
|
2024-06-09 23:54:20 +02:00
|
|
|
HealInfo heal(int64_t & amount, EHealLevel level, EHealPower power);
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
int32_t getCount() const;
|
|
|
|
int32_t getFirstHPleft() const;
|
|
|
|
int32_t getResurrected() const;
|
|
|
|
|
2023-03-24 17:17:17 +02:00
|
|
|
/// returns total remaining health
|
2017-07-20 06:08:49 +02:00
|
|
|
int64_t available() const;
|
2023-03-24 17:17:17 +02:00
|
|
|
|
|
|
|
/// returns total initial health
|
2017-07-20 06:08:49 +02:00
|
|
|
int64_t total() const;
|
|
|
|
|
|
|
|
void takeResurrected();
|
|
|
|
|
|
|
|
void serializeJson(JsonSerializeFormat & handler);
|
|
|
|
private:
|
|
|
|
void addResurrected(int32_t amount);
|
|
|
|
void setFromTotal(const int64_t totalHealth);
|
|
|
|
const battle::Unit * owner;
|
|
|
|
|
|
|
|
int32_t firstHPleft;
|
|
|
|
int32_t fullUnits;
|
|
|
|
int32_t resurrected;
|
|
|
|
};
|
|
|
|
|
|
|
|
class DLL_LINKAGE CUnitState : public Unit
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
bool cloned;
|
|
|
|
bool defending;
|
|
|
|
bool defendingAnim;
|
|
|
|
bool drainedMana;
|
|
|
|
bool fear;
|
|
|
|
bool hadMorale;
|
2024-09-18 21:24:27 +02:00
|
|
|
bool castSpellThisTurn;
|
2017-07-20 06:08:49 +02:00
|
|
|
bool ghost;
|
|
|
|
bool ghostPending;
|
|
|
|
bool movedThisRound;
|
|
|
|
bool summoned;
|
|
|
|
bool waiting;
|
2019-03-24 00:51:50 +02:00
|
|
|
bool waitedThisTurn; //"waited()" that stays true for full turn after wait - needed as UI button hackfix
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
CCasts casts;
|
|
|
|
CRetaliations counterAttacks;
|
|
|
|
CHealth health;
|
|
|
|
CShots shots;
|
|
|
|
|
|
|
|
CTotalsProxy totalAttacks;
|
|
|
|
|
|
|
|
CTotalsProxy minDamage;
|
|
|
|
CTotalsProxy maxDamage;
|
|
|
|
|
|
|
|
///id of alive clone of this stack clone if any
|
|
|
|
si32 cloneID;
|
|
|
|
|
|
|
|
///position on battlefield; -2 - keep, -3 - lower tower, -4 - upper tower
|
|
|
|
BattleHex position;
|
|
|
|
|
|
|
|
CUnitState();
|
|
|
|
|
|
|
|
CUnitState(const CUnitState & other) = delete;
|
|
|
|
CUnitState(CUnitState && other) = delete;
|
|
|
|
|
|
|
|
CUnitState & operator= (const CUnitState & other);
|
|
|
|
CUnitState & operator= (CUnitState && other) = delete;
|
|
|
|
|
|
|
|
bool doubleWide() const override;
|
|
|
|
|
|
|
|
int32_t creatureIndex() const override;
|
|
|
|
CreatureID creatureId() const override;
|
|
|
|
int32_t creatureLevel() const override;
|
|
|
|
int32_t creatureCost() const override;
|
|
|
|
int32_t creatureIconIndex() const override;
|
|
|
|
|
2018-03-04 10:13:07 +02:00
|
|
|
int32_t getCasterUnitId() const override;
|
|
|
|
|
2023-11-05 18:58:07 +02:00
|
|
|
int32_t getSpellSchoolLevel(const spells::Spell * spell, SpellSchool * outSelectedSchool = nullptr) const override;
|
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 getEffectLevel(const spells::Spell * spell) const override;
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
int64_t getSpellBonus(const spells::Spell * spell, int64_t base, const Unit * affectedStack) const override;
|
|
|
|
int64_t getSpecificSpellBonus(const spells::Spell * spell, int64_t base) const override;
|
|
|
|
|
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 getEffectPower(const spells::Spell * spell) const override;
|
|
|
|
int32_t getEnchantPower(const spells::Spell * spell) const override;
|
2017-07-20 06:08:49 +02:00
|
|
|
int64_t getEffectValue(const spells::Spell * spell) const override;
|
|
|
|
|
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
|
|
|
PlayerColor getCasterOwner() const override;
|
2023-04-09 23:31:41 +02:00
|
|
|
const CGHeroInstance * getHeroCaster() const override;
|
2017-07-20 06:08:49 +02:00
|
|
|
void getCasterName(MetaString & text) const override;
|
|
|
|
void getCastDescription(const spells::Spell * spell, const std::vector<const Unit *> & attacked, MetaString & text) const override;
|
2023-04-10 13:40:08 +02:00
|
|
|
int32_t manaLimit() const override;
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
bool ableToRetaliate() const override;
|
|
|
|
bool alive() const override;
|
|
|
|
bool isGhost() const override;
|
2022-12-16 18:34:35 +02:00
|
|
|
bool isFrozen() const override;
|
2017-07-20 06:08:49 +02:00
|
|
|
bool isValidTarget(bool allowDead = false) const override;
|
|
|
|
|
|
|
|
bool isClone() const override;
|
|
|
|
bool hasClone() const override;
|
|
|
|
|
|
|
|
bool canCast() const override;
|
|
|
|
bool isCaster() const override;
|
|
|
|
bool canShoot() const override;
|
|
|
|
bool isShooter() const override;
|
|
|
|
|
|
|
|
int32_t getKilled() const override;
|
|
|
|
int32_t getCount() const override;
|
|
|
|
int32_t getFirstHPleft() const override;
|
|
|
|
int64_t getAvailableHealth() const override;
|
|
|
|
int64_t getTotalHealth() const override;
|
|
|
|
|
|
|
|
BattleHex getPosition() const override;
|
|
|
|
void setPosition(BattleHex hex) override;
|
|
|
|
int32_t getInitiative(int turn = 0) const override;
|
2023-05-17 21:03:33 +02:00
|
|
|
uint8_t getRangedFullDamageDistance() const;
|
2023-06-23 19:05:15 +02:00
|
|
|
uint8_t getShootingRangeDistance() const;
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
bool canMove(int turn = 0) const override;
|
|
|
|
bool defended(int turn = 0) const override;
|
|
|
|
bool moved(int turn = 0) const override;
|
|
|
|
bool willMove(int turn = 0) const override;
|
|
|
|
bool waited(int turn = 0) const override;
|
|
|
|
|
|
|
|
std::shared_ptr<Unit> acquire() const override;
|
|
|
|
std::shared_ptr<CUnitState> acquireState() const override;
|
|
|
|
|
2023-03-01 17:35:20 +02:00
|
|
|
BattlePhases::Type battleQueuePhase(int turn) const override;
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
int getTotalAttacks(bool ranged) const override;
|
|
|
|
|
|
|
|
int getMinDamage(bool ranged) const override;
|
|
|
|
int getMaxDamage(bool ranged) const override;
|
|
|
|
|
|
|
|
int getAttack(bool ranged) const override;
|
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
|
|
|
int getDefense(bool ranged) const override;
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
void save(JsonNode & data) override;
|
|
|
|
void load(const JsonNode & data) override;
|
|
|
|
|
|
|
|
void damage(int64_t & amount) override;
|
2024-06-09 23:54:20 +02:00
|
|
|
HealInfo heal(int64_t & amount, EHealLevel level, EHealPower power) override;
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
void localInit(const IUnitEnvironment * env_);
|
|
|
|
void serializeJson(JsonSerializeFormat & handler);
|
|
|
|
|
2024-10-05 21:37:52 +02:00
|
|
|
FactionID getFactionID() const override;
|
2023-04-05 17:56:28 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
void afterAttack(bool ranged, bool counter);
|
|
|
|
|
|
|
|
void afterNewRound();
|
|
|
|
|
|
|
|
void afterGetsTurn();
|
|
|
|
|
|
|
|
void makeGhost();
|
|
|
|
|
|
|
|
void onRemoved();
|
|
|
|
|
|
|
|
private:
|
|
|
|
const IUnitEnvironment * env;
|
|
|
|
|
|
|
|
CTotalsProxy attack;
|
|
|
|
CTotalsProxy defence;
|
|
|
|
CBonusProxy inFrenzy;
|
|
|
|
|
|
|
|
CCheckProxy cloneLifetimeMarker;
|
|
|
|
|
|
|
|
void reset();
|
|
|
|
};
|
|
|
|
|
|
|
|
class DLL_LINKAGE CUnitStateDetached : public CUnitState
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit CUnitStateDetached(const IUnitInfo * unit_, const IBonusBearer * bonus_);
|
|
|
|
|
2020-10-01 07:55:41 +02:00
|
|
|
TConstBonusListPtr getAllBonuses(const CSelector & selector, const CSelector & limit,
|
2024-08-25 12:44:11 +02:00
|
|
|
const std::string & cachingStr = "") const override;
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
int64_t getTreeVersion() const override;
|
|
|
|
|
|
|
|
CUnitStateDetached & operator= (const CUnitState & other);
|
|
|
|
|
|
|
|
uint32_t unitId() const override;
|
2024-08-11 22:22:35 +02:00
|
|
|
BattleSide unitSide() const override;
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
const CCreature * unitType() const override;
|
|
|
|
PlayerColor unitOwner() const override;
|
|
|
|
|
|
|
|
SlotID unitSlot() const override;
|
|
|
|
|
|
|
|
|
|
|
|
int32_t unitBaseAmount() const override;
|
|
|
|
|
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
|
|
|
void spendMana(ServerCallback * server, const int spellCost) const override;
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
const IUnitInfo * unit;
|
|
|
|
const IBonusBearer * bonus;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
2022-07-26 15:07:42 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|