Freeciv-3.1
Loading...
Searching...
No Matches
action_dialog.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996-2005 - Freeciv Development Team
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18#include <gtk/gtk.h>
19
20/* utility */
21#include "astring.h"
22#include "support.h"
23
24/* common */
25#include "actions.h"
26#include "game.h"
27#include "traderoutes.h"
28#include "movement.h"
29#include "research.h"
30#include "unit.h"
31#include "unitlist.h"
32
33/* client */
34#include "dialogs_g.h"
35#include "chatline.h"
36#include "choice_dialog.h"
37#include "client_main.h"
38#include "climisc.h"
39#include "connectdlg_common.h"
40#include "control.h"
41#include "gui_main.h"
42#include "gui_stuff.h"
43#include "mapview.h"
44#include "packhand.h"
45#include "text.h"
46
47/* client/gui-gtk-3.22 */
48#include "citydlg.h"
49#include "dialogs.h"
50#include "unitselextradlg.h"
51#include "unitselunitdlg.h"
52#include "wldlg.h"
53
54/* Locations for non action enabler controlled buttons. */
55#define BUTTON_NEW_UNIT_TGT (ACTION_COUNT + 1)
56#define BUTTON_NEW_EXTRA_TGT (BUTTON_NEW_UNIT_TGT + 1)
57#define BUTTON_LOCATION (BUTTON_NEW_EXTRA_TGT + 1)
58#define BUTTON_WAIT (BUTTON_LOCATION + 1)
59#define BUTTON_CANCEL (BUTTON_WAIT + 1)
60#define BUTTON_COUNT (BUTTON_CANCEL + 1)
61
62#define BUTTON_NOT_THERE -1
63
64
65static GtkWidget *act_sel_dialog;
67
68static int actor_unit_id;
69static int target_ids[ATK_COUNT];
70static int target_extra_id;
72static bool did_not_decide = FALSE;
74
75static GtkWidget *spy_tech_shell;
76
77static GtkWidget *spy_sabotage_shell;
78
79/* A structure to hold parameters for actions inside the GUI instead of
80 * storing the needed data in a global variable. */
81struct action_data {
83 int actor_unit_id;
90};
91
92/* TODO: maybe this should be in the dialog itself? */
94
95/**********************************************************************/
100 int actor_id,
101 int target_city_id,
102 int target_unit_id,
103 int target_tile_id,
105 int target_tech_id,
106 int tgt_extra_id)
107{
108 struct action_data *data = fc_malloc(sizeof(*data));
109
110 data->act_id = act_id;
111 data->actor_unit_id = actor_id;
117 data->target_extra_id = tgt_extra_id;
118
119 return data;
120}
121
122/**********************************************************************/
127{
129 /* The client isn't waiting for information for any unanswered follow
130 * up questions. */
131
132 struct unit *actor_unit;
133
135 /* The action selection dialog wasn't closed because the actor unit
136 * was lost. */
137
138 /* The probabilities didn't just disappear, right? */
141
143 }
144
146 /* The action selection dialog was closed but only so it can be
147 * redrawn with fresh data. */
148
150 } else {
151 /* The action selection process is over, at least for now. */
153 }
154
155 if (did_not_decide) {
156 /* The action selection dialog was closed but the player didn't
157 * decide what the unit should do. */
158
159 /* Reset so the next action selection dialog does the right thing. */
161 } else {
162 /* An action, or no action at all, was selected. */
165 }
166 }
167}
168
169/**********************************************************************/
174{
175 /* Stop waiting. Move on to the next queued unit. */
178}
179
180/**********************************************************************/
187{
188 /* Stop assuming the answer to a follow up question will arrive. */
190}
191
192/**********************************************************************/
197{
198 /* Don't add an action mapping here unless the non targeted version is
199 * selectable in the targeted version's target selection dialog. */
200 switch ((enum gen_action)tgt_action_id) {
201 case ACTION_SPY_TARGETED_SABOTAGE_CITY:
202 return ACTION_SPY_SABOTAGE_CITY;
203 case ACTION_SPY_TARGETED_SABOTAGE_CITY_ESC:
204 return ACTION_SPY_SABOTAGE_CITY_ESC;
205 case ACTION_SPY_TARGETED_STEAL_TECH:
206 return ACTION_SPY_STEAL_TECH;
207 case ACTION_SPY_TARGETED_STEAL_TECH_ESC:
208 return ACTION_SPY_STEAL_TECH_ESC;
209 default:
210 /* No non targeted version found. */
211 return ACTION_NONE;
212 }
213}
214
215/**********************************************************************/
220{
221 /* Don't add an action mapping here unless the non targeted version is
222 * selectable in the targeted version's target selection dialog. */
223 switch ((enum gen_action)tgt_action_id) {
224 case ACTION_SPY_TARGETED_SABOTAGE_CITY:
225 return ACTION_SPY_SABOTAGE_CITY_PRODUCTION;
226 case ACTION_SPY_TARGETED_SABOTAGE_CITY_ESC:
227 return ACTION_SPY_SABOTAGE_CITY_PRODUCTION_ESC;
228 case ACTION_STRIKE_BUILDING:
229 return ACTION_STRIKE_PRODUCTION;
230 default:
231 /* No non targeted version found. */
232 return ACTION_NONE;
233 }
234}
235
236/**********************************************************************/
240static void simple_action_callback(GtkWidget *w, gpointer data)
241{
242 int actor_id, target_id, sub_target;
243 struct action *paction;
244
245 struct action_data *args = act_sel_dialog_data;
246
247 bool failed = FALSE;
248
249 /* Data */
250 args->act_id = GPOINTER_TO_INT(data);
251 paction = action_by_number(args->act_id);
252
253 /* Actor */
254 fc_assert(action_get_actor_kind(paction) == AAK_UNIT);
255 actor_id = args->actor_unit_id;
256 if (NULL == game_unit_by_number(actor_id)) {
257 /* Probably dead. */
258 failed = TRUE;
259 }
260
261 /* Target */
262 target_id = IDENTITY_NUMBER_ZERO;
263 switch (action_get_target_kind(paction)) {
264 case ATK_CITY:
265 target_id = args->target_city_id;
266 if (NULL == game_city_by_number(target_id)) {
267 /* Probably destroyed. */
268 failed = TRUE;
269 }
270 break;
271 case ATK_UNIT:
272 target_id = args->target_unit_id;
273 if (NULL == game_unit_by_number(target_id)) {
274 /* Probably dead. */
275 failed = TRUE;
276 }
277 break;
278 case ATK_UNITS:
279 case ATK_TILE:
280 case ATK_EXTRAS:
281 target_id = args->target_tile_id;
282 if (NULL == index_to_tile(&(wld.map), target_id)) {
283 /* TODO: Should this be possible at all? If not: add assertion. */
284 failed = TRUE;
285 }
286 break;
287 case ATK_SELF:
288 target_id = IDENTITY_NUMBER_ZERO;
289 break;
290 case ATK_COUNT:
291 fc_assert(action_get_target_kind(paction) != ATK_COUNT);
292 failed = TRUE;
293 }
294
295 /* Sub target. */
296 sub_target = NO_TARGET;
297 if (paction->target_complexity != ACT_TGT_COMPL_SIMPLE) {
298 switch (action_get_sub_target_kind(paction)) {
299 case ASTK_BUILDING:
300 sub_target = args->target_building_id;
301 if (NULL == improvement_by_number(sub_target)) {
302 /* Did the ruleset change? */
303 failed = TRUE;
304 }
305 break;
306 case ASTK_TECH:
307 sub_target = args->target_tech_id;
308 if (NULL == valid_advance_by_number(sub_target)) {
309 /* Did the ruleset change? */
310 failed = TRUE;
311 }
312 break;
313 case ASTK_EXTRA:
314 case ASTK_EXTRA_NOT_THERE:
315 /* TODO: validate if the extra is there? */
316 sub_target = args->target_extra_id;
317 if (NULL == extra_by_number(sub_target)) {
318 /* Did the ruleset change? */
319 failed = TRUE;
320 }
321 break;
322 case ASTK_NONE:
323 case ASTK_COUNT:
324 /* Shouldn't happen. */
325 fc_assert(action_get_sub_target_kind(paction) != ASTK_NONE);
326 failed = TRUE;
327 break;
328 }
329 }
330
331 /* Send request. */
332 if (!failed) {
333 request_do_action(paction->id, actor_id, target_id, sub_target, "");
334 }
335
336 /* Clean up. */
337 gtk_widget_destroy(act_sel_dialog);
338 /* No follow up questions. */
339 act_sel_dialog_data = NULL;
340 FC_FREE(args);
341}
342
343/**********************************************************************/
347static void request_action_details_callback(GtkWidget *w, gpointer data)
348{
349 int actor_id, target_id;
350 struct action *paction;
351
352 struct action_data *args = act_sel_dialog_data;
353
354 bool failed = FALSE;
355
356 /* Data */
357 args->act_id = GPOINTER_TO_INT(data);
358 paction = action_by_number(args->act_id);
359
360 /* Actor */
361 fc_assert(action_get_actor_kind(paction) == AAK_UNIT);
362 actor_id = args->actor_unit_id;
363 if (NULL == game_unit_by_number(actor_id)) {
364 /* Probably dead. */
365 failed = TRUE;
366 }
367
368 /* Target */
369 target_id = IDENTITY_NUMBER_ZERO;
370 switch (action_get_target_kind(paction)) {
371 case ATK_CITY:
372 target_id = args->target_city_id;
373 if (NULL == game_city_by_number(target_id)) {
374 /* Probably destroyed. */
375 failed = TRUE;
376 }
377 break;
378 case ATK_UNIT:
379 target_id = args->target_unit_id;
380 if (NULL == game_unit_by_number(target_id)) {
381 /* Probably dead. */
382 failed = TRUE;
383 }
384 break;
385 case ATK_UNITS:
386 case ATK_TILE:
387 case ATK_EXTRAS:
388 target_id = args->target_tile_id;
389 if (NULL == index_to_tile(&(wld.map), target_id)) {
390 /* TODO: Should this be possible at all? If not: add assertion. */
391 failed = TRUE;
392 }
393 break;
394 case ATK_SELF:
395 target_id = IDENTITY_NUMBER_ZERO;
396 break;
397 case ATK_COUNT:
398 fc_assert(action_get_target_kind(paction) != ATK_COUNT);
399 failed = TRUE;
400 }
401
402 /* Send request. */
403 if (!failed) {
404 request_action_details(paction->id, actor_id, target_id);
405 }
406
407 /* Wait for the server's reply before moving on to the next unit that
408 * needs to know what action to take. */
410
411 /* Clean up. */
412 gtk_widget_destroy(act_sel_dialog);
413 /* No client side follow up questions. */
414 act_sel_dialog_data = NULL;
415 FC_FREE(args);
416}
417
418/**********************************************************************/
421static void found_city_callback(GtkWidget *w, gpointer data)
422{
423 struct action_data *args = act_sel_dialog_data;
424
426 args->actor_unit_id,
427 args->actor_unit_id);
428
429 gtk_widget_destroy(act_sel_dialog);
430 free(args);
431}
432
433/**********************************************************************/
436static void upgrade_callback(GtkWidget *w, gpointer data)
437{
438 struct unit *punit;
439
440 struct action_data *args = act_sel_dialog_data;
441
443 && NULL != game_city_by_number(args->target_city_id)) {
444 struct unit_list *as_list;
445
446 as_list = unit_list_new();
447 unit_list_append(as_list, punit);
448 popup_upgrade_dialog(as_list);
449 unit_list_destroy(as_list);
450 }
451
452 gtk_widget_destroy(act_sel_dialog);
453 free(args);
454}
455
456/**********************************************************************/
459static void bribe_response(GtkWidget *w, gint response, gpointer data)
460{
461 struct action_data *args = (struct action_data *)data;
462
463 if (response == GTK_RESPONSE_YES) {
465 args->target_unit_id, 0, "");
466 }
467
468 gtk_widget_destroy(w);
469 free(args);
470
471 /* The user have answered the follow up question. Move on. */
473}
474
475/**********************************************************************/
478void popup_bribe_dialog(struct unit *actor, struct unit *punit, int cost,
479 const struct action *paction)
480{
481 GtkWidget *shell;
482 char buf[1024];
483
484 fc_snprintf(buf, ARRAY_SIZE(buf), PL_("Treasury contains %d gold.",
485 "Treasury contains %d gold.",
486 client_player()->economic.gold),
487 client_player()->economic.gold);
488
489 if (cost <= client_player()->economic.gold) {
490 shell = gtk_message_dialog_new(NULL, 0,
491 GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
492 /* TRANS: %s is pre-pluralised "Treasury contains %d gold." */
493 PL_("Bribe unit for %d gold?\n%s",
494 "Bribe unit for %d gold?\n%s", cost), cost, buf);
495 gtk_window_set_title(GTK_WINDOW(shell), _("Bribe Enemy Unit"));
497 } else {
498 shell = gtk_message_dialog_new(NULL, 0,
499 GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE,
500 /* TRANS: %s is pre-pluralised "Treasury contains %d gold." */
501 PL_("Bribing the unit costs %d gold.\n%s",
502 "Bribing the unit costs %d gold.\n%s", cost), cost, buf);
503 gtk_window_set_title(GTK_WINDOW(shell), _("Traitors Demand Too Much!"));
505 }
506 gtk_window_present(GTK_WINDOW(shell));
507
508 g_signal_connect(shell, "response", G_CALLBACK(bribe_response),
509 act_data(paction->id, actor->id,
510 0, punit->id, 0,
511 0, 0, 0));
512}
513
514/**********************************************************************/
517static void spy_advances_response(GtkWidget *w, gint response,
518 gpointer data)
519{
520 struct action_data *args = (struct action_data *)data;
521
522 if (response == GTK_RESPONSE_ACCEPT && args->target_tech_id > 0) {
523 if (NULL != game_unit_by_number(args->actor_unit_id)
524 && NULL != game_city_by_number(args->target_city_id)) {
525 if (args->target_tech_id == A_UNSET) {
526 /* This is the untargeted version. */
528 args->actor_unit_id, args->target_city_id,
529 args->target_tech_id, "");
530 } else {
531 /* This is the targeted version. */
533 args->actor_unit_id, args->target_city_id,
534 args->target_tech_id, "");
535 }
536 }
537 }
538
539 gtk_widget_destroy(spy_tech_shell);
540 spy_tech_shell = NULL;
541 free(data);
542
543 /* The user have answered the follow up question. Move on. */
545}
546
547/**********************************************************************/
550static void spy_advances_callback(GtkTreeSelection *select,
551 gpointer data)
552{
553 struct action_data *args = (struct action_data *)data;
554
555 GtkTreeModel *model;
556 GtkTreeIter it;
557
558 if (gtk_tree_selection_get_selected(select, &model, &it)) {
559 gtk_tree_model_get(model, &it, 1, &(args->target_tech_id), -1);
560
561 gtk_dialog_set_response_sensitive(GTK_DIALOG(spy_tech_shell),
562 GTK_RESPONSE_ACCEPT, TRUE);
563 } else {
564 args->target_tech_id = 0;
565
566 gtk_dialog_set_response_sensitive(GTK_DIALOG(spy_tech_shell),
567 GTK_RESPONSE_ACCEPT, FALSE);
568 }
569}
570
571/**********************************************************************/
574static void create_advances_list(struct player *pplayer,
575 struct player *pvictim,
576 struct action_data *args)
577{
578 GtkWidget *sw, *label, *vbox, *view;
579 GtkListStore *store;
580 GtkCellRenderer *rend;
581 GtkTreeViewColumn *col;
582
584
585 spy_tech_shell = gtk_dialog_new_with_buttons(_("Steal Technology"),
586 NULL, 0,
587 _("_Cancel"), GTK_RESPONSE_CANCEL,
588 _("_Steal"), GTK_RESPONSE_ACCEPT,
589 NULL);
591 gtk_window_set_position(GTK_WINDOW(spy_tech_shell), GTK_WIN_POS_MOUSE);
592
593 gtk_dialog_set_default_response(GTK_DIALOG(spy_tech_shell),
594 GTK_RESPONSE_ACCEPT);
595
596 label = gtk_frame_new(_("Select Advance to Steal"));
597 gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(spy_tech_shell))), label);
598
599 vbox = gtk_grid_new();
600 gtk_orientable_set_orientation(GTK_ORIENTABLE(vbox),
601 GTK_ORIENTATION_VERTICAL);
602 gtk_grid_set_row_spacing(GTK_GRID(vbox), 6);
603 gtk_container_add(GTK_CONTAINER(label), vbox);
604
605 store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_INT);
606
607 view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
608 gtk_widget_set_hexpand(view, TRUE);
609 gtk_widget_set_vexpand(view, TRUE);
610 g_object_unref(store);
611 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), FALSE);
612
613 rend = gtk_cell_renderer_text_new();
614 col = gtk_tree_view_column_new_with_attributes(NULL, rend,
615 "text", 0, NULL);
616 gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);
617
618 label = g_object_new(GTK_TYPE_LABEL,
619 "use-underline", TRUE,
620 "mnemonic-widget", view,
621 "label", _("_Advances:"),
622 "xalign", 0.0,
623 "yalign", 0.5,
624 NULL);
625 gtk_container_add(GTK_CONTAINER(vbox), label);
626
627 sw = gtk_scrolled_window_new(NULL, NULL);
628 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw),
629 GTK_SHADOW_ETCHED_IN);
630 gtk_container_add(GTK_CONTAINER(sw), view);
631
632 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
633 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
634 gtk_widget_set_size_request(sw, -1, 200);
635
636 gtk_container_add(GTK_CONTAINER(vbox), sw);
637
638 /* Now populate the list */
639 if (pvictim) { /* you don't want to know what lag can do -- Syela */
640 const struct research *presearch = research_get(pplayer);
641 const struct research *vresearch = research_get(pvictim);
642 GtkTreeIter it;
643 GValue value = { 0, };
644
646 if (research_invention_gettable(presearch, i,
648 && research_invention_state(vresearch, i) == TECH_KNOWN
649 && research_invention_state(presearch, i) != TECH_KNOWN) {
650 gtk_list_store_append(store, &it);
651
652 g_value_init(&value, G_TYPE_STRING);
653 g_value_set_static_string(&value, research_advance_name_translation
654 (presearch, i));
655 gtk_list_store_set_value(store, &it, 0, &value);
656 g_value_unset(&value);
657 gtk_list_store_set(store, &it, 1, i, -1);
658 }
660
663 gtk_list_store_append(store, &it);
664
665 g_value_init(&value, G_TYPE_STRING);
666 {
667 struct astring str = ASTRING_INIT;
668 /* TRANS: %s is a unit name, e.g., Spy */
669 astr_set(&str, _("At %s's Discretion"),
671 g_value_set_string(&value, astr_str(&str));
672 astr_free(&str);
673 }
674 gtk_list_store_set_value(store, &it, 0, &value);
675 g_value_unset(&value);
676 gtk_list_store_set(store, &it, 1, A_UNSET, -1);
677 }
678 }
679
680 gtk_dialog_set_response_sensitive(GTK_DIALOG(spy_tech_shell),
681 GTK_RESPONSE_ACCEPT, FALSE);
682
683 gtk_widget_show_all(gtk_dialog_get_content_area(GTK_DIALOG(spy_tech_shell)));
684
685 g_signal_connect(gtk_tree_view_get_selection(GTK_TREE_VIEW(view)), "changed",
686 G_CALLBACK(spy_advances_callback), args);
687 g_signal_connect(spy_tech_shell, "response",
688 G_CALLBACK(spy_advances_response), args);
689
690 args->target_tech_id = 0;
691
692 gtk_tree_view_focus(GTK_TREE_VIEW(view));
693}
694
695/**********************************************************************/
698static void spy_improvements_response(GtkWidget *w, gint response, gpointer data)
699{
700 struct action_data *args = (struct action_data *)data;
701
702 if (response == GTK_RESPONSE_ACCEPT && args->target_building_id > -2) {
703 if (NULL != game_unit_by_number(args->actor_unit_id)
704 && NULL != game_city_by_number(args->target_city_id)) {
705 if (args->target_building_id == B_LAST) {
706 /* This is the untargeted version. */
708 args->actor_unit_id,
709 args->target_city_id,
710 args->target_building_id, "");
711 } else if (args->target_building_id == -1) {
712 /* This is the city production version. */
714 args->actor_unit_id,
715 args->target_city_id,
716 args->target_building_id, "");
717 } else {
718 /* This is the targeted version. */
720 args->actor_unit_id,
721 args->target_city_id,
722 args->target_building_id, "");
723 }
724 }
725 }
726
727 gtk_widget_destroy(spy_sabotage_shell);
728 spy_sabotage_shell = NULL;
729 free(args);
730
731 /* The user have answered the follow up question. Move on. */
733}
734
735/**********************************************************************/
738static void spy_improvements_callback(GtkTreeSelection *select, gpointer data)
739{
740 struct action_data *args = (struct action_data *)data;
741
742 GtkTreeModel *model;
743 GtkTreeIter it;
744
745 if (gtk_tree_selection_get_selected(select, &model, &it)) {
746 gtk_tree_model_get(model, &it, 1, &(args->target_building_id), -1);
747
748 gtk_dialog_set_response_sensitive(GTK_DIALOG(spy_sabotage_shell),
749 GTK_RESPONSE_ACCEPT, TRUE);
750 } else {
751 args->target_building_id = -2;
752
753 gtk_dialog_set_response_sensitive(GTK_DIALOG(spy_sabotage_shell),
754 GTK_RESPONSE_ACCEPT, FALSE);
755 }
756}
757
758/**********************************************************************/
761static void create_improvements_list(struct player *pplayer,
762 struct city *pcity,
763 struct action_data *args)
764{
765 GtkWidget *sw, *label, *vbox, *view;
766 GtkListStore *store;
767 GtkCellRenderer *rend;
768 GtkTreeViewColumn *col;
769 GtkTreeIter it;
770
772
773 spy_sabotage_shell = gtk_dialog_new_with_buttons(_("Sabotage Improvements"),
774 NULL, 0,
775 _("_Cancel"), GTK_RESPONSE_CANCEL,
776 _("_Sabotage"), GTK_RESPONSE_ACCEPT,
777 NULL);
779 gtk_window_set_position(GTK_WINDOW(spy_sabotage_shell), GTK_WIN_POS_MOUSE);
780
781 gtk_dialog_set_default_response(GTK_DIALOG(spy_sabotage_shell),
782 GTK_RESPONSE_ACCEPT);
783
784 label = gtk_frame_new(_("Select Improvement to Sabotage"));
785 gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(spy_sabotage_shell))), label);
786
787 vbox = gtk_grid_new();
788 gtk_orientable_set_orientation(GTK_ORIENTABLE(vbox),
789 GTK_ORIENTATION_VERTICAL);
790 gtk_grid_set_row_spacing(GTK_GRID(vbox), 6);
791 gtk_container_add(GTK_CONTAINER(label), vbox);
792
793 store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_INT);
794
795 view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
796 gtk_widget_set_hexpand(view, TRUE);
797 gtk_widget_set_vexpand(view, TRUE);
798 g_object_unref(store);
799 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), FALSE);
800
801 rend = gtk_cell_renderer_text_new();
802 col = gtk_tree_view_column_new_with_attributes(NULL, rend,
803 "text", 0, NULL);
804 gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);
805
806 label = g_object_new(GTK_TYPE_LABEL,
807 "use-underline", TRUE,
808 "mnemonic-widget", view,
809 "label", _("_Improvements:"),
810 "xalign", 0.0,
811 "yalign", 0.5,
812 NULL);
813 gtk_container_add(GTK_CONTAINER(vbox), label);
814
815 sw = gtk_scrolled_window_new(NULL, NULL);
816 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw),
817 GTK_SHADOW_ETCHED_IN);
818 gtk_container_add(GTK_CONTAINER(sw), view);
819
820 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
821 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
822 gtk_scrolled_window_set_min_content_height(GTK_SCROLLED_WINDOW(sw), 200);
823
824 gtk_container_add(GTK_CONTAINER(vbox), sw);
825
826 /* Now populate the list */
829 args->act_id)])) {
830 gtk_list_store_append(store, &it);
831 gtk_list_store_set(store, &it, 0, _("City Production"), 1, -1, -1);
832 }
833
834 city_built_iterate(pcity, pimprove) {
835 if (pimprove->sabotage > 0) {
836 gtk_list_store_append(store, &it);
837 gtk_list_store_set(store, &it,
838 0, city_improvement_name_translation(pcity, pimprove),
839 1, improvement_number(pimprove),
840 -1);
841 }
843
846 struct astring str = ASTRING_INIT;
847
848 gtk_list_store_append(store, &it);
849
850 /* TRANS: %s is a unit name, e.g., Spy */
851 astr_set(&str, _("At %s's Discretion"),
853 gtk_list_store_set(store, &it, 0, astr_str(&str), 1, B_LAST, -1);
854
855 astr_free(&str);
856 }
857
858 gtk_dialog_set_response_sensitive(GTK_DIALOG(spy_sabotage_shell),
859 GTK_RESPONSE_ACCEPT, FALSE);
860
861 gtk_widget_show_all(gtk_dialog_get_content_area(GTK_DIALOG(spy_sabotage_shell)));
862
863 g_signal_connect(gtk_tree_view_get_selection(GTK_TREE_VIEW(view)), "changed",
864 G_CALLBACK(spy_improvements_callback), args);
865 g_signal_connect(spy_sabotage_shell, "response",
866 G_CALLBACK(spy_improvements_response), args);
867
868 args->target_building_id = -2;
869
870 gtk_tree_view_focus(GTK_TREE_VIEW(view));
871}
872
873/**********************************************************************/
876static void spy_steal_popup_shared(GtkWidget *w, gpointer data)
877{
878 struct action_data *args = (struct action_data *)data;
879
880 args->act_id = args->act_id;
881
882 struct city *pvcity = game_city_by_number(args->target_city_id);
883 struct player *pvictim = NULL;
884
885 if (pvcity) {
886 pvictim = city_owner(pvcity);
887 }
888
889/* it is concievable that pvcity will not be found, because something
890has happened to the city during latency. Therefore we must initialize
891pvictim to NULL and account for !pvictim in create_advances_list. -- Syela */
892
893 /* FIXME: Don't discard the second tech choice dialog. */
894 if (!spy_tech_shell) {
895 create_advances_list(client.conn.playing, pvictim, args);
896 gtk_window_present(GTK_WINDOW(spy_tech_shell));
897 } else {
898 free(args);
899 }
900
901 /* Wait for the player's reply before moving on to the next unit that
902 * needs to know what action to take. */
904
905 gtk_widget_destroy(act_sel_dialog);
906}
907
908/**********************************************************************/
912static void spy_steal_popup(GtkWidget *w, gpointer data)
913{
914 act_sel_dialog_data->act_id = ACTION_SPY_TARGETED_STEAL_TECH;
916}
917
918/**********************************************************************/
922static void spy_steal_esc_popup(GtkWidget *w, gpointer data)
923{
924 act_sel_dialog_data->act_id = ACTION_SPY_TARGETED_STEAL_TECH_ESC;
926}
927
928/**********************************************************************/
932void popup_sabotage_dialog(struct unit *actor, struct city *pcity,
933 const struct action *paction)
934{
935 /* FIXME: Don't discard the second target choice dialog. */
936 if (!spy_sabotage_shell) {
938 act_data(paction->id,
939 actor->id, pcity->id, 0, 0,
940 0, 0, 0));
941 gtk_window_present(GTK_WINDOW(spy_sabotage_shell));
942 }
943}
944
945/**********************************************************************/
948static void incite_response(GtkWidget *w, gint response, gpointer data)
949{
950 struct action_data *args = (struct action_data *)data;
951
952 if (response == GTK_RESPONSE_YES) {
954 args->target_city_id, 0, "");
955 }
956
957 gtk_widget_destroy(w);
958 free(args);
959
960 /* The user have answered the follow up question. Move on. */
962}
963
964/**********************************************************************/
967void popup_incite_dialog(struct unit *actor, struct city *pcity, int cost,
968 const struct action *paction)
969{
970 GtkWidget *shell;
971 char buf[1024];
972
973 fc_snprintf(buf, ARRAY_SIZE(buf), PL_("Treasury contains %d gold.",
974 "Treasury contains %d gold.",
975 client_player()->economic.gold),
976 client_player()->economic.gold);
977
979 shell = gtk_message_dialog_new(NULL, 0,
980 GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE,
981 _("You can't incite a revolt in %s."),
982 city_name_get(pcity));
983 gtk_window_set_title(GTK_WINDOW(shell), _("City can't be incited!"));
985 } else if (cost <= client_player()->economic.gold) {
986 shell = gtk_message_dialog_new(NULL, 0,
987 GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
988 /* TRANS: %s is pre-pluralised "Treasury contains %d gold." */
989 PL_("Incite a revolt for %d gold?\n%s",
990 "Incite a revolt for %d gold?\n%s", cost), cost, buf);
991 gtk_window_set_title(GTK_WINDOW(shell), _("Incite a Revolt!"));
993 } else {
994 shell = gtk_message_dialog_new(NULL,
995 0,
996 GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE,
997 /* TRANS: %s is pre-pluralised "Treasury contains %d gold." */
998 PL_("Inciting a revolt costs %d gold.\n%s",
999 "Inciting a revolt costs %d gold.\n%s", cost), cost, buf);
1000 gtk_window_set_title(GTK_WINDOW(shell), _("Traitors Demand Too Much!"));
1002 }
1003 gtk_window_present(GTK_WINDOW(shell));
1004
1005 g_signal_connect(shell, "response", G_CALLBACK(incite_response),
1006 act_data(paction->id, actor->id,
1007 pcity->id, 0, 0,
1008 0, 0, 0));
1009}
1010
1011/**********************************************************************/
1014static void tgt_unit_change_callback(GtkWidget *dlg, gint arg)
1015{
1016 int au_id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(dlg), "actor"));
1017
1018 if (arg == GTK_RESPONSE_YES) {
1019 struct unit *actor = game_unit_by_number(au_id);
1020
1021 if (actor != NULL) {
1022 int tgt_id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(dlg),
1023 "target"));
1024 struct unit *tgt_unit = game_unit_by_number(tgt_id);
1025 struct tile *tgt_tile = g_object_get_data(G_OBJECT(dlg), "tile");
1026
1027 if (tgt_unit == NULL) {
1028 /* Make the action dialog pop up again. */
1030 actor->id, actor->id,
1031 /* Let the server choose the target
1032 * unit. */
1035 tgt_tile->index,
1038 } else {
1040 actor->id, actor->id,
1041 tgt_id, tgt_id,
1042 tgt_tile->index,
1045 }
1046 }
1047 } else {
1048 /* Dialog canceled. This ends the action selection process. */
1050 }
1051
1052 gtk_widget_destroy(dlg);
1053}
1054
1055/**********************************************************************/
1058static void act_sel_new_unit_tgt_callback(GtkWidget *w, gpointer data)
1059{
1060 struct action_data *args = act_sel_dialog_data;
1061
1062 struct unit *punit;
1063 struct unit *tunit;
1064 struct tile *ptile;
1065
1067 && (ptile = index_to_tile(&(wld.map), args->target_tile_id))
1068 && (tunit = game_unit_by_number(args->target_unit_id))) {
1069 select_tgt_unit(punit, ptile, ptile->units, tunit,
1070 _("Target unit selection"),
1071 _("Looking for target unit:"),
1072 _("Units at tile:"),
1073 _("Select"),
1074 G_CALLBACK(tgt_unit_change_callback));
1075 }
1076
1079 gtk_widget_destroy(act_sel_dialog);
1080 free(args);
1081}
1082
1083/**********************************************************************/
1086static void tgt_extra_change_callback(GtkWidget *dlg, gint arg)
1087{
1088 int au_id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(dlg), "actor"));
1089
1090 if (arg == GTK_RESPONSE_YES) {
1091 struct unit *actor = game_unit_by_number(au_id);
1092
1093 if (actor != NULL) {
1094 int tgt_id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(dlg),
1095 "target"));
1096 struct extra_type *tgt_extra = extra_by_number(tgt_id);
1097 struct tile *tgt_tile = g_object_get_data(G_OBJECT(dlg), "tile");
1098 int tgt_unit = action_selection_target_unit();
1099
1100 if (tgt_extra == NULL) {
1101 /* Make the action dialog pop up again. */
1103 actor->id, actor->id,
1104 tgt_unit, tgt_unit,
1105 tgt_tile->index,
1106 /* Let the server choose the target
1107 * extra. */
1110 } else {
1112 actor->id, actor->id,
1113 tgt_unit, tgt_unit,
1114 tgt_tile->index,
1115 tgt_id,
1117 }
1118 }
1119 } else {
1120 /* Dialog canceled. This ends the action selection process. */
1122 }
1123
1124 gtk_widget_destroy(dlg);
1125}
1126
1127/**********************************************************************/
1130static void act_sel_new_extra_tgt_callback(GtkWidget *w, gpointer data)
1131{
1132 struct action_data *args = act_sel_dialog_data;
1133
1134 struct unit *act_unit;
1135 struct extra_type *tgt_extra;
1136 struct tile *tgt_tile;
1137
1138 if ((act_unit = game_unit_by_number(args->actor_unit_id))
1139 && (tgt_tile = index_to_tile(&(wld.map), args->target_tile_id))
1140 && (tgt_extra = extra_by_number(args->target_extra_id))) {
1141 bv_extras potential_targets;
1142
1143 /* Start with the extras at the tile */
1144 potential_targets = *tile_extras(tgt_tile);
1145
1147 if (BV_ISSET(potential_targets, extra_number(pextra))) {
1148 /* This extra is at the tile. Can anything be done to it? */
1150 pextra)) {
1151 BV_CLR(potential_targets, extra_number(pextra));
1152 }
1153 } else {
1154 /* This extra isn't at the tile yet. Can it be created? */
1156 pextra)) {
1157 BV_SET(potential_targets, extra_number(pextra));
1158 }
1159 }
1161
1162 select_tgt_extra(act_unit, tgt_tile, potential_targets, tgt_extra,
1163 /* TRANS: GTK action selection dialog extra target
1164 * selection dialog title. */
1165 _("Target extra selection"),
1166 /* TRANS: GTK action selection dialog extra target
1167 * selection dialog actor unit label. */
1168 _("Looking for target extra:"),
1169 /* TRANS: GTK action selection dialog extra target
1170 * selection dialog extra list label. */
1171 _("Extra targets:"),
1172 _("Select"),
1173 G_CALLBACK(tgt_extra_change_callback));
1174 }
1175
1178 gtk_widget_destroy(act_sel_dialog);
1179 free(args);
1180}
1181
1182/**********************************************************************/
1185static void act_sel_location_callback(GtkWidget *w, gpointer data)
1186{
1187 struct action_data *args = act_sel_dialog_data;
1188
1189 struct unit *punit;
1190
1191 if ((punit = game_unit_by_number(args->actor_unit_id))) {
1193 }
1194}
1195
1196/**********************************************************************/
1199static void act_sel_wait_callback(GtkWidget *w, gpointer data)
1200{
1201 struct action_data *args = act_sel_dialog_data;
1202
1203 key_unit_wait();
1204
1205 /* the dialog was destroyed when key_unit_wait() resulted in
1206 * action_selection_close() being called. */
1207
1208 free(args);
1209}
1210
1211/**********************************************************************/
1214static void act_sel_destroy_callback(GtkWidget *w, gpointer data)
1215{
1216 act_sel_dialog = NULL;
1218}
1219
1220/**********************************************************************/
1223static void act_sel_cancel_callback(GtkWidget *w, gpointer data)
1224{
1225 gtk_widget_destroy(act_sel_dialog);
1226 free(act_sel_dialog_data);
1227}
1228
1229/**********************************************************************/
1232static void act_sel_close_callback(GtkWidget *w,
1233 gint response_id,
1234 gpointer data)
1235{
1236 gtk_widget_destroy(act_sel_dialog);
1237 free(act_sel_dialog_data);
1238}
1239
1240/* Mapping from an action to the function to call when its button is
1241 * pushed. */
1242static const GCallback af_map[ACTION_COUNT] = {
1243 /* Unit acting against a city target. */
1244 [ACTION_SPY_TARGETED_SABOTAGE_CITY] =
1246 [ACTION_SPY_TARGETED_SABOTAGE_CITY_ESC] =
1248 [ACTION_SPY_TARGETED_STEAL_TECH] = (GCallback)spy_steal_popup,
1249 [ACTION_SPY_TARGETED_STEAL_TECH_ESC] = (GCallback)spy_steal_esc_popup,
1250 [ACTION_SPY_INCITE_CITY] = (GCallback)request_action_details_callback,
1251 [ACTION_SPY_INCITE_CITY_ESC] = (GCallback)request_action_details_callback,
1252 [ACTION_UPGRADE_UNIT] = (GCallback)upgrade_callback,
1253 [ACTION_STRIKE_BUILDING] = (GCallback)request_action_details_callback,
1254
1255 /* Unit acting against a unit target. */
1256 [ACTION_SPY_BRIBE_UNIT] = (GCallback)request_action_details_callback,
1257
1258 /* Unit acting against all units at a tile. */
1259 /* No special callback functions needed for any unit stack targeted
1260 * actions. */
1261
1262 /* Unit acting against a tile. */
1263 [ACTION_FOUND_CITY] = (GCallback)found_city_callback,
1264
1265 /* Unit acting with no target except itself. */
1266 /* No special callback functions needed for any self targeted actions. */
1267};
1268
1269/**********************************************************************/
1272static void action_entry(GtkWidget *shl,
1274 const struct act_prob *act_probs,
1275 const char *custom,
1276 action_id act_num)
1277{
1278 const gchar *label;
1279 const gchar *tooltip;
1280 GCallback cb;
1281
1282 if (af_map[act_id] == NULL) {
1283 /* No special call back function needed for this action. */
1284 cb = (GCallback)simple_action_callback;
1285 } else {
1286 /* Special action specific callback function specified. */
1287 cb = af_map[act_id];
1288 }
1289
1290 /* Don't show disabled actions. */
1291 if (!action_prob_possible(act_probs[act_id])) {
1292 return;
1293 }
1294
1295 label = action_prepare_ui_name(act_id, "_",
1296 act_probs[act_id],
1297 custom);
1298
1300 act_probs[act_id]);
1301
1303 choice_dialog_add(shl, label, cb, GINT_TO_POINTER(act_num),
1304 FALSE, tooltip);
1305}
1306
1307/**********************************************************************/
1310static void action_entry_update(GtkWidget *shl,
1312 const struct act_prob *act_probs,
1313 const char *custom,
1314 action_id act_num)
1315{
1316 const gchar *label;
1317 const gchar *tooltip;
1318
1319 /* An action that just became impossible has its button disabled.
1320 * An action that became possible again must be re-enabled. */
1323 action_prob_possible(act_probs[act_id]));
1324
1325 /* The probability may have changed. */
1326 label = action_prepare_ui_name(act_id, "_",
1327 act_probs[act_id], custom);
1328
1330 act_probs[act_id]);
1331
1334 label);
1337 tooltip);
1338}
1339
1340/**********************************************************************/
1345 struct city *target_city,
1346 struct unit *target_unit,
1347 struct tile *target_tile,
1348 struct extra_type *target_extra,
1349 const struct act_prob *act_probs)
1350{
1351 GtkWidget *shl;
1352 struct astring title = ASTRING_INIT, text = ASTRING_INIT;
1353 struct city *actor_homecity;
1354
1355 int button_id;
1356
1358 act_data(ACTION_ANY, /* Not decided yet */
1359 actor_unit->id,
1363 /* No target_building or target_tech supplied. (Dec 2019) */
1364 B_LAST, A_UNSET,
1366
1367 /* Could be caused by the server failing to reply to a request for more
1368 * information or a bug in the client code. */
1370 "Diplomat queue problem. Is another diplomat window open?");
1371
1372 /* No extra input is required as no action has been chosen yet. */
1374
1375 /* No buttons are added yet. */
1376 for (button_id = 0; button_id < BUTTON_COUNT; button_id++) {
1378 }
1379
1380 actor_homecity = game_city_by_number(actor_unit->homecity);
1381
1383 target_ids[ATK_SELF] = actor_unit_id;
1384 target_ids[ATK_CITY] = target_city ?
1385 target_city->id :
1387 target_ids[ATK_UNIT] = target_unit ?
1388 target_unit->id :
1390 target_ids[ATK_UNITS] = target_tile ?
1393 target_ids[ATK_TILE] = target_tile ?
1396 target_ids[ATK_EXTRAS] = target_tile ?
1401 EXTRA_NONE;
1402
1403 astr_set(&title,
1404 /* TRANS: %s is a unit name, e.g., Spy */
1405 _("Choose Your %s's Strategy"),
1407
1408 if (target_city && actor_homecity) {
1409 astr_set(&text,
1410 _("Your %s from %s reaches the city of %s.\nWhat now?"),
1412 city_name_get(actor_homecity),
1414 } else if (target_city) {
1415 astr_set(&text,
1416 _("Your %s has arrived at %s.\nWhat is your command?"),
1419 } else if (target_unit) {
1420 astr_set(&text,
1421 /* TRANS: Your Spy is ready to act against Roman Freight. */
1422 _("Your %s is ready to act against %s %s."),
1426 } else {
1428 "No target specified.");
1429 astr_set(&text,
1430 /* TRANS: %s is a unit name, e.g., Diplomat, Spy */
1431 _("Your %s is waiting for your command."),
1433 }
1434
1435 shl = choice_dialog_start(GTK_WINDOW(toplevel), astr_str(&title),
1436 astr_str(&text));
1437
1438 /* Unit acting against a city */
1439
1440 action_iterate(act) {
1441 if (action_id_get_actor_kind(act) == AAK_UNIT
1442 && action_id_get_target_kind(act) == ATK_CITY) {
1443 action_entry(shl, act, act_probs,
1445 act_probs[act],
1446 actor_unit,
1447 target_city),
1448 act);
1449 }
1451
1452 /* Unit acting against another unit */
1453
1454 action_iterate(act) {
1455 if (action_id_get_actor_kind(act) == AAK_UNIT
1456 && action_id_get_target_kind(act) == ATK_UNIT) {
1457 action_entry(shl, act, act_probs,
1459 act_probs[act],
1460 actor_unit,
1461 target_city),
1462 act);
1463 }
1465
1466 /* Unit acting against all units at a tile */
1467
1468 action_iterate(act) {
1469 if (action_id_get_actor_kind(act) == AAK_UNIT
1470 && action_id_get_target_kind(act) == ATK_UNITS) {
1471 action_entry(shl, act, act_probs,
1473 act_probs[act],
1474 actor_unit,
1475 target_city),
1476 act);
1477 }
1479
1480 /* Unit acting against a tile */
1481
1482 action_iterate(act) {
1483 if (action_id_get_actor_kind(act) == AAK_UNIT
1484 && action_id_get_target_kind(act) == ATK_TILE) {
1485 action_entry(shl, act, act_probs,
1487 act_probs[act],
1488 actor_unit,
1489 target_city),
1490 act);
1491 }
1493
1494 /* Unit acting against a tile's extras */
1495
1496 action_iterate(act) {
1497 if (action_id_get_actor_kind(act) == AAK_UNIT
1498 && action_id_get_target_kind(act) == ATK_EXTRAS) {
1499 action_entry(shl, act, act_probs,
1501 act_probs[act],
1502 actor_unit,
1503 target_city),
1504 act);
1505 }
1507
1508 /* Unit acting against itself. */
1509
1510 action_iterate(act) {
1511 if (action_id_get_actor_kind(act) == AAK_UNIT
1512 && action_id_get_target_kind(act) == ATK_SELF) {
1513 action_entry(shl, act, act_probs,
1515 act_probs[act],
1516 actor_unit,
1517 target_city),
1518 act);
1519 }
1521
1522 if (target_unit != NULL
1523 && unit_list_size(target_tile->units) > 1) {
1526 choice_dialog_add(shl, _("Change unit target"),
1528 GINT_TO_POINTER(ACTION_NONE), TRUE, NULL);
1529 }
1530
1531 if (target_extra != NULL) {
1534 choice_dialog_add(shl, _("Change extra target"),
1536 GINT_TO_POINTER(ACTION_NONE), TRUE, NULL);
1537 }
1538
1541 choice_dialog_add(shl, _("Show Location"),
1542 (GCallback)act_sel_location_callback,
1543 GINT_TO_POINTER(ACTION_NONE),
1544 TRUE, NULL);
1545
1548 choice_dialog_add(shl, _("_Wait"),
1549 (GCallback)act_sel_wait_callback,
1550 GINT_TO_POINTER(ACTION_NONE),
1551 TRUE, NULL);
1552
1555 choice_dialog_add(shl, _("_Cancel"),
1556 (GCallback)act_sel_cancel_callback,
1557 GINT_TO_POINTER(ACTION_NONE),
1558 FALSE, NULL);
1559
1560 choice_dialog_end(shl);
1561
1562 act_sel_dialog = shl;
1563
1565 g_signal_connect(shl, "destroy",
1566 G_CALLBACK(act_sel_destroy_callback), NULL);
1567 g_signal_connect(shl, "delete_event",
1568 G_CALLBACK(act_sel_close_callback),
1569 GINT_TO_POINTER(ACTION_NONE));
1570
1571 /* Give follow up questions access to action probabilities. */
1573 action_iterate(act) {
1574 actor_unit->client.act_prob_cache[act] = act_probs[act];
1576
1577 astr_free(&title);
1578 astr_free(&text);
1579}
1580
1581/**********************************************************************/
1587{
1588 if (act_sel_dialog == NULL) {
1589 return IDENTITY_NUMBER_ZERO;
1590 }
1591 return actor_unit_id;
1592}
1593
1594/**********************************************************************/
1601{
1602 if (act_sel_dialog == NULL) {
1603 return IDENTITY_NUMBER_ZERO;
1604 }
1605 return target_ids[ATK_CITY];
1606}
1607
1608/**********************************************************************/
1615{
1616 if (act_sel_dialog == NULL) {
1617 return IDENTITY_NUMBER_ZERO;
1618 }
1619
1620 return target_ids[ATK_UNIT];
1621}
1622
1623/**********************************************************************/
1630{
1631 if (act_sel_dialog == NULL) {
1632 return TILE_INDEX_NONE;
1633 }
1634
1635 return target_ids[ATK_TILE];
1636}
1637
1638/**********************************************************************/
1645{
1646 if (act_sel_dialog == NULL) {
1647 return EXTRA_NONE;
1648 }
1649
1650 return target_extra_id;
1651}
1652
1653/**********************************************************************/
1657 struct city *target_city,
1658 struct unit *target_unit,
1659 struct tile *target_tile,
1660 struct extra_type *target_extra,
1661 const struct act_prob *act_probs)
1662{
1663 if (act_sel_dialog == NULL) {
1665 "The action selection dialog should have been open");
1666 return;
1667 }
1668
1671 "The action selection dialog is for another actor unit.");
1672 return;
1673 }
1674
1675 /* A new target may have appeared. */
1676 if (target_city) {
1678 }
1679 if (target_unit) {
1681 }
1682 if (target_tile) {
1684 }
1685 /* No target_building or target_tech supplied. (Dec 2019) */
1686 if (target_extra) {
1688 }
1689
1690 action_iterate(act) {
1691 const char *custom;
1692
1693 if (action_id_get_actor_kind(act) != AAK_UNIT) {
1694 /* Not relevant. */
1695 continue;
1696 }
1697
1699 act_probs[act],
1700 actor_unit,
1701 target_city);
1702
1703 if (BUTTON_NOT_THERE == action_button_map[act]) {
1704 /* Add the button (unless its probability is 0). */
1705 action_entry(act_sel_dialog, act, act_probs, custom, act);
1706 } else {
1707 /* Update the existing button. */
1708 action_entry_update(act_sel_dialog, act, act_probs, custom, act);
1709 }
1711
1712 /* DO NOT change the action_button_map[] for any button to reflect its
1713 * new position. A button keeps its choice dialog internal name when its
1714 * position changes. A button's id number is therefore based on when
1715 * it was added, not on its current position. */
1716
1718 /* Move the wait button below the recently added button. */
1721 }
1722
1724 /* Move the cancel button below the recently added button. */
1727 }
1728
1730}
1731
1732/**********************************************************************/
1736{
1737 if (act_sel_dialog != NULL) {
1739 gtk_widget_destroy(act_sel_dialog);
1740 }
1741}
const char * action_prepare_ui_name(action_id act_id, const char *mnemonic, const struct act_prob prob, const char *custom)
Definition actions.c:1972
enum action_actor_kind action_get_actor_kind(const struct action *paction)
Definition actions.c:1730
bool action_prob_possible(const struct act_prob probability)
Definition actions.c:6703
enum action_sub_target_kind action_get_sub_target_kind(const struct action *paction)
Definition actions.c:1751
enum action_target_kind action_get_target_kind(const struct action *paction)
Definition actions.c:1740
static struct action * action_by_number(action_id act_id)
Definition actions.h:638
#define action_iterate_end
Definition actions.h:472
#define action_id_get_actor_kind(act_id)
Definition actions.h:651
#define action_iterate(_act_)
Definition actions.h:467
#define ACTION_ANY
Definition actions.h:290
#define action_id_get_target_kind(act_id)
Definition actions.h:655
#define ACTION_NONE
Definition actions.h:293
void astr_free(struct astring *astr)
Definition astring.c:153
void astr_set(struct astring *astr, const char *format,...)
Definition astring.c:267
#define str
Definition astring.c:76
static const char * astr_str(const struct astring *astr) fc__attribute((nonnull(1)))
Definition astring.h:93
#define ASTRING_INIT
Definition astring.h:44
#define BV_SET(bv, bit)
Definition bitvector.h:81
#define BV_ISSET(bv, bit)
Definition bitvector.h:78
#define BV_CLR(bv, bit)
Definition bitvector.h:86
const char * city_improvement_name_translation(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:658
const char * city_name_get(const struct city *pcity)
Definition city.c:1115
#define INCITE_IMPOSSIBLE_COST
Definition city.h:88
#define city_owner(_pcity_)
Definition city.h:543
#define city_built_iterate(_pcity, _p)
Definition city.h:810
#define city_built_iterate_end
Definition city.h:816
struct civclient client
#define client_player()
void client_unit_init_act_prob_cache(struct unit *punit)
Definition climisc.c:1252
void action_selection_no_longer_in_progress(const int old_actor_id)
Definition control.c:1050
void request_do_action(action_id action, int actor_id, int target_id, int sub_tgt, const char *name)
Definition control.c:1701
void request_action_details(action_id action, int actor_id, int target_id)
Definition control.c:1721
void action_decision_clear_want(const int old_actor_id)
Definition control.c:1079
void key_unit_wait(void)
Definition control.c:3375
void action_selection_next_in_focus(const int old_actor_id)
Definition control.c:1091
struct unit struct city struct unit * target_unit
Definition dialogs_g.h:55
popup_action_selection
Definition dialogs_g.h:54
struct unit * actor_unit
Definition dialogs_g.h:54
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id popup_bribe_dialog
Definition dialogs_g.h:72
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit * actor
Definition dialogs_g.h:72
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs action_selection_no_longer_in_progress_gui_specific
Definition dialogs_g.h:68
struct unit struct city struct unit struct tile * target_tile
Definition dialogs_g.h:56
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit * punit
Definition dialogs_g.h:73
struct unit struct city * target_city
Definition dialogs_g.h:55
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit int cost
Definition dialogs_g.h:73
struct unit struct city struct unit struct tile struct extra_type * target_extra
Definition dialogs_g.h:56
int extra_number(const struct extra_type *pextra)
Definition extras.c:153
struct extra_type * extra_by_number(int id)
Definition extras.c:175
#define EXTRA_NONE
Definition extras.h:82
#define extra_type_re_active_iterate_end
Definition extras.h:305
#define extra_type_re_active_iterate(_p)
Definition extras.h:301
#define NO_TARGET
Definition fc_types.h:324
int action_id
Definition fc_types.h:359
#define IDENTITY_NUMBER_ZERO
Definition fc_types.h:82
#define PL_(String1, String2, n)
Definition fcintl.h:71
#define _(String)
Definition fcintl.h:67
struct civ_game game
Definition game.c:57
struct world wld
Definition game.c:58
struct unit * game_unit_by_number(int id)
Definition game.c:111
struct city * game_city_by_number(int id)
Definition game.c:102
static GtkWidget * spy_sabotage_shell
int action_selection_target_extra(void)
static void incite_response(GtkWidget *w, gint response, gpointer data)
static int action_button_map[BUTTON_COUNT]
static void spy_improvements_callback(GtkTreeSelection *select, gpointer data)
static int actor_unit_id
#define BUTTON_NEW_EXTRA_TGT
static void act_sel_new_extra_tgt_callback(GtkWidget *w, gpointer data)
int action_selection_target_tile(void)
static void create_improvements_list(struct player *pplayer, struct city *pcity, struct action_data *args)
static void act_sel_destroy_callback(GtkWidget *w, gpointer data)
int action_selection_actor_unit(void)
static void spy_advances_response(GtkWidget *w, gint response, gpointer data)
static void tgt_extra_change_callback(GtkWidget *dlg, gint arg)
static GtkWidget * act_sel_dialog
static void spy_steal_popup_shared(GtkWidget *w, gpointer data)
static void diplomat_queue_handle_primary(void)
void action_selection_close(void)
static void spy_improvements_response(GtkWidget *w, gint response, gpointer data)
int action_selection_target_city(void)
static void bribe_response(GtkWidget *w, gint response, gpointer data)
#define BUTTON_WAIT
static void action_entry(GtkWidget *shl, action_id act_id, const struct act_prob *act_probs, const char *custom, action_id act_num)
static void spy_steal_esc_popup(GtkWidget *w, gpointer data)
static void spy_steal_popup(GtkWidget *w, gpointer data)
static void act_sel_close_callback(GtkWidget *w, gint response_id, gpointer data)
static void diplomat_queue_handle_secondary(void)
static action_id get_non_targeted_action_id(action_id tgt_action_id)
static void request_action_details_callback(GtkWidget *w, gpointer data)
static bool action_selection_restart
#define BUTTON_NEW_UNIT_TGT
#define BUTTON_COUNT
static struct action_data * act_sel_dialog_data
static void found_city_callback(GtkWidget *w, gpointer data)
static void act_sel_location_callback(GtkWidget *w, gpointer data)
void action_selection_refresh(struct unit *actor_unit, struct city *target_city, struct unit *target_unit, struct tile *target_tile, struct extra_type *target_extra, const struct act_prob *act_probs)
static struct action_data * act_data(action_id act_id, int actor_id, int target_city_id, int target_unit_id, int target_tile_id, int target_building_id, int target_tech_id, int tgt_extra_id)
static void simple_action_callback(GtkWidget *w, gpointer data)
static void create_advances_list(struct player *pplayer, struct player *pvictim, struct action_data *args)
static bool is_more_user_input_needed
static int target_extra_id
static void act_sel_wait_callback(GtkWidget *w, gpointer data)
static void act_sel_new_unit_tgt_callback(GtkWidget *w, gpointer data)
static void tgt_unit_change_callback(GtkWidget *dlg, gint arg)
#define BUTTON_NOT_THERE
static action_id get_production_targeted_action_id(action_id tgt_action_id)
static bool did_not_decide
#define BUTTON_CANCEL
void popup_sabotage_dialog(struct unit *actor, struct city *pcity, const struct action *paction)
static GtkWidget * spy_tech_shell
static int target_ids[ATK_COUNT]
static void act_sel_cancel_callback(GtkWidget *w, gpointer data)
static void action_entry_update(GtkWidget *shl, action_id act_id, const struct act_prob *act_probs, const char *custom, action_id act_num)
int action_selection_target_unit(void)
void popup_incite_dialog(struct unit *actor, struct city *pcity, int cost, const struct action *paction)
static const GCallback af_map[ACTION_COUNT]
static void upgrade_callback(GtkWidget *w, gpointer data)
static void spy_advances_callback(GtkTreeSelection *select, gpointer data)
#define BUTTON_LOCATION
GtkWidget * choice_dialog_start(GtkWindow *parent, const gchar *name, const gchar *text)
void choice_dialog_end(GtkWidget *dshell)
int choice_dialog_get_number_of_buttons(GtkWidget *cd)
void choice_dialog_button_set_tooltip(GtkWidget *cd, int number, const char *tool_tip)
void choice_dialog_button_move_to_the_end(GtkWidget *cd, const int number)
void choice_dialog_set_hide(GtkWidget *dshell, gboolean setting)
void choice_dialog_add(GtkWidget *dshell, const gchar *label, GCallback handler, gpointer data, bool meta, const gchar *tool_tip)
void choice_dialog_button_set_label(GtkWidget *cd, int number, const char *label)
void choice_dialog_button_set_sensitive(GtkWidget *cd, int button, gboolean state)
void popup_upgrade_dialog(struct unit_list *punits)
Definition dialogs.c:1444
GtkWidget * toplevel
Definition gui_main.c:124
void gtk_tree_view_focus(GtkTreeView *view)
Definition gui_stuff.c:230
void setup_dialog(GtkWidget *shell, GtkWidget *parent)
Definition gui_stuff.c:281
static struct gui_dialog * shell
Definition messagedlg.c:39
const char * tooltip
Definition repodlgs.c:1314
const char * title
Definition repodlgs.c:1313
bool select_tgt_extra(struct unit *actor, struct tile *ptile, bv_extras potential_tgt_extras, struct extra_type *suggested_tgt_extra, const gchar *dlg_title, const gchar *actor_label, const gchar *tgt_label, const gchar *do_label, GCallback do_callback)
bool select_tgt_unit(struct unit *actor, struct tile *ptile, struct unit_list *potential_tgt_units, struct unit *suggested_tgt_unit, const gchar *dlg_title, const gchar *actor_label, const gchar *tgt_label, const gchar *do_label, GCallback do_callback)
struct impr_type * improvement_by_number(const Impr_type_id id)
Impr_type_id improvement_number(const struct impr_type *pimprove)
#define B_LAST
Definition improvement.h:42
#define fc_assert_msg(condition, message,...)
Definition log.h:181
#define fc_assert(condition)
Definition log.h:176
#define fc_assert_action(condition, action)
Definition log.h:187
struct tile * index_to_tile(const struct civ_map *imap, int mindex)
Definition map.c:454
void center_tile_mapcanvas(const struct tile *ptile)
#define FC_FREE(ptr)
Definition mem.h:41
#define fc_malloc(sz)
Definition mem.h:34
const char * nation_adjective_for_player(const struct player *pplayer)
Definition nation.c:168
#define REQEST_PLAYER_INITIATED
Definition packets.h:70
int dsend_packet_unit_get_actions(struct connection *pc, int actor_unit_id16, int actor_unit_id32, int target_unit_id16, int target_unit_id32, int target_tile_id, int target_extra_id, int request_kind)
int dsend_packet_city_name_suggestion_req(struct connection *pc, int unit_id16, int unit_id32)
const char * research_advance_name_translation(const struct research *presearch, Tech_type_id tech)
Definition research.c:271
struct research * research_get(const struct player *pplayer)
Definition research.c:126
enum tech_state research_invention_state(const struct research *presearch, Tech_type_id tech)
Definition research.c:616
bool research_invention_gettable(const struct research *presearch, const Tech_type_id tech, bool allow_holes)
Definition research.c:690
#define ARRAY_SIZE(x)
Definition shared.h:85
int target_building_id
action_id act_id
action_id id
Definition actions.h:380
enum act_tgt_compl target_complexity
Definition actions.h:390
Definition city.h:309
int id
Definition city.h:315
struct packet_game_info info
Definition game.h:89
struct connection conn
Definition client_main.h:96
struct player * playing
Definition connection.h:156
bool tech_steal_allow_holes
Definition tile.h:49
int index
Definition tile.h:50
struct unit_list * units
Definition tile.h:57
Definition unit.h:138
int id
Definition unit.h:145
int index
Definition unit.h:195
struct unit::@80::@82 client
struct act_prob * act_prob_cache
Definition unit.h:225
int homecity
Definition unit.h:146
struct civ_map map
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:969
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
struct advance * valid_advance_by_number(const Tech_type_id id)
Definition tech.c:176
#define advance_index_iterate_end
Definition tech.h:248
#define A_FIRST
Definition tech.h:44
#define A_UNSET
Definition tech.h:48
#define advance_index_iterate(_start, _index)
Definition tech.h:244
const char * get_act_sel_action_custom_text(struct action *paction, const struct act_prob prob, const struct unit *actor_unit, const struct city *target_city)
Definition text.c:1743
const char * act_sel_action_tool_tip(const struct action *paction, const struct act_prob prob)
Definition text.c:1820
#define tile_index(_pt_)
Definition tile.h:87
static const bv_extras * tile_extras(const struct tile *ptile)
Definition tile.h:119
#define TILE_INDEX_NONE
Definition tile.h:47
#define unit_tile(_pu)
Definition unit.h:395
#define unit_owner(_pu)
Definition unit.h:394
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:123
bool utype_can_remove_extra(const struct unit_type *putype, const struct extra_type *pextra)
Definition unittype.c:235
const char * unit_name_translation(const struct unit *punit)
Definition unittype.c:1621
bool utype_can_create_extra(const struct unit_type *putype, const struct extra_type *pextra)
Definition unittype.c:211