Freeciv21
Develop your civilization from humble roots to a global empire
control.h
Go to the documentation of this file.
1 /*__ ___ ***************************************
2 / \ / \ Copyright (c) 1996-2020 Freeciv21 and Freeciv
3 \_ \ / __/ contributors. This file is part of Freeciv21.
4  _\ \ / /__ Freeciv21 is free software: you can redistribute it
5  \___ \____/ __/ and/or modify it under the terms of the GNU General
6  \_ _/ Public License as published by the Free Software
7  | @ @ \_ Foundation, either version 3 of the License,
8  | or (at your option) any later version.
9  _/ /\ You should have received a copy of the GNU
10  /o) (o/\ \_ General Public License along with Freeciv21.
11  \_____/ / If not, see https://www.gnu.org/licenses/.
12  \____/ ********************************************************/
13 #pragma once
14 
15 // common
16 #include "unitlist.h"
17 
27 };
28 
29 // Selecting unit from a stack without popup.
36 };
37 
38 void control_init();
39 void control_free();
40 void control_unit_killed(struct unit *punit);
41 
42 void unit_change_battlegroup(struct unit *punit, int battlegroup);
43 void unit_register_battlegroup(struct unit *punit);
44 
46 extern enum unit_activity connect_activity;
47 extern struct extra_type *connect_tgt;
49 extern int goto_last_tgt;
50 extern int goto_last_sub_tgt;
51 extern enum unit_orders goto_last_order;
52 extern bool non_ai_unit_focus;
53 
54 bool can_unit_do_connect(struct unit *punit, enum unit_activity activity,
55  struct extra_type *tgt);
56 
57 int check_recursive_road_connect(struct tile *ptile,
58  const struct extra_type *pextra,
59  const struct unit *punit,
60  const struct player *pplayer, int rec);
61 
62 void do_move_unit(struct unit *punit, struct unit *target_unit);
63 void do_unit_goto(struct tile *ptile);
64 void do_unit_paradrop_to(struct unit *punit, struct tile *ptile);
65 void do_unit_patrol_to(struct tile *ptile);
66 void do_unit_connect(struct tile *ptile, enum unit_activity activity,
67  struct extra_type *tgt);
68 void do_map_click(struct tile *ptile, enum quickselect_type qtype);
69 void control_mouse_cursor(struct tile *ptile);
70 
71 void set_hover_state(const std::vector<unit *> &units,
72  enum cursor_hover_state state,
73  enum unit_activity connect_activity,
74  struct extra_type *tgt, int last_tgt,
77 void clear_hover_state();
79 void request_unit_non_action_move(struct unit *punit,
80  struct tile *dest_tile);
81 void request_move_unit_direction(struct unit *punit, int dir);
82 void request_new_unit_activity(struct unit *punit, enum unit_activity act);
83 void request_new_unit_activity_targeted(struct unit *punit,
84  enum unit_activity act,
85  struct extra_type *tgt);
86 void request_unit_load(struct unit *pcargo, struct unit *ptransporter,
87  struct tile *ptile);
88 void request_unit_unload(struct unit *pcargo);
89 void request_unit_ssa_set(const struct unit *punit,
90  enum server_side_agent agent);
91 void request_unit_autosettlers(const struct unit *punit);
92 void request_unit_build_city(struct unit *punit);
94 void request_unit_change_homecity(struct unit *punit);
95 void request_unit_connect(enum unit_activity activity,
96  struct extra_type *tgt);
97 void request_unit_disband(struct unit *punit);
98 void request_unit_fortify(struct unit *punit);
99 void request_unit_goto(enum unit_orders last_order, action_id act_id,
100  int sub_tgt_id);
102 void request_unit_paradrop(const std::vector<unit *> &units);
103 void request_unit_patrol();
104 void request_unit_pillage(struct unit *punit);
105 void request_unit_sentry(struct unit *punit);
106 struct unit *request_unit_unload_all(struct unit *punit);
107 void request_unit_airlift(struct unit *punit, struct city *pcity);
108 void request_units_return();
109 void request_unit_upgrade(struct unit *punit);
110 void request_unit_convert(struct unit *punit);
111 void request_units_wait(const std::vector<unit *> &units);
112 void request_unit_wakeup(struct unit *punit);
113 
115 
117  SELLOC_TILE, // Tile.
118  SELLOC_CONT, // Continent.
119  SELLOC_WORLD // World.
120 };
121 
122 void request_unit_select(const std::vector<unit *> &punits,
123  enum unit_select_type_mode seltype,
124  enum unit_select_location_mode selloc);
125 
126 void request_do_action(action_id action, int actor_id, int target_id,
127  int sub_tgt, const char *name);
128 void request_action_details(action_id action, int actor_id, int target_id);
139 
140 void wakeup_sentried_units(struct tile *ptile);
141 void clear_unit_orders(struct unit *punit);
142 
143 bool unit_is_in_focus(const struct unit *punit);
144 struct unit *get_focus_unit_on_tile(const struct tile *ptile);
145 struct unit *head_of_units_in_focus();
146 std::vector<unit *> &get_units_in_focus();
148 
149 void unit_focus_set(struct unit *punit);
150 void unit_focus_set_and_select(struct unit *punit);
151 void unit_focus_add(struct unit *punit);
152 void unit_focus_urgent(struct unit *punit);
153 
154 void unit_focus_advance();
155 void unit_focus_update();
156 
157 void set_auto_center_enabled(bool enabled);
159 
160 unit *find_visible_unit(const ::tile *ptile);
161 void set_units_in_combat(struct unit *pattacker, struct unit *pdefender);
162 int blink_active_unit();
164 
165 bool should_ask_server_for_actions(const struct unit *punit);
166 void action_selection_no_longer_in_progress(const int old_actor_id);
167 void action_decision_clear_want(const int old_actor_id);
168 void action_selection_next_in_focus(const int old_actor_id);
169 void action_decision_request(struct unit *actor_unit);
170 
171 void key_cancel_action();
172 void key_center_capital();
173 void key_city_names_toggle();
178 void key_end_turn();
181 void key_map_grid_toggle();
183 void key_map_native_toggle();
185 void key_unit_move(enum direction8 gui_dir);
186 void key_unit_airbase();
187 void key_unit_auto_explore();
188 void key_unit_auto_settle();
189 void key_unit_connect(enum unit_activity activity, struct extra_type *tgt);
192 void key_unit_convert();
193 void key_unit_done();
194 void key_unit_fallout();
195 void key_unit_fortify();
196 void key_unit_fortress();
197 void key_unit_goto();
198 void key_unit_homecity();
199 void key_unit_irrigate();
200 void key_unit_cultivate();
201 void key_unit_mine();
202 void key_unit_plant();
203 void key_unit_patrol();
204 void key_unit_paradrop();
205 void key_unit_pillage();
206 void key_unit_sentry();
207 void key_unit_transform();
208 void key_unit_unload_all();
209 void key_unit_wait();
211 
212 void finish_city(struct tile *ptile, const char *name);
213 void cancel_city(struct tile *ptile);
void request_toggle_city_productions()
Toggle display of city productions.
Definition: control.cpp:2215
void request_unit_airlift(struct unit *punit, struct city *pcity)
Send unit airlift request to server.
Definition: control.cpp:1397
void do_move_unit(struct unit *punit, struct unit *target_unit)
Called to have the client move a unit from one location to another, updating the graphics if necessar...
Definition: control.cpp:2303
void request_unit_non_action_move(struct unit *punit, struct tile *dest_tile)
Order a unit to move to a neighboring tile without performing an action.
Definition: control.cpp:1618
void request_toggle_city_output()
Toggle display of worker output of cities on the map.
Definition: control.cpp:2137
void key_unit_plant()
Handle user 'plant' input.
Definition: control.cpp:3107
bool unit_is_in_focus(const struct unit *punit)
Return TRUE iff this unit is in focus.
Definition: control.cpp:364
std::vector< unit * > & get_units_in_focus()
Returns list of units currently in focus.
Definition: control.cpp:169
void key_unit_paradrop()
Handle user 'paradrop' input.
Definition: control.cpp:2901
void key_unit_goto()
Handle user 'unit goto' input.
Definition: control.cpp:2896
void request_units_wait(const std::vector< unit * > &units)
Set units in list to waiting focus and advance focus.
Definition: control.cpp:2266
void key_unit_homecity()
Handle user 'change homecity' input.
Definition: control.cpp:3041
void request_unit_fortify(struct unit *punit)
Try to fortify unit.
Definition: control.cpp:2077
void request_unit_caravan_action(struct unit *punit, action_id action)
Send request to do caravan action - establishing traderoute or helping in wonder building - to server...
Definition: control.cpp:1988
void action_selection_no_longer_in_progress(const int old_actor_id)
The action selection process is no longer in progres for the specified unit.
Definition: control.cpp:924
enum unit_orders goto_last_order
Definition: control.cpp:89
void request_unit_wakeup(struct unit *punit)
(RP:) un-sentry all my own sentried units on punit's tile
Definition: control.cpp:1476
void key_city_names_toggle()
Handle user 'toggle city names display' input.
Definition: control.cpp:3180
void action_decision_request(struct unit *actor_unit)
Request that the player makes a decision for the specified unit.
Definition: control.cpp:976
void key_unit_fallout()
Handle user 'clean fallout' input.
Definition: control.cpp:3004
unit_select_location_mode
Definition: control.h:116
@ SELLOC_CONT
Definition: control.h:118
@ SELLOC_TILE
Definition: control.h:117
@ SELLOC_WORLD
Definition: control.h:119
void key_unit_mine()
Handle user 'build mine' input.
Definition: control.cpp:3102
void key_unit_done()
Handle user 'unit done' input.
Definition: control.cpp:2891
void set_units_in_combat(struct unit *pattacker, struct unit *pdefender)
Adjusts way combatants are displayed suitable for combat.
Definition: control.cpp:905
int check_recursive_road_connect(struct tile *ptile, const struct extra_type *pextra, const struct unit *punit, const struct player *pplayer, int rec)
Fill orders to build recursive roads.
Definition: control.cpp:1188
void request_toggle_city_trade_routes()
Toggle display of city trade routes.
Definition: control.cpp:2241
void request_toggle_map_grid()
Toggle display of grid lines on the map.
Definition: control.cpp:2150
void key_unit_wait()
Handle user 'wait' input.
Definition: control.cpp:2937
void unit_focus_update()
If there is no unit currently in focus, or if the current unit in focus should not be in focus,...
Definition: control.cpp:718
unit * find_visible_unit(const ::tile *ptile)
Return a pointer to a visible unit, if there is one.
Definition: control.cpp:749
void key_unit_connect(enum unit_activity activity, struct extra_type *tgt)
Handle user pressing key for 'Connect' command.
Definition: control.cpp:2802
void do_map_click(struct tile *ptile, enum quickselect_type qtype)
Handles everything when the user clicked a tile.
Definition: control.cpp:2410
void key_unit_auto_settle()
Call to request (from the server) that the focus unit is put into autosettler mode.
Definition: control.cpp:2982
void control_init()
Called only by client_game_init() in client/client_main.c.
Definition: control.cpp:131
void key_unit_irrigate()
Handle user 'irrigate' input.
Definition: control.cpp:3082
void unit_focus_add(struct unit *punit)
Adds this unit to the list of units in focus.
Definition: control.cpp:534
void key_city_trade_routes_toggle()
Handle client request to toggle drawing of trade route information by the city name for cities visibl...
Definition: control.cpp:3203
void key_unit_wakeup_others()
Handle user 'wakeup others' input.
Definition: control.cpp:2942
void unit_focus_set(struct unit *punit)
Sets the focus unit directly.
Definition: control.cpp:479
struct unit * request_unit_unload_all(struct unit *punit)
Returns one of the unit of the transporter which can have focus next.
Definition: control.cpp:1364
void request_unit_goto(enum unit_orders last_order, action_id act_id, int sub_tgt_id)
Do a goto with an order at the end (or ORDER_LAST).
Definition: control.cpp:995
void key_center_capital()
Center the mapview on the player's named capital, or print a failure message.
Definition: control.cpp:2745
void do_unit_paradrop_to(struct unit *punit, struct tile *ptile)
Paradrop to a location.
Definition: control.cpp:2669
bool should_ask_server_for_actions(const struct unit *punit)
Returns TRUE iff the client should ask the server about what actions a unit can perform.
Definition: control.cpp:318
int goto_last_tgt
Definition: control.cpp:87
struct extra_type * connect_tgt
Definition: control.cpp:84
void request_do_action(action_id action, int actor_id, int target_id, int sub_tgt, const char *name)
Request an actor unit to do a specific action.
Definition: control.cpp:1563
void key_map_native_toggle()
Toggle native tiles on the mapview on/off based on a keypress.
Definition: control.cpp:3175
void request_unit_disband(struct unit *punit)
Send request to disband unit to server.
Definition: control.cpp:1853
void request_unit_autosettlers(const struct unit *punit)
Call to request (from the server) that the settler unit is put into autosettler mode.
Definition: control.cpp:1918
void request_unit_pillage(struct unit *punit)
Send pillage request to server.
Definition: control.cpp:2088
void unit_focus_urgent(struct unit *punit)
Store a priority focus unit.
Definition: control.cpp:193
bool can_unit_do_connect(struct unit *punit, enum unit_activity activity, struct extra_type *tgt)
Return whether the unit can connect with given activity (or with any activity if activity arg is set ...
Definition: control.cpp:1270
quickselect_type
Definition: control.h:30
@ SELECT_LAND
Definition: control.h:33
@ SELECT_APPEND
Definition: control.h:34
@ SELECT_SEA
Definition: control.h:32
@ SELECT_POPUP
Definition: control.h:31
@ SELECT_FOCUS
Definition: control.h:35
void request_unit_change_homecity(struct unit *punit)
Send request to change unit homecity to server.
Definition: control.cpp:1872
void request_unit_patrol()
Either start new patrol route planning, or add waypoint to current one.
Definition: control.cpp:2043
void key_unit_transform()
Handle user 'transform unit' input.
Definition: control.cpp:3143
void request_unit_load(struct unit *pcargo, struct unit *ptransporter, struct tile *ptile)
Send a request to the server that the cargo be loaded into the transporter.
Definition: control.cpp:1934
void request_unit_move_done()
Set focus units to FOCUS_DONE state.
Definition: control.cpp:2277
void request_toggle_map_native()
Toggle display of native tiles on the map.
Definition: control.cpp:2176
void key_unit_unload_all()
Handle user 'unload all' input.
Definition: control.cpp:2911
void request_unit_unload(struct unit *pcargo)
Send a request to the server that the cargo be unloaded from its current transporter.
Definition: control.cpp:1962
void key_unit_sentry()
Handle user 'sentry' input.
Definition: control.cpp:3131
void request_unit_ssa_set(const struct unit *punit, enum server_side_agent agent)
Call to request (from the server) that the unit is put under the control of the specified server side...
Definition: control.cpp:1906
void request_action_details(action_id action, int actor_id, int target_id)
Request data for follow up questions about an action the unit can perform.
Definition: control.cpp:1582
void request_unit_paradrop(const std::vector< unit * > &units)
Have the player select what tile to paradrop to.
Definition: control.cpp:2009
enum unit_activity connect_activity
Definition: control.cpp:83
void request_toggle_city_growth()
Toggle display of city growth (turns-to-grow)
Definition: control.cpp:2202
void request_new_unit_activity_targeted(struct unit *punit, enum unit_activity act, struct extra_type *tgt)
Send request for unit activity changing to server.
Definition: control.cpp:1721
void key_city_productions_toggle()
Handle user 'toggle city production display' input.
Definition: control.cpp:3197
void set_auto_center_enabled(bool enabled)
Allows disabling automatic map recentering.
Definition: control.cpp:417
void request_unit_build_city(struct unit *punit)
Player pressed 'b' or otherwise instructed unit to build or add to city.
Definition: control.cpp:1599
void unit_change_battlegroup(struct unit *punit, int battlegroup)
Change the battlegroup for this unit.
Definition: control.cpp:237
void key_unit_auto_explore()
Handle user 'autoexplore' input.
Definition: control.cpp:2969
void key_map_grid_toggle()
Handle user 'toggle map grid' input.
Definition: control.cpp:3165
void key_cancel_action()
The 'Escape' key.
Definition: control.cpp:2709
void key_city_buycost_toggle()
Toggles the showing of the buy cost of the current production in the city descriptions.
Definition: control.cpp:3192
void key_unit_convert()
Unit convert key pressed or respective menu entry selected.
Definition: control.cpp:2994
void control_free()
Called only by client_game_free() in client/client_main.c.
Definition: control.cpp:147
void key_unit_move(enum direction8 gui_dir)
Move the focus unit in the given direction.
Definition: control.cpp:2790
cursor_hover_state
Definition: control.h:18
@ HOVER_GOTO
Definition: control.h:20
@ HOVER_PARADROP
Definition: control.h:21
@ HOVER_ACT_SEL_TGT
Definition: control.h:24
@ HOVER_NONE
Definition: control.h:19
@ HOVER_CONNECT
Definition: control.h:22
@ HOVER_DEBUG_TILE
Definition: control.h:26
@ HOVER_PATROL
Definition: control.h:23
@ HOVER_GOTO_SEL_TGT
Definition: control.h:25
void request_unit_select(const std::vector< unit * > &punits, enum unit_select_type_mode seltype, enum unit_select_location_mode selloc)
Select all units based on the given list of units and the selection modes.
Definition: control.cpp:1484
void key_unit_action_select()
Handle user 'Do...' input.
Definition: control.cpp:2810
int get_num_units_in_focus()
Return the number of units currently in focus (0 or more).
Definition: control.cpp:174
void key_recall_previous_focus_unit()
Recall the previous focus unit(s).
Definition: control.cpp:2767
void request_center_focus_unit()
Center to focus unit.
Definition: control.cpp:2254
void key_unit_patrol()
Handle user 'patrol' input.
Definition: control.cpp:2906
void key_city_output_toggle()
Toggle drawing of city output produced by workers of the city.
Definition: control.cpp:3160
int blink_turn_done_button()
Blink the turn done button (if necessary).
Definition: control.cpp:857
void request_unit_sentry(struct unit *punit)
Try to sentry unit.
Definition: control.cpp:2066
bool non_ai_unit_focus
Definition: control.cpp:118
void key_unit_fortify()
Handle user 'fortify' input.
Definition: control.cpp:3012
enum cursor_hover_state hover_state
Definition: control.cpp:82
void request_unit_connect(enum unit_activity activity, struct extra_type *tgt)
Prompt player for entering destination point for unit connect (e.g.
Definition: control.cpp:1336
void clear_unit_orders(struct unit *punit)
Clear all orders for the given unit.
Definition: control.cpp:454
void key_unit_cultivate()
Handle user 'cultivate' input.
Definition: control.cpp:3090
void action_decision_clear_want(const int old_actor_id)
Have the server record that a decision no longer is wanted for the specified unit.
Definition: control.cpp:944
void do_unit_connect(struct tile *ptile, enum unit_activity activity, struct extra_type *tgt)
"Connect" to the given location.
Definition: control.cpp:2693
int goto_last_sub_tgt
Definition: control.cpp:88
struct unit * get_focus_unit_on_tile(const struct tile *ptile)
Return TRUE iff a unit on this tile is in focus.
Definition: control.cpp:373
void key_end_turn()
Handle user 'end turn' input.
Definition: control.cpp:2762
void do_unit_patrol_to(struct tile *ptile)
Patrol to a location.
Definition: control.cpp:2677
void request_toggle_city_buycost()
Toggle display of city buycost.
Definition: control.cpp:2228
void finish_city(struct tile *ptile, const char *name)
All units ready to build city to the tile should now proceed.
Definition: control.cpp:3208
void key_city_outlines_toggle()
Toggle drawing of city outlines.
Definition: control.cpp:3155
void unit_focus_advance()
This function may be called from packhand.c, via unit_focus_update(), as a result of packets indicati...
Definition: control.cpp:617
void key_unit_action_select_tgt()
Have the user select what action the unit(s) in focus should perform to the targets at the tile the u...
Definition: control.cpp:2837
void request_move_unit_direction(struct unit *punit, int dir)
This function is called whenever the player pressed an arrow key.
Definition: control.cpp:1660
void request_toggle_city_outlines()
Toggle display of city outlines on the map.
Definition: control.cpp:2124
unit_select_type_mode
Definition: control.h:114
@ SELTYPE_SINGLE
Definition: control.h:114
@ SELTYPE_ALL
Definition: control.h:114
@ SELTYPE_SAME
Definition: control.h:114
void unit_focus_set_and_select(struct unit *punit)
The only difference is that here we draw the "cross".
Definition: control.cpp:563
void request_unit_convert(struct unit *punit)
Sends unit convert packet.
Definition: control.cpp:1896
void clear_hover_state()
Clear current hover state (go to HOVER_NONE).
Definition: control.cpp:308
void unit_register_battlegroup(struct unit *punit)
Call this on new units to enter them in the battlegroup lists.
Definition: control.cpp:257
void request_units_return()
Return-and-recover for a particular unit.
Definition: control.cpp:1406
void control_mouse_cursor(struct tile *ptile)
Determines which mouse cursor should be used, according to hover_state, and the information gathered ...
Definition: control.cpp:1067
void set_hover_state(const std::vector< unit * > &units, enum cursor_hover_state state, enum unit_activity connect_activity, struct extra_type *tgt, int last_tgt, int goto_last_sub_tgt, action_id goto_last_action, enum unit_orders goto_last_order)
Enter the given hover state.
Definition: control.cpp:272
void request_toggle_map_borders()
Toggle display of national borders on the map.
Definition: control.cpp:2163
void wakeup_sentried_units(struct tile *ptile)
Wakes all owned sentried units on tile.
Definition: control.cpp:1458
void auto_center_on_focus_unit()
Center on the focus unit, if off-screen and auto_center_on_unit is true.
Definition: control.cpp:422
void key_unit_pillage()
Handle user 'pillage' input.
Definition: control.cpp:3119
void key_unit_fortress()
Handle user 'build base of class fortress' input.
Definition: control.cpp:3024
void request_unit_upgrade(struct unit *punit)
Send request to upgrade unit to server.
Definition: control.cpp:1884
void control_unit_killed(struct unit *punit)
Called when a unit is killed; this removes it from the control lists.
Definition: control.cpp:212
void request_toggle_city_names()
Toggle display of city names.
Definition: control.cpp:2189
void cancel_city(struct tile *ptile)
Do not build city after all.
Definition: control.cpp:3228
struct unit * head_of_units_in_focus()
Return head of focus units list.
Definition: control.cpp:387
void request_new_unit_activity(struct unit *punit, enum unit_activity act)
Send request for unit activity changing to server.
Definition: control.cpp:1712
action_id goto_last_action
Definition: control.cpp:86
void key_map_borders_toggle()
Toggle map borders on the mapview on/off based on a keypress.
Definition: control.cpp:3170
void do_unit_goto(struct tile *ptile)
Finish the goto mode and let the units stored in goto_map_list move to a given location.
Definition: control.cpp:2647
void key_city_growth_toggle()
Toggles the "show city growth turns" option by passing off the request to another function....
Definition: control.cpp:3186
void action_selection_next_in_focus(const int old_actor_id)
Move on to the next unit in focus that needs an action decision.
Definition: control.cpp:958
void key_unit_airbase()
Handle user 'build base of class airbase' input.
Definition: control.cpp:2952
int blink_active_unit()
Blink the active unit (if necessary).
Definition: control.cpp:827
int action_id
Definition: fc_types.h:306
const char * name
Definition: inputfile.cpp:118
Definition: city.h:291
Definition: player.h:231
Definition: tile.h:42
Definition: unit.h:134
enum unit_activity activity
Definition: unit.h:154
unit_orders
Definition: unit.h:31