| 1 |
#include "Specifier.h" |
| 2 |
#include "Component.h" |
| 3 |
|
| 4 |
#include "i18n.h" |
| 5 |
#include "itextstream.h" |
| 6 |
#include "string/convert.h" |
| 7 |
#include <fmt/format.h> |
| 8 |
|
| 9 |
namespace objectives { |
| 10 |
|
| 11 |
namespace { |
| 12 |
|
| 13 |
inline std::string getPlural(int count, |
| 14 |
const std::string& singular, const std::string& plural) |
| 15 |
{ |
| 16 |
return (count == 1) ? singular : plural; |
| 17 |
} |
| 18 |
|
| 19 |
inline std::string printEntity(int count) { |
| 20 |
return getPlural(count, _("entity"), _("entities")); |
| 21 |
} |
| 22 |
|
| 23 |
inline std::string printEntityAmount(const std::string& amountStr) { |
| 24 |
if (amountStr.empty()) { |
| 25 |
return printEntity(1); |
| 26 |
} |
| 27 |
else { |
| 28 |
return amountStr + " " + printEntity(string::convert<int>(amountStr)); |
| 29 |
} |
| 30 |
} |
| 31 |
|
| 32 |
} // namespace |
| 33 |
|
| 34 |
std::string Specifier::getSentence(Component& component) { |
| 35 |
|
| 36 |
int id = getType().getId(); |
| 37 |
std::string result; |
| 38 |
|
| 39 |
std::string amountStr = component.getArgument(0); |
| 40 |
int amount = string::convert<int>(amountStr); |
| 41 |
|
| 42 |
if (id == SpecifierType::SPEC_NONE().getId()) { |
| 43 |
result += _("<not specified>"); |
| 44 |
} |
| 45 |
else if (id == SpecifierType::SPEC_NAME().getId()) { |
| 46 |
result += _("entity ") + _value; |
| 47 |
} |
| 48 |
else if (id == SpecifierType::SPEC_OVERALL().getId()) { |
| 49 |
result += printEntityAmount(amountStr); |
| 50 |
} |
| 51 |
else if (id == SpecifierType::SPEC_GROUP().getId()) { |
| 52 |
|
| 53 |
if (_value == "loot_gold") { |
| 54 |
result += fmt::format(_("{0:d} loot in gold"), amount); |
| 55 |
} |
| 56 |
else if (_value == "loot_goods") { |
| 57 |
result += fmt::format(_("{0:d} loot in goods"), amount); |
| 58 |
} |
| 59 |
else if (_value == "loot_jewels") { |
| 60 |
result += fmt::format(_("{0:d} loot in jewels"), amount); |
| 61 |
} |
| 62 |
else if (_value == "loot_total") { |
| 63 |
result += fmt::format(_("{0:d} loot"), amount); |
| 64 |
} |
| 65 |
else { |
| 66 |
result += fmt::format(_("{0:d} of \"{1}\""), amount, _value); |
| 67 |
} |
| 68 |
} |
| 69 |
else if (id == SpecifierType::SPEC_CLASSNAME().getId()) { |
| 70 |
result += fmt::format(_("{0} of type {1}"), printEntityAmount(amountStr), _value); |
| 71 |
} |
| 72 |
else if (id == SpecifierType::SPEC_SPAWNCLASS().getId()) { |
| 73 |
result += fmt::format(_("{0} of spawnclass {1}"), printEntityAmount(amountStr), _value); |
| 74 |
} |
| 75 |
else if (id == SpecifierType::SPEC_AI_TYPE().getId()) { |
| 76 |
result += fmt::format(_("{0} AI of type {1}"), amountStr, _value); |
| 77 |
} |
| 78 |
else if (id == SpecifierType::SPEC_AI_TEAM().getId()) { |
| 79 |
result += fmt::format(_("{0} AI of team {1}"), amountStr, _value); |
| 80 |
} |
| 81 |
else if (id == SpecifierType::SPEC_AI_INNOCENCE().getId()) { |
| 82 |
result += fmt::format(_("{0} AI of {1}"), amountStr, _value); |
| 83 |
} |
| 84 |
else { |
| 85 |
rError() << "Unknown specifier ID " << id << "found!" << std::endl; |
| 86 |
} |
| 87 |
|
| 88 |
return result; |
| 89 |
} |
| 90 |
|
| 91 |
} // namespace objectives |