Freeciv-3.2
Loading...
Searching...
No Matches
Functions
unitlist.c File Reference
#include "log.h"
#include "game.h"
#include "movement.h"
#include "unitlist.h"

Go to the source code of this file.

Functions

struct unitunit_list_find (const struct unit_list *punitlist, int unit_id)
 
static int compar_unit_ord_map (const struct unit *const *ua, const struct unit *const *ub)
 
static int compar_unit_ord_city (const struct unit *const *ua, const struct unit *const *ub)
 
void unit_list_sort_ord_map (struct unit_list *punitlist)
 
void unit_list_sort_ord_city (struct unit_list *punitlist)
 
bool can_units_do (const struct unit_list *punits, bool(can_fn)(const struct unit *punit))
 
bool can_units_do_on_map (const struct civ_map *nmap, const struct unit_list *punits, bool(can_fn)(const struct civ_map *nmap, const struct unit *punit))
 
bool can_units_do_activity (const struct civ_map *nmap, const struct unit_list *punits, enum unit_activity activity)
 
bool can_units_do_activity_targeted (const struct civ_map *nmap, const struct unit_list *punits, enum unit_activity activity, struct extra_type *pextra)
 
bool can_units_do_any_road (const struct civ_map *nmap, const struct unit_list *punits)
 
bool can_units_do_base_gui (const struct unit_list *punits, enum base_gui_type base_gui)
 
bool units_have_type_flag (const struct unit_list *punits, enum unit_type_flag_id flag, bool has_flag)
 
bool units_contain_cityfounder (const struct unit_list *punits)
 
bool units_can_do_action (const struct unit_list *punits, action_id act_id, bool can_do)
 
bool units_can_do_action_with_result (const struct unit_list *punits, enum action_result result, bool can_do)
 
bool units_are_occupied (const struct unit_list *punits)
 
bool units_can_load (const struct unit_list *punits)
 
bool units_can_unload (const struct unit_list *punits)
 
bool units_have_activity_on_tile (const struct unit_list *punits, enum unit_activity activity)
 
bool units_can_upgrade (const struct civ_map *nmap, const struct unit_list *punits)
 
bool units_can_convert (const struct civ_map *nmap, const struct unit_list *punits)
 

Function Documentation

◆ can_units_do()

bool can_units_do ( const struct unit_list *  punits,
bool(can_fn)(const struct unit *punit  
)

Return TRUE if the function returns true for any of the units.

Definition at line 95 of file unitlist.c.

Referenced by mr_menu::menus_sensitive(), and real_menus_update().

◆ can_units_do_activity()

bool can_units_do_activity ( const struct civ_map nmap,
const struct unit_list *  punits,
enum unit_activity  activity 
)

Returns TRUE if any of the units can do the activity.

Definition at line 128 of file unitlist.c.

◆ can_units_do_activity_targeted()

bool can_units_do_activity_targeted ( const struct civ_map nmap,
const struct unit_list *  punits,
enum unit_activity  activity,
struct extra_type pextra 
)

Returns TRUE if any of the units can do the targeted activity.

Definition at line 144 of file unitlist.c.

◆ can_units_do_any_road()

bool can_units_do_any_road ( const struct civ_map nmap,
const struct unit_list *  punits 
)

Returns TRUE if any of the units can build any road.

Definition at line 161 of file unitlist.c.

Referenced by mr_menu::menus_sensitive(), and real_menus_update().

◆ can_units_do_base_gui()

bool can_units_do_base_gui ( const struct unit_list *  punits,
enum base_gui_type  base_gui 
)

Returns TRUE if any of the units can build base with given gui_type.

Definition at line 180 of file unitlist.c.

Referenced by mr_menu::menus_sensitive(), and real_menus_update().

◆ can_units_do_on_map()

bool can_units_do_on_map ( const struct civ_map nmap,
const struct unit_list *  punits,
bool(can_fn)(const struct civ_map *nmap, const struct unit *punit  
)

Return TRUE if the function returns true for any of the units, on specific map.

Definition at line 111 of file unitlist.c.

Referenced by mr_menu::menus_sensitive(), and real_menus_update().

◆ compar_unit_ord_city()

static int compar_unit_ord_city ( const struct unit *const ua,
const struct unit *const ub 
)
static

Comparison function for unit_list_sort, sorting by ord_city: see above.

Only used in server/savegame.c.

Definition at line 62 of file unitlist.c.

Referenced by unit_list_sort_ord_city().

◆ compar_unit_ord_map()

static int compar_unit_ord_map ( const struct unit *const ua,
const struct unit *const ub 
)
static

Comparison function for unit_list_sort, sorting by ord_map: The indirection is a bit gory: Read from the right:

  1. cast arg "a" to "ptr to void*" (we're sorting a list of "void*"'s)
  2. dereference to get the "void*"
  3. cast that "void*" to a "struct unit*"

Only used in server/savegame.c.

Definition at line 51 of file unitlist.c.

Referenced by unit_list_sort_ord_map().

◆ unit_list_find()

struct unit * unit_list_find ( const struct unit_list *  punitlist,
int  unit_id 
)

Look for a unit with the given ID in the unit list. Returns NULL if none is found.

Definition at line 30 of file unitlist.c.

Referenced by dai_manage_military(), mr_menu::find_last_unit_pos(), sha_unit_change(), sha_unit_recall(), sha_unit_remove(), and mr_menu::slot_execute_orders().

◆ unit_list_sort_ord_city()

void unit_list_sort_ord_city ( struct unit_list *  punitlist)

Sorts the unit list by punit->server.ord_city values.

Only used in server/savegame/savegame[23].c.

Definition at line 85 of file unitlist.c.

Referenced by unit_ordering_apply(), and unit_ordering_apply().

◆ unit_list_sort_ord_map()

void unit_list_sort_ord_map ( struct unit_list *  punitlist)

Sorts the unit list by punit->server.ord_map values.

Only used in server/savegame/savegame[23].c.

Definition at line 73 of file unitlist.c.

Referenced by unit_ordering_apply(), and unit_ordering_apply().

◆ units_are_occupied()

bool units_are_occupied ( const struct unit_list *  punits)

Return TRUE iff any of the units is a transporter that is occupied.

Definition at line 273 of file unitlist.c.

Referenced by unit_item::create_actions(), mr_menu::menus_sensitive(), and real_menus_update().

◆ units_can_convert()

bool units_can_convert ( const struct civ_map nmap,
const struct unit_list *  punits 
)

Return TRUE iff any of the units can convert to another unit type

Definition at line 349 of file unitlist.c.

Referenced by mr_menu::menus_sensitive(), and real_menus_update().

◆ units_can_do_action()

bool units_can_do_action ( const struct unit_list *  punits,
action_id  act_id,
bool  can_do 
)

If has_flag is true, returns true iff any of the units are able to do the specified action.

If has_flag is false, returns true iff any of the units are unable do the specified action.

Definition at line 239 of file unitlist.c.

Referenced by mr_menu::menus_sensitive(), real_menus_update(), and go_act_menu::update().

◆ units_can_do_action_with_result()

bool units_can_do_action_with_result ( const struct unit_list *  punits,
enum action_result  result,
bool  can_do 
)

If has_flag is true, returns true iff any of the units are able to do any action with the specified result.

If has_flag is false, returns true iff any of the units are unable do any action with the specified result.

Definition at line 258 of file unitlist.c.

◆ units_can_load()

bool units_can_load ( const struct unit_list *  punits)

Returns TRUE iff any of these units can load.

Definition at line 287 of file unitlist.c.

Referenced by unit_item::create_actions(), mr_menu::menus_sensitive(), and real_menus_update().

◆ units_can_unload()

bool units_can_unload ( const struct unit_list *  punits)

Return TRUE iff any of these units can unload.

Definition at line 301 of file unitlist.c.

Referenced by unit_item::create_actions(), mr_menu::menus_sensitive(), and real_menus_update().

◆ units_can_upgrade()

bool units_can_upgrade ( const struct civ_map nmap,
const struct unit_list *  punits 
)

Return TRUE iff any of the units can be upgraded to another unit type (for money)

Definition at line 334 of file unitlist.c.

Referenced by unit_item::create_actions(), mr_menu::menus_sensitive(), and real_menus_update().

◆ units_contain_cityfounder()

bool units_contain_cityfounder ( const struct unit_list *  punits)

Does the list contain any cityfounder units

Definition at line 217 of file unitlist.c.

Referenced by mr_menu::menus_sensitive().

◆ units_have_activity_on_tile()

bool units_have_activity_on_tile ( const struct unit_list *  punits,
enum unit_activity  activity 
)

Return TRUE iff any of the units' tiles have the activity running on them.

Definition at line 318 of file unitlist.c.

Referenced by mr_menu::menus_sensitive(), and real_menus_update().

◆ units_have_type_flag()

bool units_have_type_flag ( const struct unit_list *  punits,
enum unit_type_flag_id  flag,
bool  has_flag 
)

If has_flag is true, returns true iff any of the units have the flag.

If has_flag is false, returns true iff any of the units don't have the flag.

Definition at line 202 of file unitlist.c.

Referenced by mr_menu::menus_sensitive(), and real_menus_update().