1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-22 22:13:35 +02:00

Add bonus description generation for map objects

This commit is contained in:
Ivan Savenko 2024-10-25 18:36:02 +00:00
parent 8a5ac73438
commit ee59bc4e71
8 changed files with 22 additions and 15 deletions

View File

@ -581,13 +581,13 @@ void MoraleLuckBox::set(const AFactionMember * node)
else if(morale && node && node->getBonusBearer()->hasBonusOfType(BonusType::NO_MORALE))
{
auto noMorale = node->getBonusBearer()->getBonus(Selector::type()(BonusType::NO_MORALE));
text += "\n" + noMorale->Description();
text += "\n" + noMorale->Description(LOCPLINT->cb.get());
component.value = 0;
}
else if (!morale && node && node->getBonusBearer()->hasBonusOfType(BonusType::NO_LUCK))
{
auto noLuck = node->getBonusBearer()->getBonus(Selector::type()(BonusType::NO_LUCK));
text += "\n" + noLuck->Description();
text += "\n" + noLuck->Description(LOCPLINT->cb.get());
component.value = 0;
}
else
@ -596,7 +596,7 @@ void MoraleLuckBox::set(const AFactionMember * node)
for(auto & bonus : * modifierList)
{
if(bonus->val) {
const std::string& description = bonus->Description();
const std::string& description = bonus->Description(LOCPLINT->cb.get());
//arraytxt already contains \n
if (description.size() && description[0] != '\n')
addInfo += '\n';

View File

@ -13,10 +13,9 @@
"index" : 0,
"aiValue" : 500,
"rmg" : {
}
},
"message" : "@core.advevent.69",
"bonuses" : {
"seaMovement" : {
"type" : "MOVEMENT",

View File

@ -122,7 +122,7 @@ CSkill::LevelInfo & CSkill::at(int level)
DLL_LINKAGE std::ostream & operator<<(std::ostream & out, const CSkill::LevelInfo & info)
{
for(int i=0; i < info.effects.size(); i++)
out << (i ? "," : "") << info.effects[i]->Description();
out << (i ? "," : "") << info.effects[i]->Description(nullptr);
return out << "])";
}

View File

@ -885,12 +885,12 @@ void BattleInfo::addOrUpdateUnitBonus(CStack * sta, const Bonus & value, bool fo
if(forceAdd || !sta->hasBonus(Selector::source(BonusSource::SPELL_EFFECT, value.sid).And(Selector::typeSubtypeValueType(value.type, value.subtype, value.valType))))
{
//no such effect or cumulative - add new
logBonus->trace("%s receives a new bonus: %s", sta->nodeName(), value.Description());
logBonus->trace("%s receives a new bonus: %s", sta->nodeName(), value.Description(nullptr));
sta->addNewBonus(std::make_shared<Bonus>(value));
}
else
{
logBonus->trace("%s updated bonus: %s", sta->nodeName(), value.Description());
logBonus->trace("%s updated bonus: %s", sta->nodeName(), value.Description(nullptr));
for(const auto & stackBonus : sta->getExportedBonusList()) //TODO: optimize
{

View File

@ -18,8 +18,11 @@
#include "../CCreatureHandler.h"
#include "../CCreatureSet.h"
#include "../CSkillHandler.h"
#include "../IGameCallback.h"
#include "../TerrainHandler.h"
#include "../VCMI_Lib.h"
#include "../mapObjects/CGObjectInstance.h"
#include "../mapObjectConstructors/CObjectClassesHandler.h"
#include "../battle/BattleInfo.h"
#include "../constants/StringConstants.h"
#include "../entities/hero/CHero.h"
@ -87,7 +90,7 @@ JsonNode CAddInfo::toJsonNode() const
return node;
}
}
std::string Bonus::Description(std::optional<si32> customValue) const
std::string Bonus::Description(const IGameInfoCallback * cb, std::optional<si32> customValue) const
{
MetaString descriptionHelper = description;
auto valueToShow = customValue.value_or(val);
@ -112,6 +115,10 @@ std::string Bonus::Description(std::optional<si32> customValue) const
case BonusSource::HERO_SPECIAL:
descriptionHelper.appendTextID(sid.as<HeroTypeID>().toEntity(VLC)->getNameTextID());
break;
case BonusSource::OBJECT_INSTANCE:
const auto * object = cb->getObj(sid.as<ObjectInstanceID>());
if (object)
descriptionHelper.appendTextID(VLC->objtypeh->getObjectName(object->ID, object->subID));
}
}

View File

@ -26,6 +26,7 @@ class IPropagator;
class IUpdater;
class BonusList;
class CSelector;
class IGameInfoCallback;
using BonusSubtypeID = VariantIdentifier<BonusCustomSubtype, SpellID, CreatureID, PrimarySkill, TerrainId, GameResID, SpellSchool>;
using BonusSourceID = VariantIdentifier<BonusCustomSource, SpellID, CreatureID, ArtifactID, CampaignScenarioID, SecondarySkill, HeroTypeID, Obj, ObjectInstanceID, BuildingTypeUniqueID, BattleField>;
@ -177,7 +178,7 @@ struct DLL_LINKAGE Bonus : public std::enable_shared_from_this<Bonus>, public Se
val += Val;
}
std::string Description(std::optional<si32> customValue = {}) const;
std::string Description(const IGameInfoCallback * cb, std::optional<si32> customValue = {}) const;
JsonNode toJsonNode() const;
std::shared_ptr<Bonus> addLimiter(const TLimiterPtr & Limiter); //returns this for convenient chain-calls

View File

@ -378,7 +378,7 @@ void CBonusSystemNode::propagateBonus(const std::shared_ptr<Bonus> & b, const CB
? source.getUpdatedBonus(b, b->propagationUpdater)
: b;
bonuses.push_back(propagated);
logBonus->trace("#$# %s #propagated to# %s", propagated->Description(), nodeName());
logBonus->trace("#$# %s #propagated to# %s", propagated->Description(nullptr), nodeName());
}
TNodes lchildren;
@ -392,9 +392,9 @@ void CBonusSystemNode::unpropagateBonus(const std::shared_ptr<Bonus> & b)
if(b->propagator->shouldBeAttached(this))
{
if (bonuses -= b)
logBonus->trace("#$# %s #is no longer propagated to# %s", b->Description(), nodeName());
logBonus->trace("#$# %s #is no longer propagated to# %s", b->Description(nullptr), nodeName());
else
logBonus->warn("Attempt to remove #$# %s, which is not propagated to %s", b->Description(), nodeName());
logBonus->warn("Attempt to remove #$# %s, which is not propagated to %s", b->Description(nullptr), nodeName());
bonuses.remove_if([b](const auto & bonus)
{

View File

@ -166,7 +166,7 @@ GrowthInfo CGTownInstance::getGrowthInfo(int level) const
const auto growth = b->val * (base + castleBonus) / 100;
if (growth)
{
ret.entries.emplace_back(growth, b->Description(growth));
ret.entries.emplace_back(growth, b->Description(cb, growth));
}
}
@ -174,7 +174,7 @@ GrowthInfo CGTownInstance::getGrowthInfo(int level) const
// Note: bonus uses 1-based levels (Pikeman is level 1), town list uses 0-based (Pikeman in 0-th creatures entry)
TConstBonusListPtr bonuses = getBonuses(Selector::typeSubtype(BonusType::CREATURE_GROWTH, BonusCustomSubtype::creatureLevel(level+1)));
for(const auto & b : *bonuses)
ret.entries.emplace_back(b->val, b->Description());
ret.entries.emplace_back(b->val, b->Description(cb));
int dwellingBonus = 0;
if(const PlayerState *p = cb->getPlayerState(tempOwner, false))