1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303
|
/*
* 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"
#include "../bonuses/BonusCache.h"
VCMI_LIB_NAMESPACE_BEGIN
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);
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;
BonusValueCache totalProxy;
};
class DLL_LINKAGE CShots : public CAmmo
{
public:
explicit CShots(const battle::Unit * Owner);
bool isLimited() const override;
int32_t total() const override;
void setEnv(const IUnitEnvironment * env_);
private:
const IUnitEnvironment * env;
BonusValueCache shooter;
};
class DLL_LINKAGE CCasts : public CAmmo
{
public:
explicit CCasts(const battle::Unit * Owner);
};
class DLL_LINKAGE CRetaliations : public CAmmo
{
public:
explicit CRetaliations(const battle::Unit * Owner);
bool isLimited() const override;
int32_t total() const override;
void reset() override;
void serializeJson(JsonSerializeFormat & handler) override;
private:
mutable int32_t totalCache;
BonusValueCache noRetaliation;
BonusValueCache unlimited;
};
class DLL_LINKAGE CHealth
{
public:
explicit CHealth(const battle::Unit * Owner);
CHealth(const CHealth & other) = default;
CHealth & operator=(const CHealth & other);
void init();
void reset();
void damage(int64_t & amount);
HealInfo heal(int64_t & amount, EHealLevel level, EHealPower power);
int32_t getCount() const;
int32_t getFirstHPleft() const;
int32_t getResurrected() const;
/// returns total remaining health
int64_t available() const;
/// returns total initial health
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;
bool castSpellThisTurn;
bool ghost;
bool ghostPending;
bool movedThisRound;
bool summoned;
bool waiting;
bool waitedThisTurn; //"waited()" that stays true for full turn after wait - needed as UI button hackfix
CCasts casts;
CRetaliations counterAttacks;
CHealth health;
CShots shots;
///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;
int32_t getCasterUnitId() const override;
int32_t getSpellSchoolLevel(const spells::Spell * spell, SpellSchool * outSelectedSchool = nullptr) const override;
int32_t getEffectLevel(const spells::Spell * spell) const override;
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;
int32_t getEffectPower(const spells::Spell * spell) const override;
int32_t getEnchantPower(const spells::Spell * spell) const override;
int64_t getEffectValue(const spells::Spell * spell) const override;
PlayerColor getCasterOwner() const override;
const CGHeroInstance * getHeroCaster() const override;
void getCasterName(MetaString & text) const override;
void getCastDescription(const spells::Spell * spell, const battle::Units & attacked, MetaString & text) const override;
int32_t manaLimit() const override;
bool ableToRetaliate() const override;
bool alive() const override;
bool isGhost() const override;
bool isFrozen() const override;
bool isValidTarget(bool allowDead = false) const override;
bool isHypnotized() const override;
bool isInvincible() const override;
bool isClone() const override;
bool hasClone() const override;
bool canCast() const override;
bool isCaster() const override;
bool canShootBlocked() 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;
uint32_t getMaxHealth() const override;
BattleHex getPosition() const override;
void setPosition(const BattleHex & hex) override;
int32_t getInitiative(int turn = 0) const override;
uint8_t getRangedFullDamageDistance() const;
uint8_t getShootingRangeDistance() const;
ui32 getMovementRange(int turn) const override;
ui32 getMovementRange() const override;
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;
BattlePhases::Type battleQueuePhase(int turn) const override;
int getTotalAttacks(bool ranged) const override;
int getMinDamage(bool ranged) const override;
int getMaxDamage(bool ranged) const override;
int getAttack(bool ranged) const override;
int getDefense(bool ranged) const override;
void save(JsonNode & data) override;
void load(const JsonNode & data) override;
void damage(int64_t & amount) override;
HealInfo heal(int64_t & amount, EHealLevel level, EHealPower power) override;
void localInit(const IUnitEnvironment * env_);
void serializeJson(JsonSerializeFormat & handler);
FactionID getFactionID() const override;
void afterAttack(bool ranged, bool counter);
void afterNewRound();
void afterGetsTurn();
void makeGhost();
void onRemoved();
private:
const IUnitEnvironment * env;
BonusCachePerTurn immobilizedPerTurn;
BonusCachePerTurn stackSpeedPerTurn;
UnitBonusValuesProxy bonusCache;
void reset();
};
class DLL_LINKAGE CUnitStateDetached final : public CUnitState
{
public:
explicit CUnitStateDetached(const IUnitInfo * unit_, const IBonusBearer * bonus_);
CUnitStateDetached & operator= (const CUnitState & other);
TConstBonusListPtr getAllBonuses(const CSelector & selector, const CSelector & limit, const std::string & cachingStr = "") const override;
int32_t getTreeVersion() const override;
uint32_t unitId() const override;
BattleSide unitSide() const override;
const CCreature * unitType() const override;
PlayerColor unitOwner() const override;
SlotID unitSlot() const override;
int32_t unitBaseAmount() const override;
void spendMana(ServerCallback * server, const int spellCost) const override;
private:
const IUnitInfo * unit;
const IBonusBearer * bonus;
};
}
VCMI_LIB_NAMESPACE_END
|