Freeciv21
Develop your civilization from humble roots to a global empire
advgoto.cpp
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 
14 // common
15 #include "ai.h"
16 #include "combat.h"
17 #include "game.h"
18 #include "movement.h"
19 #include "tile.h"
20 #include "unit.h"
21 
22 // aicore
23 #include "path_finding.h"
24 
25 // server
26 #include "maphand.h"
27 #include "srv_log.h"
28 #include "unithand.h"
29 #include "unittools.h"
30 
31 /* server/advisors */
32 #include "advtools.h"
33 
34 #include "advgoto.h"
35 
36 static bool adv_unit_move(struct unit *punit, struct tile *ptile);
37 
43 bool adv_follow_path(struct unit *punit, const PFPath &path,
44  struct tile *ptile)
45 {
46  struct tile *old_tile = punit->goto_tile;
47  enum unit_activity activity = punit->activity;
48  struct extra_type *tgt = punit->activity_target;
49  bool alive;
50 
51  if (punit->moves_left <= 0) {
52  return true;
53  }
54  punit->goto_tile = ptile;
55  unit_activity_handling(punit, ACTIVITY_GOTO);
56  alive = adv_unit_execute_path(punit, path);
57  if (alive) {
58  if (activity != ACTIVITY_GOTO) {
59  /* Only go via ACTIVITY_IDLE if we are actually changing the activity
60  */
61  unit_activity_handling(punit, ACTIVITY_IDLE);
62  send_unit_info(nullptr, punit); // FIXME: probably duplicate
63  unit_activity_handling_targeted(punit, activity, &tgt);
64  }
65  punit->goto_tile = old_tile; // May be nullptr.
66  send_unit_info(nullptr, punit);
67  }
68  return alive;
69 }
70 
78 bool adv_unit_execute_path(struct unit *punit, const PFPath &path)
79 {
80  const bool is_plr_ai = is_ai(unit_owner(punit));
81  int i;
82 
83  // We start with i = 1 for i = 0 is our present position
84  for (i = 1; i < path.length(); i++) {
85  struct tile *ptile = path[i].tile;
86  int id = punit->id;
87 
88  if (same_pos(unit_tile(punit), ptile)) {
89  UNIT_LOG(LOG_DEBUG, punit, "execute_path: waiting this turn");
90  return true;
91  }
92 
93  /* We use ai_unit_move() for everything but the last step
94  * of the way so that we abort if unexpected opposition
95  * shows up. Any enemy on the target tile is expected to
96  * be our target and any attack there intentional.
97  * However, do not annoy human players by automatically attacking
98  * using units temporarily under AI control (such as auto-explorers)
99  */
100 
101  if (is_plr_ai) {
102  CALL_PLR_AI_FUNC(unit_move, unit_owner(punit), punit, ptile, path, i);
103  } else {
104  (void) adv_unit_move(punit, ptile);
105  }
106  if (!game_unit_by_number(id)) {
107  // Died...
108  return false;
109  }
110 
111  if (!same_pos(unit_tile(punit), ptile) || punit->moves_left <= 0) {
112  // Stopped (or maybe fought) or ran out of moves
113  return true;
114  }
115  }
116 
117  return true;
118 }
119 
128 static bool adv_unit_move(struct unit *punit, struct tile *ptile)
129 {
130  struct action *paction;
131  struct player *pplayer = unit_owner(punit);
132  struct unit *ptrans = nullptr;
133 
134  /* if enemy, stop and give a chance for the human player to
135  handle this case */
136  if (is_enemy_unit_tile(ptile, pplayer)
137  || is_enemy_city_tile(ptile, pplayer)) {
138  UNIT_LOG(LOG_DEBUG, punit, "movement halted due to enemy presence");
139  return false;
140  }
141 
142  // Select move kind.
143  if (!can_unit_survive_at_tile(&(wld.map), punit, ptile)
144  && ((ptrans = transporter_for_unit_at(punit, ptile)))
145  && is_action_enabled_unit_on_unit(ACTION_TRANSPORT_EMBARK, punit,
146  ptrans)) {
147  // "Transport Embark".
148  paction = action_by_number(ACTION_TRANSPORT_EMBARK);
149  } else if (is_action_enabled_unit_on_tile(ACTION_TRANSPORT_DISEMBARK1,
150  punit, ptile, nullptr)) {
151  // "Transport Disembark".
152  paction = action_by_number(ACTION_TRANSPORT_DISEMBARK1);
153  } else if (is_action_enabled_unit_on_tile(ACTION_TRANSPORT_DISEMBARK2,
154  punit, ptile, nullptr)) {
155  // "Transport Disembark 2".
156  paction = action_by_number(ACTION_TRANSPORT_DISEMBARK2);
157  } else {
158  // Other move.
159  paction = nullptr;
160  }
161 
162  // Try not to end move next to an enemy if we can avoid it by waiting
163  if (paction == nullptr // Regular move
164  || action_has_result(paction, ACTRES_TRANSPORT_DISEMBARK)) {
165  // The unit will have to move it self rather than being moved.
166  int mcost = map_move_cost_unit(&(wld.map), punit, ptile);
167 
168  if (paction) {
169  struct tile *from_tile;
170 
171  /* Ugly hack to understand the OnNativeTile unit state requirements
172  * used in the Action_Success_Actor_Move_Cost effect. */
173  fc_assert(
175  from_tile = unit_tile(punit);
176  punit->tile = ptile;
177 
178  mcost += unit_pays_mp_for_action(paction, punit);
179 
180  punit->tile = from_tile;
181  }
182 
183  if (punit->moves_left <= mcost && unit_move_rate(punit) > mcost
184  && adv_danger_at(punit, ptile)
185  && !adv_danger_at(punit, unit_tile(punit))) {
186  UNIT_LOG(LOG_DEBUG, punit, "ending move early to stay out of trouble");
187  return false;
188  }
189  }
190 
191  // go
192  unit_activity_handling(punit, ACTIVITY_IDLE);
193  // Move
194  /* TODO: Differentiate (server side AI) player from server side agent
195  * working for (possibly AI) player by using ACT_REQ_PLAYER and
196  * ACT_REQ_SS_AGENT */
197  if (paction && ptrans
198  && action_has_result(paction, ACTRES_TRANSPORT_EMBARK)) {
199  // "Transport Embark".
200  unit_do_action(unit_owner(punit), punit->id, ptrans->id, 0, "",
201  action_number(paction));
202  } else if (paction
203  && (action_has_result(paction, ACTRES_TRANSPORT_DISEMBARK))) {
204  // "Transport Disembark" or "Transport Disembark 2".
205  unit_do_action(unit_owner(punit), punit->id, tile_index(ptile), 0, "",
206  action_number(paction));
207  } else {
208  // Other move.
209  (void) unit_move_handling(punit, ptile, false, true);
210  }
211 
212  return true;
213 }
214 
222 static bool adv_could_be_my_zoc(struct unit *myunit, struct tile *ptile)
223 {
224  if (same_pos(ptile, unit_tile(myunit))) {
225  return false; // can't be my zoc
226  }
227  if (is_tiles_adjacent(ptile, unit_tile(myunit))
228  && !is_non_allied_unit_tile(ptile, unit_owner(myunit))) {
229  return false;
230  }
231 
232  adjc_iterate(&(wld.map), ptile, atile)
233  {
234  if (!terrain_has_flag(tile_terrain(atile), TER_NO_ZOC)
235  && is_non_allied_unit_tile(atile, unit_owner(myunit))) {
236  return false;
237  }
238  }
240 
241  return true;
242 }
243 
252 int adv_could_unit_move_to_tile(struct unit *punit, struct tile *dest_tile)
253 {
255  &(wld.map), punit, ACTIVITY_IDLE, unit_tile(punit), dest_tile,
256  unit_has_type_flag(punit, UTYF_IGZOC), nullptr, false);
257 
258  switch (reason) {
259  case MR_OK:
260  return 1;
261 
262  case MR_ZOC:
263  if (adv_could_be_my_zoc(punit, unit_tile(punit))) {
264  return -1;
265  }
266  break;
267 
268  default:
269  break;
270  };
271  return 0;
272 }
273 
277 int adv_unittype_att_rating(const struct unit_type *punittype, int veteran,
278  int moves_left, int hp)
279 {
280  return base_get_attack_power(punittype, veteran, moves_left) * hp
281  * punittype->firepower / POWER_DIVIDER;
282 }
283 
288 int adv_unit_att_rating(const struct unit *punit)
289 {
290  return adv_unittype_att_rating(unit_type_get(punit), punit->veteran,
291  SINGLE_MOVE, punit->hp);
292 }
293 
298 int adv_unit_def_rating_basic(const struct unit *punit)
299 {
300  return base_get_defense_power(punit) * punit->hp
302 }
303 
307 int adv_unit_def_rating_basic_squared(const struct unit *punit)
308 {
309  int v = adv_unit_def_rating_basic(punit);
310 
311  return v * v;
312 }
313 
317 bool adv_danger_at(struct unit *punit, struct tile *ptile)
318 {
319  int a = 0, d, db;
320  struct player *pplayer = unit_owner(punit);
321  struct city *pcity = tile_city(ptile);
322  enum override_bool dc = NO_OVERRIDE;
323  int extras_bonus = 0;
324 
325  // Give AI code possibility to decide itself
326  CALL_PLR_AI_FUNC(consider_tile_dangerous, unit_owner(punit), ptile, punit,
327  &dc);
328  if (dc == OVERRIDE_TRUE) {
329  return true;
330  } else if (dc == OVERRIDE_FALSE) {
331  return false;
332  }
333 
334  if (pcity && pplayers_allied(city_owner(pcity), unit_owner(punit))
335  && !is_non_allied_unit_tile(ptile, pplayer)) {
336  // We will be safe in a friendly city
337  return false;
338  }
339 
340  // Calculate how well we can defend at (x,y)
341  db = 10 + tile_terrain(ptile)->defense_bonus / 10;
342  extras_bonus += tile_extras_defense_bonus(ptile, unit_type_get(punit));
343  db += (db * extras_bonus) / 100;
344  d = adv_unit_def_rating_basic_squared(punit) * db;
345 
346  adjc_iterate(&(wld.map), ptile, ptile1)
347  {
348  if (!map_is_known_and_seen(ptile1, unit_owner(punit), V_MAIN)) {
349  // We cannot see danger at (ptile1) => assume there is none
350  continue;
351  }
352  unit_list_iterate(ptile1->units, enemy)
353  {
354  if (pplayers_at_war(unit_owner(enemy), unit_owner(punit))
355  && unit_attack_unit_at_tile_result(enemy, punit, ptile) == ATT_OK
356  && unit_attack_units_at_tile_result(enemy, ptile) == ATT_OK) {
357  a += adv_unit_att_rating(enemy);
358  if ((a * a * 10) >= d) {
359  // The enemies combined strength is too big!
360  return true;
361  }
362  }
363  }
365  }
367 
368  return false; // as good a quick'n'dirty should be -- Syela
369 }
370 
374 static int stack_value(const struct tile *ptile,
375  const struct player *pplayer)
376 {
377  int cost = 0;
378 
379  if (is_stack_vulnerable(ptile)) {
380  unit_list_iterate(ptile->units, punit)
381  {
382  if (unit_owner(punit) == pplayer) {
383  cost += unit_build_shield_cost_base(punit);
384  }
385  }
387  }
388 
389  return cost;
390 }
391 
402 static double chance_killed_at(const struct tile *ptile,
403  struct adv_risk_cost *risk_cost,
404  const struct pf_parameter *param)
405 {
406  double db;
407  int extras_bonus = 0;
408  // Compute the basic probability
409  // WAG
410  /* In the early stages of a typical game, ferries
411  * are effectively invulnerable (not until Frigates set sail),
412  * so we make seas appear safer.
413  * If we don't do this, the amphibious movement code has too strong a
414  * desire to minimise the length of the path,
415  * leading to poor choice for landing beaches */
416  double p = is_ocean_tile(ptile) ? 0.05 : 0.15;
417 
418  // If we are on defensive terrain, we are more likely to survive
419  db = 10 + tile_terrain(ptile)->defense_bonus / 10;
420  extras_bonus +=
422  db += (extras_bonus) / 100;
423  p *= 10.0 / db;
424 
425  return p;
426 }
427 
443 static int stack_risk(const struct tile *ptile,
444  struct adv_risk_cost *risk_cost,
445  const struct pf_parameter *param)
446 {
447  double risk = 0;
448  // Compute the risk of destruction, assuming we will stop at this tile
449  const double value =
450  risk_cost->base_value + stack_value(ptile, param->owner);
451  const double p_killed = chance_killed_at(ptile, risk_cost, param);
452  double danger = value * p_killed;
453 
454  /* Adjust for the fact that we might not stop at this tile,
455  * and for our fearfulness */
456  risk += danger * risk_cost->fearfulness;
457 
458  /* Adjust for the risk that we might become stuck (for an indefinite
459  * period) if we enter or try to enter the tile. */
460  if (risk_cost->enemy_zoc_cost != 0
461  && (is_non_allied_city_tile(ptile, param->owner)
462  || !is_my_zoc(param->owner, ptile, param->map)
463  || is_non_allied_unit_tile(ptile, param->owner))) {
464  // We could become stuck.
465  risk += risk_cost->enemy_zoc_cost;
466  }
467 
468  return risk;
469 }
470 
478 static int prefer_short_stacks(const struct tile *ptile,
479  enum known_type known,
480  const struct pf_parameter *param)
481 {
482  return stack_risk(ptile, static_cast<struct adv_risk_cost *>(param->data),
483  param);
484 }
485 
490 void adv_avoid_risks(struct pf_parameter *parameter,
491  struct adv_risk_cost *risk_cost, struct unit *punit,
492  const double fearfulness)
493 {
494  /* If we stay a short time on each tile, the danger of each individual tile
495  * is reduced. If we do not do this,
496  * we will not favour longer but faster routs. */
497  const double linger_fraction =
498  static_cast<double> SINGLE_MOVE / parameter->move_rate;
499 
500  parameter->data = risk_cost;
501  parameter->get_EC = prefer_short_stacks;
502  risk_cost->base_value = unit_build_shield_cost_base(punit);
503  risk_cost->fearfulness = fearfulness * linger_fraction;
504 
505  risk_cost->enemy_zoc_cost = PF_TURN_FACTOR * 20;
506 }
bool is_action_enabled_unit_on_unit(const action_id wanted_action, const struct unit *actor_unit, const struct unit *target_unit)
Returns TRUE if actor_unit can do wanted_action to target_unit as far as action enablers are concerne...
Definition: actions.cpp:4007
int action_number(const struct action *action)
Get the universal number of the action.
Definition: actions.cpp:1338
bool is_action_enabled_unit_on_tile(const action_id wanted_action, const struct unit *actor_unit, const struct tile *target_tile, const struct extra_type *target_extra)
Returns TRUE if actor_unit can do wanted_action to the target_tile as far as action enablers are conc...
Definition: actions.cpp:4136
struct action * action_by_number(action_id act_id)
Return the action with the given id.
Definition: actions.cpp:1149
bool action_has_result(const struct action *paction, enum action_result result)
Returns TRUE iff performing the specified action has the specified result.
Definition: actions.cpp:1248
int adv_unit_def_rating_basic_squared(const struct unit *punit)
Square of the previous function - used in actual computations.
Definition: advgoto.cpp:307
static int stack_value(const struct tile *ptile, const struct player *pplayer)
The value of the units belonging to a given player on a given tile.
Definition: advgoto.cpp:374
int adv_unit_def_rating_basic(const struct unit *punit)
Basic (i.e.
Definition: advgoto.cpp:298
static int stack_risk(const struct tile *ptile, struct adv_risk_cost *risk_cost, const struct pf_parameter *param)
PF stack risk cost.
Definition: advgoto.cpp:443
bool adv_unit_execute_path(struct unit *punit, const PFPath &path)
This is a function to execute paths returned by the path-finding engine, for units controlled by advi...
Definition: advgoto.cpp:78
bool adv_danger_at(struct unit *punit, struct tile *ptile)
Are there dangerous enemies at or adjacent to the tile 'ptile'?
Definition: advgoto.cpp:317
static bool adv_unit_move(struct unit *punit, struct tile *ptile)
Move a unit.
Definition: advgoto.cpp:128
static double chance_killed_at(const struct tile *ptile, struct adv_risk_cost *risk_cost, const struct pf_parameter *param)
How dangerous would it be stop on a particular tile, because of enemy attacks, expressed as the proba...
Definition: advgoto.cpp:402
int adv_unittype_att_rating(const struct unit_type *punittype, int veteran, int moves_left, int hp)
Attack rating of this kind of unit.
Definition: advgoto.cpp:277
int adv_unit_att_rating(const struct unit *punit)
Attack rating of this particular unit assuming that it has a complete move left.
Definition: advgoto.cpp:288
static bool adv_could_be_my_zoc(struct unit *myunit, struct tile *ptile)
Similar to is_my_zoc(), but with some changes:
Definition: advgoto.cpp:222
bool adv_follow_path(struct unit *punit, const PFPath &path, struct tile *ptile)
Move a unit along a path without disturbing its activity, role or assigned destination Return FALSE i...
Definition: advgoto.cpp:43
int adv_could_unit_move_to_tile(struct unit *punit, struct tile *dest_tile)
returns: 0 if can't move 1 if zoc_ok -1 if zoc could be ok?
Definition: advgoto.cpp:252
void adv_avoid_risks(struct pf_parameter *parameter, struct adv_risk_cost *risk_cost, struct unit *punit, const double fearfulness)
Set PF callbacks to favour paths that do not create tall stacks or cross dangerous tiles.
Definition: advgoto.cpp:490
static int prefer_short_stacks(const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
PF extra cost call back to avoid creating tall stacks or crossing dangerous tiles.
Definition: advgoto.cpp:478
#define POWER_DIVIDER
Definition: advtools.h:25
#define CALL_PLR_AI_FUNC(_func, _player,...)
Definition: ai.h:383
struct city * is_non_allied_city_tile(const struct tile *ptile, const struct player *pplayer)
Is there an non_allied city on this tile?
Definition: city.cpp:1968
struct city * is_enemy_city_tile(const struct tile *ptile, const struct player *pplayer)
Is there an enemy city on this tile?
Definition: city.cpp:1923
struct player * city_owner(const struct city *pcity)
Return the owner of the city.
Definition: city.cpp:1083
int length() const
enum unit_attack_result unit_attack_unit_at_tile_result(const struct unit *punit, const struct unit *pdefender, const struct tile *dest_tile)
Checks if a unit can physically attack pdefender at the tile (assuming it is adjacent and at war).
Definition: combat.cpp:121
enum unit_attack_result unit_attack_units_at_tile_result(const struct unit *punit, const struct tile *ptile)
Check if unit can attack unit stack at tile.
Definition: combat.cpp:237
bool is_stack_vulnerable(const struct tile *ptile)
Is it a city/fortress/air base or will the whole stack die in an attack.
Definition: combat.cpp:839
int base_get_attack_power(const struct unit_type *punittype, int veteran, int moves_left)
Returns the attack power, modified by moves left, and veteran status.
Definition: combat.cpp:463
int base_get_defense_power(const struct unit *punit)
Returns the defense power, modified by veteran status.
Definition: combat.cpp:487
@ ATT_OK
Definition: combat.h:26
override_bool
Definition: fc_types.h:78
@ OVERRIDE_TRUE
Definition: fc_types.h:78
@ NO_OVERRIDE
Definition: fc_types.h:78
@ OVERRIDE_FALSE
Definition: fc_types.h:78
struct unit * game_unit_by_number(int id)
Find unit out of all units in game: now uses fast idex method, instead of looking through all units o...
Definition: game.cpp:112
struct world wld
Definition: game.cpp:48
constexpr auto LOG_DEBUG
Definition: log.h:27
#define fc_assert(condition)
Definition: log.h:89
bool is_tiles_adjacent(const struct tile *tile0, const struct tile *tile1)
Are two tiles adjacent to each other.
Definition: map.cpp:878
bool same_pos(const struct tile *tile1, const struct tile *tile2)
Are (x1,y1) and (x2,y2) really the same when adjusted? This function might be necessary ALOT of place...
Definition: map.cpp:887
#define adjc_iterate_end
Definition: map.h:358
#define adjc_iterate(nmap, center_tile, itr_tile)
Definition: map.h:351
static int map_move_cost_unit(const struct civ_map *nmap, struct unit *punit, const struct tile *ptile)
Definition: map.h:221
bool map_is_known_and_seen(const struct tile *ptile, const struct player *pplayer, enum vision_layer vlayer)
Returns whether the layer 'vlayer' of the tile 'ptile' is known and seen by the player 'pplayer'.
Definition: maphand.cpp:894
int unit_move_rate(const struct unit *punit)
This function calculates the move rate of the unit.
Definition: movement.cpp:78
bool can_unit_survive_at_tile(const struct civ_map *nmap, const struct unit *punit, const struct tile *ptile)
Return TRUE iff the unit can "survive" at this location.
Definition: movement.cpp:452
enum unit_move_result unit_move_to_tile_test(const struct civ_map *nmap, const struct unit *punit, enum unit_activity activity, const struct tile *src_tile, const struct tile *dst_tile, bool igzoc, struct unit *embark_to, bool enter_enemy_city)
Returns whether the unit can move from its current tile to the destination tile.
Definition: movement.cpp:566
#define SINGLE_MOVE
Definition: movement.h:17
unit_move_result
Definition: movement.h:25
@ MR_OK
Definition: movement.h:26
@ MR_ZOC
Definition: movement.h:31
#define PF_TURN_FACTOR
Definition: path_finding.h:250
bool pplayers_at_war(const struct player *pplayer, const struct player *pplayer2)
Returns true iff players can attack each other.
Definition: player.cpp:1317
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Returns true iff players are allied.
Definition: player.cpp:1334
#define is_ai(plr)
Definition: player.h:227
#define UNIT_LOG(_, punit, msg,...)
Definition: srv_log.h:95
double enemy_zoc_cost
Definition: advgoto.h:25
double base_value
Definition: advgoto.h:23
double fearfulness
Definition: advgoto.h:24
Definition: city.h:291
const struct civ_map * map
Definition: path_finding.h:340
int(* get_EC)(const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
Definition: path_finding.h:387
const struct player * owner
Definition: path_finding.h:356
const struct unit_type * utype
Definition: path_finding.h:355
Definition: player.h:231
Definition: tile.h:42
struct unit_list * units
Definition: tile.h:50
int firepower
Definition: unittype.h:490
Definition: unit.h:134
enum unit_activity activity
Definition: unit.h:154
int moves_left
Definition: unit.h:147
int id
Definition: unit.h:141
int hp
Definition: unit.h:148
struct tile * tile
Definition: unit.h:136
struct extra_type * activity_target
Definition: unit.h:161
struct tile * goto_tile
Definition: unit.h:152
int veteran
Definition: unit.h:149
struct civ_map map
Definition: world_object.h:21
#define is_ocean_tile(ptile)
Definition: terrain.h:279
#define terrain_has_flag(terr, flag)
Definition: terrain.h:260
int tile_extras_class_defense_bonus(const struct tile *ptile, const struct unit_class *pclass)
Calculate defense bonus given for unit class by extras.
Definition: tile.cpp:232
int tile_extras_defense_bonus(const struct tile *ptile, const struct unit_type *punittype)
Calculate defense bonus given for unit type by bases and roads.
Definition: tile.cpp:223
struct city * tile_city(const struct tile *ptile)
Return the city on this tile (or nullptr), checking for city center.
Definition: tile.cpp:72
#define tile_index(_pt_)
Definition: tile.h:70
known_type
Definition: tile.h:28
#define tile_terrain(_tile)
Definition: tile.h:93
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
bool is_my_zoc(const struct player *pplayer, const struct tile *ptile0, const struct civ_map *zmap)
Is this square controlled by the pplayer?
Definition: unit.cpp:1341
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
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
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
#define unit_tile(_pu)
Definition: unit.h:371
#define unit_owner(_pu)
Definition: unit.h:370
bool unit_move_handling(struct unit *punit, struct tile *pdesttile, bool igzoc, bool move_do_not_act)
Will try to move to/attack the tile dest_x,dest_y.
Definition: unithand.cpp:4654
bool unit_activity_handling(struct unit *punit, enum unit_activity new_activity)
Handle request for changing activity.
Definition: unithand.cpp:5485
void unit_do_action(struct player *pplayer, const int actor_id, const int target_id, const int sub_tgt_id, const char *name, const action_id action_type)
Handle unit action.
Definition: unithand.cpp:2718
bool unit_activity_handling_targeted(struct unit *punit, enum unit_activity new_activity, struct extra_type **new_target)
Handle request for targeted activity.
Definition: unithand.cpp:5551
#define unit_list_iterate(unitlist, punit)
Definition: unitlist.h:25
#define unit_list_iterate_end
Definition: unitlist.h:27
bool unit_move(struct unit *punit, struct tile *pdesttile, int move_cost, struct unit *embark_to, bool find_embark_target, bool conquer_city_allowed)
Moves a unit.
Definition: unittools.cpp:3878
void send_unit_info(struct conn_list *dest, struct unit *punit)
Send the unit to the players who need the info.
Definition: unittools.cpp:2808
const struct unit_type * unit_type_get(const struct unit *punit)
Return the unit type for this unit.
Definition: unittype.cpp:114
bool utype_is_moved_to_tgt_by_action(const struct action *paction, const struct unit_type *utype)
Returns TRUE iff successfully performing the specified action always will move the actor unit of the ...
Definition: unittype.cpp:969
int unit_build_shield_cost_base(const struct unit *punit)
Returns the number of shields this unit represents.
Definition: unittype.cpp:1185
bool unit_has_type_flag(const struct unit *punit, enum unit_type_flag_id flag)
Return whether the unit has the given flag.
Definition: unittype.cpp:176
#define utype_class(_t_)
Definition: unittype.h:691