Author: sveinung Date: Fri Aug 29 13:19:47 2014 New Revision: 26133 URL: http://svn.gna.org/viewcvs/freeciv?rev=26133&view=rev Log: Centralize client side diplomat/spy action targeting
Find target city and target unit in handle_unit_actions() in stead of repeating the same code in each client's popup_diplomat_dialog(). See patch #5134 Modified: trunk/client/gui-gtk-2.0/diplomat_dialog.c trunk/client/gui-gtk-3.0/diplomat_dialog.c trunk/client/gui-qt/dialogs.cpp trunk/client/gui-sdl/diplomat_dialog.c trunk/client/gui-sdl2/diplomat_dialog.c trunk/client/gui-stub/dialogs.c trunk/client/gui-xaw/diplomat_dialog.c trunk/client/include/dialogs_g.h trunk/client/packhand.c Modified: trunk/client/gui-gtk-2.0/diplomat_dialog.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-gtk-2.0/diplomat_dialog.c?rev=26133&r1=26132&r2=26133&view=diff ============================================================================== --- trunk/client/gui-gtk-2.0/diplomat_dialog.c (original) +++ trunk/client/gui-gtk-2.0/diplomat_dialog.c Fri Aug 29 13:19:47 2014 @@ -696,11 +696,10 @@ /**************************************************************** Popup new diplomat dialog. *****************************************************************/ -void popup_diplomat_dialog(struct unit *punit, struct tile *dest_tile, +void popup_diplomat_dialog(struct unit *punit, struct city *pcity, + struct unit *ptunit, struct tile *dest_tile, const action_probability *action_probabilities) { - struct city *pcity; - struct unit *ptunit; GtkWidget *shl; struct astring title = ASTRING_INIT, text = ASTRING_INIT; @@ -720,7 +719,7 @@ shl = choice_dialog_start(GTK_WINDOW(toplevel), astr_str(&title), astr_str(&text)); - if ((pcity = tile_city(dest_tile))) { + if (pcity) { /* Spy/Diplomat acting against a city */ diplomat_target_id[ATK_CITY] = pcity->id; @@ -766,7 +765,7 @@ (GCallback)diplomat_incite_callback); } - if ((ptunit = unit_list_get(dest_tile->units, 0))){ + if (ptunit) { /* Spy/Diplomat acting against a unit */ diplomat_target_id[ATK_UNIT] = ptunit->id; Modified: trunk/client/gui-gtk-3.0/diplomat_dialog.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-gtk-3.0/diplomat_dialog.c?rev=26133&r1=26132&r2=26133&view=diff ============================================================================== --- trunk/client/gui-gtk-3.0/diplomat_dialog.c (original) +++ trunk/client/gui-gtk-3.0/diplomat_dialog.c Fri Aug 29 13:19:47 2014 @@ -706,11 +706,10 @@ /**************************************************************** Popup new diplomat dialog. *****************************************************************/ -void popup_diplomat_dialog(struct unit *punit, struct tile *dest_tile, +void popup_diplomat_dialog(struct unit *punit, struct city *pcity, + struct unit *ptunit, struct tile *dest_tile, const action_probability *action_probabilities) { - struct city *pcity; - struct unit *ptunit; GtkWidget *shl; struct astring title = ASTRING_INIT, text = ASTRING_INIT; @@ -730,7 +729,7 @@ shl = choice_dialog_start(GTK_WINDOW(toplevel), astr_str(&title), astr_str(&text)); - if ((pcity = tile_city(dest_tile))) { + if (pcity) { /* Spy/Diplomat acting against a city */ diplomat_target_id[ATK_CITY] = pcity->id; @@ -776,7 +775,7 @@ (GCallback)diplomat_incite_callback); } - if ((ptunit = unit_list_get(dest_tile->units, 0))){ + if (ptunit) { /* Spy/Diplomat acting against a unit */ diplomat_target_id[ATK_UNIT] = ptunit->id; Modified: trunk/client/gui-qt/dialogs.cpp URL: http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-qt/dialogs.cpp?rev=26133&r1=26132&r2=26133&view=diff ============================================================================== --- trunk/client/gui-qt/dialogs.cpp (original) +++ trunk/client/gui-qt/dialogs.cpp Fri Aug 29 13:19:47 2014 @@ -918,11 +918,10 @@ Popup a dialog giving a diplomatic unit some options when moving into the target tile. **************************************************************************/ -void popup_diplomat_dialog(struct unit *punit, struct tile *dest_tile, +void popup_diplomat_dialog(struct unit *punit, struct city *pcity, + struct unit *ptunit, struct tile *dest_tile, const action_probability *action_probabilities) { - struct city *pcity; - struct unit *ptunit; struct astring title = ASTRING_INIT, text = ASTRING_INIT; int diplomat_id; QVariant qv1, qv2; @@ -951,7 +950,7 @@ qv1 = punit->id; cd->unit_id = diplomat_id; - if ((pcity = tile_city(dest_tile))) { + if (pcity) { /* Spy/Diplomat acting against a city */ gui()->set_current_unit(diplomat_id, pcity->id, ATK_CITY); qv2 = pcity->id; Modified: trunk/client/gui-sdl/diplomat_dialog.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-sdl/diplomat_dialog.c?rev=26133&r1=26132&r2=26133&view=diff ============================================================================== --- trunk/client/gui-sdl/diplomat_dialog.c (original) +++ trunk/client/gui-sdl/diplomat_dialog.c Fri Aug 29 13:19:47 2014 @@ -673,19 +673,17 @@ Popup a dialog giving a diplomatic unit some options when moving into the target tile. **************************************************************************/ -void popup_diplomat_dialog(struct unit *pUnit, struct tile *ptile, +void popup_diplomat_dialog(struct unit *pUnit, struct city *pCity, + struct unit *pTunit, struct tile *ptile, const action_probability *action_probabilities) { struct widget *pWindow = NULL, *pBuf = NULL; SDL_String16 *pStr; - struct city *pCity; - struct unit *pTunit; SDL_Rect area; fc_assert_ret_msg(!pDiplomat_Dlg, "Diplomat dialog already open"); is_unit_move_blocked = TRUE; - pCity = tile_city(ptile); pDiplomat_Dlg = fc_calloc(1, sizeof(struct diplomat_dialog)); pDiplomat_Dlg->diplomat_id = pUnit->id; @@ -779,7 +777,7 @@ pWindow, &area); } - if ((pTunit = unit_list_get(ptile->units, 0))) { + if (pTunit) { /* Spy/Diplomat acting against a unit */ pDiplomat_Dlg->diplomat_target_id[ATK_UNIT] = pTunit->id; Modified: trunk/client/gui-sdl2/diplomat_dialog.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-sdl2/diplomat_dialog.c?rev=26133&r1=26132&r2=26133&view=diff ============================================================================== --- trunk/client/gui-sdl2/diplomat_dialog.c (original) +++ trunk/client/gui-sdl2/diplomat_dialog.c Fri Aug 29 13:19:47 2014 @@ -673,19 +673,17 @@ Popup a dialog giving a diplomatic unit some options when moving into the target tile. **************************************************************************/ -void popup_diplomat_dialog(struct unit *pUnit, struct tile *ptile, +void popup_diplomat_dialog(struct unit *pUnit, struct city *pCity, + struct unit *pTunit, struct tile *ptile, const action_probability *action_probabilities) { struct widget *pWindow = NULL, *pBuf = NULL; SDL_String16 *pStr; - struct city *pCity; - struct unit *pTunit; SDL_Rect area; fc_assert_ret_msg(!pDiplomat_Dlg, "Diplomat dialog already open"); is_unit_move_blocked = TRUE; - pCity = tile_city(ptile); pDiplomat_Dlg = fc_calloc(1, sizeof(struct diplomat_dialog)); pDiplomat_Dlg->diplomat_id = pUnit->id; @@ -724,7 +722,7 @@ pDiplomat_Dlg->diplomat_target_id[ATK_UNIT] = -1; /* ---------- */ - if((pCity)) + if (pCity) { /* Spy/Diplomat acting against a city */ @@ -779,7 +777,7 @@ pWindow, &area); } - if ((pTunit = unit_list_get(ptile->units, 0))) { + if (pTunit) { /* Spy/Diplomat acting against a unit */ pDiplomat_Dlg->diplomat_target_id[ATK_UNIT] = pTunit->id; Modified: trunk/client/gui-stub/dialogs.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-stub/dialogs.c?rev=26133&r1=26132&r2=26133&view=diff ============================================================================== --- trunk/client/gui-stub/dialogs.c (original) +++ trunk/client/gui-stub/dialogs.c Fri Aug 29 13:19:47 2014 @@ -138,7 +138,8 @@ Popup a dialog giving a diplomatic unit some options when moving into the target tile. **************************************************************************/ -void popup_diplomat_dialog(struct unit *punit, struct tile *ptile, +void popup_diplomat_dialog(struct unit *punit, struct city *pcity, + struct unit *ptunit, struct tile *ptile, const action_probability *action_probabilities) { /* PORTME */ Modified: trunk/client/gui-xaw/diplomat_dialog.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-xaw/diplomat_dialog.c?rev=26133&r1=26132&r2=26133&view=diff ============================================================================== --- trunk/client/gui-xaw/diplomat_dialog.c (original) +++ trunk/client/gui-xaw/diplomat_dialog.c Fri Aug 29 13:19:47 2014 @@ -773,22 +773,21 @@ /**************************************************************** Popups the diplomat dialog *****************************************************************/ -void popup_diplomat_dialog(struct unit *punit, struct tile *dest_tile, +void popup_diplomat_dialog(struct unit *punit, struct city *pcity, + struct unit *ptunit, struct tile *dest_tile, const action_probability *action_probabilities) { - struct city *pcity; - struct unit *ptunit; struct astring text = ASTRING_INIT; diplomat_id = punit->id; - if ((ptunit = unit_list_get(dest_tile->units, 0))) { + if (ptunit) { diplomat_target_id[ATK_UNIT] = ptunit->id; } else { diplomat_target_id[ATK_UNIT] = -1; } - if ((pcity = tile_city(dest_tile))) { + if (pcity) { diplomat_target_id[ATK_CITY] = pcity->id; } else { diplomat_target_id[ATK_CITY] = -1; Modified: trunk/client/include/dialogs_g.h URL: http://svn.gna.org/viewcvs/freeciv/trunk/client/include/dialogs_g.h?rev=26133&r1=26132&r2=26133&view=diff ============================================================================== --- trunk/client/include/dialogs_g.h (original) +++ trunk/client/include/dialogs_g.h Fri Aug 29 13:19:47 2014 @@ -53,7 +53,8 @@ GUI_FUNC_PROTO(void, caravan_dialog_update, void) GUI_FUNC_PROTO(void, popup_diplomat_dialog, struct unit *punit, - struct tile *ptile, + struct city *target_city, struct unit *target_unit, + struct tile *target_tile, const action_probability *action_probabilities) GUI_FUNC_PROTO(int, diplomat_handled_in_diplomat_dialog, void) GUI_FUNC_PROTO(void, close_diplomat_dialog, void) Modified: trunk/client/packhand.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/client/packhand.c?rev=26133&r1=26132&r2=26133&view=diff ============================================================================== --- trunk/client/packhand.c (original) +++ trunk/client/packhand.c Fri Aug 29 13:19:47 2014 @@ -3963,6 +3963,8 @@ { struct unit *actor_unit = game_unit_by_number(actor_unit_id); struct tile *target_tile = index_to_tile(target_tile_id); + struct city *target_city = tile_city(target_tile); + struct unit *target_unit = unit_list_get(target_tile->units, 0); bool ask_user = FALSE; /* The dead can't act */ @@ -3982,7 +3984,9 @@ unit_focus_set(actor_unit); /* Show the client specific action dialog */ - popup_diplomat_dialog(actor_unit, target_tile, action_probabilities); + popup_diplomat_dialog(actor_unit, + target_city, target_unit, target_tile, + action_probabilities); } else { /* Nothing to do. Go to the next queued dipomat */ choose_action_queue_next(); _______________________________________________ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits