Freeciv21
Develop your civilization from humble roots to a global empire
unittools.h File Reference
#include "fc_types.h"
#include "packets.h"
#include "unitlist.h"
#include "specenum_gen.h"
+ Include dependency graph for unittools.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define SPECENUM_NAME   unit_loss_reason
 
#define SPECENUM_VALUE0   ULR_KILLED
 
#define SPECENUM_VALUE0NAME   "killed"
 
#define SPECENUM_VALUE1   ULR_RETIRED
 
#define SPECENUM_VALUE1NAME   "retired"
 
#define SPECENUM_VALUE2   ULR_DISBANDED
 
#define SPECENUM_VALUE2NAME   "disbanded"
 
#define SPECENUM_VALUE3   ULR_BARB_UNLEASH
 
#define SPECENUM_VALUE3NAME   "barb_unleash"
 
#define SPECENUM_VALUE4   ULR_CITY_LOST
 
#define SPECENUM_VALUE4NAME   "city_lost"
 
#define SPECENUM_VALUE5   ULR_STARVED
 
#define SPECENUM_VALUE5NAME   "starved"
 
#define SPECENUM_VALUE6   ULR_SOLD
 
#define SPECENUM_VALUE6NAME   "sold"
 
#define SPECENUM_VALUE7   ULR_USED
 
#define SPECENUM_VALUE7NAME   "used"
 
#define SPECENUM_VALUE8   ULR_EXECUTED
 
#define SPECENUM_VALUE8NAME   "executed"
 
#define SPECENUM_VALUE9   ULR_ELIMINATED
 
#define SPECENUM_VALUE9NAME   "eliminated"
 
#define SPECENUM_VALUE10   ULR_EDITOR
 
#define SPECENUM_VALUE10NAME   "editor"
 
#define SPECENUM_VALUE11   ULR_NONNATIVE_TERR
 
#define SPECENUM_VALUE11NAME   "nonnative_terr"
 
#define SPECENUM_VALUE12   ULR_PLAYER_DIED
 
#define SPECENUM_VALUE12NAME   "player_died"
 
#define SPECENUM_VALUE13   ULR_ARMISTICE
 
#define SPECENUM_VALUE13NAME   "armistice"
 
#define SPECENUM_VALUE14   ULR_SDI
 
#define SPECENUM_VALUE14NAME   "sdi"
 
#define SPECENUM_VALUE15   ULR_DETONATED
 
#define SPECENUM_VALUE15NAME   "detonated"
 
#define SPECENUM_VALUE16   ULR_MISSILE
 
#define SPECENUM_VALUE16NAME   "missile"
 
#define SPECENUM_VALUE17   ULR_NUKE
 
#define SPECENUM_VALUE17NAME   "nuke"
 
#define SPECENUM_VALUE18   ULR_HP_LOSS
 
#define SPECENUM_VALUE18NAME   "hp_loss"
 
#define SPECENUM_VALUE19   ULR_FUEL
 
#define SPECENUM_VALUE19NAME   "fuel"
 
#define SPECENUM_VALUE20   ULR_STACK_CONFLICT
 
#define SPECENUM_VALUE20NAME   "stack_conflict"
 
#define SPECENUM_VALUE21   ULR_BRIBED
 
#define SPECENUM_VALUE21NAME   "bribed"
 
#define SPECENUM_VALUE22   ULR_CAPTURED
 
#define SPECENUM_VALUE22NAME   "captured"
 
#define SPECENUM_VALUE23   ULR_CAUGHT
 
#define SPECENUM_VALUE23NAME   "caught"
 
#define SPECENUM_VALUE24   ULR_TRANSPORT_LOST
 
#define SPECENUM_VALUE24NAME   "transport_lost"
 

Enumerations

enum class  bounce_reason { generic , terrain_change }
 Why do we need to bounce a unit? More...
 

Functions

struct unit_typefind_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. More...
 
bool maybe_make_veteran (struct unit *punit)
 Unit has a chance to become veteran. More...
 
void notify_unit_experience (struct unit *punit)
 Common notification for all experience levels. More...
 
void unit_versus_unit (struct unit *attacker, struct unit *defender, int *att_hp, int *def_hp)
 This is the basic unit versus unit combat routine. More...
 
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. More...
 
void combat_veterans (struct unit *attacker, struct unit *defender)
 Maybe make either side of combat veteran. More...
 
void player_restore_units (struct player *pplayer)
 
void update_unit_activities (struct player *pplayer)
 Iterate through all units and update them. More...
 
void execute_unit_orders (struct player *pplayer)
 Iterate through all units and execute their orders. More...
 
void finalize_unit_phase_beginning (struct player *pplayer)
 Iterate through all units and remember their current activities. More...
 
void finish_unit_wait (struct unit *punit, int activity_count)
 Finish activity of a unit that was deferred by unitwaittime. More...
 
void place_partisans (struct tile *pcenter, struct player *powner, int count, int sq_radius)
 Place partisans for powner around pcenter (normally around a city). More...
 
bool teleport_unit_to_city (struct unit *punit, struct city *pcity, int move_cost, bool verbose)
 Teleport punit to city at cost specified. More...
 
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. More...
 
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'. More...
 
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). More...
 
void give_allied_visibility (struct player *pplayer, struct player *aplayer)
 Refresh units visibility of 'aplayer' for 'pplayer' after alliance have been contracted. More...
 
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. More...
 
void unit_refresh_vision (struct unit *punit)
 Refresh the unit's vision. More...
 
void unit_list_refresh_vision (struct unit_list *punitlist)
 Refresh the vision of all units in the list - see unit_refresh_vision. More...
 
void bounce_unit (struct unit *punit, bool verbose, bounce_reason reason=bounce_reason::generic, int max_distance=2)
 Move or remove a unit due to stack conflicts. More...
 
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. More...
 
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. More...
 
void unit_forget_last_activity (struct unit *punit)
 Forget the unit's last activity so that it can't be resumed. More...
 
void transform_unit (struct unit *punit, const struct unit_type *to_unit, bool has_to_pay)
 Really transforms a single unit to another type. More...
 
struct unitcreate_unit (struct player *pplayer, struct tile *ptile, const struct unit_type *punittype, int veteran_level, int homecity_id, int moves_left)
 Wrapper of the below. More...
 
struct unitcreate_unit_full (struct player *pplayer, struct tile *ptile, const struct unit_type *punittype, int veteran_level, int homecity_id, int moves_left, int hp_left, struct unit *ptrans)
 Creates a unit, and set it's initial values, and put it into the right lists. More...
 
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. More...
 
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). More...
 
struct unitunit_change_owner (struct unit *punit, struct player *pplayer, int homecity, enum unit_loss_reason reason) fc__warn_unused_result
 We don't really change owner of the unit, but create completely new unit as its copy. More...
 
void unit_set_removal_callback (struct unit *punit, void(*callback)(struct unit *punit))
 Set the call back to run when the server removes the unit. More...
 
void unit_unset_removal_callback (struct unit *punit)
 Remove the call back so nothing runs when the server removes the unit. More...
 
void package_unit (struct unit *punit, struct packet_unit_info *packet)
 Package a unit_info packet. More...
 
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. More...
 
void send_unit_info (struct conn_list *dest, struct unit *punit)
 Send the unit to the players who need the info. More...
 
void send_all_known_units (struct conn_list *dest)
 For each specified connections, send information about all the units known to that player/conn. More...
 
void unit_goes_out_of_sight (struct player *pplayer, const unit *punit)
 Handle situation where unit goes out of player sight. More...
 
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. More...
 
bool do_airline (struct unit *punit, struct city *city2, 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. More...
 
void do_explore (struct unit *punit)
 Autoexplore with unit. More...
 
bool do_paradrop (struct unit *punit, struct tile *ptile, const struct action *paction)
 Returns whether the drop was made or not. More...
 
void unit_transport_load_send (struct unit *punit, struct unit *ptrans)
 Put the unit onto the transporter, and tell everyone. More...
 
void unit_transport_unload_send (struct unit *punit)
 Pull the unit off of the transporter, and tell everyone. More...
 
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. More...
 
bool execute_orders (struct unit *punit, const bool fresh)
 Executes a unit's orders stored in punit->orders. More...
 
bool unit_can_do_action_now (const struct unit *punit)
 Used to implement the game rule controlled by the unitwaittime setting. More...
 
void unit_did_action (struct unit *punit)
 Mark a unit as having done something at the current time. More...
 
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. More...
 
void unit_activities_cancel_all_illegal (const struct tile *ptile)
 Cancel all illegal activities done by units at the specified tile. More...
 
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. More...
 
void unit_get_goods (struct unit *punit)
 Set carried goods for unit. More...
 
bool unit_order_list_is_sane (int length, const struct unit_order *orders)
 Returns TRUE iff the unit order array is sane. More...
 
struct unit_ordercreate_unit_orders (int length, const struct unit_order *orders)
 Sanity-check unit order arrays from a packet and create a unit_order array from their contents if valid. More...
 

Macro Definition Documentation

◆ SPECENUM_NAME

#define SPECENUM_NAME   unit_loss_reason

Definition at line 20 of file unittools.h.

◆ SPECENUM_VALUE0

#define SPECENUM_VALUE0   ULR_KILLED

Definition at line 21 of file unittools.h.

◆ SPECENUM_VALUE0NAME

#define SPECENUM_VALUE0NAME   "killed"

Definition at line 22 of file unittools.h.

◆ SPECENUM_VALUE1

#define SPECENUM_VALUE1   ULR_RETIRED

Definition at line 23 of file unittools.h.

◆ SPECENUM_VALUE10

#define SPECENUM_VALUE10   ULR_EDITOR

Definition at line 41 of file unittools.h.

◆ SPECENUM_VALUE10NAME

#define SPECENUM_VALUE10NAME   "editor"

Definition at line 42 of file unittools.h.

◆ SPECENUM_VALUE11

#define SPECENUM_VALUE11   ULR_NONNATIVE_TERR

Definition at line 43 of file unittools.h.

◆ SPECENUM_VALUE11NAME

#define SPECENUM_VALUE11NAME   "nonnative_terr"

Definition at line 44 of file unittools.h.

◆ SPECENUM_VALUE12

#define SPECENUM_VALUE12   ULR_PLAYER_DIED

Definition at line 45 of file unittools.h.

◆ SPECENUM_VALUE12NAME

#define SPECENUM_VALUE12NAME   "player_died"

Definition at line 46 of file unittools.h.

◆ SPECENUM_VALUE13

#define SPECENUM_VALUE13   ULR_ARMISTICE

Definition at line 47 of file unittools.h.

◆ SPECENUM_VALUE13NAME

#define SPECENUM_VALUE13NAME   "armistice"

Definition at line 48 of file unittools.h.

◆ SPECENUM_VALUE14

#define SPECENUM_VALUE14   ULR_SDI

Definition at line 49 of file unittools.h.

◆ SPECENUM_VALUE14NAME

#define SPECENUM_VALUE14NAME   "sdi"

Definition at line 50 of file unittools.h.

◆ SPECENUM_VALUE15

#define SPECENUM_VALUE15   ULR_DETONATED

Definition at line 51 of file unittools.h.

◆ SPECENUM_VALUE15NAME

#define SPECENUM_VALUE15NAME   "detonated"

Definition at line 52 of file unittools.h.

◆ SPECENUM_VALUE16

#define SPECENUM_VALUE16   ULR_MISSILE

Definition at line 53 of file unittools.h.

◆ SPECENUM_VALUE16NAME

#define SPECENUM_VALUE16NAME   "missile"

Definition at line 54 of file unittools.h.

◆ SPECENUM_VALUE17

#define SPECENUM_VALUE17   ULR_NUKE

Definition at line 55 of file unittools.h.

◆ SPECENUM_VALUE17NAME

#define SPECENUM_VALUE17NAME   "nuke"

Definition at line 56 of file unittools.h.

◆ SPECENUM_VALUE18

#define SPECENUM_VALUE18   ULR_HP_LOSS

Definition at line 57 of file unittools.h.

◆ SPECENUM_VALUE18NAME

#define SPECENUM_VALUE18NAME   "hp_loss"

Definition at line 58 of file unittools.h.

◆ SPECENUM_VALUE19

#define SPECENUM_VALUE19   ULR_FUEL

Definition at line 59 of file unittools.h.

◆ SPECENUM_VALUE19NAME

#define SPECENUM_VALUE19NAME   "fuel"

Definition at line 60 of file unittools.h.

◆ SPECENUM_VALUE1NAME

#define SPECENUM_VALUE1NAME   "retired"

Definition at line 24 of file unittools.h.

◆ SPECENUM_VALUE2

#define SPECENUM_VALUE2   ULR_DISBANDED

Definition at line 25 of file unittools.h.

◆ SPECENUM_VALUE20

#define SPECENUM_VALUE20   ULR_STACK_CONFLICT

Definition at line 61 of file unittools.h.

◆ SPECENUM_VALUE20NAME

#define SPECENUM_VALUE20NAME   "stack_conflict"

Definition at line 62 of file unittools.h.

◆ SPECENUM_VALUE21

#define SPECENUM_VALUE21   ULR_BRIBED

Definition at line 63 of file unittools.h.

◆ SPECENUM_VALUE21NAME

#define SPECENUM_VALUE21NAME   "bribed"

Definition at line 64 of file unittools.h.

◆ SPECENUM_VALUE22

#define SPECENUM_VALUE22   ULR_CAPTURED

Definition at line 65 of file unittools.h.

◆ SPECENUM_VALUE22NAME

#define SPECENUM_VALUE22NAME   "captured"

Definition at line 66 of file unittools.h.

◆ SPECENUM_VALUE23

#define SPECENUM_VALUE23   ULR_CAUGHT

Definition at line 67 of file unittools.h.

◆ SPECENUM_VALUE23NAME

#define SPECENUM_VALUE23NAME   "caught"

Definition at line 68 of file unittools.h.

◆ SPECENUM_VALUE24

#define SPECENUM_VALUE24   ULR_TRANSPORT_LOST

Definition at line 69 of file unittools.h.

◆ SPECENUM_VALUE24NAME

#define SPECENUM_VALUE24NAME   "transport_lost"

Definition at line 70 of file unittools.h.

◆ SPECENUM_VALUE2NAME

#define SPECENUM_VALUE2NAME   "disbanded"

Definition at line 26 of file unittools.h.

◆ SPECENUM_VALUE3

#define SPECENUM_VALUE3   ULR_BARB_UNLEASH

Definition at line 27 of file unittools.h.

◆ SPECENUM_VALUE3NAME

#define SPECENUM_VALUE3NAME   "barb_unleash"

Definition at line 28 of file unittools.h.

◆ SPECENUM_VALUE4

#define SPECENUM_VALUE4   ULR_CITY_LOST

Definition at line 29 of file unittools.h.

◆ SPECENUM_VALUE4NAME

#define SPECENUM_VALUE4NAME   "city_lost"

Definition at line 30 of file unittools.h.

◆ SPECENUM_VALUE5

#define SPECENUM_VALUE5   ULR_STARVED

Definition at line 31 of file unittools.h.

◆ SPECENUM_VALUE5NAME

#define SPECENUM_VALUE5NAME   "starved"

Definition at line 32 of file unittools.h.

◆ SPECENUM_VALUE6

#define SPECENUM_VALUE6   ULR_SOLD

Definition at line 33 of file unittools.h.

◆ SPECENUM_VALUE6NAME

#define SPECENUM_VALUE6NAME   "sold"

Definition at line 34 of file unittools.h.

◆ SPECENUM_VALUE7

#define SPECENUM_VALUE7   ULR_USED

Definition at line 35 of file unittools.h.

◆ SPECENUM_VALUE7NAME

#define SPECENUM_VALUE7NAME   "used"

Definition at line 36 of file unittools.h.

◆ SPECENUM_VALUE8

#define SPECENUM_VALUE8   ULR_EXECUTED

Definition at line 37 of file unittools.h.

◆ SPECENUM_VALUE8NAME

#define SPECENUM_VALUE8NAME   "executed"

Definition at line 38 of file unittools.h.

◆ SPECENUM_VALUE9

#define SPECENUM_VALUE9   ULR_ELIMINATED

Definition at line 39 of file unittools.h.

◆ SPECENUM_VALUE9NAME

#define SPECENUM_VALUE9NAME   "eliminated"

Definition at line 40 of file unittools.h.

Enumeration Type Documentation

◆ bounce_reason

enum bounce_reason
strong

Why do we need to bounce a unit?

Enumerator
generic 

We just need to do it.

terrain_change 

We need to do it because of changing terrain.

Definition at line 109 of file unittools.h.

Function Documentation

◆ bounce_unit()

void bounce_unit ( struct unit punit,
bool  verbose,
bounce_reason  reason,
int  max_distance 
)

Move or remove a unit due to stack conflicts.

This function will try to find a random safe tile within a given 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 (the exact message depends on 'reason'). The maximum distance it 2 by default for backward compatibility.

Definition at line 1327 of file unittools.cpp.

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

◆ combat_veterans()

void combat_veterans ( struct unit attacker,
struct unit defender 
)

Maybe make either side of combat veteran.

Definition at line 371 of file unittools.cpp.

Referenced by do_attack().

◆ create_unit()

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

◆ 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, and set it's initial values, and put it into the right lists.

If moves_left is less than zero, unit will get max moves.

Definition at line 1789 of file unittools.cpp.

Referenced by api_edit_create_unit_full(), create_unit(), try_summon_barbarians(), and unit_change_owner().

◆ create_unit_orders()

struct unit_order* create_unit_orders ( int  length,
const struct unit_order orders 
)

Sanity-check unit order arrays from a packet and create a unit_order array from their contents if valid.

Definition at line 5119 of file unittools.cpp.

Referenced by handle_city_rally_point(), and handle_unit_orders().

◆ do_airline()

bool do_airline ( struct unit punit,
struct city city2,
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 3018 of file unittools.cpp.

Referenced by unit_perform_action().

◆ do_explore()

void do_explore ( struct unit punit)

Autoexplore with unit.

Definition at line 3047 of file unittools.cpp.

Referenced by handle_unit_server_side_agent_set(), and unit_activity_complete().

◆ 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 2999 of file unittools.cpp.

Referenced by spy_nuke_city(), and unit_nuke().

◆ 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 succesful, but the unit was killed by barbarians in a hut.

Definition at line 3082 of file unittools.cpp.

Referenced by unit_perform_action().

◆ 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 4384 of file unittools.cpp.

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 659 of file unittools.cpp.

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 673 of file unittools.cpp.

Referenced by begin_phase().

◆ 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 159 of file unittools.cpp.

Referenced by try_summon_barbarians(), and unleash_barbarians().

◆ finish_unit_wait()

void finish_unit_wait ( struct unit punit,
int  activity_count 
)

Finish activity of a unit that was deferred by unitwaittime.

Definition at line 1063 of file unittools.cpp.

Referenced by finish_unit_waits().

◆ 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 4791 of file unittools.cpp.

Referenced by maybe_cancel_patrol_due_to_enemy(), unit_move_data(), unit_refresh_vision(), and wakeup_neighbor_sentries().

◆ 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 1552 of file unittools.cpp.

Referenced by handle_diplomacy_accept_treaty_req(), and handle_diplomacy_cancel_pact_explicit().

◆ 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 1621 of file unittools.cpp.

Referenced by handle_diplomacy_accept_treaty_req().

◆ 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.

Note
WARNING: This function iterates through all possible players, not just the players present in the server. That means that, in the loops, you must account for situations where the loop is going to go through players that do not exist, and the consequences that such iterations could have. E.g. notify_player, when pointed to nullptr, will send messages to everyone.

Definition at line 2358 of file unittools.cpp.

Referenced by do_attack().

◆ maybe_make_veteran()

bool maybe_make_veteran ( struct unit punit)

Unit has a chance to become veteran.

This should not be used for settlers for the work they do.

Definition at line 204 of file unittools.cpp.

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 723 of file unittools.cpp.

Referenced by diplomat_bribe(), diplomat_escape_full(), diplomat_infiltrate_tile(), do_attack(), 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 2750 of file unittools.cpp.

Referenced by diplomat_investigate(), see_combat_unit(), 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 2662 of file unittools.cpp.

Referenced by see_combat_unit(), 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 1180 of file unittools.cpp.

Referenced by api_edit_place_partisans().

◆ 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 481 of file unittools.cpp.

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 1593 of file unittools.cpp.

Referenced by update_players_after_alliance_breakup().

◆ 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 1537 of file unittools.cpp.

Referenced by civil_war(), kill_player(), 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 2859 of file unittools.cpp.

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 = nullptr means all connections (game.est_connections)

Definition at line 2808 of file unittools.cpp.

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(), create_unit_full(), 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_rename(), handle_unit_sscs_set(), illegal_action_pay_price(), map_change_seen(), map_claim_base(), map_show_tile(), place_animal(), place_partisans(), player_restore_units(), remove_city(), research_tech_lost(), 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_all_illegal(), unit_activity_complete(), unit_activity_dependencies(), unit_activity_internal(), unit_activity_targeted_internal(), unit_bombard(), unit_change_homecity_handling(), unit_change_owner(), 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().

◆ 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 succesfully moves, i.e., even when return value is TRUE. (If specified cost is -1, then teleportation costs all movement.)

Definition at line 1212 of file unittools.cpp.

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

◆ transform_unit()

void transform_unit ( struct unit punit,
const struct unit_type to_unit,
bool  is_free 
)

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 (test_unit_upgrade() or test_unit_convert()).

is_free: Does unit owner need to pay upgrade price.

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

Definition at line 1676 of file unittools.cpp.

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

◆ unit_activities_cancel_all_illegal()

void unit_activities_cancel_all_illegal ( const struct tile ptile)

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

Definition at line 774 of file unittools.cpp.

Referenced by unit_activities_cancel_all_illegal_area().

◆ 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 801 of file unittools.cpp.

Referenced by climate_change(), end_turn(), and unit_activity_complete().

◆ 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 1085 of file unittools.cpp.

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 1105 of file unittools.cpp.

Referenced by action_sub_target_id_for_action(), ai_level_convert(), 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 321 of file unittools.cpp.

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 4906 of file unittools.cpp.

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 4844 of file unittools.cpp.

Referenced by unit_move_handling(), and 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.

Definition at line 2302 of file unittools.cpp.

Referenced by diplomat_bribe(), and do_capture_units().

◆ 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 4879 of file unittools.cpp.

Referenced by diplomat_bribe(), do_attack(), do_capture_units(), unit_bombard(), unit_change_owner(), and unit_move_data().

◆ 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.cpp.

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

◆ unit_get_goods()

void unit_get_goods ( struct unit punit)

Set carried goods for unit.

Definition at line 1773 of file unittools.cpp.

Referenced by create_unit_full(), and unit_change_homecity_handling().

◆ unit_goes_out_of_sight()

void unit_goes_out_of_sight ( struct player pplayer,
const unit punit 
)

◆ 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 4834 of file unittools.cpp.

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

◆ 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 
)

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 3878 of file unittools.cpp.

Referenced by adv_unit_execute_path(), api_edit_unit_move(), api_edit_unit_teleport(), do_airline(), do_disembark(), do_paradrop(), do_unit_conquer_city(), do_unit_embark(), kill_unit(), teleport_unit_to_city(), and unit_move_handling().

◆ unit_order_list_is_sane()

bool unit_order_list_is_sane ( int  length,
const struct unit_order orders 
)

Returns TRUE iff the unit order array is sane.

Definition at line 4924 of file unittools.cpp.

Referenced by create_unit_orders(), and sg_load_sanitycheck().

◆ 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 city.

Definition at line 4818 of file unittools.cpp.

Referenced by create_unit_full(), sg_load_player_units(), transform_unit(), unit_change_homecity_handling(), and unit_list_refresh_vision().

◆ 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 1872 of file unittools.cpp.

Referenced by uk_rem_gold_append().

◆ 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 3261 of file unittools.cpp.

Referenced by dai_unit_new_task(), and do_unit_board().

◆ 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 3316 of file unittools.cpp.

Referenced by do_attack(), do_unit_alight(), do_unit_board(), do_unit_embark(), 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 1886 of file unittools.cpp.

Referenced by unit_list_referred_destroy().

◆ unit_versus_unit()

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

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

Definition at line 268 of file unittools.cpp.

Referenced by do_attack().

◆ update_unit_activities()

void update_unit_activities ( struct player pplayer)

Iterate through all units and update them.

Definition at line 646 of file unittools.cpp.

Referenced by begin_phase().

◆ wipe_unit()