mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-23 22:37:55 +02:00
Apply formatting on changed files
This commit is contained in:
@@ -24,7 +24,7 @@ VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
void CArmedInstance::randomizeArmy(FactionID type)
|
||||
{
|
||||
for (auto & elem : stacks)
|
||||
for(auto & elem : stacks)
|
||||
{
|
||||
if(elem.second->randomStack)
|
||||
{
|
||||
@@ -39,16 +39,16 @@ void CArmedInstance::randomizeArmy(FactionID type)
|
||||
}
|
||||
}
|
||||
|
||||
CArmedInstance::CArmedInstance(IGameInfoCallback *cb)
|
||||
:CArmedInstance(cb, BonusNodeType::ARMY, false)
|
||||
CArmedInstance::CArmedInstance(IGameInfoCallback * cb)
|
||||
: CArmedInstance(cb, BonusNodeType::ARMY, false)
|
||||
{
|
||||
}
|
||||
|
||||
CArmedInstance::CArmedInstance(IGameInfoCallback *cb, BonusNodeType nodeType, bool isHypothetic):
|
||||
CGObjectInstance(cb),
|
||||
CBonusSystemNode(nodeType, isHypothetic),
|
||||
nonEvilAlignmentMix(this, Selector::type()(BonusType::NONEVIL_ALIGNMENT_MIX)), // Take Angelic Alliance troop-mixing freedom of non-evil units into account.
|
||||
battle(nullptr)
|
||||
CArmedInstance::CArmedInstance(IGameInfoCallback * cb, BonusNodeType nodeType, bool isHypothetic)
|
||||
: CGObjectInstance(cb)
|
||||
, CBonusSystemNode(nodeType, isHypothetic)
|
||||
, nonEvilAlignmentMix(this, Selector::type()(BonusType::NONEVIL_ALIGNMENT_MIX)) // Take Angelic Alliance troop-mixing freedom of non-evil units into account.
|
||||
, battle(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ void CArmedInstance::updateMoraleBonusFromArmy()
|
||||
return;
|
||||
|
||||
auto b = getExportedBonusList().getFirst(Selector::sourceType()(BonusSource::ARMY).And(Selector::type()(BonusType::MORALE)));
|
||||
if(!b)
|
||||
if(!b)
|
||||
{
|
||||
b = std::make_shared<Bonus>(BonusDuration::PERMANENT, BonusType::MORALE, BonusSource::ARMY, 0, BonusSourceID());
|
||||
addNewBonus(b);
|
||||
@@ -70,11 +70,11 @@ void CArmedInstance::updateMoraleBonusFromArmy()
|
||||
|
||||
for(const auto & slot : Slots())
|
||||
{
|
||||
const auto * creature = slot.second->getCreatureID().toEntity(LIBRARY);
|
||||
const auto * creature = slot.second->getCreatureID().toEntity(LIBRARY);
|
||||
|
||||
factions.insert(creature->getFactionID());
|
||||
// Check for undead flag instead of faction (undead mummies are neutral)
|
||||
if (!hasUndead)
|
||||
if(!hasUndead)
|
||||
{
|
||||
//this is costly check, let's skip it at first undead
|
||||
hasUndead |= slot.second->hasBonusOfType(BonusType::UNDEAD);
|
||||
@@ -83,16 +83,16 @@ void CArmedInstance::updateMoraleBonusFromArmy()
|
||||
|
||||
size_t factionsInArmy = factions.size(); //town garrison seems to take both sets into account
|
||||
|
||||
if (nonEvilAlignmentMix.hasBonus())
|
||||
if(nonEvilAlignmentMix.hasBonus())
|
||||
{
|
||||
size_t mixableFactions = 0;
|
||||
|
||||
for(auto f : factions)
|
||||
{
|
||||
if (LIBRARY->factions()->getById(f)->getAlignment() != EAlignment::EVIL)
|
||||
if(LIBRARY->factions()->getById(f)->getAlignment() != EAlignment::EVIL)
|
||||
mixableFactions++;
|
||||
}
|
||||
if (mixableFactions > 0)
|
||||
if(mixableFactions > 0)
|
||||
factionsInArmy -= mixableFactions - 1;
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ void CArmedInstance::updateMoraleBonusFromArmy()
|
||||
b->val = +1;
|
||||
bonusDescription.appendTextID("core.arraytxt.115"); //All troops of one alignment +1
|
||||
}
|
||||
else if (!factions.empty()) // no bonus from empty garrison
|
||||
else if(!factions.empty()) // no bonus from empty garrison
|
||||
{
|
||||
b->val = 2 - static_cast<si32>(factionsInArmy);
|
||||
bonusDescription.appendTextID("core.arraytxt.114"); //Troops of %d alignments %d
|
||||
@@ -116,7 +116,7 @@ void CArmedInstance::updateMoraleBonusFromArmy()
|
||||
|
||||
//-1 modifier for any Undead unit in army
|
||||
auto undeadModifier = getExportedBonusList().getFirst(Selector::source(BonusSource::ARMY, BonusCustomSource::undeadMoraleDebuff));
|
||||
if(hasUndead)
|
||||
if(hasUndead)
|
||||
{
|
||||
if(!undeadModifier)
|
||||
{
|
||||
@@ -127,7 +127,6 @@ void CArmedInstance::updateMoraleBonusFromArmy()
|
||||
}
|
||||
else if(undeadModifier)
|
||||
removeBonus(undeadModifier);
|
||||
|
||||
}
|
||||
|
||||
void CArmedInstance::armyChanged()
|
||||
@@ -174,7 +173,7 @@ void CArmedInstance::attachUnitsToArmy()
|
||||
elem.second->setArmy(getArmy());
|
||||
}
|
||||
|
||||
const IBonusBearer* CArmedInstance::getBonusBearer() const
|
||||
const IBonusBearer * CArmedInstance::getBonusBearer() const
|
||||
{
|
||||
return this;
|
||||
}
|
||||
@@ -187,7 +186,7 @@ void CArmedInstance::serializeJsonOptions(JsonSerializeFormat & handler)
|
||||
|
||||
TerrainId CArmedInstance::getCurrentTerrain() const
|
||||
{
|
||||
if (anchorPos().isValid())
|
||||
if(anchorPos().isValid())
|
||||
return cb->getTile(visitablePos())->getTerrainID();
|
||||
else
|
||||
return TerrainId::NONE;
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
|
||||
#include "../CGObjectInstance.h"
|
||||
|
||||
#include "../../bonuses/CBonusSystemNode.h"
|
||||
#include "../../bonuses/BonusCache.h"
|
||||
#include "../../bonuses/CBonusSystemNode.h"
|
||||
|
||||
#include <vcmi/Entity.h>
|
||||
|
||||
@@ -36,26 +36,32 @@ protected:
|
||||
virtual CBonusSystemNode & whatShouldBeAttached();
|
||||
|
||||
public:
|
||||
BattleInfo *battle; //set to the current battle, if engaged
|
||||
BattleInfo * battle; //set to the current battle, if engaged
|
||||
|
||||
void randomizeArmy(FactionID type);
|
||||
virtual void updateMoraleBonusFromArmy();
|
||||
|
||||
void armyChanged() override;
|
||||
CArmedInstance * getArmy() final { return this; }
|
||||
const CArmedInstance * getArmy() const final { return this; }
|
||||
CArmedInstance * getArmy() final
|
||||
{
|
||||
return this;
|
||||
}
|
||||
const CArmedInstance * getArmy() const final
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//IConstBonusProvider
|
||||
const IBonusBearer* getBonusBearer() const override;
|
||||
const IBonusBearer * getBonusBearer() const override;
|
||||
|
||||
void attachToBonusSystem(CGameState & gs) override;
|
||||
void detachFromBonusSystem(CGameState & gs) override;
|
||||
void restoreBonusSystem(CGameState & gs) override;
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
CArmedInstance(IGameInfoCallback *cb);
|
||||
CArmedInstance(IGameInfoCallback *cb, BonusNodeType nodeType, bool isHypothetic);
|
||||
CArmedInstance(IGameInfoCallback * cb);
|
||||
CArmedInstance(IGameInfoCallback * cb, BonusNodeType nodeType, bool isHypothetic);
|
||||
|
||||
PlayerColor getOwner() const override
|
||||
{
|
||||
@@ -66,11 +72,12 @@ public:
|
||||
|
||||
void serializeJsonOptions(JsonSerializeFormat & handler) override;
|
||||
|
||||
template <typename Handler> void serialize(Handler &h)
|
||||
template<typename Handler>
|
||||
void serialize(Handler & h)
|
||||
{
|
||||
h & static_cast<CGObjectInstance&>(*this);
|
||||
h & static_cast<CBonusSystemNode&>(*this);
|
||||
h & static_cast<CCreatureSet&>(*this);
|
||||
h & static_cast<CGObjectInstance &>(*this);
|
||||
h & static_cast<CBonusSystemNode &>(*this);
|
||||
h & static_cast<CCreatureSet &>(*this);
|
||||
|
||||
if(!h.saving && h.loadingGamestate)
|
||||
attachUnitsToArmy();
|
||||
|
||||
@@ -15,11 +15,12 @@
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
CCommanderInstance::CCommanderInstance(IGameInfoCallback *cb)
|
||||
:CStackInstance(cb)
|
||||
{}
|
||||
CCommanderInstance::CCommanderInstance(IGameInfoCallback * cb)
|
||||
: CStackInstance(cb)
|
||||
{
|
||||
}
|
||||
|
||||
CCommanderInstance::CCommanderInstance(IGameInfoCallback *cb, const CreatureID & id)
|
||||
CCommanderInstance::CCommanderInstance(IGameInfoCallback * cb, const CreatureID & id)
|
||||
: CStackInstance(cb, BonusNodeType::COMMANDER, false)
|
||||
, name("Commando")
|
||||
{
|
||||
@@ -27,16 +28,16 @@ CCommanderInstance::CCommanderInstance(IGameInfoCallback *cb, const CreatureID &
|
||||
level = 1;
|
||||
setCount(1);
|
||||
setType(nullptr);
|
||||
secondarySkills.resize (ECommander::SPELL_POWER + 1);
|
||||
secondarySkills.resize(ECommander::SPELL_POWER + 1);
|
||||
setType(id);
|
||||
//TODO - parse them
|
||||
}
|
||||
|
||||
void CCommanderInstance::setAlive (bool Alive)
|
||||
void CCommanderInstance::setAlive(bool Alive)
|
||||
{
|
||||
//TODO: helm of immortality
|
||||
alive = Alive;
|
||||
if (!alive)
|
||||
if(!alive)
|
||||
{
|
||||
removeBonusesRecursive(Bonus::UntilCommanderKilled);
|
||||
}
|
||||
@@ -49,15 +50,15 @@ bool CCommanderInstance::canGainExperience() const
|
||||
|
||||
int CCommanderInstance::getExpRank() const
|
||||
{
|
||||
return LIBRARY->heroh->level (getTotalExperience());
|
||||
return LIBRARY->heroh->level(getTotalExperience());
|
||||
}
|
||||
|
||||
int CCommanderInstance::getLevel() const
|
||||
{
|
||||
return std::max (1, getExpRank());
|
||||
return std::max(1, getExpRank());
|
||||
}
|
||||
|
||||
void CCommanderInstance::levelUp ()
|
||||
void CCommanderInstance::levelUp()
|
||||
{
|
||||
level++;
|
||||
for(const auto & bonus : LIBRARY->creh->commanderLevelPremy)
|
||||
|
||||
@@ -22,24 +22,28 @@ public:
|
||||
ui8 alive; //maybe change to bool when breaking save compatibility?
|
||||
ui8 level; //required only to count callbacks
|
||||
std::string name; // each Commander has different name
|
||||
std::vector <ui8> secondarySkills; //ID -> level
|
||||
std::set <ui8> specialSkills;
|
||||
std::vector<ui8> secondarySkills; //ID -> level
|
||||
std::set<ui8> specialSkills;
|
||||
//std::vector <CArtifactInstance *> arts;
|
||||
CCommanderInstance(IGameInfoCallback *cb);
|
||||
CCommanderInstance(IGameInfoCallback *cb, const CreatureID & id);
|
||||
void setAlive (bool alive);
|
||||
void levelUp ();
|
||||
CCommanderInstance(IGameInfoCallback * cb);
|
||||
CCommanderInstance(IGameInfoCallback * cb, const CreatureID & id);
|
||||
void setAlive(bool alive);
|
||||
void levelUp();
|
||||
|
||||
bool canGainExperience() const override;
|
||||
bool gainsLevel() const; //true if commander has lower level than should upon his experience
|
||||
ui64 getPower() const override {return 0;};
|
||||
ui64 getPower() const override
|
||||
{
|
||||
return 0;
|
||||
};
|
||||
int getExpRank() const override;
|
||||
int getLevel() const override;
|
||||
ArtBearer bearerType() const override; //from CArtifactSet
|
||||
|
||||
template <typename Handler> void serialize(Handler &h)
|
||||
template<typename Handler>
|
||||
void serialize(Handler & h)
|
||||
{
|
||||
h & static_cast<CStackInstance&>(*this);
|
||||
h & static_cast<CStackInstance &>(*this);
|
||||
h & alive;
|
||||
h & level;
|
||||
h & name;
|
||||
|
||||
@@ -18,8 +18,7 @@
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
|
||||
bool CreatureSlotComparer::operator()(const TPairCreatureSlot & lhs, const TPairCreatureSlot & rhs)
|
||||
bool CreatureSlotComparer::operator()(const TPairCreatureSlot & lhs, const TPairCreatureSlot & rhs)
|
||||
{
|
||||
return lhs.first->getAIValue() < rhs.first->getAIValue(); // Descendant order sorting
|
||||
}
|
||||
@@ -27,7 +26,7 @@ bool CreatureSlotComparer::operator()(const TPairCreatureSlot & lhs, const TPair
|
||||
const CStackInstance & CCreatureSet::operator[](const SlotID & slot) const
|
||||
{
|
||||
auto i = stacks.find(slot);
|
||||
if (i != stacks.end())
|
||||
if(i != stacks.end())
|
||||
return *i->second;
|
||||
else
|
||||
throw std::runtime_error("That slot is empty!");
|
||||
@@ -36,7 +35,7 @@ const CStackInstance & CCreatureSet::operator[](const SlotID & slot) const
|
||||
const CCreature * CCreatureSet::getCreature(const SlotID & slot) const
|
||||
{
|
||||
auto i = stacks.find(slot);
|
||||
if (i != stacks.end())
|
||||
if(i != stacks.end())
|
||||
return i->second->getCreature();
|
||||
else
|
||||
return nullptr;
|
||||
@@ -71,7 +70,7 @@ SlotID CCreatureSet::getSlotFor(const CreatureID & creature, ui32 slotsAmount) c
|
||||
return getSlotFor(creature.toCreature(), slotsAmount);
|
||||
}
|
||||
|
||||
SlotID CCreatureSet::getSlotFor(const CCreature *c, ui32 slotsAmount) const
|
||||
SlotID CCreatureSet::getSlotFor(const CCreature * c, ui32 slotsAmount) const
|
||||
{
|
||||
assert(c);
|
||||
for(const auto & elem : stacks)
|
||||
@@ -138,7 +137,6 @@ bool CCreatureSet::isCreatureBalanced(const CCreature * c, TQuantity ignoreAmoun
|
||||
if(count == ignoreAmount || count < 1)
|
||||
continue;
|
||||
|
||||
|
||||
if(count > max)
|
||||
max = count;
|
||||
if(count < min)
|
||||
@@ -151,7 +149,7 @@ bool CCreatureSet::isCreatureBalanced(const CCreature * c, TQuantity ignoreAmoun
|
||||
|
||||
SlotID CCreatureSet::getFreeSlot(ui32 slotsAmount) const
|
||||
{
|
||||
for(ui32 i=0; i<slotsAmount; i++)
|
||||
for(ui32 i = 0; i < slotsAmount; i++)
|
||||
{
|
||||
if(!vstd::contains(stacks, SlotID(i)))
|
||||
{
|
||||
@@ -179,7 +177,7 @@ std::queue<SlotID> CCreatureSet::getFreeSlotsQueue(ui32 slotsAmount) const
|
||||
{
|
||||
std::queue<SlotID> freeSlots;
|
||||
|
||||
for (ui32 i = 0; i < slotsAmount; i++)
|
||||
for(ui32 i = 0; i < slotsAmount; i++)
|
||||
{
|
||||
auto slot = SlotID(i);
|
||||
|
||||
@@ -225,7 +223,7 @@ TCreatureQueue CCreatureSet::getCreatureQueue(const SlotID & exclude) const
|
||||
|
||||
TQuantity CCreatureSet::getStackCount(const SlotID & slot) const
|
||||
{
|
||||
if (!hasStackAtSlot(slot))
|
||||
if(!hasStackAtSlot(slot))
|
||||
return 0;
|
||||
return stacks.at(slot)->getCount();
|
||||
}
|
||||
@@ -243,9 +241,9 @@ TExpType CCreatureSet::getStackAverageExperience(const SlotID & slot) const
|
||||
bool CCreatureSet::mergeableStacks(std::pair<SlotID, SlotID> & out, const SlotID & preferable) const /*looks for two same stacks, returns slot positions */
|
||||
{
|
||||
//try to match creature to our preferred stack
|
||||
if(preferable.validSlot() && vstd::contains(stacks, preferable))
|
||||
if(preferable.validSlot() && vstd::contains(stacks, preferable))
|
||||
{
|
||||
const CCreature *cr = stacks.find(preferable)->second->getCreature();
|
||||
const CCreature * cr = stacks.find(preferable)->second->getCreature();
|
||||
for(const auto & elem : stacks)
|
||||
{
|
||||
if(cr == elem.second->getType() && elem.first != preferable)
|
||||
@@ -274,7 +272,7 @@ bool CCreatureSet::mergeableStacks(std::pair<SlotID, SlotID> & out, const SlotID
|
||||
|
||||
void CCreatureSet::addToSlot(const SlotID & slot, const CreatureID & cre, TQuantity count, bool allowMerging)
|
||||
{
|
||||
const CCreature *c = cre.toCreature();
|
||||
const CCreature * c = cre.toCreature();
|
||||
|
||||
if(!hasStackAtSlot(slot))
|
||||
{
|
||||
@@ -331,15 +329,15 @@ bool CCreatureSet::needsLastStack() const
|
||||
ui64 CCreatureSet::getArmyStrength(int fortLevel) const
|
||||
{
|
||||
ui64 ret = 0;
|
||||
for (const auto& elem : stacks)
|
||||
for(const auto & elem : stacks)
|
||||
{
|
||||
ui64 powerToAdd = elem.second->getPower();
|
||||
if (fortLevel > 0)
|
||||
if(fortLevel > 0)
|
||||
{
|
||||
if (!elem.second->hasBonusOfType(BonusType::FLYING))
|
||||
if(!elem.second->hasBonusOfType(BonusType::FLYING))
|
||||
{
|
||||
powerToAdd /= fortLevel;
|
||||
if (!elem.second->hasBonusOfType(BonusType::SHOOTER))
|
||||
if(!elem.second->hasBonusOfType(BonusType::SHOOTER))
|
||||
powerToAdd /= fortLevel;
|
||||
}
|
||||
}
|
||||
@@ -351,7 +349,7 @@ ui64 CCreatureSet::getArmyStrength(int fortLevel) const
|
||||
ui64 CCreatureSet::getArmyCost() const
|
||||
{
|
||||
ui64 ret = 0;
|
||||
for (const auto& elem : stacks)
|
||||
for(const auto & elem : stacks)
|
||||
ret += elem.second->getMarketValue();
|
||||
return ret;
|
||||
}
|
||||
@@ -372,7 +370,7 @@ std::string CCreatureSet::getRoughAmount(const SlotID & slot, int mode) const
|
||||
if(settings["gameTweaks"]["numericCreaturesQuantities"].Bool())
|
||||
return CCreature::getQuantityRangeStringForId(quantity);
|
||||
|
||||
return LIBRARY->generaltexth->arraytxt[(174 + mode) + 3*(int)quantity];
|
||||
return LIBRARY->generaltexth->arraytxt[(174 + mode) + 3 * (int)quantity];
|
||||
}
|
||||
return "";
|
||||
}
|
||||
@@ -450,7 +448,8 @@ CStackInstance * CCreatureSet::getStackPtr(const SlotID & slot) const
|
||||
{
|
||||
if(hasStackAtSlot(slot))
|
||||
return stacks.find(slot)->second.get();
|
||||
else return nullptr;
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void CCreatureSet::eraseStack(const SlotID & slot)
|
||||
@@ -459,7 +458,7 @@ void CCreatureSet::eraseStack(const SlotID & slot)
|
||||
detachStack(slot);
|
||||
}
|
||||
|
||||
bool CCreatureSet::contains(const CStackInstance *stack) const
|
||||
bool CCreatureSet::contains(const CStackInstance * stack) const
|
||||
{
|
||||
if(!stack)
|
||||
return false;
|
||||
@@ -471,10 +470,10 @@ bool CCreatureSet::contains(const CStackInstance *stack) const
|
||||
return false;
|
||||
}
|
||||
|
||||
SlotID CCreatureSet::findStack(const CStackInstance *stack) const
|
||||
SlotID CCreatureSet::findStack(const CStackInstance * stack) const
|
||||
{
|
||||
const auto * h = dynamic_cast<const CGHeroInstance *>(this);
|
||||
if (h && h->getCommander() == stack)
|
||||
if(h && h->getCommander() == stack)
|
||||
return SlotID::COMMANDER_SLOT_PLACEHOLDER;
|
||||
|
||||
if(!stack)
|
||||
@@ -499,7 +498,7 @@ void CCreatureSet::putStack(const SlotID & slot, std::unique_ptr<CStackInstance>
|
||||
|
||||
void CCreatureSet::joinStack(const SlotID & slot, std::unique_ptr<CStackInstance> stack)
|
||||
{
|
||||
[[maybe_unused]] const CCreature *c = getCreature(slot);
|
||||
[[maybe_unused]] const CCreature * c = getCreature(slot);
|
||||
assert(c == stack->getType());
|
||||
assert(c);
|
||||
|
||||
@@ -530,7 +529,7 @@ void CCreatureSet::changeStackCount(const SlotID & slot, TQuantity toAdd)
|
||||
|
||||
CCreatureSet::~CCreatureSet() = default;
|
||||
|
||||
void CCreatureSet::setToArmy(CSimpleArmy &src)
|
||||
void CCreatureSet::setToArmy(CSimpleArmy & src)
|
||||
{
|
||||
clearSlots();
|
||||
while(src)
|
||||
@@ -566,12 +565,12 @@ void CCreatureSet::setStackType(const SlotID & slot, const CreatureID & type)
|
||||
armyChanged();
|
||||
}
|
||||
|
||||
bool CCreatureSet::canBeMergedWith(const CCreatureSet &cs, bool allowMergingStacks) const
|
||||
bool CCreatureSet::canBeMergedWith(const CCreatureSet & cs, bool allowMergingStacks) const
|
||||
{
|
||||
if(!allowMergingStacks)
|
||||
{
|
||||
int freeSlots = stacksCount() - GameConstants::ARMY_SIZE;
|
||||
std::set<const CCreature*> cresToAdd;
|
||||
std::set<const CCreature *> cresToAdd;
|
||||
for(const auto & elem : cs.stacks)
|
||||
{
|
||||
SlotID dest = getSlotFor(elem.second->getCreature());
|
||||
@@ -587,13 +586,13 @@ bool CCreatureSet::canBeMergedWith(const CCreatureSet &cs, bool allowMergingStac
|
||||
|
||||
//get types of creatures that need their own slot
|
||||
for(const auto & elem : cs.stacks)
|
||||
if ((j = cres.getSlotFor(elem.second->getCreature())).validSlot())
|
||||
cres.addToSlot(j, elem.second->getId(), 1, true); //merge if possible
|
||||
//cres.addToSlot(elem.first, elem.second->type->getId(), 1, true);
|
||||
if((j = cres.getSlotFor(elem.second->getCreature())).validSlot())
|
||||
cres.addToSlot(j, elem.second->getId(), 1, true); //merge if possible
|
||||
//cres.addToSlot(elem.first, elem.second->type->getId(), 1, true);
|
||||
for(const auto & elem : stacks)
|
||||
{
|
||||
if ((j = cres.getSlotFor(elem.second->getCreature())).validSlot())
|
||||
cres.addToSlot(j, elem.second->getId(), 1, true); //merge if possible
|
||||
if((j = cres.getSlotFor(elem.second->getCreature())).validSlot())
|
||||
cres.addToSlot(j, elem.second->getId(), 1, true); //merge if possible
|
||||
else
|
||||
return false; //no place found
|
||||
}
|
||||
@@ -611,22 +610,22 @@ bool CCreatureSet::hasUnits(const std::vector<CStackBasicDescriptor> & units, bo
|
||||
for(const auto & slot : Slots())
|
||||
{
|
||||
const auto & heroStack = slot.second;
|
||||
if (heroStack->getType() == reqStack.getType())
|
||||
if(heroStack->getType() == reqStack.getType())
|
||||
{
|
||||
count += heroStack->getCount();
|
||||
testedSlots += 1;
|
||||
}
|
||||
}
|
||||
if (count > reqStack.getCount())
|
||||
if(count > reqStack.getCount())
|
||||
foundExtraCreatures = true;
|
||||
|
||||
if (count < reqStack.getCount()) //not enough creatures of this kind
|
||||
if(count < reqStack.getCount()) //not enough creatures of this kind
|
||||
return false;
|
||||
}
|
||||
|
||||
if (requireLastStack)
|
||||
if(requireLastStack)
|
||||
{
|
||||
if (!foundExtraCreatures && testedSlots >= Slots().size())
|
||||
if(!foundExtraCreatures && testedSlots >= Slots().size())
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -638,16 +637,13 @@ bool CCreatureSet::hasStackAtSlot(const SlotID & slot) const
|
||||
return vstd::contains(stacks, slot);
|
||||
}
|
||||
|
||||
CCreatureSet & CCreatureSet::operator=(const CCreatureSet&cs)
|
||||
CCreatureSet & CCreatureSet::operator=(const CCreatureSet & cs)
|
||||
{
|
||||
assert(0);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void CCreatureSet::armyChanged()
|
||||
{
|
||||
|
||||
}
|
||||
void CCreatureSet::armyChanged() {}
|
||||
|
||||
void CCreatureSet::serializeJson(JsonSerializeFormat & handler, const std::string & armyFieldName, const std::optional<int> fixedSize)
|
||||
{
|
||||
@@ -657,13 +653,12 @@ void CCreatureSet::serializeJson(JsonSerializeFormat & handler, const std::strin
|
||||
handler.serializeEnum("formation", formation, NArmyFormation::names);
|
||||
auto a = handler.enterArray(armyFieldName);
|
||||
|
||||
|
||||
if(handler.saving)
|
||||
{
|
||||
size_t sz = 0;
|
||||
|
||||
for(const auto & p : stacks)
|
||||
vstd::amax(sz, p.first.getNum()+1);
|
||||
vstd::amax(sz, p.first.getNum() + 1);
|
||||
|
||||
if(fixedSize)
|
||||
vstd::amax(sz, fixedSize.value());
|
||||
|
||||
@@ -34,13 +34,13 @@ using TCreatureQueue = std::priority_queue<TPairCreatureSlot, std::vector<TPairC
|
||||
|
||||
namespace NArmyFormation
|
||||
{
|
||||
static const std::vector<std::string> names{ "wide", "tight" };
|
||||
static const std::vector<std::string> names{"wide", "tight"};
|
||||
}
|
||||
|
||||
class DLL_LINKAGE CCreatureSet : public IArmyDescriptor, public virtual Serializeable //seven combined creatures
|
||||
{
|
||||
CCreatureSet(const CCreatureSet &) = delete;
|
||||
CCreatureSet &operator=(const CCreatureSet&);
|
||||
CCreatureSet & operator=(const CCreatureSet &);
|
||||
|
||||
public:
|
||||
TSlots stacks; //slots[slot_id]->> pair(creature_id,creature_quantity)
|
||||
@@ -54,17 +54,23 @@ public:
|
||||
|
||||
const TSlots &Slots() const {return stacks;}
|
||||
|
||||
void addToSlot(const SlotID & slot, const CreatureID & cre, TQuantity count, bool allowMerging = true); //Adds stack to slot. Slot must be empty or with same type creature
|
||||
void addToSlot(const SlotID & slot, std::unique_ptr<CStackInstance> stack, bool allowMerging = true); //Adds stack to slot. Slot must be empty or with same type creature
|
||||
//Adds stack to slot. Slot must be empty or with same type creature
|
||||
void addToSlot(const SlotID & slot, const CreatureID & cre, TQuantity count, bool allowMerging = true);
|
||||
//Adds stack to slot. Slot must be empty or with same type creature
|
||||
void addToSlot(const SlotID & slot, std::unique_ptr<CStackInstance> stack, bool allowMerging = true);
|
||||
|
||||
void clearSlots() override;
|
||||
void setFormation(EArmyFormation tight);
|
||||
virtual CArmedInstance * getArmy() { return nullptr; }
|
||||
virtual const CArmedInstance * getArmy() const { return nullptr; }
|
||||
|
||||
//basic operations
|
||||
void putStack(const SlotID & slot, std::unique_ptr<CStackInstance> stack); //adds new stack to the army, slot must be empty
|
||||
void setStackCount(const SlotID & slot, TQuantity count); //stack must exist!
|
||||
std::unique_ptr<CStackInstance> detachStack(const SlotID & slot); //removes stack from army but doesn't destroy it (so it can be moved somewhere else or safely deleted)
|
||||
//adds new stack to the army, slot must be empty
|
||||
void putStack(const SlotID & slot, std::unique_ptr<CStackInstance> stack);
|
||||
//stack must exist!
|
||||
void setStackCount(const SlotID & slot, TQuantity count);
|
||||
//removes stack from army but doesn't destroy it (so it can be moved somewhere else or safely deleted)
|
||||
std::unique_ptr<CStackInstance> detachStack(const SlotID & slot);
|
||||
|
||||
void setStackType(const SlotID & slot, const CreatureID & type);
|
||||
|
||||
/// Give specified amount of experience to all units in army
|
||||
@@ -86,9 +92,14 @@ public:
|
||||
/// Slot must be non-empty and contain more units that split quantity
|
||||
std::unique_ptr<CStackInstance> splitStack(const SlotID & slot, TQuantity toSplit);
|
||||
|
||||
void changeStackCount(const SlotID & slot, TQuantity toAdd); //stack must exist!
|
||||
bool setCreature (SlotID slot, CreatureID type, TQuantity quantity) override; //replaces creature in stack; slots 0 to 6, if quantity=0 erases stack
|
||||
void setToArmy(CSimpleArmy &src); //erases all our army and moves stacks from src to us; src MUST NOT be an armed object! WARNING: use it wisely. Or better do not use at all.
|
||||
//stack must exist!
|
||||
void changeStackCount(const SlotID & slot, TQuantity toAdd);
|
||||
|
||||
//replaces creature in stack; slots 0 to 6, if quantity=0 erases stack
|
||||
bool setCreature(SlotID slot, CreatureID type, TQuantity quantity) override;
|
||||
|
||||
//erases all our army and moves stacks from src to us; src MUST NOT be an armed object! WARNING: use it wisely. Or better do not use at all.
|
||||
void setToArmy(CSimpleArmy & src);
|
||||
|
||||
const CStackInstance & getStack(const SlotID & slot) const; //stack must exist
|
||||
CStackInstance * getStackPtr(const SlotID & slot) const; //if stack doesn't exist, returns nullptr
|
||||
@@ -96,12 +107,12 @@ public:
|
||||
int getStackCount(const SlotID & slot) const;
|
||||
TExpType getStackTotalExperience(const SlotID & slot) const;
|
||||
TExpType getStackAverageExperience(const SlotID & slot) const;
|
||||
SlotID findStack(const CStackInstance *stack) const; //-1 if none
|
||||
SlotID findStack(const CStackInstance * stack) const; //-1 if none
|
||||
SlotID getSlotFor(const CreatureID & creature, ui32 slotsAmount = GameConstants::ARMY_SIZE) const; //returns -1 if no slot available
|
||||
SlotID getSlotFor(const CCreature *c, ui32 slotsAmount = GameConstants::ARMY_SIZE) const; //returns -1 if no slot available
|
||||
SlotID getSlotFor(const CCreature * c, ui32 slotsAmount = GameConstants::ARMY_SIZE) const; //returns -1 if no slot available
|
||||
bool hasCreatureSlots(const CCreature * c, const SlotID & exclude) const;
|
||||
std::vector<SlotID> getCreatureSlots(const CCreature * c, const SlotID & exclude, TQuantity ignoreAmount = -1) const;
|
||||
bool isCreatureBalanced(const CCreature* c, TQuantity ignoreAmount = 1) const; // Check if the creature is evenly distributed across slots
|
||||
bool isCreatureBalanced(const CCreature * c, TQuantity ignoreAmount = 1) const; // Check if the creature is evenly distributed across slots
|
||||
|
||||
SlotID getFreeSlot(ui32 slotsAmount = GameConstants::ARMY_SIZE) const; //returns first free slot
|
||||
std::vector<SlotID> getFreeSlots(ui32 slotsAmount = GameConstants::ARMY_SIZE) const;
|
||||
@@ -122,15 +133,16 @@ public:
|
||||
std::string getArmyDescription() const;
|
||||
bool hasStackAtSlot(const SlotID & slot) const;
|
||||
|
||||
bool contains(const CStackInstance *stack) const;
|
||||
bool canBeMergedWith(const CCreatureSet &cs, bool allowMergingStacks = true) const;
|
||||
bool contains(const CStackInstance * stack) const;
|
||||
bool canBeMergedWith(const CCreatureSet & cs, bool allowMergingStacks = true) const;
|
||||
|
||||
/// Returns true if this creature set contains all listed units
|
||||
/// If requireLastStack is true, then this function will also
|
||||
/// require presence of any unit other than requested (or more units than requested)
|
||||
bool hasUnits(const std::vector<CStackBasicDescriptor> & units, bool requireLastStack = true) const;
|
||||
|
||||
template <typename Handler> void serialize(Handler &h)
|
||||
template<typename Handler>
|
||||
void serialize(Handler & h)
|
||||
{
|
||||
h & stacks;
|
||||
h & formation;
|
||||
|
||||
@@ -44,8 +44,8 @@ public:
|
||||
return !army.empty();
|
||||
}
|
||||
|
||||
|
||||
template <typename Handler> void serialize(Handler &h)
|
||||
template<typename Handler>
|
||||
void serialize(Handler & h)
|
||||
{
|
||||
h & army;
|
||||
}
|
||||
|
||||
@@ -19,14 +19,15 @@ VCMI_LIB_NAMESPACE_BEGIN
|
||||
//This constructor should be placed here to avoid side effects
|
||||
CStackBasicDescriptor::CStackBasicDescriptor() = default;
|
||||
|
||||
CStackBasicDescriptor::CStackBasicDescriptor(const CreatureID & id, TQuantity Count):
|
||||
typeID(id),
|
||||
count(Count)
|
||||
CStackBasicDescriptor::CStackBasicDescriptor(const CreatureID & id, TQuantity Count)
|
||||
: typeID(id)
|
||||
, count(Count)
|
||||
{
|
||||
}
|
||||
|
||||
CStackBasicDescriptor::CStackBasicDescriptor(const CCreature *c, TQuantity Count)
|
||||
: typeID(c ? c->getId() : CreatureID()), count(Count)
|
||||
CStackBasicDescriptor::CStackBasicDescriptor(const CCreature * c, TQuantity Count)
|
||||
: typeID(c ? c->getId() : CreatureID())
|
||||
, count(Count)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -61,7 +62,7 @@ void CStackBasicDescriptor::setCount(TQuantity newCount)
|
||||
count = newCount;
|
||||
}
|
||||
|
||||
bool operator== (const CStackBasicDescriptor & l, const CStackBasicDescriptor & r)
|
||||
bool operator==(const CStackBasicDescriptor & l, const CStackBasicDescriptor & r)
|
||||
{
|
||||
return l.typeID == r.typeID && l.count == r.count;
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ class DLL_LINKAGE CStackBasicDescriptor
|
||||
public:
|
||||
CStackBasicDescriptor();
|
||||
CStackBasicDescriptor(const CreatureID & id, TQuantity Count);
|
||||
CStackBasicDescriptor(const CCreature *c, TQuantity Count);
|
||||
CStackBasicDescriptor(const CCreature * c, TQuantity Count);
|
||||
virtual ~CStackBasicDescriptor() = default;
|
||||
|
||||
const Creature * getType() const;
|
||||
@@ -39,9 +39,10 @@ public:
|
||||
virtual void setType(const CCreature * c);
|
||||
virtual void setCount(TQuantity amount);
|
||||
|
||||
friend bool operator== (const CStackBasicDescriptor & l, const CStackBasicDescriptor & r);
|
||||
friend bool operator==(const CStackBasicDescriptor & l, const CStackBasicDescriptor & r);
|
||||
|
||||
template <typename Handler> void serialize(Handler &h)
|
||||
template<typename Handler>
|
||||
void serialize(Handler & h)
|
||||
{
|
||||
if(h.saving)
|
||||
{
|
||||
|
||||
@@ -23,11 +23,12 @@
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
CStackInstance::CStackInstance(IGameInfoCallback *cb)
|
||||
CStackInstance::CStackInstance(IGameInfoCallback * cb)
|
||||
: CStackInstance(cb, BonusNodeType::STACK_INSTANCE, false)
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
CStackInstance::CStackInstance(IGameInfoCallback *cb, BonusNodeType nodeType, bool isHypothetic)
|
||||
CStackInstance::CStackInstance(IGameInfoCallback * cb, BonusNodeType nodeType, bool isHypothetic)
|
||||
: CBonusSystemNode(nodeType, isHypothetic)
|
||||
, CStackBasicDescriptor(nullptr, 0)
|
||||
, CArtifactSet(cb)
|
||||
@@ -35,9 +36,10 @@ CStackInstance::CStackInstance(IGameInfoCallback *cb, BonusNodeType nodeType, bo
|
||||
, nativeTerrain(this, Selector::type()(BonusType::TERRAIN_NATIVE))
|
||||
, initiative(this, Selector::type()(BonusType::STACKS_SPEED))
|
||||
, totalExperience(0)
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
CStackInstance::CStackInstance(IGameInfoCallback *cb, const CreatureID & id, TQuantity Count, bool isHypothetic)
|
||||
CStackInstance::CStackInstance(IGameInfoCallback * cb, const CreatureID & id, TQuantity Count, bool isHypothetic)
|
||||
: CStackInstance(cb, BonusNodeType::STACK_INSTANCE, false)
|
||||
{
|
||||
setType(id);
|
||||
@@ -51,14 +53,14 @@ CCreature::CreatureQuantityId CStackInstance::getQuantityID() const
|
||||
|
||||
int CStackInstance::getExpRank() const
|
||||
{
|
||||
if (!LIBRARY->engineSettings()->getBoolean(EGameSettings::MODULE_STACK_EXPERIENCE))
|
||||
if(!LIBRARY->engineSettings()->getBoolean(EGameSettings::MODULE_STACK_EXPERIENCE))
|
||||
return 0;
|
||||
int tier = getType()->getLevel();
|
||||
if (vstd::iswithin(tier, 1, 7))
|
||||
if(vstd::iswithin(tier, 1, 7))
|
||||
{
|
||||
for(int i = static_cast<int>(LIBRARY->creh->expRanks[tier].size()) - 2; i > -1; --i) //sic!
|
||||
{ //exp values vary from 1st level to max exp at 11th level
|
||||
if (getAverageExperience() >= LIBRARY->creh->expRanks[tier][i])
|
||||
if(getAverageExperience() >= LIBRARY->creh->expRanks[tier][i])
|
||||
return ++i; //faster, but confusing - 0 index mean 1st level of experience
|
||||
}
|
||||
return 0;
|
||||
@@ -67,7 +69,7 @@ int CStackInstance::getExpRank() const
|
||||
{
|
||||
for(int i = static_cast<int>(LIBRARY->creh->expRanks[0].size()) - 2; i > -1; --i)
|
||||
{
|
||||
if (getAverageExperience() >= LIBRARY->creh->expRanks[0][i])
|
||||
if(getAverageExperience() >= LIBRARY->creh->expRanks[0][i])
|
||||
return ++i;
|
||||
}
|
||||
return 0;
|
||||
@@ -81,25 +83,25 @@ int CStackInstance::getLevel() const
|
||||
|
||||
void CStackInstance::giveAverageStackExperience(TExpType desiredAmountPerUnit)
|
||||
{
|
||||
if (!canGainExperience())
|
||||
if(!canGainExperience())
|
||||
return;
|
||||
|
||||
int level = std::clamp(getLevel(), 1, 7);
|
||||
TExpType maxAmountPerUnit = LIBRARY->creh->expRanks[level].back();
|
||||
TExpType actualAmountPerUnit = std::min(desiredAmountPerUnit, maxAmountPerUnit * LIBRARY->creh->maxExpPerBattle[level]/100);
|
||||
TExpType actualAmountPerUnit = std::min(desiredAmountPerUnit, maxAmountPerUnit * LIBRARY->creh->maxExpPerBattle[level] / 100);
|
||||
TExpType maxExperience = maxAmountPerUnit * getCount();
|
||||
TExpType maxExperienceToGain = maxExperience - totalExperience;
|
||||
TExpType actualGainedExperience = std::min(maxExperienceToGain, actualAmountPerUnit * getCount());
|
||||
|
||||
totalExperience += actualGainedExperience;
|
||||
totalExperience += actualGainedExperience;
|
||||
}
|
||||
|
||||
void CStackInstance::giveTotalStackExperience(TExpType experienceToGive)
|
||||
{
|
||||
if (!canGainExperience())
|
||||
if(!canGainExperience())
|
||||
return;
|
||||
|
||||
totalExperience += experienceToGive;
|
||||
totalExperience += experienceToGive;
|
||||
}
|
||||
|
||||
TExpType CStackInstance::getTotalExperience() const
|
||||
@@ -119,18 +121,18 @@ bool CStackInstance::canGainExperience() const
|
||||
|
||||
void CStackInstance::setType(const CreatureID & creID)
|
||||
{
|
||||
if (creID == CreatureID::NONE)
|
||||
setType(nullptr);//FIXME: unused branch?
|
||||
if(creID == CreatureID::NONE)
|
||||
setType(nullptr); //FIXME: unused branch?
|
||||
else
|
||||
setType(creID.toCreature());
|
||||
}
|
||||
|
||||
void CStackInstance::setType(const CCreature *c)
|
||||
void CStackInstance::setType(const CCreature * c)
|
||||
{
|
||||
if(getCreature())
|
||||
{
|
||||
detachFromSource(*getCreature());
|
||||
if (LIBRARY->engineSettings()->getBoolean(EGameSettings::MODULE_STACK_EXPERIENCE))
|
||||
if(LIBRARY->engineSettings()->getBoolean(EGameSettings::MODULE_STACK_EXPERIENCE))
|
||||
totalExperience = totalExperience * LIBRARY->creh->expAfterUpgrade / 100;
|
||||
}
|
||||
|
||||
@@ -144,7 +146,7 @@ void CStackInstance::setCount(TQuantity newCount)
|
||||
{
|
||||
assert(newCount >= 0);
|
||||
|
||||
if (newCount < getCount())
|
||||
if(newCount < getCount())
|
||||
{
|
||||
TExpType averageExperience = totalExperience / getCount();
|
||||
totalExperience = averageExperience * newCount;
|
||||
@@ -154,9 +156,9 @@ void CStackInstance::setCount(TQuantity newCount)
|
||||
nodeHasChanged();
|
||||
}
|
||||
|
||||
std::string CStackInstance::bonusToString(const std::shared_ptr<Bonus>& bonus) const
|
||||
std::string CStackInstance::bonusToString(const std::shared_ptr<Bonus> & bonus) const
|
||||
{
|
||||
if (!bonus->description.empty())
|
||||
if(!bonus->description.empty())
|
||||
return bonus->description.toString();
|
||||
else
|
||||
return LIBRARY->getBth()->bonusToString(bonus, this);
|
||||
@@ -164,7 +166,7 @@ std::string CStackInstance::bonusToString(const std::shared_ptr<Bonus>& bonus) c
|
||||
|
||||
ImagePath CStackInstance::bonusToGraphics(const std::shared_ptr<Bonus> & bonus) const
|
||||
{
|
||||
if (!bonus->customIconPath.empty())
|
||||
if(!bonus->customIconPath.empty())
|
||||
return bonus->customIconPath;
|
||||
return LIBRARY->getBth()->bonusToGraphics(bonus);
|
||||
}
|
||||
@@ -191,7 +193,7 @@ void CStackInstance::setArmy(CArmedInstance * ArmyObj)
|
||||
|
||||
if(ArmyObj)
|
||||
{
|
||||
attachTo(const_cast<CArmedInstance&>(*ArmyObj));
|
||||
attachTo(const_cast<CArmedInstance &>(*ArmyObj));
|
||||
armyInstance = ArmyObj;
|
||||
}
|
||||
}
|
||||
@@ -200,12 +202,12 @@ std::string CStackInstance::getQuantityTXT(bool capitalized) const
|
||||
{
|
||||
CCreature::CreatureQuantityId quantity = getQuantityID();
|
||||
|
||||
if ((int)quantity)
|
||||
if((int)quantity)
|
||||
{
|
||||
if(settings["gameTweaks"]["numericCreaturesQuantities"].Bool())
|
||||
return CCreature::getQuantityRangeStringForId(quantity);
|
||||
|
||||
return LIBRARY->generaltexth->arraytxt[174 + (int)quantity*3 - 1 - capitalized];
|
||||
return LIBRARY->generaltexth->arraytxt[174 + (int)quantity * 3 - 1 - capitalized];
|
||||
}
|
||||
else
|
||||
return "";
|
||||
@@ -241,7 +243,7 @@ PlayerColor CStackInstance::getOwner() const
|
||||
|
||||
int32_t CStackInstance::getInitiative(int turn) const
|
||||
{
|
||||
if (turn == 0)
|
||||
if(turn == 0)
|
||||
return initiative.getValue();
|
||||
|
||||
return ACreature::getInitiative(turn);
|
||||
@@ -249,7 +251,7 @@ int32_t CStackInstance::getInitiative(int turn) const
|
||||
|
||||
TerrainId CStackInstance::getNativeTerrain() const
|
||||
{
|
||||
if (nativeTerrain.hasBonus())
|
||||
if(nativeTerrain.hasBonus())
|
||||
return TerrainId::ANY_TERRAIN;
|
||||
|
||||
return getFactionID().toEntity(LIBRARY)->getNativeTerrain();
|
||||
@@ -311,7 +313,7 @@ void CStackInstance::removeArtifact(const ArtifactPosition & pos)
|
||||
void CStackInstance::serializeJson(JsonSerializeFormat & handler)
|
||||
{
|
||||
//todo: artifacts
|
||||
CStackBasicDescriptor::serializeJson(handler);//must be first
|
||||
CStackBasicDescriptor::serializeJson(handler); //must be first
|
||||
|
||||
if(handler.saving)
|
||||
{
|
||||
@@ -335,7 +337,7 @@ void CStackInstance::serializeJson(JsonSerializeFormat & handler)
|
||||
handler.serializeInt("level", level, 0);
|
||||
handler.serializeInt("upgrade", upgrade, 0);
|
||||
|
||||
randomStack = RandomStackInfo{ level, upgrade };
|
||||
randomStack = RandomStackInfo{level, upgrade};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -348,7 +350,7 @@ FactionID CStackInstance::getFactionID() const
|
||||
return FactionID::NEUTRAL;
|
||||
}
|
||||
|
||||
const IBonusBearer* CStackInstance::getBonusBearer() const
|
||||
const IBonusBearer * CStackInstance::getBonusBearer() const
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
#include "bonuses/BonusCache.h"
|
||||
#include "bonuses/CBonusSystemNode.h"
|
||||
#include "callback/GameCallbackHolder.h"
|
||||
#include "mapObjects/CGObjectInstance.h"
|
||||
#include "entities/artifact/CArtifactSet.h"
|
||||
#include "mapObjects/CGObjectInstance.h"
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
@@ -34,9 +34,12 @@ class DLL_LINKAGE CStackInstance : public CBonusSystemNode, public CStackBasicDe
|
||||
|
||||
CArmedInstance * armyInstance = nullptr; //stack must be part of some army, army must be part of some object
|
||||
|
||||
IGameInfoCallback * getCallback() const final { return cb; }
|
||||
IGameInfoCallback * getCallback() const final
|
||||
{
|
||||
return cb;
|
||||
}
|
||||
|
||||
TExpType totalExperience;//commander needs same amount of exp as hero
|
||||
TExpType totalExperience; //commander needs same amount of exp as hero
|
||||
public:
|
||||
struct RandomStackInfo
|
||||
{
|
||||
@@ -48,23 +51,24 @@ public:
|
||||
|
||||
CArmedInstance * getArmy();
|
||||
const CArmedInstance * getArmy() const; //stack must be part of some army, army must be part of some object
|
||||
void setArmy(CArmedInstance *ArmyObj);
|
||||
void setArmy(CArmedInstance * ArmyObj);
|
||||
|
||||
TExpType getTotalExperience() const;
|
||||
TExpType getAverageExperience() const;
|
||||
virtual bool canGainExperience() const;
|
||||
|
||||
template <typename Handler> void serialize(Handler &h)
|
||||
template<typename Handler>
|
||||
void serialize(Handler & h)
|
||||
{
|
||||
h & static_cast<CBonusSystemNode&>(*this);
|
||||
h & static_cast<CStackBasicDescriptor&>(*this);
|
||||
h & static_cast<CArtifactSet&>(*this);
|
||||
h & static_cast<CBonusSystemNode &>(*this);
|
||||
h & static_cast<CStackBasicDescriptor &>(*this);
|
||||
h & static_cast<CArtifactSet &>(*this);
|
||||
|
||||
if (h.hasFeature(Handler::Version::STACK_INSTANCE_ARMY_FIX))
|
||||
if(h.hasFeature(Handler::Version::STACK_INSTANCE_ARMY_FIX))
|
||||
{
|
||||
// no-op
|
||||
}
|
||||
if (h.hasFeature(Handler::Version::NO_RAW_POINTERS_IN_SERIALIZER))
|
||||
if(h.hasFeature(Handler::Version::NO_RAW_POINTERS_IN_SERIALIZER))
|
||||
{
|
||||
ObjectInstanceID dummyID;
|
||||
h & dummyID;
|
||||
@@ -76,7 +80,7 @@ public:
|
||||
}
|
||||
|
||||
h & totalExperience;
|
||||
if (!h.hasFeature(Handler::Version::STACK_INSTANCE_EXPERIENCE_FIX))
|
||||
if(!h.hasFeature(Handler::Version::STACK_INSTANCE_EXPERIENCE_FIX))
|
||||
{
|
||||
totalExperience *= getCount();
|
||||
}
|
||||
@@ -85,11 +89,11 @@ public:
|
||||
void serializeJson(JsonSerializeFormat & handler);
|
||||
|
||||
//overrides CBonusSystemNode
|
||||
std::string bonusToString(const std::shared_ptr<Bonus>& bonus) const override; // how would bonus description look for this particular type of node
|
||||
std::string bonusToString(const std::shared_ptr<Bonus> & bonus) const override; // how would bonus description look for this particular type of node
|
||||
ImagePath bonusToGraphics(const std::shared_ptr<Bonus> & bonus) const; //file name of graphics from StackSkills , in future possibly others
|
||||
|
||||
//IConstBonusProvider
|
||||
const IBonusBearer* getBonusBearer() const override;
|
||||
const IBonusBearer * getBonusBearer() const override;
|
||||
//INativeTerrainProvider
|
||||
FactionID getFactionID() const override;
|
||||
|
||||
@@ -102,9 +106,9 @@ public:
|
||||
virtual int getLevel() const; //different for regular stack and commander
|
||||
CreatureID getCreatureID() const; //-1 if not available
|
||||
std::string getName() const; //plural or singular
|
||||
CStackInstance(IGameInfoCallback *cb);
|
||||
CStackInstance(IGameInfoCallback *cb, BonusNodeType nodeType, bool isHypothetic = false);
|
||||
CStackInstance(IGameInfoCallback *cb, const CreatureID & id, TQuantity count, bool isHypothetic = false);
|
||||
CStackInstance(IGameInfoCallback * cb);
|
||||
CStackInstance(IGameInfoCallback * cb, BonusNodeType nodeType, bool isHypothetic = false);
|
||||
CStackInstance(IGameInfoCallback * cb, const CreatureID & id, TQuantity count, bool isHypothetic = false);
|
||||
virtual ~CStackInstance() = default;
|
||||
|
||||
void setType(const CreatureID & creID);
|
||||
@@ -116,7 +120,7 @@ public:
|
||||
void giveTotalStackExperience(TExpType exp);
|
||||
|
||||
bool valid(bool allowUnrandomized) const;
|
||||
ArtPlacementMap putArtifact(const ArtifactPosition & pos, const CArtifactInstance * art) override;//from CArtifactSet
|
||||
ArtPlacementMap putArtifact(const ArtifactPosition & pos, const CArtifactInstance * art) override; //from CArtifactSet
|
||||
void removeArtifact(const ArtifactPosition & pos) override;
|
||||
ArtBearer bearerType() const override; //from CArtifactSet
|
||||
std::string nodeName() const override; //from CBonusSystemnode
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
/// The castle event builds/adds buildings/creatures for a specific town.
|
||||
class DLL_LINKAGE CCastleEvent: public CMapEvent
|
||||
class DLL_LINKAGE CCastleEvent : public CMapEvent
|
||||
{
|
||||
public:
|
||||
CCastleEvent() = default;
|
||||
@@ -23,7 +23,7 @@ public:
|
||||
std::set<BuildingID> buildings;
|
||||
std::vector<si32> creatures;
|
||||
|
||||
template <typename Handler>
|
||||
template<typename Handler>
|
||||
void serialize(Handler & h)
|
||||
{
|
||||
h & static_cast<CMapEvent &>(*this);
|
||||
|
||||
@@ -39,7 +39,7 @@ public:
|
||||
|
||||
std::vector<ObjectInstanceID> deletedObjectsInstances;
|
||||
|
||||
template <typename Handler>
|
||||
template<typename Handler>
|
||||
void serialize(Handler & h)
|
||||
{
|
||||
h & name;
|
||||
|
||||
@@ -67,7 +67,7 @@ struct DLL_LINKAGE TerrainTile
|
||||
std::vector<ObjectInstanceID> visitableObjects;
|
||||
std::vector<ObjectInstanceID> blockingObjects;
|
||||
|
||||
template <typename Handler>
|
||||
template<typename Handler>
|
||||
void serialize(Handler & h)
|
||||
{
|
||||
h & terrainType;
|
||||
@@ -78,7 +78,7 @@ struct DLL_LINKAGE TerrainTile
|
||||
h & roadDir;
|
||||
h & extTileFlags;
|
||||
|
||||
if (h.hasFeature(Handler::Version::NO_RAW_POINTERS_IN_SERIALIZER))
|
||||
if(h.hasFeature(Handler::Version::NO_RAW_POINTERS_IN_SERIALIZER))
|
||||
{
|
||||
h & visitableObjects;
|
||||
h & blockingObjects;
|
||||
@@ -87,14 +87,12 @@ struct DLL_LINKAGE TerrainTile
|
||||
{
|
||||
std::vector<std::shared_ptr<CGObjectInstance>> objectPtrs;
|
||||
h & objectPtrs;
|
||||
for (const auto & ptr : objectPtrs)
|
||||
for(const auto & ptr : objectPtrs)
|
||||
visitableObjects.push_back(ptr->id);
|
||||
h & objectPtrs;
|
||||
for (const auto & ptr : objectPtrs)
|
||||
for(const auto & ptr : objectPtrs)
|
||||
blockingObjects.push_back(ptr->id);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user