فهرست منبع

CBonusSystemNode: remove description

It was almost unused, but this change is save-breaking
Konstantin P 2 سال پیش
والد
کامیت
0cbc2e458c

+ 1 - 1
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;

+ 2 - 3
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;
 	}

+ 0 - 2
lib/CGameState.cpp

@@ -703,8 +703,6 @@ CGameState::CGameState()
 	applier = std::make_shared<CApplier<CBaseForGSApply>>();
 	registerTypesClientPacks1(*applier);
 	registerTypesClientPacks2(*applier);
-	//objCaller = new CObjectCallersHandler();
-	globalEffects.setDescription("Global effects");
 	globalEffects.setNodeType(CBonusSystemNode::GLOBAL_EFFECTS);
 }
 

+ 5 - 40
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<Bonus> CBonusSystemNode::getBonusLocalFirst(const CSelector & selector)
 {
 	auto ret = bonuses.getFirst(selector);
@@ -51,19 +46,15 @@ std::shared_ptr<const Bonus> 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<CBonusSystemNode*>(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?

+ 4 - 9
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<Bonus> & 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<Bonus> 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>& 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;
 	}

+ 1 - 1
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;
 }

+ 1 - 1
lib/bonuses/Updaters.cpp

@@ -197,7 +197,7 @@ JsonNode OwnerUpdater::toJsonNode() const
 
 std::shared_ptr<Bonus> OwnerUpdater::createUpdatedBonus(const std::shared_ptr<Bonus> & b, const CBonusSystemNode & context) const
 {
-	auto owner = CBonusSystemNode::retrieveNodeOwner(&context);
+	auto owner = context.getOwner();
 
 	if(owner == PlayerColor::UNFLAGGABLE)
 		owner = PlayerColor::NEUTRAL;