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
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? */
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: */
77
78/* current_focus points to the current unit(s) in focus */
79static 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). */
83static struct unit_list *previous_focus = NULL;
84
85/* The priority unit(s) for unit_focus_advance(). */
86static struct unit_list *urgent_focus_queue = NULL;
87
88/* These should be set via set_hover_state() */
90enum unit_activity connect_activity;
92
96enum unit_orders goto_last_order; /* Last order for goto */
97
98static struct tile *hover_tile = NULL;
99static struct unit_list *battlegroups[MAX_NUM_BATTLEGROUPS];
100
101/* Current moving unit. */
102static struct unit *punit_moving = NULL;
103
104/* units involved in current combat */
105static struct unit *punit_attacking = NULL;
106static 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 */
120
121/*
122 * This variable is TRUE iff a NON-AI controlled unit was focused this
123 * turn.
124 */
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/**********************************************************************/
137void 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/**********************************************************************/
154void 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
172}
173
174/**********************************************************************/
177struct unit_list *get_units_in_focus(void)
178{
179 return current_focus;
180}
181
182/**********************************************************************/
186{
187 return (NULL != current_focus ? unit_list_size(current_focus) : 0);
188}
189
190/**********************************************************************/
194static void store_previous_focus(void)
195{
196 if (get_num_units_in_focus() > 0) {
197 unit_list_clear(previous_focus);
199 unit_list_append(previous_focus, punit);
201 }
202}
203
204/**********************************************************************/
208{
209 unit_list_append(urgent_focus_queue, punit);
210}
211
212/**********************************************************************/
215static void focus_units_changed(void)
216{
218 menus_update();
219 /* Notify the GUI */
221}
222
223/**********************************************************************/
227{
228 int i;
229
231
232 unit_list_remove(get_units_in_focus(), punit);
233 if (get_num_units_in_focus() < 1) {
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
245}
246
247/**********************************************************************/
250void 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 }
261 unit_list_remove(battlegroups[punit->battlegroup], punit);
262 }
263 punit->battlegroup = battlegroup;
264 }
265}
266
267/**********************************************************************/
271{
274 } else {
275 unit_list_append(battlegroups[punit->battlegroup], punit);
276 }
277}
278
279/**********************************************************************/
285void 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,
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
302 && (state == HOVER_GOTO || state == HOVER_GOTO_SEL_TGT))) {
303 /* Exit goto unless this is a switch between goto states */
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;
316 goto_last_tgt = last_tgt;
317 goto_last_sub_tgt = last_sub_tgt;
318}
319
320/**********************************************************************/
324{
326 ACTIVITY_LAST, NULL,
328}
329
330/**********************************************************************/
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
341}
342
343/**********************************************************************/
348{
349 /* OK as long as no other unit already asked and aren't done yet. */
352}
353
354/**********************************************************************/
362{
365
366 /* Only one action selection dialog at a time is supported. */
368 "Unit %d started action selection before unit %d was done",
371
373 punit->id, punit->id,
379}
380
381/**********************************************************************/
384bool unit_is_in_focus(const struct unit *punit)
385{
386 return unit_list_search(get_units_in_focus(), punit) != NULL;
387}
388
389/**********************************************************************/
392struct unit *get_focus_unit_on_tile(const struct tile *ptile)
393{
395 if (unit_tile(punit) == ptile) {
396 return punit;
397 }
399
400 return NULL;
401}
402
403/**********************************************************************/
407{
408 return unit_list_get(current_focus, 0);
409}
410
411/**********************************************************************/
415{
416 struct unit *punit;
417
419 return unit_tile(punit);
420 } else if (get_num_units_in_focus() > 0) {
422 } else {
423 return NULL;
424 }
425}
426
427/**********************************************************************/
431{
433
437 }
438}
439
440/**********************************************************************/
459
460/**********************************************************************/
463static void current_focus_remove(struct unit *punit)
464{
465 /* Close the action selection dialog if the actor unit lose focus. */
468 }
469
470 unit_list_remove(current_focus, punit);
472}
473
474/**********************************************************************/
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;
487 request_new_unit_activity(punit, ACTIVITY_IDLE);
488 } else if (unit_has_orders(punit)) {
489 /* Clear the focus unit's orders. */
491 }
492}
493
494/**********************************************************************/
503{
504 bool focus_changed = FALSE;
505
506 if (NULL != punit
507 && NULL != 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 erroneously. 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())) {
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) {
526 }
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);
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) {
546 }
547
548 if (focus_changed) {
551 }
552}
553
554/**********************************************************************/
558{
559 if (NULL != punit
560 && NULL != 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. */
578 }
579
582}
583
584/**********************************************************************/
588{
589 if (NULL != punit
590 && NULL != 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. */
608 }
609
611 if (get_num_units_in_focus() > 0) {
613 } else {
615 }
616}
617
618/**********************************************************************/
628
629/**********************************************************************/
634static 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)
651 && punit->activity == ACTIVITY_IDLE
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 }
660
661 return NULL;
662}
663
664/**********************************************************************/
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
679 unit_focus_set(NULL);
680 return;
681 }
682
684
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) {
692 break;
693 }
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
700 : NULL);
701
703 if ((ACTIVITY_IDLE != punit->activity
705 /* This isn't an action decision needed because of an
706 * ORDER_ACTION_MOVE located in the middle of an order. */
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 }
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". */
727 }
728 }
729 }
730
731 if (NULL == candidate) {
732 candidate = find_best_focus_candidate(FALSE);
733
734 if (!candidate) {
735 /* Try for "waiting" units. */
739 }
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 */
759 && num_units_in_old_focus > 0
760 && get_num_units_in_focus() == 0
762 key_end_turn();
763 }
764}
765
766/**********************************************************************/
773{
774 if (NULL == client.conn.playing || !can_client_change_view()) {
775 return;
776 }
777
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. */
789 if ((punit->activity == ACTIVITY_IDLE
790 || punit->activity == ACTIVITY_GOTO
792 && punit->moves_left > 0
793 && !punit->done_moving
794 && punit->ssa_controller == SSA_NONE) {
795 return;
796 }
798
800}
801
802/**********************************************************************/
805struct 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 */
816 unit_list_iterate(ptile->units, punit) {
817 if (punit == punit_attacking) {
818 return punit;
819 }
821 }
822
823 /* If a unit is defending we should show that on top */
825 unit_list_iterate(ptile->units, punit) {
826 if (punit == punit_defending) {
827 return punit;
828 }
830 }
831
832 /* If the unit in focus is at this tile, show that on top */
834 if (punit != punit_moving && unit_tile(punit) == ptile) {
835 return punit;
836 }
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). */
852 if (!unit_transported(punit)) {
854 return punit;
855 } else if (!panyowned) {
856 panyowned = punit;
857 }
858 }
859 } else if (!ptptother && !unit_transported(punit)) {
861 ptptother = punit;
862 } else if (!panyother) {
863 panyother = punit;
864 }
865 }
867
868 return (panyowned ? panyowned : (ptptother ? ptptother : panyother));
869}
870
871/**********************************************************************/
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) {
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
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. */
895 }
896
897 return blink_time - timer_read_seconds(blink_timer);
898 }
899
900 return blink_time;
901}
902
903/**********************************************************************/
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
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 }
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/**********************************************************************/
966void 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 }
993
994 if (i > num_units_below) {
996 } else {
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 }
1007 }
1008}
1009
1010/**********************************************************************/
1013void set_units_in_combat(struct unit *pattacker, struct unit *pdefender)
1014{
1015 punit_attacking = pattacker;
1016 punit_defending = pdefender;
1017
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. */
1025 }
1026}
1027
1028/**********************************************************************/
1032void 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. */
1037 || old_actor_id == 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. */
1044
1045 /* Clean up any client specific assumptions. */
1047}
1048
1049/**********************************************************************/
1053void 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/**********************************************************************/
1065void 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. */
1073 if (old != funit && should_ask_server_for_actions(funit)) {
1075 return;
1076 }
1078}
1079
1080/**********************************************************************/
1084{
1087
1089 /* Getting feed back may be urgent. A unit standing next to an enemy
1090 * could be killed while waiting. */
1092 } else if (can_client_issue_orders()
1094 /* No need to wait. The actor unit is in focus. No other actor unit
1095 * is currently asking about action selection. */
1097 }
1098}
1099
1100/**********************************************************************/
1103void 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. */
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),
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."),
1145 }
1146
1147 return;
1148 }
1150 }
1151
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);
1157 update_unit_info_label(punits);
1159 } else {
1161 /* Adding a long range action in the middle isn't handled yet */
1164 }
1165}
1166
1167/**********************************************************************/
1170static bool can_units_attack_at(struct unit_list *punits,
1171 const struct tile *ptile)
1172{
1173 unit_list_iterate(punits, punit) {
1175 && can_unit_attack_tile(punit, NULL, ptile)) {
1176 return TRUE;
1177 }
1179
1180 return FALSE;
1181}
1182
1183/**********************************************************************/
1188void 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();
1194
1196 return;
1197 }
1198
1199 if (C_S_RUNNING != client_state()) {
1201 return;
1202 }
1203
1204 if (is_server_busy()) {
1205 /* Server will not accept any commands. */
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 {
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. */
1231 } else if (NULL != pcity
1233 /* Set mouse cursor to select a city. */
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)
1244 /* Goto results in nuclear attack. */
1246 } else if (can_units_attack_at(active_units, ptile)) {
1247 /* Goto results in military attack. */
1249 } else if (is_enemy_city_tile(ptile, client.conn.playing)) {
1250 /* Goto results in attack of enemy city. */
1252 } else {
1254 }
1255 } else {
1257 }
1258 break;
1259 case HOVER_PATROL:
1260 if (is_valid_goto_destination(ptile)) {
1262 } else {
1264 }
1265 break;
1266 case HOVER_CONNECT:
1267 if (is_valid_goto_destination(ptile)) {
1269 } else {
1271 }
1272 break;
1273 case HOVER_PARADROP:
1274 /* FIXME: check for invalid tiles. */
1276 break;
1277 case HOVER_ACT_SEL_TGT:
1278 case HOVER_GOTO_SEL_TGT:
1279 /* Select a tile to target / find targets on. */
1281 break;
1282 };
1283
1285}
1286
1287/**********************************************************************/
1290static 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 }
1298
1299 return FALSE;
1300}
1301
1302/**********************************************************************/
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 }
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/*******************************************************************/
1361static 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/**********************************************************************/
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/**********************************************************************/
1451void 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))) {
1465 activity, tgt, NO_TARGET, NO_TARGET,
1467 enter_goto_state(punits);
1469 update_unit_info_label(punits);
1471 } else {
1474 }
1475}
1476
1477/**********************************************************************/
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 }
1505
1506 return plast;
1507}
1508
1509/**********************************************************************/
1512void request_unit_airlift(struct unit *punit, struct city *pcity)
1513{
1514 request_do_action(ACTION_AIRLIFT, punit->id, pcity->id, 0, "");
1515}
1516
1517/**********************************************************************/
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
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/**********************************************************************/
1552void 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
1560 request_new_unit_activity(punit, ACTIVITY_IDLE);
1561 }
1562 }
1564}
1565
1566/**********************************************************************/
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/**********************************************************************/
1590void 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 }
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 }
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
1657 }
1658
1659 tile_hash_destroy(tile_table);
1660 unit_type_hash_destroy(type_table);
1661 continent_hash_destroy(cont_table);
1662}
1663
1664/**********************************************************************/
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. */
1682
1684 actor_id, actor_id, target_id, sub_tgt, name,
1685 action);
1686}
1687
1688/**********************************************************************/
1696 int target_id)
1697{
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. */
1704}
1705
1706/**********************************************************************/
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. */
1724 }
1725}
1726
1727/**********************************************************************/
1734 struct tile *dest_tile)
1735{
1736 struct packet_unit_orders p;
1737 int dir;
1738
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;
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;
1762 p.orders[0].action = ACTION_NONE;
1763
1764 request_unit_ssa_set(punit, SSA_NONE);
1766}
1767
1768/**********************************************************************/
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;
1809 p.dest_tile = tile_index(dest_tile);
1810
1811 p.length = 1;
1814 p.orders[0].dir = dir;
1815 p.orders[0].activity = ACTIVITY_LAST;
1816 p.orders[0].target = NO_TARGET;
1818 p.orders[0].action = ACTION_NONE;
1819
1820 request_unit_ssa_set(punit, SSA_NONE);
1822}
1823
1824/**********************************************************************/
1828void request_new_unit_activity(struct unit *punit, enum unit_activity act)
1829{
1831}
1832
1833/**********************************************************************/
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) {
1850 act, EXTRA_NONE);
1851 } else {
1853 act, extra_index(tgt));
1854 }
1855}
1856
1857/**********************************************************************/
1861{
1862 struct client_disband_unit_data *data = p;
1863
1864 free(data);
1865}
1866
1867/**********************************************************************/
1870static 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 const struct civ_map *nmap = &(wld.map);
1880
1882
1883 /* Fetch the unit to get rid of. */
1885
1886 if (punit == NULL) {
1887 /* Success! It is gone. */
1888 return;
1889 }
1890
1891 if (data->alt == -1) {
1892 /* All alternatives have been tried. */
1893 create_event(unit_tile(punit), E_BAD_COMMAND, ftc_client,
1894 /* TRANS: Unable to get rid of Leader. */
1895 _("Unable to get rid of %s."),
1897 return;
1898 }
1899
1900 act = disband_unit_alternatives[data->alt];
1901
1902 /* Prepare the data for the next try in case this try fails. */
1903 next = fc_malloc(sizeof(struct client_disband_unit_data));
1904 next->unit_id = data->unit_id;
1905 next->alt = data->alt - 1;
1906
1907 /* Latest request ID before trying to send a request. */
1908 last_request_id_used = client.conn.client.last_request_id_used;
1909
1910 /* Send a request to the server unless it is known to be pointless. */
1911 switch (action_id_get_target_kind(act)) {
1912 case ATK_CITY:
1913 if ((pcity = tile_city(unit_tile(punit)))
1915 act, pcity))) {
1916 request_do_action(act, punit->id, pcity->id, 0, "");
1917 }
1918 break;
1919 case ATK_UNIT:
1921 request_do_action(act, punit->id, punit->id, 0, "");
1922 }
1923 break;
1924 case ATK_UNITS:
1925 if ((ptile = unit_tile(punit))
1927 request_do_action(act, punit->id, ptile->index, 0, "");
1928 }
1929 break;
1930 case ATK_TILE:
1931 if ((ptile = unit_tile(punit))
1932 && action_prob_possible(action_prob_vs_tile(punit, act, ptile, NULL))) {
1933 request_do_action(act, punit->id, ptile->index, 0, "");
1934 }
1935 break;
1936 case ATK_EXTRAS:
1937 if ((ptile = unit_tile(punit))
1939 ptile, NULL))) {
1940 request_do_action(act, punit->id, ptile->index, 0, "");
1941 }
1942 break;
1943 case ATK_SELF:
1945 request_do_action(act, punit->id, punit->id, 0, "");
1946 }
1947 break;
1948 case ATK_COUNT:
1949 fc_assert(action_id_get_target_kind(act) != ATK_COUNT);
1950 break;
1951 }
1952
1953 if (last_request_id_used != client.conn.client.last_request_id_used) {
1954 /* A request was sent. */
1955
1956 /* Check if it worked. Move on if it didn't. */
1961 } else {
1962 /* No request was sent. */
1963
1964 /* Move on. */
1966
1967 /* Won't be freed by anyone else. */
1969 }
1970}
1971
1972/**********************************************************************/
1976{
1977 struct client_disband_unit_data *data;
1978
1979 /* Set up disband data. Start at the end of the array. */
1980 data = fc_malloc(sizeof(struct client_disband_unit_data));
1981 data->unit_id = punit->id;
1982 data->alt = 2;
1983
1984 /* Begin. */
1986
1987 /* Won't be freed by anyone else. */
1989}
1990
1991/**********************************************************************/
1995{
1996 struct city *pcity=tile_city(unit_tile(punit));
1997
1998 if (pcity) {
1999 request_do_action(ACTION_HOME_CITY, punit->id, pcity->id, 0, "");
2000 }
2001}
2002
2003/**********************************************************************/
2007{
2008 struct city *pcity=tile_city(unit_tile(punit));
2009
2010 if (pcity) {
2011 request_do_action(ACTION_UPGRADE_UNIT, punit->id, pcity->id, 0, "");
2012 }
2013}
2014
2015/**********************************************************************/
2019{
2020 request_new_unit_activity(punit, ACTIVITY_CONVERT);
2021}
2022
2023/**********************************************************************/
2029 enum server_side_agent agent)
2030{
2031 if (punit) {
2033 agent);
2034 }
2035}
2036
2037/**********************************************************************/
2042{
2044 request_unit_ssa_set(punit, SSA_AUTOSETTLER);
2045 } else if (punit) {
2046 create_event(unit_tile(punit), E_BAD_COMMAND, ftc_client,
2047 _("Only settler units can be put into auto mode."));
2048 }
2049}
2050
2051/**********************************************************************/
2056void request_unit_load(struct unit *pcargo, struct unit *ptrans,
2057 struct tile *ptile)
2058{
2059 if (!ptrans) {
2060 ptrans = transporter_for_unit(pcargo);
2061 }
2062
2063 if (ptrans
2065 && could_unit_load(pcargo, ptrans)) {
2067 same_pos(unit_tile(pcargo), ptile)
2068 ? ACTRES_TRANSPORT_BOARD
2069 : ACTRES_TRANSPORT_EMBARK) {
2070 if (action_prob_possible(action_prob_vs_unit(&(wld.map), pcargo, paction->id,
2071 ptrans))) {
2072 /* Try the first action that may be legal. */
2073 /* Implement something like do_disband_alternative() if a ruleset
2074 * appears where this isn't good enough. */
2075 request_do_action(paction->id, pcargo->id, ptrans->id, 0, "");
2076 break;
2077 }
2079
2080 /* Sentry the unit. */
2081 /* FIXME: Should not sentry if above loading fails (transport moved away,
2082 * or filled already in server side) */
2083 dsend_packet_unit_sscs_set(&client.conn, pcargo->id, pcargo->id,
2084 USSDT_SENTRY, 1);
2085 }
2086}
2087
2088/**********************************************************************/
2092void request_unit_unload(struct unit *pcargo)
2093{
2094 struct unit *ptrans = unit_transport_get(pcargo);
2095
2097 && ptrans
2098 && can_unit_unload(pcargo, ptrans)
2099 && can_unit_survive_at_tile(&(wld.map), pcargo, unit_tile(pcargo))) {
2100 if (unit_owner(pcargo) == client.conn.playing) {
2101 request_do_action(ACTION_TRANSPORT_ALIGHT,
2102 pcargo->id, ptrans->id, 0, "");
2103 } else {
2104 request_do_action(ACTION_TRANSPORT_UNLOAD,
2105 ptrans->id, pcargo->id, 0, "");
2106 }
2107
2108 if (unit_owner(pcargo) == client.conn.playing
2109 && pcargo->activity == ACTIVITY_SENTRY) {
2110 /* Activate the unit. */
2111 dsend_packet_unit_sscs_set(&client.conn, pcargo->id, pcargo->id,
2112 USSDT_SENTRY, 0);
2113 }
2114 }
2115}
2116
2117/**********************************************************************/
2122{
2123 struct city *target_city;
2124
2125 if (!((target_city = tile_city(unit_tile(punit))))) {
2126 return;
2127 }
2128
2129 if (action == ACTION_TRADE_ROUTE) {
2130 request_do_action(ACTION_TRADE_ROUTE, punit->id,
2131 target_city->id, 0, "");
2132 } else if (action == ACTION_HELP_WONDER) {
2133 request_do_action(ACTION_HELP_WONDER, punit->id,
2134 target_city->id, 0, "");
2135 } else {
2136 log_error("request_unit_caravan_action() Bad action (%d)", action);
2137 }
2138}
2139
2140/**********************************************************************/
2144void request_unit_paradrop(struct unit_list *punits)
2145{
2146 bool can = FALSE;
2147 struct tile *offender = NULL;
2148
2149 if (unit_list_size(punits) == 0) {
2150 return;
2151 }
2152 unit_list_iterate(punits, punit) {
2153 if (can_unit_paradrop(&(wld.map), punit)) {
2154 can = TRUE;
2155 break;
2156 }
2157 if (!offender) { /* Take first offender tile/unit */
2158 offender = unit_tile(punit);
2159 }
2161 if (can) {
2162 create_event(unit_tile(unit_list_get(punits, 0)), E_BEGINNER_HELP,
2163 ftc_client,
2164 /* TRANS: paradrop target tile. */
2165 _("Click on a tile to paradrop to it."));
2166
2167 set_hover_state(punits, HOVER_PARADROP, ACTIVITY_LAST, NULL,
2169 update_unit_info_label(punits);
2170 } else {
2171 create_event(offender, E_BAD_COMMAND, ftc_client,
2172 _("Only paratrooper units can do this."));
2173 }
2174}
2175
2176/**********************************************************************/
2180{
2181 struct unit_list *punits = get_units_in_focus();
2182
2183 if (unit_list_size(punits) == 0) {
2184 return;
2185 }
2186
2187 if (hover_state != HOVER_PATROL) {
2188 set_hover_state(punits, HOVER_PATROL, ACTIVITY_LAST, NULL,
2190 update_unit_info_label(punits);
2191 enter_goto_state(punits);
2193 } else {
2196 }
2197}
2198
2199/**********************************************************************/
2203{
2204 if (punit->activity != ACTIVITY_SENTRY
2205 && can_unit_do_activity_client(punit, ACTIVITY_SENTRY)) {
2206 request_new_unit_activity(punit, ACTIVITY_SENTRY);
2207 }
2208}
2209
2210/**********************************************************************/
2214{
2215 if (punit->activity != ACTIVITY_FORTIFYING
2216 && can_unit_do_activity_client(punit, ACTIVITY_FORTIFYING)) {
2217 request_new_unit_activity(punit, ACTIVITY_FORTIFYING);
2218 }
2219}
2220
2221/**********************************************************************/
2225{
2226 if (!game.info.pillage_select) {
2227 /* Leave choice up to the server */
2228 request_new_unit_activity_targeted(punit, ACTIVITY_PILLAGE, NULL);
2229 } else {
2230 bv_extras pspossible;
2231 int count = 0;
2232
2233 BV_CLR_ALL(pspossible);
2234 extra_type_iterate(potential) {
2235 if (can_unit_do_activity_targeted_client(punit, ACTIVITY_PILLAGE,
2236 potential)) {
2237 BV_SET(pspossible, extra_index(potential));
2238 count++;
2239 }
2241
2242 if (count > 1) {
2243 popup_pillage_dialog(punit, pspossible);
2244 } else {
2245 /* Should be only one choice... */
2246 struct extra_type *target = get_preferred_pillage(pspossible);
2247
2248 if (target != NULL) {
2249 request_new_unit_activity_targeted(punit, ACTIVITY_PILLAGE, target);
2250 }
2251 }
2252 }
2253}
2254
2255/**********************************************************************/
2267
2268/**********************************************************************/
2280
2281/**********************************************************************/
2285{
2286 if (!can_client_change_view()) {
2287 return;
2288 }
2289
2292}
2293
2294/**********************************************************************/
2298{
2299 if (!can_client_change_view()) {
2300 return;
2301 }
2302
2305}
2306
2307/**********************************************************************/
2311{
2312 if (!can_client_change_view()) {
2313 return;
2314 }
2315
2318}
2319
2320/**********************************************************************/
2324{
2325 if (!can_client_change_view()) {
2326 return;
2327 }
2328
2331}
2332
2333/**********************************************************************/
2337{
2338 if (!can_client_change_view()) {
2339 return;
2340 }
2341
2344}
2345
2346/**********************************************************************/
2350{
2351 if (!can_client_change_view()) {
2352 return;
2353 }
2354
2357}
2358
2359/**********************************************************************/
2363{
2364 if (!can_client_change_view()) {
2365 return;
2366 }
2367
2370}
2371
2372/**********************************************************************/
2376{
2377 if (!can_client_change_view()) {
2378 return;
2379 }
2380
2383}
2384
2385/**********************************************************************/
2389{
2390 if (!can_client_change_view()) {
2391 return;
2392 }
2393
2396}
2397
2398/**********************************************************************/
2402{
2403 if (!can_client_change_view()) {
2404 return;
2405 }
2406
2409}
2410
2411/**********************************************************************/
2415{
2416 if (!can_client_change_view()) {
2417 return;
2418 }
2419
2422}
2423
2424/**********************************************************************/
2428{
2429 if (!can_client_change_view()) {
2430 return;
2431 }
2432
2435}
2436
2437/**********************************************************************/
2441{
2442 if (!can_client_change_view()) {
2443 return;
2444 }
2445
2448}
2449
2450/**********************************************************************/
2454{
2455 if (!can_client_change_view()) {
2456 return;
2457 }
2458
2461}
2462
2463/**********************************************************************/
2467{
2468 if (!can_client_change_view()) {
2469 return;
2470 }
2471
2474}
2475
2476/**********************************************************************/
2480{
2481 if (!can_client_change_view()) {
2482 return;
2483 }
2484
2487}
2488
2489/**********************************************************************/
2493{
2494 if (!can_client_change_view()) {
2495 return;
2496 }
2497
2500}
2501
2502/**********************************************************************/
2506{
2507 if (!can_client_change_view()) {
2508 return;
2509 }
2510
2513}
2514
2515/**********************************************************************/
2519{
2520 if (!can_client_change_view()) {
2521 return;
2522 }
2523
2526}
2527
2528/**********************************************************************/
2532{
2533 if (!can_client_change_view()) {
2534 return;
2535 }
2536
2539}
2540
2541/**********************************************************************/
2545{
2546 if (!can_client_change_view()) {
2547 return;
2548 }
2549
2552}
2553
2554/**********************************************************************/
2558{
2559 if (!can_client_change_view()) {
2560 return;
2561 }
2562
2565}
2566
2567/**********************************************************************/
2571{
2572 if (!can_client_change_view()) {
2573 return;
2574 }
2575
2578}
2579
2580/**********************************************************************/
2584{
2585 if (!can_client_change_view()) {
2586 return;
2587 }
2588
2591}
2592
2593/**********************************************************************/
2597{
2598 if (!can_client_change_view()) {
2599 return;
2600 }
2601
2605}
2606
2607/**********************************************************************/
2611{
2612 struct tile *ptile = find_a_focus_unit_tile_to_center_on();
2613
2614 if (ptile) {
2615 center_tile_mapcanvas(ptile);
2616 }
2617}
2618
2619/**********************************************************************/
2623void request_units_wait(struct unit_list *punits)
2624{
2625 unit_list_iterate(punits, punit) {
2628 if (punits == get_units_in_focus()) {
2630 }
2631}
2632
2633/**********************************************************************/
2637{
2638 if (get_num_units_in_focus() > 0) {
2639 enum unit_focus_status new_status = FOCUS_DONE;
2641 /* If any of the focused units are busy, keep all of them
2642 * in focus; another tap of the key will dismiss them */
2643 if (punit->activity != ACTIVITY_IDLE) {
2644 new_status = FOCUS_WAIT;
2645 }
2649 punit->client.focus_status = new_status;
2651 if (new_status == FOCUS_DONE) {
2653 }
2654 }
2655}
2656
2657/**********************************************************************/
2663{
2664 struct tile *src_tile = unit_tile(punit);
2665 struct tile *dst_tile = unit_tile(target_unit);
2666 bool was_teleported, do_animation;
2667 bool in_focus = unit_is_in_focus(punit);
2668
2669 was_teleported = !is_tiles_adjacent(src_tile, dst_tile);
2670 do_animation = (!was_teleported && gui_options.smooth_move_unit_msec > 0);
2671
2672 if (!was_teleported
2673 && punit->activity != ACTIVITY_SENTRY
2674 && !unit_transported(punit)) {
2676 unit_type_get(punit)->sound_move_alt);
2677 }
2678
2682 && punit->activity != ACTIVITY_GOTO
2683 && punit->activity != ACTIVITY_SENTRY
2685 && punit->ssa_controller != SSA_NONE)
2686 || (punit->ssa_controller == SSA_NONE))
2688 center_tile_mapcanvas(dst_tile);
2689 }
2690
2691 if (hover_state != HOVER_NONE && in_focus) {
2692 /* Cancel current goto/patrol/connect/nuke command. */
2695 }
2696
2697 unit_list_remove(src_tile->units, punit);
2698
2699 if (!unit_transported(punit)) {
2700 /* Mark the unit as moving unit, then find_visible_unit() won't return
2701 * it. It is especially useful to don't draw many times the unit when
2702 * refreshing the canvas. */
2704
2705 /* We have to refresh the tile before moving. This will draw
2706 * the tile without the unit (because it was unlinked above). */
2708
2710 && punit->ssa_controller != SSA_NONE) {
2711 /* Dont animate automatic units */
2712 } else if (do_animation) {
2713 int dx, dy;
2714
2715 /* For the duration of the animation the unit exists at neither
2716 * tile. */
2717 map_distance_vector(&dx, &dy, src_tile, dst_tile);
2718 move_unit_map_canvas(punit, src_tile, dx, dy);
2719 }
2720 }
2721
2722 unit_tile_set(punit, dst_tile);
2723 unit_list_prepend(dst_tile->units, punit);
2724
2725 if (!unit_transported(punit)) {
2726 /* For find_visible_unit(), see above. */
2727 punit_moving = NULL;
2728
2730 }
2731
2732 /* With the "full" city bar we have to update the city bar when units move
2733 * into or out of a city. For foreign cities this is handled separately,
2734 * via the occupied field of the short-city packet. */
2735 if (NULL != tile_city(src_tile)
2738 }
2739 if (NULL != tile_city(dst_tile)
2742 }
2743
2744 if (in_focus) {
2745 menus_update();
2746 }
2747}
2748
2749/**********************************************************************/
2753static void do_unit_act_sel_vs(struct tile *ptile)
2754{
2757 /* Have the server record that an action decision is wanted for
2758 * this unit against this tile. */
2760 USSDT_QUEUE, tile_index(ptile));
2761 }
2763}
2764
2765/**********************************************************************/
2768void do_map_click(struct tile *ptile, enum quickselect_type qtype)
2769{
2770 struct city *pcity = tile_city(ptile);
2771 struct unit_list *punits = get_units_in_focus();
2772 bool maybe_goto = FALSE;
2773
2774 if (hover_state != HOVER_NONE) {
2775 switch (hover_state) {
2776 case HOVER_NONE:
2777 break;
2778 case HOVER_GOTO:
2779 do_unit_goto(ptile);
2780 break;
2781 case HOVER_PARADROP:
2782 unit_list_iterate(punits, punit) {
2783 do_unit_paradrop_to(punit, ptile);
2785 break;
2786 case HOVER_CONNECT:
2788 break;
2789 case HOVER_PATROL:
2790 do_unit_patrol_to(ptile);
2791 break;
2792 case HOVER_ACT_SEL_TGT:
2793 do_unit_act_sel_vs(ptile);
2794 break;
2795 case HOVER_GOTO_SEL_TGT:
2797 do_unit_goto(ptile);
2798 break;
2799 }
2800
2803 } else if (qtype != SELECT_POPUP && qtype != SELECT_APPEND) {
2804 /* Bypass stack or city popup if quickselect is specified. */
2805 struct unit *qunit = quickselect(ptile, qtype);
2806
2807 if (qunit) {
2809 maybe_goto = gui_options.keyboardless_goto;
2810 }
2811 } else if (NULL != pcity
2813 /* Otherwise use popups. */
2814 popup_city_dialog(pcity);
2815 } else if (unit_list_size(ptile->units) == 0
2816 && NULL == pcity
2817 && get_num_units_in_focus() > 0) {
2818 maybe_goto = gui_options.keyboardless_goto;
2819 } else if (unit_list_size(ptile->units) == 1
2820 && !get_transporter_occupancy(unit_list_get(ptile->units, 0))) {
2821 struct unit *punit = unit_list_get(ptile->units, 0);
2822
2824 if (can_unit_do_activity_client(punit, ACTIVITY_IDLE)) {
2825 maybe_goto = gui_options.keyboardless_goto;
2826 if (qtype == SELECT_APPEND) {
2828 } else {
2830 }
2831 }
2832 } else if (pcity) {
2833 /* Don't hide the unit in the city. */
2835 }
2836 } else if (unit_list_size(ptile->units) > 0) {
2837 /* The stack list is always popped up, even if it includes enemy units.
2838 * If the server doesn't want the player to know about them it shouldn't
2839 * tell them! The previous behavior would only pop up the stack if you
2840 * owned a unit on the tile. This gave cheating clients an advantage,
2841 * and also showed you allied units if (and only if) you had a unit on
2842 * the tile (inconsistent). */
2844 }
2845
2846 /* See mapctrl_common.c */
2847 keyboardless_goto_start_tile = maybe_goto ? ptile : NULL;
2848 keyboardless_goto_button_down = maybe_goto;
2850}
2851
2852/**********************************************************************/
2857static struct unit *quickselect(struct tile *ptile,
2858 enum quickselect_type qtype)
2859{
2860 int listsize = unit_list_size(ptile->units);
2861 struct unit *panytransporter = NULL,
2862 *panymovesea = NULL, *panysea = NULL,
2863 *panymoveland = NULL, *panyland = NULL,
2864 *panymoveunit = NULL, *panyunit = NULL;
2865
2866 fc_assert_ret_val(qtype > SELECT_POPUP, NULL);
2867
2868 if (qtype == SELECT_FOCUS) {
2869 return head_of_units_in_focus();
2870 }
2871
2872 if (listsize == 0) {
2873 return NULL;
2874 } else if (listsize == 1) {
2875 struct unit *punit = unit_list_get(ptile->units, 0);
2876 return (unit_owner(punit) == client.conn.playing) ? punit : NULL;
2877 }
2878
2879 /* Quickselect priorities. Units with moves left
2880 * before exhausted. Focus unit is excluded.
2881 *
2882 * SEA: Transporter
2883 * Sea unit
2884 * Any unit
2885 *
2886 * LAND: Military land unit
2887 * Non-combatant
2888 * Sea unit
2889 * Any unit
2890 */
2891
2892 unit_list_iterate(ptile->units, punit) {
2894 continue;
2895 }
2896 if (qtype == SELECT_SEA) {
2897 /* Transporter. */
2899 if (punit->moves_left > 0) {
2900 return punit;
2901 } else if (!panytransporter) {
2902 panytransporter = punit;
2903 }
2904 }
2905 /* Any sea, pref. moves left. */
2906 else if (utype_move_type(unit_type_get(punit)) == UMT_SEA) {
2907 if (punit->moves_left > 0) {
2908 if (!panymovesea) {
2909 panymovesea = punit;
2910 }
2911 } else if (!panysea) {
2912 panysea = punit;
2913 }
2914 }
2915 } else if (qtype == SELECT_LAND) {
2916 if (utype_move_type(unit_type_get(punit)) == UMT_LAND) {
2917 if (punit->moves_left > 0) {
2918 if (is_military_unit(punit)) {
2919 return punit;
2920 } else if (!panymoveland) {
2921 panymoveland = punit;
2922 }
2923 } else if (!panyland) {
2924 panyland = punit;
2925 }
2926 }
2927 else if (utype_move_type(unit_type_get(punit)) == UMT_SEA) {
2928 if (punit->moves_left > 0) {
2929 panymovesea = punit;
2930 } else {
2931 panysea = punit;
2932 }
2933 }
2934 }
2935 if (punit->moves_left > 0 && !panymoveunit) {
2936 panymoveunit = punit;
2937 }
2938 if (!panyunit) {
2939 panyunit = punit;
2940 }
2942
2943 if (qtype == SELECT_SEA) {
2944 if (panytransporter) {
2945 return panytransporter;
2946 } else if (panymovesea) {
2947 return panymovesea;
2948 } else if (panysea) {
2949 return panysea;
2950 } else if (panymoveunit) {
2951 return panymoveunit;
2952 } else if (panyunit) {
2953 return panyunit;
2954 }
2955 }
2956 else if (qtype == SELECT_LAND) {
2957 if (panymoveland) {
2958 return panymoveland;
2959 } else if (panyland) {
2960 return panyland;
2961 } else if (panymovesea) {
2962 return panymovesea;
2963 } else if (panysea) {
2964 return panysea;
2965 } else if (panymoveunit) {
2966 return panymoveunit;
2967 } else if (panyunit) {
2968 return panyunit;
2969 }
2970 }
2971 return NULL;
2972}
2973
2974/**********************************************************************/
2978void do_unit_goto(struct tile *ptile)
2979{
2983
2986 return;
2987 }
2988
2989 if (is_valid_goto_draw_line(ptile)) {
2991 } else {
2992 create_event(ptile, E_BAD_COMMAND, ftc_client,
2993 _("Didn't find a route to the destination!"));
2994 }
2995}
2996
2997/**********************************************************************/
3000void do_unit_paradrop_to(struct unit *punit, struct tile *ptile)
3001{
3002 struct action *paradrop_action = NULL;
3003
3004 action_iterate(act_id) {
3005 struct action *paction = action_by_number(act_id);
3006
3007 if (!(action_has_result(paction, ACTRES_PARADROP_CONQUER)
3008 || action_has_result(paction, ACTRES_PARADROP))) {
3009 /* Not relevant. */
3010 continue;
3011 }
3012
3015 tile_city(ptile), NULL,
3016 ptile, NULL))) {
3017 if (paradrop_action == NULL) {
3018 /* This is the first possible paradrop action. */
3019 paradrop_action = paction;
3020 } else {
3021 /* More than one paradrop action may be possible. The user must
3022 * choose. Have the server record that an action decision is wanted
3023 * for this unit so the dialog will be brought up. */
3025 USSDT_QUEUE, tile_index(ptile));
3026 return;
3027 }
3028 }
3030
3031 if (paradrop_action != NULL) {
3032 request_do_action(paradrop_action->id, punit->id,
3033 tile_index(ptile), 0 , "");
3034 }
3035}
3036
3037/**********************************************************************/
3040void do_unit_patrol_to(struct tile *ptile)
3041{
3042 if (is_valid_goto_draw_line(ptile)
3045 } else {
3046 create_event(ptile, E_BAD_COMMAND, ftc_client,
3047 _("Didn't find a route to the destination!"));
3048 }
3049
3051}
3052
3053/**********************************************************************/
3056void do_unit_connect(struct tile *ptile,
3057 enum unit_activity activity,
3058 struct extra_type *tgt)
3059{
3060 if (is_valid_goto_draw_line(ptile)) {
3061 send_connect_route(activity, tgt);
3062 } else {
3063 create_event(ptile, E_BAD_COMMAND, ftc_client,
3064 _("Didn't find a route to the destination!"));
3065 }
3066
3068}
3069
3070/**********************************************************************/
3074{
3075 struct unit_list *punits = get_units_in_focus();
3077
3078 switch (hover_state) {
3079 case HOVER_GOTO_SEL_TGT:
3083 break;
3084 case HOVER_GOTO:
3085 case HOVER_PATROL:
3086 case HOVER_CONNECT:
3087 if (goto_pop_waypoint()) {
3088 break;
3089 }
3090 fc__fallthrough; /* else fall through: */
3091 case HOVER_PARADROP:
3092 case HOVER_ACT_SEL_TGT:
3095
3099 break;
3100 case HOVER_NONE:
3101 break;
3102 };
3103}
3104
3105/**********************************************************************/
3110{
3112
3113 if (capital) {
3114 /* Center on the tile, and pop up the crosshair overlay. */
3117 } else {
3118 create_event(NULL, E_BAD_COMMAND, ftc_client,
3119 _("Oh my! You seem to have no capital!"));
3120 }
3121}
3122
3123/**********************************************************************/
3127{
3129}
3130
3131/**********************************************************************/
3135{
3136 int i = 0;
3137
3138 /* Could use unit_list_copy here instead. Just having safe genlists
3139 * wouldn't be sufficient since we don't want to skip units already
3140 * removed from focus... */
3142 if (i == 0) {
3144 } else {
3146 }
3147 i++;
3149}
3150
3151/**********************************************************************/
3155void key_unit_move(enum direction8 gui_dir)
3156{
3158 enum direction8 map_dir = gui_to_map_dir(gui_dir);
3159
3162}
3163
3164/**********************************************************************/
3173
3174/**********************************************************************/
3178{
3180 if (unit_can_do_action(punit, ACTION_HELP_WONDER)) {
3181 request_unit_caravan_action(punit, ACTION_HELP_WONDER);
3182 }
3184}
3185
3186/**********************************************************************/
3189void key_unit_connect(enum unit_activity activity,
3190 struct extra_type *tgt)
3191{
3192 request_unit_connect(activity, tgt);
3193}
3194
3195/**********************************************************************/
3199{
3200 struct tile *ptile;
3201
3204 && (ptile = unit_tile(punit))) {
3205 /* Have the server record that an action decision is wanted for this
3206 * unit. */
3208 USSDT_QUEUE, tile_index(ptile));
3209 }
3211}
3212
3213/**********************************************************************/
3221{
3222 struct unit_list *punits = get_units_in_focus();
3223
3225 /* The 2nd key press means that the actor should target its own
3226 * tile. */
3228
3229 /* Target tile selected. Clean up hover state. */
3231 update_unit_info_label(punits);
3232
3233 return;
3234 } else if (hover_state == HOVER_GOTO_SEL_TGT) {
3236
3237 /* We don't support long range actions in the middle of orders yet so
3238 * send it at once. */
3240
3241 /* Target tile selected. Clean up hover state. */
3243 update_unit_info_label(punits);
3244
3245 return;
3246 } else if (hover_state == HOVER_GOTO
3248 struct action *paction = action_by_number(goto_last_action);
3249
3250 create_event(unit_tile(unit_list_get(punits, 0)), E_BEGINNER_HELP,
3251 ftc_client,
3252 /* TRANS: Perform action inside a goto. */
3253 _("Click on a tile to do %s against it."),
3254 action_name_translation(paction));
3255
3260
3261 return;
3262 }
3263
3264 create_event(unit_tile(unit_list_get(punits, 0)), E_BEGINNER_HELP,
3265 ftc_client,
3266 /* TRANS: "Do..." action selection dialog target. */
3267 _("Click on a tile to act against it. "
3268 "Press 'd' again to act against own tile."));
3269
3270 set_hover_state(punits, HOVER_ACT_SEL_TGT, ACTIVITY_LAST, NULL,
3272}
3273
3274/**********************************************************************/
3278{
3280}
3281
3282/**********************************************************************/
3286{
3288}
3289
3290/**********************************************************************/
3297
3298/**********************************************************************/
3302{
3304}
3305
3306/**********************************************************************/
3310{
3312 /* TODO: Is falling back on ACTION_MARKETPLACE if not able to establish
3313 * a trade route trade a good idea or an unplecant surprice? */
3314 if (unit_can_do_action(punit, ACTION_TRADE_ROUTE)) {
3315 request_unit_caravan_action(punit, ACTION_TRADE_ROUTE);
3316 }
3318}
3319
3320/**********************************************************************/
3324{
3325 struct unit *pnext_focus = NULL, *plast;
3326
3328 if ((plast = request_unit_unload_all(punit))) {
3329 pnext_focus = plast;
3330 }
3332
3333 if (pnext_focus) {
3335 /* Unfocus the ships, and advance the focus to the last unloaded unit.
3336 * If there is no unit unloaded (which shouldn't happen, but could if
3337 * the caller doesn't check if the transporter is loaded), the we
3338 * don't do anything. */
3341 unit_focus_set(pnext_focus);
3342 }
3343}
3344
3345/**********************************************************************/
3352
3353/**********************************************************************/
3362
3363/**********************************************************************/
3367{
3369 struct base_type *pbase =
3370 get_base_by_gui_type(BASE_GUI_AIRBASE, punit, unit_tile(punit));
3371
3372 if (pbase) {
3373 struct extra_type *pextra = base_extra_get(pbase);
3374
3375 request_new_unit_activity_targeted(punit, ACTIVITY_BASE, pextra);
3376 }
3378}
3379
3380/**********************************************************************/
3384{
3386 if (can_unit_do_activity_client(punit, ACTIVITY_EXPLORE)) {
3387 request_unit_ssa_set(punit, SSA_AUTOEXPLORE);
3388 }
3390}
3391
3392/**********************************************************************/
3404
3405/**********************************************************************/
3414
3415/**********************************************************************/
3419{
3420 key_unit_gen_clean(ACTIVITY_FALLOUT, ERM_CLEANFALLOUT);
3421}
3422
3423/**********************************************************************/
3427{
3429 if (can_unit_do_activity_client(punit, ACTIVITY_FORTIFYING)) {
3430 request_new_unit_activity(punit, ACTIVITY_FORTIFYING);
3431 }
3433}
3434
3435/**********************************************************************/
3439{
3441 struct base_type *pbase =
3442 get_base_by_gui_type(BASE_GUI_FORTRESS, punit, unit_tile(punit));
3443
3444 if (pbase) {
3445 struct extra_type *pextra = base_extra_get(pbase);
3446
3447 request_new_unit_activity_targeted(punit, ACTIVITY_BASE, pextra);
3448 }
3450}
3451
3452/**********************************************************************/
3461
3462/**********************************************************************/
3465static void key_unit_extra(enum unit_activity act, enum extra_cause cause)
3466{
3469 cause,
3471 punit);
3472
3475 }
3477}
3478
3479/**********************************************************************/
3482static void key_unit_gen_clean(enum unit_activity act,
3483 enum extra_rmcause rmcause)
3484{
3487 rmcause,
3489 punit);
3490
3491 if (tgt != NULL
3494 }
3496}
3497
3498/**********************************************************************/
3502{
3503 key_unit_extra(ACTIVITY_IRRIGATE, EC_IRRIGATION);
3504}
3505
3506/**********************************************************************/
3510{
3512 if (can_unit_do_activity_client(punit, ACTIVITY_CULTIVATE)) {
3513 request_new_unit_activity(punit, ACTIVITY_CULTIVATE);
3514 }
3516}
3517
3518/**********************************************************************/
3522{
3523 key_unit_extra(ACTIVITY_MINE, EC_MINE);
3524}
3525
3526/**********************************************************************/
3530{
3532 if (can_unit_do_activity_client(punit, ACTIVITY_PLANT)) {
3533 request_new_unit_activity(punit, ACTIVITY_PLANT);
3534 }
3536}
3537
3538/**********************************************************************/
3542{
3544 if (can_unit_do_activity_client(punit, ACTIVITY_PILLAGE)) {
3546 }
3548}
3549
3550/**********************************************************************/
3554{
3557 ERM_CLEANPOLLUTION,
3559 punit);
3560
3561 if (tgt != NULL
3562 && can_unit_do_activity_targeted_client(punit, ACTIVITY_POLLUTION, tgt)) {
3563 request_new_unit_activity_targeted(punit, ACTIVITY_POLLUTION, tgt);
3564 } else {
3566 ERM_CLEANFALLOUT,
3568 punit);
3569
3570 if (tgt != NULL
3571 && can_unit_do_activity_targeted_client(punit, ACTIVITY_FALLOUT, tgt)) {
3572 request_new_unit_activity_targeted(punit, ACTIVITY_FALLOUT, tgt);
3573 }
3574 }
3576}
3577
3578/**********************************************************************/
3582{
3583 key_unit_gen_clean(ACTIVITY_POLLUTION, ERM_CLEANPOLLUTION);
3584}
3585
3586/**********************************************************************/
3590{
3593 EC_ROAD,
3595 punit);
3596
3597 if (tgt != NULL
3598 && can_unit_do_activity_targeted_client(punit, ACTIVITY_GEN_ROAD, tgt)) {
3599 request_new_unit_activity_targeted(punit, ACTIVITY_GEN_ROAD, tgt);
3600 }
3602}
3603
3604/**********************************************************************/
3608{
3610 if (can_unit_do_activity_client(punit, ACTIVITY_SENTRY)) {
3611 request_new_unit_activity(punit, ACTIVITY_SENTRY);
3612 }
3614}
3615
3616/**********************************************************************/
3620{
3622 if (can_unit_do_activity_client(punit, ACTIVITY_TRANSFORM)) {
3623 request_new_unit_activity(punit, ACTIVITY_TRANSFORM);
3624 }
3626}
3627
3628/**********************************************************************/
3631void key_unit_assign_battlegroup(int battlegroup, bool append)
3632{
3634 && battlegroups >= 0 && battlegroup < MAX_NUM_BATTLEGROUPS) {
3635 if (!append) {
3637 if (!unit_is_in_focus(punit)) {
3640 USSDT_BATTLE_GROUP,
3643 unit_list_remove(battlegroups[battlegroup], punit);
3644 }
3646 }
3648 if (punit->battlegroup != battlegroup) {
3649 if (punit->battlegroup >= 0
3651 unit_list_remove(battlegroups[punit->battlegroup], punit);
3652 }
3653 punit->battlegroup = battlegroup;
3655 USSDT_BATTLE_GROUP,
3656 battlegroup);
3657 unit_list_append(battlegroups[battlegroup], punit);
3659 }
3661 unit_list_iterate(battlegroups[battlegroup], punit) {
3664 }
3665}
3666
3667/**********************************************************************/
3670void key_unit_select_battlegroup(int battlegroup, bool append)
3671{
3672 if (NULL != client.conn.playing && can_client_change_view()
3673 && battlegroups >= 0 && battlegroup < MAX_NUM_BATTLEGROUPS) {
3674 int i = 0;
3675
3676 if (unit_list_size(battlegroups[battlegroup]) == 0 && !append) {
3677 unit_focus_set(NULL);
3678 return;
3679 }
3680
3681 /* FIXME: this is very inefficient and can be improved. */
3682 unit_list_iterate(battlegroups[battlegroup], punit) {
3683 if (i == 0 && !append) {
3685 } else {
3687 }
3688 i++;
3690 }
3691}
3692
3693/**********************************************************************/
3700
3701/**********************************************************************/
3708
3709/**********************************************************************/
3713{
3715}
3716
3717/**********************************************************************/
3724
3725/**********************************************************************/
3732
3733/**********************************************************************/
3740
3741/**********************************************************************/
3748
3749/**********************************************************************/
3757
3758/**********************************************************************/
3766
3767/**********************************************************************/
3774
3775/**********************************************************************/
3783
3784/**********************************************************************/
3791
3792/**********************************************************************/
3796{
3798}
3799
3800/**********************************************************************/
3804{
3806}
3807
3808/**********************************************************************/
3815
3816/**********************************************************************/
3823
3824/**********************************************************************/
3828{
3830}
3831
3832/**********************************************************************/
3836{
3838}
3839
3840/**********************************************************************/
3844{
3846}
3847
3848/**********************************************************************/
3852{
3854}
3855
3856/**********************************************************************/
3860{
3862}
3863
3864/**********************************************************************/
3868{
3870}
3871
3872/**********************************************************************/
3876{
3878}
3879
3880/**********************************************************************/
3887
3888/**********************************************************************/
3895
3896/**********************************************************************/
3903
3904/**********************************************************************/
3911
3912/**********************************************************************/
3919
3920/**********************************************************************/
3927
3928/**********************************************************************/
3938
3939/**********************************************************************/
3942void finish_city(struct tile *ptile, const char *name)
3943{
3944 unit_list_iterate(ptile->units, punit) {
3946 /* Unit will disappear only in case city building still success.
3947 * Cancel city building status just in case something has changed
3948 * to prevent city building in the meanwhile and unit will remain
3949 * alive. */
3951 request_do_action(ACTION_FOUND_CITY, punit->id, ptile->index,
3952 0, name);
3953 }
3955}
3956
3957/**********************************************************************/
3961void cancel_city(struct tile *ptile)
3962{
3963 unit_list_iterate(ptile->units, punit) {
3966}
const char * action_name_translation(const struct action *action)
Definition actions.c:1890
const char * action_id_name_translation(action_id act_id)
Definition actions.c:1910
struct act_prob action_prob_self(const struct unit *actor_unit, const action_id act_id)
Definition actions.c:6380
bool action_prob_possible(const struct act_prob probability)
Definition actions.c:6707
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:6402
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:6225
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:6141
struct act_prob action_prob_vs_city(const struct civ_map *nmap, const struct unit *actor_unit, const action_id act_id, const struct city *target_city)
Definition actions.c:5870
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:6309
bool action_id_exists(const action_id act_id)
Definition actions.c:1697
struct act_prob action_prob_vs_unit(const struct civ_map *nmap, const struct unit *actor_unit, const action_id act_id, const struct unit *target_unit)
Definition actions.c:5953
#define action_id_univs_not_blocking(act_id, act_uni, tgt_uni)
Definition actions.h:950
#define action_by_result_iterate(_paction_, _result_)
Definition actions.h:488
static struct action * action_by_number(action_id act_id)
Definition actions.h:638
#define action_has_result(_act_, _res_)
Definition actions.h:448
#define action_id_get_role(act_id)
Definition actions.h:708
#define action_by_result_iterate_end
Definition actions.h:492
#define action_iterate_end
Definition actions.h:472
#define action_iterate(_act_)
Definition actions.h:467
#define action_id_get_target_kind(act_id)
Definition actions.h:655
#define action_id_has_result_safe(act_id, result)
Definition actions.h:668
#define ACTION_NONE
Definition actions.h:293
void astr_free(struct astring *astr)
Definition astring.c:153
static const char * astr_str(const struct astring *astr) fc__attribute((nonnull(1)))
Definition astring.h:93
#define ASTRING_INIT
Definition astring.h:44
void audio_play_sound(const char *const tag, const char *const alt_tag)
Definition audio.c:521
struct extra_type * base_extra_get(const struct base_type *pbase)
Definition base.c:101
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
#define BV_CLR_ALL(bv)
Definition bitvector.h:95
#define BV_SET(bv, bit)
Definition bitvector.h:81
static bool is_enemy_city_tile(const struct tile *ptile, const struct player *pplayer)
Definition city.h:705
void popup_city_dialog(struct city *pcity)
int client_player_number(void)
void send_turn_done(void)
struct civclient client
enum client_states client_state(void)
bool can_client_issue_orders(void)
bool client_has_player(void)
bool is_server_busy(void)
bool can_client_change_view(void)
#define client_player()
@ C_S_RUNNING
Definition client_main.h:47
@ C_S_OVER
Definition client_main.h:48
enum direction8 gui_to_map_dir(enum direction8 gui_dir)
Definition climap.c:59
void create_event(struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
Definition climisc.c:1075
bool can_units_do_connect(struct unit_list *punits, enum unit_activity activity, struct extra_type *tgt)
Definition climisc.c:1224
bool can_unit_attack_tile(const struct unit *punit, const struct action *paction, const struct tile *dest_tile)
Definition combat.c:271
double blink_turn_done_button(void)
Definition control.c:907
void key_coastline_toggle(void)
Definition control.c:3803
void key_irrigation_toggle(void)
Definition control.c:3819
void request_toggle_huts(void)
Definition control.c:2505
void key_unit_sentry(void)
Definition control.c:3607
void request_toggle_city_outlines(void)
Definition control.c:2258
void key_unit_road(void)
Definition control.c:3589
void request_unit_airlift(struct unit *punit, struct city *pcity)
Definition control.c:1512
void do_move_unit(struct unit *punit, struct unit *target_unit)
Definition control.c:2662
void request_toggle_resources(void)
Definition control.c:2492
void request_toggle_city_names(void)
Definition control.c:2336
void key_recall_previous_focus_unit(void)
Definition control.c:3134
void request_unit_non_action_move(struct unit *punit, struct tile *dest_tile)
Definition control.c:1733
void request_toggle_unit_stack_size(void)
Definition control.c:2401
void key_unit_pollution(void)
Definition control.c:3581
bool unit_is_in_focus(const struct unit *punit)
Definition control.c:384
void key_city_output_toggle(void)
Definition control.c:3704
void request_toggle_focus_unit(void)
Definition control.c:2583
void request_toggle_city_output(void)
Definition control.c:2271
void request_unit_return(struct unit *punit)
Definition control.c:1521
void request_unit_fortify(struct unit *punit)
Definition control.c:2213
void key_unit_build_city(void)
Definition control.c:3167
void key_editor_recalculate_borders(void)
Definition control.c:3923
struct unit * request_unit_unload_all(struct unit *punit)
Definition control.c:1480
void key_roads_rails_toggle(void)
Definition control.c:3811
void request_unit_caravan_action(struct unit *punit, action_id action)
Definition control.c:2121
void action_selection_no_longer_in_progress(const int old_actor_id)
Definition control.c:1032
void request_toggle_roads_rails(void)
Definition control.c:2440
enum unit_orders goto_last_order
Definition control.c:96
void request_units_wait(struct unit_list *punits)
Definition control.c:2623
void request_unit_wakeup(struct unit *punit)
Definition control.c:1569
struct unit * get_focus_unit_on_tile(const struct tile *ptile)
Definition control.c:392
void key_focus_unit_toggle(void)
Definition control.c:3899
void request_toggle_map_grid(void)
Definition control.c:2284
void action_decision_request(struct unit *actor_unit)
Definition control.c:1083
void control_free(void)
Definition control.c:154
void request_toggle_mines(void)
Definition control.c:2466
void set_units_in_combat(struct unit *pattacker, struct unit *pdefender)
Definition control.c:1013
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
void key_unit_action_select(void)
Definition control.c:3198
void key_unit_auto_explore(void)
Definition control.c:3383
static int action_selection_in_progress_for
Definition control.c:119
static void do_disband_alternative(void *p)
Definition control.c:1870
void key_cancel_action(void)
Definition control.c:3073
void request_toggle_city_buycost(void)
Definition control.c:2375
void key_unit_auto_settle(void)
Definition control.c:3396
void clear_hover_state(void)
Definition control.c:323
void request_toggle_map_native(void)
Definition control.c:2310
void request_unit_patrol(void)
Definition control.c:2179
int num_units_below
Definition control.c:76
void key_unit_connect(enum unit_activity activity, struct extra_type *tgt)
Definition control.c:3189
void key_city_full_bar_toggle(void)
Definition control.c:3736
void request_unit_load(struct unit *pcargo, struct unit *ptrans, struct tile *ptile)
Definition control.c:2056
void key_bases_toggle(void)
Definition control.c:3835
void do_map_click(struct tile *ptile, enum quickselect_type qtype)
Definition control.c:2768
static void key_unit_extra(enum unit_activity act, enum extra_cause cause)
Definition control.c:3465
void key_map_native_toggle(void)
Definition control.c:3728
void request_toggle_map_borders(void)
Definition control.c:2297
void key_resources_toggle(void)
Definition control.c:3843
static struct unit * punit_attacking
Definition control.c:105
void unit_focus_add(struct unit *punit)
Definition control.c:557
void unit_focus_set(struct unit *punit)
Definition control.c:502
static void do_unit_act_sel_vs(struct tile *ptile)
Definition control.c:2753
void request_unit_goto(enum unit_orders last_order, action_id act_id, int sub_tgt_id)
Definition control.c:1103
void do_unit_paradrop_to(struct unit *punit, struct tile *ptile)
Definition control.c:3000
bool should_ask_server_for_actions(const struct unit *punit)
Definition control.c:334
int goto_last_tgt
Definition control.c:94
struct extra_type * connect_tgt
Definition control.c:91
void key_unit_paradrop(void)
Definition control.c:3293
static bool can_units_attack_at(struct unit_list *punits, const struct tile *ptile)
Definition control.c:1170
struct unit_list * get_units_in_focus(void)
Definition control.c:177
void request_do_action(action_id action, int actor_id, int target_id, int sub_tgt, const char *name)
Definition control.c:1675
void key_end_turn(void)
Definition control.c:3126
void request_unit_disband(struct unit *punit)
Definition control.c:1975
void request_toggle_irrigation(void)
Definition control.c:2453
static struct unit_list * current_focus
Definition control.c:79
static struct unit_list * previous_focus
Definition control.c:83
void unit_focus_advance(void)
Definition control.c:671
static void key_unit_gen_clean(enum unit_activity act, enum extra_rmcause rmcause)
Definition control.c:3482
void request_unit_autosettlers(const struct unit *punit)
Definition control.c:2041
void request_unit_pillage(struct unit *punit)
Definition control.c:2224
void request_center_focus_unit(void)
Definition control.c:2610
void unit_focus_urgent(struct unit *punit)
Definition control.c:207
void key_unit_shields_toggle(void)
Definition control.c:3891
void key_city_productions_toggle(void)
Definition control.c:3770
bool can_unit_do_connect(struct unit *punit, enum unit_activity activity, struct extra_type *tgt)
Definition control.c:1384
void key_unit_build_wonder(void)
Definition control.c:3177
void key_unit_plant(void)
Definition control.c:3529
void key_unit_fortress(void)
Definition control.c:3438
void key_unit_mine(void)
Definition control.c:3521
void request_unit_change_homecity(struct unit *punit)
Definition control.c:1994
void request_toggle_fog_of_war(void)
Definition control.c:2596
void key_unit_pillage(void)
Definition control.c:3541
void request_unit_unload(struct unit *pcargo)
Definition control.c:2092
void key_editor_toggle_fogofwar(void)
Definition control.c:3932
static void client_disband_unit_data_destroy(void *p)
Definition control.c:1860
void request_unit_ssa_set(const struct unit *punit, enum server_side_agent agent)
Definition control.c:2028
static struct unit * find_best_focus_candidate(bool accept_current)
Definition control.c:634
void request_action_details(action_id action, int actor_id, int target_id)
Definition control.c:1695
static struct unit * quickselect(struct tile *ptile, enum quickselect_type qtype)
Definition control.c:2857
enum unit_activity connect_activity
Definition control.c:90
void request_toggle_units(void)
Definition control.c:2544
void request_new_unit_activity_targeted(struct unit *punit, enum unit_activity act, struct extra_type *tgt)
Definition control.c:1837
void update_unit_pix_label(struct unit_list *punitlist)
Definition control.c:966
void key_unit_irrigate(void)
Definition control.c:3501
void request_unit_build_city(struct unit *punit)
Definition control.c:1714
void unit_change_battlegroup(struct unit *punit, int battlegroup)
Definition control.c:250
static struct unit_list * urgent_focus_queue
Definition control.c:86
void key_unit_unload_all(void)
Definition control.c:3323
void key_cities_toggle(void)
Definition control.c:3867
void key_unit_move(enum direction8 gui_dir)
Definition control.c:3155
void key_city_outlines_toggle(void)
Definition control.c:3696
void key_unit_homecity(void)
Definition control.c:3455
void request_unit_paradrop(struct unit_list *punits)
Definition control.c:2144
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
static int disband_unit_alternatives[3]
Definition control.c:69
void key_unit_patrol(void)
Definition control.c:3301
void request_toggle_city_full_bar(void)
Definition control.c:2323
void request_toggle_city_growth(void)
Definition control.c:2349
void key_unit_solid_bg_toggle(void)
Definition control.c:3883
void request_toggle_unit_solid_bg(void)
Definition control.c:2557
void key_terrain_toggle(void)
Definition control.c:3795
void request_unit_sentry(struct unit *punit)
Definition control.c:2202
void key_unit_wakeup_others(void)
Definition control.c:3356
bool non_ai_unit_focus
Definition control.c:125
static struct unit * punit_defending
Definition control.c:106
static struct tile * find_a_focus_unit_tile_to_center_on(void)
Definition control.c:414
enum cursor_hover_state hover_state
Definition control.c:89
void key_unit_stack_size_toggle(void)
Definition control.c:3787
static void store_previous_focus(void)
Definition control.c:194
void key_huts_toggle(void)
Definition control.c:3851
void key_fog_of_war_toggle(void)
Definition control.c:3907
void request_unit_connect(enum unit_activity activity, struct extra_type *tgt)
Definition control.c:1451
void clear_unit_orders(struct unit *punit)
Definition control.c:477
void control_init(void)
Definition control.c:137
void request_toggle_terrain(void)
Definition control.c:2414
void action_decision_clear_want(const int old_actor_id)
Definition control.c:1053
void key_unit_wait(void)
Definition control.c:3348
void key_units_toggle(void)
Definition control.c:3875
void do_unit_connect(struct tile *ptile, enum unit_activity activity, struct extra_type *tgt)
Definition control.c:3056
int goto_last_sub_tgt
Definition control.c:95
void unit_focus_remove(struct unit *punit)
Definition control.c:587
void request_toggle_bases(void)
Definition control.c:2479
void do_unit_patrol_to(struct tile *ptile)
Definition control.c:3040
void key_unit_trade_route(void)
Definition control.c:3309
void request_toggle_coastline(void)
Definition control.c:2427
void key_unit_select_battlegroup(int battlegroup, bool append)
Definition control.c:3670
void key_map_grid_toggle(void)
Definition control.c:3712
void finish_city(struct tile *ptile, const char *name)
Definition control.c:3942
static struct unit * punit_moving
Definition control.c:102
void key_pollution_toggle(void)
Definition control.c:3859
struct unit * head_of_units_in_focus(void)
Definition control.c:406
static bool is_activity_on_tile(struct tile *ptile, enum unit_activity activity)
Definition control.c:1290
struct unit * find_visible_unit(struct tile *ptile)
Definition control.c:805
static bool can_be_irrigated(const struct tile *ptile, const struct unit *punit)
Definition control.c:1361
void key_city_growth_toggle(void)
Definition control.c:3753
void key_unit_action_select_tgt(void)
Definition control.c:3220
void key_unit_fallout(void)
Definition control.c:3418
static struct unit_list * battlegroups[MAX_NUM_BATTLEGROUPS]
Definition control.c:99
void key_city_buycost_toggle(void)
Definition control.c:3762
int get_num_units_in_focus(void)
Definition control.c:185
void key_unit_transform(void)
Definition control.c:3619
void request_move_unit_direction(struct unit *punit, int dir)
Definition control.c:1777
static void current_focus_append(struct unit *punit)
Definition control.c:443
void key_unit_done(void)
Definition control.c:3277
static void current_focus_remove(struct unit *punit)
Definition control.c:463
static struct tile * hover_tile
Definition control.c:98
void key_city_trade_routes_toggle(void)
Definition control.c:3779
static void focus_units_changed(void)
Definition control.c:215
void request_toggle_city_trade_routes(void)
Definition control.c:2388
void unit_focus_set_and_select(struct unit *punit)
Definition control.c:621
void request_unit_convert(struct unit *punit)
Definition control.c:2018
void request_toggle_unit_shields(void)
Definition control.c:2570
void key_city_names_toggle(void)
Definition control.c:3744
void unit_register_battlegroup(struct unit *punit)
Definition control.c:270
void request_unit_select(struct unit_list *punits, enum unit_select_type_mode seltype, enum unit_select_location_mode selloc)
Definition control.c:1590
void unit_focus_update(void)
Definition control.c:772
void key_unit_airbase(void)
Definition control.c:3366
void key_unit_goto(void)
Definition control.c:3285
void control_mouse_cursor(struct tile *ptile)
Definition control.c:1188
void key_unit_convert(void)
Definition control.c:3408
void key_unit_clean(void)
Definition control.c:3553
void key_center_capital(void)
Definition control.c:3109
void wakeup_sentried_units(struct tile *ptile)
Definition control.c:1552
void request_toggle_cities(void)
Definition control.c:2531
void key_unit_fortify(void)
Definition control.c:3426
void key_editor_toggle(void)
Definition control.c:3915
void key_unit_assign_battlegroup(int battlegroup, bool append)
Definition control.c:3631
void request_unit_move_done(void)
Definition control.c:2636
void auto_center_on_focus_unit(void)
Definition control.c:430
void key_unit_cultivate(void)
Definition control.c:3509
double blink_active_unit(void)
Definition control.c:875
void request_unit_upgrade(struct unit *punit)
Definition control.c:2006
void control_unit_killed(struct unit *punit)
Definition control.c:226
void request_toggle_city_productions(void)
Definition control.c:2362
void cancel_city(struct tile *ptile)
Definition control.c:3961
static void ask_server_for_actions(struct unit *punit)
Definition control.c:361
void request_new_unit_activity(struct unit *punit, enum unit_activity act)
Definition control.c:1828
void request_toggle_pollution(void)
Definition control.c:2518
action_id goto_last_action
Definition control.c:93
void key_mines_toggle(void)
Definition control.c:3827
void do_unit_goto(struct tile *ptile)
Definition control.c:2978
void action_selection_next_in_focus(const int old_actor_id)
Definition control.c:1065
static bool can_ask_server_for_actions(void)
Definition control.c:347
void key_map_borders_toggle(void)
Definition control.c:3720
#define can_unit_do_activity_targeted_client(_punit_, _act_, _tgt_)
Definition control.h:42
#define MAX_NUM_UNITS_BELOW
Definition control.h:285
quickselect_type
Definition control.h:36
@ SELECT_LAND
Definition control.h:37
@ SELECT_APPEND
Definition control.h:37
@ SELECT_SEA
Definition control.h:37
@ SELECT_POPUP
Definition control.h:37
@ SELECT_FOCUS
Definition control.h:37
cursor_hover_state
Definition control.h:25
@ HOVER_GOTO
Definition control.h:27
@ HOVER_PARADROP
Definition control.h:28
@ HOVER_ACT_SEL_TGT
Definition control.h:31
@ HOVER_NONE
Definition control.h:26
@ HOVER_CONNECT
Definition control.h:29
@ HOVER_PATROL
Definition control.h:30
@ HOVER_GOTO_SEL_TGT
Definition control.h:32
#define can_unit_do_activity_client(_punit_, _act_)
Definition control.h:40
struct unit struct city struct unit * target_unit
Definition dialogs_g.h:55
struct unit * actor_unit
Definition dialogs_g.h:54
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs action_selection_no_longer_in_progress_gui_specific
Definition dialogs_g.h:68
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit * punit
Definition dialogs_g.h:73
struct unit struct city * target_city
Definition dialogs_g.h:55
int get_unit_bonus(const struct unit *punit, enum effect_type effect_type)
Definition effects.c:992
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
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
bool can_build_extra(const struct extra_type *pextra, const struct unit *punit, const struct tile *ptile)
Definition extras.c:507
#define extra_type_iterate(_p)
Definition extras.h:291
#define extra_deps_iterate(_reqs, _dep)
Definition extras.h:338
#define extra_type_iterate_end
Definition extras.h:297
#define is_extra_caused_by(e, c)
Definition extras.h:196
#define extra_index(_e_)
Definition extras.h:177
#define extra_deps_iterate_end
Definition extras.h:346
#define EXTRA_NONE
Definition extras.h:82
#define extra_road_get(_e_)
Definition extras.h:185
#define NO_TARGET
Definition fc_types.h:324
@ RPT_POSSIBLE
Definition fc_types.h:585
#define DIR8_ORIGIN
Definition fc_types.h:427
int action_id
Definition fc_types.h:359
#define MAX_EXTRA_TYPES
Definition fc_types.h:50
#define IDENTITY_NUMBER_ZERO
Definition fc_types.h:82
#define _(String)
Definition fcintl.h:67
const struct ft_color ftc_client
struct civ_game game
Definition game.c:57
bool is_player_phase(const struct player *pplayer, int phase)
Definition game.c:687
struct world wld
Definition game.c:58
struct unit * game_unit_by_number(int id)
Definition game.c:111
void exit_goto_state(void)
Definition goto.c:1019
bool goto_is_active(void)
Definition goto.c:1056
struct pf_path * path_to_nearest_allied_city(struct unit *punit)
Definition goto.c:1983
void send_patrol_route(void)
Definition goto.c:1647
bool is_valid_goto_draw_line(struct tile *dest_tile)
Definition goto.c:1335
bool goto_add_waypoint(void)
Definition goto.c:487
bool goto_pop_waypoint(void)
Definition goto.c:524
void send_connect_route(enum unit_activity activity, struct extra_type *tgt)
Definition goto.c:1713
void goto_unit_killed(struct unit *punit)
Definition goto.c:1037
void free_client_goto(void)
Definition goto.c:162
void enter_goto_state(struct unit_list *punits)
Definition goto.c:998
void send_goto_route(void)
Definition goto.c:1870
bool is_valid_goto_destination(const struct tile *ptile)
Definition goto.c:179
void request_orders_cleared(struct unit *punit)
Definition goto.c:1360
void send_goto_path(struct unit *punit, struct pf_path *path, struct unit_order *final_order)
Definition goto.c:1530
int action_selection_actor_unit(void)
void action_selection_close(void)
void refresh_unit_city_dialogs(struct unit *punit)
Definition citydlg.c:538
void unit_select_dialog_popup(struct tile *ptile)
Definition dialogs.c:382
void popup_pillage_dialog(struct unit *punit, bv_extras extras)
Definition dialogs.c:343
void real_focus_units_changed(void)
Definition gui_main.c:1955
void set_unit_icons_more_arrow(bool onoff)
Definition gui_main.c:1932
void set_unit_icon(int idx, struct unit *punit)
Definition gui_main.c:1902
void create_line_at_mouse_pos(void)
Definition mapctrl.c:347
void update_turn_done_button(bool do_restore)
Definition mapview.c:75
void put_cross_overlay_tile(struct tile *ptile)
Definition mapview.c:622
void update_unit_info_label(struct unit_list *punits)
Definition mapview.c:258
void update_mouse_cursor(enum cursor_type new_cursor_type)
Definition mapview.c:240
bool request_transport(struct unit *cargo, struct tile *ptile)
enum cursor_type mouse_cursor_type
Definition gui_mouse.c:46
const char * name
Definition inputfile.c:127
#define fc_assert_msg(condition, message,...)
Definition log.h:181
#define fc_assert_ret(condition)
Definition log.h:191
#define fc_assert(condition)
Definition log.h:176
#define fc_assert_ret_val(condition, val)
Definition log.h:194
#define log_error(message,...)
Definition log.h:103
int get_direction_for_step(const struct civ_map *nmap, const struct tile *start_tile, const struct tile *end_tile)
Definition map.c:1345
bool is_tiles_adjacent(const struct tile *tile0, const struct tile *tile1)
Definition map.c:929
bool same_pos(const struct tile *tile1, const struct tile *tile2)
Definition map.c:938
struct tile * mapstep(const struct civ_map *nmap, const struct tile *ptile, enum direction8 dir)
Definition map.c:369
void map_distance_vector(int *dx, int *dy, const struct tile *tile0, const struct tile *tile1)
Definition map.c:1071
#define iterate_outward(nmap, start_tile, max_dist, itr_tile)
Definition map.h:361
#define iterate_outward_end
Definition map.h:365
bool keyboardless_goto_button_down
void cancel_tile_hiliting(void)
bool keyboardless_goto_active
struct tile * keyboardless_goto_start_tile
void update_map_canvas_visible(void)
struct tile * get_center_tile_mapcanvas(void)
void move_unit_map_canvas(struct unit *punit, struct tile *src_tile, int dx, int dy)
void center_tile_mapcanvas(const struct tile *ptile)
void update_city_description(struct city *pcity)
void refresh_unit_mapcanvas(struct unit *punit, struct tile *ptile, bool full_refresh, bool write_to_screen)
bool tile_visible_and_not_on_border_mapcanvas(struct tile *ptile)
#define fc_malloc(sz)
Definition mem.h:34
void menus_update(void)
bool can_unit_exist_at_tile(const struct civ_map *nmap, const struct unit *punit, const struct tile *ptile)
Definition movement.c:304
bool can_unit_survive_at_tile(const struct civ_map *nmap, const struct unit *punit, const struct tile *ptile)
Definition movement.c:476
const struct option_set * server_optset
Definition options.c:4009
bool option_bool_get(const struct option *poption)
Definition options.c:772
struct client_options gui_options
Definition options.c:71
struct option * optset_option_by_name(const struct option_set *poptset, const char *name)
Definition options.c:406
void refresh_overview_canvas(void)
#define REQEST_PLAYER_INITIATED
Definition packets.h:70
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)
int dsend_packet_unit_sscs_set(struct connection *pc, int unit_id16, int unit_id32, enum unit_ss_data_type type, int value)
int send_packet_unit_orders(struct connection *pc, const struct packet_unit_orders *packet)
int send_packet_edit_recalculate_borders(struct connection *pc)
int dsend_packet_unit_get_actions(struct connection *pc, int actor_unit_id16, int actor_unit_id32, int target_unit_id16, int target_unit_id32, int target_tile_id, int target_extra_id, int request_kind)
int dsend_packet_unit_action_query(struct connection *pc, int actor_id16, int actor_id32, int target_id, action_id action_type, int request_kind)
int dsend_packet_unit_server_side_agent_set(struct connection *pc, int unit_id16, int unit_id32, enum server_side_agent agent)
int dsend_packet_unit_change_activity(struct connection *pc, int unit_id16, int unit_id32, enum unit_activity activity, int target)
int dsend_packet_city_name_suggestion_req(struct connection *pc, int unit_id16, int unit_id32)
int dsend_packet_edit_toggle_fogofwar(struct connection *pc, int player)
int dsend_packet_edit_mode(struct connection *pc, bool state)
const struct pf_position * pf_path_last_position(const struct pf_path *path)
void pf_path_destroy(struct pf_path *path)
struct unit * player_unit_by_number(const struct player *pplayer, int unit_id)
Definition player.c:1205
struct city * player_primary_capital(const struct player *pplayer)
Definition player.c:1313
bool can_player_see_units_in_city(const struct player *pplayer, const struct city *pcity)
Definition player.c:1113
bool can_player_see_city_internals(const struct player *pplayer, const struct city *pcity)
Definition player.c:1129
#define players_iterate_alive_end
Definition player.h:545
#define players_iterate_alive(_pplayer)
Definition player.h:540
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)
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
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
#define FC_INFINITY
Definition shared.h:36
action_id id
Definition actions.h:380
Definition agents.h:40
Definition city.h:309
int id
Definition city.h:315
enum capital_type capital
Definition city.h:317
struct packet_game_info info
Definition game.h:89
struct connection conn
Definition client_main.h:96
bool draw_native
Definition options.h:207
bool enable_cursor_changes
Definition options.h:166
bool auto_turn_done
Definition options.h:157
bool draw_specials
Definition options.h:199
bool draw_city_output
Definition options.h:186
bool draw_city_names
Definition options.h:188
bool draw_city_productions
Definition options.h:190
int smooth_move_unit_msec
Definition options.h:144
bool draw_mines
Definition options.h:197
bool draw_borders
Definition options.h:206
bool draw_fortress_airbase
Definition options.h:198
bool draw_city_buycost
Definition options.h:191
bool draw_unit_stack_size
Definition options.h:210
bool draw_irrigation
Definition options.h:196
bool draw_terrain
Definition options.h:193
bool draw_units
Definition options.h:203
bool auto_center_on_automated
Definition options.h:149
bool draw_fog_of_war
Definition options.h:205
bool draw_city_trade_routes
Definition options.h:192
bool unit_selection_clears_orders
Definition options.h:168
bool draw_unit_shields
Definition options.h:209
bool draw_cities
Definition options.h:202
bool draw_map_grid
Definition options.h:187
bool draw_city_growth
Definition options.h:189
bool draw_focus_unit
Definition options.h:204
bool draw_city_outlines
Definition options.h:185
bool draw_coastline
Definition options.h:194
bool popup_actor_arrival
Definition options.h:161
bool draw_full_citybar
Definition options.h:208
bool draw_roads_rails
Definition options.h:195
bool draw_pollution
Definition options.h:201
bool auto_center_on_unit
Definition options.h:148
bool solid_color_behind_units
Definition options.h:142
bool popup_last_move_to_allied
Definition options.h:163
bool keyboardless_goto
Definition options.h:165
struct player * playing
Definition connection.h:156
struct connection::@57::@62 client
int last_request_id_used
Definition connection.h:192
struct requirement_vector reqs
Definition extras.h:102
struct unit_order orders[MAX_LEN_ROUTE]
struct unit_list * units
Definition player.h:282
bool is_alive
Definition player.h:268
bool phase_done
Definition player.h:263
const struct unit * unit
Definition tile.h:49
int index
Definition tile.h:50
struct unit_list * units
Definition tile.h:57
Definition timing.c:81
enum unit_activity activity
Definition unit.h:94
enum unit_orders order
Definition unit.h:93
int action
Definition unit.h:100
enum direction8 dir
Definition unit.h:102
int target
Definition unit.h:97
int sub_target
Definition unit.h:98
Definition unit.h:138
enum action_decision action_decision_want
Definition unit.h:202
int battlegroup
Definition unit.h:191
enum unit_activity activity
Definition unit.h:157
int moves_left
Definition unit.h:150
int id
Definition unit.h:145
int hp
Definition unit.h:151
struct unit::@80::@82 client
bool asking_city_name
Definition unit.h:222
bool done_moving
Definition unit.h:181
struct tile * action_decision_tile
Definition unit.h:203
enum unit_focus_status focus_status
Definition unit.h:211
enum server_side_agent ssa_controller
Definition unit.h:172
enum universals_n kind
Definition fc_types.h:758
struct civ_map map
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
#define fc__fallthrough
Definition support.h:109
struct extra_type * get_preferred_pillage(bv_extras extras)
Definition terrain.c:538
int terrain_extra_build_time(const struct terrain *pterrain, enum unit_activity activity, const struct extra_type *tgt)
Definition terrain.c:682
#define T_UNKNOWN
Definition terrain.h:57
void tile_add_extra(struct tile *ptile, const struct extra_type *pextra)
Definition tile.c:940
void tile_virtual_destroy(struct tile *vtile)
Definition tile.c:1018
bool tile_has_road(const struct tile *ptile, const struct road_type *proad)
Definition tile.c:829
struct tile * tile_virtual_new(const struct tile *ptile)
Definition tile.c:966
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
#define tile_index(_pt_)
Definition tile.h:87
#define tile_hash_iterate(hash, ptile)
Definition tile.h:81
#define tile_terrain(_tile)
Definition tile.h:109
#define tile_hash_iterate_end
Definition tile.h:83
#define tile_continent(_tile)
Definition tile.h:91
#define tile_has_extra(ptile, pextra)
Definition tile.h:146
double get_focus_unit_toggle_timeout(const struct tileset *t)
Definition tilespec.c:6261
void toggle_focus_unit_state(struct tileset *t)
Definition tilespec.c:6293
void focus_unit_in_combat(struct tileset *t)
Definition tilespec.c:6282
cursor_type
Definition tilespec.h:285
@ CURSOR_GOTO
Definition tilespec.h:286
@ CURSOR_INVALID
Definition tilespec.h:291
@ CURSOR_PATROL
Definition tilespec.h:287
@ CURSOR_WAIT
Definition tilespec.h:295
@ CURSOR_SELECT
Definition tilespec.h:290
@ CURSOR_DEFAULT
Definition tilespec.h:297
@ CURSOR_PARADROP
Definition tilespec.h:288
@ CURSOR_NUKE
Definition tilespec.h:289
@ CURSOR_ATTACK
Definition tilespec.h:292
void timer_start(struct timer *t)
Definition timing.c:224
double timer_read_seconds(struct timer *t)
Definition timing.c:344
struct timer * timer_renew(struct timer *t, enum timer_timetype type, enum timer_use use)
Definition timing.c:176
@ TIMER_ACTIVE
Definition timing.h:45
@ TIMER_USER
Definition timing.h:41
int get_transporter_occupancy(const struct unit *ptrans)
Definition unit.c:1769
bool is_attack_unit(const struct unit *punit)
Definition unit.c:310
struct unit * unit_transport_get(const struct unit *pcargo)
Definition unit.c:2427
bool is_military_unit(const struct unit *punit)
Definition unit.c:322
bool could_unit_load(const struct unit *pcargo, const struct unit *ptrans)
Definition unit.c:719
bool can_unit_do_autosettlers(const struct unit *punit)
Definition unit.c:583
bool unit_can_do_action(const struct unit *punit, const action_id act_id)
Definition unit.c:331
int get_transporter_capacity(const struct unit *punit)
Definition unit.c:302
bool can_unit_paradrop(const struct civ_map *nmap, const struct unit *punit)
Definition unit.c:827
void unit_tile_set(struct unit *punit, struct tile *ptile)
Definition unit.c:1282
bool unit_transported(const struct unit *pcargo)
Definition unit.c:2411
bool can_unit_unload(const struct unit *pcargo, const struct unit *ptrans)
Definition unit.c:771
bool unit_has_orders(const struct unit *punit)
Definition unit.c:207
struct unit * transporter_for_unit(const struct unit *pcargo)
Definition unit.c:1898
#define unit_tile(_pu)
Definition unit.h:388
unit_focus_status
Definition unit.h:52
@ FOCUS_AVAIL
Definition unit.h:53
@ FOCUS_DONE
Definition unit.h:53
@ FOCUS_WAIT
Definition unit.h:53
#define BATTLEGROUP_NONE
Definition unit.h:190
unit_orders
Definition unit.h:37
@ ORDER_ACTION_MOVE
Definition unit.h:45
@ ORDER_ACTIVITY
Definition unit.h:41
@ ORDER_MOVE
Definition unit.h:39
@ ORDER_LAST
Definition unit.h:49
@ ORDER_PERFORM_ACTION
Definition unit.h:47
#define unit_owner(_pu)
Definition unit.h:387
#define MAX_NUM_BATTLEGROUPS
Definition unit.h:189
static bool is_non_allied_unit_tile(const struct tile *ptile, const struct player *pplayer)
Definition unit.h:423
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
#define unit_list_iterate_safe(unitlist, _unit)
Definition unitlist.h:39
#define unit_list_iterate_end
Definition unitlist.h:33
#define unit_list_both_iterate_end
Definition unitlist.h:37
#define unit_list_both_iterate(unitlist, plink, punit)
Definition unitlist.h:34
#define unit_list_iterate_safe_end
Definition unitlist.h:61
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:123
const char * unit_name_translation(const struct unit *punit)
Definition unittype.c:1621
enum unit_move_type utype_move_type(const struct unit_type *punittype)
Definition unittype.c:1603
bool utype_may_act_at_all(const struct unit_type *putype)
Definition unittype.c:431
struct unit_class * unit_class_get(const struct unit *punit)
Definition unittype.c:2546
bool unit_has_type_flag(const struct unit *punit, enum unit_type_flag_id flag)
Definition unittype.c:184
bool role_units_translations(struct astring *astr, int flag, bool alts)
Definition unittype.c:1720
void update_queue_connect_processing_finished_full(int request_id, uq_callback_t callback, void *data, uq_free_fn_t free_data_func)