Freeciv-3.3
Loading...
Searching...
No Matches
unitlist.c
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#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18/* utility */
19#include "log.h"
20
21/* common */
22#include "game.h"
23#include "movement.h"
24#include "unitlist.h"
25
26/************************************************************************/
30struct unit *unit_list_find(const struct unit_list *punitlist, int unit_id)
31{
33 if (punit->id == unit_id) {
34 return punit;
35 }
37
38 return NULL;
39}
40
41/************************************************************************/
51static int compar_unit_ord_map(const struct unit *const *ua,
52 const struct unit *const *ub)
53{
54 return (*ua)->server.ord_map - (*ub)->server.ord_map;
55}
56
57/************************************************************************/
62static int compar_unit_ord_city(const struct unit *const *ua,
63 const struct unit *const *ub)
64{
65 return (*ua)->server.ord_city - (*ub)->server.ord_city;
66}
67
68/************************************************************************/
79
80/************************************************************************/
91
92/************************************************************************/
95bool can_units_do(const struct unit_list *punits,
96 bool (can_fn)(const struct unit *punit))
97{
99 if (can_fn(punit)) {
100 return TRUE;
101 }
103
104 return FALSE;
105}
106
107/************************************************************************/
112 const struct unit_list *punits,
113 bool (can_fn)(const struct civ_map *nmap,
114 const struct unit *punit))
115{
117 if (can_fn(nmap, punit)) {
118 return TRUE;
119 }
121
122 return FALSE;
123}
124
125/************************************************************************/
129 const struct unit_list *punits,
131{
134 return TRUE;
135 }
137
138 return FALSE;
139}
140
141/************************************************************************/
145 const struct unit_list *punits,
147 struct extra_type *pextra)
148{
151 return TRUE;
152 }
154
155 return FALSE;
156}
157
158/************************************************************************/
162 const struct unit_list *punits)
163{
166 struct road_type *proad = extra_road_get(pextra);
167
169 return TRUE;
170 }
173
174 return FALSE;
175}
176
177/************************************************************************/
180bool can_units_do_base_gui(const struct unit_list *punits,
182{
186
187 if (pbase) {
188 /* Some unit can build base of given gui_type */
189 return TRUE;
190 }
192
193 return FALSE;
194}
195
196/************************************************************************/
202bool units_have_type_flag(const struct unit_list *punits,
203 enum unit_type_flag_id flag, bool has_flag)
204{
206 if (EQ(has_flag, unit_has_type_flag(punit, flag))) {
207 return TRUE;
208 }
210
211 return FALSE;
212}
213
214/************************************************************************/
217bool units_contain_cityfounder(const struct unit_list *punits)
218{
220 return FALSE;
221 }
222
225 return TRUE;
226 }
228
229 return FALSE;
230}
231
232/************************************************************************/
239bool units_can_do_action(const struct unit_list *punits,
240 action_id act_id, bool can_do)
241{
243 if (EQ(can_do, unit_can_do_action(punit, act_id))) {
244 return TRUE;
245 }
247
248 return FALSE;
249}
250
251/************************************************************************/
258bool units_can_do_action_with_result(const struct unit_list *punits,
259 enum action_result result, bool can_do)
260{
262 if (EQ(can_do, unit_can_do_action_result(punit, result))) {
263 return TRUE;
264 }
266
267 return FALSE;
268}
269
270/************************************************************************/
273bool units_are_occupied(const struct unit_list *punits)
274{
277 return TRUE;
278 }
280
281 return FALSE;
282}
283
284/************************************************************************/
287bool units_can_load(const struct unit_list *punits)
288{
290 if (unit_can_load(punit)) {
291 return TRUE;
292 }
294
295 return FALSE;
296}
297
298/************************************************************************/
301bool units_can_unload(const struct civ_map *nmap,
302 const struct unit_list *punits)
303{
308 return TRUE;
309 }
311
312 return FALSE;
313}
314
315/************************************************************************/
319bool units_have_activity_on_tile(const struct unit_list *punits,
320 enum unit_activity activity)
321{
323 if (is_unit_activity_on_tile(activity, unit_tile(punit))) {
324 return TRUE;
325 }
327
328 return FALSE;
329}
330
331/************************************************************************/
335bool units_can_upgrade(const struct civ_map *nmap,
336 const struct unit_list *punits)
337{
340 return TRUE;
341 }
343
344 return FALSE;
345}
346
347/************************************************************************/
350bool units_can_convert(const struct civ_map *nmap,
351 const struct unit_list *punits)
352{
356 return TRUE;
357 }
359
360 return FALSE;
361}
struct base_type * get_base_by_gui_type(enum base_gui_type type, const struct unit *punit, const struct tile *ptile)
Definition base.c:143
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
#define extra_road_get(_e_)
Definition extras.h:191
#define extra_type_by_cause_iterate_end
Definition extras.h:339
#define extra_type_by_cause_iterate(_cause, _extra)
Definition extras.h:333
static bool is_server(void)
int action_id
Definition fc_types.h:248
struct civ_game game
Definition game.c:61
#define fc_assert_ret(condition)
Definition log.h:192
bool can_unit_exist_at_tile(const struct civ_map *nmap, const struct unit *punit, const struct tile *ptile)
Definition movement.c:318
bool unit_can_load(const struct unit *punit)
Definition movement.c:884
bool can_build_road(const struct civ_map *nmap, struct road_type *proad, const struct unit *punit, const struct tile *ptile)
Definition road.c:301
#define EQ(p, q)
Definition shared.h:72
struct packet_scenario_info scenario
Definition game.h:87
Definition unit.h:140
enum unit_activity activity
Definition unit.h:159
int id
Definition unit.h:147
int ord_map
Definition unit.h:244
struct unit::@84::@87 server
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
int get_transporter_occupancy(const struct unit *ptrans)
Definition unit.c:1820
struct unit * unit_transport_get(const struct unit *pcargo)
Definition unit.c:2518
bool is_unit_activity_on_tile(enum unit_activity activity, const struct tile *ptile)
Definition unit.c:1151
bool unit_can_do_action(const struct unit *punit, const action_id act_id)
Definition unit.c:383
bool unit_can_do_action_result(const struct unit *punit, enum action_result result)
Definition unit.c:393
bool can_unit_do_activity(const struct civ_map *nmap, const struct unit *punit, enum unit_activity activity)
Definition unit.c:892
enum unit_upgrade_result unit_upgrade_test(const struct civ_map *nmap, const struct unit *punit, bool is_free)
Definition unit.c:2025
bool unit_transported(const struct unit *pcargo)
Definition unit.c:2502
bool can_unit_unload(const struct unit *pcargo, const struct unit *ptrans)
Definition unit.c:776
bool unit_can_convert(const struct civ_map *nmap, const struct unit *punit)
Definition unit.c:2072
bool can_unit_do_activity_targeted(const struct civ_map *nmap, const struct unit *punit, enum unit_activity activity, struct extra_type *target)
Definition unit.c:931
#define unit_tile(_pu)
Definition unit.h:404
@ UU_OK
Definition unit.h:62
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
static int compar_unit_ord_city(const struct unit *const *ua, const struct unit *const *ub)
Definition unitlist.c:62
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
static int compar_unit_ord_map(const struct unit *const *ua, const struct unit *const *ub)
Definition unitlist.c:51
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
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
#define unit_list_iterate_end
Definition unitlist.h:33
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:123
bool unit_has_type_flag(const struct unit *punit, enum unit_type_flag_id flag)
Definition unittype.c:196
bool utype_can_do_action(const struct unit_type *putype, const action_id act_id)
Definition unittype.c:377