From 4e3c4840fc247693f7a22e738bc1ddf7c898348b Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 25 Jun 2023 11:23:07 +0300 Subject: [PATCH 31/31] Unhardcode units_can_unload() wld.map usage See osdn #48287 Signed-off-by: Marko Lindqvist --- client/gui-gtk-3.22/menu.c | 2 +- client/gui-gtk-4.0/menu.c | 2 +- client/gui-qt/citydlg.cpp | 2 +- client/gui-qt/menu.cpp | 2 +- client/gui-sdl2/menu.c | 2 +- common/unitlist.c | 5 +++-- common/unitlist.h | 13 +++++++------ 7 files changed, 15 insertions(+), 13 deletions(-) diff --git a/client/gui-gtk-3.22/menu.c b/client/gui-gtk-3.22/menu.c index ca912fce8f..e2ad0e1231 100644 --- a/client/gui-gtk-3.22/menu.c +++ b/client/gui-gtk-3.22/menu.c @@ -2595,7 +2595,7 @@ void real_menus_update(void) menu_entry_set_sensitive("UNIT_BOARD", units_can_load(punits)); menu_entry_set_sensitive("UNIT_DEBOARD", - units_can_unload(punits)); + units_can_unload(&(wld.map), punits)); menu_entry_set_sensitive("UNIT_UNSENTRY", units_have_activity_on_tile(punits, ACTIVITY_SENTRY)); diff --git a/client/gui-gtk-4.0/menu.c b/client/gui-gtk-4.0/menu.c index 5cd1959e7b..6ce53ba2bd 100644 --- a/client/gui-gtk-4.0/menu.c +++ b/client/gui-gtk-4.0/menu.c @@ -3932,7 +3932,7 @@ void real_menus_update(void) menu_entry_set_sensitive(map, "UNIT_BOARD", units_can_load(punits)); menu_entry_set_sensitive(map, "UNIT_DEBOARD", - units_can_unload(punits)); + units_can_unload(&(wld.map), punits)); menu_entry_set_sensitive(map, "UNIT_UNLOAD_TRANSPORTER", units_are_occupied(punits)); diff --git a/client/gui-qt/citydlg.cpp b/client/gui-qt/citydlg.cpp index 7a90e666bd..5957ac02c1 100644 --- a/client/gui-qt/citydlg.cpp +++ b/client/gui-qt/citydlg.cpp @@ -839,7 +839,7 @@ void unit_item::create_actions() load = NULL; } - if (units_can_unload(qunits)) { + if (units_can_unload(&(wld.map), qunits)) { unload = new QAction(_("Unload"), this); connect(unload, &QAction::triggered, this, &unit_item::unload_unit); } else { diff --git a/client/gui-qt/menu.cpp b/client/gui-qt/menu.cpp index 06b0eddad3..824d7f5dbe 100644 --- a/client/gui-qt/menu.cpp +++ b/client/gui-qt/menu.cpp @@ -2130,7 +2130,7 @@ void mr_menu::menus_sensitive() break; case DEBOARD: - if (units_can_unload(punits)) { + if (units_can_unload(&(wld.map), punits)) { i.value()->setEnabled(true); } break; diff --git a/client/gui-sdl2/menu.c b/client/gui-sdl2/menu.c index 97681cd99e..24f713f08e 100644 --- a/client/gui-sdl2/menu.c +++ b/client/gui-sdl2/menu.c @@ -1324,7 +1324,7 @@ void real_menus_update(void) local_hide(ID_UNIT_ORDER_BOARD); } - if (units_can_unload(punits)) { + if (units_can_unload(&(wld.map), punits)) { local_show(ID_UNIT_ORDER_DEBOARD); } else { local_hide(ID_UNIT_ORDER_DEBOARD); diff --git a/common/unitlist.c b/common/unitlist.c index 5727418252..369750c4cc 100644 --- a/common/unitlist.c +++ b/common/unitlist.c @@ -277,12 +277,13 @@ bool units_can_load(const struct unit_list *punits) /************************************************************************//** Return TRUE iff any of these units can unload. ****************************************************************************/ -bool units_can_unload(const struct unit_list *punits) +bool units_can_unload(const struct civ_map *nmap, + const struct unit_list *punits) { unit_list_iterate(punits, punit) { if (unit_transported(punit) && can_unit_unload(punit, unit_transport_get(punit)) - && can_unit_exist_at_tile(&(wld.map), punit, unit_tile(punit))) { + && can_unit_exist_at_tile(nmap, punit, unit_tile(punit))) { return TRUE; } } unit_list_iterate_end; diff --git a/common/unitlist.h b/common/unitlist.h index 195cc249ea..0e8ee5570b 100644 --- a/common/unitlist.h +++ b/common/unitlist.h @@ -36,7 +36,7 @@ extern "C" { plink, punit) #define unit_list_both_iterate_end LIST_BOTH_ITERATE_END -#define unit_list_iterate_safe(unitlist, _unit) \ +#define unit_list_iterate_safe(unitlist, _unit) \ { \ struct unit_list *_unit##_ul = unitlist; \ int _unit##_size = unit_list_size(_unit##_ul); \ @@ -70,9 +70,9 @@ void unit_list_sort_ord_map(struct unit_list *punitlist); 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_fn)(const struct unit *punit)); bool can_units_do_activity(const struct unit_list *punits, - enum unit_activity activity); + enum unit_activity activity); bool can_units_do_activity_targeted(const struct unit_list *punits, enum unit_activity activity, struct extra_type *pextra); @@ -89,9 +89,10 @@ bool units_can_do_action_with_result(const struct unit_list *punits, bool can_do); bool units_are_occupied(const struct unit_list *punits); bool units_can_load(const struct unit_list *punits); -bool units_can_unload(const struct unit_list *punits); +bool units_can_unload(const struct civ_map *nmap, + const struct unit_list *punits); bool units_have_activity_on_tile(const struct unit_list *punits, - enum unit_activity activity); + enum unit_activity activity); bool units_can_upgrade(const struct unit_list *punits); bool units_can_convert(const struct unit_list *punits); @@ -100,4 +101,4 @@ bool units_can_convert(const struct unit_list *punits); } #endif /* __cplusplus */ -#endif /* FC__UNITLIST_H */ +#endif /* FC__UNITLIST_H */ -- 2.40.1