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__UNITTYPE_H
14 #define FC__UNITTYPE_H
15
16 #ifdef __cplusplus
17 extern "C" {
18 #endif /* __cplusplus */
19
20 /* utility */
21 #include "bitvector.h"
22 #include "shared.h"
23
24 /* common */
25 #include "fc_types.h"
26 #include "name_translation.h"
27
28 struct astring; /* Actually defined in "utility/astring.h". */
29 struct strvec; /* Actually defined in "utility/string_vector.h". */
30
31 struct ai_type;
32
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
39
40 /* The largest distance a ruleset can allow a unit to paradrop.
41 *
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.
45 *
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)
51 */
52 #define UNIT_MAX_PARADROP_RANGE (65535 - 1)
53
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 /* Can launch attack from non-native tile (to native tile) */
89 #define SPECENUM_VALUE13 UCF_ATT_FROM_NON_NATIVE
90 #define SPECENUM_VALUE13NAME N_("?uclassflag:AttFromNonNative")
91 /* Kills citizens upon successful attack against a city */
92 #define SPECENUM_VALUE14 UCF_KILLCITIZEN
93 #define SPECENUM_VALUE14NAME N_("?uclassflag:KillCitizen")
94 /* Can be airlifted */
95 #define SPECENUM_VALUE15 UCF_AIRLIFTABLE
96 #define SPECENUM_VALUE15NAME N_("?uclassflag:Airliftable")
97 /* keep this last */
98 #define SPECENUM_COUNT UCF_COUNT
99 #define SPECENUM_BITVECTOR bv_unit_class_flags
100 #include "specenum_gen.h"
101
102 /* Used in savegame processing and clients. */
103 #define SPECENUM_NAME unit_move_type
104 #define SPECENUM_VALUE0 UMT_LAND
105 #define SPECENUM_VALUE0NAME "Land"
106 #define SPECENUM_VALUE1 UMT_SEA
107 #define SPECENUM_VALUE1NAME "Sea"
108 #define SPECENUM_VALUE2 UMT_BOTH
109 #define SPECENUM_VALUE2NAME "Both"
110 #include "specenum_gen.h"
111
112 /* Used in the network protocol. */
113 BV_DEFINE(bv_unit_classes, UCL_LAST);
114
115 enum hut_behavior { HUT_NORMAL, HUT_NOTHING, HUT_FRIGHTEN };
116
117 enum move_level { MOVE_NONE, MOVE_PARTIAL, MOVE_FULL };
118
119 struct extra_type_list;
120 struct unit_class_list;
121
122 struct unit_class {
123 Unit_Class_id item_number;
124 struct name_translation name;
125 enum unit_move_type move_type;
126 int min_speed; /* Minimum speed after damage and effects */
127 int hp_loss_pct; /* Percentage of hitpoints lost each turn not in city or airbase */
128 int non_native_def_pct;
129 enum hut_behavior hut_behavior;
130 bv_unit_class_flags flags;
131
132 struct strvec *helptext;
133
134 struct {
135 enum move_level land_move;
136 enum move_level sea_move;
137 } adv;
138
139 struct {
140 struct extra_type_list *refuel_bases;
141 struct extra_type_list *native_tile_extras;
142 struct extra_type_list *bonus_roads;
143 struct unit_class_list *subset_movers;
144 } cache;
145 };
146
147 /* Unit "special effects" flags:
148 * Note this is now an enumerated type, and not power-of-two integers
149 * for bits, though unit_type.flags is still a bitfield, and code
150 * which uses unit_has_type_flag() without twiddling bits is unchanged.
151 * (It is easier to go from i to (1<<i) than the reverse.)
152 * See data/classic/units.ruleset for documentation of their effects.
153 * Change the array *flag_names[] in unittype.c accordingly.
154 * Used in the network protocol.
155 */
156 #define SPECENUM_NAME unit_type_flag_id
157 /* Cannot fortify even if class can */
158 #define SPECENUM_VALUE0 UTYF_CANT_FORTIFY
159 /* TRANS: this and following strings are 'unit type flags', which may rarely
160 * be presented to the player in ruleset help text */
161 #define SPECENUM_VALUE0NAME N_("?unitflag:Cant_Fortify")
162 /* Unit has no ZOC */
163 #define SPECENUM_VALUE1 UTYF_NOZOC
164 #define SPECENUM_VALUE1NAME N_("?unitflag:HasNoZOC")
165 #define SPECENUM_VALUE2 UTYF_IGZOC
166 /* TRANS: unit type flag (rarely shown): "ignore zones of control" */
167 #define SPECENUM_VALUE2NAME N_("?unitflag:IgZOC")
168 #define SPECENUM_VALUE3 UTYF_CIVILIAN
169 #define SPECENUM_VALUE3NAME N_("?unitflag:NonMil")
170 #define SPECENUM_VALUE4 UTYF_IGTER
171 /* TRANS: unit type flag (rarely shown): "ignore terrain" */
172 #define SPECENUM_VALUE4NAME N_("?unitflag:IgTer")
173 #define SPECENUM_VALUE5 UTYF_ONEATTACK
174 #define SPECENUM_VALUE5NAME N_("?unitflag:OneAttack")
175 #define SPECENUM_VALUE6 UTYF_FIELDUNIT
176 #define SPECENUM_VALUE6NAME N_("?unitflag:FieldUnit")
177 #define SPECENUM_VALUE7 UTYF_MARINES
178 #define SPECENUM_VALUE7NAME N_("?unitflag:Marines")
179 /* Invisible except when adjacent (Submarine) */
180 #define SPECENUM_VALUE8 UTYF_PARTIAL_INVIS
181 #define SPECENUM_VALUE8NAME N_("?unitflag:Partial_Invis")
182 /* Does not include ability to found cities */
183 #define SPECENUM_VALUE9 UTYF_SETTLERS
184 #define SPECENUM_VALUE9NAME N_("?unitflag:Settlers")
185 #define SPECENUM_VALUE10 UTYF_DIPLOMAT
186 #define SPECENUM_VALUE10NAME N_("?unitflag:Diplomat")
187 /* Trireme must stay close to the coast */
188 #define SPECENUM_VALUE11 UTYF_TRIREME
189 #define SPECENUM_VALUE11NAME N_("?unitflag:Trireme")
190 /* Nuclear attack effect */
191 #define SPECENUM_VALUE12 UTYF_NUCLEAR
192 #define SPECENUM_VALUE12NAME N_("?unitflag:Nuclear")
193 /* Enhanced spy abilities */
194 #define SPECENUM_VALUE13 UTYF_SPY
195 #define SPECENUM_VALUE13NAME N_("?unitflag:Spy")
196 #define SPECENUM_VALUE14 UTYF_PARATROOPERS
197 #define SPECENUM_VALUE14NAME N_("?unitflag:Paratroopers")
198 /* Can build cities */
199 #define SPECENUM_VALUE15 UTYF_CITIES
200 #define SPECENUM_VALUE15NAME N_("?unitflag:Cities")
201 /* Cannot attack vs non-native tiles even if class can */
202 #define SPECENUM_VALUE16 UTYF_ONLY_NATIVE_ATTACK
203 #define SPECENUM_VALUE16NAME N_("?unitflag:Only_Native_Attack")
204 /* unit can add to city population */
205 #define SPECENUM_VALUE17 UTYF_ADD_TO_CITY
206 #define SPECENUM_VALUE17NAME N_("?unitflag:AddToCity")
207 /* Only Fundamentalist government can build these units */
208 #define SPECENUM_VALUE18 UTYF_FANATIC
209 #define SPECENUM_VALUE18NAME N_("?unitflag:Fanatic")
210 /* Losing this unit means losing the game */
211 #define SPECENUM_VALUE19 UTYF_GAMELOSS
212 #define SPECENUM_VALUE19NAME N_("?unitflag:GameLoss")
213 /* A player can only have one unit of this type */
214 #define SPECENUM_VALUE20 UTYF_UNIQUE
215 #define SPECENUM_VALUE20NAME N_("?unitflag:Unique")
216 /* Cannot be disbanded, won't easily go away */
217 #define SPECENUM_VALUE21 UTYF_UNDISBANDABLE
218 #define SPECENUM_VALUE21NAME N_("?unitflag:Undisbandable")
219 /* Always wins diplomatic contests */
220 #define SPECENUM_VALUE22 UTYF_SUPERSPY
221 #define SPECENUM_VALUE22NAME N_("?unitflag:SuperSpy")
222 /* Has no homecity */
223 #define SPECENUM_VALUE23 UTYF_NOHOME
224 #define SPECENUM_VALUE23NAME N_("?unitflag:NoHome")
225 /* Cannot increase veteran level */
226 #define SPECENUM_VALUE24 UTYF_NO_VETERAN
227 #define SPECENUM_VALUE24NAME N_("?unitflag:NoVeteran")
228 /* Has the ability to bombard */
229 #define SPECENUM_VALUE25 UTYF_BOMBARDER
230 #define SPECENUM_VALUE25NAME N_("?unitflag:Bombarder")
231 /* Gets double firepower against cities */
232 #define SPECENUM_VALUE26 UTYF_CITYBUSTER
233 #define SPECENUM_VALUE26NAME N_("?unitflag:CityBuster")
234 /* Unit cannot be built (barb leader etc) */
235 #define SPECENUM_VALUE27 UTYF_NOBUILD
236 #define SPECENUM_VALUE27NAME N_("?unitflag:NoBuild")
237 /* Firepower set to 1 when EFT_DEFEND_BONUS applies
238 * (for example, land unit attacking city with walls) */
239 #define SPECENUM_VALUE28 UTYF_BADWALLATTACKER
240 #define SPECENUM_VALUE28NAME N_("?unitflag:BadWallAttacker")
241 /* Firepower set to 1 and attackers x2 when in city */
242 #define SPECENUM_VALUE29 UTYF_BADCITYDEFENDER
243 #define SPECENUM_VALUE29NAME N_("?unitflag:BadCityDefender")
244 /* Only barbarians can build this unit */
245 #define SPECENUM_VALUE30 UTYF_BARBARIAN_ONLY
246 #define SPECENUM_VALUE30NAME N_("?unitflag:BarbarianOnly")
247 /* upkeep can switch from shield to gold */
248 #define SPECENUM_VALUE31 UTYF_SHIELD2GOLD
249 #define SPECENUM_VALUE31NAME N_("?unitflag:Shield2Gold")
250 /* Unit can be captured */
251 #define SPECENUM_VALUE32 UTYF_CAPTURABLE
252 #define SPECENUM_VALUE32NAME N_("?unitflag:Capturable")
253 /* Unit can capture other */
254 #define SPECENUM_VALUE33 UTYF_CAPTURER
255 #define SPECENUM_VALUE33NAME N_("?unitflag:Capturer")
256 /* Unit can't be built in scenarios where founding new cities is prevented. */
257 #define SPECENUM_VALUE34 UTYF_NEWCITY_GAMES_ONLY
258 #define SPECENUM_VALUE34NAME N_("?unitflag:NewCityGamesOnly")
259
260 #define SPECENUM_VALUE35 UTYF_USER_FLAG_1
261 #define SPECENUM_VALUE36 UTYF_USER_FLAG_2
262 #define SPECENUM_VALUE37 UTYF_USER_FLAG_3
263 #define SPECENUM_VALUE38 UTYF_USER_FLAG_4
264 #define SPECENUM_VALUE39 UTYF_USER_FLAG_5
265 #define SPECENUM_VALUE40 UTYF_USER_FLAG_6
266 #define SPECENUM_VALUE41 UTYF_USER_FLAG_7
267 #define SPECENUM_VALUE42 UTYF_USER_FLAG_8
268 #define SPECENUM_VALUE43 UTYF_USER_FLAG_9
269 #define SPECENUM_VALUE44 UTYF_USER_FLAG_10
270 #define SPECENUM_VALUE45 UTYF_USER_FLAG_11
271 #define SPECENUM_VALUE46 UTYF_USER_FLAG_12
272 #define SPECENUM_VALUE47 UTYF_USER_FLAG_13
273 #define SPECENUM_VALUE48 UTYF_USER_FLAG_14
274 #define SPECENUM_VALUE49 UTYF_USER_FLAG_15
275 #define SPECENUM_VALUE50 UTYF_USER_FLAG_16
276 #define SPECENUM_VALUE51 UTYF_USER_FLAG_17
277 #define SPECENUM_VALUE52 UTYF_USER_FLAG_18
278 #define SPECENUM_VALUE53 UTYF_USER_FLAG_19
279 #define SPECENUM_VALUE54 UTYF_USER_FLAG_20
280 #define SPECENUM_VALUE55 UTYF_USER_FLAG_21
281 #define SPECENUM_VALUE56 UTYF_USER_FLAG_22
282 #define SPECENUM_VALUE57 UTYF_USER_FLAG_23
283 #define SPECENUM_VALUE58 UTYF_USER_FLAG_24
284 #define SPECENUM_VALUE59 UTYF_USER_FLAG_25
285 #define SPECENUM_VALUE60 UTYF_USER_FLAG_26
286 #define SPECENUM_VALUE61 UTYF_USER_FLAG_27
287 #define SPECENUM_VALUE62 UTYF_USER_FLAG_28
288 #define SPECENUM_VALUE63 UTYF_USER_FLAG_29
289 #define SPECENUM_VALUE64 UTYF_USER_FLAG_30
290 #define SPECENUM_VALUE65 UTYF_USER_FLAG_31
291 #define SPECENUM_VALUE66 UTYF_USER_FLAG_32
292 /* Note that first role must have value next to last flag */
293
294 #define UTYF_LAST_USER_FLAG UTYF_USER_FLAG_32
295 #define MAX_NUM_USER_UNIT_FLAGS (UTYF_LAST_USER_FLAG - UTYF_USER_FLAG_1 + 1)
296 #define SPECENUM_NAMEOVERRIDE
297 #define SPECENUM_BITVECTOR bv_unit_type_flags
298 #include "specenum_gen.h"
299
300
301 /* Unit "roles": these are similar to unit flags but differ in that
302 they don't represent intrinsic properties or abilities of units,
303 but determine which units are used (mainly by the server or AI)
304 in various circumstances, or "roles".
305 Note that in some cases flags can act as roles, eg, we don't need
306 a role for "settlers", because we can just use UTYF_SETTLERS.
307 (Now have to consider UTYF_CITIES too)
308 So we make sure flag values and role values are distinct,
309 so some functions can use them interchangably.
310 See data/classic/units.ruleset for documentation of their effects.
311 */
312 #define L_FIRST (UTYF_LAST_USER_FLAG + 1)
313
314 #define SPECENUM_NAME unit_role_id
315 /* is built first when city established */
316 #define SPECENUM_VALUE67 L_FIRSTBUILD
317 #define SPECENUM_VALUE67NAME N_("?unitflag:FirstBuild")
318 /* initial explorer unit */
319 #define SPECENUM_VALUE68 L_EXPLORER
320 #define SPECENUM_VALUE68NAME N_("?unitflag:Explorer")
321 /* can be found in hut */
322 #define SPECENUM_VALUE69 L_HUT
323 #define SPECENUM_VALUE69NAME N_("?unitflag:Hut")
324 /* can be found in hut, tech required */
325 #define SPECENUM_VALUE70 L_HUT_TECH
326 #define SPECENUM_VALUE70NAME N_("?unitflag:HutTech")
327 /* is created in Partisan circumstances */
328 #define SPECENUM_VALUE71 L_PARTISAN
329 #define SPECENUM_VALUE71NAME N_("?unitflag:Partisan")
330 /* ok on defense (AI) */
331 #define SPECENUM_VALUE72 L_DEFEND_OK
332 #define SPECENUM_VALUE72NAME N_("?unitflag:DefendOk")
333 /* primary purpose is defense (AI) */
334 #define SPECENUM_VALUE73 L_DEFEND_GOOD
335 #define SPECENUM_VALUE73NAME N_("?unitflag:DefendGood")
336 /* is useful for ferrying (AI) */
337 #define SPECENUM_VALUE74 L_FERRYBOAT
338 #define SPECENUM_VALUE74NAME N_("?unitflag:FerryBoat")
339 /* barbarians unit, land only */
340 #define SPECENUM_VALUE75 L_BARBARIAN
341 #define SPECENUM_VALUE75NAME N_("?unitflag:Barbarian")
342 /* barbarians unit, global tech required */
343 #define SPECENUM_VALUE76 L_BARBARIAN_TECH
344 #define SPECENUM_VALUE76NAME N_("?unitflag:BarbarianTech")
345 /* barbarian boat */
346 #define SPECENUM_VALUE77 L_BARBARIAN_BOAT
347 #define SPECENUM_VALUE77NAME N_("?unitflag:BarbarianBoat")
348 /* what barbarians should build */
349 #define SPECENUM_VALUE78 L_BARBARIAN_BUILD
350 #define SPECENUM_VALUE78NAME N_("?unitflag:BarbarianBuild")
351 /* barbarians build when global tech */
352 #define SPECENUM_VALUE79 L_BARBARIAN_BUILD_TECH
353 #define SPECENUM_VALUE79NAME N_("?unitflag:BarbarianBuildTech")
354 /* barbarian leader */
355 #define SPECENUM_VALUE80 L_BARBARIAN_LEADER
356 #define SPECENUM_VALUE80NAME N_("?unitflag:BarbarianLeader")
357 /* sea raider unit */
358 #define SPECENUM_VALUE81 L_BARBARIAN_SEA
359 #define SPECENUM_VALUE81NAME N_("?unitflag:BarbarianSea")
360 /* sea raider unit, global tech required */
361 #define SPECENUM_VALUE82 L_BARBARIAN_SEA_TECH
362 #define SPECENUM_VALUE82NAME N_("?unitflag:BarbarianSeaTech")
363 /* Startunit: Cities */
364 #define SPECENUM_VALUE83 L_START_CITIES
365 #define SPECENUM_VALUE83NAME N_("?unitflag:CitiesStartunit")
366 /* Startunit: Worker */
367 #define SPECENUM_VALUE84 L_START_WORKER
368 #define SPECENUM_VALUE84NAME N_("?unitflag:WorkerStartunit")
369 /* Startunit: Explorer */
370 #define SPECENUM_VALUE85 L_START_EXPLORER
371 #define SPECENUM_VALUE85NAME N_("?unitflag:ExplorerStartunit")
372 /* Startunit: King */
373 #define SPECENUM_VALUE86 L_START_KING
374 #define SPECENUM_VALUE86NAME N_("?unitflag:KingStartunit")
375 /* Startunit: Diplomat */
376 #define SPECENUM_VALUE87 L_START_DIPLOMAT
377 #define SPECENUM_VALUE87NAME N_("?unitflag:DiplomatStartunit")
378 /* Startunit: Ferryboat */
379 #define SPECENUM_VALUE88 L_START_FERRY
380 #define SPECENUM_VALUE88NAME N_("?unitflag:FerryStartunit")
381 /* Startunit: DefendOk */
382 #define SPECENUM_VALUE89 L_START_DEFEND_OK
383 #define SPECENUM_VALUE89NAME N_("?unitflag:DefendOkStartunit")
384 /* Startunit: DefendGood */
385 #define SPECENUM_VALUE90 L_START_DEFEND_GOOD
386 #define SPECENUM_VALUE90NAME N_("?unitflag:DefendGoodStartunit")
387 /* Startunit: AttackFast */
388 #define SPECENUM_VALUE91 L_START_ATTACK_FAST
389 #define SPECENUM_VALUE91NAME N_("?unitflag:AttackFastStartunit")
390 /* Startunit: AttackStrong */
391 #define SPECENUM_VALUE92 L_START_ATTACK_STRONG
392 #define SPECENUM_VALUE92NAME N_("?unitflag:AttackStrongStartunit")
393 /* AI hunter type unit */
394 #define SPECENUM_VALUE93 L_HUNTER
395 #define SPECENUM_VALUE93NAME N_("?unitflag:Hunter")
396 /* can improve terrain */
397 #define SPECENUM_VALUE94 L_SETTLERS
398 #define SPECENUM_VALUE94NAME N_("?unitflag:Settlers")
399 #define L_LAST (L_SETTLERS + 1)
400
401 #include "specenum_gen.h"
402
403 #define L_MAX 64 /* Used in the network protocol. */
404
405 FC_STATIC_ASSERT(L_LAST - L_FIRST <= L_MAX, too_many_unit_roles);
406
407 /* Used in the network protocol. */
408 BV_DEFINE(bv_unit_type_roles, L_MAX);
409
410 /* Used in the network protocol. */
411 #define SPECENUM_NAME combat_bonus_type
412 #define SPECENUM_VALUE0 CBONUS_DEFENSE_MULTIPLIER
413 #define SPECENUM_VALUE0NAME "DefenseMultiplier"
414 #define SPECENUM_VALUE1 CBONUS_DEFENSE_DIVIDER
415 #define SPECENUM_VALUE1NAME "DefenseDivider"
416 #define SPECENUM_VALUE2 CBONUS_FIREPOWER1
417 #define SPECENUM_VALUE2NAME "Firepower1"
418 #include "specenum_gen.h"
419
420 struct combat_bonus {
421 enum unit_type_flag_id flag;
422 enum combat_bonus_type type;
423 int value;
424
425 /* Not listed in the help text. */
426 bool quiet;
427 };
428
429 /* get 'struct combat_bonus_list' and related functions: */
430 #define SPECLIST_TAG combat_bonus
431 #define SPECLIST_TYPE struct combat_bonus
432 #include "speclist.h"
433
434 #define combat_bonus_list_iterate(bonuslist, pbonus) \
435 TYPED_LIST_ITERATE(struct combat_bonus, bonuslist, pbonus)
436 #define combat_bonus_list_iterate_end LIST_ITERATE_END
437
438 BV_DEFINE(bv_unit_types, U_LAST);
439
440 struct veteran_level {
441 struct name_translation name; /* level/rank name */
442 int power_fact; /* combat/work speed/diplomatic power factor (in %) */
443 int move_bonus;
444 int raise_chance; /* server only */
445 int work_raise_chance; /* server only */
446 };
447
448 struct veteran_system {
449 int levels;
450
451 struct veteran_level *definitions;
452 };
453
454 struct unit_type {
455 Unit_type_id item_number;
456 struct name_translation name;
457 bool disabled; /* Does not really exist - hole in units array */
458 char graphic_str[MAX_LEN_NAME];
459 char graphic_alt[MAX_LEN_NAME];
460 char sound_move[MAX_LEN_NAME];
461 char sound_move_alt[MAX_LEN_NAME];
462 char sound_fight[MAX_LEN_NAME];
463 char sound_fight_alt[MAX_LEN_NAME];
464 int build_cost; /* Use wrappers to access this. */
465 int pop_cost; /* number of workers the unit contains (e.g., settlers, engineers)*/
466 int attack_strength;
467 int defense_strength;
468 int move_rate;
469 int unknown_move_cost; /* See utype_unknown_move_cost(). */
470
471 struct advance *require_advance; /* may be NULL */
472 struct impr_type *need_improvement; /* may be NULL */
473 struct government *need_government; /* may be NULL */
474
475 int vision_radius_sq;
476 int transport_capacity;
477 int hp;
478 int firepower;
479 struct combat_bonus_list *bonuses;
480
481 #define U_NOT_OBSOLETED (NULL)
482 struct unit_type *obsoleted_by;
483 struct unit_type *converted_to;
484 int convert_time;
485 int fuel;
486
487 bv_unit_type_flags flags;
488 bv_unit_type_roles roles;
489
490 int happy_cost; /* unhappy people in home city */
491 int upkeep[O_LAST];
492
493 /* Only valid for UTYF_PARATROOPERS */
494 int paratroopers_range;
495 int paratroopers_mr_req;
496 int paratroopers_mr_sub;
497
498 /* Additional values for the expanded veteran system */
499 struct veteran_system *veteran;
500
501 /* Values for bombardment */
502 int bombard_rate;
503
504 /* Values for founding cities */
505 int city_size;
506
507 struct unit_class *uclass;
508
509 bv_unit_classes cargo;
510
511 /* Can attack these classes even if they are otherwise "Unreachable" */
512 bv_unit_classes targets;
513 /* Can load into these class transports at any location,
514 * even if they are otherwise "Unreachable". */
515 bv_unit_classes embarks;
516 /* Can unload from these class transports at any location,
517 * even if they are otherwise "Unreachable". */
518 bv_unit_classes disembarks;
519
520 struct strvec *helptext;
521
522 struct {
523 bool igwall;
524 } adv;
525
526 struct {
527 int max_defense_mp; /* Value 0 here does not guarantee that unit never
528 * has CBONUS_DEFENSE_MULTIPLIER, it merely means
529 * that there's no POSITIVE one */
530 int defense_mp_bonuses[U_LAST];
531 } cache;
532
533 void *ais[FREECIV_AI_MOD_LAST];
534 };
535
536 /* General unit and unit type (matched) routines */
537 Unit_type_id utype_count(void);
538 Unit_type_id utype_index(const struct unit_type *punittype);
539 Unit_type_id utype_number(const struct unit_type *punittype);
540
541 struct unit_type *unit_type_get(const struct unit *punit);
542 struct unit_type *utype_by_number(const Unit_type_id id);
543
544 struct unit_type *unit_type_by_rule_name(const char *name);
545 struct unit_type *unit_type_by_translated_name(const char *name);
546
547 const char *unit_rule_name(const struct unit *punit);
548 const char *utype_rule_name(const struct unit_type *punittype);
549
550 const char *unit_name_translation(const struct unit *punit);
551 const char *utype_name_translation(const struct unit_type *punittype);
552
553 const char *utype_values_string(const struct unit_type *punittype);
554 const char *utype_values_translation(const struct unit_type *punittype);
555
556 /* General unit type flag and role routines */
557 bool unit_has_type_flag(const struct unit *punit, enum unit_type_flag_id flag);
558
559 /**************************************************************************
560 Return whether the given unit type has the flag.
561 **************************************************************************/
utype_has_flag(const struct unit_type * punittype,int flag)562 static inline bool utype_has_flag(const struct unit_type *punittype, int flag)
563 {
564 return BV_ISSET(punittype->flags, flag);
565 }
566
567 bool unit_has_type_role(const struct unit *punit, enum unit_role_id role);
568 bool utype_has_role(const struct unit_type *punittype, int role);
569
570 void user_unit_type_flags_init(void);
571 void set_user_unit_type_flag_name(enum unit_type_flag_id id, const char *name,
572 const char *helptxt);
573 const char *unit_type_flag_helptxt(enum unit_type_flag_id id);
574
575 bool unit_can_take_over(const struct unit *punit);
576 bool utype_can_take_over(const struct unit_type *punittype);
577
578 bool utype_can_freely_load(const struct unit_type *pcargotype,
579 const struct unit_type *ptranstype);
580 bool utype_can_freely_unload(const struct unit_type *pcargotype,
581 const struct unit_type *ptranstype);
582
583 bool utype_may_act_at_all(const struct unit_type *putype);
584 bool utype_can_do_action(const struct unit_type *putype,
585 const int act_id);
586 bool utype_acts_hostile(const struct unit_type *putype);
587
588 bool can_unit_act_when_ustate_is(const struct unit_type *punit_type,
589 const enum ustate_prop prop,
590 const bool is_there);
591 bool utype_can_do_act_when_ustate(const struct unit_type *punit_type,
592 const int act_id,
593 const enum ustate_prop prop,
594 const bool is_there);
595
596 bool can_utype_do_act_if_tgt_diplrel(const struct unit_type *punit_type,
597 const int act_id,
598 const int prop,
599 const bool is_there);
600
601 bool utype_may_act_move_frags(struct unit_type *punit_type,
602 const int act_id,
603 const int move_fragments);
604
605 /* Functions to operate on various flag and roles. */
606 typedef bool (*role_unit_callback)(struct unit_type *ptype, void *data);
607
608 void role_unit_precalcs(void);
609 void role_unit_precalcs_free(void);
610 int num_role_units(int role);
611 struct unit_type *role_units_iterate(int role, role_unit_callback cb, void *data);
612 struct unit_type *role_units_iterate_backwards(int role, role_unit_callback cb, void *data);
613 struct unit_type *get_role_unit(int role, int role_index);
614 struct unit_type *best_role_unit(const struct city *pcity, int role);
615 struct unit_type *best_role_unit_for_player(const struct player *pplayer,
616 int role);
617 struct unit_type *first_role_unit_for_player(const struct player *pplayer,
618 int role);
619 bool role_units_translations(struct astring *astr, int flag, bool alts);
620
621 /* General unit class routines */
622 Unit_Class_id uclass_count(void);
623 Unit_Class_id uclass_number(const struct unit_class *pclass);
624 /* Optimised to be identical to uclass_number: the implementation
625 * unittype.c is also semantically correct. */
626 #define uclass_index(_c_) (_c_)->item_number
627 #ifndef uclass_index
628 Unit_Class_id uclass_index(const struct unit_class *pclass);
629 #endif /* uclass_index */
630
631 struct unit_class *unit_class_get(const struct unit *punit);
632 struct unit_class *uclass_by_number(const Unit_Class_id id);
633 #define utype_class(_t_) (_t_)->uclass
634 #ifndef utype_class
635 struct unit_class *utype_class(const struct unit_type *punittype);
636 #endif /* utype_class */
637
638 struct unit_class *unit_class_by_rule_name(const char *s);
639
640 const char *uclass_rule_name(const struct unit_class *pclass);
641 const char *uclass_name_translation(const struct unit_class *pclass);
642
643 /**************************************************************************
644 Return whether the given unit class has the flag.
645 **************************************************************************/
uclass_has_flag(const struct unit_class * punitclass,enum unit_class_flag_id flag)646 static inline bool uclass_has_flag(const struct unit_class *punitclass,
647 enum unit_class_flag_id flag)
648 {
649 return BV_ISSET(punitclass->flags, flag);
650 }
651
652 /* Ancillary routines */
653 int unit_build_shield_cost(const struct unit *punit);
654 int utype_build_shield_cost(const struct unit_type *punittype);
655
656 int utype_buy_gold_cost(const struct unit_type *punittype,
657 int shields_in_stock);
658
659 const struct veteran_system *
660 utype_veteran_system(const struct unit_type *punittype);
661 int utype_veteran_levels(const struct unit_type *punittype);
662 const struct veteran_level *
663 utype_veteran_level(const struct unit_type *punittype, int level);
664 const char *utype_veteran_name_translation(const struct unit_type *punittype,
665 int level);
666 bool utype_veteran_has_power_bonus(const struct unit_type *punittype);
667
668 struct veteran_system *veteran_system_new(int count);
669 void veteran_system_destroy(struct veteran_system *vsystem);
670 void veteran_system_definition(struct veteran_system *vsystem, int level,
671 const char *vlist_name, int vlist_power,
672 int vlist_move, int vlist_raise,
673 int vlist_wraise);
674
675 int unit_disband_shields(const struct unit *punit);
676 int utype_disband_shields(const struct unit_type *punittype);
677
678 int unit_pop_value(const struct unit *punit);
679 int utype_pop_value(const struct unit_type *punittype);
680
681 enum unit_move_type utype_move_type(const struct unit_type *punittype);
682 void set_unit_move_type(struct unit_class *puclass);
683
684 /* player related unit functions */
685 int utype_upkeep_cost(const struct unit_type *ut, struct player *pplayer,
686 Output_type_id otype);
687 int utype_happy_cost(const struct unit_type *ut, const struct player *pplayer);
688
689 struct unit_type *can_upgrade_unittype(const struct player *pplayer,
690 struct unit_type *punittype);
691 int unit_upgrade_price(const struct player *pplayer,
692 const struct unit_type *from,
693 const struct unit_type *to);
694
695 bool utype_player_already_has_this(const struct player *pplayer,
696 const struct unit_type *putype);
697 bool utype_player_already_has_this_unique(const struct player *pplayer,
698 const struct unit_type *putype);
699
700 bool can_player_build_unit_direct(const struct player *p,
701 const struct unit_type *punittype);
702 bool can_player_build_unit_later(const struct player *p,
703 const struct unit_type *punittype);
704 bool can_player_build_unit_now(const struct player *p,
705 const struct unit_type *punittype);
706
707 #define utype_fuel(ptype) (ptype)->fuel
708
709 bool utype_is_cityfounder(struct unit_type *utype);
710
711 /* Initialization and iteration */
712 void unit_types_init(void);
713 void unit_types_free(void);
714 void unit_type_flags_free(void);
715
716 struct unit_type *unit_type_array_first(void);
717 const struct unit_type *unit_type_array_last(void);
718
719 #define unit_type_iterate(_p) \
720 { \
721 struct unit_type *_p = unit_type_array_first(); \
722 if (NULL != _p) { \
723 for (; _p <= unit_type_array_last(); _p++) {
724
725 #define unit_type_iterate_end \
726 } \
727 } \
728 }
729
730 #define unit_active_type_iterate(_p) \
731 unit_type_iterate(_p) { \
732 if (!_p->disabled) {
733
734 #define unit_active_type_iterate_end \
735 } \
736 } unit_type_iterate_end;
737
738
739 void *utype_ai_data(const struct unit_type *ptype, const struct ai_type *ai);
740 void utype_set_ai_data(struct unit_type *ptype, const struct ai_type *ai,
741 void *data);
742
743 void unit_type_action_cache_set(struct unit_type *ptype);
744 void unit_type_action_cache_init(void);
745
746 /* Initialization and iteration */
747 void unit_classes_init(void);
748 void unit_classes_free(void);
749
750 void set_unit_class_caches(struct unit_class *pclass);
751 void set_unit_type_caches(struct unit_type *ptype);
752
753 struct unit_class *unit_class_array_first(void);
754 const struct unit_class *unit_class_array_last(void);
755
756 #define unit_class_iterate(_p) \
757 { \
758 struct unit_class *_p = unit_class_array_first(); \
759 if (NULL != _p) { \
760 for (; _p <= unit_class_array_last(); _p++) {
761
762 #define unit_class_iterate_end \
763 } \
764 } \
765 }
766
767 #define SPECLIST_TAG unit_class
768 #define SPECLIST_TYPE struct unit_class
769 #include "speclist.h"
770
771 #define unit_class_list_iterate(uclass_list, pclass) \
772 TYPED_LIST_ITERATE(struct unit_class, uclass_list, pclass)
773 #define unit_class_list_iterate_end LIST_ITERATE_END
774
775 #define SPECLIST_TAG unit_type
776 #define SPECLIST_TYPE struct unit_type
777 #include "speclist.h"
778
779 #define unit_type_list_iterate(utype_list, ptype) \
780 TYPED_LIST_ITERATE(struct unit_type, utype_list, ptype)
781 #define unit_type_list_iterate_end LIST_ITERATE_END
782
783 #ifdef __cplusplus
784 }
785 #endif /* __cplusplus */
786
787 #endif /* FC__UNITTYPE_H */
788