Allow the player to recruit, even when some recruitable units aren't known (#5146)

Fixes #5144 "one missing unit in recruit list makes entire recruit list
unavailable". The player will see an error dialog every time they try to
recruit, that seems good given that the limited recruitment options are likely
to severely affect game balance.

The `std::vector<t_string> unknown_units` uses t_string instead of std::string
because that's the class needed for format_conjunct_list. Those items aren't
translated - they're the values of [unit_type]id=, but the corresponding
[unit_type] is missing, so we can't get the translatable [unit_type]name=.
This commit is contained in:
Steve Cotton 2020-09-12 10:02:31 +02:00 committed by GitHub
parent ae52d22f5c
commit 303d2eee77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -259,17 +259,30 @@ void menu_handler::recruit(int side_num, const map_location& last_hex)
std::set<std::string> recruits = actions::get_recruits(side_num, last_hex);
std::vector<t_string> unknown_units;
for(const auto& recruit : recruits) {
const unit_type* type = unit_types.find(recruit);
if(!type) {
ERR_NG << "could not find unit '" << recruit << "'" << std::endl;
return;
unknown_units.emplace_back(recruit);
continue;
}
map_location ignored;
map_location recruit_hex = last_hex;
sample_units[type] = (can_recruit(type->id(), side_num, recruit_hex, ignored));
}
if(!unknown_units.empty()) {
auto unknown_ids = utils::format_conjunct_list("", unknown_units);
// TRANSLATORS: An error that should never happen, might happen when loading an old savegame. If there are
// any units that the player can recruit then their standard recruitment dialog will be shown after this
// error message, otherwise they'll get the "You have no units available to recruit." error after this one.
const auto message = VNGETTEXT("Error: theres an unknown unit type on your recruit list: $unknown_ids",
"Error: there are several unknown unit types on your recruit list: $unknown_ids",
unknown_units.size(),
utils::string_map { { "unknown_ids", unknown_ids }});
gui2::show_transient_message("", message);
}
if(sample_units.empty()) {
gui2::show_transient_message("", _("You have no units available to recruit."));