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)
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 ***********************************************************************/
18 #endif /* __cplusplus */
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)
84 struct name_translation name
;
86 enum extra_category category
;
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
110 int build_time_factor
;
112 int removal_time_factor
;
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
;
126 Tech_type_id visibility_req
;
128 /* Same information as in hidden_by, but iterating through this list is much
129 * faster than through all extra types to check which ones are hiding this one.
130 * Only used client side. */
131 struct extra_type_list
*hiders
;
133 struct strvec
*helptext
;
138 struct base_type
*base
;
139 struct road_type
*road
;
140 struct resource_type
*resource
;
144 /* get 'struct extra_type_list' and related functions: */
145 #define SPECLIST_TAG extra_type
146 #define SPECLIST_TYPE struct extra_type
147 #include "speclist.h"
149 #define extra_type_list_iterate(extralist, pextra) \
150 TYPED_LIST_ITERATE(struct extra_type, extralist, pextra)
151 #define extra_type_list_iterate_end LIST_ITERATE_END
153 #define extra_type_list_iterate_rev(extralist, pextra) \
154 TYPED_LIST_ITERATE_REV(struct extra_type, extralist, pextra)
155 #define extra_type_list_iterate_rev_end LIST_ITERATE_REV_END
157 void extras_init(void);
158 void extras_free(void);
160 int extra_count(void);
161 int extra_number(const struct extra_type
*pextra
);
162 struct extra_type
*extra_by_number(int id
);
164 /* For optimization purposes (being able to have it as macro instead of function
165 * call) this is now same as extra_number(). extras.c does have semantically correct
166 * implementation too. */
167 #define extra_index(_e_) (_e_)->id
169 const char *extra_name_translation(const struct extra_type
*pextra
);
170 const char *extra_rule_name(const struct extra_type
*pextra
);
171 struct extra_type
*extra_type_by_rule_name(const char *name
);
172 struct extra_type
*extra_type_by_translated_name(const char *name
);
174 #define extra_base_get(_e_) (_e_)->data.base
175 #define extra_road_get(_e_) (_e_)->data.road
176 #define extra_resource_get(_e_) (_e_)->data.resource
178 void extra_to_caused_by_list(struct extra_type
*pextra
, enum extra_cause cause
);
179 struct extra_type_list
*extra_type_list_by_cause(enum extra_cause cause
);
180 struct extra_type
*rand_extra_for_tile(struct tile
*ptile
, enum extra_cause cause
);
182 struct extra_type_list
*extra_type_list_of_unit_hiders(void);
184 void extra_to_category_list(struct extra_type
*pextra
, enum extra_category cat
);
185 struct extra_type_list
*extra_type_list_for_category(enum extra_category cat
);
187 bool is_extra_caused_by(const struct extra_type
*pextra
, enum extra_cause cause
);
188 bool is_extra_caused_by_worker_action(const struct extra_type
*pextra
);
189 bool is_extra_caused_by_action(const struct extra_type
*pextra
,
190 enum unit_activity act
);
192 void extra_to_removed_by_list(struct extra_type
*pextra
, enum extra_rmcause rmcause
);
193 struct extra_type_list
*extra_type_list_by_rmcause(enum extra_rmcause rmcause
);
195 bool is_extra_removed_by(const struct extra_type
*pextra
, enum extra_rmcause rmcause
);
196 bool is_extra_removed_by_worker_action(const struct extra_type
*pextra
);
197 bool is_extra_removed_by_action(const struct extra_type
*pextra
,
198 enum unit_activity act
);
200 bool is_extra_card_near(const struct tile
*ptile
, const struct extra_type
*pextra
);
201 bool is_extra_near_tile(const struct tile
*ptile
, const struct extra_type
*pextra
);
203 bool extra_can_be_built(const struct extra_type
*pextra
, const struct tile
*ptile
);
204 bool can_build_extra(struct extra_type
*pextra
,
205 const struct unit
*punit
,
206 const struct tile
*ptile
);
207 bool player_can_build_extra(const struct extra_type
*pextra
,
208 const struct player
*pplayer
,
209 const struct tile
*ptile
);
211 bool can_remove_extra(struct extra_type
*pextra
,
212 const struct unit
*punit
,
213 const struct tile
*ptile
);
214 bool player_can_remove_extra(const struct extra_type
*pextra
,
215 const struct player
*pplayer
,
216 const struct tile
*ptile
);
218 bool is_native_extra_to_uclass(const struct extra_type
*pextra
,
219 const struct unit_class
*pclass
);
220 bool is_native_extra_to_utype(const struct extra_type
*pextra
,
221 const struct unit_type
*punittype
);
222 bool is_native_tile_to_extra(const struct extra_type
*pextra
,
223 const struct tile
*ptile
);
224 bool extra_conflicting_on_tile(const struct extra_type
*pextra
,
225 const struct tile
*ptile
);
227 bool extra_has_flag(const struct extra_type
*pextra
, enum extra_flag_id flag
);
228 bool is_extra_flag_card_near(const struct tile
*ptile
,
229 enum extra_flag_id flag
);
230 bool is_extra_flag_near_tile(const struct tile
*ptile
,
231 enum extra_flag_id flag
);
233 void user_extra_flags_init(void);
234 void extra_flags_free(void);
235 void set_user_extra_flag_name(enum extra_flag_id id
,
237 const char *helptxt
);
238 const char *extra_flag_helptxt(enum extra_flag_id id
);
240 bool extra_causes_env_upset(struct extra_type
*pextra
,
241 enum environment_upset_type upset
);
243 bool can_extras_coexist(const struct extra_type
*pextra1
,
244 const struct extra_type
*pextra2
);
246 bool can_extra_appear(const struct extra_type
*pextra
, const struct tile
*ptile
);
247 bool can_extra_disappear(const struct extra_type
*pextra
, const struct tile
*ptile
);
249 struct extra_type
*next_extra_for_tile(const struct tile
*ptile
, enum extra_cause cause
,
250 const struct player
*pplayer
,
251 const struct unit
*punit
);
252 struct extra_type
*prev_extra_in_tile(const struct tile
*ptile
, enum extra_rmcause rmcause
,
253 const struct player
*pplayer
,
254 const struct unit
*punit
);
256 enum extra_cause
activity_to_extra_cause(enum unit_activity act
);
257 enum extra_rmcause
activity_to_extra_rmcause(enum unit_activity act
);
259 struct player
*extra_owner(const struct tile
*ptile
);
261 bool player_knows_extra_exist(const struct player
*pplayer
,
262 const struct extra_type
*pextra
,
263 const struct tile
*ptile
);
265 #define extra_type_iterate(_p) \
268 for (_i_##_p = 0; _i_##_p < game.control.num_extra_types; _i_##_p++) { \
269 struct extra_type *_p = extra_by_number(_i_##_p);
271 #define extra_type_iterate_end \
275 #define extra_active_type_iterate(_p) \
276 extra_type_iterate(_p) { \
279 #define extra_active_type_iterate_end \
281 } extra_type_iterate_end;
283 #define extra_type_by_cause_iterate(_cause, _extra) \
285 struct extra_type_list *_etl_##_extra = extra_type_list_by_cause(_cause); \
286 if (_etl_##_extra != NULL) { \
287 extra_type_list_iterate(_etl_##_extra, _extra) {
289 #define extra_type_by_cause_iterate_end \
290 } extra_type_list_iterate_end \
294 #define extra_type_by_cause_iterate_rev(_cause, _extra) \
296 struct extra_type_list *_etl_ = extra_type_list_by_cause(_cause); \
297 extra_type_list_iterate_rev(_etl_, _extra) {
299 #define extra_type_by_cause_iterate_rev_end \
300 } extra_type_list_iterate_rev_end \
303 #define extra_type_by_rmcause_iterate(_rmcause, _extra) \
305 struct extra_type_list *_etl_ = extra_type_list_by_rmcause(_rmcause); \
306 extra_type_list_iterate_rev(_etl_, _extra) {
308 #define extra_type_by_rmcause_iterate_end \
309 } extra_type_list_iterate_rev_end \
312 #define extra_type_by_category_iterate(_cat, _extra) \
314 struct extra_type_list *_etl_##_extra = extra_type_list_for_category(_cat); \
315 if (_etl_##_extra != NULL) { \
316 extra_type_list_iterate(_etl_##_extra, _extra) {
318 #define extra_type_by_category_iterate_end \
319 } extra_type_list_iterate_end \
323 #define extra_deps_iterate(_reqs, _dep) \
325 requirement_vector_iterate(_reqs, preq) { \
326 if (preq->source.kind == VUT_EXTRA \
327 && preq->present) { \
328 struct extra_type *_dep; \
329 _dep = preq->source.value.extra;
331 #define extra_deps_iterate_end \
333 } requirement_vector_iterate_end; \
338 #endif /* __cplusplus */
340 #endif /* FC__EXTRAS_H */