1 /****************************************************************************
2 Freeciv - Copyright (C) 2005 - The Freeciv Project
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12 ****************************************************************************/
14 #ifndef FC__UNITLIST_H
15 #define FC__UNITLIST_H
19 #endif /* __cplusplus */
22 #include "unit.h" /* for diplomat_actions */
23 #include "unittype.h" /* for unit_type_flag_id */
25 /* get 'struct unit_list' and related functions: */
26 #define SPECLIST_TAG unit
27 #define SPECLIST_TYPE struct unit
30 #define unit_list_iterate(unitlist, punit) \
31 TYPED_LIST_ITERATE(struct unit, unitlist, punit)
32 #define unit_list_iterate_end LIST_ITERATE_END
33 #define unit_list_both_iterate(unitlist, plink, punit) \
34 TYPED_LIST_BOTH_ITERATE(struct unit_list_link, struct unit, unitlist, \
36 #define unit_list_both_iterate_end LIST_BOTH_ITERATE_END
38 #define unit_list_iterate_safe(unitlist, _unit) \
40 int _unit##_size = unit_list_size(unitlist); \
42 if (_unit##_size > 0) { \
43 int _unit##_numbers[_unit##_size]; \
44 int _unit##_index = 0; \
46 unit_list_iterate(unitlist, _unit) { \
47 _unit##_numbers[_unit##_index++] = _unit->id; \
48 } unit_list_iterate_end; \
50 for (_unit##_index = 0; \
51 _unit##_index < _unit##_size; \
53 struct unit *_unit = \
54 game_unit_by_number(_unit##_numbers[_unit##_index]); \
58 #define unit_list_iterate_safe_end \
64 struct unit
*unit_list_find(const struct unit_list
*punitlist
, int unit_id
);
66 void unit_list_sort_ord_map(struct unit_list
*punitlist
);
67 void unit_list_sort_ord_city(struct unit_list
*punitlist
);
69 bool can_units_do(const struct unit_list
*punits
,
70 bool (can_fn
)(const struct unit
*punit
));
71 bool can_units_do_activity(const struct unit_list
*punits
,
72 enum unit_activity activity
);
73 bool can_units_do_activity_targeted(const struct unit_list
*punits
,
74 enum unit_activity activity
,
75 struct extra_type
*pextra
);
76 bool can_units_do_any_road(const struct unit_list
*punits
);
77 bool can_units_do_base_gui(const struct unit_list
*punits
,
78 enum base_gui_type base_gui
);
79 bool units_have_type_flag(const struct unit_list
*punits
,
80 enum unit_type_flag_id flag
, bool has_flag
);
81 bool units_contain_cityfounder(const struct unit_list
*punits
);
82 bool units_can_do_action(const struct unit_list
*punits
,
83 int action_id
, bool can_do
);
84 bool units_are_occupied(const struct unit_list
*punits
);
85 bool units_can_load(const struct unit_list
*punits
);
86 bool units_can_unload(const struct unit_list
*punits
);
87 bool units_have_activity_on_tile(const struct unit_list
*punits
,
88 enum unit_activity activity
);
90 bool units_can_upgrade(const struct unit_list
*punits
);
91 bool units_can_convert(const struct unit_list
*punits
);
95 #endif /* __cplusplus */
97 #endif /* FC__UNITLIST_H */