From 002cb43f3795e730896fa694390068e9c6888bc3 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Fri, 21 Apr 2023 22:58:35 +0300 Subject: [PATCH 21/21] sdl2: Use "Clean" action for all nuisance cleaning See osdn #47836 Signed-off-by: Marko Lindqvist --- client/gui-sdl2/gui_id.h | 2 - client/gui-sdl2/gui_tilespec.c | 2 - client/gui-sdl2/gui_tilespec.h | 2 - client/gui-sdl2/menu.c | 95 ++----------------- common/extras.c | 50 +++++++++- common/extras.h | 28 +++++- .../gui-sdl2/human/theme_orders_buttons.tspec | 3 +- 7 files changed, 80 insertions(+), 102 deletions(-) diff --git a/client/gui-sdl2/gui_id.h b/client/gui-sdl2/gui_id.h index bbcee3ed0d..cfa9dfa12d 100644 --- a/client/gui-sdl2/gui_id.h +++ b/client/gui-sdl2/gui_id.h @@ -95,10 +95,8 @@ enum GUI_ID { ID_UNIT_ORDER_FORTRESS, ID_UNIT_ORDER_FORTIFY, ID_UNIT_ORDER_AIRBASE, - ID_UNIT_ORDER_POLLUTION, ID_UNIT_ORDER_PARADROP, ID_UNIT_ORDER_CLEAN, - ID_UNIT_ORDER_FALLOUT, ID_UNIT_ORDER_SENTRY, ID_UNIT_ORDER_PILLAGE, ID_UNIT_ORDER_HOMECITY, diff --git a/client/gui-sdl2/gui_tilespec.c b/client/gui-sdl2/gui_tilespec.c index 2122ed7e29..d688ef1cde 100644 --- a/client/gui-sdl2/gui_tilespec.c +++ b/client/gui-sdl2/gui_tilespec.c @@ -348,8 +348,6 @@ void tilespec_setup_theme(void) load_order_theme_surface(buf, o_wait_icon, "theme.order_wait"); load_order_theme_surface(buf, o_fortress_icon, "theme.order_build_fortress"); load_order_theme_surface(buf, o_clean_icon, "theme.order_clean"); - load_order_theme_surface(buf, o_fallout_icon, "theme.order_clean_fallout"); - load_order_theme_surface(buf, o_pollution_icon, "theme.order_clean_pollution"); load_order_theme_surface(buf, o_airbase_icon, "theme.order_build_airbase"); load_order_theme_surface(buf, o_transform_icon, "theme.order_transform"); load_order_theme_surface(buf, OAddCity_Icon, "theme.order_add_to_city"); diff --git a/client/gui-sdl2/gui_tilespec.h b/client/gui-sdl2/gui_tilespec.h index 71b6ce9362..7a80bd5e8e 100644 --- a/client/gui-sdl2/gui_tilespec.h +++ b/client/gui-sdl2/gui_tilespec.h @@ -133,8 +133,6 @@ struct theme_icons { SDL_Surface *o_nuke_icon; SDL_Surface *o_fortress_icon; SDL_Surface *o_clean_icon; - SDL_Surface *o_fallout_icon; - SDL_Surface *o_pollution_icon; SDL_Surface *o_airbase_icon; SDL_Surface *o_transform_icon; SDL_Surface *OAddCity_Icon; diff --git a/client/gui-sdl2/menu.c b/client/gui-sdl2/menu.c index 6e3120da4d..ca284476f4 100644 --- a/client/gui-sdl2/menu.c +++ b/client/gui-sdl2/menu.c @@ -66,8 +66,6 @@ static struct widget *begin_order_widget_list; static struct widget *end_order_widget_list; static struct widget *order_clean_button; -static struct widget *order_fallout_button; -static struct widget *order_pollution_button; static struct widget *order_airbase_button; static struct widget *order_fortress_button; static struct widget *order_build_add_to_city_button; @@ -145,15 +143,9 @@ static int unit_order_callback(struct widget *order_widget) case ID_UNIT_ORDER_CLEAN: key_unit_clean(); break; - case ID_UNIT_ORDER_POLLUTION: - key_unit_pollution(); - break; case ID_UNIT_ORDER_PARADROP: key_unit_paradrop(); break; - case ID_UNIT_ORDER_FALLOUT: - key_unit_fallout(); - break; case ID_UNIT_ORDER_SENTRY: key_unit_sentry(); break; @@ -734,20 +726,6 @@ void create_units_order_widgets(void) add_to_gui_list(ID_UNIT_ORDER_SENTRY, buf); /* --------- */ - /* Clean Nuclear Fallout */ - /* Label will be replaced by real_menus_update() before it's seen */ - fc_snprintf(cbuf, sizeof(cbuf), "placeholder"); - buf = create_themeicon(current_theme->o_fallout_icon, main_data.gui, - WF_HIDDEN | WF_RESTORE_BACKGROUND - | WF_WIDGET_HAS_INFO_LABEL); - set_wstate(buf, FC_WS_NORMAL); - buf->action = unit_order_callback; - buf->info_label = create_utf8_from_char_fonto(cbuf, FONTO_DEFAULT); - buf->key = SDLK_n; - order_fallout_button = buf; - add_to_gui_list(ID_UNIT_ORDER_FALLOUT, buf); - /* --------- */ - /* Paradrop */ fc_snprintf(cbuf, sizeof(cbuf), "%s (%s)", action_id_name_translation(ACTION_PARADROP), "J"); @@ -761,20 +739,6 @@ void create_units_order_widgets(void) add_to_gui_list(ID_UNIT_ORDER_PARADROP, buf); /* --------- */ - /* Clean Pollution */ - /* Label will be replaced by real_menus_update() before it's seen */ - fc_snprintf(cbuf, sizeof(cbuf), "placeholder"); - buf = create_themeicon(current_theme->o_pollution_icon, main_data.gui, - WF_HIDDEN | WF_RESTORE_BACKGROUND - | WF_WIDGET_HAS_INFO_LABEL); - set_wstate(buf, FC_WS_NORMAL); - buf->action = unit_order_callback; - buf->info_label = create_utf8_from_char_fonto(cbuf, FONTO_DEFAULT); - buf->key = SDLK_p; - order_pollution_button = buf; - add_to_gui_list(ID_UNIT_ORDER_POLLUTION, buf); - /* --------- */ - /* Generic Clean */ /* Label will be replaced by real_menus_update() before it's seen */ fc_snprintf(cbuf, sizeof(cbuf), "placeholder"); @@ -784,7 +748,7 @@ void create_units_order_widgets(void) set_wstate(buf, FC_WS_NORMAL); buf->action = unit_order_callback; buf->info_label = create_utf8_from_char_fonto(cbuf, FONTO_DEFAULT); - /* buf->key = SDLK_p; */ + buf->key = SDLK_p; order_clean_button = buf; add_to_gui_list(ID_UNIT_ORDER_CLEAN, buf); /* --------- */ @@ -1107,7 +1071,6 @@ void real_menus_update(void) struct terrain *pterrain = tile_terrain(ptile); struct base_type *pbase; struct extra_type *pextra; - struct extra_type *clean_target = NULL; if (!counter) { local_show(ID_UNIT_ORDER_GOTO); @@ -1307,66 +1270,22 @@ void real_menus_update(void) set_wflag(order_airbase_button, WF_HIDDEN); } - clean_target = prev_extra_in_tile(ptile, ERM_CLEAN, - unit_owner(punit), punit); - - pextra = prev_extra_in_tile(ptile, ERM_CLEANPOLLUTION, - unit_owner(punit), punit); - if (clean_target == NULL) { - clean_target = pextra; /* Fallback */ - } - - if (pextra != NULL - && can_unit_do_activity_targeted(punit, ACTIVITY_POLLUTION, - pextra)) { - time = turns_to_activity_done(ptile, ACTIVITY_POLLUTION, - pextra, punit); - /* TRANS: "Clean Pollution (P) 3 turns" */ - fc_snprintf(cbuf, sizeof(cbuf), _("Clean %s (%s) %d %s"), - extra_name_translation(pextra), "P", time, - PL_("turn", "turns", time)); - copy_chars_to_utf8_str(order_pollution_button->info_label, cbuf); - clear_wflag(order_pollution_button, WF_HIDDEN); - } else { - set_wflag(order_pollution_button, WF_HIDDEN); - } - if (can_unit_paradrop(punit)) { local_show(ID_UNIT_ORDER_PARADROP); } else { local_hide(ID_UNIT_ORDER_PARADROP); } - pextra = prev_extra_in_tile(ptile, ERM_CLEANFALLOUT, - unit_owner(punit), punit); - - if (clean_target == NULL) { - clean_target = pextra; /* Fallback */ - } + pextra = prev_cleanable_in_tile(ptile, unit_owner(punit), punit); if (pextra != NULL - && can_unit_do_activity_targeted(punit, ACTIVITY_FALLOUT, pextra)) { - time = turns_to_activity_done(ptile, ACTIVITY_FALLOUT, pextra, - punit); - /* TRANS: "Clean Fallout (N) 3 turns" */ - fc_snprintf(cbuf, sizeof(cbuf), _("Clean %s (%s) %d %s"), - extra_name_translation(pextra), "N", time, - PL_("turn", "turns", time)); - copy_chars_to_utf8_str(order_fallout_button->info_label, cbuf); - clear_wflag(order_fallout_button, WF_HIDDEN); - } else { - set_wflag(order_fallout_button, WF_HIDDEN); - } - - if (clean_target != NULL && can_unit_do_activity_targeted(punit, ACTIVITY_CLEAN, - clean_target)) { + pextra)) { time = turns_to_activity_done(ptile, ACTIVITY_CLEAN, - clean_target, punit); - /* FIXME: No key assigned for this at the moment */ - /* TRANS: "Clean Pollution 3 turns" */ - fc_snprintf(cbuf, sizeof(cbuf), _("Clean %s %d %s"), - extra_name_translation(clean_target), time, + pextra, punit); + /* TRANS: "Clean Pollution (P) 3 turns" */ + fc_snprintf(cbuf, sizeof(cbuf), _("Clean %s (%s) %d %s"), + extra_name_translation(pextra), "P", time, PL_("turn", "turns", time)); copy_chars_to_utf8_str(order_clean_button->info_label, cbuf); clear_wflag(order_clean_button, WF_HIDDEN); diff --git a/common/extras.c b/common/extras.c index 0db1e033de..9bffda7c8e 100644 --- a/common/extras.c +++ b/common/extras.c @@ -34,6 +34,7 @@ static struct user_flag user_extra_flags[MAX_NUM_USER_EXTRA_FLAGS]; static struct extra_type_list *caused_by[EC_LAST]; static struct extra_type_list *removed_by[ERM_COUNT]; +static struct extra_type_list *cleanable; static struct extra_type_list *unit_hidden; /************************************************************************//** @@ -49,6 +50,7 @@ void extras_init(void) for (i = 0; i < ERM_COUNT; i++) { removed_by[i] = extra_type_list_new(); } + cleanable = extra_type_list_new(); unit_hidden = extra_type_list_new(); for (i = 0; i < MAX_EXTRA_TYPES; i++) { @@ -108,6 +110,8 @@ void extras_free(void) removed_by[i] = NULL; } + extra_type_list_destroy(cleanable); + cleanable = NULL; extra_type_list_destroy(unit_hidden); unit_hidden = NULL; @@ -289,7 +293,7 @@ void extra_to_caused_by_list(struct extra_type *pextra, enum extra_cause cause) } /************************************************************************//** - Returns extra type for given rmcause. + Returns extra type list for given rmcause. ****************************************************************************/ struct extra_type_list *extra_type_list_by_rmcause(enum extra_rmcause rmcause) { @@ -299,14 +303,24 @@ struct extra_type_list *extra_type_list_by_rmcause(enum extra_rmcause rmcause) } /************************************************************************//** - Add extra type to list of extra removed by given cause. + Returns extra type list of cleanables ****************************************************************************/ -void extra_to_removed_by_list(struct extra_type *pextra, - enum extra_rmcause rmcause) +struct extra_type_list *extra_type_list_cleanable(void) { - fc_assert(rmcause < ERM_COUNT); + return cleanable; +} +/************************************************************************//** + Add extra type to list of extra removed by given cause. +****************************************************************************/ +void _extra_to_removed_by_list(struct extra_type *pextra, + enum extra_rmcause rmcause) +{ extra_type_list_append(removed_by[rmcause], pextra); + + if (rmcause == ERM_CLEANPOLLUTION || rmcause == ERM_CLEANFALLOUT) { + extra_type_list_append(cleanable, pextra); + } } /************************************************************************//** @@ -771,6 +785,32 @@ struct extra_type *prev_extra_in_tile(const struct tile *ptile, return NULL; } +/************************************************************************//** + Returns prev cleanable extra that unit or player can remove from tile. +****************************************************************************/ +struct extra_type *prev_cleanable_in_tile(const struct tile *ptile, + const struct player *pplayer, + const struct unit *punit) +{ + fc_assert(punit != NULL || pplayer != NULL); + + extra_type_cleanable_iterate(pextra) { + if (tile_has_extra(ptile, pextra)) { + if (punit != NULL) { + if (can_remove_extra(pextra, punit, ptile)) { + return pextra; + } + } else { + if (player_can_remove_extra(pextra, pplayer, ptile)) { + return pextra; + } + } + } + } extra_type_cleanable_iterate_end; + + return NULL; +} + /************************************************************************//** Is extra native to unit class? ****************************************************************************/ diff --git a/common/extras.h b/common/extras.h index ac57684571..b5a9c0f5a8 100644 --- a/common/extras.h +++ b/common/extras.h @@ -199,8 +199,22 @@ bool is_extra_caused_by_worker_action(const struct extra_type *pextra); bool is_extra_caused_by_action(const struct extra_type *pextra, const struct action *paction); -void extra_to_removed_by_list(struct extra_type *pextra, enum extra_rmcause rmcause); +void _extra_to_removed_by_list(struct extra_type *pextra, enum extra_rmcause rmcause); + +/************************************************************************//** + Wrapper around real _extra_to_removed_by_list(), notifying compiler about + illegal parameters. +****************************************************************************/ +static inline void extra_to_removed_by_list(struct extra_type *pextra, + enum extra_rmcause rmcause) +{ + fc__unreachable(rmcause >= ERM_COUNT); + + _extra_to_removed_by_list(pextra, rmcause); +} + struct extra_type_list *extra_type_list_by_rmcause(enum extra_rmcause rmcause); +struct extra_type_list *extra_type_list_cleanable(void); bool is_extra_removed_by(const struct extra_type *pextra, enum extra_rmcause rmcause); bool is_extra_removed_by_worker_action(const struct extra_type *pextra); @@ -275,6 +289,9 @@ struct extra_type *next_extra_for_tile(const struct tile *ptile, enum extra_caus struct extra_type *prev_extra_in_tile(const struct tile *ptile, enum extra_rmcause rmcause, const struct player *pplayer, const struct unit *punit); +struct extra_type *prev_cleanable_in_tile(const struct tile *ptile, + const struct player *pplayer, + const struct unit *punit); enum extra_cause activity_to_extra_cause(enum unit_activity act); enum extra_rmcause activity_to_extra_rmcause(enum unit_activity act); @@ -332,6 +349,15 @@ bool player_knows_extra_exist(const struct player *pplayer, } extra_type_list_iterate_rev_end \ } +#define extra_type_cleanable_iterate(_extra) \ +{ \ + struct extra_type_list *_etl_ = extra_type_list_cleanable(); \ + extra_type_list_iterate_rev(_etl_, _extra) { + +#define extra_type_cleanable_iterate_end \ + } extra_type_list_iterate_rev_end \ +} + #define extra_deps_iterate(_reqs, _dep) \ { \ requirement_vector_iterate(_reqs, preq) { \ diff --git a/data/themes/gui-sdl2/human/theme_orders_buttons.tspec b/data/themes/gui-sdl2/human/theme_orders_buttons.tspec index f6603339d9..133231300b 100644 --- a/data/themes/gui-sdl2/human/theme_orders_buttons.tspec +++ b/data/themes/gui-sdl2/human/theme_orders_buttons.tspec @@ -53,8 +53,7 @@ tiles = { "row", "column", "tag" 22, 0, "theme.order_unload" 23, 0, "theme.order_wait" 24, 0, "theme.order_build_fortress" - 25, 0, "theme.order_clean_fallout" - 26, 0, "theme.order_clean", "theme.order_clean_pollution" + 26, 0, "theme.order_clean" 27, 0, "theme.order_build_airbase" 28, 0, "theme.order_transform" 29, 0, "theme.order_add_to_city" -- 2.39.2