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

moved nameForBonus into Bonus class

This commit is contained in:
Henning Koehler 2017-09-15 10:48:34 +12:00
parent ba7709da50
commit ab7ce6625e
3 changed files with 28 additions and 30 deletions

View File

@ -559,7 +559,7 @@ std::vector<std::shared_ptr<Bonus>> SpecialtyBonusToBonuses(const SSpecialtyBonu
if(creatureLimiter) if(creatureLimiter)
{ {
const CCreature * cre = creatureLimiter->creature; const CCreature * cre = creatureLimiter->creature;
int creStat = newBonus->subtype == PrimarySkill::ATTACK ? cre->Attack() : cre->Defense(); int creStat = newBonus->subtype == PrimarySkill::ATTACK ? cre->getAttack(false) : cre->getDefence(false);
int creLevel = cre->level ? cre->level : 5; int creLevel = cre->level ? cre->level : 5;
newBonus->updater = std::make_shared<ScalingUpdater>(creStat, creLevel); newBonus->updater = std::make_shared<ScalingUpdater>(creStat, creLevel);
} }
@ -823,7 +823,7 @@ void CHeroHandler::afterLoadFinalization()
hero->specialty.push_back(bonus); hero->specialty.push_back(bonus);
specVec.push_back(bonus->toJsonNode()); specVec.push_back(bonus->toJsonNode());
// find fitting & unique bonus name // find fitting & unique bonus name
std::string bonusName = nameForBonus(*bonus); std::string bonusName = bonus->nameForBonus();
if(vstd::contains(specNames, bonusName)) if(vstd::contains(specNames, bonusName))
{ {
int suffix = 2; int suffix = 2;

View File

@ -1218,6 +1218,31 @@ JsonNode Bonus::toJsonNode() const
return root; return root;
} }
std::string Bonus::nameForBonus() const
{
switch(type)
{
case Bonus::PRIMARY_SKILL:
return PrimarySkill::names[subtype];
case Bonus::SECONDARY_SKILL_PREMY:
return NSecondarySkill::names[subtype];
case Bonus::SPECIAL_SPELL_LEV:
case Bonus::SPECIFIC_SPELL_DAMAGE:
case Bonus::SPECIAL_BLESS_DAMAGE:
case Bonus::MAXED_SPELL:
case Bonus::SPECIAL_PECULIAR_ENCHANT:
return (*VLC->spellh)[SpellID::ESpellID(subtype)]->identifier;
case Bonus::SPECIAL_UPGRADE:
return CreatureID::encode(subtype) + "2" + CreatureID::encode(additionalInfo);
case Bonus::GENERATE_RESOURCE:
return GameConstants::RESOURCE_NAMES[subtype];
case Bonus::STACKS_SPEED:
return "speed";
default:
return vstd::findKey(bonusNameMap, type);
}
}
Bonus::Bonus(ui16 Dur, BonusType Type, BonusSource Src, si32 Val, ui32 ID, std::string Desc, si32 Subtype) Bonus::Bonus(ui16 Dur, BonusType Type, BonusSource Src, si32 Val, ui32 ID, std::string Desc, si32 Subtype)
: duration(Dur), type(Type), subtype(Subtype), source(Src), val(Val), sid(ID), description(Desc) : duration(Dur), type(Type), subtype(Subtype), source(Src), val(Val), sid(ID), description(Desc)
{ {
@ -1717,28 +1742,3 @@ JsonNode ScalingUpdater::toJsonNode() const
return root; return root;
} }
std::string nameForBonus(const Bonus & bonus)
{
switch(bonus.type)
{
case Bonus::PRIMARY_SKILL:
return PrimarySkill::names[bonus.subtype];
case Bonus::SECONDARY_SKILL_PREMY:
return NSecondarySkill::names[bonus.subtype];
case Bonus::SPECIAL_SPELL_LEV:
case Bonus::SPECIFIC_SPELL_DAMAGE:
case Bonus::SPECIAL_BLESS_DAMAGE:
case Bonus::MAXED_SPELL:
case Bonus::SPECIAL_PECULIAR_ENCHANT:
return (*VLC->spellh)[SpellID::ESpellID(bonus.subtype)]->identifier;
case Bonus::SPECIAL_UPGRADE:
return CreatureID::encode(bonus.subtype) + "2" + CreatureID::encode(bonus.additionalInfo);
case Bonus::GENERATE_RESOURCE:
return GameConstants::RESOURCE_NAMES[bonus.subtype];
case Bonus::STACKS_SPEED:
return "speed";
default:
return vstd::findKey(bonusNameMap, bonus.type);
}
}

View File

@ -426,6 +426,7 @@ struct DLL_LINKAGE Bonus : public std::enable_shared_from_this<Bonus>
std::string Description() const; std::string Description() const;
JsonNode toJsonNode() const; JsonNode toJsonNode() const;
std::string nameForBonus() const; // generate suitable name for bonus - e.g. for storing in json struct
std::shared_ptr<Bonus> addLimiter(TLimiterPtr Limiter); //returns this for convenient chain-calls std::shared_ptr<Bonus> addLimiter(TLimiterPtr Limiter); //returns this for convenient chain-calls
std::shared_ptr<Bonus> addPropagator(TPropagatorPtr Propagator); //returns this for convenient chain-calls std::shared_ptr<Bonus> addPropagator(TPropagatorPtr Propagator); //returns this for convenient chain-calls
@ -1057,6 +1058,3 @@ struct DLL_LINKAGE ScalingUpdater : public IUpdater
virtual std::string toString() const override; virtual std::string toString() const override;
virtual JsonNode toJsonNode() const override; virtual JsonNode toJsonNode() const override;
}; };
// generate suitable name for bonus - e.g. for storing in json struct
DLL_LINKAGE std::string nameForBonus(const Bonus & bonus);