Freeciv-3.3
Loading...
Searching...
No Matches
unitlist.h
Go to the documentation of this file.
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)
6 any later version.
7
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****************************************************************************/
13
14#ifndef FC__UNITLIST_H
15#define FC__UNITLIST_H
16
17#ifdef __cplusplus
18extern "C" {
19#endif /* __cplusplus */
20
21/* common */
22#include "fc_types.h"
23#include "unit.h" /* for diplomat_actions */
24#include "unittype.h" /* for unit_type_flag_id */
25
26/* get 'struct unit_list' and related functions: */
27#define SPECLIST_TAG unit
28#define SPECLIST_TYPE struct unit
29#include "speclist.h"
30
31#define unit_list_iterate(unitlist, punit) \
32 TYPED_LIST_ITERATE(struct unit, unitlist, punit)
33#define unit_list_iterate_end LIST_ITERATE_END
34#define unit_list_both_iterate(unitlist, plink, punit) \
35 TYPED_LIST_BOTH_ITERATE(struct unit_list_link, struct unit, unitlist, \
36 plink, punit)
37#define unit_list_both_iterate_end LIST_BOTH_ITERATE_END
38
39#define unit_list_iterate_safe(unitlist, _unit) \
40{ \
41 struct unit_list *_unit##_ul = unitlist; \
42 int _unit##_size = unit_list_size(_unit##_ul); \
43 \
44 if (_unit##_size > 0) { \
45 int _unit##_numbers[_unit##_size]; \
46 int _unit##_index; \
47 \
48 _unit##_size = 0; \
49 unit_list_iterate(_unit##_ul, _unit) { \
50 _unit##_numbers[_unit##_size++] = _unit->id; \
51 } unit_list_iterate_end; \
52 \
53 for (_unit##_index = 0; \
54 _unit##_index < _unit##_size; \
55 _unit##_index++) { \
56 struct unit *_unit = \
57 game_unit_by_number(_unit##_numbers[_unit##_index]); \
58 \
59 if (NULL != _unit) {
60
61#define unit_list_iterate_safe_end \
62 } \
63 } \
64 } \
65}
66
67struct unit *unit_list_find(const struct unit_list *punitlist, int unit_id);
68
69void unit_list_sort_ord_map(struct unit_list *punitlist);
70void unit_list_sort_ord_city(struct unit_list *punitlist);
71
72bool can_units_do(const struct unit_list *punits,
73 bool (can_fn)(const struct unit *punit));
74bool can_units_do_on_map(const struct civ_map *nmap,
75 const struct unit_list *punits,
76 bool (can_fn)(const struct civ_map *nmap,
77 const struct unit *punit));
78bool can_units_do_activity(const struct civ_map *nmap,
79 const struct unit_list *punits,
82 const struct unit_list *punits,
84 struct extra_type *pextra);
85bool can_units_do_any_road(const struct civ_map *nmap,
86 const struct unit_list *punits);
87bool can_units_do_base_gui(const struct unit_list *punits,
89bool units_have_type_flag(const struct unit_list *punits,
90 enum unit_type_flag_id flag, bool has_flag);
91bool units_contain_cityfounder(const struct unit_list *punits);
92bool units_can_do_action(const struct unit_list *punits,
93 action_id act_id, bool can_do);
94bool units_can_do_action_with_result(const struct unit_list *punits,
95 enum action_result result,
96 bool can_do);
97bool units_are_occupied(const struct unit_list *punits);
98bool units_can_load(const struct unit_list *punits);
99bool units_can_unload(const struct civ_map *nmap,
100 const struct unit_list *punits);
101bool units_have_activity_on_tile(const struct unit_list *punits,
103
104bool units_can_upgrade(const struct civ_map *nmap,
105 const struct unit_list *punits);
106bool units_can_convert(const struct civ_map *nmap,
107 const struct unit_list *punits);
108
109#ifdef __cplusplus
110}
111#endif /* __cplusplus */
112
113#endif /* FC__UNITLIST_H */
char * incite_cost
Definition comments.c:76
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit * punit
Definition dialogs_g.h:74
int action_id
Definition fc_types.h:248
Definition unit.h:140
enum unit_activity activity
Definition unit.h:159
bool units_can_convert(const struct civ_map *nmap, const struct unit_list *punits)
Definition unitlist.c:350
bool units_are_occupied(const struct unit_list *punits)
Definition unitlist.c:273
bool units_can_do_action_with_result(const struct unit_list *punits, enum action_result result, bool can_do)
Definition unitlist.c:258
bool units_can_unload(const struct civ_map *nmap, const struct unit_list *punits)
Definition unitlist.c:301
bool can_units_do_base_gui(const struct unit_list *punits, enum base_gui_type base_gui)
Definition unitlist.c:180
bool units_contain_cityfounder(const struct unit_list *punits)
Definition unitlist.c:217
void unit_list_sort_ord_map(struct unit_list *punitlist)
Definition unitlist.c:73
bool can_units_do_any_road(const struct civ_map *nmap, const struct unit_list *punits)
Definition unitlist.c:161
bool can_units_do_activity(const struct civ_map *nmap, const struct unit_list *punits, enum unit_activity activity)
Definition unitlist.c:128
struct unit * unit_list_find(const struct unit_list *punitlist, int unit_id)
Definition unitlist.c:30
bool units_can_upgrade(const struct civ_map *nmap, const struct unit_list *punits)
Definition unitlist.c:335
bool units_have_activity_on_tile(const struct unit_list *punits, enum unit_activity activity)
Definition unitlist.c:319
bool units_have_type_flag(const struct unit_list *punits, enum unit_type_flag_id flag, bool has_flag)
Definition unitlist.c:202
bool can_units_do(const struct unit_list *punits, bool(can_fn)(const struct unit *punit))
Definition unitlist.c:95
bool units_can_do_action(const struct unit_list *punits, action_id act_id, bool can_do)
Definition unitlist.c:239
bool units_can_load(const struct unit_list *punits)
Definition unitlist.c:287
void unit_list_sort_ord_city(struct unit_list *punitlist)
Definition unitlist.c:85
bool can_units_do_activity_targeted(const struct civ_map *nmap, const struct unit_list *punits, enum unit_activity activity, struct extra_type *pextra)
Definition unitlist.c:144
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))
Definition unitlist.c:111