Freeciv21
Develop your civilization from humble roots to a global empire
unitlist.h
Go to the documentation of this file.
1 /**************************************************************************
2  Copyright (c) 1996-2020 Freeciv21 and Freeciv contributors. This file is
3  __ __ part of Freeciv21. Freeciv21 is free software: you can
4 / \\..// \ redistribute it and/or modify it under the terms of the GNU
5  ( oo ) General Public License as published by the Free Software
6  \__/ Foundation, either version 3 of the License, or (at your
7  option) any later version. You should have received
8  a copy of the GNU General Public License along with Freeciv21. If not,
9  see https://www.gnu.org/licenses/.
10 **************************************************************************/
11 
12 #pragma once
13 
14 #include "fc_types.h"
15 #include "unit.h" // for diplomat_actions
16 #include "unittype.h" // for unit_type_flag_id
17 
18 #include <vector>
19 
20 // get 'struct unit_list' and related functions:
21 #define SPECLIST_TAG unit
22 #define SPECLIST_TYPE struct unit
23 #include "speclist.h"
24 
25 #define unit_list_iterate(unitlist, punit) \
26  TYPED_LIST_ITERATE(struct unit, unitlist, punit)
27 #define unit_list_iterate_end LIST_ITERATE_END
28 #define unit_list_both_iterate(unitlist, plink, punit) \
29  TYPED_LIST_BOTH_ITERATE(struct unit_list_link, struct unit, unitlist, \
30  plink, punit)
31 #define unit_list_both_iterate_end LIST_BOTH_ITERATE_END
32 
33 #define unit_list_iterate_safe(unitlist, _unit) \
34  { \
35  int _unit##_size = unit_list_size(unitlist); \
36  \
37  if (_unit##_size > 0) { \
38  int _unit##_numbers[_unit##_size]; \
39  int _unit##_index = 0; \
40  \
41  unit_list_iterate(unitlist, _unit) \
42  { \
43  _unit##_numbers[_unit##_index++] = _unit->id; \
44  } \
45  unit_list_iterate_end; \
46  \
47  for (_unit##_index = 0; _unit##_index < _unit##_size; \
48  _unit##_index++) { \
49  struct unit *_unit = \
50  game_unit_by_number(_unit##_numbers[_unit##_index]); \
51  \
52  if (nullptr != _unit) {
53 
54 #define unit_list_iterate_safe_end \
55  } \
56  } \
57  } \
58  }
59 
60 struct unit *unit_list_find(const struct unit_list *punitlist, int unit_id);
61 
62 void unit_list_sort_ord_map(struct unit_list *punitlist);
63 void unit_list_sort_ord_city(struct unit_list *punitlist);
64 
65 bool can_units_do(const std::vector<unit *> &units,
66  bool(can_fn)(const struct unit *punit));
67 bool can_units_do_activity(const std::vector<unit *> &units,
68  enum unit_activity activity);
69 bool can_units_do_activity_targeted(const std::vector<unit *> &units,
70  enum unit_activity activity,
71  struct extra_type *pextra);
72 bool can_units_do_any_road(const std::vector<unit *> &units);
73 bool can_units_do_base_gui(const std::vector<unit *> &units,
74  enum base_gui_type base_gui);
75 bool units_have_type_flag(const std::vector<unit *> &units,
76  enum unit_type_flag_id flag, bool has_flag);
77 bool units_contain_cityfounder(const std::vector<unit *> &units);
78 bool units_can_do_action(const std::vector<unit *> &units, action_id act_id,
79  bool can_do);
80 bool units_are_occupied(const std::vector<unit *> &units);
81 bool units_can_load(const std::vector<unit *> &units);
82 bool units_can_unload(const std::vector<unit *> &units);
83 bool units_have_activity_on_tile(const std::vector<unit *> &units,
84  enum unit_activity activity);
85 
86 bool units_can_upgrade(const std::vector<unit *> &units);
87 bool units_can_convert(const std::vector<unit *> &units);
88 bool any_unit_in_city(const std::vector<unit *> &units);
89 bool units_on_the_same_tile(const std::vector<unit *> &units);
int action_id
Definition: fc_types.h:306
Definition: unit.h:134
enum unit_activity activity
Definition: unit.h:154
bool units_can_load(const std::vector< unit * > &units)
Returns TRUE iff any of these units can load.
Definition: unitlist.cpp:247
bool can_units_do_base_gui(const std::vector< unit * > &units, enum base_gui_type base_gui)
Returns TRUE if any of the units can build base with given gui_type.
Definition: unitlist.cpp:159
bool can_units_do_any_road(const std::vector< unit * > &units)
Returns TRUE if any of the units can build any road.
Definition: unitlist.cpp:139
bool units_can_do_action(const std::vector< unit * > &units, 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.
Definition: unitlist.cpp:218
bool any_unit_in_city(const std::vector< unit * > &units)
Definition: unitlist.cpp:321
bool can_units_do(const std::vector< unit * > &units, bool(can_fn)(const struct unit *punit))
Return TRUE if the function returns true for any of the units.
Definition: unitlist.cpp:89
void unit_list_sort_ord_map(struct unit_list *punitlist)
Sorts the unit list by punit->server.ord_map values.
Definition: unitlist.cpp:69
bool can_units_do_activity_targeted(const std::vector< unit * > &units, enum unit_activity activity, struct extra_type *pextra)
Returns TRUE if any of the units can do the targeted activity.
Definition: unitlist.cpp:123
bool units_are_occupied(const std::vector< unit * > &units)
Return TRUE iff any of the units is a transporter that is occupied.
Definition: unitlist.cpp:233
bool units_can_unload(const std::vector< unit * > &units)
Return TRUE iff any of these units can unload.
Definition: unitlist.cpp:261
bool units_contain_cityfounder(const std::vector< unit * > &units)
Does the list contain any cityfounder units.
Definition: unitlist.cpp:196
bool can_units_do_activity(const std::vector< unit * > &units, enum unit_activity activity)
Returns TRUE if any of the units can do the activity.
Definition: unitlist.cpp:104
bool units_have_activity_on_tile(const std::vector< unit * > &units, enum unit_activity activity)
Return TRUE iff any of the units' tiles have the activity running on them.
Definition: unitlist.cpp:278
bool units_can_upgrade(const std::vector< unit * > &units)
Return TRUE iff any of the units can be upgraded to another unit type (for money)
Definition: unitlist.cpp:294
bool units_can_convert(const std::vector< unit * > &units)
Return TRUE iff any of the units can convert to another unit type.
Definition: unitlist.cpp:308
bool units_have_type_flag(const std::vector< unit * > &units, enum unit_type_flag_id flag, bool has_flag)
If has_flag is true, returns true iff any of the units have the flag.
Definition: unitlist.cpp:181
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.
Definition: unitlist.cpp:24
bool units_on_the_same_tile(const std::vector< unit * > &units)
Definition: unitlist.cpp:332
void unit_list_sort_ord_city(struct unit_list *punitlist)
Sorts the unit list by punit->server.ord_city values.
Definition: unitlist.cpp:80