diff --git a/client/ClientCommandManager.cpp b/client/ClientCommandManager.cpp index 05f8cced4..80fefa147 100644 --- a/client/ClientCommandManager.cpp +++ b/client/ClientCommandManager.cpp @@ -387,7 +387,7 @@ void ClientCommandManager::handleBonusesCommand(std::istringstream & singleWordB return ss.str(); }; printCommandMessage("Bonuses of " + LOCPLINT->localState->getCurrentArmy()->getObjectName() + "\n"); - printCommandMessage(format(LOCPLINT->localState->getCurrentArmy()->getBonusList()) + "\n"); + printCommandMessage(format(*LOCPLINT->localState->getCurrentArmy()->getAllBonuses(Selector::all, Selector::all)) + "\n"); printCommandMessage("\nInherited bonuses:\n"); TCNodes parents; diff --git a/client/NetPacksClient.cpp b/client/NetPacksClient.cpp index ae2a35d26..df5e7152b 100644 --- a/client/NetPacksClient.cpp +++ b/client/NetPacksClient.cpp @@ -329,13 +329,12 @@ void ApplyClientNetPackVisitor::visitGiveBonus(GiveBonus & pack) case GiveBonus::ETarget::HERO: { const CGHeroInstance *h = gs.getHero(ObjectInstanceID(pack.id)); - callInterfaceIfPresent(cl, h->tempOwner, &IGameEventsReceiver::heroBonusChanged, h, *h->getBonusList().back(), true); + callInterfaceIfPresent(cl, h->tempOwner, &IGameEventsReceiver::heroBonusChanged, h, pack.bonus, true); } break; case GiveBonus::ETarget::PLAYER: { - const PlayerState *p = gs.getPlayerState(PlayerColor(pack.id)); - callInterfaceIfPresent(cl, PlayerColor(pack.id), &IGameEventsReceiver::playerBonusChanged, *p->getBonusList().back(), true); + callInterfaceIfPresent(cl, PlayerColor(pack.id), &IGameEventsReceiver::playerBonusChanged, pack.bonus, true); } break; } diff --git a/lib/CGameState.cpp b/lib/CGameState.cpp index 5cf720bc8..5ece9a50c 100644 --- a/lib/CGameState.cpp +++ b/lib/CGameState.cpp @@ -703,8 +703,6 @@ CGameState::CGameState() applier = std::make_shared>(); registerTypesClientPacks1(*applier); registerTypesClientPacks2(*applier); - //objCaller = new CObjectCallersHandler(); - globalEffects.setDescription("Global effects"); globalEffects.setNodeType(CBonusSystemNode::GLOBAL_EFFECTS); } diff --git a/lib/bonuses/CBonusSystemNode.cpp b/lib/bonuses/CBonusSystemNode.cpp index a7b461852..4de398409 100644 --- a/lib/bonuses/CBonusSystemNode.cpp +++ b/lib/bonuses/CBonusSystemNode.cpp @@ -23,11 +23,6 @@ constexpr bool CBonusSystemNode::cachingEnabled = true; #define FOREACH_PARENT(pname) TNodes lparents; getParents(lparents); for(CBonusSystemNode *pname : lparents) #define FOREACH_RED_CHILD(pname) TNodes lchildren; getRedChildren(lchildren); for(CBonusSystemNode *pname : lchildren) -PlayerColor CBonusSystemNode::retrieveNodeOwner(const CBonusSystemNode * node) -{ - return node ? node->getOwner() : PlayerColor::CANNOT_DETERMINE; -} - std::shared_ptr CBonusSystemNode::getBonusLocalFirst(const CSelector & selector) { auto ret = bonuses.getFirst(selector); @@ -51,19 +46,15 @@ std::shared_ptr CBonusSystemNode::getBonusLocalFirst(const CSelecto void CBonusSystemNode::getParents(TCNodes & out) const /*retrieves list of parent nodes (nodes to inherit bonuses from) */ { - for(const auto & elem : parents) - { - const CBonusSystemNode *parent = elem; - out.insert(parent); - } + for(const auto * elem : parents) + out.insert(elem); } void CBonusSystemNode::getParents(TNodes &out) { - for (auto & elem : parents) + for (auto * elem : parents) { - const CBonusSystemNode *parent = elem; - out.insert(const_cast(parent)); + out.insert(elem); } } @@ -240,7 +231,6 @@ CBonusSystemNode::CBonusSystemNode(CBonusSystemNode && other) noexcept: bonuses(std::move(other.bonuses)), exportedBonuses(std::move(other.exportedBonuses)), nodeType(other.nodeType), - description(other.description), cachedLast(0), isHypotheticNode(other.isHypotheticNode) { @@ -461,18 +451,13 @@ bool CBonusSystemNode::isIndependentNode() const std::string CBonusSystemNode::nodeName() const { - return !description.empty() - ? description - : std::string("Bonus system node of type ") + typeid(*this).name(); + return std::string("Bonus system node of type ") + typeid(*this).name(); } std::string CBonusSystemNode::nodeShortInfo() const { std::ostringstream str; str << "'" << typeid(* this).name() << "'"; - description.length() > 0 - ? str << " (" << description << ")" - : str << " (no description)"; return str.str(); } @@ -589,21 +574,11 @@ CBonusSystemNode::ENodeTypes CBonusSystemNode::getNodeType() const return nodeType; } -const BonusList& CBonusSystemNode::getBonusList() const -{ - return bonuses; -} - const TNodesVector& CBonusSystemNode::getParentNodes() const { return parents; } -const TNodesVector& CBonusSystemNode::getChildrenNodes() const -{ - return children; -} - void CBonusSystemNode::setNodeType(CBonusSystemNode::ENodeTypes type) { nodeType = type; @@ -619,16 +594,6 @@ const BonusList & CBonusSystemNode::getExportedBonusList() const return exportedBonuses; } -const std::string& CBonusSystemNode::getDescription() const -{ - return description; -} - -void CBonusSystemNode::setDescription(const std::string &description) -{ - this->description = description; -} - void CBonusSystemNode::limitBonuses(const BonusList &allBonuses, BonusList &out) const { assert(&allBonuses != &out); //todo should it work in-place? diff --git a/lib/bonuses/CBonusSystemNode.h b/lib/bonuses/CBonusSystemNode.h index a8a7deb15..e6f6f1dee 100644 --- a/lib/bonuses/CBonusSystemNode.h +++ b/lib/bonuses/CBonusSystemNode.h @@ -35,7 +35,6 @@ private: TNodesVector children; ENodeTypes nodeType; - std::string description; bool isHypotheticNode; static const bool cachingEnabled; @@ -72,6 +71,10 @@ private: void exportBonus(const std::shared_ptr & b); +protected: + bool isIndependentNode() const; //node is independent when it has no parents nor children + void exportBonuses(); + public: explicit CBonusSystemNode(bool isHypotetic = false); explicit CBonusSystemNode(ENodeTypes NodeType); @@ -86,7 +89,6 @@ public: //non-const interface void getParents(TNodes &out); //retrieves list of parent nodes (nodes to inherit bonuses from) - static PlayerColor retrieveNodeOwner(const CBonusSystemNode * node); std::shared_ptr getBonusLocalFirst(const CSelector & selector); void attachTo(CBonusSystemNode & parent); @@ -99,7 +101,6 @@ public: void removeBonuses(const CSelector & selector); void removeBonusesRecursive(const CSelector & s); - bool isIndependentNode() const; //node is independent when it has no parents nor children ///updates count of remaining turns and removes outdated bonuses by selector void reduceBonusDurations(const CSelector &s); virtual std::string bonusToString(const std::shared_ptr& bonus, bool description) const {return "";}; //description or bonus name @@ -107,17 +108,12 @@ public: bool isHypothetic() const { return isHypotheticNode; } void deserializationFix(); - void exportBonuses(); - const BonusList &getBonusList() const; BonusList & getExportedBonusList(); const BonusList & getExportedBonusList() const; CBonusSystemNode::ENodeTypes getNodeType() const; void setNodeType(CBonusSystemNode::ENodeTypes type); const TNodesVector & getParentNodes() const; - const TNodesVector & getChildrenNodes() const; - const std::string & getDescription() const; - void setDescription(const std::string & description); static void treeHasChanged(); @@ -133,7 +129,6 @@ public: // h & bonuses; h & nodeType; h & exportedBonuses; - h & description; BONUS_TREE_DESERIALIZATION_FIX //h & parents & children; } diff --git a/lib/bonuses/Limiters.cpp b/lib/bonuses/Limiters.cpp index 02e35915d..eace34379 100644 --- a/lib/bonuses/Limiters.cpp +++ b/lib/bonuses/Limiters.cpp @@ -430,7 +430,7 @@ OppositeSideLimiter::OppositeSideLimiter(PlayerColor Owner): ILimiter::EDecision OppositeSideLimiter::limit(const BonusLimitationContext & context) const { - auto contextOwner = CBonusSystemNode::retrieveNodeOwner(& context.node); + auto contextOwner = context.node.getOwner(); auto decision = (owner == contextOwner || owner == PlayerColor::CANNOT_DETERMINE) ? ILimiter::EDecision::DISCARD : ILimiter::EDecision::ACCEPT; return decision; } diff --git a/lib/bonuses/Updaters.cpp b/lib/bonuses/Updaters.cpp index cc68f30d0..0c21733b8 100644 --- a/lib/bonuses/Updaters.cpp +++ b/lib/bonuses/Updaters.cpp @@ -197,7 +197,7 @@ JsonNode OwnerUpdater::toJsonNode() const std::shared_ptr OwnerUpdater::createUpdatedBonus(const std::shared_ptr & b, const CBonusSystemNode & context) const { - auto owner = CBonusSystemNode::retrieveNodeOwner(&context); + auto owner = context.getOwner(); if(owner == PlayerColor::UNFLAGGABLE) owner = PlayerColor::NEUTRAL;