32 template <
class Callback>
33 auto unit_action_helper(
const std::vector<int> &unit_ids, Callback &&cb)
35 return [unit_ids, cb] {
41 auto units = std::vector<unit *>();
42 for (
const auto id : unit_ids) {
46 units.push_back(
unit);
57 template <
class RetType>
using unit_callback_type = RetType (*)(
unit *);
64 template <
class RetType>
65 auto unit_action_helper(
const std::vector<int> &unit_ids,
66 unit_callback_type<RetType> cb)
68 return unit_action_helper(unit_ids, [cb](
auto units) {
69 std::for_each(units.begin(), units.end(), cb);
78 template <
class Callback>
79 void add_units_action(QMenu *menu,
const QString &text,
80 const std::vector<int> &unit_ids,
bool enabled,
83 auto action = menu->addAction(text, unit_action_helper(unit_ids, cb));
90 void activate_callback(
const std::vector<unit *> &units)
93 for (
const auto unit : units) {
106 void load_callback(
const std::vector<unit *> &units)
108 for (
const auto unit : units) {
122 std::vector<int> unit_ids;
123 std::transform(units.begin(), units.end(), std::back_inserter(unit_ids),
124 [](
auto u) { return u->id; });
126 add_units_action(menu,
_(
"Activate Unit"), unit_ids,
true,
129 add_units_action(menu,
_(
"Sentry Unit"), unit_ids,
const QString action_id_name_translation(action_id act_id)
Get the action name used when displaying the action in the UI.
void popdown_city_dialog()
Closes the city overlay.
city_dialog * city_overlay
struct player * client_player()
Either controlling or observing.
bool can_client_issue_orders()
Returns TRUE iff the client can issue orders (such as giving unit commands).
void request_unit_fortify(struct unit *punit)
Try to fortify unit.
void unit_focus_add(struct unit *punit)
Adds this unit to the list of units in focus.
void unit_focus_set(struct unit *punit)
Sets the focus unit directly.
struct unit * request_unit_unload_all(struct unit *punit)
Returns one of the unit of the transporter which can have focus next.
void request_unit_change_homecity(struct unit *punit)
Send request to change unit homecity to server.
void request_unit_unload(struct unit *pcargo)
Send a request to the server that the cargo be unloaded from its current transporter.
void request_unit_sentry(struct unit *punit)
Try to sentry unit.
void popup_upgrade_dialog(const std::vector< unit * > &punits)
Popup dialog for upgrade units.
bool request_transport(struct unit *pcargo, struct tile *ptile)
Unit wants to get into some transport on given tile.
void popup_disband_dialog(const std::vector< unit * > &punits)
Pops up a dialog to confirm disband of the unit(s).
struct unit * game_unit_by_number(int id)
Find unit out of all units in game: now uses fast idex method, instead of looking through all units o...
void add_quick_unit_actions(QMenu *menu, const std::vector< unit * > &units)
Adds a small set of common unit actions to a menu.
pageGame * queen()
Return game instandce.
bool units_can_load(const std::vector< unit * > &units)
Returns TRUE iff any of these units can load.
bool units_can_do_action(const std::vector< unit * > &units, action_id act_id, bool can_do)
If has_flag is true, returns true iff any of the units are able to do the specified action.
bool units_are_occupied(const std::vector< unit * > &units)
Return TRUE iff any of the units is a transporter that is occupied.
bool units_can_unload(const std::vector< unit * > &units)
Return TRUE iff any of these units can unload.
bool can_units_do_activity(const std::vector< unit * > &units, enum unit_activity activity)
Returns TRUE if any of the units can do the activity.
bool units_can_upgrade(const std::vector< unit * > &units)
Return TRUE iff any of the units can be upgraded to another unit type (for money)