1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-15 01:24:45 +02:00

More battle log refactoring

This commit is contained in:
AlexVinS
2015-03-22 12:18:58 +03:00
parent 7cf9bd36b7
commit 5d0ecd9cdf

View File

@ -1350,39 +1350,47 @@ void CBattleInterface::spellCast( const BattleSpellCast * sc )
} }
else else
{ {
auto getPluralText = [attackedStack, attackedName](const int baseTextID) -> std::string auto getPluralFormat = [attackedStack](const int baseTextID) -> boost::format
{ {
std::string res = CGI->generaltexth->allTexts[(attackedStack->count > 1 ? baseTextID+1 : baseTextID)]; return boost::format(CGI->generaltexth->allTexts[(attackedStack->count > 1 ? baseTextID+1 : baseTextID)]);
boost::algorithm::replace_first(res, "%s", attackedName); };
return res;
auto logSimple = [&logLines, getPluralFormat, attackedName](const int baseTextID)
{
boost::format fmt = getPluralFormat(baseTextID);
fmt % attackedName;
logLines.push_back(fmt.str());
};
auto logPlural = [&logLines, attackedNamePl](const int baseTextID)
{
boost::format fmt(CGI->generaltexth->allTexts[baseTextID]);
fmt % attackedNamePl;
logLines.push_back(fmt.str());
}; };
customSpell = true; //in most following cases text is custom customSpell = true; //in most following cases text is custom
switch(sc->id) switch(sc->id)
{ {
case SpellID::STONE_GAZE: case SpellID::STONE_GAZE:
logLines.push_back(getPluralText(558)); logSimple(558);
break; break;
case SpellID::POISON: case SpellID::POISON:
logLines.push_back(getPluralText(561)); logSimple(561);
break; break;
case SpellID::BIND: case SpellID::BIND:
{ logPlural(560);//Roots and vines bind the %s to the ground!
//Roots and vines bind the %s to the ground!
boost::format text(CGI->generaltexth->allTexts[560]);
text % attackedNamePl;
logLines.push_back(text.str());
}
break; break;
case SpellID::DISEASE: case SpellID::DISEASE:
logLines.push_back(getPluralText(553)); logSimple(553);
break; break;
case SpellID::PARALYZE: case SpellID::PARALYZE:
logLines.push_back(getPluralText(563)); logSimple(563);
break; break;
case SpellID::AGE: case SpellID::AGE:
{ {
boost::format text(getPluralText(551)); boost::format text = getPluralFormat(551);
text % attackedName;
//The %s shrivel with age, and lose %d hit points." //The %s shrivel with age, and lose %d hit points."
TBonusListPtr bl = attackedStack->getBonuses(Selector::type(Bonus::STACK_HEALTH)); TBonusListPtr bl = attackedStack->getBonuses(Selector::type(Bonus::STACK_HEALTH));
const int fullHP = bl->totalValue(); const int fullHP = bl->totalValue();
@ -1393,20 +1401,14 @@ void CBattleInterface::spellCast( const BattleSpellCast * sc )
break; break;
case SpellID::THUNDERBOLT: case SpellID::THUNDERBOLT:
{ {
std::string text = CGI->generaltexth->allTexts[367]; logPlural(367);
boost::algorithm::replace_first(text, "%s", attackedNamePl); std::string text = CGI->generaltexth->allTexts[343].substr(1, CGI->generaltexth->allTexts[343].size() - 1); //Does %d points of damage.
logLines.push_back(text);
text = CGI->generaltexth->allTexts[343].substr(1, CGI->generaltexth->allTexts[343].size() - 1); //Does %d points of damage.
boost::algorithm::replace_first(text, "%d", boost::lexical_cast<std::string>(sc->dmgToDisplay)); //no more text afterwards boost::algorithm::replace_first(text, "%d", boost::lexical_cast<std::string>(sc->dmgToDisplay)); //no more text afterwards
logLines.push_back(text); logLines.push_back(text);
} }
break; break;
case SpellID::DISPEL_HELPFUL_SPELLS: case SpellID::DISPEL_HELPFUL_SPELLS:
{ logPlural(555);
boost::format text(CGI->generaltexth->allTexts[555]);
text % attackedNamePl;
logLines.push_back(text.str());
}
break; break;
case SpellID::DEATH_STARE: case SpellID::DEATH_STARE:
if (sc->dmgToDisplay) if (sc->dmgToDisplay)