diff --git a/src/gui/dialogs/unit_recruit.cpp b/src/gui/dialogs/unit_recruit.cpp index a181e66816a0..08754405c2d1 100644 --- a/src/gui/dialogs/unit_recruit.cpp +++ b/src/gui/dialogs/unit_recruit.cpp @@ -134,28 +134,15 @@ void unit_recruit::pre_show(window& window) std::string image_string = recruit->image() + "~RC(" + recruit->flag_rgb() + ">" + team_.color() + ")"; - int wb_gold = 0; - if(resources::controller) { - if(const std::shared_ptr& whiteb = resources::controller->get_whiteboard()) { - wb::future_map future; // So gold takes into account planned spending - wb_gold = whiteb->get_spent_gold_for(team_.side()); - } - } - - /// TODO: The name is historical. This is false whenever the unit is not recruitable, not just for gold issues. - const bool can_afford = (error.empty() && recruit->cost() <= team_.gold() - wb_gold); + /// TODO: The name is historical. This is false whenever the unit is not recruitable. + const bool can_afford = error.empty(); const std::string cost_string = std::to_string(recruit->cost()); column["use_markup"] = "true"; if(!error.empty()) { - column["tooltip"] = error; - } else if(!can_afford) { // Just set the tooltip on every single element in this row. - if(wb_gold > 0) - column["tooltip"] = _("This unit cannot be recruited because you will not have enough gold at this point in your plan."); - else - column["tooltip"] = _("This unit cannot be recruited because you do not have enough gold."); + column["tooltip"] = error; } column["label"] = image_string + (can_afford ? "" : "~GS()"); diff --git a/src/menu_events.cpp b/src/menu_events.cpp index d6949312bdfe..338552aec5ec 100644 --- a/src/menu_events.cpp +++ b/src/menu_events.cpp @@ -298,6 +298,9 @@ void menu_handler::repeat_recruit(int side_num, const map_location& last_hex) } } +// TODO: Return multiple strings here, in case more than one error applies? For +// example, if you start AOI S5 with 0GP and recruit a Mage, two reasons apply, +// leader not on keep (extrarecruit=Mage) and not enough gold. std::string menu_handler::can_recruit(const std::string& name, int side_num, map_location& loc, map_location& recruited_from) { team& current_team = board().get_team(side_num); @@ -314,11 +317,19 @@ std::string menu_handler::can_recruit(const std::string& name, int side_num, map utils::string_map { { "unit_type_name", u_type->type_name() }}); } - if(u_type->cost() > current_team.gold() - (pc_.get_whiteboard() - ? pc_.get_whiteboard()->get_spent_gold_for(side_num) - : 0)) + // TODO take a wb::future_map RAII as unit_recruit::pre_show does + int wb_gold = 0; { - return _("You do not have enough gold to recruit this unit."); + wb::future_map future; + wb_gold = (pc_.get_whiteboard() ? pc_.get_whiteboard()->get_spent_gold_for(side_num) : 0); + } + if(u_type->cost() > current_team.gold() - wb_gold) + { + if(wb_gold > 0) + // TRANSLATORS: "plan" refers to Planning Mode + return _("At this point in your plan, you will not have enough gold to recruit this unit."); + else + return _("You do not have enough gold to recruit this unit."); } current_team.last_recruit(name);