Freeciv-3.3
Loading...
Searching...
No Matches
actions.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996-2013 - Freeciv Development Team
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 <math.h> /* ceil(), floor() */
19
20/* utility */
21#include "astring.h"
22
23/* common */
24#include "actions.h"
25#include "city.h"
26#include "combat.h"
27#include "fc_interface.h"
28#include "game.h"
29#include "map.h"
30#include "metaknowledge.h"
31#include "movement.h"
32#include "oblig_reqs.h"
33#include "research.h"
34#include "server_settings.h"
35#include "unit.h"
36
37
38/* Values used to interpret action probabilities.
39 *
40 * Action probabilities are sent over the network. A change in a value here
41 * will therefore change the network protocol.
42 *
43 * A change in a value here should also update the action probability
44 * format documentation in fc_types.h */
45/* The lowest possible probability value (0%) */
46#define ACTPROB_VAL_MIN 0
47/* The highest possible probability value (100%) */
48#define ACTPROB_VAL_MAX 200
49/* A probability increase of 1% corresponds to this increase. */
50#define ACTPROB_VAL_1_PCT (ACTPROB_VAL_MAX / 100)
51/* Action probability doesn't apply when min is this. */
52#define ACTPROB_VAL_NA 253
53/* Action probability unsupported when min is this. */
54#define ACTPROB_VAL_NOT_IMPL 254
55
60
62
64
65static struct action *
68 bool rare_pop_up,
71 const int min_distance,
72 const int max_distance,
74static struct action *
77
78static bool is_enabler_active(const struct action_enabler *enabler,
79 const struct req_context *actor,
80 const struct req_context *target);
81
82static inline bool
84static inline bool
86static inline bool
88
90 const struct unit *pvictim,
91 const struct tile *tgt_tile,
92 const struct action *paction)
94
95/* Make sure that an action distance can target the whole map. */
98
101
102
103/**********************************************************************/
106static void hard_code_actions(void)
107{
110 FALSE, TRUE,
111 MAK_ESCAPE, 0, 1, TRUE);
114 FALSE, TRUE,
115 MAK_ESCAPE, 0, 1, FALSE);
118 FALSE, TRUE,
119 MAK_ESCAPE, 0, 1, TRUE);
122 FALSE, TRUE,
123 MAK_ESCAPE, 0, 1, FALSE);
126 FALSE, TRUE,
127 /* Tries a forced move if the target unit is alone at
128 * its tile and not in a city. Takes all movement if
129 * the forced move fails. */
131 0, 1, FALSE);
134 FALSE, TRUE,
136 0, 1, FALSE);
139 FALSE, TRUE,
140 MAK_ESCAPE, 0, 1, TRUE);
143 FALSE, TRUE,
144 MAK_ESCAPE, 0, 1, FALSE);
148 FALSE, TRUE,
149 MAK_ESCAPE, 0, 1, TRUE);
153 FALSE, TRUE,
154 MAK_ESCAPE, 0, 1, TRUE);
158 FALSE, TRUE,
159 MAK_ESCAPE, 0, 1, FALSE);
163 FALSE, TRUE,
164 MAK_ESCAPE, 0, 1, FALSE);
167 FALSE, TRUE,
168 MAK_ESCAPE, 0, 1, TRUE);
171 FALSE, TRUE,
172 MAK_ESCAPE, 0, 1, FALSE);
176 FALSE, TRUE,
177 MAK_STAYS, 0, 1, FALSE);
181 FALSE, TRUE,
182 MAK_STAYS, 0, 1, TRUE);
186 FALSE, TRUE,
187 MAK_ESCAPE, 0, 1, TRUE);
191 FALSE, TRUE,
192 MAK_ESCAPE, 0, 1, FALSE);
196 FALSE, TRUE,
197 MAK_ESCAPE, 0, 1, TRUE);
201 FALSE, TRUE,
202 MAK_ESCAPE, 0, 1, FALSE);
206 FALSE, TRUE,
207 MAK_STAYS, 0, 1, FALSE);
211 FALSE, TRUE,
212 MAK_STAYS, 0, 1, TRUE);
216 FALSE, TRUE,
217 MAK_ESCAPE, 0, 1, TRUE);
221 FALSE, TRUE,
222 MAK_ESCAPE, 0, 1, FALSE);
226 FALSE, TRUE,
227 MAK_ESCAPE, 0, 1, FALSE);
231 FALSE, TRUE,
232 MAK_ESCAPE, 0, 1, FALSE);
235 FALSE, TRUE,
236 MAK_STAYS, 0, 1, TRUE);
239 FALSE, TRUE,
240 MAK_STAYS, 0, 1, TRUE);
243 FALSE, TRUE,
244 MAK_STAYS, 0, 1, TRUE);
248 /* A single domestic unit at the target tile will make
249 * the action illegal. It must therefore be performed
250 * from another tile. */
251 1, 1,
252 FALSE);
256 /* Illegal to perform to a target on another tile.
257 * Reason: The Freeciv code assumes that the city
258 * founding unit is located at the tile were the new
259 * city is founded. */
260 0, 0,
261 TRUE);
264 TRUE, TRUE,
265 MAK_STAYS, 0, 1, TRUE);
268 FALSE, TRUE,
269 MAK_ESCAPE, 0, 1, TRUE);
272 FALSE, TRUE,
273 MAK_ESCAPE, 0, 1, FALSE);
277 /* A single domestic unit at the target tile will make
278 * the action illegal. It must therefore be performed
279 * from another tile. */
280 1,
281 /* Overwritten by the ruleset's bombard_max_range */
282 1,
283 FALSE);
286 FALSE, TRUE,
287 MAK_STAYS,
288 /* A single domestic unit at the target tile will make
289 * the action illegal. It must therefore be performed
290 * from another tile. */
291 1,
292 /* Overwritten by the ruleset's bombard_2_max_range */
293 1,
294 FALSE);
298 /* A single domestic unit at the target tile will make
299 * the action illegal. It must therefore be performed
300 * from another tile. */
301 1,
302 /* Overwritten by the ruleset's bombard_3_max_range */
303 1,
304 FALSE);
308 /* A single domestic unit at the target tile will make
309 * the action illegal. It must therefore be performed
310 * from another tile. */
311 1,
312 /* Overwritten by the ruleset's bombard_4_max_range */
313 1,
314 FALSE);
318 /* A single domestic unit at the target tile will make
319 * the action illegal. It must therefore be performed
320 * from another tile. */
321 1,
322 /* Overwritten by the ruleset's bombard_lethal_max_range */
323 1,
324 FALSE);
328 /* A single domestic unit at the target tile will make
329 * the action illegal. It must therefore be performed
330 * from another tile. */
331 1,
332 /* Overwritten by the ruleset's bombard_lethal_2_max_range */
333 1,
334 FALSE);
337 FALSE, TRUE,
338 MAK_ESCAPE, 0, 1, TRUE);
341 FALSE, TRUE,
342 MAK_ESCAPE, 0, 1, FALSE);
345 TRUE, TRUE,
346 MAK_STAYS, 0,
347 /* Overwritten by the ruleset's
348 * explode_nuclear_max_range */
349 0,
350 TRUE);
353 TRUE, TRUE,
354 MAK_STAYS, 1, 1, TRUE);
357 TRUE, TRUE,
358 MAK_STAYS, 1, 1, TRUE);
361 TRUE, TRUE,
362 MAK_STAYS, 0, 1, FALSE);
365 FALSE, TRUE,
366 MAK_STAYS, 0, 1, FALSE);
370 /* Illegal to perform to a target on another tile to
371 * keep the rules exactly as they were for now. */
372 0, 1,
373 TRUE);
376 /* Can't be ACTRES_NONE because
377 * action_success_actor_consume() sets unit lost
378 * reason based on action result. */
380 TRUE, TRUE,
381 MAK_STAYS, 0, 0, TRUE);
384 TRUE, FALSE,
385 /* Illegal to perform to a target on another tile to
386 * keep the rules exactly as they were for now. */
387 MAK_STAYS, 0, 0, FALSE);
390 TRUE, FALSE,
391 MAK_STAYS, 0, 0, FALSE);
395 /* Illegal to perform to a target on another tile to
396 * keep the rules exactly as they were for now. */
397 0, 0,
398 FALSE);
401 TRUE, TRUE,
403 1,
404 /* Still limited by each unit type's
405 * paratroopers_range field. */
407 FALSE);
410 TRUE, TRUE,
412 1,
413 /* Still limited by each unit type's
414 * paratroopers_range field. */
416 FALSE);
419 TRUE, TRUE,
421 1,
422 /* Still limited by each unit type's
423 * paratroopers_range field. */
425 FALSE);
429 TRUE, TRUE,
431 1,
432 /* Still limited by each unit type's
433 * paratroopers_range field. */
435 FALSE);
438 TRUE, TRUE,
440 1,
441 /* Still limited by each unit type's
442 * paratroopers_range field. */
444 FALSE);
448 TRUE, TRUE,
450 1,
451 /* Still limited by each unit type's
452 * paratroopers_range field. */
454 FALSE);
457 TRUE, TRUE,
459 1,
460 /* Overwritten by the ruleset's airlift_max_range. */
462 FALSE);
465 FALSE, TRUE,
466 /* Tries a forced move if the target unit's tile has
467 * no non-allied units and the occupychance dice roll
468 * tells it to move. */
470 1, 1, FALSE);
473 FALSE, TRUE,
474 /* Tries a forced move if the target unit's tile has
475 * no non-allied units and the occupychance dice roll
476 * tells it to move. */
478 1, 1, FALSE);
481 FALSE, TRUE,
482 MAK_FORCED, 1, 1, TRUE);
485 FALSE, TRUE,
486 MAK_FORCED, 1, 1, TRUE);
489 FALSE, TRUE,
491 1, 1, FALSE);
494 FALSE, FALSE,
495 MAK_STAYS, 1, 1, FALSE);
498 FALSE, FALSE,
499 MAK_STAYS, 1, 1, FALSE);
502 FALSE, TRUE,
503 MAK_REGULAR, 1, 1, FALSE);
506 FALSE, TRUE,
507 MAK_REGULAR, 1, 1, FALSE);
510 FALSE, TRUE,
511 MAK_REGULAR, 1, 1, FALSE);
514 FALSE, TRUE,
515 MAK_REGULAR, 1, 1, FALSE);
518 FALSE, TRUE,
519 MAK_REGULAR, 1, 1, FALSE);
522 FALSE, TRUE,
523 MAK_REGULAR, 1, 1, FALSE);
526 FALSE, TRUE,
527 MAK_REGULAR, 1, 1, FALSE);
530 FALSE, TRUE,
531 MAK_REGULAR, 1, 1, FALSE);
534 FALSE, TRUE,
535 MAK_STAYS, 0, 1, FALSE);
538 FALSE, TRUE,
539 MAK_STAYS, 0, 1, FALSE);
542 TRUE, FALSE,
543 MAK_STAYS, 0, 0, FALSE);
546 TRUE, FALSE,
547 MAK_STAYS, 0, 0, FALSE);
550 TRUE, FALSE,
551 MAK_STAYS, 0, 0, FALSE);
554 TRUE, FALSE,
555 MAK_STAYS, 0, 0, FALSE);
558 TRUE, FALSE,
559 MAK_STAYS, 0, 0, FALSE);
562 TRUE, FALSE,
563 MAK_STAYS, 0, 0, FALSE);
566 TRUE, FALSE,
567 MAK_STAYS, 0, 0, FALSE);
570 TRUE, FALSE,
571 MAK_STAYS, 0, 0, FALSE);
574 TRUE, FALSE,
575 MAK_STAYS, 0, 0, FALSE);
578 TRUE, FALSE,
579 MAK_STAYS, 0, 0, FALSE);
582 TRUE, FALSE,
583 MAK_STAYS, 0, 0, FALSE);
586 TRUE, FALSE,
587 MAK_STAYS, 0, 0, FALSE);
590 TRUE, FALSE,
591 MAK_STAYS, 0, 0, FALSE);
594 TRUE, FALSE,
595 MAK_STAYS, 0, 0, FALSE);
598 TRUE, FALSE,
599 MAK_STAYS, 0, 0, FALSE);
602 TRUE, FALSE,
603 MAK_STAYS, 0, 0, FALSE);
606 TRUE, FALSE,
607 MAK_STAYS, 0, 0, FALSE);
610 TRUE, FALSE,
611 MAK_STAYS, 0, 0, FALSE);
614 TRUE, FALSE,
615 MAK_STAYS, 0, 0, FALSE);
618 TRUE, FALSE,
619 MAK_STAYS, 0, 0, FALSE);
622 TRUE, FALSE,
623 MAK_STAYS, 0, 0, FALSE);
626 TRUE, FALSE,
627 MAK_STAYS, 0, 0, FALSE);
630 TRUE, FALSE,
631 MAK_STAYS, 0, 0, FALSE);
634 TRUE, FALSE,
635 MAK_STAYS, 0, 0, FALSE);
638 TRUE, FALSE,
639 MAK_STAYS, 0, 0, FALSE);
642 TRUE, FALSE,
643 MAK_STAYS, 0, 0, FALSE);
646 TRUE, FALSE,
647 MAK_STAYS, 0, 0, FALSE);
650 TRUE, FALSE,
651 MAK_STAYS, 0, 0, FALSE);
654 TRUE, FALSE,
655 MAK_STAYS, 0, 0, FALSE);
659 FALSE, TRUE,
660 MAK_REGULAR, 1, 1, FALSE);
664 FALSE, TRUE,
665 MAK_REGULAR, 1, 1, FALSE);
669 FALSE, TRUE,
670 MAK_REGULAR, 1, 1, FALSE);
674 FALSE, TRUE,
675 MAK_REGULAR, 1, 1, FALSE);
678 TRUE, TRUE,
679 MAK_REGULAR, 1, 1, FALSE);
682 TRUE, TRUE,
683 MAK_REGULAR, 1, 1, FALSE);
686 TRUE, TRUE,
687 MAK_REGULAR, 1, 1, FALSE);
690 TRUE, TRUE,
691 MAK_REGULAR, 1, 1, FALSE);
694 FALSE, TRUE,
695 MAK_STAYS, 1, 1, FALSE);
698 FALSE, TRUE,
699 MAK_REGULAR, 1, 1, FALSE);
702 FALSE, TRUE,
703 MAK_REGULAR, 1, 1, FALSE);
706 FALSE, TRUE,
707 MAK_REGULAR, 1, 1, FALSE);
710 FALSE, TRUE,
711 MAK_REGULAR, 1, 1, FALSE);
714 FALSE, TRUE,
715 MAK_REGULAR, 1, 1, FALSE);
718 FALSE, TRUE,
719 MAK_REGULAR, 1, 1, FALSE);
722 FALSE, TRUE,
723 MAK_REGULAR, 1, 1, FALSE);
726 FALSE, TRUE,
727 MAK_REGULAR, 1, 1, FALSE);
730 TRUE, TRUE,
731 MAK_REGULAR, 1, 1, FALSE);
734 TRUE, TRUE,
735 MAK_REGULAR, 1, 1, FALSE);
738 TRUE, TRUE,
739 MAK_REGULAR, 1, 1, FALSE);
742 TRUE, TRUE,
743 MAK_TELEPORT, 1, 1, FALSE);
746 TRUE, TRUE,
747 MAK_TELEPORT, 1, 1, FALSE);
750 TRUE, TRUE,
751 MAK_TELEPORT, 1, 1, FALSE);
754 TRUE, TRUE,
755 MAK_TELEPORT, 1,
760 TRUE, TRUE,
761 MAK_TELEPORT, 1,
766 TRUE, TRUE,
767 MAK_TELEPORT, 1,
772 TRUE, TRUE,
773 MAK_TELEPORT, 1,
778 TRUE, TRUE,
779 MAK_TELEPORT, 1,
783 TRUE, FALSE,
784 MAK_STAYS, 0, 0, FALSE);
787 TRUE, FALSE,
788 MAK_STAYS, 0, 0, FALSE);
791 FALSE, TRUE,
793 /* Overwritten by the ruleset */
794 0, 1, FALSE);
797 FALSE, TRUE,
799 /* Overwritten by the ruleset */
800 0, 1, FALSE);
803 FALSE, TRUE,
805 /* Overwritten by the ruleset */
806 0, 1, FALSE);
809 FALSE, TRUE,
811 /* Overwritten by the ruleset */
812 0, 1, FALSE);
815 FALSE, TRUE,
816 /* Tries a forced move if the target unit's tile has
817 * no non-allied units and the occupychance dice roll
818 * tells it to move. */
820 1, 1, FALSE);
821
824
825 /* The structure even for these need to be created, for
826 * the action_id_rule_name() to work on iterations. */
827
828 /*
829 actions[ACTION_UNUSED_1]
830 = unit_action_new(ACTION_UNUSED_1, ACTRES_NONE,
831 FALSE, FALSE,
832 MAK_UNREPRESENTABLE,
833 0, 0, FALSE);
834 */
835}
836
837/**********************************************************************/
840void actions_init(void)
841{
842 int i, j;
843
844 for (i = 0; i < ACTRES_LAST; i++) {
846 }
847 for (i = 0; i < ACTIVITY_LAST; i++) {
849 }
850
851 /* Hard code the actions */
853
854 /* Initialize the action enabler list */
855 action_iterate_all(act) {
858
859 /* Initialize action obligatory hard requirements. */
861
862 /* Obligatory hard requirements are sorted by requirement in the source
863 * code. This makes it easy to read, modify and explain it. */
865
866 /* Initialize the action auto performers. */
867 for (i = 0; i < MAX_NUM_ACTION_AUTO_PERFORMERS; i++) {
868 /* Nothing here. Nothing after this point. */
870
871 /* The criteria to pick *this* auto performer for its cause. */
873
874 for (j = 0; j < MAX_NUM_ACTIONS; j++) {
875 /* Nothing here. Nothing after this point. */
877 }
878 }
879
880 /* The actions them self are now initialized. */
882}
883
884/**********************************************************************/
890{
891 /* Some obligatory hard requirements needs access to the rest of the
892 * ruleset. */
894}
895
896/**********************************************************************/
899void actions_free(void)
900{
901 int i;
902
903 /* Don't consider the actions to be initialized any longer. */
905
906 action_iterate_all(act) {
910
912
913 FC_FREE(actions[act]);
915
916 /* Free the obligatory hard action requirements. */
918
919 /* Free the action auto performers. */
920 for (i = 0; i < MAX_NUM_ACTION_AUTO_PERFORMERS; i++) {
922 }
923
925
926 for (i = 0; i < ACTRES_LAST; i++) {
929 }
930 for (i = 0; i < ACTIVITY_LAST; i++) {
933 }
934}
935
936/**********************************************************************/
942{
943 if (!actions_initialized) {
944 /* The actions them self aren't initialized yet. */
945 return FALSE;
946 }
947
949 if (actions[act]->ui_name[0] == '\0') {
950 /* A noninternal action without a UI name exists means that
951 * the ruleset haven't loaded yet. The ruleset loading will assign
952 * a default name to any actions not named by the ruleset.
953 * The client will get this name from the server. */
954 return FALSE;
955 }
957
958 /* The actions should be ready for use. */
959 return TRUE;
960}
961
962/**********************************************************************/
965static struct action *action_new(action_id id,
968 const int min_distance,
969 const int max_distance,
971{
972 struct action *action;
973
974 action = fc_malloc(sizeof(*action));
975
976 action->id = id;
978
980
981 if (result != ACTRES_LAST) {
983
985
986 if (act != ACTIVITY_LAST) {
988 }
989 }
990
991 /* Not set here */
993
998
999 /* ASTK_NONE implies ACT_TGT_COMPL_SIMPLE and
1000 * !ASTK_NONE implies !ACT_TGT_COMPL_SIMPLE */
1005 "%s contradicts itself regarding sub targets.",
1007
1008 /* The distance between the actor and itself is always 0. */
1010 || (min_distance == 0 && max_distance == 0));
1011
1014
1016
1017 /* Loaded from the ruleset. Until generalized actions are ready it has to
1018 * be defined separately from other action data. */
1019 action->ui_name[0] = '\0';
1020 action->quiet = FALSE;
1022
1023 return action;
1024}
1025
1026/**********************************************************************/
1029static struct action *
1031 enum action_result result,
1032 bool rare_pop_up,
1035 const int min_distance,
1036 const int max_distance,
1038{
1039 struct action *act = action_new(id, AAK_UNIT, result,
1042
1044
1046
1048
1049 return act;
1050}
1051
1052/**********************************************************************/
1055static struct action *
1057 enum action_result result)
1058{
1059 struct action *act = action_new(id, AAK_PLAYER, result,
1060 0, 0, FALSE);
1061
1062 return act;
1063}
1064
1065/**********************************************************************/
1068bool action_id_exists(const action_id act_id)
1069{
1070 /* Actions are still hard coded. */
1071 return gen_action_is_valid(act_id) && actions[act_id];
1072}
1073
1074/**********************************************************************/
1079struct action *action_by_rule_name(const char *name)
1080{
1081 /* Actions are still hard coded in the gen_action enum. */
1083
1084 if (!action_id_exists(act_id)) {
1085 /* Nothing to return. */
1086
1087 log_verbose("Asked for non existing action named %s", name);
1088
1089 return NULL;
1090 }
1091
1092 return action_by_number(act_id);
1093}
1094
1095/**********************************************************************/
1099{
1100 fc_assert_ret_val_msg(paction, AAK_COUNT, "Action doesn't exist.");
1101
1102 return paction->actor_kind;
1103}
1104
1105/**********************************************************************/
1109 const struct action *paction)
1110{
1111 fc_assert_ret_val_msg(paction, ATK_COUNT, "Action doesn't exist.");
1112
1113 return paction->target_kind;
1114}
1115
1116/**********************************************************************/
1120 const struct action *paction)
1121{
1122 fc_assert_ret_val_msg(paction, ASTK_COUNT, "Action doesn't exist.");
1123
1124 return paction->sub_target_kind;
1125}
1126
1127/**********************************************************************/
1133{
1135
1136 return paction->target_complexity >= ACT_TGT_COMPL_FLEXIBLE;
1137}
1138
1139/**********************************************************************/
1146{
1148
1149 return paction->target_complexity >= ACT_TGT_COMPL_MANDATORY;
1150}
1151
1152/**********************************************************************/
1161{
1163 FALSE, "Action %d don't exist.", act_id);
1165
1166 return actions[act_id]->actor.is_unit.rare_pop_up;
1167}
1168
1169/**********************************************************************/
1174 const int distance)
1175{
1178}
1179
1180/**********************************************************************/
1185 const int distance)
1186{
1188
1189 return (distance >= action->min_distance
1190 && action_distance_inside_max(action, distance));
1191}
1192
1193/**********************************************************************/
1196bool action_would_be_blocked_by(const struct action *blocked,
1197 const struct action *blocker)
1198{
1199 fc_assert_ret_val(blocked, FALSE);
1200 fc_assert_ret_val(blocker, FALSE);
1201
1202 return BV_ISSET(blocked->blocked_by, action_number(blocker));
1203}
1204
1205/**********************************************************************/
1208int action_number(const struct action *action)
1209{
1210 return action->id;
1211}
1212
1213/**********************************************************************/
1216const char *action_rule_name(const struct action *action)
1217{
1218 /* Rule name is still hard coded. */
1219 return action_id_rule_name(action->id);
1220}
1221
1222/**********************************************************************/
1230const char *action_name_translation(const struct action *paction)
1231{
1232 /* Use action_id_name_translation() to format the UI name. */
1234}
1235
1236/**********************************************************************/
1240{
1241 fc_assert_msg(actions[act_id], "Action %d don't exist.", act_id);
1242
1243 return gen_action_name(act_id);
1244}
1245
1246/**********************************************************************/
1251{
1252 return action_prepare_ui_name(act_id, "", ACTPROB_NA, NULL);
1253}
1254
1255/**********************************************************************/
1259 const char *mnemonic)
1260{
1262}
1263
1264/**********************************************************************/
1271static const char *action_prob_to_text(const struct act_prob prob)
1272{
1273 static struct astring chance = ASTRING_INIT;
1274
1275 /* How to interpret action probabilities like prob is documented in
1276 * fc_types.h */
1277 if (action_prob_is_signal(prob)) {
1279 || action_prob_not_relevant(prob));
1280
1281 /* Unknown because of missing server support or should not exits. */
1282 return NULL;
1283 }
1284
1285 if (prob.min == prob.max) {
1286 /* Only one probability in range. */
1287
1288 /* TRANS: the probability that an action will succeed. Given in
1289 * percentage. Resolution is 0.5%. */
1290 astr_set(&chance, _("%.1f%%"), (double)prob.max / ACTPROB_VAL_1_PCT);
1291 } else {
1292 /* TRANS: the interval (end points included) where the probability of
1293 * the action's success is. Given in percentage. Resolution is 0.5%. */
1294 astr_set(&chance, _("[%.1f%%, %.1f%%]"),
1295 (double)prob.min / ACTPROB_VAL_1_PCT,
1296 (double)prob.max / ACTPROB_VAL_1_PCT);
1297 }
1298
1299 return astr_str(&chance);
1300}
1301
1302/**********************************************************************/
1312const char *action_prepare_ui_name(action_id act_id, const char *mnemonic,
1313 const struct act_prob prob,
1314 const char *custom)
1315{
1316 struct astring chance = ASTRING_INIT;
1317
1318 /* Text representation of the probability. */
1319 const char *probtxt;
1320
1321 if (!actions_are_ready()) {
1322 /* Could be a client who haven't gotten the ruleset yet */
1323
1324 /* so there shouldn't be any action probability to show */
1326
1327 /* but the action should be valid */
1329 "Invalid action",
1330 "Invalid action %d", act_id);
1331
1332 /* and no custom text will be inserted */
1333 fc_assert(custom == NULL || custom[0] == '\0');
1334
1335 /* Make the best of what is known */
1336 astr_set(&ui_name_str, _("%s%s (name may be wrong)"),
1337 mnemonic, action_id_rule_name(act_id));
1338
1339 /* Return the guess. */
1340 return astr_str(&ui_name_str);
1341 }
1342
1344
1345 /* Format the info part of the action's UI name. */
1346 if (probtxt != NULL && custom != NULL) {
1347 /* TRANS: action UI name's info part with custom info and probability.
1348 * Hint: you can move the paren handling from this string to the action
1349 * names if you need to add extra information (like a mnemonic letter
1350 * that doesn't appear in the action UI name) to it. In that case you
1351 * must do so for all strings with this comment and for every action
1352 * name. To avoid a `()` when no UI name info part is added you have
1353 * to add the extra information to every action name or remove the
1354 * surrounding parens. */
1355 astr_set(&chance, _(" (%s; %s)"), custom, probtxt);
1356 } else if (probtxt != NULL) {
1357 /* TRANS: action UI name's info part with probability.
1358 * Hint: you can move the paren handling from this string to the action
1359 * names if you need to add extra information (like a mnemonic letter
1360 * that doesn't appear in the action UI name) to it. In that case you
1361 * must do so for all strings with this comment and for every action
1362 * name. To avoid a `()` when no UI name info part is added you have
1363 * to add the extra information to every action name or remove the
1364 * surrounding parens. */
1365 astr_set(&chance, _(" (%s)"), probtxt);
1366 } else if (custom != NULL) {
1367 /* TRANS: action UI name's info part with custom info.
1368 * Hint: you can move the paren handling from this string to the action
1369 * names if you need to add extra information (like a mnemonic letter
1370 * that doesn't appear in the action UI name) to it. In that case you
1371 * must do so for all strings with this comment and for every action
1372 * name. To avoid a `()` when no UI name info part is added you have
1373 * to add the extra information to every action name or remove the
1374 * surrounding parens. */
1375 astr_set(&chance, _(" (%s)"), custom);
1376 } else {
1377 /* No info part to display. */
1379 }
1380
1381 fc_assert_msg(actions[act_id], "Action %d don't exist.", act_id);
1382
1383 /* Escape any instances of the mnemonic in the action's UI format string.
1384 * (Assumes any mnemonic can be escaped by doubling, and that they are
1385 * unlikely to appear in a format specifier. True for clients seen so
1386 * far: Gtk's _ and Qt's &) */
1387 {
1388 struct astring fmtstr = ASTRING_INIT;
1389 const char *ui_name = _(actions[act_id]->ui_name);
1390
1391 if (mnemonic[0] != '\0') {
1392 const char *hit;
1393
1394 fc_assert(!strchr(mnemonic, '%'));
1395 while ((hit = strstr(ui_name, mnemonic))) {
1396 astr_add(&fmtstr, "%.*s%s%s", (int)(hit - ui_name), ui_name,
1398 ui_name = hit + strlen(mnemonic);
1399 }
1400 }
1401 astr_add(&fmtstr, "%s", ui_name);
1402
1403 /* Use the modified format string */
1405 astr_str(&chance));
1406
1407 astr_free(&fmtstr);
1408 }
1409
1410 astr_free(&chance);
1411
1412 return astr_str(&ui_name_str);
1413}
1414
1415/**********************************************************************/
1423const char *action_prob_explain(const struct act_prob prob)
1424{
1425 static struct astring tool_tip = ASTRING_INIT;
1426
1427 if (action_prob_is_signal(prob)) {
1429
1430 /* Missing server support. No in game action will change this. */
1432 } else if (prob.min == prob.max) {
1433 /* TRANS: action probability of success. Given in percentage.
1434 * Resolution is 0.5%. */
1435 astr_set(&tool_tip, _("The probability of success is %.1f%%."),
1436 (double)prob.max / ACTPROB_VAL_1_PCT);
1437 } else {
1439 /* TRANS: action probability interval (min to max). Given in
1440 * percentage. Resolution is 0.5%. The string at the end is
1441 * shown when the interval is wide enough to not be caused by
1442 * rounding. It explains that the interval is imprecise because
1443 * the player doesn't have enough information. */
1444 _("The probability of success is %.1f%%, %.1f%% or somewhere"
1445 " in between.%s"),
1446 (double)prob.min / ACTPROB_VAL_1_PCT,
1447 (double)prob.max / ACTPROB_VAL_1_PCT,
1448 prob.max - prob.min > 1 ?
1449 /* TRANS: explanation used in the action probability tooltip
1450 * above. Preserve leading space. */
1451 _(" (This is the most precise interval I can calculate "
1452 "given the information our nation has access to.)") :
1453 "");
1454 }
1455
1456 return astr_str(&tool_tip);
1457}
1458
1459/**********************************************************************/
1464{
1466 "Action %s isn't performed by a unit",
1468
1469 return paction->id + L_LAST;
1470}
1471
1472/**********************************************************************/
1476{
1477 struct action_enabler *enabler;
1478
1479 enabler = fc_malloc(sizeof(*enabler));
1480 enabler->rulesave.ruledit_disabled = FALSE;
1481 enabler->rulesave.comment = nullptr;
1482 requirement_vector_init(&enabler->actor_reqs);
1483 requirement_vector_init(&enabler->target_reqs);
1484
1485 /* Make sure that action doesn't end up as a random value that happens to
1486 * be a valid action id. */
1487 enabler->action = ACTION_NONE;
1488
1489 return enabler;
1490}
1491
1492/**********************************************************************/
1496{
1497 if (enabler->rulesave.comment != nullptr) {
1498 free(enabler->rulesave.comment);
1499 }
1500
1501 requirement_vector_free(&enabler->actor_reqs);
1502 requirement_vector_free(&enabler->target_reqs);
1503
1504 free(enabler);
1505}
1506
1507/**********************************************************************/
1510struct action_enabler *
1512{
1514
1515 enabler->action = original->action;
1516
1517 requirement_vector_copy(&enabler->actor_reqs, &original->actor_reqs);
1518 requirement_vector_copy(&enabler->target_reqs, &original->target_reqs);
1519
1520 return enabler;
1521}
1522
1523/**********************************************************************/
1527{
1528 /* Sanity check: a non existing action enabler can't be added. */
1530 /* Sanity check: a non existing action doesn't have enablers. */
1532
1535 enabler);
1536}
1537
1538/**********************************************************************/
1544{
1545 /* Sanity check: a non existing action enabler can't be removed. */
1547 /* Sanity check: a non existing action doesn't have enablers. */
1549
1552 enabler);
1553}
1554
1555/**********************************************************************/
1558struct action_enabler_list *
1560{
1561 /* Sanity check: a non existing action doesn't have enablers. */
1563
1565}
1566
1567/**********************************************************************/
1578static struct req_vec_problem *
1580 const struct obligatory_req_vector *oblig)
1581{
1582 struct action *paction;
1583
1584 /* Sanity check: a non existing action enabler is missing but it doesn't
1585 * miss any obligatory hard requirements. */
1587
1588 /* Sanity check: a non existing action doesn't have any obligatory hard
1589 * requirements. */
1592
1593 /* No obligatory hard requirements. */
1595
1597 struct req_vec_problem *out;
1598 int i;
1599 bool fulfilled = FALSE;
1600
1601 /* Check each alternative. */
1602 for (i = 0; i < obreq->contras->alternatives; i++) {
1603 const struct requirement_vector *ae_vec;
1604
1605 /* Select action enabler requirement vector. */
1606 ae_vec = (obreq->contras->alternative[i].is_target
1607 ? &enabler->target_reqs
1608 : &enabler->actor_reqs);
1609
1610 if (does_req_contradicts_reqs(&obreq->contras->alternative[i].req,
1611 ae_vec)
1612 /* Consider the hard requirement fulfilled since a universal that
1613 * never is there always will be absent in this ruleset. */
1614 || (obreq->contras->alternative[i].req.present
1616 &obreq->contras->alternative[i].req.source))) {
1617 /* It is enough that one alternative accepts the enabler. */
1618 fulfilled = TRUE;
1619 break;
1620 }
1621
1622 /* Fall back to the next alternative */
1623 }
1624
1625 if (fulfilled) {
1626 /* This obligatory hard requirement isn't a problem. */
1627 continue;
1628 }
1629
1630 /* Missing hard obligatory requirement detected */
1631
1632 out = req_vec_problem_new(obreq->contras->alternatives,
1633 obreq->error_msg,
1635
1636 for (i = 0; i < obreq->contras->alternatives; i++) {
1637 const struct requirement_vector *ae_vec;
1638
1639 /* Select action enabler requirement vector. */
1640 ae_vec = (obreq->contras->alternative[i].is_target
1641 ? &enabler->target_reqs
1642 : &enabler->actor_reqs);
1643
1644 /* The suggested fix is to append a requirement that makes the enabler
1645 * contradict the missing hard obligatory requirement detector. */
1646 out->suggested_solutions[i].operation = RVCO_APPEND;
1647 out->suggested_solutions[i].vector_number
1649
1650 /* Change the requirement from what should conflict to what is
1651 * wanted. */
1652 out->suggested_solutions[i].req.present
1653 = !obreq->contras->alternative[i].req.present;
1654 out->suggested_solutions[i].req.source
1655 = obreq->contras->alternative[i].req.source;
1656 out->suggested_solutions[i].req.range
1657 = obreq->contras->alternative[i].req.range;
1658 out->suggested_solutions[i].req.survives
1659 = obreq->contras->alternative[i].req.survives;
1660 out->suggested_solutions[i].req.quiet
1661 = obreq->contras->alternative[i].req.quiet;
1662 }
1663
1664 /* Return the first problem found. The next problem will be detected
1665 * during the next call. */
1666 return out;
1668
1669 /* No obligatory req problems found. */
1670 return NULL;
1671}
1672
1673/**********************************************************************/
1682struct req_vec_problem *
1684{
1685 struct action *paction;
1687 struct req_vec_problem *out;
1688
1689 /* Sanity check: a non existing action enabler is missing but it doesn't
1690 * miss any obligatory hard requirements. */
1692
1693 /* Sanity check: a non existing action doesn't have any obligatory hard
1694 * requirements. */
1697
1698 if (paction->result != ACTRES_NONE) {
1699 /* A hard coded action result may mean obligatory requirements. */
1701 if (out != NULL) {
1702 return out;
1703 }
1704 }
1705
1709 if (!BV_ISSET(paction->sub_results, sub_res)) {
1710 /* Not relevant */
1711 continue;
1712 }
1713
1714 /* The action has this sub result. Check its hard requirements. */
1717 if (out != NULL) {
1718 return out;
1719 }
1720 }
1721
1722 /* No obligatory req problems found. */
1723 return NULL;
1724}
1725
1726/**********************************************************************/
1732static struct requirement *
1734{
1736 if (preq->source.kind == VUT_DIPLREL
1737 && preq->range == REQ_RANGE_LOCAL) {
1738 return preq;
1739 }
1741
1742 return NULL;
1743}
1744
1745/**********************************************************************/
1751static struct req_vec_problem *
1753 const struct action_enabler *enabler)
1754{
1755 struct req_vec_problem *out;
1756 struct requirement *local_diplrel;
1757 struct requirement *claimed_req;
1761 struct astring astr;
1762
1764 /* Not tile targeted */
1765 return NULL;
1766 }
1767
1769 if (local_diplrel == NULL) {
1770 /* No local diplrel */
1771 return NULL;
1772 }
1773
1774 /* Tile is unclaimed as a requirement. */
1776 tile_is_unclaimed.survives = FALSE;
1777 tile_is_unclaimed.source.kind = VUT_CITYTILE;
1778 tile_is_unclaimed.present = FALSE;
1779 tile_is_unclaimed.source.value.citytile = CITYT_CLAIMED;
1780
1782 &enabler->target_reqs);
1783
1784 if (claimed_req) {
1785 /* Already clear */
1786 return NULL;
1787 }
1788
1789 /* Tile is claimed as a requirement. */
1791 tile_is_claimed.survives = FALSE;
1792 tile_is_claimed.source.kind = VUT_CITYTILE;
1793 tile_is_claimed.present = TRUE;
1794 tile_is_claimed.source.value.citytile = CITYT_CLAIMED;
1795
1797 1,
1798 /* TRANS: ruledit shows this when an enabler for a tile targeted
1799 * action requires that the actor has a diplomatic relationship to
1800 * the target but doesn't require that the target tile is claimed.
1801 * (DiplRel requirements to an unclaimed tile are never fulfilled
1802 * so this is implicit.) */
1803 N_("Requirement {%s} of action \"%s\" implies a claimed "
1804 "tile. No diplomatic relation to Nature."),
1806
1807 astr_free(&astr);
1808
1809 /* The solution is to add the requirement that the tile is claimed */
1810 out->suggested_solutions[0].req = tile_is_claimed;
1811 out->suggested_solutions[0].vector_number
1813 out->suggested_solutions[0].operation = RVCO_APPEND;
1814
1815 return out;
1816}
1817
1818/**********************************************************************/
1824static struct req_vec_problem *
1826{
1827 struct req_vec_problem *out;
1828 struct requirement *local_diplrel;
1829 struct requirement *unclaimed_req;
1832 struct astring astr1;
1833 struct astring astr2;
1834
1836 /* Not tile targeted */
1837 return NULL;
1838 }
1839
1841 if (local_diplrel == NULL) {
1842 /* No local diplrel */
1843 return NULL;
1844 }
1845
1846 /* Tile is claimed as a requirement. */
1848 tile_is_claimed.survives = FALSE;
1849 tile_is_claimed.source.kind = VUT_CITYTILE;
1850 tile_is_claimed.present = TRUE;
1851 tile_is_claimed.source.value.citytile = CITYT_CLAIMED;
1852
1854 &enabler->target_reqs);
1855
1856 if (unclaimed_req == NULL) {
1857 /* No unclaimed req */
1858 return NULL;
1859 }
1860
1862 2,
1863 /* TRANS: ruledit shows this when an enabler for a tile targeted
1864 * action requires that the target tile is unclaimed and that the
1865 * actor has a diplomatic relationship to the target. (DiplRel
1866 * requirements to an unclaimed tile are never fulfilled.) */
1867 N_("In enabler for \"%s\": No diplomatic relation to Nature."
1868 " Requirements {%s} and {%s} contradict each other."),
1872
1873 astr_free(&astr1);
1874 astr_free(&astr2);
1875
1876 /* The first suggestion is to remove the diplrel */
1877 out->suggested_solutions[0].req = *local_diplrel;
1878 out->suggested_solutions[0].vector_number
1880 out->suggested_solutions[0].operation = RVCO_REMOVE;
1881
1882 /* The 2nd is to remove the requirement that the tile is unclaimed */
1883 out->suggested_solutions[1].req = *unclaimed_req;
1884 out->suggested_solutions[1].vector_number
1886 out->suggested_solutions[1].operation = RVCO_REMOVE;
1887
1888 return out;
1889}
1890
1891/**********************************************************************/
1896struct req_vec_problem *
1898{
1899 struct req_vec_problem *out;
1900
1902 if (out != NULL) {
1903 return out;
1904 }
1905
1906 /* Look for errors in the requirement vectors. */
1907 out = req_vec_suggest_repair(&enabler->actor_reqs,
1909 enabler);
1910 if (out != NULL) {
1911 return out;
1912 }
1913
1914 out = req_vec_suggest_repair(&enabler->target_reqs,
1916 enabler);
1917 if (out != NULL) {
1918 return out;
1919 }
1920
1921 /* Enabler specific contradictions. */
1923 if (out != NULL) {
1924 return out;
1925 }
1926
1927 /* Needed in action not enabled explanation finding. */
1929 if (out != NULL) {
1930 return out;
1931 }
1932
1933 /* No problems found. */
1934 return NULL;
1935}
1936
1937/**********************************************************************/
1944static struct req_vec_problem *
1946{
1947 struct req_vec_problem *out;
1948
1949 out = NULL;
1950
1951 return out;
1952}
1953
1954/**********************************************************************/
1962struct req_vec_problem *
1964{
1965 struct action *paction;
1966 struct req_vec_problem *out;
1967
1969 if (out) {
1970 /* A bug, not just a potential improvement */
1971 return out;
1972 }
1973
1975
1976 /* Look for improvement suggestions to the requirement vectors. */
1979 enabler);
1980 if (out) {
1981 return out;
1982 }
1983 out = req_vec_suggest_improvement(&enabler->target_reqs,
1985 enabler);
1986 if (out) {
1987 return out;
1988 }
1989
1990 /* Detect unused action enablers. */
1992 bool has_user = FALSE;
1993
1997 &(enabler->actor_reqs))) {
1998 has_user = TRUE;
1999 break;
2000 }
2002
2003 if (!has_user) {
2004 /* TRANS: ruledit warns a user about an unused action enabler */
2005 out = req_vec_problem_new(0, N_("Action enabler for \"%s\" is never"
2006 " used by any unit."),
2008 }
2009 }
2010 if (out != NULL) {
2011 return out;
2012 }
2013
2015
2016 return out;
2017}
2018
2019/**********************************************************************/
2028 const struct requirement_vector *vec)
2029{
2030 struct action_enabler *ae = (struct action_enabler *)enabler;
2031
2032 if (vec == &ae->actor_reqs) {
2033 return 0;
2034 } else if (vec == &ae->target_reqs) {
2035 return 1;
2036 } else {
2037 return -1;
2038 }
2039}
2040
2041/********************************************************************/
2049struct requirement_vector *
2051 req_vec_num_in_item number)
2052{
2053 struct action_enabler *ae = (struct action_enabler *)enabler;
2054
2055 fc_assert_ret_val(number >= 0, NULL);
2056
2057 switch (number) {
2058 case 0:
2059 return &ae->actor_reqs;
2060 case 1:
2061 return &ae->target_reqs;
2062 default:
2063 return NULL;
2064 }
2065}
2066
2067/*********************************************************************/
2075{
2076 switch (vec) {
2077 case 0:
2078 /* TRANS: requirement vector in an action enabler (ruledit) */
2079 return _("actor_reqs");
2080 case 1:
2081 /* TRANS: requirement vector in an action enabler (ruledit) */
2082 return _("target_reqs");
2083 default:
2084 return NULL;
2085 }
2086}
2087
2088/**********************************************************************/
2093static const struct impr_type *
2095{
2096 /* Only used with city targets */
2098
2099 if (target_city->production.kind == VUT_IMPROVEMENT) {
2100 /* The local building is what the target city currently is building. */
2101 return target_city->production.value.building;
2102 } else {
2103 /* In the current semantic the local building is always the building
2104 * being built. */
2105 /* TODO: Consider making the local building the target building for
2106 * actions that allows specifying a building target. */
2107 return NULL;
2108 }
2109}
2110
2111/**********************************************************************/
2116static const struct unit_type *
2118{
2119 /* Only used with city targets */
2121
2122 if (target_city->production.kind == VUT_UTYPE) {
2123 /* The local unit type is what the target city currently is
2124 * building. */
2125 return target_city->production.value.utype;
2126 } else {
2127 /* In the current semantic the local utype is always the type of the
2128 * unit being built. */
2129 return NULL;
2130 }
2131}
2132
2133/**********************************************************************/
2141static const struct tile *
2143 const struct unit *actor_unit,
2144 const struct tile *target_tile_arg,
2145 const struct city *target_city,
2146 const struct unit *target_unit)
2147{
2148 if (target_tile_arg != NULL) {
2149 /* Trust the caller. */
2150 return target_tile_arg;
2151 }
2152
2153 /* Action should always be set */
2154 fc_assert_ret_val(act, NULL);
2155
2156 switch (action_get_target_kind(act)) {
2157 case ATK_CITY:
2159 return city_tile(target_city);
2160 case ATK_UNIT:
2161 if (target_unit == NULL) {
2163 return NULL;
2164 }
2165 return unit_tile(target_unit);
2166 case ATK_STACK:
2168 if (target_unit) {
2169 return unit_tile(target_unit);
2170 }
2171
2173 case ATK_TILE:
2174 case ATK_EXTRAS:
2176 return target_tile_arg;
2177 case ATK_SELF:
2178 if (actor_unit != nullptr) {
2179 return unit_tile(actor_unit);
2180 }
2181 return nullptr;
2182 case ATK_COUNT:
2183 /* Handled below. */
2184 break;
2185 }
2186
2187 fc_assert_msg(FALSE, "Bad action target kind %d for action %s",
2189 return nullptr;
2190}
2191
2192/**********************************************************************/
2201static const struct city *
2203 const struct unit *actor_unit,
2204 const struct tile *target_tile,
2205 const struct city *target_city_arg,
2206 const struct unit *target_unit)
2207{
2208 if (target_city_arg != NULL) {
2209 /* Trust the caller. */
2210 return target_city_arg;
2211 }
2212
2213 /* action should always be set */
2214 fc_assert_ret_val(act, NULL);
2215
2216 switch (action_get_target_kind(act)) {
2217 case ATK_CITY:
2219 return target_city_arg;
2220 case ATK_UNIT:
2224 case ATK_STACK:
2226 if (target_unit) {
2229 }
2230
2232 case ATK_TILE:
2233 case ATK_EXTRAS:
2235 return tile_city(target_tile);
2236 case ATK_SELF:
2237 if (actor_unit != nullptr) {
2238 struct tile *ptile = unit_tile(actor_unit);
2239
2240 if (ptile != nullptr) {
2241 return tile_city(ptile);
2242 }
2243 }
2244 return nullptr;
2245 case ATK_COUNT:
2246 /* Handled below. */
2247 break;
2248 }
2249
2250 fc_assert_msg(FALSE, "Bad action target kind %d for action %s",
2252 return NULL;
2253}
2254
2255/**********************************************************************/
2262 const struct action *act,
2263 const struct unit *actor_unit,
2264 const struct tile *target_tile_arg,
2265 const struct city *target_city_arg,
2266 const struct unit *target_unit)
2267{
2268 const struct tile *target_tile
2271 const struct city *target_city
2274
2276 struct action *blocker = action_by_number(blocker_id);
2277
2278 if (action_get_actor_kind(blocker) != AAK_UNIT) {
2279 /* Currently, only unit's actions may block each other */
2280 continue;
2281 }
2282
2283 if (!action_would_be_blocked_by(act, blocker)) {
2284 /* It doesn't matter if it is legal. It won't block the action. */
2285 continue;
2286 }
2287
2288 switch (action_get_target_kind(blocker)) {
2289 case ATK_CITY:
2290 if (!target_city) {
2291 /* Can't be enabled. No target. */
2292 continue;
2293 }
2296 return blocker;
2297 }
2298 break;
2299 case ATK_UNIT:
2300 if (!target_unit) {
2301 /* Can't be enabled. No target. */
2302 continue;
2303 }
2306 return blocker;
2307 }
2308 break;
2309 case ATK_STACK:
2310 if (!target_tile) {
2311 /* Can't be enabled. No target. */
2312 continue;
2313 }
2316 return blocker;
2317 }
2318 break;
2319 case ATK_TILE:
2320 if (!target_tile) {
2321 /* Can't be enabled. No target. */
2322 continue;
2323 }
2326 return blocker;
2327 }
2328 break;
2329 case ATK_EXTRAS:
2330 if (!target_tile) {
2331 /* Can't be enabled. No target. */
2332 continue;
2333 }
2336 return blocker;
2337 }
2338 break;
2339 case ATK_SELF:
2341 return blocker;
2342 }
2343 break;
2344 case ATK_COUNT:
2346 continue);
2347 break;
2348 }
2350
2351 /* Not blocked. */
2352 return NULL;
2353}
2354
2355/**********************************************************************/
2375static bool
2377 const struct unit_type *actor_unittype,
2378 bool ignore_third_party)
2379{
2380 switch (paction->result) {
2381 case ACTRES_JOIN_CITY:
2382 if (actor_unittype->pop_cost <= 0) {
2383 /* Reason: Must have population to add. */
2384 return FALSE;
2385 }
2386 break;
2387
2388 case ACTRES_BOMBARD:
2389 if (actor_unittype->bombard_rate <= 0) {
2390 /* Reason: Can't bombard if it never fires. */
2391 return FALSE;
2392 }
2393
2394 if (actor_unittype->attack_strength <= 0) {
2395 /* Reason: Can't bombard without attack strength. */
2396 return FALSE;
2397 }
2398
2399 break;
2400
2402 if (actor_unittype->obsoleted_by == U_NOT_OBSOLETED) {
2403 /* Reason: Nothing to upgrade to. */
2404 return FALSE;
2405 }
2406 break;
2407
2408 case ACTRES_ATTACK:
2409 case ACTRES_WIPE_UNITS:
2411 if (actor_unittype->attack_strength <= 0) {
2412 /* Reason: Can't attack without strength. */
2413 return FALSE;
2414 }
2415 break;
2416
2417 case ACTRES_CONVERT:
2418 if (!actor_unittype->converted_to) {
2419 /* Reason: must be able to convert to something. */
2420 return FALSE;
2421 }
2422 break;
2423
2425 if (actor_unittype->transport_capacity < 1) {
2426 /* Reason: can't transport anything to unload. */
2427 return FALSE;
2428 }
2429 break;
2430
2432 if (actor_unittype->transport_capacity < 1) {
2433 /* Reason: can't transport anything to load. */
2434 return FALSE;
2435 }
2436 break;
2437
2442 if (!ignore_third_party) {
2443 bool has_transporter = FALSE;
2444
2448 break;
2449 }
2451
2452 if (!has_transporter) {
2453 /* Reason: no other unit can transport this unit. */
2454 return FALSE;
2455 }
2456 }
2457 break;
2458
2460 if (!ignore_third_party) {
2461 bool has_target = FALSE;
2463
2464 /* Use cache when it has been initialized */
2465 if (pclass->cache.native_bases != NULL) {
2466 /* Extra being native one is a hard requirement */
2467 extra_type_list_iterate(pclass->cache.native_bases, pextra) {
2468 if (!territory_claiming_base(pextra->data.base)) {
2469 /* Hard requirement */
2470 continue;
2471 }
2472
2473 has_target = TRUE;
2474 break;
2476 } else {
2478
2480 if (!is_native_extra_to_uclass(pextra, pclass)) {
2481 /* Hard requirement */
2482 continue;
2483 }
2484
2485 has_target = TRUE;
2486 break;
2488 }
2489
2490 if (!has_target) {
2491 /* Reason: no extras can be conquered by this unit. */
2492 return FALSE;
2493 }
2494 }
2495 break;
2496
2497 case ACTRES_PARADROP:
2499 if (actor_unittype->paratroopers_range <= 0) {
2500 /* Reason: Can't paradrop 0 tiles. */
2501 return FALSE;
2502 }
2503 break;
2504
2505 case ACTRES_HUT_ENTER:
2509 case ACTRES_SPY_POISON:
2518 case ACTRES_SPY_ESCAPE:
2519 case ACTRES_TRADE_ROUTE:
2520 case ACTRES_MARKETPLACE:
2521 case ACTRES_HELP_WONDER:
2526 case ACTRES_FOUND_CITY:
2527 case ACTRES_STEAL_MAPS:
2528 case ACTRES_SPY_NUKE:
2529 case ACTRES_NUKE:
2530 case ACTRES_NUKE_UNITS:
2532 case ACTRES_EXPEL_UNIT:
2535 case ACTRES_HOME_CITY:
2536 case ACTRES_HOMELESS:
2537 case ACTRES_AIRLIFT:
2541 case ACTRES_HEAL_UNIT:
2542 case ACTRES_PILLAGE:
2543 case ACTRES_CLEAN:
2544 case ACTRES_FORTIFY:
2546 case ACTRES_CULTIVATE:
2547 case ACTRES_PLANT:
2548 case ACTRES_ROAD:
2549 case ACTRES_BASE:
2550 case ACTRES_MINE:
2551 case ACTRES_IRRIGATE:
2552 case ACTRES_SPY_ATTACK:
2553 case ACTRES_UNIT_MOVE:
2554 case ACTRES_TELEPORT:
2557 case ACTRES_NONE:
2558 /* No hard unit type requirements. */
2559 break;
2560
2562 }
2563
2564 return TRUE;
2565}
2566
2567/**********************************************************************/
2583bool
2590
2591/**********************************************************************/
2603static enum fc_tristate
2605 const struct action *paction,
2606 const struct req_context *actor,
2607 const bool omniscient,
2608 const struct city *homecity)
2609{
2610 enum action_result result = paction->result;
2611
2612 if (actor == NULL) {
2614 }
2615
2617 TRUE)) {
2618 /* Info leak: The actor player knows the type of their unit. */
2619 /* The actor unit type can't perform the action because of hard
2620 * unit type requirements. */
2621 return TRI_NO;
2622 }
2623
2624 switch (result) {
2625 case ACTRES_PARADROP:
2627 /* Reason: Keep the old rules. */
2628 /* Info leak: The player knows if their unit already has paradropped this
2629 * turn. */
2630 if (actor->unit->paradropped) {
2631 return TRI_NO;
2632 }
2633
2634 break;
2635
2636 case ACTRES_AIRLIFT:
2637 {
2638 /* Obligatory hard requirement. Checked here too since
2639 * action_hard_reqs_actor() may be called before any
2640 * action enablers are checked. */
2641 if (actor->city == NULL) {
2642 /* No city to airlift from. */
2643 return TRI_NO;
2644 }
2645
2646 if (actor->player != city_owner(actor->city)
2648 && pplayers_allied(actor->player,
2649 city_owner(actor->city)))) {
2650 /* Not allowed to airlift from this source. */
2651 return TRI_NO;
2652 }
2653
2654 if (!(omniscient || city_owner(actor->city) == actor->player)) {
2655 /* Can't check for airlifting capacity. */
2656 return TRI_MAYBE;
2657 }
2658
2659 if (0 >= actor->city->airlift
2662 /* The source cannot airlift for this turn (maybe already airlifted
2663 * or no airport).
2664 *
2665 * See also do_airline() in server/unittools.h. */
2666 return TRI_NO;
2667 }
2668 }
2669 break;
2670
2671 case ACTRES_CONVERT:
2672 /* Reason: Keep the old rules. */
2673 /* Info leak: The player knows their unit's cargo and location. */
2674 if (!unit_can_convert(nmap, actor->unit)) {
2675 return TRI_NO;
2676 }
2677 break;
2678
2681 if (unit_transported(actor->unit)) {
2682 if (!can_unit_unload(actor->unit, unit_transport_get(actor->unit))) {
2683 /* Can't leave current transport. */
2684 return TRI_NO;
2685 }
2686 }
2687 break;
2688
2690 if (!can_unit_unload(actor->unit, unit_transport_get(actor->unit))) {
2691 /* Keep the old rules about Unreachable and disembarks. */
2692 return TRI_NO;
2693 }
2694 break;
2695
2696 case ACTRES_HOMELESS:
2697 case ACTRES_UNIT_MOVE:
2698 case ACTRES_TELEPORT:
2702 case ACTRES_SPY_POISON:
2711 case ACTRES_SPY_ESCAPE:
2712 case ACTRES_TRADE_ROUTE:
2713 case ACTRES_MARKETPLACE:
2714 case ACTRES_HELP_WONDER:
2719 case ACTRES_FOUND_CITY:
2720 case ACTRES_JOIN_CITY:
2721 case ACTRES_STEAL_MAPS:
2722 case ACTRES_BOMBARD:
2723 case ACTRES_SPY_NUKE:
2724 case ACTRES_NUKE:
2725 case ACTRES_NUKE_UNITS:
2727 case ACTRES_EXPEL_UNIT:
2730 case ACTRES_HOME_CITY:
2732 case ACTRES_ATTACK:
2733 case ACTRES_WIPE_UNITS:
2739 case ACTRES_HEAL_UNIT:
2741 case ACTRES_CULTIVATE:
2742 case ACTRES_PLANT:
2743 case ACTRES_PILLAGE:
2744 case ACTRES_CLEAN:
2745 case ACTRES_FORTIFY:
2746 case ACTRES_ROAD:
2747 case ACTRES_BASE:
2748 case ACTRES_MINE:
2749 case ACTRES_IRRIGATE:
2753 case ACTRES_SPY_ATTACK:
2754 case ACTRES_HUT_ENTER:
2757 case ACTRES_NONE:
2758 /* No hard unit requirements. */
2759 break;
2760
2762 }
2763
2764 return TRI_YES;
2765}
2766
2767/**********************************************************************/
2790static enum fc_tristate
2793 const struct req_context *actor,
2794 const struct req_context *target,
2795 const struct extra_type *target_extra,
2796 const bool omniscient,
2797 const struct city *homecity)
2798{
2799 enum fc_tristate out;
2802
2803 if (actor == NULL) {
2805 }
2806 if (target == NULL) {
2807 target = req_context_empty();
2808 }
2809
2810 fc_assert_msg((tkind == ATK_CITY && target->city != NULL)
2811 || (tkind == ATK_TILE && target->tile != NULL)
2812 || (tkind == ATK_EXTRAS && target->tile != NULL)
2813 || (tkind == ATK_UNIT && target->unit != NULL)
2814 /* At this level each individual unit is tested. */
2815 || (tkind == ATK_STACK && target->unit != NULL)
2816 || (tkind == ATK_SELF),
2817 "Missing target!");
2818
2819 /* Info leak: The player knows where their unit is. */
2820 if (tkind != ATK_SELF
2823 target->tile))) {
2824 /* The distance between the actor and the target isn't inside the
2825 * action's accepted range. */
2826 return TRI_NO;
2827 }
2828
2829 switch (tkind) {
2830 case ATK_UNIT:
2831 /* The Freeciv code for all actions that is controlled by action
2832 * enablers and targets a unit assumes that the acting
2833 * player can see the target unit.
2834 * Examples:
2835 * - action_prob_vs_unit()'s quick check that the distance between actor
2836 * and target is acceptable would leak distance to target unit if the
2837 * target unit can't be seen.
2838 */
2839 if (!can_player_see_unit(actor->player, target->unit)) {
2840 return TRI_NO;
2841 }
2842 break;
2843 case ATK_CITY:
2844 /* The Freeciv code assumes that the player is aware of the target
2845 * city's existence. (How can you order an airlift to a city when you
2846 * don't know its city ID?) */
2848 actor->player)
2849 != target->city->id) {
2850 return TRI_NO;
2851 }
2852 break;
2853 case ATK_STACK:
2854 case ATK_TILE:
2855 case ATK_EXTRAS:
2856 case ATK_SELF:
2857 /* No special player knowledge checks. */
2858 break;
2859 case ATK_COUNT:
2861 break;
2862 }
2863
2865 target->tile, target->city, target->unit)) {
2866 /* Allows an action to block an other action. If a blocking action is
2867 * legal the actions it blocks becomes illegal. */
2868 return TRI_NO;
2869 }
2870
2871 /* Actor specific hard requirements. */
2873
2874 if (out == TRI_NO) {
2875 /* Illegal because of a hard actor requirement. */
2876 return TRI_NO;
2877 }
2878
2879 /* Quick checks for action itself */
2880 if (paction->result == ACTRES_ATTACK
2881 || paction->result == ACTRES_WIPE_UNITS
2882 || paction->result == ACTRES_COLLECT_RANSOM) {
2883 /* Reason: Keep the old rules. */
2884 if (!can_unit_attack_tile(actor->unit, paction, target->tile)) {
2885 return TRI_NO;
2886 }
2887 }
2888
2889 /* Hard requirements for results. */
2891 paction->result, actor,
2892 target, target_extra, out, omniscient,
2893 homecity);
2894
2895 if (out == TRI_NO) {
2896 /* Illegal because of a hard actor requirement. */
2897 return TRI_NO;
2898 }
2899
2900 if (paction->result == ACTRES_NUKE_UNITS) {
2902 target->tile)
2903 != ATT_OK) {
2904 /* Unreachable. */
2905 return TRI_NO;
2906 }
2907 } else if (paction->result == ACTRES_PARADROP
2908 || paction->result == ACTRES_PARADROP_CONQUER) {
2909 if (can_player_see_tile(actor->player, target->tile)) {
2910 /* Check for seen stuff that may kill the actor unit. */
2911
2912 /* Reason: Keep the old rules. Be merciful. */
2913 /* Info leak: The player sees the target tile. */
2914 if (!can_unit_exist_at_tile(nmap, actor->unit, target->tile)
2915 && (!BV_ISSET(paction->sub_results, ACT_SUB_RES_MAY_EMBARK)
2916 || !unit_could_load_at(actor->unit, target->tile))) {
2917 return TRI_NO;
2918 }
2919
2920 /* Reason: Keep the old rules. Be merciful. */
2921 /* Info leak: The player sees the target tile. */
2922 if (is_non_attack_city_tile(target->tile, actor->player)) {
2923 return TRI_NO;
2924 }
2925
2926 /* Reason: Be merciful. */
2927 /* Info leak: The player sees all units checked. Invisible units are
2928 * ignored. */
2929 unit_list_iterate(target->tile->units, pother) {
2930 if (can_player_see_unit(actor->player, pother)
2931 && !pplayers_allied(actor->player, unit_owner(pother))) {
2932 return TRI_NO;
2933 }
2935 }
2936 }
2937
2938 return out;
2939}
2940
2941/**********************************************************************/
2947static bool is_enabler_active(const struct action_enabler *enabler,
2948 const struct req_context *actor,
2949 const struct req_context *target)
2950{
2951 return are_reqs_active(actor, target, &enabler->actor_reqs, RPT_CERTAIN)
2952 && are_reqs_active(target, actor, &enabler->target_reqs, RPT_CERTAIN);
2953}
2954
2955/**********************************************************************/
2964static bool is_action_enabled(const struct civ_map *nmap,
2966 const struct req_context *actor,
2967 const struct req_context *target,
2968 const struct extra_type *target_extra,
2969 const struct city *actor_home)
2970{
2971 enum fc_tristate possible;
2972
2974 TRUE, actor_home);
2975
2976 if (possible != TRI_YES) {
2977 /* This context is omniscient. Should be yes or no. */
2979 "Is omniscient, should get yes or no.");
2980
2981 /* The action enablers are irrelevant since the action it self is
2982 * impossible. */
2983 return FALSE;
2984 }
2985
2986 return action_enablers_allow(wanted_action, actor, target);
2987}
2988
2989/**********************************************************************/
2994 const struct req_context *actor,
2995 const struct req_context *target)
2996{
2998 enabler) {
2999 if (is_enabler_active(enabler, actor, target)) {
3000 return TRUE;
3001 }
3003
3004 return FALSE;
3005}
3006
3007/**********************************************************************/
3013static bool
3016 const struct unit *actor_unit,
3017 const struct city *actor_home,
3018 const struct tile *actor_tile,
3019 const struct city *target_city)
3020{
3021 const struct impr_type *target_building;
3022 const struct unit_type *target_utype;
3023
3024 if (actor_unit == NULL || target_city == NULL) {
3025 /* Can't do an action when actor or target are missing. */
3026 return FALSE;
3027 }
3028
3030 FALSE, "Action %s is performed by %s not %s",
3035
3038 FALSE, "Action %s is against %s not %s",
3043
3045
3047 /* No point in continuing. */
3048 return FALSE;
3049 }
3050
3053
3055 &(const struct req_context) {
3056 .player = unit_owner(actor_unit),
3057 .city = tile_city(actor_tile),
3058 .tile = actor_tile,
3059 .unit = actor_unit,
3060 .unittype = unit_type_get(actor_unit),
3061 },
3062 &(const struct req_context) {
3063 .player = city_owner(target_city),
3064 .city = target_city,
3065 .building = target_building,
3067 .unittype = target_utype,
3068 },
3069 NULL,
3070 actor_home);
3071}
3072
3073/**********************************************************************/
3089
3090/**********************************************************************/
3096static bool
3099 const struct unit *actor_unit,
3100 const struct city *actor_home,
3101 const struct tile *actor_tile,
3102 const struct unit *target_unit)
3103{
3104 if (actor_unit == NULL || target_unit == NULL) {
3105 /* Can't do an action when actor or target are missing. */
3106 return FALSE;
3107 }
3108
3110 FALSE, "Action %s is performed by %s not %s",
3115
3118 FALSE, "Action %s is against %s not %s",
3123
3125
3127 /* No point in continuing. */
3128 return FALSE;
3129 }
3130
3132 &(const struct req_context) {
3133 .player = unit_owner(actor_unit),
3134 .city = tile_city(actor_tile),
3135 .tile = actor_tile,
3136 .unit = actor_unit,
3137 .unittype = unit_type_get(actor_unit),
3138 },
3139 &(const struct req_context) {
3140 .player = unit_owner(target_unit),
3143 .unit = target_unit,
3144 .unittype = unit_type_get(target_unit),
3145 },
3146 NULL,
3147 actor_home);
3148}
3149
3150/**********************************************************************/
3166
3167/**********************************************************************/
3173static bool
3176 const struct unit *actor_unit,
3177 const struct city *actor_home,
3178 const struct tile *actor_tile,
3179 const struct tile *target_tile)
3180{
3181 const struct req_context *actor_ctxt;
3182
3183 if (actor_unit == NULL || target_tile == NULL
3184 || unit_list_size(target_tile->units) == 0) {
3185 /* Can't do an action when actor or target are missing. */
3186 return FALSE;
3187 }
3188
3190 FALSE, "Action %s is performed by %s not %s",
3195
3198 FALSE, "Action %s is against %s not %s",
3203
3205
3207 /* No point in continuing. */
3208 return FALSE;
3209 }
3210
3211 actor_ctxt = &(const struct req_context) {
3212 .player = unit_owner(actor_unit),
3213 .city = tile_city(actor_tile),
3214 .tile = actor_tile,
3215 .unit = actor_unit,
3216 .unittype = unit_type_get(actor_unit),
3217 };
3218
3221 &(const struct req_context) {
3222 .player = unit_owner(target_unit),
3225 .unit = target_unit,
3226 .unittype = unit_type_get(target_unit),
3227 },
3228 NULL, actor_home)) {
3229 /* One unit makes it impossible for all units. */
3230 return FALSE;
3231 }
3233
3234 /* Not impossible for any of the units at the tile. */
3235 return TRUE;
3236}
3237
3238/**********************************************************************/
3254
3255/**********************************************************************/
3261static bool
3264 const struct unit *actor_unit,
3265 const struct city *actor_home,
3266 const struct tile *actor_tile,
3267 const struct tile *target_tile,
3268 const struct extra_type *target_extra)
3269{
3270 if (actor_unit == NULL || target_tile == NULL) {
3271 /* Can't do an action when actor or target are missing. */
3272 return FALSE;
3273 }
3274
3276 FALSE, "Action %s is performed by %s not %s",
3281
3284 FALSE, "Action %s is against %s not %s",
3289
3291
3293 /* No point in continuing. */
3294 return FALSE;
3295 }
3296
3298 &(const struct req_context) {
3299 .player = unit_owner(actor_unit),
3300 .city = tile_city(actor_tile),
3301 .tile = actor_tile,
3302 .unit = actor_unit,
3303 .unittype = unit_type_get(actor_unit),
3304 },
3305 &(const struct req_context) {
3306 .player = tile_owner(target_tile),
3307 .city = tile_city(target_tile),
3308 .tile = target_tile,
3309 },
3311 actor_home);
3312}
3313
3314/**********************************************************************/
3322 const struct unit *actor_unit,
3323 const struct tile *target_tile,
3324 const struct extra_type *target_extra)
3325{
3330}
3331
3332/**********************************************************************/
3338static bool
3341 const struct unit *actor_unit,
3342 const struct city *actor_home,
3343 const struct tile *actor_tile,
3344 const struct tile *target_tile,
3345 const struct extra_type *target_extra)
3346{
3347 if (actor_unit == NULL || target_tile == NULL) {
3348 /* Can't do an action when actor or target are missing. */
3349 return FALSE;
3350 }
3351
3353 FALSE, "Action %s is performed by %s not %s",
3358
3361 FALSE, "Action %s is against %s not %s",
3366
3368
3370 /* No point in continuing. */
3371 return FALSE;
3372 }
3373
3375 &(const struct req_context) {
3376 .player = unit_owner(actor_unit),
3377 .city = tile_city(actor_tile),
3378 .tile = actor_tile,
3379 .unit = actor_unit,
3380 .unittype = unit_type_get(actor_unit),
3381 },
3382 &(const struct req_context) {
3383 .player = target_tile->extras_owner,
3384 .city = tile_city(target_tile),
3385 .tile = target_tile,
3386 },
3388 actor_home);
3389}
3390
3391/**********************************************************************/
3408
3409/**********************************************************************/
3416static bool
3419 const struct unit *actor_unit,
3420 const struct city *actor_home,
3421 const struct tile *actor_tile)
3422{
3423 if (actor_unit == NULL) {
3424 /* Can't do an action when the actor is missing. */
3425 return FALSE;
3426 }
3427
3429 FALSE, "Action %s is performed by %s not %s",
3434
3437 FALSE, "Action %s is against %s not %s",
3442
3444
3446 /* No point in continuing. */
3447 return FALSE;
3448 }
3449
3451 &(const struct req_context) {
3452 .player = unit_owner(actor_unit),
3453 .city = tile_city(actor_tile),
3454 .tile = actor_tile,
3455 .unit = actor_unit,
3456 .unittype = unit_type_get(actor_unit),
3457 },
3458 NULL, NULL,
3459 actor_home);
3460}
3461
3462/**********************************************************************/
3477
3478/**********************************************************************/
3484 const struct player *actor_plr)
3485{
3487 &(const struct req_context) {
3488 .player = actor_plr,
3489 },
3490 nullptr, nullptr, nullptr);
3491}
3492
3493/**********************************************************************/
3511static enum fc_tristate
3513 const struct req_context *actor,
3514 const struct req_context *target)
3515{
3516 enum fc_tristate current;
3517 enum fc_tristate result;
3518
3519 if (actor == NULL || actor->player == NULL) {
3520 /* Need actor->player for point of view */
3521 return TRI_MAYBE;
3522 }
3523
3524 if (target == NULL) {
3525 target = req_context_empty();
3526 }
3527
3528 result = TRI_NO;
3530 enabler) {
3531 current = fc_tristate_and(mke_eval_reqs(actor->player,
3532 actor, target,
3533 &enabler->actor_reqs,
3534 RPT_CERTAIN),
3535 mke_eval_reqs(actor->player,
3536 target, actor,
3537 &enabler->target_reqs,
3538 RPT_CERTAIN));
3539 if (current == TRI_YES) {
3540 return TRI_YES;
3541 } else if (current == TRI_MAYBE) {
3542 result = TRI_MAYBE;
3543 }
3545
3546 return result;
3547}
3548
3549/**********************************************************************/
3559static bool is_effect_val_known(enum effect_type effect_type,
3560 const struct player *pov_player,
3561 const struct req_context *context,
3562 const struct req_context *other_context)
3563{
3564 effect_list_iterate(get_effects(effect_type), peffect) {
3566 &(peffect->reqs), RPT_CERTAIN)) {
3567 return FALSE;
3568 }
3570
3571 return TRUE;
3572}
3573
3574/**********************************************************************/
3577static enum fc_tristate
3605
3606/**********************************************************************/
3615 const struct unit *pdefender)
3616{
3617 /* Keep unconverted until the end to avoid scaling each step */
3618 int chance;
3619 struct act_prob out;
3620
3621 /* Superspy always win */
3623 /* A defending UTYF_SUPERSPY will defeat every possible attacker. */
3624 return ACTPROB_IMPOSSIBLE;
3625 }
3627 /* An attacking UTYF_SUPERSPY will defeat every possible defender
3628 * except another UTYF_SUPERSPY. */
3629 return ACTPROB_CERTAIN;
3630 }
3631
3632 /* Base chance is 50% */
3633 chance = 50;
3634
3635 /* Spy attack bonus */
3637 chance += 25;
3638 }
3639
3640 /* Spy defense bonus */
3642 chance -= 25;
3643 }
3644
3645 /* Veteran attack and defense bonus */
3646 {
3647 const struct veteran_level *vatt
3649 const struct veteran_level *vdef
3651
3652 chance += vatt->power_fact - vdef->power_fact;
3653 }
3654
3655 /* Defense bonus. */
3656 {
3657 const struct req_context defender_ctxt = {
3658 .player = tile_owner(pdefender->tile),
3659 .city = tile_city(pdefender->tile),
3660 .tile = pdefender->tile,
3661 };
3664 NULL)) {
3665 return ACTPROB_NOT_KNOWN;
3666 }
3667
3668 /* Reduce the chance of an attack by EFT_SPY_RESISTANT percent. */
3670 NULL,
3672 NULL,
3674 ) / 100;
3675 }
3676
3677 chance = CLIP(0, chance, 100);
3678
3679 /* Convert to action probability */
3682
3683 return out;
3684}
3685
3686/**********************************************************************/
3692 const struct unit *pvictim,
3693 const struct tile *tgt_tile,
3694 const struct action *paction)
3695{
3696 struct unit *pdefender;
3697
3699 tgt_tile)) {
3700 /* Don't leak information about unseen defenders. */
3701 return ACTPROB_NOT_KNOWN;
3702 }
3703
3705 paction);
3706
3707 if (pdefender) {
3708 /* There will be a diplomatic battle instead of an action. */
3710 };
3711
3712 /* No diplomatic battle will occur. */
3713 return ACTPROB_CERTAIN;
3714}
3715
3716/**********************************************************************/
3720 action_id act_id,
3721 const struct unit *actor_unit)
3722{
3724 /* Unknown because the target is unseen. */
3725 return ACTPROB_NOT_KNOWN;
3726 } else {
3727 /* The actor it self can't do this. */
3728 return ACTPROB_IMPOSSIBLE;
3729 }
3730}
3731
3732/**********************************************************************/
3736static struct act_prob
3738 const struct unit *act_unit,
3739 const struct city *tgt_city,
3740 const struct player *tgt_player,
3741 const struct action *paction)
3742{
3744 &(const struct req_context) {
3745 .player = act_player,
3746 .city = tgt_city,
3747 .unit = act_unit,
3748 .unittype = unit_type_get(act_unit),
3749 },
3750 &(const struct req_context) {
3751 .player = tgt_player,
3752 })
3754 &(const struct req_context) {
3755 .player = tgt_player,
3756 .city = tgt_city,
3757 .unit = act_unit,
3758 },
3759 &(const struct req_context) {
3760 .player = act_player,
3761 })) {
3764 struct act_prob result = { .min = unconverted * ACTPROB_VAL_1_PCT,
3765 .max = unconverted * ACTPROB_VAL_1_PCT };
3766
3767 return result;
3768 } else {
3769 /* Could be improved to return a more exact probability in some cases.
3770 * Example: The player has enough information to know that the
3771 * probability always will be above 25% and always under 75% because
3772 * the only effect with unknown requirements that may apply adds (or
3773 * subtracts) 50% while all the requirements of the other effects that
3774 * may apply are known. */
3775 return ACTPROB_NOT_KNOWN;
3776 }
3777}
3778
3779/**********************************************************************/
3784static struct act_prob
3786 const struct unit *act_unit,
3787 const struct city *tgt_city,
3788 const struct unit *tgt_unit,
3789 const struct tile *tgt_tile,
3790 const struct player *tgt_player,
3791 const struct action *paction)
3792{
3793 struct act_prob battle;
3794 struct act_prob dice_roll;
3795
3796 battle = ACTPROB_CERTAIN;
3797 switch (actres_get_battle_kind(paction->result)) {
3798 case ABK_NONE:
3799 /* No pre action battle. */
3800 break;
3801 case ABK_DIPLOMATIC:
3803 paction);
3804 break;
3805 case ABK_STANDARD:
3806 /* Not supported here yet. Implement when users appear. */
3808 break;
3809 case ABK_COUNT:
3811 break;
3812 }
3813
3816 paction);
3817
3818 return action_prob_and(&battle, &dice_roll);
3819}
3820
3821/**********************************************************************/
3832static struct act_prob
3835 const struct req_context *actor,
3836 const struct city *actor_home,
3837 const struct req_context *target,
3838 const struct extra_type *target_extra)
3839{
3840 enum fc_tristate known;
3841 struct act_prob chance;
3843
3844 if (actor == NULL) {
3846 }
3847 if (target == NULL) {
3848 target = req_context_empty();
3849 }
3850
3851 known = is_action_possible(nmap, wanted_action, actor, target,
3853 FALSE, actor_home);
3854
3855 if (known == TRI_NO) {
3856 /* The action enablers are irrelevant since the action it self is
3857 * impossible. */
3858 return ACTPROB_IMPOSSIBLE;
3859 }
3860
3862
3863 known = fc_tristate_and(known,
3865 actor, target));
3866
3867 switch (paction->result) {
3868 case ACTRES_SPY_POISON:
3869 /* All uncertainty comes from potential diplomatic battles and the
3870 * (diplchance server setting and the) Action_Odds_Pct effect controlled
3871 * dice roll before the action. */
3873 target->city, target->unit,
3874 target->tile, target->player,
3875 paction);
3876 break;
3878 /* TODO */
3879 break;
3881 /* TODO */
3882 break;
3883 case ACTRES_STEAL_MAPS:
3884 /* TODO */
3885 break;
3887 /* All uncertainty comes from potential diplomatic battles. */
3888 chance = ap_diplomat_battle(actor->unit, target->unit, target->tile,
3889 paction);
3890 break;
3893 /* All uncertainty comes from potential diplomatic battles. */
3894 chance = ap_diplomat_battle(actor->unit, target->unit, target->tile,
3895 paction);
3896 break;
3897 case ACTRES_SPY_ATTACK:
3898 /* All uncertainty comes from potential diplomatic battles. */
3899 chance = ap_diplomat_battle(actor->unit, NULL, target->tile,
3900 paction);
3901 break;
3903 /* TODO */
3904 break;
3906 /* TODO */
3907 break;
3909 /* TODO */
3910 break;
3912 /* TODO */
3913 break;
3916 break;
3918 /* Do the victim have anything worth taking? */
3919 known = fc_tristate_and(known,
3920 tech_can_be_stolen(actor->player,
3921 target->player));
3922
3923 /* TODO: Calculate actual chance */
3924
3925 break;
3927 /* Do the victim have anything worth taking? */
3928 known = fc_tristate_and(known,
3929 tech_can_be_stolen(actor->player,
3930 target->player));
3931
3932 /* TODO: Calculate actual chance */
3933
3934 break;
3936 /* There is no risk that the city won't get investigated. */
3938 break;
3939 case ACTRES_SPY_ESCAPE:
3940 /* TODO */
3941 break;
3942 case ACTRES_TRADE_ROUTE:
3943 /* TODO */
3944 break;
3945 case ACTRES_MARKETPLACE:
3946 /* Possible when not blocked by is_action_possible() */
3948 break;
3949 case ACTRES_HELP_WONDER:
3950 /* Possible when not blocked by is_action_possible() */
3952 break;
3954 /* No battle is fought first. */
3956 break;
3957 case ACTRES_EXPEL_UNIT:
3958 /* No battle is fought first. */
3960 break;
3961 case ACTRES_BOMBARD:
3962 /* No battle is fought first. */
3964 break;
3965 case ACTRES_FOUND_CITY:
3966 /* Possible when not blocked by is_action_possible() */
3968 break;
3969 case ACTRES_JOIN_CITY:
3970 /* Possible when not blocked by is_action_possible() */
3972 break;
3973 case ACTRES_SPY_NUKE:
3974 /* All uncertainty comes from potential diplomatic battles and the
3975 * (diplchance server setting and the) Action_Odds_Pct effect controlled
3976 * dice roll before the action. */
3978 target->city, target->unit,
3979 target->tile,
3980 target->player,
3981 paction);
3982 break;
3983 case ACTRES_NUKE:
3984 /* TODO */
3985 break;
3986 case ACTRES_NUKE_UNITS:
3987 /* TODO */
3988 break;
3990 /* No battle is fought first. */
3992 break;
3994 /* No battle is fought first. */
3996 break;
3998 /* No battle is fought first. */
4000 break;
4001 case ACTRES_HOME_CITY:
4002 /* No battle is fought first. */
4004 break;
4005 case ACTRES_HOMELESS:
4006 /* No battle is fought first. */
4008 break;
4010 /* No battle is fought first. */
4012 break;
4013 case ACTRES_PARADROP:
4015 /* TODO */
4016 break;
4017 case ACTRES_AIRLIFT:
4018 /* Possible when not blocked by is_action_possible() */
4020 break;
4021 case ACTRES_ATTACK:
4023 {
4024 struct unit *defender_unit = get_defender(nmap, actor->unit,
4025 target->tile, paction);
4026
4027 if (can_player_see_unit(actor->player, defender_unit)) {
4028 double unconverted = unit_win_chance(nmap, actor->unit,
4030
4032 floor((double)ACTPROB_VAL_MAX * unconverted));
4034 ceil((double)ACTPROB_VAL_MAX * unconverted));
4035 } else if (known == TRI_YES) {
4036 known = TRI_MAYBE;
4037 }
4038 }
4039 break;
4040 case ACTRES_WIPE_UNITS:
4042 break;
4044 /* TODO: not implemented yet because:
4045 * - dice roll 100% * Action_Odds_Pct could be handled with
4046 * action_prob_pre_action_dice_roll().
4047 * - sub target building may be missing. May be missing without player
4048 * knowledge if it isn't visible. See is_improvement_visible() and
4049 * can_player_see_city_internals(). */
4050 break;
4052 /* All uncertainty comes from the (diplchance server setting and the)
4053 * Action_Odds_Pct effect controlled dice roll before the action. */
4055 target->city, target->player,
4056 paction);
4057 break;
4059 /* No battle is fought first. */
4061 break;
4063 /* No battle is fought first. */
4065 break;
4066 case ACTRES_HEAL_UNIT:
4067 /* No battle is fought first. */
4069 break;
4071 case ACTRES_CULTIVATE:
4072 case ACTRES_PLANT:
4073 case ACTRES_PILLAGE:
4074 case ACTRES_CLEAN:
4075 case ACTRES_FORTIFY:
4076 case ACTRES_ROAD:
4077 case ACTRES_CONVERT:
4078 case ACTRES_BASE:
4079 case ACTRES_MINE:
4080 case ACTRES_IRRIGATE:
4082 break;
4085 break;
4088 break;
4091 break;
4094 break;
4097 break;
4100 break;
4101 case ACTRES_HUT_ENTER:
4103 /* Entering the hut happens with a probability of 100%. What happens
4104 * next is probably up to dice rolls in Lua. */
4106 break;
4107 case ACTRES_UNIT_MOVE:
4108 case ACTRES_TELEPORT:
4111 break;
4112 /* Not UI action, so chance is meaningless */
4115 break;
4116 case ACTRES_NONE:
4117 /* Accommodate ruleset authors that wishes to roll the dice in Lua.
4118 * Would be ACTPROB_CERTAIN if not for that. */
4119 /* TODO: maybe allow the ruleset author to give a probability from
4120 * Lua? */
4122 break;
4123 }
4124
4125 /* Non signal action probabilities should be in range. */
4127 || chance.max <= ACTPROB_VAL_MAX),
4128 chance.max = ACTPROB_VAL_MAX);
4130 || chance.min >= ACTPROB_VAL_MIN),
4131 chance.min = ACTPROB_VAL_MIN);
4132
4133 switch (known) {
4134 case TRI_NO:
4135 return ACTPROB_IMPOSSIBLE;
4136 break;
4137 case TRI_MAYBE:
4138 return ACTPROB_NOT_KNOWN;
4139 break;
4140 case TRI_YES:
4141 return chance;
4142 break;
4143 };
4144
4145 fc_assert_msg(FALSE, "Should be yes, maybe or no");
4146
4148}
4149
4150/**********************************************************************/
4154static struct act_prob
4156 const struct unit *actor_unit,
4157 const struct city *actor_home,
4158 const struct tile *actor_tile,
4159 const action_id act_id,
4160 const struct city *target_city)
4161{
4162 const struct impr_type *target_building;
4163 const struct unit_type *target_utype;
4164 const struct action *act = action_by_number(act_id);
4165
4166 if (actor_unit == NULL || target_city == NULL) {
4167 /* Can't do an action when actor or target are missing. */
4168 return ACTPROB_IMPOSSIBLE;
4169 }
4170
4173 "Action %s is performed by %s not %s",
4174 action_id_rule_name(act_id),
4176 action_id_get_actor_kind(act_id)),
4178
4181 "Action %s is against %s not %s",
4182 action_id_rule_name(act_id),
4186
4188
4189 if (!unit_can_do_action(actor_unit, act_id)) {
4190 /* No point in continuing. */
4191 return ACTPROB_IMPOSSIBLE;
4192 }
4193
4194 /* Doesn't leak information about city position since an unknown city
4195 * can't be targeted and a city can't move. */
4196 if (!action_id_distance_accepted(act_id,
4199 /* No point in continuing. */
4200 return ACTPROB_IMPOSSIBLE;
4201 }
4202
4203 /* Doesn't leak information since it must be 100% certain from the
4204 * player's perspective that the blocking action is legal. */
4207 /* Don't offer to perform an action known to be blocked. */
4208 return ACTPROB_IMPOSSIBLE;
4209 }
4210
4212 /* The invisible city at this tile may, as far as the player knows, not
4213 * exist anymore. */
4214 return act_prob_unseen_target(nmap, act_id, actor_unit);
4215 }
4216
4219
4220 return action_prob(nmap, act_id,
4221 &(const struct req_context) {
4222 .player = unit_owner(actor_unit),
4223 .city = tile_city(actor_tile),
4224 .tile = actor_tile,
4225 .unit = actor_unit,
4226 .unittype = unit_type_get(actor_unit),
4227 },
4228 actor_home,
4229 &(const struct req_context) {
4230 .player = city_owner(target_city),
4231 .city = target_city,
4232 .building = target_building,
4234 .unittype = target_utype,
4235 }, NULL);
4236}
4237
4238/**********************************************************************/
4243 const struct unit *actor_unit,
4244 const action_id act_id,
4245 const struct city *target_city)
4246{
4250 act_id, target_city);
4251}
4252
4253/**********************************************************************/
4257static struct act_prob
4259 const struct unit *actor_unit,
4260 const struct city *actor_home,
4261 const struct tile *actor_tile,
4262 const action_id act_id,
4263 const struct unit *target_unit)
4264{
4265 if (actor_unit == NULL || target_unit == NULL) {
4266 /* Can't do an action when actor or target are missing. */
4267 return ACTPROB_IMPOSSIBLE;
4268 }
4269
4272 "Action %s is performed by %s not %s",
4273 action_id_rule_name(act_id),
4275 action_id_get_actor_kind(act_id)),
4277
4280 "Action %s is against %s not %s",
4281 action_id_rule_name(act_id),
4285
4287
4288 if (!unit_can_do_action(actor_unit, act_id)) {
4289 /* No point in continuing. */
4290 return ACTPROB_IMPOSSIBLE;
4291 }
4292
4293 /* Doesn't leak information about unit position since an unseen unit can't
4294 * be targeted. */
4295 if (!action_id_distance_accepted(act_id,
4298 /* No point in continuing. */
4299 return ACTPROB_IMPOSSIBLE;
4300 }
4301
4302 return action_prob(nmap, act_id,
4303 &(const struct req_context) {
4304 .player = unit_owner(actor_unit),
4305 .city = tile_city(actor_tile),
4306 .tile = actor_tile,
4307 .unit = actor_unit,
4308 .unittype = unit_type_get(actor_unit),
4309 },
4310 actor_home,
4311 &(const struct req_context) {
4312 .player = unit_owner(target_unit),
4315 .unit = target_unit,
4316 .unittype = unit_type_get(target_unit),
4317 },
4318 NULL);
4319}
4320
4321/**********************************************************************/
4326 const struct unit *actor_unit,
4327 const action_id act_id,
4328 const struct unit *target_unit)
4329{
4333 act_id,
4334 target_unit);
4335}
4336
4337/**********************************************************************/
4341static struct act_prob
4343 const struct unit *actor_unit,
4344 const struct city *actor_home,
4345 const struct tile *actor_tile,
4346 const action_id act_id,
4347 const struct tile *target_tile)
4348{
4349 struct act_prob prob_all;
4350 const struct req_context *actor_ctxt;
4351 const struct action *act = action_by_number(act_id);
4352
4353 if (actor_unit == NULL || target_tile == NULL) {
4354 /* Can't do an action when actor or target are missing. */
4355 return ACTPROB_IMPOSSIBLE;
4356 }
4357
4360 "Action %s is performed by %s not %s",
4361 action_id_rule_name(act_id),
4363 action_id_get_actor_kind(act_id)),
4365
4368 "Action %s is against %s not %s",
4369 action_id_rule_name(act_id),
4373
4375
4376 if (!unit_can_do_action(actor_unit, act_id)) {
4377 /* No point in continuing. */
4378 return ACTPROB_IMPOSSIBLE;
4379 }
4380
4381 /* Doesn't leak information about unit stack position since it is
4382 * specified as a tile and an unknown tile's position is known. */
4383 if (!action_id_distance_accepted(act_id,
4385 target_tile))) {
4386 /* No point in continuing. */
4387 return ACTPROB_IMPOSSIBLE;
4388 }
4389
4390 /* Doesn't leak information since the actor player can see the target
4391 * tile. */
4395 act_id,
4396 CITYT_CENTER, TRUE)) {
4397 /* Don't offer to perform actions that never can target a unit stack in
4398 * a city. */
4399 return ACTPROB_IMPOSSIBLE;
4400 }
4401
4402 /* Doesn't leak information since it must be 100% certain from the
4403 * player's perspective that the blocking action is legal. */
4407 target_unit)) {
4408 /* Don't offer to perform an action known to be blocked. */
4409 return ACTPROB_IMPOSSIBLE;
4410 }
4412
4413 /* Must be done here since an empty unseen tile will result in
4414 * ACTPROB_IMPOSSIBLE. */
4415 if (unit_list_size(target_tile->units) == 0) {
4416 /* Can't act against an empty tile. */
4417
4419 target_tile)) {
4420 /* Known empty tile. */
4421 return ACTPROB_IMPOSSIBLE;
4422 } else {
4423 /* The player doesn't know that the tile is empty. */
4424 return act_prob_unseen_target(nmap, act_id, actor_unit);
4425 }
4426 }
4427
4434 /* Hard coded rule: can't "Bombard", "Suicide Attack", or "Attack"
4435 * units in non enemy cities. */
4436 return ACTPROB_IMPOSSIBLE;
4437 }
4438
4445 /* Hard coded rule: can't "Nuke Units", "Wipe Units", "Suicide Attack",
4446 * or "Attack" units on non native tile without "AttackNonNative" and
4447 * not "Only_Native_Attack". */
4448 return ACTPROB_IMPOSSIBLE;
4449 }
4450
4451 /* Invisible units at this tile can make the action legal or illegal.
4452 * Invisible units can be stacked with visible units. The possible
4453 * existence of invisible units therefore makes the result uncertain. */
4457
4458 actor_ctxt = &(const struct req_context) {
4459 .player = unit_owner(actor_unit),
4460 .city = tile_city(actor_tile),
4461 .tile = actor_tile,
4462 .unit = actor_unit,
4463 .unittype = unit_type_get(actor_unit),
4464 };
4465
4467 struct act_prob prob_unit;
4468
4470 /* Only visible units are considered. The invisible units contributed
4471 * their uncertainty to prob_all above. */
4472 continue;
4473 }
4474
4476 &(const struct req_context) {
4477 .player = unit_owner(target_unit),
4480 .unit = target_unit,
4481 .unittype = unit_type_get(target_unit),
4482 },
4483 NULL);
4484
4486 /* One unit makes it impossible for all units. */
4487 return ACTPROB_IMPOSSIBLE;
4488 } else if (action_prob_not_impl(prob_unit)) {
4489 /* Not implemented dominates all except impossible. */
4491 } else {
4493 "Invalid probability [%d, %d]",
4494 prob_unit.min, prob_unit.max);
4495
4497 /* Special values dominate regular values. */
4498 continue;
4499 }
4500
4501 /* Probability against all target units considered until this moment
4502 * and the probability against this target unit. */
4503 prob_all.min = (prob_all.min * prob_unit.min) / ACTPROB_VAL_MAX;
4504 prob_all.max = (prob_all.max * prob_unit.max) / ACTPROB_VAL_MAX;
4505 break;
4506 }
4508
4509 /* Not impossible for any of the units at the tile. */
4510 return prob_all;
4511}
4512
4513/**********************************************************************/
4518 const struct unit *actor_unit,
4519 const action_id act_id,
4520 const struct tile *target_tile)
4521{
4525 act_id,
4526 target_tile);
4527}
4528
4529/**********************************************************************/
4533static struct act_prob
4535 const struct unit *actor_unit,
4536 const struct city *actor_home,
4537 const struct tile *actor_tile,
4538 const action_id act_id,
4539 const struct tile *target_tile,
4540 const struct extra_type *target_extra)
4541{
4542 if (actor_unit == NULL || target_tile == NULL) {
4543 /* Can't do an action when actor or target are missing. */
4544 return ACTPROB_IMPOSSIBLE;
4545 }
4546
4549 "Action %s is performed by %s not %s",
4550 action_id_rule_name(act_id),
4552 action_id_get_actor_kind(act_id)),
4554
4557 "Action %s is against %s not %s",
4558 action_id_rule_name(act_id),
4562
4564
4565 if (!unit_can_do_action(actor_unit, act_id)) {
4566 /* No point in continuing. */
4567 return ACTPROB_IMPOSSIBLE;
4568 }
4569
4570 /* Doesn't leak information about tile position since an unknown tile's
4571 * position is known. */
4572 if (!action_id_distance_accepted(act_id,
4574 target_tile))) {
4575 /* No point in continuing. */
4576 return ACTPROB_IMPOSSIBLE;
4577 }
4578
4579 return action_prob(nmap, act_id,
4580 &(const struct req_context) {
4581 .player = unit_owner(actor_unit),
4582 .city = tile_city(actor_tile),
4583 .tile = actor_tile,
4584 .unit = actor_unit,
4585 .unittype = unit_type_get(actor_unit),
4586 },
4587 actor_home,
4588 &(const struct req_context) {
4589 .player = tile_owner(target_tile),
4590 .city = tile_city(target_tile),
4591 .tile = target_tile,
4592 },
4593 target_extra);
4594}
4595
4596/**********************************************************************/
4601 const struct unit *actor_unit,
4602 const action_id act_id,
4603 const struct tile *target_tile,
4604 const struct extra_type *target_extra)
4605{
4609 act_id, target_tile, target_extra);
4610}
4611
4612/**********************************************************************/
4616static struct act_prob
4618 const struct unit *actor_unit,
4619 const struct city *actor_home,
4620 const struct tile *actor_tile,
4621 const action_id act_id,
4622 const struct tile *target_tile,
4623 const struct extra_type *target_extra)
4624{
4625 if (actor_unit == NULL || target_tile == NULL) {
4626 /* Can't do an action when actor or target are missing. */
4627 return ACTPROB_IMPOSSIBLE;
4628 }
4629
4632 "Action %s is performed by %s not %s",
4633 action_id_rule_name(act_id),
4635 action_id_get_actor_kind(act_id)),
4637
4640 "Action %s is against %s not %s",
4641 action_id_rule_name(act_id),
4645
4647
4648 if (!unit_can_do_action(actor_unit, act_id)) {
4649 /* No point in continuing. */
4650 return ACTPROB_IMPOSSIBLE;
4651 }
4652
4653 /* Doesn't leak information about tile position since an unknown tile's
4654 * position is known. */
4655 if (!action_id_distance_accepted(act_id,
4657 target_tile))) {
4658 /* No point in continuing. */
4659 return ACTPROB_IMPOSSIBLE;
4660 }
4661
4662 return action_prob(nmap, act_id,
4663 &(const struct req_context) {
4664 .player = unit_owner(actor_unit),
4665 .city = tile_city(actor_tile),
4666 .tile = actor_tile,
4667 .unit = actor_unit,
4668 .unittype = unit_type_get(actor_unit),
4669 },
4670 actor_home,
4671 &(const struct req_context) {
4672 .player = target_tile->extras_owner,
4673 .city = tile_city(target_tile),
4674 .tile = target_tile,
4675 },
4676 target_extra);
4677}
4678
4679/**********************************************************************/
4684 const struct unit *actor_unit,
4685 const action_id act_id,
4686 const struct tile *target_tile,
4687 const struct extra_type *target_extra)
4688{
4692 act_id, target_tile, target_extra);
4693}
4694
4695/**********************************************************************/
4699static struct act_prob
4701 const struct unit *actor_unit,
4702 const struct city *actor_home,
4703 const struct tile *actor_tile,
4704 const action_id act_id)
4705{
4706 if (actor_unit == NULL) {
4707 /* Can't do the action when the actor is missing. */
4708 return ACTPROB_IMPOSSIBLE;
4709 }
4710
4711 /* No point in checking distance to target. It is always 0. */
4712
4715 "Action %s is performed by %s not %s",
4716 action_id_rule_name(act_id),
4718 action_id_get_actor_kind(act_id)),
4720
4723 "Action %s is against %s not %s",
4724 action_id_rule_name(act_id),
4728
4730
4731 if (!unit_can_do_action(actor_unit, act_id)) {
4732 /* No point in continuing. */
4733 return ACTPROB_IMPOSSIBLE;
4734 }
4735
4736 return action_prob(nmap, act_id,
4737 &(const struct req_context) {
4738 .player = unit_owner(actor_unit),
4739 .city = tile_city(actor_tile),
4740 .tile = actor_tile,
4741 .unit = actor_unit,
4742 .unittype = unit_type_get(actor_unit),
4743 },
4744 actor_home,
4745 NULL,
4746 NULL);
4747}
4748
4749/**********************************************************************/
4754 const struct unit *actor_unit,
4755 const action_id act_id)
4756{
4760 act_id);
4761}
4762
4763/**********************************************************************/
4776 const struct action *paction,
4777 const struct unit *act_unit,
4778 const struct city *tgt_city,
4779 const struct unit *tgt_unit,
4780 const struct tile *tgt_tile,
4781 const struct extra_type *extra_tgt)
4782{
4783 /* Assume impossible until told otherwise. */
4784 struct act_prob prob = ACTPROB_IMPOSSIBLE;
4785
4788
4790 case ATK_STACK:
4791 if (tgt_tile) {
4793 }
4794 break;
4795 case ATK_TILE:
4796 if (tgt_tile) {
4798 }
4799 break;
4800 case ATK_EXTRAS:
4801 if (tgt_tile) {
4804 }
4805 break;
4806 case ATK_CITY:
4807 if (tgt_city) {
4809 }
4810 break;
4811 case ATK_UNIT:
4812 if (tgt_unit) {
4814 }
4815 break;
4816 case ATK_SELF:
4817 prob = action_prob_self(nmap, act_unit, paction->id);
4818 break;
4819 case ATK_COUNT:
4820 log_error("Invalid action target kind");
4821 break;
4822 }
4823
4824 return prob;
4825}
4826
4827/**********************************************************************/
4833 const action_id act_id,
4834 const struct unit *actor,
4835 const struct city *actor_home,
4836 const struct tile *actor_tile,
4837 const bool omniscient_cheat,
4838 const struct city* target)
4839{
4840 /* FIXME: some unit state requirements still depend on the actor unit's
4841 * current position rather than on actor_tile. Maybe this function should
4842 * return ACTPROB_NOT_IMPLEMENTED when one of those is detected and no
4843 * other requirement makes the action ACTPROB_IMPOSSIBLE? */
4844
4845 if (omniscient_cheat) {
4848 target)) {
4849 return ACTPROB_CERTAIN;
4850 } else {
4851 return ACTPROB_IMPOSSIBLE;
4852 }
4853 } else {
4854 /* FIXME: this branch result depends _directly_ on actor's position.
4855 * I.e., like, not adjacent, no action. Other branch ignores radius. */
4857 act_id, target);
4858 }
4859}
4860
4861/**********************************************************************/
4866struct act_prob
4868 action_id act_id,
4869 const struct unit *actor,
4870 const struct city *actor_home,
4871 const struct tile *actor_tile,
4872 bool omniscient_cheat,
4873 const struct unit *target)
4874{
4875 /* FIXME: some unit state requirements still depend on the actor unit's
4876 * current position rather than on actor_tile. Maybe this function should
4877 * return ACTPROB_NOT_IMPLEMENTED when one of those is detected and no
4878 * other requirement makes the action ACTPROB_IMPOSSIBLE? */
4879
4880 if (omniscient_cheat) {
4883 target)) {
4884 return ACTPROB_CERTAIN;
4885 } else {
4886 return ACTPROB_IMPOSSIBLE;
4887 }
4888 } else {
4890 act_id, target);
4891 }
4892}
4893
4894/**********************************************************************/
4899struct act_prob
4901 action_id act_id,
4902 const struct unit *actor,
4903 const struct city *actor_home,
4904 const struct tile *actor_tile,
4905 bool omniscient_cheat,
4906 const struct tile *target)
4907{
4908 /* FIXME: some unit state requirements still depend on the actor unit's
4909 * current position rather than on actor_tile. Maybe this function should
4910 * return ACTPROB_NOT_IMPLEMENTED when one of those is detected and no
4911 * other requirement makes the action ACTPROB_IMPOSSIBLE? */
4912
4913 if (omniscient_cheat) {
4916 target)) {
4917 return ACTPROB_CERTAIN;
4918 } else {
4919 return ACTPROB_IMPOSSIBLE;
4920 }
4921 } else {
4923 act_id, target);
4924 }
4925}
4926
4927/**********************************************************************/
4932struct act_prob
4934 action_id act_id,
4935 const struct unit *actor,
4936 const struct city *actor_home,
4937 const struct tile *actor_tile,
4938 bool omniscient_cheat,
4939 const struct tile *target_tile,
4940 const struct extra_type *target_extra)
4941{
4942 /* FIXME: some unit state requirements still depend on the actor unit's
4943 * current position rather than on actor_tile. Maybe this function should
4944 * return ACTPROB_NOT_IMPLEMENTED when one of those is detected and no
4945 * other requirement makes the action ACTPROB_IMPOSSIBLE? */
4946
4947 if (omniscient_cheat) {
4951 return ACTPROB_CERTAIN;
4952 } else {
4953 return ACTPROB_IMPOSSIBLE;
4954 }
4955 } else {
4957 act_id, target_tile, target_extra);
4958 }
4959}
4960
4961/**********************************************************************/
4966struct act_prob
4968 action_id act_id,
4969 const struct unit *actor,
4970 const struct city *actor_home,
4971 const struct tile *actor_tile,
4972 bool omniscient_cheat,
4973 const struct tile *target_tile,
4974 const struct extra_type *target_extra)
4975{
4976 /* FIXME: some unit state requirements still depend on the actor unit's
4977 * current position rather than on actor_tile. Maybe this function should
4978 * return ACTPROB_NOT_IMPLEMENTED when one of those is detected and no
4979 * other requirement makes the action ACTPROB_IMPOSSIBLE? */
4980
4981 if (omniscient_cheat) {
4985 return ACTPROB_CERTAIN;
4986 } else {
4987 return ACTPROB_IMPOSSIBLE;
4988 }
4989 } else {
4991 act_id, target_tile, target_extra);
4992 }
4993}
4994
4995/**********************************************************************/
5000struct act_prob
5002 action_id act_id,
5003 const struct unit *actor,
5004 const struct city *actor_home,
5005 const struct tile *actor_tile,
5006 bool omniscient_cheat)
5007{
5008 /* FIXME: some unit state requirements still depend on the actor unit's
5009 * current position rather than on actor_tile. Maybe this function should
5010 * return ACTPROB_NOT_IMPLEMENTED when one of those is detected and no
5011 * other requirement makes the action ACTPROB_IMPOSSIBLE? */
5012 if (omniscient_cheat) {
5015 return ACTPROB_CERTAIN;
5016 } else {
5017 return ACTPROB_IMPOSSIBLE;
5018 }
5019 } else {
5021 act_id);
5022 }
5023}
5024
5025/**********************************************************************/
5029{
5031
5032 return out;
5033}
5034
5035/**********************************************************************/
5039{
5041
5042 return out;
5043}
5044
5045/**********************************************************************/
5049{
5051
5052 return out;
5053}
5054
5055/**********************************************************************/
5059{
5061
5062 return out;
5063}
5064
5065/**********************************************************************/
5069{
5071
5072 return out;
5073}
5074
5075/**********************************************************************/
5080{
5081 return (ACTPROB_VAL_MIN < probability.max
5083}
5084
5085/**********************************************************************/
5090{
5091 return (ACTPROB_VAL_MAX == probability.min
5092 && ACTPROB_VAL_MAX == probability.max);
5093}
5094
5095/**********************************************************************/
5099static inline bool
5105
5106/**********************************************************************/
5110static inline bool
5112{
5113 return probability.min == ACTPROB_VAL_NOT_IMPL
5114 && probability.max == ACTPROB_VAL_MIN;
5115}
5116
5117/**********************************************************************/
5121static inline bool
5123{
5124 return probability.max < probability.min;
5125}
5126
5127/**********************************************************************/
5131 const struct act_prob *ap2)
5132{
5133 return ap1->min == ap2->min && ap1->max == ap2->max;
5134}
5135
5136/**********************************************************************/
5140 const struct act_prob ap2)
5141{
5142 struct act_prob my_ap1;
5143 struct act_prob my_ap2;
5144
5145 /* The action probabilities are real. */
5148
5149 /* Convert any signals to ACTPROB_NOT_KNOWN. */
5151 /* Assert that it is OK to convert the signal. */
5153
5155 } else {
5156 my_ap1 = ap1;
5157 }
5158
5160 /* Assert that it is OK to convert the signal. */
5162
5164 } else {
5165 my_ap2 = ap2;
5166 }
5167
5168 /* The action probabilities now have a comparison friendly form. */
5171
5172 /* Do the comparison. Start with min. Continue with max. */
5173 if (my_ap1.min < my_ap2.min) {
5174 return -1;
5175 } else if (my_ap1.min > my_ap2.min) {
5176 return 1;
5177 } else if (my_ap1.max < my_ap2.max) {
5178 return -1;
5179 } else if (my_ap1.max > my_ap2.max) {
5180 return 1;
5181 } else {
5182 return 0;
5183 }
5184}
5185
5186/**********************************************************************/
5191{
5192 struct act_prob my_ap;
5193
5194 /* The action probability is real. */
5196
5197 /* Convert any signals to ACTPROB_NOT_KNOWN. */
5199 /* Assert that it is OK to convert the signal. */
5201
5203 } else {
5204 my_ap = ap;
5205 }
5206
5207 /* The action probability now has a math friendly form. */
5209
5210 return (double)my_ap.min / (double) ACTPROB_VAL_MAX;
5211}
5212
5213/**********************************************************************/
5218 const struct act_prob *ap2)
5219{
5220 struct act_prob my_ap1;
5221 struct act_prob my_ap2;
5222 struct act_prob out;
5223
5224 /* The action probabilities are real. */
5227
5230 /* Keep the information rather than converting the signal to
5231 * ACTPROB_NOT_KNOWN. */
5232
5233 /* Assert that it is OK to convert the signal. */
5235
5236 out.min = ap1->min;
5237 out.max = ap2->max;
5238
5239 return out;
5240 }
5241
5242 /* Convert any signals to ACTPROB_NOT_KNOWN. */
5243 if (action_prob_is_signal(*ap1)) {
5244 /* Assert that it is OK to convert the signal. */
5246
5247 my_ap1.min = ACTPROB_VAL_MIN;
5248 my_ap1.max = ACTPROB_VAL_MAX;
5249 } else {
5250 my_ap1.min = ap1->min;
5251 my_ap1.max = ap1->max;
5252 }
5253
5254 if (action_prob_is_signal(*ap2)) {
5255 /* Assert that it is OK to convert the signal. */
5257
5258 my_ap2.min = ACTPROB_VAL_MIN;
5259 my_ap2.max = ACTPROB_VAL_MAX;
5260 } else {
5261 my_ap2.min = ap2->min;
5262 my_ap2.max = ap2->max;
5263 }
5264
5265 /* The action probabilities now have a math friendly form. */
5268
5269 /* Do the math. */
5270 out.min = (my_ap1.min * my_ap2.min) / ACTPROB_VAL_MAX;
5271 out.max = (my_ap1.max * my_ap2.max) / ACTPROB_VAL_MAX;
5272
5273 /* Cap at 100%. */
5274 out.min = MIN(out.min, ACTPROB_VAL_MAX);
5275 out.max = MIN(out.max, ACTPROB_VAL_MAX);
5276
5277 return out;
5278}
5279
5280/**********************************************************************/
5288 const struct act_prob *ap2)
5289{
5290 struct act_prob my_ap1;
5291 struct act_prob my_ap2;
5292 struct act_prob out;
5293
5294 /* The action probabilities are real. */
5297
5300 /* Keep the information rather than converting the signal to
5301 * ACTPROB_NOT_KNOWN. */
5302
5303 /* Assert that it is OK to convert the signal. */
5305
5306 out.min = ap1->min;
5307 out.max = ap2->max;
5308
5309 return out;
5310 }
5311
5312 /* Convert any signals to ACTPROB_NOT_KNOWN. */
5313 if (action_prob_is_signal(*ap1)) {
5314 /* Assert that it is OK to convert the signal. */
5316
5317 my_ap1.min = ACTPROB_VAL_MIN;
5318 my_ap1.max = ACTPROB_VAL_MAX;
5319 } else {
5320 my_ap1.min = ap1->min;
5321 my_ap1.max = ap1->max;
5322 }
5323
5324 if (action_prob_is_signal(*ap2)) {
5325 /* Assert that it is OK to convert the signal. */
5327
5328 my_ap2.min = ACTPROB_VAL_MIN;
5329 my_ap2.max = ACTPROB_VAL_MAX;
5330 } else {
5331 my_ap2.min = ap2->min;
5332 my_ap2.max = ap2->max;
5333 }
5334
5335 /* The action probabilities now have a math friendly form. */
5338
5339 /* Do the math. */
5340 out.min = my_ap1.min + (((ACTPROB_VAL_MAX - my_ap1.min) * my_ap2.min)
5341 / ACTPROB_VAL_MAX);
5342 out.max = my_ap1.max + (((ACTPROB_VAL_MAX - my_ap1.max) * my_ap2.max)
5343 / ACTPROB_VAL_MAX);
5344
5345 /* Cap at 100%. */
5346 out.min = MIN(out.min, ACTPROB_VAL_MAX);
5347 out.max = MIN(out.max, ACTPROB_VAL_MAX);
5348
5349 return out;
5350}
5351
5352/**********************************************************************/
5356{
5357 switch (actres_dice_type(paction->result)) {
5358 case DRT_DIPLCHANCE:
5360 /* Take the initial odds from the diplchance setting. */
5362 server_setting_by_name("diplchance"));
5363 }
5365 case DRT_CERTAIN:
5366 return 100;
5367 case DRT_NONE:
5368 break;
5369 }
5370
5371 /* The odds of the action not being stopped by its dice roll when the dice
5372 * isn't thrown is 100%. ACTION_ODDS_PCT_DICE_ROLL_NA is above 100% */
5374}
5375
5376/**********************************************************************/
5380 const struct unit *act_unit,
5381 const struct city *tgt_city,
5382 const struct player *tgt_player,
5383 const struct action *paction)
5384{
5386 const struct unit_type *actu_type = unit_type_get(act_unit);
5387
5388 fc_assert_action_msg(odds >= 0 && odds <= 100,
5389 odds = 100,
5390 "Bad initial odds for action number %d."
5391 " Does it roll the dice at all?",
5392 paction->id);
5393
5394 /* Let the Action_Odds_Pct effect modify the odds. The advantage of doing
5395 * it this way instead of rolling twice is that Action_Odds_Pct can
5396 * increase the odds. */
5397 odds = odds
5398 + ((odds
5400 &(const struct req_context) {
5401 .player = act_player,
5402 .city = tgt_city,
5403 .unit = act_unit,
5404 .unittype = actu_type,
5405 .action = paction,
5406 },
5407 &(const struct req_context) {
5408 .player = tgt_player,
5409 },
5411 / 100)
5412 - ((odds
5414 &(const struct req_context) {
5415 .player = tgt_player,
5416 .city = tgt_city,
5417 .unit = act_unit,
5418 .unittype = actu_type,
5419 .action = paction,
5420 },
5421 &(const struct req_context) {
5422 .player = act_player,
5423 },
5425 / 100);
5426
5427
5428 /* Odds are between 0% and 100%. */
5429 return CLIP(0, odds, 100);
5430}
5431
5432/**********************************************************************/
5436{
5437 struct action *paction = action_by_number(act);
5438
5439 /* Always immune since its not enabled. Doesn't count. */
5440 if (!action_is_in_use(paction)) {
5441 return FALSE;
5442 }
5443
5445 if (requirement_fulfilled_by_government(gov, &(enabler->target_reqs))) {
5446 return FALSE;
5447 }
5449
5450 return TRUE;
5451}
5452
5453/**********************************************************************/
5459 const struct player *actor_player,
5460 const struct req_context *target)
5461{
5463 enabler) {
5464 if (are_reqs_active(target,
5465 &(const struct req_context) {
5467 },
5468 &enabler->target_reqs, RPT_POSSIBLE)) {
5469 return TRUE;
5470 }
5472
5473 return FALSE;
5474}
5475
5476/**********************************************************************/
5480 const struct player *actor_player,
5481 const struct city* target_city)
5482{
5484 FALSE, "Action %s is against %s not cities",
5485 action_id_rule_name(act_id),
5487 action_id_get_target_kind(act_id)));
5488
5489 return is_target_possible(act_id, actor_player,
5490 &(const struct req_context) {
5491 .player = city_owner(target_city),
5492 .city = target_city,
5494 });
5495}
5496
5497/**********************************************************************/
5503 const action_id act_id,
5504 const struct unit *actor_unit)
5505{
5506 const struct player *actor_player = unit_owner(actor_unit);
5507 const struct req_context actor_ctxt = {
5509 .city = tile_city(unit_tile(actor_unit)),
5511 .unit = actor_unit,
5512 .unittype = unit_type_get(actor_unit),
5513 };
5514 const struct action *paction = action_by_number(act_id);
5515
5516 enum fc_tristate result;
5517
5519
5520 if (!utype_can_do_action(actor_unit->utype, act_id)) {
5521 /* The unit type can't perform the action. */
5522 return FALSE;
5523 }
5524
5527
5528 if (result == TRI_NO) {
5529 /* The hard requirements aren't fulfilled. */
5530 return FALSE;
5531 }
5532
5534 enabler) {
5535 const enum fc_tristate current
5537 &enabler->actor_reqs,
5538 /* Needed since no player to evaluate DiplRel
5539 * requirements against. */
5540 RPT_POSSIBLE);
5541
5542 if (current == TRI_YES
5543 || current == TRI_MAYBE) {
5544 /* The ruleset requirements may be fulfilled. */
5545 return TRUE;
5546 }
5548
5549 /* No action enabler allows this action. */
5550 return FALSE;
5551}
5552
5553/**********************************************************************/
5558 const action_id act_id)
5559{
5560 fc_assert(action_id_exists(act_id) || act_id == ACTION_ANY);
5561
5562 /* Check if full movement points may enable the specified action. */
5564 act_id,
5567 act_id,
5569}
5570
5571/**********************************************************************/
5596
5597/**********************************************************************/
5608{
5609 const struct action *paction = enabler_get_action(ae);
5610
5611 switch (action_get_actor_kind(paction)) {
5612 case AAK_UNIT:
5615 /* A possible actor unit type has been found. */
5616 return TRUE;
5617 }
5619
5620 /* No actor detected. */
5621 return FALSE;
5622 case AAK_CITY:
5623 case AAK_PLAYER:
5624 /* Currently can't detect */
5625 return TRUE;
5626 case AAK_COUNT:
5628 break;
5629 }
5630
5631 /* No actor detected. */
5632 return FALSE;
5633}
5634
5635/**********************************************************************/
5643{
5644 switch (action_get_actor_kind(paction)) {
5645 case AAK_UNIT:
5648 return TRUE;
5649 }
5651 break;
5652 case AAK_CITY:
5653 case AAK_PLAYER:
5654 /* No ruleset hard reqs atm */
5655 return TRUE;
5656 case AAK_COUNT:
5658 break;
5659 }
5660
5661 /* No actor detected. */
5662 return FALSE;
5663}
5664
5665/**********************************************************************/
5673{
5675
5677 /* Hard requirements not fulfilled. */
5678 return FALSE;
5679 }
5680
5682
5684 /* If this iteration finds any entries, action is enabled. */
5685 return TRUE;
5687
5688 /* No non deleted action enabler. */
5689 return FALSE;
5690}
5691
5692/**********************************************************************/
5699{
5700 return paction != nullptr
5702}
5703
5704/**********************************************************************/
5714
5715/**********************************************************************/
5719{
5720 fc_assert_ret_val(num >= 0, NULL);
5722
5723 return &auto_perfs[num];
5724}
5725
5726/**********************************************************************/
5735{
5736 return action_auto_perf_slot_number(num);
5737}
5738
5739/**********************************************************************/
5743 struct universal *actor_uni,
5744 struct universal *target_uni)
5745{
5747 enab) {
5748 if ((actor_uni == NULL
5749 || universal_fulfills_requirements(FALSE, &(enab->actor_reqs),
5750 actor_uni))
5751 && (target_uni == NULL
5752 || universal_fulfills_requirements(FALSE, &(enab->target_reqs),
5753 target_uni))) {
5754 return TRUE;
5755 }
5757
5758 return FALSE;
5759}
5760
5761/**********************************************************************/
5767{
5769
5770 if (size < MAX_NUM_ACTIONS) {
5771 /* An action array is terminated by ACTION_NONE */
5773 }
5774}
5775
5776/**********************************************************************/
5784 int *position,
5785 enum action_result result)
5786{
5787 action_iterate(act) {
5788 struct action *paction = action_by_number(act);
5789 if (paction->result == result) {
5790 /* Assume one result for each action. */
5791 fc_assert_ret(*position < MAX_NUM_ACTIONS);
5792
5793 act_array[(*position)++] = paction->id;
5794 }
5796}
5797
5798/**********************************************************************/
5804{
5805 switch ((enum gen_action)act) {
5806 case ACTION_SPY_POISON:
5807 return "ui_name_poison_city";
5809 return "ui_name_poison_city_escape";
5811 return "ui_name_sabotage_unit";
5813 return "ui_name_sabotage_unit_escape";
5815 return "ui_name_bribe_unit";
5817 return "ui_name_bribe_stack";
5819 return "ui_name_sabotage_city";
5821 return "ui_name_sabotage_city_escape";
5823 return "ui_name_targeted_sabotage_city";
5825 return "ui_name_sabotage_city_production";
5827 return "ui_name_targeted_sabotage_city_escape";
5829 return "ui_name_sabotage_city_production_escape";
5831 return "ui_name_incite_city";
5833 return "ui_name_incite_city_escape";
5835 return "ui_name_establish_embassy";
5837 return "ui_name_establish_embassy_stay";
5839 return "ui_name_steal_tech";
5841 return "ui_name_steal_tech_escape";
5843 return "ui_name_targeted_steal_tech";
5845 return "ui_name_targeted_steal_tech_escape";
5847 return "ui_name_investigate_city";
5849 return "ui_name_investigate_city_spend_unit";
5851 return "ui_name_steal_gold";
5853 return "ui_name_steal_gold_escape";
5855 return "ui_name_spread_plague";
5856 case ACTION_STEAL_MAPS:
5857 return "ui_name_steal_maps";
5859 return "ui_name_steal_maps_escape";
5860 case ACTION_TRADE_ROUTE:
5861 return "ui_name_establish_trade_route";
5862 case ACTION_MARKETPLACE:
5863 return "ui_name_enter_marketplace";
5864 case ACTION_HELP_WONDER:
5865 return "ui_name_help_wonder";
5867 return "ui_name_capture_units";
5868 case ACTION_EXPEL_UNIT:
5869 return "ui_name_expel_unit";
5870 case ACTION_FOUND_CITY:
5871 return "ui_name_found_city";
5872 case ACTION_JOIN_CITY:
5873 return "ui_name_join_city";
5874 case ACTION_BOMBARD:
5875 return "ui_name_bombard";
5876 case ACTION_BOMBARD2:
5877 return "ui_name_bombard_2";
5878 case ACTION_BOMBARD3:
5879 return "ui_name_bombard_3";
5880 case ACTION_BOMBARD4:
5881 return "ui_name_bombard_4";
5883 return "ui_name_bombard_lethal";
5885 return "ui_name_bombard_lethal_2";
5886 case ACTION_SPY_NUKE:
5887 return "ui_name_suitcase_nuke";
5889 return "ui_name_suitcase_nuke_escape";
5890 case ACTION_NUKE:
5891 return "ui_name_explode_nuclear";
5892 case ACTION_NUKE_CITY:
5893 return "ui_name_nuke_city";
5894 case ACTION_NUKE_UNITS:
5895 return "ui_name_nuke_units";
5897 return "ui_name_destroy_city";
5899 return "ui_name_disband_unit_recover";
5901 return "ui_name_disband_unit";
5902 case ACTION_HOME_CITY:
5903 return "ui_name_home_city";
5904 case ACTION_HOMELESS:
5905 return "ui_name_homeless";
5907 return "ui_name_upgrade_unit";
5908 case ACTION_PARADROP:
5909 return "ui_name_paradrop_unit";
5911 return "ui_name_paradrop_unit_conquer";
5913 return "ui_name_paradrop_unit_frighten";
5915 return "ui_name_paradrop_unit_frighten_conquer";
5917 return "ui_name_paradrop_unit_enter";
5919 return "ui_name_paradrop_unit_enter_conquer";
5920 case ACTION_AIRLIFT:
5921 return "ui_name_airlift_unit";
5922 case ACTION_ATTACK:
5923 return "ui_name_attack";
5924 case ACTION_ATTACK2:
5925 return "ui_name_attack_2";
5927 return "ui_name_suicide_attack";
5929 return "ui_name_suicide_attack_2";
5930 case ACTION_WIPE_UNITS:
5931 return "ui_name_wipe_units";
5933 return "ui_name_collect_ransom";
5935 return "ui_name_surgical_strike_building";
5937 return "ui_name_surgical_strike_production";
5939 return "ui_name_conquer_city_shrink";
5941 return "ui_name_conquer_city_shrink2";
5943 return "ui_name_conquer_city_shrink3";
5945 return "ui_name_conquer_city_shrink4";
5947 return "ui_name_conquer_extras";
5949 return "ui_name_conquer_extras_2";
5951 return "ui_name_conquer_extras_3";
5953 return "ui_name_conquer_extras_4";
5954 case ACTION_HEAL_UNIT:
5955 return "ui_name_heal_unit";
5956 case ACTION_HEAL_UNIT2:
5957 return "ui_name_heal_unit_2";
5959 return "ui_name_transform_terrain";
5961 return "ui_name_transform_terrain_2";
5962 case ACTION_CULTIVATE:
5963 return "ui_name_cultivate";
5964 case ACTION_CULTIVATE2:
5965 return "ui_name_cultivate_2";
5966 case ACTION_PLANT:
5967 return "ui_name_plant";
5968 case ACTION_PLANT2:
5969 return "ui_name_plant_2";
5970 case ACTION_PILLAGE:
5971 return "ui_name_pillage";
5972 case ACTION_PILLAGE2:
5973 return "ui_name_pillage_2";
5974 case ACTION_CLEAN:
5975 return "ui_name_clean";
5976 case ACTION_CLEAN2:
5977 return "ui_name_clean_2";
5978 case ACTION_FORTIFY:
5979 return "ui_name_fortify";
5980 case ACTION_FORTIFY2:
5981 return "ui_name_fortify_2";
5982 case ACTION_ROAD:
5983 return "ui_name_build_road";
5984 case ACTION_ROAD2:
5985 return "ui_name_build_road_2";
5986 case ACTION_CONVERT:
5987 return "ui_name_convert_unit";
5988 case ACTION_BASE:
5989 return "ui_name_build_base";
5990 case ACTION_BASE2:
5991 return "ui_name_build_base_2";
5992 case ACTION_MINE:
5993 return "ui_name_build_mine";
5994 case ACTION_MINE2:
5995 return "ui_name_build_mine_2";
5996 case ACTION_IRRIGATE:
5997 return "ui_name_irrigate";
5998 case ACTION_IRRIGATE2:
5999 return "ui_name_irrigate_2";
6001 return "ui_name_transport_deboard";
6003 return "ui_name_transport_board";
6005 return "ui_name_transport_board_2";
6007 return "ui_name_transport_board_3";
6009 return "ui_name_transport_embark";
6011 return "ui_name_transport_embark_2";
6013 return "ui_name_transport_embark_3";
6015 return "ui_name_transport_embark_4";
6017 return "ui_name_transport_unload";
6019 return "ui_name_transport_load";
6021 return "ui_name_transport_load_2";
6023 return "ui_name_transport_load_3";
6025 return "ui_name_transport_disembark";
6027 return "ui_name_transport_disembark_2";
6029 return "ui_name_transport_disembark_3";
6031 return "ui_name_transport_disembark_4";
6032 case ACTION_HUT_ENTER:
6033 return "ui_name_enter_hut";
6034 case ACTION_HUT_ENTER2:
6035 return "ui_name_enter_hut_2";
6036 case ACTION_HUT_ENTER3:
6037 return "ui_name_enter_hut_3";
6038 case ACTION_HUT_ENTER4:
6039 return "ui_name_enter_hut_4";
6041 return "ui_name_frighten_hut";
6043 return "ui_name_frighten_hut_2";
6045 return "ui_name_frighten_hut_3";
6047 return "ui_name_frighten_hut_4";
6048 case ACTION_SPY_ATTACK:
6049 return "ui_name_spy_attack";
6050 case ACTION_UNIT_MOVE:
6051 return "ui_name_unit_move";
6052 case ACTION_UNIT_MOVE2:
6053 return "ui_name_unit_move_2";
6054 case ACTION_UNIT_MOVE3:
6055 return "ui_name_unit_move_3";
6056 case ACTION_TELEPORT:
6057 return "ui_name_teleport";
6058 case ACTION_TELEPORT2:
6059 return "ui_name_teleport_2";
6060 case ACTION_TELEPORT3:
6061 return "ui_name_teleport_3";
6063 return "ui_name_teleport_conquer";
6065 return "ui_name_teleport_frighten";
6067 return "ui_name_teleport_frighten_conquer";
6069 return "ui_name_teleport_enter";
6071 return "ui_name_teleport_enter_conquer";
6072 case ACTION_SPY_ESCAPE:
6073 return "ui_name_escape";
6075 return "ui_name_user_action_1";
6077 return "ui_name_user_action_2";
6079 return "ui_name_user_action_3";
6081 return "ui_name_user_action_4";
6083 case ACTION_ESCAPE:
6084 case ACTION_CIVIL_WAR:
6085 fc_assert(!action_id_is_internal(act)); /* Fail always */
6086 break;
6087 case ACTION_COUNT:
6088 break;
6089
6091 }
6092
6093 fc_assert(act >= 0 && act < ACTION_COUNT);
6094
6095 return NULL;
6096}
6097
6098/**********************************************************************/
6101const char *action_ui_name_default(int act)
6102{
6103 switch ((enum gen_action)act) {
6104 case ACTION_SPY_POISON:
6105 /* TRANS: _Poison City (3% chance of success). */
6106 return N_("%sPoison City%s");
6108 /* TRANS: _Poison City and Escape (3% chance of success). */
6109 return N_("%sPoison City and Escape%s");
6111 /* TRANS: S_abotage Enemy Unit (3% chance of success). */
6112 return N_("S%sabotage Enemy Unit%s");
6114 /* TRANS: S_abotage Enemy Unit and Escape (3% chance of success). */
6115 return N_("S%sabotage Enemy Unit and Escape%s");
6117 /* TRANS: Bribe Enemy _Unit (3% chance of success). */
6118 return N_("Bribe Enemy %sUnit%s");
6120 /* TRANS: Bribe Enemy _Stack (3% chance of success). */
6121 return N_("Bribe Enemy %sStack%s");
6123 /* TRANS: _Sabotage City (3% chance of success). */
6124 return N_("%sSabotage City%s");
6126 /* TRANS: _Sabotage City and Escape (3% chance of success). */
6127 return N_("%sSabotage City and Escape%s");
6129 /* TRANS: Industria_l Sabotage (3% chance of success). */
6130 return N_("Industria%sl Sabotage%s");
6132 /* TRANS: Industria_l Sabotage Production (3% chance of success). */
6133 return N_("Industria%sl Sabotage Production%s");
6135 /* TRANS: Industria_l Sabotage and Escape (3% chance of success). */
6136 return N_("Industria%sl Sabotage and Escape%s");
6138 /* TRANS: Industria_l Sabotage Production and Escape (3% chance of success). */
6139 return N_("Industria%sl Sabotage Production and Escape%s");
6141 /* TRANS: Incite a Re_volt (3% chance of success). */
6142 return N_("Incite a Re%svolt%s");
6144 /* TRANS: Incite a Re_volt and Escape (3% chance of success). */
6145 return N_("Incite a Re%svolt and Escape%s");
6147 /* TRANS: Establish _Embassy (100% chance of success). */
6148 return N_("Establish %sEmbassy%s");
6150 /* TRANS: Becom_e Ambassador (100% chance of success). */
6151 return N_("Becom%se Ambassador%s");
6153 /* TRANS: Steal _Technology (3% chance of success). */
6154 return N_("Steal %sTechnology%s");
6156 /* TRANS: Steal _Technology and Escape (3% chance of success). */
6157 return N_("Steal %sTechnology and Escape%s");
6159 /* TRANS: In_dustrial Espionage (3% chance of success). */
6160 return N_("In%sdustrial Espionage%s");
6162 /* TRANS: In_dustrial Espionage and Escape (3% chance of success). */
6163 return N_("In%sdustrial Espionage and Escape%s");
6165 /* TRANS: _Investigate City (100% chance of success). */
6166 return N_("%sInvestigate City%s");
6168 /* TRANS: _Investigate City (spends the unit) (100% chance of
6169 * success). */
6170 return N_("%sInvestigate City (spends the unit)%s");
6172 /* TRANS: Steal _Gold (100% chance of success). */
6173 return N_("Steal %sGold%s");
6175 /* TRANS: Steal _Gold and Escape (100% chance of success). */
6176 return N_("Steal %sGold and Escape%s");
6178 /* TRANS: Spread _Plague (100% chance of success). */
6179 return N_("Spread %sPlague%s");
6180 case ACTION_STEAL_MAPS:
6181 /* TRANS: Steal _Maps (100% chance of success). */
6182 return N_("Steal %sMaps%s");
6184 /* TRANS: Steal _Maps and Escape (100% chance of success). */
6185 return N_("Steal %sMaps and Escape%s");
6186 case ACTION_TRADE_ROUTE:
6187 /* TRANS: Establish Trade _Route (100% chance of success). */
6188 return N_("Establish Trade %sRoute%s");
6189 case ACTION_MARKETPLACE:
6190 /* TRANS: Enter _Marketplace (100% chance of success). */
6191 return N_("Enter %sMarketplace%s");
6192 case ACTION_HELP_WONDER:
6193 /* TRANS: Help _build Wonder (100% chance of success). */
6194 return N_("Help %sbuild Wonder%s");
6196 /* TRANS: _Capture Units (100% chance of success). */
6197 return N_("%sCapture Units%s");
6198 case ACTION_EXPEL_UNIT:
6199 /* TRANS: _Expel Unit (100% chance of success). */
6200 return N_("%sExpel Unit%s");
6201 case ACTION_FOUND_CITY:
6202 /* TRANS: _Found City (100% chance of success). */
6203 return N_("%sFound City%s");
6204 case ACTION_JOIN_CITY:
6205 /* TRANS: _Join City (100% chance of success). */
6206 return N_("%sJoin City%s");
6207 case ACTION_BOMBARD:
6208 /* TRANS: B_ombard (100% chance of success). */
6209 return N_("B%sombard%s");
6210 case ACTION_BOMBARD2:
6211 /* TRANS: B_ombard 2 (100% chance of success). */
6212 return N_("B%sombard 2%s");
6213 case ACTION_BOMBARD3:
6214 /* TRANS: B_ombard 3 (100% chance of success). */
6215 return N_("B%sombard 3%s");
6216 case ACTION_BOMBARD4:
6217 /* TRANS: B_ombard 4 (100% chance of success). */
6218 return N_("B%sombard 4%s");
6221 /* TRANS: Lethal B_ombard (100% chance of success). */
6222 return N_("Lethal B%sombard%s");
6223 case ACTION_SPY_NUKE:
6224 /* TRANS: Suitcase _Nuke (100% chance of success). */
6225 return N_("Suitcase %sNuke%s");
6227 /* TRANS: Suitcase _Nuke and Escape (100% chance of success). */
6228 return N_("Suitcase %sNuke and Escape%s");
6229 case ACTION_NUKE:
6230 /* TRANS: Explode _Nuclear (100% chance of success). */
6231 return N_("Explode %sNuclear%s");
6232 case ACTION_NUKE_CITY:
6233 /* TRANS: _Nuke City (100% chance of success). */
6234 return N_("%sNuke City%s");
6235 case ACTION_NUKE_UNITS:
6236 /* TRANS: _Nuke Units (100% chance of success). */
6237 return N_("%sNuke Units%s");
6239 /* TRANS: Destroy _City (100% chance of success). */
6240 return N_("Destroy %sCity%s");
6242 /* TRANS: Dis_band recovering production (100% chance of success). */
6243 return N_("Dis%sband recovering production%s");
6245 /* TRANS: Dis_band without recovering production (100% chance of success). */
6246 return N_("Dis%sband without recovering production%s");
6247 case ACTION_HOME_CITY:
6248 /* TRANS: Set _Home City (100% chance of success). */
6249 return N_("Set %sHome City%s");
6250 case ACTION_HOMELESS:
6251 /* TRANS: Make _Homeless (100% chance of success). */
6252 return N_("Make %sHomeless%s");
6254 /* TRANS: _Upgrade Unit (100% chance of success). */
6255 return N_("%sUpgrade Unit%s");
6256 case ACTION_PARADROP:
6257 /* TRANS: Drop _Paratrooper (100% chance of success). */
6258 return N_("Drop %sParatrooper%s");
6260 /* TRANS: Drop _Paratrooper (100% chance of success). */
6261 return N_("Drop %sParatrooper%s");
6263 /* TRANS: Drop _Paratrooper (100% chance of success). */
6264 return N_("Drop %sParatrooper%s");
6266 /* TRANS: Drop _Paratrooper (100% chance of success). */
6267 return N_("Drop %sParatrooper%s");
6269 /* TRANS: Drop _Paratrooper (100% chance of success). */
6270 return N_("Drop %sParatrooper%s");
6272 /* TRANS: Drop _Paratrooper (100% chance of success). */
6273 return N_("Drop %sParatrooper%s");
6274 case ACTION_AIRLIFT:
6275 /* TRANS: _Airlift to City (100% chance of success). */
6276 return N_("%sAirlift to City%s");
6277 case ACTION_ATTACK:
6278 case ACTION_ATTACK2:
6279 /* TRANS: _Attack (100% chance of success). */
6280 return N_("%sAttack%s");
6283 /* TRANS: _Suicide Attack (100% chance of success). */
6284 return N_("%sSuicide Attack%s");
6285 case ACTION_WIPE_UNITS:
6286 /* TRANS: _Wipe Units (100% chance of success). */
6287 return N_("%sWipe Units%s");
6289 /* TRANS: Collect _Ransom (100% chance of success). */
6290 return N_("Collect %sRansom%s");
6292 /* TRANS: Surgical Str_ike Building (100% chance of success). */
6293 return N_("Surgical Str%sike Building%s");
6295 /* TRANS: Surgical Str_ike Production (100% chance of success). */
6296 return N_("Surgical Str%sike Production%s");
6300 /* TRANS: _Conquer City (100% chance of success). */
6301 return N_("%sConquer City%s");
6303 /* TRANS: _Conquer City 2 (100% chance of success). */
6304 return N_("%sConquer City 2%s");
6308 /* TRANS: _Conquer Extras (100% chance of success). */
6309 return N_("%sConquer Extras%s");
6311 /* TRANS: _Conquer Extras 2 (100% chance of success). */
6312 return N_("%sConquer Extras 2%s");
6313 case ACTION_HEAL_UNIT:
6314 case ACTION_HEAL_UNIT2:
6315 /* TRANS: Heal _Unit (3% chance of success). */
6316 return N_("Heal %sUnit%s");
6319 /* TRANS: _Transform Terrain (3% chance of success). */
6320 return N_("%sTransform Terrain%s");
6321 case ACTION_CULTIVATE:
6322 case ACTION_CULTIVATE2:
6323 /* TRANS: Transform by _Cultivating (3% chance of success). */
6324 return N_("Transform by %sCultivating%s");
6325 case ACTION_PLANT:
6326 case ACTION_PLANT2:
6327 /* TRANS: Transform by _Planting (3% chance of success). */
6328 return N_("Transform by %sPlanting%s");
6329 case ACTION_PILLAGE:
6330 case ACTION_PILLAGE2:
6331 /* TRANS: Pilla_ge (100% chance of success). */
6332 return N_("Pilla%sge%s");
6333 case ACTION_CLEAN:
6334 case ACTION_CLEAN2:
6335 /* TRANS: Clean (100% chance of success). */
6336 return N_("%sClean%s");
6337 case ACTION_FORTIFY:
6338 case ACTION_FORTIFY2:
6339 /* TRANS: _Fortify (100% chance of success). */
6340 return N_("%sFortify%s");
6341 case ACTION_ROAD:
6342 case ACTION_ROAD2:
6343 /* TRANS: Build _Road (100% chance of success). */
6344 return N_("Build %sRoad%s");
6345 case ACTION_CONVERT:
6346 /* TRANS: _Convert Unit (100% chance of success). */
6347 return N_("%sConvert Unit%s");
6348 case ACTION_BASE:
6349 case ACTION_BASE2:
6350 /* TRANS: _Build Base (100% chance of success). */
6351 return N_("%sBuild Base%s");
6352 case ACTION_MINE:
6353 case ACTION_MINE2:
6354 /* TRANS: Build _Mine (100% chance of success). */
6355 return N_("Build %sMine%s");
6356 case ACTION_IRRIGATE:
6357 case ACTION_IRRIGATE2:
6358 /* TRANS: Build _Irrigation (100% chance of success). */
6359 return N_("Build %sIrrigation%s");
6361 /* TRANS: _Deboard (100% chance of success). */
6362 return N_("%sDeboard%s");
6366 /* TRANS: _Board (100% chance of success). */
6367 return N_("%sBoard%s");
6372 /* TRANS: _Embark (100% chance of success). */
6373 return N_("%sEmbark%s");
6375 /* TRANS: _Unload (100% chance of success). */
6376 return N_("%sUnload%s");
6380 /* TRANS: _Load (100% chance of success). */
6381 return N_("%sLoad%s");
6385 /* TRANS: _Disembark (100% chance of success). */
6386 return N_("%sDisembark%s");
6388 /* TRANS: _Disembark 2 (100% chance of success). */
6389 return N_("%sDisembark 2%s");
6390 case ACTION_SPY_ATTACK:
6391 /* TRANS: _Eliminate Diplomat (100% chance of success). */
6392 return N_("%sEliminate Diplomat%s");
6393 case ACTION_HUT_ENTER:
6394 case ACTION_HUT_ENTER2:
6395 case ACTION_HUT_ENTER3:
6396 case ACTION_HUT_ENTER4:
6397 /* TRANS: Enter _Hut (100% chance of success). */
6398 return N_("Enter %sHut%s");
6403 /* TRANS: Frighten _Hut (100% chance of success). */
6404 return N_("Frighten %sHut%s");
6405 case ACTION_UNIT_MOVE:
6406 case ACTION_UNIT_MOVE2:
6407 case ACTION_UNIT_MOVE3:
6408 /* TRANS: Regular _Move (100% chance of success). */
6409 return N_("Regular %sMove%s");
6410 case ACTION_TELEPORT:
6411 case ACTION_TELEPORT2:
6412 case ACTION_TELEPORT3:
6413 /* TRANS: _Teleport (100% chance of success). */
6414 return N_("%sTeleport%s");
6416 /* TRANS: _Teleport (100% chance of success). */
6417 return N_("%sTeleport%s");
6419 /* TRANS: _Teleport (100% chance of success). */
6420 return N_("%sTeleport%s");
6422 /* TRANS: _Teleport (100% chance of success). */
6423 return N_("%sTeleport%s");
6425 /* TRANS: _Teleport (100% chance of success). */
6426 return N_("%sTeleport%s");
6428 /* TRANS: _Teleport (100% chance of success). */
6429 return N_("%sTeleport%s");
6430 case ACTION_SPY_ESCAPE:
6431 /* TRANS: _Escape To Nearest City (100% chance of success). */
6432 return N_("%sEscape To Nearest City%s");
6434 /* TRANS: _User Action 1 (100% chance of success). */
6435 return N_("%sUser Action 1%s");
6437 /* TRANS: _User Action 2 (100% chance of success). */
6438 return N_("%sUser Action 2%s");
6440 /* TRANS: _User Action 3 (100% chance of success). */
6441 return N_("%sUser Action 3%s");
6443 /* TRANS: _User Action 4 (100% chance of success). */
6444 return N_("%sUser Action 4%s");
6446 return N_("%sGain Veterancy%s");
6447 case ACTION_ESCAPE:
6448 return N_("%sEscape%s");
6449 case ACTION_CIVIL_WAR:
6450 return N_("%sCivil War%s");
6451 case ACTION_COUNT:
6452 fc_assert(act != ACTION_COUNT);
6453 break;
6454 }
6455
6456 return NULL;
6457}
6458
6459/**********************************************************************/
6466{
6467 switch ((enum gen_action)act) {
6468 case ACTION_SPY_POISON:
6493 case ACTION_STEAL_MAPS:
6495 case ACTION_TRADE_ROUTE:
6496 case ACTION_MARKETPLACE:
6497 case ACTION_HELP_WONDER:
6499 case ACTION_EXPEL_UNIT:
6500 case ACTION_FOUND_CITY:
6501 case ACTION_JOIN_CITY:
6502 case ACTION_SPY_NUKE:
6507 case ACTION_HOME_CITY:
6508 case ACTION_HOMELESS:
6510 case ACTION_PARADROP:
6516 case ACTION_AIRLIFT:
6517 case ACTION_ATTACK:
6518 case ACTION_ATTACK2:
6521 case ACTION_WIPE_UNITS:
6529 case ACTION_HEAL_UNIT:
6530 case ACTION_HEAL_UNIT2:
6533 case ACTION_CULTIVATE:
6534 case ACTION_CULTIVATE2:
6535 case ACTION_PLANT:
6536 case ACTION_PLANT2:
6537 case ACTION_PILLAGE:
6538 case ACTION_PILLAGE2:
6539 case ACTION_CLEAN:
6540 case ACTION_CLEAN2:
6541 case ACTION_FORTIFY:
6542 case ACTION_FORTIFY2:
6543 case ACTION_ROAD:
6544 case ACTION_ROAD2:
6545 case ACTION_CONVERT:
6546 case ACTION_BASE:
6547 case ACTION_BASE2:
6548 case ACTION_MINE:
6549 case ACTION_MINE2:
6550 case ACTION_IRRIGATE:
6551 case ACTION_IRRIGATE2:
6568 case ACTION_BOMBARD:
6569 case ACTION_BOMBARD2:
6570 case ACTION_BOMBARD3:
6571 case ACTION_BOMBARD4:
6574 case ACTION_SPY_ATTACK:
6579 case ACTION_HUT_ENTER:
6580 case ACTION_HUT_ENTER2:
6581 case ACTION_HUT_ENTER3:
6582 case ACTION_HUT_ENTER4:
6587 case ACTION_UNIT_MOVE:
6588 case ACTION_UNIT_MOVE2:
6589 case ACTION_UNIT_MOVE3:
6590 case ACTION_SPY_ESCAPE:
6592 case ACTION_ESCAPE:
6593 case ACTION_CIVIL_WAR:
6594 /* Min range is not ruleset changeable */
6595 return NULL;
6596 case ACTION_NUKE:
6597 return "explode_nuclear_min_range";
6598 case ACTION_NUKE_CITY:
6599 return "nuke_city_min_range";
6600 case ACTION_NUKE_UNITS:
6601 return "nuke_units_min_range";
6602 case ACTION_TELEPORT:
6603 return "teleport_min_range";
6604 case ACTION_TELEPORT2:
6605 return "teleport_2_min_range";
6606 case ACTION_TELEPORT3:
6607 return "teleport_3_min_range";
6609 return "teleport_conquer_min_range";
6611 return "teleport_frighten_min_range";
6613 return "teleport_frighten_conquer_min_range";
6615 return "teleport_enter_min_range";
6617 return "teleport_enter_conquer_min_range";
6619 return "user_action_1_min_range";
6621 return "user_action_2_min_range";
6623 return "user_action_3_min_range";
6625 return "user_action_4_min_range";
6626 case ACTION_COUNT:
6627 break;
6628
6630 }
6631
6632 fc_assert(act >= 0 && act < ACTION_COUNT);
6633
6634 return NULL;
6635}
6636
6637/**********************************************************************/
6644{
6645 switch ((enum gen_action)act) {
6646 case ACTION_SPY_POISON:
6671 case ACTION_STEAL_MAPS:
6673 case ACTION_TRADE_ROUTE:
6674 case ACTION_MARKETPLACE:
6676 case ACTION_EXPEL_UNIT:
6677 case ACTION_FOUND_CITY:
6678 case ACTION_JOIN_CITY:
6679 case ACTION_SPY_NUKE:
6683 case ACTION_HOME_CITY:
6684 case ACTION_HOMELESS:
6686 case ACTION_PARADROP:
6692 case ACTION_ATTACK:
6693 case ACTION_ATTACK2:
6696 case ACTION_WIPE_UNITS:
6704 case ACTION_HEAL_UNIT:
6705 case ACTION_HEAL_UNIT2:
6708 case ACTION_CULTIVATE:
6709 case ACTION_CULTIVATE2:
6710 case ACTION_PLANT:
6711 case ACTION_PLANT2:
6712 case ACTION_PILLAGE:
6713 case ACTION_PILLAGE2:
6714 case ACTION_CLEAN:
6715 case ACTION_CLEAN2:
6716 case ACTION_FORTIFY:
6717 case ACTION_FORTIFY2:
6718 case ACTION_ROAD:
6719 case ACTION_ROAD2:
6720 case ACTION_CONVERT:
6721 case ACTION_BASE:
6722 case ACTION_BASE2:
6723 case ACTION_MINE:
6724 case ACTION_MINE2:
6725 case ACTION_IRRIGATE:
6726 case ACTION_IRRIGATE2:
6743 case ACTION_SPY_ATTACK:
6748 case ACTION_HUT_ENTER:
6749 case ACTION_HUT_ENTER2:
6750 case ACTION_HUT_ENTER3:
6751 case ACTION_HUT_ENTER4:
6756 case ACTION_UNIT_MOVE:
6757 case ACTION_UNIT_MOVE2:
6758 case ACTION_UNIT_MOVE3:
6759 case ACTION_SPY_ESCAPE:
6761 case ACTION_ESCAPE:
6762 case ACTION_CIVIL_WAR:
6763 /* Max range is not ruleset changeable */
6764 return NULL;
6765 case ACTION_HELP_WONDER:
6766 return "help_wonder_max_range";
6768 return "disband_unit_recover_max_range";
6769 case ACTION_BOMBARD:
6770 return "bombard_max_range";
6771 case ACTION_BOMBARD2:
6772 return "bombard_2_max_range";
6773 case ACTION_BOMBARD3:
6774 return "bombard_3_max_range";
6775 case ACTION_BOMBARD4:
6776 return "bombard_4_max_range";
6778 return "bombard_lethal_max_range";
6780 return "bombard_lethal_2_max_range";
6781 case ACTION_NUKE:
6782 return "explode_nuclear_max_range";
6783 case ACTION_NUKE_CITY:
6784 return "nuke_city_max_range";
6785 case ACTION_NUKE_UNITS:
6786 return "nuke_units_max_range";
6787 case ACTION_AIRLIFT:
6788 return "airlift_max_range";
6789 case ACTION_TELEPORT:
6790 return "teleport_max_range";
6791 case ACTION_TELEPORT2:
6792 return "teleport_2_max_range";
6793 case ACTION_TELEPORT3:
6794 return "teleport_3_max_range";
6796 return "teleport_conquer_max_range";
6798 return "teleport_frighten_max_range";
6800 return "teleport_frighten_conquer_max_range";
6802 return "teleport_enter_max_range";
6804 return "teleport_enter_conquer_max_range";
6806 return "user_action_1_max_range";
6808 return "user_action_2_max_range";
6810 return "user_action_3_max_range";
6812 return "user_action_4_max_range";
6813 case ACTION_COUNT:
6814 break;
6815
6817 }
6818
6819 fc_assert(act >= 0 && act < ACTION_COUNT);
6820
6821 return NULL;
6822}
6823
6824/**********************************************************************/
6831{
6832 switch ((enum gen_action)act) {
6833 case ACTION_SPY_POISON:
6858 case ACTION_STEAL_MAPS:
6860 case ACTION_TRADE_ROUTE:
6861 case ACTION_MARKETPLACE:
6862 case ACTION_HELP_WONDER:
6864 case ACTION_EXPEL_UNIT:
6865 case ACTION_FOUND_CITY:
6866 case ACTION_JOIN_CITY:
6867 case ACTION_SPY_NUKE:
6869 case ACTION_NUKE_UNITS:
6873 case ACTION_HOME_CITY:
6874 case ACTION_HOMELESS:
6876 case ACTION_PARADROP:
6882 case ACTION_AIRLIFT:
6883 case ACTION_ATTACK:
6884 case ACTION_ATTACK2:
6887 case ACTION_WIPE_UNITS:
6895 case ACTION_HEAL_UNIT:
6896 case ACTION_HEAL_UNIT2:
6899 case ACTION_CULTIVATE:
6900 case ACTION_CULTIVATE2:
6901 case ACTION_PLANT:
6902 case ACTION_PLANT2:
6903 case ACTION_CLEAN:
6904 case ACTION_CLEAN2:
6905 case ACTION_FORTIFY:
6906 case ACTION_FORTIFY2:
6907 case ACTION_ROAD:
6908 case ACTION_ROAD2:
6909 case ACTION_CONVERT:
6910 case ACTION_BASE:
6911 case ACTION_BASE2:
6912 case ACTION_MINE:
6913 case ACTION_MINE2:
6914 case ACTION_IRRIGATE:
6915 case ACTION_IRRIGATE2:
6932 case ACTION_BOMBARD:
6933 case ACTION_BOMBARD2:
6934 case ACTION_BOMBARD3:
6935 case ACTION_BOMBARD4:
6938 case ACTION_SPY_ATTACK:
6943 case ACTION_HUT_ENTER:
6944 case ACTION_HUT_ENTER2:
6945 case ACTION_HUT_ENTER3:
6946 case ACTION_HUT_ENTER4:
6951 case ACTION_UNIT_MOVE:
6952 case ACTION_UNIT_MOVE2:
6953 case ACTION_UNIT_MOVE3:
6954 case ACTION_TELEPORT:
6955 case ACTION_TELEPORT2:
6956 case ACTION_TELEPORT3:
6962 case ACTION_SPY_ESCAPE:
6964 case ACTION_ESCAPE:
6965 case ACTION_CIVIL_WAR:
6966 /* Target kind is not ruleset changeable */
6967 return NULL;
6968 case ACTION_NUKE:
6969 return "explode_nuclear_target_kind";
6970 case ACTION_NUKE_CITY:
6971 return "nuke_city_target_kind";
6972 case ACTION_PILLAGE:
6973 return "pillage_target_kind";
6974 case ACTION_PILLAGE2:
6975 return "pillage_2_target_kind";
6977 return "user_action_1_target_kind";
6979 return "user_action_2_target_kind";
6981 return "user_action_3_target_kind";
6983 return "user_action_4_target_kind";
6984 case ACTION_COUNT:
6985 break;
6986
6988 }
6989
6990 fc_assert(act >= 0 && act < ACTION_COUNT);
6991
6992 return NULL;
6993}
6994
6995/**********************************************************************/
7003{
7004 switch ((enum gen_action)act) {
7005 case ACTION_SPY_POISON:
7029 case ACTION_STEAL_MAPS:
7031 case ACTION_TRADE_ROUTE:
7032 case ACTION_MARKETPLACE:
7033 case ACTION_HELP_WONDER:
7035 case ACTION_EXPEL_UNIT:
7036 case ACTION_JOIN_CITY:
7037 case ACTION_SPY_NUKE:
7042 case ACTION_HOME_CITY:
7043 case ACTION_HOMELESS:
7045 case ACTION_PARADROP:
7051 case ACTION_AIRLIFT:
7052 case ACTION_ATTACK:
7053 case ACTION_ATTACK2:
7056 case ACTION_WIPE_UNITS:
7064 case ACTION_HEAL_UNIT:
7065 case ACTION_HEAL_UNIT2:
7068 case ACTION_CULTIVATE:
7069 case ACTION_CULTIVATE2:
7070 case ACTION_PLANT:
7071 case ACTION_PLANT2:
7072 case ACTION_PILLAGE:
7073 case ACTION_PILLAGE2:
7074 case ACTION_CLEAN:
7075 case ACTION_CLEAN2:
7076 case ACTION_FORTIFY:
7077 case ACTION_FORTIFY2:
7078 case ACTION_ROAD:
7079 case ACTION_ROAD2:
7080 case ACTION_CONVERT:
7081 case ACTION_BASE:
7082 case ACTION_BASE2:
7083 case ACTION_MINE:
7084 case ACTION_MINE2:
7085 case ACTION_IRRIGATE:
7086 case ACTION_IRRIGATE2:
7103 case ACTION_BOMBARD:
7104 case ACTION_BOMBARD2:
7105 case ACTION_BOMBARD3:
7106 case ACTION_BOMBARD4:
7109 case ACTION_SPY_ATTACK:
7114 case ACTION_HUT_ENTER:
7115 case ACTION_HUT_ENTER2:
7116 case ACTION_HUT_ENTER3:
7117 case ACTION_HUT_ENTER4:
7122 case ACTION_UNIT_MOVE:
7123 case ACTION_UNIT_MOVE2:
7124 case ACTION_UNIT_MOVE3:
7125 case ACTION_TELEPORT:
7126 case ACTION_TELEPORT2:
7127 case ACTION_TELEPORT3:
7133 case ACTION_SPY_ESCAPE:
7135 case ACTION_ESCAPE:
7136 case ACTION_CIVIL_WAR:
7137 /* Actor consuming always is not ruleset changeable */
7138 return NULL;
7139 case ACTION_FOUND_CITY:
7140 return "found_city_consuming_always";
7141 case ACTION_NUKE:
7142 return "explode_nuclear_consuming_always";
7143 case ACTION_NUKE_CITY:
7144 return "nuke_city_consuming_always";
7145 case ACTION_NUKE_UNITS:
7146 return "nuke_units_consuming_always";
7148 return "spread_plague_actor_consuming_always";
7150 return "user_action_1_actor_consuming_always";
7152 return "user_action_2_actor_consuming_always";
7154 return "user_action_3_actor_consuming_always";
7156 return "user_action_4_actor_consuming_always";
7157 case ACTION_COUNT:
7158 break;
7159
7161 }
7162
7163 fc_assert(act >= 0 && act < ACTION_COUNT);
7164
7165 return NULL;
7166}
7167
7168/**********************************************************************/
7175const char *action_blocked_by_ruleset_var_name(const struct action *act)
7176{
7177 fc_assert_ret_val(act != NULL, NULL);
7178
7179 switch ((enum gen_action)action_number(act)) {
7180 case ACTION_MARKETPLACE:
7181 return "enter_marketplace_blocked_by";
7182 case ACTION_BOMBARD:
7183 return "bombard_blocked_by";
7184 case ACTION_BOMBARD2:
7185 return "bombard_2_blocked_by";
7186 case ACTION_BOMBARD3:
7187 return "bombard_3_blocked_by";
7188 case ACTION_BOMBARD4:
7189 return "bombard_4_blocked_by";
7191 return "bombard_lethal_blocked_by";
7193 return "bombard_lethal_2_blocked_by";
7194 case ACTION_NUKE:
7195 return "explode_nuclear_blocked_by";
7196 case ACTION_NUKE_CITY:
7197 return "nuke_city_blocked_by";
7198 case ACTION_NUKE_UNITS:
7199 return "nuke_units_blocked_by";
7200 case ACTION_ATTACK:
7201 return "attack_blocked_by";
7202 case ACTION_ATTACK2:
7203 return "attack_2_blocked_by";
7205 return "suicide_attack_blocked_by";
7207 return "suicide_attack_2_blocked_by";
7208 case ACTION_WIPE_UNITS:
7209 return "wipe_units_blocked_by";
7211 return "collect_ransom_blocked_by";
7213 return "conquer_city_shrink_blocked_by";
7215 return "conquer_city_shrink_2_blocked_by";
7217 return "conquer_city_shrink_3_blocked_by";
7219 return "conquer_city_shrink_4_blocked_by";
7220 case ACTION_UNIT_MOVE:
7221 return "move_blocked_by";
7222 case ACTION_UNIT_MOVE2:
7223 return "move_2_blocked_by";
7224 case ACTION_UNIT_MOVE3:
7225 return "move_3_blocked_by";
7226 case ACTION_TELEPORT:
7227 return "teleport_blocked_by";
7228 case ACTION_TELEPORT2:
7229 return "teleport_2_blocked_by";
7230 case ACTION_TELEPORT3:
7231 return "teleport_3_blocked_by";
7233 return "teleport_conquer_blocked_by";
7235 return "teleport_frighten_blocked_by";
7237 return "teleport_frighten_conquer_blocked_by";
7239 return "teleport_enter_blocked_by";
7241 return "teleport_enter_conquer_blocked_by";
7242 case ACTION_SPY_ESCAPE:
7243 case ACTION_SPY_POISON:
7267 case ACTION_STEAL_MAPS:
7269 case ACTION_TRADE_ROUTE:
7270 case ACTION_HELP_WONDER:
7272 case ACTION_EXPEL_UNIT:
7273 case ACTION_FOUND_CITY:
7274 case ACTION_JOIN_CITY:
7275 case ACTION_SPY_NUKE:
7280 case ACTION_HOME_CITY:
7281 case ACTION_HOMELESS:
7283 case ACTION_PARADROP:
7289 case ACTION_AIRLIFT:
7292 case ACTION_HEAL_UNIT:
7293 case ACTION_HEAL_UNIT2:
7296 case ACTION_CULTIVATE:
7297 case ACTION_CULTIVATE2:
7298 case ACTION_PLANT:
7299 case ACTION_PLANT2:
7300 case ACTION_PILLAGE:
7301 case ACTION_PILLAGE2:
7302 case ACTION_CLEAN:
7303 case ACTION_CLEAN2:
7304 case ACTION_FORTIFY:
7305 case ACTION_FORTIFY2:
7306 case ACTION_ROAD:
7307 case ACTION_ROAD2:
7308 case ACTION_CONVERT:
7309 case ACTION_BASE:
7310 case ACTION_BASE2:
7311 case ACTION_MINE:
7312 case ACTION_MINE2:
7313 case ACTION_IRRIGATE:
7314 case ACTION_IRRIGATE2:
7332 case ACTION_SPY_ATTACK:
7337 case ACTION_HUT_ENTER:
7338 case ACTION_HUT_ENTER2:
7339 case ACTION_HUT_ENTER3:
7340 case ACTION_HUT_ENTER4:
7346 case ACTION_CIVIL_WAR:
7347 case ACTION_ESCAPE:
7352 /* blocked_by is not ruleset changeable */
7353 return NULL;
7354 case ACTION_COUNT:
7356 break;
7357
7359 }
7360
7361 return NULL;
7362}
7363
7364/**********************************************************************/
7368const char *
7370{
7371 fc_assert_ret_val(act != NULL, NULL);
7372
7378 /* No support in the action performer function */
7379 return NULL;
7380 }
7381
7382 switch ((enum gen_action)action_number(act)) {
7384 return "bribe_unit_post_success_forced_actions";
7386 return "bribe_stack_post_success_forced_actions";
7387 case ACTION_ATTACK:
7388 return "attack_post_success_forced_actions";
7389 case ACTION_ATTACK2:
7390 return "attack_2_post_success_forced_actions";
7391 case ACTION_WIPE_UNITS:
7392 return "wipe_units_post_success_forced_actions";
7394 return "collect_ransom_post_success_forced_actions";
7395 case ACTION_MARKETPLACE:
7396 case ACTION_BOMBARD:
7397 case ACTION_BOMBARD2:
7398 case ACTION_BOMBARD3:
7399 case ACTION_BOMBARD4:
7402 case ACTION_NUKE:
7403 case ACTION_NUKE_CITY:
7404 case ACTION_NUKE_UNITS:
7411 case ACTION_SPY_POISON:
7433 case ACTION_STEAL_MAPS:
7435 case ACTION_TRADE_ROUTE:
7436 case ACTION_HELP_WONDER:
7438 case ACTION_EXPEL_UNIT:
7439 case ACTION_FOUND_CITY:
7440 case ACTION_JOIN_CITY:
7441 case ACTION_SPY_NUKE:
7446 case ACTION_HOME_CITY:
7447 case ACTION_HOMELESS:
7449 case ACTION_PARADROP:
7455 case ACTION_AIRLIFT:
7458 case ACTION_HEAL_UNIT:
7459 case ACTION_HEAL_UNIT2:
7462 case ACTION_CULTIVATE:
7463 case ACTION_CULTIVATE2:
7464 case ACTION_PLANT:
7465 case ACTION_PLANT2:
7466 case ACTION_PILLAGE:
7467 case ACTION_PILLAGE2:
7468 case ACTION_CLEAN:
7469 case ACTION_CLEAN2:
7470 case ACTION_FORTIFY:
7471 case ACTION_FORTIFY2:
7472 case ACTION_ROAD:
7473 case ACTION_ROAD2:
7474 case ACTION_CONVERT:
7475 case ACTION_BASE:
7476 case ACTION_BASE2:
7477 case ACTION_MINE:
7478 case ACTION_MINE2:
7479 case ACTION_IRRIGATE:
7480 case ACTION_IRRIGATE2:
7498 case ACTION_SPY_ATTACK:
7503 case ACTION_HUT_ENTER:
7504 case ACTION_HUT_ENTER2:
7505 case ACTION_HUT_ENTER3:
7506 case ACTION_HUT_ENTER4:
7511 case ACTION_UNIT_MOVE:
7512 case ACTION_UNIT_MOVE2:
7513 case ACTION_UNIT_MOVE3:
7514 case ACTION_TELEPORT:
7515 case ACTION_TELEPORT2:
7516 case ACTION_TELEPORT3:
7522 case ACTION_SPY_ESCAPE:
7524 case ACTION_ESCAPE:
7525 case ACTION_CIVIL_WAR:
7530 /* Not ruleset changeable */
7531 return NULL;
7532 case ACTION_COUNT:
7534 break;
7535
7537 }
7538
7539 return NULL;
7540}
7541
7542/**********************************************************************/
7550
7551/**********************************************************************/
7554const char *gen_action_name_update_cb(const char *old_name)
7555{
7556 if (is_ruleset_compat_mode()) {
7557 if (!fc_strcasecmp("Conquer City", old_name)) {
7558 return "Conquer City Shrink";
7559 }
7560 if (!fc_strcasecmp("Conquer City 2", old_name)) {
7561 return "Conquer City Shrink 2";
7562 }
7563 if (!fc_strcasecmp("Conquer City 3", old_name)) {
7564 return "Conquer City Shrink 3";
7565 }
7566 if (!fc_strcasecmp("Conquer City 4", old_name)) {
7567 return "Conquer City Shrink 4";
7568 }
7569 }
7570
7571 return old_name;
7572}
7573
7575{
7576 N_("individual cities"), /* ATK_CITY */
7577 N_("individual units"), /* ATK_UNIT */
7578 N_("unit stacks"), /* ATK_STACK */
7579 N_("tiles"), /* ATK_TILE */
7580 N_("tile extras"), /* ATK_EXTRAS */
7581 N_("itself") /* ATK_SELF */
7582};
7583
7584/**********************************************************************/
7589{
7590 fc_assert(kind >= 0 && kind < ATK_COUNT);
7591
7592 return _(atk_helpnames[kind]);
7593}
7594
7595/************************************************************************/
7599{
7600 fc_assert(result < ACTRES_LAST);
7601
7602 return actlist_by_result[result];
7603}
7604
7605/************************************************************************/
7609{
7610 fc_assert(activity < ACTIVITY_LAST);
7611
7612 return actlist_by_activity[activity];
7613}
bool is_action_possible_on_city(action_id act_id, const struct player *actor_player, const struct city *target_city)
Definition actions.c:5479
static struct action * actions[MAX_NUM_ACTIONS]
Definition actions.c:56
const char * action_prepare_ui_name(action_id act_id, const char *mnemonic, const struct act_prob prob, const char *custom)
Definition actions.c:1312
bool action_distance_inside_max(const struct action *action, const int distance)
Definition actions.c:1173
struct act_prob action_speculate_unit_on_extras(const struct civ_map *nmap, action_id act_id, const struct unit *actor, const struct city *actor_home, const struct tile *actor_tile, bool omniscient_cheat, const struct tile *target_tile, const struct extra_type *target_extra)
Definition actions.c:4967
static enum fc_tristate is_action_possible(const struct civ_map *nmap, const action_id wanted_action, const struct req_context *actor, const struct req_context *target, const struct extra_type *target_extra, const bool omniscient, const struct city *homecity)
Definition actions.c:2791
const char * action_prob_explain(const struct act_prob prob)
Definition actions.c:1423
bool action_mp_full_makes_legal(const struct unit *actor, const action_id act_id)
Definition actions.c:5557
static struct act_prob action_prob_battle_then_dice_roll(const struct player *act_player, const struct unit *act_unit, const struct city *tgt_city, const struct unit *tgt_unit, const struct tile *tgt_tile, const struct player *tgt_player, const struct action *paction)
Definition actions.c:3785
static bool is_action_enabled_unit_on_self_full(const struct civ_map *nmap, const action_id wanted_action, const struct unit *actor_unit, const struct city *actor_home, const struct tile *actor_tile)
Definition actions.c:3417
enum action_actor_kind action_get_actor_kind(const struct action *paction)
Definition actions.c:1098
bool action_prob_certain(const struct act_prob probability)
Definition actions.c:5089
const char * action_id_name_translation(action_id act_id)
Definition actions.c:1250
struct action_auto_perf * action_auto_perf_slot_number(const int num)
Definition actions.c:5718
req_vec_num_in_item action_enabler_vector_number(const void *enabler, const struct requirement_vector *vec)
Definition actions.c:2027
bool action_has_complex_target(const struct action *paction)
Definition actions.c:1132
static bool action_actor_utype_hard_reqs_ok_full(const struct action *paction, const struct unit_type *actor_unittype, bool ignore_third_party)
Definition actions.c:2376
struct req_vec_problem * action_enabler_suggest_repair(const struct action_enabler *enabler)
Definition actions.c:1897
static bool is_action_enabled_unit_on_tile_full(const struct civ_map *nmap, const action_id wanted_action, const struct unit *actor_unit, const struct city *actor_home, const struct tile *actor_tile, const struct tile *target_tile, const struct extra_type *target_extra)
Definition actions.c:3262
bool action_prob_possible(const struct act_prob probability)
Definition actions.c:5079
#define ACTPROB_VAL_NOT_IMPL
Definition actions.c:54
struct action_auto_perf auto_perfs[MAX_NUM_ACTION_AUTO_PERFORMERS]
Definition actions.c:58
bool action_actor_utype_hard_reqs_ok(const struct action *paction, const struct unit_type *actor_unittype)
Definition actions.c:2584
struct act_prob action_prob_new_not_impl(void)
Definition actions.c:5058
struct req_vec_problem * action_enabler_suggest_improvement(const struct action_enabler *enabler)
Definition actions.c:1963
static enum fc_tristate action_enabled_local(const action_id wanted_action, const struct req_context *actor, const struct req_context *target)
Definition actions.c:3512
struct act_prob action_speculate_unit_on_stack(const struct civ_map *nmap, action_id act_id, const struct unit *actor, const struct city *actor_home, const struct tile *actor_tile, bool omniscient_cheat, const struct tile *target)
Definition actions.c:4900
void actions_rs_pre_san_gen(void)
Definition actions.c:889
const char * action_min_range_ruleset_var_name(int act)
Definition actions.c:6465
struct act_prob action_speculate_unit_on_self(const struct civ_map *nmap, action_id act_id, const struct unit *actor, const struct city *actor_home, const struct tile *actor_tile, bool omniscient_cheat)
Definition actions.c:5001
static bool is_effect_val_known(enum effect_type effect_type, const struct player *pov_player, const struct req_context *context, const struct req_context *other_context)
Definition actions.c:3559
const char * action_blocked_by_ruleset_var_name(const struct action *act)
Definition actions.c:7175
static bool is_action_enabled(const struct civ_map *nmap, const action_id wanted_action, const struct req_context *actor, const struct req_context *target, const struct extra_type *target_extra, const struct city *actor_home)
Definition actions.c:2964
#define ACTPROB_VAL_MAX
Definition actions.c:48
static struct act_prob action_prob(const struct civ_map *nmap, const action_id wanted_action, const struct req_context *actor, const struct city *actor_home, const struct req_context *target, const struct extra_type *target_extra)
Definition actions.c:3833
struct req_vec_problem * action_enabler_suggest_repair_oblig(const struct action_enabler *enabler)
Definition actions.c:1683
void action_array_add_all_by_result(action_id *act_array, int *position, enum action_result result)
Definition actions.c:5783
const char * action_name_translation(const struct action *paction)
Definition actions.c:1230
int action_dice_roll_odds(const struct player *act_player, const struct unit *act_unit, const struct city *tgt_city, const struct player *tgt_player, const struct action *paction)
Definition actions.c:5379
void action_array_end(action_id *act_array, int size)
Definition actions.c:5766
struct act_prob action_prob_vs_tile(const struct civ_map *nmap, const struct unit *actor_unit, const action_id act_id, const struct tile *target_tile, const struct extra_type *target_extra)
Definition actions.c:4600
static struct act_prob action_prob_pre_action_dice_roll(const struct player *act_player, const struct unit *act_unit, const struct city *tgt_city, const struct player *tgt_player, const struct action *paction)
Definition actions.c:3737
const char * atk_helpnames[ATK_COUNT]
Definition actions.c:7574
static enum fc_tristate action_hard_reqs_actor(const struct civ_map *nmap, const struct action *paction, const struct req_context *actor, const bool omniscient, const struct city *homecity)
Definition actions.c:2604
static void hard_code_actions(void)
Definition actions.c:106
static bool is_action_enabled_unit_on_city_full(const struct civ_map *nmap, const action_id wanted_action, const struct unit *actor_unit, const struct city *actor_home, const struct tile *actor_tile, const struct city *target_city)
Definition actions.c:3014
bool action_is_in_use(struct action *paction)
Definition actions.c:5672
static struct req_vec_problem * enabler_tile_tgt_local_diplrel_implies_claimed(const struct action_enabler *enabler)
Definition actions.c:1752
bool action_ever_possible(action_id action)
Definition actions.c:7546
const char * action_enabler_vector_by_number_name(req_vec_num_in_item vec)
Definition actions.c:2074
bool are_action_probabilitys_equal(const struct act_prob *ap1, const struct act_prob *ap2)
Definition actions.c:5130
static struct act_prob action_prob_self_full(const struct civ_map *nmap, const struct unit *actor_unit, const struct city *actor_home, const struct tile *actor_tile, const action_id act_id)
Definition actions.c:4700
const char * action_post_success_forced_ruleset_var_name(const struct action *act)
Definition actions.c:7369
struct action * action_by_rule_name(const char *name)
Definition actions.c:1079
static bool action_has_possible_actor_hard_reqs(struct action *paction)
Definition actions.c:5642
static struct action * action_new(action_id id, enum action_actor_kind aak, enum action_result result, const int min_distance, const int max_distance, bool actor_consuming_always)
Definition actions.c:965
const char * action_rule_name(const struct action *action)
Definition actions.c:1216
const char * action_id_rule_name(action_id act_id)
Definition actions.c:1239
enum action_sub_target_kind action_get_sub_target_kind(const struct action *paction)
Definition actions.c:1119
static const struct tile * blocked_find_target_tile(const struct action *act, const struct unit *actor_unit, const struct tile *target_tile_arg, const struct city *target_city, const struct unit *target_unit)
Definition actions.c:2142
static bool action_prob_not_relevant(const struct act_prob probability)
Definition actions.c:5100
static struct act_prob ap_diplomat_battle(const struct unit *pattacker, const struct unit *pvictim, const struct tile *tgt_tile, const struct action *paction) fc__attribute((nonnull(3)))
Definition actions.c:3691
void actions_free(void)
Definition actions.c:899
static bool is_action_enabled_unit_on_extras_full(const struct civ_map *nmap, const action_id wanted_action, const struct unit *actor_unit, const struct city *actor_home, const struct tile *actor_tile, const struct tile *target_tile, const struct extra_type *target_extra)
Definition actions.c:3339
void action_enabler_free(struct action_enabler *enabler)
Definition actions.c:1495
bool is_action_enabled_unit_on_stack(const struct civ_map *nmap, const action_id wanted_action, const struct unit *actor_unit, const struct tile *target_tile)
Definition actions.c:3244
static enum fc_tristate tech_can_be_stolen(const struct player *actor_player, const struct player *target_player)
Definition actions.c:3578
static struct action_list * actlist_by_result[ACTRES_LAST]
Definition actions.c:99
struct action_list * action_list_by_activity(enum unit_activity activity)
Definition actions.c:7608
int action_number(const struct action *action)
Definition actions.c:1208
struct act_prob action_prob_new_unknown(void)
Definition actions.c:5068
bool action_would_be_blocked_by(const struct action *blocked, const struct action *blocker)
Definition actions.c:1196
#define ACTPROB_VAL_NA
Definition actions.c:52
static struct action * player_action_new(action_id id, enum action_result result)
Definition actions.c:1056
static struct req_vec_problem * enabler_first_clarification(const struct action_enabler *enabler)
Definition actions.c:1945
static bool action_prob_not_impl(const struct act_prob probability)
Definition actions.c:5111
bool is_action_enabled_unit_on_tile(const struct civ_map *nmap, const action_id wanted_action, const struct unit *actor_unit, const struct tile *target_tile, const struct extra_type *target_extra)
Definition actions.c:3320
struct act_prob action_prob_and(const struct act_prob *ap1, const struct act_prob *ap2)
Definition actions.c:5217
static bool actions_initialized
Definition actions.c:59
const char * action_actor_consuming_always_ruleset_var_name(action_id act)
Definition actions.c:7002
bool action_immune_government(struct government *gov, action_id act)
Definition actions.c:5435
static bool is_target_possible(const action_id wanted_action, const struct player *actor_player, const struct req_context *target)
Definition actions.c:5458
static struct act_prob ap_dipl_battle_win(const struct unit *pattacker, const struct unit *pdefender)
Definition actions.c:3614
static struct act_prob action_prob_vs_stack_full(const struct civ_map *nmap, const struct unit *actor_unit, const struct city *actor_home, const struct tile *actor_tile, const action_id act_id, const struct tile *target_tile)
Definition actions.c:4342
struct act_prob action_prob_vs_extras(const struct civ_map *nmap, const struct unit *actor_unit, const action_id act_id, const struct tile *target_tile, const struct extra_type *target_extra)
Definition actions.c:4683
struct act_prob action_prob_new_certain(void)
Definition actions.c:5038
const char * action_max_range_ruleset_var_name(int act)
Definition actions.c:6643
static struct act_prob action_prob_vs_city_full(const struct civ_map *nmap, const struct unit *actor_unit, const struct city *actor_home, const struct tile *actor_tile, const action_id act_id, const struct city *target_city)
Definition actions.c:4155
bool action_is_internal(struct action *paction)
Definition actions.c:5698
int action_dice_roll_initial_odds(const struct action *paction)
Definition actions.c:5355
struct act_prob action_prob_self(const struct civ_map *nmap, const struct unit *actor_unit, const action_id act_id)
Definition actions.c:4753
struct act_prob action_prob_fall_back(const struct act_prob *ap1, const struct act_prob *ap2)
Definition actions.c:5287
static const struct unit_type * tgt_city_local_utype(const struct city *target_city)
Definition actions.c:2117
static struct requirement * req_vec_first_local_diplrel(const struct requirement_vector *vec)
Definition actions.c:1733
static struct act_prob action_prob_vs_tile_full(const struct civ_map *nmap, const struct unit *actor_unit, const struct city *actor_home, const struct tile *actor_tile, const action_id act_id, const struct tile *target_tile, const struct extra_type *target_extra)
Definition actions.c:4534
bool is_action_enabled_unit_on_city(const struct civ_map *nmap, const action_id wanted_action, const struct unit *actor_unit, const struct city *target_city)
Definition actions.c:3079
struct action_list * action_list_by_result(enum action_result result)
Definition actions.c:7598
bool action_univs_not_blocking(const struct action *paction, struct universal *actor_uni, struct universal *target_uni)
Definition actions.c:5742
struct act_prob action_speculate_unit_on_city(const struct civ_map *nmap, const action_id act_id, const struct unit *actor, const struct city *actor_home, const struct tile *actor_tile, const bool omniscient_cheat, const struct city *target)
Definition actions.c:4832
bool actions_are_ready(void)
Definition actions.c:941
bool is_action_enabled_unit_on_unit(const struct civ_map *nmap, const action_id wanted_action, const struct unit *actor_unit, const struct unit *target_unit)
Definition actions.c:3156
struct act_prob action_speculate_unit_on_tile(const struct civ_map *nmap, action_id act_id, const struct unit *actor, const struct city *actor_home, const struct tile *actor_tile, bool omniscient_cheat, const struct tile *target_tile, const struct extra_type *target_extra)
Definition actions.c:4933
struct act_prob action_prob_vs_city(const struct civ_map *nmap, const struct unit *actor_unit, const action_id act_id, const struct city *target_city)
Definition actions.c:4242
const char * action_target_kind_ruleset_var_name(int act)
Definition actions.c:6830
static struct act_prob action_prob_vs_unit_full(const struct civ_map *nmap, const struct unit *actor_unit, const struct city *actor_home, const struct tile *actor_tile, const action_id act_id, const struct unit *target_unit)
Definition actions.c:4258
bool action_maybe_possible_actor_unit(const struct civ_map *nmap, const action_id act_id, const struct unit *actor_unit)
Definition actions.c:5502
struct action * action_is_blocked_by(const struct civ_map *nmap, const struct action *act, const struct unit *actor_unit, const struct tile *target_tile_arg, const struct city *target_city_arg, const struct unit *target_unit)
Definition actions.c:2261
static bool is_enabler_active(const struct action_enabler *enabler, const struct req_context *actor, const struct req_context *target)
Definition actions.c:2947
static struct action_enabler_list * action_enablers_by_action[MAX_NUM_ACTIONS]
Definition actions.c:61
void action_enabler_add(struct action_enabler *enabler)
Definition actions.c:1526
const char * action_ui_name_default(int act)
Definition actions.c:6101
bool action_enablers_allow(const action_id wanted_action, const struct req_context *actor, const struct req_context *target)
Definition actions.c:2993
#define ACTPROB_VAL_1_PCT
Definition actions.c:50
bool action_enabler_utype_possible_actor(const struct action_enabler *ae, const struct unit_type *act_utype)
Definition actions.c:5580
static struct act_prob act_prob_unseen_target(const struct civ_map *nmap, action_id act_id, const struct unit *actor_unit)
Definition actions.c:3719
struct action_enabler * action_enabler_new(void)
Definition actions.c:1475
bool action_requires_details(const struct action *paction)
Definition actions.c:1145
struct act_prob action_prob_new_not_relevant(void)
Definition actions.c:5048
const char * action_target_kind_help(enum action_target_kind kind)
Definition actions.c:7588
static struct req_vec_problem * enabler_first_self_contradiction(const struct action_enabler *enabler)
Definition actions.c:1825
int action_get_role(const struct action *paction)
Definition actions.c:1463
struct act_prob action_speculate_unit_on_unit(const struct civ_map *nmap, action_id act_id, const struct unit *actor, const struct city *actor_home, const struct tile *actor_tile, bool omniscient_cheat, const struct unit *target)
Definition actions.c:4867
static struct action * unit_action_new(action_id id, enum action_result result, bool rare_pop_up, bool unitwaittime_controlled, enum moves_actor_kind moves_actor, const int min_distance, const int max_distance, bool actor_consuming_always)
Definition actions.c:1030
const struct action_auto_perf * action_auto_perf_by_number(const int num)
Definition actions.c:5734
struct act_prob action_prob_new_impossible(void)
Definition actions.c:5028
bool action_enabler_possible_actor(const struct action_enabler *ae)
Definition actions.c:5607
static const struct city * blocked_find_target_city(const struct action *act, const struct unit *actor_unit, const struct tile *target_tile, const struct city *target_city_arg, const struct unit *target_unit)
Definition actions.c:2202
struct action ** _actions
Definition actions.c:57
bool action_id_exists(const action_id act_id)
Definition actions.c:1068
bool action_enabler_remove(struct action_enabler *enabler)
Definition actions.c:1543
enum action_target_kind action_get_target_kind(const struct action *paction)
Definition actions.c:1108
struct act_prob action_prob_unit_vs_tgt(const struct civ_map *nmap, const struct action *paction, const struct unit *act_unit, const struct city *tgt_city, const struct unit *tgt_unit, const struct tile *tgt_tile, const struct extra_type *extra_tgt)
Definition actions.c:4775
static bool action_prob_is_signal(const struct act_prob probability)
Definition actions.c:5122
struct action_enabler * action_enabler_copy(const struct action_enabler *original)
Definition actions.c:1511
static const char * action_prob_to_text(const struct act_prob prob)
Definition actions.c:1271
int action_prob_cmp_pessimist(const struct act_prob ap1, const struct act_prob ap2)
Definition actions.c:5139
struct act_prob action_prob_vs_stack(const struct civ_map *nmap, const struct unit *actor_unit, const action_id act_id, const struct tile *target_tile)
Definition actions.c:4517
bool action_id_is_internal(action_id act)
Definition actions.c:5710
bool is_action_enabled_unit_on_self(const struct civ_map *nmap, const action_id wanted_action, const struct unit *actor_unit)
Definition actions.c:3469
bool action_id_is_rare_pop_up(action_id act_id)
Definition actions.c:1160
void actions_init(void)
Definition actions.c:840
static struct req_vec_problem * ae_suggest_repair_if_no_oblig(const struct action_enabler *enabler, const struct obligatory_req_vector *oblig)
Definition actions.c:1579
struct act_prob action_prob_vs_unit(const struct civ_map *nmap, const struct unit *actor_unit, const action_id act_id, const struct unit *target_unit)
Definition actions.c:4325
bool is_action_enabled_player(const struct civ_map *nmap, const action_id wanted_action, const struct player *actor_plr)
Definition actions.c:3482
static const struct impr_type * tgt_city_local_building(const struct city *target_city)
Definition actions.c:2094
static struct astring ui_name_str
Definition actions.c:63
bool is_action_enabled_unit_on_extras(const struct civ_map *nmap, const action_id wanted_action, const struct unit *actor_unit, const struct tile *target_tile, const struct extra_type *target_extra)
Definition actions.c:3397
static bool is_action_enabled_unit_on_unit_full(const struct civ_map *nmap, const action_id wanted_action, const struct unit *actor_unit, const struct city *actor_home, const struct tile *actor_tile, const struct unit *target_unit)
Definition actions.c:3097
static bool is_action_enabled_unit_on_stack_full(const struct civ_map *nmap, const action_id wanted_action, const struct unit *actor_unit, const struct city *actor_home, const struct tile *actor_tile, const struct tile *target_tile)
Definition actions.c:3174
double action_prob_to_0_to_1_pessimist(const struct act_prob ap)
Definition actions.c:5190
const char * gen_action_name_update_cb(const char *old_name)
Definition actions.c:7554
static struct action_list * actlist_by_activity[ACTIVITY_LAST]
Definition actions.c:100
struct action_enabler_list * action_enablers_for_action(action_id action)
Definition actions.c:1559
struct requirement_vector * action_enabler_vector_by_number(const void *enabler, req_vec_num_in_item number)
Definition actions.c:2050
bool action_distance_accepted(const struct action *action, const int distance)
Definition actions.c:1184
static struct act_prob action_prob_vs_extras_full(const struct civ_map *nmap, const struct unit *actor_unit, const struct city *actor_home, const struct tile *actor_tile, const action_id act_id, const struct tile *target_tile, const struct extra_type *target_extra)
Definition actions.c:4617
const char * action_ui_name_ruleset_var_name(int act)
Definition actions.c:5803
const char * action_get_ui_name_mnemonic(action_id act_id, const char *mnemonic)
Definition actions.c:1258
#define ACTPROB_VAL_MIN
Definition actions.c:46
#define action_noninternal_iterate_end
Definition actions.h:240
#define ACTION_DISTANCE_MAX
Definition actions.h:107
#define enabler_get_action(_enabler_)
Definition actions.h:186
#define ASSERT_UNUSED_ACTION_CASES
Definition actions.h:38
#define ACTPROB_CERTAIN
Definition actions.h:692
#define enabler_get_action_id(_enabler_)
Definition actions.h:187
#define ACTPROB_NA
Definition actions.h:693
static struct action * action_by_number(action_id act_id)
Definition actions.h:400
#define action_enabler_list_re_iterate_end
Definition actions.h:200
#define ACTION_DISTANCE_LAST_NON_SIGNAL
Definition actions.h:103
#define action_enabler_list_re_iterate(action_enabler_list, aenabler)
Definition actions.h:196
#define action_has_result(_act_, _res_)
Definition actions.h:184
#define action_enabler_list_iterate_end
Definition actions.h:194
#define ACTION_DISTANCE_UNLIMITED
Definition actions.h:105
#define action_iterate_end
Definition actions.h:218
#define MAX_NUM_ACTIONS
Definition actions.h:62
#define action_iterate_all(_act_)
Definition actions.h:204
#define action_id_get_actor_kind(act_id)
Definition actions.h:413
#define action_iterate_all_end
Definition actions.h:209
#define ACTPROB_NOT_KNOWN
Definition actions.h:695
#define action_enabler_list_iterate(action_enabler_list, aenabler)
Definition actions.h:192
#define action_id_distance_accepted(act_id, distance)
Definition actions.h:449
#define ACTPROB_IMPOSSIBLE
Definition actions.h:691
#define ACTPROB_NOT_IMPLEMENTED
Definition actions.h:694
#define action_iterate(_act_)
Definition actions.h:214
#define ACTION_ANY
Definition actions.h:56
#define action_noninternal_iterate(_act_)
Definition actions.h:235
#define action_id_get_target_kind(act_id)
Definition actions.h:417
#define action_id_has_result_safe(act_id, result)
Definition actions.h:430
#define ACTION_ODDS_PCT_DICE_ROLL_NA
Definition actions.h:698
#define ACTION_NONE
Definition actions.h:59
enum action_sub_target_kind actres_sub_target_kind_default(enum action_result result)
Definition actres.c:672
enum act_tgt_compl actres_target_compl_calc(enum action_result result)
Definition actres.c:258
enum fc_tristate actres_possible(const struct civ_map *nmap, enum action_result result, const struct req_context *actor, const struct req_context *target, const struct extra_type *target_extra, enum fc_tristate def, bool omniscient, const struct city *homecity)
Definition actres.c:835
enum unit_activity actres_activity_result(enum action_result result)
Definition actres.c:301
enum dice_roll_type actres_dice_type(enum action_result result)
Definition actres.c:364
enum action_battle_kind actres_get_battle_kind(enum action_result result)
Definition actres.c:272
enum action_target_kind actres_target_kind_default(enum action_result result)
Definition actres.c:770
#define ASSERT_UNUSED_ACTRES_CASES
Definition actres.h:37
@ DRT_DIPLCHANCE
Definition actres.h:107
@ DRT_CERTAIN
Definition actres.h:107
@ DRT_NONE
Definition actres.h:107
void astr_free(struct astring *astr)
Definition astring.c:148
void astr_set(struct astring *astr, const char *format,...)
Definition astring.c:251
void astr_clear(struct astring *astr)
Definition astring.c:201
void astr_add(struct astring *astr, const char *format,...)
Definition astring.c:271
static const char * astr_str(const struct astring *astr) fc__attribute((nonnull(1)))
Definition astring.h:93
#define ASTRING_INIT
Definition astring.h:44
bool territory_claiming_base(const struct base_type *pbase)
Definition base.c:162
#define BV_CLR_ALL(bv)
Definition bitvector.h:103
#define BV_ISSET(bv, bit)
Definition bitvector.h:86
static bool is_non_attack_city_tile(const struct tile *ptile, const struct player *pplayer)
Definition city.h:755
#define city_tile(_pcity_)
Definition city.h:561
#define city_owner(_pcity_)
Definition city.h:560
double unit_win_chance(const struct civ_map *nmap, const struct unit *attacker, const struct unit *defender, const struct action *paction)
Definition combat.c:480
enum unit_attack_result unit_attack_units_at_tile_result(const struct unit *punit, const struct action *paction, const struct tile *ptile)
Definition combat.c:257
struct unit * get_defender(const struct civ_map *nmap, const struct unit *attacker, const struct tile *ptile, const struct action *paction)
Definition combat.c:841
struct unit * get_diplomatic_defender(const struct unit *act_unit, const struct unit *pvictim, const struct tile *tgt_tile, const struct action *paction)
Definition combat.c:947
bool can_unit_attack_tile(const struct unit *punit, const struct action *paction, const struct tile *dest_tile)
Definition combat.c:312
@ ATT_OK
Definition combat.h:35
char * enablers
Definition comments.c:57
char * incite_cost
Definition comments.c:76
struct unit struct city struct unit * target_unit
Definition dialogs_g.h:56
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit * actor
Definition dialogs_g.h:73
struct unit * actor_unit
Definition dialogs_g.h:55
struct unit struct city struct unit struct tile * target_tile
Definition dialogs_g.h:57
struct unit struct city * target_city
Definition dialogs_g.h:56
struct unit struct city struct unit struct tile struct extra_type * target_extra
Definition dialogs_g.h:57
int int id
Definition editgui_g.h:28
struct @22::@23 reqs
int get_target_bonus_effects(struct effect_list *plist, const struct req_context *context, const struct req_context *other_context, enum effect_type effect_type)
Definition effects.c:744
struct effect_list * get_effects(enum effect_type effect_type)
Definition effects.c:143
#define effect_list_iterate_end
Definition effects.h:81
#define effect_list_iterate(effect_list, peffect)
Definition effects.h:79
struct extra_type_list * extra_type_list_of_terr_claimers(void)
Definition extras.c:275
bool is_native_extra_to_uclass(const struct extra_type *pextra, const struct unit_class *pclass)
Definition extras.c:857
#define extra_type_list_iterate(extralist, pextra)
Definition extras.h:165
#define extra_type_list_iterate_end
Definition extras.h:167
const struct functions * fc_funcs
int Tech_type_id
Definition fc_types.h:237
@ RPT_CERTAIN
Definition fc_types.h:534
@ RPT_POSSIBLE
Definition fc_types.h:533
int action_id
Definition fc_types.h:249
#define ACTRES_NONE
Definition fc_types.h:187
#define MAX_NUM_ACTION_AUTO_PERFORMERS
Definition fc_types.h:54
#define _(String)
Definition fcintl.h:67
#define N_(String)
Definition fcintl.h:69
struct civ_game game
Definition game.c:61
static bool is_ruleset_compat_mode(void)
Definition game.h:370
const char * name
Definition inputfile.c:127
#define fc_assert_msg(condition, message,...)
Definition log.h:182
#define fc_assert_ret(condition)
Definition log.h:192
#define log_verbose(message,...)
Definition log.h:110
#define fc_assert(condition)
Definition log.h:177
#define fc_assert_action_msg(condition, action, message,...)
Definition log.h:202
#define fc_assert_ret_val(condition, val)
Definition log.h:195
#define fc_assert_action(condition, action)
Definition log.h:188
#define log_error(message,...)
Definition log.h:104
#define FC_STATIC_ASSERT(cond, tag)
Definition log.h:238
#define fc_assert_ret_val_msg(condition, val, message,...)
Definition log.h:209
int real_map_distance(const struct tile *tile0, const struct tile *tile1)
Definition map.c:675
#define MAP_DISTANCE_MAX
Definition map.h:674
#define FC_FREE(ptr)
Definition mem.h:41
#define fc_malloc(sz)
Definition mem.h:34
bool can_see_techs_of_target(const struct player *pow_player, const struct player *target_player)
enum fc_tristate mke_eval_reqs(const struct player *pov_player, const struct req_context *context, const struct req_context *other_context, const struct requirement_vector *reqs, const enum req_problem_type prob_type)
bool can_unit_exist_at_tile(const struct civ_map *nmap, const struct unit *punit, const struct tile *ptile)
Definition movement.c:350
bool is_native_tile(const struct unit_type *punittype, const struct tile *ptile)
Definition movement.c:362
int unit_move_rate(const struct unit *punit)
Definition movement.c:89
bool unit_could_load_at(const struct unit *punit, const struct tile *ptile)
Definition movement.c:962
bool can_unit_type_transport(const struct unit_type *transporter, const struct unit_class *transported)
Definition movement.c:919
bool can_attack_non_native(const struct unit_type *utype)
Definition movement.c:213
void oblig_hard_reqs_init(void)
Definition oblig_reqs.c:809
void oblig_hard_reqs_free(void)
Definition oblig_reqs.c:829
void hard_code_oblig_hard_reqs_ruleset(void)
Definition oblig_reqs.c:772
void hard_code_oblig_hard_reqs(void)
Definition oblig_reqs.c:252
struct obligatory_req_vector * oblig_hard_reqs_get(enum action_result res)
Definition oblig_reqs.c:854
struct obligatory_req_vector * oblig_hard_reqs_get_sub(enum action_sub_result res)
Definition oblig_reqs.c:865
#define obligatory_req_vector_iterate_end
Definition oblig_reqs.h:48
#define obligatory_req_vector_iterate(obreq_vec, pobreq)
Definition oblig_reqs.h:46
bool can_player_see_tile(const struct player *plr, const struct tile *ptile)
Definition player.c:1091
bool can_player_see_unit(const struct player *pplayer, const struct unit *punit)
Definition player.c:1104
bool pplayers_at_war(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1388
bool player_can_see_city_externals(const struct player *pow_player, const struct city *target_city)
Definition player.c:1164
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1409
bool can_player_see_hypotetic_units_at(const struct player *pplayer, const struct tile *ptile)
Definition player.c:993
bool player_can_trust_tile_has_no_units(const struct player *pplayer, const struct tile *ptile)
Definition player.c:967
bool universal_never_there(const struct universal *source)
const struct req_context * req_context_empty(void)
const char * req_to_fstring(const struct requirement *req, struct astring *astr)
bool universal_fulfills_requirements(bool check_necessary, const struct requirement_vector *reqs, const struct universal *source)
struct req_vec_problem * req_vec_suggest_repair(const struct requirement_vector *vec, requirement_vector_number get_num, const void *parent_item)
struct req_vec_problem * req_vec_problem_new(int num_suggested_solutions, const char *descr,...)
bool are_reqs_active(const struct req_context *context, const struct req_context *other_context, const struct requirement_vector *reqs, const enum req_problem_type prob_type)
struct requirement * req_vec_first_contradiction_in_vec(const struct requirement *req, const struct requirement_vector *vec)
bool does_req_contradicts_reqs(const struct requirement *req, const struct requirement_vector *vec)
bool req_vec_is_impossible_to_fulfill(const struct requirement_vector *reqs)
struct req_vec_problem * req_vec_suggest_improvement(const struct requirement_vector *vec, requirement_vector_number get_num, const void *parent_item)
#define requirement_fulfilled_by_unit_type(_ut_, _rqs_)
signed char req_vec_num_in_item
req_vec_num_in_item a requirement vectors number in an item.
#define requirement_vector_iterate_end
#define requirement_fulfilled_by_government(_gov_, _rqs_)
#define requirement_vector_iterate(req_vec, preq)
struct research * research_get(const struct player *pplayer)
Definition research.c:128
enum tech_state research_invention_state(const struct research *presearch, Tech_type_id tech)
Definition research.c:619
bool research_invention_gettable(const struct research *presearch, const Tech_type_id tech, bool allow_holes)
Definition research.c:693
server_setting_id server_setting_by_name(const char *name)
int server_setting_value_int_get(server_setting_id id)
enum fc_tristate fc_tristate_and(enum fc_tristate one, enum fc_tristate two)
Definition shared.c:127
fc_tristate
Definition shared.h:46
@ TRI_YES
Definition shared.h:46
@ TRI_NO
Definition shared.h:46
@ TRI_MAYBE
Definition shared.h:46
#define CLIP(lower, current, upper)
Definition shared.h:57
#define MIN(x, y)
Definition shared.h:55
#define MAX(x, y)
Definition shared.h:54
size_t size
Definition specvec.h:72
int max
Definition fc_types.h:949
int min
Definition fc_types.h:948
enum action_auto_perf_cause cause
Definition actions.h:327
action_id alternatives[MAX_NUM_ACTIONS]
Definition actions.h:335
action_id action
Definition actions.h:171
struct requirement_vector actor_reqs
Definition actions.h:172
struct requirement_vector target_reqs
Definition actions.h:173
bool unitwaittime_controlled
Definition actions.h:160
action_id id
Definition actions.h:111
bool actor_consuming_always
Definition actions.h:144
bool rare_pop_up
Definition actions.h:157
int max_distance
Definition actions.h:127
bool quiet
Definition actions.h:134
enum action_sub_target_kind sub_target_kind
Definition actions.h:119
enum moves_actor_kind moves_actor
Definition actions.h:164
struct action::@12::@13 is_unit
enum action_result result
Definition actions.h:114
char ui_name[MAX_LEN_NAME]
Definition actions.h:130
bv_action_sub_results sub_results
Definition actions.h:115
enum action_actor_kind actor_kind
Definition actions.h:117
enum act_tgt_compl target_complexity
Definition actions.h:122
bv_actions blocked_by
Definition actions.h:138
bool configured
Definition actions.h:112
union action::@12 actor
enum action_target_kind target_kind
Definition actions.h:118
int min_distance
Definition actions.h:127
Definition city.h:317
int id
Definition city.h:323
struct tile * tile
Definition city.h:319
struct packet_game_info info
Definition game.h:89
int(* player_tile_city_id_get)(const struct tile *ptile, const struct player *pplayer)
bool tech_steal_allow_holes
enum airlifting_style airlifting_style
bool airlift_from_always_enabled
bv_actions diplchance_initial_odds
const struct tile * tile
const struct player * player
const struct unit * unit
const struct city * city
Definition tile.h:50
struct unit_list * units
Definition tile.h:58
struct veteran_system * veteran
Definition unittype.h:549
Definition unit.h:140
int moves_left
Definition unit.h:152
struct tile * tile
Definition unit.h:142
bool paradropped
Definition unit.h:177
const struct unit_type * utype
Definition unit.h:141
enum universals_n kind
Definition fc_types.h:609
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:186
#define fc__attribute(x)
Definition support.h:99
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
#define fc__fallthrough
Definition support.h:119
Tech_type_id advance_number(const struct advance *padvance)
Definition tech.c:98
#define advance_iterate(_p)
Definition tech.h:271
#define advance_iterate_end
Definition tech.h:272
bool tile_is_seen(const struct tile *target_tile, const struct player *pow_player)
Definition tile.c:407
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
#define tile_owner(_tile)
Definition tile.h:97
struct unit * unit_transport_get(const struct unit *pcargo)
Definition unit.c:2544
bool unit_can_do_action(const struct unit *punit, const action_id act_id)
Definition unit.c:401
bool unit_transported(const struct unit *pcargo)
Definition unit.c:2528
bool can_unit_unload(const struct unit *pcargo, const struct unit *ptrans)
Definition unit.c:794
bool unit_can_convert(const struct civ_map *nmap, const struct unit *punit)
Definition unit.c:2098
#define unit_tile(_pu)
Definition unit.h:407
#define unit_owner(_pu)
Definition unit.h:406
#define unit_home(_pu_)
Definition unit.h:404
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
#define unit_list_iterate_end
Definition unitlist.h:33
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:123
bool utype_may_act_move_frags(const struct unit_type *punit_type, const action_id act_id, const int move_fragments)
Definition unittype.c:1062
const struct veteran_level * utype_veteran_level(const struct unit_type *punittype, int level)
Definition unittype.c:2601
bool unit_has_type_flag(const struct unit *punit, enum unit_type_flag_id flag)
Definition unittype.c:194
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:1000
bool utype_can_do_action(const struct unit_type *putype, const action_id act_id)
Definition unittype.c:375
#define utype_class(_t_)
Definition unittype.h:754
#define L_LAST
Definition unittype.h:444
#define unit_type_iterate(_p)
Definition unittype.h:860
#define unit_type_iterate_end
Definition unittype.h:867
#define U_NOT_OBSOLETED
Definition unittype.h:533