Freeciv21
Develop your civilization from humble roots to a global empire
extras.h
Go to the documentation of this file.
1 /*__ ___ ***************************************
2 / \ / \ Copyright (c) 1996-2020 Freeciv21 and Freeciv
3 \_ \ / __/ contributors. This file is part of Freeciv21.
4  _\ \ / /__ Freeciv21 is free software: you can redistribute it
5  \___ \____/ __/ and/or modify it under the terms of the GNU General
6  \_ _/ Public License as published by the Free Software
7  | @ @ \_ Foundation, either version 3 of the License,
8  | or (at your option) any later version.
9  _/ /\ You should have received a copy of the GNU
10  /o) (o/\ \_ General Public License along with Freeciv21.
11  \_____/ / If not, see https://www.gnu.org/licenses/.
12  \____/ ********************************************************/
13 #pragma once
14 
15 // common
16 #include "fc_types.h"
17 #include "terrain.h"
18 
19 // Used in the network protocol.
20 #define SPECENUM_NAME extra_flag_id
21 // Tile with this extra is considered native for units in tile.
22 #define SPECENUM_VALUE0 EF_NATIVE_TILE
23 #define SPECENUM_VALUE0NAME N_("?extraflag:NativeTile")
24 // Refuel native units
25 #define SPECENUM_VALUE1 EF_REFUEL
26 #define SPECENUM_VALUE1NAME N_("?extraflag:Refuel")
27 #define SPECENUM_VALUE2 EF_TERR_CHANGE_REMOVES
28 #define SPECENUM_VALUE2NAME N_("?extraflag:TerrChangeRemoves")
29 // Extra will be built in cities automatically
30 #define SPECENUM_VALUE3 EF_AUTO_ON_CITY_CENTER
31 #define SPECENUM_VALUE3NAME N_("?extraflag:AutoOnCityCenter")
32 // Extra is always present in cities
33 #define SPECENUM_VALUE4 EF_ALWAYS_ON_CITY_CENTER
34 #define SPECENUM_VALUE4NAME N_("?extraflag:AlwaysOnCityCenter")
35 // Road style gfx from ocean extra connects to nearby land
36 #define SPECENUM_VALUE5 EF_CONNECT_LAND
37 #define SPECENUM_VALUE5NAME N_("?extraflag:ConnectLand")
38 // Counts towards Global Warming
39 #define SPECENUM_VALUE6 EF_GLOBAL_WARMING
40 #define SPECENUM_VALUE6NAME N_("?extraflag:GlobalWarming")
41 // Counts towards Nuclear Winter
42 #define SPECENUM_VALUE7 EF_NUCLEAR_WINTER
43 #define SPECENUM_VALUE7NAME N_("?extraflag:NuclearWinter")
44 // Owner's flag will be shown on the tile
45 #define SPECENUM_VALUE8 EF_SHOW_FLAG
46 #define SPECENUM_VALUE8NAME N_("?extraflag:ShowFlag")
47 /* Extra's defense bonus will be counted to
48  * separate "Natural" defense layer. */
49 #define SPECENUM_VALUE9 EF_NATURAL_DEFENSE
50 #define SPECENUM_VALUE9NAME N_("?extraflag:NaturalDefense")
51 // Units inside will not die all at once
52 #define SPECENUM_VALUE10 EF_NO_STACK_DEATH
53 #define SPECENUM_VALUE10NAME N_("NoStackDeath")
54 
55 #define SPECENUM_VALUE11 EF_USER_FLAG_1
56 #define SPECENUM_VALUE12 EF_USER_FLAG_2
57 #define SPECENUM_VALUE13 EF_USER_FLAG_3
58 #define SPECENUM_VALUE14 EF_USER_FLAG_4
59 #define SPECENUM_VALUE15 EF_USER_FLAG_5
60 #define SPECENUM_VALUE16 EF_USER_FLAG_6
61 #define SPECENUM_VALUE17 EF_USER_FLAG_7
62 #define SPECENUM_VALUE18 EF_USER_FLAG_8
63 
64 #define SPECENUM_COUNT EF_COUNT
65 #define SPECENUM_NAMEOVERRIDE
66 #define SPECENUM_BITVECTOR bv_extra_flags
67 #include "specenum_gen.h"
68 
69 #define EF_LAST_USER_FLAG EF_USER_FLAG_8
70 #define MAX_NUM_USER_EXTRA_FLAGS (EF_LAST_USER_FLAG - EF_USER_FLAG_1 + 1)
71 
72 #define EXTRA_NONE (-1)
73 
74 struct extra_type {
75  int id;
76  struct name_translation name;
78  enum extra_category category;
79  uint16_t causes;
80  uint8_t rmcauses;
81 
89 
90  struct requirement_vector reqs;
91  struct requirement_vector rmreqs;
92  struct requirement_vector appearance_reqs;
93  struct requirement_vector disappearance_reqs;
94 
95  /* 'buildable' is unclean. Clean solution would be to rely solely on
96  * extra_cause: if the extra cannot be built, it's not in the cause's list.
97  * But we currently rely on actually-not-buildable extras to be on the
98  * lists, for example for the editor to list non-buildable but
99  * editor-placeable extras. */
100  bool buildable;
101  bool generated;
106 
110 
111  enum extra_unit_seen_type eus;
112 
113  bv_unit_classes native_to;
114 
115  bv_extra_flags flags;
116  bv_extras conflicts;
117  bv_extras hidden_by;
118  bv_extras bridged_over; // Needs "bridge" to get built over these extras
119 
121 
122  /* Same information as in hidden_by, but iterating through this list is
123  * much faster than through all extra types to check which ones are hiding
124  * this one. Only used client side. */
125  struct extra_type_list *hiders;
126 
127  // Same information as bridged_over
128  struct extra_type_list *bridged;
129 
131 
132  struct {
134  struct base_type *base;
135  struct road_type *road;
137  } data;
138 };
139 
140 // get 'struct extra_type_list' and related functions:
141 #define SPECLIST_TAG extra_type
142 #define SPECLIST_TYPE struct extra_type
143 #include "speclist.h"
144 
145 #define extra_type_list_iterate(extralist, pextra) \
146  TYPED_LIST_ITERATE(struct extra_type, extralist, pextra)
147 #define extra_type_list_iterate_end LIST_ITERATE_END
148 
149 #define extra_type_list_iterate_rev(extralist, pextra) \
150  TYPED_LIST_ITERATE_REV(struct extra_type, extralist, pextra)
151 #define extra_type_list_iterate_rev_end LIST_ITERATE_REV_END
152 
153 void extras_init();
154 void extras_free();
155 
156 int extra_count();
157 int extra_number(const struct extra_type *pextra);
158 struct extra_type *extra_by_number(int id);
159 
160 /* For optimization purposes (being able to have it as macro instead of
161  * function call) this is now same as extra_number(). extras.c does have
162  * semantically correct implementation too. */
163 #define extra_index(_e_) (_e_)->id
164 
165 const char *extra_name_translation(const struct extra_type *pextra);
166 const char *extra_rule_name(const struct extra_type *pextra);
167 struct extra_type *extra_type_by_rule_name(const char *name);
168 struct extra_type *extra_type_by_translated_name(const char *name);
169 
170 #define extra_base_get(_e_) (_e_)->data.base
171 #define extra_road_get(_e_) (_e_)->data.road
172 
173 void extra_to_caused_by_list(struct extra_type *pextra,
174  enum extra_cause cause);
175 struct extra_type_list *extra_type_list_by_cause(enum extra_cause cause);
176 struct extra_type *rand_extra_for_tile(struct tile *ptile,
177  enum extra_cause cause,
178  bool generated);
179 
180 struct extra_type_list *extra_type_list_of_unit_hiders();
181 
182 #define is_extra_caused_by(e, c) (e->causes & (1 << c))
183 bool is_extra_caused_by_worker_action(const struct extra_type *pextra);
184 bool is_extra_caused_by_action(const struct extra_type *pextra,
185  const struct action *paction);
186 
187 void extra_to_removed_by_list(struct extra_type *pextra,
188  enum extra_rmcause rmcause);
189 struct extra_type_list *
190 extra_type_list_by_rmcause(enum extra_rmcause rmcause);
191 
192 bool is_extra_removed_by(const struct extra_type *pextra,
193  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  const struct action *paction);
197 
198 bool is_extra_card_near(const struct tile *ptile,
199  const struct extra_type *pextra);
200 bool is_extra_near_tile(const struct tile *ptile,
201  const struct extra_type *pextra);
202 
203 bool extra_can_be_built(const struct extra_type *pextra,
204  const struct tile *ptile);
205 bool can_build_extra(const struct extra_type *pextra,
206  const struct unit *punit, const struct tile *ptile);
207 bool can_build_extra_base(const struct extra_type *pextra,
208  const struct player *pplayer,
209  const struct tile *ptile);
210 bool player_can_build_extra(const struct extra_type *pextra,
211  const struct player *pplayer,
212  const struct tile *ptile);
213 bool player_can_place_extra(const struct extra_type *pextra,
214  const struct player *pplayer,
215  const struct tile *ptile);
216 
217 bool can_remove_extra(const struct extra_type *pextra,
218  const struct unit *punit, const struct tile *ptile);
219 bool player_can_remove_extra(const struct extra_type *pextra,
220  const struct player *pplayer,
221  const struct tile *ptile);
222 
223 bool is_native_extra_to_uclass(const struct extra_type *pextra,
224  const struct unit_class *pclass);
225 bool is_native_extra_to_utype(const struct extra_type *pextra,
226  const struct unit_type *punittype);
227 bool is_native_tile_to_extra(const struct extra_type *pextra,
228  const struct tile *ptile);
229 bool extra_conflicting_on_tile(const struct extra_type *pextra,
230  const struct tile *ptile);
231 
232 bool hut_on_tile(const struct tile *ptile);
233 bool unit_can_enter_hut(const struct unit *punit, const struct tile *ptile);
234 bool unit_can_displace_hut(const struct unit *punit,
235  const struct tile *ptile);
236 
237 bool extra_has_flag(const struct extra_type *pextra,
238  enum extra_flag_id flag);
239 bool is_extra_flag_card_near(const struct tile *ptile,
240  enum extra_flag_id flag);
241 bool is_extra_flag_near_tile(const struct tile *ptile,
242  enum extra_flag_id flag);
243 
244 void user_extra_flags_init();
245 void extra_flags_free();
246 void set_user_extra_flag_name(enum extra_flag_id id, const char *name,
247  const char *helptxt);
248 const char *extra_flag_helptxt(enum extra_flag_id id);
249 
250 bool extra_causes_env_upset(struct extra_type *pextra,
251  enum environment_upset_type upset);
252 
253 bool can_extras_coexist(const struct extra_type *pextra1,
254  const struct extra_type *pextra2);
255 
256 bool can_extra_appear(const struct extra_type *pextra,
257  const struct tile *ptile);
258 bool can_extra_disappear(const struct extra_type *pextra,
259  const struct tile *ptile);
260 
261 struct extra_type *next_extra_for_tile(const struct tile *ptile,
262  enum extra_cause cause,
263  const struct player *pplayer,
264  const struct unit *punit);
265 struct extra_type *prev_extra_in_tile(const struct tile *ptile,
266  enum extra_rmcause rmcause,
267  const struct player *pplayer,
268  const struct unit *punit);
269 
270 enum extra_cause activity_to_extra_cause(enum unit_activity act);
271 enum extra_rmcause activity_to_extra_rmcause(enum unit_activity act);
272 
273 struct player *extra_owner(const struct tile *ptile);
274 
275 bool player_knows_extra_exist(const struct player *pplayer,
276  const struct extra_type *pextra,
277  const struct tile *ptile);
278 
279 #define extra_type_iterate(_p) \
280  { \
281  int _i_##_p; \
282  for (_i_##_p = 0; _i_##_p < game.control.num_extra_types; _i_##_p++) { \
283  struct extra_type *_p = extra_by_number(_i_##_p);
284 
285 #define extra_type_iterate_end \
286  } \
287  }
288 
289 #define extra_type_re_active_iterate(_p) \
290  extra_type_iterate(_p) \
291  { \
292  if (!_p->ruledit_disabled) {
293 
294 #define extra_type_re_active_iterate_end \
295  } \
296  } \
297  extra_type_iterate_end;
298 
299 #define extra_type_by_cause_iterate(_cause, _extra) \
300  { \
301  struct extra_type_list *_etl_##_extra = \
302  extra_type_list_by_cause(_cause); \
303  if (_etl_##_extra != nullptr) { \
304  extra_type_list_iterate(_etl_##_extra, _extra) \
305  {
306 
307 #define extra_type_by_cause_iterate_end \
308  } \
309  extra_type_list_iterate_end \
310  } \
311  }
312 
313 #define extra_type_by_cause_iterate_rev(_cause, _extra) \
314  { \
315  struct extra_type_list *_etl_ = extra_type_list_by_cause(_cause); \
316  extra_type_list_iterate_rev(_etl_, _extra) \
317  {
318 
319 #define extra_type_by_cause_iterate_rev_end \
320  } \
321  extra_type_list_iterate_rev_end \
322  }
323 
324 #define extra_type_by_rmcause_iterate(_rmcause, _extra) \
325  { \
326  struct extra_type_list *_etl_ = extra_type_list_by_rmcause(_rmcause); \
327  extra_type_list_iterate_rev(_etl_, _extra) \
328  {
329 
330 #define extra_type_by_rmcause_iterate_end \
331  } \
332  extra_type_list_iterate_rev_end \
333  }
334 
335 #define extra_deps_iterate(_reqs, _dep) \
336  { \
337  requirement_vector_iterate(_reqs, preq) \
338  { \
339  if (preq->source.kind == VUT_EXTRA && preq->present) { \
340  struct extra_type *_dep; \
341  _dep = preq->source.value.extra;
342 
343 #define extra_deps_iterate_end \
344  } \
345  } \
346  requirement_vector_iterate_end; \
347  }
bool is_extra_removed_by_worker_action(const struct extra_type *pextra)
Is the extra removed by some kind of worker action?
Definition: extras.cpp:942
struct extra_type_list * extra_type_list_of_unit_hiders()
Returns extra types that hide units.
Definition: extras.cpp:234
bool extra_causes_env_upset(struct extra_type *pextra, enum environment_upset_type upset)
Does the extra count toward environment upset?
Definition: extras.cpp:915
bool can_build_extra_base(const struct extra_type *pextra, const struct player *pplayer, const struct tile *ptile)
Tells if player can build extra to tile with suitable unit.
Definition: extras.cpp:371
bool unit_can_displace_hut(const struct unit *punit, const struct tile *ptile)
Returns TRUE iff the unit can enter or frighten any hut on the tile.
Definition: extras.cpp:665
bool player_can_place_extra(const struct extra_type *pextra, const struct player *pplayer, const struct tile *ptile)
Tells if player can place extra on tile.
Definition: extras.cpp:430
struct extra_type * rand_extra_for_tile(struct tile *ptile, enum extra_cause cause, bool generated)
Return random extra type for given cause that is native to the tile.
Definition: extras.cpp:242
struct extra_type * extra_type_by_rule_name(const char *name)
Returns extra type matching rule name or nullptr if there is no extra type with such name.
Definition: extras.cpp:183
void set_user_extra_flag_name(enum extra_flag_id id, const char *name, const char *helptxt)
Sets user defined name for extra flag.
Definition: extras.cpp:859
struct extra_type * extra_by_number(int id)
Return extras type of given id.
Definition: extras.cpp:154
bool unit_can_enter_hut(const struct unit *punit, const struct tile *ptile)
Returns TRUE iff the unit can enter any hut on the tile.
Definition: extras.cpp:643
bool is_extra_caused_by_worker_action(const struct extra_type *pextra)
Is the extra caused by some kind of worker action?
Definition: extras.cpp:931
bool can_extra_appear(const struct extra_type *pextra, const struct tile *ptile)
Are all the requirements for extra to appear on tile fulfilled.
Definition: extras.cpp:1021
struct player * extra_owner(const struct tile *ptile)
Who owns extras on tile.
Definition: extras.cpp:1013
int extra_number(const struct extra_type *pextra)
Return the extra id.
Definition: extras.cpp:132
bool is_extra_flag_card_near(const struct tile *ptile, enum extra_flag_id flag)
Returns TRUE iff any cardinally adjacent tile contains an extra with the given flag (does not check p...
Definition: extras.cpp:788
bool extra_has_flag(const struct extra_type *pextra, enum extra_flag_id flag)
Check if extra has given flag.
Definition: extras.cpp:779
bool is_native_tile_to_extra(const struct extra_type *pextra, const struct tile *ptile)
Is tile native to extra?
Definition: extras.cpp:559
void extra_flags_free()
Frees the memory associated with all extra flags.
Definition: extras.cpp:847
bool hut_on_tile(const struct tile *ptile)
Returns TRUE iff an extra on the tile is a hut (removed by entering).
Definition: extras.cpp:626
const char * extra_name_translation(const struct extra_type *pextra)
Return the (translated) name of the extra type.
Definition: extras.cpp:165
void extra_to_caused_by_list(struct extra_type *pextra, enum extra_cause cause)
Add extra type to list of extra caused by given cause.
Definition: extras.cpp:274
bool player_can_build_extra(const struct extra_type *pextra, const struct player *pplayer, const struct tile *ptile)
Tells if player can build extra to tile with suitable unit.
Definition: extras.cpp:414
enum extra_cause activity_to_extra_cause(enum unit_activity act)
What extra cause activity is considered to be?
Definition: extras.cpp:973
bool extra_can_be_built(const struct extra_type *pextra, const struct tile *ptile)
Tells if extra can build to tile if all other requirements are met.
Definition: extras.cpp:352
bool is_native_extra_to_utype(const struct extra_type *pextra, const struct unit_type *punittype)
Is extra native to unit type?
Definition: extras.cpp:770
bool extra_conflicting_on_tile(const struct extra_type *pextra, const struct tile *ptile)
Returns TRUE iff an extra that conflicts with pextra exists at ptile.
Definition: extras.cpp:607
void extras_init()
Initialize extras structures.
Definition: extras.cpp:36
void extra_to_removed_by_list(struct extra_type *pextra, enum extra_rmcause rmcause)
Add extra type to list of extra removed by given cause.
Definition: extras.cpp:296
struct extra_type * extra_type_by_translated_name(const char *name)
Returns extra type matching the translated name, or nullptr if there is no extra type with that name.
Definition: extras.cpp:208
struct extra_type * prev_extra_in_tile(const struct tile *ptile, enum extra_rmcause rmcause, const struct player *pplayer, const struct unit *punit)
Returns prev extra by cause that unit or player can remove from tile.
Definition: extras.cpp:732
bool can_extras_coexist(const struct extra_type *pextra1, const struct extra_type *pextra2)
Can two extras coexist in same tile?
Definition: extras.cpp:902
bool is_extra_near_tile(const struct tile *ptile, const struct extra_type *pextra)
Is there extra of the given type near tile? (Does not check ptile itself.)
Definition: extras.cpp:335
struct extra_type_list * extra_type_list_by_cause(enum extra_cause cause)
Returns extra type for given cause.
Definition: extras.cpp:224
bool can_remove_extra(const struct extra_type *pextra, const struct unit *punit, const struct tile *ptile)
Tells if unit can remove extra from tile.
Definition: extras.cpp:543
struct extra_type_list * extra_type_list_by_rmcause(enum extra_rmcause rmcause)
Returns extra type for given rmcause.
Definition: extras.cpp:286
bool is_extra_flag_near_tile(const struct tile *ptile, enum extra_flag_id flag)
Returns TRUE iff any adjacent tile contains an extra with the given flag (does not check ptile itself...
Definition: extras.cpp:812
bool is_extra_caused_by_action(const struct extra_type *pextra, const struct action *paction)
Is the extra caused by specific worker action?
Definition: extras.cpp:953
const char * extra_flag_helptxt(enum extra_flag_id id)
Return the (untranslated) help text of the user extra flag.
Definition: extras.cpp:892
bool is_extra_removed_by(const struct extra_type *pextra, enum extra_rmcause rmcause)
Is given cause one of the removal causes for the given extra?
Definition: extras.cpp:307
void extras_free()
Free the memory associated with extras.
Definition: extras.cpp:71
bool is_extra_removed_by_action(const struct extra_type *pextra, const struct action *paction)
Is the extra removed by specific worker action?
Definition: extras.cpp:963
int extra_count()
Return the number of extra_types.
Definition: extras.cpp:127
enum extra_rmcause activity_to_extra_rmcause(enum unit_activity act)
What extra rmcause activity is considered to be?
Definition: extras.cpp:994
bool is_extra_card_near(const struct tile *ptile, const struct extra_type *pextra)
Is there extra of the given type cardinally near tile? (Does not check ptile itself....
Definition: extras.cpp:317
bool player_can_remove_extra(const struct extra_type *pextra, const struct player *pplayer, const struct tile *ptile)
Tells if player can remove extra from tile with suitable unit.
Definition: extras.cpp:525
void user_extra_flags_init()
Initialize user extra flags.
Definition: extras.cpp:835
const char * extra_rule_name(const struct extra_type *pextra)
Return the (untranslated) rule name of the extra type.
Definition: extras.cpp:174
bool player_knows_extra_exist(const struct player *pplayer, const struct extra_type *pextra, const struct tile *ptile)
Extra is not hidden from the user.
Definition: extras.cpp:1051
bool can_build_extra(const struct extra_type *pextra, const struct unit *punit, const struct tile *ptile)
Tells if unit can build extra on tile.
Definition: extras.cpp:475
bool is_native_extra_to_uclass(const struct extra_type *pextra, const struct unit_class *pclass)
Is extra native to unit class?
Definition: extras.cpp:761
struct extra_type * next_extra_for_tile(const struct tile *ptile, enum extra_cause cause, const struct player *pplayer, const struct unit *punit)
Returns next extra by cause that unit or player can build to tile.
Definition: extras.cpp:687
bool can_extra_disappear(const struct extra_type *pextra, const struct tile *ptile)
Are all the requirements for extra to disappear from tile fulfilled.
Definition: extras.cpp:1036
environment_upset_type
Definition: fc_types.h:1085
int Tech_type_id
Definition: fc_types.h:294
#define MAX_LEN_NAME
Definition: fc_types.h:61
const char * name
Definition: inputfile.cpp:118
Definition: base.h:43
bv_unit_classes native_to
Definition: extras.h:113
char rmact_gfx[MAX_LEN_NAME]
Definition: extras.h:87
bv_extras conflicts
Definition: extras.h:116
uint8_t rmcauses
Definition: extras.h:80
char act_gfx_alt[MAX_LEN_NAME]
Definition: extras.h:85
struct requirement_vector appearance_reqs
Definition: extras.h:92
bv_extra_flags flags
Definition: extras.h:115
struct extra_type_list * hiders
Definition: extras.h:125
char rmact_gfx_alt[MAX_LEN_NAME]
Definition: extras.h:88
uint16_t causes
Definition: extras.h:79
struct road_type * road
Definition: extras.h:135
bv_extras bridged_over
Definition: extras.h:118
struct resource_type * resource
Definition: extras.h:136
int removal_time
Definition: extras.h:104
struct extra_type_list * bridged
Definition: extras.h:128
int build_time_factor
Definition: extras.h:103
bool ruledit_disabled
Definition: extras.h:77
struct requirement_vector disappearance_reqs
Definition: extras.h:93
bool generated
Definition: extras.h:101
int special_idx
Definition: extras.h:133
struct requirement_vector rmreqs
Definition: extras.h:91
Tech_type_id visibility_req
Definition: extras.h:120
enum extra_category category
Definition: extras.h:78
int id
Definition: extras.h:75
struct extra_type::@22 data
char graphic_alt[MAX_LEN_NAME]
Definition: extras.h:83
char activity_gfx[MAX_LEN_NAME]
Definition: extras.h:84
int disappearance_chance
Definition: extras.h:109
int removal_time_factor
Definition: extras.h:105
char act_gfx_alt2[MAX_LEN_NAME]
Definition: extras.h:86
struct requirement_vector reqs
Definition: extras.h:90
bool buildable
Definition: extras.h:100
enum extra_unit_seen_type eus
Definition: extras.h:111
int defense_bonus
Definition: extras.h:107
int appearance_chance
Definition: extras.h:108
char graphic_str[MAX_LEN_NAME]
Definition: extras.h:82
int build_time
Definition: extras.h:102
bv_extras hidden_by
Definition: extras.h:117
QVector< QString > * helptext
Definition: extras.h:130
struct name_translation name
Definition: extras.h:76
struct base_type * base
Definition: extras.h:134
Definition: player.h:231
Definition: road.h:54
Definition: tile.h:42
Definition: unit.h:134