1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-10-08 23:22:25 +02:00

Some more work on bonus-to-string feature.

This commit is contained in:
DjWarmonger
2011-02-02 18:49:48 +00:00
parent 094bb6fd8f
commit c11f7c2020
6 changed files with 117 additions and 40 deletions

View File

@@ -7,6 +7,9 @@
#include "IGameCallback.h"
#include "CGameState.h"
#include "../hch/CGeneralTextHandler.h"
#include "../hch/CSpellHandler.h"
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string/replace.hpp>
const CStackInstance CCreatureSet::operator[](TSlot slot) const
{
@@ -279,11 +282,11 @@ void CStackInstance::getParents(TCNodes &out, const CBonusSystemNode *source /*=
}
std::string CStackInstance::bonusToString(Bonus *bonus, bool description) const
{
std::map<TBonusType, std::pair<std::string, std::string>>::iterator it = VLC->generaltexth->stackBonuses.find(bonus->type);
if (it != VLC->generaltexth->stackBonuses.end())
std::map<TBonusType, std::pair<std::string, std::string>>::iterator it = VLC->creh->stackBonuses.find(bonus->type);
if (it != VLC->creh->stackBonuses.end())
{
std::string text;
if (description)
if (description) //long ability description
{
text = it->second.second;
switch (bonus->type)
@@ -316,11 +319,55 @@ std::string CStackInstance::bonusToString(Bonus *bonus, bool description) const
case Bonus::NON_LIVING:
case Bonus::UNDEAD:
break;
//One numeric value
//case Bonus::STACKS_SPEED: //Do we need description for creature stats?
//case Bonus::STACK_HEALTH:
case Bonus::MAGIC_RESISTANCE:
case Bonus::SPELL_DAMAGE_REDUCTION:
case Bonus::LEVEL_SPELL_IMMUNITY:
case Bonus::CHANGES_SPELL_COST_FOR_ALLY:
case Bonus::CHANGES_SPELL_COST_FOR_ENEMY:
case Bonus::MANA_CHANNELING:
case Bonus::MANA_DRAIN:
case Bonus::HP_REGENERATION:
case Bonus::ADDITIONAL_RETALIATION:
case Bonus::DOUBLE_DAMAGE_CHANCE:
case Bonus::ENEMY_DEFENCE_REDUCTION:
case Bonus::MAGIC_MIRROR:
case Bonus::DARKNESS: //Darkness Dragons any1?
boost::algorithm::replace_first(text, "%d", boost::lexical_cast<std::string>(bonus->val));
break;
//Complex descriptions
case Bonus::HATE: //TODO: customize damage percent
boost::algorithm::replace_first(text, "%s", VLC->creh->creatures[bonus->subtype]->namePl);
break;
case Bonus::SPELL_IMMUNITY:
boost::algorithm::replace_first(text, "%s", VLC->spellh->spells[bonus->subtype].name);
break;
case Bonus::SPELL_AFTER_ATTACK:
boost::algorithm::replace_first(text, "%d", boost::lexical_cast<std::string>(bonus->additionalInfo % 100));
boost::algorithm::replace_first(text, "%s", VLC->spellh->spells[bonus->subtype].name);
break;
default:
{}//TODO: allow custom bonus types... someday, somehow
}
}
else
else //short name
{
text = it->second.first;
switch (bonus->type)
{
case Bonus::HATE:
boost::algorithm::replace_first(text, "%s", VLC->creh->creatures[bonus->subtype]->namePl);
break;
case Bonus::LEVEL_SPELL_IMMUNITY:
boost::algorithm::replace_first(text, "%d", boost::lexical_cast<std::string>(bonus->val));
break;
case Bonus::SPELL_IMMUNITY:
case Bonus::SPELL_AFTER_ATTACK:
boost::algorithm::replace_first(text, "%s", VLC->spellh->spells[bonus->subtype].name);
break;
}
}
return text;
}