Freeciv21
Develop your civilization from humble roots to a global empire
unittype.h
Go to the documentation of this file.
1 /*__ ___ ***************************************
2 / \ / \ Copyright (c) 1996-2020 Freeciv21 and Freeciv
3 \_ \ / __/ contributors. This file is part of Freeciv21.
4  _\ \ / /__ Freeciv21 is free software: you can redistribute it
5  \___ \____/ __/ and/or modify it under the terms of the GNU General
6  \_ _/ Public License as published by the Free Software
7  | @ @ \_ Foundation, either version 3 of the License,
8  | or (at your option) any later version.
9  _/ /\ You should have received a copy of the GNU
10  /o) (o/\ \_ General Public License along with Freeciv21.
11  \_____/ / If not, see https://www.gnu.org/licenses/.
12  \____/ ********************************************************/
13 #pragma once
14 
15 // utility
16 #include "bitvector.h"
17 #include "shared.h"
18 
19 // common
20 #include "fc_types.h"
21 #include "name_translation.h"
22 #include "requirements.h"
23 
24 struct ai_type;
25 
26 /* U_LAST is a value which is guaranteed to be larger than all
27  * actual Unit_type_id values. It is used as a flag value;
28  * it can also be used for fixed allocations to ensure able
29  * to hold full number of unit types.
30  * Used in the network protocol. */
31 #define U_LAST MAX_NUM_UNIT_TYPES
32 
33 /* The largest distance a ruleset can allow a unit to paradrop.
34  *
35  * Remember to make sure that the field type of PACKET_RULESET_UNIT's
36  * paratroopers_range field can transfer the new maximum if you increase
37  * it.
38  *
39  * The top value is reserved in case a future Freeciv21 version wants to
40  * implement "no maximum range". It could be used to signal that the unit
41  * can paradrop anywhere. Note that the value below it is high enough to
42  * give the same effect on all maps inside the current size limits.
43  * (No map side can be larger than MAP_MAX_LINEAR_SIZE)
44  */
45 #define UNIT_MAX_PARADROP_RANGE (65535 - 1)
46 
47 // Used in the network protocol.
48 #define SPECENUM_NAME unit_class_flag_id
49 #define SPECENUM_VALUE0 UCF_TERRAIN_SPEED
50 #define SPECENUM_VALUE0NAME N_("?uclassflag:TerrainSpeed")
51 #define SPECENUM_VALUE1 UCF_TERRAIN_DEFENSE
52 #define SPECENUM_VALUE1NAME N_("?uclassflag:TerrainDefense")
53 #define SPECENUM_VALUE2 UCF_DAMAGE_SLOWS
54 #define SPECENUM_VALUE2NAME N_("?uclassflag:DamageSlows")
55 // Can occupy enemy cities
56 #define SPECENUM_VALUE3 UCF_CAN_OCCUPY_CITY
57 #define SPECENUM_VALUE3NAME N_("?uclassflag:CanOccupyCity")
58 #define SPECENUM_VALUE4 UCF_BUILD_ANYWHERE
59 #define SPECENUM_VALUE4NAME N_("?uclassflag:BuildAnywhere")
60 #define SPECENUM_VALUE5 UCF_UNREACHABLE
61 #define SPECENUM_VALUE5NAME N_("?uclassflag:Unreachable")
62 // Can collect ransom from barbarian leader
63 #define SPECENUM_VALUE6 UCF_COLLECT_RANSOM
64 #define SPECENUM_VALUE6NAME N_("?uclassflag:CollectRansom")
65 // Is subject to ZOC
66 #define SPECENUM_VALUE7 UCF_ZOC
67 #define SPECENUM_VALUE7NAME N_("?uclassflag:ZOC")
68 // Cities can still work tile when enemy unit on it
69 #define SPECENUM_VALUE8 UCF_DOESNT_OCCUPY_TILE
70 #define SPECENUM_VALUE8NAME N_("?uclassflag:DoesntOccupyTile")
71 // Can attack against units on non-native tiles
72 #define SPECENUM_VALUE9 UCF_ATTACK_NON_NATIVE
73 #define SPECENUM_VALUE9NAME N_("?uclassflag:AttackNonNative")
74 // Kills citizens upon successful attack against a city
75 #define SPECENUM_VALUE10 UCF_KILLCITIZEN
76 #define SPECENUM_VALUE10NAME N_("?uclassflag:KillCitizen")
77 
78 #define SPECENUM_VALUE11 UCF_USER_FLAG_1
79 #define SPECENUM_VALUE12 UCF_USER_FLAG_2
80 #define SPECENUM_VALUE13 UCF_USER_FLAG_3
81 #define SPECENUM_VALUE14 UCF_USER_FLAG_4
82 #define SPECENUM_VALUE15 UCF_USER_FLAG_5
83 #define SPECENUM_VALUE16 UCF_USER_FLAG_6
84 #define SPECENUM_VALUE17 UCF_USER_FLAG_7
85 #define SPECENUM_VALUE18 UCF_USER_FLAG_8
86 #define SPECENUM_VALUE19 UCF_USER_FLAG_9
87 #define SPECENUM_VALUE20 UCF_USER_FLAG_10
88 #define SPECENUM_VALUE21 UCF_USER_FLAG_11
89 #define SPECENUM_VALUE22 UCF_USER_FLAG_12
90 
91 // keep this last
92 #define SPECENUM_COUNT UCF_COUNT
93 #define SPECENUM_NAMEOVERRIDE
94 #define SPECENUM_BITVECTOR bv_unit_class_flags
95 #include "specenum_gen.h"
96 
97 #define UCF_LAST_USER_FLAG UCF_USER_FLAG_12
98 #define MAX_NUM_USER_UCLASS_FLAGS (UCF_LAST_USER_FLAG - UCF_USER_FLAG_1 + 1)
99 
100 // Used in savegame processing and clients.
101 #define SPECENUM_NAME unit_move_type
102 #define SPECENUM_VALUE0 UMT_LAND
103 #define SPECENUM_VALUE0NAME "Land"
104 #define SPECENUM_VALUE1 UMT_SEA
105 #define SPECENUM_VALUE1NAME "Sea"
106 #define SPECENUM_VALUE2 UMT_BOTH
107 #define SPECENUM_VALUE2NAME "Both"
108 #include "specenum_gen.h"
109 
110 // Used in the network protocol.
111 BV_DEFINE(bv_unit_classes, UCL_LAST);
112 
114 
116 
117 struct extra_type_list;
118 struct unit_class_list;
119 
120 struct unit_class {
122  struct name_translation name;
124  enum unit_move_type move_type;
125  int min_speed; // Minimum speed after damage and effects
126  int hp_loss_pct; /* Percentage of hitpoints lost each turn not in city or
127  airbase */
130  bv_unit_class_flags flags;
131 
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 // Feel free to take this.
158 #define SPECENUM_VALUE0 UTYF_RESERVED_2
159 #define SPECENUM_VALUE0NAME N_("Reserved 2")
160 // Unit has no ZOC
161 #define SPECENUM_VALUE1 UTYF_NOZOC
162 #define SPECENUM_VALUE1NAME N_("?unitflag:HasNoZOC")
163 #define SPECENUM_VALUE2 UTYF_IGZOC
164 // TRANS: unit type flag (rarely shown): "ignore zones of control"
165 #define SPECENUM_VALUE2NAME N_("?unitflag:IgZOC")
166 #define SPECENUM_VALUE3 UTYF_CIVILIAN
167 #define SPECENUM_VALUE3NAME N_("?unitflag:NonMil")
168 #define SPECENUM_VALUE4 UTYF_IGTER
169 // TRANS: unit type flag (rarely shown): "ignore terrain"
170 #define SPECENUM_VALUE4NAME N_("?unitflag:IgTer")
171 #define SPECENUM_VALUE5 UTYF_ONEATTACK
172 #define SPECENUM_VALUE5NAME N_("?unitflag:OneAttack")
173 #define SPECENUM_VALUE6 UTYF_FIELDUNIT
174 #define SPECENUM_VALUE6NAME N_("?unitflag:FieldUnit")
175 /* autoattack: a unit will choose to attack this unit even if defending
176  * against it has better odds. */
177 #define SPECENUM_VALUE7 UTYF_PROVOKING
178 #define SPECENUM_VALUE7NAME N_("?unitflag:Provoking")
179 // Overrides unreachable_protects server setting
180 #define SPECENUM_VALUE8 UTYF_NEVER_PROTECTS
181 #define SPECENUM_VALUE8NAME N_("?unitflag:NeverProtects")
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 // Can't leave the coast
188 #define SPECENUM_VALUE11 UTYF_COAST_STRICT
189 #define SPECENUM_VALUE11NAME N_("?unitflag:CoastStrict")
190 // Can 'refuel' at coast - meaningless if fuel value not set
191 #define SPECENUM_VALUE12 UTYF_COAST
192 #define SPECENUM_VALUE12NAME N_("?unitflag:Coast")
193 // upkeep can switch from shield to gold
194 #define SPECENUM_VALUE13 UTYF_SHIELD2GOLD
195 #define SPECENUM_VALUE13NAME N_("?unitflag:Shield2Gold")
196 // Strong in diplomatic battles.
197 #define SPECENUM_VALUE14 UTYF_SPY
198 #define SPECENUM_VALUE14NAME N_("?unitflag:Spy")
199 // Cannot attack vs non-native tiles even if class can
200 #define SPECENUM_VALUE15 UTYF_ONLY_NATIVE_ATTACK
201 #define SPECENUM_VALUE15NAME N_("?unitflag:Only_Native_Attack")
202 // Only Fundamentalist government can build these units
203 #define SPECENUM_VALUE16 UTYF_FANATIC
204 #define SPECENUM_VALUE16NAME N_("?unitflag:Fanatic")
205 // Losing this unit means losing the game
206 #define SPECENUM_VALUE17 UTYF_GAMELOSS
207 #define SPECENUM_VALUE17NAME N_("?unitflag:GameLoss")
208 // A player can only have one unit of this type
209 #define SPECENUM_VALUE18 UTYF_UNIQUE
210 #define SPECENUM_VALUE18NAME N_("?unitflag:Unique")
211 /* When a transport containing this unit disappears the game will try to
212  * rescue units with this flag before it tries to rescue units without
213  * it. */
214 #define SPECENUM_VALUE19 UTYF_EVAC_FIRST
215 #define SPECENUM_VALUE19NAME N_("?unitflag:EvacuateFirst")
216 // Always wins diplomatic contests
217 #define SPECENUM_VALUE20 UTYF_SUPERSPY
218 #define SPECENUM_VALUE20NAME N_("?unitflag:SuperSpy")
219 // Has no homecity
220 #define SPECENUM_VALUE21 UTYF_NOHOME
221 #define SPECENUM_VALUE21NAME N_("?unitflag:NoHome")
222 // Cannot increase veteran level
223 #define SPECENUM_VALUE22 UTYF_NO_VETERAN
224 #define SPECENUM_VALUE22NAME N_("?unitflag:NoVeteran")
225 // Gets double firepower against cities
226 #define SPECENUM_VALUE23 UTYF_CITYBUSTER
227 #define SPECENUM_VALUE23NAME N_("?unitflag:CityBuster")
228 // Unit cannot be built (barb leader etc)
229 #define SPECENUM_VALUE24 UTYF_NOBUILD
230 #define SPECENUM_VALUE24NAME N_("?unitflag:NoBuild")
231 /* Firepower set to 1 when EFT_DEFEND_BONUS applies
232  * (for example, land unit attacking city with walls) */
233 #define SPECENUM_VALUE25 UTYF_BADWALLATTACKER
234 #define SPECENUM_VALUE25NAME N_("?unitflag:BadWallAttacker")
235 // Firepower set to 1 and attackers x2 when in city
236 #define SPECENUM_VALUE26 UTYF_BADCITYDEFENDER
237 #define SPECENUM_VALUE26NAME N_("?unitflag:BadCityDefender")
238 // Only barbarians can build this unit
239 #define SPECENUM_VALUE27 UTYF_BARBARIAN_ONLY
240 #define SPECENUM_VALUE27NAME N_("?unitflag:BarbarianOnly")
241 // Feel free to take this.
242 #define SPECENUM_VALUE28 UTYF_RESERVED_1
243 #define SPECENUM_VALUE28NAME N_("Reserved 1")
244 /* Unit can't be built in scenarios where founding new cities is prevented.
245  */
246 #define SPECENUM_VALUE29 UTYF_NEWCITY_GAMES_ONLY
247 #define SPECENUM_VALUE29NAME N_("?unitflag:NewCityGamesOnly")
248 // Can escape when killstack occours
249 #define SPECENUM_VALUE30 UTYF_CANESCAPE
250 #define SPECENUM_VALUE30NAME N_("?unitflag:CanEscape")
251 // Can kill escaping units
252 #define SPECENUM_VALUE31 UTYF_CANKILLESCAPING
253 #define SPECENUM_VALUE31NAME N_("?unitflag:CanKillEscaping")
254 
255 #define SPECENUM_VALUE32 UTYF_USER_FLAG_1
256 #define SPECENUM_VALUE33 UTYF_USER_FLAG_2
257 #define SPECENUM_VALUE34 UTYF_USER_FLAG_3
258 #define SPECENUM_VALUE35 UTYF_USER_FLAG_4
259 #define SPECENUM_VALUE36 UTYF_USER_FLAG_5
260 #define SPECENUM_VALUE37 UTYF_USER_FLAG_6
261 #define SPECENUM_VALUE38 UTYF_USER_FLAG_7
262 #define SPECENUM_VALUE39 UTYF_USER_FLAG_8
263 #define SPECENUM_VALUE40 UTYF_USER_FLAG_9
264 #define SPECENUM_VALUE41 UTYF_USER_FLAG_10
265 #define SPECENUM_VALUE42 UTYF_USER_FLAG_11
266 #define SPECENUM_VALUE43 UTYF_USER_FLAG_12
267 #define SPECENUM_VALUE44 UTYF_USER_FLAG_13
268 #define SPECENUM_VALUE45 UTYF_USER_FLAG_14
269 #define SPECENUM_VALUE46 UTYF_USER_FLAG_15
270 #define SPECENUM_VALUE47 UTYF_USER_FLAG_16
271 #define SPECENUM_VALUE48 UTYF_USER_FLAG_17
272 #define SPECENUM_VALUE49 UTYF_USER_FLAG_18
273 #define SPECENUM_VALUE50 UTYF_USER_FLAG_19
274 #define SPECENUM_VALUE51 UTYF_USER_FLAG_20
275 #define SPECENUM_VALUE52 UTYF_USER_FLAG_21
276 #define SPECENUM_VALUE53 UTYF_USER_FLAG_22
277 #define SPECENUM_VALUE54 UTYF_USER_FLAG_23
278 #define SPECENUM_VALUE55 UTYF_USER_FLAG_24
279 #define SPECENUM_VALUE56 UTYF_USER_FLAG_25
280 #define SPECENUM_VALUE57 UTYF_USER_FLAG_26
281 #define SPECENUM_VALUE58 UTYF_USER_FLAG_27
282 #define SPECENUM_VALUE59 UTYF_USER_FLAG_28
283 #define SPECENUM_VALUE60 UTYF_USER_FLAG_29
284 #define SPECENUM_VALUE61 UTYF_USER_FLAG_30
285 #define SPECENUM_VALUE62 UTYF_USER_FLAG_31
286 #define SPECENUM_VALUE63 UTYF_USER_FLAG_32
287 #define SPECENUM_VALUE64 UTYF_USER_FLAG_33
288 #define SPECENUM_VALUE65 UTYF_USER_FLAG_34
289 #define SPECENUM_VALUE66 UTYF_USER_FLAG_35
290 #define SPECENUM_VALUE67 UTYF_USER_FLAG_36
291 #define SPECENUM_VALUE68 UTYF_USER_FLAG_37
292 #define SPECENUM_VALUE69 UTYF_USER_FLAG_38
293 #define SPECENUM_VALUE70 UTYF_USER_FLAG_39
294 #define SPECENUM_VALUE71 UTYF_USER_FLAG_40
295 #define SPECENUM_VALUE72 UTYF_USER_FLAG_41
296 #define SPECENUM_VALUE73 UTYF_USER_FLAG_42
297 #define SPECENUM_VALUE74 UTYF_USER_FLAG_43
298 #define SPECENUM_VALUE75 UTYF_USER_FLAG_44
299 #define SPECENUM_VALUE76 UTYF_USER_FLAG_45
300 // Note that first role must have value next to last flag
301 
302 #define UTYF_LAST_USER_FLAG UTYF_USER_FLAG_45
303 #define MAX_NUM_USER_UNIT_FLAGS (UTYF_LAST_USER_FLAG - UTYF_USER_FLAG_1 + 1)
304 #define SPECENUM_NAMEOVERRIDE
305 #define SPECENUM_BITVECTOR bv_unit_type_flags
306 #include "specenum_gen.h"
307 
308 /* Unit "roles": these are similar to unit flags but differ in that
309  they don't represent intrinsic properties or abilities of units,
310  but determine which units are used (mainly by the server or AI)
311  in various circumstances, or "roles".
312  Note that in some cases flags can act as roles, eg, we don't need
313  a role for "settlers", because we can just use UTYF_SETTLERS.
314  (Now have to consider ACTION_FOUND_CITY too)
315  So we make sure flag values and role values are distinct,
316  so some functions can use them interchangably.
317  See data/classic/units.ruleset for documentation of their effects.
318 */
319 #define L_FIRST (UTYF_LAST_USER_FLAG + 1)
320 
321 #define SPECENUM_NAME unit_role_id
322 // is built first when city established
323 #define SPECENUM_VALUE77 L_FIRSTBUILD
324 #define SPECENUM_VALUE77NAME N_("?unitflag:FirstBuild")
325 // initial explorer unit
326 #define SPECENUM_VALUE78 L_EXPLORER
327 #define SPECENUM_VALUE78NAME N_("?unitflag:Explorer")
328 // can be found in hut
329 #define SPECENUM_VALUE79 L_HUT
330 #define SPECENUM_VALUE79NAME N_("?unitflag:Hut")
331 // can be found in hut, tech required
332 #define SPECENUM_VALUE80 L_HUT_TECH
333 #define SPECENUM_VALUE80NAME N_("?unitflag:HutTech")
334 // is created in Partisan circumstances
335 #define SPECENUM_VALUE81 L_PARTISAN
336 #define SPECENUM_VALUE81NAME N_("?unitflag:Partisan")
337 // ok on defense (AI)
338 #define SPECENUM_VALUE82 L_DEFEND_OK
339 #define SPECENUM_VALUE82NAME N_("?unitflag:DefendOk")
340 // primary purpose is defense (AI)
341 #define SPECENUM_VALUE83 L_DEFEND_GOOD
342 #define SPECENUM_VALUE83NAME N_("?unitflag:DefendGood")
343 // is useful for ferrying (AI)
344 #define SPECENUM_VALUE84 L_FERRYBOAT
345 #define SPECENUM_VALUE84NAME N_("?unitflag:FerryBoat")
346 // barbarians unit, land only
347 #define SPECENUM_VALUE85 L_BARBARIAN
348 #define SPECENUM_VALUE85NAME N_("?unitflag:Barbarian")
349 // barbarians unit, global tech required
350 #define SPECENUM_VALUE86 L_BARBARIAN_TECH
351 #define SPECENUM_VALUE86NAME N_("?unitflag:BarbarianTech")
352 // barbarian boat
353 #define SPECENUM_VALUE87 L_BARBARIAN_BOAT
354 #define SPECENUM_VALUE87NAME N_("?unitflag:BarbarianBoat")
355 // what barbarians should build
356 #define SPECENUM_VALUE88 L_BARBARIAN_BUILD
357 #define SPECENUM_VALUE88NAME N_("BarbarianBuild")
358 // barbarians build when global tech
359 #define SPECENUM_VALUE89 L_BARBARIAN_BUILD_TECH
360 #define SPECENUM_VALUE89NAME N_("?unitflag:BarbarianBuildTech")
361 // barbarian leader
362 #define SPECENUM_VALUE90 L_BARBARIAN_LEADER
363 #define SPECENUM_VALUE90NAME N_("?unitflag:BarbarianLeader")
364 // sea raider unit
365 #define SPECENUM_VALUE91 L_BARBARIAN_SEA
366 #define SPECENUM_VALUE91NAME N_("?unitflag:BarbarianSea")
367 // sea raider unit, global tech required
368 #define SPECENUM_VALUE92 L_BARBARIAN_SEA_TECH
369 #define SPECENUM_VALUE92NAME N_("?unitflag:BarbarianSeaTech")
370 // Startunit: Cities
371 #define SPECENUM_VALUE93 L_START_CITIES
372 #define SPECENUM_VALUE93NAME N_("?unitflag:CitiesStartunit")
373 // Startunit: Worker
374 #define SPECENUM_VALUE94 L_START_WORKER
375 #define SPECENUM_VALUE94NAME N_("?unitflag:WorkerStartunit")
376 // Startunit: Explorer
377 #define SPECENUM_VALUE95 L_START_EXPLORER
378 #define SPECENUM_VALUE95NAME N_("?unitflag:ExplorerStartunit")
379 // Startunit: King
380 #define SPECENUM_VALUE96 L_START_KING
381 #define SPECENUM_VALUE96NAME N_("?unitflag:KingStartunit")
382 // Startunit: Diplomat
383 #define SPECENUM_VALUE97 L_START_DIPLOMAT
384 #define SPECENUM_VALUE97NAME N_("?unitflag:DiplomatStartunit")
385 // Startunit: Ferryboat
386 #define SPECENUM_VALUE98 L_START_FERRY
387 #define SPECENUM_VALUE98NAME N_("?unitflag:FerryStartunit")
388 // Startunit: DefendOk
389 #define SPECENUM_VALUE99 L_START_DEFEND_OK
390 #define SPECENUM_VALUE99NAME N_("?unitflag:DefendOkStartunit")
391 // Startunit: DefendGood
392 #define SPECENUM_VALUE100 L_START_DEFEND_GOOD
393 #define SPECENUM_VALUE100NAME N_("?unitflag:DefendGoodStartunit")
394 // Startunit: AttackFast
395 #define SPECENUM_VALUE101 L_START_ATTACK_FAST
396 #define SPECENUM_VALUE101NAME N_("?unitflag:AttackFastStartunit")
397 // Startunit: AttackStrong
398 #define SPECENUM_VALUE102 L_START_ATTACK_STRONG
399 #define SPECENUM_VALUE102NAME N_("?unitflag:AttackStrongStartunit")
400 // AI hunter type unit
401 #define SPECENUM_VALUE103 L_HUNTER
402 #define SPECENUM_VALUE103NAME N_("?unitflag:Hunter")
403 // can improve terrain
404 #define SPECENUM_VALUE104 L_SETTLERS
405 #define SPECENUM_VALUE104NAME N_("?unitflag:Settlers")
406 #define L_LAST (L_SETTLERS + 1)
407 
408 #include "specenum_gen.h"
409 
410 #define L_MAX 64 // Used in the network protocol.
411 
412 FC_STATIC_ASSERT(L_LAST - L_FIRST <= L_MAX, too_many_unit_roles);
413 
414 // Used in the network protocol.
415 BV_DEFINE(bv_unit_type_roles, L_MAX);
416 
417 // Used in the network protocol.
418 #define SPECENUM_NAME combat_bonus_type
419 #define SPECENUM_VALUE0 CBONUS_DEFENSE_MULTIPLIER
420 #define SPECENUM_VALUE0NAME "DefenseMultiplier"
421 #define SPECENUM_VALUE1 CBONUS_DEFENSE_DIVIDER
422 #define SPECENUM_VALUE1NAME "DefenseDivider"
423 #define SPECENUM_VALUE2 CBONUS_FIREPOWER1
424 #define SPECENUM_VALUE2NAME "Firepower1"
425 #define SPECENUM_VALUE3 CBONUS_DEFENSE_MULTIPLIER_PCT
426 #define SPECENUM_VALUE3NAME "DefenseMultiplierPct"
427 #define SPECENUM_VALUE4 CBONUS_DEFENSE_DIVIDER_PCT
428 #define SPECENUM_VALUE4NAME "DefenseDividerPct"
429 #include "specenum_gen.h"
430 
431 struct combat_bonus {
432  enum unit_type_flag_id flag;
433  enum combat_bonus_type type;
434  int value;
435 
436  // Not listed in the help text.
437  bool quiet;
438 };
439 
440 // get 'struct combat_bonus_list' and related functions:
441 #define SPECLIST_TAG combat_bonus
442 #define SPECLIST_TYPE struct combat_bonus
443 #include "speclist.h"
444 
445 #define combat_bonus_list_iterate(bonuslist, pbonus) \
446  TYPED_LIST_ITERATE(struct combat_bonus, bonuslist, pbonus)
447 #define combat_bonus_list_iterate_end LIST_ITERATE_END
448 
449 BV_DEFINE(bv_unit_types, U_LAST);
450 
452  struct name_translation name; /* level/rank name */
453  int power_fact; /* combat/work speed/diplomatic power factor (in %) */
455  int base_raise_chance; // server only
456  int work_raise_chance; // server only
457 };
458 
460  int levels;
461 
463 };
464 
465 struct unit_type {
467  struct name_translation name;
468  bool ruledit_disabled; /* Does not really exist - hole in improvments array
469  */
476  int build_cost; // Use wrappers to access this.
477  int pop_cost; /* number of workers the unit contains (e.g., settlers,
478  engineers)*/
482  int unknown_move_cost; // See utype_unknown_move_cost().
483 
484  struct advance *require_advance; // may be nullptr
485  struct requirement_vector build_reqs;
486 
489  int hp;
491  struct combat_bonus_list *bonuses;
492 
493 #define U_NOT_OBSOLETED (nullptr)
494  const struct unit_type *obsoleted_by;
495  const struct unit_type *converted_to;
497  int fuel;
498 
499  bv_unit_type_flags flags;
500  bv_unit_type_roles roles;
501 
502  int happy_cost; // unhappy people in home city
504 
505  // Only valid for ACTION_PARADROP
507 
508  // Additional values for the expanded veteran system
510 
511  // Values for bombardment
513 
514  // Values for founding cities
516 
518 
520 
521  bv_unit_classes cargo;
522 
523  // Can attack these classes even if they are otherwise "Unreachable"
524  bv_unit_classes targets;
525  /* Can load into these class transports at any location,
526  * even if they are otherwise "Unreachable". */
527  bv_unit_classes embarks;
528  /* Can unload from these class transports at any location,
529  * even if they are otherwise "Unreachable". */
530  bv_unit_classes disembarks;
531 
532  enum vision_layer vlayer;
533 
535 
536  struct {
537  bool igwall;
538  bool worker;
539  } adv;
540 
541  struct {
542  int max_defense_mp_pct; /* Value 0 here does not guarantee that unit
543  * never has CBONUS_DEFENSE_MULTIPLIER, it
544  * merely means that there's no POSITIVE one */
546  } cache;
547 
548  // Used to upgrade the ruleset format version.
549  struct {
553 
554  void *ais[FREECIV_AI_MOD_LAST];
555 };
556 
557 // General unit and unit type (matched) routines
559 Unit_type_id utype_index(const struct unit_type *punittype);
560 Unit_type_id utype_number(const struct unit_type *punittype);
561 
562 const struct unit_type *unit_type_get(const struct unit *punit);
563 struct unit_type *utype_by_number(const Unit_type_id id);
564 
565 struct unit_type *unit_type_by_rule_name(const char *name);
566 struct unit_type *unit_type_by_translated_name(const char *name);
567 
568 const char *unit_rule_name(const struct unit *punit);
569 const char *utype_rule_name(const struct unit_type *punittype);
570 
571 const char *unit_name_translation(const struct unit *punit);
572 const char *utype_name_translation(const struct unit_type *punittype);
573 
574 const char *utype_values_string(const struct unit_type *punittype);
575 const char *utype_values_translation(const struct unit_type *punittype);
576 
577 // General unit type flag and role routines
578 bool unit_has_type_flag(const struct unit *punit,
579  enum unit_type_flag_id flag);
580 
581 /**************************************************************************
582  Return whether the given unit type has the flag.
583 **************************************************************************/
584 static inline bool utype_has_flag(const struct unit_type *punittype,
585  int flag)
586 {
587  return BV_ISSET(punittype->flags, flag);
588 }
589 
590 bool unit_has_type_role(const struct unit *punit, enum unit_role_id role);
591 bool utype_has_role(const struct unit_type *punittype, int role);
592 
594 void set_user_unit_type_flag_name(enum unit_type_flag_id id,
595  const char *name, const char *helptxt);
596 const char *unit_type_flag_helptxt(enum unit_type_flag_id id);
597 
598 bool unit_can_take_over(const struct unit *punit);
599 bool utype_can_take_over(const struct unit_type *punittype);
600 
601 bool utype_can_freely_load(const struct unit_type *pcargotype,
602  const struct unit_type *ptranstype);
603 bool utype_can_freely_unload(const struct unit_type *pcargotype,
604  const struct unit_type *ptranstype);
605 
606 bool utype_may_act_at_all(const struct unit_type *putype);
607 bool utype_can_do_action(const struct unit_type *putype,
608  const action_id act_id);
609 bool utype_can_do_action_result(const struct unit_type *putype,
610  enum action_result result);
611 bool utype_acts_hostile(const struct unit_type *putype);
612 
613 bool can_unit_act_when_ustate_is(const struct unit_type *punit_type,
614  const enum ustate_prop prop,
615  const bool is_there);
616 bool utype_can_do_act_when_ustate(const struct unit_type *punit_type,
617  const action_id act_id,
618  const enum ustate_prop prop,
619  const bool is_there);
620 
621 bool utype_can_do_act_if_tgt_citytile(const struct unit_type *punit_type,
622  const action_id act_id,
623  const enum citytile_type prop,
624  const bool is_there);
625 
626 bool can_utype_do_act_if_tgt_diplrel(const struct unit_type *punit_type,
627  const action_id act_id, const int prop,
628  const bool is_there);
629 
630 bool utype_may_act_move_frags(const struct unit_type *punit_type,
631  const action_id act_id,
632  const int move_fragments);
633 
634 bool utype_may_act_tgt_city_tile(const struct unit_type *punit_type,
635  const action_id act_id,
636  const enum citytile_type prop,
637  const bool is_there);
638 
639 bool utype_is_consumed_by_action(const struct action *paction,
640  const struct unit_type *utype);
641 
642 bool utype_is_consumed_by_action_result(enum action_result result,
643  const struct unit_type *utype);
644 
645 bool utype_is_moved_to_tgt_by_action(const struct action *paction,
646  const struct unit_type *utype);
647 
648 bool utype_is_unmoved_by_action(const struct action *paction,
649  const struct unit_type *utype);
650 
651 bool utype_pays_for_regular_move_to_tgt(const struct action *paction,
652  const struct unit_type *utype);
653 
654 int utype_pays_mp_for_action_base(const struct action *paction,
655  const struct unit_type *putype);
656 
657 int utype_pays_mp_for_action_estimate(const struct action *paction,
658  const struct unit_type *putype,
659  const struct player *act_player,
660  const struct tile *act_tile,
661  const struct tile *tgt_tile);
662 
663 // Functions to operate on various flag and roles.
664 typedef bool (*role_unit_callback)(struct unit_type *ptype, void *data);
665 
666 void role_unit_precalcs();
668 int num_role_units(int role);
669 struct unit_type *
670 role_units_iterate_backwards(int role, role_unit_callback cb, void *data);
671 struct unit_type *get_role_unit(int role, int role_index);
672 struct unit_type *best_role_unit(const struct city *pcity, int role);
673 struct unit_type *best_role_unit_for_player(const struct player *pplayer,
674  int role);
675 struct unit_type *first_role_unit_for_player(const struct player *pplayer,
676  int role);
677 bool role_units_translations(QString &astr, int flag, bool alts);
678 
679 // General unit class routines
681 Unit_Class_id uclass_number(const struct unit_class *pclass);
682 /* Optimised to be identical to uclass_number: the implementation
683  * unittype.c is also semantically correct. */
684 #define uclass_index(_c_) (_c_)->item_number
685 #ifndef uclass_index
686 Unit_Class_id uclass_index(const struct unit_class *pclass);
687 #endif // uclass_index
688 
689 struct unit_class *unit_class_get(const struct unit *punit);
690 struct unit_class *uclass_by_number(const Unit_Class_id id);
691 #define utype_class(_t_) (_t_)->uclass
692 #ifndef utype_class
693 struct unit_class *utype_class(const struct unit_type *punittype);
694 #endif // utype_class
695 
696 struct unit_class *unit_class_by_rule_name(const char *s);
697 
698 const char *uclass_rule_name(const struct unit_class *pclass);
699 const char *uclass_name_translation(const struct unit_class *pclass);
700 
701 /**************************************************************************
702  Return whether the given unit class has the flag.
703 **************************************************************************/
704 static inline bool uclass_has_flag(const struct unit_class *punitclass,
705  enum unit_class_flag_id flag)
706 {
707  return BV_ISSET(punitclass->flags, flag);
708 }
709 
711 void set_user_unit_class_flag_name(enum unit_class_flag_id id,
712  const char *name, const char *helptxt);
713 const char *unit_class_flag_helptxt(enum unit_class_flag_id id);
714 
715 // Ancillary routines
716 int unit_build_shield_cost(const struct city *pcity,
717  const struct unit *punit);
718 int utype_build_shield_cost(const struct city *pcity,
719  const struct unit_type *punittype);
720 int utype_build_shield_cost_base(const struct unit_type *punittype);
721 int unit_build_shield_cost_base(const struct unit *punit);
722 
723 int utype_buy_gold_cost(const struct city *pcity,
724  const struct unit_type *punittype,
725  int shields_in_stock);
726 
727 const struct veteran_system *
728 utype_veteran_system(const struct unit_type *punittype);
729 int utype_veteran_levels(const struct unit_type *punittype);
730 const struct veteran_level *
731 utype_veteran_level(const struct unit_type *punittype, int level);
732 const char *utype_veteran_name_translation(const struct unit_type *punittype,
733  int level);
734 bool utype_veteran_has_power_bonus(const struct unit_type *punittype);
735 
736 struct veteran_system *veteran_system_new(int count);
737 void veteran_system_destroy(struct veteran_system *vsystem);
738 void veteran_system_definition(struct veteran_system *vsystem, int level,
739  const char *vlist_name, int vlist_power,
740  int vlist_move, int vlist_raise,
741  int vlist_wraise);
742 
743 int unit_pop_value(const struct unit *punit);
744 int utype_pop_value(const struct unit_type *punittype);
745 
746 enum unit_move_type utype_move_type(const struct unit_type *punittype);
747 void set_unit_move_type(struct unit_class *puclass);
748 
749 // player related unit functions
750 int utype_upkeep_cost(const struct unit_type *ut, struct player *pplayer,
751  Output_type_id otype);
752 int utype_happy_cost(const struct unit_type *ut,
753  const struct player *pplayer);
754 
755 const struct unit_type *
756 can_upgrade_unittype(const struct player *pplayer,
757  const struct unit_type *punittype);
758 int unit_upgrade_price(const struct player *pplayer,
759  const struct unit_type *from,
760  const struct unit_type *to);
761 
762 bool utype_player_already_has_this_unique(const struct player *pplayer,
763  const struct unit_type *putype);
764 
765 bool can_player_build_unit_direct(const struct player *p,
766  const struct unit_type *punittype);
767 bool can_player_build_unit_later(const struct player *p,
768  const struct unit_type *punittype);
769 bool can_player_build_unit_now(const struct player *p,
770  const struct unit_type *punittype);
771 
772 #define utype_fuel(ptype) (ptype)->fuel
773 
774 bool utype_is_cityfounder(const struct unit_type *utype);
775 
776 // Initialization and iteration
777 void unit_types_init();
778 void unit_types_free();
779 void unit_type_flags_free();
780 void unit_class_flags_free();
781 
783 const struct unit_type *unit_type_array_last();
784 
785 #define unit_type_iterate(_p) \
786  { \
787  struct unit_type *_p = unit_type_array_first(); \
788  if (nullptr != _p) { \
789  for (; _p <= unit_type_array_last(); _p++) {
790 
791 #define unit_type_iterate_end \
792  } \
793  } \
794  }
795 
796 #define unit_type_re_active_iterate(_p) \
797  unit_type_iterate(_p) \
798  { \
799  if (!_p->ruledit_disabled) {
800 
801 #define unit_type_re_active_iterate_end \
802  } \
803  } \
804  unit_type_iterate_end;
805 
806 void *utype_ai_data(const struct unit_type *ptype, const struct ai_type *ai);
807 void utype_set_ai_data(struct unit_type *ptype, const struct ai_type *ai,
808  void *data);
809 
810 void unit_type_action_cache_set(struct unit_type *ptype);
812 
813 // Initialization and iteration
814 void unit_classes_init();
815 void unit_classes_free();
816 
817 void set_unit_class_caches(struct unit_class *pclass);
818 void set_unit_type_caches(struct unit_type *ptype);
819 
821 const struct unit_class *unit_class_array_last();
822 
823 #define unit_class_iterate(_p) \
824  { \
825  struct unit_class *_p = unit_class_array_first(); \
826  if (nullptr != _p) { \
827  for (; _p <= unit_class_array_last(); _p++) {
828 
829 #define unit_class_iterate_end \
830  } \
831  } \
832  }
833 
834 #define unit_class_re_active_iterate(_p) \
835  unit_class_iterate(_p) \
836  { \
837  if (!_p->ruledit_disabled) {
838 
839 #define unit_class_re_active_iterate_end \
840  } \
841  } \
842  unit_class_iterate_end;
843 
844 #define SPECLIST_TAG unit_class
845 #define SPECLIST_TYPE struct unit_class
846 #include "speclist.h"
847 
848 #define unit_class_list_iterate(uclass_list, pclass) \
849  TYPED_LIST_ITERATE(struct unit_class, uclass_list, pclass)
850 #define unit_class_list_iterate_end LIST_ITERATE_END
851 
852 #define SPECLIST_TAG unit_type
853 #define SPECLIST_TYPE struct unit_type
854 #include "speclist.h"
855 
856 #define unit_type_list_iterate(utype_list, ptype) \
857  TYPED_LIST_ITERATE(struct unit_type, utype_list, ptype)
858 #define unit_type_list_iterate_end LIST_ITERATE_END
bool BV_ISSET(const BV &bv, int bit)
Definition: bitvector.h:37
int Unit_Class_id
Definition: fc_types.h:333
int action_id
Definition: fc_types.h:306
#define MAX_LEN_NAME
Definition: fc_types.h:61
int Unit_type_id
Definition: fc_types.h:299
@ O_LAST
Definition: fc_types.h:91
#define UCL_LAST
Definition: fc_types.h:332
enum output_type_id Output_type_id
Definition: fc_types.h:295
const char * name
Definition: inputfile.cpp:118
struct setting_list * level[OLEVELS_NUM]
Definition: settings.cpp:167
Definition: tech.h:113
Definition: ai.h:42
Definition: city.h:291
enum unit_type_flag_id flag
Definition: unittype.h:432
bool quiet
Definition: unittype.h:437
enum combat_bonus_type type
Definition: unittype.h:433
Definition: player.h:231
Definition: tile.h:42
struct unit_class::@81 cache
Unit_Class_id item_number
Definition: unittype.h:121
int hp_loss_pct
Definition: unittype.h:126
enum unit_move_type move_type
Definition: unittype.h:124
int non_native_def_pct
Definition: unittype.h:128
struct unit_class::@80 adv
enum move_level sea_move
Definition: unittype.h:136
struct unit_class_list * subset_movers
Definition: unittype.h:143
struct extra_type_list * native_tile_extras
Definition: unittype.h:141
int min_speed
Definition: unittype.h:125
enum hut_behavior hut_behavior
Definition: unittype.h:129
struct extra_type_list * bonus_roads
Definition: unittype.h:142
QVector< QString > * helptext
Definition: unittype.h:132
struct extra_type_list * refuel_bases
Definition: unittype.h:140
struct name_translation name
Definition: unittype.h:122
bv_unit_class_flags flags
Definition: unittype.h:130
bool ruledit_disabled
Definition: unittype.h:123
enum move_level land_move
Definition: unittype.h:135
int transport_capacity
Definition: unittype.h:488
struct unit_class * uclass
Definition: unittype.h:519
int pop_cost
Definition: unittype.h:477
struct unit_type::@82 adv
void * ais[FREECIV_AI_MOD_LAST]
Definition: unittype.h:554
struct requirement_vector build_reqs
Definition: unittype.h:485
Unit_type_id item_number
Definition: unittype.h:466
int defense_strength
Definition: unittype.h:480
bv_unit_classes cargo
Definition: unittype.h:521
struct unit_type::@84 rscompat_cache
int firepower
Definition: unittype.h:490
QVector< QString > * helptext
Definition: unittype.h:534
int paratroopers_range
Definition: unittype.h:506
char graphic_alt[MAX_LEN_NAME]
Definition: unittype.h:471
bool worker
Definition: unittype.h:538
char sound_move_alt[MAX_LEN_NAME]
Definition: unittype.h:473
int build_cost
Definition: unittype.h:476
int convert_time
Definition: unittype.h:496
int city_size
Definition: unittype.h:515
struct veteran_system * veteran
Definition: unittype.h:509
const struct unit_type * obsoleted_by
Definition: unittype.h:494
int vision_radius_sq
Definition: unittype.h:487
int move_rate
Definition: unittype.h:481
bv_unit_classes targets
Definition: unittype.h:524
enum vision_layer vlayer
Definition: unittype.h:532
struct advance * require_advance
Definition: unittype.h:484
struct unit_type::@83 cache
int paratroopers_mr_sub
Definition: unittype.h:551
int bombard_rate
Definition: unittype.h:512
char graphic_str[MAX_LEN_NAME]
Definition: unittype.h:470
int city_slots
Definition: unittype.h:517
char sound_move[MAX_LEN_NAME]
Definition: unittype.h:472
int hp
Definition: unittype.h:489
int paratroopers_mr_req
Definition: unittype.h:550
char sound_fight_alt[MAX_LEN_NAME]
Definition: unittype.h:475
bool igwall
Definition: unittype.h:537
struct name_translation name
Definition: unittype.h:467
int fuel
Definition: unittype.h:497
bv_unit_type_roles roles
Definition: unittype.h:500
int unknown_move_cost
Definition: unittype.h:482
int upkeep[O_LAST]
Definition: unittype.h:503
bv_unit_classes disembarks
Definition: unittype.h:530
const struct unit_type * converted_to
Definition: unittype.h:495
int max_defense_mp_pct
Definition: unittype.h:542
bv_unit_type_flags flags
Definition: unittype.h:499
bool ruledit_disabled
Definition: unittype.h:468
char sound_fight[MAX_LEN_NAME]
Definition: unittype.h:474
bv_unit_classes embarks
Definition: unittype.h:527
int attack_strength
Definition: unittype.h:479
int happy_cost
Definition: unittype.h:502
int defense_mp_bonuses_pct[U_LAST]
Definition: unittype.h:545
struct combat_bonus_list * bonuses
Definition: unittype.h:491
Definition: unit.h:134
int power_fact
Definition: unittype.h:453
int base_raise_chance
Definition: unittype.h:455
struct name_translation name
Definition: unittype.h:452
int move_bonus
Definition: unittype.h:454
int work_raise_chance
Definition: unittype.h:456
struct veteran_level * definitions
Definition: unittype.h:462
bool utype_may_act_tgt_city_tile(const struct unit_type *punit_type, const action_id act_id, const enum citytile_type prop, const bool is_there)
Return TRUE iff the given (action enabler controlled) action may be performed by a unit of the given ...
Definition: unittype.cpp:870
int utype_buy_gold_cost(const struct city *pcity, const struct unit_type *punittype, int shields_in_stock)
Returns the amount of gold it takes to rush this unit.
Definition: unittype.cpp:1193
bool can_unit_act_when_ustate_is(const struct unit_type *punit_type, const enum ustate_prop prop, const bool is_there)
Return TRUE iff there exists an (action enabler controlled) action that a unit of the type punit_type...
Definition: unittype.cpp:733
const struct unit_class * unit_class_array_last()
Return the last item of unit_classes.
Definition: unittype.cpp:2090
const char * unit_rule_name(const struct unit *punit)
Return the (untranslated) rule name of the unit.
Definition: unittype.cpp:1283
void set_unit_class_caches(struct unit_class *pclass)
Set caches for unit class.
Definition: unittype.cpp:2349
const struct unit_type * unit_type_get(const struct unit *punit)
Return the unit type for this unit.
Definition: unittype.cpp:114
struct unit_type * best_role_unit(const struct city *pcity, int role)
Return "best" unit this city can build, with given role/flag.
Definition: unittype.cpp:1920
int utype_pop_value(const struct unit_type *punittype)
How much city shrinks when it builds unit of this type.
Definition: unittype.cpp:1231
BV_DEFINE(bv_unit_classes, UCL_LAST)
const char * uclass_name_translation(const struct unit_class *pclass)
Return the (translated) name of the unit class.
Definition: unittype.cpp:1324
static bool uclass_has_flag(const struct unit_class *punitclass, enum unit_class_flag_id flag)
Definition: unittype.h:704
int utype_pays_mp_for_action_base(const struct action *paction, const struct unit_type *putype)
Returns the amount of movement points successfully performing the specified action will consume in th...
Definition: unittype.cpp:1083
struct unit_type * utype_by_number(const Unit_type_id id)
Return a pointer for the unit type struct for the given unit type id.
Definition: unittype.cpp:103
bool utype_can_freely_unload(const struct unit_type *pcargotype, const struct unit_type *ptranstype)
Return TRUE iff the given cargo type has no restrictions on when it can unload from the given transpo...
Definition: unittype.cpp:239
bool utype_pays_for_regular_move_to_tgt(const struct action *paction, const struct unit_type *utype)
Returns TRUE iff successfully performing the specified action always will cost the actor unit of the ...
Definition: unittype.cpp:1052
#define utype_class(_t_)
Definition: unittype.h:691
const char * utype_values_translation(const struct unit_type *punittype)
Return string with translated unit name and list of its values.
Definition: unittype.cpp:1310
int unit_build_shield_cost(const struct city *pcity, const struct unit *punit)
Returns the number of shields it takes to build this unit.
Definition: unittype.cpp:1176
const char * unit_class_flag_helptxt(enum unit_class_flag_id id)
Return the (untranslated) help text of the user unit class flag.
Definition: unittype.cpp:1534
#define L_FIRST
Definition: unittype.h:319
struct unit_type * unit_type_array_first()
Return the first item of unit_types.
Definition: unittype.cpp:52
bool utype_is_moved_to_tgt_by_action(const struct action *paction, const struct unit_type *utype)
Returns TRUE iff successfully performing the specified action always will move the actor unit of the ...
Definition: unittype.cpp:969
const struct unit_type * unit_type_array_last()
Return the last item of unit_types.
Definition: unittype.cpp:63
int utype_upkeep_cost(const struct unit_type *ut, struct player *pplayer, Output_type_id otype)
Returns the upkeep of a unit of this type under the given government.
Definition: unittype.cpp:123
enum unit_move_type utype_move_type(const struct unit_type *punittype)
Return move type of the unit type.
Definition: unittype.cpp:1247
const char * utype_rule_name(const struct unit_type *punittype)
Return the (untranslated) rule name of the unit type.
Definition: unittype.cpp:1274
struct unit_type * best_role_unit_for_player(const struct player *pplayer, int role)
Return "best" unit the player can build, with given role/flag.
Definition: unittype.cpp:1950
hut_behavior
Definition: unittype.h:113
@ HUT_FRIGHTEN
Definition: unittype.h:113
@ HUT_NOTHING
Definition: unittype.h:113
@ HUT_NORMAL
Definition: unittype.h:113
bool utype_is_cityfounder(const struct unit_type *utype)
Is cityfounder type.
Definition: unittype.cpp:2549
const struct unit_type * can_upgrade_unittype(const struct player *pplayer, const struct unit_type *punittype)
Return whether this player can upgrade this unit type (to any other unit type).
Definition: unittype.cpp:1379
void unit_classes_init()
Initialize unit_class structures.
Definition: unittype.cpp:2159
void unit_class_flags_free()
Frees the memory associated with all unit class flags.
Definition: unittype.cpp:2067
bool utype_has_role(const struct unit_type *punittype, int role)
Return whether the given unit type has the role.
Definition: unittype.cpp:186
void set_unit_move_type(struct unit_class *puclass)
Set move_type for unit class.
Definition: unittype.cpp:2504
int utype_build_shield_cost(const struct city *pcity, const struct unit_type *punittype)
Returns the number of shields it takes to build this unit type.
Definition: unittype.cpp:1141
move_level
Definition: unittype.h:115
@ MOVE_PARTIAL
Definition: unittype.h:115
@ MOVE_FULL
Definition: unittype.h:115
@ MOVE_NONE
Definition: unittype.h:115
Unit_type_id utype_count()
Return the number of unit types.
Definition: unittype.cpp:74
int utype_build_shield_cost_base(const struct unit_type *punittype)
Returns the number of shields this unit type represents.
Definition: unittype.cpp:1168
void set_unit_type_caches(struct unit_type *ptype)
Set caches for unit types.
Definition: unittype.cpp:2408
const char * unit_type_flag_helptxt(enum unit_type_flag_id id)
Return the (untranslated) helptxt of the user unit flag.
Definition: unittype.cpp:1589
bool utype_may_act_move_frags(const struct unit_type *punit_type, const action_id act_id, const int move_fragments)
Return TRUE iff the given (action enabler controlled) action may be performed by a unit of the given ...
Definition: unittype.cpp:804
bool utype_is_consumed_by_action_result(enum action_result result, const struct unit_type *utype)
Returns TRUE iff performing an action with the specified action result will consume an actor unit of ...
Definition: unittype.cpp:947
void user_unit_class_flags_init()
Initialize user unit class flags.
Definition: unittype.cpp:1481
int num_role_units(int role)
How many unit types have specified role/flag.
Definition: unittype.cpp:1866
bool utype_player_already_has_this_unique(const struct player *pplayer, const struct unit_type *putype)
Returns TRUE iff the unit type is unique and the player already has one.
Definition: unittype.cpp:1599
static bool utype_has_flag(const struct unit_type *punittype, int flag)
Definition: unittype.h:584
bool utype_may_act_at_all(const struct unit_type *putype)
Return TRUE iff units of this type can do actions controlled by generalized (ruleset defined) action ...
Definition: unittype.cpp:374
int unit_build_shield_cost_base(const struct unit *punit)
Returns the number of shields this unit represents.
Definition: unittype.cpp:1185
struct unit_class * unit_class_by_rule_name(const char *s)
Returns the unit class that has the given (untranslated) rule name.
Definition: unittype.cpp:1463
struct veteran_system * veteran_system_new(int count)
Allocate new veteran system structure with given veteran level count.
Definition: unittype.cpp:2281
bool utype_can_freely_load(const struct unit_type *pcargotype, const struct unit_type *ptranstype)
Return TRUE iff the given cargo type has no restrictions on when it can load onto the given transport...
Definition: unittype.cpp:227
void unit_classes_free()
Free resources allocated for unit classes.
Definition: unittype.cpp:2179
void veteran_system_definition(struct veteran_system *vsystem, int level, const char *vlist_name, int vlist_power, int vlist_move, int vlist_raise, int vlist_wraise)
Fill veteran level in given veteran system with given information.
Definition: unittype.cpp:2310
Unit_Class_id uclass_count()
Return the unit_class count.
Definition: unittype.cpp:2101
#define L_LAST
Definition: unittype.h:406
struct unit_class * unit_class_get(const struct unit *punit)
Returns unit class pointer for a unit.
Definition: unittype.cpp:2151
void unit_type_flags_free()
Frees the memory associated with all unit type flags.
Definition: unittype.cpp:2055
const char * utype_values_string(const struct unit_type *punittype)
Return string describing unit type values.
Definition: unittype.cpp:1292
bool(* role_unit_callback)(struct unit_type *ptype, void *data)
Definition: unittype.h:664
bool can_player_build_unit_direct(const struct player *p, const struct unit_type *punittype)
Whether player can build given unit somewhere, ignoring whether unit is obsolete and assuming the pla...
Definition: unittype.cpp:1628
void role_unit_precalcs_free()
Free memory allocated by role_unit_precalcs().
Definition: unittype.cpp:1823
int utype_veteran_levels(const struct unit_type *punittype)
Return veteran levels of the given unit type.
Definition: unittype.cpp:2254
bool utype_can_do_act_when_ustate(const struct unit_type *punit_type, const action_id act_id, const enum ustate_prop prop, const bool is_there)
Return TRUE iff the unit type can do the specified (action enabler controlled) action while its unit ...
Definition: unittype.cpp:746
void veteran_system_destroy(struct veteran_system *vsystem)
Free veteran system.
Definition: unittype.cpp:2298
bool utype_can_do_action_result(const struct unit_type *putype, enum action_result result)
Return TRUE iff units of the given type can do any enabler controlled action with the specified actio...
Definition: unittype.cpp:402
bool unit_has_type_role(const struct unit *punit, enum unit_role_id role)
Return whether the unit has the given role.
Definition: unittype.cpp:195
bool role_units_translations(QString &astr, int flag, bool alts)
Return a string with all the names of units with this flag.
Definition: unittype.cpp:1343
FC_STATIC_ASSERT(L_LAST - L_FIRST<=L_MAX, too_many_unit_roles)
const struct veteran_system * utype_veteran_system(const struct unit_type *punittype)
Return veteran system used for this unit type.
Definition: unittype.cpp:2208
bool unit_has_type_flag(const struct unit *punit, enum unit_type_flag_id flag)
Return whether the unit has the given flag.
Definition: unittype.cpp:176
bool unit_can_take_over(const struct unit *punit)
Return whether the unit can take over enemy cities.
Definition: unittype.cpp:203
struct unit_type * unit_type_by_translated_name(const char *name)
Returns the unit type that has the given (translated) name.
Definition: unittype.cpp:1427
void role_unit_precalcs()
Initialize; it is safe to call this multiple times (e.g., if units have changed due to rulesets in cl...
Definition: unittype.cpp:1838
void unit_type_action_cache_set(struct unit_type *ptype)
Cache if any action may be possible for a unit of the type putype given the property tested for.
Definition: unittype.cpp:710
const char * utype_name_translation(const struct unit_type *punittype)
Return the (translated) name of the unit type.
Definition: unittype.cpp:1256
void unit_types_init()
Inialize unit-type structures.
Definition: unittype.cpp:2001
void user_unit_type_flags_init()
Initialize user unit type flags.
Definition: unittype.cpp:1544
struct unit_class * uclass_by_number(const Unit_Class_id id)
Returns unit class pointer for an ID value.
Definition: unittype.cpp:2129
int utype_pays_mp_for_action_estimate(const struct action *paction, const struct unit_type *putype, const struct player *act_player, const struct tile *act_tile, const struct tile *tgt_tile)
Returns an estimate of the amount of movement points successfully performing the specified action wil...
Definition: unittype.cpp:1104
bool utype_is_consumed_by_action(const struct action *paction, const struct unit_type *utype)
Returns TRUE iff performing the specified action will consume an actor unit of the specified type.
Definition: unittype.cpp:936
struct unit_type * unit_type_by_rule_name(const char *name)
Returns the unit type that has the given (untranslated) rule name.
Definition: unittype.cpp:1444
#define U_LAST
Definition: unittype.h:31
Unit_type_id utype_number(const struct unit_type *punittype)
Return the unit type index.
Definition: unittype.cpp:91
bool utype_veteran_has_power_bonus(const struct unit_type *punittype)
Return whether this unit type's veteran system, if any, confers a power factor bonus at any level (it...
Definition: unittype.cpp:2267
#define uclass_index(_c_)
Definition: unittype.h:684
struct unit_type * get_role_unit(int role, int role_index)
Return index-th unit with specified role/flag.
Definition: unittype.cpp:1900
Unit_type_id utype_index(const struct unit_type *punittype)
Return the unit type index.
Definition: unittype.cpp:82
#define L_MAX
Definition: unittype.h:410
bool utype_can_take_over(const struct unit_type *punittype)
Return whether the unit type can take over enemy cities.
Definition: unittype.cpp:215
void utype_set_ai_data(struct unit_type *ptype, const struct ai_type *ai, void *data)
Attach ai data to unit type.
Definition: unittype.cpp:2340
struct unit_class * unit_class_array_first()
Return the first item of unit_classes.
Definition: unittype.cpp:2079
void set_user_unit_class_flag_name(enum unit_class_flag_id id, const char *name, const char *helptxt)
Sets user defined name for unit class flag.
Definition: unittype.cpp:1493
const char * uclass_rule_name(const struct unit_class *pclass)
Return the (untranslated) rule name of the unit class.
Definition: unittype.cpp:1333
const char * unit_name_translation(const struct unit *punit)
Return the (translated) name of the unit.
Definition: unittype.cpp:1265
bool can_player_build_unit_later(const struct player *p, const struct unit_type *punittype)
Whether player can eventually build given unit somewhere – ie, returns TRUE if unit is available with...
Definition: unittype.cpp:1761
int unit_pop_value(const struct unit *punit)
How much population is put to building this unit.
Definition: unittype.cpp:1239
const char * utype_veteran_name_translation(const struct unit_type *punittype, int level)
Return translated name of the given veteran level.
Definition: unittype.cpp:2239
Unit_Class_id uclass_number(const struct unit_class *pclass)
Return the unit_class index.
Definition: unittype.cpp:2120
bool can_player_build_unit_now(const struct player *p, const struct unit_type *punittype)
Whether player can build given unit somewhere; returns FALSE if unit is obsolete.
Definition: unittype.cpp:1742
void unit_types_free()
Frees the memory associated with all unit types.
Definition: unittype.cpp:2041
bool utype_is_unmoved_by_action(const struct action *paction, const struct unit_type *utype)
Returns TRUE iff successfully performing the specified action never will move the actor unit from its...
Definition: unittype.cpp:1009
bool utype_acts_hostile(const struct unit_type *putype)
Return TRUE iff units of this type can do hostile actions controlled by generalized (ruleset defined)...
Definition: unittype.cpp:432
bool utype_can_do_act_if_tgt_citytile(const struct unit_type *punit_type, const action_id act_id, const enum citytile_type prop, const bool is_there)
Returns TRUE iff the unit type can do the specified (action enabler controlled) action while its targ...
Definition: unittype.cpp:763
struct unit_type * first_role_unit_for_player(const struct player *pplayer, int role)
Return first unit the player can build, with given role/flag.
Definition: unittype.cpp:1976
void unit_type_action_cache_init()
Cache what unit types may be allowed do what actions, both at all and when certain properties are tru...
Definition: unittype.cpp:722
bool can_utype_do_act_if_tgt_diplrel(const struct unit_type *punit_type, const action_id act_id, const int prop, const bool is_there)
Return TRUE iff the given (action enabler controlled) action can be performed by a unit of the given ...
Definition: unittype.cpp:784
struct unit_type * role_units_iterate_backwards(int role, role_unit_callback cb, void *data)
Iterate over all the role units and feed them to callback, starting from the last one.
Definition: unittype.cpp:1883
bool utype_can_do_action(const struct unit_type *putype, const action_id act_id)
Return TRUE iff units of the given type can do the specified generalized (ruleset defined) action ena...
Definition: unittype.cpp:386
void set_user_unit_type_flag_name(enum unit_type_flag_id id, const char *name, const char *helptxt)
Sets user defined name for unit flag.
Definition: unittype.cpp:1556
const struct veteran_level * utype_veteran_level(const struct unit_type *punittype, int level)
Return veteran level properties of given unit in given veterancy level.
Definition: unittype.cpp:2224
int utype_happy_cost(const struct unit_type *ut, const struct player *pplayer)
Return the "happy cost" (the number of citizens who are discontented) for this unit.
Definition: unittype.cpp:167
void * utype_ai_data(const struct unit_type *ptype, const struct ai_type *ai)
Return pointer to ai data of given unit type and ai type.
Definition: unittype.cpp:2332
int unit_upgrade_price(const struct player *pplayer, const struct unit_type *from, const struct unit_type *to)
Return the cost (gold) of upgrading a single unit of the specified type to the new type.
Definition: unittype.cpp:1407