mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-21 12:05:29 +00:00
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:
parent
ae52d22f5c
commit
303d2eee77
@ -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: there’s 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."));
|
||||
|
Loading…
x
Reference in New Issue
Block a user