Freeciv-3.1: /fast/freeciv/nightly/S3_1/client/gui-sdl2/action_dialog.c Source File

Freeciv-3.1

Loading...
Searching...
No Matches
action_dialog.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996-2006 - 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/* utility */
19#include "astring.h"
20#include "fcintl.h"
21#include "log.h"
22
23/* common */
24#include "actions.h"
25#include "game.h"
26#include "movement.h"
27#include "research.h"
28#include "traderoutes.h"
29#include "unitlist.h"
30
31/* client */
32#include "client_main.h"
33#include "climisc.h"
34#include "control.h"
35#include "text.h"
36
37/* client/gui-sdl2 */
38#include "citydlg.h"
39#include "colors.h"
40#include "dialogs.h"
41#include "graphics.h"
42#include "gui_id.h"
43#include "gui_tilespec.h"
44#include "mapview.h"
45#include "repodlgs.h"
46#include "themespec.h"
47#include "widget.h"
48
49#include "dialogs_g.h"
50
51 typedef int (*act_func)(struct widget *);
52
53 struct diplomat_dialog {
54 int actor_unit_id;
55 int target_ids[ATK_COUNT];
56 int sub_target_id[ASTK_COUNT];
57 action_id act_id;
58 struct advanced_dialog *pdialog;
59};
60
61 struct small_diplomat_dialog {
62 int actor_unit_id;
63 int target_id;
64 action_id act_id;
65 struct small_dialog *pdialog;
66};
67
68extern bool is_unit_move_blocked;
69
70void popdown_diplomat_dialog(void);
71void popdown_incite_dialog(void);
72void popdown_bribe_dialog(void);
73
74
75 static struct diplomat_dialog *diplomat_dlg = NULL;
76 static bool is_more_user_input_needed = FALSE;
77 static bool did_not_decide = FALSE;
78
79/**********************************************************************/
82 static void act_sel_done_primary(int actor_unit_id)
83{
84 if (!is_more_user_input_needed) {
85 /* The client isn't waiting for information for any unanswered follow
86 * up questions. */
87
88 struct unit *actor_unit;
89
90 if ((actor_unit = game_unit_by_number(actor_unit_id))) {
91 /* The action selection dialog wasn't closed because the actor unit
92 * was lost. */
93
94 /* The probabilities didn't just disappear, right? */
95 fc_assert_action(actor_unit->client.act_prob_cache,
96 client_unit_init_act_prob_cache(actor_unit));
97
98 FC_FREE(actor_unit->client.act_prob_cache);
99 }
100
101 /* The action selection process is over, at least for now. */
102 action_selection_no_longer_in_progress(actor_unit_id);
103
104 if (did_not_decide) {
105 /* The action selection dialog was closed but the player didn't
106 * decide what the unit should do. */
107
108 /* Reset so the next action selection dialog does the right thing. */
109 did_not_decide = FALSE;
110 } else {
111 /* An action, or no action at all, was selected. */
112 action_decision_clear_want(actor_unit_id);
113 action_selection_next_in_focus(actor_unit_id);
114 }
115 }
116}
117
118/**********************************************************************/
121 static void act_sel_done_secondary(int actor_unit_id)
122{
123 /* Stop blocking. */
124 is_more_user_input_needed = FALSE;
125 act_sel_done_primary(actor_unit_id);
126}
127
128/**********************************************************************/
134 void action_selection_no_longer_in_progress_gui_specific(int actor_id)
135{
136 /* Stop assuming the answer to a follow up question will arrive. */
137 is_more_user_input_needed = FALSE;
138}
139
140/**********************************************************************/
144 static action_id get_non_targeted_action_id(action_id tgt_action_id)
145{
146 /* Don't add an action mapping here unless the non targeted version is
147 * selectable in the targeted version's target selection dialog. */
148 switch ((enum gen_action)tgt_action_id) {
149 case ACTION_SPY_TARGETED_SABOTAGE_CITY:
150 return ACTION_SPY_SABOTAGE_CITY;
151 case ACTION_SPY_TARGETED_SABOTAGE_CITY_ESC:
152 return ACTION_SPY_SABOTAGE_CITY_ESC;
153 case ACTION_SPY_TARGETED_STEAL_TECH:
154 return ACTION_SPY_STEAL_TECH;
155 case ACTION_SPY_TARGETED_STEAL_TECH_ESC:
156 return ACTION_SPY_STEAL_TECH_ESC;
157 default:
158 /* No non targeted version found. */
159 return ACTION_NONE;
160 }
161}
162
163/**********************************************************************/
167 static action_id get_production_targeted_action_id(action_id tgt_action_id)
168{
169 /* Don't add an action mapping here unless the non targeted version is
170 * selectable in the targeted version's target selection dialog. */
171 switch ((enum gen_action)tgt_action_id) {
172 case ACTION_SPY_TARGETED_SABOTAGE_CITY:
173 return ACTION_SPY_SABOTAGE_CITY_PRODUCTION;
174 case ACTION_SPY_TARGETED_SABOTAGE_CITY_ESC:
175 return ACTION_SPY_SABOTAGE_CITY_PRODUCTION_ESC;
176 case ACTION_STRIKE_BUILDING:
177 return ACTION_STRIKE_PRODUCTION;
178 default:
179 /* No non targeted version found. */
180 return ACTION_NONE;
181 }
182}
183
184/**********************************************************************/
187 static int diplomat_dlg_window_callback(struct widget *pwindow)
188{
189 if (PRESSED_EVENT(main_data.event)) {
190 move_window_group(diplomat_dlg->pdialog->begin_widget_list, pwindow);
191 }
192
193 return -1;
194}
195
196/**********************************************************************/
200 static int spy_strike_bld_request(struct widget *pwidget)
201{
202 if (NULL != game_unit_by_number(diplomat_dlg->actor_unit_id)
203 && NULL != game_city_by_number(
204 diplomat_dlg->target_ids[ATK_CITY])) {
205 request_action_details(ACTION_STRIKE_BUILDING,
206 diplomat_dlg->actor_unit_id,
207 diplomat_dlg->target_ids[ATK_CITY]);
208 is_more_user_input_needed = TRUE;
209 popdown_diplomat_dialog();
210 } else {
211 popdown_diplomat_dialog();
212 }
213
214 return -1;
215}
216
217/**********************************************************************/
221 static int spy_sabotage_request(struct widget *pwidget)
222{
223 if (NULL != game_unit_by_number(diplomat_dlg->actor_unit_id)
224 && NULL != game_city_by_number(
225 diplomat_dlg->target_ids[ATK_CITY])) {
226 request_action_details(ACTION_SPY_TARGETED_SABOTAGE_CITY,
227 diplomat_dlg->actor_unit_id,
228 diplomat_dlg->target_ids[ATK_CITY]);
229 is_more_user_input_needed = TRUE;
230 popdown_diplomat_dialog();
231 } else {
232 popdown_diplomat_dialog();
233 }
234
235 return -1;
236}
237
238/**********************************************************************/
243 static int spy_sabotage_esc_request(struct widget *pwidget)
244{
245 if (NULL != game_unit_by_number(diplomat_dlg->actor_unit_id)
246 && NULL != game_city_by_number(
247 diplomat_dlg->target_ids[ATK_CITY])) {
248 request_action_details(ACTION_SPY_TARGETED_SABOTAGE_CITY_ESC,
249 diplomat_dlg->actor_unit_id,
250 diplomat_dlg->target_ids[ATK_CITY]);
251 is_more_user_input_needed = TRUE;
252 popdown_diplomat_dialog();
253 } else {
254 popdown_diplomat_dialog();
255 }
256
257 return -1;
258}
259
260/* --------------------------------------------------------- */
261
262/**********************************************************************/
265 static int spy_steal_dlg_window_callback(struct widget *pwindow)
266{
267 if (PRESSED_EVENT(main_data.event)) {
268 move_window_group(diplomat_dlg->pdialog->begin_widget_list, pwindow);
269 }
270
271 return -1;
272}
273
274/**********************************************************************/
277 static int exit_spy_tgt_dlg_callback(struct widget *pwidget)
278{
279 if (PRESSED_EVENT(main_data.event)) {
280 int actor_id = diplomat_dlg->actor_unit_id;
281
282 fc_assert(is_more_user_input_needed);
283 popdown_diplomat_dialog();
284 act_sel_done_secondary(actor_id);
285 }
286
287 return -1;
288}
289
290/**********************************************************************/
293 static int spy_steal_callback(struct widget *pwidget)
294{
295 if (PRESSED_EVENT(main_data.event)) {
296 int steal_advance = MAX_ID - pwidget->id;
297 int actor_id = diplomat_dlg->actor_unit_id;
298
299 if (NULL != game_unit_by_number(diplomat_dlg->actor_unit_id)
300 && NULL != game_city_by_number(
301 diplomat_dlg->target_ids[ATK_CITY])) {
302 if (steal_advance == A_UNSET) {
303 /* This is the untargeted version. */
304 request_do_action(get_non_targeted_action_id(
305 diplomat_dlg->act_id),
306 diplomat_dlg->actor_unit_id,
307 diplomat_dlg->target_ids[ATK_CITY],
308 steal_advance, "");
309 } else {
310 /* This is the targeted version. */
311 request_do_action(diplomat_dlg->act_id,
312 diplomat_dlg->actor_unit_id,
313 diplomat_dlg->target_ids[ATK_CITY],
314 steal_advance, "");
315 }
316 }
317
318 fc_assert(is_more_user_input_needed);
319 popdown_diplomat_dialog();
320 act_sel_done_secondary(actor_id);
321 }
322
323 return -1;
324}
325
326/**********************************************************************/
329 static int spy_steal_popup_shared(struct widget *pwidget)
330{
331 const struct research *presearch, *vresearch;
332 struct city *vcity = pwidget->data.city;
333 int id = diplomat_dlg->actor_unit_id;
334 struct player *victim = NULL;
335 struct container *cont;
336 struct widget *buf = NULL;
337 struct widget *pwindow;
338 utf8_str *pstr;
339 SDL_Surface *surf;
340 int max_col, max_row, col, count = 0;
341 int tech, idx;
342 SDL_Rect area;
343
344 struct unit *actor_unit = game_unit_by_number(id);
345 action_id act_id = diplomat_dlg->act_id;
346
347 is_more_user_input_needed = TRUE;
348 popdown_diplomat_dialog();
349
350 if (vcity) {
351 victim = city_owner(vcity);
352 }
353
354 fc_assert_ret_val_msg(!diplomat_dlg, 1, "Diplomat dialog already open");
355
356 if (!victim) {
357 act_sel_done_secondary(id);
358 return 1;
359 }
360
361 count = 0;
362 presearch = research_get(client_player());
363 vresearch = research_get(victim);
364 advance_index_iterate(A_FIRST, i) {
365 if (research_invention_gettable(presearch, i,
366 game.info.tech_steal_allow_holes)
367 && TECH_KNOWN == research_invention_state(vresearch, i)
368 && TECH_KNOWN != research_invention_state(presearch, i)) {
369 count++;
370 }
371 } advance_index_iterate_end;
372
373 if (!count) {
374 /* if there is no known tech to steal then
375 * send steal order at Spy's Discretion */
376 int target_id = vcity->id;
377
378 request_do_action(get_non_targeted_action_id(act_id),
379 id, target_id, A_UNSET, "");
380
381 act_sel_done_secondary(id);
382
383 return -1;
384 }
385
386 cont = fc_calloc(1, sizeof(struct container));
387 cont->id0 = vcity->id;
388 cont->id1 = id; /* spy id */
389
390 diplomat_dlg = fc_calloc(1, sizeof(struct diplomat_dialog));
391 diplomat_dlg->act_id = act_id;
392 diplomat_dlg->actor_unit_id = id;
393 diplomat_dlg->target_ids[ATK_CITY] = vcity->id;
394 diplomat_dlg->pdialog = fc_calloc(1, sizeof(struct advanced_dialog));
395
396 pstr = create_utf8_from_char_fonto(_("Select Advance to Steal"),
397 FONTO_ATTENTION);
398 pstr->style |= TTF_STYLE_BOLD;
399
400 pwindow = create_window_skeleton(NULL, pstr, 0);
401
402 pwindow->action = spy_steal_dlg_window_callback;
403 set_wstate(pwindow , FC_WS_NORMAL);
404
405 add_to_gui_list(ID_DIPLOMAT_DLG_WINDOW, pwindow);
406 diplomat_dlg->pdialog->end_widget_list = pwindow;
407
408 area = pwindow->area;
409 area.w = MAX(area.w, adj_size(8));
410
411 /* ------------------ */
412 /* Exit button */
413 buf = create_themeicon(current_theme->small_cancel_icon, pwindow->dst,
414 WF_WIDGET_HAS_INFO_LABEL | WF_RESTORE_BACKGROUND);
415 buf->info_label = create_utf8_from_char_fonto(_("Close Dialog (Esc)"),
416 FONTO_ATTENTION);
417 area.w += buf->size.w + adj_size(10);
418 buf->action = exit_spy_tgt_dlg_callback;
419 set_wstate(buf, FC_WS_NORMAL);
420 buf->key = SDLK_ESCAPE;
421
422 add_to_gui_list(ID_TERRAIN_ADV_DLG_EXIT_BUTTON, buf);
423 /* ------------------------- */
424
425 if (action_prob_possible(actor_unit->client.act_prob_cache[
426 get_non_targeted_action_id(act_id)])) {
427 /* count + at Spy's Discretion */
428 count++;
429 }
430
431 /* max col - 104 is steal tech widget width */
432 max_col = (main_window_width() - (pwindow->size.w - pwindow->area.w) - adj_size(2)) / adj_size(104);
433 /* max row - 204 is steal tech widget height */
434 max_row = (main_window_height() - (pwindow->size.h - pwindow->area.h)) / adj_size(204);
435
436 /* make space on screen for scrollbar */
437 if (max_col * max_row < count) {
438 max_col--;
439 }
440
441 if (count < max_col + 1) {
442 col = count;
443 } else {
444 if (count < max_col + adj_size(3)) {
445 col = max_col - adj_size(2);
446 } else {
447 if (count < max_col + adj_size(5)) {
448 col = max_col - 1;
449 } else {
450 col = max_col;
451 }
452 }
453 }
454
455 pstr = create_utf8_str_fonto(NULL, 0, FONTO_DEFAULT);
456 pstr->style |= (TTF_STYLE_BOLD | SF_CENTER);
457
458 count = 0;
459 advance_index_iterate(A_FIRST, i) {
460 if (research_invention_gettable(presearch, i,
461 game.info.tech_steal_allow_holes)
462 && TECH_KNOWN == research_invention_state(vresearch, i)
463 && TECH_KNOWN != research_invention_state(presearch, i)) {
464 count++;
465
466 copy_chars_to_utf8_str(pstr, advance_name_translation(advance_by_number(i)));
467 surf = create_select_tech_icon(pstr, i, TIM_FULL_MODE);
468 buf = create_icon2(surf, pwindow->dst,
469 WF_FREE_THEME | WF_RESTORE_BACKGROUND);
470
471 set_wstate(buf, FC_WS_NORMAL);
472 buf->action = spy_steal_callback;
473 buf->data.cont = cont;
474
475 add_to_gui_list(MAX_ID - i, buf);
476
477 if (count > (col * max_row)) {
478 set_wflag(buf, WF_HIDDEN);
479 }
480 }
481 } advance_index_iterate_end;
482
483 /* Get Spy tech to use for "At Spy's Discretion" -- this will have the
484 * side effect of displaying the unit's icon */
485 tech = advance_number(unit_type_get(actor_unit)->require_advance);
486
487 if (action_prob_possible(actor_unit->client.act_prob_cache[
488 get_non_targeted_action_id(act_id)])) {
489 struct astring str = ASTRING_INIT;
490
491 /* TRANS: %s is a unit name, e.g., Spy */
492 astr_set(&str, _("At %s's Discretion"),
493 unit_name_translation(actor_unit));
494 copy_chars_to_utf8_str(pstr, astr_str(&str));
495 astr_free(&str);
496
497 surf = create_select_tech_icon(pstr, tech, TIM_FULL_MODE);
498
499 buf = create_icon2(surf, pwindow->dst,
500 (WF_FREE_THEME | WF_RESTORE_BACKGROUND
501 | WF_FREE_DATA));
502 set_wstate(buf, FC_WS_NORMAL);
503 buf->action = spy_steal_callback;
504 buf->data.cont = cont;
505
506 add_to_gui_list(MAX_ID - A_UNSET, buf);
507 count++;
508 }
509
510 /* --------------------------------------------------------- */
511 FREEUTF8STR(pstr);
512 diplomat_dlg->pdialog->begin_widget_list = buf;
513 diplomat_dlg->pdialog->begin_active_widget_list = diplomat_dlg->pdialog->begin_widget_list;
514 diplomat_dlg->pdialog->end_active_widget_list = diplomat_dlg->pdialog->end_widget_list->prev->prev;
515
516 /* -------------------------------------------------------------- */
517
518 idx = 0;
519 if (count > col) {
520 count = (count + (col - 1)) / col;
521 if (count > max_row) {
522 diplomat_dlg->pdialog->active_widget_list = diplomat_dlg->pdialog->end_active_widget_list;
523 count = max_row;
524 idx = create_vertical_scrollbar(diplomat_dlg->pdialog, col, count, TRUE, TRUE);
525 }
526 } else {
527 count = 1;
528 }
529
530 area.w = MAX(area.w, (col * buf->size.w + adj_size(2) + idx));
531 area.h = count * buf->size.h + adj_size(2);
532
533 /* alloca window theme and win background buffer */
534 surf = theme_get_background(active_theme, BACKGROUND_SPYSTEALDLG);
535 if (resize_window(pwindow, surf, NULL,
536 (pwindow->size.w - pwindow->area.w) + area.w,
537 (pwindow->size.h - pwindow->area.h) + area.h)) {
538 FREESURFACE(surf);
539 }
540
541 area = pwindow->area;
542
543 widget_set_position(pwindow,
544 (main_window_width() - pwindow->size.w) / 2,
545 (main_window_height() - pwindow->size.h) / 2);
546
547 /* exit button */
548 buf = pwindow->prev;
549 buf->size.x = area.x + area.w - buf->size.w - 1;
550 buf->size.y = pwindow->size.y + adj_size(2);
551
552 setup_vertical_widgets_position(col, area.x + 1,
553 area.y, 0, 0,
554 diplomat_dlg->pdialog->begin_active_widget_list,
555 diplomat_dlg->pdialog->end_active_widget_list);
556
557 if (diplomat_dlg->pdialog->scroll) {
558 setup_vertical_scrollbar_area(diplomat_dlg->pdialog->scroll,
559 area.x + area.w, area.y,
560 area.h, TRUE);
561 }
562
563 redraw_group(diplomat_dlg->pdialog->begin_widget_list, pwindow, FALSE);
564 widget_mark_dirty(pwindow);
565
566 return -1;
567}
568
569/**********************************************************************/
572 static int spy_steal_popup(struct widget *pwidget)
573{
574 diplomat_dlg->act_id = ACTION_SPY_TARGETED_STEAL_TECH;
575 return spy_steal_popup_shared(pwidget);
576}
577
578/**********************************************************************/
581 static int spy_steal_esc_popup(struct widget *pwidget)
582{
583 diplomat_dlg->act_id = ACTION_SPY_TARGETED_STEAL_TECH_ESC;
584 return spy_steal_popup_shared(pwidget);
585}
586
587/**********************************************************************/
590 static int diplomat_incite_callback(struct widget *pwidget)
591{
592 if (PRESSED_EVENT(main_data.event)) {
593 if (NULL != game_unit_by_number(diplomat_dlg->actor_unit_id)
594 && NULL != game_city_by_number(
595 diplomat_dlg->target_ids[ATK_CITY])) {
596 request_action_details(ACTION_SPY_INCITE_CITY,
597 diplomat_dlg->actor_unit_id,
598 diplomat_dlg->target_ids[ATK_CITY]);
599 is_more_user_input_needed = TRUE;
600 popdown_diplomat_dialog();
601 } else {
602 popdown_diplomat_dialog();
603 }
604 }
605
606 return -1;
607}
608
609/**********************************************************************/
612 static int spy_incite_callback(struct widget *pwidget)
613{
614 if (PRESSED_EVENT(main_data.event)) {
615 if (NULL != game_unit_by_number(diplomat_dlg->actor_unit_id)
616 && NULL != game_city_by_number(
617 diplomat_dlg->target_ids[ATK_CITY])) {
618 request_action_details(ACTION_SPY_INCITE_CITY_ESC,
619 diplomat_dlg->actor_unit_id,
620 diplomat_dlg->target_ids[ATK_CITY]);
621 is_more_user_input_needed = TRUE;
622 popdown_diplomat_dialog();
623 } else {
624 popdown_diplomat_dialog();
625 }
626 }
627
628 return -1;
629}
630
631/**********************************************************************/
634 static int act_sel_wait_callback(struct widget *pwidget)
635{
636 if (PRESSED_EVENT(main_data.event)) {
637 key_unit_wait();
638
639 /* The dialog was popped down when key_unit_wait() resulted in
640 * action_selection_close() being called. */
641 }
642
643 return -1;
644}
645
646/**********************************************************************/
649 static int diplomat_bribe_callback(struct widget *pwidget)
650{
651 if (PRESSED_EVENT(main_data.event)) {
652 if (NULL != game_unit_by_number(diplomat_dlg->actor_unit_id)
653 && NULL !=
654 game_unit_by_number(diplomat_dlg->target_ids[ATK_UNIT])) {
655 request_action_details(ACTION_SPY_BRIBE_UNIT,
656 diplomat_dlg->actor_unit_id,
657 diplomat_dlg->target_ids[ATK_UNIT]);
658 is_more_user_input_needed = TRUE;
659 popdown_diplomat_dialog();
660 } else {
661 popdown_diplomat_dialog();
662 }
663 }
664
665 return -1;
666}
667
668/**********************************************************************/
671 static int found_city_callback(struct widget *pwidget)
672{
673 if (PRESSED_EVENT(main_data.event)) {
674 int actor_id = diplomat_dlg->actor_unit_id;
675
676 popdown_diplomat_dialog();
677 dsend_packet_city_name_suggestion_req(&client.conn,
678 actor_id, actor_id);
679 }
680
681 return -1;
682}
683
684/**********************************************************************/
687 static int upgrade_callback(struct widget *pwidget)
688{
689 if (PRESSED_EVENT(main_data.event)) {
690 struct unit *punit;
691
692 if (game_city_by_number(diplomat_dlg->target_ids[ATK_CITY]) != NULL
693 && (punit = game_unit_by_number(diplomat_dlg->actor_unit_id))) {
694 popup_unit_upgrade_dlg(punit, FALSE);
695 }
696
697 popdown_diplomat_dialog();
698 }
699
700 return -1;
701}
702
703/**********************************************************************/
707 static int simple_action_callback(struct widget *pwidget)
708{
709 int actor_id, target_id, sub_target;
710 struct action *paction;
711
712 bool failed = FALSE;
713
714 if (!PRESSED_EVENT(main_data.event)) {
715 return -1;
716 }
717
718 /* Data */
719 paction = action_by_number(MAX_ID - pwidget->id);
720
721 /* Actor */
722 fc_assert(action_get_actor_kind(paction) == AAK_UNIT);
723 actor_id = diplomat_dlg->actor_unit_id;
724 if (NULL == game_unit_by_number(actor_id)) {
725 /* Probably dead. */
726 failed = TRUE;
727 }
728
729 /* Target */
730 target_id = IDENTITY_NUMBER_ZERO;
731 switch (action_get_target_kind(paction)) {
732 case ATK_CITY:
733 target_id = diplomat_dlg->target_ids[ATK_CITY];
734 if (NULL == game_city_by_number(target_id)) {
735 /* Probably destroyed. */
736 failed = TRUE;
737 }
738 break;
739 case ATK_UNIT:
740 target_id = diplomat_dlg->target_ids[ATK_UNIT];
741 if (NULL == game_unit_by_number(target_id)) {
742 /* Probably dead. */
743 failed = TRUE;
744 }
745 break;
746 case ATK_UNITS:
747 case ATK_TILE:
748 case ATK_EXTRAS:
749 target_id = diplomat_dlg->target_ids[ATK_TILE];
750 if (NULL == index_to_tile(&(wld.map), target_id)) {
751 /* TODO: Should this be possible at all? If not: add assertion. */
752 failed = TRUE;
753 }
754 break;
755 case ATK_SELF:
756 target_id = IDENTITY_NUMBER_ZERO;
757 break;
758 case ATK_COUNT:
759 fc_assert(action_get_target_kind(paction) != ATK_COUNT);
760 failed = TRUE;
761 }
762
763 /* Sub target. */
764 sub_target = NO_TARGET;
765 if (paction->target_complexity != ACT_TGT_COMPL_SIMPLE) {
766 switch (action_get_sub_target_kind(paction)) {
767 case ASTK_BUILDING:
768 sub_target = diplomat_dlg->sub_target_id[ASTK_BUILDING];
769 if (NULL == improvement_by_number(sub_target)) {
770 /* Did the ruleset change? */
771 failed = TRUE;
772 }
773 break;
774 case ASTK_TECH:
775 sub_target = diplomat_dlg->sub_target_id[ASTK_TECH];
776 if (NULL == valid_advance_by_number(sub_target)) {
777 /* Did the ruleset change? */
778 failed = TRUE;
779 }
780 break;
781 case ASTK_EXTRA:
782 case ASTK_EXTRA_NOT_THERE:
783 /* TODO: validate if the extra is there? */
784 sub_target = diplomat_dlg->sub_target_id[ASTK_EXTRA];
785 if (NULL == extra_by_number(sub_target)) {
786 /* Did the ruleset change? */
787 failed = TRUE;
788 }
789 break;
790 case ASTK_NONE:
791 case ASTK_COUNT:
792 /* Shouldn't happen. */
793 fc_assert(action_get_sub_target_kind(paction) != ASTK_NONE);
794 failed = TRUE;
795 break;
796 }
797 }
798
799 /* Send request. */
800 if (!failed) {
801 request_do_action(paction->id, actor_id, target_id, sub_target, "");
802 }
803
804 /* Clean up. */
805 popdown_diplomat_dialog();
806 return -1;
807}
808
809/**********************************************************************/
812 static int diplomat_close_callback(struct widget *pwidget)
813{
814 if (PRESSED_EVENT(main_data.event)) {
815 popdown_diplomat_dialog();
816 }
817
818 return -1;
819}
820
821/**********************************************************************/
825 void popdown_diplomat_dialog(void)
826{
827 if (diplomat_dlg) {
828 act_sel_done_primary(diplomat_dlg->actor_unit_id);
829
830 is_unit_move_blocked = FALSE;
831 popdown_window_group_dialog(diplomat_dlg->pdialog->begin_widget_list,
832 diplomat_dlg->pdialog->end_widget_list);
833 FC_FREE(diplomat_dlg->pdialog->scroll);
834 FC_FREE(diplomat_dlg->pdialog);
835 FC_FREE(diplomat_dlg);
836 queue_flush();
837 }
838}
839
840/* Mapping from an action to the function to call when its button is
841 * pushed. */
842 static const act_func af_map[ACTION_COUNT] = {
843 /* Unit acting against a city target. */
844 [ACTION_SPY_TARGETED_SABOTAGE_CITY] = spy_sabotage_request,
845 [ACTION_SPY_TARGETED_SABOTAGE_CITY_ESC] = spy_sabotage_esc_request,
846 [ACTION_SPY_TARGETED_STEAL_TECH] = spy_steal_popup,
847 [ACTION_SPY_TARGETED_STEAL_TECH_ESC] = spy_steal_esc_popup,
848 [ACTION_SPY_INCITE_CITY] = diplomat_incite_callback,
849 [ACTION_SPY_INCITE_CITY_ESC] = spy_incite_callback,
850 [ACTION_UPGRADE_UNIT] = upgrade_callback,
851 [ACTION_STRIKE_BUILDING] = spy_strike_bld_request,
852
853 /* Unit acting against a unit target. */
854 [ACTION_SPY_BRIBE_UNIT] = diplomat_bribe_callback,
855
856 /* Unit acting against all units at a tile. */
857 /* No special callback functions needed for any unit stack targeted
858 * actions. */
859
860 /* Unit acting against a tile. */
861 [ACTION_FOUND_CITY] = found_city_callback,
862
863 /* Unit acting with no target except itself. */
864 /* No special callback functions needed for any self targeted actions. */
865};
866
867/**********************************************************************/
870 static void action_entry(const action_id act,
871 const struct act_prob *act_probs,
872 struct unit *act_unit,
873 struct tile *tgt_tile,
874 struct city *tgt_city,
875 struct unit *tgt_unit,
876 struct widget *pwindow,
877 SDL_Rect *area)
878{
879 struct widget *buf;
880 utf8_str *pstr;
881 const char *ui_name;
882 act_func cb;
883
884 const char *custom = get_act_sel_action_custom_text(action_by_number(act),
885 act_probs[act],
886 act_unit,
887 tgt_city);
888
889 if (af_map[act] == NULL) {
890 /* No special call back function needed for this action. */
891 cb = simple_action_callback;
892 } else {
893 /* Special action specific callback function specified. */
894 cb = af_map[act];
895 }
896
897 /* Don't show disabled actions */
898 if (!action_prob_possible(act_probs[act])) {
899 return;
900 }
901
902 ui_name = action_prepare_ui_name(act, "",
903 act_probs[act], custom);
904
905 create_active_iconlabel(buf, pwindow->dst, pstr,
906 ui_name, cb);
907
908 switch (action_id_get_target_kind(act)) {
909 case ATK_CITY:
910 buf->data.city = tgt_city;
911 break;
912 case ATK_UNIT:
913 buf->data.unit = tgt_unit;
914 break;
915 case ATK_TILE:
916 case ATK_EXTRAS:
917 case ATK_UNITS:
918 buf->data.tile = tgt_tile;
919 break;
920 case ATK_SELF:
921 buf->data.unit = act_unit;
922 break;
923 case ATK_COUNT:
924 fc_assert_msg(FALSE, "Unsupported target kind");
925 }
926
927 set_wstate(buf, FC_WS_NORMAL);
928
929 add_to_gui_list(MAX_ID - act, buf);
930
931 area->w = MAX(area->w, buf->size.w);
932 area->h += buf->size.h;
933}
934
935/**********************************************************************/
939 void popup_action_selection(struct unit *actor_unit,
940 struct city *target_city,
941 struct unit *target_unit,
942 struct tile *target_tile,
943 struct extra_type *target_extra,
944 const struct act_prob *act_probs)
945{
946 struct widget *pwindow = NULL, *buf = NULL;
947 utf8_str *pstr;
948 SDL_Rect area;
949
950 fc_assert_ret_msg(!diplomat_dlg, "Diplomat dialog already open");
951
952 /* Could be caused by the server failing to reply to a request for more
953 * information or a bug in the client code. */
954 fc_assert_msg(!is_more_user_input_needed,
955 "Diplomat queue problem. Is another diplomat window open?");
956
957 /* No extra input is required as no action has been chosen yet. */
958 is_more_user_input_needed = FALSE;
959
960 is_unit_move_blocked = TRUE;
961
962 diplomat_dlg = fc_calloc(1, sizeof(struct diplomat_dialog));
963 diplomat_dlg->actor_unit_id = actor_unit->id;
964 diplomat_dlg->pdialog = fc_calloc(1, sizeof(struct advanced_dialog));
965
966 /* window */
967 if (target_city) {
968 struct astring title = ASTRING_INIT;
969
970 /* TRANS: %s is a unit name, e.g., Spy */
971 astr_set(&title, _("Choose Your %s's Strategy"),
972 unit_name_translation(actor_unit));
973 pstr = create_utf8_from_char_fonto(astr_str(&title), FONTO_ATTENTION);
974 astr_free(&title);
975 } else {
976 pstr = create_utf8_from_char_fonto(_("Subvert Enemy Unit"),
977 FONTO_ATTENTION);
978 }
979
980 pstr->style |= TTF_STYLE_BOLD;
981
982 pwindow = create_window_skeleton(NULL, pstr, 0);
983
984 pwindow->action = diplomat_dlg_window_callback;
985 set_wstate(pwindow, FC_WS_NORMAL);
986
987 add_to_gui_list(ID_CARAVAN_DLG_WINDOW, pwindow);
988 diplomat_dlg->pdialog->end_widget_list = pwindow;
989
990 area = pwindow->area;
991 area.w = MAX(area.w, adj_size(8));
992 area.h = MAX(area.h, adj_size(2));
993
994 if (target_city) {
995 diplomat_dlg->target_ids[ATK_CITY] = target_city->id;
996 } else {
997 diplomat_dlg->target_ids[ATK_CITY] = IDENTITY_NUMBER_ZERO;
998 }
999
1000 if (target_unit) {
1001 diplomat_dlg->target_ids[ATK_UNIT] = target_unit->id;
1002 } else {
1003 diplomat_dlg->target_ids[ATK_UNIT] = IDENTITY_NUMBER_ZERO;
1004 }
1005
1006 diplomat_dlg->target_ids[ATK_UNITS] = tile_index(target_tile);
1007 diplomat_dlg->target_ids[ATK_TILE] = tile_index(target_tile);
1008 diplomat_dlg->target_ids[ATK_EXTRAS] = tile_index(target_tile);
1009
1010 /* No target building or target tech supplied. (Feb 2020) */
1011 diplomat_dlg->sub_target_id[ASTK_BUILDING] = B_LAST;
1012 diplomat_dlg->sub_target_id[ASTK_TECH] = A_UNSET;
1013
1014 if (target_extra) {
1015 diplomat_dlg->sub_target_id[ASTK_EXTRA] = extra_number(target_extra);
1016 diplomat_dlg->sub_target_id[ASTK_EXTRA_NOT_THERE]
1017 = extra_number(target_extra);
1018 } else {
1019 diplomat_dlg->sub_target_id[ASTK_EXTRA] = EXTRA_NONE;
1020 diplomat_dlg->sub_target_id[ASTK_EXTRA_NOT_THERE] = EXTRA_NONE;
1021 }
1022
1023 diplomat_dlg->target_ids[ATK_SELF] = actor_unit->id;
1024
1025 /* ---------- */
1026 /* Unit acting against a city */
1027
1028 action_iterate(act) {
1029 if (action_id_get_actor_kind(act) == AAK_UNIT
1030 && action_id_get_target_kind(act) == ATK_CITY) {
1031 action_entry(act, act_probs,
1032 actor_unit, NULL, target_city, NULL,
1033 pwindow, &area);
1034 }
1035 } action_iterate_end;
1036
1037 /* Unit acting against another unit */
1038
1039 action_iterate(act) {
1040 if (action_id_get_actor_kind(act) == AAK_UNIT
1041 && action_id_get_target_kind(act) == ATK_UNIT) {
1042 action_entry(act, act_probs,
1043 actor_unit, NULL, NULL, target_unit,
1044 pwindow, &area);
1045 }
1046 } action_iterate_end;
1047
1048 /* Unit acting against all units at a tile */
1049
1050 action_iterate(act) {
1051 if (action_id_get_actor_kind(act) == AAK_UNIT
1052 && action_id_get_target_kind(act) == ATK_UNITS) {
1053 action_entry(act, act_probs,
1054 actor_unit, target_tile, NULL, NULL,
1055 pwindow, &area);
1056 }
1057 } action_iterate_end;
1058
1059 /* Unit acting against a tile. */
1060
1061 action_iterate(act) {
1062 if (action_id_get_actor_kind(act) == AAK_UNIT
1063 && action_id_get_target_kind(act) == ATK_TILE) {
1064 action_entry(act, act_probs,
1065 actor_unit, target_tile, NULL, NULL,
1066 pwindow, &area);
1067 }
1068 } action_iterate_end;
1069
1070 /* Unit acting against a tile's extras. */
1071
1072 action_iterate(act) {
1073 if (action_id_get_actor_kind(act) == AAK_UNIT
1074 && action_id_get_target_kind(act) == ATK_EXTRAS) {
1075 action_entry(act, act_probs,
1076 actor_unit, target_tile, NULL, NULL,
1077 pwindow, &area);
1078 }
1079 } action_iterate_end;
1080
1081 /* Unit acting against itself. */
1082
1083 action_iterate(act) {
1084 if (action_id_get_actor_kind(act) == AAK_UNIT
1085 && action_id_get_target_kind(act) == ATK_SELF) {
1086 action_entry(act, act_probs,
1087 actor_unit, NULL, NULL, target_unit,
1088 pwindow, &area);
1089 }
1090 } action_iterate_end;
1091
1092 /* ---------- */
1093 create_active_iconlabel(buf, pwindow->dst, pstr,
1094 _("Wait"), act_sel_wait_callback);
1095
1096 buf->data.tile = target_tile;
1097
1098 set_wstate(buf, FC_WS_NORMAL);
1099
1100 add_to_gui_list(MAX_ID - actor_unit->id, buf);
1101
1102 area.w = MAX(area.w, buf->size.w);
1103 area.h += buf->size.h;
1104
1105 /* ---------- */
1106 create_active_iconlabel(buf, pwindow->dst, pstr,
1107 _("Cancel"), diplomat_close_callback);
1108
1109 set_wstate(buf , FC_WS_NORMAL);
1110 buf->key = SDLK_ESCAPE;
1111
1112 add_to_gui_list(ID_LABEL , buf);
1113
1114 area.w = MAX(area.w, buf->size.w);
1115 area.h += buf->size.h;
1116 /* ---------- */
1117 diplomat_dlg->pdialog->begin_widget_list = buf;
1118
1119 /* setup window size and start position */
1120
1121 resize_window(pwindow, NULL, NULL,
1122 (pwindow->size.w - pwindow->area.w) + area.w,
1123 (pwindow->size.h - pwindow->area.h) + area.h);
1124
1125 area = pwindow->area;
1126
1127 auto_center_on_focus_unit();
1128 put_window_near_map_tile(pwindow, pwindow->size.w, pwindow->size.h,
1129 unit_tile(actor_unit));
1130
1131 /* setup widget size and start position */
1132
1133 buf = pwindow->prev;
1134 setup_vertical_widgets_position(1,
1135 area.x,
1136 area.y + 1, area.w, 0,
1137 diplomat_dlg->pdialog->begin_widget_list, buf);
1138
1139 /* --------------------- */
1140 /* redraw */
1141 redraw_group(diplomat_dlg->pdialog->begin_widget_list, pwindow, 0);
1142
1143 widget_flush(pwindow);
1144
1145 /* Give follow up questions access to action probabilities. */
1146 client_unit_init_act_prob_cache(actor_unit);
1147 action_iterate(act) {
1148 actor_unit->client.act_prob_cache[act] = act_probs[act];
1149 } action_iterate_end;
1150}
1151
1152/**********************************************************************/
1157 int action_selection_actor_unit(void)
1158{
1159 if (!diplomat_dlg) {
1160 return IDENTITY_NUMBER_ZERO;
1161 }
1162
1163 return diplomat_dlg->actor_unit_id;
1164}
1165
1166/**********************************************************************/
1172 int action_selection_target_city(void)
1173{
1174 if (!diplomat_dlg) {
1175 return IDENTITY_NUMBER_ZERO;
1176 }
1177
1178 return diplomat_dlg->target_ids[ATK_CITY];
1179}
1180
1181/**********************************************************************/
1187 int action_selection_target_unit(void)
1188{
1189 if (!diplomat_dlg) {
1190 return IDENTITY_NUMBER_ZERO;
1191 }
1192
1193 return diplomat_dlg->target_ids[ATK_UNIT];
1194}
1195
1196/**********************************************************************/
1202 int action_selection_target_tile(void)
1203{
1204 if (!diplomat_dlg) {
1205 return TILE_INDEX_NONE;
1206 }
1207
1208 return diplomat_dlg->target_ids[ATK_TILE];
1209}
1210
1211/**********************************************************************/
1217 int action_selection_target_extra(void)
1218{
1219 if (!diplomat_dlg) {
1220 return EXTRA_NONE;
1221 }
1222
1223 return diplomat_dlg->sub_target_id[ASTK_EXTRA];
1224}
1225
1226/**********************************************************************/
1229 void action_selection_refresh(struct unit *actor_unit,
1230 struct city *target_city,
1231 struct unit *target_unit,
1232 struct tile *target_tile,
1233 struct extra_type *target_extra,
1234 const struct act_prob *act_probs)
1235{
1236 action_selection_close();
1237 popup_action_selection(actor_unit,
1238 target_city, target_unit,
1239 target_tile, target_extra,
1240 act_probs);
1241}
1242
1243/**********************************************************************/
1246 void action_selection_close(void)
1247{
1248 did_not_decide = TRUE;
1249 popdown_diplomat_dialog();
1250}
1251
1252/* ====================================================================== */
1253/* ============================ SABOTAGE DIALOG ========================= */
1254/* ====================================================================== */
1255
1256/**********************************************************************/
1259 static int sabotage_impr_callback(struct widget *pwidget)
1260{
1261 if (PRESSED_EVENT(main_data.event)) {
1262 int sabotage_improvement = MAX_ID - pwidget->id;
1263 int diplomat_target_id = pwidget->data.cont->id0;
1264 int diplomat_id = pwidget->data.cont->id1;
1265 action_id act_id = pwidget->data.cont->value;
1266
1267 fc_assert(is_more_user_input_needed);
1268 popdown_diplomat_dialog();
1269
1270 if (sabotage_improvement == 1000) {
1271 sabotage_improvement = -1;
1272 }
1273
1274 if (NULL != game_unit_by_number(diplomat_id)
1275 && NULL != game_city_by_number(diplomat_target_id)) {
1276 if (sabotage_improvement == B_LAST) {
1277 /* This is the untargeted version. */
1278 request_do_action(get_non_targeted_action_id(act_id),
1279 diplomat_id, diplomat_target_id,
1280 sabotage_improvement, "");
1281 } else if (sabotage_improvement == -1) {
1282 /* This is the city production version. */
1283 request_do_action(get_production_targeted_action_id(act_id),
1284 diplomat_id, diplomat_target_id,
1285 sabotage_improvement, "");
1286 } else {
1287 /* This is the targeted version. */
1288 request_do_action(act_id,
1289 diplomat_id, diplomat_target_id,
1290 sabotage_improvement, "");
1291 }
1292 }
1293
1294 act_sel_done_secondary(diplomat_id);
1295 }
1296
1297 return -1;
1298}
1299
1300/**********************************************************************/
1304 void popup_sabotage_dialog(struct unit *actor, struct city *pcity,
1305 const struct action *paction)
1306{
1307 struct widget *pwindow = NULL, *buf = NULL , *last = NULL;
1308 struct container *cont;
1309 utf8_str *pstr;
1310 SDL_Rect area, area2;
1311 int n, w = 0, h, imp_h = 0, y;
1312
1313 fc_assert_ret_msg(!diplomat_dlg, "Diplomat dialog already open");
1314
1315 /* Should be set before sending request to the server. */
1316 fc_assert(is_more_user_input_needed);
1317
1318 if (!actor) {
1319 act_sel_done_secondary(IDENTITY_NUMBER_ZERO);
1320 return;
1321 }
1322
1323 is_unit_move_blocked = TRUE;
1324
1325 diplomat_dlg = fc_calloc(1, sizeof(struct diplomat_dialog));
1326 diplomat_dlg->actor_unit_id = actor->id;
1327 diplomat_dlg->target_ids[ATK_CITY] = pcity->id;
1328 diplomat_dlg->pdialog = fc_calloc(1, sizeof(struct advanced_dialog));
1329
1330 cont = fc_calloc(1, sizeof(struct container));
1331 cont->id0 = pcity->id;
1332 cont->id1 = actor->id; /* Spy id */
1333 cont->value = paction->id;
1334
1335 pstr = create_utf8_from_char_fonto(_("Select Improvement to Sabotage"),
1336 FONTO_ATTENTION);
1337 pstr->style |= TTF_STYLE_BOLD;
1338
1339 pwindow = create_window_skeleton(NULL, pstr, 0);
1340
1341 pwindow->action = diplomat_dlg_window_callback;
1342 set_wstate(pwindow, FC_WS_NORMAL);
1343
1344 add_to_gui_list(ID_TERRAIN_ADV_DLG_WINDOW, pwindow);
1345 diplomat_dlg->pdialog->end_widget_list = pwindow;
1346
1347 area = pwindow->area;
1348 area.h = MAX(area.h, adj_size(2));
1349
1350 /* ---------- */
1351 /* Exit button */
1352 buf = create_themeicon(current_theme->small_cancel_icon, pwindow->dst,
1353 WF_WIDGET_HAS_INFO_LABEL | WF_RESTORE_BACKGROUND);
1354 buf->info_label = create_utf8_from_char_fonto(_("Close Dialog (Esc)"),
1355 FONTO_ATTENTION);
1356 area.w += buf->size.w + adj_size(10);
1357 buf->action = exit_spy_tgt_dlg_callback;
1358 set_wstate(buf, FC_WS_NORMAL);
1359 buf->key = SDLK_ESCAPE;
1360
1361 add_to_gui_list(ID_TERRAIN_ADV_DLG_EXIT_BUTTON, buf);
1362 /* ---------- */
1363
1364 if (action_prob_possible(actor->client.act_prob_cache[
1365 get_production_targeted_action_id(
1366 paction->id)])) {
1367 create_active_iconlabel(buf, pwindow->dst, pstr,
1368 _("City Production"), sabotage_impr_callback);
1369 buf->data.cont = cont;
1370 set_wstate(buf, FC_WS_NORMAL);
1371 set_wflag(buf, WF_FREE_DATA);
1372 add_to_gui_list(MAX_ID - 1000, buf);
1373
1374 area.w = MAX(area.w, buf->size.w);
1375 area.h += buf->size.h;
1376
1377 /* separator */
1378 buf = create_iconlabel(NULL, pwindow->dst, NULL, WF_FREE_THEME);
1379
1380 add_to_gui_list(ID_SEPARATOR, buf);
1381 area.h += buf->next->size.h;
1382
1383 diplomat_dlg->pdialog->end_active_widget_list = buf;
1384 }
1385
1386 /* ------------------ */
1387 n = 0;
1388 city_built_iterate(pcity, pimprove) {
1389 if (pimprove->sabotage > 0) {
1390 create_active_iconlabel(buf, pwindow->dst, pstr,
1391 (char *) city_improvement_name_translation(pcity, pimprove),
1392 sabotage_impr_callback);
1393 buf->data.cont = cont;
1394 set_wstate(buf, FC_WS_NORMAL);
1395
1396 add_to_gui_list(MAX_ID - improvement_number(pimprove), buf);
1397
1398 area.w = MAX(area.w , buf->size.w);
1399 imp_h += buf->size.h;
1400
1401 if (n > 9) {
1402 set_wflag(buf, WF_HIDDEN);
1403 }
1404
1405 n++;
1406 /* ----------- */
1407 }
1408 } city_built_iterate_end;
1409
1410 diplomat_dlg->pdialog->begin_active_widget_list = buf;
1411
1412 if (n > 0
1413 && action_prob_possible(actor->client.act_prob_cache[
1414 get_non_targeted_action_id(paction->id)])) {
1415 /* separator */
1416 buf = create_iconlabel(NULL, pwindow->dst, NULL, WF_FREE_THEME);
1417
1418 add_to_gui_list(ID_SEPARATOR, buf);
1419 area.h += buf->next->size.h;
1420 /* ------------------ */
1421 }
1422
1423 if (action_prob_possible(actor->client.act_prob_cache[
1424 get_non_targeted_action_id(paction->id)])) {
1425 struct astring str = ASTRING_INIT;
1426
1427 /* TRANS: %s is a unit name, e.g., Spy */
1428 astr_set(&str, _("At %s's Discretion"), unit_name_translation(actor));
1429 create_active_iconlabel(buf, pwindow->dst, pstr, astr_str(&str),
1430 sabotage_impr_callback);
1431 astr_free(&str);
1432
1433 buf->data.cont = cont;
1434 set_wstate(buf, FC_WS_NORMAL);
1435
1436 add_to_gui_list(MAX_ID - B_LAST, buf);
1437
1438 area.w = MAX(area.w, buf->size.w);
1439 area.h += buf->size.h;
1440 }
1441
1442 /* ----------- */
1443
1444 last = buf;
1445 diplomat_dlg->pdialog->begin_widget_list = last;
1446 diplomat_dlg->pdialog->active_widget_list = diplomat_dlg->pdialog->end_active_widget_list;
1447
1448 /* ---------- */
1449 if (n > 10) {
1450 imp_h = 10 * buf->size.h;
1451
1452 n = create_vertical_scrollbar(diplomat_dlg->pdialog,
1453 1, 10, TRUE, TRUE);
1454 area.w += n;
1455 } else {
1456 n = 0;
1457 }
1458 /* ---------- */
1459
1460 area.h += imp_h;
1461
1462 resize_window(pwindow, NULL, NULL,
1463 (pwindow->size.w - pwindow->area.w) + area.w,
1464 (pwindow->size.h - pwindow->area.h) + area.h);
1465
1466 area = pwindow->area;
1467
1468 auto_center_on_focus_unit();
1469 put_window_near_map_tile(pwindow, pwindow->size.w, pwindow->size.h,
1470 unit_tile(actor));
1471
1472 w = area.w;
1473
1474 /* exit button */
1475 buf = pwindow->prev;
1476 buf->size.x = area.x + area.w - buf->size.w - 1;
1477 buf->size.y = pwindow->size.y + adj_size(2);
1478
1479 /* Production sabotage */
1480 buf = buf->prev;
1481
1482 buf->size.x = area.x;
1483 buf->size.y = y = area.y + 1;
1484 buf->size.w = w;
1485 h = buf->size.h;
1486
1487 area2.x = adj_size(10);
1488 area2.h = adj_size(2);
1489
1490 buf = buf->prev;
1491 while (buf) {
1492 if (buf == diplomat_dlg->pdialog->end_active_widget_list) {
1493 w -= n;
1494 }
1495
1496 buf->size.w = w;
1497 buf->size.x = buf->next->size.x;
1498 buf->size.y = y = y + buf->next->size.h;
1499
1500 if (buf->id == ID_SEPARATOR) {
1501 FREESURFACE(buf->theme);
1502 buf->size.h = h;
1503 buf->theme = create_surf(w, h, SDL_SWSURFACE);
1504
1505 area2.y = buf->size.h / 2 - 1;
1506 area2.w = buf->size.w - adj_size(20);
1507
1508 SDL_FillRect(buf->theme , &area2, map_rgba(buf->theme->format,
1509 *get_theme_color(COLOR_THEME_SABOTAGEDLG_SEPARATOR)));
1510 }
1511
1512 if (buf == last) {
1513 break;
1514 }
1515
1516 if (buf == diplomat_dlg->pdialog->begin_active_widget_list) {
1517 /* Reset to end of scrolling area */
1518 y = MIN(y, diplomat_dlg->pdialog->end_active_widget_list->size.y
1519 + 9 * buf->size.h);
1520 w += n;
1521 }
1522 buf = buf->prev;
1523 }
1524
1525 if (diplomat_dlg->pdialog->scroll) {
1526 setup_vertical_scrollbar_area(diplomat_dlg->pdialog->scroll,
1527 area.x + area.w,
1528 diplomat_dlg->pdialog->end_active_widget_list->size.y,
1529 diplomat_dlg->pdialog->begin_active_widget_list->prev->size.y
1530 - diplomat_dlg->pdialog->end_active_widget_list->size.y,
1531 TRUE);
1532 }
1533
1534 /* -------------------- */
1535 /* redraw */
1536 redraw_group(diplomat_dlg->pdialog->begin_widget_list, pwindow, 0);
1537
1538 widget_flush(pwindow);
1539}
1540
1541/* ====================================================================== */
1542/* ============================== INCITE DIALOG ========================= */
1543/* ====================================================================== */
1544 static struct small_diplomat_dialog *incite_dlg = NULL;
1545
1546/**********************************************************************/
1549 static int incite_dlg_window_callback(struct widget *pwindow)
1550{
1551 if (PRESSED_EVENT(main_data.event)) {
1552 move_window_group(incite_dlg->pdialog->begin_widget_list, pwindow);
1553 }
1554
1555 return -1;
1556}
1557
1558/**********************************************************************/
1561 static int diplomat_incite_yes_callback(struct widget *pwidget)
1562{
1563 if (PRESSED_EVENT(main_data.event)) {
1564 if (NULL != game_unit_by_number(incite_dlg->actor_unit_id)
1565 && NULL != game_city_by_number(incite_dlg->target_id)) {
1566 request_do_action(incite_dlg->act_id, incite_dlg->actor_unit_id,
1567 incite_dlg->target_id, 0, "");
1568 }
1569
1570 popdown_incite_dialog();
1571 }
1572
1573 return -1;
1574}
1575
1576/**********************************************************************/
1579 static int exit_incite_dlg_callback(struct widget *pwidget)
1580{
1581 if (PRESSED_EVENT(main_data.event)) {
1582 popdown_incite_dialog();
1583 }
1584
1585 return -1;
1586}
1587
1588/**********************************************************************/
1592 void popdown_incite_dialog(void)
1593{
1594 if (incite_dlg) {
1595 act_sel_done_secondary(incite_dlg->actor_unit_id);
1596
1597 is_unit_move_blocked = FALSE;
1598 popdown_window_group_dialog(incite_dlg->pdialog->begin_widget_list,
1599 incite_dlg->pdialog->end_widget_list);
1600 FC_FREE(incite_dlg->pdialog);
1601 FC_FREE(incite_dlg);
1602 flush_dirty();
1603 }
1604}
1605
1606/**********************************************************************/
1610 void popup_incite_dialog(struct unit *actor, struct city *pcity, int cost,
1611 const struct action *paction)
1612{
1613 struct widget *pwindow = NULL, *buf = NULL;
1614 utf8_str *pstr;
1615 char tBuf[255], cbuf[255];
1616 bool exit = FALSE;
1617 SDL_Rect area;
1618
1619 if (incite_dlg) {
1620 return;
1621 }
1622
1623 /* Should be set before sending request to the server. */
1624 fc_assert(is_more_user_input_needed);
1625
1626 if (!actor || !unit_can_do_action(actor, paction->id)) {
1627 act_sel_done_secondary(actor ? actor->id : IDENTITY_NUMBER_ZERO);
1628 return;
1629 }
1630
1631 is_unit_move_blocked = TRUE;
1632
1633 incite_dlg = fc_calloc(1, sizeof(struct small_diplomat_dialog));
1634 incite_dlg->actor_unit_id = actor->id;
1635 incite_dlg->target_id = pcity->id;
1636 incite_dlg->act_id = paction->id;
1637 incite_dlg->pdialog = fc_calloc(1, sizeof(struct small_dialog));
1638
1639 fc_snprintf(tBuf, ARRAY_SIZE(tBuf), PL_("Treasury contains %d gold.",
1640 "Treasury contains %d gold.",
1641 client_player()->economic.gold),
1642 client_player()->economic.gold);
1643
1644 /* Window */
1645 pstr = create_utf8_from_char_fonto(_("Incite a Revolt!"), FONTO_ATTENTION);
1646
1647 pstr->style |= TTF_STYLE_BOLD;
1648
1649 pwindow = create_window_skeleton(NULL, pstr, 0);
1650
1651 pwindow->action = incite_dlg_window_callback;
1652 set_wstate(pwindow, FC_WS_NORMAL);
1653
1654 add_to_gui_list(ID_INCITE_DLG_WINDOW, pwindow);
1655 incite_dlg->pdialog->end_widget_list = pwindow;
1656
1657 area = pwindow->area;
1658 area.w = MAX(area.w, adj_size(8));
1659 area.h = MAX(area.h, adj_size(2));
1660
1661 if (INCITE_IMPOSSIBLE_COST == cost) {
1662 /* Exit button */
1663 buf = create_themeicon(current_theme->small_cancel_icon, pwindow->dst,
1664 WF_WIDGET_HAS_INFO_LABEL
1665 | WF_RESTORE_BACKGROUND);
1666 buf->info_label = create_utf8_from_char_fonto(_("Close Dialog (Esc)"),
1667 FONTO_ATTENTION);
1668 area.w += buf->size.w + adj_size(10);
1669 buf->action = exit_incite_dlg_callback;
1670 set_wstate(buf, FC_WS_NORMAL);
1671 buf->key = SDLK_ESCAPE;
1672
1673 add_to_gui_list(ID_INCITE_DLG_EXIT_BUTTON, buf);
1674 exit = TRUE;
1675 /* --------------- */
1676
1677 fc_snprintf(cbuf, sizeof(cbuf), _("You can't incite a revolt in %s."),
1678 city_name_get(pcity));
1679
1680 create_active_iconlabel(buf, pwindow->dst, pstr, cbuf, NULL);
1681
1682 add_to_gui_list(ID_LABEL , buf);
1683
1684 area.w = MAX(area.w , buf->size.w);
1685 area.h += buf->size.h;
1686 /*------------*/
1687 create_active_iconlabel(buf, pwindow->dst, pstr,
1688 _("City can't be incited!"), NULL);
1689
1690 add_to_gui_list(ID_LABEL, buf);
1691
1692 area.w = MAX(area.w, buf->size.w);
1693 area.h += buf->size.h;
1694
1695 } else if (cost <= client_player()->economic.gold) {
1696 fc_snprintf(cbuf, sizeof(cbuf),
1697 /* TRANS: %s is pre-pluralised "Treasury contains %d gold." */
1698 PL_("Incite a revolt for %d gold?\n%s",
1699 "Incite a revolt for %d gold?\n%s", cost), cost, tBuf);
1700
1701 create_active_iconlabel(buf, pwindow->dst, pstr, cbuf, NULL);
1702
1703 add_to_gui_list(ID_LABEL, buf);
1704
1705 area.w = MAX(area.w, buf->size.w);
1706 area.h += buf->size.h;
1707
1708 /*------------*/
1709 create_active_iconlabel(buf, pwindow->dst, pstr,
1710 _("Yes") , diplomat_incite_yes_callback);
1711
1712 buf->data.city = pcity;
1713 set_wstate(buf, FC_WS_NORMAL);
1714
1715 add_to_gui_list(MAX_ID - actor->id, buf);
1716
1717 area.w = MAX(area.w, buf->size.w);
1718 area.h += buf->size.h;
1719 /* ------- */
1720 create_active_iconlabel(buf, pwindow->dst, pstr,
1721 _("No") , exit_incite_dlg_callback);
1722
1723 set_wstate(buf, FC_WS_NORMAL);
1724 buf->key = SDLK_ESCAPE;
1725
1726 add_to_gui_list(ID_LABEL, buf);
1727
1728 area.w = MAX(area.w, buf->size.w);
1729 area.h += buf->size.h;
1730
1731 } else {
1732 /* Exit button */
1733 buf = create_themeicon(current_theme->small_cancel_icon, pwindow->dst,
1734 WF_WIDGET_HAS_INFO_LABEL
1735 | WF_RESTORE_BACKGROUND);
1736 buf->info_label = create_utf8_from_char_fonto(_("Close Dialog (Esc)"),
1737 FONTO_ATTENTION);
1738 area.w += buf->size.w + adj_size(10);
1739 buf->action = exit_incite_dlg_callback;
1740 set_wstate(buf, FC_WS_NORMAL);
1741 buf->key = SDLK_ESCAPE;
1742
1743 add_to_gui_list(ID_INCITE_DLG_EXIT_BUTTON, buf);
1744 exit = TRUE;
1745 /* --------------- */
1746
1747 fc_snprintf(cbuf, sizeof(cbuf),
1748 /* TRANS: %s is pre-pluralised "Treasury contains %d gold." */
1749 PL_("Inciting a revolt costs %d gold.\n%s",
1750 "Inciting a revolt costs %d gold.\n%s", cost), cost, tBuf);
1751
1752 create_active_iconlabel(buf, pwindow->dst, pstr, cbuf, NULL);
1753
1754 add_to_gui_list(ID_LABEL, buf);
1755
1756 area.w = MAX(area.w, buf->size.w);
1757 area.h += buf->size.h;
1758
1759 /*------------*/
1760 create_active_iconlabel(buf, pwindow->dst, pstr,
1761 _("Traitors Demand Too Much!"), NULL);
1762
1763 add_to_gui_list(ID_LABEL, buf);
1764
1765 area.w = MAX(area.w, buf->size.w);
1766 area.h += buf->size.h;
1767 }
1768 incite_dlg->pdialog->begin_widget_list = buf;
1769
1770 /* setup window size and start position */
1771
1772 resize_window(pwindow, NULL, NULL,
1773 (pwindow->size.w - pwindow->area.w) + area.w,
1774 (pwindow->size.h - pwindow->area.h) + area.h);
1775
1776 area = pwindow->area;
1777
1778 auto_center_on_focus_unit();
1779 put_window_near_map_tile(pwindow, pwindow->size.w, pwindow->size.h,
1780 pcity->tile);
1781
1782 /* setup widget size and start position */
1783 buf = pwindow;
1784
1785 if (exit) {
1786 /* exit button */
1787 buf = buf->prev;
1788 buf->size.x = area.x + area.w - buf->size.w - 1;
1789 buf->size.y = pwindow->size.y + adj_size(2);
1790 }
1791
1792 buf = buf->prev;
1793 setup_vertical_widgets_position(1,
1794 area.x,
1795 area.y + 1, area.w, 0,
1796 incite_dlg->pdialog->begin_widget_list, buf);
1797
1798 /* --------------------- */
1799 /* redraw */
1800 redraw_group(incite_dlg->pdialog->begin_widget_list, pwindow, 0);
1801
1802 widget_flush(pwindow);
1803}
1804
1805/* ====================================================================== */
1806/* ============================ BRIBE DIALOG ========================== */
1807/* ====================================================================== */
1808 static struct small_diplomat_dialog *bribe_dlg = NULL;
1809
1810/**********************************************************************/
1813 static int bribe_dlg_window_callback(struct widget *pwindow)
1814{
1815 if (PRESSED_EVENT(main_data.event)) {
1816 move_window_group(bribe_dlg->pdialog->begin_widget_list, pwindow);
1817 }
1818
1819 return -1;
1820}
1821
1822/**********************************************************************/
1825 static int diplomat_bribe_yes_callback(struct widget *pwidget)
1826{
1827 if (PRESSED_EVENT(main_data.event)) {
1828 if (NULL != game_unit_by_number(bribe_dlg->actor_unit_id)
1829 && NULL != game_unit_by_number(bribe_dlg->target_id)) {
1830 request_do_action(bribe_dlg->act_id, bribe_dlg->actor_unit_id,
1831 bribe_dlg->target_id, 0, "");
1832 }
1833 popdown_bribe_dialog();
1834 }
1835
1836 return -1;
1837}
1838
1839/**********************************************************************/
1842 static int exit_bribe_dlg_callback(struct widget *pwidget)
1843{
1844 if (PRESSED_EVENT(main_data.event)) {
1845 popdown_bribe_dialog();
1846 }
1847
1848 return -1;
1849}
1850
1851/**********************************************************************/
1855 void popdown_bribe_dialog(void)
1856{
1857 if (bribe_dlg) {
1858 act_sel_done_secondary(bribe_dlg->actor_unit_id);
1859
1860 is_unit_move_blocked = FALSE;
1861 popdown_window_group_dialog(bribe_dlg->pdialog->begin_widget_list,
1862 bribe_dlg->pdialog->end_widget_list);
1863 FC_FREE(bribe_dlg->pdialog);
1864 FC_FREE(bribe_dlg);
1865 flush_dirty();
1866 }
1867}
1868
1869/**********************************************************************/
1873 void popup_bribe_dialog(struct unit *actor, struct unit *punit, int cost,
1874 const struct action *paction)
1875{
1876 struct widget *pwindow = NULL, *buf = NULL;
1877 utf8_str *pstr;
1878 char tBuf[255], cbuf[255];
1879 bool exit = FALSE;
1880 SDL_Rect area;
1881
1882 if (bribe_dlg) {
1883 return;
1884 }
1885
1886 /* Should be set before sending request to the server. */
1887 fc_assert(is_more_user_input_needed);
1888
1889 if (!actor || !unit_can_do_action(actor, paction->id)) {
1890 act_sel_done_secondary(actor ? actor->id : IDENTITY_NUMBER_ZERO);
1891 return;
1892 }
1893
1894 is_unit_move_blocked = TRUE;
1895
1896 bribe_dlg = fc_calloc(1, sizeof(struct small_diplomat_dialog));
1897 bribe_dlg->act_id = paction->id;
1898 bribe_dlg->actor_unit_id = actor->id;
1899 bribe_dlg->target_id = punit->id;
1900 bribe_dlg->pdialog = fc_calloc(1, sizeof(struct small_dialog));
1901
1902 fc_snprintf(tBuf, ARRAY_SIZE(tBuf), PL_("Treasury contains %d gold.",
1903 "Treasury contains %d gold.",
1904 client_player()->economic.gold),
1905 client_player()->economic.gold);
1906
1907 /* Window */
1908 pstr = create_utf8_from_char_fonto(_("Bribe Enemy Unit"), FONTO_ATTENTION);
1909
1910 pstr->style |= TTF_STYLE_BOLD;
1911
1912 pwindow = create_window_skeleton(NULL, pstr, 0);
1913
1914 pwindow->action = bribe_dlg_window_callback;
1915 set_wstate(pwindow, FC_WS_NORMAL);
1916
1917 add_to_gui_list(ID_BRIBE_DLG_WINDOW, pwindow);
1918 bribe_dlg->pdialog->end_widget_list = pwindow;
1919
1920 area = pwindow->area;
1921 area.w = MAX(area.w, adj_size(8));
1922 area.h = MAX(area.h, adj_size(2));
1923
1924 if (cost <= client_player()->economic.gold) {
1925 fc_snprintf(cbuf, sizeof(cbuf),
1926 /* TRANS: %s is pre-pluralised "Treasury contains %d gold." */
1927 PL_("Bribe unit for %d gold?\n%s",
1928 "Bribe unit for %d gold?\n%s", cost), cost, tBuf);
1929
1930 create_active_iconlabel(buf, pwindow->dst, pstr, cbuf, NULL);
1931
1932 add_to_gui_list(ID_LABEL, buf);
1933
1934 area.w = MAX(area.w, buf->size.w);
1935 area.h += buf->size.h;
1936
1937 /*------------*/
1938 create_active_iconlabel(buf, pwindow->dst, pstr,
1939 _("Yes"), diplomat_bribe_yes_callback);
1940 buf->data.unit = punit;
1941 set_wstate(buf, FC_WS_NORMAL);
1942
1943 add_to_gui_list(MAX_ID - actor->id, buf);
1944
1945 area.w = MAX(area.w, buf->size.w);
1946 area.h += buf->size.h;
1947 /* ------- */
1948 create_active_iconlabel(buf, pwindow->dst, pstr,
1949 _("No") , exit_bribe_dlg_callback);
1950
1951 set_wstate(buf, FC_WS_NORMAL);
1952 buf->key = SDLK_ESCAPE;
1953
1954 add_to_gui_list(ID_LABEL, buf);
1955
1956 area.w = MAX(area.w, buf->size.w);
1957 area.h += buf->size.h;
1958
1959 } else {
1960 /* Exit button */
1961 buf = create_themeicon(current_theme->small_cancel_icon, pwindow->dst,
1962 WF_WIDGET_HAS_INFO_LABEL
1963 | WF_RESTORE_BACKGROUND);
1964 buf->info_label = create_utf8_from_char_fonto(_("Close Dialog (Esc)"),
1965 FONTO_ATTENTION);
1966 area.w += buf->size.w + adj_size(10);
1967 buf->action = exit_bribe_dlg_callback;
1968 set_wstate(buf, FC_WS_NORMAL);
1969 buf->key = SDLK_ESCAPE;
1970
1971 add_to_gui_list(ID_BRIBE_DLG_EXIT_BUTTON, buf);
1972 exit = TRUE;
1973 /* --------------- */
1974
1975 fc_snprintf(cbuf, sizeof(cbuf),
1976 /* TRANS: %s is pre-pluralised "Treasury contains %d gold." */
1977 PL_("Bribing the unit costs %d gold.\n%s",
1978 "Bribing the unit costs %d gold.\n%s", cost), cost, tBuf);
1979
1980 create_active_iconlabel(buf, pwindow->dst, pstr, cbuf, NULL);
1981
1982 add_to_gui_list(ID_LABEL, buf);
1983
1984 area.w = MAX(area.w, buf->size.w);
1985 area.h += buf->size.h;
1986
1987 /*------------*/
1988 create_active_iconlabel(buf, pwindow->dst, pstr,
1989 _("Traitors Demand Too Much!"), NULL);
1990
1991 add_to_gui_list(ID_LABEL, buf);
1992
1993 area.w = MAX(area.w, buf->size.w);
1994 area.h += buf->size.h;
1995 }
1996 bribe_dlg->pdialog->begin_widget_list = buf;
1997
1998 /* setup window size and start position */
1999
2000 resize_window(pwindow, NULL, NULL,
2001 (pwindow->size.w - pwindow->area.w) + area.w,
2002 (pwindow->size.h - pwindow->area.h) + area.h);
2003
2004 area = pwindow->area;
2005
2006 auto_center_on_focus_unit();
2007 put_window_near_map_tile(pwindow, pwindow->size.w, pwindow->size.h,
2008 unit_tile(actor));
2009
2010 /* setup widget size and start position */
2011 buf = pwindow;
2012
2013 if (exit) {
2014 /* exit button */
2015 buf = buf->prev;
2016 buf->size.x = area.x + area.w - buf->size.w - 1;
2017 buf->size.y = pwindow->size.y + adj_size(2);
2018 }
2019
2020 buf = buf->prev;
2021 setup_vertical_widgets_position(1,
2022 area.x,
2023 area.y + 1, area.w, 0,
2024 bribe_dlg->pdialog->begin_widget_list, buf);
2025
2026 /* --------------------- */
2027 /* redraw */
2028 redraw_group(bribe_dlg->pdialog->begin_widget_list, pwindow, 0);
2029
2030 widget_flush(pwindow);
2031}
action_prepare_ui_name
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
action_get_actor_kind
enum action_actor_kind action_get_actor_kind(const struct action *paction)
Definition actions.c:1730
action_prob_possible
bool action_prob_possible(const struct act_prob probability)
Definition actions.c:6707
action_get_sub_target_kind
enum action_sub_target_kind action_get_sub_target_kind(const struct action *paction)
Definition actions.c:1751
action_get_target_kind
enum action_target_kind action_get_target_kind(const struct action *paction)
Definition actions.c:1740
actions.h
action_by_number
static struct action * action_by_number(action_id act_id)
Definition actions.h:638
action_iterate_end
#define action_iterate_end
Definition actions.h:472
action_id_get_actor_kind
#define action_id_get_actor_kind(act_id)
Definition actions.h:651
action_iterate
#define action_iterate(_act_)
Definition actions.h:467
action_id_get_target_kind
#define action_id_get_target_kind(act_id)
Definition actions.h:655
ACTION_NONE
#define ACTION_NONE
Definition actions.h:293
astr_free
void astr_free(struct astring *astr)
Definition astring.c:153
astr_set
void astr_set(struct astring *astr, const char *format,...)
Definition astring.c:267
str
#define str
Definition astring.c:76
n
#define n
Definition astring.c:77
astring.h
astr_str
static const char * astr_str(const struct astring *astr) fc__attribute((nonnull(1)))
Definition astring.h:93
ASTRING_INIT
#define ASTRING_INIT
Definition astring.h:44
city_improvement_name_translation
const char * city_improvement_name_translation(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:658
city_name_get
const char * city_name_get(const struct city *pcity)
Definition city.c:1111
INCITE_IMPOSSIBLE_COST
#define INCITE_IMPOSSIBLE_COST
Definition city.h:88
city_owner
#define city_owner(_pcity_)
Definition city.h:543
city_built_iterate
#define city_built_iterate(_pcity, _p)
Definition city.h:801
city_built_iterate_end
#define city_built_iterate_end
Definition city.h:807
client
struct civclient client
Definition client_main.c:149
client_main.h
client_player
#define client_player()
Definition client_main.h:106
client_unit_init_act_prob_cache
void client_unit_init_act_prob_cache(struct unit *punit)
Definition climisc.c:1241
climisc.h
action_selection_no_longer_in_progress
void action_selection_no_longer_in_progress(const int old_actor_id)
Definition control.c:1032
request_do_action
void request_do_action(action_id action, int actor_id, int target_id, int sub_tgt, const char *name)
Definition control.c:1675
request_action_details
void request_action_details(action_id action, int actor_id, int target_id)
Definition control.c:1695
action_decision_clear_want
void action_decision_clear_want(const int old_actor_id)
Definition control.c:1053
key_unit_wait
void key_unit_wait(void)
Definition control.c:3348
auto_center_on_focus_unit
void auto_center_on_focus_unit(void)
Definition control.c:430
action_selection_next_in_focus
void action_selection_next_in_focus(const int old_actor_id)
Definition control.c:1065
control.h
dialogs_g.h
target_unit
struct unit struct city struct unit * target_unit
Definition dialogs_g.h:55
popup_action_selection
popup_action_selection
Definition dialogs_g.h:54
actor_unit
struct unit * actor_unit
Definition dialogs_g.h:54
popup_bribe_dialog
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
actor
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
action_selection_no_longer_in_progress_gui_specific
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
target_tile
struct unit struct city struct unit struct tile * target_tile
Definition dialogs_g.h:56
punit
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
target_city
struct unit struct city * target_city
Definition dialogs_g.h:55
cost
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
target_extra
struct unit struct city struct unit struct tile struct extra_type * target_extra
Definition dialogs_g.h:56
id
int int id
Definition editgui_g.h:28
extra_number
int extra_number(const struct extra_type *pextra)
Definition extras.c:153
extra_by_number
struct extra_type * extra_by_number(int id)
Definition extras.c:175
EXTRA_NONE
#define EXTRA_NONE
Definition extras.h:82
current_theme
QString current_theme
Definition fc_client.cpp:65
NO_TARGET
#define NO_TARGET
Definition fc_types.h:324
action_id
int action_id
Definition fc_types.h:359
IDENTITY_NUMBER_ZERO
#define IDENTITY_NUMBER_ZERO
Definition fc_types.h:82
fcintl.h
PL_
#define PL_(String1, String2, n)
Definition fcintl.h:71
_
#define _(String)
Definition fcintl.h:67
game
struct civ_game game
Definition game.c:57
wld
struct world wld
Definition game.c:58
game_unit_by_number
struct unit * game_unit_by_number(int id)
Definition game.c:111
game_city_by_number
struct city * game_city_by_number(int id)
Definition game.c:102
game.h
action_selection_target_extra
int action_selection_target_extra(void)
Definition action_dialog.c:1650
actor_unit_id
static int actor_unit_id
Definition action_dialog.c:68
action_selection_target_tile
int action_selection_target_tile(void)
Definition action_dialog.c:1635
action_selection_actor_unit
int action_selection_actor_unit(void)
Definition action_dialog.c:1592
spy_steal_popup_shared
static void spy_steal_popup_shared(GtkWidget *w, gpointer data)
Definition action_dialog.c:882
action_selection_close
void action_selection_close(void)
Definition action_dialog.c:1741
action_selection_target_city
int action_selection_target_city(void)
Definition action_dialog.c:1606
action_entry
static void action_entry(GtkWidget *shl, action_id act_id, const struct act_prob *act_probs, const char *custom, action_id act_num)
Definition action_dialog.c:1278
spy_steal_esc_popup
static void spy_steal_esc_popup(GtkWidget *w, gpointer data)
Definition action_dialog.c:928
spy_steal_popup
static void spy_steal_popup(GtkWidget *w, gpointer data)
Definition action_dialog.c:918
get_non_targeted_action_id
static action_id get_non_targeted_action_id(action_id tgt_action_id)
Definition action_dialog.c:196
found_city_callback
static void found_city_callback(GtkWidget *w, gpointer data)
Definition action_dialog.c:421
action_selection_refresh
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)
Definition action_dialog.c:1662
simple_action_callback
static void simple_action_callback(GtkWidget *w, gpointer data)
Definition action_dialog.c:240
is_more_user_input_needed
static bool is_more_user_input_needed
Definition action_dialog.c:71
act_sel_wait_callback
static void act_sel_wait_callback(GtkWidget *w, gpointer data)
Definition action_dialog.c:1205
get_production_targeted_action_id
static action_id get_production_targeted_action_id(action_id tgt_action_id)
Definition action_dialog.c:219
did_not_decide
static bool did_not_decide
Definition action_dialog.c:72
popup_sabotage_dialog
void popup_sabotage_dialog(struct unit *actor, struct city *pcity, const struct action *paction)
Definition action_dialog.c:938
action_selection_target_unit
int action_selection_target_unit(void)
Definition action_dialog.c:1620
popup_incite_dialog
void popup_incite_dialog(struct unit *actor, struct city *pcity, int cost, const struct action *paction)
Definition action_dialog.c:973
af_map
static const GCallback af_map[ACTION_COUNT]
Definition action_dialog.c:1248
upgrade_callback
static void upgrade_callback(GtkWidget *w, gpointer data)
Definition action_dialog.c:436
flush_dirty
void flush_dirty(void)
Definition mapview.c:450
title
const char * title
Definition repodlgs.c:1313
diplomat_dlg
static struct diplomat_dialog * diplomat_dlg
Definition action_dialog.c:75
incite_dlg
static struct small_diplomat_dialog * incite_dlg
Definition action_dialog.c:1544
exit_incite_dlg_callback
static int exit_incite_dlg_callback(struct widget *pwidget)
Definition action_dialog.c:1579
incite_dlg_window_callback
static int incite_dlg_window_callback(struct widget *pwindow)
Definition action_dialog.c:1549
spy_sabotage_request
static int spy_sabotage_request(struct widget *pwidget)
Definition action_dialog.c:221
is_unit_move_blocked
bool is_unit_move_blocked
Definition gui_main.c:103
diplomat_bribe_yes_callback
static int diplomat_bribe_yes_callback(struct widget *pwidget)
Definition action_dialog.c:1825
spy_strike_bld_request
static int spy_strike_bld_request(struct widget *pwidget)
Definition action_dialog.c:200
sabotage_impr_callback
static int sabotage_impr_callback(struct widget *pwidget)
Definition action_dialog.c:1259
bribe_dlg_window_callback
static int bribe_dlg_window_callback(struct widget *pwindow)
Definition action_dialog.c:1813
act_sel_done_primary
static void act_sel_done_primary(int actor_unit_id)
Definition action_dialog.c:82
diplomat_incite_yes_callback
static int diplomat_incite_yes_callback(struct widget *pwidget)
Definition action_dialog.c:1561
diplomat_close_callback
static int diplomat_close_callback(struct widget *pwidget)
Definition action_dialog.c:812
spy_sabotage_esc_request
static int spy_sabotage_esc_request(struct widget *pwidget)
Definition action_dialog.c:243
diplomat_dlg_window_callback
static int diplomat_dlg_window_callback(struct widget *pwindow)
Definition action_dialog.c:187
spy_incite_callback
static int spy_incite_callback(struct widget *pwidget)
Definition action_dialog.c:612
act_sel_done_secondary
static void act_sel_done_secondary(int actor_unit_id)
Definition action_dialog.c:121
popdown_diplomat_dialog
void popdown_diplomat_dialog(void)
Definition action_dialog.c:825
exit_bribe_dlg_callback
static int exit_bribe_dlg_callback(struct widget *pwidget)
Definition action_dialog.c:1842
popdown_incite_dialog
void popdown_incite_dialog(void)
Definition action_dialog.c:1592
popdown_bribe_dialog
void popdown_bribe_dialog(void)
Definition action_dialog.c:1855
exit_spy_tgt_dlg_callback
static int exit_spy_tgt_dlg_callback(struct widget *pwidget)
Definition action_dialog.c:277
spy_steal_dlg_window_callback
static int spy_steal_dlg_window_callback(struct widget *pwindow)
Definition action_dialog.c:265
spy_steal_callback
static int spy_steal_callback(struct widget *pwidget)
Definition action_dialog.c:293
diplomat_bribe_callback
static int diplomat_bribe_callback(struct widget *pwidget)
Definition action_dialog.c:649
diplomat_incite_callback
static int diplomat_incite_callback(struct widget *pwidget)
Definition action_dialog.c:590
act_func
int(* act_func)(struct widget *)
Definition action_dialog.c:51
bribe_dlg
static struct small_diplomat_dialog * bribe_dlg
Definition action_dialog.c:1808
get_theme_color
SDL_Color * get_theme_color(enum theme_color themecolor)
Definition colors.c:44
put_window_near_map_tile
void put_window_near_map_tile(struct widget *pwindow, int window_width, int window_height, struct tile *ptile)
Definition dialogs.c:108
popup_unit_upgrade_dlg
void popup_unit_upgrade_dlg(struct unit *punit, bool city)
Definition dialogs.c:680
main_window_width
int main_window_width(void)
Definition graphics.c:685
main_data
struct sdl2_data main_data
Definition graphics.c:57
create_surf
SDL_Surface * create_surf(int width, int height, Uint32 flags)
Definition graphics.c:351
main_window_height
int main_window_height(void)
Definition graphics.c:693
FREESURFACE
#define FREESURFACE(ptr)
Definition graphics.h:322
map_rgba
#define map_rgba(format, color)
Definition graphics.h:315
adj_size
#define adj_size(size)
Definition gui_main.h:138
PRESSED_EVENT
#define PRESSED_EVENT(event)
Definition gui_main.h:68
queue_flush
void queue_flush(void)
Definition mapview.c:152
create_select_tech_icon
SDL_Surface * create_select_tech_icon(utf8_str *pstr, Tech_type_id tech_id, enum tech_info_mode mode)
Definition repodlgs.c:2423
TIM_FULL_MODE
@ TIM_FULL_MODE
Definition repodlgs.h:30
citydlg.h
colors.h
dialogs.h
graphics.h
mapview.h
repodlgs.h
gui_id.h
ID_BRIBE_DLG_WINDOW
@ ID_BRIBE_DLG_WINDOW
Definition gui_id.h:213
ID_TERRAIN_ADV_DLG_WINDOW
@ ID_TERRAIN_ADV_DLG_WINDOW
Definition gui_id.h:202
ID_CARAVAN_DLG_WINDOW
@ ID_CARAVAN_DLG_WINDOW
Definition gui_id.h:206
ID_BRIBE_DLG_EXIT_BUTTON
@ ID_BRIBE_DLG_EXIT_BUTTON
Definition gui_id.h:214
ID_INCITE_DLG_WINDOW
@ ID_INCITE_DLG_WINDOW
Definition gui_id.h:209
ID_TERRAIN_ADV_DLG_EXIT_BUTTON
@ ID_TERRAIN_ADV_DLG_EXIT_BUTTON
Definition gui_id.h:203
ID_DIPLOMAT_DLG_WINDOW
@ ID_DIPLOMAT_DLG_WINDOW
Definition gui_id.h:208
ID_SEPARATOR
@ ID_SEPARATOR
Definition gui_id.h:28
ID_LABEL
@ ID_LABEL
Definition gui_id.h:27
ID_INCITE_DLG_EXIT_BUTTON
@ ID_INCITE_DLG_EXIT_BUTTON
Definition gui_id.h:210
copy_chars_to_utf8_str
utf8_str * copy_chars_to_utf8_str(utf8_str *pstr, const char *pchars)
Definition gui_string.c:251
create_utf8_str_fonto
utf8_str * create_utf8_str_fonto(char *in_text, size_t n_alloc, enum font_origin origin)
Definition gui_string.c:241
FREEUTF8STR
#define FREEUTF8STR(pstr)
Definition gui_string.h:92
SF_CENTER
#define SF_CENTER
Definition gui_string.h:40
FONTO_DEFAULT
@ FONTO_DEFAULT
Definition gui_string.h:64
FONTO_ATTENTION
@ FONTO_ATTENTION
Definition gui_string.h:66
create_utf8_from_char_fonto
#define create_utf8_from_char_fonto(string_in, fonto)
Definition gui_string.h:107
gui_tilespec.h
improvement_by_number
struct impr_type * improvement_by_number(const Impr_type_id id)
Definition improvement.c:192
improvement_number
Impr_type_id improvement_number(const struct impr_type *pimprove)
Definition improvement.c:182
B_LAST
#define B_LAST
Definition improvement.h:42
log.h
fc_assert_msg
#define fc_assert_msg(condition, message,...)
Definition log.h:181
fc_assert
#define fc_assert(condition)
Definition log.h:176
fc_assert_ret_msg
#define fc_assert_ret_msg(condition, message,...)
Definition log.h:205
fc_assert_action
#define fc_assert_action(condition, action)
Definition log.h:187
fc_assert_ret_val_msg
#define fc_assert_ret_val_msg(condition, val, message,...)
Definition log.h:208
index_to_tile
struct tile * index_to_tile(const struct civ_map *imap, int mindex)
Definition map.c:454
fc_calloc
#define fc_calloc(n, esz)
Definition mem.h:38
FC_FREE
#define FC_FREE(ptr)
Definition mem.h:41
movement.h
dsend_packet_city_name_suggestion_req
int dsend_packet_city_name_suggestion_req(struct connection *pc, int unit_id16, int unit_id32)
Definition packets_gen.c:30284
research_get
struct research * research_get(const struct player *pplayer)
Definition research.c:126
research_invention_state
enum tech_state research_invention_state(const struct research *presearch, Tech_type_id tech)
Definition research.c:616
research_invention_gettable
bool research_invention_gettable(const struct research *presearch, const Tech_type_id tech, bool allow_holes)
Definition research.c:690
research.h
ARRAY_SIZE
#define ARRAY_SIZE(x)
Definition shared.h:85
MIN
#define MIN(x, y)
Definition shared.h:55
MAX
#define MAX(x, y)
Definition shared.h:54
act_prob
Definition fc_types.h:1092
action
Definition actions.h:379
action::id
action_id id
Definition actions.h:380
action::target_complexity
enum act_tgt_compl target_complexity
Definition actions.h:390
advanced_dialog
Definition widget.h:180
advanced_dialog::active_widget_list
struct widget * active_widget_list
Definition widget.h:186
advanced_dialog::end_widget_list
struct widget * end_widget_list
Definition widget.h:182
advanced_dialog::begin_widget_list
struct widget * begin_widget_list
Definition widget.h:181
advanced_dialog::begin_active_widget_list
struct widget * begin_active_widget_list
Definition widget.h:184
advanced_dialog::end_active_widget_list
struct widget * end_active_widget_list
Definition widget.h:185
advanced_dialog::scroll
struct scroll_bar * scroll
Definition widget.h:187
astring
Definition astring.h:36
city
Definition city.h:309
city::id
int id
Definition city.h:315
city::tile
struct tile * tile
Definition city.h:311
civ_game::info
struct packet_game_info info
Definition game.h:89
civclient::conn
struct connection conn
Definition client_main.h:96
container
Definition widget.h:102
container::id1
int id1
Definition widget.h:104
container::id0
int id0
Definition widget.h:103
container::value
int value
Definition widget.h:105
diplomat_dialog
Definition action_dialog.c:53
diplomat_dialog::sub_target_id
int sub_target_id[ASTK_COUNT]
Definition action_dialog.c:56
diplomat_dialog::pdialog
struct advanced_dialog * pdialog
Definition action_dialog.c:58
diplomat_dialog::target_ids
int target_ids[ATK_COUNT]
Definition action_dialog.c:55
diplomat_dialog::act_id
action_id act_id
Definition action_dialog.c:57
diplomat_dialog::actor_unit_id
int actor_unit_id
Definition action_dialog.c:54
extra_type
Definition extras.h:85
packet_game_info::tech_steal_allow_holes
bool tech_steal_allow_holes
Definition packets_gen.h:211
player
Definition player.h:249
research
Definition research.h:39
sdl2_data::event
SDL_Event event
Definition graphics.h:217
small_dialog
Definition widget.h:174
small_dialog::begin_widget_list
struct widget * begin_widget_list
Definition widget.h:175
small_dialog::end_widget_list
struct widget * end_widget_list
Definition widget.h:176
small_diplomat_dialog
Definition action_dialog.c:61
small_diplomat_dialog::pdialog
struct small_dialog * pdialog
Definition action_dialog.c:65
small_diplomat_dialog::target_id
int target_id
Definition action_dialog.c:63
small_diplomat_dialog::actor_unit_id
int actor_unit_id
Definition action_dialog.c:62
small_diplomat_dialog::act_id
action_id act_id
Definition action_dialog.c:64
tile
Definition tile.h:49
unit
Definition unit.h:138
unit::id
int id
Definition unit.h:145
unit::client
struct unit::@80::@82 client
unit::act_prob_cache
struct act_prob * act_prob_cache
Definition unit.h:225
utf8_str
Definition gui_string.h:52
utf8_str::style
Uint8 style
Definition gui_string.h:53
widget
Definition widget.h:112
widget::info_label
utf8_str * info_label
Definition widget.h:122
widget::key
SDL_Keycode key
Definition widget.h:153
widget::data
union widget::@214 data
widget::dst
struct gui_layer * dst
Definition widget.h:116
widget::prev
struct widget * prev
Definition widget.h:114
widget::action
int(* action)(struct widget *)
Definition widget.h:157
widget::city
struct city * city
Definition widget.h:128
widget::cont
struct container * cont
Definition widget.h:127
widget::area
SDL_Rect area
Definition widget.h:149
widget::id
Uint16 id
Definition widget.h:155
widget::size
SDL_Rect size
Definition widget.h:145
world::map
struct civ_map map
Definition world_object.h:38
fc_snprintf
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:969
TRUE
#define TRUE
Definition support.h:46
FALSE
#define FALSE
Definition support.h:47
advance_by_number
struct advance * advance_by_number(const Tech_type_id atype)
Definition tech.c:107
advance_name_translation
const char * advance_name_translation(const struct advance *padvance)
Definition tech.c:290
valid_advance_by_number
struct advance * valid_advance_by_number(const Tech_type_id id)
Definition tech.c:176
advance_number
Tech_type_id advance_number(const struct advance *padvance)
Definition tech.c:98
advance_index_iterate_end
#define advance_index_iterate_end
Definition tech.h:248
A_FIRST
#define A_FIRST
Definition tech.h:44
A_UNSET
#define A_UNSET
Definition tech.h:48
advance_index_iterate
#define advance_index_iterate(_start, _index)
Definition tech.h:244
get_act_sel_action_custom_text
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
text.h
theme_get_background
SDL_Surface * theme_get_background(const struct theme *t, enum theme_background background)
Definition themebackgrounds.c:94
BACKGROUND_SPYSTEALDLG
@ BACKGROUND_SPYSTEALDLG
Definition themebackgrounds.h:46
COLOR_THEME_SABOTAGEDLG_SEPARATOR
@ COLOR_THEME_SABOTAGEDLG_SEPARATOR
Definition themecolors.h:115
active_theme
struct theme * active_theme
Definition themespec.c:154
themespec.h
tile_index
#define tile_index(_pt_)
Definition tile.h:87
TILE_INDEX_NONE
#define TILE_INDEX_NONE
Definition tile.h:47
traderoutes.h
unit_can_do_action
bool unit_can_do_action(const struct unit *punit, const action_id act_id)
Definition unit.c:331
unit_tile
#define unit_tile(_pu)
Definition unit.h:388
unitlist.h
unit_type_get
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:123
unit_name_translation
const char * unit_name_translation(const struct unit *punit)
Definition unittype.c:1621
add_to_gui_list
void add_to_gui_list(Uint16 id, struct widget *gui)
Definition widget.c:585
setup_vertical_widgets_position
int setup_vertical_widgets_position(int step, Sint16 start_x, Sint16 start_y, Uint16 w, Uint16 h, struct widget *begin, struct widget *end)
Definition widget.c:1050
redraw_group
Uint16 redraw_group(const struct widget *begin_group_widget_list, const struct widget *end_group_widget_list, int add_to_update)
Definition widget.c:719
popdown_window_group_dialog
void popdown_window_group_dialog(struct widget *begin_group_widget_list, struct widget *end_group_widget_list)
Definition widget.c:982
move_window_group
void move_window_group(struct widget *begin_widget_list, struct widget *pwindow)
Definition widget.c:1038
widget.h
widget_set_position
static void widget_set_position(struct widget *pwidget, int x, int y)
Definition widget.h:266
MAX_ID
#define MAX_ID
Definition widget.h:38
FC_WS_NORMAL
@ FC_WS_NORMAL
Definition widget.h:96
widget_mark_dirty
static void widget_mark_dirty(struct widget *pwidget)
Definition widget.h:286
widget_flush
static void widget_flush(struct widget *pwidget)
Definition widget.h:291
set_wstate
void set_wstate(struct widget *pwidget, enum widget_state state)
Definition widget_core.c:36
WF_WIDGET_HAS_INFO_LABEL
@ WF_WIDGET_HAS_INFO_LABEL
Definition widget.h:88
WF_FREE_DATA
@ WF_FREE_DATA
Definition widget.h:78
WF_RESTORE_BACKGROUND
@ WF_RESTORE_BACKGROUND
Definition widget.h:85
WF_HIDDEN
@ WF_HIDDEN
Definition widget.h:68
WF_FREE_THEME
@ WF_FREE_THEME
Definition widget.h:72
set_wflag
void set_wflag(struct widget *pwidget, enum widget_flag flag)
Definition widget_core.c:54
create_themeicon
struct widget * create_themeicon(SDL_Surface *icon_theme, struct gui_layer *pdest, Uint32 flags)
Definition widget_icon.c:208
create_icon2
struct widget * create_icon2(SDL_Surface *icon, struct gui_layer *pdest, Uint32 flags)
Definition widget_icon.c:333
create_iconlabel
struct widget * create_iconlabel(SDL_Surface *icon, struct gui_layer *pdest, utf8_str *pstr, Uint32 flags)
Definition widget_label.c:215
create_active_iconlabel
#define create_active_iconlabel(buf, pdest, pstr, pstring, cb)
Definition widget_label.h:23
setup_vertical_scrollbar_area
void setup_vertical_scrollbar_area(struct scroll_bar *scroll, Sint16 start_x, Sint16 start_y, Uint16 height, bool swap_start_x)
Definition widget_scrollbar.c:572
create_vertical_scrollbar
Uint32 create_vertical_scrollbar(struct advanced_dialog *dlg, Uint8 step, Uint8 active, bool create_scrollbar, bool create_buttons)
Definition widget_scrollbar.c:491
resize_window
int resize_window(struct widget *pwindow, SDL_Surface *bcgd, SDL_Color *pcolor, Uint16 new_w, Uint16 new_h)
Definition widget_window.c:255
create_window_skeleton
struct widget * create_window_skeleton(struct gui_layer *pdest, utf8_str *title, Uint32 flags)
Definition widget_window.c:180