2017-03-17 17:48:44 +02:00
|
|
|
/*
|
|
|
|
* CStack.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
|
|
|
|
*
|
|
|
|
*/
|
2017-07-09 21:15:06 +02:00
|
|
|
|
2017-03-17 17:48:44 +02:00
|
|
|
#pragma once
|
2017-07-20 06:08:49 +02:00
|
|
|
#include "JsonNode.h"
|
|
|
|
#include "HeroBonus.h"
|
|
|
|
#include "CCreatureHandler.h" //todo: remove
|
2017-06-24 16:42:05 +02:00
|
|
|
#include "battle/BattleHex.h"
|
2017-03-17 17:48:44 +02:00
|
|
|
#include "mapObjects/CGHeroInstance.h" // for commander serialization
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
#include "battle/CUnitState.h"
|
2017-07-04 13:24:46 +02:00
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
struct BattleStackAttacked;
|
|
|
|
class BattleInfo;
|
2017-07-04 13:24:46 +02:00
|
|
|
|
2021-09-12 13:30:54 +02:00
|
|
|
//Represents STACK_BATTLE nodes
|
2017-07-20 06:08:49 +02:00
|
|
|
class DLL_LINKAGE CStack : public CBonusSystemNode, public battle::CUnitState, public battle::IUnitEnvironment
|
2017-07-04 13:24:46 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
const CStackInstance * base; //garrison slot from which stack originates (nullptr for war machines, summoned cres, etc)
|
2017-03-17 17:48:44 +02:00
|
|
|
|
|
|
|
ui32 ID; //unique ID of stack
|
2017-07-04 13:24:46 +02:00
|
|
|
const CCreature * type;
|
2022-09-29 11:44:46 +02:00
|
|
|
TerrainId nativeTerrain; //tmp variable to save native terrain value on battle init
|
2017-07-20 06:08:49 +02:00
|
|
|
ui32 baseAmount;
|
2017-07-04 13:24:46 +02:00
|
|
|
|
|
|
|
PlayerColor owner; //owner - player color (255 for neutrals)
|
2017-03-17 17:48:44 +02:00
|
|
|
SlotID slot; //slot - position in garrison (may be 255 for neutrals/called creatures)
|
2017-07-01 10:34:00 +02:00
|
|
|
ui8 side;
|
2017-07-20 06:08:49 +02:00
|
|
|
BattleHex initialPosition; //position on battlefield; -2 - keep, -3 - lower tower, -4 - upper tower
|
2017-03-17 17:48:44 +02:00
|
|
|
|
2017-07-17 23:04:00 +02:00
|
|
|
CStack(const CStackInstance * base, PlayerColor O, int I, ui8 Side, SlotID S);
|
|
|
|
CStack(const CStackBasicDescriptor * stack, PlayerColor O, int I, ui8 Side, SlotID S = SlotID(255));
|
|
|
|
CStack();
|
2017-03-17 17:48:44 +02:00
|
|
|
~CStack();
|
2017-07-04 13:24:46 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
const CCreature * getCreature() const; //deprecated
|
2017-07-04 13:24:46 +02:00
|
|
|
|
2017-03-17 17:48:44 +02:00
|
|
|
std::string nodeName() const override;
|
|
|
|
|
2017-07-04 13:24:46 +02:00
|
|
|
void localInit(BattleInfo * battleInfo);
|
2017-03-17 17:48:44 +02:00
|
|
|
std::string getName() const; //plural or singular
|
2017-07-04 13:24:46 +02:00
|
|
|
|
2017-03-17 17:48:44 +02:00
|
|
|
bool canBeHealed() const; //for first aid tent - only harmed stacks that are not war machines
|
2018-04-17 14:59:30 +02:00
|
|
|
bool isOnNativeTerrain() const;
|
2022-09-29 11:44:46 +02:00
|
|
|
bool isOnTerrain(TerrainId terrain) const;
|
2017-07-04 13:24:46 +02:00
|
|
|
|
2017-03-17 17:48:44 +02:00
|
|
|
ui32 level() const;
|
|
|
|
si32 magicResistance() const override; //include aura of resistance
|
|
|
|
std::vector<si32> activeSpells() const; //returns vector of active spell IDs sorted by time of cast
|
2017-07-04 13:24:46 +02:00
|
|
|
const CGHeroInstance * getMyHero() const; //if stack belongs to hero (directly or was by him summoned) returns hero, nullptr otherwise
|
2017-03-17 17:48:44 +02:00
|
|
|
|
2019-06-28 20:05:25 +02:00
|
|
|
static std::vector<BattleHex> meleeAttackHexes(const battle::Unit * attacker, const battle::Unit * defender, BattleHex attackerPos = BattleHex::INVALID, BattleHex defenderPos = BattleHex::INVALID);
|
2017-07-20 06:08:49 +02:00
|
|
|
static bool isMeleeAttackPossible(const battle::Unit * attacker, const battle::Unit * defender, BattleHex attackerPos = BattleHex::INVALID, BattleHex defenderPos = BattleHex::INVALID);
|
2017-03-17 17:48:44 +02:00
|
|
|
|
2017-07-01 10:34:00 +02:00
|
|
|
BattleHex::EDir destShiftDir() const;
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
void prepareAttacked(BattleStackAttacked & bsa, vstd::RNG & rand) const; //requires bsa.damageAmout filled
|
|
|
|
static void prepareAttacked(BattleStackAttacked & bsa, vstd::RNG & rand, std::shared_ptr<battle::CUnitState> customState); //requires bsa.damageAmout filled
|
2017-03-17 17:48:44 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
const CCreature * unitType() const override;
|
2017-07-09 18:49:52 +02:00
|
|
|
int32_t unitBaseAmount() const override;
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
uint32_t unitId() const override;
|
|
|
|
ui8 unitSide() const override;
|
|
|
|
PlayerColor unitOwner() const override;
|
|
|
|
SlotID unitSlot() const override;
|
2017-07-04 13:24:46 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
std::string getDescription() const override;
|
2017-07-04 13:24:46 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
bool unitHasAmmoCart(const battle::Unit * unit) const override;
|
|
|
|
PlayerColor unitEffectiveOwner(const battle::Unit * unit) const override;
|
2017-07-04 13:24:46 +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
|
|
|
void spendMana(ServerCallback * server, const int spellCost) const override;
|
2017-03-17 17:48:44 +02:00
|
|
|
|
2021-09-12 13:30:54 +02:00
|
|
|
PlayerColor getOwner() const override
|
|
|
|
{
|
|
|
|
return this->owner;
|
|
|
|
}
|
|
|
|
|
2017-07-04 13:24:46 +02:00
|
|
|
template <typename Handler> void serialize(Handler & h, const int version)
|
2017-03-17 17:48:44 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
//this assumes that stack objects is newly created
|
|
|
|
//stackState is not serialized here
|
2017-03-17 17:48:44 +02:00
|
|
|
assert(isIndependentNode());
|
2017-07-31 15:35:42 +02:00
|
|
|
h & static_cast<CBonusSystemNode&>(*this);
|
2017-07-04 13:24:46 +02:00
|
|
|
h & type;
|
2017-07-31 15:35:42 +02:00
|
|
|
h & ID;
|
|
|
|
h & baseAmount;
|
|
|
|
h & owner;
|
|
|
|
h & slot;
|
|
|
|
h & side;
|
2017-07-20 06:08:49 +02:00
|
|
|
h & initialPosition;
|
2017-03-17 17:48:44 +02:00
|
|
|
|
2017-07-09 14:49:37 +02:00
|
|
|
const CArmedInstance * army = (base ? base->armyObj : nullptr);
|
2017-03-17 17:48:44 +02:00
|
|
|
SlotID extSlot = (base ? base->armyObj->findStack(base) : SlotID());
|
|
|
|
|
|
|
|
if(h.saving)
|
|
|
|
{
|
2017-07-31 15:35:42 +02:00
|
|
|
h & army;
|
|
|
|
h & extSlot;
|
2017-03-17 17:48:44 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-07-31 15:35:42 +02:00
|
|
|
h & army;
|
|
|
|
h & extSlot;
|
2017-07-20 06:08:49 +02:00
|
|
|
|
2017-03-17 17:48:44 +02:00
|
|
|
if(extSlot == SlotID::COMMANDER_SLOT_PLACEHOLDER)
|
|
|
|
{
|
|
|
|
auto hero = dynamic_cast<const CGHeroInstance *>(army);
|
2017-07-09 14:49:37 +02:00
|
|
|
assert(hero);
|
2017-03-17 17:48:44 +02:00
|
|
|
base = hero->commander;
|
|
|
|
}
|
|
|
|
else if(slot == SlotID::SUMMONED_SLOT_PLACEHOLDER || slot == SlotID::ARROW_TOWERS_SLOT || slot == SlotID::WAR_MACHINES_SLOT)
|
|
|
|
{
|
|
|
|
//no external slot possible, so no base stack
|
|
|
|
base = nullptr;
|
|
|
|
}
|
|
|
|
else if(!army || extSlot == SlotID() || !army->hasStackAtSlot(extSlot))
|
|
|
|
{
|
|
|
|
base = nullptr;
|
2023-01-02 18:00:51 +02:00
|
|
|
logGlobal->warn("%s doesn't have a base stack!", type->getNameSingularTranslated());
|
2017-03-17 17:48:44 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
base = &army->getStack(extSlot);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-07-04 13:24:46 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
const BattleInfo * battle; //do not serialize
|
2017-03-17 17:48:44 +02:00
|
|
|
};
|
2022-07-26 15:07:42 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|