Stop sharing requirement_unit_state_ereq().
[freeciv.git] / common / extras.h
blobfc4cb0b67eca75c926e973148f39e0a797beb6e9
1 /***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
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.
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 #ifndef FC__EXTRAS_H
14 #define FC__EXTRAS_H
16 #ifdef __cplusplus
17 extern "C" {
18 #endif /* __cplusplus */
20 /* common */
21 #include "base.h"
22 #include "fc_types.h"
23 #include "road.h"
24 #include "terrain.h"
26 /* Used in the network protocol. */
27 #define SPECENUM_NAME extra_flag_id
28 /* Tile with this extra is considered native for units in tile. */
29 #define SPECENUM_VALUE0 EF_NATIVE_TILE
30 #define SPECENUM_VALUE0NAME N_("?extraflag:NativeTile")
31 /* Refuel native units */
32 #define SPECENUM_VALUE1 EF_REFUEL
33 #define SPECENUM_VALUE1NAME N_("?extraflag:Refuel")
34 #define SPECENUM_VALUE2 EF_TERR_CHANGE_REMOVES
35 #define SPECENUM_VALUE2NAME N_("?extraflag:TerrChangeRemoves")
36 /* Extra will be built in cities automatically */
37 #define SPECENUM_VALUE3 EF_AUTO_ON_CITY_CENTER
38 #define SPECENUM_VALUE3NAME N_("?extraflag:AutoOnCityCenter")
39 /* Extra is always present in cities */
40 #define SPECENUM_VALUE4 EF_ALWAYS_ON_CITY_CENTER
41 #define SPECENUM_VALUE4NAME N_("?extraflag:AlwaysOnCityCenter")
42 /* Road style gfx from ocean extra connects to nearby land */
43 #define SPECENUM_VALUE5 EF_CONNECT_LAND
44 #define SPECENUM_VALUE5NAME N_("?extraflag:ConnectLand")
45 /* Counts towards Global Warming */
46 #define SPECENUM_VALUE6 EF_GLOBAL_WARMING
47 #define SPECENUM_VALUE6NAME N_("?extraflag:GlobalWarming")
48 /* Counts towards Nuclear Winter */
49 #define SPECENUM_VALUE7 EF_NUCLEAR_WINTER
50 #define SPECENUM_VALUE7NAME N_("?extraflag:NuclearWinter")
51 /* Owner's flag will be shown on the tile */
52 #define SPECENUM_VALUE8 EF_SHOW_FLAG
53 #define SPECENUM_VALUE8NAME N_("?extraflag:ShowFlag")
54 /* Extra's defense bonus will be counted to
55 * separate "Natural" defense layer. */
56 #define SPECENUM_VALUE9 EF_NATURAL_DEFENSE
57 #define SPECENUM_VALUE9NAME N_("?extraflag:NaturalDefense")
58 /* Units inside will not die all at once */
59 #define SPECENUM_VALUE10 EF_NO_STACK_DEATH
60 #define SPECENUM_VALUE10NAME N_("NoStackDeath")
62 #define SPECENUM_VALUE11 EF_USER_FLAG_1
63 #define SPECENUM_VALUE12 EF_USER_FLAG_2
64 #define SPECENUM_VALUE13 EF_USER_FLAG_3
65 #define SPECENUM_VALUE14 EF_USER_FLAG_4
66 #define SPECENUM_VALUE15 EF_USER_FLAG_5
67 #define SPECENUM_VALUE16 EF_USER_FLAG_6
68 #define SPECENUM_VALUE17 EF_USER_FLAG_7
69 #define SPECENUM_VALUE18 EF_USER_FLAG_8
71 #define SPECENUM_COUNT EF_COUNT
72 #define SPECENUM_NAMEOVERRIDE
73 #define SPECENUM_BITVECTOR bv_extra_flags
74 #include "specenum_gen.h"
76 #define EF_LAST_USER_FLAG EF_USER_FLAG_8
77 #define MAX_NUM_USER_EXTRA_FLAGS (EF_LAST_USER_FLAG - EF_USER_FLAG_1 + 1)
79 #define EXTRA_NONE (-1)
81 struct extra_type
83 int id;
84 struct name_translation name;
85 bool disabled;
86 enum extra_category category;
87 uint16_t causes;
88 uint8_t rmcauses;
90 char graphic_str[MAX_LEN_NAME];
91 char graphic_alt[MAX_LEN_NAME];
92 char activity_gfx[MAX_LEN_NAME];
93 char act_gfx_alt[MAX_LEN_NAME];
94 char act_gfx_alt2[MAX_LEN_NAME];
95 char rmact_gfx[MAX_LEN_NAME];
96 char rmact_gfx_alt[MAX_LEN_NAME];
98 struct requirement_vector reqs;
99 struct requirement_vector rmreqs;
100 struct requirement_vector appearance_reqs;
101 struct requirement_vector disappearance_reqs;
103 /* 'buildable' is unclean. Clean solution would be to rely solely on extra_cause:
104 * if the extra cannot be built, it's not in the cause's list.
105 * But we currently rely on actually-not-buildable extras to be on the lists,
106 * for example for the editor to list non-buildable but editor-placeable
107 * extras. */
108 bool buildable;
109 int build_time;
110 int build_time_factor;
111 int removal_time;
112 int removal_time_factor;
114 int defense_bonus;
115 int appearance_chance;
116 int disappearance_chance;
118 enum extra_unit_seen_type eus;
120 bv_unit_classes native_to;
122 bv_extra_flags flags;
123 bv_extras conflicts;
124 bv_extras hidden_by;
126 /* Same information as in hidden_by, but iterating through this list is much
127 * faster than through all extra types to check which ones are hiding this one.
128 * Only used client side. */
129 struct extra_type_list *hiders;
131 struct strvec *helptext;
133 struct
135 int special_idx;
136 struct base_type *base;
137 struct road_type *road;
138 struct resource_type *resource;
139 } data;
142 /* get 'struct extra_type_list' and related functions: */
143 #define SPECLIST_TAG extra_type
144 #define SPECLIST_TYPE struct extra_type
145 #include "speclist.h"
147 #define extra_type_list_iterate(extralist, pextra) \
148 TYPED_LIST_ITERATE(struct extra_type, extralist, pextra)
149 #define extra_type_list_iterate_end LIST_ITERATE_END
151 #define extra_type_list_iterate_rev(extralist, pextra) \
152 TYPED_LIST_ITERATE_REV(struct extra_type, extralist, pextra)
153 #define extra_type_list_iterate_rev_end LIST_ITERATE_REV_END
155 void extras_init(void);
156 void extras_free(void);
158 int extra_count(void);
159 int extra_number(const struct extra_type *pextra);
160 struct extra_type *extra_by_number(int id);
162 /* For optimization purposes (being able to have it as macro instead of function
163 * call) this is now same as extra_number(). extras.c does have semantically correct
164 * implementation too. */
165 #define extra_index(_e_) (_e_)->id
167 const char *extra_name_translation(const struct extra_type *pextra);
168 const char *extra_rule_name(const struct extra_type *pextra);
169 struct extra_type *extra_type_by_rule_name(const char *name);
170 struct extra_type *extra_type_by_translated_name(const char *name);
172 #define extra_base_get(_e_) (_e_)->data.base
173 #define extra_road_get(_e_) (_e_)->data.road
174 #define extra_resource_get(_e_) (_e_)->data.resource
176 void extra_to_caused_by_list(struct extra_type *pextra, enum extra_cause cause);
177 struct extra_type_list *extra_type_list_by_cause(enum extra_cause cause);
178 struct extra_type *rand_extra_for_tile(struct tile *ptile, enum extra_cause cause);
180 struct extra_type_list *extra_type_list_of_unit_hiders(void);
182 void extra_to_category_list(struct extra_type *pextra, enum extra_category cat);
183 struct extra_type_list *extra_type_list_for_category(enum extra_category cat);
185 bool is_extra_caused_by(const struct extra_type *pextra, enum extra_cause cause);
186 bool is_extra_caused_by_worker_action(const struct extra_type *pextra);
187 bool is_extra_caused_by_action(const struct extra_type *pextra,
188 enum unit_activity act);
190 void extra_to_removed_by_list(struct extra_type *pextra, enum extra_rmcause rmcause);
191 struct extra_type_list *extra_type_list_by_rmcause(enum extra_rmcause rmcause);
193 bool is_extra_removed_by(const struct extra_type *pextra, enum extra_rmcause rmcause);
194 bool is_extra_removed_by_worker_action(const struct extra_type *pextra);
195 bool is_extra_removed_by_action(const struct extra_type *pextra,
196 enum unit_activity act);
198 bool is_extra_card_near(const struct tile *ptile, const struct extra_type *pextra);
199 bool is_extra_near_tile(const struct tile *ptile, const struct extra_type *pextra);
201 bool extra_can_be_built(const struct extra_type *pextra, const struct tile *ptile);
202 bool can_build_extra(struct extra_type *pextra,
203 const struct unit *punit,
204 const struct tile *ptile);
205 bool player_can_build_extra(const struct extra_type *pextra,
206 const struct player *pplayer,
207 const struct tile *ptile);
209 bool can_remove_extra(struct extra_type *pextra,
210 const struct unit *punit,
211 const struct tile *ptile);
212 bool player_can_remove_extra(const struct extra_type *pextra,
213 const struct player *pplayer,
214 const struct tile *ptile);
216 bool is_native_extra_to_uclass(const struct extra_type *pextra,
217 const struct unit_class *pclass);
218 bool is_native_extra_to_utype(const struct extra_type *pextra,
219 const struct unit_type *punittype);
220 bool is_native_tile_to_extra(const struct extra_type *pextra,
221 const struct tile *ptile);
222 bool extra_conflicting_on_tile(const struct extra_type *pextra,
223 const struct tile *ptile);
225 bool extra_has_flag(const struct extra_type *pextra, enum extra_flag_id flag);
226 bool is_extra_flag_card_near(const struct tile *ptile,
227 enum extra_flag_id flag);
228 bool is_extra_flag_near_tile(const struct tile *ptile,
229 enum extra_flag_id flag);
231 void user_extra_flags_init(void);
232 void extra_flags_free(void);
233 void set_user_extra_flag_name(enum extra_flag_id id,
234 const char *name,
235 const char *helptxt);
236 const char *extra_flag_helptxt(enum extra_flag_id id);
238 bool extra_causes_env_upset(struct extra_type *pextra,
239 enum environment_upset_type upset);
241 bool can_extras_coexist(const struct extra_type *pextra1,
242 const struct extra_type *pextra2);
244 bool can_extra_appear(const struct extra_type *pextra, const struct tile *ptile);
245 bool can_extra_disappear(const struct extra_type *pextra, const struct tile *ptile);
247 struct extra_type *next_extra_for_tile(const struct tile *ptile, enum extra_cause cause,
248 const struct player *pplayer,
249 const struct unit *punit);
250 struct extra_type *prev_extra_in_tile(const struct tile *ptile, enum extra_rmcause rmcause,
251 const struct player *pplayer,
252 const struct unit *punit);
254 enum extra_cause activity_to_extra_cause(enum unit_activity act);
255 enum extra_rmcause activity_to_extra_rmcause(enum unit_activity act);
257 struct player *extra_owner(const struct tile *ptile);
259 #define extra_type_iterate(_p) \
261 int _i_##_p; \
262 for (_i_##_p = 0; _i_##_p < game.control.num_extra_types; _i_##_p++) { \
263 struct extra_type *_p = extra_by_number(_i_##_p);
265 #define extra_type_iterate_end \
269 #define extra_active_type_iterate(_p) \
270 extra_type_iterate(_p) { \
271 if (!_p->disabled) {
273 #define extra_active_type_iterate_end \
275 } extra_type_iterate_end;
277 #define extra_type_by_cause_iterate(_cause, _extra) \
279 struct extra_type_list *_etl_##_extra = extra_type_list_by_cause(_cause); \
280 if (_etl_##_extra != NULL) { \
281 extra_type_list_iterate(_etl_##_extra, _extra) {
283 #define extra_type_by_cause_iterate_end \
284 } extra_type_list_iterate_end \
288 #define extra_type_by_cause_iterate_rev(_cause, _extra) \
290 struct extra_type_list *_etl_ = extra_type_list_by_cause(_cause); \
291 extra_type_list_iterate_rev(_etl_, _extra) {
293 #define extra_type_by_cause_iterate_rev_end \
294 } extra_type_list_iterate_rev_end \
297 #define extra_type_by_rmcause_iterate(_rmcause, _extra) \
299 struct extra_type_list *_etl_ = extra_type_list_by_rmcause(_rmcause); \
300 extra_type_list_iterate_rev(_etl_, _extra) {
302 #define extra_type_by_rmcause_iterate_end \
303 } extra_type_list_iterate_rev_end \
306 #define extra_type_by_category_iterate(_cat, _extra) \
308 struct extra_type_list *_etl_##_extra = extra_type_list_for_category(_cat); \
309 if (_etl_##_extra != NULL) { \
310 extra_type_list_iterate(_etl_##_extra, _extra) {
312 #define extra_type_by_category_iterate_end \
313 } extra_type_list_iterate_end \
317 #define extra_deps_iterate(_reqs, _dep) \
319 requirement_vector_iterate(_reqs, preq) { \
320 if (preq->source.kind == VUT_EXTRA \
321 && preq->present) { \
322 struct extra_type *_dep; \
323 _dep = preq->source.value.extra;
325 #define extra_deps_iterate_end \
327 } requirement_vector_iterate_end; \
330 #ifdef __cplusplus
332 #endif /* __cplusplus */
334 #endif /* FC__EXTRAS_H */