Freeciv21
Develop your civilization from humble roots to a global empire
unit.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 // utility
16 #include "bitvector.h"
17 
18 // common
19 #include "base.h"
20 #include "fc_types.h"
21 #include "terrain.h" // enum tile_special_type
22 #include "unittype.h"
23 #include "vision.h"
24 #include "world_object.h"
25 
26 struct road_type;
27 struct unit_move_data; /* Actually defined in "server/unittools.c". */
28 
29 /* Changing this enum will break network compatibility.
30  * Different orders take different parameters; see struct unit_order. */
32  // Move without performing any action (dir)
34  // Perform activity (activity, extra)
36  // Pause to regain movement points (no parameters)
38  /* Move; if necessary prompt for action/target when order executed (dir) */
40  // Perform pre-specified action (action, target, extra, dir)
42  // and plenty more for later...
44 };
45 
47 
55  UU_NOT_TERRAIN, // The upgraded unit could not survive.
56  UU_UNSUITABLE_TRANSPORT // Can't upgrade inside current transport.
57 };
58 
60  // Codes treated as success:
61  AR_OK, // This will definitely work
62  AR_OK_SRC_UNKNOWN, // Source city's airlift capability is unknown
63  AR_OK_DST_UNKNOWN, // Dest city's airlift capability is unknown
64  // Codes treated as failure:
65  AR_NO_MOVES, // Unit has no moves left
66  AR_WRONG_UNITTYPE, // Can't airlift this type of unit
67  AR_OCCUPIED, // Can't airlift units with passengers
68  AR_NOT_IN_CITY, // Unit not in a city
69  AR_BAD_SRC_CITY, // Can't airlift from this src city
70  AR_BAD_DST_CITY, // Can't airlift to this dst city
71  AR_SRC_NO_FLIGHTS, // No flights available from src
72  AR_DST_NO_FLIGHTS // No flights available to dst
73 };
74 
75 struct unit_adv {
76  enum adv_unit_task task;
77 };
78 
79 struct unit_order {
80  enum unit_orders order;
81  enum unit_activity activity; // Only valid for ORDER_ACTIVITY.
82  /* Only valid for ORDER_PERFORM_ACTION. Validity and meaning depend on
83  * 'action'. See action_target_kind and action_sub_target_kind */
84  int target;
86  // Only valid for ORDER_PERFORM_ACTION
87  int action;
88  // Valid for ORDER_MOVE and ORDER_ACTION_MOVE.
89  enum direction8 dir;
90 };
91 
92 // Used in the network protocol
93 #define SPECENUM_NAME unit_ss_data_type
94 /* The player wants to be reminded to ask what actions the unit can perform
95  * to a certain target tile. */
96 #define SPECENUM_VALUE0 USSDT_QUEUE
97 /* The player no longer wants the reminder to ask what actions the unit can
98  * perform to a certain target tile. */
99 #define SPECENUM_VALUE1 USSDT_UNQUEUE
100 /* The player wants to record that the unit now belongs to the specified
101  * battle group. */
102 #define SPECENUM_VALUE2 USSDT_BATTLE_GROUP
103 #include "specenum_gen.h"
104 
105 // Used in the network protocol
106 #define SPECENUM_NAME server_side_agent
107 #define SPECENUM_VALUE0 SSA_NONE
108 #define SPECENUM_VALUE0NAME N_("None")
109 #define SPECENUM_VALUE1 SSA_AUTOSETTLER
110 #define SPECENUM_VALUE1NAME N_("Autosettlers")
111 #define SPECENUM_VALUE2 SSA_AUTOEXPLORE
112 #define SPECENUM_VALUE2NAME N_("Autoexplore")
113 #define SPECENUM_COUNT SSA_COUNT
114 #include "specenum_gen.h"
115 
116 struct unit;
117 struct unit_list;
118 
119 struct unit_wait {
120  int id;
121  time_t wake_up;
122  enum unit_activity activity;
124 };
125 
126 // 'struct unit_wait_list' and related functions.
127 #define SPECLIST_TAG unit_wait
128 #define SPECLIST_TYPE struct unit_wait
129 #include "speclist.h"
130 #define unit_wait_list_link_iterate(unit_wait_list, plink) \
131  TYPED_LIST_LINK_ITERATE(struct unit_wait_list_link, unit_wait_list, plink)
132 #define unit_wait_list_link_iterate_end LIST_LINK_ITERATE_END
133 
134 struct unit {
135  const struct unit_type *utype; // Cannot be nullptr.
136  struct tile *tile;
137  int refcount;
138  enum direction8 facing;
139  struct player *owner; // Cannot be nullptr.
141  int id;
142  int homecity;
143  QString name;
144 
145  int upkeep[O_LAST]; // unit upkeep with regards to the homecity
146 
148  int hp;
149  int veteran;
150  int fuel;
151 
152  struct tile *goto_tile; // May be nullptr.
153 
154  enum unit_activity activity;
155 
156  /* The amount of work that has been done on the current activity. This
157  * is counted in turns but is multiplied by ACTIVITY_FACTOR (which allows
158  * fractional values in some cases). */
160 
162 
163  /* Previous activity, so it can be resumed without loss of progress
164  * if the user changes their mind during a turn. */
165  enum unit_activity changed_from;
168 
169  enum server_side_agent ssa_controller;
170  bool moved;
172 
173  /* This value is set if the unit is done moving for this turn. This
174  * information is used by the client. The invariant is:
175  * - If the unit has no more moves, it's done moving.
176  * - If the unit is on a goto but is waiting, it's done moving.
177  * - Otherwise the unit is not done moving. */
179 
180  struct unit *transporter; // This unit is transported by ...
181  struct unit_list *transporting; // This unit transports ...
182 
184 
185  // The battlegroup ID: defined by the client but stored by the server.
186 #define MAX_NUM_BATTLEGROUPS (4)
187 #define BATTLEGROUP_NONE (-1)
189 
191  struct {
192  int length, index;
193  bool repeat; // The path is to be repeated on completion.
194  bool vigilant; // Orders should be cleared if an enemy is met.
195  struct unit_order *list;
197 
198  // The unit may want the player to choose an action.
199  enum action_decision action_decision_want;
201 
202  bool stay; // Unit is prohibited from moving
205  union {
206  struct {
207  /* Only used at the client (the server is omniscient; ./client/). */
208 
210 
211  int transported_by; /* Used for unit_short_info packets where we can't
212  * be sure that the information about the
213  * transporter is known. */
214  bool occupied; // TRUE if at least one cargo on the transporter.
215 
216  // Equivalent to pcity->client.color. Only for cityfounder units.
217  bool colored;
219 
221 
222  // Used in a follow up question about a selected action.
225 
226  struct {
227  /* Only used in the server (./ai/ and ./server/). */
228 
229  bool debug;
230 
231  struct unit_adv *adv;
232  void *ais[FREECIV_AI_MOD_LAST];
234 
235  /* ord_map and ord_city are the order index of this unit in tile.units
236  * and city.units_supported; they are only used for save/reload */
237  int ord_map;
238  int ord_city;
239 
240  struct vision *vision;
241  struct unit_wait_list_link *wait;
243 
244  // The unit is in the process of dying.
245  bool dying;
246 
247  // Call back to run on unit removal.
248  void (*removal_callback)(struct unit *punit);
249 
250  // The upkeep that actually was payed.
253  };
254 };
255 
256 #ifdef FREECIV_DEBUG
257 #define CHECK_UNIT(punit) \
258  (fc_assert(punit != nullptr), fc_assert(unit_type_get(punit) != nullptr), \
259  fc_assert(unit_owner(punit) != nullptr), \
260  fc_assert(player_by_number(player_index(unit_owner(punit))) \
261  == unit_owner(punit)), \
262  fc_assert(game_unit_by_number(punit->id) != nullptr))
263 #else // FREECIV_DEBUG
264 #define CHECK_UNIT(punit) // Do nothing
265 #endif // FREECIV_DEBUG
266 
268 
269 extern Activity_type_id real_activities[ACTIVITY_LAST];
270 
271 #define activity_type_list_iterate(_act_list_, _act_) \
272  { \
273  int _act_i_; \
274  for (_act_i_ = 0; _act_list_[_act_i_] != ACTIVITY_LAST; _act_i_++) { \
275  Activity_type_id _act_ = _act_list_[_act_i_];
276 
277 #define activity_type_list_iterate_end \
278  } \
279  }
280 
281 // Iterates over the types of unit activity.
282 #define activity_type_iterate(_act_) \
283  { \
284  activity_type_list_iterate(real_activities, _act_)
285 
286 #define activity_type_iterate_end \
287  activity_type_list_iterate_end \
288  }
289 
291 
292 #define tile_changing_activities_iterate(_act_) \
293  { \
294  activity_type_list_iterate(tile_changing_activities, _act_)
295 
296 #define tile_changing_activities_iterate_end \
297  activity_type_list_iterate_end \
298  }
299 
300 // Used in send_packet_city_info_100
301 bool are_unit_orders_equal(const struct unit_order *order1,
302  const struct unit_order *order2);
303 
304 int unit_shield_value(const struct unit *punit,
305  const struct unit_type *punittype,
306  const struct action *paction);
307 bool unit_can_help_build_wonder_here(const struct unit *punit);
308 bool unit_can_est_trade_route_here(const struct unit *punit);
310 test_unit_can_airlift_to(const struct player *restriction,
311  const struct unit *punit,
312  const struct city *pdest_city);
313 bool unit_can_airlift_to(const struct unit *punit, const struct city *pcity);
314 bool unit_has_orders(const struct unit *punit);
315 
316 bool could_unit_load(const struct unit *pcargo, const struct unit *ptrans);
317 bool can_unit_load(const struct unit *punit, const struct unit *ptrans);
318 bool can_unit_unload(const struct unit *punit, const struct unit *ptrans);
319 bool can_unit_alight_or_be_unloaded(const struct unit *pcargo,
320  const struct unit *ptrans);
321 bool can_unit_paradrop(const struct unit *punit);
322 bool can_unit_change_homecity_to(const struct unit *punit,
323  const struct city *pcity);
324 bool can_unit_change_homecity(const struct unit *punit);
325 const char *get_activity_text(enum unit_activity activity);
326 bool can_unit_continue_current_activity(struct unit *punit);
327 bool can_unit_do_activity(const struct unit *punit,
328  enum unit_activity activity);
329 bool can_unit_do_activity_targeted(const struct unit *punit,
330  enum unit_activity activity,
331  struct extra_type *target);
332 bool can_unit_do_activity_targeted_at(const struct unit *punit,
333  enum unit_activity activity,
334  struct extra_type *target,
335  const struct tile *ptile);
336 void set_unit_activity(struct unit *punit, enum unit_activity new_activity);
337 void set_unit_activity_targeted(struct unit *punit,
338  enum unit_activity new_activity,
339  struct extra_type *new_target);
340 int get_activity_rate(const struct unit *punit);
341 int get_activity_rate_this_turn(const struct unit *punit);
342 int get_turns_for_activity_at(const struct unit *punit,
343  enum unit_activity activity,
344  const struct tile *ptile,
345  struct extra_type *tgt);
346 bool activity_requires_target(enum unit_activity activity);
347 bool can_unit_do_autosettlers(const struct unit *punit);
348 bool is_unit_activity_on_tile(enum unit_activity activity,
349  const struct tile *ptile);
350 bv_extras get_unit_tile_pillage_set(const struct tile *ptile);
351 bool is_attack_unit(const struct unit *punit);
352 bool is_military_unit(const struct unit *punit); // !set !dip !cara
353 bool unit_can_do_action(const struct unit *punit, const action_id act_id);
354 bool unit_can_do_action_result(const struct unit *punit,
355  enum action_result result);
356 bool is_square_threatened(const struct player *pplayer,
357  const struct tile *ptile, bool omniscient);
358 bool is_field_unit(const struct unit *punit); // ships+aero
359 bool is_hiding_unit(const struct unit *punit);
360 bool unit_can_add_or_build_city(const struct unit *punit);
361 
362 bool kills_citizen_after_attack(const struct unit *punit);
363 void unit_activity_astr(const struct unit *punit, QString &astr);
364 void unit_upkeep_astr(const struct unit *punit, QString &astr);
365 const QString unit_activity_text(const struct unit *punit);
366 
367 int get_transporter_capacity(const struct unit *punit);
368 
369 #define unit_home(_pu_) (game_city_by_number((_pu_)->homecity))
370 #define unit_owner(_pu) ((_pu)->owner)
371 #define unit_tile(_pu) ((_pu)->tile)
372 struct player *unit_nationality(const struct unit *punit);
373 void unit_tile_set(struct unit *punit, struct tile *ptile);
374 
375 struct unit *is_allied_unit_tile(const struct tile *ptile,
376  const struct player *pplayer);
377 struct unit *is_enemy_unit_tile(const struct tile *ptile,
378  const struct player *pplayer);
379 struct unit *is_non_allied_unit_tile(const struct tile *ptile,
380  const struct player *pplayer);
381 struct unit *is_other_players_unit_tile(const struct tile *ptile,
382  const struct player *pplayer);
383 struct unit *is_non_attack_unit_tile(const struct tile *ptile,
384  const struct player *pplayer);
385 struct unit *unit_occupies_tile(const struct tile *ptile,
386  const struct player *pplayer);
387 
388 bool is_my_zoc(const struct player *unit_owner, const struct tile *ptile,
389  const struct civ_map *zmap);
390 bool unit_being_aggressive(const struct unit *punit);
391 bool unit_type_really_ignores_zoc(const struct unit_type *punittype);
392 
393 bool is_build_activity(enum unit_activity activity,
394  const struct tile *ptile);
395 bool is_clean_activity(enum unit_activity activity);
396 bool is_terrain_change_activity(enum unit_activity activity);
397 bool is_tile_activity(enum unit_activity activity);
398 
399 struct unit *unit_virtual_create(struct player *pplayer, struct city *pcity,
400  const struct unit_type *punittype,
401  int veteran_level);
402 void unit_virtual_destroy(struct unit *punit);
403 bool unit_is_virtual(const struct unit *punit);
404 void free_unit_orders(struct unit *punit);
405 
406 int get_transporter_occupancy(const struct unit *ptrans);
407 struct unit *transporter_for_unit(const struct unit *pcargo);
408 struct unit *transporter_for_unit_at(const struct unit *pcargo,
409  const struct tile *ptile);
410 
411 enum unit_upgrade_result unit_upgrade_test(const struct unit *punit,
412  bool is_free);
413 enum unit_upgrade_result unit_upgrade_info(const struct unit *punit,
414  char *buf, size_t bufsz);
415 bool unit_can_convert(const struct unit *punit);
416 
417 int unit_pays_mp_for_action(const struct action *paction,
418  const struct unit *punit);
419 
420 bool is_losing_hp(const struct unit *punit);
421 bool unit_type_is_losing_hp(const struct player *pplayer,
422  const struct unit_type *punittype);
423 
424 bool unit_is_alive(int id);
425 
426 void *unit_ai_data(const struct unit *punit, const struct ai_type *ai);
427 void unit_set_ai_data(struct unit *punit, const struct ai_type *ai,
428  void *data);
429 
430 int unit_bribe_cost(struct unit *punit, struct player *briber);
431 
432 bool unit_transport_load(struct unit *pcargo, struct unit *ptrans,
433  bool force);
434 bool unit_transport_unload(struct unit *pcargo);
435 struct unit *unit_transport_get(const struct unit *pcargo);
436 bool unit_transported(const struct unit *pcargo);
437 struct unit_list *unit_transport_cargo(const struct unit *ptrans);
438 bool unit_transport_check(const struct unit *pcargo,
439  const struct unit *ptrans);
440 bool unit_contained_in(const struct unit *pcargo, const struct unit *ptrans);
441 int unit_cargo_depth(const struct unit *pcargo);
442 int unit_transport_depth(const struct unit *ptrans);
443 
444 bool unit_is_cityfounder(const struct unit *punit);
445 
446 // Iterate all transporters carrying '_pcargo', directly or indirectly.
447 #define unit_transports_iterate(_pcargo, _ptrans) \
448  { \
449  struct unit *_ptrans; \
450  for (_ptrans = unit_transport_get(_pcargo); nullptr != _ptrans; \
451  _ptrans = unit_transport_get(_ptrans)) {
452 #define unit_transports_iterate_end \
453  } \
454  }
455 
456 struct cargo_iter;
458 
459 struct iterator *cargo_iter_init(struct cargo_iter *iter,
460  const struct unit *ptrans);
461 #define unit_cargo_iterate(_ptrans, _pcargo) \
462  generic_iterate(struct cargo_iter, struct unit *, _pcargo, \
463  cargo_iter_sizeof, cargo_iter_init, _ptrans)
464 #define unit_cargo_iterate_end generic_iterate_end
enum unit_activity Activity_type_id
Definition: fc_types.h:296
adv_unit_task
Definition: fc_types.h:287
int action_id
Definition: fc_types.h:306
@ O_LAST
Definition: fc_types.h:91
Definition: ai.h:42
Definition: city.h:291
Definition: player.h:231
Definition: road.h:54
Definition: tile.h:42
Definition: unit.h:75
enum adv_unit_task task
Definition: unit.h:76
enum unit_activity activity
Definition: unit.h:81
enum unit_orders order
Definition: unit.h:80
int action
Definition: unit.h:87
enum direction8 dir
Definition: unit.h:89
int target
Definition: unit.h:84
int sub_target
Definition: unit.h:85
time_t wake_up
Definition: unit.h:121
enum unit_activity activity
Definition: unit.h:122
int id
Definition: unit.h:120
int activity_count
Definition: unit.h:123
Definition: unit.h:134
time_t action_timestamp
Definition: unit.h:203
int length
Definition: unit.h:192
int upkeep[O_LAST]
Definition: unit.h:145
bool has_orders
Definition: unit.h:190
bool occupied
Definition: unit.h:214
enum action_decision action_decision_want
Definition: unit.h:199
int battlegroup
Definition: unit.h:188
enum unit_activity activity
Definition: unit.h:154
int moves_left
Definition: unit.h:147
struct unit::@76::@78 client
int refcount
Definition: unit.h:137
int id
Definition: unit.h:141
struct unit_list * transporting
Definition: unit.h:181
int ord_city
Definition: unit.h:238
bool moved
Definition: unit.h:170
int ord_map
Definition: unit.h:237
bool debug
Definition: unit.h:229
int index
Definition: unit.h:192
struct vision * vision
Definition: unit.h:240
bool vigilant
Definition: unit.h:194
int hp
Definition: unit.h:148
int upkeep_payed[O_LAST]
Definition: unit.h:251
int fuel
Definition: unit.h:150
struct extra_type * changed_from_target
Definition: unit.h:167
bool stay
Definition: unit.h:202
bool colored
Definition: unit.h:217
enum direction8 facing
Definition: unit.h:138
struct unit::@76::@79 server
bool asking_city_name
Definition: unit.h:220
struct tile * tile
Definition: unit.h:136
struct extra_type * activity_target
Definition: unit.h:161
struct act_prob * act_prob_cache
Definition: unit.h:223
int activity_count
Definition: unit.h:159
struct unit_order * list
Definition: unit.h:195
enum unit_activity changed_from
Definition: unit.h:165
struct unit_adv * adv
Definition: unit.h:231
struct player * nationality
Definition: unit.h:140
int transported_by
Definition: unit.h:211
bool repeat
Definition: unit.h:193
QString name
Definition: unit.h:143
void(* removal_callback)(struct unit *punit)
Definition: unit.h:248
int color_index
Definition: unit.h:218
void * ais[FREECIV_AI_MOD_LAST]
Definition: unit.h:232
struct unit_move_data * moving
Definition: unit.h:242
int action_turn
Definition: unit.h:204
int homecity
Definition: unit.h:142
bool paradropped
Definition: unit.h:171
bool done_moving
Definition: unit.h:178
struct unit * transporter
Definition: unit.h:180
int birth_turn
Definition: unit.h:233
struct unit_wait_list_link * wait
Definition: unit.h:241
struct goods_type * carrying
Definition: unit.h:183
struct tile * goto_tile
Definition: unit.h:152
struct unit::@75 orders
struct tile * action_decision_tile
Definition: unit.h:200
const struct unit_type * utype
Definition: unit.h:135
int veteran
Definition: unit.h:149
int changed_from_count
Definition: unit.h:166
struct player * owner
Definition: unit.h:139
bool dying
Definition: unit.h:245
enum unit_focus_status focus_status
Definition: unit.h:209
enum server_side_agent ssa_controller
Definition: unit.h:169
Definition: vision.h:83
int fc__attribute((nonnull(1, 3)))
void unit_upkeep_astr(const struct unit *punit, QString &astr)
Append a line of text describing the unit's upkeep to the astring.
Definition: unit.cpp:1174
Activity_type_id real_activities[ACTIVITY_LAST]
Definition: unit.cpp:36
bool is_tile_activity(enum unit_activity activity)
Returns true if given activity affects tile.
Definition: unit.cpp:1480
bool unit_being_aggressive(const struct unit *punit)
An "aggressive" unit is a unit which may cause unhappiness under a Republic or Democracy.
Definition: unit.cpp:1399
bool unit_type_really_ignores_zoc(const struct unit_type *punittype)
Takes into account unit class flag UCF_ZOC as well as IGZOC.
Definition: unit.cpp:1385
bool unit_type_is_losing_hp(const struct player *pplayer, const struct unit_type *punittype)
Does unit lose hitpoints each turn?
Definition: unit.cpp:2003
bool is_terrain_change_activity(enum unit_activity activity)
Returns true if given activity changes terrain.
Definition: unit.cpp:1465
int unit_shield_value(const struct unit *punit, const struct unit_type *punittype, const struct action *paction)
Returns how many shields the unit (type) is worth.
Definition: unit.cpp:204
int get_transporter_occupancy(const struct unit *ptrans)
Return how many units are in the transport.
Definition: unit.cpp:1647
bool unit_can_airlift_to(const struct unit *punit, const struct city *pcity)
Determines if punit can be airlifted to dest_city now! So punit needs to be in a city now.
Definition: unit.cpp:179
void free_unit_orders(struct unit *punit)
Free and reset the unit's goto route (punit->pgr).
Definition: unit.cpp:1633
bool can_unit_change_homecity(const struct unit *punit)
Return TRUE iff the unit can change homecity at its current location.
Definition: unit.cpp:430
struct unit * transporter_for_unit(const struct unit *pcargo)
Find the best transporter at the given location for the unit.
Definition: unit.cpp:1779
enum unit_upgrade_result unit_upgrade_test(const struct unit *punit, bool is_free)
Tests if the unit could be updated.
Definition: unit.cpp:1826
void * unit_ai_data(const struct unit *punit, const struct ai_type *ai)
Return pointer to ai data of given unit and ai type.
Definition: unit.cpp:2039
void unit_set_ai_data(struct unit *punit, const struct ai_type *ai, void *data)
Attach ai data to unit.
Definition: unit.cpp:2047
bool unit_is_alive(int id)
Check if unit with given id is still alive.
Definition: unit.cpp:2014
bool unit_can_est_trade_route_here(const struct unit *punit)
Return TRUE iff this unit can be disbanded at its current location to provide a trade route from the ...
Definition: unit.cpp:267
bool is_hiding_unit(const struct unit *punit)
Is the unit one that is invisible on the map.
Definition: unit.cpp:367
int get_activity_rate_this_turn(const struct unit *punit)
Returns the amount of work a unit does (will do) on an activity this turn.
Definition: unit.cpp:470
int unit_pays_mp_for_action(const struct action *paction, const struct unit *punit)
Returns the amount of movement points successfully performing the specified action will consume in th...
Definition: unit.cpp:1973
int get_turns_for_activity_at(const struct unit *punit, enum unit_activity activity, const struct tile *ptile, struct extra_type *tgt)
Return the estimated number of turns for the worker unit to start and complete the activity at the gi...
Definition: unit.cpp:486
bool can_unit_paradrop(const struct unit *punit)
Return whether the unit can be paradropped - that is, if the unit is in a friendly city or on an airb...
Definition: unit.cpp:772
struct unit * is_other_players_unit_tile(const struct tile *ptile, const struct player *pplayer)
Is there an unit belonging to another player on this tile?
Definition: unit.cpp:1269
unit_focus_status
Definition: unit.h:46
@ FOCUS_AVAIL
Definition: unit.h:46
@ FOCUS_DONE
Definition: unit.h:46
@ FOCUS_WAIT
Definition: unit.h:46
bool unit_transport_load(struct unit *pcargo, struct unit *ptrans, bool force)
Load pcargo onto ptrans.
Definition: unit.cpp:2123
bool unit_can_add_or_build_city(const struct unit *punit)
Return TRUE iff this unit can add to a current city or build a new city at its current location.
Definition: unit.cpp:399
int unit_cargo_depth(const struct unit *pcargo)
Returns the number of unit cargo layers within transport 'ptrans'.
Definition: unit.cpp:2289
unit_orders
Definition: unit.h:31
@ ORDER_ACTION_MOVE
Definition: unit.h:39
@ ORDER_ACTIVITY
Definition: unit.h:35
@ ORDER_FULL_MP
Definition: unit.h:37
@ ORDER_MOVE
Definition: unit.h:33
@ ORDER_LAST
Definition: unit.h:43
@ ORDER_PERFORM_ACTION
Definition: unit.h:41
void set_unit_activity(struct unit *punit, enum unit_activity new_activity)
Assign a new untargeted task to a unit.
Definition: unit.cpp:1011
bool is_losing_hp(const struct unit *punit)
Does unit lose hitpoints each turn?
Definition: unit.cpp:1992
bool can_unit_change_homecity_to(const struct unit *punit, const struct city *pcity)
Return TRUE iff the unit can change homecity to the given city.
Definition: unit.cpp:415
struct unit * is_allied_unit_tile(const struct tile *ptile, const struct player *pplayer)
Returns true if the tile contains an allied unit and only allied units.
Definition: unit.cpp:1211
int get_activity_rate(const struct unit *punit)
Returns the speed of a unit doing an activity.
Definition: unit.cpp:443
struct unit * is_non_allied_unit_tile(const struct tile *ptile, const struct player *pplayer)
Is there an non-allied unit on this tile?
Definition: unit.cpp:1252
bool unit_transport_check(const struct unit *pcargo, const struct unit *ptrans)
Returns whether 'pcargo' in 'ptrans' is a valid transport.
Definition: unit.cpp:2227
bool is_attack_unit(const struct unit *punit)
Is the unit capable of attacking?
Definition: unit.cpp:288
const Activity_type_id tile_changing_activities[]
Definition: unit.cpp:38
struct unit * unit_transport_get(const struct unit *pcargo)
Returns the transporter of the unit or nullptr if it is not transported.
Definition: unit.cpp:2189
bool unit_transport_unload(struct unit *pcargo)
Unload pcargo from ptrans.
Definition: unit.cpp:2144
bool unit_contained_in(const struct unit *pcargo, const struct unit *ptrans)
Returns whether 'pcargo' is transported by 'ptrans', either directly or indirectly.
Definition: unit.cpp:2274
bool can_unit_continue_current_activity(struct unit *punit)
Check if the unit's current activity is actually legal.
Definition: unit.cpp:780
#define unit_owner(_pu)
Definition: unit.h:370
bool is_military_unit(const struct unit *punit)
Military units are capable of enforcing martial law.
Definition: unit.cpp:300
struct unit * unit_occupies_tile(const struct tile *ptile, const struct player *pplayer)
Is there an occupying unit on this tile?
Definition: unit.cpp:1308
bool can_unit_do_activity_targeted_at(const struct unit *punit, enum unit_activity activity, struct extra_type *target, const struct tile *ptile)
Return TRUE if the unit can do the targeted activity at the given location.
Definition: unit.cpp:854
struct unit * transporter_for_unit_at(const struct unit *pcargo, const struct tile *ptile)
Find the best transporter at the given location for the unit.
Definition: unit.cpp:1789
int unit_bribe_cost(struct unit *punit, struct player *briber)
Calculate how expensive it is to bribe the unit.
Definition: unit.cpp:2061
bool is_build_activity(enum unit_activity activity, const struct tile *ptile)
Returns true if given activity is some kind of building.
Definition: unit.cpp:1434
bool is_square_threatened(const struct player *pplayer, const struct tile *ptile, bool omniscient)
Return TRUE iff this tile is threatened from any unit within 2 tiles.
Definition: unit.cpp:327
bool could_unit_load(const struct unit *pcargo, const struct unit *ptrans)
Return TRUE iff the given unit could be loaded into the transporter if we moved there.
Definition: unit.cpp:646
bool unit_is_cityfounder(const struct unit *punit)
Is a cityfounder unit?
Definition: unit.cpp:2389
bool is_unit_activity_on_tile(enum unit_activity activity, const struct tile *ptile)
Return whether any units on the tile are doing this activity.
Definition: unit.cpp:1046
bool can_unit_do_autosettlers(const struct unit *punit)
Return whether the unit can be put in auto-settler mode.
Definition: unit.cpp:548
unit_upgrade_result
Definition: unit.h:48
@ UU_NO_MONEY
Definition: unit.h:51
@ UU_NOT_IN_CITY
Definition: unit.h:52
@ UU_NO_UNITTYPE
Definition: unit.h:50
@ UU_NOT_TERRAIN
Definition: unit.h:55
@ UU_UNSUITABLE_TRANSPORT
Definition: unit.h:56
@ UU_NOT_CITY_OWNER
Definition: unit.h:53
@ UU_NOT_ENOUGH_ROOM
Definition: unit.h:54
@ UU_OK
Definition: unit.h:49
bool unit_can_help_build_wonder_here(const struct unit *punit)
Return TRUE unless it is known to be imposible to disband this unit at its current position to get fu...
Definition: unit.cpp:243
bool can_unit_alight_or_be_unloaded(const struct unit *pcargo, const struct unit *ptrans)
Return TRUE iff the given unit can leave its current transporter without doing any other action or mo...
Definition: unit.cpp:745
bool is_field_unit(const struct unit *punit)
This checks the "field unit" flag on the unit.
Definition: unit.cpp:355
bool unit_can_do_action(const struct unit *punit, const action_id act_id)
Return TRUE iff this unit can do the specified generalized (ruleset defined) action enabler controlle...
Definition: unit.cpp:309
bool unit_can_do_action_result(const struct unit *punit, enum action_result result)
Return TRUE iff this unit can do any enabler controlled action with the specified action result.
Definition: unit.cpp:318
void set_unit_activity_targeted(struct unit *punit, enum unit_activity new_activity, struct extra_type *new_target)
assign a new targeted task to a unit.
Definition: unit.cpp:1028
bool unit_can_convert(const struct unit *punit)
Tests if unit can be converted to another type.
Definition: unit.cpp:1877
size_t cargo_iter_sizeof() fc__attribute((const))
bool can_unit_do_activity_targeted(const struct unit *punit, enum unit_activity activity, struct extra_type *target)
Return whether the unit can do the targeted activity at its current location.
Definition: unit.cpp:842
struct unit_list * unit_transport_cargo(const struct unit *ptrans)
Returns the list of cargo units.
Definition: unit.cpp:2199
bv_extras get_unit_tile_pillage_set(const struct tile *ptile)
Return a mask of the extras which are actively (currently) being pillaged on the given tile.
Definition: unit.cpp:1063
int get_transporter_capacity(const struct unit *punit)
Return the number of units the transporter can hold (or 0).
Definition: unit.cpp:280
struct unit * is_non_attack_unit_tile(const struct tile *ptile, const struct player *pplayer)
Is there an unit we have peace or ceasefire with on this tile?
Definition: unit.cpp:1286
bool can_unit_unload(const struct unit *punit, const struct unit *ptrans)
Return TRUE iff the given unit can be unloaded from its current transporter.
Definition: unit.cpp:720
bool is_clean_activity(enum unit_activity activity)
Returns true if given activity is some kind of cleaning.
Definition: unit.cpp:1450
int unit_transport_depth(const struct unit *ptrans)
Returns the number of unit transport layers which carry unit 'pcargo'.
Definition: unit.cpp:2307
enum unit_upgrade_result unit_upgrade_info(const struct unit *punit, char *buf, size_t bufsz)
Find the result of trying to upgrade the unit, and a message that most callers can use directly.
Definition: unit.cpp:1900
bool can_unit_do_activity(const struct unit *punit, enum unit_activity activity)
Return TRUE iff the unit can do the given untargeted activity at its current location.
Definition: unit.cpp:806
void unit_virtual_destroy(struct unit *punit)
Free the memory used by virtual unit.
Definition: unit.cpp:1588
const char * get_activity_text(enum unit_activity activity)
Return the name of the activity in a static buffer.
Definition: unit.cpp:586
struct unit * unit_virtual_create(struct player *pplayer, struct city *pcity, const struct unit_type *punittype, int veteran_level)
Create a virtual unit skeleton.
Definition: unit.cpp:1490
void unit_tile_set(struct unit *punit, struct tile *ptile)
Set the tile location of the unit.
Definition: unit.cpp:1200
struct iterator * cargo_iter_init(struct cargo_iter *iter, const struct unit *ptrans)
Initialize the cargo iterator.
Definition: unit.cpp:2372
enum unit_airlift_result test_unit_can_airlift_to(const struct player *restriction, const struct unit *punit, const struct city *pdest_city)
Determines if punit can be airlifted to dest_city now! So punit needs to be in a city now.
Definition: unit.cpp:75
const QString unit_activity_text(const struct unit *punit)
Return text describing the unit's current activity as a static string.
Definition: unit.cpp:1085
bool kills_citizen_after_attack(const struct unit *punit)
Return TRUE iff an attack from this unit would kill a citizen in a city (city walls protect against t...
Definition: unit.cpp:389
bool can_unit_load(const struct unit *punit, const struct unit *ptrans)
Return TRUE iff the given unit can be loaded into the transporter.
Definition: unit.cpp:693
bool unit_transported(const struct unit *pcargo)
Returns TRUE iff the unit is transported.
Definition: unit.cpp:2176
bool are_unit_orders_equal(const struct unit_order *order1, const struct unit_order *order2)
Checks unit orders for equality.
Definition: unit.cpp:54
bool unit_is_virtual(const struct unit *punit)
Return TRUE if this is a valid unit pointer but does not correspond to any unit that exists in the ga...
Definition: unit.cpp:2027
bool unit_has_orders(const struct unit *punit)
Return TRUE iff the unit is following client-side orders.
Definition: unit.cpp:195
unit_airlift_result
Definition: unit.h:59
@ AR_SRC_NO_FLIGHTS
Definition: unit.h:71
@ AR_OK_SRC_UNKNOWN
Definition: unit.h:62
@ AR_OK_DST_UNKNOWN
Definition: unit.h:63
@ AR_NO_MOVES
Definition: unit.h:65
@ AR_BAD_DST_CITY
Definition: unit.h:70
@ AR_NOT_IN_CITY
Definition: unit.h:68
@ AR_OCCUPIED
Definition: unit.h:67
@ AR_OK
Definition: unit.h:61
@ AR_DST_NO_FLIGHTS
Definition: unit.h:72
@ AR_WRONG_UNITTYPE
Definition: unit.h:66
@ AR_BAD_SRC_CITY
Definition: unit.h:69
struct player * unit_nationality(const struct unit *punit)
Return the nationality of the unit.
Definition: unit.cpp:1190
bool activity_requires_target(enum unit_activity activity)
Return TRUE if activity requires some sort of target to be specified.
Definition: unit.cpp:506
bool is_my_zoc(const struct player *unit_owner, const struct tile *ptile, const struct civ_map *zmap)
Is this square controlled by the pplayer?
Definition: unit.cpp:1341
struct unit * is_enemy_unit_tile(const struct tile *ptile, const struct player *pplayer)
Is there an enemy unit on this tile? Returns the unit or nullptr if none.
Definition: unit.cpp:1235
void unit_activity_astr(const struct unit *punit, QString &astr)
Append text describing the unit's current activity to the given astring.
Definition: unit.cpp:1096
void setup_real_activities_array()
Setup array of real activities.
Definition: unit.cpp:556