Stop sharing requirement_unit_state_ereq().
[freeciv.git] / common / unittype.h
blobe1795600e0db61187214f658058e209fabc3adef
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__UNITTYPE_H
14 #define FC__UNITTYPE_H
16 #ifdef __cplusplus
17 extern "C" {
18 #endif /* __cplusplus */
20 /* utility */
21 #include "bitvector.h"
22 #include "shared.h"
24 /* common */
25 #include "fc_types.h"
26 #include "name_translation.h"
28 struct astring; /* Actually defined in "utility/astring.h". */
29 struct strvec; /* Actually defined in "utility/string_vector.h". */
31 struct ai_type;
33 /* U_LAST is a value which is guaranteed to be larger than all
34 * actual Unit_type_id values. It is used as a flag value;
35 * it can also be used for fixed allocations to ensure able
36 * to hold full number of unit types.
37 * Used in the network protocol. */
38 #define U_LAST MAX_NUM_ITEMS
40 /* The largest distance a ruleset can allow a unit to paradrop.
42 * Remember to make sure that the field type of PACKET_RULESET_UNIT's
43 * paratroopers_range field can transfer the new maximum if you increase
44 * it.
46 * The top value is reserved in case a future Freeciv version wants to
47 * implement "no maximum range". It could be used to signal that the unit
48 * can paradrop anywhere. Note that the value below it is high enough to
49 * give the same effect on all maps inside the current size limits.
50 * (No map side can be larger than MAP_MAX_LINEAR_SIZE)
52 #define UNIT_MAX_PARADROP_RANGE (65535 - 1)
54 /* Used in the network protocol. */
55 #define SPECENUM_NAME unit_class_flag_id
56 #define SPECENUM_VALUE0 UCF_TERRAIN_SPEED
57 #define SPECENUM_VALUE0NAME N_("?uclassflag:TerrainSpeed")
58 #define SPECENUM_VALUE1 UCF_TERRAIN_DEFENSE
59 #define SPECENUM_VALUE1NAME N_("?uclassflag:TerrainDefense")
60 #define SPECENUM_VALUE2 UCF_DAMAGE_SLOWS
61 #define SPECENUM_VALUE2NAME N_("?uclassflag:DamageSlows")
62 /* Can occupy enemy cities */
63 #define SPECENUM_VALUE3 UCF_CAN_OCCUPY_CITY
64 #define SPECENUM_VALUE3NAME N_("?uclassflag:CanOccupyCity")
65 #define SPECENUM_VALUE4 UCF_MISSILE
66 #define SPECENUM_VALUE4NAME N_("?uclassflag:Missile")
67 #define SPECENUM_VALUE5 UCF_BUILD_ANYWHERE
68 #define SPECENUM_VALUE5NAME N_("?uclassflag:BuildAnywhere")
69 #define SPECENUM_VALUE6 UCF_UNREACHABLE
70 #define SPECENUM_VALUE6NAME N_("?uclassflag:Unreachable")
71 /* Can collect ransom from barbarian leader */
72 #define SPECENUM_VALUE7 UCF_COLLECT_RANSOM
73 #define SPECENUM_VALUE7NAME N_("?uclassflag:CollectRansom")
74 /* Is subject to ZOC */
75 #define SPECENUM_VALUE8 UCF_ZOC
76 #define SPECENUM_VALUE8NAME N_("?uclassflag:ZOC")
77 /* Can fortify on land squares */
78 #define SPECENUM_VALUE9 UCF_CAN_FORTIFY
79 #define SPECENUM_VALUE9NAME N_("?uclassflag:CanFortify")
80 #define SPECENUM_VALUE10 UCF_CAN_PILLAGE
81 #define SPECENUM_VALUE10NAME N_("?uclassflag:CanPillage")
82 /* Cities can still work tile when enemy unit on it */
83 #define SPECENUM_VALUE11 UCF_DOESNT_OCCUPY_TILE
84 #define SPECENUM_VALUE11NAME N_("?uclassflag:DoesntOccupyTile")
85 /* Can attack against units on non-native tiles */
86 #define SPECENUM_VALUE12 UCF_ATTACK_NON_NATIVE
87 #define SPECENUM_VALUE12NAME N_("?uclassflag:AttackNonNative")
88 /* Kills citizens upon successful attack against a city */
89 #define SPECENUM_VALUE13 UCF_KILLCITIZEN
90 #define SPECENUM_VALUE13NAME N_("?uclassflag:KillCitizen")
92 #define SPECENUM_VALUE14 UCF_USER_FLAG_1
93 #define SPECENUM_VALUE15 UCF_USER_FLAG_2
94 #define SPECENUM_VALUE16 UCF_USER_FLAG_3
95 #define SPECENUM_VALUE17 UCF_USER_FLAG_4
96 #define SPECENUM_VALUE18 UCF_USER_FLAG_5
97 #define SPECENUM_VALUE19 UCF_USER_FLAG_6
98 #define SPECENUM_VALUE20 UCF_USER_FLAG_7
99 #define SPECENUM_VALUE21 UCF_USER_FLAG_8
101 /* keep this last */
102 #define SPECENUM_COUNT UCF_COUNT
103 #define SPECENUM_NAMEOVERRIDE
104 #define SPECENUM_BITVECTOR bv_unit_class_flags
105 #include "specenum_gen.h"
107 #define UCF_LAST_USER_FLAG UCF_USER_FLAG_8
108 #define MAX_NUM_USER_UCLASS_FLAGS (UCF_LAST_USER_FLAG \
109 - UCF_USER_FLAG_1 + 1)
111 /* Used in savegame processing and clients. */
112 #define SPECENUM_NAME unit_move_type
113 #define SPECENUM_VALUE0 UMT_LAND
114 #define SPECENUM_VALUE0NAME "Land"
115 #define SPECENUM_VALUE1 UMT_SEA
116 #define SPECENUM_VALUE1NAME "Sea"
117 #define SPECENUM_VALUE2 UMT_BOTH
118 #define SPECENUM_VALUE2NAME "Both"
119 #include "specenum_gen.h"
121 /* Used in the network protocol. */
122 BV_DEFINE(bv_unit_classes, UCL_LAST);
124 enum hut_behavior { HUT_NORMAL, HUT_NOTHING, HUT_FRIGHTEN };
126 enum move_level { MOVE_NONE, MOVE_PARTIAL, MOVE_FULL };
128 struct extra_type_list;
129 struct unit_class_list;
131 struct unit_class {
132 Unit_Class_id item_number;
133 struct name_translation name;
134 bool disabled;
135 enum unit_move_type move_type;
136 int min_speed; /* Minimum speed after damage and effects */
137 int hp_loss_pct; /* Percentage of hitpoints lost each turn not in city or airbase */
138 int non_native_def_pct;
139 enum hut_behavior hut_behavior;
140 bv_unit_class_flags flags;
142 struct strvec *helptext;
144 struct {
145 enum move_level land_move;
146 enum move_level sea_move;
147 } adv;
149 struct {
150 struct extra_type_list *refuel_bases;
151 struct extra_type_list *native_tile_extras;
152 struct extra_type_list *bonus_roads;
153 struct unit_class_list *subset_movers;
154 } cache;
157 /* Unit "special effects" flags:
158 * Note this is now an enumerated type, and not power-of-two integers
159 * for bits, though unit_type.flags is still a bitfield, and code
160 * which uses unit_has_type_flag() without twiddling bits is unchanged.
161 * (It is easier to go from i to (1<<i) than the reverse.)
162 * See data/default/units.ruleset for documentation of their effects.
163 * Change the array *flag_names[] in unittype.c accordingly.
164 * Used in the network protocol.
166 #define SPECENUM_NAME unit_type_flag_id
167 /* Cannot fortify even if class can */
168 #define SPECENUM_VALUE0 UTYF_CANT_FORTIFY
169 /* TRANS: this and following strings are 'unit type flags', which may rarely
170 * be presented to the player in ruleset help text */
171 #define SPECENUM_VALUE0NAME N_("?unitflag:Cant_Fortify")
172 /* Unit has no ZOC */
173 #define SPECENUM_VALUE1 UTYF_NOZOC
174 #define SPECENUM_VALUE1NAME N_("?unitflag:HasNoZOC")
175 #define SPECENUM_VALUE2 UTYF_IGZOC
176 /* TRANS: unit type flag (rarely shown): "ignore zones of control" */
177 #define SPECENUM_VALUE2NAME N_("?unitflag:IgZOC")
178 #define SPECENUM_VALUE3 UTYF_CIVILIAN
179 #define SPECENUM_VALUE3NAME N_("?unitflag:NonMil")
180 #define SPECENUM_VALUE4 UTYF_IGTER
181 /* TRANS: unit type flag (rarely shown): "ignore terrain" */
182 #define SPECENUM_VALUE4NAME N_("?unitflag:IgTer")
183 #define SPECENUM_VALUE5 UTYF_ONEATTACK
184 #define SPECENUM_VALUE5NAME N_("?unitflag:OneAttack")
185 #define SPECENUM_VALUE6 UTYF_FIELDUNIT
186 #define SPECENUM_VALUE6NAME N_("?unitflag:FieldUnit")
187 /* autoattack: a unit will choose to attack this unit even if defending
188 * against it has better odds. */
189 #define SPECENUM_VALUE7 UTYF_PROVOKING
190 #define SPECENUM_VALUE7NAME "?unitflag:Provoking"
191 /* Invisible except when adjacent (Submarine) */
192 #define SPECENUM_VALUE8 UTYF_PARTIAL_INVIS
193 #define SPECENUM_VALUE8NAME N_("?unitflag:Partial_Invis")
194 /* Does not include ability to found cities */
195 #define SPECENUM_VALUE9 UTYF_SETTLERS
196 #define SPECENUM_VALUE9NAME N_("?unitflag:Settlers")
197 #define SPECENUM_VALUE10 UTYF_DIPLOMAT
198 #define SPECENUM_VALUE10NAME N_("?unitflag:Diplomat")
199 /* Can't leave the coast */
200 #define SPECENUM_VALUE11 UTYF_COAST_STRICT
201 #define SPECENUM_VALUE11NAME N_("?unitflag:CoastStrict")
202 /* Can 'refuel' at coast - meaningless if fuel value not set */
203 #define SPECENUM_VALUE12 UTYF_COAST
204 #define SPECENUM_VALUE12NAME N_("?unitflag:Coast")
205 /* upkeep can switch from shield to gold */
206 #define SPECENUM_VALUE13 UTYF_SHIELD2GOLD
207 #define SPECENUM_VALUE13NAME N_("?unitflag:Shield2Gold")
208 /* Enhanced spy abilities */
209 #define SPECENUM_VALUE14 UTYF_SPY
210 #define SPECENUM_VALUE14NAME N_("?unitflag:Spy")
211 /* Cannot attack vs non-native tiles even if class can */
212 #define SPECENUM_VALUE15 UTYF_ONLY_NATIVE_ATTACK
213 #define SPECENUM_VALUE15NAME N_("?unitflag:Only_Native_Attack")
214 /* Only Fundamentalist government can build these units */
215 #define SPECENUM_VALUE16 UTYF_FANATIC
216 #define SPECENUM_VALUE16NAME N_("?unitflag:Fanatic")
217 /* Losing this unit means losing the game */
218 #define SPECENUM_VALUE17 UTYF_GAMELOSS
219 #define SPECENUM_VALUE17NAME N_("?unitflag:GameLoss")
220 /* A player can only have one unit of this type */
221 #define SPECENUM_VALUE18 UTYF_UNIQUE
222 #define SPECENUM_VALUE18NAME N_("?unitflag:Unique")
223 /* When a transport containing this unit disappears the game will try to
224 * rescue units with this flag before it tries to rescue units without
225 * it. */
226 #define SPECENUM_VALUE19 UTYF_EVAC_FIRST
227 #define SPECENUM_VALUE19NAME N_("?unitflag:EvacuateFirst")
228 /* Always wins diplomatic contests */
229 #define SPECENUM_VALUE20 UTYF_SUPERSPY
230 #define SPECENUM_VALUE20NAME N_("?unitflag:SuperSpy")
231 /* Has no homecity */
232 #define SPECENUM_VALUE21 UTYF_NOHOME
233 #define SPECENUM_VALUE21NAME N_("?unitflag:NoHome")
234 /* Cannot increase veteran level */
235 #define SPECENUM_VALUE22 UTYF_NO_VETERAN
236 #define SPECENUM_VALUE22NAME N_("?unitflag:NoVeteran")
237 /* Gets double firepower against cities */
238 #define SPECENUM_VALUE23 UTYF_CITYBUSTER
239 #define SPECENUM_VALUE23NAME N_("?unitflag:CityBuster")
240 /* Unit cannot be built (barb leader etc) */
241 #define SPECENUM_VALUE24 UTYF_NOBUILD
242 #define SPECENUM_VALUE24NAME N_("?unitflag:NoBuild")
243 /* Firepower set to 1 when EFT_DEFEND_BONUS applies
244 * (for example, land unit attacking city with walls) */
245 #define SPECENUM_VALUE25 UTYF_BADWALLATTACKER
246 #define SPECENUM_VALUE25NAME N_("?unitflag:BadWallAttacker")
247 /* Firepower set to 1 and attackers x2 when in city */
248 #define SPECENUM_VALUE26 UTYF_BADCITYDEFENDER
249 #define SPECENUM_VALUE26NAME N_("?unitflag:BadCityDefender")
250 /* Only barbarians can build this unit */
251 #define SPECENUM_VALUE27 UTYF_BARBARIAN_ONLY
252 #define SPECENUM_VALUE27NAME N_("?unitflag:BarbarianOnly")
253 /* Unit won't lose all its movement when moving from non-nantive terrain to
254 * native terrain even if slow_invasions is turned on. */
255 #define SPECENUM_VALUE28 UTYF_BEACH_LANDER
256 #define SPECENUM_VALUE28NAME N_("?unitflag:BeachLander")
257 /* Unit can't be built in scenarios where founding new cities is prevented. */
258 #define SPECENUM_VALUE29 UTYF_NEWCITY_GAMES_ONLY
259 #define SPECENUM_VALUE29NAME N_("?unitflag:NewCityGamesOnly")
260 /* Can escape when killstack occours */
261 #define SPECENUM_VALUE30 UTYF_CANESCAPE
262 #define SPECENUM_VALUE30NAME N_("?unitflag:CanEscape")
263 /* Can kill escaping units */
264 #define SPECENUM_VALUE31 UTYF_CANKILLESCAPING
265 #define SPECENUM_VALUE31NAME N_("?unitflag:CanKillEscaping")
267 #define SPECENUM_VALUE32 UTYF_USER_FLAG_1
268 #define SPECENUM_VALUE33 UTYF_USER_FLAG_2
269 #define SPECENUM_VALUE34 UTYF_USER_FLAG_3
270 #define SPECENUM_VALUE35 UTYF_USER_FLAG_4
271 #define SPECENUM_VALUE36 UTYF_USER_FLAG_5
272 #define SPECENUM_VALUE37 UTYF_USER_FLAG_6
273 #define SPECENUM_VALUE38 UTYF_USER_FLAG_7
274 #define SPECENUM_VALUE39 UTYF_USER_FLAG_8
275 #define SPECENUM_VALUE40 UTYF_USER_FLAG_9
276 #define SPECENUM_VALUE41 UTYF_USER_FLAG_10
277 #define SPECENUM_VALUE42 UTYF_USER_FLAG_11
278 #define SPECENUM_VALUE43 UTYF_USER_FLAG_12
279 #define SPECENUM_VALUE44 UTYF_USER_FLAG_13
280 #define SPECENUM_VALUE45 UTYF_USER_FLAG_14
281 #define SPECENUM_VALUE46 UTYF_USER_FLAG_15
282 #define SPECENUM_VALUE47 UTYF_USER_FLAG_16
283 #define SPECENUM_VALUE48 UTYF_USER_FLAG_17
284 #define SPECENUM_VALUE49 UTYF_USER_FLAG_18
285 #define SPECENUM_VALUE50 UTYF_USER_FLAG_19
286 #define SPECENUM_VALUE51 UTYF_USER_FLAG_20
287 #define SPECENUM_VALUE52 UTYF_USER_FLAG_21
288 #define SPECENUM_VALUE53 UTYF_USER_FLAG_22
289 #define SPECENUM_VALUE54 UTYF_USER_FLAG_23
290 #define SPECENUM_VALUE55 UTYF_USER_FLAG_24
291 #define SPECENUM_VALUE56 UTYF_USER_FLAG_25
292 #define SPECENUM_VALUE57 UTYF_USER_FLAG_26
293 #define SPECENUM_VALUE58 UTYF_USER_FLAG_27
294 #define SPECENUM_VALUE59 UTYF_USER_FLAG_28
295 #define SPECENUM_VALUE60 UTYF_USER_FLAG_29
296 #define SPECENUM_VALUE61 UTYF_USER_FLAG_30
297 #define SPECENUM_VALUE62 UTYF_USER_FLAG_31
298 #define SPECENUM_VALUE63 UTYF_USER_FLAG_32
299 #define SPECENUM_VALUE64 UTYF_USER_FLAG_33
300 #define SPECENUM_VALUE65 UTYF_USER_FLAG_34
301 #define SPECENUM_VALUE66 UTYF_USER_FLAG_35
302 #define SPECENUM_VALUE67 UTYF_USER_FLAG_36
303 #define SPECENUM_VALUE68 UTYF_USER_FLAG_37
304 #define SPECENUM_VALUE69 UTYF_USER_FLAG_38
305 #define SPECENUM_VALUE70 UTYF_USER_FLAG_39
306 #define SPECENUM_VALUE71 UTYF_USER_FLAG_40
307 #define SPECENUM_VALUE72 UTYF_USER_FLAG_41
308 #define SPECENUM_VALUE73 UTYF_USER_FLAG_42
309 #define SPECENUM_VALUE74 UTYF_USER_FLAG_43
310 #define SPECENUM_VALUE75 UTYF_USER_FLAG_44
311 #define SPECENUM_VALUE76 UTYF_USER_FLAG_45
312 /* Note that first role must have value next to last flag */
314 #define UTYF_LAST_USER_FLAG UTYF_USER_FLAG_45
315 #define MAX_NUM_USER_UNIT_FLAGS (UTYF_LAST_USER_FLAG - UTYF_USER_FLAG_1 + 1)
316 #define SPECENUM_NAMEOVERRIDE
317 #define SPECENUM_BITVECTOR bv_unit_type_flags
318 #include "specenum_gen.h"
321 /* Unit "roles": these are similar to unit flags but differ in that
322 they don't represent intrinsic properties or abilities of units,
323 but determine which units are used (mainly by the server or AI)
324 in various circumstances, or "roles".
325 Note that in some cases flags can act as roles, eg, we don't need
326 a role for "settlers", because we can just use UTYF_SETTLERS.
327 (Now have to consider ACTION_FOUND_CITY too)
328 So we make sure flag values and role values are distinct,
329 so some functions can use them interchangably.
330 See data/classic/units.ruleset for documentation of their effects.
332 #define L_FIRST (UTYF_LAST_USER_FLAG + 1)
334 #define SPECENUM_NAME unit_role_id
335 /* is built first when city established */
336 #define SPECENUM_VALUE77 L_FIRSTBUILD
337 #define SPECENUM_VALUE77NAME N_("?unitflag:FirstBuild")
338 /* initial explorer unit */
339 #define SPECENUM_VALUE78 L_EXPLORER
340 #define SPECENUM_VALUE78NAME N_("?unitflag:Explorer")
341 /* can be found in hut */
342 #define SPECENUM_VALUE79 L_HUT
343 #define SPECENUM_VALUE79NAME N_("?unitflag:Hut")
344 /* can be found in hut, global tech required */
345 #define SPECENUM_VALUE80 L_HUT_TECH
346 #define SPECENUM_VALUE80NAME N_("?unitflag:HutTech")
347 /* is created in Partisan circumstances */
348 #define SPECENUM_VALUE81 L_PARTISAN
349 #define SPECENUM_VALUE81NAME N_("?unitflag:Partisan")
350 /* ok on defense (AI) */
351 #define SPECENUM_VALUE82 L_DEFEND_OK
352 #define SPECENUM_VALUE82NAME N_("?unitflag:DefendOk")
353 /* primary purpose is defense (AI) */
354 #define SPECENUM_VALUE83 L_DEFEND_GOOD
355 #define SPECENUM_VALUE83NAME N_("?unitflag:DefendGood")
356 /* is useful for ferrying (AI) */
357 #define SPECENUM_VALUE84 L_FERRYBOAT
358 #define SPECENUM_VALUE84NAME N_("?unitflag:FerryBoat")
359 /* barbarians unit, land only */
360 #define SPECENUM_VALUE85 L_BARBARIAN
361 #define SPECENUM_VALUE85NAME N_("?unitflag:Barbarian")
362 /* barbarians unit, global tech required */
363 #define SPECENUM_VALUE86 L_BARBARIAN_TECH
364 #define SPECENUM_VALUE86NAME N_("?unitflag:BarbarianTech")
365 /* barbarian boat */
366 #define SPECENUM_VALUE87 L_BARBARIAN_BOAT
367 #define SPECENUM_VALUE87NAME N_("?unitflag:BarbarianBoat")
368 /* what barbarians should build */
369 #define SPECENUM_VALUE88 L_BARBARIAN_BUILD
370 #define SPECENUM_VALUE88NAME N_("BarbarianBuild")
371 /* barbarians build when global tech */
372 #define SPECENUM_VALUE89 L_BARBARIAN_BUILD_TECH
373 #define SPECENUM_VALUE89NAME N_("?unitflag:BarbarianBuildTech")
374 /* barbarian leader */
375 #define SPECENUM_VALUE90 L_BARBARIAN_LEADER
376 #define SPECENUM_VALUE90NAME N_("?unitflag:BarbarianLeader")
377 /* sea raider unit */
378 #define SPECENUM_VALUE91 L_BARBARIAN_SEA
379 #define SPECENUM_VALUE91NAME N_("?unitflag:BarbarianSea")
380 /* sea raider unit, global tech required */
381 #define SPECENUM_VALUE92 L_BARBARIAN_SEA_TECH
382 #define SPECENUM_VALUE92NAME N_("?unitflag:BarbarianSeaTech")
383 /* Startunit: Cities */
384 #define SPECENUM_VALUE93 L_START_CITIES
385 #define SPECENUM_VALUE93NAME N_("?unitflag:CitiesStartunit")
386 /* Startunit: Worker */
387 #define SPECENUM_VALUE94 L_START_WORKER
388 #define SPECENUM_VALUE94NAME N_("?unitflag:WorkerStartunit")
389 /* Startunit: Explorer */
390 #define SPECENUM_VALUE95 L_START_EXPLORER
391 #define SPECENUM_VALUE95NAME N_("?unitflag:ExplorerStartunit")
392 /* Startunit: King */
393 #define SPECENUM_VALUE96 L_START_KING
394 #define SPECENUM_VALUE96NAME N_("?unitflag:KingStartunit")
395 /* Startunit: Diplomat */
396 #define SPECENUM_VALUE97 L_START_DIPLOMAT
397 #define SPECENUM_VALUE97NAME N_("?unitflag:DiplomatStartunit")
398 /* Startunit: Ferryboat */
399 #define SPECENUM_VALUE98 L_START_FERRY
400 #define SPECENUM_VALUE98NAME N_("?unitflag:FerryStartunit")
401 /* Startunit: DefendOk */
402 #define SPECENUM_VALUE99 L_START_DEFEND_OK
403 #define SPECENUM_VALUE99NAME N_("?unitflag:DefendOkStartunit")
404 /* Startunit: DefendGood */
405 #define SPECENUM_VALUE100 L_START_DEFEND_GOOD
406 #define SPECENUM_VALUE100NAME N_("?unitflag:DefendGoodStartunit")
407 /* Startunit: AttackFast */
408 #define SPECENUM_VALUE101 L_START_ATTACK_FAST
409 #define SPECENUM_VALUE101NAME N_("?unitflag:AttackFastStartunit")
410 /* Startunit: AttackStrong */
411 #define SPECENUM_VALUE102 L_START_ATTACK_STRONG
412 #define SPECENUM_VALUE102NAME N_("?unitflag:AttackStrongStartunit")
413 /* AI hunter type unit */
414 #define SPECENUM_VALUE103 L_HUNTER
415 #define SPECENUM_VALUE103NAME N_("?unitflag:Hunter")
416 /* can improve terrain */
417 #define SPECENUM_VALUE104 L_SETTLERS
418 #define SPECENUM_VALUE104NAME N_("?unitflag:Settlers")
419 #define L_LAST (L_SETTLERS + 1)
421 #include "specenum_gen.h"
423 #define L_MAX 64 /* Used in the network protocol. */
425 FC_STATIC_ASSERT(L_LAST - L_FIRST <= L_MAX, too_many_unit_roles);
427 /* Used in the network protocol. */
428 BV_DEFINE(bv_unit_type_roles, L_MAX);
430 /* Used in the network protocol. */
431 #define SPECENUM_NAME combat_bonus_type
432 #define SPECENUM_VALUE0 CBONUS_DEFENSE_MULTIPLIER
433 #define SPECENUM_VALUE0NAME "DefenseMultiplier"
434 #define SPECENUM_VALUE1 CBONUS_DEFENSE_DIVIDER
435 #define SPECENUM_VALUE1NAME "DefenseDivider"
436 #define SPECENUM_VALUE2 CBONUS_FIREPOWER1
437 #define SPECENUM_VALUE2NAME "Firepower1"
438 #include "specenum_gen.h"
440 struct combat_bonus {
441 enum unit_type_flag_id flag;
442 enum combat_bonus_type type;
443 int value;
445 /* Not listed in the help text. */
446 bool quiet;
449 /* get 'struct combat_bonus_list' and related functions: */
450 #define SPECLIST_TAG combat_bonus
451 #define SPECLIST_TYPE struct combat_bonus
452 #include "speclist.h"
454 #define combat_bonus_list_iterate(bonuslist, pbonus) \
455 TYPED_LIST_ITERATE(struct combat_bonus, bonuslist, pbonus)
456 #define combat_bonus_list_iterate_end LIST_ITERATE_END
458 BV_DEFINE(bv_unit_types, U_LAST);
460 struct veteran_level {
461 struct name_translation name; /* level/rank name */
462 int power_fact; /* combat/work speed/diplomatic power factor (in %) */
463 int move_bonus;
464 int raise_chance; /* server only */
465 int work_raise_chance; /* server only */
468 struct veteran_system {
469 int levels;
471 struct veteran_level *definitions;
474 struct unit_type {
475 Unit_type_id item_number;
476 struct name_translation name;
477 bool disabled; /* Does not really exist - hole in improvments array */
478 char graphic_str[MAX_LEN_NAME];
479 char graphic_alt[MAX_LEN_NAME];
480 char sound_move[MAX_LEN_NAME];
481 char sound_move_alt[MAX_LEN_NAME];
482 char sound_fight[MAX_LEN_NAME];
483 char sound_fight_alt[MAX_LEN_NAME];
484 int build_cost; /* Use wrappers to access this. */
485 int pop_cost; /* number of workers the unit contains (e.g., settlers, engineers)*/
486 int attack_strength;
487 int defense_strength;
488 int move_rate;
489 int unknown_move_cost; /* See utype_unknown_move_cost(). */
491 struct advance *require_advance; /* may be NULL */
492 struct impr_type *need_improvement; /* may be NULL */
493 struct government *need_government; /* may be NULL */
495 int vision_radius_sq;
496 int transport_capacity;
497 int hp;
498 int firepower;
499 struct combat_bonus_list *bonuses;
501 #define U_NOT_OBSOLETED (NULL)
502 struct unit_type *obsoleted_by;
503 struct unit_type *converted_to;
504 int convert_time;
505 int fuel;
507 bv_unit_type_flags flags;
508 bv_unit_type_roles roles;
510 int happy_cost; /* unhappy people in home city */
511 int upkeep[O_LAST];
513 /* Only valid for ACTION_PARADROP */
514 int paratroopers_range;
515 int paratroopers_mr_req;
516 int paratroopers_mr_sub;
518 /* Additional values for the expanded veteran system */
519 struct veteran_system *veteran;
521 /* Values for bombardment */
522 int bombard_rate;
524 /* Values for founding cities */
525 int city_size;
527 int city_slots;
529 struct unit_class *uclass;
531 bv_unit_classes cargo;
533 /* Can attack these classes even if they are otherwise "Unreachable" */
534 bv_unit_classes targets;
535 /* Can load into these class transports at any location,
536 * even if they are otherwise "Unreachable". */
537 bv_unit_classes embarks;
538 /* Can unload from these class transports at any location,
539 * even if they are otherwise "Unreachable". */
540 bv_unit_classes disembarks;
542 struct strvec *helptext;
544 struct {
545 bool igwall;
546 } adv;
548 struct {
549 int max_defense_mp; /* Value 0 here does not guarantee that unit never
550 * has CBONUS_DEFENSE_MULTIPLIER, it merely means
551 * that there's no POSITIVE one */
552 int defense_mp_bonuses[U_LAST];
553 } cache;
555 void *ais[FREECIV_AI_MOD_LAST];
558 /* General unit and unit type (matched) routines */
559 Unit_type_id utype_count(void);
560 Unit_type_id utype_index(const struct unit_type *punittype);
561 Unit_type_id utype_number(const struct unit_type *punittype);
563 struct unit_type *unit_type_get(const struct unit *punit);
564 struct unit_type *utype_by_number(const Unit_type_id id);
566 struct unit_type *unit_type_by_rule_name(const char *name);
567 struct unit_type *unit_type_by_translated_name(const char *name);
569 const char *unit_rule_name(const struct unit *punit);
570 const char *utype_rule_name(const struct unit_type *punittype);
572 const char *unit_name_translation(const struct unit *punit);
573 const char *utype_name_translation(const struct unit_type *punittype);
575 const char *utype_values_string(const struct unit_type *punittype);
576 const char *utype_values_translation(const struct unit_type *punittype);
578 /* General unit type flag and role routines */
579 bool unit_has_type_flag(const struct unit *punit, enum unit_type_flag_id flag);
581 /**************************************************************************
582 Return whether the given unit type has the flag.
583 **************************************************************************/
584 static inline bool utype_has_flag(const struct unit_type *punittype, int flag)
586 return BV_ISSET(punittype->flags, flag);
589 bool unit_has_type_role(const struct unit *punit, enum unit_role_id role);
590 bool utype_has_role(const struct unit_type *punittype, int role);
592 void user_unit_type_flags_init(void);
593 void set_user_unit_type_flag_name(enum unit_type_flag_id id, const char *name,
594 const char *helptxt);
595 const char *unit_type_flag_helptxt(enum unit_type_flag_id id);
597 bool unit_can_take_over(const struct unit *punit);
598 bool utype_can_take_over(const struct unit_type *punittype);
600 bool utype_can_freely_load(const struct unit_type *pcargotype,
601 const struct unit_type *ptranstype);
602 bool utype_can_freely_unload(const struct unit_type *pcargotype,
603 const struct unit_type *ptranstype);
605 bool utype_may_act_at_all(const struct unit_type *putype);
606 bool utype_can_do_action(const struct unit_type *putype,
607 const int action_id);
608 bool utype_acts_hostile(const struct unit_type *putype);
610 bool can_unit_act_when_ustate_is(const struct unit_type *punit_type,
611 const enum ustate_prop prop,
612 const bool is_there);
613 bool utype_can_do_act_when_ustate(const struct unit_type *punit_type,
614 const int action_id,
615 const enum ustate_prop prop,
616 const bool is_there);
618 bool can_utype_do_act_if_tgt_diplrel(const struct unit_type *punit_type,
619 const int action_id,
620 const int prop,
621 const bool is_there);
623 bool utype_may_act_move_frags(struct unit_type *punit_type,
624 const int action_id,
625 const int move_fragments);
627 bool utype_may_act_tgt_city_tile(struct unit_type *punit_type,
628 const int action_id,
629 const enum citytile_type prop,
630 const bool is_there);
632 /* Functions to operate on various flag and roles. */
633 typedef bool (*role_unit_callback)(struct unit_type *ptype, void *data);
635 void role_unit_precalcs(void);
636 void role_unit_precalcs_free(void);
637 int num_role_units(int role);
638 struct unit_type *role_units_iterate(int role, role_unit_callback cb, void *data);
639 struct unit_type *role_units_iterate_backwards(int role, role_unit_callback cb, void *data);
640 struct unit_type *get_role_unit(int role, int role_index);
641 struct unit_type *best_role_unit(const struct city *pcity, int role);
642 struct unit_type *best_role_unit_for_player(const struct player *pplayer,
643 int role);
644 struct unit_type *first_role_unit_for_player(const struct player *pplayer,
645 int role);
646 bool role_units_translations(struct astring *astr, int flag, bool alts);
648 /* General unit class routines */
649 Unit_Class_id uclass_count(void);
650 Unit_Class_id uclass_number(const struct unit_class *pclass);
651 /* Optimised to be identical to uclass_number: the implementation
652 * unittype.c is also semantically correct. */
653 #define uclass_index(_c_) (_c_)->item_number
654 #ifndef uclass_index
655 Unit_Class_id uclass_index(const struct unit_class *pclass);
656 #endif /* uclass_index */
658 struct unit_class *unit_class_get(const struct unit *punit);
659 struct unit_class *uclass_by_number(const Unit_Class_id id);
660 #define utype_class(_t_) (_t_)->uclass
661 #ifndef utype_class
662 struct unit_class *utype_class(const struct unit_type *punittype);
663 #endif /* utype_class */
665 struct unit_class *unit_class_by_rule_name(const char *s);
667 const char *uclass_rule_name(const struct unit_class *pclass);
668 const char *uclass_name_translation(const struct unit_class *pclass);
670 /**************************************************************************
671 Return whether the given unit class has the flag.
672 **************************************************************************/
673 static inline bool uclass_has_flag(const struct unit_class *punitclass,
674 enum unit_class_flag_id flag)
676 return BV_ISSET(punitclass->flags, flag);
679 void user_unit_class_flags_init(void);
680 void set_user_unit_class_flag_name(enum unit_class_flag_id id,
681 const char *name,
682 const char *helptxt);
683 const char *unit_class_flag_helptxt(enum unit_class_flag_id id);
685 /* Ancillary routines */
686 int unit_build_shield_cost(const struct unit *punit);
687 int utype_build_shield_cost(const struct unit_type *punittype);
689 int utype_buy_gold_cost(const struct unit_type *punittype,
690 int shields_in_stock);
692 const struct veteran_system *
693 utype_veteran_system(const struct unit_type *punittype);
694 int utype_veteran_levels(const struct unit_type *punittype);
695 const struct veteran_level *
696 utype_veteran_level(const struct unit_type *punittype, int level);
697 const char *utype_veteran_name_translation(const struct unit_type *punittype,
698 int level);
699 bool utype_veteran_has_power_bonus(const struct unit_type *punittype);
701 struct veteran_system *veteran_system_new(int count);
702 void veteran_system_destroy(struct veteran_system *vsystem);
703 void veteran_system_definition(struct veteran_system *vsystem, int level,
704 const char *vlist_name, int vlist_power,
705 int vlist_move, int vlist_raise,
706 int vlist_wraise);
708 int unit_disband_shields(const struct unit *punit);
709 int utype_disband_shields(const struct unit_type *punittype);
711 int unit_pop_value(const struct unit *punit);
712 int utype_pop_value(const struct unit_type *punittype);
714 enum unit_move_type utype_move_type(const struct unit_type *punittype);
715 void set_unit_move_type(struct unit_class *puclass);
717 /* player related unit functions */
718 int utype_upkeep_cost(const struct unit_type *ut, struct player *pplayer,
719 Output_type_id otype);
720 int utype_happy_cost(const struct unit_type *ut, const struct player *pplayer);
722 struct unit_type *can_upgrade_unittype(const struct player *pplayer,
723 struct unit_type *punittype);
724 int unit_upgrade_price(const struct player *pplayer,
725 const struct unit_type *from,
726 const struct unit_type *to);
728 bool utype_player_already_has_this_unique(const struct player *pplayer,
729 const struct unit_type *putype);
731 bool can_player_build_unit_direct(const struct player *p,
732 const struct unit_type *punittype);
733 bool can_player_build_unit_later(const struct player *p,
734 const struct unit_type *punittype);
735 bool can_player_build_unit_now(const struct player *p,
736 const struct unit_type *punittype);
738 #define utype_fuel(ptype) (ptype)->fuel
740 bool utype_is_cityfounder(struct unit_type *utype);
742 /* Initialization and iteration */
743 void unit_types_init(void);
744 void unit_types_free(void);
745 void unit_type_flags_free(void);
746 void unit_class_flags_free(void);
748 struct unit_type *unit_type_array_first(void);
749 const struct unit_type *unit_type_array_last(void);
751 #define unit_type_iterate(_p) \
753 struct unit_type *_p = unit_type_array_first(); \
754 if (NULL != _p) { \
755 for (; _p <= unit_type_array_last(); _p++) {
757 #define unit_type_iterate_end \
762 #define unit_active_type_iterate(_p) \
763 unit_type_iterate(_p) { \
764 if (!_p->disabled) {
766 #define unit_active_type_iterate_end \
768 } unit_type_iterate_end;
771 void *utype_ai_data(const struct unit_type *ptype, const struct ai_type *ai);
772 void utype_set_ai_data(struct unit_type *ptype, const struct ai_type *ai,
773 void *data);
775 void unit_type_action_cache_set(struct unit_type *ptype);
776 void unit_type_action_cache_init(void);
778 /* Initialization and iteration */
779 void unit_classes_init(void);
780 void unit_classes_free(void);
782 void set_unit_class_caches(struct unit_class *pclass);
783 void set_unit_type_caches(struct unit_type *ptype);
785 struct unit_class *unit_class_array_first(void);
786 const struct unit_class *unit_class_array_last(void);
788 #define unit_class_iterate(_p) \
790 struct unit_class *_p = unit_class_array_first(); \
791 if (NULL != _p) { \
792 for (; _p <= unit_class_array_last(); _p++) {
794 #define unit_class_iterate_end \
799 #define unit_active_class_iterate(_p) \
800 unit_class_iterate(_p) { \
801 if (!_p->disabled) {
803 #define unit_active_class_iterate_end \
805 } unit_class_iterate_end;
807 #define SPECLIST_TAG unit_class
808 #define SPECLIST_TYPE struct unit_class
809 #include "speclist.h"
811 #define unit_class_list_iterate(uclass_list, pclass) \
812 TYPED_LIST_ITERATE(struct unit_class, uclass_list, pclass)
813 #define unit_class_list_iterate_end LIST_ITERATE_END
815 #define SPECLIST_TAG unit_type
816 #define SPECLIST_TYPE struct unit_type
817 #include "speclist.h"
819 #define unit_type_list_iterate(utype_list, ptype) \
820 TYPED_LIST_ITERATE(struct unit_type, utype_list, ptype)
821 #define unit_type_list_iterate_end LIST_ITERATE_END
823 #ifdef __cplusplus
825 #endif /* __cplusplus */
827 #endif /* FC__UNITTYPE_H */