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)
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
18 #endif /* __cplusplus */
21 #include "bitvector.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". */
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
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
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
;
132 Unit_Class_id item_number
;
133 struct name_translation name
;
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
;
145 enum move_level land_move
;
146 enum move_level sea_move
;
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
;
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
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")
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
;
445 /* Not listed in the help text. */
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 %) */
464 int raise_chance
; /* server only */
465 int work_raise_chance
; /* server only */
468 struct veteran_system
{
471 struct veteran_level
*definitions
;
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)*/
487 int defense_strength
;
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
;
499 struct combat_bonus_list
*bonuses
;
501 #define U_NOT_OBSOLETED (NULL)
502 struct unit_type
*obsoleted_by
;
503 struct unit_type
*converted_to
;
507 bv_unit_type_flags flags
;
508 bv_unit_type_roles roles
;
510 int happy_cost
; /* unhappy people in home city */
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 */
524 /* Values for founding cities */
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
;
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
];
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
,
615 const enum ustate_prop prop
,
616 const bool is_there
);
618 bool utype_can_do_act_if_tgt_citytile(const struct unit_type
*punit_type
,
620 const enum citytile_type prop
,
621 const bool is_there
);
623 bool can_utype_do_act_if_tgt_diplrel(const struct unit_type
*punit_type
,
626 const bool is_there
);
628 bool utype_may_act_move_frags(struct unit_type
*punit_type
,
630 const int move_fragments
);
632 bool utype_may_act_tgt_city_tile(struct unit_type
*punit_type
,
634 const enum citytile_type prop
,
635 const bool is_there
);
637 bool utype_is_consumed_by_action(const struct action
*paction
,
638 const struct unit_type
*utype
);
640 /* Functions to operate on various flag and roles. */
641 typedef bool (*role_unit_callback
)(struct unit_type
*ptype
, void *data
);
643 void role_unit_precalcs(void);
644 void role_unit_precalcs_free(void);
645 int num_role_units(int role
);
646 struct unit_type
*role_units_iterate(int role
, role_unit_callback cb
, void *data
);
647 struct unit_type
*role_units_iterate_backwards(int role
, role_unit_callback cb
, void *data
);
648 struct unit_type
*get_role_unit(int role
, int role_index
);
649 struct unit_type
*best_role_unit(const struct city
*pcity
, int role
);
650 struct unit_type
*best_role_unit_for_player(const struct player
*pplayer
,
652 struct unit_type
*first_role_unit_for_player(const struct player
*pplayer
,
654 bool role_units_translations(struct astring
*astr
, int flag
, bool alts
);
656 /* General unit class routines */
657 Unit_Class_id
uclass_count(void);
658 Unit_Class_id
uclass_number(const struct unit_class
*pclass
);
659 /* Optimised to be identical to uclass_number: the implementation
660 * unittype.c is also semantically correct. */
661 #define uclass_index(_c_) (_c_)->item_number
663 Unit_Class_id
uclass_index(const struct unit_class
*pclass
);
664 #endif /* uclass_index */
666 struct unit_class
*unit_class_get(const struct unit
*punit
);
667 struct unit_class
*uclass_by_number(const Unit_Class_id id
);
668 #define utype_class(_t_) (_t_)->uclass
670 struct unit_class
*utype_class(const struct unit_type
*punittype
);
671 #endif /* utype_class */
673 struct unit_class
*unit_class_by_rule_name(const char *s
);
675 const char *uclass_rule_name(const struct unit_class
*pclass
);
676 const char *uclass_name_translation(const struct unit_class
*pclass
);
678 /**************************************************************************
679 Return whether the given unit class has the flag.
680 **************************************************************************/
681 static inline bool uclass_has_flag(const struct unit_class
*punitclass
,
682 enum unit_class_flag_id flag
)
684 return BV_ISSET(punitclass
->flags
, flag
);
687 void user_unit_class_flags_init(void);
688 void set_user_unit_class_flag_name(enum unit_class_flag_id id
,
690 const char *helptxt
);
691 const char *unit_class_flag_helptxt(enum unit_class_flag_id id
);
693 /* Ancillary routines */
694 int unit_build_shield_cost(const struct unit
*punit
);
695 int utype_build_shield_cost(const struct unit_type
*punittype
);
697 int utype_buy_gold_cost(const struct unit_type
*punittype
,
698 int shields_in_stock
);
700 const struct veteran_system
*
701 utype_veteran_system(const struct unit_type
*punittype
);
702 int utype_veteran_levels(const struct unit_type
*punittype
);
703 const struct veteran_level
*
704 utype_veteran_level(const struct unit_type
*punittype
, int level
);
705 const char *utype_veteran_name_translation(const struct unit_type
*punittype
,
707 bool utype_veteran_has_power_bonus(const struct unit_type
*punittype
);
709 struct veteran_system
*veteran_system_new(int count
);
710 void veteran_system_destroy(struct veteran_system
*vsystem
);
711 void veteran_system_definition(struct veteran_system
*vsystem
, int level
,
712 const char *vlist_name
, int vlist_power
,
713 int vlist_move
, int vlist_raise
,
716 int unit_disband_shields(const struct unit
*punit
);
717 int utype_disband_shields(const struct unit_type
*punittype
);
719 int unit_pop_value(const struct unit
*punit
);
720 int utype_pop_value(const struct unit_type
*punittype
);
722 enum unit_move_type
utype_move_type(const struct unit_type
*punittype
);
723 void set_unit_move_type(struct unit_class
*puclass
);
725 /* player related unit functions */
726 int utype_upkeep_cost(const struct unit_type
*ut
, struct player
*pplayer
,
727 Output_type_id otype
);
728 int utype_happy_cost(const struct unit_type
*ut
, const struct player
*pplayer
);
730 struct unit_type
*can_upgrade_unittype(const struct player
*pplayer
,
731 struct unit_type
*punittype
);
732 int unit_upgrade_price(const struct player
*pplayer
,
733 const struct unit_type
*from
,
734 const struct unit_type
*to
);
736 bool utype_player_already_has_this_unique(const struct player
*pplayer
,
737 const struct unit_type
*putype
);
739 bool can_player_build_unit_direct(const struct player
*p
,
740 const struct unit_type
*punittype
);
741 bool can_player_build_unit_later(const struct player
*p
,
742 const struct unit_type
*punittype
);
743 bool can_player_build_unit_now(const struct player
*p
,
744 const struct unit_type
*punittype
);
746 #define utype_fuel(ptype) (ptype)->fuel
748 bool utype_is_cityfounder(struct unit_type
*utype
);
750 /* Initialization and iteration */
751 void unit_types_init(void);
752 void unit_types_free(void);
753 void unit_type_flags_free(void);
754 void unit_class_flags_free(void);
756 struct unit_type
*unit_type_array_first(void);
757 const struct unit_type
*unit_type_array_last(void);
759 #define unit_type_iterate(_p) \
761 struct unit_type *_p = unit_type_array_first(); \
763 for (; _p <= unit_type_array_last(); _p++) {
765 #define unit_type_iterate_end \
770 #define unit_active_type_iterate(_p) \
771 unit_type_iterate(_p) { \
774 #define unit_active_type_iterate_end \
776 } unit_type_iterate_end;
779 void *utype_ai_data(const struct unit_type
*ptype
, const struct ai_type
*ai
);
780 void utype_set_ai_data(struct unit_type
*ptype
, const struct ai_type
*ai
,
783 void unit_type_action_cache_set(struct unit_type
*ptype
);
784 void unit_type_action_cache_init(void);
786 /* Initialization and iteration */
787 void unit_classes_init(void);
788 void unit_classes_free(void);
790 void set_unit_class_caches(struct unit_class
*pclass
);
791 void set_unit_type_caches(struct unit_type
*ptype
);
793 struct unit_class
*unit_class_array_first(void);
794 const struct unit_class
*unit_class_array_last(void);
796 #define unit_class_iterate(_p) \
798 struct unit_class *_p = unit_class_array_first(); \
800 for (; _p <= unit_class_array_last(); _p++) {
802 #define unit_class_iterate_end \
807 #define unit_active_class_iterate(_p) \
808 unit_class_iterate(_p) { \
811 #define unit_active_class_iterate_end \
813 } unit_class_iterate_end;
815 #define SPECLIST_TAG unit_class
816 #define SPECLIST_TYPE struct unit_class
817 #include "speclist.h"
819 #define unit_class_list_iterate(uclass_list, pclass) \
820 TYPED_LIST_ITERATE(struct unit_class, uclass_list, pclass)
821 #define unit_class_list_iterate_end LIST_ITERATE_END
823 #define SPECLIST_TAG unit_type
824 #define SPECLIST_TYPE struct unit_type
825 #include "speclist.h"
827 #define unit_type_list_iterate(utype_list, ptype) \
828 TYPED_LIST_ITERATE(struct unit_type, utype_list, ptype)
829 #define unit_type_list_iterate_end LIST_ITERATE_END
833 #endif /* __cplusplus */
835 #endif /* FC__UNITTYPE_H */