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

@ -360,7 +360,7 @@ CBattleInterface::CBattleInterface(const CCreatureSet * army1, const CCreatureSe
{ {
idToObstacle[ID] = CDefHandler::giveDef(elem->getInfo().defName); idToObstacle[ID] = CDefHandler::giveDef(elem->getInfo().defName);
for(auto & _n : idToObstacle[ID]->ourImages) for(auto & _n : idToObstacle[ID]->ourImages)
{ {
CSDL_Ext::setDefaultColorKey(_n.bitmap); CSDL_Ext::setDefaultColorKey(_n.bitmap);
} }
} }
@ -1263,7 +1263,7 @@ void CBattleInterface::spellCast( const BattleSpellCast * sc )
if(casterStack != nullptr) if(casterStack != nullptr)
{ {
casterName = casterStack->type->namePl; casterName = casterStack->type->namePl;
srccoord = CClickableHex::getXYUnitAnim(casterStack->position, casterStack, this); srccoord = CClickableHex::getXYUnitAnim(casterStack->position, casterStack, this);
srccoord.x += 250; srccoord.x += 250;
srccoord.y += 240; srccoord.y += 240;
} }
@ -1274,7 +1274,7 @@ void CBattleInterface::spellCast( const BattleSpellCast * sc )
{ {
} }
//playing projectile animation //playing projectile animation
if(sc->tile.isValid()) if(sc->tile.isValid())
{ {
@ -1304,13 +1304,13 @@ void CBattleInterface::spellCast( const BattleSpellCast * sc )
delete animDef; delete animDef;
addNewAnim(new CSpellEffectAnimation(this, animToDisplay, srccoord.x, srccoord.y, dx, dy, Vflip)); addNewAnim(new CSpellEffectAnimation(this, animToDisplay, srccoord.x, srccoord.y, dx, dy, Vflip));
} }
} }
waitForAnims(); waitForAnims();
displaySpellHit(spellID, sc->tile); displaySpellHit(spellID, sc->tile);
//queuing affect /resist animation //queuing affect /resist animation
for (auto & elem : sc->affectedCres) for (auto & elem : sc->affectedCres)
{ {
BattleHex position = curInt->cb->battleGetStackByID(elem, false)->position; BattleHex position = curInt->cb->battleGetStackByID(elem, false)->position;
@ -1333,7 +1333,7 @@ void CBattleInterface::spellCast( const BattleSpellCast * sc )
} //switch(sc->id) } //switch(sc->id)
//displaying message in console //displaying message in console
std::vector<std::string> logLines; std::vector<std::string> logLines;
bool customSpell = false; bool customSpell = false;
if(sc->affectedCres.size() == 1) if(sc->affectedCres.size() == 1)
{ {
@ -1350,42 +1350,50 @@ 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();
bl->remove_if(Selector::source(Bonus::SPELL_EFFECT, SpellID::AGE)); bl->remove_if(Selector::source(Bonus::SPELL_EFFECT, SpellID::AGE));
text % (fullHP - bl->totalValue()); text % (fullHP - bl->totalValue());
logLines.push_back(text.str()); logLines.push_back(text.str());
@ -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)
@ -1432,7 +1434,7 @@ void CBattleInterface::spellCast( const BattleSpellCast * sc )
boost::format text(CGI->generaltexth->allTexts[565]); //The %s casts %s boost::format text(CGI->generaltexth->allTexts[565]); //The %s casts %s
text % casterName % spellName; text % casterName % spellName;
customSpell = false; customSpell = false;
logLines.push_back(text.str()); logLines.push_back(text.str());
} }
break; break;
} }
@ -1444,17 +1446,17 @@ void CBattleInterface::spellCast( const BattleSpellCast * sc )
text % casterName % spellName; text % casterName % spellName;
logLines.push_back(text.str()); logLines.push_back(text.str());
} }
if(sc->dmgToDisplay && !customSpell) if(sc->dmgToDisplay && !customSpell)
{ {
boost::format dmgInfo(CGI->generaltexth->allTexts[376]); boost::format dmgInfo(CGI->generaltexth->allTexts[376]);
dmgInfo % spellName % sc->dmgToDisplay; dmgInfo % spellName % sc->dmgToDisplay;
logLines.push_back(dmgInfo.str()); logLines.push_back(dmgInfo.str());
} }
for(auto line : logLines) for(auto line : logLines)
console->addText(line); console->addText(line);
waitForAnims(); waitForAnims();
//mana absorption //mana absorption
if(sc->manaGained > 0) if(sc->manaGained > 0)
@ -1511,14 +1513,14 @@ void CBattleInterface::castThisSpell(SpellID spellID)
assert(castingHero); // code below assumes non-null hero assert(castingHero); // code below assumes non-null hero
sp = spellID.toSpell(); sp = spellID.toSpell();
spellSelMode = ANY_LOCATION; spellSelMode = ANY_LOCATION;
const CSpell::TargetInfo ti = sp->getTargetInfo(castingHero->getSpellSchoolLevel(sp)); const CSpell::TargetInfo ti = sp->getTargetInfo(castingHero->getSpellSchoolLevel(sp));
if(ti.massive || ti.type == CSpell::NO_TARGET) if(ti.massive || ti.type == CSpell::NO_TARGET)
spellSelMode = NO_LOCATION; spellSelMode = NO_LOCATION;
else if(ti.type == CSpell::LOCATION && ti.clearAffected) else if(ti.type == CSpell::LOCATION && ti.clearAffected)
{ {
spellSelMode = FREE_LOCATION; spellSelMode = FREE_LOCATION;
} }
else if(ti.type == CSpell::CREATURE) else if(ti.type == CSpell::CREATURE)
{ {
@ -1526,11 +1528,11 @@ void CBattleInterface::castThisSpell(SpellID spellID)
spellSelMode = selectionTypeByPositiveness(*sp); spellSelMode = selectionTypeByPositiveness(*sp);
else else
spellSelMode = ANY_CREATURE; spellSelMode = ANY_CREATURE;
} }
else if(ti.type == CSpell::OBSTACLE) else if(ti.type == CSpell::OBSTACLE)
{ {
spellSelMode = OBSTACLE; spellSelMode = OBSTACLE;
} }
if (spellSelMode == NO_LOCATION) //user does not have to select location if (spellSelMode == NO_LOCATION) //user does not have to select location
{ {
@ -1555,12 +1557,12 @@ void CBattleInterface::displayEffect(ui32 effect, int destTile, bool areaEffect)
void CBattleInterface::displaySpellEffect(SpellID spellID, BattleHex destinationTile, bool areaEffect) void CBattleInterface::displaySpellEffect(SpellID spellID, BattleHex destinationTile, bool areaEffect)
{ {
const CSpell * spell = spellID.toSpell(); const CSpell * spell = spellID.toSpell();
if(spell == nullptr) if(spell == nullptr)
return; return;
for(const CSpell::TAnimation & animation : spell->animationInfo.affect) for(const CSpell::TAnimation & animation : spell->animationInfo.affect)
{ {
addNewAnim(new CSpellEffectAnimation(this, animation.resourceName, destinationTile, false, animation.verticalPosition == VerticalPosition::BOTTOM)); addNewAnim(new CSpellEffectAnimation(this, animation.resourceName, destinationTile, false, animation.verticalPosition == VerticalPosition::BOTTOM));
} }
} }
@ -1568,12 +1570,12 @@ void CBattleInterface::displaySpellEffect(SpellID spellID, BattleHex destination
void CBattleInterface::displaySpellHit(SpellID spellID, BattleHex destinationTile, bool areaEffect) void CBattleInterface::displaySpellHit(SpellID spellID, BattleHex destinationTile, bool areaEffect)
{ {
const CSpell * spell = spellID.toSpell(); const CSpell * spell = spellID.toSpell();
if(spell == nullptr) if(spell == nullptr)
return; return;
for(const CSpell::TAnimation & animation : spell->animationInfo.hit) for(const CSpell::TAnimation & animation : spell->animationInfo.hit)
{ {
addNewAnim(new CSpellEffectAnimation(this, animation.resourceName, destinationTile, false, animation.verticalPosition == VerticalPosition::BOTTOM)); addNewAnim(new CSpellEffectAnimation(this, animation.resourceName, destinationTile, false, animation.verticalPosition == VerticalPosition::BOTTOM));
} }
} }
@ -1791,7 +1793,7 @@ void CBattleInterface::printConsoleAttacked( const CStack * defender, int dmg, i
{ {
if (attacker) if (attacker)
formattedText.append(" "); formattedText.append(" ");
boost::format txt; boost::format txt;
if(killed > 1) if(killed > 1)
{ {