Freeciv-3.1
Loading...
Searching...
No Matches
extras.h
Go to the documentation of this file.
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.
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#ifndef FC__EXTRAS_H
14#define FC__EXTRAS_H
15
16#ifdef __cplusplus
17extern "C" {
18#endif /* __cplusplus */
19
20/* common */
21#include "base.h"
22#include "fc_types.h"
23#include "road.h"
24#include "terrain.h"
25
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")
61/* Unit inside are not considered aggressive if extra is close to city */
62#define SPECENUM_VALUE11 EF_NOT_AGGRESSIVE
63#define SPECENUM_VALUE11NAME N_("NoAggressive")
64
65#define SPECENUM_VALUE12 EF_USER_FLAG_1
66#define SPECENUM_VALUE13 EF_USER_FLAG_2
67#define SPECENUM_VALUE14 EF_USER_FLAG_3
68#define SPECENUM_VALUE15 EF_USER_FLAG_4
69#define SPECENUM_VALUE16 EF_USER_FLAG_5
70#define SPECENUM_VALUE17 EF_USER_FLAG_6
71#define SPECENUM_VALUE18 EF_USER_FLAG_7
72#define SPECENUM_VALUE19 EF_USER_FLAG_8
73
74#define SPECENUM_COUNT EF_COUNT
75#define SPECENUM_NAMEOVERRIDE
76#define SPECENUM_BITVECTOR bv_extra_flags
77#include "specenum_gen.h"
78
79#define EF_LAST_USER_FLAG EF_USER_FLAG_8
80#define MAX_NUM_USER_EXTRA_FLAGS (EF_LAST_USER_FLAG - EF_USER_FLAG_1 + 1)
81
82#define EXTRA_NONE (-1)
83
85{
86 int id;
90 enum extra_category category;
91 uint16_t causes;
92 uint8_t rmcauses;
93
101
102 struct requirement_vector reqs;
103 struct requirement_vector rmreqs;
104 struct requirement_vector appearance_reqs;
105 struct requirement_vector disappearance_reqs;
106
107 /* 'buildable' is unclean. Clean solution would be to rely solely on extra_cause:
108 * if the extra cannot be built, it's not in the cause's list.
109 * But we currently rely on actually-not-buildable extras to be on the lists,
110 * for example for the editor to list non-buildable but editor-placeable
111 * extras. */
119
123
124 enum extra_unit_seen_type eus;
125
126 bv_unit_classes native_to;
127
128 bv_extra_flags flags;
129 bv_extras conflicts;
130 bv_extras hidden_by;
131 bv_extras bridged_over; /* Needs "bridge" to get built over these extras */
132
134
135 /* Same information as in hidden_by, but iterating through this list is much
136 * faster than through all extra types to check which ones are hiding this one.
137 * Only used client side. */
138 struct extra_type_list *hiders;
139
140 /* Same information as bridged_over */
141 struct extra_type_list *bridged;
142
144
145 struct
146 {
152};
153
154/* get 'struct extra_type_list' and related functions: */
155#define SPECLIST_TAG extra_type
156#define SPECLIST_TYPE struct extra_type
157#include "speclist.h"
158
159#define extra_type_list_iterate(extralist, pextra) \
160 TYPED_LIST_ITERATE(struct extra_type, extralist, pextra)
161#define extra_type_list_iterate_end LIST_ITERATE_END
162
163#define extra_type_list_iterate_rev(extralist, pextra) \
164 TYPED_LIST_ITERATE_REV(struct extra_type, extralist, pextra)
165#define extra_type_list_iterate_rev_end LIST_ITERATE_REV_END
166
167void extras_init(void);
168void extras_free(void);
169
170int extra_count(void);
171int extra_number(const struct extra_type *pextra);
172struct extra_type *extra_by_number(int id);
173
174/* For optimization purposes (being able to have it as macro instead of function
175 * call) this is now same as extra_number(). extras.c does have semantically correct
176 * implementation too. */
177#define extra_index(_e_) (_e_)->id
178
179const char *extra_name_translation(const struct extra_type *pextra);
180const char *extra_rule_name(const struct extra_type *pextra);
181struct extra_type *extra_type_by_rule_name(const char *name);
183
184#define extra_base_get(_e_) (_e_)->data.base
185#define extra_road_get(_e_) (_e_)->data.road
186#define extra_resource_get(_e_) (_e_)->data.resource
187
188void extra_to_caused_by_list(struct extra_type *pextra, enum extra_cause cause);
189struct extra_type_list *extra_type_list_by_cause(enum extra_cause cause);
190struct extra_type *rand_extra_for_tile(struct tile *ptile, enum extra_cause cause,
191 bool generated);
192
193struct extra_type_list *extra_type_list_of_unit_hiders(void);
194struct extra_type_list *extra_type_list_of_terr_claimers(void);
195
196#define is_extra_caused_by(e, c) (e->causes & (1 << c))
197bool is_extra_caused_by_worker_action(const struct extra_type *pextra);
198bool is_extra_caused_by_action(const struct extra_type *pextra,
199 const struct action *paction);
200
201void extra_to_removed_by_list(struct extra_type *pextra, enum extra_rmcause rmcause);
202struct extra_type_list *extra_type_list_by_rmcause(enum extra_rmcause rmcause);
203
204bool is_extra_removed_by(const struct extra_type *pextra, enum extra_rmcause rmcause);
205bool is_extra_removed_by_worker_action(const struct extra_type *pextra);
206bool is_extra_removed_by_action(const struct extra_type *pextra,
207 const struct action *paction);
208
209bool is_extra_card_near(const struct civ_map *nmap, const struct tile *ptile,
210 const struct extra_type *pextra);
211bool is_extra_near_tile(const struct civ_map *nmap, const struct tile *ptile,
212 const struct extra_type *pextra);
213
214bool extra_can_be_built(const struct extra_type *pextra, const struct tile *ptile);
215bool can_build_extra(const struct extra_type *pextra,
216 const struct unit *punit,
217 const struct tile *ptile);
218bool can_build_extra_base(const struct extra_type *pextra,
219 const struct player *pplayer,
220 const struct tile *ptile);
221bool player_can_build_extra(const struct extra_type *pextra,
222 const struct player *pplayer,
223 const struct tile *ptile);
224bool player_can_place_extra(const struct extra_type *pextra,
225 const struct player *pplayer,
226 const struct tile *ptile);
227
228bool can_remove_extra(const struct extra_type *pextra,
229 const struct unit *punit,
230 const struct tile *ptile);
231bool player_can_remove_extra(const struct extra_type *pextra,
232 const struct player *pplayer,
233 const struct tile *ptile);
234
235bool is_native_extra_to_uclass(const struct extra_type *pextra,
236 const struct unit_class *pclass);
237bool is_native_extra_to_utype(const struct extra_type *pextra,
238 const struct unit_type *punittype);
239bool is_native_tile_to_extra(const struct extra_type *pextra,
240 const struct tile *ptile);
241bool extra_conflicting_on_tile(const struct extra_type *pextra,
242 const struct tile *ptile);
243
244bool hut_on_tile(const struct tile *ptile);
245bool unit_can_enter_hut(const struct unit *punit,
246 const struct tile *ptile);
247bool unit_can_displace_hut(const struct unit *punit,
248 const struct tile *ptile);
249
250bool extra_has_flag(const struct extra_type *pextra, enum extra_flag_id flag);
251bool is_extra_flag_card_near(const struct civ_map *nmap,
252 const struct tile *ptile,
253 enum extra_flag_id flag);
254bool is_extra_flag_near_tile(const struct civ_map *nmap,
255 const struct tile *ptile,
256 enum extra_flag_id flag);
257
258void user_extra_flags_init(void);
259void extra_flags_free(void);
260void set_user_extra_flag_name(enum extra_flag_id id,
261 const char *name,
262 const char *helptxt);
263const char *extra_flag_helptxt(enum extra_flag_id id);
264bool extra_flag_is_in_use(enum extra_flag_id id);
265
266bool extra_causes_env_upset(struct extra_type *pextra,
267 enum environment_upset_type upset);
268
269bool can_extras_coexist(const struct extra_type *pextra1,
270 const struct extra_type *pextra2);
271
272bool can_extra_appear(const struct extra_type *pextra, const struct tile *ptile);
273bool can_extra_disappear(const struct extra_type *pextra, const struct tile *ptile);
274
275struct extra_type *next_extra_for_tile(const struct tile *ptile, enum extra_cause cause,
276 const struct player *pplayer,
277 const struct unit *punit);
278struct extra_type *prev_extra_in_tile(const struct tile *ptile, enum extra_rmcause rmcause,
279 const struct player *pplayer,
280 const struct unit *punit);
281
282enum extra_cause activity_to_extra_cause(enum unit_activity act);
283enum extra_rmcause activity_to_extra_rmcause(enum unit_activity act);
284
285struct player *extra_owner(const struct tile *ptile);
286
287bool player_knows_extra_exist(const struct player *pplayer,
288 const struct extra_type *pextra,
289 const struct tile *ptile);
290
291#define extra_type_iterate(_p) \
292{ \
293 int _i_##_p; \
294 for (_i_##_p = 0; _i_##_p < game.control.num_extra_types; _i_##_p++) { \
295 struct extra_type *_p = extra_by_number(_i_##_p);
296
297#define extra_type_iterate_end \
298 } \
299}
300
301#define extra_type_re_active_iterate(_p) \
302 extra_type_iterate(_p) { \
303 if (!_p->ruledit_disabled) {
304
305#define extra_type_re_active_iterate_end \
306 } \
307 } extra_type_iterate_end;
308
309#define extra_type_by_cause_iterate(_cause, _extra) \
310{ \
311 struct extra_type_list *_etl_##_extra = extra_type_list_by_cause(_cause); \
312 if (_etl_##_extra != NULL) { \
313 extra_type_list_iterate(_etl_##_extra, _extra) {
314
315#define extra_type_by_cause_iterate_end \
316 } extra_type_list_iterate_end \
317 } \
318}
319
320#define extra_type_by_cause_iterate_rev(_cause, _extra) \
321{ \
322 struct extra_type_list *_etl_ = extra_type_list_by_cause(_cause); \
323 extra_type_list_iterate_rev(_etl_, _extra) {
324
325#define extra_type_by_cause_iterate_rev_end \
326 } extra_type_list_iterate_rev_end \
327}
328
329#define extra_type_by_rmcause_iterate(_rmcause, _extra) \
330{ \
331 struct extra_type_list *_etl_ = extra_type_list_by_rmcause(_rmcause); \
332 extra_type_list_iterate_rev(_etl_, _extra) {
333
334#define extra_type_by_rmcause_iterate_end \
335 } extra_type_list_iterate_rev_end \
336}
337
338#define extra_deps_iterate(_reqs, _dep) \
339{ \
340 requirement_vector_iterate(_reqs, preq) { \
341 if (preq->source.kind == VUT_EXTRA \
342 && preq->present) { \
343 struct extra_type *_dep; \
344 _dep = preq->source.value.extra;
345
346#define extra_deps_iterate_end \
347 } \
348 } requirement_vector_iterate_end; \
349}
350
351#ifdef __cplusplus
352}
353#endif /* __cplusplus */
354
355#endif /* FC__EXTRAS_H */
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:73
bool is_extra_removed_by_worker_action(const struct extra_type *pextra)
Definition extras.c:994
struct extra_type * next_extra_for_tile(const struct tile *ptile, enum extra_cause cause, const struct player *pplayer, const struct unit *punit)
Definition extras.c:740
struct extra_type * extra_type_by_rule_name(const char *name)
Definition extras.c:204
bool extra_causes_env_upset(struct extra_type *pextra, enum environment_upset_type upset)
Definition extras.c:965
bool can_build_extra_base(const struct extra_type *pextra, const struct player *pplayer, const struct tile *ptile)
Definition extras.c:387
bool unit_can_displace_hut(const struct unit *punit, const struct tile *ptile)
Definition extras.c:713
struct extra_type * rand_extra_for_tile(struct tile *ptile, enum extra_cause cause, bool generated)
Definition extras.c:267
bool player_can_place_extra(const struct extra_type *pextra, const struct player *pplayer, const struct tile *ptile)
Definition extras.c:462
void user_extra_flags_init(void)
Definition extras.c:858
struct player * extra_owner(const struct tile *ptile)
Definition extras.c:1068
bool extra_flag_is_in_use(enum extra_flag_id id)
Definition extras.c:936
const char * extra_flag_helptxt(enum extra_flag_id id)
Definition extras.c:923
struct extra_type * extra_type_by_translated_name(const char *name)
Definition extras.c:227
void set_user_extra_flag_name(enum extra_flag_id id, const char *name, const char *helptxt)
Definition extras.c:882
bool is_extra_flag_near_tile(const struct civ_map *nmap, const struct tile *ptile, enum extra_flag_id flag)
Definition extras.c:839
bool unit_can_enter_hut(const struct unit *punit, const struct tile *ptile)
Definition extras.c:687
bool is_extra_caused_by_worker_action(const struct extra_type *pextra)
Definition extras.c:981
bool is_extra_flag_card_near(const struct civ_map *nmap, const struct tile *ptile, enum extra_flag_id flag)
Definition extras.c:819
void extras_free(void)
Definition extras.c:80
bool can_extra_appear(const struct extra_type *pextra, const struct tile *ptile)
Definition extras.c:1076
bool is_extra_near_tile(const struct civ_map *nmap, const struct tile *ptile, const struct extra_type *pextra)
Definition extras.c:353
int extra_number(const struct extra_type *pextra)
Definition extras.c:153
bool extra_has_flag(const struct extra_type *pextra, enum extra_flag_id flag)
Definition extras.c:810
bool is_native_tile_to_extra(const struct extra_type *pextra, const struct tile *ptile)
Definition extras.c:608
struct extra_type_list * extra_type_list_by_cause(enum extra_cause cause)
Definition extras.c:241
struct extra_type_list * extra_type_list_by_rmcause(enum extra_rmcause rmcause)
Definition extras.c:306
struct extra_type * prev_extra_in_tile(const struct tile *ptile, enum extra_rmcause rmcause, const struct player *pplayer, const struct unit *punit)
Definition extras.c:765
bool hut_on_tile(const struct tile *ptile)
Definition extras.c:672
bool is_extra_card_near(const struct civ_map *nmap, const struct tile *ptile, const struct extra_type *pextra)
Definition extras.c:337
void extra_to_caused_by_list(struct extra_type *pextra, enum extra_cause cause)
Definition extras.c:296
bool player_can_build_extra(const struct extra_type *pextra, const struct player *pplayer, const struct tile *ptile)
Definition extras.c:442
struct extra_type * extra_by_number(int id)
Definition extras.c:175
enum extra_cause activity_to_extra_cause(enum unit_activity act)
Definition extras.c:1028
bool extra_can_be_built(const struct extra_type *pextra, const struct tile *ptile)
Definition extras.c:368
bool is_native_extra_to_utype(const struct extra_type *pextra, const struct unit_type *punittype)
Definition extras.c:801
bool extra_conflicting_on_tile(const struct extra_type *pextra, const struct tile *ptile)
Definition extras.c:655
void extra_to_removed_by_list(struct extra_type *pextra, enum extra_rmcause rmcause)
Definition extras.c:316
bool can_extras_coexist(const struct extra_type *pextra1, const struct extra_type *pextra2)
Definition extras.c:952
void extra_flags_free(void)
Definition extras.c:870
bool can_remove_extra(const struct extra_type *pextra, const struct unit *punit, const struct tile *ptile)
Definition extras.c:586
struct extra_type_list * extra_type_list_of_terr_claimers(void)
Definition extras.c:259
bool is_extra_caused_by_action(const struct extra_type *pextra, const struct action *paction)
Definition extras.c:1006
const char * extra_rule_name(const struct extra_type *pextra)
Definition extras.c:195
bool is_extra_removed_by(const struct extra_type *pextra, enum extra_rmcause rmcause)
Definition extras.c:327
bool is_extra_removed_by_action(const struct extra_type *pextra, const struct action *paction)
Definition extras.c:1017
enum extra_rmcause activity_to_extra_rmcause(enum unit_activity act)
Definition extras.c:1049
bool player_can_remove_extra(const struct extra_type *pextra, const struct player *pplayer, const struct tile *ptile)
Definition extras.c:564
struct extra_type_list * extra_type_list_of_unit_hiders(void)
Definition extras.c:251
void extras_init(void)
Definition extras.c:43
int extra_count(void)
Definition extras.c:145
bool player_knows_extra_exist(const struct player *pplayer, const struct extra_type *pextra, const struct tile *ptile)
Definition extras.c:1103
bool can_build_extra(const struct extra_type *pextra, const struct unit *punit, const struct tile *ptile)
Definition extras.c:507
bool is_native_extra_to_uclass(const struct extra_type *pextra, const struct unit_class *pclass)
Definition extras.c:792
const char * extra_name_translation(const struct extra_type *pextra)
Definition extras.c:186
bool can_extra_disappear(const struct extra_type *pextra, const struct tile *ptile)
Definition extras.c:1090
environment_upset_type
Definition fc_types.h:1129
int Tech_type_id
Definition fc_types.h:347
#define MAX_LEN_NAME
Definition fc_types.h:66
const char * name
Definition inputfile.c:127
bv_unit_classes native_to
Definition extras.h:126
char rmact_gfx[MAX_LEN_NAME]
Definition extras.h:99
bv_extras conflicts
Definition extras.h:129
uint8_t rmcauses
Definition extras.h:92
char act_gfx_alt[MAX_LEN_NAME]
Definition extras.h:97
struct requirement_vector appearance_reqs
Definition extras.h:104
struct strvec * helptext
Definition extras.h:143
bv_extra_flags flags
Definition extras.h:128
struct extra_type_list * hiders
Definition extras.h:138
char rmact_gfx_alt[MAX_LEN_NAME]
Definition extras.h:100
uint16_t causes
Definition extras.h:91
struct road_type * road
Definition extras.h:149
bv_extras bridged_over
Definition extras.h:131
struct resource_type * resource
Definition extras.h:150
int removal_time
Definition extras.h:116
struct extra_type_list * bridged
Definition extras.h:141
int build_time_factor
Definition extras.h:115
bool ruledit_disabled
Definition extras.h:88
struct requirement_vector disappearance_reqs
Definition extras.h:105
bool generated
Definition extras.h:113
int special_idx
Definition extras.h:147
struct requirement_vector rmreqs
Definition extras.h:103
struct extra_type::@24 data
Tech_type_id visibility_req
Definition extras.h:133
enum extra_category category
Definition extras.h:90
int id
Definition extras.h:86
char graphic_alt[MAX_LEN_NAME]
Definition extras.h:95
char activity_gfx[MAX_LEN_NAME]
Definition extras.h:96
void * ruledit_dlg
Definition extras.h:89
int disappearance_chance
Definition extras.h:122
int removal_time_factor
Definition extras.h:117
char act_gfx_alt2[MAX_LEN_NAME]
Definition extras.h:98
struct requirement_vector reqs
Definition extras.h:102
bool buildable
Definition extras.h:112
enum extra_unit_seen_type eus
Definition extras.h:124
int defense_bonus
Definition extras.h:120
int appearance_chance
Definition extras.h:121
char graphic_str[MAX_LEN_NAME]
Definition extras.h:94
int build_time
Definition extras.h:114
int infracost
Definition extras.h:118
bv_extras hidden_by
Definition extras.h:130
struct name_translation name
Definition extras.h:87
struct base_type * base
Definition extras.h:148
Definition tile.h:49
Definition unit.h:138