Freeciv-3.1: /fast/freeciv/nightly/S3_1/client/control.c Source File

Freeciv-3.1

Loading...
Searching...
No Matches
control.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
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 "bitvector.h"
21#include "fcintl.h"
22#include "log.h"
23#include "mem.h"
24#include "timing.h"
25
26/* common */
27#include "combat.h"
28#include "game.h"
29#include "map.h"
30#include "movement.h"
31#include "unitlist.h"
32
33/* common/aicore */
34#include "path_finding.h"
35
36/* client/include */
37#include "chatline_g.h"
38#include "citydlg_g.h"
39#include "dialogs_g.h"
40#include "gui_main_g.h"
41#include "mapctrl_g.h"
42#include "mapview_g.h"
43#include "menu_g.h"
44
45/* client */
46#include "audio.h"
47#include "client_main.h"
48#include "climap.h"
49#include "climisc.h"
50#include "editor.h"
51#include "goto.h"
52#include "options.h"
53#include "overview_common.h"
54#include "tilespec.h"
55#include "update_queue.h"
56
57#include "control.h"
58
59
60 struct client_disband_unit_data {
61 int unit_id;
62 int alt;
63};
64
65/* Ways to disband a unit. Sorted by preference. Starts with the worst. */
66/* TODO: Should other actions that consumes the unit be considered?
67 * Join City may be an appealing alternative. Perhaps it should be a
68 * user configurable client option? */
69 static int disband_unit_alternatives[3] = {
70 ACTION_DISBAND_UNIT,
71 ACTION_DISBAND_UNIT_RECOVER,
72 ACTION_HELP_WONDER,
73};
74
75/* gui-dep code may adjust depending on tile size etc: */
76 int num_units_below = MAX_NUM_UNITS_BELOW;
77
78/* current_focus points to the current unit(s) in focus */
79 static struct unit_list *current_focus = NULL;
80
81/* The previously focused unit(s). Focus can generally be recalled
82 * with keypad 5 (or the equivalent). */
83 static struct unit_list *previous_focus = NULL;
84
85/* The priority unit(s) for unit_focus_advance(). */
86 static struct unit_list *urgent_focus_queue = NULL;
87
88/* These should be set via set_hover_state() */
89 enum cursor_hover_state hover_state = HOVER_NONE;
90 enum unit_activity connect_activity;
91 struct extra_type *connect_tgt;
92
93 action_id goto_last_action;
94 int goto_last_tgt;
95 int goto_last_sub_tgt;
96 enum unit_orders goto_last_order; /* Last order for goto */
97
98 static struct tile *hover_tile = NULL;
99 static struct unit_list *battlegroups[MAX_NUM_BATTLEGROUPS];
100
101/* Current moving unit. */
102 static struct unit *punit_moving = NULL;
103
104/* units involved in current combat */
105 static struct unit *punit_attacking = NULL;
106 static struct unit *punit_defending = NULL;
107
108/* The ID of the unit that currently is in the action selection process.
109 *
110 * The action selection process begins when the client asks the server what
111 * actions a unit can take. It ends when the last follow up question is
112 * answered.
113 *
114 * No common client code using client supports more than one action
115 * selection process at once. The interface between the common client code
116 * and the clients would have to change before that could happen. (See
117 * action_selection_actor_unit() etc)
118 */
119 static int action_selection_in_progress_for = IDENTITY_NUMBER_ZERO;
120
121/*
122 * This variable is TRUE iff a NON-AI controlled unit was focused this
123 * turn.
124 */
125 bool non_ai_unit_focus;
126
127static void key_unit_gen_clean(enum unit_activity act, enum extra_rmcause rmcause);
128
129/*************************************************************************/
130
131static struct unit *quickselect(struct tile *ptile,
132 enum quickselect_type qtype);
133
134/**********************************************************************/
137 void control_init(void)
138{
139 int i;
140
141 current_focus = unit_list_new();
142 previous_focus = unit_list_new();
143 urgent_focus_queue = unit_list_new();
144
145 for (i = 0; i < MAX_NUM_BATTLEGROUPS; i++) {
146 battlegroups[i] = unit_list_new();
147 }
148 hover_tile = NULL;
149}
150
151/**********************************************************************/
154 void control_free(void)
155{
156 int i;
157
158 unit_list_destroy(current_focus);
159 current_focus = NULL;
160 unit_list_destroy(previous_focus);
161 previous_focus = NULL;
162 unit_list_destroy(urgent_focus_queue);
163 urgent_focus_queue = NULL;
164
165 for (i = 0; i < MAX_NUM_BATTLEGROUPS; i++) {
166 unit_list_destroy(battlegroups[i]);
167 battlegroups[i] = NULL;
168 }
169
170 clear_hover_state();
171 free_client_goto();
172}
173
174/**********************************************************************/
177 struct unit_list *get_units_in_focus(void)
178{
179 return current_focus;
180}
181
182/**********************************************************************/
185 int get_num_units_in_focus(void)
186{
187 return (NULL != current_focus ? unit_list_size(current_focus) : 0);
188}
189
190/**********************************************************************/
194 static void store_previous_focus(void)
195{
196 if (get_num_units_in_focus() > 0) {
197 unit_list_clear(previous_focus);
198 unit_list_iterate(get_units_in_focus(), punit) {
199 unit_list_append(previous_focus, punit);
200 } unit_list_iterate_end;
201 }
202}
203
204/**********************************************************************/
207 void unit_focus_urgent(struct unit *punit)
208{
209 unit_list_append(urgent_focus_queue, punit);
210}
211
212/**********************************************************************/
215 static void focus_units_changed(void)
216{
217 update_unit_info_label(get_units_in_focus());
218 menus_update();
219 /* Notify the GUI */
220 real_focus_units_changed();
221}
222
223/**********************************************************************/
226 void control_unit_killed(struct unit *punit)
227{
228 int i;
229
230 goto_unit_killed(punit);
231
232 unit_list_remove(get_units_in_focus(), punit);
233 if (get_num_units_in_focus() < 1) {
234 clear_hover_state();
235 }
236
237 unit_list_remove(previous_focus, punit);
238 unit_list_remove(urgent_focus_queue, punit);
239
240 for (i = 0; i < MAX_NUM_BATTLEGROUPS; i++) {
241 unit_list_remove(battlegroups[i], punit);
242 }
243
244 focus_units_changed();
245}
246
247/**********************************************************************/
250 void unit_change_battlegroup(struct unit *punit, int battlegroup)
251{
252 if (battlegroup < 0 || battlegroup >= MAX_NUM_BATTLEGROUPS) {
253 battlegroup = BATTLEGROUP_NONE;
254 }
255
256 if (punit->battlegroup != battlegroup) {
257 if (battlegroup != BATTLEGROUP_NONE) {
258 unit_list_append(battlegroups[battlegroup], punit);
259 }
260 if (punit->battlegroup != BATTLEGROUP_NONE) {
261 unit_list_remove(battlegroups[punit->battlegroup], punit);
262 }
263 punit->battlegroup = battlegroup;
264 }
265}
266
267/**********************************************************************/
270 void unit_register_battlegroup(struct unit *punit)
271{
272 if (punit->battlegroup < 0 || punit->battlegroup >= MAX_NUM_BATTLEGROUPS) {
273 punit->battlegroup = BATTLEGROUP_NONE;
274 } else {
275 unit_list_append(battlegroups[punit->battlegroup], punit);
276 }
277}
278
279/**********************************************************************/
285 void set_hover_state(struct unit_list *punits, enum cursor_hover_state state,
286 enum unit_activity activity,
287 struct extra_type *tgt,
288 int last_tgt,
289 int last_sub_tgt,
290 action_id action,
291 enum unit_orders order)
292{
293 fc_assert_ret((punits && unit_list_size(punits) > 0)
294 || state == HOVER_NONE);
295 fc_assert_ret(state == HOVER_CONNECT || activity == ACTIVITY_LAST);
296 fc_assert_ret((state == HOVER_GOTO || state == HOVER_GOTO_SEL_TGT)
297 || order == ORDER_LAST);
298 fc_assert_ret((state == HOVER_GOTO || state == HOVER_GOTO_SEL_TGT)
299 || action == ACTION_NONE);
300
301 if (!((hover_state == HOVER_GOTO || hover_state == HOVER_GOTO_SEL_TGT)
302 && (state == HOVER_GOTO || state == HOVER_GOTO_SEL_TGT))) {
303 /* Exit goto unless this is a switch between goto states */
304 exit_goto_state();
305 }
306
307 hover_state = state;
308 connect_activity = activity;
309 if (tgt) {
310 connect_tgt = tgt;
311 } else {
312 connect_tgt = NULL;
313 }
314 goto_last_order = order;
315 goto_last_action = action;
316 goto_last_tgt = last_tgt;
317 goto_last_sub_tgt = last_sub_tgt;
318}
319
320/**********************************************************************/
323 void clear_hover_state(void)
324{
325 set_hover_state(NULL, HOVER_NONE,
326 ACTIVITY_LAST, NULL,
327 NO_TARGET, NO_TARGET, ACTION_NONE, ORDER_LAST);
328}
329
330/**********************************************************************/
334 bool should_ask_server_for_actions(const struct unit *punit)
335{
336 return (punit->action_decision_want == ACT_DEC_ACTIVE
337 /* The player is interested in getting a pop up for a mere
338 * arrival. */
339 || (punit->action_decision_want == ACT_DEC_PASSIVE
340 && gui_options.popup_actor_arrival));
341}
342
343/**********************************************************************/
347 static bool can_ask_server_for_actions(void)
348{
349 /* OK as long as no other unit already asked and aren't done yet. */
350 return (action_selection_in_progress_for == IDENTITY_NUMBER_ZERO
351 && action_selection_actor_unit() == IDENTITY_NUMBER_ZERO);
352}
353
354/**********************************************************************/
361 static void ask_server_for_actions(struct unit *punit)
362{
363 fc_assert_ret(punit);
364 fc_assert_ret(punit->action_decision_tile);
365
366 /* Only one action selection dialog at a time is supported. */
367 fc_assert_msg(action_selection_in_progress_for == IDENTITY_NUMBER_ZERO,
368 "Unit %d started action selection before unit %d was done",
369 action_selection_in_progress_for, punit->id);
370 action_selection_in_progress_for = punit->id;
371
372 dsend_packet_unit_get_actions(&client.conn,
373 punit->id, punit->id,
374 IDENTITY_NUMBER_ZERO,
375 IDENTITY_NUMBER_ZERO,
376 tile_index(punit->action_decision_tile),
377 EXTRA_NONE,
378 REQEST_PLAYER_INITIATED);
379}
380
381/**********************************************************************/
384 bool unit_is_in_focus(const struct unit *punit)
385{
386 return unit_list_search(get_units_in_focus(), punit) != NULL;
387}
388
389/**********************************************************************/
392 struct unit *get_focus_unit_on_tile(const struct tile *ptile)
393{
394 unit_list_iterate(get_units_in_focus(), punit) {
395 if (unit_tile(punit) == ptile) {
396 return punit;
397 }
398 } unit_list_iterate_end;
399
400 return NULL;
401}
402
403/**********************************************************************/
406 struct unit *head_of_units_in_focus(void)
407{
408 return unit_list_get(current_focus, 0);
409}
410
411/**********************************************************************/
414 static struct tile *find_a_focus_unit_tile_to_center_on(void)
415{
416 struct unit *punit;
417
418 if (NULL != (punit = get_focus_unit_on_tile(get_center_tile_mapcanvas()))) {
419 return unit_tile(punit);
420 } else if (get_num_units_in_focus() > 0) {
421 return unit_tile(head_of_units_in_focus());
422 } else {
423 return NULL;
424 }
425}
426
427/**********************************************************************/
430 void auto_center_on_focus_unit(void)
431{
432 struct tile *ptile = find_a_focus_unit_tile_to_center_on();
433
434 if (ptile && gui_options.auto_center_on_unit
435 && !tile_visible_and_not_on_border_mapcanvas(ptile)) {
436 center_tile_mapcanvas(ptile);
437 }
438}
439
440/**********************************************************************/
443 static void current_focus_append(struct unit *punit)
444{
445 unit_list_append(current_focus, punit);
446
447 punit->client.focus_status = FOCUS_AVAIL;
448 refresh_unit_mapcanvas(punit, unit_tile(punit), TRUE, FALSE);
449
450 if (should_ask_server_for_actions(punit)
451 && can_ask_server_for_actions()) {
452 ask_server_for_actions(punit);
453 }
454
455 if (gui_options.unit_selection_clears_orders) {
456 clear_unit_orders(punit);
457 }
458}
459
460/**********************************************************************/
463 static void current_focus_remove(struct unit *punit)
464{
465 /* Close the action selection dialog if the actor unit lose focus. */
466 if (action_selection_actor_unit() == punit->id) {
467 action_selection_close();
468 }
469
470 unit_list_remove(current_focus, punit);
471 refresh_unit_mapcanvas(punit, unit_tile(punit), TRUE, FALSE);
472}
473
474/**********************************************************************/
477 void clear_unit_orders(struct unit *punit)
478{
479 if (!punit) {
480 return;
481 }
482
483 if (punit->activity != ACTIVITY_IDLE
484 || punit->ssa_controller != SSA_NONE) {
485 punit->ssa_controller = SSA_NONE;
486 refresh_unit_city_dialogs(punit);
487 request_new_unit_activity(punit, ACTIVITY_IDLE);
488 } else if (unit_has_orders(punit)) {
489 /* Clear the focus unit's orders. */
490 request_orders_cleared(punit);
491 }
492}
493
494/**********************************************************************/
502 void unit_focus_set(struct unit *punit)
503{
504 bool focus_changed = FALSE;
505
506 if (NULL != punit
507 && NULL != client.conn.playing
508 && unit_owner(punit) != client.conn.playing) {
509 /* Callers should make sure this never happens. */
510 return;
511 }
512
513 /* FIXME: this won't work quite right; for instance activating a
514 * battlegroup twice in a row will store the focus erronously. The only
515 * solution would be a set_units_focus() */
516 if (!(get_num_units_in_focus() == 1
517 && punit == head_of_units_in_focus())) {
518 store_previous_focus();
519 focus_changed = TRUE;
520 }
521
522 /* Close the action selection dialog if the actor unit lose focus. */
523 unit_list_iterate(current_focus, punit_old) {
524 if (action_selection_actor_unit() == punit_old->id) {
525 action_selection_close();
526 }
527 } unit_list_iterate_end;
528
529 /* Redraw the old focus unit (to fix blinking or remove the selection
530 * circle). */
531 unit_list_iterate(current_focus, punit_old) {
532 refresh_unit_mapcanvas(punit_old, unit_tile(punit_old), TRUE, FALSE);
533 } unit_list_iterate_end;
534 unit_list_clear(current_focus);
535
536 if (!can_client_change_view()) {
537 /* This function can be called to set the focus to NULL when
538 * disconnecting. In this case we don't want any other actions! */
539 fc_assert(punit == NULL);
540 return;
541 }
542
543 if (NULL != punit) {
544 current_focus_append(punit);
545 auto_center_on_focus_unit();
546 }
547
548 if (focus_changed) {
549 clear_hover_state();
550 focus_units_changed();
551 }
552}
553
554/**********************************************************************/
557 void unit_focus_add(struct unit *punit)
558{
559 if (NULL != punit
560 && NULL != client.conn.playing
561 && unit_owner(punit) != client.conn.playing) {
562 /* Callers should make sure this never happens. */
563 return;
564 }
565
566 if (NULL == punit || !can_client_change_view()) {
567 return;
568 }
569
570 if (unit_is_in_focus(punit)) {
571 return;
572 }
573
574 if (hover_state != HOVER_NONE) {
575 /* Can't continue with current goto if set of focus units
576 * change. Cancel it. */
577 clear_hover_state();
578 }
579
580 current_focus_append(punit);
581 focus_units_changed();
582}
583
584/**********************************************************************/
587 void unit_focus_remove(struct unit *punit)
588{
589 if (NULL != punit
590 && NULL != client.conn.playing
591 && unit_owner(punit) != client.conn.playing) {
592 /* Callers should make sure this never happens. */
593 return;
594 }
595
596 if (NULL == punit || !can_client_change_view()) {
597 return;
598 }
599
600 if (!unit_is_in_focus(punit)) {
601 return;
602 }
603
604 if (hover_state != HOVER_NONE) {
605 /* Can't continue with current goto if set of focus units
606 * change. Cancel it. */
607 clear_hover_state();
608 }
609
610 current_focus_remove(punit);
611 if (get_num_units_in_focus() > 0) {
612 focus_units_changed();
613 } else {
614 unit_focus_advance();
615 }
616}
617
618/**********************************************************************/
621 void unit_focus_set_and_select(struct unit *punit)
622{
623 unit_focus_set(punit);
624 if (punit) {
625 put_cross_overlay_tile(unit_tile(punit));
626 }
627}
628
629/**********************************************************************/
634 static struct unit *find_best_focus_candidate(bool accept_current)
635{
636 struct tile *ptile = get_center_tile_mapcanvas();
637
638 if (!get_focus_unit_on_tile(ptile)) {
639 struct unit *pfirst = head_of_units_in_focus();
640
641 if (pfirst) {
642 ptile = unit_tile(pfirst);
643 }
644 }
645
646 iterate_outward(&(wld.map), ptile, FC_INFINITY, ptile2) {
647 unit_list_iterate(ptile2->units, punit) {
648 if ((!unit_is_in_focus(punit) || accept_current)
649 && unit_owner(punit) == client.conn.playing
650 && punit->client.focus_status == FOCUS_AVAIL
651 && punit->activity == ACTIVITY_IDLE
652 && !unit_has_orders(punit)
653 && (punit->moves_left > 0 || unit_type_get(punit)->move_rate == 0)
654 && !punit->done_moving
655 && punit->ssa_controller == SSA_NONE) {
656 return punit;
657 }
658 } unit_list_iterate_end;
659 } iterate_outward_end;
660
661 return NULL;
662}
663
664/**********************************************************************/
671 void unit_focus_advance(void)
672{
673 struct unit *candidate = NULL;
674 const int num_units_in_old_focus = get_num_units_in_focus();
675
676 if (NULL == client.conn.playing
677 || !is_player_phase(client.conn.playing, game.info.phase)
678 || !can_client_change_view()) {
679 unit_focus_set(NULL);
680 return;
681 }
682
683 clear_hover_state();
684
685 unit_list_iterate(get_units_in_focus(), punit) {
686 /*
687 * Is the unit which just lost focus a non-AI unit? If yes this
688 * enables the auto end turn.
689 */
690 if (punit->ssa_controller == SSA_NONE) {
691 non_ai_unit_focus = TRUE;
692 break;
693 }
694 } unit_list_iterate_end;
695
696 if (unit_list_size(urgent_focus_queue) > 0) {
697 /* Try top of the urgent list. */
698 struct tile *focus_tile = (get_num_units_in_focus() > 0
699 ? unit_tile(head_of_units_in_focus())
700 : NULL);
701
702 unit_list_both_iterate(urgent_focus_queue, plink, punit) {
703 if ((ACTIVITY_IDLE != punit->activity
704 || unit_has_orders(punit))
705 /* This isn't an action decision needed because of an
706 * ORDER_ACTION_MOVE located in the middle of an order. */
707 && !should_ask_server_for_actions(punit)) {
708 /* We have assigned new orders to this unit since, remove it. */
709 unit_list_erase(urgent_focus_queue, plink);
710 } else if (NULL == focus_tile
711 || focus_tile == unit_tile(punit)) {
712 /* Use the first one found */
713 candidate = punit;
714 break;
715 } else if (NULL == candidate) {
716 candidate = punit;
717 }
718 } unit_list_both_iterate_end;
719
720 if (NULL != candidate) {
721 unit_list_remove(urgent_focus_queue, candidate);
722
723 /* Autocenter on Wakeup, regardless of the local option
724 * "auto_center_on_unit". */
725 if (!tile_visible_and_not_on_border_mapcanvas(unit_tile(candidate))) {
726 center_tile_mapcanvas(unit_tile(candidate));
727 }
728 }
729 }
730
731 if (NULL == candidate) {
732 candidate = find_best_focus_candidate(FALSE);
733
734 if (!candidate) {
735 /* Try for "waiting" units. */
736 unit_list_iterate(client.conn.playing->units, punit) {
737 if (punit->client.focus_status == FOCUS_WAIT) {
738 punit->client.focus_status = FOCUS_AVAIL;
739 }
740 } unit_list_iterate_end;
741 candidate = find_best_focus_candidate(FALSE);
742
743 if (!candidate) {
744 /* Accept current focus unit as last resort. */
745 candidate = find_best_focus_candidate(TRUE);
746 }
747 }
748 }
749
750 unit_focus_set(candidate);
751
752 /*
753 * Handle auto-turn-done mode: If a unit was in focus (did move),
754 * but now none are (no more to move) and there was at least one
755 * non-AI unit this turn which was focused, then fake a Turn Done
756 * keypress.
757 */
758 if (gui_options.auto_turn_done
759 && num_units_in_old_focus > 0
760 && get_num_units_in_focus() == 0
761 && non_ai_unit_focus) {
762 key_end_turn();
763 }
764}
765
766/**********************************************************************/
772 void unit_focus_update(void)
773{
774 if (NULL == client.conn.playing || !can_client_change_view()) {
775 return;
776 }
777
778 if (!can_ask_server_for_actions()) {
779 fc_assert(get_num_units_in_focus() > 0);
780
781 /* An actor unit is asking the player what to do. Don't change the
782 * focus. */
783 return;
784 }
785
786 /* iterate zero times for no units in focus,
787 * otherwise quit for any of the conditions. */
788 unit_list_iterate(get_units_in_focus(), punit) {
789 if ((punit->activity == ACTIVITY_IDLE
790 || punit->activity == ACTIVITY_GOTO
791 || unit_has_orders(punit))
792 && punit->moves_left > 0
793 && !punit->done_moving
794 && punit->ssa_controller == SSA_NONE) {
795 return;
796 }
797 } unit_list_iterate_end;
798
799 unit_focus_advance();
800}
801
802/**********************************************************************/
805 struct unit *find_visible_unit(struct tile *ptile)
806{
807 struct unit *panyowned = NULL, *panyother = NULL, *ptptother = NULL;
808
809 /* If no units here, return nothing. */
810 if (unit_list_size(ptile->units) == 0) {
811 return NULL;
812 }
813
814 /* If a unit is attacking we should show that on top */
815 if (punit_attacking && same_pos(unit_tile(punit_attacking), ptile)) {
816 unit_list_iterate(ptile->units, punit) {
817 if (punit == punit_attacking) {
818 return punit;
819 }
820 } unit_list_iterate_end;
821 }
822
823 /* If a unit is defending we should show that on top */
824 if (punit_defending && same_pos(unit_tile(punit_defending), ptile)) {
825 unit_list_iterate(ptile->units, punit) {
826 if (punit == punit_defending) {
827 return punit;
828 }
829 } unit_list_iterate_end;
830 }
831
832 /* If the unit in focus is at this tile, show that on top */
833 unit_list_iterate(get_units_in_focus(), punit) {
834 if (punit != punit_moving && unit_tile(punit) == ptile) {
835 return punit;
836 }
837 } unit_list_iterate_end;
838
839 /* If a city is here, return nothing (unit hidden by city). */
840 if (tile_city(ptile)) {
841 return NULL;
842 }
843
844 /* Iterate through the units to find the best one we prioritize this way:
845 1: owned transporter.
846 2: any owned unit
847 3: any transporter
848 4: any unit
849 (always return first in stack). */
850 unit_list_iterate(ptile->units, punit)
851 if (unit_owner(punit) == client.conn.playing) {
852 if (!unit_transported(punit)) {
853 if (get_transporter_capacity(punit) > 0) {
854 return punit;
855 } else if (!panyowned) {
856 panyowned = punit;
857 }
858 }
859 } else if (!ptptother && !unit_transported(punit)) {
860 if (get_transporter_capacity(punit) > 0) {
861 ptptother = punit;
862 } else if (!panyother) {
863 panyother = punit;
864 }
865 }
866 unit_list_iterate_end;
867
868 return (panyowned ? panyowned : (ptptother ? ptptother : panyother));
869}
870
871/**********************************************************************/
875 double blink_active_unit(void)
876{
877 static struct timer *blink_timer = NULL;
878 const double blink_time = get_focus_unit_toggle_timeout(tileset);
879
880 if (get_num_units_in_focus() > 0) {
881 if (!blink_timer || timer_read_seconds(blink_timer) > blink_time) {
882 toggle_focus_unit_state(tileset);
883
884 /* If we lag, we don't try to catch up. Instead we just start a
885 * new blink_time on every update. */
886 blink_timer = timer_renew(blink_timer, TIMER_USER, TIMER_ACTIVE);
887 timer_start(blink_timer);
888
889 unit_list_iterate(get_units_in_focus(), punit) {
890 /* We used to unqueue here, but that's inherently risky
891 * for a function run from a timer - the UI can be in any
892 * inconsistent state. */
893 refresh_unit_mapcanvas(punit, unit_tile(punit), FALSE, FALSE);
894 } unit_list_iterate_end;
895 }
896
897 return blink_time - timer_read_seconds(blink_timer);
898 }
899
900 return blink_time;
901}
902
903/**********************************************************************/
907 double blink_turn_done_button(void)
908{
909 static struct timer *blink_timer = NULL;
910 const double blink_time = 0.5; /* half-second blink interval */
911
912 if (NULL != client.conn.playing
913 && client.conn.playing->is_alive
914 && !client.conn.playing->phase_done
915 && is_player_phase(client.conn.playing, game.info.phase)) {
916 if (!blink_timer || timer_read_seconds(blink_timer) > blink_time) {
917 int is_waiting = 0, is_moving = 0;
918 bool blocking_mode;
919 struct option *opt;
920
921 opt = optset_option_by_name(server_optset, "turnblock");
922 if (opt != NULL) {
923 blocking_mode = option_bool_get(opt);
924 } else {
925 blocking_mode = FALSE;
926 }
927
928 players_iterate_alive(pplayer) {
929 if ((pplayer->is_connected || blocking_mode)
930 && is_player_phase(pplayer, game.info.phase)) {
931 if (pplayer->phase_done) {
932 is_waiting++;
933 } else {
934 is_moving++;
935 }
936 }
937 } players_iterate_alive_end;
938
939 if (is_moving == 1 && is_waiting > 0) {
940 update_turn_done_button(FALSE); /* stress the slow player! */
941 }
942 blink_timer = timer_renew(blink_timer, TIMER_USER, TIMER_ACTIVE);
943 timer_start(blink_timer);
944 }
945 return blink_time - timer_read_seconds(blink_timer);
946 }
947
948 return blink_time;
949}
950
951/**********************************************************************/
966 void update_unit_pix_label(struct unit_list *punitlist)
967{
968 int i;
969
970 /* Check for any change in the unit's state. This assumes that a unit's
971 * orders cannot be changed directly but must be removed and then reset. */
972 if (punitlist && unit_list_size(punitlist) > 0
973 && C_S_OVER != client_state()) {
974 /* There used to be a complicated and bug-prone check here to see if
975 * the unit had actually changed. This was misguided since the stacked
976 * units (below) are redrawn in any case. Unless we write a general
977 * system for unit updates here we might as well just redraw it every
978 * time. */
979 struct unit *punit = unit_list_get(punitlist, 0);
980
981 set_unit_icon(-1, punit);
982
983 i = 0; /* index into unit_below_canvas */
984 unit_list_iterate(unit_tile(punit)->units, aunit) {
985 if (aunit != punit) {
986 if (i < num_units_below) {
987 set_unit_icon(i, aunit);
988 }
989 i++;
990 }
991 }
992 unit_list_iterate_end;
993
994 if (i > num_units_below) {
995 set_unit_icons_more_arrow(TRUE);
996 } else {
997 set_unit_icons_more_arrow(FALSE);
998 for (; i < num_units_below; i++) {
999 set_unit_icon(i, NULL);
1000 }
1001 }
1002 } else {
1003 for (i = -1; i < num_units_below; i++) {
1004 set_unit_icon(i, NULL);
1005 }
1006 set_unit_icons_more_arrow(FALSE);
1007 }
1008}
1009
1010/**********************************************************************/
1013 void set_units_in_combat(struct unit *pattacker, struct unit *pdefender)
1014{
1015 punit_attacking = pattacker;
1016 punit_defending = pdefender;
1017
1018 if (unit_is_in_focus(punit_attacking)
1019 || unit_is_in_focus(punit_defending)) {
1020 /* If one of the units is the focus unit, make sure hidden-focus is
1021 * disabled. We don't just do this as a check later because then
1022 * with a blinking unit it would just disappear again right after the
1023 * battle. */
1024 focus_unit_in_combat(tileset);
1025 }
1026}
1027
1028/**********************************************************************/
1032 void action_selection_no_longer_in_progress(const int old_actor_id)
1033{
1034 /* IDENTITY_NUMBER_ZERO is accepted for cases where the unit is gone
1035 * without a trace. */
1036 fc_assert_msg(old_actor_id == action_selection_in_progress_for
1037 || old_actor_id == IDENTITY_NUMBER_ZERO
1038 || action_selection_in_progress_for == IDENTITY_NUMBER_ZERO,
1039 "Decision taken for %d but selection is for %d.",
1040 old_actor_id, action_selection_in_progress_for);
1041
1042 /* Stop objecting to allowing the next unit to ask. */
1043 action_selection_in_progress_for = IDENTITY_NUMBER_ZERO;
1044
1045 /* Clean up any client specific assumptions. */
1046 action_selection_no_longer_in_progress_gui_specific(old_actor_id);
1047}
1048
1049/**********************************************************************/
1053 void action_decision_clear_want(const int old_actor_id)
1054{
1055 if (game_unit_by_number(old_actor_id) != NULL) {
1056 /* Have the server record that a decision no longer is wanted. */
1057 dsend_packet_unit_sscs_set(&client.conn, old_actor_id, old_actor_id,
1058 USSDT_UNQUEUE, IDENTITY_NUMBER_ZERO);
1059 }
1060}
1061
1062/**********************************************************************/
1065 void action_selection_next_in_focus(const int old_actor_id)
1066{
1067 struct unit *old;
1068
1069 old = game_unit_by_number(old_actor_id);
1070
1071 /* Go to the next unit in focus that needs a decision. */
1072 unit_list_iterate(get_units_in_focus(), funit) {
1073 if (old != funit && should_ask_server_for_actions(funit)) {
1074 ask_server_for_actions(funit);
1075 return;
1076 }
1077 } unit_list_iterate_end;
1078}
1079
1080/**********************************************************************/
1083 void action_decision_request(struct unit *actor_unit)
1084{
1085 fc_assert_ret(actor_unit);
1086 fc_assert_ret(actor_unit->action_decision_tile);
1087
1088 if (!unit_is_in_focus(actor_unit)) {
1089 /* Getting feed back may be urgent. A unit standing next to an enemy
1090 * could be killed while waiting. */
1091 unit_focus_urgent(actor_unit);
1092 } else if (can_client_issue_orders()
1093 && can_ask_server_for_actions()) {
1094 /* No need to wait. The actor unit is in focus. No other actor unit
1095 * is currently asking about action selection. */
1096 ask_server_for_actions(actor_unit);
1097 }
1098}
1099
1100/**********************************************************************/
1103 void request_unit_goto(enum unit_orders last_order,
1104 action_id act_id, int sub_tgt_id)
1105{
1106 struct unit_list *punits = get_units_in_focus();
1107
1108 fc_assert_ret(act_id == ACTION_NONE
1109 || last_order == ORDER_PERFORM_ACTION);
1110
1111 if (unit_list_size(punits) == 0) {
1112 return;
1113 }
1114
1115 if (last_order == ORDER_PERFORM_ACTION) {
1116 /* An action has been specified. */
1117 fc_assert_ret(action_id_exists(act_id));
1118
1119 unit_list_iterate(punits, punit) {
1120 if (!unit_can_do_action(punit, act_id)) {
1121 /* This unit can't perform the action specified in the last
1122 * order. */
1123
1124 struct astring astr = ASTRING_INIT;
1125
1126 if (role_units_translations(&astr,
1127 action_id_get_role(act_id),
1128 TRUE)) {
1129 /* ...but other units can perform it. */
1130
1131 create_event(unit_tile(punit), E_BAD_COMMAND, ftc_client,
1132 /* TRANS: Only Nuclear or ICBM can do Explode
1133 * Nuclear. */
1134 _("Only %s can do %s."),
1135 astr_str(&astr),
1136 action_id_name_translation(act_id));
1137
1138 astr_free(&astr);
1139 } else {
1140 create_event(unit_tile(punit), E_BAD_COMMAND, ftc_client,
1141 /* TRANS: Spy can't do Explode Nuclear. */
1142 _("%s can't do %s."),
1143 unit_name_translation(punit),
1144 action_id_name_translation(act_id));
1145 }
1146
1147 return;
1148 }
1149 } unit_list_iterate_end;
1150 }
1151
1152 if (hover_state != HOVER_GOTO && hover_state != HOVER_GOTO_SEL_TGT) {
1153 set_hover_state(punits, HOVER_GOTO, ACTIVITY_LAST, NULL,
1154 NO_TARGET, sub_tgt_id, act_id, last_order);
1155 enter_goto_state(punits);
1156 create_line_at_mouse_pos();
1157 update_unit_info_label(punits);
1158 control_mouse_cursor(NULL);
1159 } else {
1160 fc_assert_ret(goto_is_active());
1161 /* Adding a long range action in the middle isn't handled yet */
1162 fc_assert_ret(hover_state != HOVER_GOTO_SEL_TGT);
1163 goto_add_waypoint();
1164 }
1165}
1166
1167/**********************************************************************/
1170 static bool can_units_attack_at(struct unit_list *punits,
1171 const struct tile *ptile)
1172{
1173 unit_list_iterate(punits, punit) {
1174 if (is_attack_unit(punit)
1175 && can_unit_attack_tile(punit, NULL, ptile)) {
1176 return TRUE;
1177 }
1178 } unit_list_iterate_end;
1179
1180 return FALSE;
1181}
1182
1183/**********************************************************************/
1188 void control_mouse_cursor(struct tile *ptile)
1189{
1190 struct unit *punit = NULL;
1191 struct city *pcity = NULL;
1192 struct unit_list *active_units = get_units_in_focus();
1193 enum cursor_type mouse_cursor_type = CURSOR_DEFAULT;
1194
1195 if (!gui_options.enable_cursor_changes) {
1196 return;
1197 }
1198
1199 if (C_S_RUNNING != client_state()) {
1200 update_mouse_cursor(CURSOR_DEFAULT);
1201 return;
1202 }
1203
1204 if (is_server_busy()) {
1205 /* Server will not accept any commands. */
1206 update_mouse_cursor(CURSOR_WAIT);
1207 return;
1208 }
1209
1210 if (!ptile) {
1211 if (hover_tile) {
1212 /* hover_tile is the tile that was previously under the mouse cursor. */
1213 ptile = hover_tile;
1214 } else {
1215 update_mouse_cursor(CURSOR_DEFAULT);
1216 return;
1217 }
1218 } else {
1219 hover_tile = ptile;
1220 }
1221
1222 punit = find_visible_unit(ptile);
1223 pcity = ptile ? tile_city(ptile) : NULL;
1224
1225 switch (hover_state) {
1226 case HOVER_NONE:
1227 if (NULL != punit
1228 && unit_owner(punit) == client_player()) {
1229 /* Set mouse cursor to select a unit. */
1230 mouse_cursor_type = CURSOR_SELECT;
1231 } else if (NULL != pcity
1232 && can_player_see_city_internals(client.conn.playing, pcity)) {
1233 /* Set mouse cursor to select a city. */
1234 mouse_cursor_type = CURSOR_SELECT;
1235 } else {
1236 /* Set default mouse cursor, because nothing selectable found. */
1237 }
1238 break;
1239 case HOVER_GOTO:
1240 /* Determine if the goto is valid, invalid, nuke or will attack. */
1241 if (is_valid_goto_destination(ptile)) {
1242 if (action_id_has_result_safe(goto_last_action, ACTRES_NUKE_UNITS)
1243 || action_id_has_result_safe(goto_last_action, ACTRES_NUKE)) {
1244 /* Goto results in nuclear attack. */
1245 mouse_cursor_type = CURSOR_NUKE;
1246 } else if (can_units_attack_at(active_units, ptile)) {
1247 /* Goto results in military attack. */
1248 mouse_cursor_type = CURSOR_ATTACK;
1249 } else if (is_enemy_city_tile(ptile, client.conn.playing)) {
1250 /* Goto results in attack of enemy city. */
1251 mouse_cursor_type = CURSOR_ATTACK;
1252 } else {
1253 mouse_cursor_type = CURSOR_GOTO;
1254 }
1255 } else {
1256 mouse_cursor_type = CURSOR_INVALID;
1257 }
1258 break;
1259 case HOVER_PATROL:
1260 if (is_valid_goto_destination(ptile)) {
1261 mouse_cursor_type = CURSOR_PATROL;
1262 } else {
1263 mouse_cursor_type = CURSOR_INVALID;
1264 }
1265 break;
1266 case HOVER_CONNECT:
1267 if (is_valid_goto_destination(ptile)) {
1268 mouse_cursor_type = CURSOR_GOTO;
1269 } else {
1270 mouse_cursor_type = CURSOR_INVALID;
1271 }
1272 break;
1273 case HOVER_PARADROP:
1274 /* FIXME: check for invalid tiles. */
1275 mouse_cursor_type = CURSOR_PARADROP;
1276 break;
1277 case HOVER_ACT_SEL_TGT:
1278 case HOVER_GOTO_SEL_TGT:
1279 /* Select a tile to target / find targets on. */
1280 mouse_cursor_type = CURSOR_SELECT;
1281 break;
1282 };
1283
1284 update_mouse_cursor(mouse_cursor_type);
1285}
1286
1287/**********************************************************************/
1290 static bool is_activity_on_tile(struct tile *ptile,
1291 enum unit_activity activity)
1292{
1293 unit_list_iterate(ptile->units, punit) {
1294 if (punit->activity == activity) {
1295 return TRUE;
1296 }
1297 } unit_list_iterate_end;
1298
1299 return FALSE;
1300}
1301
1302/**********************************************************************/
1306 int check_recursive_road_connect(struct tile *ptile,
1307 const struct extra_type *pextra,
1308 const struct unit *punit,
1309 const struct player *pplayer, int rec)
1310{
1311 int activity_mc = 0;
1312 struct terrain *pterrain = tile_terrain(ptile);
1313 const struct civ_map *nmap = &(wld.map);
1314
1315 if (rec > MAX_EXTRA_TYPES) {
1316 return -1;
1317 }
1318
1319 if (!is_extra_caused_by(pextra, EC_ROAD)) {
1320 return -1;
1321 }
1322
1323 extra_deps_iterate(&(pextra->reqs), pdep) {
1324 if (!tile_has_extra(ptile, pdep)) {
1325 int single_mc;
1326
1327 single_mc = check_recursive_road_connect(ptile, pdep, punit,
1328 pplayer, rec + 1);
1329
1330 if (single_mc < 0) {
1331 return -1;
1332 }
1333
1334 activity_mc += single_mc;
1335 }
1336 } extra_deps_iterate_end;
1337
1338 /* Can build road after that? */
1339 if (punit != NULL) {
1340 if (!can_build_road(nmap, extra_road_get(pextra), punit, ptile)) {
1341 return -1;
1342 }
1343 } else if (pplayer != NULL) {
1344 if (!player_can_build_road(nmap, extra_road_get(pextra),
1345 pplayer, ptile)) {
1346 return -1;
1347 }
1348 }
1349
1350 tile_add_extra(ptile, pextra);
1351
1352 activity_mc += terrain_extra_build_time(pterrain, ACTIVITY_GEN_ROAD, pextra);
1353
1354 return activity_mc;
1355}
1356
1357/*******************************************************************/
1361 static bool can_be_irrigated(const struct tile *ptile,
1362 const struct unit *punit)
1363{
1364 struct terrain* pterrain = tile_terrain(ptile);
1365 struct universal for_unit = { .kind = VUT_UTYPE,
1366 .value.utype = unit_type_get(punit)};
1367 struct universal for_tile = { .kind = VUT_TERRAIN,
1368 .value.terrain = tile_terrain(ptile)};
1369
1370 if (T_UNKNOWN == pterrain) {
1371 return FALSE;
1372 }
1373
1374 return action_id_univs_not_blocking(ACTION_IRRIGATE,
1375 &for_unit, &for_tile);
1376}
1377
1378/**********************************************************************/
1384 bool can_unit_do_connect(struct unit *punit,
1385 enum unit_activity activity,
1386 struct extra_type *tgt)
1387{
1388 struct tile *ptile = unit_tile(punit);
1389 struct road_type *proad = NULL;
1390 const struct req_context unit_ctxt = {
1391 .unit = punit,
1392 .unittype = unit_type_get(punit),
1393 };
1394
1395 /* HACK: This code duplicates that in
1396 * can_unit_do_activity_targeted_at(). The general logic here is that
1397 * the connect is allowed if both:
1398 * (1) the unit can do that activity type, in general
1399 * (2) either
1400 * (a) the activity has already been completed at this tile
1401 * (b) it can be done by the unit at this tile. */
1402 switch (activity) {
1403 case ACTIVITY_GEN_ROAD:
1404 {
1405 struct tile *vtile;
1406 int build_time;
1407
1408 fc_assert(is_extra_caused_by(tgt, EC_ROAD));
1409
1410 proad = extra_road_get(tgt);
1411
1412 if (tile_has_road(ptile, proad)) {
1413 /* This tile has road, can unit build road to other tiles too? */
1414 return are_reqs_active(&unit_ctxt, NULL, &tgt->reqs, RPT_POSSIBLE);
1415 }
1416
1417 /* To start connect, unit must be able to build road to this
1418 * particular tile. */
1419 vtile = tile_virtual_new(ptile);
1420 build_time = check_recursive_road_connect(vtile, tgt, punit, NULL, 0);
1421 tile_virtual_destroy(vtile);
1422
1423 return build_time >= 0;
1424 }
1425
1426 case ACTIVITY_IRRIGATE:
1427 /* Special case for irrigation: only irrigate to make S_IRRIGATION,
1428 * never to transform tiles. */
1429 if (!unit_has_type_flag(punit, UTYF_SETTLERS)) {
1430 return FALSE;
1431 }
1432 if (tile_has_extra(ptile, tgt)) {
1433 return are_reqs_active(&unit_ctxt, NULL, &tgt->reqs, RPT_POSSIBLE);
1434 }
1435
1436 return can_be_irrigated(ptile, punit)
1437 && can_build_extra(tgt, punit, ptile)
1438 && !is_activity_on_tile(ptile,
1439 ACTIVITY_MINE);
1440 default:
1441 break;
1442 }
1443
1444 return FALSE;
1445}
1446
1447/**********************************************************************/
1451 void request_unit_connect(enum unit_activity activity,
1452 struct extra_type *tgt)
1453{
1454 struct unit_list *punits = get_units_in_focus();
1455
1456 if (!can_units_do_connect(punits, activity, tgt)) {
1457 return;
1458 }
1459
1460 if (hover_state != HOVER_CONNECT || connect_activity != activity
1461 || (connect_tgt != tgt
1462 && (activity == ACTIVITY_GEN_ROAD
1463 || activity == ACTIVITY_IRRIGATE))) {
1464 set_hover_state(punits, HOVER_CONNECT,
1465 activity, tgt, NO_TARGET, NO_TARGET,
1466 ACTION_NONE, ORDER_LAST);
1467 enter_goto_state(punits);
1468 create_line_at_mouse_pos();
1469 update_unit_info_label(punits);
1470 control_mouse_cursor(NULL);
1471 } else {
1472 fc_assert_ret(goto_is_active());
1473 goto_add_waypoint();
1474 }
1475}
1476
1477/**********************************************************************/
1480 struct unit *request_unit_unload_all(struct unit *punit)
1481{
1482 struct tile *ptile = unit_tile(punit);
1483 struct unit *plast = NULL;
1484
1485 if (get_transporter_capacity(punit) == 0) {
1486 create_event(unit_tile(punit), E_BAD_COMMAND, ftc_client,
1487 _("Only transporter units can be unloaded."));
1488 return NULL;
1489 }
1490
1491 unit_list_iterate(ptile->units, pcargo) {
1492 if (unit_transport_get(pcargo) == punit) {
1493 request_unit_unload(pcargo);
1494
1495 if (pcargo->activity == ACTIVITY_SENTRY) {
1496 dsend_packet_unit_sscs_set(&client.conn, pcargo->id, pcargo->id,
1497 USSDT_SENTRY, 0);
1498 }
1499
1500 if (unit_owner(pcargo) == unit_owner(punit)) {
1501 plast = pcargo;
1502 }
1503 }
1504 } unit_list_iterate_end;
1505
1506 return plast;
1507}
1508
1509/**********************************************************************/
1512 void request_unit_airlift(struct unit *punit, struct city *pcity)
1513{
1514 request_do_action(ACTION_AIRLIFT, punit->id, pcity->id, 0, "");
1515}
1516
1517/**********************************************************************/
1521 void request_unit_return(struct unit *punit)
1522{
1523 struct pf_path *path;
1524
1525 if ((path = path_to_nearest_allied_city(punit))) {
1526 int turns = pf_path_last_position(path)->turn;
1527 int max_hp = unit_type_get(punit)->hp;
1528
1529 if (punit->hp + turns *
1530 (get_unit_bonus(punit, EFT_UNIT_RECOVER)
1531 - (max_hp * unit_class_get(punit)->hp_loss_pct / 100))
1532 < max_hp) {
1533 struct unit_order order;
1534
1535 order.order = ORDER_ACTIVITY;
1536 order.dir = DIR8_ORIGIN;
1537 order.activity = ACTIVITY_SENTRY;
1538 order.target = NO_TARGET;
1539 order.sub_target = NO_TARGET;
1540 order.action = ACTION_NONE;
1541 send_goto_path(punit, path, &order);
1542 } else {
1543 send_goto_path(punit, path, NULL);
1544 }
1545 pf_path_destroy(path);
1546 }
1547}
1548
1549/**********************************************************************/
1552 void wakeup_sentried_units(struct tile *ptile)
1553{
1554 if (!can_client_issue_orders()) {
1555 return;
1556 }
1557 unit_list_iterate(ptile->units, punit) {
1558 if (punit->activity == ACTIVITY_SENTRY
1559 && unit_owner(punit) == client.conn.playing) {
1560 request_new_unit_activity(punit, ACTIVITY_IDLE);
1561 }
1562 }
1563 unit_list_iterate_end;
1564}
1565
1566/**********************************************************************/
1569 void request_unit_wakeup(struct unit *punit)
1570{
1571 wakeup_sentried_units(unit_tile(punit));
1572}
1573
1574/**************************************************************************
1575 Defines specific hash tables needed for request_unit_select().
1576**************************************************************************/
1577#define SPECHASH_TAG unit_type
1578#define SPECHASH_IKEY_TYPE struct unit_type *
1579#define SPECHASH_IDATA_TYPE void *
1580#include "spechash.h"
1581
1582#define SPECHASH_TAG continent
1583#define SPECHASH_INT_KEY_TYPE
1584#define SPECHASH_IDATA_TYPE void *
1585#include "spechash.h"
1586
1587/**********************************************************************/
1590 void request_unit_select(struct unit_list *punits,
1591 enum unit_select_type_mode seltype,
1592 enum unit_select_location_mode selloc)
1593{
1594 const struct player *pplayer;
1595 const struct tile *ptile;
1596 struct unit *punit_first;
1597 struct tile_hash *tile_table;
1598 struct unit_type_hash *type_table;
1599 struct continent_hash *cont_table;
1600
1601 if (!can_client_change_view() || !punits
1602 || unit_list_size(punits) < 1) {
1603 return;
1604 }
1605
1606 punit_first = unit_list_get(punits, 0);
1607
1608 if (seltype == SELTYPE_SINGLE) {
1609 unit_focus_set(punit_first);
1610 return;
1611 }
1612
1613 pplayer = unit_owner(punit_first);
1614 tile_table = tile_hash_new();
1615 type_table = unit_type_hash_new();
1616 cont_table = continent_hash_new();
1617
1618 unit_list_iterate(punits, punit) {
1619 if (seltype == SELTYPE_SAME) {
1620 unit_type_hash_insert(type_table, unit_type_get(punit), NULL);
1621 }
1622
1623 ptile = unit_tile(punit);
1624 if (selloc == SELLOC_TILE) {
1625 tile_hash_insert(tile_table, ptile, NULL);
1626 } else if (selloc == SELLOC_CONT) {
1627 continent_hash_insert(cont_table, tile_continent(ptile), NULL);
1628 }
1629 } unit_list_iterate_end;
1630
1631 if (selloc == SELLOC_TILE) {
1632 tile_hash_iterate(tile_table, hash_tile) {
1633 unit_list_iterate(hash_tile->units, punit) {
1634 if (unit_owner(punit) != pplayer) {
1635 continue;
1636 }
1637 if (seltype == SELTYPE_SAME
1638 && !unit_type_hash_lookup(type_table, unit_type_get(punit), NULL)) {
1639 continue;
1640 }
1641 unit_focus_add(punit);
1642 } unit_list_iterate_end;
1643 } tile_hash_iterate_end;
1644 } else {
1645 unit_list_iterate(pplayer->units, punit) {
1646 ptile = unit_tile(punit);
1647 if ((seltype == SELTYPE_SAME
1648 && !unit_type_hash_lookup(type_table, unit_type_get(punit), NULL))
1649 || (selloc == SELLOC_CONT
1650 && !continent_hash_lookup(cont_table, tile_continent(ptile),
1651 NULL))) {
1652 continue;
1653 }
1654
1655 unit_focus_add(punit);
1656 } unit_list_iterate_end;
1657 }
1658
1659 tile_hash_destroy(tile_table);
1660 unit_type_hash_destroy(type_table);
1661 continent_hash_destroy(cont_table);
1662}
1663
1664/**********************************************************************/
1675 void request_do_action(action_id action, int actor_id,
1676 int target_id, int sub_tgt, const char *name)
1677{
1678 struct unit *actor_unit = game_unit_by_number(actor_id);
1679
1680 /* Giving an order takes back control. */
1681 request_unit_ssa_set(actor_unit, SSA_NONE);
1682
1683 dsend_packet_unit_do_action(&client.conn,
1684 actor_id, actor_id, target_id, sub_tgt, name,
1685 action);
1686}
1687
1688/**********************************************************************/
1695 void request_action_details(action_id action, int actor_id,
1696 int target_id)
1697{
1698 dsend_packet_unit_action_query(&client.conn,
1699 actor_id, actor_id, target_id, action,
1700 /* Users that need the answer in the
1701 * background should send the packet them
1702 * self. At least for now. */
1703 REQEST_PLAYER_INITIATED);
1704}
1705
1706/**********************************************************************/
1714 void request_unit_build_city(struct unit *punit)
1715{
1716 struct city *pcity;
1717
1718 if ((pcity = tile_city(unit_tile(punit)))) {
1719 /* Try to join the city. */
1720 request_do_action(ACTION_JOIN_CITY, punit->id, pcity->id, 0, "");
1721 } else {
1722 /* The reply will trigger a dialog to name the new city. */
1723 dsend_packet_city_name_suggestion_req(&client.conn, punit->id, punit->id);
1724 }
1725}
1726
1727/**********************************************************************/
1733 void request_unit_non_action_move(struct unit *punit,
1734 struct tile *dest_tile)
1735{
1736 struct packet_unit_orders p;
1737 int dir;
1738
1739 dir = get_direction_for_step(&(wld.map), unit_tile(punit), dest_tile);
1740
1741 if (dir == -1) {
1742 /* The unit isn't located next to the destination tile. */
1743 return;
1744 }
1745
1746 memset(&p, 0, sizeof(p));
1747
1748 p.repeat = FALSE;
1749 p.vigilant = FALSE;
1750
1751 p.unit_id32 = punit->id;
1752 p.unit_id16 = p.unit_id32;
1753 p.src_tile = tile_index(unit_tile(punit));
1754 p.dest_tile = tile_index(dest_tile);
1755
1756 p.length = 1;
1757 p.orders[0].order = ORDER_MOVE;
1758 p.orders[0].dir = dir;
1759 p.orders[0].activity = ACTIVITY_LAST;
1760 p.orders[0].target = NO_TARGET;
1761 p.orders[0].sub_target = NO_TARGET;
1762 p.orders[0].action = ACTION_NONE;
1763
1764 request_unit_ssa_set(punit, SSA_NONE);
1765 send_packet_unit_orders(&client.conn, &p);
1766}
1767
1768/**********************************************************************/
1777 void request_move_unit_direction(struct unit *punit, int dir)
1778{
1779 struct packet_unit_orders p;
1780 struct tile *dest_tile;
1781
1782 /* Catches attempts to move off map */
1783 dest_tile = mapstep(&(wld.map), unit_tile(punit), dir);
1784 if (!dest_tile) {
1785 return;
1786 }
1787
1788 if (!can_unit_exist_at_tile(&(wld.map), punit, dest_tile)) {
1789 if (request_transport(punit, dest_tile)) {
1790 return;
1791 }
1792 }
1793
1794 /* The goto system isn't used to send the order because that would
1795 * prevent direction movement from overriding it.
1796 * Example of a situation when overriding the goto system is useful:
1797 * The goto system creates a longer path to make a move legal. The player
1798 * wishes to order the illegal move so the server will explain why the
1799 * short move is illegal. */
1800
1801 memset(&p, 0, sizeof(p));
1802
1803 p.repeat = FALSE;
1804 p.vigilant = FALSE;
1805
1806 p.unit_id32 = punit->id;
1807 p.unit_id16 = p.unit_id32;
1808 p.src_tile = tile_index(unit_tile(punit));
1809 p.dest_tile = tile_index(dest_tile);
1810
1811 p.length = 1;
1812 p.orders[0].order = (gui_options.popup_last_move_to_allied
1813 ? ORDER_ACTION_MOVE : ORDER_MOVE);
1814 p.orders[0].dir = dir;
1815 p.orders[0].activity = ACTIVITY_LAST;
1816 p.orders[0].target = NO_TARGET;
1817 p.orders[0].sub_target = NO_TARGET;
1818 p.orders[0].action = ACTION_NONE;
1819
1820 request_unit_ssa_set(punit, SSA_NONE);
1821 send_packet_unit_orders(&client.conn, &p);
1822}
1823
1824/**********************************************************************/
1828 void request_new_unit_activity(struct unit *punit, enum unit_activity act)
1829{
1830 request_new_unit_activity_targeted(punit, act, NULL);
1831}
1832
1833/**********************************************************************/
1837 void request_new_unit_activity_targeted(struct unit *punit,
1838 enum unit_activity act,
1839 struct extra_type *tgt)
1840{
1841 if (!can_client_issue_orders()) {
1842 return;
1843 }
1844
1845 /* Callers rely on this to take back control from server side agents. */
1846 request_unit_ssa_set(punit, SSA_NONE);
1847
1848 if (tgt == NULL) {
1849 dsend_packet_unit_change_activity(&client.conn, punit->id, punit->id,
1850 act, EXTRA_NONE);
1851 } else {
1852 dsend_packet_unit_change_activity(&client.conn, punit->id, punit->id,
1853 act, extra_index(tgt));
1854 }
1855}
1856
1857/**********************************************************************/
1860 static void client_disband_unit_data_destroy(void *p)
1861{
1862 struct client_disband_unit_data *data = p;
1863
1864 free(data);
1865}
1866
1867/**********************************************************************/
1870 static void do_disband_alternative(void *p)
1871{
1872 struct unit *punit;
1873 struct city *pcity;
1874 struct tile *ptile;
1875 int last_request_id_used;
1876 struct client_disband_unit_data *next;
1877 struct client_disband_unit_data *data = p;
1878 int act;
1879
1880 fc_assert_ret(can_client_issue_orders());
1881
1882 /* Fetch the unit to get rid of. */
1883 punit = player_unit_by_number(client_player(), data->unit_id);
1884
1885 if (punit == NULL) {
1886 /* Success! It is gone. */
1887 return;
1888 }
1889
1890 if (data->alt == -1) {
1891 /* All alternatives have been tried. */
1892 create_event(unit_tile(punit), E_BAD_COMMAND, ftc_client,
1893 /* TRANS: Unable to get rid of Leader. */
1894 _("Unable to get rid of %s."),
1895 unit_name_translation(punit));
1896 return;
1897 }
1898
1899 act = disband_unit_alternatives[data->alt];
1900
1901 /* Prepare the data for the next try in case this try fails. */
1902 next = fc_malloc(sizeof(struct client_disband_unit_data));
1903 next->unit_id = data->unit_id;
1904 next->alt = data->alt - 1;
1905
1906 /* Latest request ID before trying to send a request. */
1907 last_request_id_used = client.conn.client.last_request_id_used;
1908
1909 /* Send a request to the server unless it is known to be pointless. */
1910 switch (action_id_get_target_kind(act)) {
1911 case ATK_CITY:
1912 if ((pcity = tile_city(unit_tile(punit)))
1913 && action_prob_possible(action_prob_vs_city(punit, act, pcity))) {
1914 request_do_action(act, punit->id, pcity->id, 0, "");
1915 }
1916 break;
1917 case ATK_UNIT:
1918 if (action_prob_possible(action_prob_vs_unit(punit, act, punit))) {
1919 request_do_action(act, punit->id, punit->id, 0, "");
1920 }
1921 break;
1922 case ATK_UNITS:
1923 if ((ptile = unit_tile(punit))
1924 && action_prob_possible(action_prob_vs_units(punit, act, ptile))) {
1925 request_do_action(act, punit->id, ptile->index, 0, "");
1926 }
1927 break;
1928 case ATK_TILE:
1929 if ((ptile = unit_tile(punit))
1930 && action_prob_possible(action_prob_vs_tile(punit, act, ptile, NULL))) {
1931 request_do_action(act, punit->id, ptile->index, 0, "");
1932 }
1933 break;
1934 case ATK_EXTRAS:
1935 if ((ptile = unit_tile(punit))
1936 && action_prob_possible(action_prob_vs_extras(punit, act,
1937 ptile, NULL))) {
1938 request_do_action(act, punit->id, ptile->index, 0, "");
1939 }
1940 break;
1941 case ATK_SELF:
1942 if (action_prob_possible(action_prob_self(punit, act))) {
1943 request_do_action(act, punit->id, punit->id, 0, "");
1944 }
1945 break;
1946 case ATK_COUNT:
1947 fc_assert(action_id_get_target_kind(act) != ATK_COUNT);
1948 break;
1949 }
1950
1951 if (last_request_id_used != client.conn.client.last_request_id_used) {
1952 /* A request was sent. */
1953
1954 /* Check if it worked. Move on if it didn't. */
1955 update_queue_connect_processing_finished_full
1956 (client.conn.client.last_request_id_used,
1957 do_disband_alternative, next,
1958 client_disband_unit_data_destroy);
1959 } else {
1960 /* No request was sent. */
1961
1962 /* Move on. */
1963 do_disband_alternative(next);
1964
1965 /* Won't be freed by anyone else. */
1966 client_disband_unit_data_destroy(next);
1967 }
1968}
1969
1970/**********************************************************************/
1973 void request_unit_disband(struct unit *punit)
1974{
1975 struct client_disband_unit_data *data;
1976
1977 /* Set up disband data. Start at the end of the array. */
1978 data = fc_malloc(sizeof(struct client_disband_unit_data));
1979 data->unit_id = punit->id;
1980 data->alt = 2;
1981
1982 /* Begin. */
1983 do_disband_alternative(data);
1984
1985 /* Won't be freed by anyone else. */
1986 client_disband_unit_data_destroy(data);
1987}
1988
1989/**********************************************************************/
1992 void request_unit_change_homecity(struct unit *punit)
1993{
1994 struct city *pcity=tile_city(unit_tile(punit));
1995
1996 if (pcity) {
1997 request_do_action(ACTION_HOME_CITY, punit->id, pcity->id, 0, "");
1998 }
1999}
2000
2001/**********************************************************************/
2004 void request_unit_upgrade(struct unit *punit)
2005{
2006 struct city *pcity=tile_city(unit_tile(punit));
2007
2008 if (pcity) {
2009 request_do_action(ACTION_UPGRADE_UNIT, punit->id, pcity->id, 0, "");
2010 }
2011}
2012
2013/**********************************************************************/
2016 void request_unit_convert(struct unit *punit)
2017{
2018 request_new_unit_activity(punit, ACTIVITY_CONVERT);
2019}
2020
2021/**********************************************************************/
2026 void request_unit_ssa_set(const struct unit *punit,
2027 enum server_side_agent agent)
2028{
2029 if (punit) {
2030 dsend_packet_unit_server_side_agent_set(&client.conn, punit->id, punit->id,
2031 agent);
2032 }
2033}
2034
2035/**********************************************************************/
2039 void request_unit_autosettlers(const struct unit *punit)
2040{
2041 if (punit && can_unit_do_autosettlers(punit)) {
2042 request_unit_ssa_set(punit, SSA_AUTOSETTLER);
2043 } else if (punit) {
2044 create_event(unit_tile(punit), E_BAD_COMMAND, ftc_client,
2045 _("Only settler units can be put into auto mode."));
2046 }
2047}
2048
2049/**********************************************************************/
2054 void request_unit_load(struct unit *pcargo, struct unit *ptrans,
2055 struct tile *ptile)
2056{
2057 if (!ptrans) {
2058 ptrans = transporter_for_unit(pcargo);
2059 }
2060
2061 if (ptrans
2062 && can_client_issue_orders()
2063 && could_unit_load(pcargo, ptrans)) {
2064 action_by_result_iterate(paction,
2065 same_pos(unit_tile(pcargo), ptile)
2066 ? ACTRES_TRANSPORT_BOARD
2067 : ACTRES_TRANSPORT_EMBARK) {
2068 if (action_prob_possible(action_prob_vs_unit(pcargo, paction->id,
2069 ptrans))) {
2070 /* Try the first action that may be legal. */
2071 /* Implement something like do_disband_alternative() if a ruleset
2072 * appears where this isn't good enough. */
2073 request_do_action(paction->id, pcargo->id, ptrans->id, 0, "");
2074 break;
2075 }
2076 } action_by_result_iterate_end;
2077
2078 /* Sentry the unit. */
2079 /* FIXME: Should not sentry if above loading fails (transport moved away,
2080 * or filled already in server side) */
2081 dsend_packet_unit_sscs_set(&client.conn, pcargo->id, pcargo->id,
2082 USSDT_SENTRY, 1);
2083 }
2084}
2085
2086/**********************************************************************/
2090 void request_unit_unload(struct unit *pcargo)
2091{
2092 struct unit *ptrans = unit_transport_get(pcargo);
2093
2094 if (can_client_issue_orders()
2095 && ptrans
2096 && can_unit_unload(pcargo, ptrans)
2097 && can_unit_survive_at_tile(&(wld.map), pcargo, unit_tile(pcargo))) {
2098 if (unit_owner(pcargo) == client.conn.playing) {
2099 request_do_action(ACTION_TRANSPORT_ALIGHT,
2100 pcargo->id, ptrans->id, 0, "");
2101 } else {
2102 request_do_action(ACTION_TRANSPORT_UNLOAD,
2103 ptrans->id, pcargo->id, 0, "");
2104 }
2105
2106 if (unit_owner(pcargo) == client.conn.playing
2107 && pcargo->activity == ACTIVITY_SENTRY) {
2108 /* Activate the unit. */
2109 dsend_packet_unit_sscs_set(&client.conn, pcargo->id, pcargo->id,
2110 USSDT_SENTRY, 0);
2111 }
2112 }
2113}
2114
2115/**********************************************************************/
2119 void request_unit_caravan_action(struct unit *punit, action_id action)
2120{
2121 struct city *target_city;
2122
2123 if (!((target_city = tile_city(unit_tile(punit))))) {
2124 return;
2125 }
2126
2127 if (action == ACTION_TRADE_ROUTE) {
2128 request_do_action(ACTION_TRADE_ROUTE, punit->id,
2129 target_city->id, 0, "");
2130 } else if (action == ACTION_HELP_WONDER) {
2131 request_do_action(ACTION_HELP_WONDER, punit->id,
2132 target_city->id, 0, "");
2133 } else {
2134 log_error("request_unit_caravan_action() Bad action (%d)", action);
2135 }
2136}
2137
2138/**********************************************************************/
2142 void request_unit_paradrop(struct unit_list *punits)
2143{
2144 bool can = FALSE;
2145 struct tile *offender = NULL;
2146
2147 if (unit_list_size(punits) == 0) {
2148 return;
2149 }
2150 unit_list_iterate(punits, punit) {
2151 if (can_unit_paradrop(&(wld.map), punit)) {
2152 can = TRUE;
2153 break;
2154 }
2155 if (!offender) { /* Take first offender tile/unit */
2156 offender = unit_tile(punit);
2157 }
2158 } unit_list_iterate_end;
2159 if (can) {
2160 create_event(unit_tile(unit_list_get(punits, 0)), E_BEGINNER_HELP,
2161 ftc_client,
2162 /* TRANS: paradrop target tile. */
2163 _("Click on a tile to paradrop to it."));
2164
2165 set_hover_state(punits, HOVER_PARADROP, ACTIVITY_LAST, NULL,
2166 NO_TARGET, NO_TARGET, ACTION_NONE, ORDER_LAST);
2167 update_unit_info_label(punits);
2168 } else {
2169 create_event(offender, E_BAD_COMMAND, ftc_client,
2170 _("Only paratrooper units can do this."));
2171 }
2172}
2173
2174/**********************************************************************/
2177 void request_unit_patrol(void)
2178{
2179 struct unit_list *punits = get_units_in_focus();
2180
2181 if (unit_list_size(punits) == 0) {
2182 return;
2183 }
2184
2185 if (hover_state != HOVER_PATROL) {
2186 set_hover_state(punits, HOVER_PATROL, ACTIVITY_LAST, NULL,
2187 NO_TARGET, NO_TARGET, ACTION_NONE, ORDER_LAST);
2188 update_unit_info_label(punits);
2189 enter_goto_state(punits);
2190 create_line_at_mouse_pos();
2191 } else {
2192 fc_assert_ret(goto_is_active());
2193 goto_add_waypoint();
2194 }
2195}
2196
2197/**********************************************************************/
2200 void request_unit_sentry(struct unit *punit)
2201{
2202 if (punit->activity != ACTIVITY_SENTRY
2203 && can_unit_do_activity_client(punit, ACTIVITY_SENTRY)) {
2204 request_new_unit_activity(punit, ACTIVITY_SENTRY);
2205 }
2206}
2207
2208/**********************************************************************/
2211 void request_unit_fortify(struct unit *punit)
2212{
2213 if (punit->activity != ACTIVITY_FORTIFYING
2214 && can_unit_do_activity_client(punit, ACTIVITY_FORTIFYING)) {
2215 request_new_unit_activity(punit, ACTIVITY_FORTIFYING);
2216 }
2217}
2218
2219/**********************************************************************/
2222 void request_unit_pillage(struct unit *punit)
2223{
2224 if (!game.info.pillage_select) {
2225 /* Leave choice up to the server */
2226 request_new_unit_activity_targeted(punit, ACTIVITY_PILLAGE, NULL);
2227 } else {
2228 bv_extras pspossible;
2229 int count = 0;
2230
2231 BV_CLR_ALL(pspossible);
2232 extra_type_iterate(potential) {
2233 if (can_unit_do_activity_targeted_client(punit, ACTIVITY_PILLAGE,
2234 potential)) {
2235 BV_SET(pspossible, extra_index(potential));
2236 count++;
2237 }
2238 } extra_type_iterate_end;
2239
2240 if (count > 1) {
2241 popup_pillage_dialog(punit, pspossible);
2242 } else {
2243 /* Should be only one choice... */
2244 struct extra_type *target = get_preferred_pillage(pspossible);
2245
2246 if (target != NULL) {
2247 request_new_unit_activity_targeted(punit, ACTIVITY_PILLAGE, target);
2248 }
2249 }
2250 }
2251}
2252
2253/**********************************************************************/
2256 void request_toggle_city_outlines(void)
2257{
2258 if (!can_client_change_view()) {
2259 return;
2260 }
2261
2262 gui_options.draw_city_outlines = !gui_options.draw_city_outlines;
2263 update_map_canvas_visible();
2264}
2265
2266/**********************************************************************/
2269 void request_toggle_city_output(void)
2270{
2271 if (!can_client_change_view()) {
2272 return;
2273 }
2274
2275 gui_options.draw_city_output = !gui_options.draw_city_output;
2276 update_map_canvas_visible();
2277}
2278
2279/**********************************************************************/
2282 void request_toggle_map_grid(void)
2283{
2284 if (!can_client_change_view()) {
2285 return;
2286 }
2287
2288 gui_options.draw_map_grid ^= 1;
2289 update_map_canvas_visible();
2290}
2291
2292/**********************************************************************/
2295 void request_toggle_map_borders(void)
2296{
2297 if (!can_client_change_view()) {
2298 return;
2299 }
2300
2301 gui_options.draw_borders ^= 1;
2302 update_map_canvas_visible();
2303}
2304
2305/**********************************************************************/
2308 void request_toggle_map_native(void)
2309{
2310 if (!can_client_change_view()) {
2311 return;
2312 }
2313
2314 gui_options.draw_native ^= 1;
2315 update_map_canvas_visible();
2316}
2317
2318/**********************************************************************/
2321 void request_toggle_city_full_bar(void)
2322{
2323 if (!can_client_change_view()) {
2324 return;
2325 }
2326
2327 gui_options.draw_full_citybar ^= 1;
2328 update_map_canvas_visible();
2329}
2330
2331/**********************************************************************/
2334 void request_toggle_city_names(void)
2335{
2336 if (!can_client_change_view()) {
2337 return;
2338 }
2339
2340 gui_options.draw_city_names ^= 1;
2341 update_map_canvas_visible();
2342}
2343
2344/**********************************************************************/
2347 void request_toggle_city_growth(void)
2348{
2349 if (!can_client_change_view()) {
2350 return;
2351 }
2352
2353 gui_options.draw_city_growth ^= 1;
2354 update_map_canvas_visible();
2355}
2356
2357/**********************************************************************/
2360 void request_toggle_city_productions(void)
2361{
2362 if (!can_client_change_view()) {
2363 return;
2364 }
2365
2366 gui_options.draw_city_productions ^= 1;
2367 update_map_canvas_visible();
2368}
2369
2370/**********************************************************************/
2373 void request_toggle_city_buycost(void)
2374{
2375 if (!can_client_change_view()) {
2376 return;
2377 }
2378
2379 gui_options.draw_city_buycost ^= 1;
2380 update_map_canvas_visible();
2381}
2382
2383/**********************************************************************/
2386 void request_toggle_city_trade_routes(void)
2387{
2388 if (!can_client_change_view()) {
2389 return;
2390 }
2391
2392 gui_options.draw_city_trade_routes ^= 1;
2393 update_map_canvas_visible();
2394}
2395
2396/**********************************************************************/
2399 void request_toggle_unit_stack_size(void)
2400{
2401 if (!can_client_change_view()) {
2402 return;
2403 }
2404
2405 gui_options.draw_unit_stack_size ^= 1;
2406 update_map_canvas_visible();
2407}
2408
2409/**********************************************************************/
2412 void request_toggle_terrain(void)
2413{
2414 if (!can_client_change_view()) {
2415 return;
2416 }
2417
2418 gui_options.draw_terrain ^= 1;
2419 update_map_canvas_visible();
2420}
2421
2422/**********************************************************************/
2425 void request_toggle_coastline(void)
2426{
2427 if (!can_client_change_view()) {
2428 return;
2429 }
2430
2431 gui_options.draw_coastline ^= 1;
2432 update_map_canvas_visible();
2433}
2434
2435/**********************************************************************/
2438 void request_toggle_roads_rails(void)
2439{
2440 if (!can_client_change_view()) {
2441 return;
2442 }
2443
2444 gui_options.draw_roads_rails ^= 1;
2445 update_map_canvas_visible();
2446}
2447
2448/**********************************************************************/
2451 void request_toggle_irrigation(void)
2452{
2453 if (!can_client_change_view()) {
2454 return;
2455 }
2456
2457 gui_options.draw_irrigation ^= 1;
2458 update_map_canvas_visible();
2459}
2460
2461/**********************************************************************/
2464 void request_toggle_mines(void)
2465{
2466 if (!can_client_change_view()) {
2467 return;
2468 }
2469
2470 gui_options.draw_mines ^= 1;
2471 update_map_canvas_visible();
2472}
2473
2474/**********************************************************************/
2477 void request_toggle_bases(void)
2478{
2479 if (!can_client_change_view()) {
2480 return;
2481 }
2482
2483 gui_options.draw_fortress_airbase ^= 1;
2484 update_map_canvas_visible();
2485}
2486
2487/**********************************************************************/
2490 void request_toggle_resources(void)
2491{
2492 if (!can_client_change_view()) {
2493 return;
2494 }
2495
2496 gui_options.draw_specials ^= 1;
2497 update_map_canvas_visible();
2498}
2499
2500/**********************************************************************/
2503 void request_toggle_huts(void)
2504{
2505 if (!can_client_change_view()) {
2506 return;
2507 }
2508
2509 gui_options.draw_huts ^= 1;
2510 update_map_canvas_visible();
2511}
2512
2513/**********************************************************************/
2516 void request_toggle_pollution(void)
2517{
2518 if (!can_client_change_view()) {
2519 return;
2520 }
2521
2522 gui_options.draw_pollution ^= 1;
2523 update_map_canvas_visible();
2524}
2525
2526/**********************************************************************/
2529 void request_toggle_cities(void)
2530{
2531 if (!can_client_change_view()) {
2532 return;
2533 }
2534
2535 gui_options.draw_cities ^= 1;
2536 update_map_canvas_visible();
2537}
2538
2539/**********************************************************************/
2542 void request_toggle_units(void)
2543{
2544 if (!can_client_change_view()) {
2545 return;
2546 }
2547
2548 gui_options.draw_units ^= 1;
2549 update_map_canvas_visible();
2550}
2551
2552/**********************************************************************/
2555 void request_toggle_unit_solid_bg(void)
2556{
2557 if (!can_client_change_view()) {
2558 return;
2559 }
2560
2561 gui_options.solid_color_behind_units ^= 1;
2562 update_map_canvas_visible();
2563}
2564
2565/**********************************************************************/
2568 void request_toggle_unit_shields(void)
2569{
2570 if (!can_client_change_view()) {
2571 return;
2572 }
2573
2574 gui_options.draw_unit_shields ^= 1;
2575 update_map_canvas_visible();
2576}
2577
2578/**********************************************************************/
2581 void request_toggle_focus_unit(void)
2582{
2583 if (!can_client_change_view()) {
2584 return;
2585 }
2586
2587 gui_options.draw_focus_unit ^= 1;
2588 update_map_canvas_visible();
2589}
2590
2591/**********************************************************************/
2594 void request_toggle_fog_of_war(void)
2595{
2596 if (!can_client_change_view()) {
2597 return;
2598 }
2599
2600 gui_options.draw_fog_of_war ^= 1;
2601 update_map_canvas_visible();
2602 refresh_overview_canvas();
2603}
2604
2605/**********************************************************************/
2608 void request_center_focus_unit(void)
2609{
2610 struct tile *ptile = find_a_focus_unit_tile_to_center_on();
2611
2612 if (ptile) {
2613 center_tile_mapcanvas(ptile);
2614 }
2615}
2616
2617/**********************************************************************/
2621 void request_units_wait(struct unit_list *punits)
2622{
2623 unit_list_iterate(punits, punit) {
2624 punit->client.focus_status = FOCUS_WAIT;
2625 } unit_list_iterate_end;
2626 if (punits == get_units_in_focus()) {
2627 unit_focus_advance();
2628 }
2629}
2630
2631/**********************************************************************/
2634 void request_unit_move_done(void)
2635{
2636 if (get_num_units_in_focus() > 0) {
2637 enum unit_focus_status new_status = FOCUS_DONE;
2638 unit_list_iterate(get_units_in_focus(), punit) {
2639 /* If any of the focused units are busy, keep all of them
2640 * in focus; another tap of the key will dismiss them */
2641 if (punit->activity != ACTIVITY_IDLE) {
2642 new_status = FOCUS_WAIT;
2643 }
2644 } unit_list_iterate_end;
2645 unit_list_iterate(get_units_in_focus(), punit) {
2646 clear_unit_orders(punit);
2647 punit->client.focus_status = new_status;
2648 } unit_list_iterate_end;
2649 if (new_status == FOCUS_DONE) {
2650 unit_focus_advance();
2651 }
2652 }
2653}
2654
2655/**********************************************************************/
2660 void do_move_unit(struct unit *punit, struct unit *target_unit)
2661{
2662 struct tile *src_tile = unit_tile(punit);
2663 struct tile *dst_tile = unit_tile(target_unit);
2664 bool was_teleported, do_animation;
2665 bool in_focus = unit_is_in_focus(punit);
2666
2667 was_teleported = !is_tiles_adjacent(src_tile, dst_tile);
2668 do_animation = (!was_teleported && gui_options.smooth_move_unit_msec > 0);
2669
2670 if (!was_teleported
2671 && punit->activity != ACTIVITY_SENTRY
2672 && !unit_transported(punit)) {
2673 audio_play_sound(unit_type_get(punit)->sound_move,
2674 unit_type_get(punit)->sound_move_alt);
2675 }
2676
2677 if (unit_owner(punit) == client.conn.playing
2678 && gui_options.auto_center_on_unit
2679 && !unit_has_orders(punit)
2680 && punit->activity != ACTIVITY_GOTO
2681 && punit->activity != ACTIVITY_SENTRY
2682 && ((gui_options.auto_center_on_automated
2683 && punit->ssa_controller != SSA_NONE)
2684 || (punit->ssa_controller == SSA_NONE))
2685 && !tile_visible_and_not_on_border_mapcanvas(dst_tile)) {
2686 center_tile_mapcanvas(dst_tile);
2687 }
2688
2689 if (hover_state != HOVER_NONE && in_focus) {
2690 /* Cancel current goto/patrol/connect/nuke command. */
2691 clear_hover_state();
2692 update_unit_info_label(get_units_in_focus());
2693 }
2694
2695 unit_list_remove(src_tile->units, punit);
2696
2697 if (!unit_transported(punit)) {
2698 /* Mark the unit as moving unit, then find_visible_unit() won't return
2699 * it. It is especially useful to don't draw many times the unit when
2700 * refreshing the canvas. */
2701 punit_moving = punit;
2702
2703 /* We have to refresh the tile before moving. This will draw
2704 * the tile without the unit (because it was unlinked above). */
2705 refresh_unit_mapcanvas(punit, src_tile, TRUE, FALSE);
2706
2707 if (!gui_options.auto_center_on_automated
2708 && punit->ssa_controller != SSA_NONE) {
2709 /* Dont animate automatic units */
2710 } else if (do_animation) {
2711 int dx, dy;
2712
2713 /* For the duration of the animation the unit exists at neither
2714 * tile. */
2715 map_distance_vector(&dx, &dy, src_tile, dst_tile);
2716 move_unit_map_canvas(punit, src_tile, dx, dy);
2717 }
2718 }
2719
2720 unit_tile_set(punit, dst_tile);
2721 unit_list_prepend(dst_tile->units, punit);
2722
2723 if (!unit_transported(punit)) {
2724 /* For find_visible_unit(), see above. */
2725 punit_moving = NULL;
2726
2727 refresh_unit_mapcanvas(punit, dst_tile, TRUE, FALSE);
2728 }
2729
2730 /* With the "full" city bar we have to update the city bar when units move
2731 * into or out of a city. For foreign cities this is handled separately,
2732 * via the occupied field of the short-city packet. */
2733 if (NULL != tile_city(src_tile)
2734 && can_player_see_units_in_city(client.conn.playing, tile_city(src_tile))) {
2735 update_city_description(tile_city(src_tile));
2736 }
2737 if (NULL != tile_city(dst_tile)
2738 && can_player_see_units_in_city(client.conn.playing, tile_city(dst_tile))) {
2739 update_city_description(tile_city(dst_tile));
2740 }
2741
2742 if (in_focus) {
2743 menus_update();
2744 }
2745}
2746
2747/**********************************************************************/
2751 static void do_unit_act_sel_vs(struct tile *ptile)
2752{
2753 unit_list_iterate(get_units_in_focus(), punit) {
2754 if (utype_may_act_at_all(unit_type_get(punit))) {
2755 /* Have the server record that an action decision is wanted for
2756 * this unit against this tile. */
2757 dsend_packet_unit_sscs_set(&client.conn, punit->id, punit->id,
2758 USSDT_QUEUE, tile_index(ptile));
2759 }
2760 } unit_list_iterate_end;
2761}
2762
2763/**********************************************************************/
2766 void do_map_click(struct tile *ptile, enum quickselect_type qtype)
2767{
2768 struct city *pcity = tile_city(ptile);
2769 struct unit_list *punits = get_units_in_focus();
2770 bool maybe_goto = FALSE;
2771
2772 if (hover_state != HOVER_NONE) {
2773 switch (hover_state) {
2774 case HOVER_NONE:
2775 break;
2776 case HOVER_GOTO:
2777 do_unit_goto(ptile);
2778 break;
2779 case HOVER_PARADROP:
2780 unit_list_iterate(punits, punit) {
2781 do_unit_paradrop_to(punit, ptile);
2782 } unit_list_iterate_end;
2783 break;
2784 case HOVER_CONNECT:
2785 do_unit_connect(ptile, connect_activity, connect_tgt);
2786 break;
2787 case HOVER_PATROL:
2788 do_unit_patrol_to(ptile);
2789 break;
2790 case HOVER_ACT_SEL_TGT:
2791 do_unit_act_sel_vs(ptile);
2792 break;
2793 case HOVER_GOTO_SEL_TGT:
2794 fc_assert(action_id_exists(goto_last_action));
2795 do_unit_goto(ptile);
2796 break;
2797 }
2798
2799 clear_hover_state();
2800 update_unit_info_label(get_units_in_focus());
2801 } else if (qtype != SELECT_POPUP && qtype != SELECT_APPEND) {
2802 /* Bypass stack or city popup if quickselect is specified. */
2803 struct unit *qunit = quickselect(ptile, qtype);
2804
2805 if (qunit) {
2806 unit_focus_set_and_select(qunit);
2807 maybe_goto = gui_options.keyboardless_goto;
2808 }
2809 } else if (NULL != pcity
2810 && can_player_see_city_internals(client.conn.playing, pcity)) {
2811 /* Otherwise use popups. */
2812 popup_city_dialog(pcity);
2813 } else if (unit_list_size(ptile->units) == 0
2814 && NULL == pcity
2815 && get_num_units_in_focus() > 0) {
2816 maybe_goto = gui_options.keyboardless_goto;
2817 } else if (unit_list_size(ptile->units) == 1
2818 && !get_transporter_occupancy(unit_list_get(ptile->units, 0))) {
2819 struct unit *punit = unit_list_get(ptile->units, 0);
2820
2821 if (unit_owner(punit) == client.conn.playing) {
2822 if (can_unit_do_activity_client(punit, ACTIVITY_IDLE)) {
2823 maybe_goto = gui_options.keyboardless_goto;
2824 if (qtype == SELECT_APPEND) {
2825 unit_focus_add(punit);
2826 } else {
2827 unit_focus_set_and_select(punit);
2828 }
2829 }
2830 } else if (pcity) {
2831 /* Don't hide the unit in the city. */
2832 unit_select_dialog_popup(ptile);
2833 }
2834 } else if (unit_list_size(ptile->units) > 0) {
2835 /* The stack list is always popped up, even if it includes enemy units.
2836 * If the server doesn't want the player to know about them it shouldn't
2837 * tell them! The previous behavior would only pop up the stack if you
2838 * owned a unit on the tile. This gave cheating clients an advantage,
2839 * and also showed you allied units if (and only if) you had a unit on
2840 * the tile (inconsistent). */
2841 unit_select_dialog_popup(ptile);
2842 }
2843
2844 /* See mapctrl_common.c */
2845 keyboardless_goto_start_tile = maybe_goto ? ptile : NULL;
2846 keyboardless_goto_button_down = maybe_goto;
2847 keyboardless_goto_active = FALSE;
2848}
2849
2850/**********************************************************************/
2855 static struct unit *quickselect(struct tile *ptile,
2856 enum quickselect_type qtype)
2857{
2858 int listsize = unit_list_size(ptile->units);
2859 struct unit *panytransporter = NULL,
2860 *panymovesea = NULL, *panysea = NULL,
2861 *panymoveland = NULL, *panyland = NULL,
2862 *panymoveunit = NULL, *panyunit = NULL;
2863
2864 fc_assert_ret_val(qtype > SELECT_POPUP, NULL);
2865
2866 if (qtype == SELECT_FOCUS) {
2867 return head_of_units_in_focus();
2868 }
2869
2870 if (listsize == 0) {
2871 return NULL;
2872 } else if (listsize == 1) {
2873 struct unit *punit = unit_list_get(ptile->units, 0);
2874 return (unit_owner(punit) == client.conn.playing) ? punit : NULL;
2875 }
2876
2877 /* Quickselect priorities. Units with moves left
2878 * before exhausted. Focus unit is excluded.
2879 *
2880 * SEA: Transporter
2881 * Sea unit
2882 * Any unit
2883 *
2884 * LAND: Military land unit
2885 * Non-combatant
2886 * Sea unit
2887 * Any unit
2888 */
2889
2890 unit_list_iterate(ptile->units, punit) {
2891 if (unit_owner(punit) != client.conn.playing || unit_is_in_focus(punit)) {
2892 continue;
2893 }
2894 if (qtype == SELECT_SEA) {
2895 /* Transporter. */
2896 if (get_transporter_capacity(punit)) {
2897 if (punit->moves_left > 0) {
2898 return punit;
2899 } else if (!panytransporter) {
2900 panytransporter = punit;
2901 }
2902 }
2903 /* Any sea, pref. moves left. */
2904 else if (utype_move_type(unit_type_get(punit)) == UMT_SEA) {
2905 if (punit->moves_left > 0) {
2906 if (!panymovesea) {
2907 panymovesea = punit;
2908 }
2909 } else if (!panysea) {
2910 panysea = punit;
2911 }
2912 }
2913 } else if (qtype == SELECT_LAND) {
2914 if (utype_move_type(unit_type_get(punit)) == UMT_LAND) {
2915 if (punit->moves_left > 0) {
2916 if (is_military_unit(punit)) {
2917 return punit;
2918 } else if (!panymoveland) {
2919 panymoveland = punit;
2920 }
2921 } else if (!panyland) {
2922 panyland = punit;
2923 }
2924 }
2925 else if (utype_move_type(unit_type_get(punit)) == UMT_SEA) {
2926 if (punit->moves_left > 0) {
2927 panymovesea = punit;
2928 } else {
2929 panysea = punit;
2930 }
2931 }
2932 }
2933 if (punit->moves_left > 0 && !panymoveunit) {
2934 panymoveunit = punit;
2935 }
2936 if (!panyunit) {
2937 panyunit = punit;
2938 }
2939 } unit_list_iterate_end;
2940
2941 if (qtype == SELECT_SEA) {
2942 if (panytransporter) {
2943 return panytransporter;
2944 } else if (panymovesea) {
2945 return panymovesea;
2946 } else if (panysea) {
2947 return panysea;
2948 } else if (panymoveunit) {
2949 return panymoveunit;
2950 } else if (panyunit) {
2951 return panyunit;
2952 }
2953 }
2954 else if (qtype == SELECT_LAND) {
2955 if (panymoveland) {
2956 return panymoveland;
2957 } else if (panyland) {
2958 return panyland;
2959 } else if (panymovesea) {
2960 return panymovesea;
2961 } else if (panysea) {
2962 return panysea;
2963 } else if (panymoveunit) {
2964 return panymoveunit;
2965 } else if (panyunit) {
2966 return panyunit;
2967 }
2968 }
2969 return NULL;
2970}
2971
2972/**********************************************************************/
2976 void do_unit_goto(struct tile *ptile)
2977{
2978 fc_assert_ret(hover_state == HOVER_GOTO
2979 || hover_state == HOVER_GOTO_SEL_TGT);
2980 fc_assert_ret(goto_is_active());
2981
2982 if (hover_state == HOVER_GOTO_SEL_TGT) {
2983 send_goto_route();
2984 return;
2985 }
2986
2987 if (is_valid_goto_draw_line(ptile)) {
2988 send_goto_route();
2989 } else {
2990 create_event(ptile, E_BAD_COMMAND, ftc_client,
2991 _("Didn't find a route to the destination!"));
2992 }
2993}
2994
2995/**********************************************************************/
2998 void do_unit_paradrop_to(struct unit *punit, struct tile *ptile)
2999{
3000 struct action *paradrop_action = NULL;
3001
3002 action_iterate(act_id) {
3003 struct action *paction = action_by_number(act_id);
3004
3005 if (!(action_has_result(paction, ACTRES_PARADROP_CONQUER)
3006 || action_has_result(paction, ACTRES_PARADROP))) {
3007 /* Not relevant. */
3008 continue;
3009 }
3010
3011 if (action_prob_possible(
3012 action_prob_unit_vs_tgt(paction, punit,
3013 tile_city(ptile), NULL,
3014 ptile, NULL))) {
3015 if (paradrop_action == NULL) {
3016 /* This is the first possible paradrop action. */
3017 paradrop_action = paction;
3018 } else {
3019 /* More than one paradrop action may be possible. The user must
3020 * choose. Have the server record that an action decision is wanted
3021 * for this unit so the dialog will be brought up. */
3022 dsend_packet_unit_sscs_set(&client.conn, punit->id, punit->id,
3023 USSDT_QUEUE, tile_index(ptile));
3024 return;
3025 }
3026 }
3027 } action_iterate_end;
3028
3029 if (paradrop_action != NULL) {
3030 request_do_action(paradrop_action->id, punit->id,
3031 tile_index(ptile), 0 , "");
3032 }
3033}
3034
3035/**********************************************************************/
3038 void do_unit_patrol_to(struct tile *ptile)
3039{
3040 if (is_valid_goto_draw_line(ptile)
3041 && !is_non_allied_unit_tile(ptile, client.conn.playing)) {
3042 send_patrol_route();
3043 } else {
3044 create_event(ptile, E_BAD_COMMAND, ftc_client,
3045 _("Didn't find a route to the destination!"));
3046 }
3047
3048 clear_hover_state();
3049}
3050
3051/**********************************************************************/
3054 void do_unit_connect(struct tile *ptile,
3055 enum unit_activity activity,
3056 struct extra_type *tgt)
3057{
3058 if (is_valid_goto_draw_line(ptile)) {
3059 send_connect_route(activity, tgt);
3060 } else {
3061 create_event(ptile, E_BAD_COMMAND, ftc_client,
3062 _("Didn't find a route to the destination!"));
3063 }
3064
3065 clear_hover_state();
3066}
3067
3068/**********************************************************************/
3071 void key_cancel_action(void)
3072{
3073 struct unit_list *punits = get_units_in_focus();
3074 cancel_tile_hiliting();
3075
3076 switch (hover_state) {
3077 case HOVER_GOTO_SEL_TGT:
3078 set_hover_state(punits, HOVER_GOTO, connect_activity, connect_tgt,
3079 goto_last_tgt, goto_last_sub_tgt,
3080 goto_last_action, goto_last_order);
3081 break;
3082 case HOVER_GOTO:
3083 case HOVER_PATROL:
3084 case HOVER_CONNECT:
3085 if (goto_pop_waypoint()) {
3086 break;
3087 }
3088 fc__fallthrough; /* else fall through: */
3089 case HOVER_PARADROP:
3090 case HOVER_ACT_SEL_TGT:
3091 clear_hover_state();
3092 update_unit_info_label(get_units_in_focus());
3093
3094 keyboardless_goto_button_down = FALSE;
3095 keyboardless_goto_active = FALSE;
3096 keyboardless_goto_start_tile = NULL;
3097 break;
3098 case HOVER_NONE:
3099 break;
3100 };
3101}
3102
3103/**********************************************************************/
3107 void key_center_capital(void)
3108{
3109 struct city *capital = player_primary_capital(client_player());
3110
3111 if (capital) {
3112 /* Center on the tile, and pop up the crosshair overlay. */
3113 center_tile_mapcanvas(capital->tile);
3114 put_cross_overlay_tile(capital->tile);
3115 } else {
3116 create_event(NULL, E_BAD_COMMAND, ftc_client,
3117 _("Oh my! You seem to have no capital!"));
3118 }
3119}
3120
3121/**********************************************************************/
3124 void key_end_turn(void)
3125{
3126 send_turn_done();
3127}
3128
3129/**********************************************************************/
3132 void key_recall_previous_focus_unit(void)
3133{
3134 int i = 0;
3135
3136 /* Could use unit_list_copy here instead. Just having safe genlists
3137 * wouldn't be sufficient since we don't want to skip units already
3138 * removed from focus... */
3139 unit_list_iterate_safe(previous_focus, punit) {
3140 if (i == 0) {
3141 unit_focus_set(punit);
3142 } else {
3143 unit_focus_add(punit);
3144 }
3145 i++;
3146 } unit_list_iterate_safe_end;
3147}
3148
3149/**********************************************************************/
3153 void key_unit_move(enum direction8 gui_dir)
3154{
3155 unit_list_iterate(get_units_in_focus(), punit) {
3156 enum direction8 map_dir = gui_to_map_dir(gui_dir);
3157
3158 request_move_unit_direction(punit, map_dir);
3159 } unit_list_iterate_end;
3160}
3161
3162/**********************************************************************/
3165 void key_unit_build_city(void)
3166{
3167 unit_list_iterate(get_units_in_focus(), punit) {
3168 request_unit_build_city(punit);
3169 } unit_list_iterate_end;
3170}
3171
3172/**********************************************************************/
3175 void key_unit_build_wonder(void)
3176{
3177 unit_list_iterate(get_units_in_focus(), punit) {
3178 if (unit_can_do_action(punit, ACTION_HELP_WONDER)) {
3179 request_unit_caravan_action(punit, ACTION_HELP_WONDER);
3180 }
3181 } unit_list_iterate_end;
3182}
3183
3184/**********************************************************************/
3187 void key_unit_connect(enum unit_activity activity,
3188 struct extra_type *tgt)
3189{
3190 request_unit_connect(activity, tgt);
3191}
3192
3193/**********************************************************************/
3196 void key_unit_action_select(void)
3197{
3198 struct tile *ptile;
3199
3200 unit_list_iterate(get_units_in_focus(), punit) {
3201 if (utype_may_act_at_all(unit_type_get(punit))
3202 && (ptile = unit_tile(punit))) {
3203 /* Have the server record that an action decision is wanted for this
3204 * unit. */
3205 dsend_packet_unit_sscs_set(&client.conn, punit->id, punit->id,
3206 USSDT_QUEUE, tile_index(ptile));
3207 }
3208 } unit_list_iterate_end;
3209}
3210
3211/**********************************************************************/
3218 void key_unit_action_select_tgt(void)
3219{
3220 struct unit_list *punits = get_units_in_focus();
3221
3222 if (hover_state == HOVER_ACT_SEL_TGT) {
3223 /* The 2nd key press means that the actor should target its own
3224 * tile. */
3225 key_unit_action_select();
3226
3227 /* Target tile selected. Clean up hover state. */
3228 clear_hover_state();
3229 update_unit_info_label(punits);
3230
3231 return;
3232 } else if (hover_state == HOVER_GOTO_SEL_TGT) {
3233 fc_assert(action_id_exists(goto_last_action));
3234
3235 /* We don't support long range actions in the middle of orders yet so
3236 * send it at once. */
3237 send_goto_route();
3238
3239 /* Target tile selected. Clean up hover state. */
3240 clear_hover_state();
3241 update_unit_info_label(punits);
3242
3243 return;
3244 } else if (hover_state == HOVER_GOTO
3245 && action_id_exists(goto_last_action)) {
3246 struct action *paction = action_by_number(goto_last_action);
3247
3248 create_event(unit_tile(unit_list_get(punits, 0)), E_BEGINNER_HELP,
3249 ftc_client,
3250 /* TRANS: Perform action inside a goto. */
3251 _("Click on a tile to do %s against it."),
3252 action_name_translation(paction));
3253
3254 set_hover_state(punits, HOVER_GOTO_SEL_TGT,
3255 connect_activity, connect_tgt,
3256 goto_last_tgt, goto_last_sub_tgt,
3257 goto_last_action, goto_last_order);
3258
3259 return;
3260 }
3261
3262 create_event(unit_tile(unit_list_get(punits, 0)), E_BEGINNER_HELP,
3263 ftc_client,
3264 /* TRANS: "Do..." action selection dialog target. */
3265 _("Click on a tile to act against it. "
3266 "Press 'd' again to act against own tile."));
3267
3268 set_hover_state(punits, HOVER_ACT_SEL_TGT, ACTIVITY_LAST, NULL,
3269 NO_TARGET, NO_TARGET, ACTION_NONE, ORDER_LAST);
3270}
3271
3272/**********************************************************************/
3275 void key_unit_done(void)
3276{
3277 request_unit_move_done();
3278}
3279
3280/**********************************************************************/
3283 void key_unit_goto(void)
3284{
3285 request_unit_goto(ORDER_LAST, ACTION_NONE, -1);
3286}
3287
3288/**********************************************************************/
3291 void key_unit_paradrop(void)
3292{
3293 request_unit_paradrop(get_units_in_focus());
3294}
3295
3296/**********************************************************************/
3299 void key_unit_patrol(void)
3300{
3301 request_unit_patrol();
3302}
3303
3304/**********************************************************************/
3307 void key_unit_trade_route(void)
3308{
3309 unit_list_iterate(get_units_in_focus(), punit) {
3310 /* TODO: Is falling back on ACTION_MARKETPLACE if not able to establish
3311 * a trade route trade a good idea or an unplecant surprice? */
3312 if (unit_can_do_action(punit, ACTION_TRADE_ROUTE)) {
3313 request_unit_caravan_action(punit, ACTION_TRADE_ROUTE);
3314 }
3315 } unit_list_iterate_end;
3316}
3317
3318/**********************************************************************/
3321 void key_unit_unload_all(void)
3322{
3323 struct unit *pnext_focus = NULL, *plast;
3324
3325 unit_list_iterate(get_units_in_focus(), punit) {
3326 if ((plast = request_unit_unload_all(punit))) {
3327 pnext_focus = plast;
3328 }
3329 } unit_list_iterate_end;
3330
3331 if (pnext_focus) {
3332 unit_list_iterate(get_units_in_focus(), punit) {
3333 /* Unfocus the ships, and advance the focus to the last unloaded unit.
3334 * If there is no unit unloaded (which shouldn't happen, but could if
3335 * the caller doesn't check if the transporter is loaded), the we
3336 * don't do anything. */
3337 punit->client.focus_status = FOCUS_WAIT;
3338 } unit_list_iterate_end;
3339 unit_focus_set(pnext_focus);
3340 }
3341}
3342
3343/**********************************************************************/
3346 void key_unit_wait(void)
3347{
3348 request_units_wait(get_units_in_focus());
3349}
3350
3351/**********************************************************************/
3354 void key_unit_wakeup_others(void)
3355{
3356 unit_list_iterate(get_units_in_focus(), punit) {
3357 request_unit_wakeup(punit);
3358 } unit_list_iterate_end;
3359}
3360
3361/**********************************************************************/
3364 void key_unit_airbase(void)
3365{
3366 unit_list_iterate(get_units_in_focus(), punit) {
3367 struct base_type *pbase =
3368 get_base_by_gui_type(BASE_GUI_AIRBASE, punit, unit_tile(punit));
3369
3370 if (pbase) {
3371 struct extra_type *pextra = base_extra_get(pbase);
3372
3373 request_new_unit_activity_targeted(punit, ACTIVITY_BASE, pextra);
3374 }
3375 } unit_list_iterate_end;
3376}
3377
3378/**********************************************************************/
3381 void key_unit_auto_explore(void)
3382{
3383 unit_list_iterate(get_units_in_focus(), punit) {
3384 if (can_unit_do_activity_client(punit, ACTIVITY_EXPLORE)) {
3385 request_unit_ssa_set(punit, SSA_AUTOEXPLORE);
3386 }
3387 } unit_list_iterate_end;
3388}
3389
3390/**********************************************************************/
3394 void key_unit_auto_settle(void)
3395{
3396 unit_list_iterate(get_units_in_focus(), punit) {
3397 if (can_unit_do_autosettlers(punit)) {
3398 request_unit_autosettlers(punit);
3399 }
3400 } unit_list_iterate_end;
3401}
3402
3403/**********************************************************************/
3406 void key_unit_convert(void)
3407{
3408 unit_list_iterate(get_units_in_focus(), punit) {
3409 request_unit_convert(punit);
3410 } unit_list_iterate_end;
3411}
3412
3413/**********************************************************************/
3416 void key_unit_fallout(void)
3417{
3418 key_unit_gen_clean(ACTIVITY_FALLOUT, ERM_CLEANFALLOUT);
3419}
3420
3421/**********************************************************************/
3424 void key_unit_fortify(void)
3425{
3426 unit_list_iterate(get_units_in_focus(), punit) {
3427 if (can_unit_do_activity_client(punit, ACTIVITY_FORTIFYING)) {
3428 request_new_unit_activity(punit, ACTIVITY_FORTIFYING);
3429 }
3430 } unit_list_iterate_end;
3431}
3432
3433/**********************************************************************/
3436 void key_unit_fortress(void)
3437{
3438 unit_list_iterate(get_units_in_focus(), punit) {
3439 struct base_type *pbase =
3440 get_base_by_gui_type(BASE_GUI_FORTRESS, punit, unit_tile(punit));
3441
3442 if (pbase) {
3443 struct extra_type *pextra = base_extra_get(pbase);
3444
3445 request_new_unit_activity_targeted(punit, ACTIVITY_BASE, pextra);
3446 }
3447 } unit_list_iterate_end;
3448}
3449
3450/**********************************************************************/
3453 void key_unit_homecity(void)
3454{
3455 unit_list_iterate(get_units_in_focus(), punit) {
3456 request_unit_change_homecity(punit);
3457 } unit_list_iterate_end;
3458}
3459
3460/**********************************************************************/
3463 static void key_unit_extra(enum unit_activity act, enum extra_cause cause)
3464{
3465 unit_list_iterate(get_units_in_focus(), punit) {
3466 struct extra_type *tgt = next_extra_for_tile(unit_tile(punit),
3467 cause,
3468 unit_owner(punit),
3469 punit);
3470
3471 if (can_unit_do_activity_targeted_client(punit, act, tgt)) {
3472 request_new_unit_activity_targeted(punit, act, tgt);
3473 }
3474 } unit_list_iterate_end;
3475}
3476
3477/**********************************************************************/
3480 static void key_unit_gen_clean(enum unit_activity act,
3481 enum extra_rmcause rmcause)
3482{
3483 unit_list_iterate(get_units_in_focus(), punit) {
3484 struct extra_type *tgt = prev_extra_in_tile(unit_tile(punit),
3485 rmcause,
3486 unit_owner(punit),
3487 punit);
3488
3489 if (tgt != NULL
3490 && can_unit_do_activity_targeted_client(punit, act, tgt)) {
3491 request_new_unit_activity_targeted(punit, act, tgt);
3492 }
3493 } unit_list_iterate_end;
3494}
3495
3496/**********************************************************************/
3499 void key_unit_irrigate(void)
3500{
3501 key_unit_extra(ACTIVITY_IRRIGATE, EC_IRRIGATION);
3502}
3503
3504/**********************************************************************/
3507 void key_unit_cultivate(void)
3508{
3509 unit_list_iterate(get_units_in_focus(), punit) {
3510 if (can_unit_do_activity_client(punit, ACTIVITY_CULTIVATE)) {
3511 request_new_unit_activity(punit, ACTIVITY_CULTIVATE);
3512 }
3513 } unit_list_iterate_end;
3514}
3515
3516/**********************************************************************/
3519 void key_unit_mine(void)
3520{
3521 key_unit_extra(ACTIVITY_MINE, EC_MINE);
3522}
3523
3524/**********************************************************************/
3527 void key_unit_plant(void)
3528{
3529 unit_list_iterate(get_units_in_focus(), punit) {
3530 if (can_unit_do_activity_client(punit, ACTIVITY_PLANT)) {
3531 request_new_unit_activity(punit, ACTIVITY_PLANT);
3532 }
3533 } unit_list_iterate_end;
3534}
3535
3536/**********************************************************************/
3539 void key_unit_pillage(void)
3540{
3541 unit_list_iterate(get_units_in_focus(), punit) {
3542 if (can_unit_do_activity_client(punit, ACTIVITY_PILLAGE)) {
3543 request_unit_pillage(punit);
3544 }
3545 } unit_list_iterate_end;
3546}
3547
3548/**********************************************************************/
3551 void key_unit_clean(void)
3552{
3553 unit_list_iterate(get_units_in_focus(), punit) {
3554 struct extra_type *tgt = prev_extra_in_tile(unit_tile(punit),
3555 ERM_CLEANPOLLUTION,
3556 unit_owner(punit),
3557 punit);
3558
3559 if (tgt != NULL
3560 && can_unit_do_activity_targeted_client(punit, ACTIVITY_POLLUTION, tgt)) {
3561 request_new_unit_activity_targeted(punit, ACTIVITY_POLLUTION, tgt);
3562 } else {
3563 tgt = prev_extra_in_tile(unit_tile(punit),
3564 ERM_CLEANFALLOUT,
3565 unit_owner(punit),
3566 punit);
3567
3568 if (tgt != NULL
3569 && can_unit_do_activity_targeted_client(punit, ACTIVITY_FALLOUT, tgt)) {
3570 request_new_unit_activity_targeted(punit, ACTIVITY_FALLOUT, tgt);
3571 }
3572 }
3573 } unit_list_iterate_end;
3574}
3575
3576/**********************************************************************/
3579 void key_unit_pollution(void)
3580{
3581 key_unit_gen_clean(ACTIVITY_POLLUTION, ERM_CLEANPOLLUTION);
3582}
3583
3584/**********************************************************************/
3587 void key_unit_road(void)
3588{
3589 unit_list_iterate(get_units_in_focus(), punit) {
3590 struct extra_type *tgt = next_extra_for_tile(unit_tile(punit),
3591 EC_ROAD,
3592 unit_owner(punit),
3593 punit);
3594
3595 if (tgt != NULL
3596 && can_unit_do_activity_targeted_client(punit, ACTIVITY_GEN_ROAD, tgt)) {
3597 request_new_unit_activity_targeted(punit, ACTIVITY_GEN_ROAD, tgt);
3598 }
3599 } unit_list_iterate_end;
3600}
3601
3602/**********************************************************************/
3605 void key_unit_sentry(void)
3606{
3607 unit_list_iterate(get_units_in_focus(), punit) {
3608 if (can_unit_do_activity_client(punit, ACTIVITY_SENTRY)) {
3609 request_new_unit_activity(punit, ACTIVITY_SENTRY);
3610 }
3611 } unit_list_iterate_end;
3612}
3613
3614/**********************************************************************/
3617 void key_unit_transform(void)
3618{
3619 unit_list_iterate(get_units_in_focus(), punit) {
3620 if (can_unit_do_activity_client(punit, ACTIVITY_TRANSFORM)) {
3621 request_new_unit_activity(punit, ACTIVITY_TRANSFORM);
3622 }
3623 } unit_list_iterate_end;
3624}
3625
3626/**********************************************************************/
3629 void key_unit_assign_battlegroup(int battlegroup, bool append)
3630{
3631 if (NULL != client.conn.playing && can_client_issue_orders()
3632 && battlegroups >= 0 && battlegroup < MAX_NUM_BATTLEGROUPS) {
3633 if (!append) {
3634 unit_list_iterate_safe(battlegroups[battlegroup], punit) {
3635 if (!unit_is_in_focus(punit)) {
3636 punit->battlegroup = BATTLEGROUP_NONE;
3637 dsend_packet_unit_sscs_set(&client.conn, punit->id, punit->id,
3638 USSDT_BATTLE_GROUP,
3639 BATTLEGROUP_NONE);
3640 refresh_unit_mapcanvas(punit, unit_tile(punit), TRUE, FALSE);
3641 unit_list_remove(battlegroups[battlegroup], punit);
3642 }
3643 } unit_list_iterate_safe_end;
3644 }
3645 unit_list_iterate(get_units_in_focus(), punit) {
3646 if (punit->battlegroup != battlegroup) {
3647 if (punit->battlegroup >= 0
3648 && punit->battlegroup < MAX_NUM_BATTLEGROUPS) {
3649 unit_list_remove(battlegroups[punit->battlegroup], punit);
3650 }
3651 punit->battlegroup = battlegroup;
3652 dsend_packet_unit_sscs_set(&client.conn, punit->id, punit->id,
3653 USSDT_BATTLE_GROUP,
3654 battlegroup);
3655 unit_list_append(battlegroups[battlegroup], punit);
3656 refresh_unit_mapcanvas(punit, unit_tile(punit), TRUE, FALSE);
3657 }
3658 } unit_list_iterate_end;
3659 unit_list_iterate(battlegroups[battlegroup], punit) {
3660 unit_focus_add(punit);
3661 } unit_list_iterate_end;
3662 }
3663}
3664
3665/**********************************************************************/
3668 void key_unit_select_battlegroup(int battlegroup, bool append)
3669{
3670 if (NULL != client.conn.playing && can_client_change_view()
3671 && battlegroups >= 0 && battlegroup < MAX_NUM_BATTLEGROUPS) {
3672 int i = 0;
3673
3674 if (unit_list_size(battlegroups[battlegroup]) == 0 && !append) {
3675 unit_focus_set(NULL);
3676 return;
3677 }
3678
3679 /* FIXME: this is very inefficient and can be improved. */
3680 unit_list_iterate(battlegroups[battlegroup], punit) {
3681 if (i == 0 && !append) {
3682 unit_focus_set(punit);
3683 } else {
3684 unit_focus_add(punit);
3685 }
3686 i++;
3687 } unit_list_iterate_end;
3688 }
3689}
3690
3691/**********************************************************************/
3694 void key_city_outlines_toggle(void)
3695{
3696 request_toggle_city_outlines();
3697}
3698
3699/**********************************************************************/
3702 void key_city_output_toggle(void)
3703{
3704 request_toggle_city_output();
3705}
3706
3707/**********************************************************************/
3710 void key_map_grid_toggle(void)
3711{
3712 request_toggle_map_grid();
3713}
3714
3715/**********************************************************************/
3718 void key_map_borders_toggle(void)
3719{
3720 request_toggle_map_borders();
3721}
3722
3723/**********************************************************************/
3726 void key_map_native_toggle(void)
3727{
3728 request_toggle_map_native();
3729}
3730
3731/**********************************************************************/
3734 void key_city_full_bar_toggle(void)
3735{
3736 request_toggle_city_full_bar();
3737}
3738
3739/**********************************************************************/
3742 void key_city_names_toggle(void)
3743{
3744 request_toggle_city_names();
3745}
3746
3747/**********************************************************************/
3751 void key_city_growth_toggle(void)
3752{
3753 request_toggle_city_growth();
3754}
3755
3756/**********************************************************************/
3760 void key_city_buycost_toggle(void)
3761{
3762 request_toggle_city_buycost();
3763}
3764
3765/**********************************************************************/
3768 void key_city_productions_toggle(void)
3769{
3770 request_toggle_city_productions();
3771}
3772
3773/**********************************************************************/
3777 void key_city_trade_routes_toggle(void)
3778{
3779 request_toggle_city_trade_routes();
3780}
3781
3782/**********************************************************************/
3785 void key_unit_stack_size_toggle(void)
3786{
3787 request_toggle_unit_stack_size();
3788}
3789
3790/**********************************************************************/
3793 void key_terrain_toggle(void)
3794{
3795 request_toggle_terrain();
3796}
3797
3798/**********************************************************************/
3801 void key_coastline_toggle(void)
3802{
3803 request_toggle_coastline();
3804}
3805
3806/**********************************************************************/
3809 void key_roads_rails_toggle(void)
3810{
3811 request_toggle_roads_rails();
3812}
3813
3814/**********************************************************************/
3817 void key_irrigation_toggle(void)
3818{
3819 request_toggle_irrigation();
3820}
3821
3822/**********************************************************************/
3825 void key_mines_toggle(void)
3826{
3827 request_toggle_mines();
3828}
3829
3830/**********************************************************************/
3833 void key_bases_toggle(void)
3834{
3835 request_toggle_bases();
3836}
3837
3838/**********************************************************************/
3841 void key_resources_toggle(void)
3842{
3843 request_toggle_resources();
3844}
3845
3846/**********************************************************************/
3849 void key_huts_toggle(void)
3850{
3851 request_toggle_huts();
3852}
3853
3854/**********************************************************************/
3857 void key_pollution_toggle(void)
3858{
3859 request_toggle_pollution();
3860}
3861
3862/**********************************************************************/
3865 void key_cities_toggle(void)
3866{
3867 request_toggle_cities();
3868}
3869
3870/**********************************************************************/
3873 void key_units_toggle(void)
3874{
3875 request_toggle_units();
3876}
3877
3878/**********************************************************************/
3881 void key_unit_solid_bg_toggle(void)
3882{
3883 request_toggle_unit_solid_bg();
3884}
3885
3886/**********************************************************************/
3889 void key_unit_shields_toggle(void)
3890{
3891 request_toggle_unit_shields();
3892}
3893
3894/**********************************************************************/
3897 void key_focus_unit_toggle(void)
3898{
3899 request_toggle_focus_unit();
3900}
3901
3902/**********************************************************************/
3905 void key_fog_of_war_toggle(void)
3906{
3907 request_toggle_fog_of_war();
3908}
3909
3910/**********************************************************************/
3913 void key_editor_toggle(void)
3914{
3915 dsend_packet_edit_mode(&client.conn, !game.info.is_edit_mode);
3916}
3917
3918/**********************************************************************/
3921 void key_editor_recalculate_borders(void)
3922{
3923 send_packet_edit_recalculate_borders(&client.conn);
3924}
3925
3926/**********************************************************************/
3930 void key_editor_toggle_fogofwar(void)
3931{
3932 if (client_has_player()) {
3933 dsend_packet_edit_toggle_fogofwar(&client.conn, client_player_number());
3934 }
3935}
3936
3937/**********************************************************************/
3940 void finish_city(struct tile *ptile, const char *name)
3941{
3942 unit_list_iterate(ptile->units, punit) {
3943 if (punit->client.asking_city_name) {
3944 /* Unit will disappear only in case city building still success.
3945 * Cancel city building status just in case something has changed
3946 * to prevent city building in the meanwhile and unit will remain
3947 * alive. */
3948 punit->client.asking_city_name = FALSE;
3949 request_do_action(ACTION_FOUND_CITY, punit->id, ptile->index,
3950 0, name);
3951 }
3952 } unit_list_iterate_end;
3953}
3954
3955/**********************************************************************/
3959 void cancel_city(struct tile *ptile)
3960{
3961 unit_list_iterate(ptile->units, punit) {
3962 punit->client.asking_city_name = FALSE;
3963 } unit_list_iterate_end;
3964}
action_name_translation
const char * action_name_translation(const struct action *action)
Definition actions.c:1890
action_id_name_translation
const char * action_id_name_translation(action_id act_id)
Definition actions.c:1910
action_prob_self
struct act_prob action_prob_self(const struct unit *actor_unit, const action_id act_id)
Definition actions.c:6383
action_prob_possible
bool action_prob_possible(const struct act_prob probability)
Definition actions.c:6709
action_prob_unit_vs_tgt
struct act_prob action_prob_unit_vs_tgt(const struct action *paction, const struct unit *act_unit, const struct city *tgt_city, const struct unit *tgt_unit, const struct tile *tgt_tile, const struct extra_type *extra_tgt)
Definition actions.c:6405
action_prob_vs_city
struct act_prob action_prob_vs_city(const struct unit *actor_unit, const action_id act_id, const struct city *target_city)
Definition actions.c:5871
action_prob_vs_unit
struct act_prob action_prob_vs_unit(const struct unit *actor_unit, const action_id act_id, const struct unit *target_unit)
Definition actions.c:5955
action_prob_vs_tile
struct act_prob action_prob_vs_tile(const struct unit *actor_unit, const action_id act_id, const struct tile *target_tile, const struct extra_type *target_extra)
Definition actions.c:6228
action_prob_vs_units
struct act_prob action_prob_vs_units(const struct unit *actor_unit, const action_id act_id, const struct tile *target_tile)
Definition actions.c:6144
action_prob_vs_extras
struct act_prob action_prob_vs_extras(const struct unit *actor_unit, const action_id act_id, const struct tile *target_tile, const struct extra_type *target_extra)
Definition actions.c:6312
action_id_exists
bool action_id_exists(const action_id act_id)
Definition actions.c:1697
action_id_univs_not_blocking
#define action_id_univs_not_blocking(act_id, act_uni, tgt_uni)
Definition actions.h:947
action_by_result_iterate
#define action_by_result_iterate(_paction_, _result_)
Definition actions.h:488
action_by_number
static struct action * action_by_number(action_id act_id)
Definition actions.h:638
action_has_result
#define action_has_result(_act_, _res_)
Definition actions.h:448
action_id_get_role
#define action_id_get_role(act_id)
Definition actions.h:708
action_by_result_iterate_end
#define action_by_result_iterate_end
Definition actions.h:492
action_iterate_end
#define action_iterate_end
Definition actions.h:472
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_id_has_result_safe
#define action_id_has_result_safe(act_id, result)
Definition actions.h:668
ACTION_NONE
#define ACTION_NONE
Definition actions.h:293
astr_free
void astr_free(struct astring *astr)
Definition astring.c:153
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
audio_play_sound
void audio_play_sound(const char *const tag, const char *const alt_tag)
Definition audio.c:521
audio.h
base_extra_get
struct extra_type * base_extra_get(const struct base_type *pbase)
Definition base.c:101
get_base_by_gui_type
struct base_type * get_base_by_gui_type(enum base_gui_type type, const struct unit *punit, const struct tile *ptile)
Definition base.c:139
bitvector.h
BV_CLR_ALL
#define BV_CLR_ALL(bv)
Definition bitvector.h:95
BV_SET
#define BV_SET(bv, bit)
Definition bitvector.h:81
chatline_g.h
is_enemy_city_tile
static bool is_enemy_city_tile(const struct tile *ptile, const struct player *pplayer)
Definition city.h:704
citydlg_g.h
popup_city_dialog
void popup_city_dialog(struct city *pcity)
Definition update_queue.c:623
client_player_number
int client_player_number(void)
Definition client_main.c:1354
send_turn_done
void send_turn_done(void)
Definition client_main.c:809
client
struct civclient client
Definition client_main.c:149
client_state
enum client_states client_state(void)
Definition client_main.c:1029
can_client_issue_orders
bool can_client_issue_orders(void)
Definition client_main.c:1265
client_has_player
bool client_has_player(void)
Definition client_main.c:1365
is_server_busy
bool is_server_busy(void)
Definition client_main.c:1338
can_client_change_view
bool can_client_change_view(void)
Definition client_main.c:1313
client_main.h
client_player
#define client_player()
Definition client_main.h:106
C_S_RUNNING
@ C_S_RUNNING
Definition client_main.h:47
C_S_OVER
@ C_S_OVER
Definition client_main.h:48
gui_to_map_dir
enum direction8 gui_to_map_dir(enum direction8 gui_dir)
Definition climap.c:59
climap.h
create_event
void create_event(struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
Definition climisc.c:1075
can_units_do_connect
bool can_units_do_connect(struct unit_list *punits, enum unit_activity activity, struct extra_type *tgt)
Definition climisc.c:1224
climisc.h
can_unit_attack_tile
bool can_unit_attack_tile(const struct unit *punit, const struct action *paction, const struct tile *dest_tile)
Definition combat.c:271
combat.h
blink_turn_done_button
double blink_turn_done_button(void)
Definition control.c:907
key_coastline_toggle
void key_coastline_toggle(void)
Definition control.c:3801
key_irrigation_toggle
void key_irrigation_toggle(void)
Definition control.c:3817
request_toggle_huts
void request_toggle_huts(void)
Definition control.c:2503
key_unit_sentry
void key_unit_sentry(void)
Definition control.c:3605
request_toggle_city_outlines
void request_toggle_city_outlines(void)
Definition control.c:2256
key_unit_road
void key_unit_road(void)
Definition control.c:3587
request_unit_airlift
void request_unit_airlift(struct unit *punit, struct city *pcity)
Definition control.c:1512
do_move_unit
void do_move_unit(struct unit *punit, struct unit *target_unit)
Definition control.c:2660
request_toggle_resources
void request_toggle_resources(void)
Definition control.c:2490
request_toggle_city_names
void request_toggle_city_names(void)
Definition control.c:2334
key_recall_previous_focus_unit
void key_recall_previous_focus_unit(void)
Definition control.c:3132
request_unit_non_action_move
void request_unit_non_action_move(struct unit *punit, struct tile *dest_tile)
Definition control.c:1733
request_toggle_unit_stack_size
void request_toggle_unit_stack_size(void)
Definition control.c:2399
key_unit_pollution
void key_unit_pollution(void)
Definition control.c:3579
unit_is_in_focus
bool unit_is_in_focus(const struct unit *punit)
Definition control.c:384
key_city_output_toggle
void key_city_output_toggle(void)
Definition control.c:3702
request_toggle_focus_unit
void request_toggle_focus_unit(void)
Definition control.c:2581
request_toggle_city_output
void request_toggle_city_output(void)
Definition control.c:2269
request_unit_return
void request_unit_return(struct unit *punit)
Definition control.c:1521
request_unit_fortify
void request_unit_fortify(struct unit *punit)
Definition control.c:2211
key_unit_build_city
void key_unit_build_city(void)
Definition control.c:3165
key_editor_recalculate_borders
void key_editor_recalculate_borders(void)
Definition control.c:3921
request_unit_unload_all
struct unit * request_unit_unload_all(struct unit *punit)
Definition control.c:1480
key_roads_rails_toggle
void key_roads_rails_toggle(void)
Definition control.c:3809
request_unit_caravan_action
void request_unit_caravan_action(struct unit *punit, action_id action)
Definition control.c:2119
action_selection_no_longer_in_progress
void action_selection_no_longer_in_progress(const int old_actor_id)
Definition control.c:1032
request_toggle_roads_rails
void request_toggle_roads_rails(void)
Definition control.c:2438
goto_last_order
enum unit_orders goto_last_order
Definition control.c:96
request_units_wait
void request_units_wait(struct unit_list *punits)
Definition control.c:2621
request_unit_wakeup
void request_unit_wakeup(struct unit *punit)
Definition control.c:1569
get_focus_unit_on_tile
struct unit * get_focus_unit_on_tile(const struct tile *ptile)
Definition control.c:392
key_focus_unit_toggle
void key_focus_unit_toggle(void)
Definition control.c:3897
request_toggle_map_grid
void request_toggle_map_grid(void)
Definition control.c:2282
action_decision_request
void action_decision_request(struct unit *actor_unit)
Definition control.c:1083
control_free
void control_free(void)
Definition control.c:154
request_toggle_mines
void request_toggle_mines(void)
Definition control.c:2464
set_units_in_combat
void set_units_in_combat(struct unit *pattacker, struct unit *pdefender)
Definition control.c:1013
check_recursive_road_connect
int check_recursive_road_connect(struct tile *ptile, const struct extra_type *pextra, const struct unit *punit, const struct player *pplayer, int rec)
Definition control.c:1306
key_unit_action_select
void key_unit_action_select(void)
Definition control.c:3196
key_unit_auto_explore
void key_unit_auto_explore(void)
Definition control.c:3381
action_selection_in_progress_for
static int action_selection_in_progress_for
Definition control.c:119
do_disband_alternative
static void do_disband_alternative(void *p)
Definition control.c:1870
key_cancel_action
void key_cancel_action(void)
Definition control.c:3071
request_toggle_city_buycost
void request_toggle_city_buycost(void)
Definition control.c:2373
key_unit_auto_settle
void key_unit_auto_settle(void)
Definition control.c:3394
clear_hover_state
void clear_hover_state(void)
Definition control.c:323
request_toggle_map_native
void request_toggle_map_native(void)
Definition control.c:2308
request_unit_patrol
void request_unit_patrol(void)
Definition control.c:2177
num_units_below
int num_units_below
Definition control.c:76
key_unit_connect
void key_unit_connect(enum unit_activity activity, struct extra_type *tgt)
Definition control.c:3187
key_city_full_bar_toggle
void key_city_full_bar_toggle(void)
Definition control.c:3734
request_unit_load
void request_unit_load(struct unit *pcargo, struct unit *ptrans, struct tile *ptile)
Definition control.c:2054
key_bases_toggle
void key_bases_toggle(void)
Definition control.c:3833
do_map_click
void do_map_click(struct tile *ptile, enum quickselect_type qtype)
Definition control.c:2766
key_unit_extra
static void key_unit_extra(enum unit_activity act, enum extra_cause cause)
Definition control.c:3463
key_map_native_toggle
void key_map_native_toggle(void)
Definition control.c:3726
request_toggle_map_borders
void request_toggle_map_borders(void)
Definition control.c:2295
key_resources_toggle
void key_resources_toggle(void)
Definition control.c:3841
punit_attacking
static struct unit * punit_attacking
Definition control.c:105
unit_focus_add
void unit_focus_add(struct unit *punit)
Definition control.c:557
unit_focus_set
void unit_focus_set(struct unit *punit)
Definition control.c:502
do_unit_act_sel_vs
static void do_unit_act_sel_vs(struct tile *ptile)
Definition control.c:2751
request_unit_goto
void request_unit_goto(enum unit_orders last_order, action_id act_id, int sub_tgt_id)
Definition control.c:1103
do_unit_paradrop_to
void do_unit_paradrop_to(struct unit *punit, struct tile *ptile)
Definition control.c:2998
should_ask_server_for_actions
bool should_ask_server_for_actions(const struct unit *punit)
Definition control.c:334
goto_last_tgt
int goto_last_tgt
Definition control.c:94
connect_tgt
struct extra_type * connect_tgt
Definition control.c:91
key_unit_paradrop
void key_unit_paradrop(void)
Definition control.c:3291
can_units_attack_at
static bool can_units_attack_at(struct unit_list *punits, const struct tile *ptile)
Definition control.c:1170
get_units_in_focus
struct unit_list * get_units_in_focus(void)
Definition control.c:177
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
key_end_turn
void key_end_turn(void)
Definition control.c:3124
request_unit_disband
void request_unit_disband(struct unit *punit)
Definition control.c:1973
request_toggle_irrigation
void request_toggle_irrigation(void)
Definition control.c:2451
current_focus
static struct unit_list * current_focus
Definition control.c:79
previous_focus
static struct unit_list * previous_focus
Definition control.c:83
unit_focus_advance
void unit_focus_advance(void)
Definition control.c:671
key_unit_gen_clean
static void key_unit_gen_clean(enum unit_activity act, enum extra_rmcause rmcause)
Definition control.c:3480
request_unit_autosettlers
void request_unit_autosettlers(const struct unit *punit)
Definition control.c:2039
request_unit_pillage
void request_unit_pillage(struct unit *punit)
Definition control.c:2222
request_center_focus_unit
void request_center_focus_unit(void)
Definition control.c:2608
unit_focus_urgent
void unit_focus_urgent(struct unit *punit)
Definition control.c:207
key_unit_shields_toggle
void key_unit_shields_toggle(void)
Definition control.c:3889
key_city_productions_toggle
void key_city_productions_toggle(void)
Definition control.c:3768
can_unit_do_connect
bool can_unit_do_connect(struct unit *punit, enum unit_activity activity, struct extra_type *tgt)
Definition control.c:1384
key_unit_build_wonder
void key_unit_build_wonder(void)
Definition control.c:3175
key_unit_plant
void key_unit_plant(void)
Definition control.c:3527
key_unit_fortress
void key_unit_fortress(void)
Definition control.c:3436
key_unit_mine
void key_unit_mine(void)
Definition control.c:3519
request_unit_change_homecity
void request_unit_change_homecity(struct unit *punit)
Definition control.c:1992
request_toggle_fog_of_war
void request_toggle_fog_of_war(void)
Definition control.c:2594
key_unit_pillage
void key_unit_pillage(void)
Definition control.c:3539
request_unit_unload
void request_unit_unload(struct unit *pcargo)
Definition control.c:2090
key_editor_toggle_fogofwar
void key_editor_toggle_fogofwar(void)
Definition control.c:3930
client_disband_unit_data_destroy
static void client_disband_unit_data_destroy(void *p)
Definition control.c:1860
request_unit_ssa_set
void request_unit_ssa_set(const struct unit *punit, enum server_side_agent agent)
Definition control.c:2026
find_best_focus_candidate
static struct unit * find_best_focus_candidate(bool accept_current)
Definition control.c:634
request_action_details
void request_action_details(action_id action, int actor_id, int target_id)
Definition control.c:1695
quickselect
static struct unit * quickselect(struct tile *ptile, enum quickselect_type qtype)
Definition control.c:2855
connect_activity
enum unit_activity connect_activity
Definition control.c:90
request_toggle_units
void request_toggle_units(void)
Definition control.c:2542
request_new_unit_activity_targeted
void request_new_unit_activity_targeted(struct unit *punit, enum unit_activity act, struct extra_type *tgt)
Definition control.c:1837
update_unit_pix_label
void update_unit_pix_label(struct unit_list *punitlist)
Definition control.c:966
key_unit_irrigate
void key_unit_irrigate(void)
Definition control.c:3499
request_unit_build_city
void request_unit_build_city(struct unit *punit)
Definition control.c:1714
unit_change_battlegroup
void unit_change_battlegroup(struct unit *punit, int battlegroup)
Definition control.c:250
urgent_focus_queue
static struct unit_list * urgent_focus_queue
Definition control.c:86
key_unit_unload_all
void key_unit_unload_all(void)
Definition control.c:3321
key_cities_toggle
void key_cities_toggle(void)
Definition control.c:3865
key_unit_move
void key_unit_move(enum direction8 gui_dir)
Definition control.c:3153
key_city_outlines_toggle
void key_city_outlines_toggle(void)
Definition control.c:3694
key_unit_homecity
void key_unit_homecity(void)
Definition control.c:3453
request_unit_paradrop
void request_unit_paradrop(struct unit_list *punits)
Definition control.c:2142
set_hover_state
void set_hover_state(struct unit_list *punits, enum cursor_hover_state state, enum unit_activity activity, struct extra_type *tgt, int last_tgt, int last_sub_tgt, action_id action, enum unit_orders order)
Definition control.c:285
disband_unit_alternatives
static int disband_unit_alternatives[3]
Definition control.c:69
key_unit_patrol
void key_unit_patrol(void)
Definition control.c:3299
request_toggle_city_full_bar
void request_toggle_city_full_bar(void)
Definition control.c:2321
request_toggle_city_growth
void request_toggle_city_growth(void)
Definition control.c:2347
key_unit_solid_bg_toggle
void key_unit_solid_bg_toggle(void)
Definition control.c:3881
request_toggle_unit_solid_bg
void request_toggle_unit_solid_bg(void)
Definition control.c:2555
key_terrain_toggle
void key_terrain_toggle(void)
Definition control.c:3793
request_unit_sentry
void request_unit_sentry(struct unit *punit)
Definition control.c:2200
key_unit_wakeup_others
void key_unit_wakeup_others(void)
Definition control.c:3354
non_ai_unit_focus
bool non_ai_unit_focus
Definition control.c:125
punit_defending
static struct unit * punit_defending
Definition control.c:106
find_a_focus_unit_tile_to_center_on
static struct tile * find_a_focus_unit_tile_to_center_on(void)
Definition control.c:414
hover_state
enum cursor_hover_state hover_state
Definition control.c:89
key_unit_stack_size_toggle
void key_unit_stack_size_toggle(void)
Definition control.c:3785
store_previous_focus
static void store_previous_focus(void)
Definition control.c:194
key_huts_toggle
void key_huts_toggle(void)
Definition control.c:3849
key_fog_of_war_toggle
void key_fog_of_war_toggle(void)
Definition control.c:3905
request_unit_connect
void request_unit_connect(enum unit_activity activity, struct extra_type *tgt)
Definition control.c:1451
clear_unit_orders
void clear_unit_orders(struct unit *punit)
Definition control.c:477
control_init
void control_init(void)
Definition control.c:137
request_toggle_terrain
void request_toggle_terrain(void)
Definition control.c:2412
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:3346
key_units_toggle
void key_units_toggle(void)
Definition control.c:3873
do_unit_connect
void do_unit_connect(struct tile *ptile, enum unit_activity activity, struct extra_type *tgt)
Definition control.c:3054
goto_last_sub_tgt
int goto_last_sub_tgt
Definition control.c:95
unit_focus_remove
void unit_focus_remove(struct unit *punit)
Definition control.c:587
request_toggle_bases
void request_toggle_bases(void)
Definition control.c:2477
do_unit_patrol_to
void do_unit_patrol_to(struct tile *ptile)
Definition control.c:3038
key_unit_trade_route
void key_unit_trade_route(void)
Definition control.c:3307
request_toggle_coastline
void request_toggle_coastline(void)
Definition control.c:2425
key_unit_select_battlegroup
void key_unit_select_battlegroup(int battlegroup, bool append)
Definition control.c:3668
key_map_grid_toggle
void key_map_grid_toggle(void)
Definition control.c:3710
finish_city
void finish_city(struct tile *ptile, const char *name)
Definition control.c:3940
punit_moving
static struct unit * punit_moving
Definition control.c:102
key_pollution_toggle
void key_pollution_toggle(void)
Definition control.c:3857
head_of_units_in_focus
struct unit * head_of_units_in_focus(void)
Definition control.c:406
is_activity_on_tile
static bool is_activity_on_tile(struct tile *ptile, enum unit_activity activity)
Definition control.c:1290
find_visible_unit
struct unit * find_visible_unit(struct tile *ptile)
Definition control.c:805
can_be_irrigated
static bool can_be_irrigated(const struct tile *ptile, const struct unit *punit)
Definition control.c:1361
key_city_growth_toggle
void key_city_growth_toggle(void)
Definition control.c:3751
key_unit_action_select_tgt
void key_unit_action_select_tgt(void)
Definition control.c:3218
key_unit_fallout
void key_unit_fallout(void)
Definition control.c:3416
battlegroups
static struct unit_list * battlegroups[MAX_NUM_BATTLEGROUPS]
Definition control.c:99
key_city_buycost_toggle
void key_city_buycost_toggle(void)
Definition control.c:3760
get_num_units_in_focus
int get_num_units_in_focus(void)
Definition control.c:185
key_unit_transform
void key_unit_transform(void)
Definition control.c:3617
request_move_unit_direction
void request_move_unit_direction(struct unit *punit, int dir)
Definition control.c:1777
current_focus_append
static void current_focus_append(struct unit *punit)
Definition control.c:443
key_unit_done
void key_unit_done(void)
Definition control.c:3275
current_focus_remove
static void current_focus_remove(struct unit *punit)
Definition control.c:463
hover_tile
static struct tile * hover_tile
Definition control.c:98
key_city_trade_routes_toggle
void key_city_trade_routes_toggle(void)
Definition control.c:3777
focus_units_changed
static void focus_units_changed(void)
Definition control.c:215
request_toggle_city_trade_routes
void request_toggle_city_trade_routes(void)
Definition control.c:2386
unit_focus_set_and_select
void unit_focus_set_and_select(struct unit *punit)
Definition control.c:621
request_unit_convert
void request_unit_convert(struct unit *punit)
Definition control.c:2016
request_toggle_unit_shields
void request_toggle_unit_shields(void)
Definition control.c:2568
key_city_names_toggle
void key_city_names_toggle(void)
Definition control.c:3742
unit_register_battlegroup
void unit_register_battlegroup(struct unit *punit)
Definition control.c:270
request_unit_select
void request_unit_select(struct unit_list *punits, enum unit_select_type_mode seltype, enum unit_select_location_mode selloc)
Definition control.c:1590
unit_focus_update
void unit_focus_update(void)
Definition control.c:772
key_unit_airbase
void key_unit_airbase(void)
Definition control.c:3364
key_unit_goto
void key_unit_goto(void)
Definition control.c:3283
control_mouse_cursor
void control_mouse_cursor(struct tile *ptile)
Definition control.c:1188
key_unit_convert
void key_unit_convert(void)
Definition control.c:3406
key_unit_clean
void key_unit_clean(void)
Definition control.c:3551
key_center_capital
void key_center_capital(void)
Definition control.c:3107
wakeup_sentried_units
void wakeup_sentried_units(struct tile *ptile)
Definition control.c:1552
request_toggle_cities
void request_toggle_cities(void)
Definition control.c:2529
key_unit_fortify
void key_unit_fortify(void)
Definition control.c:3424
key_editor_toggle
void key_editor_toggle(void)
Definition control.c:3913
key_unit_assign_battlegroup
void key_unit_assign_battlegroup(int battlegroup, bool append)
Definition control.c:3629
request_unit_move_done
void request_unit_move_done(void)
Definition control.c:2634
auto_center_on_focus_unit
void auto_center_on_focus_unit(void)
Definition control.c:430
key_unit_cultivate
void key_unit_cultivate(void)
Definition control.c:3507
blink_active_unit
double blink_active_unit(void)
Definition control.c:875
request_unit_upgrade
void request_unit_upgrade(struct unit *punit)
Definition control.c:2004
control_unit_killed
void control_unit_killed(struct unit *punit)
Definition control.c:226
request_toggle_city_productions
void request_toggle_city_productions(void)
Definition control.c:2360
cancel_city
void cancel_city(struct tile *ptile)
Definition control.c:3959
ask_server_for_actions
static void ask_server_for_actions(struct unit *punit)
Definition control.c:361
request_new_unit_activity
void request_new_unit_activity(struct unit *punit, enum unit_activity act)
Definition control.c:1828
request_toggle_pollution
void request_toggle_pollution(void)
Definition control.c:2516
goto_last_action
action_id goto_last_action
Definition control.c:93
key_mines_toggle
void key_mines_toggle(void)
Definition control.c:3825
do_unit_goto
void do_unit_goto(struct tile *ptile)
Definition control.c:2976
action_selection_next_in_focus
void action_selection_next_in_focus(const int old_actor_id)
Definition control.c:1065
can_ask_server_for_actions
static bool can_ask_server_for_actions(void)
Definition control.c:347
key_map_borders_toggle
void key_map_borders_toggle(void)
Definition control.c:3718
control.h
can_unit_do_activity_targeted_client
#define can_unit_do_activity_targeted_client(_punit_, _act_, _tgt_)
Definition control.h:42
MAX_NUM_UNITS_BELOW
#define MAX_NUM_UNITS_BELOW
Definition control.h:285
quickselect_type
quickselect_type
Definition control.h:36
SELECT_LAND
@ SELECT_LAND
Definition control.h:37
SELECT_APPEND
@ SELECT_APPEND
Definition control.h:37
SELECT_SEA
@ SELECT_SEA
Definition control.h:37
SELECT_POPUP
@ SELECT_POPUP
Definition control.h:37
SELECT_FOCUS
@ SELECT_FOCUS
Definition control.h:37
cursor_hover_state
cursor_hover_state
Definition control.h:25
HOVER_GOTO
@ HOVER_GOTO
Definition control.h:27
HOVER_PARADROP
@ HOVER_PARADROP
Definition control.h:28
HOVER_ACT_SEL_TGT
@ HOVER_ACT_SEL_TGT
Definition control.h:31
HOVER_NONE
@ HOVER_NONE
Definition control.h:26
HOVER_CONNECT
@ HOVER_CONNECT
Definition control.h:29
HOVER_PATROL
@ HOVER_PATROL
Definition control.h:30
HOVER_GOTO_SEL_TGT
@ HOVER_GOTO_SEL_TGT
Definition control.h:32
can_unit_do_activity_client
#define can_unit_do_activity_client(_punit_, _act_)
Definition control.h:40
dialogs_g.h
target_unit
struct unit struct city struct unit * target_unit
Definition dialogs_g.h:55
actor_unit
struct unit * actor_unit
Definition dialogs_g.h:54
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
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
editor.h
get_unit_bonus
int get_unit_bonus(const struct unit *punit, enum effect_type effect_type)
Definition effects.c:992
next_extra_for_tile
struct extra_type * next_extra_for_tile(const struct tile *ptile, enum extra_cause cause, const struct player *pplayer, const struct unit *punit)
Definition extras.c:740
prev_extra_in_tile
struct extra_type * prev_extra_in_tile(const struct tile *ptile, enum extra_rmcause rmcause, const struct player *pplayer, const struct unit *punit)
Definition extras.c:765
can_build_extra
bool can_build_extra(const struct extra_type *pextra, const struct unit *punit, const struct tile *ptile)
Definition extras.c:507
extra_type_iterate
#define extra_type_iterate(_p)
Definition extras.h:291
extra_deps_iterate
#define extra_deps_iterate(_reqs, _dep)
Definition extras.h:338
extra_type_iterate_end
#define extra_type_iterate_end
Definition extras.h:297
is_extra_caused_by
#define is_extra_caused_by(e, c)
Definition extras.h:196
extra_index
#define extra_index(_e_)
Definition extras.h:177
extra_deps_iterate_end
#define extra_deps_iterate_end
Definition extras.h:346
EXTRA_NONE
#define EXTRA_NONE
Definition extras.h:82
extra_road_get
#define extra_road_get(_e_)
Definition extras.h:185
NO_TARGET
#define NO_TARGET
Definition fc_types.h:324
RPT_POSSIBLE
@ RPT_POSSIBLE
Definition fc_types.h:585
DIR8_ORIGIN
#define DIR8_ORIGIN
Definition fc_types.h:427
action_id
int action_id
Definition fc_types.h:359
MAX_EXTRA_TYPES
#define MAX_EXTRA_TYPES
Definition fc_types.h:50
IDENTITY_NUMBER_ZERO
#define IDENTITY_NUMBER_ZERO
Definition fc_types.h:82
fcintl.h
_
#define _(String)
Definition fcintl.h:67
ftc_client
const struct ft_color ftc_client
Definition featured_text.c:78
game
struct civ_game game
Definition game.c:57
is_player_phase
bool is_player_phase(const struct player *pplayer, int phase)
Definition game.c:687
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.h
exit_goto_state
void exit_goto_state(void)
Definition goto.c:1019
goto_is_active
bool goto_is_active(void)
Definition goto.c:1056
path_to_nearest_allied_city
struct pf_path * path_to_nearest_allied_city(struct unit *punit)
Definition goto.c:1983
send_patrol_route
void send_patrol_route(void)
Definition goto.c:1647
is_valid_goto_draw_line
bool is_valid_goto_draw_line(struct tile *dest_tile)
Definition goto.c:1335
goto_add_waypoint
bool goto_add_waypoint(void)
Definition goto.c:487
goto_pop_waypoint
bool goto_pop_waypoint(void)
Definition goto.c:524
send_connect_route
void send_connect_route(enum unit_activity activity, struct extra_type *tgt)
Definition goto.c:1713
goto_unit_killed
void goto_unit_killed(struct unit *punit)
Definition goto.c:1037
free_client_goto
void free_client_goto(void)
Definition goto.c:162
enter_goto_state
void enter_goto_state(struct unit_list *punits)
Definition goto.c:998
send_goto_route
void send_goto_route(void)
Definition goto.c:1870
is_valid_goto_destination
bool is_valid_goto_destination(const struct tile *ptile)
Definition goto.c:179
request_orders_cleared
void request_orders_cleared(struct unit *punit)
Definition goto.c:1360
send_goto_path
void send_goto_path(struct unit *punit, struct pf_path *path, struct unit_order *final_order)
Definition goto.c:1530
goto.h
action_selection_actor_unit
int action_selection_actor_unit(void)
Definition action_dialog.c:1592
action_selection_close
void action_selection_close(void)
Definition action_dialog.c:1741
refresh_unit_city_dialogs
void refresh_unit_city_dialogs(struct unit *punit)
Definition citydlg.c:538
unit_select_dialog_popup
void unit_select_dialog_popup(struct tile *ptile)
Definition dialogs.c:382
popup_pillage_dialog
void popup_pillage_dialog(struct unit *punit, bv_extras extras)
Definition dialogs.c:343
real_focus_units_changed
void real_focus_units_changed(void)
Definition gui_main.c:1954
set_unit_icons_more_arrow
void set_unit_icons_more_arrow(bool onoff)
Definition gui_main.c:1931
set_unit_icon
void set_unit_icon(int idx, struct unit *punit)
Definition gui_main.c:1901
create_line_at_mouse_pos
void create_line_at_mouse_pos(void)
Definition mapctrl.c:347
update_turn_done_button
void update_turn_done_button(bool do_restore)
Definition mapview.c:75
put_cross_overlay_tile
void put_cross_overlay_tile(struct tile *ptile)
Definition mapview.c:622
update_unit_info_label
void update_unit_info_label(struct unit_list *punits)
Definition mapview.c:258
update_mouse_cursor
void update_mouse_cursor(enum cursor_type new_cursor_type)
Definition mapview.c:240
request_transport
bool request_transport(struct unit *cargo, struct tile *ptile)
Definition transportdlg.c:82
gui_main_g.h
mouse_cursor_type
enum cursor_type mouse_cursor_type
Definition gui_mouse.c:46
name
const char * name
Definition inputfile.c:127
log.h
fc_assert_msg
#define fc_assert_msg(condition, message,...)
Definition log.h:181
fc_assert_ret
#define fc_assert_ret(condition)
Definition log.h:191
fc_assert
#define fc_assert(condition)
Definition log.h:176
fc_assert_ret_val
#define fc_assert_ret_val(condition, val)
Definition log.h:194
log_error
#define log_error(message,...)
Definition log.h:103
get_direction_for_step
int get_direction_for_step(const struct civ_map *nmap, const struct tile *start_tile, const struct tile *end_tile)
Definition map.c:1345
is_tiles_adjacent
bool is_tiles_adjacent(const struct tile *tile0, const struct tile *tile1)
Definition map.c:929
same_pos
bool same_pos(const struct tile *tile1, const struct tile *tile2)
Definition map.c:938
mapstep
struct tile * mapstep(const struct civ_map *nmap, const struct tile *ptile, enum direction8 dir)
Definition map.c:369
map_distance_vector
void map_distance_vector(int *dx, int *dy, const struct tile *tile0, const struct tile *tile1)
Definition map.c:1071
map.h
iterate_outward
#define iterate_outward(nmap, start_tile, max_dist, itr_tile)
Definition map.h:361
iterate_outward_end
#define iterate_outward_end
Definition map.h:365
keyboardless_goto_button_down
bool keyboardless_goto_button_down
Definition mapctrl_common.c:69
cancel_tile_hiliting
void cancel_tile_hiliting(void)
Definition mapctrl_common.c:310
keyboardless_goto_active
bool keyboardless_goto_active
Definition mapctrl_common.c:70
keyboardless_goto_start_tile
struct tile * keyboardless_goto_start_tile
Definition mapctrl_common.c:71
mapctrl_g.h
update_map_canvas_visible
void update_map_canvas_visible(void)
Definition mapview_common.c:1843
get_center_tile_mapcanvas
struct tile * get_center_tile_mapcanvas(void)
Definition mapview_common.c:1212
move_unit_map_canvas
void move_unit_map_canvas(struct unit *punit, struct tile *src_tile, int dx, int dy)
Definition mapview_common.c:2684
center_tile_mapcanvas
void center_tile_mapcanvas(const struct tile *ptile)
Definition mapview_common.c:1222
update_city_description
void update_city_description(struct city *pcity)
Definition mapview_common.c:1863
refresh_unit_mapcanvas
void refresh_unit_mapcanvas(struct unit *punit, struct tile *ptile, bool full_refresh, bool write_to_screen)
Definition mapview_common.c:510
tile_visible_and_not_on_border_mapcanvas
bool tile_visible_and_not_on_border_mapcanvas(struct tile *ptile)
Definition mapview_common.c:1267
mapview_g.h
mem.h
fc_malloc
#define fc_malloc(sz)
Definition mem.h:34
menu_g.h
menus_update
void menus_update(void)
Definition update_queue.c:562
can_unit_exist_at_tile
bool can_unit_exist_at_tile(const struct civ_map *nmap, const struct unit *punit, const struct tile *ptile)
Definition movement.c:304
can_unit_survive_at_tile
bool can_unit_survive_at_tile(const struct civ_map *nmap, const struct unit *punit, const struct tile *ptile)
Definition movement.c:476
movement.h
server_optset
const struct option_set * server_optset
Definition options.c:4009
option_bool_get
bool option_bool_get(const struct option *poption)
Definition options.c:772
gui_options
struct client_options gui_options
Definition options.c:71
optset_option_by_name
struct option * optset_option_by_name(const struct option_set *poptset, const char *name)
Definition options.c:406
options.h
refresh_overview_canvas
void refresh_overview_canvas(void)
Definition overview_common.c:375
overview_common.h
REQEST_PLAYER_INITIATED
#define REQEST_PLAYER_INITIATED
Definition packets.h:70
dsend_packet_unit_do_action
int dsend_packet_unit_do_action(struct connection *pc, int actor_id16, int actor_id32, int target_id, int sub_tgt_id, const char *name, action_id action_type)
Definition packets_gen.c:45609
dsend_packet_unit_sscs_set
int dsend_packet_unit_sscs_set(struct connection *pc, int unit_id16, int unit_id32, enum unit_ss_data_type type, int value)
Definition packets_gen.c:43126
send_packet_unit_orders
int send_packet_unit_orders(struct connection *pc, const struct packet_unit_orders *packet)
Definition packets_gen.c:43956
send_packet_edit_recalculate_borders
int send_packet_edit_recalculate_borders(struct connection *pc)
Definition packets_gen.c:85204
dsend_packet_unit_get_actions
int dsend_packet_unit_get_actions(struct connection *pc, int actor_unit_id16, int actor_unit_id32, int target_unit_id16, int target_unit_id32, int target_tile_id, int target_extra_id, int request_kind)
Definition packets_gen.c:46745
dsend_packet_unit_action_query
int dsend_packet_unit_action_query(struct connection *pc, int actor_id16, int actor_id32, int target_id, action_id action_type, int request_kind)
Definition packets_gen.c:44859
dsend_packet_unit_server_side_agent_set
int dsend_packet_unit_server_side_agent_set(struct connection *pc, int unit_id16, int unit_id32, enum server_side_agent agent)
Definition packets_gen.c:44346
dsend_packet_unit_change_activity
int dsend_packet_unit_change_activity(struct connection *pc, int unit_id16, int unit_id32, enum unit_activity activity, int target)
Definition packets_gen.c:48102
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
dsend_packet_edit_toggle_fogofwar
int dsend_packet_edit_toggle_fogofwar(struct connection *pc, int player)
Definition packets_gen.c:85400
dsend_packet_edit_mode
int dsend_packet_edit_mode(struct connection *pc, bool state)
Definition packets_gen.c:85177
pf_path_last_position
const struct pf_position * pf_path_last_position(const struct pf_path *path)
Definition path_finding.c:3531
pf_path_destroy
void pf_path_destroy(struct pf_path *path)
Definition path_finding.c:3411
path_finding.h
player_unit_by_number
struct unit * player_unit_by_number(const struct player *pplayer, int unit_id)
Definition player.c:1205
player_primary_capital
struct city * player_primary_capital(const struct player *pplayer)
Definition player.c:1313
can_player_see_units_in_city
bool can_player_see_units_in_city(const struct player *pplayer, const struct city *pcity)
Definition player.c:1113
can_player_see_city_internals
bool can_player_see_city_internals(const struct player *pplayer, const struct city *pcity)
Definition player.c:1129
players_iterate_alive_end
#define players_iterate_alive_end
Definition player.h:545
players_iterate_alive
#define players_iterate_alive(_pplayer)
Definition player.h:540
are_reqs_active
bool are_reqs_active(const struct req_context *context, const struct player *other_player, const struct requirement_vector *reqs, const enum req_problem_type prob_type)
Definition requirements.c:4361
can_build_road
bool can_build_road(const struct civ_map *nmap, struct road_type *proad, const struct unit *punit, const struct tile *ptile)
Definition road.c:295
player_can_build_road
bool player_can_build_road(const struct civ_map *nmap, const struct road_type *proad, const struct player *pplayer, const struct tile *ptile)
Definition road.c:280
FC_INFINITY
#define FC_INFINITY
Definition shared.h:36
spechash.h
action
Definition actions.h:379
action::id
action_id id
Definition actions.h:380
agent
Definition agents.h:40
astring
Definition astring.h:36
base_type
Definition base.h:41
city
Definition city.h:309
city::id
int id
Definition city.h:315
city::capital
enum capital_type capital
Definition city.h:317
civ_game::info
struct packet_game_info info
Definition game.h:89
civ_map
Definition map_types.h:71
civclient::conn
struct connection conn
Definition client_main.h:96
client_disband_unit_data
Definition control.c:60
client_disband_unit_data::unit_id
int unit_id
Definition control.c:61
client_disband_unit_data::alt
int alt
Definition control.c:62
client_options::draw_native
bool draw_native
Definition options.h:207
client_options::enable_cursor_changes
bool enable_cursor_changes
Definition options.h:166
client_options::auto_turn_done
bool auto_turn_done
Definition options.h:157
client_options::draw_specials
bool draw_specials
Definition options.h:199
client_options::draw_city_output
bool draw_city_output
Definition options.h:186
client_options::draw_city_names
bool draw_city_names
Definition options.h:188
client_options::draw_city_productions
bool draw_city_productions
Definition options.h:190
client_options::smooth_move_unit_msec
int smooth_move_unit_msec
Definition options.h:144
client_options::draw_mines
bool draw_mines
Definition options.h:197
client_options::draw_borders
bool draw_borders
Definition options.h:206
client_options::draw_fortress_airbase
bool draw_fortress_airbase
Definition options.h:198
client_options::draw_city_buycost
bool draw_city_buycost
Definition options.h:191
client_options::draw_unit_stack_size
bool draw_unit_stack_size
Definition options.h:210
client_options::draw_irrigation
bool draw_irrigation
Definition options.h:196
client_options::draw_terrain
bool draw_terrain
Definition options.h:193
client_options::draw_units
bool draw_units
Definition options.h:203
client_options::auto_center_on_automated
bool auto_center_on_automated
Definition options.h:149
client_options::draw_fog_of_war
bool draw_fog_of_war
Definition options.h:205
client_options::draw_city_trade_routes
bool draw_city_trade_routes
Definition options.h:192
client_options::unit_selection_clears_orders
bool unit_selection_clears_orders
Definition options.h:168
client_options::draw_unit_shields
bool draw_unit_shields
Definition options.h:209
client_options::draw_cities
bool draw_cities
Definition options.h:202
client_options::draw_map_grid
bool draw_map_grid
Definition options.h:187
client_options::draw_city_growth
bool draw_city_growth
Definition options.h:189
client_options::draw_huts
bool draw_huts
Definition options.h:200
client_options::draw_focus_unit
bool draw_focus_unit
Definition options.h:204
client_options::draw_city_outlines
bool draw_city_outlines
Definition options.h:185
client_options::draw_coastline
bool draw_coastline
Definition options.h:194
client_options::popup_actor_arrival
bool popup_actor_arrival
Definition options.h:161
client_options::draw_full_citybar
bool draw_full_citybar
Definition options.h:208
client_options::draw_roads_rails
bool draw_roads_rails
Definition options.h:195
client_options::draw_pollution
bool draw_pollution
Definition options.h:201
client_options::auto_center_on_unit
bool auto_center_on_unit
Definition options.h:148
client_options::solid_color_behind_units
bool solid_color_behind_units
Definition options.h:142
client_options::popup_last_move_to_allied
bool popup_last_move_to_allied
Definition options.h:163
client_options::keyboardless_goto
bool keyboardless_goto
Definition options.h:165
connection::playing
struct player * playing
Definition connection.h:156
connection::client
struct connection::@57::@62 client
connection::last_request_id_used
int last_request_id_used
Definition connection.h:192
connection::id
int id
Definition connection.h:142
extra_type
Definition extras.h:85
extra_type::reqs
struct requirement_vector reqs
Definition extras.h:102
option
Definition options.c:454
packet_game_info::is_edit_mode
bool is_edit_mode
Definition packets_gen.h:185
packet_game_info::pillage_select
bool pillage_select
Definition packets_gen.h:208
packet_game_info::phase
int phase
Definition packets_gen.h:206
packet_unit_orders
Definition packets_gen.h:722
packet_unit_orders::src_tile
int src_tile
Definition packets_gen.h:725
packet_unit_orders::length
int length
Definition packets_gen.h:726
packet_unit_orders::unit_id16
int unit_id16
Definition packets_gen.h:723
packet_unit_orders::dest_tile
int dest_tile
Definition packets_gen.h:730
packet_unit_orders::repeat
bool repeat
Definition packets_gen.h:727
packet_unit_orders::vigilant
bool vigilant
Definition packets_gen.h:728
packet_unit_orders::unit_id32
int unit_id32
Definition packets_gen.h:724
packet_unit_orders::orders
struct unit_order orders[MAX_LEN_ROUTE]
Definition packets_gen.h:729
pf_path
Definition path_finding.h:344
pf_position::turn
int turn
Definition path_finding.h:329
player
Definition player.h:249
player::units
struct unit_list * units
Definition player.h:282
player::is_alive
bool is_alive
Definition player.h:268
player::phase_done
bool phase_done
Definition player.h:263
req_context
Definition requirements.h:99
req_context::unit
const struct unit * unit
Definition requirements.h:105
road_type
Definition road.h:75
terrain
Definition terrain.h:176
tile
Definition tile.h:49
tile::index
int index
Definition tile.h:50
tile::units
struct unit_list * units
Definition tile.h:57
tileset
Definition tilespec.c:459
timer
Definition timing.c:81
unit_order
Definition unit.h:92
unit_order::activity
enum unit_activity activity
Definition unit.h:94
unit_order::order
enum unit_orders order
Definition unit.h:93
unit_order::action
int action
Definition unit.h:100
unit_order::dir
enum direction8 dir
Definition unit.h:102
unit_order::target
int target
Definition unit.h:97
unit_order::sub_target
int sub_target
Definition unit.h:98
unit_type::hp
int hp
Definition unittype.h:505
unit
Definition unit.h:138
unit::action_decision_want
enum action_decision action_decision_want
Definition unit.h:202
unit::battlegroup
int battlegroup
Definition unit.h:191
unit::activity
enum unit_activity activity
Definition unit.h:157
unit::moves_left
int moves_left
Definition unit.h:150
unit::id
int id
Definition unit.h:145
unit::hp
int hp
Definition unit.h:151
unit::client
struct unit::@80::@82 client
unit::asking_city_name
bool asking_city_name
Definition unit.h:222
unit::done_moving
bool done_moving
Definition unit.h:181
unit::action_decision_tile
struct tile * action_decision_tile
Definition unit.h:203
unit::focus_status
enum unit_focus_status focus_status
Definition unit.h:211
unit::ssa_controller
enum server_side_agent ssa_controller
Definition unit.h:172
universal
Definition fc_types.h:756
universal::kind
enum universals_n kind
Definition fc_types.h:758
world::map
struct civ_map map
Definition world_object.h:38
TRUE
#define TRUE
Definition support.h:46
FALSE
#define FALSE
Definition support.h:47
fc__fallthrough
#define fc__fallthrough
Definition support.h:109
get_preferred_pillage
struct extra_type * get_preferred_pillage(bv_extras extras)
Definition terrain.c:538
terrain_extra_build_time
int terrain_extra_build_time(const struct terrain *pterrain, enum unit_activity activity, const struct extra_type *tgt)
Definition terrain.c:682
T_UNKNOWN
#define T_UNKNOWN
Definition terrain.h:57
tile_add_extra
void tile_add_extra(struct tile *ptile, const struct extra_type *pextra)
Definition tile.c:940
tile_virtual_destroy
void tile_virtual_destroy(struct tile *vtile)
Definition tile.c:1018
tile_has_road
bool tile_has_road(const struct tile *ptile, const struct road_type *proad)
Definition tile.c:829
tile_virtual_new
struct tile * tile_virtual_new(const struct tile *ptile)
Definition tile.c:966
tile_city
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
tile_index
#define tile_index(_pt_)
Definition tile.h:87
tile_hash_iterate
#define tile_hash_iterate(hash, ptile)
Definition tile.h:81
tile_terrain
#define tile_terrain(_tile)
Definition tile.h:109
tile_hash_iterate_end
#define tile_hash_iterate_end
Definition tile.h:83
tile_continent
#define tile_continent(_tile)
Definition tile.h:91
tile_has_extra
#define tile_has_extra(ptile, pextra)
Definition tile.h:146
get_focus_unit_toggle_timeout
double get_focus_unit_toggle_timeout(const struct tileset *t)
Definition tilespec.c:6261
toggle_focus_unit_state
void toggle_focus_unit_state(struct tileset *t)
Definition tilespec.c:6293
focus_unit_in_combat
void focus_unit_in_combat(struct tileset *t)
Definition tilespec.c:6282
tilespec.h
cursor_type
cursor_type
Definition tilespec.h:285
CURSOR_GOTO
@ CURSOR_GOTO
Definition tilespec.h:286
CURSOR_INVALID
@ CURSOR_INVALID
Definition tilespec.h:291
CURSOR_PATROL
@ CURSOR_PATROL
Definition tilespec.h:287
CURSOR_WAIT
@ CURSOR_WAIT
Definition tilespec.h:295
CURSOR_SELECT
@ CURSOR_SELECT
Definition tilespec.h:290
CURSOR_DEFAULT
@ CURSOR_DEFAULT
Definition tilespec.h:297
CURSOR_PARADROP
@ CURSOR_PARADROP
Definition tilespec.h:288
CURSOR_NUKE
@ CURSOR_NUKE
Definition tilespec.h:289
CURSOR_ATTACK
@ CURSOR_ATTACK
Definition tilespec.h:292
timer_start
void timer_start(struct timer *t)
Definition timing.c:224
timer_read_seconds
double timer_read_seconds(struct timer *t)
Definition timing.c:344
timer_renew
struct timer * timer_renew(struct timer *t, enum timer_timetype type, enum timer_use use)
Definition timing.c:176
timing.h
TIMER_ACTIVE
@ TIMER_ACTIVE
Definition timing.h:45
TIMER_USER
@ TIMER_USER
Definition timing.h:41
get_transporter_occupancy
int get_transporter_occupancy(const struct unit *ptrans)
Definition unit.c:1763
is_attack_unit
bool is_attack_unit(const struct unit *punit)
Definition unit.c:309
unit_transport_get
struct unit * unit_transport_get(const struct unit *pcargo)
Definition unit.c:2421
is_military_unit
bool is_military_unit(const struct unit *punit)
Definition unit.c:321
could_unit_load
bool could_unit_load(const struct unit *pcargo, const struct unit *ptrans)
Definition unit.c:715
can_unit_do_autosettlers
bool can_unit_do_autosettlers(const struct unit *punit)
Definition unit.c:579
unit_can_do_action
bool unit_can_do_action(const struct unit *punit, const action_id act_id)
Definition unit.c:330
get_transporter_capacity
int get_transporter_capacity(const struct unit *punit)
Definition unit.c:301
can_unit_paradrop
bool can_unit_paradrop(const struct civ_map *nmap, const struct unit *punit)
Definition unit.c:823
unit_tile_set
void unit_tile_set(struct unit *punit, struct tile *ptile)
Definition unit.c:1278
unit_transported
bool unit_transported(const struct unit *pcargo)
Definition unit.c:2405
can_unit_unload
bool can_unit_unload(const struct unit *pcargo, const struct unit *ptrans)
Definition unit.c:767
unit_has_orders
bool unit_has_orders(const struct unit *punit)
Definition unit.c:207
transporter_for_unit
struct unit * transporter_for_unit(const struct unit *pcargo)
Definition unit.c:1892
unit_tile
#define unit_tile(_pu)
Definition unit.h:388
unit_focus_status
unit_focus_status
Definition unit.h:52
FOCUS_AVAIL
@ FOCUS_AVAIL
Definition unit.h:53
FOCUS_DONE
@ FOCUS_DONE
Definition unit.h:53
FOCUS_WAIT
@ FOCUS_WAIT
Definition unit.h:53
BATTLEGROUP_NONE
#define BATTLEGROUP_NONE
Definition unit.h:190
unit_orders
unit_orders
Definition unit.h:37
ORDER_ACTION_MOVE
@ ORDER_ACTION_MOVE
Definition unit.h:45
ORDER_ACTIVITY
@ ORDER_ACTIVITY
Definition unit.h:41
ORDER_MOVE
@ ORDER_MOVE
Definition unit.h:39
ORDER_LAST
@ ORDER_LAST
Definition unit.h:49
ORDER_PERFORM_ACTION
@ ORDER_PERFORM_ACTION
Definition unit.h:47
unit_owner
#define unit_owner(_pu)
Definition unit.h:387
MAX_NUM_BATTLEGROUPS
#define MAX_NUM_BATTLEGROUPS
Definition unit.h:189
is_non_allied_unit_tile
static bool is_non_allied_unit_tile(const struct tile *ptile, const struct player *pplayer)
Definition unit.h:423
unitlist.h
unit_list_iterate
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
unit_list_iterate_safe
#define unit_list_iterate_safe(unitlist, _unit)
Definition unitlist.h:39
unit_list_iterate_end
#define unit_list_iterate_end
Definition unitlist.h:33
unit_list_both_iterate_end
#define unit_list_both_iterate_end
Definition unitlist.h:37
unit_list_both_iterate
#define unit_list_both_iterate(unitlist, plink, punit)
Definition unitlist.h:34
unit_list_iterate_safe_end
#define unit_list_iterate_safe_end
Definition unitlist.h:61
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
utype_move_type
enum unit_move_type utype_move_type(const struct unit_type *punittype)
Definition unittype.c:1603
utype_may_act_at_all
bool utype_may_act_at_all(const struct unit_type *putype)
Definition unittype.c:431
unit_class_get
struct unit_class * unit_class_get(const struct unit *punit)
Definition unittype.c:2546
unit_has_type_flag
bool unit_has_type_flag(const struct unit *punit, enum unit_type_flag_id flag)
Definition unittype.c:184
role_units_translations
bool role_units_translations(struct astring *astr, int flag, bool alts)
Definition unittype.c:1720
update_queue_connect_processing_finished_full
void update_queue_connect_processing_finished_full(int request_id, uq_callback_t callback, void *data, uq_free_fn_t free_data_func)
Definition update_queue.c:462
update_queue.h