mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-24 03:47:18 +02:00
Implement placeholders for creature banks messages
This commit is contained in:
parent
525ae72f8e
commit
2ee4e42348
@ -477,7 +477,7 @@
|
||||
},
|
||||
{
|
||||
"message" : 34,
|
||||
"appearChance" : { "min" : 30, "max" : 60 },
|
||||
"appearChance" : { "min" : 60, "max" : 90 },
|
||||
"guards" : [
|
||||
{ "amount" : 4, "type" : "naga" },
|
||||
{ "amount" : 4, "type" : "naga" },
|
||||
|
@ -481,11 +481,11 @@ BattleInfo::BattleInfo(const BattleLayout & layout):
|
||||
}
|
||||
|
||||
BattleInfo::BattleInfo():
|
||||
layout(std::make_unique<BattleLayout>()),
|
||||
round(-1),
|
||||
activeStack(-1),
|
||||
town(nullptr),
|
||||
tile(-1,-1,-1),
|
||||
layout(std::make_unique<BattleLayout>()),
|
||||
battlefieldType(BattleField::NONE),
|
||||
tacticsSide(BattleSide::NONE),
|
||||
tacticDistance(0)
|
||||
|
@ -508,6 +508,11 @@ void CRewardableObject::initializeGuards()
|
||||
{
|
||||
clearSlots();
|
||||
|
||||
// Workaround for default creature banks strings that has placeholder for object name
|
||||
// TODO: find better location for this code
|
||||
for (auto & visitInfo : configuration.info)
|
||||
visitInfo.message.replaceRawString(getObjectName());
|
||||
|
||||
for (auto const & visitInfo : configuration.info)
|
||||
{
|
||||
for (auto const & guard : visitInfo.reward.guards)
|
||||
|
@ -266,14 +266,55 @@ void Rewardable::Info::replaceTextPlaceholders(MetaString & target, const Variab
|
||||
|
||||
void Rewardable::Info::replaceTextPlaceholders(MetaString & target, const Variables & variables, const VisitInfo & info) const
|
||||
{
|
||||
for (const auto & artifact : info.reward.artifacts )
|
||||
target.replaceName(artifact);
|
||||
if (!info.reward.guards.empty())
|
||||
{
|
||||
CreatureID strongest = info.reward.guards.at(0).getId();
|
||||
|
||||
for (const auto & spell : info.reward.spells )
|
||||
target.replaceName(spell);
|
||||
for (const auto & guard : info.reward.guards )
|
||||
{
|
||||
if (strongest.toEntity(VLC)->getFightValue() < guard.getId().toEntity(VLC)->getFightValue())
|
||||
strongest = guard.getId();
|
||||
}
|
||||
target.replaceNamePlural(strongest); // FIXME: use singular if only 1 such unit is in guards
|
||||
|
||||
for (const auto & secondary : info.reward.secondary )
|
||||
target.replaceName(secondary.first);
|
||||
MetaString loot;
|
||||
|
||||
for (GameResID it : GameResID::ALL_RESOURCES())
|
||||
{
|
||||
if (info.reward.resources[it] != 0)
|
||||
{
|
||||
loot.appendRawString("%d %s");
|
||||
loot.replaceNumber(info.reward.resources[it]);
|
||||
loot.replaceName(it);
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto & artifact : info.reward.artifacts )
|
||||
{
|
||||
loot.appendRawString("%s");
|
||||
loot.replaceName(artifact);
|
||||
}
|
||||
|
||||
for (const auto & spell : info.reward.spells )
|
||||
{
|
||||
target.replaceName(spell);
|
||||
}
|
||||
|
||||
for (const auto & secondary : info.reward.secondary )
|
||||
target.replaceName(secondary.first);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
for (const auto & artifact : info.reward.artifacts )
|
||||
target.replaceName(artifact);
|
||||
|
||||
for (const auto & spell : info.reward.spells )
|
||||
target.replaceName(spell);
|
||||
|
||||
for (const auto & secondary : info.reward.secondary )
|
||||
target.replaceName(secondary.first);
|
||||
}
|
||||
|
||||
replaceTextPlaceholders(target, variables);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user