1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-17 01:32:21 +02:00

Remove strange & unused double-selector logic

This commit is contained in:
Ivan Savenko
2025-06-24 12:06:23 +03:00
parent 2d24c28996
commit 1e3e2f665c
39 changed files with 71 additions and 85 deletions

View File

@ -133,11 +133,10 @@ SlotID StackWithBonuses::unitSlot() const
return slot; return slot;
} }
TConstBonusListPtr StackWithBonuses::getAllBonuses(const CSelector & selector, const CSelector & limit, TConstBonusListPtr StackWithBonuses::getAllBonuses(const CSelector & selector, const std::string & cachingStr) const
const std::string & cachingStr) const
{ {
auto ret = std::make_shared<BonusList>(); auto ret = std::make_shared<BonusList>();
TConstBonusListPtr originalList = origBearer->getAllBonuses(selector, limit, cachingStr); TConstBonusListPtr originalList = origBearer->getAllBonuses(selector, cachingStr);
vstd::copy_if(*originalList, std::back_inserter(*ret), [this](const std::shared_ptr<Bonus> & b) vstd::copy_if(*originalList, std::back_inserter(*ret), [this](const std::shared_ptr<Bonus> & b)
{ {
@ -147,7 +146,7 @@ TConstBonusListPtr StackWithBonuses::getAllBonuses(const CSelector & selector, c
for(const Bonus & bonus : bonusesToUpdate) for(const Bonus & bonus : bonusesToUpdate)
{ {
if(selector(&bonus) && (!limit || limit(&bonus))) if(selector(&bonus))
{ {
if(ret->getFirst(Selector::source(BonusSource::SPELL_EFFECT, bonus.sid).And(Selector::typeSubtype(bonus.type, bonus.subtype)))) if(ret->getFirst(Selector::source(BonusSource::SPELL_EFFECT, bonus.sid).And(Selector::typeSubtype(bonus.type, bonus.subtype))))
{ {
@ -164,7 +163,7 @@ TConstBonusListPtr StackWithBonuses::getAllBonuses(const CSelector & selector, c
for(auto & bonus : bonusesToAdd) for(auto & bonus : bonusesToAdd)
{ {
auto b = std::make_shared<Bonus>(bonus); auto b = std::make_shared<Bonus>(bonus);
if(selector(b.get()) && (!limit || !limit(b.get()))) if(selector(b.get()))
ret->push_back(b); ret->push_back(b);
} }
//TODO limiters? //TODO limiters?

View File

@ -90,8 +90,7 @@ public:
SlotID unitSlot() const override; SlotID unitSlot() const override;
///IBonusBearer ///IBonusBearer
TConstBonusListPtr getAllBonuses(const CSelector & selector, const CSelector & limit, TConstBonusListPtr getAllBonuses(const CSelector & selector, const std::string & cachingStr = "") const override;
const std::string & cachingStr = "") const override;
int32_t getTreeVersion() const override; int32_t getTreeVersion() const override;

View File

@ -290,7 +290,7 @@ double getArtifactBonusRelevance(const CGHeroInstance * hero, const std::shared_
for (const auto & slot : hero->Slots()) for (const auto & slot : hero->Slots())
{ {
const auto allBonuses = slot.second->getAllBonuses(Selector::all, Selector::all); const auto allBonuses = slot.second->getAllBonuses(Selector::all);
BonusLimitationContext context = {*bonus, *slot.second, *allBonuses, stillUndecided}; BonusLimitationContext context = {*bonus, *slot.second, *allBonuses, stillUndecided};
uint64_t unitStrength = slot.second->getPower(); uint64_t unitStrength = slot.second->getPower();

View File

@ -440,14 +440,14 @@ void ClientCommandManager::handleBonusesCommand(std::istringstream & singleWordB
return ss.str(); return ss.str();
}; };
printCommandMessage("Bonuses of " + GAME->interface()->localState->getCurrentArmy()->getObjectName() + "\n"); printCommandMessage("Bonuses of " + GAME->interface()->localState->getCurrentArmy()->getObjectName() + "\n");
printCommandMessage(format(*GAME->interface()->localState->getCurrentArmy()->getAllBonuses(Selector::all, Selector::all)) + "\n"); printCommandMessage(format(*GAME->interface()->localState->getCurrentArmy()->getAllBonuses(Selector::all)) + "\n");
printCommandMessage("\nInherited bonuses:\n"); printCommandMessage("\nInherited bonuses:\n");
TCNodes parents; TCNodes parents;
GAME->interface()->localState->getCurrentArmy()->getParents(parents); GAME->interface()->localState->getCurrentArmy()->getParents(parents);
for(const CBonusSystemNode *parent : parents) for(const CBonusSystemNode *parent : parents)
{ {
printCommandMessage(std::string("\nBonuses from ") + typeid(*parent).name() + "\n" + format(*parent->getAllBonuses(Selector::all, Selector::all)) + "\n"); printCommandMessage(std::string("\nBonuses from ") + typeid(*parent).name() + "\n" + format(*parent->getAllBonuses(Selector::all)) + "\n");
} }
} }

View File

@ -805,7 +805,7 @@ void BattleStacksController::removeExpiredColorFilters()
{ {
if (!filter.persistent) if (!filter.persistent)
{ {
if (filter.source && !filter.target->hasBonus(Selector::source(BonusSource::SPELL_EFFECT, BonusSourceID(filter.source->id)), Selector::all)) if (filter.source && !filter.target->hasBonus(Selector::source(BonusSource::SPELL_EFFECT, BonusSourceID(filter.source->id))))
return true; return true;
if (filter.effectColor == Colors::TRANSPARENCY && filter.transparency == 255) if (filter.effectColor == Colors::TRANSPARENCY && filter.transparency == 255)
return true; return true;

View File

@ -848,7 +848,7 @@ void CStackWindow::init()
void CStackWindow::initBonusesList() void CStackWindow::initBonusesList()
{ {
BonusList receivedBonuses = *info->stackNode->getBonuses(CSelector(Bonus::Permanent), Selector::all); BonusList receivedBonuses = *info->stackNode->getBonuses(CSelector(Bonus::Permanent));
BonusList abilities = info->creature->getExportedBonusList(); BonusList abilities = info->creature->getExportedBonusList();
// remove all bonuses that are not propagated away // remove all bonuses that are not propagated away

View File

@ -329,7 +329,7 @@ void CCreature::addBonus(int val, BonusType type, BonusSubtypeID subtype)
BonusList & exported = getExportedBonusList(); BonusList & exported = getExportedBonusList();
BonusList existing; BonusList existing;
exported.getBonuses(existing, selector, Selector::all); exported.getBonuses(existing, selector);
if(existing.empty()) if(existing.empty())
{ {

View File

@ -134,7 +134,7 @@ std::vector<SpellID> CStack::activeSpells() const
return b->type != BonusType::NONE && b->sid.as<SpellID>().toSpell() && !b->sid.as<SpellID>().toSpell()->isAdventure(); return b->type != BonusType::NONE && b->sid.as<SpellID>().toSpell() && !b->sid.as<SpellID>().toSpell()->isAdventure();
})); }));
TConstBonusListPtr spellEffects = getBonuses(selector, Selector::all, cachingStr.str()); TConstBonusListPtr spellEffects = getBonuses(selector, cachingStr.str());
for(const auto & it : *spellEffects) for(const auto & it : *spellEffects)
{ {
if(!vstd::contains(ret, it->sid.as<SpellID>())) //do not duplicate spells with multiple effects if(!vstd::contains(ret, it->sid.as<SpellID>())) //do not duplicate spells with multiple effects

View File

@ -1797,7 +1797,7 @@ SpellID CBattleInfoCallback::getRandomBeneficialSpell(vstd::RNG & rand, const ba
std::stringstream cachingStr; std::stringstream cachingStr;
cachingStr << "source_" << vstd::to_underlying(BonusSource::SPELL_EFFECT) << "id_" << spellID.num; cachingStr << "source_" << vstd::to_underlying(BonusSource::SPELL_EFFECT) << "id_" << spellID.num;
if(subject->hasBonus(Selector::source(BonusSource::SPELL_EFFECT, BonusSourceID(spellID)), Selector::all, cachingStr.str())) if(subject->hasBonus(Selector::source(BonusSource::SPELL_EFFECT, BonusSourceID(spellID)), cachingStr.str()))
continue; continue;
auto spellPtr = spellID.toSpell(); auto spellPtr = spellID.toSpell();

View File

@ -495,7 +495,7 @@ bool CUnitState::isGhost() const
bool CUnitState::isFrozen() const bool CUnitState::isFrozen() const
{ {
return hasBonus(Selector::source(BonusSource::SPELL_EFFECT, BonusSourceID(SpellID(SpellID::STONE_GAZE))), Selector::all); return hasBonus(Selector::source(BonusSource::SPELL_EFFECT, BonusSourceID(SpellID(SpellID::STONE_GAZE))));
} }
bool CUnitState::isValidTarget(bool allowDead) const bool CUnitState::isValidTarget(bool allowDead) const
@ -948,9 +948,9 @@ CUnitStateDetached::CUnitStateDetached(const IUnitInfo * unit_, const IBonusBear
{ {
} }
TConstBonusListPtr CUnitStateDetached::getAllBonuses(const CSelector & selector, const CSelector & limit, const std::string & cachingStr) const TConstBonusListPtr CUnitStateDetached::getAllBonuses(const CSelector & selector, const std::string & cachingStr) const
{ {
return bonus->getAllBonuses(selector, limit, cachingStr); return bonus->getAllBonuses(selector, cachingStr);
} }
int32_t CUnitStateDetached::getTreeVersion() const int32_t CUnitStateDetached::getTreeVersion() const

View File

@ -278,7 +278,7 @@ public:
CUnitStateDetached & operator= (const CUnitState & other); CUnitStateDetached & operator= (const CUnitState & other);
TConstBonusListPtr getAllBonuses(const CSelector & selector, const CSelector & limit, const std::string & cachingStr = "") const override; TConstBonusListPtr getAllBonuses(const CSelector & selector, const std::string & cachingStr = "") const override;
int32_t getTreeVersion() const override; int32_t getTreeVersion() const override;

View File

@ -523,7 +523,7 @@ int DamageCalculator::battleBonusValue(const IBonusBearer * bearer, const CSelec
: Selector::effectRange()(BonusLimitEffect::ONLY_MELEE_FIGHT); : Selector::effectRange()(BonusLimitEffect::ONLY_MELEE_FIGHT);
//any regular bonuses or just ones for melee/ranged //any regular bonuses or just ones for melee/ranged
return bearer->getBonuses(selector, noLimit.Or(limitMatches))->totalValue(); return bearer->getBonuses(selector)->valOfBonuses(noLimit.Or(limitMatches));
}; };
DamageEstimation DamageCalculator::calculateDmgRange() const DamageEstimation DamageCalculator::calculateDmgRange() const

View File

@ -172,11 +172,11 @@ std::shared_ptr<const Bonus> BonusList::getFirst(const CSelector &selector) cons
return nullptr; return nullptr;
} }
void BonusList::getBonuses(BonusList & out, const CSelector &selector, const CSelector &limit) const void BonusList::getBonuses(BonusList & out, const CSelector &selector) const
{ {
for(const auto & b : bonuses) for(const auto & b : bonuses)
{ {
if(selector(b.get()) && (!limit || ((bool)limit && limit(b.get())))) if(selector(b.get()))
out.push_back(b); out.push_back(b);
} }
} }
@ -190,8 +190,7 @@ void BonusList::getAllBonuses(BonusList &out) const
int BonusList::valOfBonuses(const CSelector &select, int baseValue) const int BonusList::valOfBonuses(const CSelector &select, int baseValue) const
{ {
BonusList ret; BonusList ret;
CSelector limit = nullptr; getBonuses(ret, select);
getBonuses(ret, select, limit);
return ret.totalValue(baseValue); return ret.totalValue(baseValue);
} }

View File

@ -54,7 +54,7 @@ public:
// BonusList functions // BonusList functions
void stackBonuses(); void stackBonuses();
int totalValue(int baseValue = 0) const; int totalValue(int baseValue = 0) const;
void getBonuses(BonusList &out, const CSelector &selector, const CSelector &limit = nullptr) const; void getBonuses(BonusList &out, const CSelector &selector) const;
void getAllBonuses(BonusList &out) const; void getAllBonuses(BonusList &out) const;
//special find functions //special find functions

View File

@ -80,7 +80,7 @@ void CBonusSystemNode::getAllBonusesRec(BonusList &out) const
} }
} }
TConstBonusListPtr CBonusSystemNode::getAllBonuses(const CSelector &selector, const CSelector &limit, const std::string &cachingStr) const TConstBonusListPtr CBonusSystemNode::getAllBonuses(const CSelector &selector, const std::string &cachingStr) const
{ {
if (cachingEnabled) if (cachingEnabled)
{ {
@ -103,7 +103,7 @@ TConstBonusListPtr CBonusSystemNode::getAllBonuses(const CSelector &selector, co
{ {
// Cached bonuses are up-to-date - use shared/read access and compute results // Cached bonuses are up-to-date - use shared/read access and compute results
std::shared_lock lock(sync); std::shared_lock lock(sync);
cachedBonuses.getBonuses(*ret, selector, limit); cachedBonuses.getBonuses(*ret, selector);
} }
else else
{ {
@ -113,7 +113,7 @@ TConstBonusListPtr CBonusSystemNode::getAllBonuses(const CSelector &selector, co
if (cachedLast == nodeChanged) if (cachedLast == nodeChanged)
{ {
// While our thread was waiting, another one have updated bonus tree. Use cached bonuses. // While our thread was waiting, another one have updated bonus tree. Use cached bonuses.
cachedBonuses.getBonuses(*ret, selector, limit); cachedBonuses.getBonuses(*ret, selector);
} }
else else
{ {
@ -126,7 +126,7 @@ TConstBonusListPtr CBonusSystemNode::getAllBonuses(const CSelector &selector, co
limitBonuses(allBonuses, cachedBonuses); limitBonuses(allBonuses, cachedBonuses);
cachedBonuses.stackBonuses(); cachedBonuses.stackBonuses();
cachedLast = nodeChanged; cachedLast = nodeChanged;
cachedBonuses.getBonuses(*ret, selector, limit); cachedBonuses.getBonuses(*ret, selector);
} }
} }
@ -147,11 +147,11 @@ TConstBonusListPtr CBonusSystemNode::getAllBonuses(const CSelector &selector, co
} }
else else
{ {
return getAllBonusesWithoutCaching(selector, limit); return getAllBonusesWithoutCaching(selector);
} }
} }
TConstBonusListPtr CBonusSystemNode::getAllBonusesWithoutCaching(const CSelector &selector, const CSelector &limit) const TConstBonusListPtr CBonusSystemNode::getAllBonusesWithoutCaching(const CSelector &selector) const
{ {
auto ret = std::make_shared<BonusList>(); auto ret = std::make_shared<BonusList>();
@ -160,7 +160,7 @@ TConstBonusListPtr CBonusSystemNode::getAllBonusesWithoutCaching(const CSelector
BonusList afterLimiting; BonusList afterLimiting;
getAllBonusesRec(beforeLimiting); getAllBonusesRec(beforeLimiting);
limitBonuses(beforeLimiting, afterLimiting); limitBonuses(beforeLimiting, afterLimiting);
afterLimiting.getBonuses(*ret, selector, limit); afterLimiting.getBonuses(*ret, selector);
ret->stackBonuses(); ret->stackBonuses();
return ret; return ret;
} }
@ -300,7 +300,7 @@ void CBonusSystemNode::removeBonusesRecursive(const CSelector & s)
void CBonusSystemNode::reduceBonusDurations(const CSelector &s) void CBonusSystemNode::reduceBonusDurations(const CSelector &s)
{ {
BonusList bl; BonusList bl;
exportedBonuses.getBonuses(bl, s, Selector::all); exportedBonuses.getBonuses(bl, s);
for(const auto & b : bl) for(const auto & b : bl)
{ {
b->turnsRemain--; b->turnsRemain--;
@ -351,7 +351,7 @@ void CBonusSystemNode::removeBonus(const std::shared_ptr<Bonus>& b)
void CBonusSystemNode::removeBonuses(const CSelector & selector) void CBonusSystemNode::removeBonuses(const CSelector & selector)
{ {
BonusList toRemove; BonusList toRemove;
exportedBonuses.getBonuses(toRemove, selector, Selector::all); exportedBonuses.getBonuses(toRemove, selector);
for(const auto & bonus : toRemove) for(const auto & bonus : toRemove)
removeBonus(bonus); removeBonus(bonus);
} }

View File

@ -70,7 +70,7 @@ private:
mutable std::shared_mutex sync; mutable std::shared_mutex sync;
void getAllBonusesRec(BonusList &out) const; void getAllBonusesRec(BonusList &out) const;
TConstBonusListPtr getAllBonusesWithoutCaching(const CSelector &selector, const CSelector &limit) const; TConstBonusListPtr getAllBonusesWithoutCaching(const CSelector &selector) const;
std::shared_ptr<Bonus> getUpdatedBonus(const std::shared_ptr<Bonus> & b, const TUpdaterPtr & updater) const; std::shared_ptr<Bonus> getUpdatedBonus(const std::shared_ptr<Bonus> & b, const TUpdaterPtr & updater) const;
void limitBonuses(const BonusList &allBonuses, BonusList &out) const; //out will bo populed with bonuses that are not limited here void limitBonuses(const BonusList &allBonuses, BonusList &out) const; //out will bo populed with bonuses that are not limited here
@ -101,7 +101,7 @@ public:
explicit CBonusSystemNode(ENodeTypes NodeType); explicit CBonusSystemNode(ENodeTypes NodeType);
virtual ~CBonusSystemNode(); virtual ~CBonusSystemNode();
TConstBonusListPtr getAllBonuses(const CSelector &selector, const CSelector &limit, const std::string &cachingStr = "") const override; TConstBonusListPtr getAllBonuses(const CSelector &selector, const std::string &cachingStr = "") const override;
void getParents(TCNodes &out) const; //retrieves list of parent nodes (nodes to inherit bonuses from), void getParents(TCNodes &out) const; //retrieves list of parent nodes (nodes to inherit bonuses from),
/// Returns first bonus matching selector /// Returns first bonus matching selector

View File

@ -17,7 +17,7 @@ VCMI_LIB_NAMESPACE_BEGIN
int IBonusBearer::valOfBonuses(const CSelector &selector, const std::string &cachingStr, int baseValue) const int IBonusBearer::valOfBonuses(const CSelector &selector, const std::string &cachingStr, int baseValue) const
{ {
TConstBonusListPtr hlp = getAllBonuses(selector, nullptr, cachingStr); TConstBonusListPtr hlp = getAllBonuses(selector, cachingStr);
return hlp->totalValue(baseValue); return hlp->totalValue(baseValue);
} }
@ -27,19 +27,9 @@ bool IBonusBearer::hasBonus(const CSelector &selector, const std::string &cachin
return !getBonuses(selector, cachingStr)->empty(); return !getBonuses(selector, cachingStr)->empty();
} }
bool IBonusBearer::hasBonus(const CSelector &selector, const CSelector &limit, const std::string &cachingStr) const
{
return !getBonuses(selector, limit, cachingStr)->empty();
}
TConstBonusListPtr IBonusBearer::getBonuses(const CSelector &selector, const std::string &cachingStr) const TConstBonusListPtr IBonusBearer::getBonuses(const CSelector &selector, const std::string &cachingStr) const
{ {
return getAllBonuses(selector, nullptr, cachingStr); return getAllBonuses(selector, cachingStr);
}
TConstBonusListPtr IBonusBearer::getBonuses(const CSelector &selector, const CSelector &limit, const std::string &cachingStr) const
{
return getAllBonuses(selector, limit, cachingStr);
} }
TConstBonusListPtr IBonusBearer::getBonusesFrom(BonusSource source) const TConstBonusListPtr IBonusBearer::getBonusesFrom(BonusSource source) const
@ -120,7 +110,7 @@ bool IBonusBearer::hasBonusFrom(BonusSource source) const
std::shared_ptr<const Bonus> IBonusBearer::getBonus(const CSelector &selector) const std::shared_ptr<const Bonus> IBonusBearer::getBonus(const CSelector &selector) const
{ {
auto bonuses = getAllBonuses(selector, Selector::all); auto bonuses = getAllBonuses(selector);
return bonuses->getFirst(Selector::all); return bonuses->getFirst(Selector::all);
} }

View File

@ -20,11 +20,9 @@ public:
// * selector is predicate that tests if Bonus matches our criteria // * selector is predicate that tests if Bonus matches our criteria
IBonusBearer() = default; IBonusBearer() = default;
virtual ~IBonusBearer() = default; virtual ~IBonusBearer() = default;
virtual TConstBonusListPtr getAllBonuses(const CSelector &selector, const CSelector &limit, const std::string &cachingStr = {}) const = 0; virtual TConstBonusListPtr getAllBonuses(const CSelector &selector, const std::string &cachingStr = {}) const = 0;
int valOfBonuses(const CSelector &selector, const std::string &cachingStr = {}, int baseValue = 0) const; int valOfBonuses(const CSelector &selector, const std::string &cachingStr = {}, int baseValue = 0) const;
bool hasBonus(const CSelector &selector, const std::string &cachingStr = {}) const; bool hasBonus(const CSelector &selector, const std::string &cachingStr = {}) const;
bool hasBonus(const CSelector &selector, const CSelector &limit, const std::string &cachingStr = {}) const;
TConstBonusListPtr getBonuses(const CSelector &selector, const CSelector &limit, const std::string &cachingStr = {}) const;
TConstBonusListPtr getBonuses(const CSelector &selector, const std::string &cachingStr = {}) const; TConstBonusListPtr getBonuses(const CSelector &selector, const std::string &cachingStr = {}) const;
std::shared_ptr<const Bonus> getBonus(const CSelector &selector) const; //returns any bonus visible on node that matches (or nullptr if none matches) std::shared_ptr<const Bonus> getBonus(const CSelector &selector) const; //returns any bonus visible on node that matches (or nullptr if none matches)

View File

@ -317,7 +317,7 @@ bool DimensionDoorMechanics::canBeCastImpl(spells::Problem & problem, const IGam
std::stringstream cachingStr; std::stringstream cachingStr;
cachingStr << "source_" << vstd::to_underlying(BonusSource::SPELL_EFFECT) << "id_" << owner->id.num; cachingStr << "source_" << vstd::to_underlying(BonusSource::SPELL_EFFECT) << "id_" << owner->id.num;
int castsAlreadyPerformedThisTurn = caster->getHeroCaster()->getBonuses(Selector::source(BonusSource::SPELL_EFFECT, BonusSourceID(owner->id)), Selector::all, cachingStr.str())->size(); int castsAlreadyPerformedThisTurn = caster->getHeroCaster()->getBonuses(Selector::source(BonusSource::SPELL_EFFECT, BonusSourceID(owner->id)), cachingStr.str())->size();
int castsLimit = owner->getLevelPower(schoolLevel); int castsLimit = owner->getLevelPower(schoolLevel);
bool isTournamentRulesLimitEnabled = cb->getSettings().getBoolean(EGameSettings::DIMENSION_DOOR_TOURNAMENT_RULES_LIMIT); bool isTournamentRulesLimitEnabled = cb->getSettings().getBoolean(EGameSettings::DIMENSION_DOOR_TOURNAMENT_RULES_LIMIT);

View File

@ -246,21 +246,22 @@ int BonusBearerProxy::getBonuses(lua_State * L)
if(hasRangeSelector) if(hasRangeSelector)
{ {
auto rangeSelector = [](const Bonus * b) //TODO: BonusBearerProxy::getBonuses rangeSelector
{ //auto rangeSelector = [](const Bonus * b)
return false;//TODO: BonusBearerProxy::getBonuses rangeSelector //{
}; // return false;
//};
ret = object->getBonuses(selector, rangeSelector); ret = object->getBonuses(selector);
} }
else else
{ {
ret = object->getBonuses(selector, Selector::all); ret = object->getBonuses(selector);
} }
} }
else else
{ {
ret = object->getBonuses(Selector::all, Selector::all); ret = object->getBonuses(Selector::all);
} }
S.clear(); S.clear();

View File

@ -83,13 +83,13 @@ public:
void redirectBonusesToFake() void redirectBonusesToFake()
{ {
ON_CALL(*this, getAllBonuses(_, _, _)).WillByDefault(Invoke(&bonusFake, &BonusBearerMock::getAllBonuses)); ON_CALL(*this, getAllBonuses(_, _)).WillByDefault(Invoke(&bonusFake, &BonusBearerMock::getAllBonuses));
ON_CALL(*this, getTreeVersion()).WillByDefault(Invoke(&bonusFake, &BonusBearerMock::getTreeVersion)); ON_CALL(*this, getTreeVersion()).WillByDefault(Invoke(&bonusFake, &BonusBearerMock::getTreeVersion));
} }
void expectAnyBonusSystemCall() void expectAnyBonusSystemCall()
{ {
EXPECT_CALL(*this, getAllBonuses(_, _, _)).Times(AtLeast(0)); EXPECT_CALL(*this, getAllBonuses(_, _)).Times(AtLeast(0));
EXPECT_CALL(*this, getTreeVersion()).Times(AtLeast(0)); EXPECT_CALL(*this, getTreeVersion()).Times(AtLeast(0));
} }

View File

@ -29,7 +29,7 @@ public:
void setDefaultExpectations() void setDefaultExpectations()
{ {
EXPECT_CALL(mock, getAllBonuses(_, _, _)).WillRepeatedly(Invoke(&bonusMock, &BonusBearerMock::getAllBonuses)); EXPECT_CALL(mock, getAllBonuses(_, _)).WillRepeatedly(Invoke(&bonusMock, &BonusBearerMock::getAllBonuses));
EXPECT_CALL(mock, getTreeVersion()).WillRepeatedly(Return(1)); EXPECT_CALL(mock, getTreeVersion()).WillRepeatedly(Return(1));
bonusMock.addNewBonus(std::make_shared<Bonus>(BonusDuration::PERMANENT, BonusType::STACK_HEALTH, BonusSource::CREATURE_ABILITY, UNIT_HEALTH, BonusSourceID())); bonusMock.addNewBonus(std::make_shared<Bonus>(BonusDuration::PERMANENT, BonusType::STACK_HEALTH, BonusSource::CREATURE_ABILITY, UNIT_HEALTH, BonusSourceID()));
@ -235,7 +235,7 @@ TEST_F(HealthTest, singleUnitStack)
//one Titan //one Titan
EXPECT_CALL(mock, getAllBonuses(_, _, _)).WillRepeatedly(Invoke(&bonusMock, &BonusBearerMock::getAllBonuses)); EXPECT_CALL(mock, getAllBonuses(_, _)).WillRepeatedly(Invoke(&bonusMock, &BonusBearerMock::getAllBonuses));
EXPECT_CALL(mock, getTreeVersion()).WillRepeatedly(Return(1)); EXPECT_CALL(mock, getTreeVersion()).WillRepeatedly(Return(1));
bonusMock.addNewBonus(std::make_shared<Bonus>(BonusDuration::PERMANENT, BonusType::STACK_HEALTH, BonusSource::CREATURE_ABILITY, 300, BonusSourceID())); bonusMock.addNewBonus(std::make_shared<Bonus>(BonusDuration::PERMANENT, BonusType::STACK_HEALTH, BonusSource::CREATURE_ABILITY, 300, BonusSourceID()));

View File

@ -34,13 +34,13 @@ void UnitFake::makeDead()
void UnitFake::redirectBonusesToFake() void UnitFake::redirectBonusesToFake()
{ {
ON_CALL(*this, getAllBonuses(_, _, _)).WillByDefault(Invoke(&bonusFake, &BonusBearerMock::getAllBonuses)); ON_CALL(*this, getAllBonuses(_, _)).WillByDefault(Invoke(&bonusFake, &BonusBearerMock::getAllBonuses));
ON_CALL(*this, getTreeVersion()).WillByDefault(Invoke(&bonusFake, &BonusBearerMock::getTreeVersion)); ON_CALL(*this, getTreeVersion()).WillByDefault(Invoke(&bonusFake, &BonusBearerMock::getTreeVersion));
} }
void UnitFake::expectAnyBonusSystemCall() void UnitFake::expectAnyBonusSystemCall()
{ {
EXPECT_CALL(*this, getAllBonuses(_, _, _)).Times(AtLeast(0)); EXPECT_CALL(*this, getAllBonuses(_, _)).Times(AtLeast(0));
EXPECT_CALL(*this, getTreeVersion()).Times(AtLeast(0)); EXPECT_CALL(*this, getTreeVersion()).Times(AtLeast(0));
} }

View File

@ -25,7 +25,7 @@ void BonusBearerMock::addNewBonus(const std::shared_ptr<Bonus> & b)
treeVersion++; treeVersion++;
} }
TConstBonusListPtr BonusBearerMock::getAllBonuses(const CSelector & selector, const CSelector & limit, const std::string & cachingStr) const TConstBonusListPtr BonusBearerMock::getAllBonuses(const CSelector & selector, const std::string & cachingStr) const
{ {
if(cachedLast != treeVersion) if(cachedLast != treeVersion)
{ {
@ -34,7 +34,7 @@ TConstBonusListPtr BonusBearerMock::getAllBonuses(const CSelector & selector, co
} }
auto ret = std::make_shared<BonusList>(); auto ret = std::make_shared<BonusList>();
bonuses.getBonuses(*ret, selector, limit); bonuses.getBonuses(*ret, selector);
return ret; return ret;
} }

View File

@ -23,7 +23,7 @@ public:
void addNewBonus(const std::shared_ptr<Bonus> & b); void addNewBonus(const std::shared_ptr<Bonus> & b);
TConstBonusListPtr getAllBonuses(const CSelector & selector, const CSelector & limit, const std::string & cachingStr = "") const override; TConstBonusListPtr getAllBonuses(const CSelector & selector, const std::string & cachingStr = "") const override;
int32_t getTreeVersion() const override; int32_t getTreeVersion() const override;
private: private:

View File

@ -15,7 +15,7 @@
class UnitMock : public battle::Unit class UnitMock : public battle::Unit
{ {
public: public:
MOCK_CONST_METHOD3(getAllBonuses, TConstBonusListPtr(const CSelector &, const CSelector &, const std::string &)); MOCK_CONST_METHOD2(getAllBonuses, TConstBonusListPtr(const CSelector &, const std::string &));
MOCK_CONST_METHOD0(getTreeVersion, int32_t()); MOCK_CONST_METHOD0(getTreeVersion, int32_t());
MOCK_CONST_METHOD0(getCasterUnitId, int32_t()); MOCK_CONST_METHOD0(getCasterUnitId, int32_t());

View File

@ -33,7 +33,7 @@ public:
protected: protected:
void SetUp() override void SetUp() override
{ {
ON_CALL(actualCaster, getAllBonuses(_, _, _)).WillByDefault(Invoke(&casterBonuses, &BonusBearerMock::getAllBonuses)); ON_CALL(actualCaster, getAllBonuses(_, _)).WillByDefault(Invoke(&casterBonuses, &BonusBearerMock::getAllBonuses));
ON_CALL(actualCaster, getTreeVersion()).WillByDefault(Invoke(&casterBonuses, &BonusBearerMock::getTreeVersion)); ON_CALL(actualCaster, getTreeVersion()).WillByDefault(Invoke(&casterBonuses, &BonusBearerMock::getTreeVersion));
} }
@ -57,7 +57,7 @@ TEST_F(AbilityCasterTest, MagicAbilityAffectedByGenericBonus)
casterBonuses.addNewBonus(std::make_shared<Bonus>(BonusDuration::ONE_BATTLE, BonusType::MAGIC_SCHOOL_SKILL, BonusSource::OTHER, 2, BonusSourceID(), BonusSubtypeID(SpellSchool::ANY))); casterBonuses.addNewBonus(std::make_shared<Bonus>(BonusDuration::ONE_BATTLE, BonusType::MAGIC_SCHOOL_SKILL, BonusSource::OTHER, 2, BonusSourceID(), BonusSubtypeID(SpellSchool::ANY)));
EXPECT_CALL(actualCaster, getAllBonuses(_, _, _)).Times(AtLeast(1)); EXPECT_CALL(actualCaster, getAllBonuses(_, _)).Times(AtLeast(1));
EXPECT_CALL(actualCaster, getTreeVersion()).Times(AtLeast(0)); EXPECT_CALL(actualCaster, getTreeVersion()).Times(AtLeast(0));
setupSubject(1); setupSubject(1);
@ -71,7 +71,7 @@ TEST_F(AbilityCasterTest, MagicAbilityIgnoresSchoolBonus)
casterBonuses.addNewBonus(std::make_shared<Bonus>(BonusDuration::ONE_BATTLE, BonusType::MAGIC_SCHOOL_SKILL, BonusSource::OTHER, 2, BonusSourceID(), BonusSubtypeID(SpellSchool::AIR))); casterBonuses.addNewBonus(std::make_shared<Bonus>(BonusDuration::ONE_BATTLE, BonusType::MAGIC_SCHOOL_SKILL, BonusSource::OTHER, 2, BonusSourceID(), BonusSubtypeID(SpellSchool::AIR)));
EXPECT_CALL(actualCaster, getAllBonuses(_, _, _)).Times(AtLeast(1)); EXPECT_CALL(actualCaster, getAllBonuses(_, _)).Times(AtLeast(1));
EXPECT_CALL(actualCaster, getTreeVersion()).Times(AtLeast(0)); EXPECT_CALL(actualCaster, getTreeVersion()).Times(AtLeast(0));
setupSubject(1); setupSubject(1);

View File

@ -24,7 +24,7 @@ public:
void setDefaultExpectations() void setDefaultExpectations()
{ {
EXPECT_CALL(mechanicsMock, isMagicalEffect()).WillRepeatedly(Return(true)); EXPECT_CALL(mechanicsMock, isMagicalEffect()).WillRepeatedly(Return(true));
EXPECT_CALL(unitMock, getAllBonuses(_, _, _)).Times(AtLeast(1)); EXPECT_CALL(unitMock, getAllBonuses(_, _)).Times(AtLeast(1));
EXPECT_CALL(unitMock, getTreeVersion()).Times(AtLeast(0)); EXPECT_CALL(unitMock, getTreeVersion()).Times(AtLeast(0));
} }

View File

@ -24,7 +24,7 @@ public:
void setDefaultExpectations() void setDefaultExpectations()
{ {
EXPECT_CALL(unitMock, getAllBonuses(_, _, _)).Times(AtLeast(1)); EXPECT_CALL(unitMock, getAllBonuses(_, _)).Times(AtLeast(1));
EXPECT_CALL(unitMock, getTreeVersion()).Times(AtLeast(0)); EXPECT_CALL(unitMock, getTreeVersion()).Times(AtLeast(0));
EXPECT_CALL(mechanicsMock, getSpellIndex()).WillRepeatedly(Return(castSpell)); EXPECT_CALL(mechanicsMock, getSpellIndex()).WillRepeatedly(Return(castSpell));
} }

View File

@ -21,7 +21,7 @@ class BonusConditionTest : public TargetConditionItemTest
public: public:
void setDefaultExpectations() void setDefaultExpectations()
{ {
EXPECT_CALL(unitMock, getAllBonuses(_, _, _)).Times(AtLeast(1)); EXPECT_CALL(unitMock, getAllBonuses(_, _)).Times(AtLeast(1));
EXPECT_CALL(unitMock, getTreeVersion()).Times(AtLeast(0)); EXPECT_CALL(unitMock, getTreeVersion()).Times(AtLeast(0));
} }

View File

@ -21,7 +21,7 @@ class CreatureConditionTest : public TargetConditionItemTest
public: public:
void setDefaultExpectations() void setDefaultExpectations()
{ {
EXPECT_CALL(unitMock, getAllBonuses(_, _, _)).Times(0); EXPECT_CALL(unitMock, getAllBonuses(_, _)).Times(0);
EXPECT_CALL(unitMock, getTreeVersion()).Times(0); EXPECT_CALL(unitMock, getTreeVersion()).Times(0);
} }

View File

@ -23,7 +23,7 @@ public:
void setDefaultExpectations() void setDefaultExpectations()
{ {
EXPECT_CALL(unitMock, getAllBonuses(_, _, _)).Times(AtLeast(1)); EXPECT_CALL(unitMock, getAllBonuses(_, _)).Times(AtLeast(1));
EXPECT_CALL(unitMock, getTreeVersion()).Times(AtLeast(0)); EXPECT_CALL(unitMock, getTreeVersion()).Times(AtLeast(0));
EXPECT_CALL(mechanicsMock, getSpell()).Times(AtLeast(1)).WillRepeatedly(Return(&spellMock)); EXPECT_CALL(mechanicsMock, getSpell()).Times(AtLeast(1)).WillRepeatedly(Return(&spellMock));

View File

@ -23,7 +23,7 @@ public:
const int64_t EFFECT_VALUE = 101; const int64_t EFFECT_VALUE = 101;
void setDefaultExpectations() void setDefaultExpectations()
{ {
EXPECT_CALL(unitMock, getAllBonuses(_, _, _)).Times(0); EXPECT_CALL(unitMock, getAllBonuses(_, _)).Times(0);
EXPECT_CALL(unitMock, getTreeVersion()).Times(0); EXPECT_CALL(unitMock, getTreeVersion()).Times(0);
EXPECT_CALL(unitMock, getAvailableHealth()).WillOnce(Return(UNIT_HP)); EXPECT_CALL(unitMock, getAvailableHealth()).WillOnce(Return(UNIT_HP));
EXPECT_CALL(mechanicsMock, getEffectValue()).WillOnce(Return(EFFECT_VALUE)); EXPECT_CALL(mechanicsMock, getEffectValue()).WillOnce(Return(EFFECT_VALUE));

View File

@ -30,7 +30,7 @@ public:
{ {
ownerMatches = ::testing::get<0>(GetParam()); ownerMatches = ::testing::get<0>(GetParam());
isMagicalEffect = ::testing::get<1>(GetParam()); isMagicalEffect = ::testing::get<1>(GetParam());
EXPECT_CALL(unitMock, getAllBonuses(_, _, _)).Times(AtLeast(0)); EXPECT_CALL(unitMock, getAllBonuses(_, _)).Times(AtLeast(0));
EXPECT_CALL(unitMock, getTreeVersion()).Times(AtLeast(0)); EXPECT_CALL(unitMock, getTreeVersion()).Times(AtLeast(0));
EXPECT_CALL(mechanicsMock, isMagicalEffect()).Times(AtLeast(0)).WillRepeatedly(Return(isMagicalEffect)); EXPECT_CALL(mechanicsMock, isMagicalEffect()).Times(AtLeast(0)).WillRepeatedly(Return(isMagicalEffect));
EXPECT_CALL(mechanicsMock, ownerMatches(Eq(&unitMock), Field(&boost::logic::tribool::value, boost::logic::tribool::false_value))).WillRepeatedly(Return(ownerMatches)); EXPECT_CALL(mechanicsMock, ownerMatches(Eq(&unitMock), Field(&boost::logic::tribool::value, boost::logic::tribool::false_value))).WillRepeatedly(Return(ownerMatches));

View File

@ -27,7 +27,7 @@ public:
isMagicalEffect = GetParam(); isMagicalEffect = GetParam();
EXPECT_CALL(mechanicsMock, isMagicalEffect()).WillRepeatedly(Return(isMagicalEffect)); EXPECT_CALL(mechanicsMock, isMagicalEffect()).WillRepeatedly(Return(isMagicalEffect));
if(isMagicalEffect) if(isMagicalEffect)
EXPECT_CALL(unitMock, getAllBonuses(_, _, _)).Times(AtLeast(1)); EXPECT_CALL(unitMock, getAllBonuses(_, _)).Times(AtLeast(1));
EXPECT_CALL(unitMock, getTreeVersion()).Times(AtLeast(0)); EXPECT_CALL(unitMock, getTreeVersion()).Times(AtLeast(0));
} }

View File

@ -24,7 +24,7 @@ public:
void setDefaultExpectations() void setDefaultExpectations()
{ {
EXPECT_CALL(unitMock, getAllBonuses(_, _, _)).Times(AtLeast(1)); EXPECT_CALL(unitMock, getAllBonuses(_, _)).Times(AtLeast(1));
EXPECT_CALL(unitMock, getTreeVersion()).Times(AtLeast(0)); EXPECT_CALL(unitMock, getTreeVersion()).Times(AtLeast(0));
EXPECT_CALL(mechanicsMock, getSpellIndex()).WillRepeatedly(Return(castSpell)); EXPECT_CALL(mechanicsMock, getSpellIndex()).WillRepeatedly(Return(castSpell));
} }

View File

@ -27,7 +27,7 @@ public:
isPositive = ::testing::get<0>(GetParam()); isPositive = ::testing::get<0>(GetParam());
hasBonus = ::testing::get<1>(GetParam()); hasBonus = ::testing::get<1>(GetParam());
EXPECT_CALL(unitMock, getAllBonuses(_, _, _)).Times(AtLeast(0)); EXPECT_CALL(unitMock, getAllBonuses(_, _)).Times(AtLeast(0));
EXPECT_CALL(unitMock, getTreeVersion()).Times(AtLeast(0)); EXPECT_CALL(unitMock, getTreeVersion()).Times(AtLeast(0));
EXPECT_CALL(mechanicsMock, isPositiveSpell()).WillRepeatedly(Return(isPositive)); EXPECT_CALL(mechanicsMock, isPositiveSpell()).WillRepeatedly(Return(isPositive));
if(hasBonus) if(hasBonus)

View File

@ -21,7 +21,7 @@ class SpellEffectConditionTest : public TargetConditionItemTest
public: public:
void setDefaultExpectations() void setDefaultExpectations()
{ {
EXPECT_CALL(unitMock, getAllBonuses(_, _, _)).Times(AtLeast(1)); EXPECT_CALL(unitMock, getAllBonuses(_, _)).Times(AtLeast(1));
EXPECT_CALL(unitMock, getTreeVersion()).Times(AtLeast(0)); EXPECT_CALL(unitMock, getTreeVersion()).Times(AtLeast(0));
} }

View File

@ -37,7 +37,7 @@ protected:
void SetUp() override void SetUp() override
{ {
using namespace ::testing; using namespace ::testing;
ON_CALL(unitMock, getAllBonuses(_, _, _)).WillByDefault(Invoke(&unitBonuses, &BonusBearerMock::getAllBonuses)); ON_CALL(unitMock, getAllBonuses(_, _)).WillByDefault(Invoke(&unitBonuses, &BonusBearerMock::getAllBonuses));
ON_CALL(unitMock, getTreeVersion()).WillByDefault(Invoke(&unitBonuses, &BonusBearerMock::getTreeVersion)); ON_CALL(unitMock, getTreeVersion()).WillByDefault(Invoke(&unitBonuses, &BonusBearerMock::getTreeVersion));
} }
}; };