Freeciv-3.3: /fast/freeciv/nightly/main/client/gui-sdl3/action_dialog.c Source File

Freeciv-3.3

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