From 7c043b59c812fde9697738e4cfd4c8093cdc43e1 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 1 Oct 2023 04:36:31 +0300 Subject: [PATCH 48/48] 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/daiunit.c | 11 ++++--- client/control.c | 34 ++++++++++----------- client/control.h | 9 ++++++ client/gui-gtk-3.22/citydlg.c | 4 +-- client/gui-gtk-3.22/menu.c | 44 +++++++++++++-------------- client/gui-gtk-3.22/repodlgs.c | 2 +- client/gui-gtk-4.0/citydlg.c | 8 ++--- client/gui-gtk-4.0/menu.c | 54 +++++++++++++++++----------------- client/gui-gtk-4.0/repodlgs.c | 2 +- client/gui-qt/citydlg.cpp | 4 +-- client/gui-qt/hudwidget.cpp | 16 +++++----- 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 | 10 ++++--- common/unitlist.h | 6 ++-- server/unithand.c | 19 ++++++++---- server/unittools.c | 15 ++++++---- 22 files changed, 191 insertions(+), 154 deletions(-) diff --git a/ai/default/daiunit.c b/ai/default/daiunit.c index e163a73477..224e094580 100644 --- a/ai/default/daiunit.c +++ b/ai/default/daiunit.c @@ -854,17 +854,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; } @@ -875,6 +877,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 e95c59820d..caa4684bb1 100644 --- a/client/control.c +++ b/client/control.c @@ -2308,7 +2308,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); } } @@ -2319,7 +2319,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); } } @@ -2338,8 +2338,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++; } @@ -2932,7 +2932,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); @@ -2947,8 +2947,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); @@ -3542,7 +3542,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; @@ -3577,7 +3577,7 @@ void key_unit_convert(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; @@ -3621,7 +3621,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; @@ -3641,7 +3641,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; @@ -3661,7 +3661,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; @@ -3673,7 +3673,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; @@ -3691,7 +3691,7 @@ void key_unit_clean(void) punit); if (tgt != NULL - && can_unit_do_activity_targeted(punit, ACTIVITY_CLEAN, tgt)) { + && can_unit_do_activity_targeted_client(punit, ACTIVITY_CLEAN, tgt)) { request_new_unit_activity_targeted(punit, ACTIVITY_CLEAN, tgt); } } unit_list_iterate_end; @@ -3709,7 +3709,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; @@ -3721,7 +3721,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; @@ -3733,7 +3733,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 40f82d526b..7388a6bd7d 100644 --- a/client/control.h +++ b/client/control.h @@ -38,6 +38,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.22/citydlg.c b/client/gui-gtk-3.22/citydlg.c index b1083e5610..8f16b583cb 100644 --- a/client/gui-gtk-3.22/citydlg.c +++ b/client/gui-gtk-3.22/citydlg.c @@ -2556,7 +2556,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); } @@ -2567,7 +2567,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 42cc5a653a..bd69381404 100644 --- a/client/gui-gtk-3.22/menu.c +++ b/client/gui-gtk-3.22/menu.c @@ -1794,7 +1794,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; } @@ -2024,7 +2024,7 @@ static void clean_callback(GtkMenuItem *item, gpointer data) struct extra_type *pextra = data; unit_list_iterate(get_units_in_focus(), punit) { - if (can_unit_do_activity_targeted(punit, ACTIVITY_CLEAN, pextra)) { + if (can_unit_do_activity_targeted_client(punit, ACTIVITY_CLEAN, pextra)) { request_new_unit_activity_targeted(punit, ACTIVITY_CLEAN, pextra); } @@ -2480,9 +2480,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); @@ -2498,9 +2498,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); @@ -2516,9 +2516,9 @@ void real_menus_update(void) pextra = g_object_get_data(G_OBJECT(iter->data), "nuisance"); if (NULL != pextra) { gtk_widget_set_sensitive(GTK_WIDGET(iter->data), - can_units_do_activity_targeted(punits, - ACTIVITY_CLEAN, - pextra)); + can_units_do_activity_targeted_client(punits, + ACTIVITY_CLEAN, + pextra)); } } g_list_free(list); @@ -2566,33 +2566,33 @@ 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", - can_units_do_activity(punits, ACTIVITY_CLEAN)); + can_units_do_activity_client(punits, ACTIVITY_CLEAN)); 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)); @@ -2613,7 +2613,7 @@ void real_menus_update(void) menu_entry_set_sensitive("AUTO_WORKER", can_units_do(punits, can_unit_do_autoworker)); 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 cde20c895f..8d200b68a0 100644 --- a/client/gui-gtk-3.22/repodlgs.c +++ b/client/gui-gtk-3.22/repodlgs.c @@ -1606,7 +1606,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 d6548aee27..c1a49c8bf6 100644 --- a/client/gui-gtk-4.0/citydlg.c +++ b/client/gui-gtk-4.0/citydlg.c @@ -2533,8 +2533,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")); @@ -2545,8 +2545,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 b87c7850df..2b93b82e11 100644 --- a/client/gui-gtk-4.0/menu.c +++ b/client/gui-gtk-4.0/menu.c @@ -2498,7 +2498,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; } @@ -2795,7 +2795,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_CLEAN, pextra)) { + if (can_unit_do_activity_targeted_client(punit, ACTIVITY_CLEAN, pextra)) { request_new_unit_activity_targeted(punit, ACTIVITY_CLEAN, pextra); } @@ -3581,9 +3581,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); @@ -3606,9 +3606,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); @@ -3631,9 +3631,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); @@ -3655,9 +3655,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_CLEAN, - pextra)); + can_units_do_activity_targeted_client(punits, + ACTIVITY_CLEAN, + pextra)); g_action_map_add_action(map, G_ACTION(act)); g_signal_connect(act, "activate", G_CALLBACK(clean_menu_callback), pextra); @@ -3680,9 +3680,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); @@ -3809,30 +3809,30 @@ 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, + 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_CLEAN)); + can_units_do_activity_client(punits, ACTIVITY_CLEAN)); 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)); @@ -3847,7 +3847,7 @@ void real_menus_update(void) menu_entry_set_sensitive(map, "AUTO_WORKER", can_units_do(punits, can_unit_do_autoworker)); 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 454fd13ba2..499025e84d 100644 --- a/client/gui-gtk-4.0/repodlgs.c +++ b/client/gui-gtk-4.0/repodlgs.c @@ -1638,7 +1638,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 4ee2065d35..dd53ae94b5 100644 --- a/client/gui-qt/citydlg.cpp +++ b/client/gui-qt/citydlg.cpp @@ -804,14 +804,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 = nullptr; } - 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 4766fae9c6..959230b1a9 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")); @@ -1061,7 +1061,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")); @@ -1069,7 +1069,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")); @@ -1120,7 +1120,7 @@ int unit_actions::update_actions() } // Clean - if (can_unit_do_activity(current_unit, ACTIVITY_CLEAN)) { + if (can_unit_do_activity_client(current_unit, ACTIVITY_CLEAN)) { a = new hud_action(this); a->action_shortcut = SC_CLEAN; a->set_pixmap(fc_icons::instance()->get_pixmap("clean")); diff --git a/client/gui-qt/menu.cpp b/client/gui-qt/menu.cpp index 66ab36147d..1253c37c80 100644 --- a/client/gui-qt/menu.cpp +++ b/client/gui-qt/menu.cpp @@ -1989,7 +1989,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; @@ -2037,7 +2037,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 { @@ -2175,7 +2175,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; @@ -2205,7 +2205,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); } @@ -2239,7 +2239,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) { @@ -2272,7 +2272,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) { @@ -2295,7 +2295,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) { @@ -2318,7 +2318,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; @@ -2383,7 +2383,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; @@ -2401,13 +2401,13 @@ void mr_menu::menus_sensitive() break; case CLEAN: - if (can_units_do_activity(punits, ACTIVITY_CLEAN)) { + if (can_units_do_activity_client(punits, ACTIVITY_CLEAN)) { 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; @@ -2421,7 +2421,7 @@ void mr_menu::menus_sensitive() 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; @@ -2792,7 +2792,7 @@ void mr_menu::slot_build_road() bool building_road = false; if (tgt != nullptr - && 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; } @@ -3704,8 +3704,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; @@ -3720,8 +3720,8 @@ 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, - pextra)) { + && can_unit_do_activity_targeted_client(punit, ACTIVITY_BASE, + pextra)) { request_new_unit_activity_targeted(punit, ACTIVITY_BASE, pextra); } } extra_type_by_cause_iterate_end; diff --git a/client/gui-qt/repodlgs.cpp b/client/gui-qt/repodlgs.cpp index d62a6592a0..f63da073c5 100644 --- a/client/gui-qt/repodlgs.cpp +++ b/client/gui-qt/repodlgs.cpp @@ -285,7 +285,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++; } } @@ -310,7 +310,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 0b037eac50..ba61e2a5c6 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 c30cf3823c..6397a502ea 100644 --- a/client/gui-sdl2/dialogs.c +++ b/client/gui-sdl2/dialogs.c @@ -1584,7 +1584,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 2c0cffbd40..9039c08a5e 100644 --- a/client/gui-sdl2/menu.c +++ b/client/gui-sdl2/menu.c @@ -1106,7 +1106,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); @@ -1163,8 +1163,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" */ @@ -1182,7 +1182,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"), @@ -1196,7 +1196,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", @@ -1209,7 +1209,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", @@ -1222,7 +1222,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", @@ -1250,7 +1250,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); @@ -1280,8 +1280,8 @@ void real_menus_update(void) pextra = prev_cleanable_in_tile(ptile, unit_owner(punit), punit); if (pextra != NULL - && can_unit_do_activity_targeted(punit, ACTIVITY_CLEAN, - pextra)) { + && can_unit_do_activity_targeted_client(punit, ACTIVITY_CLEAN, + pextra)) { time = turns_to_activity_done(ptile, ACTIVITY_CLEAN, pextra, punit); /* TRANS: "Clean Pollution (P) 3 turns" */ @@ -1294,13 +1294,13 @@ void real_menus_update(void) set_wflag(order_clean_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); @@ -1343,7 +1343,7 @@ void real_menus_update(void) local_hide(ID_UNIT_ORDER_AUTO_WORKER); } - 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 4a22daba14..879d9624f4 100644 --- a/common/unit.c +++ b/common/unit.c @@ -866,7 +866,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; @@ -879,14 +879,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 */ @@ -912,18 +913,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)); } @@ -931,7 +933,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) @@ -1040,7 +1043,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; @@ -1076,6 +1079,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 } @@ -1958,7 +1962,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, @@ -1979,6 +1984,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 bc1d24829e..b9fa1f2294 100644 --- a/common/unit.h +++ b/common/unit.h @@ -328,12 +328,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 369750c4cc..b872b6a7e4 100644 --- a/common/unitlist.c +++ b/common/unitlist.c @@ -107,11 +107,12 @@ 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, +bool can_units_do_activity(const struct civ_map *nmap, + const struct unit_list *punits, enum unit_activity activity) { 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; @@ -122,12 +123,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 0e8ee5570b..aeb69b9760 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, +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 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); bool can_units_do_any_road(const struct unit_list *punits); diff --git a/server/unithand.c b/server/unithand.c index 8c40ffdb13..d1b0317443 100644 --- a/server/unithand.c +++ b/server/unithand.c @@ -6195,6 +6195,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 @@ -6260,7 +6261,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; } @@ -6348,6 +6349,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_AUTOWORKER: @@ -6356,7 +6359,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; @@ -6445,6 +6448,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); @@ -6454,7 +6459,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); } @@ -6471,7 +6476,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; @@ -6513,7 +6518,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); } @@ -6531,7 +6537,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 76beac5450..a7d919b5a0 100644 --- a/server/unittools.c +++ b/server/unittools.c @@ -1107,22 +1107,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; } @@ -1185,6 +1187,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, @@ -1192,9 +1195,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); } } @@ -4314,6 +4318,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); @@ -4425,7 +4430,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