Freeciv-3.2
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 unit_list *punits)
302{
307 return TRUE;
308 }
310
311 return FALSE;
312}
313
314/************************************************************************/
318bool units_have_activity_on_tile(const struct unit_list *punits,
319 enum unit_activity activity)
320{
322 if (is_unit_activity_on_tile(activity, unit_tile(punit))) {
323 return TRUE;
324 }
326
327 return FALSE;
328}
329
330/************************************************************************/
334bool units_can_upgrade(const struct civ_map *nmap,
335 const struct unit_list *punits)
336{
339 return TRUE;
340 }
342
343 return FALSE;
344}
345
346/************************************************************************/
349bool units_can_convert(const struct civ_map *nmap,
350 const struct unit_list *punits)
351{
355 return TRUE;
356 }
358
359 return FALSE;
360}
struct base_type * get_base_by_gui_type(enum base_gui_type type, const struct unit *punit, const struct tile *ptile)
Definition base.c:139
char * incite_cost
Definition comments.c:75
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:389
struct civ_game game
Definition game.c:62
struct world wld
Definition game.c:63
#define fc_assert_ret(condition)
Definition log.h:191
bool can_unit_exist_at_tile(const struct civ_map *nmap, const struct unit *punit, const struct tile *ptile)
Definition movement.c:319
bool unit_can_load(const struct unit *punit)
Definition movement.c:883
bool can_build_road(const struct civ_map *nmap, struct road_type *proad, const struct unit *punit, const struct tile *ptile)
Definition road.c:295
#define EQ(p, q)
Definition shared.h:72
struct packet_scenario_info scenario
Definition game.h:87
Definition unit.h:138
enum unit_activity activity
Definition unit.h:157
int id
Definition unit.h:145
int ord_map
Definition unit.h:241
struct unit::@81::@84 server
struct civ_map map
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
int get_transporter_occupancy(const struct unit *ptrans)
Definition unit.c:1783
struct unit * unit_transport_get(const struct unit *pcargo)
Definition unit.c:2441
bool is_unit_activity_on_tile(enum unit_activity activity, const struct tile *ptile)
Definition unit.c:1123
bool unit_can_do_action(const struct unit *punit, const action_id act_id)
Definition unit.c:359
bool unit_can_do_action_result(const struct unit *punit, enum action_result result)
Definition unit.c:369
bool can_unit_do_activity(const struct civ_map *nmap, const struct unit *punit, enum unit_activity activity)
Definition unit.c:868
enum unit_upgrade_result unit_upgrade_test(const struct civ_map *nmap, const struct unit *punit, bool is_free)
Definition unit.c:1988
bool unit_transported(const struct unit *pcargo)
Definition unit.c:2425
bool can_unit_unload(const struct unit *pcargo, const struct unit *ptrans)
Definition unit.c:752
bool unit_can_convert(const struct civ_map *nmap, const struct unit *punit)
Definition unit.c:2035
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:907
#define unit_tile(_pu)
Definition unit.h:397
@ UU_OK
Definition unit.h:61
bool units_can_convert(const struct civ_map *nmap, const struct unit_list *punits)
Definition unitlist.c:349
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
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:334
static int compar_unit_ord_map(const struct unit *const *ua, const struct unit *const *ub)
Definition unitlist.c:51
bool units_can_unload(const struct unit_list *punits)
Definition unitlist.c:301
bool units_have_activity_on_tile(const struct unit_list *punits, enum unit_activity activity)
Definition unitlist.c:318
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:190
bool utype_can_do_action(const struct unit_type *putype, const action_id act_id)
Definition unittype.c:371