Freeciv-3.3
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 "fc_types.h"
22#include "unittype.h"
23
24struct base_type;
25struct road_type;
26
27/* Used in the network protocol. */
28#define SPECENUM_NAME extra_flag_id
29/* Tile with this extra is considered native for units in tile. */
30#define SPECENUM_VALUE0 EF_NATIVE_TILE
31#define SPECENUM_VALUE0NAME N_("?extraflag:NativeTile")
32/* Refuel native units */
33#define SPECENUM_VALUE1 EF_REFUEL
34#define SPECENUM_VALUE1NAME N_("?extraflag:Refuel")
35#define SPECENUM_VALUE2 EF_TERR_CHANGE_REMOVES
36#define SPECENUM_VALUE2NAME N_("?extraflag:TerrChangeRemoves")
37/* Extra will be built in cities automatically */
38#define SPECENUM_VALUE3 EF_AUTO_ON_CITY_CENTER
39#define SPECENUM_VALUE3NAME N_("?extraflag:AutoOnCityCenter")
40/* Extra is always present in cities */
41#define SPECENUM_VALUE4 EF_ALWAYS_ON_CITY_CENTER
42#define SPECENUM_VALUE4NAME N_("?extraflag:AlwaysOnCityCenter")
43/* Road style gfx from ocean extra connects to nearby land */
44#define SPECENUM_VALUE5 EF_CONNECT_LAND
45#define SPECENUM_VALUE5NAME N_("?extraflag:ConnectLand")
46/* Counts towards Global Warming */
47#define SPECENUM_VALUE6 EF_GLOBAL_WARMING
48#define SPECENUM_VALUE6NAME N_("?extraflag:GlobalWarming")
49/* Counts towards Nuclear Winter */
50#define SPECENUM_VALUE7 EF_NUCLEAR_WINTER
51#define SPECENUM_VALUE7NAME N_("?extraflag:NuclearWinter")
52/* Owner's flag will be shown on the tile */
53#define SPECENUM_VALUE8 EF_SHOW_FLAG
54#define SPECENUM_VALUE8NAME N_("?extraflag:ShowFlag")
55/* Extra's defense bonus will be counted to
56 * separate "Natural" defense layer. */
57#define SPECENUM_VALUE9 EF_NATURAL_DEFENSE
58#define SPECENUM_VALUE9NAME N_("?extraflag:NaturalDefense")
59/* Units inside will not die all at once */
60#define SPECENUM_VALUE10 EF_NO_STACK_DEATH
61#define SPECENUM_VALUE10NAME N_("NoStackDeath")
62/* Extra itself makes tile to be considered extra owners ZoC */
63#define SPECENUM_VALUE11 EF_CAUSE_ZOC
64#define SPECENUM_VALUE11NAME N_("CauseZoC")
65
66#define SPECENUM_VALUE12 EF_USER_FLAG_1
67#define SPECENUM_VALUE13 EF_USER_FLAG_2
68#define SPECENUM_VALUE14 EF_USER_FLAG_3
69#define SPECENUM_VALUE15 EF_USER_FLAG_4
70#define SPECENUM_VALUE16 EF_USER_FLAG_5
71#define SPECENUM_VALUE17 EF_USER_FLAG_6
72#define SPECENUM_VALUE18 EF_USER_FLAG_7
73#define SPECENUM_VALUE19 EF_USER_FLAG_8
74#define SPECENUM_VALUE20 EF_USER_FLAG_9
75#define SPECENUM_VALUE21 EF_USER_FLAG_10
76
77#define SPECENUM_COUNT EF_COUNT
78#define SPECENUM_NAMEOVERRIDE
79#define SPECENUM_BITVECTOR bv_extra_flags
80#include "specenum_gen.h"
81
82#define EF_LAST_USER_FLAG EF_USER_FLAG_10
83#define MAX_NUM_USER_EXTRA_FLAGS (EF_LAST_USER_FLAG - EF_USER_FLAG_1 + 1)
84
85#define EXTRA_NONE (-1)
86
88{
89 int id;
96
105
110
111 /* 'buildable' is unclean. Clean solution would be to rely solely on extra_cause:
112 * if the extra cannot be built, it's not in the cause's list.
113 * But we currently rely on actually-not-buildable extras to be on the lists,
114 * for example for the editor to list non-buildable but editor-placeable
115 * extras. */
123
127
129
131
135 bv_extras bridged_over; /* Needs "bridge" to get built over these extras */
136
138
140
141 /* Same information as in hidden_by, but iterating through this list is much
142 * faster than through all extra types to check which ones are hiding this one.
143 * Only used client side. */
145
146 /* Same information as bridged_over */
148
150
151 struct
152 {
158};
159
160/* get 'struct extra_type_list' and related functions: */
161#define SPECLIST_TAG extra_type
162#define SPECLIST_TYPE struct extra_type
163#include "speclist.h"
164
165#define extra_type_list_iterate(extralist, pextra) \
166 TYPED_LIST_ITERATE(struct extra_type, extralist, pextra)
167#define extra_type_list_iterate_end LIST_ITERATE_END
168
169#define extra_type_list_iterate_rev(extralist, pextra) \
170 TYPED_LIST_ITERATE_REV(struct extra_type, extralist, pextra)
171#define extra_type_list_iterate_rev_end LIST_ITERATE_REV_END
172
173void extras_init(void);
174void extras_free(void);
175
176int extra_count(void);
177int extra_number(const struct extra_type *pextra);
178struct extra_type *extra_by_number(int id);
179
180/* For optimization purposes (being able to have it as macro instead of function
181 * call) this is now same as extra_number(). extras.c does have semantically correct
182 * implementation too. */
183#define extra_index(_e_) (_e_)->id
184
185const char *extra_name_translation(const struct extra_type *pextra);
186const char *extra_rule_name(const struct extra_type *pextra);
187struct extra_type *extra_type_by_rule_name(const char *name);
189
190#define extra_base_get(_e_) (_e_)->data.base
191#define extra_road_get(_e_) (_e_)->data.road
192#define extra_resource_get(_e_) (_e_)->data.resource
193
194void extra_to_caused_by_list(struct extra_type *pextra, enum extra_cause cause);
196struct extra_type *rand_extra_for_tile(struct tile *ptile, enum extra_cause cause,
197 bool generated);
198
202
203#define is_extra_caused_by(e, c) (e->causes & (1 << c))
204bool is_extra_caused_by_worker_action(const struct extra_type *pextra);
205bool is_extra_caused_by_action(const struct extra_type *pextra,
206 const struct action *paction);
207
209
210/************************************************************************/
214static inline void extra_to_removed_by_list(struct extra_type *pextra,
216{
218
220}
221
224
225bool is_extra_removed_by(const struct extra_type *pextra, enum extra_rmcause rmcause);
226bool is_extra_removed_by_worker_action(const struct extra_type *pextra);
227bool is_extra_removed_by_action(const struct extra_type *pextra,
228 const struct action *paction);
229
230bool is_extra_card_near(const struct civ_map *nmap, const struct tile *ptile,
231 const struct extra_type *pextra);
232bool is_extra_near_tile(const struct civ_map *nmap, const struct tile *ptile,
233 const struct extra_type *pextra);
234
235bool extra_can_be_built(const struct extra_type *pextra, const struct tile *ptile);
236bool can_build_extra(const struct extra_type *pextra,
237 const struct unit *punit,
238 const struct tile *ptile);
239bool can_build_extra_base(const struct extra_type *pextra,
240 const struct player *pplayer,
241 const struct tile *ptile);
242bool player_can_build_extra(const struct extra_type *pextra,
243 const struct player *pplayer,
244 const struct tile *ptile);
245bool player_can_place_extra(const struct extra_type *pextra,
246 const struct player *pplayer,
247 const struct tile *ptile);
248
249bool can_remove_extra(const struct extra_type *pextra,
250 const struct unit *punit,
251 const struct tile *ptile);
252bool player_can_remove_extra(const struct extra_type *pextra,
253 const struct player *pplayer,
254 const struct tile *ptile);
255
256bool is_native_extra_to_uclass(const struct extra_type *pextra,
257 const struct unit_class *pclass);
258bool is_native_extra_to_utype(const struct extra_type *pextra,
259 const struct unit_type *punittype);
260bool is_native_tile_to_extra(const struct extra_type *pextra,
261 const struct tile *ptile);
262bool extra_conflicting_on_tile(const struct extra_type *pextra,
263 const struct tile *ptile);
264
265bool hut_on_tile(const struct tile *ptile);
266bool unit_can_enter_hut(const struct unit *punit,
267 const struct tile *ptile);
268bool unit_can_displace_hut(const struct unit *punit,
269 const struct tile *ptile);
270
271bool extra_has_flag(const struct extra_type *pextra, enum extra_flag_id flag);
272bool is_extra_flag_card_near(const struct civ_map *nmap,
273 const struct tile *ptile,
274 enum extra_flag_id flag);
275bool is_extra_flag_near_tile(const struct civ_map *nmap,
276 const struct tile *ptile,
277 enum extra_flag_id flag);
278
279void user_extra_flags_init(void);
280void extra_flags_free(void);
282 const char *name,
283 const char *helptxt);
284const char *extra_flag_helptxt(enum extra_flag_id id);
286
287bool extra_causes_env_upset(struct extra_type *pextra,
289
290bool can_extras_coexist(const struct extra_type *pextra1,
291 const struct extra_type *pextra2);
292
293bool can_extra_appear(const struct extra_type *pextra, const struct tile *ptile);
294bool can_extra_disappear(const struct extra_type *pextra, const struct tile *ptile);
295
296struct extra_type *next_extra_for_tile(const struct tile *ptile, enum extra_cause cause,
297 const struct player *pplayer,
298 const struct unit *punit);
299struct extra_type *prev_extra_in_tile(const struct tile *ptile, enum extra_rmcause rmcause,
300 const struct player *pplayer,
301 const struct unit *punit);
302struct extra_type *prev_cleanable_in_tile(const struct tile *ptile,
303 const struct player *pplayer,
304 const struct unit *punit);
305
308
309struct player *extra_owner(const struct tile *ptile);
310
311bool player_knows_extra_exist(const struct player *pplayer,
312 const struct extra_type *pextra,
313 const struct tile *ptile);
314
315#define extra_type_iterate(_p) \
316{ \
317 int _i_##_p; \
318 for (_i_##_p = 0; _i_##_p < game.control.num_extra_types; _i_##_p++) { \
319 struct extra_type *_p = extra_by_number(_i_##_p);
320
321#define extra_type_iterate_end \
322 } \
323}
324
325#define extra_type_re_active_iterate(_p) \
326 extra_type_iterate(_p) { \
327 if (!_p->ruledit_disabled) {
328
329#define extra_type_re_active_iterate_end \
330 } \
331 } extra_type_iterate_end;
332
333#define extra_type_by_cause_iterate(_cause, _extra) \
334{ \
335 struct extra_type_list *_etl_##_extra = extra_type_list_by_cause(_cause); \
336 if (_etl_##_extra != NULL) { \
337 extra_type_list_iterate(_etl_##_extra, _extra) {
338
339#define extra_type_by_cause_iterate_end \
340 } extra_type_list_iterate_end \
341 } \
342}
343
344#define extra_type_by_cause_iterate_rev(_cause, _extra) \
345{ \
346 struct extra_type_list *_etl_ = extra_type_list_by_cause(_cause); \
347 extra_type_list_iterate_rev(_etl_, _extra) {
348
349#define extra_type_by_cause_iterate_rev_end \
350 } extra_type_list_iterate_rev_end \
351}
352
353#define extra_type_by_rmcause_iterate(_rmcause, _extra) \
354{ \
355 struct extra_type_list *_etl_ = extra_type_list_by_rmcause(_rmcause); \
356 extra_type_list_iterate_rev(_etl_, _extra) {
357
358#define extra_type_by_rmcause_iterate_end \
359 } extra_type_list_iterate_rev_end \
360}
361
362#define extra_type_cleanable_iterate(_extra) \
363{ \
364 struct extra_type_list *_etl_ = extra_type_list_cleanable(); \
365 extra_type_list_iterate_rev(_etl_, _extra) {
366
367#define extra_type_cleanable_iterate_end \
368 } extra_type_list_iterate_rev_end \
369}
370
371#define extra_deps_iterate(_reqs, _dep) \
372{ \
373 requirement_vector_iterate(_reqs, preq) { \
374 if (preq->source.kind == VUT_EXTRA \
375 && preq->present) { \
376 struct extra_type *_dep; \
377 _dep = preq->source.value.extra;
378
379#define extra_deps_iterate_end \
380 } \
381 } requirement_vector_iterate_end; \
382}
383
384#ifdef __cplusplus
385}
386#endif /* __cplusplus */
387
388#endif /* FC__EXTRAS_H */
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
bool is_extra_removed_by_worker_action(const struct extra_type *pextra)
Definition extras.c:1059
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:779
struct extra_type * extra_type_by_rule_name(const char *name)
Definition extras.c:212
struct extra_type * prev_cleanable_in_tile(const struct tile *ptile, const struct player *pplayer, const struct unit *punit)
Definition extras.c:831
bool extra_causes_env_upset(struct extra_type *pextra, enum environment_upset_type upset)
Definition extras.c:1030
bool can_build_extra_base(const struct extra_type *pextra, const struct player *pplayer, const struct tile *ptile)
Definition extras.c:413
bool unit_can_displace_hut(const struct unit *punit, const struct tile *ptile)
Definition extras.c:749
struct extra_type * rand_extra_for_tile(struct tile *ptile, enum extra_cause cause, bool generated)
Definition extras.c:283
bool player_can_place_extra(const struct extra_type *pextra, const struct player *pplayer, const struct tile *ptile)
Definition extras.c:490
void user_extra_flags_init(void)
Definition extras.c:923
struct player * extra_owner(const struct tile *ptile)
Definition extras.c:1128
bool extra_flag_is_in_use(enum extra_flag_id id)
Definition extras.c:1001
const char * extra_flag_helptxt(enum extra_flag_id id)
Definition extras.c:988
struct extra_type * extra_type_by_translated_name(const char *name)
Definition extras.c:235
void set_user_extra_flag_name(enum extra_flag_id id, const char *name, const char *helptxt)
Definition extras.c:947
bool is_extra_flag_near_tile(const struct civ_map *nmap, const struct tile *ptile, enum extra_flag_id flag)
Definition extras.c:904
static void extra_to_removed_by_list(struct extra_type *pextra, enum extra_rmcause rmcause)
Definition extras.h:214
bool unit_can_enter_hut(const struct unit *punit, const struct tile *ptile)
Definition extras.c:720
bool is_extra_caused_by_worker_action(const struct extra_type *pextra)
Definition extras.c:1046
bool is_extra_flag_card_near(const struct civ_map *nmap, const struct tile *ptile, enum extra_flag_id flag)
Definition extras.c:884
void extras_free(void)
Definition extras.c:84
bool can_extra_appear(const struct extra_type *pextra, const struct tile *ptile)
Definition extras.c:1136
struct extra_type_list * extra_type_list_of_zoccers(void)
Definition extras.c:267
bool is_extra_near_tile(const struct civ_map *nmap, const struct tile *ptile, const struct extra_type *pextra)
Definition extras.c:379
int extra_number(const struct extra_type *pextra)
Definition extras.c:161
bool extra_has_flag(const struct extra_type *pextra, enum extra_flag_id flag)
Definition extras.c:875
bool is_native_tile_to_extra(const struct extra_type *pextra, const struct tile *ptile)
Definition extras.c:641
struct extra_type_list * extra_type_list_by_cause(enum extra_cause cause)
Definition extras.c:249
struct extra_type_list * extra_type_list_by_rmcause(enum extra_rmcause rmcause)
Definition extras.c:322
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:804
bool hut_on_tile(const struct tile *ptile)
Definition extras.c:705
bool is_extra_card_near(const struct civ_map *nmap, const struct tile *ptile, const struct extra_type *pextra)
Definition extras.c:363
void extra_to_caused_by_list(struct extra_type *pextra, enum extra_cause cause)
Definition extras.c:312
bool player_can_build_extra(const struct extra_type *pextra, const struct player *pplayer, const struct tile *ptile)
Definition extras.c:468
struct extra_type * extra_by_number(int id)
Definition extras.c:183
enum extra_cause activity_to_extra_cause(enum unit_activity act)
Definition extras.c:1090
bool extra_can_be_built(const struct extra_type *pextra, const struct tile *ptile)
Definition extras.c:394
bool is_native_extra_to_utype(const struct extra_type *pextra, const struct unit_type *punittype)
Definition extras.c:866
bool extra_conflicting_on_tile(const struct extra_type *pextra, const struct tile *ptile)
Definition extras.c:688
bool can_extras_coexist(const struct extra_type *pextra1, const struct extra_type *pextra2)
Definition extras.c:1017
void extra_flags_free(void)
Definition extras.c:935
bool can_remove_extra(const struct extra_type *pextra, const struct unit *punit, const struct tile *ptile)
Definition extras.c:618
struct extra_type_list * extra_type_list_of_terr_claimers(void)
Definition extras.c:275
bool is_extra_caused_by_action(const struct extra_type *pextra, const struct action *paction)
Definition extras.c:1070
const char * extra_rule_name(const struct extra_type *pextra)
Definition extras.c:203
struct extra_type_list * extra_type_list_cleanable(void)
Definition extras.c:332
bool is_extra_removed_by(const struct extra_type *pextra, enum extra_rmcause rmcause)
Definition extras.c:353
void _extra_to_removed_by_list(struct extra_type *pextra, enum extra_rmcause rmcause)
Definition extras.c:340
bool is_extra_removed_by_action(const struct extra_type *pextra, const struct action *paction)
Definition extras.c:1080
enum extra_rmcause activity_to_extra_rmcause(enum unit_activity act)
Definition extras.c:1111
bool player_can_remove_extra(const struct extra_type *pextra, const struct player *pplayer, const struct tile *ptile)
Definition extras.c:595
struct extra_type_list * extra_type_list_of_unit_hiders(void)
Definition extras.c:259
void extras_init(void)
Definition extras.c:45
int extra_count(void)
Definition extras.c:153
bool player_knows_extra_exist(const struct player *pplayer, const struct extra_type *pextra, const struct tile *ptile)
Definition extras.c:1167
bool can_build_extra(const struct extra_type *pextra, const struct unit *punit, const struct tile *ptile)
Definition extras.c:535
bool is_native_extra_to_uclass(const struct extra_type *pextra, const struct unit_class *pclass)
Definition extras.c:857
const char * extra_name_translation(const struct extra_type *pextra)
Definition extras.c:194
bool can_extra_disappear(const struct extra_type *pextra, const struct tile *ptile)
Definition extras.c:1152
environment_upset_type
Definition fc_types.h:986
int Tech_type_id
Definition fc_types.h:236
#define MAX_LEN_NAME
Definition fc_types.h:66
const char * name
Definition inputfile.c:127
bv_unit_classes native_to
Definition extras.h:130
char rmact_gfx[MAX_LEN_NAME]
Definition extras.h:102
bv_extras conflicts
Definition extras.h:133
uint8_t rmcauses
Definition extras.h:95
char act_gfx_alt[MAX_LEN_NAME]
Definition extras.h:100
struct requirement_vector appearance_reqs
Definition extras.h:108
struct strvec * helptext
Definition extras.h:149
bv_extra_flags flags
Definition extras.h:132
struct extra_type_list * hiders
Definition extras.h:144
char rmact_gfx_alt[MAX_LEN_NAME]
Definition extras.h:103
uint16_t causes
Definition extras.h:94
struct road_type * road
Definition extras.h:155
bv_extras bridged_over
Definition extras.h:135
struct resource_type * resource
Definition extras.h:156
int removal_time
Definition extras.h:120
char rmact_gfx_alt2[MAX_LEN_NAME]
Definition extras.h:104
struct extra_type_list * bridged
Definition extras.h:147
int build_time_factor
Definition extras.h:119
bool ruledit_disabled
Definition extras.h:91
struct requirement_vector disappearance_reqs
Definition extras.h:109
bool generated
Definition extras.h:117
int special_idx
Definition extras.h:153
struct extra_type::@26 data
struct requirement_vector rmreqs
Definition extras.h:107
Tech_type_id visibility_req
Definition extras.h:139
enum extra_category category
Definition extras.h:93
int id
Definition extras.h:89
char graphic_alt[MAX_LEN_NAME]
Definition extras.h:98
char activity_gfx[MAX_LEN_NAME]
Definition extras.h:99
void * ruledit_dlg
Definition extras.h:92
int disappearance_chance
Definition extras.h:126
int removal_time_factor
Definition extras.h:121
char act_gfx_alt2[MAX_LEN_NAME]
Definition extras.h:101
struct requirement_vector reqs
Definition extras.h:106
bool buildable
Definition extras.h:116
enum extra_unit_seen_type eus
Definition extras.h:128
int defense_bonus
Definition extras.h:124
int appearance_chance
Definition extras.h:125
char graphic_str[MAX_LEN_NAME]
Definition extras.h:97
int build_time
Definition extras.h:118
int infracost
Definition extras.h:122
int no_aggr_near_city
Definition extras.h:137
bv_extras hidden_by
Definition extras.h:134
struct name_translation name
Definition extras.h:90
struct base_type * base
Definition extras.h:154
Definition tile.h:50
Definition unit.h:140
#define fc__unreachable(_cond_)
Definition support.h:134