1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-27 22:49:25 +02:00

CBonusSystemNode: remove description

It was almost unused, but this change is save-breaking
This commit is contained in:
Konstantin P
2023-05-03 16:09:21 +03:00
parent d0e6205688
commit 0cbc2e458c
7 changed files with 14 additions and 57 deletions

View File

@@ -387,7 +387,7 @@ void ClientCommandManager::handleBonusesCommand(std::istringstream & singleWordB
return ss.str(); return ss.str();
}; };
printCommandMessage("Bonuses of " + LOCPLINT->localState->getCurrentArmy()->getObjectName() + "\n"); 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"); printCommandMessage("\nInherited bonuses:\n");
TCNodes parents; TCNodes parents;

View File

@@ -329,13 +329,12 @@ void ApplyClientNetPackVisitor::visitGiveBonus(GiveBonus & pack)
case GiveBonus::ETarget::HERO: case GiveBonus::ETarget::HERO:
{ {
const CGHeroInstance *h = gs.getHero(ObjectInstanceID(pack.id)); 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; break;
case GiveBonus::ETarget::PLAYER: case GiveBonus::ETarget::PLAYER:
{ {
const PlayerState *p = gs.getPlayerState(PlayerColor(pack.id)); callInterfaceIfPresent(cl, PlayerColor(pack.id), &IGameEventsReceiver::playerBonusChanged, pack.bonus, true);
callInterfaceIfPresent(cl, PlayerColor(pack.id), &IGameEventsReceiver::playerBonusChanged, *p->getBonusList().back(), true);
} }
break; break;
} }

View File

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

View File

@@ -23,11 +23,6 @@ constexpr bool CBonusSystemNode::cachingEnabled = true;
#define FOREACH_PARENT(pname) TNodes lparents; getParents(lparents); for(CBonusSystemNode *pname : lparents) #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) #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) std::shared_ptr<Bonus> CBonusSystemNode::getBonusLocalFirst(const CSelector & selector)
{ {
auto ret = bonuses.getFirst(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) */ void CBonusSystemNode::getParents(TCNodes & out) const /*retrieves list of parent nodes (nodes to inherit bonuses from) */
{ {
for(const auto & elem : parents) for(const auto * elem : parents)
{ out.insert(elem);
const CBonusSystemNode *parent = elem;
out.insert(parent);
}
} }
void CBonusSystemNode::getParents(TNodes &out) void CBonusSystemNode::getParents(TNodes &out)
{ {
for (auto & elem : parents) for (auto * elem : parents)
{ {
const CBonusSystemNode *parent = elem; out.insert(elem);
out.insert(const_cast<CBonusSystemNode*>(parent));
} }
} }
@@ -240,7 +231,6 @@ CBonusSystemNode::CBonusSystemNode(CBonusSystemNode && other) noexcept:
bonuses(std::move(other.bonuses)), bonuses(std::move(other.bonuses)),
exportedBonuses(std::move(other.exportedBonuses)), exportedBonuses(std::move(other.exportedBonuses)),
nodeType(other.nodeType), nodeType(other.nodeType),
description(other.description),
cachedLast(0), cachedLast(0),
isHypotheticNode(other.isHypotheticNode) isHypotheticNode(other.isHypotheticNode)
{ {
@@ -461,18 +451,13 @@ bool CBonusSystemNode::isIndependentNode() const
std::string CBonusSystemNode::nodeName() const std::string CBonusSystemNode::nodeName() const
{ {
return !description.empty() return std::string("Bonus system node of type ") + typeid(*this).name();
? description
: std::string("Bonus system node of type ") + typeid(*this).name();
} }
std::string CBonusSystemNode::nodeShortInfo() const std::string CBonusSystemNode::nodeShortInfo() const
{ {
std::ostringstream str; std::ostringstream str;
str << "'" << typeid(* this).name() << "'"; str << "'" << typeid(* this).name() << "'";
description.length() > 0
? str << " (" << description << ")"
: str << " (no description)";
return str.str(); return str.str();
} }
@@ -589,21 +574,11 @@ CBonusSystemNode::ENodeTypes CBonusSystemNode::getNodeType() const
return nodeType; return nodeType;
} }
const BonusList& CBonusSystemNode::getBonusList() const
{
return bonuses;
}
const TNodesVector& CBonusSystemNode::getParentNodes() const const TNodesVector& CBonusSystemNode::getParentNodes() const
{ {
return parents; return parents;
} }
const TNodesVector& CBonusSystemNode::getChildrenNodes() const
{
return children;
}
void CBonusSystemNode::setNodeType(CBonusSystemNode::ENodeTypes type) void CBonusSystemNode::setNodeType(CBonusSystemNode::ENodeTypes type)
{ {
nodeType = type; nodeType = type;
@@ -619,16 +594,6 @@ const BonusList & CBonusSystemNode::getExportedBonusList() const
return exportedBonuses; 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 void CBonusSystemNode::limitBonuses(const BonusList &allBonuses, BonusList &out) const
{ {
assert(&allBonuses != &out); //todo should it work in-place? assert(&allBonuses != &out); //todo should it work in-place?

View File

@@ -35,7 +35,6 @@ private:
TNodesVector children; TNodesVector children;
ENodeTypes nodeType; ENodeTypes nodeType;
std::string description;
bool isHypotheticNode; bool isHypotheticNode;
static const bool cachingEnabled; static const bool cachingEnabled;
@@ -72,6 +71,10 @@ private:
void exportBonus(const std::shared_ptr<Bonus> & b); 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: public:
explicit CBonusSystemNode(bool isHypotetic = false); explicit CBonusSystemNode(bool isHypotetic = false);
explicit CBonusSystemNode(ENodeTypes NodeType); explicit CBonusSystemNode(ENodeTypes NodeType);
@@ -86,7 +89,6 @@ public:
//non-const interface //non-const interface
void getParents(TNodes &out); //retrieves list of parent nodes (nodes to inherit bonuses from) 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); std::shared_ptr<Bonus> getBonusLocalFirst(const CSelector & selector);
void attachTo(CBonusSystemNode & parent); void attachTo(CBonusSystemNode & parent);
@@ -99,7 +101,6 @@ public:
void removeBonuses(const CSelector & selector); void removeBonuses(const CSelector & selector);
void removeBonusesRecursive(const CSelector & s); 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 ///updates count of remaining turns and removes outdated bonuses by selector
void reduceBonusDurations(const CSelector &s); void reduceBonusDurations(const CSelector &s);
virtual std::string bonusToString(const std::shared_ptr<Bonus>& bonus, bool description) const {return "";}; //description or bonus name 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; } bool isHypothetic() const { return isHypotheticNode; }
void deserializationFix(); void deserializationFix();
void exportBonuses();
const BonusList &getBonusList() const;
BonusList & getExportedBonusList(); BonusList & getExportedBonusList();
const BonusList & getExportedBonusList() const; const BonusList & getExportedBonusList() const;
CBonusSystemNode::ENodeTypes getNodeType() const; CBonusSystemNode::ENodeTypes getNodeType() const;
void setNodeType(CBonusSystemNode::ENodeTypes type); void setNodeType(CBonusSystemNode::ENodeTypes type);
const TNodesVector & getParentNodes() const; const TNodesVector & getParentNodes() const;
const TNodesVector & getChildrenNodes() const;
const std::string & getDescription() const;
void setDescription(const std::string & description);
static void treeHasChanged(); static void treeHasChanged();
@@ -133,7 +129,6 @@ public:
// h & bonuses; // h & bonuses;
h & nodeType; h & nodeType;
h & exportedBonuses; h & exportedBonuses;
h & description;
BONUS_TREE_DESERIALIZATION_FIX BONUS_TREE_DESERIALIZATION_FIX
//h & parents & children; //h & parents & children;
} }

View File

@@ -430,7 +430,7 @@ OppositeSideLimiter::OppositeSideLimiter(PlayerColor Owner):
ILimiter::EDecision OppositeSideLimiter::limit(const BonusLimitationContext & context) const 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; auto decision = (owner == contextOwner || owner == PlayerColor::CANNOT_DETERMINE) ? ILimiter::EDecision::DISCARD : ILimiter::EDecision::ACCEPT;
return decision; return decision;
} }

View File

@@ -197,7 +197,7 @@ JsonNode OwnerUpdater::toJsonNode() const
std::shared_ptr<Bonus> OwnerUpdater::createUpdatedBonus(const std::shared_ptr<Bonus> & b, const CBonusSystemNode & context) 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) if(owner == PlayerColor::UNFLAGGABLE)
owner = PlayerColor::NEUTRAL; owner = PlayerColor::NEUTRAL;