Freeciv-3.1: /fast/freeciv/nightly/S3_1/server/unittools.c File Reference

Freeciv-3.1

Loading...
Searching...
No Matches
Data Structures | Macros | Functions
unittools.c File Reference
`#include <stdio.h>`
`#include <stdlib.h>`
`#include <string.h>`
`#include "bitvector.h"`
`#include "fcintl.h"`
`#include "log.h"`
`#include "mem.h"`
`#include "rand.h"`
`#include "shared.h"`
`#include "support.h"`
`#include "base.h"`
`#include "city.h"`
`#include "combat.h"`
`#include "events.h"`
`#include "game.h"`
`#include "government.h"`
`#include "idex.h"`
`#include "map.h"`
`#include "movement.h"`
`#include "packets.h"`
`#include "player.h"`
`#include "research.h"`
`#include "terrain.h"`
`#include "unit.h"`
`#include "unitlist.h"`
`#include "unittype.h"`
`#include "luascript_signal.h"`
`#include "luascript_types.h"`
`#include "path_finding.h"`
`#include "pf_tools.h"`
`#include "script_server.h"`
`#include "actiontools.h"`
`#include "aiiface.h"`
`#include "barbarian.h"`
`#include "citytools.h"`
`#include "cityturn.h"`
`#include "diplhand.h"`
`#include "gamehand.h"`
`#include "maphand.h"`
`#include "notify.h"`
`#include "plrhand.h"`
`#include "sanitycheck.h"`
`#include "sernet.h"`
`#include "srv_main.h"`
`#include "techtools.h"`
`#include "unithand.h"`
`#include "advgoto.h"`
`#include "autoexplorer.h"`
`#include "autosettlers.h"`
`#include "handicaps.h"`
`#include "unittools.h"`
`#include "speclist.h"`

Go to the source code of this file.

## Data Structures

struct | unit_move_data
struct | autoattack_prob

## Macros

#define | SPECLIST_TAG unit_move_data
#define | unit_move_data_list_iterate(_plist, _pdata) TYPED_LIST_ITERATE(struct unit_move_data, _plist, _pdata)
#define | unit_move_data_list_iterate_end LIST_ITERATE_END
#define | unit_move_data_list_iterate_rev(_plist, _pdata) TYPED_LIST_ITERATE_REV(struct unit_move_data, _plist, _pdata)
#define | unit_move_data_list_iterate_rev_end LIST_ITERATE_REV_END
#define | SPECLIST_TAG autoattack_prob
#define | SPECLIST_TYPE struct autoattack_prob
#define | autoattack_prob_list_iterate_safe(autoattack_prob_list, _aap_, _unit_)
#define | autoattack_prob_list_iterate_safe_end LIST_ITERATE_END

## Functions

static void | unit_restore_hitpoints (struct unit *punit)
static void | unit_restore_movepoints (struct player *pplayer, struct unit *punit)
static void | update_unit_activity (struct unit *punit)
static bool | try_to_save_unit (struct unit *punit, const struct unit_type *pttype, bool helpless, bool teleporting, const struct city *pexclcity)
static void | wakeup_neighbor_sentries (struct unit *punit)
static void | do_upgrade_effects (struct player *pplayer)
static bool | maybe_cancel_patrol_due_to_enemy (struct unit *punit)
static bool | maybe_become_veteran_real (struct unit *punit, int base_chance, bool settler)
static void | unit_transport_load_tp_status (struct unit *punit, struct unit *ptrans, bool force)
static void | wipe_unit_full (struct unit *punit, bool transported, enum unit_loss_reason reason, struct player *killer)
static int | get_unit_vision_base (struct unit *punit, enum vision_layer vlayer, const int base)
static int | unit_vision_range_modifiers (struct unit *punit, const struct tile *ptile)
struct unit_type * | find_a_unit_type (enum unit_role_id role, enum unit_role_id role_tech)
bool | maybe_make_veteran (struct unit *punit, int base_chance)
bool | unit_versus_unit (struct unit *attacker, struct unit *defender, int *att_hp, int *def_hp, int *att_vet, int *def_vet)
void | unit_bombs_unit (struct unit *attacker, struct unit *defender, int *att_hp, int *def_hp)
void | combat_veterans (struct unit *attacker, struct unit *defender, bool powerless, int att_vet, int def_vet)
void | player_restore_units (struct player *pplayer)
void | update_unit_activities (struct player *pplayer)
void | execute_unit_orders (struct player *pplayer)
void | unit_tc_effect_refresh (struct player *pplayer)
void | finalize_unit_phase_beginning (struct player *pplayer)
static int | total_activity (struct tile *ptile, enum unit_activity act, struct extra_type *tgt)
static bool | total_activity_done (struct tile *ptile, enum unit_activity act, struct extra_type *tgt)
void | notify_unit_experience (struct unit *punit)
static void | unit_convert (struct unit *punit)
void | unit_activities_cancel (struct unit *punit)
void | unit_activities_cancel_all_illegal_plr (const struct player *pplayer)
void | unit_activities_cancel_all_illegal_tile (const struct tile *ptile)
void | unit_activities_cancel_all_illegal_area (const struct tile *ptile)
void | unit_forget_last_activity (struct unit *punit)
bool | unit_activity_needs_target_from_client (enum unit_activity activity)
void | unit_assign_specific_activity_target (struct unit *punit, enum unit_activity *activity, struct extra_type **target)
static bool | find_a_good_partisan_spot (struct tile *pcenter, struct player *powner, struct unit_type *u_type, int sq_radius, struct tile **dst_tile)
void | place_partisans (struct tile *pcenter, struct player *powner, int count, int sq_radius)
bool | teleport_unit_to_city (struct unit *punit, struct city *pcity, int move_cost, bool verbose)
void | bounce_unit (struct unit *punit, bool verbose)
static void | throw_units_from_illegal_cities (struct player *pplayer, bool verbose)
static void | resolve_stack_conflicts (struct player *pplayer, struct player *aplayer, bool verbose)
void | resolve_unit_stacks (struct player *pplayer, struct player *aplayer, bool verbose)
struct unit_list * | get_units_seen_via_ally (const struct player *pplayer, const struct player *aplayer)
void | remove_allied_visibility (struct player *pplayer, struct player *aplayer, const struct unit_list *seen_units)
void | give_allied_visibility (struct player *pplayer, struct player *aplayer)
static bool | is_refuel_tile (const struct tile *ptile, const struct player *pplayer, const struct unit *punit)
bool | is_unit_being_refueled (const struct unit *punit)
bool | is_refuel_point (const struct tile *ptile, const struct player *pplayer, const struct unit *punit)
void | transform_unit (struct unit *punit, const struct unit_type *to_unit, int vet_loss)
struct unit * | create_unit (struct player *pplayer, struct tile *ptile, const struct unit_type *type, int veteran_level, int homecity_id, int moves_left)
void | unit_get_goods (struct unit *punit)
struct unit * | create_unit_full (struct player *pplayer, struct tile *ptile, const struct unit_type *type, int veteran_level, int homecity_id, int moves_left, int hp_left, struct unit *ptrans)
struct unit * | unit_virtual_prepare (struct player *pplayer, struct tile *ptile, const struct unit_type *type, int veteran_level, int homecity_id, int moves_left, int hp_left)
bool | place_unit (struct unit *punit, struct player *pplayer, struct city *pcity, struct unit *ptrans, bool force)
void | unit_set_removal_callback (struct unit *punit, void(*callback)(struct unit *punit))
void | unit_unset_removal_callback (struct unit *punit)
static void | server_remove_unit_full (struct unit *punit, bool transported, enum unit_loss_reason reason)
static void | server_remove_unit (struct unit *punit, enum unit_loss_reason reason)
static void | unit_lost_with_transport (const struct player *pplayer, struct unit *pcargo, const struct unit_type *ptransport, struct player *killer)
void | wipe_unit (struct unit *punit, enum unit_loss_reason reason, struct player *killer)
struct unit * | unit_change_owner (struct unit *punit, struct player *pplayer, int homecity, enum unit_loss_reason reason)
void | kill_unit (struct unit *pkiller, struct unit *punit, bool vet)
void | package_unit (struct unit *punit, struct packet_unit_info *packet)
void | package_short_unit (struct unit *punit, struct packet_unit_short_info *packet, enum unit_info_use packet_use, int info_city_id)
void | unit_goes_out_of_sight (struct player *pplayer, struct unit *punit)
void | send_unit_info (struct conn_list *dest, struct unit *punit)
void | send_all_known_units (struct conn_list *dest)
static void | do_nuke_tile (struct player *pplayer, struct tile *ptile)
void | do_nuclear_explosion (struct player *pplayer, struct tile *ptile)
bool | do_airline (struct unit *punit, struct city *pdest_city, const struct action *paction)
void | do_explore (struct unit *punit)
bool | do_paradrop (struct unit *punit, struct tile *ptile, const struct action *paction)
static bool | hut_get_limited (struct unit *punit)
static void | unit_enter_hut (struct unit *punit, bool frighten_hut)
void | unit_transport_load_send (struct unit *punit, struct unit *ptrans)
void | unit_transport_unload_send (struct unit *punit)
static void | autoattack_prob_free (struct autoattack_prob *prob)
static int | compare_units (const struct autoattack_prob *const *p1, const struct autoattack_prob *const *q1)
static bool | unit_survive_autoattack (struct unit *punit)
static void | cancel_orders (struct unit *punit, char *dbg_msg)
static bool | unit_move_consequences (struct unit *punit, struct tile *src_tile, struct tile *dst_tile, bool passenger, bool conquer_city_allowed)
static void | check_unit_activity (struct unit *punit)
static struct unit_move_data * | unit_move_data (struct unit *punit, struct tile *psrctile, struct tile *pdesttile)
static void | unit_move_by_data (struct unit_move_data *pdata, struct tile *psrctile, struct tile *pdesttile)
static void | unit_move_data_unref (struct unit_move_data *pdata)
bool | unit_move (struct unit *punit, struct tile *pdesttile, int move_cost, struct unit *embark_to, bool find_embark_target, bool conquer_city_allowed, bool conquer_extras_allowed, bool enter_hut, bool frighten_hut)
static bool | maybe_cancel_goto_due_to_enemy (struct unit *punit, struct tile *ptile)
static bool | player_is_watching (struct unit *punit, const bool fresh)
bool | execute_orders (struct unit *punit, const bool fresh)
int | get_unit_vision_at (struct unit *punit, const struct tile *ptile, enum vision_layer vlayer)
void | unit_refresh_vision (struct unit *punit)
void | unit_list_refresh_vision (struct unit_list *punitlist)
bool | unit_can_do_action_now (const struct unit *punit)
void | unit_did_action (struct unit *punit)
bool | unit_can_be_retired (struct unit *punit)

## Macro Definition Documentation

## ◆ autoattack_prob_list_iterate_safe

#define autoattack_prob_list_iterate_safe | ( |  | autoattack_prob_list,
|  |  | _aap_,
|  |  | _unit_
| ) |  |

Value:
TYPED_LIST_ITERATE(struct autoattack_prob, autoattack_prob_list, _aap_) \
struct unit *_unit_ = game_unit_by_number(_aap_->unit_id); \
\
if (_unit_ == NULL) { \
continue; \
}
game_unit_by_number
struct unit * game_unit_by_number(int id)
Definition game.c:111
TYPED_LIST_ITERATE
#define TYPED_LIST_ITERATE(TYPE_data, ARG_list, NAME_data)
Definition speclist.h:575
autoattack_prob
Definition unittools.c:113
unit
Definition unit.h:138

Definition at line 122 of file unittools.c.

## ◆ autoattack_prob_list_iterate_safe_end

#define autoattack_prob_list_iterate_safe_end LIST_ITERATE_END

Definition at line 131 of file unittools.c.

## ◆ SPECLIST_TAG [1/2]

#define SPECLIST_TAG unit_move_data

Definition at line 100 of file unittools.c.

## ◆ SPECLIST_TAG [2/2]

#define SPECLIST_TAG autoattack_prob

Definition at line 100 of file unittools.c.

## ◆ SPECLIST_TYPE

#define SPECLIST_TYPE struct autoattack_prob

Definition at line 119 of file unittools.c.

## ◆ unit_move_data_list_iterate

#define unit_move_data_list_iterate | ( |  | _plist,
|  |  | _pdata
| ) |  | TYPED_LIST_ITERATE(struct unit_move_data, _plist, _pdata)

Definition at line 102 of file unittools.c.

## ◆ unit_move_data_list_iterate_end

#define unit_move_data_list_iterate_end LIST_ITERATE_END

Definition at line 104 of file unittools.c.

## ◆ unit_move_data_list_iterate_rev

#define unit_move_data_list_iterate_rev | ( |  | _plist,
|  |  | _pdata
| ) |  | TYPED_LIST_ITERATE_REV(struct unit_move_data, _plist, _pdata)

Definition at line 105 of file unittools.c.

## ◆ unit_move_data_list_iterate_rev_end

#define unit_move_data_list_iterate_rev_end LIST_ITERATE_REV_END

Definition at line 107 of file unittools.c.

## Function Documentation

## ◆ autoattack_prob_free()

static void autoattack_prob_free | ( | struct autoattack_prob * | prob | ) |

static

Used when unit_survive_autoattack()'s autoattack_prob_list autoattack frees its items.

Definition at line 3347 of file unittools.c.

Referenced by unit_survive_autoattack().

## ◆ bounce_unit()

void bounce_unit | ( | struct unit * | punit,
|  | bool | verbose
| ) |  |

Move or remove a unit due to stack conflicts. This function will try to find a random safe tile within a two tile distance of the unit's current tile and move the unit there. If no tiles are found, the unit is disbanded. If 'verbose' is TRUE, a message is sent to the unit owner regarding what happened.

Definition at line 1245 of file unittools.c.

Referenced by bounce_unit(), diplomat_bribe(), do_capture_units(), resolve_stack_conflicts(), sg_load_sanitycheck(), sg_load_sanitycheck(), throw_units_from_illegal_cities(), transfer_city_units(), and transfer_unit().

## ◆ cancel_orders()

static void cancel_orders | ( | struct unit * | punit,
|  | char * | dbg_msg
| ) |  |

static

Cancel orders for the unit.

Definition at line 3535 of file unittools.c.

Referenced by execute_orders(), and wakeup_neighbor_sentries().

## ◆ check_unit_activity()

static void check_unit_activity | ( | struct unit * | punit | ) |

static

Check if the units activity is legal for a move , and reset it if it isn't.

Definition at line 3732 of file unittools.c.

Referenced by unit_move_by_data().

## ◆ combat_veterans()

void combat_veterans | ( | struct unit * | attacker,
|  | struct unit * | defender,
|  | bool | powerless,
|  | int | att_vet,
|  | int | def_vet
| ) |  |

Maybe make either side of combat veteran. Powerless means that either side of the combat was completely powerless.

Definition at line 392 of file unittools.c.

Referenced by do_attack().

## ◆ compare_units()

static int compare_units | ( | const struct autoattack_prob *const * | p1,
|  | const struct autoattack_prob *const * | q1
| ) |  |

static

This function is passed to autoattack_prob_list_sort() to sort a list of units and action probabilities according to their win chance against the autoattack target, modified by transportation relationships.

The reason for making sure that a cargo unit is ahead of its transporter(s) is to leave transports out of combat if at all possible. (The transport could be destroyed during combat.)

Definition at line 3361 of file unittools.c.

Referenced by unit_survive_autoattack().

## ◆ create_unit()

struct unit * create_unit | ( | struct player * | pplayer,
|  | struct tile * | ptile,
|  | const struct unit_type * | type,
|  | int | veteran_level,
|  | int | homecity_id,
|  | int | moves_left
| ) |  |

Wrapper of the below

Definition at line 1619 of file unittools.c.

Referenced by give_midgame_initial_units(), handle_edit_unit_create(), place_animal(), place_starting_unit(), try_summon_barbarians(), and unleash_barbarians().

## ◆ create_unit_full()

struct unit * create_unit_full | ( | struct player * | pplayer,
|  | struct tile * | ptile,
|  | const struct unit_type * | type,
|  | int | veteran_level,
|  | int | homecity_id,
|  | int | moves_left,
|  | int | hp_left,
|  | struct unit * | ptrans
| ) |  |

Creates a unit, sets its initial values, and puts it into the right lists. The unit must be placed to a valid tile or a loadable transport. See unit_virtual_prepare() for the processing of moves_left and hp_left

Definition at line 1646 of file unittools.c.

Referenced by create_unit(), and try_summon_barbarians().

## ◆ do_airline()

bool do_airline | ( | struct unit * | punit,
|  | struct city * | pdest_city,
|  | const struct action * | paction
| ) |  |

Go by airline, if both cities have an airport and neither has been used this turn the unit will be transported by it and have its moves set to 0

Definition at line 2966 of file unittools.c.

Referenced by unit_perform_action().

## ◆ do_explore()

void do_explore | ( | struct unit * | punit | ) |

Autoexplore with unit.

Definition at line 2999 of file unittools.c.

Referenced by handle_unit_server_side_agent_set(), and update_unit_activity().

## ◆ do_nuclear_explosion()

void do_nuclear_explosion | ( | struct player * | pplayer,
|  | struct tile * | ptile
| ) |  |

Nuke all the squares in a 3x3 square around the center of the explosion pplayer is the player that caused the explosion.

Definition at line 2949 of file unittools.c.

Referenced by spy_nuke_city(), and unit_nuke().

## ◆ do_nuke_tile()

static void do_nuke_tile | ( | struct player * | pplayer,
|  | struct tile * | ptile
| ) |  |

static

Nuke a square: 1) remove all units on the square, and 2) halve the size of the city on the square.

If it isn't a city square or an ocean square then with 50% chance add some fallout, then notify the client about the changes.

Definition at line 2869 of file unittools.c.

Referenced by do_nuclear_explosion().

## ◆ do_paradrop()

bool do_paradrop | ( | struct unit * | punit,
|  | struct tile * | ptile,
|  | const struct action * | paction
| ) |  |

Returns whether the drop was made or not. Note that it also returns 1 in the case where the drop was successful, but the unit was killed by barbarians in a hut.

Definition at line 3035 of file unittools.c.

Referenced by unit_perform_action().

## ◆ do_upgrade_effects()

static void do_upgrade_effects | ( | struct player * | pplayer | ) |

static

Do unit auto-upgrades to players with the EFT_UNIT_UPGRADE effect (traditionally from Leonardo's Workshop).

Definition at line 416 of file unittools.c.

Referenced by player_restore_units().

## ◆ execute_orders()

bool execute_orders | ( | struct unit * | punit,
|  | const bool | fresh
| ) |  |

Executes a unit's orders stored in punit->orders. The unit is put on idle if an action fails or if "patrol" is set and an enemy unit is encountered.

The return value will be TRUE if the unit lives, FALSE otherwise. (This function used to return a goto_result enumeration, declared in gotohand.h. But this enumeration was never checked by the caller and just lead to confusion. All the caller really needs to know is if the unit lived or died; everything else is handled internally within execute_orders.)

If the orders are repeating the loop starts over at the beginning once it completes. To avoid infinite loops on railroad we stop for this turn when the unit is back where it started, even if it have moves left.

A unit will attack under orders only on its final action.

The fresh parameter is true if the order execution happens because the orders just were received.

Definition at line 4370 of file unittools.c.

Referenced by execute_unit_orders(), and handle_unit_orders().

## ◆ execute_unit_orders()

void execute_unit_orders | ( | struct player * | pplayer | ) |

Iterate through all units and execute their orders.

Definition at line 668 of file unittools.c.

Referenced by begin_phase().

## ◆ finalize_unit_phase_beginning()

void finalize_unit_phase_beginning | ( | struct player * | pplayer | ) |

Iterate through all units and remember their current activities.

Definition at line 690 of file unittools.c.

Referenced by begin_phase().

## ◆ find_a_good_partisan_spot()

static bool find_a_good_partisan_spot | ( | struct tile * | pcenter,
|  | struct player * | powner,
|  | struct unit_type * | u_type,
|  | int | sq_radius,
|  | struct tile ** | dst_tile
| ) |  |

static

Find place to place partisans. Returns whether such spot was found, and if it has been found, dst_tile contains that tile.

Definition at line 1133 of file unittools.c.

Referenced by place_partisans().

## ◆ find_a_unit_type()

struct unit_type * find_a_unit_type | ( | enum unit_role_id | role,
|  | enum unit_role_id | role_tech
| ) |  |

Returns a unit type that matches the role_tech or role roles.

If role_tech is given, then we look at all units with this role whose requirements are met by any player, and return a random one. This can be used to give a unit to barbarians taken from the set of most advanced units researched by the 'real' players.

If role_tech is not give (-1) or if there are no matching unit types, then we look at 'role' value and return a random matching unit type.

It is an error if there are no available units. This function will always return a valid unit.

Definition at line 174 of file unittools.c.

Referenced by try_summon_barbarians(), and unleash_barbarians().

## ◆ get_unit_vision_at()

int get_unit_vision_at | ( | struct unit * | punit,
|  | const struct tile * | ptile,
|  | enum vision_layer | vlayer
| ) |  |

Return the vision the unit will have at the given tile. The base vision range may be modified by effects.

Note that vision MUST be independent of transported_by for this to work properly.

Definition at line 4837 of file unittools.c.

Referenced by maybe_cancel_patrol_due_to_enemy(), and wakeup_neighbor_sentries().

## ◆ get_unit_vision_base()

static int get_unit_vision_base | ( | struct unit * | punit,
|  | enum vision_layer | vlayer,
|  | const int | base
| ) |  |

static

Return the base vision range the unit will have at the given tile. Modifier effects are not considered here.

Note that vision MUST be independent of transported_by for this to work properly.

Definition at line 4798 of file unittools.c.

Referenced by get_unit_vision_at(), unit_move_by_data(), and unit_refresh_vision().

## ◆ get_units_seen_via_ally()

struct unit_list * get_units_seen_via_ally | ( | const struct player * | pplayer,
|  | const struct player * | aplayer
| ) |  |

Returns the list of the units seen by 'pplayer' potentially seen only thanks to an alliance with 'aplayer'. The returned pointer is newly allocated and should be freed by the caller, using unit_list_destroy().

Definition at line 1433 of file unittools.c.

Referenced by handle_diplomacy_accept_treaty_req(), and handle_diplomacy_cancel_pact().

## ◆ give_allied_visibility()

void give_allied_visibility | ( | struct player * | pplayer,
|  | struct player * | aplayer
| ) |  |

Refresh units visibility of 'aplayer' for 'pplayer' after alliance have been contracted.

Definition at line 1492 of file unittools.c.

Referenced by handle_diplomacy_accept_treaty_req().

## ◆ hut_get_limited()

static bool hut_get_limited | ( | struct unit * | punit | ) |

static

Give 25 Gold or kill the unit. For H_LIMITEDHUTS Return TRUE if unit is alive, and FALSE if it was killed

Definition at line 3193 of file unittools.c.

Referenced by unit_enter_hut().

## ◆ is_refuel_point()

bool is_refuel_point | ( | const struct tile * | ptile,
|  | const struct player * | pplayer,
|  | const struct unit * | punit
| ) |  |

Can unit refuel on tile. Considers also carrier capacity on tile.

Definition at line 1547 of file unittools.c.

Referenced by dai_find_strategic_airbase(), dai_manage_airunit(), find_nearest_airbase(), and player_restore_units().

## ◆ is_refuel_tile()

static bool is_refuel_tile | ( | const struct tile * | ptile,
|  | const struct player * | pplayer,
|  | const struct unit * | punit
| ) |  |

static

Will unit refuel at this tile? Does not consider carriers.

Definition at line 1505 of file unittools.c.

Referenced by is_refuel_point(), and is_unit_being_refueled().

## ◆ is_unit_being_refueled()

bool is_unit_being_refueled | ( | const struct unit * | punit | ) |

Is unit being refueled in its current position?

Definition at line 1538 of file unittools.c.

Referenced by dai_find_strategic_airbase(), dai_manage_airunit(), and player_restore_units().

## ◆ kill_unit()

void kill_unit | ( | struct unit * | pkiller,
|  | struct unit * | punit,
|  | bool | vet
| ) |  |

Called when one unit kills another in combat (this function is only called in one place). It handles all side effects including notifications and killstack.

Definition at line 2377 of file unittools.c.

Referenced by do_attack().

## ◆ maybe_become_veteran_real()

static bool maybe_become_veteran_real | ( | struct unit * | punit,
|  | int | base_chance,
|  | bool | settler
| ) |  |

static

After a battle and after diplomatic aggression this routine is called to decide whether or not the unit should become more experienced.

There is a specified chance for it to happen. The base chances are specified in the units.ruleset file. Before the chance is passed to this function, it might get modified by the factor related to how challenging the battle was. This function applies modifiers from effects.

If 'settler' is TRUE the veteran level is increased due to work done by the unit.

Definition at line 235 of file unittools.c.

Referenced by maybe_make_veteran(), and update_unit_activity().

## ◆ maybe_cancel_goto_due_to_enemy()

static bool maybe_cancel_goto_due_to_enemy | ( | struct unit * | punit,
|  | struct tile * | ptile
| ) |  |

static

Maybe cancel the goto if there is an enemy in the way

Definition at line 4301 of file unittools.c.

Referenced by execute_orders().

## ◆ maybe_cancel_patrol_due_to_enemy()

static bool maybe_cancel_patrol_due_to_enemy | ( | struct unit * | punit | ) |

static

Maybe cancel the patrol as there is an enemy near.

If you modify the wakeup range you should change it in wakeup_neighbor_sentries() too.

Definition at line 4314 of file unittools.c.

Referenced by execute_orders(), and wakeup_neighbor_sentries().

## ◆ maybe_make_veteran()

bool maybe_make_veteran | ( | struct unit * | punit,
|  | int | base_chance
| ) |  |

Unit has a chance to become veteran. This should not be used for settlers for the work they do.

Definition at line 217 of file unittools.c.

Referenced by combat_veterans(), diplomat_bribe(), diplomat_escape_full(), and diplomat_infiltrate_tile().

## ◆ notify_unit_experience()

void notify_unit_experience | ( | struct unit * | punit | ) |

Common notification for all experience levels.

Definition at line 735 of file unittools.c.

Referenced by diplomat_bribe(), diplomat_escape_full(), diplomat_infiltrate_tile(), do_attack(), kill_unit(), and update_unit_activity().

## ◆ package_short_unit()

void package_short_unit | ( | struct unit * | punit,
|  | struct packet_unit_short_info * | packet,
|  | enum unit_info_use | packet_use,
|  | int | info_city_id
| ) |  |

Package a short_unit_info packet. This contains a limited amount of information about the unit, and is sent to players who shouldn't know everything (like the unit's owner's enemies).

Definition at line 2736 of file unittools.c.

Referenced by diplomat_investigate(), see_combat(), send_unit_info(), and unit_move().

## ◆ package_unit()

void package_unit | ( | struct unit * | punit,
|  | struct packet_unit_info * | packet
| ) |  |

Package a unit_info packet. This packet contains basically all information about a unit.

Definition at line 2653 of file unittools.c.

Referenced by see_combat(), send_unit_info(), and unit_move().

## ◆ place_partisans()

void place_partisans | ( | struct tile * | pcenter,
|  | struct player * | powner,
|  | int | count,
|  | int | sq_radius
| ) |  |

Place partisans for powner around pcenter (normally around a city).

Definition at line 1181 of file unittools.c.

Referenced by api_edit_place_partisans().

## ◆ place_unit()

bool place_unit | ( | struct unit * | punit,
|  | struct player * | pplayer,
|  | struct city * | pcity,
|  | struct unit * | ptrans,
|  | bool | force
| ) |  |

Places a virtual unit into the game, assigning it an index, putting it on the right lists and dispatching the information around. The unit must have a tile, pcity and pplayer must be valid and accord to the unit's fields (basically, set by unit_virtual_prepare()). ptrans if not NULL must be a transporter on the same tile the unit can freely load into (or just that can transport it if force) Returns if the unit is placed (must be TRUE if input data are valid)

Definition at line 1727 of file unittools.c.

Referenced by api_edit_create_unit_full(), city_create_unit(), create_unit_full(), place_partisans(), and unit_change_owner().

## ◆ player_is_watching()

static bool player_is_watching | ( | struct unit * | punit,
|  | const bool | fresh
| ) |  |

inlinestatic

Returns TRUE iff it is reasonable to assume that the player is wathing the unit.

Since the player is watching the unit there is no need to inform them about things they could see happening. Remember that it still may be necessary to explain why something happened.

Definition at line 4343 of file unittools.c.

Referenced by execute_orders().

## ◆ player_restore_units()

void player_restore_units | ( | struct player * | pplayer | ) |

1. Do Leonardo's Workshop upgrade if applicable.
2. Restore/decrease unit hitpoints.
3. Kill dead units.
4. Rescue airplanes by returning them to base automatically.
5. Decrease fuel of planes in the air.
6. Refuel planes that are in bases.
7. Kill planes that are out of fuel.

Definition at line 469 of file unittools.c.

Referenced by end_phase().

## ◆ remove_allied_visibility()

void remove_allied_visibility | ( | struct player * | pplayer,
|  | struct player * | aplayer,
|  | const struct unit_list * | seen_units
| ) |  |

When two players cancel an alliance, a lot of units that were visible may no longer be visible (this includes units in transporters and cities). Call this function to inform the clients that these units are no longer visible. Pass the list of seen units returned by get_units_seen_via_ally() before alliance was broken up.

Definition at line 1468 of file unittools.c.

Referenced by update_players_after_alliance_breakup().

## ◆ resolve_stack_conflicts()

static void resolve_stack_conflicts | ( | struct player * | pplayer,
|  | struct player * | aplayer,
|  | bool | verbose
| ) |  |

static

For each pplayer's unit, check if we stack illegally, if so, bounce both players' units. If on ocean tile, bounce everyone but ships to avoid drowning. This function assumes that cities are clean.

If verbose is true, the unit owner gets messages about where each units goes.

Definition at line 1389 of file unittools.c.

Referenced by resolve_unit_stacks().

## ◆ resolve_unit_stacks()

void resolve_unit_stacks | ( | struct player * | pplayer,
|  | struct player * | aplayer,
|  | bool | verbose
| ) |  |

When in civil war or an alliance breaks there will potentially be units from both sides coexisting on the same squares. This routine resolves this by first bouncing off non-allied units from their cities, then by bouncing both players' units in now illegal multiowner stacks. To avoid drowning due to removal of transports, we bounce everyone (including third parties' units) from ocean tiles.

If verbose is true, the unit owner gets messages about where each units goes.

Definition at line 1418 of file unittools.c.

Referenced by civil_war(), kill_player(), sg_load_sanitycheck(), sg_load_sanitycheck(), transfer_city(), and update_players_after_alliance_breakup().

## ◆ send_all_known_units()

void send_all_known_units | ( | struct conn_list * | dest | ) |

For each specified connections, send information about all the units known to that player/conn.

Definition at line 2841 of file unittools.c.

Referenced by send_all_info().

## ◆ send_unit_info()

void send_unit_info | ( | struct conn_list * | dest,
|  | struct unit * | punit
| ) |  |

Send the unit to the players who need the info. dest = NULL means all connections (game.est_connections)

Definition at line 2797 of file unittools.c.

Referenced by action_success_pay_mp(), action_success_target_pay_mp(), adv_follow_path(), api_edit_unit_turn(), auto_settler_findwork(), auto_settler_setup_work(), cancel_orders(), city_units_upkeep(), dai_auto_settler_run(), dai_unit_goto_constrained(), destroy_extra(), diplomat_bribe(), diplomat_embassy(), diplomat_escape_full(), diplomat_get_tech(), diplomat_infiltrate_tile(), diplomat_investigate(), diplomat_sabotage(), do_attack(), do_capture_units(), do_expel_unit(), do_explore(), do_heal_unit(), execute_orders(), finalize_unit_phase_beginning(), give_allied_visibility(), handle_edit_unit(), handle_unit_orders(), handle_unit_sscs_set(), illegal_action_pay_price(), map_change_seen(), map_claim_base(), map_show_tile(), place_animal(), place_unit(), player_restore_units(), remove_city(), send_all_known_units(), server_remove_unit_full(), spy_sabotage_unit(), transfer_city(), transform_unit(), try_summon_barbarians(), try_to_save_unit(), unit_activities_cancel(), unit_activity_dependencies(), unit_activity_internal(), unit_activity_targeted_internal(), unit_bombard(), unit_change_homecity_handling(), unit_lost_with_transport(), unit_move(), unit_move_handling(), unit_server_side_agent_set(), unit_survive_autoattack(), unit_transport_load_send(), unit_transport_load_tp_status(), unit_transport_unload_send(), unleash_barbarians(), wakeup_neighbor_sentries(), and wipe_unit_full().

## ◆ server_remove_unit()

static void server_remove_unit | ( | struct unit * | punit,
|  | enum unit_loss_reason | reason
| ) |  |

static

We remove the unit and see if it's disappearance has affected the homecity and the city it was in.

Definition at line 1929 of file unittools.c.

Referenced by do_paradrop().

## ◆ server_remove_unit_full()

static void server_remove_unit_full | ( | struct unit * | punit,
|  | bool | transported,
|  | enum unit_loss_reason | reason
| ) |  |

static

We remove the unit and see if it's disappearance has affected the homecity and the city it was in.

Definition at line 1808 of file unittools.c.

Referenced by server_remove_unit(), and wipe_unit_full().

## ◆ teleport_unit_to_city()

bool teleport_unit_to_city | ( | struct unit * | punit,
|  | struct city * | pcity,
|  | int | move_cost,
|  | bool | verbose
| ) |  |

Teleport punit to city at cost specified. Returns success. Note that unit may die if it successfully moves, i.e., even when return value is TRUE. (If specified cost is -1, then teleportation costs all movement.)

Definition at line 1207 of file unittools.c.

Referenced by diplomat_escape_full(), do_expel_unit(), and try_to_save_unit().

## ◆ throw_units_from_illegal_cities()

static void throw_units_from_illegal_cities | ( | struct player * | pplayer,
|  | bool | verbose
| ) |  |

static

Throw pplayer's units from non-allied cities

If verbose is true, pplayer gets messages about where each units goes.

Definition at line 1324 of file unittools.c.

Referenced by resolve_unit_stacks().

## ◆ total_activity()

static int total_activity | ( | struct tile * | ptile,
|  | enum unit_activity | act,
|  | struct extra_type * | tgt
| ) |  |

static

Calculate the total amount of activity performed by all units on a tile for a given task and target.

Definition at line 706 of file unittools.c.

Referenced by total_activity_done(), and update_unit_activity().

## ◆ total_activity_done()

static bool total_activity_done | ( | struct tile * | ptile,
|  | enum unit_activity | act,
|  | struct extra_type * | tgt
| ) |  |

static

Check the total amount of activity performed by all units on a tile for a given task.

Definition at line 726 of file unittools.c.

Referenced by update_unit_activity().

## ◆ transform_unit()

void transform_unit | ( | struct unit * | punit,
|  | const struct unit_type * | to_unit,
|  | int | vet_loss
| ) |  |

Really transforms a single unit to another type.

This function performs no checks. You should perform the appropriate test first to check that the transformation is legal (unit_upgrade_test() or unit_can_convert()).

vet_loss: Number of veteran levels lost in process.

Note that this function is strongly tied to unit.c:unit_upgrade_test().

Definition at line 1569 of file unittools.c.

Referenced by do_unit_upgrade(), do_upgrade_effects(), unit_convert(), and ur_transform_unit().

## ◆ try_to_save_unit()

static bool try_to_save_unit | ( | struct unit * | punit,
|  | const struct unit_type * | pttype,
|  | bool | helpless,
|  | bool | teleporting,
|  | const struct city * | pexclcity
| ) |  |

static

Determine if it is possible to save a given unit, and if so, save them. 'pexclcity' is a city to avoid teleporting to, if 'teleporting' is set. Note that despite being saved from drowning, teleporting the units to "safety" may have killed them in the end.

Definition at line 2263 of file unittools.c.

Referenced by wipe_unit_full().

## ◆ unit_activities_cancel()

void unit_activities_cancel | ( | struct unit * | punit | ) |

Cancel activities, and orders that it might be part of.

Definition at line 792 of file unittools.c.

Referenced by climate_change(), create_city(), transform_unit(), unit_activities_cancel_all_illegal_plr(), unit_activities_cancel_all_illegal_tile(), and unit_change_homecity_handling().

## ◆ unit_activities_cancel_all_illegal_area()

void unit_activities_cancel_all_illegal_area | ( | const struct tile * | ptile | ) |

Cancel all illegal activities done by units at the specified tile, and surrounding tiles. For most rulesets this is for cancelling irrigation on surrounding tiles when the central tile was the only source of water, but does not provide water any more.

Definition at line 837 of file unittools.c.

Referenced by tile_change_side_effects().

## ◆ unit_activities_cancel_all_illegal_plr()

void unit_activities_cancel_all_illegal_plr | ( | const struct player * | pplayer | ) |

Cancel all illegal activities done by units of the specified owner.

Definition at line 810 of file unittools.c.

Referenced by research_tech_lost().

## ◆ unit_activities_cancel_all_illegal_tile()

void unit_activities_cancel_all_illegal_tile | ( | const struct tile * | ptile | ) |

Cancel all illegal activities done by units at the specified tile.

Definition at line 822 of file unittools.c.

Referenced by unit_activities_cancel_all_illegal_area().

## ◆ unit_activity_needs_target_from_client()

bool unit_activity_needs_target_from_client | ( | enum unit_activity | activity | ) |

Return TRUE iff activity requires some sort of target to be specified by the client.

Definition at line 1082 of file unittools.c.

Referenced by sg_load_player_unit(), and unit_perform_action().

## ◆ unit_assign_specific_activity_target()

void unit_assign_specific_activity_target | ( | struct unit * | punit,
|  | enum unit_activity * | activity,
|  | struct extra_type ** | target
| ) |  |

For some activities (currently only pillaging), the precise target can be assigned by the server rather than explicitly requested by the client. This function assigns a specific activity+target if the current settings are open-ended (otherwise leaves them unchanged).

Please update unit_activity_needs_target_from_client() if you add server side unit activity target setting to more activities.

Definition at line 1102 of file unittools.c.

Referenced by action_sub_target_id_for_action(), compat_post_load_030100(), and unit_activity_targeted_internal().

## ◆ unit_bombs_unit()

void unit_bombs_unit | ( | struct unit * | attacker,
|  | struct unit * | defender,
|  | int * | att_hp,
|  | int * | def_hp
| ) |  |

This is the basic unit versus unit classic bombardment routine. 1) ALOT of modifiers bonuses etc is added to the 2 units rates. 2) Do rate attacks and don't kill the defender, then return.

Definition at line 352 of file unittools.c.

Referenced by unit_bombard().

## ◆ unit_can_be_retired()

bool unit_can_be_retired | ( | struct unit * | punit | ) |

Units (usually barbarian units) may disband spontaneously if they are far from any enemy units or cities. It is to remove barbarians that do not engage into any activity for a long time.

Definition at line 4926 of file unittools.c.

Referenced by begin_turn().

## ◆ unit_can_do_action_now()

bool unit_can_do_action_now | ( | const struct unit * | punit | ) |

Used to implement the game rule controlled by the unitwaittime setting. Notifies the unit owner if the unit is unable to act.

Definition at line 4878 of file unittools.c.

Referenced by unit_perform_action().

## ◆ unit_change_owner()

struct unit * unit_change_owner | ( | struct unit * | punit,
|  | struct player * | pplayer,
|  | int | homecity,
|  | enum unit_loss_reason | reason
| ) |  |

We don't really change owner of the unit, but create completely new unit as its copy. The new pointer to 'punit' is returned. Always wipes the source unit but sometimes returns NULL or a unit of a player other than pplayer.

Definition at line 2311 of file unittools.c.

Referenced by diplomat_bribe(), and do_capture_units().

## ◆ unit_convert()

static void unit_convert | ( | struct unit * | punit | ) |

static

Convert a single unit to another type.

Definition at line 766 of file unittools.c.

Referenced by update_unit_activity().

## ◆ unit_did_action()

void unit_did_action | ( | struct unit * | punit | ) |

Mark a unit as having done something at the current time. This is used in conjunction with unit_can_do_action_now() and the unitwaittime setting.

Definition at line 4911 of file unittools.c.

Referenced by do_attack(), do_capture_units(), unit_bombard(), and unit_move_by_data().

## ◆ unit_enter_hut()

static void unit_enter_hut | ( | struct unit * | punit,
|  | bool | frighten_hut
| ) |  |

static

Due to the effects in the scripted hut behavior can not be predicted, unit_enter_hut returns nothing.

Definition at line 3224 of file unittools.c.

Referenced by unit_move().

## ◆ unit_forget_last_activity()

void unit_forget_last_activity | ( | struct unit * | punit | ) |

Forget the unit's last activity so that it can't be resumed. This is used for example when the unit moves or attacks.

Definition at line 1073 of file unittools.c.

Referenced by do_attack(), do_capture_units(), transform_unit(), unit_bombard(), and unit_move_by_data().

## ◆ unit_get_goods()

void unit_get_goods | ( | struct unit * | punit | ) |

Set carried goods for unit.

Definition at line 1630 of file unittools.c.

Referenced by place_unit(), and unit_change_homecity_handling().

## ◆ unit_goes_out_of_sight()

void unit_goes_out_of_sight | ( | struct player * | pplayer,
|  | struct unit * | punit
| ) |  |

Handle situation where unit goes out of player sight.

Definition at line 2784 of file unittools.c.

Referenced by create_city(), create_extra(), map_change_seen(), map_claim_base(), map_hide_tile(), remove_allied_visibility(), send_combat(), transfer_city(), unit_change_homecity_handling(), unit_move(), and unit_transport_load_send().

## ◆ unit_list_refresh_vision()

void unit_list_refresh_vision | ( | struct unit_list * | punitlist | ) |

Refresh the vision of all units in the list - see unit_refresh_vision().

Definition at line 4867 of file unittools.c.

Referenced by create_city(), create_extra(), found_new_tech(), and update_unit_activity().

## ◆ unit_lost_with_transport()

static void unit_lost_with_transport | ( | const struct player * | pplayer,
|  | struct unit * | pcargo,
|  | const struct unit_type * | ptransport,
|  | struct player * | killer
| ) |  |

static

Handle units destroyed when their transport is destroyed

Definition at line 1938 of file unittools.c.

Referenced by wipe_unit_full().

## ◆ unit_move()

bool unit_move | ( | struct unit * | punit,
|  | struct tile * | pdesttile,
|  | int | move_cost,
|  | struct unit * | embark_to,
|  | bool | find_embark_target,
|  | bool | conquer_city_allowed,
|  | bool | conquer_extras_allowed,
|  | bool | enter_hut,
|  | bool | frighten_hut
| ) |  |

Moves a unit. No checks whatsoever! This is meant as a practical function for other functions, like do_airline, which do the checking themselves.

If you move a unit you should always use this function, as it also sets the transport status of the unit correctly. Note that the source tile (the current tile of the unit) and pdesttile need not be adjacent.

Returns TRUE iff unit still alive.

Definition at line 3882 of file unittools.c.

Referenced by adv_unit_execute_path(), api_edit_unit_move(), api_edit_unit_move_old(), api_edit_unit_teleport(), api_edit_unit_teleport_old(), bounce_unit(), do_airline(), do_conquer_extras(), do_disembark(), do_paradrop(), do_unit_conquer_city(), do_unit_embark(), do_unit_hut(), teleport_unit_to_city(), terrain_change_bounce_single_unit(), unit_do_regular_move(), and unit_move_pay().

## ◆ unit_move_by_data()

static void unit_move_by_data | ( | struct unit_move_data * | pdata,
|  | struct tile * | psrctile,
|  | struct tile * | pdesttile
| ) |  |

static

Move the unit using move_data.

Definition at line 3803 of file unittools.c.

Referenced by unit_move().

## ◆ unit_move_consequences()

static bool unit_move_consequences | ( | struct unit * | punit,
|  | struct tile * | src_tile,
|  | struct tile * | dst_tile,
|  | bool | passenger,
|  | bool | conquer_city_allowed
| ) |  |

static

Does: 1) updates the unit's homecity and the city it enters/leaves (the city's happiness varies). This also takes into account when the unit enters/leaves a fortress. 2) updates adjacent cities' unavailable tiles.

FIXME: Sometimes it is not necessary to send cities because the goverment doesn't care whether a unit is away or not.

Definition at line 3616 of file unittools.c.

Referenced by unit_move().

## ◆ unit_move_data()

static struct unit_move_data * unit_move_data | ( | struct unit * | punit,
|  | struct tile * | psrctile,
|  | struct tile * | pdesttile
| ) |  |

static

Create a new unit move data, or use previous one if available.

Definition at line 3768 of file unittools.c.

## ◆ unit_move_data_unref()

static void unit_move_data_unref | ( | struct unit_move_data * | pdata | ) |

static

Decrease the reference counter and destroy if needed.

Definition at line 3853 of file unittools.c.

Referenced by unit_move().

## ◆ unit_refresh_vision()

void unit_refresh_vision | ( | struct unit * | punit | ) |

Refresh the unit's vision.

This function has very small overhead and can be called any time effects may have changed the vision range of the unit.

Definition at line 4850 of file unittools.c.

Referenced by place_unit(), sg_load_player_units(), sg_load_player_units(), transform_unit(), unit_change_homecity_handling(), unit_list_refresh_vision(), and unit_tc_effect_refresh().

## ◆ unit_restore_hitpoints()

static void unit_restore_hitpoints | ( | struct unit * | punit | ) |

static

Add hitpoints to the unit, hp_gain_coord returns the amount to add united nations will speed up the process by 2 hp's / turn, means helicopters will actually not lose hp's every turn if player have that wonder. Units which have moved don't gain hp, except the United Nations and helicopter effects still occur.

If 'game.server.killunhomed' is greater than 0, unhomed units lose 'game.server.killunhomed' hitpoints each turn, killing the unit at the end.

Definition at line 622 of file unittools.c.

Referenced by player_restore_units().

## ◆ unit_restore_movepoints()

static void unit_restore_movepoints | ( | struct player * | pplayer,
|  | struct unit * | punit
| ) |  |

static

Move points are trivial, only modifiers to the base value is if it's sea units and the player has certain wonders/techs. Then add veteran bonus, if any.

Definition at line 649 of file unittools.c.

Referenced by update_unit_activity().

## ◆ unit_set_removal_callback()

void unit_set_removal_callback | ( | struct unit * | punit,
|  | void(*)(struct unit *punit) | callback
| ) |  |

Set the call back to run when the server removes the unit.

Definition at line 1785 of file unittools.c.

Referenced by uk_rem_gold_append().

## ◆ unit_survive_autoattack()

static bool unit_survive_autoattack | ( | struct unit * | punit | ) |

static

Check if unit survives enemy autoattacks. We assume that any unit that is adjacent to us can see us.

Definition at line 3403 of file unittools.c.

Referenced by unit_move().

## ◆ unit_tc_effect_refresh()

void unit_tc_effect_refresh | ( | struct player * | pplayer | ) |

Recalculate some unit related effects on turn change

Definition at line 680 of file unittools.c.

Referenced by begin_phase().

## ◆ unit_transport_load_send()

void unit_transport_load_send | ( | struct unit * | punit,
|  | struct unit * | ptrans
| ) |  |

Put the unit onto the transporter, and tell everyone.

Definition at line 3275 of file unittools.c.

Referenced by dai_unit_new_task(), and do_unit_board().

## ◆ unit_transport_load_tp_status()

static void unit_transport_load_tp_status | ( | struct unit * | punit,
|  | struct unit * | ptrans,
|  | bool | force
| ) |  |

static

Load unit to transport, send transport's loaded status to everyone.

Definition at line 3305 of file unittools.c.

Referenced by place_unit(), player_restore_units(), try_to_save_unit(), and unit_move().

## ◆ unit_transport_unload_send()

void unit_transport_unload_send | ( | struct unit * | punit | ) |

Pull the unit off of the transporter, and tell everyone.

Definition at line 3327 of file unittools.c.

Referenced by do_attack(), do_unit_alight(), do_unit_unload(), and throw_units_from_illegal_cities().

## ◆ unit_unset_removal_callback()

void unit_unset_removal_callback | ( | struct unit * | punit | ) |

Remove the call back so nothing runs when the server removes the unit.

Definition at line 1799 of file unittools.c.

Referenced by unit_list_referred_destroy().

## ◆ unit_versus_unit()

bool unit_versus_unit | ( | struct unit * | attacker,
|  | struct unit * | defender,
|  | int * | att_hp,
|  | int * | def_hp,
|  | int * | att_vet,
|  | int * | def_vet
| ) |  |

This is the basic unit versus unit combat routine. 1) ALOT of modifiers bonuses etc is added to the 2 units rates. 2) the combat loop, which continues until one of the units are dead or EFT_COMBAT_ROUNDS rounds have been fought. 3) the aftermath, the loser (and potentially the stack which is below it) is wiped, and the winner gets a chance of gaining veteran status

Returns whether either side was completely powerless.

Definition at line 286 of file unittools.c.

Referenced by do_attack().

## ◆ unit_virtual_prepare()

struct unit * unit_virtual_prepare | ( | struct player * | pplayer,
|  | struct tile * | ptile,
|  | const struct unit_type * | type,
|  | int | veteran_level,
|  | int | homecity_id,
|  | int | moves_left,
|  | int | hp_left
| ) |  |

Creates a virtual unit, and sets its initial values, but does not register the unit in any other data structures or set the vision. If moves_left is less than zero, unit will get max moves; otherwise, it will get the specified number of movement fragments and will be considered moved. If hp_left is zero or less, unit will get full hp. homecity_id won't be set to units with "NoHome" flag. ptile must be a valid tile (its livability for the unit is not checked)

Definition at line 1679 of file unittools.c.

Referenced by api_edit_create_unit_full(), city_create_unit(), create_unit_full(), place_partisans(), and unit_change_owner().

## ◆ unit_vision_range_modifiers()

static int unit_vision_range_modifiers | ( | struct unit * | punit,
|  | const struct tile * | ptile
| ) |  |

static

Return unit vision range modifiers unit would have at the given tile.

Definition at line 4819 of file unittools.c.

Referenced by get_unit_vision_at(), unit_move_by_data(), and unit_refresh_vision().

## ◆ update_unit_activities()

void update_unit_activities | ( | struct player * | pplayer | ) |

Iterate through all units and update them.

Definition at line 658 of file unittools.c.

Referenced by begin_phase().

## ◆ update_unit_activity()

static void update_unit_activity | ( | struct unit * | punit | ) |

static

Progress settlers in their current tasks, and units that is pillaging. also move units that is on a goto. Restore unit move points (information needed for settler tasks)

Definition at line 852 of file unittools.c.

Referenced by update_unit_activities().

## ◆ wakeup_neighbor_sentries()

static void wakeup_neighbor_sentries | ( | struct unit * | punit | ) |

static

Will wake up any neighboring enemy sentry units or patrolling units.

Definition at line 3546 of file unittools.c.

Referenced by place_unit(), and unit_move().

## ◆ wipe_unit()

void wipe_unit | ( | struct unit * | punit,
|  | enum unit_loss_reason | reason,
|  | struct player * | killer
| ) |  |

Remove the unit, and passengers if it is a carrying any. Remove the minimum number, eg there could be another boat on the square.

Definition at line 2251 of file unittools.c.

Referenced by action_success_actor_consume(), api_edit_unit_kill(), api_edit_unit_teleport(), api_edit_unit_teleport_old(), begin_turn(), bounce_unit(), check_units_single_tile(), diplomat_escape_full(), diplomat_get_tech(), diplomat_incite(), diplomat_infiltrate_tile(), diplomat_sabotage(), do_attack(), do_capture_units(), do_nuke_tile(), handle_edit_unit_remove(), handle_edit_unit_remove_by_id(), hut_get_limited(), illegal_action_pay_price(), kill_player(), kill_unit(), player_restore_units(), remove_city(), remove_illegal_armistice_units(), spy_nuke_city(), spy_poison(), spy_sabotage_unit(), spy_spread_plague(), spy_steal_gold(), spy_steal_some_maps(), transfer_city_units(), transfer_unit(), unit_change_owner(), unit_nuke(), unleash_barbarians(), and upkeep_kill_unit().

## ◆ wipe_unit_full()

static void wipe_unit_full | ( | struct unit * | punit,
|  | bool | transported,
|  | enum unit_loss_reason | reason,
|  | struct player * | killer
| ) |  |

static

Remove the unit, and passengers if it is a carrying any. Remove the minimum number, eg there could be another boat on the square.

Definition at line 1962 of file unittools.c.

Referenced by unit_lost_with_transport(), and wipe_unit().