Freeciv-3.2
Loading...
Searching...
No Matches
unittype.c
Go to the documentation of this file.
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
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18#include <string.h>
19#include <math.h> /* ceil */
20
21/* utility */
22#include "astring.h"
23#include "fcintl.h"
24#include "log.h"
25#include "mem.h"
26#include "shared.h"
27#include "string_vector.h"
28#include "support.h"
29
30/* common */
31#include "ai.h"
32#include "combat.h"
33#include "game.h"
34#include "government.h"
35#include "movement.h"
36#include "player.h"
37#include "research.h"
38#include "unitlist.h"
39
40#include "unittype.h"
41
42#define MAX_UNIT_ROLES L_LAST + ACTION_COUNT
43
46/* the unit_types and unit_classes arrays are now setup in:
47 server/ruleset.c (for the server)
48 client/packhand.c (for the client)
49*/
50
52
54
55/**********************************************************************/
59{
60 if (game.control.num_unit_types > 0) {
61 return unit_types;
62 }
63 return NULL;
64}
65
66/**********************************************************************/
70{
71 if (game.control.num_unit_types > 0) {
73 }
74 return NULL;
75}
76
77/**********************************************************************/
84
85/**********************************************************************/
96
97/**********************************************************************/
101{
103 return punittype->item_number;
104}
105
106/**********************************************************************/
113{
115 return NULL;
116 }
117 return &unit_types[id];
118}
119
120/**********************************************************************/
123const struct unit_type *unit_type_get(const struct unit *punit)
124{
126 return punit->utype;
127}
128
129/**********************************************************************/
132int utype_upkeep_cost(const struct unit_type *ut, struct player *pplayer,
134{
135 int val = ut->upkeep[otype], gold_upkeep_factor;
136
137 if (BV_ISSET(ut->flags, UTYF_FANATIC)
138 && get_player_bonus(pplayer, EFT_FANATICS) > 0) {
139 /* Special case: fanatics have no upkeep under fanaticism. */
140 return 0;
141 }
142
143 /* Switch shield upkeep to gold upkeep if
144 - the effect 'EFT_SHIELD2GOLD_FACTOR' is non-zero (it gives the
145 conversion factor in percent) and
146 - the unit has the corresponding flag set (UTYF_SHIELD2GOLD)
147 FIXME: Should the ai know about this? */
149 && (otype == O_GOLD || otype == O_SHIELD)) {
151 if (gold_upkeep_factor > 0) {
152 switch (otype) {
153 case O_GOLD:
154 val = ceil((0.01 * gold_upkeep_factor) * ut->upkeep[O_SHIELD]);
155 break;
156 case O_SHIELD:
157 val = 0;
158 break;
159 default:
161 break;
162 }
163 }
164 }
165
167 &(const struct req_context) {
168 .player = pplayer,
169 .output = get_output_type(otype),
170 .unittype = ut
171 },
173
174 return val;
175}
176
177/**********************************************************************/
181int utype_happy_cost(const struct unit_type *ut,
182 const struct player *pplayer)
183{
184 return ut->happy_cost * get_player_bonus(pplayer, EFT_UNHAPPY_FACTOR);
185}
186
187/**********************************************************************/
190bool unit_has_type_flag(const struct unit *punit, enum unit_type_flag_id flag)
191{
192 return utype_has_flag(unit_type_get(punit), flag);
193}
194
195/**********************************************************************/
199bool utype_has_role(const struct unit_type *punittype, int role)
200{
202 return BV_ISSET(punittype->roles, role - L_FIRST);
203}
204
205/**********************************************************************/
209{
211}
212
213/**********************************************************************/
218 const struct extra_type *pextra)
219{
220 action_iterate(act_id) {
221 struct action *paction = action_by_number(act_id);
222
223 if (!utype_can_do_action(putype, act_id)) {
224 /* Not relevant. */
225 continue;
226 }
227
228 if (actres_creates_extra(paction->result, pextra)) {
229 /* Can create */
230 return TRUE;
231 }
233
234 return FALSE;
235}
236
237/**********************************************************************/
242 const struct extra_type *pextra)
243{
244 action_iterate(act_id) {
245 struct action *paction = action_by_number(act_id);
246
247 if (!utype_can_do_action(putype, act_id)) {
248 /* Not relevant. */
249 continue;
250 }
251
252 if (actres_removes_extra(paction->result, pextra)) {
253 /* Can remove */
254 return TRUE;
255 }
257
258 return FALSE;
259}
260
261/**********************************************************************/
264bool unit_can_take_over(const struct unit *punit)
265{
266 /* TODO: Should unit state dependent action enablers be considered?
267 * Some callers aren't yet ready for changeable unit state (like current
268 * location) playing a role. */
269 return unit_owner(punit)->ai_common.barbarian_type != ANIMAL_BARBARIAN
271}
272
273/**********************************************************************/
277{
278 /* FIXME: "Paradrop Unit" can in certain circumstances result in city
279 * conquest. */
281}
282
283/**********************************************************************/
289 const struct unit_type *ptranstype)
290{
291 return BV_ISSET(pcargotype->embarks,
293}
294
295/**********************************************************************/
301 const struct unit_type *ptranstype)
302{
303 return BV_ISSET(pcargotype->disembarks,
305}
306
307/* Fake action id representing any hostile action. */
308#define ACTION_HOSTILE ACTION_COUNT + 1
309
310/* Number of real and fake actions. */
311#define ACTION_AND_FAKES ACTION_HOSTILE + 1
312
313/* Cache of what generalized (ruleset defined) action enabler controlled
314 * actions units of each type can perform. Checking if any action can be
315 * done at all is done via the fake action id ACTION_ANY. If any hostile
316 * action can be performed is done via ACTION_HOSTILE. */
318
319/**********************************************************************/
324{
325 /* Clear old values. */
326 action_iterate(act_id) {
331
332 /* See if the unit type can do an action controlled by generalized action
333 * enablers */
335 const struct action *paction = enabler_get_action(enabler);
336 action_id act_id = action_id(paction);
337
341 &(enabler->actor_reqs))) {
342 log_debug("act_cache: %s can %s",
347
348 if (actres_is_hostile(paction->result)) {
350 }
351 }
353}
354
355/**********************************************************************/
360{
362}
363
364/**********************************************************************/
372 const action_id act_id)
373{
375 fc_assert_ret_val(act_id >= 0 && act_id < ACTION_AND_FAKES, FALSE);
376
378}
379
380/**********************************************************************/
400
401/**********************************************************************/
410{
412
413 action_iterate(act_id) {
414 struct action *paction = action_by_number(act_id);
415
416 if (!BV_ISSET(paction->sub_results, sub_result)) {
417 /* Not relevant */
418 continue;
419 }
420
422 return TRUE;
423 }
425
426 return FALSE;
427}
428
429/**********************************************************************/
433static bool utype_can_do_action_role(const struct unit_type *putype,
434 const int role)
435{
437}
438
439/**********************************************************************/
447
448/* Cache of if a generalized (ruleset defined) action enabler controlled
449 * action always spends all remaining movement of a unit of the specified
450 * unit type. */
452
453/**********************************************************************/
458{
459 action_iterate(act_id) {
460 /* See if the unit type has all remaining MP spent by the specified
461 * action. */
462
463 struct action *paction = action_by_number(act_id);
464 struct universal unis[] = {
465 { .kind = VUT_ACTION, .value = {.action = (paction)} },
466 { .kind = VUT_UTYPE, .value = {.utype = (putype)} }
467 };
468
470 /* Not relevant. */
471 continue;
472 }
473
477 /* Guaranteed to always consume all remaining MP of an actor unit of
478 * this type. */
479 log_debug("unit_act_takes_all_mp_cache_set: %s takes all MP from %s",
482 } else {
483 /* Clear old value in case it was set. */
485 }
487}
488
489/* Cache of if a generalized (ruleset defined) action enabler controlled
490 * action always spends all remaining movement of a unit of the specified
491 * unit type given the specified unit state property. */
492static bv_unit_types
494
495/**********************************************************************/
501{
502 action_iterate(act_id) {
503 /* See if the unit type has all remaining MP spent by the specified
504 * action given the specified unit state property. */
505
507 struct action *paction = action_by_number(act_id);
508 struct universal unis[] = {
509 { .kind = VUT_ACTION, .value = {.action = (paction)} },
510 { .kind = VUT_UTYPE, .value = {.utype = (putype)} },
511 { .kind = VUT_UNITSTATE, .value = {.unit_state = (prop)} }
512 };
513
515 /* Not relevant. */
516 continue;
517 }
518
521 unis[2].value.unit_state = prop;
525 /* Guaranteed to always consume all remaining MP of an actor unit of
526 * this type given the specified unit state property. */
527 log_debug("unit_act_takes_all_mp_cache_set: %s takes all MP from %s"
528 " when unit state is %s",
533 } else {
534 /* Clear old value in case it was set. */
537 }
538 }
540}
541
542/* Cache if any action at all may be possible when the actor unit's state
543 * is...
544 * bit 0 to USP_COUNT - 1: Possible when the corresponding property is TRUE
545 * bit USP_COUNT to ((USP_COUNT * 2) - 1): Possible when the corresponding
546 * property is FALSE
547 */
549
550/* Cache what actions may be possible when the target's local citytile state
551 * is
552 * bit 0 to CITYT_LAST - 1: Possible when the corresponding property is TRUE
553 * bit USP_COUNT to ((CITYT_LAST * 2) - 1): Possible when the corresponding
554 * property is FALSE
555 */
557
558/* Cache position lookup functions */
559#define requirement_unit_state_ereq(_id_, _present_) \
560 requirement_kind_ereq(_id_, REQ_RANGE_LOCAL, _present_, USP_COUNT)
561#define requirement_citytile_ereq(_id_, _present_) \
562 requirement_kind_ereq(_id_, REQ_RANGE_LOCAL, _present_, CITYT_LAST)
563
564/* Caches for each unit type */
570
571/**********************************************************************/
577{
578 struct requirement req;
579 int uidx = utype_index(putype);
580
581 /* The unit is not yet known to be allowed to perform any actions no
582 * matter what its unit state is. */
583 action_iterate(act_id) {
588
590 /* Not an actor unit. */
591 return;
592 }
593
594 /* Common for every situation */
596 req.survives = FALSE;
598
602 req.source.value.unit_state)) {
603
604 /* No action will ever be possible in a specific unit state if the
605 * opposite unit state is required in all action enablers.
606 * No unit state except present and !present of the same property
607 * implies or conflicts with another so the tests can be simple. */
610
612 &(enabler->actor_reqs))
614 bool present = TRUE;
615
616 do {
618
619 /* OK if not mentioned */
620 req.present = present;
621 if (!is_req_in_vec(&req, &(enabler->actor_reqs))) {
624 !req.present));
625 if (actres_is_hostile(paction->result)) {
628 !req.present));
629 }
632 !req.present));
633 }
634 present = !present;
635 } while (!present);
636 }
638 }
639}
640
641/**********************************************************************/
650{
651 struct requirement req;
653 int uidx = utype_index(putype);
654
655 /* The unit is not yet known to be allowed to perform any actions no
656 * matter what the diplomatic state is. */
657 action_iterate(act_id) {
662
664 /* Not an actor unit. */
665 return;
666 }
667
668 /* Tile is claimed as a requirement. */
670 tile_is_claimed.survives = FALSE;
671 tile_is_claimed.source.kind = VUT_CITYTILE;
672 tile_is_claimed.present = TRUE;
673 tile_is_claimed.source.value.citytile = CITYT_CLAIMED;
674
675 /* Common for every situation */
677 req.survives = FALSE;
678 req.source.kind = VUT_DIPLREL;
679
680 /* DiplRel starts with diplstate_type and ends with diplrel_other */
683 req.source.value.diplrel++) {
684
685 /* No action will ever be possible in a specific diplomatic relation if
686 * its presence contradicts all action enablers.
687 * Everything was set to false above. It is therefore OK to only change
688 * the cache when units can do an action given a certain diplomatic
689 * relationship property value. */
692
694 &(enabler->actor_reqs))
698 /* No diplomatic relation to Nature */
700 &enabler->target_reqs))) {
701 bool present = TRUE;
702
703 do {
705
706 req.present = present;
707 if (!does_req_contradicts_reqs(&req, &(enabler->actor_reqs))) {
711 if (actres_is_hostile(paction->result)) {
715 req.present));
716 }
720 }
721 present = !present;
722 } while (!present);
723 }
725 }
726}
727
728/**********************************************************************/
733static void
735{
736 struct requirement req;
738 int uidx = utype_index(putype);
739
740 /* The unit is not yet known to be allowed to perform any actions no
741 * matter what the diplomatic state is. */
742 action_iterate(act_id) {
747
748 /* Tile is claimed as a requirement. */
750 tile_is_claimed.survives = FALSE;
751 tile_is_claimed.source.kind = VUT_CITYTILE;
752 tile_is_claimed.present = TRUE;
753 tile_is_claimed.source.value.citytile = CITYT_CLAIMED;
754
755 /* Common for every situation */
757 req.survives = FALSE;
759
760 /* DiplRel starts with diplstate_type and ends with diplrel_other */
763 req.source.value.diplrel++) {
764
765 /* No action will ever be possible in a specific diplomatic relation if
766 * its presence contradicts all action enablers.
767 * Everything was set to false above. It is therefore OK to only change
768 * the cache when units can do an action given a certain diplomatic
769 * relationship property value. */
772
774 &(enabler->actor_reqs))
776 /* No diplomatic relation to Nature */
778 &enabler->target_reqs)) {
779 bool present = TRUE;
780
781 do {
783
784 req.present = present;
785 if (!does_req_contradicts_reqs(&req, &(enabler->target_reqs))) {
789 if (actres_is_hostile(paction->result)) {
793 req.present));
794 }
798 }
799 present = !present;
800 } while (!present);
801 }
803 }
804}
805
806/**********************************************************************/
812{
813 struct requirement req;
814 int uidx = utype_index(putype);
815
816 /* The unit is not yet known to be allowed to perform any actions no
817 * matter what its target's CityTile state is. */
818 action_iterate(act_id) {
823
825 /* Not an actor unit. */
826 return;
827 }
828
829 /* Common for every situation */
830 req.range = REQ_RANGE_TILE;
831 req.survives = FALSE;
833
837 req.source.value.citytile)) {
838
839 /* No action will ever be possible in a target CityTile state if the
840 * opposite target CityTile state is required in all action enablers.
841 * No CityTile property state except present and !present of the same
842 * property implies or conflicts with another so the tests can be
843 * simple. */
846
848 &(enabler->target_reqs))
850 bool present = TRUE;
851
852 do {
854
855 /* OK if not mentioned */
856 req.present = present;
857 if (!is_req_in_vec(&req, &(enabler->target_reqs))) {
858 BV_SET(
861 !req.present));
862 if (actres_is_hostile(paction->result)) {
863 BV_SET(
866 !req.present));
867 }
870 !req.present));
871 }
872 present = !present;
873 } while (!present);
874 }
876 }
877}
878
879struct range {
880 int min;
881 int max;
882};
883
884#define MOVES_LEFT_INFINITY -1
885
886/**********************************************************************/
891{
892 struct range *prange = fc_malloc(sizeof(prange));
893
894 prange->min = 0;
896
898 if (preq->source.kind == VUT_MINMOVES) {
899 if (preq->present) {
900 prange->min = preq->source.value.minmoves;
901 } else {
902 prange->max = preq->source.value.minmoves;
903 }
904 }
906
907 return prange;
908}
909
910/**********************************************************************/
926
927/**********************************************************************/
937
938/**********************************************************************/
944 const enum ustate_prop prop,
945 const bool is_there)
946{
948}
949
950/**********************************************************************/
956 const action_id act_id,
957 const enum ustate_prop prop,
958 const bool is_there)
959{
961 fc_assert_ret_val(act_id >= 0 && act_id < ACTION_AND_FAKES, FALSE);
962
965}
966
967/**********************************************************************/
976 enum action_result result,
977 const enum ustate_prop prop,
978 const bool is_there)
979{
981
984 return TRUE;
985 }
987
988 return FALSE;
989}
990
991/**********************************************************************/
997 const action_id act_id,
998 const enum citytile_type prop,
999 const bool is_there)
1000{
1002 fc_assert_ret_val(act_id >= 0 && act_id < ACTION_AND_FAKES, FALSE);
1003
1006}
1007
1008/**********************************************************************/
1018 const action_id act_id,
1019 const int prop,
1020 const bool is_there)
1021{
1023 fc_assert_ret_val(act_id >= 0 && act_id < ACTION_AND_FAKES, FALSE);
1024
1027}
1028
1029/**********************************************************************/
1035bool
1037 const action_id act_id,
1038 const int prop,
1039 const bool is_there)
1040{
1042 fc_assert_ret_val(act_id >= 0 && act_id < ACTION_AND_FAKES, FALSE);
1043
1044 return BV_ISSET(
1047}
1048
1049/**********************************************************************/
1059 const action_id act_id,
1060 const int move_fragments)
1061{
1062 struct range *ml_range;
1063
1064 fc_assert(action_id_exists(act_id) || act_id == ACTION_ANY);
1065
1067 /* Not an actor unit. */
1068 return FALSE;
1069 }
1070
1071 if (act_id == ACTION_ANY) {
1072 /* Any action is OK. */
1075 move_fragments)) {
1076 /* It only has to be true for one action. */
1077 return TRUE;
1078 }
1080
1081 /* No action enabled. */
1082 return FALSE;
1083 }
1084
1085 if (action_id_get_actor_kind(act_id) != AAK_UNIT) {
1086 /* This action isn't performed by any unit at all so this unit type
1087 * can't do it. */
1088 return FALSE;
1089 }
1090
1092 enabler) {
1094 &(enabler->actor_reqs))) {
1095 /* This action enabler isn't for this unit type at all. */
1096 continue;
1097 }
1098
1099 ml_range = moves_left_range(&(enabler->actor_reqs));
1100 if (ml_range->min <= move_fragments
1101 && (ml_range->max == MOVES_LEFT_INFINITY
1102 || ml_range->max > move_fragments)) {
1103 /* The number of move fragments is in range of the action enabler. */
1104
1105 free(ml_range);
1106
1107 return TRUE;
1108 }
1109
1110 free(ml_range);
1112
1113 return FALSE;
1114}
1115
1116/**********************************************************************/
1125 const action_id act_id,
1126 const enum citytile_type prop,
1127 const bool is_there)
1128{
1129 struct requirement req;
1130
1132 /* Not an actor unit. */
1133 return FALSE;
1134 }
1135
1136 if (act_id == ACTION_ANY) {
1137 /* Any action is OK. */
1140 prop, is_there)) {
1141 /* It only has to be true for one action. */
1142 return TRUE;
1143 }
1145
1146 /* No action enabled. */
1147 return FALSE;
1148 }
1149
1150 if (action_id_get_actor_kind(act_id) != AAK_UNIT) {
1151 /* This action isn't performed by any unit at all so this unit type
1152 * can't do it. */
1153 return FALSE;
1154 }
1155
1156 /* Common for every situation */
1157 req.range = REQ_RANGE_TILE;
1158 req.survives = FALSE;
1159 req.source.kind = VUT_CITYTILE;
1160
1161 /* Will only check for the specified is_there */
1162 req.present = is_there;
1163
1164 /* Will only check the specified property */
1165 req.source.value.citytile = prop;
1166
1168 enabler) {
1170 &(enabler->actor_reqs))) {
1171 /* This action enabler isn't for this unit type at all. */
1172 continue;
1173 }
1174
1175 if (!does_req_contradicts_reqs(&req, &(enabler->target_reqs))) {
1176 /* This action isn't blocked by the given target tile property. */
1177 return TRUE;
1178 }
1180
1181 return FALSE;
1182}
1183
1184/**********************************************************************/
1192 struct action *paction)
1193{
1196}
1197
1198/**********************************************************************/
1214
1215/**********************************************************************/
1220 const struct unit_type *utype)
1221{
1222 return paction->actor_consuming_always;
1223}
1224
1225/**********************************************************************/
1230 const struct unit_type *utype)
1231{
1233 if (!utype_can_do_action(utype, action_id(paction))) {
1234 continue;
1235 }
1236
1238 return TRUE;
1239 }
1241
1242 return FALSE;
1243}
1244
1245/**********************************************************************/
1250 const struct unit_type *utype)
1251{
1253
1254 if (paction->actor_consuming_always) {
1255 return FALSE;
1256 }
1257
1258 switch (paction->actor.is_unit.moves_actor) {
1259 case MAK_STAYS:
1260 /* Stays at the tile were it was. */
1261 return FALSE;
1262 case MAK_REGULAR:
1263 /* A "regular" move. Does it charge the move cost of a regular move?
1264 * Update utype_pays_for_regular_move_to_tgt() if yes. */
1265 return TRUE;
1266 case MAK_TELEPORT:
1267 /* A teleporting move. */
1268 return TRUE;
1269 case MAK_FORCED:
1270 /* Tries a forced move under certain conditions. */
1271 return FALSE;
1272 case MAK_ESCAPE:
1273 /* May die, may be teleported to a safe city. */
1274 return FALSE;
1276 /* Too complex to determine. */
1277 return FALSE;
1278 }
1279
1280 fc_assert_msg(FALSE, "Should not reach this code.");
1281 return FALSE;
1282}
1283
1284/**********************************************************************/
1289 const struct unit_type *utype)
1290{
1292
1293 if (paction->actor_consuming_always) {
1294 /* Dead counts as moved off the board */
1295 return FALSE;
1296 }
1297
1298 switch (paction->actor.is_unit.moves_actor) {
1299 case MAK_STAYS:
1300 /* Stays at the tile were it was. */
1301 return TRUE;
1302 case MAK_REGULAR:
1303 /* A "regular" move. Does it charge the move cost of a regular move?
1304 * Update utype_pays_for_regular_move_to_tgt() if yes. */
1305 return FALSE;
1306 case MAK_TELEPORT:
1307 /* A teleporting move. */
1308 return FALSE;
1309 case MAK_FORCED:
1310 /* Tries a forced move under certain conditions. */
1311 return FALSE;
1312 case MAK_ESCAPE:
1313 /* May die, may be teleported to a safe city. */
1314 return FALSE;
1316 /* Too complex to determine. */
1317 return FALSE;
1318 }
1319
1320 fc_assert_msg(FALSE, "Should not reach this code.");
1321 return FALSE;
1322}
1323
1324/**********************************************************************/
1331 const struct unit_type *utype)
1332{
1334 /* Not even a move. */
1335 return FALSE;
1336 }
1337
1339 /* Moves into the city to occupy it. */
1340 return TRUE;
1341 }
1342
1344 /* Moves into the tile with the extras to capture them. */
1345 return TRUE;
1346 }
1347
1349 /* Moves into the tile with the hut to enter it. */
1350 return TRUE;
1351 }
1352
1354 /* Moves into the tile with the hut to frighten it. */
1355 return TRUE;
1356 }
1357
1359 /* Moves out of the transport to disembark. */
1360 return TRUE;
1361 }
1362
1364 /* Moves into the transport to embark. */
1365 return TRUE;
1366 }
1367
1369 /* Is a regular move. */
1370 return TRUE;
1371 }
1372
1373 return FALSE;
1374}
1375
1376/**********************************************************************/
1382 const struct unit_type *putype)
1383{
1384 int mpco = 0;
1385
1386 return mpco;
1387}
1388
1389/**********************************************************************/
1394 const struct action *paction,
1395 const struct unit_type *putype,
1396 const struct player *act_player,
1397 const struct tile *act_tile,
1398 const struct tile *tgt_tile)
1399{
1400 const struct tile *post_action_tile;
1402
1405 } else {
1406 /* FIXME: Not 100% true. May escape, have a probability for moving to
1407 * target tile etc. */
1409 }
1410
1412 /* Add the cost from the move. */
1415 }
1416
1417 /* FIXME: Probably wrong result if the effect
1418 * EFT_ACTION_SUCCESS_MOVE_COST depends on unit state. Add unit state
1419 * parameters? */
1421 &(const struct req_context) {
1422 .player = act_player,
1423 .city = tile_city(post_action_tile),
1424 .tile = tgt_tile,
1425 .unittype = putype,
1426 .action = paction,
1427 },
1428 NULL,
1430
1431 return mpco;
1432}
1433
1434/**********************************************************************/
1438int utype_build_shield_cost(const struct city *pcity,
1439 const struct player *pplayer,
1440 const struct unit_type *punittype)
1441{
1442 int base;
1443 const struct player *owner;
1444 const struct tile *ptile;
1445
1446 if (pcity != NULL) {
1447 owner = city_owner(pcity);
1448 ptile = city_tile(pcity);
1449 } else {
1450 owner = NULL;
1451 ptile = NULL;
1452 }
1453 if (pplayer != NULL) {
1454 /* Override city owner. */
1455 owner = pplayer;
1456 }
1457
1458 base = punittype->build_cost
1459 * (100 + get_unittype_bonus(owner, ptile, punittype, NULL,
1461
1462 return MAX(base * game.info.shieldbox / 100, 1);
1463}
1464
1465/**********************************************************************/
1469{
1470 return MAX(punittype->build_cost * game.info.shieldbox / 100, 1);
1471}
1472
1473/**********************************************************************/
1476int unit_build_shield_cost(const struct city *pcity, const struct unit *punit)
1477{
1479}
1480
1481/**********************************************************************/
1488
1489/**********************************************************************/
1492int utype_buy_gold_cost(const struct city *pcity,
1493 const struct unit_type *punittype,
1494 int shields_in_stock)
1495{
1496 int cost = 0;
1498 struct player *owner;
1499 struct tile *ptile;
1500
1501 if (missing > 0) {
1502 cost = 2 * missing + (missing * missing) / 20;
1503 }
1504
1505 if (shields_in_stock == 0) {
1506 cost *= 2;
1507 }
1508
1509 if (pcity != NULL) {
1510 owner = city_owner(pcity);
1511 ptile = city_tile(pcity);
1512 } else {
1513 owner = NULL;
1514 ptile = NULL;
1515 }
1516
1517 cost = cost
1518 * (100 + get_unittype_bonus(owner, ptile, punittype, NULL,
1520 / 100;
1521
1522 return cost;
1523}
1524
1525/**********************************************************************/
1528int utype_pop_value(const struct unit_type *punittype, const struct city *pcity)
1529{
1530 int pop_cost = punittype->pop_cost;
1531
1532 pop_cost -= get_unittype_bonus(city_owner(pcity), city_tile(pcity),
1534
1535 return MAX(0, pop_cost);
1536}
1537
1538/**********************************************************************/
1543int unit_pop_value(const struct unit *punit)
1544{
1545 return unit_type_get(punit)->pop_cost;
1546}
1547
1548/**********************************************************************/
1552{
1553 return utype_class(punittype)->move_type;
1554}
1555
1556/**********************************************************************/
1561{
1562 return name_translation_get(&punittype->name);
1563}
1564
1565/**********************************************************************/
1569const char *unit_name_translation(const struct unit *punit)
1570{
1572}
1573
1574/**********************************************************************/
1578const char *utype_rule_name(const struct unit_type *punittype)
1579{
1580 return rule_name_get(&punittype->name);
1581}
1582
1583/**********************************************************************/
1587const char *unit_rule_name(const struct unit *punit)
1588{
1590}
1591
1592/**********************************************************************/
1596const char *utype_values_string(const struct unit_type *punittype)
1597{
1598 static char buffer[256];
1599
1600 /* Print in two parts as move_points_text() returns a static buffer */
1601 fc_snprintf(buffer, sizeof(buffer), "%d/%d/%s",
1602 punittype->attack_strength,
1603 punittype->defense_strength,
1604 move_points_text(punittype->move_rate, TRUE));
1605 if (utype_fuel(punittype)) {
1606 cat_snprintf(buffer, sizeof(buffer), "(%s)",
1608 TRUE));
1609 }
1610 return buffer;
1611}
1612
1613/**********************************************************************/
1618{
1619 static char buffer[256];
1620
1621 fc_snprintf(buffer, sizeof(buffer),
1622 "%s [%s]",
1625 return buffer;
1626}
1627
1628/**********************************************************************/
1633{
1634 return name_translation_get(&pclass->name);
1635}
1636
1637/**********************************************************************/
1641const char *uclass_rule_name(const struct unit_class *pclass)
1642{
1643 return rule_name_get(&pclass->name);
1644}
1645
1646/**********************************************************************/
1649bool unit_has_class_flag(const struct unit *punit, enum unit_class_flag_id flag)
1650{
1651 return uclass_has_flag(unit_class_get(punit), flag);
1652}
1653
1654/**********************************************************************/
1658 enum unit_class_flag_id flag)
1659{
1660 return uclass_has_flag(utype_class(ptype), flag);
1661}
1662
1663/**********************************************************************/
1668bool role_units_translations(struct astring *astr, int flag, bool alts)
1669{
1670 const int count = num_role_units(flag);
1671
1672 if (4 < count) {
1673 if (alts) {
1674 astr_set(astr, _("%s or similar units"),
1676 } else {
1677 astr_set(astr, _("%s and similar units"),
1679 }
1680 return TRUE;
1681 } else if (0 < count) {
1682 const char *vec[count];
1683 int i;
1684
1685 for (i = 0; i < count; i++) {
1686 vec[i] = utype_name_translation(get_role_unit(flag, i));
1687 }
1688
1689 if (alts) {
1690 astr_build_or_list(astr, vec, count);
1691 } else {
1692 astr_build_and_list(astr, vec, count);
1693 }
1694 return TRUE;
1695 }
1696 return FALSE;
1697}
1698
1699/**********************************************************************/
1703const struct unit_type *can_upgrade_unittype(const struct player *pplayer,
1704 const struct unit_type *punittype)
1705{
1706 const struct unit_type *upgrade = punittype;
1707 const struct unit_type *best_upgrade = NULL;
1708
1709 /* For some reason this used to check
1710 * can_player_build_unit_direct() for the unittype
1711 * we're updating from.
1712 * That check is now removed as it prevented legal updates
1713 * of units player had acquired via bribing, capturing,
1714 * diplomatic treaties, or lua script. */
1715
1716 while ((upgrade = upgrade->obsoleted_by) != U_NOT_OBSOLETED) {
1717 if (can_player_build_unit_direct(pplayer, upgrade, TRUE)) {
1718 best_upgrade = upgrade;
1719 }
1720 }
1721
1722 return best_upgrade;
1723}
1724
1725/**********************************************************************/
1731int unit_upgrade_price(const struct player *pplayer,
1732 const struct unit_type *from,
1733 const struct unit_type *to)
1734{
1735 /* Upgrade price is only paid for "Upgrade Unit" so it is safe to hard
1736 * code the action ID for now. paction will have to become a parameter
1737 * before generalized actions appears. */
1740 - unit_shield_value(NULL, from, paction));
1741 int base_cost = 2 * missing + (missing * missing) / 20;
1742
1743 return base_cost
1744 * (100 + get_player_bonus(pplayer, EFT_UPGRADE_PRICE_PCT))
1745 / 100;
1746}
1747
1748/**********************************************************************/
1753{
1756 return punittype;
1757 }
1759
1760 return NULL;
1761}
1762
1763/**********************************************************************/
1768{
1769 const char *qname = Qn_(name);
1770
1773 return punittype;
1774 }
1776
1777 return NULL;
1778}
1779
1780/**********************************************************************/
1785{
1786 const char *qs = Qn_(s);
1787
1790 return pclass;
1791 }
1793
1794 return NULL;
1795}
1796
1797/**********************************************************************/
1801{
1802 int i;
1803
1804 for (i = 0; i < MAX_NUM_USER_UCLASS_FLAGS; i++) {
1806 }
1807}
1808
1809/**********************************************************************/
1813 const char *name,
1814 const char *helptxt)
1815{
1816 int ufid = id - UCF_USER_FLAG_1;
1817
1819
1820 if (user_class_flags[ufid].name != NULL) {
1823 }
1824
1825 if (name && name[0] != '\0') {
1827 }
1828
1829 if (user_class_flags[ufid].helptxt != NULL) {
1830 free(user_class_flags[ufid].helptxt);
1832 }
1833
1834 if (helptxt && helptxt[0] != '\0') {
1836 }
1837}
1838
1839/**********************************************************************/
1843{
1845 return NULL;
1846 }
1847
1848 return user_class_flags[flag - UCF_USER_FLAG_1].name;
1849}
1850
1851/**********************************************************************/
1855{
1857
1859}
1860
1861/**********************************************************************/
1865{
1866 int i;
1867
1868 for (i = 0; i < MAX_NUM_USER_UNIT_FLAGS; i++) {
1870 }
1871}
1872
1873/**********************************************************************/
1877 const char *helptxt)
1878{
1879 int ufid = id - UTYF_USER_FLAG_1;
1880
1882
1883 if (user_type_flags[ufid].name != NULL) {
1886 }
1887
1888 if (name && name[0] != '\0') {
1890 }
1891
1892 if (user_type_flags[ufid].helptxt != NULL) {
1893 free(user_type_flags[ufid].helptxt);
1895 }
1896
1897 if (helptxt && helptxt[0] != '\0') {
1899 }
1900}
1901
1902/**********************************************************************/
1906{
1908 return NULL;
1909 }
1910
1911 return user_type_flags[flag - UTYF_USER_FLAG_1].name;
1912}
1913
1914/**********************************************************************/
1918{
1920
1922}
1923
1924/**********************************************************************/
1928 const struct unit_type *putype)
1929{
1931 /* This isn't a unique unit type. */
1932 return FALSE;
1933 }
1934
1935 return utype_player_already_has_this(pplayer, putype);
1936}
1937
1938/**********************************************************************/
1941bool utype_player_already_has_this(const struct player *pplayer,
1942 const struct unit_type *putype)
1943{
1946 /* FIXME: This could be slow if we have lots of units. We could
1947 * consider keeping an array of unittypes updated with this info
1948 * instead. */
1949
1950 return TRUE;
1951 }
1953
1954 /* The player doesn't already have one. */
1955 return FALSE;
1956}
1957
1958/**********************************************************************/
1969 const struct unit_type *punittype,
1971{
1972 const struct req_context context = { .player = p, .unittype = punittype };
1973 bool barbarian = is_barbarian(p);
1974
1976
1977 if (barbarian
1980 /* Barbarians can build only role units */
1981 return FALSE;
1982 }
1983
1986 && get_player_bonus(p, EFT_ENABLE_NUKE) <= 0) {
1987 return FALSE;
1988 }
1990 return FALSE;
1991 }
1992
1994 && !barbarian) {
1995 /* Unit can be built by barbarians only and this player is
1996 * not barbarian */
1997 return FALSE;
1998 }
1999
2002 /* Unit is usable only in games where founding of new cities is allowed. */
2003 return FALSE;
2004 }
2005
2007 if (preq->source.kind == VUT_IMPROVEMENT
2008 && preq->range == REQ_RANGE_CITY && preq->present) {
2009 /* If the unit has a building requirement, we check to see if the
2010 * player can build that building. Note that individual cities may
2011 * not have that building, so they still may not be able to build the
2012 * unit. */
2013 if (is_great_wonder(preq->source.value.building)
2014 && (great_wonder_is_built(preq->source.value.building)
2015 || great_wonder_is_destroyed(preq->source.value.building))) {
2016 /* It's already built great wonder */
2017 if (great_wonder_owner(preq->source.value.building) != p) {
2018 /* Not owned by this player. Either destroyed or owned by somebody
2019 * else. */
2020 return FALSE;
2021 }
2022 } else if (is_small_wonder(preq->source.value.building)) {
2023 if (!city_from_wonder(p, preq->source.value.building)
2025 && !can_player_build_improvement_direct(p, preq->source.value.building)) {
2026 return FALSE;
2027 }
2028 } else {
2030 && !can_player_build_improvement_direct(p, preq->source.value.building)) {
2031 return FALSE;
2032 }
2033 }
2034 }
2035
2036 if (preq->range < REQ_RANGE_PLAYER) {
2037 /* The question *here* is if the *player* can build this unit */
2038 continue;
2039 }
2040
2041 if (preq->source.kind == VUT_ADVANCE && barbarian) {
2042 /* Tech requirements do not apply to Barbarians building
2043 * L_BARBARIAN_BUILD units. */
2045 /* For L_BARBARIAN_BUILD_TECH the tech requirement must be met at World range
2046 * (i.e. *anyone* must know the tech) */
2047 if (preq->range < REQ_RANGE_WORLD /* If range already World, no need to adjust */
2049 struct requirement copy;
2050
2051 req_copy(&copy, preq);
2052 copy.range = REQ_RANGE_WORLD;
2053
2054 if (!is_req_active(&context, NULL, &copy, RPT_CERTAIN)) {
2055 return FALSE;
2056 }
2057 } else if (!is_req_active(&context, NULL, preq, RPT_CERTAIN)) {
2058 return FALSE;
2059 }
2060 }
2061 } else if (!is_req_active(&context, NULL, preq, RPT_CERTAIN)) {
2062 return FALSE;
2063 }
2065
2067 /* A player can only have one unit of each unique unit type. */
2068 return FALSE;
2069 }
2070
2071 return TRUE;
2072}
2073
2074/**********************************************************************/
2079 const struct unit_type *punittype)
2080{
2082 return FALSE;
2083 }
2084
2085 while ((punittype = punittype->obsoleted_by) != U_NOT_OBSOLETED) {
2087 return FALSE;
2088 }
2089 }
2090
2091 return TRUE;
2092}
2093
2094/**********************************************************************/
2100 const struct unit_type *punittype)
2101{
2103
2105 return FALSE;
2106 }
2107
2108 while ((punittype = punittype->obsoleted_by) != U_NOT_OBSOLETED) {
2110 return FALSE;
2111 }
2112 }
2113
2114 return TRUE;
2115}
2116
2117/**************************************************************************
2118 The following functions use static variables so we can quickly look up
2119 which unit types have given flag or role.
2120 For these functions flags and roles are considered to be in the same "space",
2121 and any "role" argument can also be a "flag".
2122 Unit order is in terms of the order in the units ruleset.
2123**************************************************************************/
2124static bool first_init = TRUE;
2127
2128/**********************************************************************/
2132static void precalc_one(int i,
2133 bool (*func_has)(const struct unit_type *, int))
2134{
2135 int j;
2136
2137 /* Count: */
2138 fc_assert(n_with_role[i] == 0);
2140 if (func_has(u, i)) {
2141 n_with_role[i]++;
2142 }
2144
2145 if (n_with_role[i] > 0) {
2146 with_role[i] = fc_malloc(n_with_role[i] * sizeof(*with_role[i]));
2147 j = 0;
2149 if (func_has(u, i)) {
2150 with_role[i][j++] = u;
2151 }
2153 fc_assert(j == n_with_role[i]);
2154 }
2155}
2156
2157/**********************************************************************/
2161{
2162 int i;
2163
2164 for (i = 0; i < MAX_UNIT_ROLES; i++) {
2165 free(with_role[i]);
2166 with_role[i] = NULL;
2167 n_with_role[i] = 0;
2168 }
2169}
2170
2171/**********************************************************************/
2176{
2177 int i;
2178
2179 if (first_init) {
2180 for (i = 0; i < MAX_UNIT_ROLES; i++) {
2181 with_role[i] = NULL;
2182 n_with_role[i] = 0;
2183 }
2184 } else {
2186 }
2187
2188 for (i = 0; i <= UTYF_LAST_USER_FLAG; i++) {
2190 }
2191 for (i = L_FIRST; i < L_LAST; i++) {
2193 }
2194 for (i = L_LAST; i < MAX_UNIT_ROLES; i++) {
2196 }
2197 first_init = FALSE;
2198}
2199
2200/**********************************************************************/
2204{
2206 || (role >= L_FIRST && role < L_LAST)
2207 || (role >= L_LAST && role < MAX_UNIT_ROLES), -1);
2209 return n_with_role[role];
2210}
2211
2212/**********************************************************************/
2218{
2219 int i;
2220
2221 for (i = 0; i < n_with_role[role]; i++) {
2222 if (cb(with_role[role][i], data)) {
2223 return with_role[role][i];
2224 }
2225 }
2226
2227 return NULL;
2228}
2229
2230/**********************************************************************/
2237{
2238 int i;
2239
2240 for (i = n_with_role[role] - 1; i >= 0; i--) {
2241 if (cb(with_role[role][i], data)) {
2242 return with_role[role][i];
2243 }
2244 }
2245
2246 return NULL;
2247}
2248
2249/**********************************************************************/
2254{
2256 || (role >= L_FIRST && role < L_LAST)
2257 || (role >= L_LAST && role < MAX_UNIT_ROLES), NULL);
2259 if (role_index == -1) {
2261 }
2263
2264 return with_role[role][role_index];
2265}
2266
2267/**********************************************************************/
2271struct unit_type *best_role_unit(const struct city *pcity, int role)
2272{
2273 struct unit_type *u;
2274 int j;
2275
2277 || (role >= L_FIRST && role < L_LAST)
2278 || (role >= L_LAST && role < MAX_UNIT_ROLES), NULL);
2280
2281 for (j = n_with_role[role] - 1; j >= 0; j--) {
2282 u = with_role[role][j];
2283 if (can_city_build_unit_now(pcity, u)) {
2284 return u;
2285 }
2286 }
2287
2288 return NULL;
2289}
2290
2291/**********************************************************************/
2297struct unit_type *best_role_unit_for_player(const struct player *pplayer,
2298 int role)
2299{
2300 int j;
2301
2303 || (role >= L_FIRST && role < L_LAST)
2304 || (role >= L_LAST && role < MAX_UNIT_ROLES), NULL);
2306
2307 for (j = n_with_role[role] - 1; j >= 0; j--) {
2308 struct unit_type *utype = with_role[role][j];
2309
2310 if (can_player_build_unit_now(pplayer, utype)) {
2311 return utype;
2312 }
2313 }
2314
2315 return NULL;
2316}
2317
2318/**********************************************************************/
2322struct unit_type *first_role_unit_for_player(const struct player *pplayer,
2323 int role)
2324{
2325 int j;
2326
2328 || (role >= L_FIRST && role < L_LAST)
2329 || (role >= L_LAST && role < MAX_UNIT_ROLES), NULL);
2331
2332 for (j = 0; j < n_with_role[role]; j++) {
2333 struct unit_type *utype = with_role[role][j];
2334
2335 if (can_player_build_unit_now(pplayer, utype)) {
2336 return utype;
2337 }
2338 }
2339
2340 return NULL;
2341}
2342
2343/**********************************************************************/
2347{
2348 int i;
2349
2350 /* Can't use unit_type_iterate or utype_by_number here because
2351 * num_unit_types isn't known yet. */
2352 for (i = 0; i < ARRAY_SIZE(unit_types); i++) {
2360 }
2361}
2362
2363/**********************************************************************/
2367{
2368 if (NULL != punittype->helptext) {
2369 strvec_destroy(punittype->helptext);
2370 punittype->helptext = NULL;
2371 }
2372
2373 requirement_vector_free(&(punittype->build_reqs));
2374
2377 FC_FREE(pbonus);
2380}
2381
2382/**********************************************************************/
2386{
2387 int i;
2388
2389 /* Can't use unit_type_iterate or utype_by_number here because
2390 * we want to free what unit_types_init() has allocated. */
2391 for (i = 0; i < ARRAY_SIZE(unit_types); i++) {
2393 }
2394}
2395
2396/**********************************************************************/
2400{
2401 int i;
2402
2403 for (i = 0; i < MAX_NUM_USER_UNIT_FLAGS; i++) {
2405 }
2406}
2407
2408/**********************************************************************/
2412{
2413 int i;
2414
2415 for (i = 0; i < MAX_NUM_USER_UCLASS_FLAGS; i++) {
2417 }
2418}
2419
2420/**********************************************************************/
2424{
2425 if (game.control.num_unit_classes > 0) {
2426 return unit_classes;
2427 }
2428 return NULL;
2429}
2430
2431/**********************************************************************/
2435{
2436 if (game.control.num_unit_classes > 0) {
2438 }
2439 return NULL;
2440}
2441
2442/**********************************************************************/
2449
2450#ifndef uclass_index
2451/**********************************************************************/
2458{
2460 return pclass - unit_classes;
2461}
2462#endif /* uclass_index */
2463
2464/**********************************************************************/
2468{
2470 return pclass->item_number;
2471}
2472
2473/**********************************************************************/
2477{
2479 return NULL;
2480 }
2481 return &unit_classes[id];
2482}
2483
2484#ifndef utype_class
2485/**********************************************************************/
2488struct unit_class *utype_class(const struct unit_type *punittype)
2489{
2490 fc_assert(NULL != punittype->uclass);
2491 return punittype->uclass;
2492}
2493#endif /* utype_class */
2494
2495/**********************************************************************/
2498struct unit_class *unit_class_get(const struct unit *punit)
2499{
2501}
2502
2503/**********************************************************************/
2507{
2508 int i;
2509
2510 /* Can't use unit_class_iterate or uclass_by_number here because
2511 * num_unit_classes isn't known yet. */
2512 for (i = 0; i < ARRAY_SIZE(unit_classes); i++) {
2522 }
2523}
2524
2525/**********************************************************************/
2562
2563/**********************************************************************/
2566const struct veteran_system *
2568{
2570
2571 if (punittype->veteran) {
2572 return punittype->veteran;
2573 }
2574
2576 return game.veteran;
2577}
2578
2579/**********************************************************************/
2582const struct veteran_level *
2584{
2586
2588 fc_assert_ret_val(vsystem->definitions != NULL, NULL);
2589 fc_assert_ret_val(vsystem->levels > level, NULL);
2590
2591 return (vsystem->definitions + level);
2592}
2593
2594/**********************************************************************/
2599 int level)
2600{
2601 if (utype_veteran_levels(punittype) <= 1) {
2602 return NULL;
2603 } else {
2605
2606 return name_translation_get(&vlvl->name);
2607 }
2608}
2609
2610/**********************************************************************/
2614{
2616
2618
2619 return vsystem->levels;
2620}
2621
2622/**********************************************************************/
2627{
2629 for (i = 1; i < utype_veteran_levels(punittype); i++) {
2631 return TRUE;
2632 }
2633 }
2634 return FALSE;
2635}
2636
2637/**********************************************************************/
2641{
2642 struct veteran_system *vsystem;
2643
2644 /* There must be at least one level. */
2645 fc_assert_ret_val(count > 0, NULL);
2646
2647 vsystem = fc_calloc(1, sizeof(*vsystem));
2648 vsystem->levels = count;
2649 vsystem->definitions = fc_calloc(vsystem->levels,
2650 sizeof(*vsystem->definitions));
2651
2652 return vsystem;
2653}
2654
2655/**********************************************************************/
2659{
2660 if (vsystem) {
2661 if (vsystem->definitions) {
2662 free(vsystem->definitions);
2663 }
2664 free(vsystem);
2665 }
2666}
2667
2668/**********************************************************************/
2672 const char *vlist_name, int vlist_power,
2673 int vlist_move, int vlist_raise,
2674 int vlist_wraise)
2675{
2676 struct veteran_level *vlevel;
2677
2679 fc_assert_ret(vsystem->levels > level);
2680
2681 vlevel = vsystem->definitions + level;
2682
2683 names_set(&vlevel->name, NULL, vlist_name, NULL);
2684 vlevel->power_fact = vlist_power;
2685 vlevel->move_bonus = vlist_move;
2686 vlevel->base_raise_chance = vlist_raise;
2687 vlevel->work_raise_chance = vlist_wraise;
2688}
2689
2690/**********************************************************************/
2697{
2699 /* Return the very first! */
2700 return padv;
2702
2703 /* There was no tech requirements */
2704 return advance_by_number(A_NONE);
2705}
2706
2707/**********************************************************************/
2711 struct advance *padv)
2712{
2714 if (padv == preq) {
2715 return TRUE;
2716 }
2718
2719 return FALSE;
2720}
2721
2722/**********************************************************************/
2725void *utype_ai_data(const struct unit_type *ptype, const struct ai_type *ai)
2726{
2727 return ptype->ais[ai_type_number(ai)];
2728}
2729
2730/**********************************************************************/
2733void utype_set_ai_data(struct unit_type *ptype, const struct ai_type *ai,
2734 void *data)
2735{
2736 ptype->ais[ai_type_number(ai)] = data;
2737}
2738
2739/**********************************************************************/
2743{
2744 pclass->cache.refuel_extras = extra_type_list_new();
2745 pclass->cache.native_tile_extras = extra_type_list_new();
2746 pclass->cache.native_bases = extra_type_list_new();
2747 pclass->cache.bonus_roads = extra_type_list_new();
2748 pclass->cache.hiding_extras = extra_type_list_new();
2749 pclass->cache.subset_movers = unit_class_list_new();
2750
2751 extra_type_iterate(pextra) {
2752 if (is_native_extra_to_uclass(pextra, pclass)) {
2753 struct road_type *proad = extra_road_get(pextra);
2754
2755 if (extra_has_flag(pextra, EF_REFUEL)) {
2756 extra_type_list_append(pclass->cache.refuel_extras, pextra);
2757 }
2758 if (extra_has_flag(pextra, EF_NATIVE_TILE)) {
2759 extra_type_list_append(pclass->cache.native_tile_extras, pextra);
2760 }
2761 if (is_extra_caused_by(pextra, EC_BASE)) {
2762 extra_type_list_append(pclass->cache.native_bases, pextra);
2763 }
2765 extra_type_list_append(pclass->cache.bonus_roads, pextra);
2766 }
2767 if (pextra->eus == EUS_HIDDEN) {
2768 extra_type_list_append(pclass->cache.hiding_extras, pextra);
2769 }
2770 }
2772
2774 bool subset_mover = TRUE;
2775
2776 terrain_type_iterate(pterrain) {
2777 if (BV_ISSET(pterrain->native_to, uclass_index(pcharge))
2778 && !BV_ISSET(pterrain->native_to, uclass_index(pclass))) {
2780 }
2782
2783 if (subset_mover) {
2784 extra_type_iterate(pextra) {
2786 && !is_native_extra_to_uclass(pextra, pclass)) {
2788 }
2790 }
2791
2792 if (subset_mover) {
2793 unit_class_list_append(pclass->cache.subset_movers, pcharge);
2794 }
2796}
2797
2798/**********************************************************************/
2802{
2803 ptype->cache.max_defense_mp_bonus_pct = -FC_INFINITY;
2804
2805 unit_type_iterate(utype) {
2806 int idx = utype_index(utype);
2807 int bonus = combat_bonus_against(
2808 ptype->bonuses, utype, CBONUS_DEFENSE_MULTIPLIER_PCT)
2809 + 100 * combat_bonus_against(ptype->bonuses, utype,
2811 int scramble_bonus =
2812 combat_bonus_against(ptype->bonuses, utype,
2814
2815 ptype->cache.defense_mp_bonuses_pct[idx] = bonus;
2816 /* max value is for city defenders, so it considers scrambling */
2817 /* FIXME: if the unit's fuel != 1, scrambling is not so useful */
2818 if (scramble_bonus) {
2819 /* Guess about city defense effect value */
2820 struct universal u
2821 = { .kind = VUT_UTYPE, .value = {.utype = utype} };
2823
2824 emax = CLIP(0, emax, 300); /* Likely sth wrong if more */
2825 emax -= emax >> 2; /* Might be no such building yet */
2826 bonus
2827 = (ptype->cache.scramble_coeff[idx]
2828 = (bonus + 100) * (scramble_bonus + 100)
2829 ) / (100 + emax) - 100;
2830 bonus = MAX(bonus, 1); /* to look better in assess_danger() */
2831 } else {
2832 ptype->cache.scramble_coeff[idx] = 0;
2833 }
2834 if (bonus > ptype->cache.max_defense_mp_bonus_pct) {
2835 ptype->cache.max_defense_mp_bonus_pct = bonus;
2836 }
2838}
2839
2840/**********************************************************************/
2844 struct unit_class *puc)
2845{
2846 bool land_allowed = TRUE;
2847 bool sea_allowed = TRUE;
2848
2849 if (!extra_has_flag(pextra, EF_NATIVE_TILE)) {
2850 return unit_move_type_invalid();
2851 }
2852 if (!is_native_extra_to_uclass(pextra, puc)) {
2853 return unit_move_type_invalid();
2854 }
2855
2856 if (is_extra_caused_by(pextra, EC_ROAD)
2857 && road_has_flag(extra_road_get(pextra), RF_RIVER)) {
2858 /* Natural rivers are created to land only */
2860 }
2861
2863 if (preq->source.kind == VUT_TERRAINCLASS) {
2864 if (!preq->present) {
2865 if (preq->source.value.terrainclass == TC_LAND) {
2867 } else if (preq->source.value.terrainclass == TC_OCEAN) {
2869 }
2870 } else {
2871 if (preq->source.value.terrainclass == TC_LAND) {
2873 } else if (preq->source.value.terrainclass == TC_OCEAN) {
2875 }
2876 }
2877 } else if (preq->source.kind == VUT_TERRAIN) {
2878 if (!preq->present) {
2879 if (preq->source.value.terrain->tclass == TC_LAND) {
2881 } else if (preq->source.value.terrain->tclass == TC_OCEAN) {
2883 }
2884 } else {
2885 if (preq->source.value.terrain->tclass == TC_LAND) {
2887 } else if (preq->source.value.terrain->tclass == TC_OCEAN) {
2889 }
2890 }
2891 }
2893
2894 if (land_allowed && sea_allowed) {
2895 return UMT_BOTH;
2896 }
2897 if (land_allowed && !sea_allowed) {
2898 return UMT_LAND;
2899 }
2900 if (!land_allowed && sea_allowed) {
2901 return UMT_SEA;
2902 }
2903
2904 return unit_move_type_invalid();
2905}
2906
2907/**********************************************************************/
2911{
2912 bool land_moving = FALSE;
2913 bool sea_moving = FALSE;
2914
2915 extra_type_iterate(pextra) {
2917
2918 if (eut == UMT_BOTH) {
2919 land_moving = TRUE;
2920 sea_moving = TRUE;
2921 } else if (eut == UMT_LAND) {
2922 land_moving = TRUE;
2923 } else if (eut == UMT_SEA) {
2924 sea_moving = TRUE;
2925 }
2927
2928 terrain_type_iterate(pterrain) {
2929 if (is_native_to_class(puclass, pterrain, NULL)) {
2930 if (is_ocean(pterrain)) {
2931 sea_moving = TRUE;
2932 } else {
2933 land_moving = TRUE;
2934 }
2935 }
2937
2938 if (land_moving && sea_moving) {
2939 puclass->move_type = UMT_BOTH;
2940 } else if (sea_moving) {
2941 puclass->move_type = UMT_SEA;
2942 } else {
2943 /* If unit has no native terrains, it is considered land moving */
2944 puclass->move_type = UMT_LAND;
2945 }
2946}
2947
2948/**********************************************************************/
2951bool utype_is_cityfounder(const struct unit_type *utype)
2952{
2954 /* No unit is allowed to found new cities */
2955 return FALSE;
2956 }
2957
2959}
2960
2961/**********************************************************************/
2968{
2969 unit_class_iterate(uclass) {
2970 if (uclass_has_flag(uclass, ucflag)) {
2971 /* Found a user. */
2972 return TRUE;
2973 }
2975
2976 /* No users detected. */
2977 return FALSE;
2978}
2979
2980/**********************************************************************/
2987{
2989 if (utype_has_flag(putype, uflag)) {
2990 /* Found a user. */
2991 return TRUE;
2992 }
2994
2995 /* No users detected. */
2996 return FALSE;
2997}
enum action_actor_kind action_get_actor_kind(const struct action *paction)
Definition actions.c:1850
bool action_actor_utype_hard_reqs_ok(const struct action *paction, const struct unit_type *actor_unittype)
Definition actions.c:3347
const char * action_rule_name(const struct action *action)
Definition actions.c:1968
bool action_id_exists(const action_id act_id)
Definition actions.c:1820
enum action_target_kind action_get_target_kind(const struct action *paction)
Definition actions.c:1860
struct action_enabler_list * action_enablers_for_action(action_id action)
Definition actions.c:2306
#define action_by_result_iterate(_paction_, _result_)
Definition actions.h:479
#define action_enablers_iterate_end
Definition actions.h:517
#define enabler_get_action(_enabler_)
Definition actions.h:431
#define enabler_get_action_id(_enabler_)
Definition actions.h:432
static struct action * action_by_number(action_id act_id)
Definition actions.h:633
#define action_has_result(_act_, _res_)
Definition actions.h:429
#define action_enabler_list_iterate_end
Definition actions.h:439
#define action_by_result_iterate_end
Definition actions.h:483
#define action_iterate_end
Definition actions.h:463
#define action_id_get_actor_kind(act_id)
Definition actions.h:646
#define action_enablers_iterate(_enabler_)
Definition actions.h:511
#define action_enabler_list_iterate(action_enabler_list, aenabler)
Definition actions.h:437
#define action_id(_act_)
Definition actions.h:659
#define action_iterate(_act_)
Definition actions.h:459
#define ACTION_ANY
Definition actions.h:306
bool actres_removes_extra(enum action_result result, const struct extra_type *pextra)
Definition actres.c:806
bool actres_creates_extra(enum action_result result, const struct extra_type *pextra)
Definition actres.c:785
bool actres_is_hostile(enum action_result result)
Definition actres.c:286
int ai_type_number(const struct ai_type *ai)
Definition ai.c:278
const char * astr_build_or_list(struct astring *astr, const char *const *items, size_t number)
Definition astring.c:329
void astr_set(struct astring *astr, const char *format,...)
Definition astring.c:267
const char * astr_build_and_list(struct astring *astr, const char *const *items, size_t number)
Definition astring.c:367
#define BV_DEFINE(name, bits)
Definition bitvector.h:132
#define BV_CLR_ALL(bv)
Definition bitvector.h:95
#define BV_SET(bv, bit)
Definition bitvector.h:81
#define BV_ISSET(bv, bit)
Definition bitvector.h:78
#define BV_CLR(bv, bit)
Definition bitvector.h:86
struct output_type * get_output_type(Output_type_id output)
Definition city.c:637
bool can_city_build_unit_now(const struct city *pcity, const struct unit_type *punittype)
Definition city.c:945
#define city_tile(_pcity_)
Definition city.h:564
#define city_owner(_pcity_)
Definition city.h:563
int combat_bonus_against(const struct combat_bonus_list *list, const struct unit_type *enemy, enum combat_bonus_type type)
Definition combat.c:1000
char * incite_cost
Definition comments.c:74
static void base(QVariant data1, QVariant data2)
Definition dialogs.cpp:2931
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit * punit
Definition dialogs_g.h:74
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit int cost
Definition dialogs_g.h:74
int int id
Definition editgui_g.h:28
bool effect_universals_value_never_below(enum effect_type type, struct universal *unis, size_t n_unis, int min_value)
Definition effects.c:545
struct @21::@22 reqs
int get_target_bonus_effects(struct effect_list *plist, const struct req_context *context, const struct player *other_player, enum effect_type effect_type)
Definition effects.c:748
int effect_cumulative_max(enum effect_type type, struct universal *unis, size_t n_unis)
Definition effects.c:388
int get_unittype_bonus(const struct player *pplayer, const struct tile *ptile, const struct unit_type *punittype, const struct action *paction, enum effect_type effect_type)
Definition effects.c:1035
int get_player_bonus(const struct player *pplayer, enum effect_type effect_type)
Definition effects.c:828
bool extra_has_flag(const struct extra_type *pextra, enum extra_flag_id flag)
Definition extras.c:861
bool is_native_extra_to_uclass(const struct extra_type *pextra, const struct unit_class *pclass)
Definition extras.c:843
#define extra_type_iterate(_p)
Definition extras.h:315
#define extra_type_iterate_end
Definition extras.h:321
#define is_extra_caused_by(e, c)
Definition extras.h:203
#define extra_type_list_iterate_end
Definition extras.h:167
#define extra_road_get(_e_)
Definition extras.h:191
@ RPT_CERTAIN
Definition fc_types.h:704
int Unit_Class_id
Definition fc_types.h:421
int action_id
Definition fc_types.h:392
int Unit_type_id
Definition fc_types.h:385
@ O_SHIELD
Definition fc_types.h:101
@ O_GOLD
Definition fc_types.h:101
#define UCL_LAST
Definition fc_types.h:420
enum output_type_id Output_type_id
Definition fc_types.h:381
#define _(String)
Definition fcintl.h:67
#define Qn_(String)
Definition fcintl.h:89
void user_flag_init(struct user_flag *flag)
Definition game.c:822
void user_flag_free(struct user_flag *flag)
Definition game.c:831
struct civ_game game
Definition game.c:62
struct city * owner
Definition citydlg.c:220
bool can_player_build_improvement_direct(const struct player *p, const struct impr_type *pimprove)
bool great_wonder_is_built(const struct impr_type *pimprove)
bool great_wonder_is_destroyed(const struct impr_type *pimprove)
struct city * city_from_wonder(const struct player *pplayer, const struct impr_type *pimprove)
bool is_great_wonder(const struct impr_type *pimprove)
bool is_small_wonder(const struct impr_type *pimprove)
struct player * great_wonder_owner(const struct impr_type *pimprove)
const char * name
Definition inputfile.c:127
#define fc_assert_msg(condition, message,...)
Definition log.h:181
#define fc_assert_ret(condition)
Definition log.h:191
#define fc_assert(condition)
Definition log.h:176
#define fc_assert_ret_val(condition, val)
Definition log.h:194
#define log_debug(message,...)
Definition log.h:115
static int map_move_cost(const struct civ_map *nmap, const struct player *pplayer, const struct unit_type *punittype, const struct tile *src_tile, const struct tile *dst_tile)
Definition map.h:305
#define fc_calloc(n, esz)
Definition mem.h:38
#define FC_FREE(ptr)
Definition mem.h:41
#define fc_strdup(str)
Definition mem.h:43
#define fc_malloc(sz)
Definition mem.h:34
const char * move_points_text(int mp, bool reduce)
Definition movement.c:1015
bool is_native_to_class(const struct unit_class *punitclass, const struct terrain *pterrain, const bv_extras *extras)
Definition movement.c:342
#define MAX_MOVE_FRAGS
Definition movement.h:29
static const char * rule_name_get(const struct name_translation *ptrans)
static const char * name_translation_get(const struct name_translation *ptrans)
static void names_set(struct name_translation *ptrans, const char *domain, const char *vernacular_name, const char *rule_name)
static bool is_barbarian(const struct player *pplayer)
Definition player.h:489
bool is_req_in_vec(const struct requirement *req, const struct requirement_vector *vec)
bool is_req_active(const struct req_context *context, const struct player *other_player, const struct requirement *req, const enum req_problem_type prob_type)
bool does_req_contradicts_reqs(const struct requirement *req, const struct requirement_vector *vec)
void req_copy(struct requirement *dst, const struct requirement *src)
#define requirement_fulfilled_by_unit_type(_ut_, _rqs_)
#define requirement_diplrel_ereq(_id_, _range_, _present_)
#define requirement_vector_iterate_end
#define requirement_vector_iterate(req_vec, preq)
bool road_has_flag(const struct road_type *proad, enum road_flag_id flag)
Definition road.c:410
bool road_provides_move_bonus(const struct road_type *proad)
Definition road.c:499
struct setting_list * level[OLEVELS_NUM]
Definition settings.c:190
#define CLIP(lower, current, upper)
Definition shared.h:57
#define ARRAY_SIZE(x)
Definition shared.h:85
#define FC_INFINITY
Definition shared.h:36
#define MAX(x, y)
Definition shared.h:54
void strvec_destroy(struct strvec *psv)
enum action_result result
Definition actions.h:363
Definition ai.h:50
Definition city.h:320
struct tile * tile
Definition city.h:322
struct packet_ruleset_control control
Definition game.h:83
struct packet_game_info info
Definition game.h:89
struct packet_scenario_info scenario
Definition game.h:87
struct veteran_system * veteran
Definition game.h:101
struct requirement_vector reqs
Definition extras.h:106
struct unit_list * units
Definition player.h:280
int max
Definition unittype.c:881
int min
Definition unittype.c:880
const struct player * player
enum req_range range
struct universal source
Definition tile.h:50
Unit_Class_id item_number
Definition unittype.h:150
struct unit_class_list * subset_movers
Definition unittype.h:173
struct extra_type_list * refuel_extras
Definition unittype.h:168
struct extra_type_list * native_tile_extras
Definition unittype.h:169
struct unit_class::@86 cache
struct extra_type_list * native_bases
Definition unittype.h:170
struct extra_type_list * bonus_roads
Definition unittype.h:171
struct strvec * helptext
Definition unittype.h:159
bool ruledit_disabled
Definition unittype.h:152
struct extra_type_list * hiding_extras
Definition unittype.h:172
int pop_cost
Definition unittype.h:513
struct requirement_vector build_reqs
Definition unittype.h:520
Unit_type_id item_number
Definition unittype.h:501
struct veteran_system * veteran
Definition unittype.h:544
const struct unit_type * obsoleted_by
Definition unittype.h:529
struct strvec * helptext
Definition unittype.h:571
int upkeep[O_LAST]
Definition unittype.h:538
bool ruledit_disabled
Definition unittype.h:503
struct combat_bonus_list * bonuses
Definition unittype.h:526
void * ruledit_dlg
Definition unittype.h:504
Definition unit.h:138
const struct unit_type * utype
Definition unit.h:139
enum universals_n kind
Definition fc_types.h:903
universals_u value
Definition fc_types.h:902
char * name
Definition game.h:74
char * helptxt
Definition game.h:75
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:974
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:189
int cat_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:1000
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
struct advance * advance_by_number(const Tech_type_id atype)
Definition tech.c:107
#define A_NONE
Definition tech.h:43
#define terrain_type_iterate(_p)
Definition terrain.h:373
#define is_ocean(pterrain)
Definition terrain.h:301
#define terrain_type_iterate_end
Definition terrain.h:379
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
enum citytile_type citytile
Definition fc_types.h:733
enum ustate_prop unit_state
Definition fc_types.h:752
int unit_shield_value(const struct unit *punit, const struct unit_type *punittype, const struct action *paction)
Definition unit.c:217
#define unit_owner(_pu)
Definition unit.h:389
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
#define unit_list_iterate_end
Definition unitlist.h:33
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)
Definition unittype.c:1124
int utype_buy_gold_cost(const struct city *pcity, const struct unit_type *punittype, int shields_in_stock)
Definition unittype.c:1492
void unit_types_init(void)
Definition unittype.c:2346
bool can_unit_act_when_ustate_is(const struct unit_type *punit_type, const enum ustate_prop prop, const bool is_there)
Definition unittype.c:943
const char * uclass_name_translation(const struct unit_class *pclass)
Definition unittype.c:1632
void set_unit_class_caches(struct unit_class *pclass)
Definition unittype.c:2742
struct unit_type * best_role_unit(const struct city *pcity, int role)
Definition unittype.c:2271
static struct unit_type unit_types[U_LAST]
Definition unittype.c:44
struct unit_type * role_units_iterate(int role, role_unit_callback cb, void *data)
Definition unittype.c:2217
bool utype_action_takes_all_mp(const struct unit_type *putype, struct action *paction)
Definition unittype.c:1191
const char * utype_veteran_name_translation(const struct unit_type *punittype, int level)
Definition unittype.c:2598
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:123
bool utype_has_class_flag(const struct unit_type *ptype, enum unit_class_flag_id flag)
Definition unittype.c:1657
void user_unit_type_flags_init(void)
Definition unittype.c:1864
int utype_pays_mp_for_action_base(const struct action *paction, const struct unit_type *putype)
Definition unittype.c:1381
bool utype_player_already_has_this(const struct player *pplayer, const struct unit_type *putype)
Definition unittype.c:1941
static struct range * moves_left_range(struct requirement_vector *reqs)
Definition unittype.c:890
bool utype_can_freely_unload(const struct unit_type *pcargotype, const struct unit_type *ptranstype)
Definition unittype.c:300
#define ACTION_HOSTILE
Definition unittype.c:308
const char * unit_class_flag_helptxt(enum unit_class_flag_id id)
Definition unittype.c:1854
bool utype_pays_for_regular_move_to_tgt(const struct action *paction, const struct unit_type *utype)
Definition unittype.c:1330
static void unit_type_free(struct unit_type *punittype)
Definition unittype.c:2366
struct unit_type * role_units_iterate_backwards(int role, role_unit_callback cb, void *data)
Definition unittype.c:2236
static void precalc_one(int i, bool(*func_has)(const struct unit_type *, int))
Definition unittype.c:2132
static struct user_flag user_class_flags[MAX_NUM_USER_UCLASS_FLAGS]
Definition unittype.c:53
static bv_diplrel_all_reqs dipl_rel_action_cache[U_LAST][ACTION_AND_FAKES]
Definition unittype.c:566
bool utype_can_remove_extra(const struct unit_type *putype, const struct extra_type *pextra)
Definition unittype.c:241
int unit_build_shield_cost(const struct city *pcity, const struct unit *punit)
Definition unittype.c:1476
const char * unit_name_translation(const struct unit *punit)
Definition unittype.c:1569
static bv_unit_types utype_act_takes_all_mp_ustate_cache[ACTION_COUNT][USP_COUNT]
Definition unittype.c:493
bool unit_has_class_flag(const struct unit *punit, enum unit_class_flag_id flag)
Definition unittype.c:1649
bool can_player_build_unit_direct(const struct player *p, const struct unit_type *punittype, bool consider_reg_impr_req)
Definition unittype.c:1968
bool utype_is_moved_to_tgt_by_action(const struct action *paction, const struct unit_type *utype)
Definition unittype.c:1249
bool is_tech_req_for_utype(const struct unit_type *ptype, struct advance *padv)
Definition unittype.c:2710
static bv_citytile_cache ctile_tgt_act_cache[U_LAST][ACTION_AND_FAKES]
Definition unittype.c:569
int utype_upkeep_cost(const struct unit_type *ut, struct player *pplayer, Output_type_id otype)
Definition unittype.c:132
enum unit_move_type utype_move_type(const struct unit_type *punittype)
Definition unittype.c:1551
struct unit_type * first_role_unit_for_player(const struct player *pplayer, int role)
Definition unittype.c:2322
Unit_Class_id uclass_count(void)
Definition unittype.c:2445
bool utype_is_cityfounder(const struct unit_type *utype)
Definition unittype.c:2951
const struct unit_class * unit_class_array_last(void)
Definition unittype.c:2434
struct unit_type * unit_type_by_rule_name(const char *name)
Definition unittype.c:1767
struct unit_type * get_role_unit(int role, int role_index)
Definition unittype.c:2253
struct unit_type * unit_type_array_first(void)
Definition unittype.c:58
void unit_class_flags_free(void)
Definition unittype.c:2411
bool uclass_flag_is_in_use(enum unit_class_flag_id ucflag)
Definition unittype.c:2967
#define MAX_UNIT_ROLES
Definition unittype.c:42
const char * unit_rule_name(const struct unit *punit)
Definition unittype.c:1587
bool utype_has_role(const struct unit_type *punittype, int role)
Definition unittype.c:199
static enum unit_move_type move_type_from_extra(struct extra_type *pextra, struct unit_class *puc)
Definition unittype.c:2843
void set_unit_move_type(struct unit_class *puclass)
Definition unittype.c:2910
static bv_diplrel_all_reqs dipl_rel_tile_other_tgt_a_cache[U_LAST][ACTION_AND_FAKES]
Definition unittype.c:568
void unit_type_action_cache_init(void)
Definition unittype.c:931
static void local_dipl_rel_tile_other_tgt_action_cache_set(struct unit_type *putype)
Definition unittype.c:734
int utype_build_shield_cost_base(const struct unit_type *punittype)
Definition unittype.c:1468
void set_unit_type_caches(struct unit_type *ptype)
Definition unittype.c:2801
bool utype_may_act_move_frags(const struct unit_type *punit_type, const action_id act_id, const int move_fragments)
Definition unittype.c:1058
const struct veteran_system * utype_veteran_system(const struct unit_type *punittype)
Definition unittype.c:2567
bool utype_is_consumed_by_action_result(enum action_result result, const struct unit_type *utype)
Definition unittype.c:1229
int num_role_units(int role)
Definition unittype.c:2203
static bool first_init
Definition unittype.c:2124
bool utype_player_already_has_this_unique(const struct player *pplayer, const struct unit_type *putype)
Definition unittype.c:1927
static bv_unit_types utype_act_takes_all_mp_cache[ACTION_COUNT]
Definition unittype.c:451
static bool utype_can_do_action_role(const struct unit_type *putype, const int role)
Definition unittype.c:433
void unit_types_free(void)
Definition unittype.c:2385
bool utype_may_act_at_all(const struct unit_type *putype)
Definition unittype.c:359
int unit_build_shield_cost_base(const struct unit *punit)
Definition unittype.c:1484
const struct unit_type * can_upgrade_unittype(const struct player *pplayer, const struct unit_type *punittype)
Definition unittype.c:1703
struct unit_type * best_role_unit_for_player(const struct player *pplayer, int role)
Definition unittype.c:2297
void role_unit_precalcs(void)
Definition unittype.c:2175
struct unit_class * uclass_by_number(const Unit_Class_id id)
Definition unittype.c:2476
bool utype_can_create_extra(const struct unit_type *putype, const struct extra_type *pextra)
Definition unittype.c:217
static void local_dipl_rel_action_cache_set(struct unit_type *putype)
Definition unittype.c:649
static void tgt_citytile_act_cache_set(struct unit_type *putype)
Definition unittype.c:811
struct advance * utype_primary_tech_req(const struct unit_type *ptype)
Definition unittype.c:2696
bool utype_can_freely_load(const struct unit_type *pcargotype, const struct unit_type *ptranstype)
Definition unittype.c:288
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)
Definition unittype.c:2671
#define MOVES_LEFT_INFINITY
Definition unittype.c:884
#define requirement_citytile_ereq(_id_, _present_)
Definition unittype.c:561
Unit_type_id utype_count(void)
Definition unittype.c:80
static void unit_state_action_cache_set(struct unit_type *putype)
Definition unittype.c:576
static bv_ustate_act_cache ustate_act_cache[U_LAST][ACTION_AND_FAKES]
Definition unittype.c:565
int utype_veteran_levels(const struct unit_type *punittype)
Definition unittype.c:2613
int utype_pays_mp_for_action_estimate(const struct civ_map *nmap, const struct action *paction, const struct unit_type *putype, const struct player *act_player, const struct tile *act_tile, const struct tile *tgt_tile)
Definition unittype.c:1393
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)
Definition unittype.c:955
void veteran_system_destroy(struct veteran_system *vsystem)
Definition unittype.c:2658
const char * utype_rule_name(const struct unit_type *punittype)
Definition unittype.c:1578
struct unit_class * unit_class_get(const struct unit *punit)
Definition unittype.c:2498
bool utype_can_do_action_result_when_ustate(const struct unit_type *putype, enum action_result result, const enum ustate_prop prop, const bool is_there)
Definition unittype.c:975
struct unit_type * utype_by_number(const Unit_type_id id)
Definition unittype.c:112
bool utype_can_do_action_result(const struct unit_type *putype, enum action_result result)
Definition unittype.c:387
bool unit_has_type_role(const struct unit *punit, enum unit_role_id role)
Definition unittype.c:208
static void unit_can_act_cache_set(struct unit_type *putype)
Definition unittype.c:323
bool utype_action_takes_all_mp_if_ustate_is(const struct unit_type *putype, struct action *paction, const enum ustate_prop prop)
Definition unittype.c:1207
const struct veteran_level * utype_veteran_level(const struct unit_type *punittype, int level)
Definition unittype.c:2583
bool unit_has_type_flag(const struct unit *punit, enum unit_type_flag_id flag)
Definition unittype.c:190
bool unit_can_take_over(const struct unit *punit)
Definition unittype.c:264
static bv_unit_types unit_can_act_cache[ACTION_AND_FAKES]
Definition unittype.c:317
void unit_classes_free(void)
Definition unittype.c:2528
void unit_type_action_cache_set(struct unit_type *ptype)
Definition unittype.c:915
const char * uclass_rule_name(const struct unit_class *pclass)
Definition unittype.c:1641
const char * unit_class_flag_id_name_cb(enum unit_class_flag_id flag)
Definition unittype.c:1842
bool utype_is_consumed_by_action(const struct action *paction, const struct unit_type *utype)
Definition unittype.c:1219
void unit_type_flags_free(void)
Definition unittype.c:2399
static void utype_act_takes_all_mp_cache_set(struct unit_type *putype)
Definition unittype.c:457
static void utype_act_takes_all_mp_ustate_cache_set(struct unit_type *putype)
Definition unittype.c:500
Unit_type_id utype_number(const struct unit_type *punittype)
Definition unittype.c:100
const char * unit_type_flag_id_name_cb(enum unit_type_flag_id flag)
Definition unittype.c:1905
bool utype_veteran_has_power_bonus(const struct unit_type *punittype)
Definition unittype.c:2626
void user_unit_class_flags_init(void)
Definition unittype.c:1800
bool utype_can_act_if_tgt_diplrel_tile_other(const struct unit_type *punit_type, const action_id act_id, const int prop, const bool is_there)
Definition unittype.c:1036
struct unit_class * unit_class_by_rule_name(const char *s)
Definition unittype.c:1784
struct unit_type * unit_type_by_translated_name(const char *name)
Definition unittype.c:1752
const char * unit_type_flag_helptxt(enum unit_type_flag_id id)
Definition unittype.c:1917
const char * utype_values_string(const struct unit_type *punittype)
Definition unittype.c:1596
void * utype_ai_data(const struct unit_type *ptype, const struct ai_type *ai)
Definition unittype.c:2725
struct unit_class * unit_class_array_first(void)
Definition unittype.c:2423
Unit_type_id utype_index(const struct unit_type *punittype)
Definition unittype.c:91
void unit_classes_init(void)
Definition unittype.c:2506
bool utype_flag_is_in_use(enum unit_type_flag_id uflag)
Definition unittype.c:2986
#define ACTION_AND_FAKES
Definition unittype.c:311
static struct user_flag user_type_flags[MAX_NUM_USER_UNIT_FLAGS]
Definition unittype.c:51
int utype_pop_value(const struct unit_type *punittype, const struct city *pcity)
Definition unittype.c:1528
bool utype_can_take_over(const struct unit_type *punittype)
Definition unittype.c:276
void utype_set_ai_data(struct unit_type *ptype, const struct ai_type *ai, void *data)
Definition unittype.c:2733
void set_user_unit_class_flag_name(enum unit_class_flag_id id, const char *name, const char *helptxt)
Definition unittype.c:1812
bool can_player_build_unit_later(const struct player *p, const struct unit_type *punittype)
Definition unittype.c:2099
static struct unit_class unit_classes[UCL_LAST]
Definition unittype.c:45
int utype_build_shield_cost(const struct city *pcity, const struct player *pplayer, const struct unit_type *punittype)
Definition unittype.c:1438
int unit_pop_value(const struct unit *punit)
Definition unittype.c:1543
#define requirement_unit_state_ereq(_id_, _present_)
Definition unittype.c:559
void role_unit_precalcs_free(void)
Definition unittype.c:2160
struct veteran_system * veteran_system_new(int count)
Definition unittype.c:2640
Unit_Class_id uclass_number(const struct unit_class *pclass)
Definition unittype.c:2467
bool can_player_build_unit_now(const struct player *p, const struct unit_type *punittype)
Definition unittype.c:2078
bool utype_can_do_action_sub_result(const struct unit_type *putype, enum action_sub_result sub_result)
Definition unittype.c:408
static struct unit_type ** with_role[MAX_UNIT_ROLES]
Definition unittype.c:2126
bool utype_is_unmoved_by_action(const struct action *paction, const struct unit_type *utype)
Definition unittype.c:1288
bool utype_acts_hostile(const struct unit_type *putype)
Definition unittype.c:443
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)
Definition unittype.c:996
const char * utype_name_translation(const struct unit_type *punittype)
Definition unittype.c:1560
static int n_with_role[MAX_UNIT_ROLES]
Definition unittype.c:2125
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)
Definition unittype.c:1017
bool utype_can_do_action(const struct unit_type *putype, const action_id act_id)
Definition unittype.c:371
void set_user_unit_type_flag_name(enum unit_type_flag_id id, const char *name, const char *helptxt)
Definition unittype.c:1876
int utype_happy_cost(const struct unit_type *ut, const struct player *pplayer)
Definition unittype.c:181
bool role_units_translations(struct astring *astr, int flag, bool alts)
Definition unittype.c:1668
const char * utype_values_translation(const struct unit_type *punittype)
Definition unittype.c:1617
const struct unit_type * unit_type_array_last(void)
Definition unittype.c:69
int unit_upgrade_price(const struct player *pplayer, const struct unit_type *from, const struct unit_type *to)
Definition unittype.c:1731
#define UCF_LAST_USER_FLAG
Definition unittype.h:127
static bool uclass_has_flag(const struct unit_class *punitclass, enum unit_class_flag_id flag)
Definition unittype.h:766
#define utype_class(_t_)
Definition unittype.h:749
#define utype_fuel(ptype)
Definition unittype.h:836
#define combat_bonus_list_iterate_end
Definition unittype.h:482
#define L_FIRST
Definition unittype.h:349
#define combat_bonus_list_iterate(bonuslist, pbonus)
Definition unittype.h:480
#define unit_tech_reqs_iterate_end
Definition unittype.h:878
#define unit_class_iterate(_p)
Definition unittype.h:905
#define unit_tech_reqs_iterate(_utype_, _p)
Definition unittype.h:872
#define MAX_NUM_USER_UNIT_FLAGS
Definition unittype.h:332
static bool utype_has_flag(const struct unit_type *punittype, int flag)
Definition unittype.h:617
#define UTYF_LAST_USER_FLAG
Definition unittype.h:331
#define L_LAST
Definition unittype.h:439
bool(* role_unit_callback)(struct unit_type *ptype, void *data)
Definition unittype.h:722
#define unit_type_iterate(_p)
Definition unittype.h:852
#define U_LAST
Definition unittype.h:40
#define uclass_index(_c_)
Definition unittype.h:742
#define unit_class_iterate_end
Definition unittype.h:912
#define unit_type_iterate_end
Definition unittype.h:859
#define MAX_NUM_USER_UCLASS_FLAGS
Definition unittype.h:128
#define U_NOT_OBSOLETED
Definition unittype.h:528