From d0983acb05f0db3ec702eac9f7e48d90439c9ce5 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 1 Oct 2023 05:03:55 +0300 Subject: [PATCH 36/36] Make can_unit_do_activity...() to take map as parameter Replaces hardcoded use of the main map. See osdn #48423 Signed-off-by: Marko Lindqvist --- ai/default/aiunit.c | 11 +++--- client/control.c | 38 ++++++++++---------- client/control.h | 9 +++++ client/gui-gtk-3.0/citydlg.c | 4 +-- client/gui-gtk-3.0/menu.c | 38 ++++++++++---------- client/gui-gtk-3.0/repodlgs.c | 2 +- client/gui-gtk-3.22/citydlg.c | 4 +-- client/gui-gtk-3.22/menu.c | 38 ++++++++++---------- client/gui-gtk-3.22/repodlgs.c | 2 +- client/gui-gtk-4.0/citydlg.c | 8 ++--- client/gui-gtk-4.0/menu.c | 64 +++++++++++++++++----------------- client/gui-gtk-4.0/repodlgs.c | 2 +- client/gui-qt/citydlg.cpp | 4 +-- client/gui-qt/hudwidget.cpp | 18 +++++----- client/gui-qt/menu.cpp | 34 +++++++++--------- client/gui-qt/repodlgs.cpp | 4 +-- client/gui-sdl2/citydlg.c | 4 +-- client/gui-sdl2/dialogs.c | 2 +- client/gui-sdl2/menu.c | 26 +++++++------- common/unit.c | 28 +++++++++------ common/unit.h | 9 +++-- common/unitlist.c | 12 ++++--- common/unitlist.h | 8 +++-- server/unithand.c | 19 ++++++---- server/unittools.c | 15 +++++--- 25 files changed, 220 insertions(+), 183 deletions(-) diff --git a/ai/default/aiunit.c b/ai/default/aiunit.c index 47b822565d..a6a6e5e72a 100644 --- a/ai/default/aiunit.c +++ b/ai/default/aiunit.c @@ -853,17 +853,19 @@ static void dai_military_findjob(struct ai_type *ait, { const struct unit_type *punittype = unit_type_get(punit); struct unit_ai *unit_data; + const struct civ_map *nmap = &(wld.map); CHECK_UNIT(punit); - /* keep barbarians aggressive and primitive */ + /* Keep barbarians aggressive and primitive */ if (is_barbarian(pplayer)) { - if (can_unit_do_activity(punit, ACTIVITY_PILLAGE) - && is_land_barbarian(pplayer)) { - /* land barbarians pillage */ + if (can_unit_do_activity(nmap, punit, ACTIVITY_PILLAGE) + && is_land_barbarian(pplayer)) { + /* Land barbarians pillage */ unit_activity_handling(punit, ACTIVITY_PILLAGE); } dai_unit_new_task(ait, punit, AIUNIT_NONE, NULL); + return; } @@ -874,6 +876,7 @@ static void dai_military_findjob(struct ai_type *ait, || unit_data->task == AIUNIT_DEFEND_HOME) { aiguard_update_charge(ait, punit); } + if (aiguard_has_charge(ait, punit) && unit_data->task == AIUNIT_ESCORT) { struct unit *aunit = aiguard_charge_unit(ait, punit); diff --git a/client/control.c b/client/control.c index be14b1fb9d..1d95805b7a 100644 --- a/client/control.c +++ b/client/control.c @@ -2190,7 +2190,7 @@ void request_unit_patrol(void) void request_unit_sentry(struct unit *punit) { if (punit->activity != ACTIVITY_SENTRY - && can_unit_do_activity(punit, ACTIVITY_SENTRY)) { + && can_unit_do_activity_client(punit, ACTIVITY_SENTRY)) { request_new_unit_activity(punit, ACTIVITY_SENTRY); } } @@ -2201,7 +2201,7 @@ void request_unit_sentry(struct unit *punit) void request_unit_fortify(struct unit *punit) { if (punit->activity != ACTIVITY_FORTIFYING - && can_unit_do_activity(punit, ACTIVITY_FORTIFYING)) { + && can_unit_do_activity_client(punit, ACTIVITY_FORTIFYING)) { request_new_unit_activity(punit, ACTIVITY_FORTIFYING); } } @@ -2220,8 +2220,8 @@ void request_unit_pillage(struct unit *punit) BV_CLR_ALL(pspossible); extra_type_iterate(potential) { - if (can_unit_do_activity_targeted(punit, ACTIVITY_PILLAGE, - potential)) { + if (can_unit_do_activity_targeted_client(punit, ACTIVITY_PILLAGE, + potential)) { BV_SET(pspossible, extra_index(potential)); count++; } @@ -2809,7 +2809,7 @@ void do_map_click(struct tile *ptile, enum quickselect_type qtype) struct unit *punit = unit_list_get(ptile->units, 0); if (unit_owner(punit) == client.conn.playing) { - if (can_unit_do_activity(punit, ACTIVITY_IDLE)) { + if (can_unit_do_activity_client(punit, ACTIVITY_IDLE)) { maybe_goto = gui_options.keyboardless_goto; if (qtype == SELECT_APPEND) { unit_focus_add(punit); @@ -2824,8 +2824,8 @@ void do_map_click(struct tile *ptile, enum quickselect_type qtype) } else if (unit_list_size(ptile->units) > 0) { /* The stack list is always popped up, even if it includes enemy units. * If the server doesn't want the player to know about them it shouldn't - * tell them! The previous behavior would only pop up the stack if you - * owned a unit on the tile. This gave cheating clients an advantage, + * tell them! The previous behavior would only pop up the stack if you + * owned a unit on the tile. This gave cheating clients an advantage, * and also showed you allied units if (and only if) you had a unit on * the tile (inconsistent). */ unit_select_dialog_popup(ptile); @@ -3371,7 +3371,7 @@ void key_unit_airbase(void) void key_unit_auto_explore(void) { unit_list_iterate(get_units_in_focus(), punit) { - if (can_unit_do_activity(punit, ACTIVITY_EXPLORE)) { + if (can_unit_do_activity_client(punit, ACTIVITY_EXPLORE)) { request_unit_ssa_set(punit, SSA_AUTOEXPLORE); } } unit_list_iterate_end; @@ -3414,7 +3414,7 @@ void key_unit_fallout(void) void key_unit_fortify(void) { unit_list_iterate(get_units_in_focus(), punit) { - if (can_unit_do_activity(punit, ACTIVITY_FORTIFYING)) { + if (can_unit_do_activity_client(punit, ACTIVITY_FORTIFYING)) { request_new_unit_activity(punit, ACTIVITY_FORTIFYING); } } unit_list_iterate_end; @@ -3458,7 +3458,7 @@ static void key_unit_extra(enum unit_activity act, enum extra_cause cause) unit_owner(punit), punit); - if (can_unit_do_activity_targeted(punit, act, tgt)) { + if (can_unit_do_activity_targeted_client(punit, act, tgt)) { request_new_unit_activity_targeted(punit, act, tgt); } } unit_list_iterate_end; @@ -3477,7 +3477,7 @@ static void key_unit_gen_clean(enum unit_activity act, punit); if (tgt != NULL - && can_unit_do_activity_targeted(punit, act, tgt)) { + && can_unit_do_activity_targeted_client(punit, act, tgt)) { request_new_unit_activity_targeted(punit, act, tgt); } } unit_list_iterate_end; @@ -3497,7 +3497,7 @@ void key_unit_irrigate(void) void key_unit_cultivate(void) { unit_list_iterate(get_units_in_focus(), punit) { - if (can_unit_do_activity(punit, ACTIVITY_CULTIVATE)) { + if (can_unit_do_activity_client(punit, ACTIVITY_CULTIVATE)) { request_new_unit_activity(punit, ACTIVITY_CULTIVATE); } } unit_list_iterate_end; @@ -3517,7 +3517,7 @@ void key_unit_mine(void) void key_unit_plant(void) { unit_list_iterate(get_units_in_focus(), punit) { - if (can_unit_do_activity(punit, ACTIVITY_PLANT)) { + if (can_unit_do_activity_client(punit, ACTIVITY_PLANT)) { request_new_unit_activity(punit, ACTIVITY_PLANT); } } unit_list_iterate_end; @@ -3529,7 +3529,7 @@ void key_unit_plant(void) void key_unit_pillage(void) { unit_list_iterate(get_units_in_focus(), punit) { - if (can_unit_do_activity(punit, ACTIVITY_PILLAGE)) { + if (can_unit_do_activity_client(punit, ACTIVITY_PILLAGE)) { request_unit_pillage(punit); } } unit_list_iterate_end; @@ -3547,7 +3547,7 @@ void key_unit_clean(void) punit); if (tgt != NULL - && can_unit_do_activity_targeted(punit, ACTIVITY_POLLUTION, tgt)) { + && can_unit_do_activity_targeted_client(punit, ACTIVITY_POLLUTION, tgt)) { request_new_unit_activity_targeted(punit, ACTIVITY_POLLUTION, tgt); } else { tgt = prev_extra_in_tile(unit_tile(punit), @@ -3556,7 +3556,7 @@ void key_unit_clean(void) punit); if (tgt != NULL - && can_unit_do_activity_targeted(punit, ACTIVITY_FALLOUT, tgt)) { + && can_unit_do_activity_targeted_client(punit, ACTIVITY_FALLOUT, tgt)) { request_new_unit_activity_targeted(punit, ACTIVITY_FALLOUT, tgt); } } @@ -3583,7 +3583,7 @@ void key_unit_road(void) punit); if (tgt != NULL - && can_unit_do_activity_targeted(punit, ACTIVITY_GEN_ROAD, tgt)) { + && can_unit_do_activity_targeted_client(punit, ACTIVITY_GEN_ROAD, tgt)) { request_new_unit_activity_targeted(punit, ACTIVITY_GEN_ROAD, tgt); } } unit_list_iterate_end; @@ -3595,7 +3595,7 @@ void key_unit_road(void) void key_unit_sentry(void) { unit_list_iterate(get_units_in_focus(), punit) { - if (can_unit_do_activity(punit, ACTIVITY_SENTRY)) { + if (can_unit_do_activity_client(punit, ACTIVITY_SENTRY)) { request_new_unit_activity(punit, ACTIVITY_SENTRY); } } unit_list_iterate_end; @@ -3607,7 +3607,7 @@ void key_unit_sentry(void) void key_unit_transform(void) { unit_list_iterate(get_units_in_focus(), punit) { - if (can_unit_do_activity(punit, ACTIVITY_TRANSFORM)) { + if (can_unit_do_activity_client(punit, ACTIVITY_TRANSFORM)) { request_new_unit_activity(punit, ACTIVITY_TRANSFORM); } } unit_list_iterate_end; diff --git a/client/control.h b/client/control.h index 047013718a..5c01794145 100644 --- a/client/control.h +++ b/client/control.h @@ -37,6 +37,15 @@ enum quickselect_type { SELECT_POPUP = 0, SELECT_SEA, SELECT_LAND, SELECT_APPEND, SELECT_FOCUS }; +#define can_unit_do_activity_client(_punit_, _act_) \ + can_unit_do_activity(&(wld.map), _punit_, _act_) +#define can_unit_do_activity_targeted_client(_punit_, _act_, _tgt_) \ + can_unit_do_activity_targeted(&(wld.map), _punit_, _act_, _tgt_) +#define can_units_do_activity_client(_punits_, _act_) \ + can_units_do_activity(&(wld.map), _punits_, _act_) +#define can_units_do_activity_targeted_client(_punits_, _act_, _tgt_) \ + can_units_do_activity_targeted(&(wld.map), _punits_, _act_, _tgt_) + void control_init(void); void control_free(void); void control_unit_killed(struct unit *punit); diff --git a/client/gui-gtk-3.0/citydlg.c b/client/gui-gtk-3.0/citydlg.c index a5345650c7..f8f1b3810b 100644 --- a/client/gui-gtk-3.0/citydlg.c +++ b/client/gui-gtk-3.0/citydlg.c @@ -2539,7 +2539,7 @@ static gboolean present_unit_callback(GtkWidget *w, GdkEventButton *ev, gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); if (punit->activity == ACTIVITY_SENTRY - || !can_unit_do_activity(punit, ACTIVITY_SENTRY)) { + || !can_unit_do_activity_client(punit, ACTIVITY_SENTRY)) { gtk_widget_set_sensitive(item, FALSE); } @@ -2550,7 +2550,7 @@ static gboolean present_unit_callback(GtkWidget *w, GdkEventButton *ev, gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); if (punit->activity == ACTIVITY_FORTIFYING - || !can_unit_do_activity(punit, ACTIVITY_FORTIFYING)) { + || !can_unit_do_activity_client(punit, ACTIVITY_FORTIFYING)) { gtk_widget_set_sensitive(item, FALSE); } diff --git a/client/gui-gtk-3.0/menu.c b/client/gui-gtk-3.0/menu.c index 04604f502a..7963c5e7b9 100644 --- a/client/gui-gtk-3.0/menu.c +++ b/client/gui-gtk-3.0/menu.c @@ -1760,7 +1760,7 @@ static void build_road_callback(GtkMenuItem *action, gpointer data) bool building_road = FALSE; if (tgt != NULL - && can_unit_do_activity_targeted(punit, ACTIVITY_GEN_ROAD, tgt)) { + && can_unit_do_activity_targeted_client(punit, ACTIVITY_GEN_ROAD, tgt)) { request_new_unit_activity_targeted(punit, ACTIVITY_GEN_ROAD, tgt); building_road = TRUE; } @@ -2428,9 +2428,9 @@ void real_menus_update(void) pextra = g_object_get_data(G_OBJECT(iter->data), "base"); if (NULL != pextra) { gtk_widget_set_sensitive(GTK_WIDGET(iter->data), - can_units_do_activity_targeted(punits, - ACTIVITY_BASE, - pextra)); + can_units_do_activity_targeted_client(punits, + ACTIVITY_BASE, + pextra)); } } g_list_free(list); @@ -2446,9 +2446,9 @@ void real_menus_update(void) pextra = g_object_get_data(G_OBJECT(iter->data), "road"); if (NULL != pextra) { gtk_widget_set_sensitive(GTK_WIDGET(iter->data), - can_units_do_activity_targeted(punits, - ACTIVITY_GEN_ROAD, - pextra)); + can_units_do_activity_targeted_client(punits, + ACTIVITY_GEN_ROAD, + pextra)); } } g_list_free(list); @@ -2496,34 +2496,34 @@ void real_menus_update(void) || can_units_do(punits, unit_can_est_trade_route_here))); menu_entry_set_sensitive("BUILD_IRRIGATION", - can_units_do_activity(punits, ACTIVITY_IRRIGATE)); + can_units_do_activity_client(punits, ACTIVITY_IRRIGATE)); menu_entry_set_sensitive("CULTIVATE", - can_units_do_activity(punits, ACTIVITY_CULTIVATE)); + can_units_do_activity_client(punits, ACTIVITY_CULTIVATE)); menu_entry_set_sensitive("BUILD_MINE", - can_units_do_activity(punits, ACTIVITY_MINE)); + can_units_do_activity_client(punits, ACTIVITY_MINE)); menu_entry_set_sensitive("PLANT", - can_units_do_activity(punits, ACTIVITY_PLANT)); + can_units_do_activity_client(punits, ACTIVITY_PLANT)); menu_entry_set_sensitive("TRANSFORM_TERRAIN", - can_units_do_activity(punits, ACTIVITY_TRANSFORM)); + can_units_do_activity_client(punits, ACTIVITY_TRANSFORM)); menu_entry_set_sensitive("FORTIFY", - can_units_do_activity(punits, - ACTIVITY_FORTIFYING)); + can_units_do_activity_client(punits, + ACTIVITY_FORTIFYING)); menu_entry_set_sensitive("BUILD_FORTRESS", can_units_do_base_gui(punits, BASE_GUI_FORTRESS)); menu_entry_set_sensitive("BUILD_AIRBASE", can_units_do_base_gui(punits, BASE_GUI_AIRBASE)); menu_entry_set_sensitive("CLEAN_POLLUTION", - can_units_do_activity(punits, ACTIVITY_POLLUTION)); + can_units_do_activity_client(punits, ACTIVITY_POLLUTION)); menu_entry_set_sensitive("CLEAN_FALLOUT", - can_units_do_activity(punits, ACTIVITY_FALLOUT)); + can_units_do_activity_client(punits, ACTIVITY_FALLOUT)); menu_entry_set_sensitive("UNIT_SENTRY", - can_units_do_activity(punits, ACTIVITY_SENTRY)); + can_units_do_activity_client(punits, ACTIVITY_SENTRY)); menu_entry_set_sensitive("DO_PARADROP", can_units_do(punits, can_unit_paradrop)); /* FIXME: should conditionally rename "Pillage" to "Pillage..." in cases where * selecting the command results in a dialog box listing options of what to pillage */ menu_entry_set_sensitive("DO_PILLAGE", - can_units_do_activity(punits, ACTIVITY_PILLAGE)); + can_units_do_activity_client(punits, ACTIVITY_PILLAGE)); menu_entry_set_sensitive("UNIT_DISBAND", units_can_do_action(punits, ACTION_DISBAND_UNIT, TRUE)); @@ -2544,7 +2544,7 @@ void real_menus_update(void) menu_entry_set_sensitive("AUTO_SETTLER", can_units_do(punits, can_unit_do_autosettlers)); menu_entry_set_sensitive("UNIT_EXPLORE", - can_units_do_activity(punits, ACTIVITY_EXPLORE)); + can_units_do_activity_client(punits, ACTIVITY_EXPLORE)); proad = road_by_gui_type(ROAD_GUI_ROAD); if (proad != NULL) { diff --git a/client/gui-gtk-3.0/repodlgs.c b/client/gui-gtk-3.0/repodlgs.c index a58e5df2d1..cc3808e402 100644 --- a/client/gui-gtk-3.0/repodlgs.c +++ b/client/gui-gtk-3.0/repodlgs.c @@ -1604,7 +1604,7 @@ static void units_report_command_callback(struct gui_dialog *pdialog, if (ACTIVITY_IDLE == punit->activity || ACTIVITY_SENTRY == punit->activity) { - if (can_unit_do_activity(punit, ACTIVITY_IDLE)) { + if (can_unit_do_activity_client(punit, ACTIVITY_IDLE)) { unit_focus_set_and_select(punit); } } diff --git a/client/gui-gtk-3.22/citydlg.c b/client/gui-gtk-3.22/citydlg.c index d10e1c7df8..f7ed883d6a 100644 --- a/client/gui-gtk-3.22/citydlg.c +++ b/client/gui-gtk-3.22/citydlg.c @@ -2555,7 +2555,7 @@ static gboolean present_unit_callback(GtkWidget *w, GdkEventButton *ev, gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); if (punit->activity == ACTIVITY_SENTRY - || !can_unit_do_activity(punit, ACTIVITY_SENTRY)) { + || !can_unit_do_activity_client(punit, ACTIVITY_SENTRY)) { gtk_widget_set_sensitive(item, FALSE); } @@ -2566,7 +2566,7 @@ static gboolean present_unit_callback(GtkWidget *w, GdkEventButton *ev, gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); if (punit->activity == ACTIVITY_FORTIFYING - || !can_unit_do_activity(punit, ACTIVITY_FORTIFYING)) { + || !can_unit_do_activity_client(punit, ACTIVITY_FORTIFYING)) { gtk_widget_set_sensitive(item, FALSE); } diff --git a/client/gui-gtk-3.22/menu.c b/client/gui-gtk-3.22/menu.c index b86428406b..6f0b48e4f2 100644 --- a/client/gui-gtk-3.22/menu.c +++ b/client/gui-gtk-3.22/menu.c @@ -1785,7 +1785,7 @@ static void build_road_callback(GtkMenuItem *action, gpointer data) bool building_road = FALSE; if (tgt != NULL - && can_unit_do_activity_targeted(punit, ACTIVITY_GEN_ROAD, tgt)) { + && can_unit_do_activity_targeted_client(punit, ACTIVITY_GEN_ROAD, tgt)) { request_new_unit_activity_targeted(punit, ACTIVITY_GEN_ROAD, tgt); building_road = TRUE; } @@ -2455,9 +2455,9 @@ void real_menus_update(void) pextra = g_object_get_data(G_OBJECT(iter->data), "base"); if (NULL != pextra) { gtk_widget_set_sensitive(GTK_WIDGET(iter->data), - can_units_do_activity_targeted(punits, - ACTIVITY_BASE, - pextra)); + can_units_do_activity_targeted_client(punits, + ACTIVITY_BASE, + pextra)); } } g_list_free(list); @@ -2473,9 +2473,9 @@ void real_menus_update(void) pextra = g_object_get_data(G_OBJECT(iter->data), "road"); if (NULL != pextra) { gtk_widget_set_sensitive(GTK_WIDGET(iter->data), - can_units_do_activity_targeted(punits, - ACTIVITY_GEN_ROAD, - pextra)); + can_units_do_activity_targeted_client(punits, + ACTIVITY_GEN_ROAD, + pextra)); } } g_list_free(list); @@ -2523,34 +2523,34 @@ void real_menus_update(void) || can_units_do(punits, unit_can_est_trade_route_here))); menu_entry_set_sensitive("BUILD_IRRIGATION", - can_units_do_activity(punits, ACTIVITY_IRRIGATE)); + can_units_do_activity_client(punits, ACTIVITY_IRRIGATE)); menu_entry_set_sensitive("CULTIVATE", - can_units_do_activity(punits, ACTIVITY_CULTIVATE)); + can_units_do_activity_client(punits, ACTIVITY_CULTIVATE)); menu_entry_set_sensitive("BUILD_MINE", - can_units_do_activity(punits, ACTIVITY_MINE)); + can_units_do_activity_client(punits, ACTIVITY_MINE)); menu_entry_set_sensitive("PLANT", - can_units_do_activity(punits, ACTIVITY_PLANT)); + can_units_do_activity_client(punits, ACTIVITY_PLANT)); menu_entry_set_sensitive("TRANSFORM_TERRAIN", - can_units_do_activity(punits, ACTIVITY_TRANSFORM)); + can_units_do_activity_client(punits, ACTIVITY_TRANSFORM)); menu_entry_set_sensitive("FORTIFY", - can_units_do_activity(punits, - ACTIVITY_FORTIFYING)); + can_units_do_activity_client(punits, + ACTIVITY_FORTIFYING)); menu_entry_set_sensitive("BUILD_FORTRESS", can_units_do_base_gui(punits, BASE_GUI_FORTRESS)); menu_entry_set_sensitive("BUILD_AIRBASE", can_units_do_base_gui(punits, BASE_GUI_AIRBASE)); menu_entry_set_sensitive("CLEAN_POLLUTION", - can_units_do_activity(punits, ACTIVITY_POLLUTION)); + can_units_do_activity_client(punits, ACTIVITY_POLLUTION)); menu_entry_set_sensitive("CLEAN_FALLOUT", - can_units_do_activity(punits, ACTIVITY_FALLOUT)); + can_units_do_activity_client(punits, ACTIVITY_FALLOUT)); menu_entry_set_sensitive("UNIT_SENTRY", - can_units_do_activity(punits, ACTIVITY_SENTRY)); + can_units_do_activity_client(punits, ACTIVITY_SENTRY)); menu_entry_set_sensitive("DO_PARADROP", can_units_do(punits, can_unit_paradrop)); /* FIXME: should conditionally rename "Pillage" to "Pillage..." in cases where * selecting the command results in a dialog box listing options of what to pillage */ menu_entry_set_sensitive("DO_PILLAGE", - can_units_do_activity(punits, ACTIVITY_PILLAGE)); + can_units_do_activity_client(punits, ACTIVITY_PILLAGE)); menu_entry_set_sensitive("UNIT_DISBAND", units_can_do_action(punits, ACTION_DISBAND_UNIT, TRUE)); @@ -2571,7 +2571,7 @@ void real_menus_update(void) menu_entry_set_sensitive("AUTO_SETTLER", can_units_do(punits, can_unit_do_autosettlers)); menu_entry_set_sensitive("UNIT_EXPLORE", - can_units_do_activity(punits, ACTIVITY_EXPLORE)); + can_units_do_activity_client(punits, ACTIVITY_EXPLORE)); proad = road_by_gui_type(ROAD_GUI_ROAD); if (proad != NULL) { diff --git a/client/gui-gtk-3.22/repodlgs.c b/client/gui-gtk-3.22/repodlgs.c index f29d2da17f..0e23b182ad 100644 --- a/client/gui-gtk-3.22/repodlgs.c +++ b/client/gui-gtk-3.22/repodlgs.c @@ -1603,7 +1603,7 @@ static void units_report_command_callback(struct gui_dialog *pdialog, if (ACTIVITY_IDLE == punit->activity || ACTIVITY_SENTRY == punit->activity) { - if (can_unit_do_activity(punit, ACTIVITY_IDLE)) { + if (can_unit_do_activity_client(punit, ACTIVITY_IDLE)) { unit_focus_set_and_select(punit); } } diff --git a/client/gui-gtk-4.0/citydlg.c b/client/gui-gtk-4.0/citydlg.c index b0cfb87864..7b6b72e792 100644 --- a/client/gui-gtk-4.0/citydlg.c +++ b/client/gui-gtk-4.0/citydlg.c @@ -2551,8 +2551,8 @@ static bool create_unit_menu(struct city_dialog *pdialog, struct unit *punit, GINT_TO_POINTER(punit->id)); g_simple_action_set_enabled(G_SIMPLE_ACTION(act), punit->activity != ACTIVITY_SENTRY - && can_unit_do_activity(punit, - ACTIVITY_SENTRY)); + && can_unit_do_activity_client(punit, + ACTIVITY_SENTRY)); menu_item_append_unref(menu, g_menu_item_new(_("_Sentry unit"), "win.sentry")); @@ -2563,8 +2563,8 @@ static bool create_unit_menu(struct city_dialog *pdialog, struct unit *punit, GINT_TO_POINTER(punit->id)); g_simple_action_set_enabled(G_SIMPLE_ACTION(act), punit->activity != ACTIVITY_FORTIFYING - && can_unit_do_activity(punit, - ACTIVITY_FORTIFYING)); + && can_unit_do_activity_client(punit, + ACTIVITY_FORTIFYING)); menu_item_append_unref(menu, g_menu_item_new(_("_Fortify unit"), "win.fortify")); } diff --git a/client/gui-gtk-4.0/menu.c b/client/gui-gtk-4.0/menu.c index c2135c5168..13c8cdbd1c 100644 --- a/client/gui-gtk-4.0/menu.c +++ b/client/gui-gtk-4.0/menu.c @@ -2465,7 +2465,7 @@ static void build_road_callback(GSimpleAction *action, bool building_road = FALSE; if (tgt != NULL - && can_unit_do_activity_targeted(punit, ACTIVITY_GEN_ROAD, tgt)) { + && can_unit_do_activity_targeted_client(punit, ACTIVITY_GEN_ROAD, tgt)) { request_new_unit_activity_targeted(punit, ACTIVITY_GEN_ROAD, tgt); building_road = TRUE; } @@ -2762,7 +2762,7 @@ static void clean_menu_callback(GSimpleAction *action, struct extra_type *pextra = data; unit_list_iterate(get_units_in_focus(), punit) { - if (can_unit_do_activity_targeted(punit, ACTIVITY_POLLUTION, pextra)) { + if (can_unit_do_activity_targeted_client(punit, ACTIVITY_POLLUTION, pextra)) { request_new_unit_activity_targeted(punit, ACTIVITY_POLLUTION, pextra); } else { @@ -3549,9 +3549,9 @@ void real_menus_update(void) fc_snprintf(actname, sizeof(actname), "path_%d", i); act = g_simple_action_new(actname, NULL); g_simple_action_set_enabled(act, - can_units_do_activity_targeted(punits, - ACTIVITY_GEN_ROAD, - pextra)); + can_units_do_activity_targeted_client(punits, + ACTIVITY_GEN_ROAD, + pextra)); g_action_map_add_action(map, G_ACTION(act)); g_signal_connect(act, "activate", G_CALLBACK(road_callback), pextra); @@ -3574,9 +3574,9 @@ void real_menus_update(void) fc_snprintf(actname, sizeof(actname), "irrig_%d", i); act = g_simple_action_new(actname, NULL); g_simple_action_set_enabled(act, - can_units_do_activity_targeted(punits, - ACTIVITY_IRRIGATE, - pextra)); + can_units_do_activity_targeted_client(punits, + ACTIVITY_IRRIGATE, + pextra)); g_action_map_add_action(map, G_ACTION(act)); g_signal_connect(act, "activate", G_CALLBACK(irrigation_callback), pextra); @@ -3599,9 +3599,9 @@ void real_menus_update(void) fc_snprintf(actname, sizeof(actname), "mine_%d", i); act = g_simple_action_new(actname, NULL); g_simple_action_set_enabled(act, - can_units_do_activity_targeted(punits, - ACTIVITY_MINE, - pextra)); + can_units_do_activity_targeted_client(punits, + ACTIVITY_MINE, + pextra)); g_action_map_add_action(map, G_ACTION(act)); g_signal_connect(act, "activate", G_CALLBACK(mine_callback), pextra); @@ -3623,9 +3623,9 @@ void real_menus_update(void) fc_snprintf(actname, sizeof(actname), "clean_%d", i); act = g_simple_action_new(actname, NULL); g_simple_action_set_enabled(act, - can_units_do_activity_targeted(punits, - ACTIVITY_POLLUTION, - pextra)); + can_units_do_activity_targeted_client(punits, + ACTIVITY_POLLUTION, + pextra)); g_action_map_add_action(map, G_ACTION(act)); g_signal_connect(act, "activate", G_CALLBACK(clean_menu_callback), pextra); @@ -3641,9 +3641,9 @@ void real_menus_update(void) fc_snprintf(actname, sizeof(actname), "clean_%d", i); act = g_simple_action_new(actname, NULL); g_simple_action_set_enabled(act, - can_units_do_activity_targeted(punits, - ACTIVITY_FALLOUT, - pextra)); + can_units_do_activity_targeted_client(punits, + ACTIVITY_FALLOUT, + pextra)); g_action_map_add_action(map, G_ACTION(act)); g_signal_connect(act, "activate", G_CALLBACK(clean_menu_callback), pextra); @@ -3666,9 +3666,9 @@ void real_menus_update(void) fc_snprintf(actname, sizeof(actname), "base_%d", i); act = g_simple_action_new(actname, NULL); g_simple_action_set_enabled(act, - can_units_do_activity_targeted(punits, - ACTIVITY_BASE, - pextra)); + can_units_do_activity_targeted_client(punits, + ACTIVITY_BASE, + pextra)); g_action_map_add_action(map, G_ACTION(act)); g_signal_connect(act, "activate", G_CALLBACK(base_callback), pextra); @@ -3790,31 +3790,31 @@ void real_menus_update(void) || can_units_do(punits, unit_can_est_trade_route_here))); menu_entry_set_sensitive(map, "BUILD_IRRIGATION", - can_units_do_activity(punits, ACTIVITY_IRRIGATE)); + can_units_do_activity_client(punits, ACTIVITY_IRRIGATE)); menu_entry_set_sensitive(map, "BUILD_MINE", - can_units_do_activity(punits, ACTIVITY_MINE)); + can_units_do_activity_client(punits, ACTIVITY_MINE)); menu_entry_set_sensitive(map, "CULTIVATE", - can_units_do_activity(punits, ACTIVITY_CULTIVATE)); + can_units_do_activity_client(punits, ACTIVITY_CULTIVATE)); menu_entry_set_sensitive(map, "PLANT", - can_units_do_activity(punits, ACTIVITY_PLANT)); + can_units_do_activity_client(punits, ACTIVITY_PLANT)); menu_entry_set_sensitive(map, "TRANSFORM_TERRAIN", - can_units_do_activity(punits, ACTIVITY_TRANSFORM)); + can_units_do_activity_client(punits, ACTIVITY_TRANSFORM)); menu_entry_set_sensitive(map, "FORTIFY", - can_units_do_activity(punits, - ACTIVITY_FORTIFYING)); + can_units_do_activity_client(punits, + ACTIVITY_FORTIFYING)); menu_entry_set_sensitive(map, "PARADROP", can_units_do(punits, can_unit_paradrop)); menu_entry_set_sensitive(map, "PILLAGE", - can_units_do_activity(punits, ACTIVITY_PILLAGE)); + can_units_do_activity_client(punits, ACTIVITY_PILLAGE)); menu_entry_set_sensitive(map, "CLEAN", - can_units_do_activity(punits, ACTIVITY_POLLUTION) - || can_units_do_activity(punits, ACTIVITY_FALLOUT)); + can_units_do_activity_client(punits, ACTIVITY_POLLUTION) + || can_units_do_activity_client(punits, ACTIVITY_FALLOUT)); menu_entry_set_sensitive(map, "BUILD_FORTRESS", can_units_do_base_gui(punits, BASE_GUI_FORTRESS)); menu_entry_set_sensitive(map, "BUILD_AIRBASE", can_units_do_base_gui(punits, BASE_GUI_AIRBASE)); menu_entry_set_sensitive(map, "UNIT_SENTRY", - can_units_do_activity(punits, ACTIVITY_SENTRY)); + can_units_do_activity_client(punits, ACTIVITY_SENTRY)); menu_entry_set_sensitive(map, "UNSENTRY_ALL", units_have_activity_on_tile(punits, ACTIVITY_SENTRY)); @@ -3829,7 +3829,7 @@ void real_menus_update(void) menu_entry_set_sensitive(map, "AUTO_SETTLER", can_units_do(punits, can_unit_do_autosettlers)); menu_entry_set_sensitive(map, "UNIT_EXPLORE", - can_units_do_activity(punits, ACTIVITY_EXPLORE)); + can_units_do_activity_client(punits, ACTIVITY_EXPLORE)); menu_entry_set_sensitive(map, "UNIT_BOARD", units_can_load(punits)); menu_entry_set_sensitive(map, "UNIT_DEBOARD", diff --git a/client/gui-gtk-4.0/repodlgs.c b/client/gui-gtk-4.0/repodlgs.c index f3dc5c2614..7777027a0b 100644 --- a/client/gui-gtk-4.0/repodlgs.c +++ b/client/gui-gtk-4.0/repodlgs.c @@ -1632,7 +1632,7 @@ static void units_report_command_callback(struct gui_dialog *pdialog, if (ACTIVITY_IDLE == punit->activity || ACTIVITY_SENTRY == punit->activity) { - if (can_unit_do_activity(punit, ACTIVITY_IDLE)) { + if (can_unit_do_activity_client(punit, ACTIVITY_IDLE)) { unit_focus_set_and_select(punit); } } diff --git a/client/gui-qt/citydlg.cpp b/client/gui-qt/citydlg.cpp index 37894bd985..b2d943af87 100644 --- a/client/gui-qt/citydlg.cpp +++ b/client/gui-qt/citydlg.cpp @@ -816,14 +816,14 @@ void unit_item::create_actions() connect(activate_and_close, &QAction::triggered, this, &unit_item::activate_and_close_dialog); - if (can_unit_do_activity(qunit, ACTIVITY_SENTRY)) { + if (can_unit_do_activity_client(qunit, ACTIVITY_SENTRY)) { sentry = new QAction(_("Sentry unit"), this); connect(sentry, &QAction::triggered, this, &unit_item::sentry_unit); } else { sentry = NULL; } - if (can_unit_do_activity(qunit, ACTIVITY_FORTIFYING)) { + if (can_unit_do_activity_client(qunit, ACTIVITY_FORTIFYING)) { fortify = new QAction(_("Fortify unit"), this); connect(fortify, &QAction::triggered, this, &unit_item::fortify_unit); } else { diff --git a/client/gui-qt/hudwidget.cpp b/client/gui-qt/hudwidget.cpp index 20daffce27..64017e52f9 100644 --- a/client/gui-qt/hudwidget.cpp +++ b/client/gui-qt/hudwidget.cpp @@ -1001,35 +1001,35 @@ int unit_actions::update_actions() } - if (can_unit_do_activity(current_unit, ACTIVITY_MINE)) { + if (can_unit_do_activity_client(current_unit, ACTIVITY_MINE)) { a = new hud_action(this); a->action_shortcut = SC_BUILDMINE; a->set_pixmap(fc_icons::instance()->get_pixmap("mine")); actions.append(a); } - if (can_unit_do_activity(current_unit, ACTIVITY_PLANT)) { + if (can_unit_do_activity_client(current_unit, ACTIVITY_PLANT)) { a = new hud_action(this); a->action_shortcut = SC_PLANT; a->set_pixmap(fc_icons::instance()->get_pixmap("plantforest")); actions.append(a); } - if (can_unit_do_activity(current_unit, ACTIVITY_IRRIGATE)) { + if (can_unit_do_activity_client(current_unit, ACTIVITY_IRRIGATE)) { a = new hud_action(this); a->action_shortcut = SC_BUILDIRRIGATION; a->set_pixmap(fc_icons::instance()->get_pixmap("irrigation")); actions.append(a); } - if (can_unit_do_activity(current_unit, ACTIVITY_CULTIVATE)) { + if (can_unit_do_activity_client(current_unit, ACTIVITY_CULTIVATE)) { a = new hud_action(this); a->action_shortcut = SC_CULTIVATE; a->set_pixmap(fc_icons::instance()->get_pixmap("chopchop")); actions.append(a); } - if (can_unit_do_activity(current_unit, ACTIVITY_TRANSFORM)) { + if (can_unit_do_activity_client(current_unit, ACTIVITY_TRANSFORM)) { a = new hud_action(this); a->action_shortcut = SC_TRANSFORM; a->set_pixmap(fc_icons::instance()->get_pixmap("transform")); @@ -1059,7 +1059,7 @@ int unit_actions::update_actions() actions.append(a); - if (can_unit_do_activity(current_unit, ACTIVITY_FORTIFYING)) { + if (can_unit_do_activity_client(current_unit, ACTIVITY_FORTIFYING)) { a = new hud_action(this); a->action_shortcut = SC_FORTIFY; a->set_pixmap(fc_icons::instance()->get_pixmap("fortify")); @@ -1067,7 +1067,7 @@ int unit_actions::update_actions() } - if (can_unit_do_activity(current_unit, ACTIVITY_SENTRY)) { + if (can_unit_do_activity_client(current_unit, ACTIVITY_SENTRY)) { a = new hud_action(this); a->action_shortcut = SC_SENTRY; a->set_pixmap(fc_icons::instance()->get_pixmap("sentry")); @@ -1117,8 +1117,8 @@ int unit_actions::update_actions() actions.append(a); } - /* Clean pollution */ - if (can_unit_do_activity(current_unit, ACTIVITY_POLLUTION)) { + // Clean pollution + if (can_unit_do_activity_client(current_unit, ACTIVITY_POLLUTION)) { a = new hud_action(this); a->action_shortcut = SC_PARADROP; a->set_pixmap(fc_icons::instance()->get_pixmap("pollution")); diff --git a/client/gui-qt/menu.cpp b/client/gui-qt/menu.cpp index ba5328966a..4dc405015c 100644 --- a/client/gui-qt/menu.cpp +++ b/client/gui-qt/menu.cpp @@ -2002,7 +2002,7 @@ void mr_menu::update_roads_menu() QObject::connect(act, &QAction::triggered, [this,road_id]() { slot_build_path(road_id); }); - if (can_units_do_activity_targeted(punits, + if (can_units_do_activity_targeted_client(punits, ACTIVITY_GEN_ROAD, pextra)) { act->setEnabled(true); enabled = true; @@ -2050,7 +2050,7 @@ void mr_menu::update_bases_menu() QObject::connect(act, &QAction::triggered, [this,base_id]() { slot_build_base(base_id); }); - if (can_units_do_activity_targeted(punits, ACTIVITY_BASE, pextra)) { + if (can_units_do_activity_targeted_client(punits, ACTIVITY_BASE, pextra)) { act->setEnabled(true); enabled = true; } else { @@ -2178,7 +2178,7 @@ void mr_menu::menus_sensitive() break; case EXPLORE: - if (can_units_do_activity(punits, ACTIVITY_EXPLORE)) { + if (can_units_do_activity_client(punits, ACTIVITY_EXPLORE)) { i.value()->setEnabled(true); } break; @@ -2208,7 +2208,7 @@ void mr_menu::menus_sensitive() break; case MINE: - if (can_units_do_activity(punits, ACTIVITY_MINE)) { + if (can_units_do_activity_client(punits, ACTIVITY_MINE)) { i.value()->setEnabled(true); } @@ -2242,7 +2242,7 @@ void mr_menu::menus_sensitive() break; case IRRIGATION: - if (can_units_do_activity(punits, ACTIVITY_IRRIGATE)) { + if (can_units_do_activity_client(punits, ACTIVITY_IRRIGATE)) { i.value()->setEnabled(true); } if (units_all_same_tile) { @@ -2275,7 +2275,7 @@ void mr_menu::menus_sensitive() break; case CULTIVATE: - if (can_units_do_activity(punits, ACTIVITY_CULTIVATE)) { + if (can_units_do_activity_client(punits, ACTIVITY_CULTIVATE)) { i.value()->setEnabled(true); } if (units_all_same_tile) { @@ -2298,7 +2298,7 @@ void mr_menu::menus_sensitive() break; case PLANT: - if (can_units_do_activity(punits, ACTIVITY_PLANT)) { + if (can_units_do_activity_client(punits, ACTIVITY_PLANT)) { i.value()->setEnabled(true); } if (units_all_same_tile) { @@ -2321,7 +2321,7 @@ void mr_menu::menus_sensitive() break; case TRANSFORM: - if (can_units_do_activity(punits, ACTIVITY_TRANSFORM)) { + if (can_units_do_activity_client(punits, ACTIVITY_TRANSFORM)) { i.value()->setEnabled(true); } else { break; @@ -2386,7 +2386,7 @@ void mr_menu::menus_sensitive() break; case FORTIFY: - if (can_units_do_activity(punits, ACTIVITY_FORTIFYING)) { + if (can_units_do_activity_client(punits, ACTIVITY_FORTIFYING)) { i.value()->setEnabled(true); } break; @@ -2404,7 +2404,7 @@ void mr_menu::menus_sensitive() break; case POLLUTION: - if (can_units_do_activity(punits, ACTIVITY_POLLUTION) + if (can_units_do_activity_client(punits, ACTIVITY_POLLUTION) || can_units_do(punits, can_unit_paradrop)) { i.value()->setEnabled(true); } @@ -2422,19 +2422,19 @@ void mr_menu::menus_sensitive() break; case FALLOUT: - if (can_units_do_activity(punits, ACTIVITY_FALLOUT)) { + if (can_units_do_activity_client(punits, ACTIVITY_FALLOUT)) { i.value()->setEnabled(true); } break; case SENTRY: - if (can_units_do_activity(punits, ACTIVITY_SENTRY)) { + if (can_units_do_activity_client(punits, ACTIVITY_SENTRY)) { i.value()->setEnabled(true); } break; case PILLAGE: - if (can_units_do_activity(punits, ACTIVITY_PILLAGE)) { + if (can_units_do_activity_client(punits, ACTIVITY_PILLAGE)) { i.value()->setEnabled(true); } break; @@ -2804,7 +2804,7 @@ void mr_menu::slot_build_road() bool building_road = false; if (tgt != NULL - && can_unit_do_activity_targeted(punit, ACTIVITY_GEN_ROAD, tgt)) { + && can_unit_do_activity_targeted_client(punit, ACTIVITY_GEN_ROAD, tgt)) { request_new_unit_activity_targeted(punit, ACTIVITY_GEN_ROAD, tgt); building_road = true; } @@ -3716,8 +3716,8 @@ void mr_menu::slot_build_path(int id) unit_list_iterate(get_units_in_focus(), punit) { extra_type_by_cause_iterate(EC_ROAD, pextra) { if (pextra->buildable && pextra->id == id - && can_unit_do_activity_targeted(punit, ACTIVITY_GEN_ROAD, - pextra)) { + && can_unit_do_activity_targeted_client(punit, ACTIVITY_GEN_ROAD, + pextra)) { request_new_unit_activity_targeted(punit, ACTIVITY_GEN_ROAD, pextra); } } extra_type_by_cause_iterate_end; @@ -3732,7 +3732,7 @@ void mr_menu::slot_build_base(int id) unit_list_iterate(get_units_in_focus(), punit) { extra_type_by_cause_iterate(EC_BASE, pextra) { if (pextra->buildable && pextra->id == id - && can_unit_do_activity_targeted(punit, ACTIVITY_BASE, + && can_unit_do_activity_targeted_client(punit, ACTIVITY_BASE, pextra)) { request_new_unit_activity_targeted(punit, ACTIVITY_BASE, pextra); } diff --git a/client/gui-qt/repodlgs.cpp b/client/gui-qt/repodlgs.cpp index 1f09de102b..123cfb610d 100644 --- a/client/gui-qt/repodlgs.cpp +++ b/client/gui-qt/repodlgs.cpp @@ -284,7 +284,7 @@ void unittype_item::wheelEvent(QWheelEvent *event) } if (ACTIVITY_IDLE == punit->activity || ACTIVITY_SENTRY == punit->activity) { - if (can_unit_do_activity(punit, ACTIVITY_IDLE)) { + if (can_unit_do_activity_client(punit, ACTIVITY_IDLE)) { unit_count++; } } @@ -309,7 +309,7 @@ void unittype_item::wheelEvent(QWheelEvent *event) } if (ACTIVITY_IDLE == punit->activity || ACTIVITY_SENTRY == punit->activity) { - if (can_unit_do_activity(punit, ACTIVITY_IDLE)) { + if (can_unit_do_activity_client(punit, ACTIVITY_IDLE)) { unit_count++; if (unit_count == unit_scroll) { unit_focus_set_and_select(punit); diff --git a/client/gui-sdl2/citydlg.c b/client/gui-sdl2/citydlg.c index 5be8439871..0468d829c9 100644 --- a/client/gui-sdl2/citydlg.c +++ b/client/gui-sdl2/citydlg.c @@ -475,7 +475,7 @@ static int units_orders_city_dlg_callback(struct widget *button) buf->data = button->data; buf->action = sentry_units_orders_city_dlg_callback; if (punit->activity != ACTIVITY_SENTRY - && can_unit_do_activity(punit, ACTIVITY_SENTRY)) { + && can_unit_do_activity_client(punit, ACTIVITY_SENTRY)) { set_wstate(buf, FC_WS_NORMAL); } add_to_gui_list(button->id, buf); @@ -491,7 +491,7 @@ static int units_orders_city_dlg_callback(struct widget *button) buf->data = button->data; buf->action = fortify_units_orders_city_dlg_callback; if (punit->activity != ACTIVITY_FORTIFYING - && can_unit_do_activity(punit, ACTIVITY_FORTIFYING)) { + && can_unit_do_activity_client(punit, ACTIVITY_FORTIFYING)) { set_wstate(buf, FC_WS_NORMAL); } add_to_gui_list(button->id, buf); diff --git a/client/gui-sdl2/dialogs.c b/client/gui-sdl2/dialogs.c index 5d90cdbca2..bfd4960337 100644 --- a/client/gui-sdl2/dialogs.c +++ b/client/gui-sdl2/dialogs.c @@ -1581,7 +1581,7 @@ static int adv_unit_sentry_idle_callback(struct widget *pwidget) if (unit_owner(other_unit) == client.conn.playing && ACTIVITY_IDLE == other_unit->activity && other_unit->ssa_controller == SSA_NONE - && can_unit_do_activity(other_unit, ACTIVITY_SENTRY)) { + && can_unit_do_activity_client(other_unit, ACTIVITY_SENTRY)) { request_new_unit_activity(other_unit, ACTIVITY_SENTRY); } } unit_list_iterate_end; diff --git a/client/gui-sdl2/menu.c b/client/gui-sdl2/menu.c index 38310419fc..305cae833f 100644 --- a/client/gui-sdl2/menu.c +++ b/client/gui-sdl2/menu.c @@ -1124,7 +1124,7 @@ void real_menus_update(void) pextra = next_extra_for_tile(ptile, EC_ROAD, unit_owner(punit), punit); if (pextra != NULL - && can_unit_do_activity_targeted(punit, ACTIVITY_GEN_ROAD, pextra)) { + && can_unit_do_activity_targeted_client(punit, ACTIVITY_GEN_ROAD, pextra)) { struct road_type *proad = extra_road_get(pextra); enum road_compat compat = road_compat_special(proad); @@ -1179,8 +1179,8 @@ void real_menus_update(void) pextra = next_extra_for_tile(ptile, EC_IRRIGATION, unit_owner(punit), punit); - if (pextra != NULL && - can_unit_do_activity_targeted(punit, ACTIVITY_IRRIGATE, pextra)) { + if (pextra != NULL + && can_unit_do_activity_targeted_client(punit, ACTIVITY_IRRIGATE, pextra)) { time = turns_to_activity_done(ptile, ACTIVITY_IRRIGATE, pextra, punit); /* TRANS: "Build Irrigation (I) 5 turns" */ @@ -1198,7 +1198,7 @@ void real_menus_update(void) pextra = next_extra_for_tile(ptile, EC_MINE, unit_owner(punit), punit); if (pextra != NULL - && can_unit_do_activity_targeted(punit, ACTIVITY_MINE, pextra)) { + && can_unit_do_activity_targeted_client(punit, ACTIVITY_MINE, pextra)) { time = turns_to_activity_done(ptile, ACTIVITY_MINE, pextra, punit); /* TRANS: "Build Mine (M) 5 turns" */ fc_snprintf(cbuf, sizeof(cbuf), _("Build %s (%s) %d %s"), @@ -1212,7 +1212,7 @@ void real_menus_update(void) set_wflag(order_mine_button, WF_HIDDEN); } - if (can_unit_do_activity(punit, ACTIVITY_CULTIVATE)) { + if (can_unit_do_activity_client(punit, ACTIVITY_CULTIVATE)) { /* Activity always results in terrain change */ time = turns_to_activity_done(ptile, ACTIVITY_CULTIVATE, NULL, punit); fc_snprintf(cbuf, sizeof(cbuf), "%s %s (%s) %d %s", @@ -1225,7 +1225,7 @@ void real_menus_update(void) set_wflag(order_cultivate_button, WF_HIDDEN); } - if (can_unit_do_activity(punit, ACTIVITY_PLANT)) { + if (can_unit_do_activity_client(punit, ACTIVITY_PLANT)) { /* Activity always results in terrain change */ time = turns_to_activity_done(ptile, ACTIVITY_PLANT, NULL, punit); fc_snprintf(cbuf, sizeof(cbuf), "%s %s (%s) %d %s", @@ -1238,7 +1238,7 @@ void real_menus_update(void) set_wflag(order_plant_button, WF_HIDDEN); } - if (can_unit_do_activity(punit, ACTIVITY_TRANSFORM)) { + if (can_unit_do_activity_client(punit, ACTIVITY_TRANSFORM)) { /* Activity always results in terrain change */ time = turns_to_activity_done(ptile, ACTIVITY_TRANSFORM, NULL, punit); fc_snprintf(cbuf, sizeof(cbuf), "%s %s (%s) %d %s", @@ -1266,7 +1266,7 @@ void real_menus_update(void) set_wflag(order_fortress_button, WF_HIDDEN); } - if (can_unit_do_activity(punit, ACTIVITY_FORTIFYING)) { + if (can_unit_do_activity_client(punit, ACTIVITY_FORTIFYING)) { local_show(ID_UNIT_ORDER_FORTIFY); } else { local_hide(ID_UNIT_ORDER_FORTIFY); @@ -1290,7 +1290,7 @@ void real_menus_update(void) pextra = prev_extra_in_tile(ptile, ERM_CLEANPOLLUTION, unit_owner(punit), punit); if (pextra != NULL - && can_unit_do_activity_targeted(punit, ACTIVITY_POLLUTION, pextra)) { + && can_unit_do_activity_targeted_client(punit, ACTIVITY_POLLUTION, pextra)) { time = turns_to_activity_done(ptile, ACTIVITY_POLLUTION, pextra, punit); /* TRANS: "Clean Pollution (P) 3 turns" */ @@ -1312,7 +1312,7 @@ void real_menus_update(void) pextra = prev_extra_in_tile(ptile, ERM_CLEANFALLOUT, unit_owner(punit), punit); if (pextra != NULL - && can_unit_do_activity_targeted(punit, ACTIVITY_FALLOUT, pextra)) { + && can_unit_do_activity_targeted_client(punit, ACTIVITY_FALLOUT, pextra)) { time = turns_to_activity_done(ptile, ACTIVITY_FALLOUT, pextra, punit); /* TRANS: "Clean Fallout (N) 3 turns" */ @@ -1325,13 +1325,13 @@ void real_menus_update(void) set_wflag(order_fallout_button, WF_HIDDEN); } - if (can_unit_do_activity(punit, ACTIVITY_SENTRY)) { + if (can_unit_do_activity_client(punit, ACTIVITY_SENTRY)) { local_show(ID_UNIT_ORDER_SENTRY); } else { local_hide(ID_UNIT_ORDER_SENTRY); } - if (can_unit_do_activity(punit, ACTIVITY_PILLAGE)) { + if (can_unit_do_activity_client(punit, ACTIVITY_PILLAGE)) { local_show(ID_UNIT_ORDER_PILLAGE); } else { local_hide(ID_UNIT_ORDER_PILLAGE); @@ -1374,7 +1374,7 @@ void real_menus_update(void) local_hide(ID_UNIT_ORDER_AUTO_SETTLER); } - if (can_unit_do_activity(punit, ACTIVITY_EXPLORE)) { + if (can_unit_do_activity_client(punit, ACTIVITY_EXPLORE)) { local_show(ID_UNIT_ORDER_AUTO_EXPLORE); } else { local_hide(ID_UNIT_ORDER_AUTO_EXPLORE); diff --git a/common/unit.c b/common/unit.c index 2fbffb02b7..64e4be296c 100644 --- a/common/unit.c +++ b/common/unit.c @@ -846,7 +846,7 @@ bool can_unit_continue_current_activity(struct unit *punit) punit->activity = ACTIVITY_IDLE; punit->activity_target = NULL; - result = can_unit_do_activity_targeted(punit, current2, target); + result = can_unit_do_activity_targeted(&(wld.map), punit, current2, target); punit->activity = current; punit->activity_target = target; @@ -859,14 +859,15 @@ bool can_unit_continue_current_activity(struct unit *punit) current location. Note that some activities must be targeted; see - can_unit_do_activity_targeted. + can_unit_do_activity_targeted(). **************************************************************************/ -bool can_unit_do_activity(const struct unit *punit, +bool can_unit_do_activity(const struct civ_map *nmap, + const struct unit *punit, enum unit_activity activity) { struct extra_type *target = NULL; - /* FIXME: lots of callers (usually client real_menus_update()) rely on + /* FIXME: Lots of callers (usually client real_menus_update()) rely on * being able to find out whether an activity is in general possible. * Find one for them, but when they come to do the activity, they will * have to determine the target themselves */ @@ -892,18 +893,19 @@ bool can_unit_do_activity(const struct unit *punit, } } - return can_unit_do_activity_targeted(punit, activity, target); + return can_unit_do_activity_targeted(nmap, punit, activity, target); } /**********************************************************************//** Return whether the unit can do the targeted activity at its current location. **************************************************************************/ -bool can_unit_do_activity_targeted(const struct unit *punit, - enum unit_activity activity, +bool can_unit_do_activity_targeted(const struct civ_map *nmap, + const struct unit *punit, + enum unit_activity activity, struct extra_type *target) { - return can_unit_do_activity_targeted_at(punit, activity, target, + return can_unit_do_activity_targeted_at(nmap, punit, activity, target, unit_tile(punit)); } @@ -911,7 +913,8 @@ bool can_unit_do_activity_targeted(const struct unit *punit, Return TRUE if the unit can do the targeted activity at the given location. **************************************************************************/ -bool can_unit_do_activity_targeted_at(const struct unit *punit, +bool can_unit_do_activity_targeted_at(const struct civ_map *nmap, + const struct unit *punit, enum unit_activity activity, struct extra_type *target, const struct tile *ptile) @@ -1027,7 +1030,7 @@ bool can_unit_do_activity_targeted_at(const struct unit *punit, punit, ptile, target); case ACTIVITY_SENTRY: - if (!can_unit_survive_at_tile(&(wld.map), punit, unit_tile(punit)) + if (!can_unit_survive_at_tile(nmap, punit, unit_tile(punit)) && !unit_transported(punit)) { /* Don't let units sentry on tiles they will die on. */ return FALSE; @@ -1068,6 +1071,7 @@ bool can_unit_do_activity_targeted_at(const struct unit *punit, log_error("can_unit_do_activity_targeted_at() unknown activity %d", activity); return FALSE; + #undef RETURN_IS_ACTIVITY_ENABLED_UNIT_ON } @@ -1920,7 +1924,8 @@ static bool can_type_transport_units_cargo(const struct unit_type *utype, Tests if something prevents punit from being transformed to to_unittype where it is now, presuming its current position is valid. - FIXME: the transport stack may still fail unit_transport_check in result + FIXME: The transport stack may still fail unit_transport_check() + in result. **************************************************************************/ enum unit_upgrade_result unit_transform_result(const struct unit *punit, @@ -1941,6 +1946,7 @@ unit_transform_result(const struct unit *punit, /* The new unit type can't survive on this terrain. */ return UU_NOT_TERRAIN; } + return UU_OK; } diff --git a/common/unit.h b/common/unit.h index 98284d9034..5c543b100d 100644 --- a/common/unit.h +++ b/common/unit.h @@ -332,12 +332,15 @@ bool can_unit_change_homecity_to(const struct unit *punit, bool can_unit_change_homecity(const struct unit *punit); const char *get_activity_text(enum unit_activity activity); bool can_unit_continue_current_activity(struct unit *punit); -bool can_unit_do_activity(const struct unit *punit, +bool can_unit_do_activity(const struct civ_map *nmap, + const struct unit *punit, enum unit_activity activity); -bool can_unit_do_activity_targeted(const struct unit *punit, +bool can_unit_do_activity_targeted(const struct civ_map *nmap, + const struct unit *punit, enum unit_activity activity, struct extra_type *target); -bool can_unit_do_activity_targeted_at(const struct unit *punit, +bool can_unit_do_activity_targeted_at(const struct civ_map *nmap, + const struct unit *punit, enum unit_activity activity, struct extra_type *target, const struct tile *ptile); diff --git a/common/unitlist.c b/common/unitlist.c index c5fd8a51ac..d1c8afe078 100644 --- a/common/unitlist.c +++ b/common/unitlist.c @@ -107,15 +107,16 @@ bool can_units_do(const struct unit_list *punits, /************************************************************************//** Returns TRUE if any of the units can do the activity. ****************************************************************************/ -bool can_units_do_activity(const struct unit_list *punits, - enum unit_activity activity) +bool can_units_do_activity(const struct civ_map *nmap, + const struct unit_list *punits, + enum unit_activity activity) { /* Make sure nobody uses these old activities any more */ fc_assert_ret_val(activity != ACTIVITY_FORTRESS && activity != ACTIVITY_AIRBASE, FALSE); unit_list_iterate(punits, punit) { - if (can_unit_do_activity(punit, activity)) { + if (can_unit_do_activity(nmap, punit, activity)) { return TRUE; } } unit_list_iterate_end; @@ -126,12 +127,13 @@ bool can_units_do_activity(const struct unit_list *punits, /************************************************************************//** Returns TRUE if any of the units can do the targeted activity. ****************************************************************************/ -bool can_units_do_activity_targeted(const struct unit_list *punits, +bool can_units_do_activity_targeted(const struct civ_map *nmap, + const struct unit_list *punits, enum unit_activity activity, struct extra_type *pextra) { unit_list_iterate(punits, punit) { - if (can_unit_do_activity_targeted(punit, activity, pextra)) { + if (can_unit_do_activity_targeted(nmap, punit, activity, pextra)) { return TRUE; } } unit_list_iterate_end; diff --git a/common/unitlist.h b/common/unitlist.h index 195cc249ea..65f97d0401 100644 --- a/common/unitlist.h +++ b/common/unitlist.h @@ -71,9 +71,11 @@ void unit_list_sort_ord_city(struct unit_list *punitlist); bool can_units_do(const struct unit_list *punits, bool (can_fn)(const struct unit *punit)); -bool can_units_do_activity(const struct unit_list *punits, - enum unit_activity activity); -bool can_units_do_activity_targeted(const struct unit_list *punits, +bool can_units_do_activity(const struct civ_map *nmap, + const struct unit_list *punits, + enum unit_activity activity); +bool can_units_do_activity_targeted(const struct civ_map *nmap, + const struct unit_list *punits, enum unit_activity activity, struct extra_type *pextra); bool can_units_do_any_road(const struct unit_list *punits); diff --git a/server/unithand.c b/server/unithand.c index 5eab963880..069cb7d7a5 100644 --- a/server/unithand.c +++ b/server/unithand.c @@ -5871,6 +5871,7 @@ void handle_unit_sscs_set(struct player *pplayer, int value) { struct unit *punit = player_unit_by_number(pplayer, unit_id); + const struct civ_map *nmap = &(wld.map); if (NULL == punit) { /* Being asked to unqueue a "spent" unit because the client haven't @@ -5936,7 +5937,7 @@ void handle_unit_sscs_set(struct player *pplayer, fc_assert(FALSE); } } else if (value == 1) { - if (!can_unit_do_activity(punit, ACTIVITY_SENTRY)) { + if (!can_unit_do_activity(nmap, punit, ACTIVITY_SENTRY)) { return; } @@ -6024,6 +6025,8 @@ bool unit_server_side_agent_set(struct player *pplayer, struct unit *punit, enum server_side_agent agent) { + const struct civ_map *nmap = &(wld.map); + /* Check that the agent can be activated for this unit. */ switch (agent) { case SSA_AUTOSETTLER: @@ -6032,7 +6035,7 @@ bool unit_server_side_agent_set(struct player *pplayer, } break; case SSA_AUTOEXPLORE: - if (!can_unit_do_activity(punit, ACTIVITY_EXPLORE)) { + if (!can_unit_do_activity(nmap, punit, ACTIVITY_EXPLORE)) { return FALSE; } break; @@ -6121,6 +6124,8 @@ static bool do_action_activity(struct unit *punit, bool unit_activity_handling(struct unit *punit, enum unit_activity new_activity) { + const struct civ_map *nmap = &(wld.map); + /* Must specify target for ACTIVITY_BASE */ fc_assert_ret_val(new_activity != ACTIVITY_BASE && new_activity != ACTIVITY_GEN_ROAD, FALSE); @@ -6130,7 +6135,7 @@ bool unit_activity_handling(struct unit *punit, /* Assume untargeted pillaging if no target specified */ unit_activity_handling_targeted(punit, new_activity, &target); - } else if (can_unit_do_activity(punit, new_activity)) { + } else if (can_unit_do_activity(nmap, punit, new_activity)) { free_unit_orders(punit); unit_activity_internal(punit, new_activity); } @@ -6147,7 +6152,7 @@ bool unit_activity_handling(struct unit *punit, static bool unit_activity_internal(struct unit *punit, enum unit_activity new_activity) { - if (!can_unit_do_activity(punit, new_activity)) { + if (!can_unit_do_activity(&(wld.map), punit, new_activity)) { return FALSE; } else { enum unit_activity old_activity = punit->activity; @@ -6189,7 +6194,8 @@ bool unit_activity_handling_targeted(struct unit *punit, { if (!activity_requires_target(new_activity)) { unit_activity_handling(punit, new_activity); - } else if (can_unit_do_activity_targeted(punit, new_activity, *new_target)) { + } else if (can_unit_do_activity_targeted(&(wld.map), punit, + new_activity, *new_target)) { free_unit_orders(punit); unit_activity_targeted_internal(punit, new_activity, new_target); } @@ -6207,7 +6213,8 @@ static bool unit_activity_targeted_internal(struct unit *punit, enum unit_activity new_activity, struct extra_type **new_target) { - if (!can_unit_do_activity_targeted(punit, new_activity, *new_target)) { + if (!can_unit_do_activity_targeted(&(wld.map), punit, + new_activity, *new_target)) { return FALSE; } else { enum unit_activity old_activity = punit->activity; diff --git a/server/unittools.c b/server/unittools.c index 8aaf7d6ae6..715fb43238 100644 --- a/server/unittools.c +++ b/server/unittools.c @@ -1127,22 +1127,24 @@ void unit_assign_specific_activity_target(struct unit *punit, enum unit_activity *activity, struct extra_type **target) { + const struct civ_map *nmap = &(wld.map); + if (*activity == ACTIVITY_PILLAGE && *target == NULL) { struct tile *ptile = unit_tile(punit); struct extra_type *tgt; - bv_extras extras = *tile_extras(ptile); while ((tgt = get_preferred_pillage(extras))) { BV_CLR(extras, extra_index(tgt)); - if (can_unit_do_activity_targeted(punit, *activity, tgt)) { + if (can_unit_do_activity_targeted(nmap, punit, *activity, tgt)) { *target = tgt; return; } } + /* Nothing we can pillage here. */ *activity = ACTIVITY_IDLE; } @@ -1205,6 +1207,7 @@ void place_partisans(struct tile *pcenter, struct player *powner, { struct tile *ptile = NULL; struct unit_type *u_type = get_role_unit(L_PARTISAN, 0); + const struct civ_map *nmap = &(wld.map); while (count-- > 0 && find_a_good_partisan_spot(pcenter, powner, u_type, @@ -1212,9 +1215,10 @@ void place_partisans(struct tile *pcenter, struct player *powner, struct unit *punit; punit = unit_virtual_prepare(powner, ptile, u_type, 0, 0, -1, -1); - if (can_unit_do_activity(punit, ACTIVITY_FORTIFYING)) { - punit->activity = ACTIVITY_FORTIFIED; /* yes; directly fortified */ + if (can_unit_do_activity(nmap, punit, ACTIVITY_FORTIFYING)) { + punit->activity = ACTIVITY_FORTIFIED; /* Yes; directly fortified */ } + (void) place_unit(punit, powner, NULL, NULL, FALSE); } } @@ -4380,6 +4384,7 @@ bool execute_orders(struct unit *punit, const bool fresh) int unitid = punit->id; struct player *pplayer = unit_owner(punit); int moves_made = 0; + const struct civ_map *nmap = &(wld.map); fc_assert_ret_val(unit_has_orders(punit), TRUE); @@ -4491,7 +4496,7 @@ bool execute_orders(struct unit *punit, const bool fresh) fc_assert(activity == ACTIVITY_SENTRY); - if (can_unit_do_activity(punit, activity)) { + if (can_unit_do_activity(nmap, punit, activity)) { punit->done_moving = TRUE; set_unit_activity(punit, activity); send_unit_info(NULL, punit); -- 2.40.1