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#include <stdarg.h>
20
21/* utility */
22#include "astring.h"
23
24/* common */
25#include "actions.h"
26#include "city.h"
27#include "combat.h"
28#include "fc_interface.h"
29#include "game.h"
30#include "map.h"
31#include "metaknowledge.h"
32#include "movement.h"
33#include "oblig_reqs.h"
34#include "research.h"
35#include "server_settings.h"
36#include "unit.h"
37
38
39/* Values used to interpret action probabilities.
40 *
41 * Action probabilities are sent over the network. A change in a value here
42 * will therefore change the network protocol.
43 *
44 * A change in a value here should also update the action probability
45 * format documentation in fc_types.h */
46/* The lowest possible probability value (0%) */
47#define ACTPROB_VAL_MIN 0
48/* The highest possible probability value (100%) */
49#define ACTPROB_VAL_MAX 200
50/* A probability increase of 1% corresponds to this increase. */
51#define ACTPROB_VAL_1_PCT (ACTPROB_VAL_MAX / 100)
52/* Action probability doesn't apply when min is this. */
53#define ACTPROB_VAL_NA 253
54/* Action probability unsupported when min is this. */
55#define ACTPROB_VAL_NOT_IMPL 254
56
61
63
65
66static struct action *
69 bool rare_pop_up,
72 const int min_distance,
73 const int max_distance,
75static struct action *
78
79static bool is_enabler_active(const struct action_enabler *enabler,
80 const struct req_context *actor,
81 const struct req_context *target);
82
83static inline bool
85static inline bool
87static inline bool
89
91 const struct unit *pvictim,
92 const struct tile *tgt_tile,
93 const struct action *paction)
95
96/* Make sure that an action distance can target the whole map. */
99
102
103
104/**********************************************************************/
107static void hard_code_actions(void)
108{
111 FALSE, TRUE,
112 MAK_ESCAPE, 0, 1, TRUE);
115 FALSE, TRUE,
116 MAK_ESCAPE, 0, 1, FALSE);
119 FALSE, TRUE,
120 MAK_ESCAPE, 0, 1, TRUE);
123 FALSE, TRUE,
124 MAK_ESCAPE, 0, 1, FALSE);
127 FALSE, TRUE,
128 /* Tries a forced move if the target unit is alone at
129 * its tile and not in a city. Takes all movement if
130 * the forced move fails. */
132 0, 1, FALSE);
135 FALSE, TRUE,
137 0, 1, FALSE);
140 FALSE, TRUE,
141 MAK_ESCAPE, 0, 1, TRUE);
144 FALSE, TRUE,
145 MAK_ESCAPE, 0, 1, FALSE);
149 FALSE, TRUE,
150 MAK_ESCAPE, 0, 1, TRUE);
154 FALSE, TRUE,
155 MAK_ESCAPE, 0, 1, TRUE);
159 FALSE, TRUE,
160 MAK_ESCAPE, 0, 1, FALSE);
164 FALSE, TRUE,
165 MAK_ESCAPE, 0, 1, FALSE);
168 FALSE, TRUE,
169 MAK_ESCAPE, 0, 1, TRUE);
172 FALSE, TRUE,
173 MAK_ESCAPE, 0, 1, FALSE);
177 FALSE, TRUE,
178 MAK_STAYS, 0, 1, FALSE);
182 FALSE, TRUE,
183 MAK_STAYS, 0, 1, TRUE);
187 FALSE, TRUE,
188 MAK_ESCAPE, 0, 1, TRUE);
192 FALSE, TRUE,
193 MAK_ESCAPE, 0, 1, FALSE);
197 FALSE, TRUE,
198 MAK_ESCAPE, 0, 1, TRUE);
202 FALSE, TRUE,
203 MAK_ESCAPE, 0, 1, FALSE);
207 FALSE, TRUE,
208 MAK_STAYS, 0, 1, FALSE);
212 FALSE, TRUE,
213 MAK_STAYS, 0, 1, TRUE);
217 FALSE, TRUE,
218 MAK_ESCAPE, 0, 1, TRUE);
222 FALSE, TRUE,
223 MAK_ESCAPE, 0, 1, FALSE);
227 FALSE, TRUE,
228 MAK_ESCAPE, 0, 1, FALSE);
232 FALSE, TRUE,
233 MAK_ESCAPE, 0, 1, FALSE);
236 FALSE, TRUE,
237 MAK_STAYS, 0, 1, TRUE);
240 FALSE, TRUE,
241 MAK_STAYS, 0, 1, TRUE);
244 FALSE, TRUE,
245 MAK_STAYS, 0, 1, TRUE);
249 /* A single domestic unit at the target tile will make
250 * the action illegal. It must therefore be performed
251 * from another tile. */
252 1, 1,
253 FALSE);
257 /* Illegal to perform to a target on another tile.
258 * Reason: The Freeciv code assumes that the city
259 * founding unit is located at the tile were the new
260 * city is founded. */
261 0, 0,
262 TRUE);
265 TRUE, TRUE,
266 MAK_STAYS, 0, 1, TRUE);
269 FALSE, TRUE,
270 MAK_ESCAPE, 0, 1, TRUE);
273 FALSE, TRUE,
274 MAK_ESCAPE, 0, 1, FALSE);
278 /* A single domestic unit at the target tile will make
279 * the action illegal. It must therefore be performed
280 * from another tile. */
281 1,
282 /* Overwritten by the ruleset's bombard_max_range */
283 1,
284 FALSE);
287 FALSE, TRUE,
288 MAK_STAYS,
289 /* A single domestic unit at the target tile will make
290 * the action illegal. It must therefore be performed
291 * from another tile. */
292 1,
293 /* Overwritten by the ruleset's bombard_2_max_range */
294 1,
295 FALSE);
299 /* A single domestic unit at the target tile will make
300 * the action illegal. It must therefore be performed
301 * from another tile. */
302 1,
303 /* Overwritten by the ruleset's bombard_3_max_range */
304 1,
305 FALSE);
309 /* A single domestic unit at the target tile will make
310 * the action illegal. It must therefore be performed
311 * from another tile. */
312 1,
313 /* Overwritten by the ruleset's bombard_4_max_range */
314 1,
315 FALSE);
319 /* A single domestic unit at the target tile will make
320 * the action illegal. It must therefore be performed
321 * from another tile. */
322 1,
323 /* Overwritten by the ruleset's bombard_lethal_max_range */
324 1,
325 FALSE);
329 /* A single domestic unit at the target tile will make
330 * the action illegal. It must therefore be performed
331 * from another tile. */
332 1,
333 /* Overwritten by the ruleset's bombard_lethal_2_max_range */
334 1,
335 FALSE);
338 FALSE, TRUE,
339 MAK_ESCAPE, 0, 1, TRUE);
342 FALSE, TRUE,
343 MAK_ESCAPE, 0, 1, FALSE);
346 TRUE, TRUE,
347 MAK_STAYS, 0,
348 /* Overwritten by the ruleset's
349 * explode_nuclear_max_range */
350 0,
351 TRUE);
354 TRUE, TRUE,
355 MAK_STAYS, 1, 1, TRUE);
358 TRUE, TRUE,
359 MAK_STAYS, 1, 1, TRUE);
362 TRUE, TRUE,
363 MAK_STAYS, 0, 1, FALSE);
366 FALSE, TRUE,
367 MAK_STAYS, 0, 1, FALSE);
371 /* Illegal to perform to a target on another tile to
372 * keep the rules exactly as they were for now. */
373 0, 1,
374 TRUE);
377 /* Can't be ACTRES_NONE because
378 * action_success_actor_consume() sets unit lost
379 * reason based on action result. */
381 TRUE, TRUE,
382 MAK_STAYS, 0, 0, TRUE);
385 TRUE, FALSE,
386 /* Illegal to perform to a target on another tile to
387 * keep the rules exactly as they were for now. */
388 MAK_STAYS, 0, 0, FALSE);
391 TRUE, FALSE,
392 MAK_STAYS, 0, 0, FALSE);
396 /* Illegal to perform to a target on another tile to
397 * keep the rules exactly as they were for now. */
398 0, 0,
399 FALSE);
402 TRUE, TRUE,
404 1,
405 /* Still limited by each unit type's
406 * paratroopers_range field. */
408 FALSE);
411 TRUE, TRUE,
413 1,
414 /* Still limited by each unit type's
415 * paratroopers_range field. */
417 FALSE);
420 TRUE, TRUE,
422 1,
423 /* Still limited by each unit type's
424 * paratroopers_range field. */
426 FALSE);
430 TRUE, TRUE,
432 1,
433 /* Still limited by each unit type's
434 * paratroopers_range field. */
436 FALSE);
439 TRUE, TRUE,
441 1,
442 /* Still limited by each unit type's
443 * paratroopers_range field. */
445 FALSE);
449 TRUE, TRUE,
451 1,
452 /* Still limited by each unit type's
453 * paratroopers_range field. */
455 FALSE);
458 TRUE, TRUE,
460 1,
461 /* Overwritten by the ruleset's airlift_max_range. */
463 FALSE);
466 FALSE, TRUE,
467 /* Tries a forced move if the target unit's tile has
468 * no non-allied units and the occupychance dice roll
469 * tells it to move. */
471 1, 1, FALSE);
474 FALSE, TRUE,
475 /* Tries a forced move if the target unit's tile has
476 * no non-allied units and the occupychance dice roll
477 * tells it to move. */
479 1, 1, FALSE);
482 FALSE, TRUE,
483 MAK_FORCED, 1, 1, TRUE);
486 FALSE, TRUE,
487 MAK_FORCED, 1, 1, TRUE);
490 FALSE, TRUE,
492 1, 1, FALSE);
495 FALSE, FALSE,
496 MAK_STAYS, 1, 1, FALSE);
499 FALSE, FALSE,
500 MAK_STAYS, 1, 1, FALSE);
503 FALSE, TRUE,
504 MAK_REGULAR, 1, 1, FALSE);
507 FALSE, TRUE,
508 MAK_REGULAR, 1, 1, FALSE);
511 FALSE, TRUE,
512 MAK_REGULAR, 1, 1, FALSE);
515 FALSE, TRUE,
516 MAK_REGULAR, 1, 1, FALSE);
519 FALSE, TRUE,
520 MAK_REGULAR, 1, 1, FALSE);
523 FALSE, TRUE,
524 MAK_REGULAR, 1, 1, FALSE);
527 FALSE, TRUE,
528 MAK_REGULAR, 1, 1, FALSE);
531 FALSE, TRUE,
532 MAK_REGULAR, 1, 1, FALSE);
535 FALSE, TRUE,
536 MAK_STAYS, 0, 1, FALSE);
539 FALSE, TRUE,
540 MAK_STAYS, 0, 1, FALSE);
543 TRUE, FALSE,
544 MAK_STAYS, 0, 0, FALSE);
547 TRUE, FALSE,
548 MAK_STAYS, 0, 0, FALSE);
551 TRUE, FALSE,
552 MAK_STAYS, 0, 0, FALSE);
555 TRUE, FALSE,
556 MAK_STAYS, 0, 0, FALSE);
559 TRUE, FALSE,
560 MAK_STAYS, 0, 0, FALSE);
563 TRUE, FALSE,
564 MAK_STAYS, 0, 0, FALSE);
567 TRUE, FALSE,
568 MAK_STAYS, 0, 0, FALSE);
571 TRUE, FALSE,
572 MAK_STAYS, 0, 0, FALSE);
575 TRUE, FALSE,
576 MAK_STAYS, 0, 0, FALSE);
579 TRUE, FALSE,
580 MAK_STAYS, 0, 0, FALSE);
583 TRUE, FALSE,
584 MAK_STAYS, 0, 0, FALSE);
587 TRUE, FALSE,
588 MAK_STAYS, 0, 0, FALSE);
591 TRUE, FALSE,
592 MAK_STAYS, 0, 0, FALSE);
595 TRUE, FALSE,
596 MAK_STAYS, 0, 0, FALSE);
599 TRUE, FALSE,
600 MAK_STAYS, 0, 0, FALSE);
603 TRUE, FALSE,
604 MAK_STAYS, 0, 0, FALSE);
607 TRUE, FALSE,
608 MAK_STAYS, 0, 0, FALSE);
611 TRUE, FALSE,
612 MAK_STAYS, 0, 0, FALSE);
615 TRUE, FALSE,
616 MAK_STAYS, 0, 0, FALSE);
619 TRUE, FALSE,
620 MAK_STAYS, 0, 0, FALSE);
623 TRUE, FALSE,
624 MAK_STAYS, 0, 0, FALSE);
627 TRUE, FALSE,
628 MAK_STAYS, 0, 0, FALSE);
631 TRUE, FALSE,
632 MAK_STAYS, 0, 0, FALSE);
635 TRUE, FALSE,
636 MAK_STAYS, 0, 0, FALSE);
639 TRUE, FALSE,
640 MAK_STAYS, 0, 0, FALSE);
643 TRUE, FALSE,
644 MAK_STAYS, 0, 0, FALSE);
647 TRUE, FALSE,
648 MAK_STAYS, 0, 0, FALSE);
651 TRUE, FALSE,
652 MAK_STAYS, 0, 0, FALSE);
655 TRUE, FALSE,
656 MAK_STAYS, 0, 0, FALSE);
660 FALSE, TRUE,
661 MAK_REGULAR, 1, 1, FALSE);
665 FALSE, TRUE,
666 MAK_REGULAR, 1, 1, FALSE);
670 FALSE, TRUE,
671 MAK_REGULAR, 1, 1, FALSE);
675 FALSE, TRUE,
676 MAK_REGULAR, 1, 1, FALSE);
679 TRUE, TRUE,
680 MAK_REGULAR, 1, 1, FALSE);
683 TRUE, TRUE,
684 MAK_REGULAR, 1, 1, FALSE);
687 TRUE, TRUE,
688 MAK_REGULAR, 1, 1, FALSE);
691 TRUE, TRUE,
692 MAK_REGULAR, 1, 1, FALSE);
695 FALSE, TRUE,
696 MAK_STAYS, 1, 1, FALSE);
699 FALSE, TRUE,
700 MAK_REGULAR, 1, 1, FALSE);
703 FALSE, TRUE,
704 MAK_REGULAR, 1, 1, FALSE);
707 FALSE, TRUE,
708 MAK_REGULAR, 1, 1, FALSE);
711 FALSE, TRUE,
712 MAK_REGULAR, 1, 1, FALSE);
715 FALSE, TRUE,
716 MAK_REGULAR, 1, 1, FALSE);
719 FALSE, TRUE,
720 MAK_REGULAR, 1, 1, FALSE);
723 FALSE, TRUE,
724 MAK_REGULAR, 1, 1, FALSE);
727 FALSE, TRUE,
728 MAK_REGULAR, 1, 1, FALSE);
731 TRUE, TRUE,
732 MAK_REGULAR, 1, 1, FALSE);
735 TRUE, TRUE,
736 MAK_REGULAR, 1, 1, FALSE);
739 TRUE, TRUE,
740 MAK_REGULAR, 1, 1, FALSE);
743 TRUE, TRUE,
744 MAK_TELEPORT, 1, 1, FALSE);
747 TRUE, TRUE,
748 MAK_TELEPORT, 1, 1, FALSE);
751 TRUE, TRUE,
752 MAK_TELEPORT, 1, 1, FALSE);
755 TRUE, TRUE,
756 MAK_TELEPORT, 1,
761 TRUE, TRUE,
762 MAK_TELEPORT, 1,
767 TRUE, TRUE,
768 MAK_TELEPORT, 1,
773 TRUE, TRUE,
774 MAK_TELEPORT, 1,
779 TRUE, TRUE,
780 MAK_TELEPORT, 1,
784 TRUE, FALSE,
785 MAK_STAYS, 0, 0, FALSE);
788 TRUE, FALSE,
789 MAK_STAYS, 0, 0, FALSE);
792 FALSE, TRUE,
794 /* Overwritten by the ruleset */
795 0, 1, FALSE);
798 FALSE, TRUE,
800 /* Overwritten by the ruleset */
801 0, 1, FALSE);
804 FALSE, TRUE,
806 /* Overwritten by the ruleset */
807 0, 1, FALSE);
810 FALSE, TRUE,
812 /* Overwritten by the ruleset */
813 0, 1, FALSE);
816 FALSE, TRUE,
817 /* Tries a forced move if the target unit's tile has
818 * no non-allied units and the occupychance dice roll
819 * tells it to move. */
821 1, 1, FALSE);
822
825
826 /* The structure even for these need to be created, for
827 * the action_id_rule_name() to work on iterations. */
828
829 /*
830 actions[ACTION_UNUSED_1]
831 = unit_action_new(ACTION_UNUSED_1, ACTRES_NONE,
832 FALSE, FALSE,
833 MAK_UNREPRESENTABLE,
834 0, 0, FALSE);
835 */
836}
837
838/**********************************************************************/
841void actions_init(void)
842{
843 int i, j;
844
845 for (i = 0; i < ACTRES_LAST; i++) {
847 }
848 for (i = 0; i < ACTIVITY_LAST; i++) {
850 }
851
852 /* Hard code the actions */
854
855 /* Initialize the action enabler list */
856 action_iterate_all(act) {
859
860 /* Initialize action obligatory hard requirements. */
862
863 /* Obligatory hard requirements are sorted by requirement in the source
864 * code. This makes it easy to read, modify and explain it. */
866
867 /* Initialize the action auto performers. */
868 for (i = 0; i < MAX_NUM_ACTION_AUTO_PERFORMERS; i++) {
869 /* Nothing here. Nothing after this point. */
871
872 /* The criteria to pick *this* auto performer for its cause. */
874
875 for (j = 0; j < MAX_NUM_ACTIONS; j++) {
876 /* Nothing here. Nothing after this point. */
878 }
879 }
880
881 /* The actions them self are now initialized. */
883}
884
885/**********************************************************************/
891{
892 /* Some obligatory hard requirements needs access to the rest of the
893 * ruleset. */
895}
896
897/**********************************************************************/
900void actions_free(void)
901{
902 int i;
903
904 /* Don't consider the actions to be initialized any longer. */
906
907 action_iterate_all(act) {
911
913
914 FC_FREE(actions[act]);
916
917 /* Free the obligatory hard action requirements. */
919
920 /* Free the action auto performers. */
921 for (i = 0; i < MAX_NUM_ACTION_AUTO_PERFORMERS; i++) {
923 }
924
926
927 for (i = 0; i < ACTRES_LAST; i++) {
930 }
931 for (i = 0; i < ACTIVITY_LAST; i++) {
934 }
935}
936
937/**********************************************************************/
943{
944 if (!actions_initialized) {
945 /* The actions them self aren't initialized yet. */
946 return FALSE;
947 }
948
950 if (actions[act]->ui_name[0] == '\0') {
951 /* A noninternal action without a UI name exists means that
952 * the ruleset haven't loaded yet. The ruleset loading will assign
953 * a default name to any actions not named by the ruleset.
954 * The client will get this name from the server. */
955 return FALSE;
956 }
958
959 /* The actions should be ready for use. */
960 return TRUE;
961}
962
963/**********************************************************************/
966static 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, 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, 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/**********************************************************************/
1753static struct requirement *
1755 const struct requirement_vector *vec)
1756{
1757 /* If the requirement is contradicted by any requirement in the vector it
1758 * contradicts the entire requirement vector. */
1761 return preq;
1762 }
1764
1765 /* Not a singe requirement in the requirement vector is contradicted be
1766 * the specified requirement. */
1767 return NULL;
1768}
1769
1770/**********************************************************************/
1776static struct req_vec_problem *
1778 const struct action_enabler *enabler)
1779{
1780 struct req_vec_problem *out;
1781 struct requirement *local_diplrel;
1782 struct requirement *claimed_req;
1786 struct astring astr;
1787
1789 /* Not tile targeted */
1790 return NULL;
1791 }
1792
1794 if (local_diplrel == NULL) {
1795 /* No local diplrel */
1796 return NULL;
1797 }
1798
1799 /* Tile is unclaimed as a requirement. */
1801 tile_is_unclaimed.survives = FALSE;
1802 tile_is_unclaimed.source.kind = VUT_CITYTILE;
1803 tile_is_unclaimed.present = FALSE;
1804 tile_is_unclaimed.source.value.citytile = CITYT_CLAIMED;
1805
1807 &enabler->target_reqs);
1808
1809 if (claimed_req) {
1810 /* Already clear */
1811 return NULL;
1812 }
1813
1814 /* Tile is claimed as a requirement. */
1816 tile_is_claimed.survives = FALSE;
1817 tile_is_claimed.source.kind = VUT_CITYTILE;
1818 tile_is_claimed.present = TRUE;
1819 tile_is_claimed.source.value.citytile = CITYT_CLAIMED;
1820
1822 1,
1823 /* TRANS: ruledit shows this when an enabler for a tile targeted
1824 * action requires that the actor has a diplomatic relationship to
1825 * the target but doesn't require that the target tile is claimed.
1826 * (DiplRel requirements to an unclaimed tile are never fulfilled
1827 * so this is implicit.) */
1828 N_("Requirement {%s} of action \"%s\" implies a claimed "
1829 "tile. No diplomatic relation to Nature."),
1831
1832 astr_free(&astr);
1833
1834 /* The solution is to add the requirement that the tile is claimed */
1835 out->suggested_solutions[0].req = tile_is_claimed;
1836 out->suggested_solutions[0].vector_number
1838 out->suggested_solutions[0].operation = RVCO_APPEND;
1839
1840 return out;
1841}
1842
1843/**********************************************************************/
1849static struct req_vec_problem *
1851{
1852 struct req_vec_problem *out;
1853 struct requirement *local_diplrel;
1854 struct requirement *unclaimed_req;
1857 struct astring astr1;
1858 struct astring astr2;
1859
1861 /* Not tile targeted */
1862 return NULL;
1863 }
1864
1866 if (local_diplrel == NULL) {
1867 /* No local diplrel */
1868 return NULL;
1869 }
1870
1871 /* Tile is claimed as a requirement. */
1873 tile_is_claimed.survives = FALSE;
1874 tile_is_claimed.source.kind = VUT_CITYTILE;
1875 tile_is_claimed.present = TRUE;
1876 tile_is_claimed.source.value.citytile = CITYT_CLAIMED;
1877
1879 &enabler->target_reqs);
1880
1881 if (unclaimed_req == NULL) {
1882 /* No unclaimed req */
1883 return NULL;
1884 }
1885
1887 2,
1888 /* TRANS: ruledit shows this when an enabler for a tile targeted
1889 * action requires that the target tile is unclaimed and that the
1890 * actor has a diplomatic relationship to the target. (DiplRel
1891 * requirements to an unclaimed tile are never fulfilled.) */
1892 N_("In enabler for \"%s\": No diplomatic relation to Nature."
1893 " Requirements {%s} and {%s} contradict each other."),
1897
1898 astr_free(&astr1);
1899 astr_free(&astr2);
1900
1901 /* The first suggestion is to remove the diplrel */
1902 out->suggested_solutions[0].req = *local_diplrel;
1903 out->suggested_solutions[0].vector_number
1905 out->suggested_solutions[0].operation = RVCO_REMOVE;
1906
1907 /* The 2nd is to remove the requirement that the tile is unclaimed */
1908 out->suggested_solutions[1].req = *unclaimed_req;
1909 out->suggested_solutions[1].vector_number
1911 out->suggested_solutions[1].operation = RVCO_REMOVE;
1912
1913 return out;
1914}
1915
1916/**********************************************************************/
1921struct req_vec_problem *
1923{
1924 struct req_vec_problem *out;
1925
1927 if (out != NULL) {
1928 return out;
1929 }
1930
1931 /* Look for errors in the requirement vectors. */
1932 out = req_vec_suggest_repair(&enabler->actor_reqs,
1934 enabler);
1935 if (out != NULL) {
1936 return out;
1937 }
1938
1939 out = req_vec_suggest_repair(&enabler->target_reqs,
1941 enabler);
1942 if (out != NULL) {
1943 return out;
1944 }
1945
1946 /* Enabler specific contradictions. */
1948 if (out != NULL) {
1949 return out;
1950 }
1951
1952 /* Needed in action not enabled explanation finding. */
1954 if (out != NULL) {
1955 return out;
1956 }
1957
1958 /* No problems found. */
1959 return NULL;
1960}
1961
1962/**********************************************************************/
1969static struct req_vec_problem *
1971{
1972 struct req_vec_problem *out;
1973
1974 out = NULL;
1975
1976 return out;
1977}
1978
1979/**********************************************************************/
1987struct req_vec_problem *
1989{
1990 struct action *paction;
1991 struct req_vec_problem *out;
1992
1994 if (out) {
1995 /* A bug, not just a potential improvement */
1996 return out;
1997 }
1998
2000
2001 /* Look for improvement suggestions to the requirement vectors. */
2004 enabler);
2005 if (out) {
2006 return out;
2007 }
2008 out = req_vec_suggest_improvement(&enabler->target_reqs,
2010 enabler);
2011 if (out) {
2012 return out;
2013 }
2014
2015 /* Detect unused action enablers. */
2017 bool has_user = FALSE;
2018
2022 &(enabler->actor_reqs))) {
2023 has_user = TRUE;
2024 break;
2025 }
2027
2028 if (!has_user) {
2029 /* TRANS: ruledit warns a user about an unused action enabler */
2030 out = req_vec_problem_new(0, N_("Action enabler for \"%s\" is never"
2031 " used by any unit."),
2033 }
2034 }
2035 if (out != NULL) {
2036 return out;
2037 }
2038
2040
2041 return out;
2042}
2043
2044/**********************************************************************/
2053 const struct requirement_vector *vec)
2054{
2055 struct action_enabler *ae = (struct action_enabler *)enabler;
2056
2057 if (vec == &ae->actor_reqs) {
2058 return 0;
2059 } else if (vec == &ae->target_reqs) {
2060 return 1;
2061 } else {
2062 return -1;
2063 }
2064}
2065
2066/********************************************************************/
2074struct requirement_vector *
2076 req_vec_num_in_item number)
2077{
2078 struct action_enabler *ae = (struct action_enabler *)enabler;
2079
2080 fc_assert_ret_val(number >= 0, NULL);
2081
2082 switch (number) {
2083 case 0:
2084 return &ae->actor_reqs;
2085 case 1:
2086 return &ae->target_reqs;
2087 default:
2088 return NULL;
2089 }
2090}
2091
2092/*********************************************************************/
2100{
2101 switch (vec) {
2102 case 0:
2103 /* TRANS: requirement vector in an action enabler (ruledit) */
2104 return _("actor_reqs");
2105 case 1:
2106 /* TRANS: requirement vector in an action enabler (ruledit) */
2107 return _("target_reqs");
2108 default:
2109 return NULL;
2110 }
2111}
2112
2113/**********************************************************************/
2118static const struct impr_type *
2120{
2121 /* Only used with city targets */
2123
2124 if (target_city->production.kind == VUT_IMPROVEMENT) {
2125 /* The local building is what the target city currently is building. */
2126 return target_city->production.value.building;
2127 } else {
2128 /* In the current semantic the local building is always the building
2129 * being built. */
2130 /* TODO: Consider making the local building the target building for
2131 * actions that allows specifying a building target. */
2132 return NULL;
2133 }
2134}
2135
2136/**********************************************************************/
2141static const struct unit_type *
2143{
2144 /* Only used with city targets */
2146
2147 if (target_city->production.kind == VUT_UTYPE) {
2148 /* The local unit type is what the target city currently is
2149 * building. */
2150 return target_city->production.value.utype;
2151 } else {
2152 /* In the current semantic the local utype is always the type of the
2153 * unit being built. */
2154 return NULL;
2155 }
2156}
2157
2158/**********************************************************************/
2166static const struct tile *
2168 const struct unit *actor_unit,
2169 const struct tile *target_tile_arg,
2170 const struct city *target_city,
2171 const struct unit *target_unit)
2172{
2173 if (target_tile_arg != NULL) {
2174 /* Trust the caller. */
2175 return target_tile_arg;
2176 }
2177
2178 /* Action should always be set */
2179 fc_assert_ret_val(act, NULL);
2180
2181 switch (action_get_target_kind(act)) {
2182 case ATK_CITY:
2184 return city_tile(target_city);
2185 case ATK_UNIT:
2186 if (target_unit == NULL) {
2188 return NULL;
2189 }
2190 return unit_tile(target_unit);
2191 case ATK_STACK:
2193 if (target_unit) {
2194 return unit_tile(target_unit);
2195 }
2196
2198 case ATK_TILE:
2199 case ATK_EXTRAS:
2201 return target_tile_arg;
2202 case ATK_SELF:
2203 if (actor_unit != nullptr) {
2204 return unit_tile(actor_unit);
2205 }
2206 return nullptr;
2207 case ATK_COUNT:
2208 /* Handled below. */
2209 break;
2210 }
2211
2212 fc_assert_msg(FALSE, "Bad action target kind %d for action %s",
2214 return nullptr;
2215}
2216
2217/**********************************************************************/
2226static const struct city *
2228 const struct unit *actor_unit,
2229 const struct tile *target_tile,
2230 const struct city *target_city_arg,
2231 const struct unit *target_unit)
2232{
2233 if (target_city_arg != NULL) {
2234 /* Trust the caller. */
2235 return target_city_arg;
2236 }
2237
2238 /* action should always be set */
2239 fc_assert_ret_val(act, NULL);
2240
2241 switch (action_get_target_kind(act)) {
2242 case ATK_CITY:
2244 return target_city_arg;
2245 case ATK_UNIT:
2249 case ATK_STACK:
2251 if (target_unit) {
2254 }
2255
2257 case ATK_TILE:
2258 case ATK_EXTRAS:
2260 return tile_city(target_tile);
2261 case ATK_SELF:
2262 if (actor_unit != nullptr) {
2263 struct tile *ptile = unit_tile(actor_unit);
2264
2265 if (ptile != nullptr) {
2266 return tile_city(ptile);
2267 }
2268 }
2269 return nullptr;
2270 case ATK_COUNT:
2271 /* Handled below. */
2272 break;
2273 }
2274
2275 fc_assert_msg(FALSE, "Bad action target kind %d for action %s",
2277 return NULL;
2278}
2279
2280/**********************************************************************/
2287 const struct action *act,
2288 const struct unit *actor_unit,
2289 const struct tile *target_tile_arg,
2290 const struct city *target_city_arg,
2291 const struct unit *target_unit)
2292{
2293 const struct tile *target_tile
2296 const struct city *target_city
2299
2301 struct action *blocker = action_by_number(blocker_id);
2302
2304 continue);
2305
2306 if (!action_would_be_blocked_by(act, blocker)) {
2307 /* It doesn't matter if it is legal. It won't block the action. */
2308 continue;
2309 }
2310
2311 switch (action_get_target_kind(blocker)) {
2312 case ATK_CITY:
2313 if (!target_city) {
2314 /* Can't be enabled. No target. */
2315 continue;
2316 }
2319 return blocker;
2320 }
2321 break;
2322 case ATK_UNIT:
2323 if (!target_unit) {
2324 /* Can't be enabled. No target. */
2325 continue;
2326 }
2329 return blocker;
2330 }
2331 break;
2332 case ATK_STACK:
2333 if (!target_tile) {
2334 /* Can't be enabled. No target. */
2335 continue;
2336 }
2339 return blocker;
2340 }
2341 break;
2342 case ATK_TILE:
2343 if (!target_tile) {
2344 /* Can't be enabled. No target. */
2345 continue;
2346 }
2349 return blocker;
2350 }
2351 break;
2352 case ATK_EXTRAS:
2353 if (!target_tile) {
2354 /* Can't be enabled. No target. */
2355 continue;
2356 }
2359 return blocker;
2360 }
2361 break;
2362 case ATK_SELF:
2364 return blocker;
2365 }
2366 break;
2367 case ATK_COUNT:
2369 continue);
2370 break;
2371 }
2373
2374 /* Not blocked. */
2375 return NULL;
2376}
2377
2378/**********************************************************************/
2398static bool
2400 const struct unit_type *actor_unittype,
2401 bool ignore_third_party)
2402{
2403 switch (paction->result) {
2404 case ACTRES_JOIN_CITY:
2405 if (actor_unittype->pop_cost <= 0) {
2406 /* Reason: Must have population to add. */
2407 return FALSE;
2408 }
2409 break;
2410
2411 case ACTRES_BOMBARD:
2412 if (actor_unittype->bombard_rate <= 0) {
2413 /* Reason: Can't bombard if it never fires. */
2414 return FALSE;
2415 }
2416
2417 if (actor_unittype->attack_strength <= 0) {
2418 /* Reason: Can't bombard without attack strength. */
2419 return FALSE;
2420 }
2421
2422 break;
2423
2425 if (actor_unittype->obsoleted_by == U_NOT_OBSOLETED) {
2426 /* Reason: Nothing to upgrade to. */
2427 return FALSE;
2428 }
2429 break;
2430
2431 case ACTRES_ATTACK:
2432 case ACTRES_WIPE_UNITS:
2434 if (actor_unittype->attack_strength <= 0) {
2435 /* Reason: Can't attack without strength. */
2436 return FALSE;
2437 }
2438 break;
2439
2440 case ACTRES_CONVERT:
2441 if (!actor_unittype->converted_to) {
2442 /* Reason: must be able to convert to something. */
2443 return FALSE;
2444 }
2445 break;
2446
2448 if (actor_unittype->transport_capacity < 1) {
2449 /* Reason: can't transport anything to unload. */
2450 return FALSE;
2451 }
2452 break;
2453
2455 if (actor_unittype->transport_capacity < 1) {
2456 /* Reason: can't transport anything to load. */
2457 return FALSE;
2458 }
2459 break;
2460
2465 if (!ignore_third_party) {
2466 bool has_transporter = FALSE;
2467
2471 break;
2472 }
2474
2475 if (!has_transporter) {
2476 /* Reason: no other unit can transport this unit. */
2477 return FALSE;
2478 }
2479 }
2480 break;
2481
2483 if (!ignore_third_party) {
2484 bool has_target = FALSE;
2486
2487 /* Use cache when it has been initialized */
2488 if (pclass->cache.native_bases != NULL) {
2489 /* Extra being native one is a hard requirement */
2490 extra_type_list_iterate(pclass->cache.native_bases, pextra) {
2491 if (!territory_claiming_base(pextra->data.base)) {
2492 /* Hard requirement */
2493 continue;
2494 }
2495
2496 has_target = TRUE;
2497 break;
2499 } else {
2501
2503 if (!is_native_extra_to_uclass(pextra, pclass)) {
2504 /* Hard requirement */
2505 continue;
2506 }
2507
2508 has_target = TRUE;
2509 break;
2511 }
2512
2513 if (!has_target) {
2514 /* Reason: no extras can be conquered by this unit. */
2515 return FALSE;
2516 }
2517 }
2518 break;
2519
2520 case ACTRES_PARADROP:
2522 if (actor_unittype->paratroopers_range <= 0) {
2523 /* Reason: Can't paradrop 0 tiles. */
2524 return FALSE;
2525 }
2526 break;
2527
2528 case ACTRES_HUT_ENTER:
2532 case ACTRES_SPY_POISON:
2541 case ACTRES_SPY_ESCAPE:
2542 case ACTRES_TRADE_ROUTE:
2543 case ACTRES_MARKETPLACE:
2544 case ACTRES_HELP_WONDER:
2549 case ACTRES_FOUND_CITY:
2550 case ACTRES_STEAL_MAPS:
2551 case ACTRES_SPY_NUKE:
2552 case ACTRES_NUKE:
2553 case ACTRES_NUKE_UNITS:
2555 case ACTRES_EXPEL_UNIT:
2558 case ACTRES_HOME_CITY:
2559 case ACTRES_HOMELESS:
2560 case ACTRES_AIRLIFT:
2564 case ACTRES_HEAL_UNIT:
2565 case ACTRES_PILLAGE:
2566 case ACTRES_CLEAN:
2567 case ACTRES_FORTIFY:
2569 case ACTRES_CULTIVATE:
2570 case ACTRES_PLANT:
2571 case ACTRES_ROAD:
2572 case ACTRES_BASE:
2573 case ACTRES_MINE:
2574 case ACTRES_IRRIGATE:
2575 case ACTRES_SPY_ATTACK:
2576 case ACTRES_UNIT_MOVE:
2577 case ACTRES_TELEPORT:
2580 case ACTRES_NONE:
2581 /* No hard unit type requirements. */
2582 break;
2583
2585 }
2586
2587 return TRUE;
2588}
2589
2590/**********************************************************************/
2606bool
2613
2614/**********************************************************************/
2626static enum fc_tristate
2628 const struct action *paction,
2629 const struct req_context *actor,
2630 const bool omniscient,
2631 const struct city *homecity)
2632{
2633 enum action_result result = paction->result;
2634
2635 if (actor == NULL) {
2637 }
2638
2640 TRUE)) {
2641 /* Info leak: The actor player knows the type of their unit. */
2642 /* The actor unit type can't perform the action because of hard
2643 * unit type requirements. */
2644 return TRI_NO;
2645 }
2646
2647 switch (result) {
2648 case ACTRES_PARADROP:
2650 /* Reason: Keep the old rules. */
2651 /* Info leak: The player knows if their unit already has paradropped this
2652 * turn. */
2653 if (actor->unit->paradropped) {
2654 return TRI_NO;
2655 }
2656
2657 break;
2658
2659 case ACTRES_AIRLIFT:
2660 {
2661 /* Obligatory hard requirement. Checked here too since
2662 * action_hard_reqs_actor() may be called before any
2663 * action enablers are checked. */
2664 if (actor->city == NULL) {
2665 /* No city to airlift from. */
2666 return TRI_NO;
2667 }
2668
2669 if (actor->player != city_owner(actor->city)
2671 && pplayers_allied(actor->player,
2672 city_owner(actor->city)))) {
2673 /* Not allowed to airlift from this source. */
2674 return TRI_NO;
2675 }
2676
2677 if (!(omniscient || city_owner(actor->city) == actor->player)) {
2678 /* Can't check for airlifting capacity. */
2679 return TRI_MAYBE;
2680 }
2681
2682 if (0 >= actor->city->airlift
2685 /* The source cannot airlift for this turn (maybe already airlifted
2686 * or no airport).
2687 *
2688 * See also do_airline() in server/unittools.h. */
2689 return TRI_NO;
2690 }
2691 }
2692 break;
2693
2694 case ACTRES_CONVERT:
2695 /* Reason: Keep the old rules. */
2696 /* Info leak: The player knows their unit's cargo and location. */
2697 if (!unit_can_convert(nmap, actor->unit)) {
2698 return TRI_NO;
2699 }
2700 break;
2701
2704 if (unit_transported(actor->unit)) {
2705 if (!can_unit_unload(actor->unit, unit_transport_get(actor->unit))) {
2706 /* Can't leave current transport. */
2707 return TRI_NO;
2708 }
2709 }
2710 break;
2711
2713 if (!can_unit_unload(actor->unit, unit_transport_get(actor->unit))) {
2714 /* Keep the old rules about Unreachable and disembarks. */
2715 return TRI_NO;
2716 }
2717 break;
2718
2719 case ACTRES_HOMELESS:
2720 case ACTRES_UNIT_MOVE:
2721 case ACTRES_TELEPORT:
2725 case ACTRES_SPY_POISON:
2734 case ACTRES_SPY_ESCAPE:
2735 case ACTRES_TRADE_ROUTE:
2736 case ACTRES_MARKETPLACE:
2737 case ACTRES_HELP_WONDER:
2742 case ACTRES_FOUND_CITY:
2743 case ACTRES_JOIN_CITY:
2744 case ACTRES_STEAL_MAPS:
2745 case ACTRES_BOMBARD:
2746 case ACTRES_SPY_NUKE:
2747 case ACTRES_NUKE:
2748 case ACTRES_NUKE_UNITS:
2750 case ACTRES_EXPEL_UNIT:
2753 case ACTRES_HOME_CITY:
2755 case ACTRES_ATTACK:
2756 case ACTRES_WIPE_UNITS:
2762 case ACTRES_HEAL_UNIT:
2764 case ACTRES_CULTIVATE:
2765 case ACTRES_PLANT:
2766 case ACTRES_PILLAGE:
2767 case ACTRES_CLEAN:
2768 case ACTRES_FORTIFY:
2769 case ACTRES_ROAD:
2770 case ACTRES_BASE:
2771 case ACTRES_MINE:
2772 case ACTRES_IRRIGATE:
2776 case ACTRES_SPY_ATTACK:
2777 case ACTRES_HUT_ENTER:
2780 case ACTRES_NONE:
2781 /* No hard unit requirements. */
2782 break;
2783
2785 }
2786
2787 return TRI_YES;
2788}
2789
2790/**********************************************************************/
2813static enum fc_tristate
2816 const struct req_context *actor,
2817 const struct req_context *target,
2818 const struct extra_type *target_extra,
2819 const bool omniscient,
2820 const struct city *homecity)
2821{
2822 enum fc_tristate out;
2825
2826 if (actor == NULL) {
2828 }
2829 if (target == NULL) {
2830 target = req_context_empty();
2831 }
2832
2833 fc_assert_msg((tkind == ATK_CITY && target->city != NULL)
2834 || (tkind == ATK_TILE && target->tile != NULL)
2835 || (tkind == ATK_EXTRAS && target->tile != NULL)
2836 || (tkind == ATK_UNIT && target->unit != NULL)
2837 /* At this level each individual unit is tested. */
2838 || (tkind == ATK_STACK && target->unit != NULL)
2839 || (tkind == ATK_SELF),
2840 "Missing target!");
2841
2842 /* Info leak: The player knows where their unit is. */
2843 if (tkind != ATK_SELF
2846 target->tile))) {
2847 /* The distance between the actor and the target isn't inside the
2848 * action's accepted range. */
2849 return TRI_NO;
2850 }
2851
2852 switch (tkind) {
2853 case ATK_UNIT:
2854 /* The Freeciv code for all actions that is controlled by action
2855 * enablers and targets a unit assumes that the acting
2856 * player can see the target unit.
2857 * Examples:
2858 * - action_prob_vs_unit()'s quick check that the distance between actor
2859 * and target is acceptable would leak distance to target unit if the
2860 * target unit can't be seen.
2861 */
2862 if (!can_player_see_unit(actor->player, target->unit)) {
2863 return TRI_NO;
2864 }
2865 break;
2866 case ATK_CITY:
2867 /* The Freeciv code assumes that the player is aware of the target
2868 * city's existence. (How can you order an airlift to a city when you
2869 * don't know its city ID?) */
2871 actor->player)
2872 != target->city->id) {
2873 return TRI_NO;
2874 }
2875 break;
2876 case ATK_STACK:
2877 case ATK_TILE:
2878 case ATK_EXTRAS:
2879 case ATK_SELF:
2880 /* No special player knowledge checks. */
2881 break;
2882 case ATK_COUNT:
2884 break;
2885 }
2886
2888 target->tile, target->city, target->unit)) {
2889 /* Allows an action to block an other action. If a blocking action is
2890 * legal the actions it blocks becomes illegal. */
2891 return TRI_NO;
2892 }
2893
2894 /* Actor specific hard requirements. */
2896
2897 if (out == TRI_NO) {
2898 /* Illegal because of a hard actor requirement. */
2899 return TRI_NO;
2900 }
2901
2902 /* Quick checks for action itself */
2903 if (paction->result == ACTRES_ATTACK
2904 || paction->result == ACTRES_WIPE_UNITS
2905 || paction->result == ACTRES_COLLECT_RANSOM) {
2906 /* Reason: Keep the old rules. */
2907 if (!can_unit_attack_tile(actor->unit, paction, target->tile)) {
2908 return TRI_NO;
2909 }
2910 }
2911
2912 /* Hard requirements for results. */
2914 paction->result, actor,
2915 target, target_extra, out, omniscient,
2916 homecity);
2917
2918 if (out == TRI_NO) {
2919 /* Illegal because of a hard actor requirement. */
2920 return TRI_NO;
2921 }
2922
2923 if (paction->result == ACTRES_NUKE_UNITS) {
2925 target->tile)
2926 != ATT_OK) {
2927 /* Unreachable. */
2928 return TRI_NO;
2929 }
2930 } else if (paction->result == ACTRES_PARADROP
2931 || paction->result == ACTRES_PARADROP_CONQUER) {
2932 if (can_player_see_tile(actor->player, target->tile)) {
2933 /* Check for seen stuff that may kill the actor unit. */
2934
2935 /* Reason: Keep the old rules. Be merciful. */
2936 /* Info leak: The player sees the target tile. */
2937 if (!can_unit_exist_at_tile(nmap, actor->unit, target->tile)
2938 && (!BV_ISSET(paction->sub_results, ACT_SUB_RES_MAY_EMBARK)
2939 || !unit_could_load_at(actor->unit, target->tile))) {
2940 return TRI_NO;
2941 }
2942
2943 /* Reason: Keep the old rules. Be merciful. */
2944 /* Info leak: The player sees the target tile. */
2945 if (is_non_attack_city_tile(target->tile, actor->player)) {
2946 return TRI_NO;
2947 }
2948
2949 /* Reason: Be merciful. */
2950 /* Info leak: The player sees all units checked. Invisible units are
2951 * ignored. */
2952 unit_list_iterate(target->tile->units, pother) {
2953 if (can_player_see_unit(actor->player, pother)
2954 && !pplayers_allied(actor->player, unit_owner(pother))) {
2955 return TRI_NO;
2956 }
2958 }
2959 }
2960
2961 return out;
2962}
2963
2964/**********************************************************************/
2970static bool is_enabler_active(const struct action_enabler *enabler,
2971 const struct req_context *actor,
2972 const struct req_context *target)
2973{
2974 return are_reqs_active(actor, target, &enabler->actor_reqs, RPT_CERTAIN)
2975 && are_reqs_active(target, actor, &enabler->target_reqs, RPT_CERTAIN);
2976}
2977
2978/**********************************************************************/
2987static bool is_action_enabled(const struct civ_map *nmap,
2989 const struct req_context *actor,
2990 const struct req_context *target,
2991 const struct extra_type *target_extra,
2992 const struct city *actor_home)
2993{
2994 enum fc_tristate possible;
2995
2997 TRUE, actor_home);
2998
2999 if (possible != TRI_YES) {
3000 /* This context is omniscient. Should be yes or no. */
3002 "Is omniscient, should get yes or no.");
3003
3004 /* The action enablers are irrelevant since the action it self is
3005 * impossible. */
3006 return FALSE;
3007 }
3008
3010 enabler) {
3011 if (is_enabler_active(enabler, actor, target)) {
3012 return TRUE;
3013 }
3015
3016 return FALSE;
3017}
3018
3019/**********************************************************************/
3025static bool
3028 const struct unit *actor_unit,
3029 const struct city *actor_home,
3030 const struct tile *actor_tile,
3031 const struct city *target_city)
3032{
3033 const struct impr_type *target_building;
3034 const struct unit_type *target_utype;
3035
3036 if (actor_unit == NULL || target_city == NULL) {
3037 /* Can't do an action when actor or target are missing. */
3038 return FALSE;
3039 }
3040
3042 FALSE, "Action %s is performed by %s not %s",
3047
3050 FALSE, "Action %s is against %s not %s",
3055
3057
3059 /* No point in continuing. */
3060 return FALSE;
3061 }
3062
3065
3067 &(const struct req_context) {
3068 .player = unit_owner(actor_unit),
3069 .city = tile_city(actor_tile),
3070 .tile = actor_tile,
3071 .unit = actor_unit,
3072 .unittype = unit_type_get(actor_unit),
3073 },
3074 &(const struct req_context) {
3075 .player = city_owner(target_city),
3076 .city = target_city,
3077 .building = target_building,
3079 .unittype = target_utype,
3080 },
3081 NULL,
3082 actor_home);
3083}
3084
3085/**********************************************************************/
3101
3102/**********************************************************************/
3108static bool
3111 const struct unit *actor_unit,
3112 const struct city *actor_home,
3113 const struct tile *actor_tile,
3114 const struct unit *target_unit)
3115{
3116 if (actor_unit == NULL || target_unit == NULL) {
3117 /* Can't do an action when actor or target are missing. */
3118 return FALSE;
3119 }
3120
3122 FALSE, "Action %s is performed by %s not %s",
3127
3130 FALSE, "Action %s is against %s not %s",
3135
3137
3139 /* No point in continuing. */
3140 return FALSE;
3141 }
3142
3144 &(const struct req_context) {
3145 .player = unit_owner(actor_unit),
3146 .city = tile_city(actor_tile),
3147 .tile = actor_tile,
3148 .unit = actor_unit,
3149 .unittype = unit_type_get(actor_unit),
3150 },
3151 &(const struct req_context) {
3152 .player = unit_owner(target_unit),
3155 .unit = target_unit,
3156 .unittype = unit_type_get(target_unit),
3157 },
3158 NULL,
3159 actor_home);
3160}
3161
3162/**********************************************************************/
3178
3179/**********************************************************************/
3185static bool
3188 const struct unit *actor_unit,
3189 const struct city *actor_home,
3190 const struct tile *actor_tile,
3191 const struct tile *target_tile)
3192{
3193 const struct req_context *actor_ctxt;
3194
3195 if (actor_unit == NULL || target_tile == NULL
3196 || unit_list_size(target_tile->units) == 0) {
3197 /* Can't do an action when actor or target are missing. */
3198 return FALSE;
3199 }
3200
3202 FALSE, "Action %s is performed by %s not %s",
3207
3210 FALSE, "Action %s is against %s not %s",
3215
3217
3219 /* No point in continuing. */
3220 return FALSE;
3221 }
3222
3223 actor_ctxt = &(const struct req_context) {
3224 .player = unit_owner(actor_unit),
3225 .city = tile_city(actor_tile),
3226 .tile = actor_tile,
3227 .unit = actor_unit,
3228 .unittype = unit_type_get(actor_unit),
3229 };
3230
3233 &(const struct req_context) {
3234 .player = unit_owner(target_unit),
3237 .unit = target_unit,
3238 .unittype = unit_type_get(target_unit),
3239 },
3240 NULL, actor_home)) {
3241 /* One unit makes it impossible for all units. */
3242 return FALSE;
3243 }
3245
3246 /* Not impossible for any of the units at the tile. */
3247 return TRUE;
3248}
3249
3250/**********************************************************************/
3266
3267/**********************************************************************/
3273static bool
3276 const struct unit *actor_unit,
3277 const struct city *actor_home,
3278 const struct tile *actor_tile,
3279 const struct tile *target_tile,
3280 const struct extra_type *target_extra)
3281{
3282 if (actor_unit == NULL || target_tile == NULL) {
3283 /* Can't do an action when actor or target are missing. */
3284 return FALSE;
3285 }
3286
3288 FALSE, "Action %s is performed by %s not %s",
3293
3296 FALSE, "Action %s is against %s not %s",
3301
3303
3305 /* No point in continuing. */
3306 return FALSE;
3307 }
3308
3310 &(const struct req_context) {
3311 .player = unit_owner(actor_unit),
3312 .city = tile_city(actor_tile),
3313 .tile = actor_tile,
3314 .unit = actor_unit,
3315 .unittype = unit_type_get(actor_unit),
3316 },
3317 &(const struct req_context) {
3318 .player = tile_owner(target_tile),
3319 .city = tile_city(target_tile),
3320 .tile = target_tile,
3321 },
3323 actor_home);
3324}
3325
3326/**********************************************************************/
3334 const struct unit *actor_unit,
3335 const struct tile *target_tile,
3336 const struct extra_type *target_extra)
3337{
3342}
3343
3344/**********************************************************************/
3350static bool
3353 const struct unit *actor_unit,
3354 const struct city *actor_home,
3355 const struct tile *actor_tile,
3356 const struct tile *target_tile,
3357 const struct extra_type *target_extra)
3358{
3359 if (actor_unit == NULL || target_tile == NULL) {
3360 /* Can't do an action when actor or target are missing. */
3361 return FALSE;
3362 }
3363
3365 FALSE, "Action %s is performed by %s not %s",
3370
3373 FALSE, "Action %s is against %s not %s",
3378
3380
3382 /* No point in continuing. */
3383 return FALSE;
3384 }
3385
3387 &(const struct req_context) {
3388 .player = unit_owner(actor_unit),
3389 .city = tile_city(actor_tile),
3390 .tile = actor_tile,
3391 .unit = actor_unit,
3392 .unittype = unit_type_get(actor_unit),
3393 },
3394 &(const struct req_context) {
3395 .player = target_tile->extras_owner,
3396 .city = tile_city(target_tile),
3397 .tile = target_tile,
3398 },
3400 actor_home);
3401}
3402
3403/**********************************************************************/
3420
3421/**********************************************************************/
3428static bool
3431 const struct unit *actor_unit,
3432 const struct city *actor_home,
3433 const struct tile *actor_tile)
3434{
3435 if (actor_unit == NULL) {
3436 /* Can't do an action when the actor is missing. */
3437 return FALSE;
3438 }
3439
3441 FALSE, "Action %s is performed by %s not %s",
3446
3449 FALSE, "Action %s is against %s not %s",
3454
3456
3458 /* No point in continuing. */
3459 return FALSE;
3460 }
3461
3463 &(const struct req_context) {
3464 .player = unit_owner(actor_unit),
3465 .city = tile_city(actor_tile),
3466 .tile = actor_tile,
3467 .unit = actor_unit,
3468 .unittype = unit_type_get(actor_unit),
3469 },
3470 NULL, NULL,
3471 actor_home);
3472}
3473
3474/**********************************************************************/
3489
3490/**********************************************************************/
3496 const struct player *actor_plr)
3497{
3499 &(const struct req_context) {
3500 .player = actor_plr,
3501 },
3502 nullptr, nullptr, nullptr);
3503}
3504
3505/**********************************************************************/
3523static enum fc_tristate
3525 const struct req_context *actor,
3526 const struct req_context *target)
3527{
3528 enum fc_tristate current;
3529 enum fc_tristate result;
3530
3531 if (actor == NULL || actor->player == NULL) {
3532 /* Need actor->player for point of view */
3533 return TRI_MAYBE;
3534 }
3535
3536 if (target == NULL) {
3537 target = req_context_empty();
3538 }
3539
3540 result = TRI_NO;
3542 enabler) {
3543 current = fc_tristate_and(mke_eval_reqs(actor->player,
3544 actor, target,
3545 &enabler->actor_reqs,
3546 RPT_CERTAIN),
3547 mke_eval_reqs(actor->player,
3548 target, actor,
3549 &enabler->target_reqs,
3550 RPT_CERTAIN));
3551 if (current == TRI_YES) {
3552 return TRI_YES;
3553 } else if (current == TRI_MAYBE) {
3554 result = TRI_MAYBE;
3555 }
3557
3558 return result;
3559}
3560
3561/**********************************************************************/
3571static bool is_effect_val_known(enum effect_type effect_type,
3572 const struct player *pov_player,
3573 const struct req_context *context,
3574 const struct req_context *other_context)
3575{
3576 effect_list_iterate(get_effects(effect_type), peffect) {
3578 &(peffect->reqs), RPT_CERTAIN)) {
3579 return FALSE;
3580 }
3582
3583 return TRUE;
3584}
3585
3586/**********************************************************************/
3589static enum fc_tristate
3617
3618/**********************************************************************/
3627 const struct unit *pdefender)
3628{
3629 /* Keep unconverted until the end to avoid scaling each step */
3630 int chance;
3631 struct act_prob out;
3632
3633 /* Superspy always win */
3635 /* A defending UTYF_SUPERSPY will defeat every possible attacker. */
3636 return ACTPROB_IMPOSSIBLE;
3637 }
3639 /* An attacking UTYF_SUPERSPY will defeat every possible defender
3640 * except another UTYF_SUPERSPY. */
3641 return ACTPROB_CERTAIN;
3642 }
3643
3644 /* Base chance is 50% */
3645 chance = 50;
3646
3647 /* Spy attack bonus */
3649 chance += 25;
3650 }
3651
3652 /* Spy defense bonus */
3654 chance -= 25;
3655 }
3656
3657 /* Veteran attack and defense bonus */
3658 {
3659 const struct veteran_level *vatt
3661 const struct veteran_level *vdef
3663
3664 chance += vatt->power_fact - vdef->power_fact;
3665 }
3666
3667 /* Defense bonus. */
3668 {
3669 const struct req_context defender_ctxt = {
3670 .player = tile_owner(pdefender->tile),
3671 .city = tile_city(pdefender->tile),
3672 .tile = pdefender->tile,
3673 };
3676 NULL)) {
3677 return ACTPROB_NOT_KNOWN;
3678 }
3679
3680 /* Reduce the chance of an attack by EFT_SPY_RESISTANT percent. */
3682 NULL,
3684 NULL,
3686 ) / 100;
3687 }
3688
3689 chance = CLIP(0, chance, 100);
3690
3691 /* Convert to action probability */
3694
3695 return out;
3696}
3697
3698/**********************************************************************/
3704 const struct unit *pvictim,
3705 const struct tile *tgt_tile,
3706 const struct action *paction)
3707{
3708 struct unit *pdefender;
3709
3711 tgt_tile)) {
3712 /* Don't leak information about unseen defenders. */
3713 return ACTPROB_NOT_KNOWN;
3714 }
3715
3717 paction);
3718
3719 if (pdefender) {
3720 /* There will be a diplomatic battle instead of an action. */
3722 };
3723
3724 /* No diplomatic battle will occur. */
3725 return ACTPROB_CERTAIN;
3726}
3727
3728/**********************************************************************/
3732 action_id act_id,
3733 const struct unit *actor_unit)
3734{
3736 /* Unknown because the target is unseen. */
3737 return ACTPROB_NOT_KNOWN;
3738 } else {
3739 /* The actor it self can't do this. */
3740 return ACTPROB_IMPOSSIBLE;
3741 }
3742}
3743
3744/**********************************************************************/
3748static struct act_prob
3750 const struct unit *act_unit,
3751 const struct city *tgt_city,
3752 const struct player *tgt_player,
3753 const struct action *paction)
3754{
3756 &(const struct req_context) {
3757 .player = act_player,
3758 .city = tgt_city,
3759 .unit = act_unit,
3760 .unittype = unit_type_get(act_unit),
3761 },
3762 &(const struct req_context) {
3763 .player = tgt_player,
3764 })
3766 &(const struct req_context) {
3767 .player = tgt_player,
3768 .city = tgt_city,
3769 .unit = act_unit,
3770 },
3771 &(const struct req_context) {
3772 .player = act_player,
3773 })) {
3776 struct act_prob result = { .min = unconverted * ACTPROB_VAL_1_PCT,
3777 .max = unconverted * ACTPROB_VAL_1_PCT };
3778
3779 return result;
3780 } else {
3781 /* Could be improved to return a more exact probability in some cases.
3782 * Example: The player has enough information to know that the
3783 * probability always will be above 25% and always under 75% because
3784 * the only effect with unknown requirements that may apply adds (or
3785 * subtracts) 50% while all the requirements of the other effects that
3786 * may apply are known. */
3787 return ACTPROB_NOT_KNOWN;
3788 }
3789}
3790
3791/**********************************************************************/
3796static struct act_prob
3798 const struct unit *act_unit,
3799 const struct city *tgt_city,
3800 const struct unit *tgt_unit,
3801 const struct tile *tgt_tile,
3802 const struct player *tgt_player,
3803 const struct action *paction)
3804{
3805 struct act_prob battle;
3806 struct act_prob dice_roll;
3807
3808 battle = ACTPROB_CERTAIN;
3809 switch (actres_get_battle_kind(paction->result)) {
3810 case ABK_NONE:
3811 /* No pre action battle. */
3812 break;
3813 case ABK_DIPLOMATIC:
3815 paction);
3816 break;
3817 case ABK_STANDARD:
3818 /* Not supported here yet. Implement when users appear. */
3820 break;
3821 case ABK_COUNT:
3823 break;
3824 }
3825
3828 paction);
3829
3830 return action_prob_and(&battle, &dice_roll);
3831}
3832
3833/**********************************************************************/
3844static struct act_prob
3847 const struct req_context *actor,
3848 const struct city *actor_home,
3849 const struct req_context *target,
3850 const struct extra_type *target_extra)
3851{
3852 enum fc_tristate known;
3853 struct act_prob chance;
3855
3856 if (actor == NULL) {
3858 }
3859 if (target == NULL) {
3860 target = req_context_empty();
3861 }
3862
3863 known = is_action_possible(nmap, wanted_action, actor, target,
3865 FALSE, actor_home);
3866
3867 if (known == TRI_NO) {
3868 /* The action enablers are irrelevant since the action it self is
3869 * impossible. */
3870 return ACTPROB_IMPOSSIBLE;
3871 }
3872
3874
3875 known = fc_tristate_and(known,
3877 actor, target));
3878
3879 switch (paction->result) {
3880 case ACTRES_SPY_POISON:
3881 /* All uncertainty comes from potential diplomatic battles and the
3882 * (diplchance server setting and the) Action_Odds_Pct effect controlled
3883 * dice roll before the action. */
3885 target->city, target->unit,
3886 target->tile, target->player,
3887 paction);
3888 break;
3890 /* TODO */
3891 break;
3893 /* TODO */
3894 break;
3895 case ACTRES_STEAL_MAPS:
3896 /* TODO */
3897 break;
3899 /* All uncertainty comes from potential diplomatic battles. */
3900 chance = ap_diplomat_battle(actor->unit, target->unit, target->tile,
3901 paction);
3902 break;
3905 /* All uncertainty comes from potential diplomatic battles. */
3906 chance = ap_diplomat_battle(actor->unit, target->unit, target->tile,
3907 paction);
3908 break;
3909 case ACTRES_SPY_ATTACK:
3910 /* All uncertainty comes from potential diplomatic battles. */
3911 chance = ap_diplomat_battle(actor->unit, NULL, target->tile,
3912 paction);
3913 break;
3915 /* TODO */
3916 break;
3918 /* TODO */
3919 break;
3921 /* TODO */
3922 break;
3924 /* TODO */
3925 break;
3928 break;
3930 /* Do the victim have anything worth taking? */
3931 known = fc_tristate_and(known,
3932 tech_can_be_stolen(actor->player,
3933 target->player));
3934
3935 /* TODO: Calculate actual chance */
3936
3937 break;
3939 /* Do the victim have anything worth taking? */
3940 known = fc_tristate_and(known,
3941 tech_can_be_stolen(actor->player,
3942 target->player));
3943
3944 /* TODO: Calculate actual chance */
3945
3946 break;
3948 /* There is no risk that the city won't get investigated. */
3950 break;
3951 case ACTRES_SPY_ESCAPE:
3952 /* TODO */
3953 break;
3954 case ACTRES_TRADE_ROUTE:
3955 /* TODO */
3956 break;
3957 case ACTRES_MARKETPLACE:
3958 /* Possible when not blocked by is_action_possible() */
3960 break;
3961 case ACTRES_HELP_WONDER:
3962 /* Possible when not blocked by is_action_possible() */
3964 break;
3966 /* No battle is fought first. */
3968 break;
3969 case ACTRES_EXPEL_UNIT:
3970 /* No battle is fought first. */
3972 break;
3973 case ACTRES_BOMBARD:
3974 /* No battle is fought first. */
3976 break;
3977 case ACTRES_FOUND_CITY:
3978 /* Possible when not blocked by is_action_possible() */
3980 break;
3981 case ACTRES_JOIN_CITY:
3982 /* Possible when not blocked by is_action_possible() */
3984 break;
3985 case ACTRES_SPY_NUKE:
3986 /* All uncertainty comes from potential diplomatic battles and the
3987 * (diplchance server setting and the) Action_Odds_Pct effect controlled
3988 * dice roll before the action. */
3990 target->city, target->unit,
3991 target->tile,
3992 target->player,
3993 paction);
3994 break;
3995 case ACTRES_NUKE:
3996 /* TODO */
3997 break;
3998 case ACTRES_NUKE_UNITS:
3999 /* TODO */
4000 break;
4002 /* No battle is fought first. */
4004 break;
4006 /* No battle is fought first. */
4008 break;
4010 /* No battle is fought first. */
4012 break;
4013 case ACTRES_HOME_CITY:
4014 /* No battle is fought first. */
4016 break;
4017 case ACTRES_HOMELESS:
4018 /* No battle is fought first. */
4020 break;
4022 /* No battle is fought first. */
4024 break;
4025 case ACTRES_PARADROP:
4027 /* TODO */
4028 break;
4029 case ACTRES_AIRLIFT:
4030 /* Possible when not blocked by is_action_possible() */
4032 break;
4033 case ACTRES_ATTACK:
4035 {
4036 struct unit *defender_unit = get_defender(nmap, actor->unit,
4037 target->tile, paction);
4038
4039 if (can_player_see_unit(actor->player, defender_unit)) {
4040 double unconverted = unit_win_chance(nmap, actor->unit,
4042
4044 floor((double)ACTPROB_VAL_MAX * unconverted));
4046 ceil((double)ACTPROB_VAL_MAX * unconverted));
4047 } else if (known == TRI_YES) {
4048 known = TRI_MAYBE;
4049 }
4050 }
4051 break;
4052 case ACTRES_WIPE_UNITS:
4054 break;
4056 /* TODO: not implemented yet because:
4057 * - dice roll 100% * Action_Odds_Pct could be handled with
4058 * action_prob_pre_action_dice_roll().
4059 * - sub target building may be missing. May be missing without player
4060 * knowledge if it isn't visible. See is_improvement_visible() and
4061 * can_player_see_city_internals(). */
4062 break;
4064 /* All uncertainty comes from the (diplchance server setting and the)
4065 * Action_Odds_Pct effect controlled dice roll before the action. */
4067 target->city, target->player,
4068 paction);
4069 break;
4071 /* No battle is fought first. */
4073 break;
4075 /* No battle is fought first. */
4077 break;
4078 case ACTRES_HEAL_UNIT:
4079 /* No battle is fought first. */
4081 break;
4083 case ACTRES_CULTIVATE:
4084 case ACTRES_PLANT:
4085 case ACTRES_PILLAGE:
4086 case ACTRES_CLEAN:
4087 case ACTRES_FORTIFY:
4088 case ACTRES_ROAD:
4089 case ACTRES_CONVERT:
4090 case ACTRES_BASE:
4091 case ACTRES_MINE:
4092 case ACTRES_IRRIGATE:
4094 break;
4097 break;
4100 break;
4103 break;
4106 break;
4109 break;
4112 break;
4113 case ACTRES_HUT_ENTER:
4115 /* Entering the hut happens with a probability of 100%. What happens
4116 * next is probably up to dice rolls in Lua. */
4118 break;
4119 case ACTRES_UNIT_MOVE:
4120 case ACTRES_TELEPORT:
4123 break;
4124 /* Not UI action, so chance is meaningless */
4127 break;
4128 case ACTRES_NONE:
4129 /* Accommodate ruleset authors that wishes to roll the dice in Lua.
4130 * Would be ACTPROB_CERTAIN if not for that. */
4131 /* TODO: maybe allow the ruleset author to give a probability from
4132 * Lua? */
4134 break;
4135 }
4136
4137 /* Non signal action probabilities should be in range. */
4139 || chance.max <= ACTPROB_VAL_MAX),
4140 chance.max = ACTPROB_VAL_MAX);
4142 || chance.min >= ACTPROB_VAL_MIN),
4143 chance.min = ACTPROB_VAL_MIN);
4144
4145 switch (known) {
4146 case TRI_NO:
4147 return ACTPROB_IMPOSSIBLE;
4148 break;
4149 case TRI_MAYBE:
4150 return ACTPROB_NOT_KNOWN;
4151 break;
4152 case TRI_YES:
4153 return chance;
4154 break;
4155 };
4156
4157 fc_assert_msg(FALSE, "Should be yes, maybe or no");
4158
4160}
4161
4162/**********************************************************************/
4166static struct act_prob
4168 const struct unit *actor_unit,
4169 const struct city *actor_home,
4170 const struct tile *actor_tile,
4171 const action_id act_id,
4172 const struct city *target_city)
4173{
4174 const struct impr_type *target_building;
4175 const struct unit_type *target_utype;
4176 const struct action *act = action_by_number(act_id);
4177
4178 if (actor_unit == NULL || target_city == NULL) {
4179 /* Can't do an action when actor or target are missing. */
4180 return ACTPROB_IMPOSSIBLE;
4181 }
4182
4185 "Action %s is performed by %s not %s",
4186 action_id_rule_name(act_id),
4188 action_id_get_actor_kind(act_id)),
4190
4193 "Action %s is against %s not %s",
4194 action_id_rule_name(act_id),
4198
4200
4201 if (!unit_can_do_action(actor_unit, act_id)) {
4202 /* No point in continuing. */
4203 return ACTPROB_IMPOSSIBLE;
4204 }
4205
4206 /* Doesn't leak information about city position since an unknown city
4207 * can't be targeted and a city can't move. */
4208 if (!action_id_distance_accepted(act_id,
4211 /* No point in continuing. */
4212 return ACTPROB_IMPOSSIBLE;
4213 }
4214
4215 /* Doesn't leak information since it must be 100% certain from the
4216 * player's perspective that the blocking action is legal. */
4219 /* Don't offer to perform an action known to be blocked. */
4220 return ACTPROB_IMPOSSIBLE;
4221 }
4222
4224 /* The invisible city at this tile may, as far as the player knows, not
4225 * exist anymore. */
4226 return act_prob_unseen_target(nmap, act_id, actor_unit);
4227 }
4228
4231
4232 return action_prob(nmap, act_id,
4233 &(const struct req_context) {
4234 .player = unit_owner(actor_unit),
4235 .city = tile_city(actor_tile),
4236 .tile = actor_tile,
4237 .unit = actor_unit,
4238 .unittype = unit_type_get(actor_unit),
4239 },
4240 actor_home,
4241 &(const struct req_context) {
4242 .player = city_owner(target_city),
4243 .city = target_city,
4244 .building = target_building,
4246 .unittype = target_utype,
4247 }, NULL);
4248}
4249
4250/**********************************************************************/
4255 const struct unit *actor_unit,
4256 const action_id act_id,
4257 const struct city *target_city)
4258{
4262 act_id, target_city);
4263}
4264
4265/**********************************************************************/
4269static struct act_prob
4271 const struct unit *actor_unit,
4272 const struct city *actor_home,
4273 const struct tile *actor_tile,
4274 const action_id act_id,
4275 const struct unit *target_unit)
4276{
4277 if (actor_unit == NULL || target_unit == NULL) {
4278 /* Can't do an action when actor or target are missing. */
4279 return ACTPROB_IMPOSSIBLE;
4280 }
4281
4284 "Action %s is performed by %s not %s",
4285 action_id_rule_name(act_id),
4287 action_id_get_actor_kind(act_id)),
4289
4292 "Action %s is against %s not %s",
4293 action_id_rule_name(act_id),
4297
4299
4300 if (!unit_can_do_action(actor_unit, act_id)) {
4301 /* No point in continuing. */
4302 return ACTPROB_IMPOSSIBLE;
4303 }
4304
4305 /* Doesn't leak information about unit position since an unseen unit can't
4306 * be targeted. */
4307 if (!action_id_distance_accepted(act_id,
4310 /* No point in continuing. */
4311 return ACTPROB_IMPOSSIBLE;
4312 }
4313
4314 return action_prob(nmap, act_id,
4315 &(const struct req_context) {
4316 .player = unit_owner(actor_unit),
4317 .city = tile_city(actor_tile),
4318 .tile = actor_tile,
4319 .unit = actor_unit,
4320 .unittype = unit_type_get(actor_unit),
4321 },
4322 actor_home,
4323 &(const struct req_context) {
4324 .player = unit_owner(target_unit),
4327 .unit = target_unit,
4328 .unittype = unit_type_get(target_unit),
4329 },
4330 NULL);
4331}
4332
4333/**********************************************************************/
4338 const struct unit *actor_unit,
4339 const action_id act_id,
4340 const struct unit *target_unit)
4341{
4345 act_id,
4346 target_unit);
4347}
4348
4349/**********************************************************************/
4353static struct act_prob
4355 const struct unit *actor_unit,
4356 const struct city *actor_home,
4357 const struct tile *actor_tile,
4358 const action_id act_id,
4359 const struct tile *target_tile)
4360{
4361 struct act_prob prob_all;
4362 const struct req_context *actor_ctxt;
4363 const struct action *act = action_by_number(act_id);
4364
4365 if (actor_unit == NULL || target_tile == NULL) {
4366 /* Can't do an action when actor or target are missing. */
4367 return ACTPROB_IMPOSSIBLE;
4368 }
4369
4372 "Action %s is performed by %s not %s",
4373 action_id_rule_name(act_id),
4375 action_id_get_actor_kind(act_id)),
4377
4380 "Action %s is against %s not %s",
4381 action_id_rule_name(act_id),
4385
4387
4388 if (!unit_can_do_action(actor_unit, act_id)) {
4389 /* No point in continuing. */
4390 return ACTPROB_IMPOSSIBLE;
4391 }
4392
4393 /* Doesn't leak information about unit stack position since it is
4394 * specified as a tile and an unknown tile's position is known. */
4395 if (!action_id_distance_accepted(act_id,
4397 target_tile))) {
4398 /* No point in continuing. */
4399 return ACTPROB_IMPOSSIBLE;
4400 }
4401
4402 /* Doesn't leak information since the actor player can see the target
4403 * tile. */
4407 act_id,
4408 CITYT_CENTER, TRUE)) {
4409 /* Don't offer to perform actions that never can target a unit stack in
4410 * a city. */
4411 return ACTPROB_IMPOSSIBLE;
4412 }
4413
4414 /* Doesn't leak information since it must be 100% certain from the
4415 * player's perspective that the blocking action is legal. */
4419 target_unit)) {
4420 /* Don't offer to perform an action known to be blocked. */
4421 return ACTPROB_IMPOSSIBLE;
4422 }
4424
4425 /* Must be done here since an empty unseen tile will result in
4426 * ACTPROB_IMPOSSIBLE. */
4427 if (unit_list_size(target_tile->units) == 0) {
4428 /* Can't act against an empty tile. */
4429
4431 target_tile)) {
4432 /* Known empty tile. */
4433 return ACTPROB_IMPOSSIBLE;
4434 } else {
4435 /* The player doesn't know that the tile is empty. */
4436 return act_prob_unseen_target(nmap, act_id, actor_unit);
4437 }
4438 }
4439
4446 /* Hard coded rule: can't "Bombard", "Suicide Attack", or "Attack"
4447 * units in non enemy cities. */
4448 return ACTPROB_IMPOSSIBLE;
4449 }
4450
4457 /* Hard coded rule: can't "Nuke Units", "Wipe Units", "Suicide Attack",
4458 * or "Attack" units on non native tile without "AttackNonNative" and
4459 * not "Only_Native_Attack". */
4460 return ACTPROB_IMPOSSIBLE;
4461 }
4462
4463 /* Invisible units at this tile can make the action legal or illegal.
4464 * Invisible units can be stacked with visible units. The possible
4465 * existence of invisible units therefore makes the result uncertain. */
4469
4470 actor_ctxt = &(const struct req_context) {
4471 .player = unit_owner(actor_unit),
4472 .city = tile_city(actor_tile),
4473 .tile = actor_tile,
4474 .unit = actor_unit,
4475 .unittype = unit_type_get(actor_unit),
4476 };
4477
4479 struct act_prob prob_unit;
4480
4482 /* Only visible units are considered. The invisible units contributed
4483 * their uncertainty to prob_all above. */
4484 continue;
4485 }
4486
4488 &(const struct req_context) {
4489 .player = unit_owner(target_unit),
4492 .unit = target_unit,
4493 .unittype = unit_type_get(target_unit),
4494 },
4495 NULL);
4496
4498 /* One unit makes it impossible for all units. */
4499 return ACTPROB_IMPOSSIBLE;
4500 } else if (action_prob_not_impl(prob_unit)) {
4501 /* Not implemented dominates all except impossible. */
4503 } else {
4505 "Invalid probability [%d, %d]",
4506 prob_unit.min, prob_unit.max);
4507
4509 /* Special values dominate regular values. */
4510 continue;
4511 }
4512
4513 /* Probability against all target units considered until this moment
4514 * and the probability against this target unit. */
4515 prob_all.min = (prob_all.min * prob_unit.min) / ACTPROB_VAL_MAX;
4516 prob_all.max = (prob_all.max * prob_unit.max) / ACTPROB_VAL_MAX;
4517 break;
4518 }
4520
4521 /* Not impossible for any of the units at the tile. */
4522 return prob_all;
4523}
4524
4525/**********************************************************************/
4530 const struct unit *actor_unit,
4531 const action_id act_id,
4532 const struct tile *target_tile)
4533{
4537 act_id,
4538 target_tile);
4539}
4540
4541/**********************************************************************/
4545static struct act_prob
4547 const struct unit *actor_unit,
4548 const struct city *actor_home,
4549 const struct tile *actor_tile,
4550 const action_id act_id,
4551 const struct tile *target_tile,
4552 const struct extra_type *target_extra)
4553{
4554 if (actor_unit == NULL || target_tile == NULL) {
4555 /* Can't do an action when actor or target are missing. */
4556 return ACTPROB_IMPOSSIBLE;
4557 }
4558
4561 "Action %s is performed by %s not %s",
4562 action_id_rule_name(act_id),
4564 action_id_get_actor_kind(act_id)),
4566
4569 "Action %s is against %s not %s",
4570 action_id_rule_name(act_id),
4574
4576
4577 if (!unit_can_do_action(actor_unit, act_id)) {
4578 /* No point in continuing. */
4579 return ACTPROB_IMPOSSIBLE;
4580 }
4581
4582 /* Doesn't leak information about tile position since an unknown tile's
4583 * position is known. */
4584 if (!action_id_distance_accepted(act_id,
4586 target_tile))) {
4587 /* No point in continuing. */
4588 return ACTPROB_IMPOSSIBLE;
4589 }
4590
4591 return action_prob(nmap, act_id,
4592 &(const struct req_context) {
4593 .player = unit_owner(actor_unit),
4594 .city = tile_city(actor_tile),
4595 .tile = actor_tile,
4596 .unit = actor_unit,
4597 .unittype = unit_type_get(actor_unit),
4598 },
4599 actor_home,
4600 &(const struct req_context) {
4601 .player = tile_owner(target_tile),
4602 .city = tile_city(target_tile),
4603 .tile = target_tile,
4604 },
4605 target_extra);
4606}
4607
4608/**********************************************************************/
4613 const struct unit *actor_unit,
4614 const action_id act_id,
4615 const struct tile *target_tile,
4616 const struct extra_type *target_extra)
4617{
4621 act_id, target_tile, target_extra);
4622}
4623
4624/**********************************************************************/
4628static struct act_prob
4630 const struct unit *actor_unit,
4631 const struct city *actor_home,
4632 const struct tile *actor_tile,
4633 const action_id act_id,
4634 const struct tile *target_tile,
4635 const struct extra_type *target_extra)
4636{
4637 if (actor_unit == NULL || target_tile == NULL) {
4638 /* Can't do an action when actor or target are missing. */
4639 return ACTPROB_IMPOSSIBLE;
4640 }
4641
4644 "Action %s is performed by %s not %s",
4645 action_id_rule_name(act_id),
4647 action_id_get_actor_kind(act_id)),
4649
4652 "Action %s is against %s not %s",
4653 action_id_rule_name(act_id),
4657
4659
4660 if (!unit_can_do_action(actor_unit, act_id)) {
4661 /* No point in continuing. */
4662 return ACTPROB_IMPOSSIBLE;
4663 }
4664
4665 /* Doesn't leak information about tile position since an unknown tile's
4666 * position is known. */
4667 if (!action_id_distance_accepted(act_id,
4669 target_tile))) {
4670 /* No point in continuing. */
4671 return ACTPROB_IMPOSSIBLE;
4672 }
4673
4674 return action_prob(nmap, act_id,
4675 &(const struct req_context) {
4676 .player = unit_owner(actor_unit),
4677 .city = tile_city(actor_tile),
4678 .tile = actor_tile,
4679 .unit = actor_unit,
4680 .unittype = unit_type_get(actor_unit),
4681 },
4682 actor_home,
4683 &(const struct req_context) {
4684 .player = target_tile->extras_owner,
4685 .city = tile_city(target_tile),
4686 .tile = target_tile,
4687 },
4688 target_extra);
4689}
4690
4691/**********************************************************************/
4696 const struct unit *actor_unit,
4697 const action_id act_id,
4698 const struct tile *target_tile,
4699 const struct extra_type *target_extra)
4700{
4704 act_id, target_tile, target_extra);
4705}
4706
4707/**********************************************************************/
4711static struct act_prob
4713 const struct unit *actor_unit,
4714 const struct city *actor_home,
4715 const struct tile *actor_tile,
4716 const action_id act_id)
4717{
4718 if (actor_unit == NULL) {
4719 /* Can't do the action when the actor is missing. */
4720 return ACTPROB_IMPOSSIBLE;
4721 }
4722
4723 /* No point in checking distance to target. It is always 0. */
4724
4727 "Action %s is performed by %s not %s",
4728 action_id_rule_name(act_id),
4730 action_id_get_actor_kind(act_id)),
4732
4735 "Action %s is against %s not %s",
4736 action_id_rule_name(act_id),
4740
4742
4743 if (!unit_can_do_action(actor_unit, act_id)) {
4744 /* No point in continuing. */
4745 return ACTPROB_IMPOSSIBLE;
4746 }
4747
4748 return action_prob(nmap, act_id,
4749 &(const struct req_context) {
4750 .player = unit_owner(actor_unit),
4751 .city = tile_city(actor_tile),
4752 .tile = actor_tile,
4753 .unit = actor_unit,
4754 .unittype = unit_type_get(actor_unit),
4755 },
4756 actor_home,
4757 NULL,
4758 NULL);
4759}
4760
4761/**********************************************************************/
4766 const struct unit *actor_unit,
4767 const action_id act_id)
4768{
4772 act_id);
4773}
4774
4775/**********************************************************************/
4788 const struct action *paction,
4789 const struct unit *act_unit,
4790 const struct city *tgt_city,
4791 const struct unit *tgt_unit,
4792 const struct tile *tgt_tile,
4793 const struct extra_type *extra_tgt)
4794{
4795 /* Assume impossible until told otherwise. */
4796 struct act_prob prob = ACTPROB_IMPOSSIBLE;
4797
4800
4802 case ATK_STACK:
4803 if (tgt_tile) {
4805 }
4806 break;
4807 case ATK_TILE:
4808 if (tgt_tile) {
4810 }
4811 break;
4812 case ATK_EXTRAS:
4813 if (tgt_tile) {
4816 }
4817 break;
4818 case ATK_CITY:
4819 if (tgt_city) {
4821 }
4822 break;
4823 case ATK_UNIT:
4824 if (tgt_unit) {
4826 }
4827 break;
4828 case ATK_SELF:
4829 prob = action_prob_self(nmap, act_unit, paction->id);
4830 break;
4831 case ATK_COUNT:
4832 log_error("Invalid action target kind");
4833 break;
4834 }
4835
4836 return prob;
4837}
4838
4839/**********************************************************************/
4845 const action_id act_id,
4846 const struct unit *actor,
4847 const struct city *actor_home,
4848 const struct tile *actor_tile,
4849 const bool omniscient_cheat,
4850 const struct city* target)
4851{
4852 /* FIXME: some unit state requirements still depend on the actor unit's
4853 * current position rather than on actor_tile. Maybe this function should
4854 * return ACTPROB_NOT_IMPLEMENTED when one of those is detected and no
4855 * other requirement makes the action ACTPROB_IMPOSSIBLE? */
4856
4857 if (omniscient_cheat) {
4860 target)) {
4861 return ACTPROB_CERTAIN;
4862 } else {
4863 return ACTPROB_IMPOSSIBLE;
4864 }
4865 } else {
4866 /* FIXME: this branch result depends _directly_ on actor's position.
4867 * I.e., like, not adjacent, no action. Other branch ignores radius. */
4869 act_id, target);
4870 }
4871}
4872
4873/**********************************************************************/
4878struct act_prob
4880 action_id act_id,
4881 const struct unit *actor,
4882 const struct city *actor_home,
4883 const struct tile *actor_tile,
4884 bool omniscient_cheat,
4885 const struct unit *target)
4886{
4887 /* FIXME: some unit state requirements still depend on the actor unit's
4888 * current position rather than on actor_tile. Maybe this function should
4889 * return ACTPROB_NOT_IMPLEMENTED when one of those is detected and no
4890 * other requirement makes the action ACTPROB_IMPOSSIBLE? */
4891
4892 if (omniscient_cheat) {
4895 target)) {
4896 return ACTPROB_CERTAIN;
4897 } else {
4898 return ACTPROB_IMPOSSIBLE;
4899 }
4900 } else {
4902 act_id, target);
4903 }
4904}
4905
4906/**********************************************************************/
4911struct act_prob
4913 action_id act_id,
4914 const struct unit *actor,
4915 const struct city *actor_home,
4916 const struct tile *actor_tile,
4917 bool omniscient_cheat,
4918 const struct tile *target)
4919{
4920 /* FIXME: some unit state requirements still depend on the actor unit's
4921 * current position rather than on actor_tile. Maybe this function should
4922 * return ACTPROB_NOT_IMPLEMENTED when one of those is detected and no
4923 * other requirement makes the action ACTPROB_IMPOSSIBLE? */
4924
4925 if (omniscient_cheat) {
4928 target)) {
4929 return ACTPROB_CERTAIN;
4930 } else {
4931 return ACTPROB_IMPOSSIBLE;
4932 }
4933 } else {
4935 act_id, target);
4936 }
4937}
4938
4939/**********************************************************************/
4944struct act_prob
4946 action_id act_id,
4947 const struct unit *actor,
4948 const struct city *actor_home,
4949 const struct tile *actor_tile,
4950 bool omniscient_cheat,
4951 const struct tile *target_tile,
4952 const struct extra_type *target_extra)
4953{
4954 /* FIXME: some unit state requirements still depend on the actor unit's
4955 * current position rather than on actor_tile. Maybe this function should
4956 * return ACTPROB_NOT_IMPLEMENTED when one of those is detected and no
4957 * other requirement makes the action ACTPROB_IMPOSSIBLE? */
4958
4959 if (omniscient_cheat) {
4963 return ACTPROB_CERTAIN;
4964 } else {
4965 return ACTPROB_IMPOSSIBLE;
4966 }
4967 } else {
4969 act_id, target_tile, target_extra);
4970 }
4971}
4972
4973/**********************************************************************/
4978struct act_prob
4980 action_id act_id,
4981 const struct unit *actor,
4982 const struct city *actor_home,
4983 const struct tile *actor_tile,
4984 bool omniscient_cheat,
4985 const struct tile *target_tile,
4986 const struct extra_type *target_extra)
4987{
4988 /* FIXME: some unit state requirements still depend on the actor unit's
4989 * current position rather than on actor_tile. Maybe this function should
4990 * return ACTPROB_NOT_IMPLEMENTED when one of those is detected and no
4991 * other requirement makes the action ACTPROB_IMPOSSIBLE? */
4992
4993 if (omniscient_cheat) {
4997 return ACTPROB_CERTAIN;
4998 } else {
4999 return ACTPROB_IMPOSSIBLE;
5000 }
5001 } else {
5003 act_id, target_tile, target_extra);
5004 }
5005}
5006
5007/**********************************************************************/
5012struct act_prob
5014 action_id act_id,
5015 const struct unit *actor,
5016 const struct city *actor_home,
5017 const struct tile *actor_tile,
5018 bool omniscient_cheat)
5019{
5020 /* FIXME: some unit state requirements still depend on the actor unit's
5021 * current position rather than on actor_tile. Maybe this function should
5022 * return ACTPROB_NOT_IMPLEMENTED when one of those is detected and no
5023 * other requirement makes the action ACTPROB_IMPOSSIBLE? */
5024 if (omniscient_cheat) {
5027 return ACTPROB_CERTAIN;
5028 } else {
5029 return ACTPROB_IMPOSSIBLE;
5030 }
5031 } else {
5033 act_id);
5034 }
5035}
5036
5037/**********************************************************************/
5041{
5043
5044 return out;
5045}
5046
5047/**********************************************************************/
5051{
5053
5054 return out;
5055}
5056
5057/**********************************************************************/
5061{
5063
5064 return out;
5065}
5066
5067/**********************************************************************/
5071{
5073
5074 return out;
5075}
5076
5077/**********************************************************************/
5081{
5083
5084 return out;
5085}
5086
5087/**********************************************************************/
5092{
5093 return (ACTPROB_VAL_MIN < probability.max
5095}
5096
5097/**********************************************************************/
5102{
5103 return (ACTPROB_VAL_MAX == probability.min
5104 && ACTPROB_VAL_MAX == probability.max);
5105}
5106
5107/**********************************************************************/
5111static inline bool
5117
5118/**********************************************************************/
5122static inline bool
5124{
5125 return probability.min == ACTPROB_VAL_NOT_IMPL
5126 && probability.max == ACTPROB_VAL_MIN;
5127}
5128
5129/**********************************************************************/
5133static inline bool
5135{
5136 return probability.max < probability.min;
5137}
5138
5139/**********************************************************************/
5143 const struct act_prob *ap2)
5144{
5145 return ap1->min == ap2->min && ap1->max == ap2->max;
5146}
5147
5148/**********************************************************************/
5152 const struct act_prob ap2)
5153{
5154 struct act_prob my_ap1;
5155 struct act_prob my_ap2;
5156
5157 /* The action probabilities are real. */
5160
5161 /* Convert any signals to ACTPROB_NOT_KNOWN. */
5163 /* Assert that it is OK to convert the signal. */
5165
5167 } else {
5168 my_ap1 = ap1;
5169 }
5170
5172 /* Assert that it is OK to convert the signal. */
5174
5176 } else {
5177 my_ap2 = ap2;
5178 }
5179
5180 /* The action probabilities now have a comparison friendly form. */
5183
5184 /* Do the comparison. Start with min. Continue with max. */
5185 if (my_ap1.min < my_ap2.min) {
5186 return -1;
5187 } else if (my_ap1.min > my_ap2.min) {
5188 return 1;
5189 } else if (my_ap1.max < my_ap2.max) {
5190 return -1;
5191 } else if (my_ap1.max > my_ap2.max) {
5192 return 1;
5193 } else {
5194 return 0;
5195 }
5196}
5197
5198/**********************************************************************/
5203{
5204 struct act_prob my_ap;
5205
5206 /* The action probability is real. */
5208
5209 /* Convert any signals to ACTPROB_NOT_KNOWN. */
5211 /* Assert that it is OK to convert the signal. */
5213
5215 } else {
5216 my_ap = ap;
5217 }
5218
5219 /* The action probability now has a math friendly form. */
5221
5222 return (double)my_ap.min / (double) ACTPROB_VAL_MAX;
5223}
5224
5225/**********************************************************************/
5230 const struct act_prob *ap2)
5231{
5232 struct act_prob my_ap1;
5233 struct act_prob my_ap2;
5234 struct act_prob out;
5235
5236 /* The action probabilities are real. */
5239
5242 /* Keep the information rather than converting the signal to
5243 * ACTPROB_NOT_KNOWN. */
5244
5245 /* Assert that it is OK to convert the signal. */
5247
5248 out.min = ap1->min;
5249 out.max = ap2->max;
5250
5251 return out;
5252 }
5253
5254 /* Convert any signals to ACTPROB_NOT_KNOWN. */
5255 if (action_prob_is_signal(*ap1)) {
5256 /* Assert that it is OK to convert the signal. */
5258
5259 my_ap1.min = ACTPROB_VAL_MIN;
5260 my_ap1.max = ACTPROB_VAL_MAX;
5261 } else {
5262 my_ap1.min = ap1->min;
5263 my_ap1.max = ap1->max;
5264 }
5265
5266 if (action_prob_is_signal(*ap2)) {
5267 /* Assert that it is OK to convert the signal. */
5269
5270 my_ap2.min = ACTPROB_VAL_MIN;
5271 my_ap2.max = ACTPROB_VAL_MAX;
5272 } else {
5273 my_ap2.min = ap2->min;
5274 my_ap2.max = ap2->max;
5275 }
5276
5277 /* The action probabilities now have a math friendly form. */
5280
5281 /* Do the math. */
5282 out.min = (my_ap1.min * my_ap2.min) / ACTPROB_VAL_MAX;
5283 out.max = (my_ap1.max * my_ap2.max) / ACTPROB_VAL_MAX;
5284
5285 /* Cap at 100%. */
5286 out.min = MIN(out.min, ACTPROB_VAL_MAX);
5287 out.max = MIN(out.max, ACTPROB_VAL_MAX);
5288
5289 return out;
5290}
5291
5292/**********************************************************************/
5300 const struct act_prob *ap2)
5301{
5302 struct act_prob my_ap1;
5303 struct act_prob my_ap2;
5304 struct act_prob out;
5305
5306 /* The action probabilities are real. */
5309
5312 /* Keep the information rather than converting the signal to
5313 * ACTPROB_NOT_KNOWN. */
5314
5315 /* Assert that it is OK to convert the signal. */
5317
5318 out.min = ap1->min;
5319 out.max = ap2->max;
5320
5321 return out;
5322 }
5323
5324 /* Convert any signals to ACTPROB_NOT_KNOWN. */
5325 if (action_prob_is_signal(*ap1)) {
5326 /* Assert that it is OK to convert the signal. */
5328
5329 my_ap1.min = ACTPROB_VAL_MIN;
5330 my_ap1.max = ACTPROB_VAL_MAX;
5331 } else {
5332 my_ap1.min = ap1->min;
5333 my_ap1.max = ap1->max;
5334 }
5335
5336 if (action_prob_is_signal(*ap2)) {
5337 /* Assert that it is OK to convert the signal. */
5339
5340 my_ap2.min = ACTPROB_VAL_MIN;
5341 my_ap2.max = ACTPROB_VAL_MAX;
5342 } else {
5343 my_ap2.min = ap2->min;
5344 my_ap2.max = ap2->max;
5345 }
5346
5347 /* The action probabilities now have a math friendly form. */
5350
5351 /* Do the math. */
5352 out.min = my_ap1.min + (((ACTPROB_VAL_MAX - my_ap1.min) * my_ap2.min)
5353 / ACTPROB_VAL_MAX);
5354 out.max = my_ap1.max + (((ACTPROB_VAL_MAX - my_ap1.max) * my_ap2.max)
5355 / ACTPROB_VAL_MAX);
5356
5357 /* Cap at 100%. */
5358 out.min = MIN(out.min, ACTPROB_VAL_MAX);
5359 out.max = MIN(out.max, ACTPROB_VAL_MAX);
5360
5361 return out;
5362}
5363
5364/**********************************************************************/
5368{
5369 switch (actres_dice_type(paction->result)) {
5370 case DRT_DIPLCHANCE:
5372 /* Take the initial odds from the diplchance setting. */
5374 server_setting_by_name("diplchance"));
5375 }
5377 case DRT_CERTAIN:
5378 return 100;
5379 case DRT_NONE:
5380 break;
5381 }
5382
5383 /* The odds of the action not being stopped by its dice roll when the dice
5384 * isn't thrown is 100%. ACTION_ODDS_PCT_DICE_ROLL_NA is above 100% */
5386}
5387
5388/**********************************************************************/
5392 const struct unit *act_unit,
5393 const struct city *tgt_city,
5394 const struct player *tgt_player,
5395 const struct action *paction)
5396{
5398 const struct unit_type *actu_type = unit_type_get(act_unit);
5399
5400 fc_assert_action_msg(odds >= 0 && odds <= 100,
5401 odds = 100,
5402 "Bad initial odds for action number %d."
5403 " Does it roll the dice at all?",
5404 paction->id);
5405
5406 /* Let the Action_Odds_Pct effect modify the odds. The advantage of doing
5407 * it this way instead of rolling twice is that Action_Odds_Pct can
5408 * increase the odds. */
5409 odds = odds
5410 + ((odds
5412 &(const struct req_context) {
5413 .player = act_player,
5414 .city = tgt_city,
5415 .unit = act_unit,
5416 .unittype = actu_type,
5417 .action = paction,
5418 },
5419 &(const struct req_context) {
5420 .player = tgt_player,
5421 },
5423 / 100)
5424 - ((odds
5426 &(const struct req_context) {
5427 .player = tgt_player,
5428 .city = tgt_city,
5429 .unit = act_unit,
5430 .unittype = actu_type,
5431 .action = paction,
5432 },
5433 &(const struct req_context) {
5434 .player = act_player,
5435 },
5437 / 100);
5438
5439
5440 /* Odds are between 0% and 100%. */
5441 return CLIP(0, odds, 100);
5442}
5443
5444/**********************************************************************/
5448{
5449 struct action *paction = action_by_number(act);
5450
5451 /* Always immune since its not enabled. Doesn't count. */
5452 if (!action_is_in_use(paction)) {
5453 return FALSE;
5454 }
5455
5457 if (requirement_fulfilled_by_government(gov, &(enabler->target_reqs))) {
5458 return FALSE;
5459 }
5461
5462 return TRUE;
5463}
5464
5465/**********************************************************************/
5471 const struct player *actor_player,
5472 const struct req_context *target)
5473{
5475 enabler) {
5476 if (are_reqs_active(target,
5477 &(const struct req_context) {
5479 },
5480 &enabler->target_reqs, RPT_POSSIBLE)) {
5481 return TRUE;
5482 }
5484
5485 return FALSE;
5486}
5487
5488/**********************************************************************/
5492 const struct player *actor_player,
5493 const struct city* target_city)
5494{
5496 FALSE, "Action %s is against %s not cities",
5497 action_id_rule_name(act_id),
5499 action_id_get_target_kind(act_id)));
5500
5501 return is_target_possible(act_id, actor_player,
5502 &(const struct req_context) {
5503 .player = city_owner(target_city),
5504 .city = target_city,
5506 });
5507}
5508
5509/**********************************************************************/
5515 const action_id act_id,
5516 const struct unit *actor_unit)
5517{
5518 const struct player *actor_player = unit_owner(actor_unit);
5519 const struct req_context actor_ctxt = {
5521 .city = tile_city(unit_tile(actor_unit)),
5523 .unit = actor_unit,
5524 .unittype = unit_type_get(actor_unit),
5525 };
5526 const struct action *paction = action_by_number(act_id);
5527
5528 enum fc_tristate result;
5529
5531
5532 if (!utype_can_do_action(actor_unit->utype, act_id)) {
5533 /* The unit type can't perform the action. */
5534 return FALSE;
5535 }
5536
5539
5540 if (result == TRI_NO) {
5541 /* The hard requirements aren't fulfilled. */
5542 return FALSE;
5543 }
5544
5546 enabler) {
5547 const enum fc_tristate current
5549 &enabler->actor_reqs,
5550 /* Needed since no player to evaluate DiplRel
5551 * requirements against. */
5552 RPT_POSSIBLE);
5553
5554 if (current == TRI_YES
5555 || current == TRI_MAYBE) {
5556 /* The ruleset requirements may be fulfilled. */
5557 return TRUE;
5558 }
5560
5561 /* No action enabler allows this action. */
5562 return FALSE;
5563}
5564
5565/**********************************************************************/
5570 const action_id act_id)
5571{
5572 fc_assert(action_id_exists(act_id) || act_id == ACTION_ANY);
5573
5574 /* Check if full movement points may enable the specified action. */
5576 act_id,
5579 act_id,
5581}
5582
5583/**********************************************************************/
5608
5609/**********************************************************************/
5620{
5621 const struct action *paction = enabler_get_action(ae);
5622
5623 switch (action_get_actor_kind(paction)) {
5624 case AAK_UNIT:
5627 /* A possible actor unit type has been found. */
5628 return TRUE;
5629 }
5631
5632 /* No actor detected. */
5633 return FALSE;
5634 case AAK_COUNT:
5636 break;
5637 }
5638
5639 /* No actor detected. */
5640 return FALSE;
5641}
5642
5643/**********************************************************************/
5651{
5652 switch (action_get_actor_kind(paction)) {
5653 case AAK_UNIT:
5656 return TRUE;
5657 }
5659 break;
5660 case AAK_COUNT:
5662 break;
5663 }
5664
5665 /* No actor detected. */
5666 return FALSE;
5667}
5668
5669/**********************************************************************/
5677{
5679
5681 /* Hard requirements not fulfilled. */
5682 return FALSE;
5683 }
5684
5686
5688 /* If this iteration finds any entries, action is enabled. */
5689 return TRUE;
5691
5692 /* No non deleted action enabler. */
5693 return FALSE;
5694}
5695
5696/**********************************************************************/
5703{
5704 return paction != nullptr
5706}
5707
5708/**********************************************************************/
5718
5719/**********************************************************************/
5723{
5724 fc_assert_ret_val(num >= 0, NULL);
5726
5727 return &auto_perfs[num];
5728}
5729
5730/**********************************************************************/
5739{
5740 return action_auto_perf_slot_number(num);
5741}
5742
5743/**********************************************************************/
5747 struct universal *actor_uni,
5748 struct universal *target_uni)
5749{
5751 enab) {
5752 if ((actor_uni == NULL
5753 || universal_fulfills_requirements(FALSE, &(enab->actor_reqs),
5754 actor_uni))
5755 && (target_uni == NULL
5756 || universal_fulfills_requirements(FALSE, &(enab->target_reqs),
5757 target_uni))) {
5758 return TRUE;
5759 }
5761
5762 return FALSE;
5763}
5764
5765/**********************************************************************/
5771{
5773
5774 if (size < MAX_NUM_ACTIONS) {
5775 /* An action array is terminated by ACTION_NONE */
5777 }
5778}
5779
5780/**********************************************************************/
5788 int *position,
5789 enum action_result result)
5790{
5791 action_iterate(act) {
5792 struct action *paction = action_by_number(act);
5793 if (paction->result == result) {
5794 /* Assume one result for each action. */
5795 fc_assert_ret(*position < MAX_NUM_ACTIONS);
5796
5797 act_array[(*position)++] = paction->id;
5798 }
5800}
5801
5802/**********************************************************************/
5808{
5809 switch ((enum gen_action)act) {
5810 case ACTION_SPY_POISON:
5811 return "ui_name_poison_city";
5813 return "ui_name_poison_city_escape";
5815 return "ui_name_sabotage_unit";
5817 return "ui_name_sabotage_unit_escape";
5819 return "ui_name_bribe_unit";
5821 return "ui_name_bribe_stack";
5823 return "ui_name_sabotage_city";
5825 return "ui_name_sabotage_city_escape";
5827 return "ui_name_targeted_sabotage_city";
5829 return "ui_name_sabotage_city_production";
5831 return "ui_name_targeted_sabotage_city_escape";
5833 return "ui_name_sabotage_city_production_escape";
5835 return "ui_name_incite_city";
5837 return "ui_name_incite_city_escape";
5839 return "ui_name_establish_embassy";
5841 return "ui_name_establish_embassy_stay";
5843 return "ui_name_steal_tech";
5845 return "ui_name_steal_tech_escape";
5847 return "ui_name_targeted_steal_tech";
5849 return "ui_name_targeted_steal_tech_escape";
5851 return "ui_name_investigate_city";
5853 return "ui_name_investigate_city_spend_unit";
5855 return "ui_name_steal_gold";
5857 return "ui_name_steal_gold_escape";
5859 return "ui_name_spread_plague";
5860 case ACTION_STEAL_MAPS:
5861 return "ui_name_steal_maps";
5863 return "ui_name_steal_maps_escape";
5864 case ACTION_TRADE_ROUTE:
5865 return "ui_name_establish_trade_route";
5866 case ACTION_MARKETPLACE:
5867 return "ui_name_enter_marketplace";
5868 case ACTION_HELP_WONDER:
5869 return "ui_name_help_wonder";
5871 return "ui_name_capture_units";
5872 case ACTION_EXPEL_UNIT:
5873 return "ui_name_expel_unit";
5874 case ACTION_FOUND_CITY:
5875 return "ui_name_found_city";
5876 case ACTION_JOIN_CITY:
5877 return "ui_name_join_city";
5878 case ACTION_BOMBARD:
5879 return "ui_name_bombard";
5880 case ACTION_BOMBARD2:
5881 return "ui_name_bombard_2";
5882 case ACTION_BOMBARD3:
5883 return "ui_name_bombard_3";
5884 case ACTION_BOMBARD4:
5885 return "ui_name_bombard_4";
5887 return "ui_name_bombard_lethal";
5889 return "ui_name_bombard_lethal_2";
5890 case ACTION_SPY_NUKE:
5891 return "ui_name_suitcase_nuke";
5893 return "ui_name_suitcase_nuke_escape";
5894 case ACTION_NUKE:
5895 return "ui_name_explode_nuclear";
5896 case ACTION_NUKE_CITY:
5897 return "ui_name_nuke_city";
5898 case ACTION_NUKE_UNITS:
5899 return "ui_name_nuke_units";
5901 return "ui_name_destroy_city";
5903 return "ui_name_disband_unit_recover";
5905 return "ui_name_disband_unit";
5906 case ACTION_HOME_CITY:
5907 return "ui_name_home_city";
5908 case ACTION_HOMELESS:
5909 return "ui_name_homeless";
5911 return "ui_name_upgrade_unit";
5912 case ACTION_PARADROP:
5913 return "ui_name_paradrop_unit";
5915 return "ui_name_paradrop_unit_conquer";
5917 return "ui_name_paradrop_unit_frighten";
5919 return "ui_name_paradrop_unit_frighten_conquer";
5921 return "ui_name_paradrop_unit_enter";
5923 return "ui_name_paradrop_unit_enter_conquer";
5924 case ACTION_AIRLIFT:
5925 return "ui_name_airlift_unit";
5926 case ACTION_ATTACK:
5927 return "ui_name_attack";
5928 case ACTION_ATTACK2:
5929 return "ui_name_attack_2";
5931 return "ui_name_suicide_attack";
5933 return "ui_name_suicide_attack_2";
5934 case ACTION_WIPE_UNITS:
5935 return "ui_name_wipe_units";
5937 return "ui_name_collect_ransom";
5939 return "ui_name_surgical_strike_building";
5941 return "ui_name_surgical_strike_production";
5943 return "ui_name_conquer_city_shrink";
5945 return "ui_name_conquer_city_shrink2";
5947 return "ui_name_conquer_city_shrink3";
5949 return "ui_name_conquer_city_shrink4";
5951 return "ui_name_conquer_extras";
5953 return "ui_name_conquer_extras_2";
5955 return "ui_name_conquer_extras_3";
5957 return "ui_name_conquer_extras_4";
5958 case ACTION_HEAL_UNIT:
5959 return "ui_name_heal_unit";
5960 case ACTION_HEAL_UNIT2:
5961 return "ui_name_heal_unit_2";
5963 return "ui_name_transform_terrain";
5965 return "ui_name_transform_terrain_2";
5966 case ACTION_CULTIVATE:
5967 return "ui_name_cultivate";
5968 case ACTION_CULTIVATE2:
5969 return "ui_name_cultivate_2";
5970 case ACTION_PLANT:
5971 return "ui_name_plant";
5972 case ACTION_PLANT2:
5973 return "ui_name_plant_2";
5974 case ACTION_PILLAGE:
5975 return "ui_name_pillage";
5976 case ACTION_PILLAGE2:
5977 return "ui_name_pillage_2";
5978 case ACTION_CLEAN:
5979 return "ui_name_clean";
5980 case ACTION_CLEAN2:
5981 return "ui_name_clean_2";
5982 case ACTION_FORTIFY:
5983 return "ui_name_fortify";
5984 case ACTION_FORTIFY2:
5985 return "ui_name_fortify_2";
5986 case ACTION_ROAD:
5987 return "ui_name_build_road";
5988 case ACTION_ROAD2:
5989 return "ui_name_build_road_2";
5990 case ACTION_CONVERT:
5991 return "ui_name_convert_unit";
5992 case ACTION_BASE:
5993 return "ui_name_build_base";
5994 case ACTION_BASE2:
5995 return "ui_name_build_base_2";
5996 case ACTION_MINE:
5997 return "ui_name_build_mine";
5998 case ACTION_MINE2:
5999 return "ui_name_build_mine_2";
6000 case ACTION_IRRIGATE:
6001 return "ui_name_irrigate";
6002 case ACTION_IRRIGATE2:
6003 return "ui_name_irrigate_2";
6005 return "ui_name_transport_deboard";
6007 return "ui_name_transport_board";
6009 return "ui_name_transport_board_2";
6011 return "ui_name_transport_board_3";
6013 return "ui_name_transport_embark";
6015 return "ui_name_transport_embark_2";
6017 return "ui_name_transport_embark_3";
6019 return "ui_name_transport_embark_4";
6021 return "ui_name_transport_unload";
6023 return "ui_name_transport_load";
6025 return "ui_name_transport_load_2";
6027 return "ui_name_transport_load_3";
6029 return "ui_name_transport_disembark";
6031 return "ui_name_transport_disembark_2";
6033 return "ui_name_transport_disembark_3";
6035 return "ui_name_transport_disembark_4";
6036 case ACTION_HUT_ENTER:
6037 return "ui_name_enter_hut";
6038 case ACTION_HUT_ENTER2:
6039 return "ui_name_enter_hut_2";
6040 case ACTION_HUT_ENTER3:
6041 return "ui_name_enter_hut_3";
6042 case ACTION_HUT_ENTER4:
6043 return "ui_name_enter_hut_4";
6045 return "ui_name_frighten_hut";
6047 return "ui_name_frighten_hut_2";
6049 return "ui_name_frighten_hut_3";
6051 return "ui_name_frighten_hut_4";
6052 case ACTION_SPY_ATTACK:
6053 return "ui_name_spy_attack";
6054 case ACTION_UNIT_MOVE:
6055 return "ui_name_unit_move";
6056 case ACTION_UNIT_MOVE2:
6057 return "ui_name_unit_move_2";
6058 case ACTION_UNIT_MOVE3:
6059 return "ui_name_unit_move_3";
6060 case ACTION_TELEPORT:
6061 return "ui_name_teleport";
6062 case ACTION_TELEPORT2:
6063 return "ui_name_teleport_2";
6064 case ACTION_TELEPORT3:
6065 return "ui_name_teleport_3";
6067 return "ui_name_teleport_conquer";
6069 return "ui_name_teleport_frighten";
6071 return "ui_name_teleport_frighten_conquer";
6073 return "ui_name_teleport_enter";
6075 return "ui_name_teleport_enter_conquer";
6076 case ACTION_SPY_ESCAPE:
6077 return "ui_name_escape";
6079 return "ui_name_user_action_1";
6081 return "ui_name_user_action_2";
6083 return "ui_name_user_action_3";
6085 return "ui_name_user_action_4";
6087 case ACTION_ESCAPE:
6088 case ACTION_CIVIL_WAR:
6089 fc_assert(!action_id_is_internal(act)); /* Fail always */
6090 break;
6091 case ACTION_COUNT:
6092 break;
6093
6095 }
6096
6097 fc_assert(act >= 0 && act < ACTION_COUNT);
6098
6099 return NULL;
6100}
6101
6102/**********************************************************************/
6105const char *action_ui_name_default(int act)
6106{
6107 switch ((enum gen_action)act) {
6108 case ACTION_SPY_POISON:
6109 /* TRANS: _Poison City (3% chance of success). */
6110 return N_("%sPoison City%s");
6112 /* TRANS: _Poison City and Escape (3% chance of success). */
6113 return N_("%sPoison City and Escape%s");
6115 /* TRANS: S_abotage Enemy Unit (3% chance of success). */
6116 return N_("S%sabotage Enemy Unit%s");
6118 /* TRANS: S_abotage Enemy Unit and Escape (3% chance of success). */
6119 return N_("S%sabotage Enemy Unit and Escape%s");
6121 /* TRANS: Bribe Enemy _Unit (3% chance of success). */
6122 return N_("Bribe Enemy %sUnit%s");
6124 /* TRANS: Bribe Enemy _Stack (3% chance of success). */
6125 return N_("Bribe Enemy %sStack%s");
6127 /* TRANS: _Sabotage City (3% chance of success). */
6128 return N_("%sSabotage City%s");
6130 /* TRANS: _Sabotage City and Escape (3% chance of success). */
6131 return N_("%sSabotage City and Escape%s");
6133 /* TRANS: Industria_l Sabotage (3% chance of success). */
6134 return N_("Industria%sl Sabotage%s");
6136 /* TRANS: Industria_l Sabotage Production (3% chance of success). */
6137 return N_("Industria%sl Sabotage Production%s");
6139 /* TRANS: Industria_l Sabotage and Escape (3% chance of success). */
6140 return N_("Industria%sl Sabotage and Escape%s");
6142 /* TRANS: Industria_l Sabotage Production and Escape (3% chance of success). */
6143 return N_("Industria%sl Sabotage Production and Escape%s");
6145 /* TRANS: Incite a Re_volt (3% chance of success). */
6146 return N_("Incite a Re%svolt%s");
6148 /* TRANS: Incite a Re_volt and Escape (3% chance of success). */
6149 return N_("Incite a Re%svolt and Escape%s");
6151 /* TRANS: Establish _Embassy (100% chance of success). */
6152 return N_("Establish %sEmbassy%s");
6154 /* TRANS: Becom_e Ambassador (100% chance of success). */
6155 return N_("Becom%se Ambassador%s");
6157 /* TRANS: Steal _Technology (3% chance of success). */
6158 return N_("Steal %sTechnology%s");
6160 /* TRANS: Steal _Technology and Escape (3% chance of success). */
6161 return N_("Steal %sTechnology and Escape%s");
6163 /* TRANS: In_dustrial Espionage (3% chance of success). */
6164 return N_("In%sdustrial Espionage%s");
6166 /* TRANS: In_dustrial Espionage and Escape (3% chance of success). */
6167 return N_("In%sdustrial Espionage and Escape%s");
6169 /* TRANS: _Investigate City (100% chance of success). */
6170 return N_("%sInvestigate City%s");
6172 /* TRANS: _Investigate City (spends the unit) (100% chance of
6173 * success). */
6174 return N_("%sInvestigate City (spends the unit)%s");
6176 /* TRANS: Steal _Gold (100% chance of success). */
6177 return N_("Steal %sGold%s");
6179 /* TRANS: Steal _Gold and Escape (100% chance of success). */
6180 return N_("Steal %sGold and Escape%s");
6182 /* TRANS: Spread _Plague (100% chance of success). */
6183 return N_("Spread %sPlague%s");
6184 case ACTION_STEAL_MAPS:
6185 /* TRANS: Steal _Maps (100% chance of success). */
6186 return N_("Steal %sMaps%s");
6188 /* TRANS: Steal _Maps and Escape (100% chance of success). */
6189 return N_("Steal %sMaps and Escape%s");
6190 case ACTION_TRADE_ROUTE:
6191 /* TRANS: Establish Trade _Route (100% chance of success). */
6192 return N_("Establish Trade %sRoute%s");
6193 case ACTION_MARKETPLACE:
6194 /* TRANS: Enter _Marketplace (100% chance of success). */
6195 return N_("Enter %sMarketplace%s");
6196 case ACTION_HELP_WONDER:
6197 /* TRANS: Help _build Wonder (100% chance of success). */
6198 return N_("Help %sbuild Wonder%s");
6200 /* TRANS: _Capture Units (100% chance of success). */
6201 return N_("%sCapture Units%s");
6202 case ACTION_EXPEL_UNIT:
6203 /* TRANS: _Expel Unit (100% chance of success). */
6204 return N_("%sExpel Unit%s");
6205 case ACTION_FOUND_CITY:
6206 /* TRANS: _Found City (100% chance of success). */
6207 return N_("%sFound City%s");
6208 case ACTION_JOIN_CITY:
6209 /* TRANS: _Join City (100% chance of success). */
6210 return N_("%sJoin City%s");
6211 case ACTION_BOMBARD:
6212 /* TRANS: B_ombard (100% chance of success). */
6213 return N_("B%sombard%s");
6214 case ACTION_BOMBARD2:
6215 /* TRANS: B_ombard 2 (100% chance of success). */
6216 return N_("B%sombard 2%s");
6217 case ACTION_BOMBARD3:
6218 /* TRANS: B_ombard 3 (100% chance of success). */
6219 return N_("B%sombard 3%s");
6220 case ACTION_BOMBARD4:
6221 /* TRANS: B_ombard 4 (100% chance of success). */
6222 return N_("B%sombard 4%s");
6225 /* TRANS: Lethal B_ombard (100% chance of success). */
6226 return N_("Lethal B%sombard%s");
6227 case ACTION_SPY_NUKE:
6228 /* TRANS: Suitcase _Nuke (100% chance of success). */
6229 return N_("Suitcase %sNuke%s");
6231 /* TRANS: Suitcase _Nuke and Escape (100% chance of success). */
6232 return N_("Suitcase %sNuke and Escape%s");
6233 case ACTION_NUKE:
6234 /* TRANS: Explode _Nuclear (100% chance of success). */
6235 return N_("Explode %sNuclear%s");
6236 case ACTION_NUKE_CITY:
6237 /* TRANS: _Nuke City (100% chance of success). */
6238 return N_("%sNuke City%s");
6239 case ACTION_NUKE_UNITS:
6240 /* TRANS: _Nuke Units (100% chance of success). */
6241 return N_("%sNuke Units%s");
6243 /* TRANS: Destroy _City (100% chance of success). */
6244 return N_("Destroy %sCity%s");
6246 /* TRANS: Dis_band recovering production (100% chance of success). */
6247 return N_("Dis%sband recovering production%s");
6249 /* TRANS: Dis_band without recovering production (100% chance of success). */
6250 return N_("Dis%sband without recovering production%s");
6251 case ACTION_HOME_CITY:
6252 /* TRANS: Set _Home City (100% chance of success). */
6253 return N_("Set %sHome City%s");
6254 case ACTION_HOMELESS:
6255 /* TRANS: Make _Homeless (100% chance of success). */
6256 return N_("Make %sHomeless%s");
6258 /* TRANS: _Upgrade Unit (100% chance of success). */
6259 return N_("%sUpgrade Unit%s");
6260 case ACTION_PARADROP:
6261 /* TRANS: Drop _Paratrooper (100% chance of success). */
6262 return N_("Drop %sParatrooper%s");
6264 /* TRANS: Drop _Paratrooper (100% chance of success). */
6265 return N_("Drop %sParatrooper%s");
6267 /* TRANS: Drop _Paratrooper (100% chance of success). */
6268 return N_("Drop %sParatrooper%s");
6270 /* TRANS: Drop _Paratrooper (100% chance of success). */
6271 return N_("Drop %sParatrooper%s");
6273 /* TRANS: Drop _Paratrooper (100% chance of success). */
6274 return N_("Drop %sParatrooper%s");
6276 /* TRANS: Drop _Paratrooper (100% chance of success). */
6277 return N_("Drop %sParatrooper%s");
6278 case ACTION_AIRLIFT:
6279 /* TRANS: _Airlift to City (100% chance of success). */
6280 return N_("%sAirlift to City%s");
6281 case ACTION_ATTACK:
6282 case ACTION_ATTACK2:
6283 /* TRANS: _Attack (100% chance of success). */
6284 return N_("%sAttack%s");
6287 /* TRANS: _Suicide Attack (100% chance of success). */
6288 return N_("%sSuicide Attack%s");
6289 case ACTION_WIPE_UNITS:
6290 /* TRANS: _Wipe Units (100% chance of success). */
6291 return N_("%sWipe Units%s");
6293 /* TRANS: Collect _Ransom (100% chance of success). */
6294 return N_("Collect %sRansom%s");
6296 /* TRANS: Surgical Str_ike Building (100% chance of success). */
6297 return N_("Surgical Str%sike Building%s");
6299 /* TRANS: Surgical Str_ike Production (100% chance of success). */
6300 return N_("Surgical Str%sike Production%s");
6304 /* TRANS: _Conquer City (100% chance of success). */
6305 return N_("%sConquer City%s");
6307 /* TRANS: _Conquer City 2 (100% chance of success). */
6308 return N_("%sConquer City 2%s");
6312 /* TRANS: _Conquer Extras (100% chance of success). */
6313 return N_("%sConquer Extras%s");
6315 /* TRANS: _Conquer Extras 2 (100% chance of success). */
6316 return N_("%sConquer Extras 2%s");
6317 case ACTION_HEAL_UNIT:
6318 case ACTION_HEAL_UNIT2:
6319 /* TRANS: Heal _Unit (3% chance of success). */
6320 return N_("Heal %sUnit%s");
6323 /* TRANS: _Transform Terrain (3% chance of success). */
6324 return N_("%sTransform Terrain%s");
6325 case ACTION_CULTIVATE:
6326 case ACTION_CULTIVATE2:
6327 /* TRANS: Transform by _Cultivating (3% chance of success). */
6328 return N_("Transform by %sCultivating%s");
6329 case ACTION_PLANT:
6330 case ACTION_PLANT2:
6331 /* TRANS: Transform by _Planting (3% chance of success). */
6332 return N_("Transform by %sPlanting%s");
6333 case ACTION_PILLAGE:
6334 case ACTION_PILLAGE2:
6335 /* TRANS: Pilla_ge (100% chance of success). */
6336 return N_("Pilla%sge%s");
6337 case ACTION_CLEAN:
6338 case ACTION_CLEAN2:
6339 /* TRANS: Clean (100% chance of success). */
6340 return N_("%sClean%s");
6341 case ACTION_FORTIFY:
6342 case ACTION_FORTIFY2:
6343 /* TRANS: _Fortify (100% chance of success). */
6344 return N_("%sFortify%s");
6345 case ACTION_ROAD:
6346 case ACTION_ROAD2:
6347 /* TRANS: Build _Road (100% chance of success). */
6348 return N_("Build %sRoad%s");
6349 case ACTION_CONVERT:
6350 /* TRANS: _Convert Unit (100% chance of success). */
6351 return N_("%sConvert Unit%s");
6352 case ACTION_BASE:
6353 case ACTION_BASE2:
6354 /* TRANS: _Build Base (100% chance of success). */
6355 return N_("%sBuild Base%s");
6356 case ACTION_MINE:
6357 case ACTION_MINE2:
6358 /* TRANS: Build _Mine (100% chance of success). */
6359 return N_("Build %sMine%s");
6360 case ACTION_IRRIGATE:
6361 case ACTION_IRRIGATE2:
6362 /* TRANS: Build _Irrigation (100% chance of success). */
6363 return N_("Build %sIrrigation%s");
6365 /* TRANS: _Deboard (100% chance of success). */
6366 return N_("%sDeboard%s");
6370 /* TRANS: _Board (100% chance of success). */
6371 return N_("%sBoard%s");
6376 /* TRANS: _Embark (100% chance of success). */
6377 return N_("%sEmbark%s");
6379 /* TRANS: _Unload (100% chance of success). */
6380 return N_("%sUnload%s");
6384 /* TRANS: _Load (100% chance of success). */
6385 return N_("%sLoad%s");
6389 /* TRANS: _Disembark (100% chance of success). */
6390 return N_("%sDisembark%s");
6392 /* TRANS: _Disembark 2 (100% chance of success). */
6393 return N_("%sDisembark 2%s");
6394 case ACTION_SPY_ATTACK:
6395 /* TRANS: _Eliminate Diplomat (100% chance of success). */
6396 return N_("%sEliminate Diplomat%s");
6397 case ACTION_HUT_ENTER:
6398 case ACTION_HUT_ENTER2:
6399 case ACTION_HUT_ENTER3:
6400 case ACTION_HUT_ENTER4:
6401 /* TRANS: Enter _Hut (100% chance of success). */
6402 return N_("Enter %sHut%s");
6407 /* TRANS: Frighten _Hut (100% chance of success). */
6408 return N_("Frighten %sHut%s");
6409 case ACTION_UNIT_MOVE:
6410 case ACTION_UNIT_MOVE2:
6411 case ACTION_UNIT_MOVE3:
6412 /* TRANS: Regular _Move (100% chance of success). */
6413 return N_("Regular %sMove%s");
6414 case ACTION_TELEPORT:
6415 case ACTION_TELEPORT2:
6416 case ACTION_TELEPORT3:
6417 /* TRANS: _Teleport (100% chance of success). */
6418 return N_("%sTeleport%s");
6420 /* TRANS: _Teleport (100% chance of success). */
6421 return N_("%sTeleport%s");
6423 /* TRANS: _Teleport (100% chance of success). */
6424 return N_("%sTeleport%s");
6426 /* TRANS: _Teleport (100% chance of success). */
6427 return N_("%sTeleport%s");
6429 /* TRANS: _Teleport (100% chance of success). */
6430 return N_("%sTeleport%s");
6432 /* TRANS: _Teleport (100% chance of success). */
6433 return N_("%sTeleport%s");
6434 case ACTION_SPY_ESCAPE:
6435 /* TRANS: _Escape To Nearest City (100% chance of success). */
6436 return N_("%sEscape To Nearest City%s");
6438 /* TRANS: _User Action 1 (100% chance of success). */
6439 return N_("%sUser Action 1%s");
6441 /* TRANS: _User Action 2 (100% chance of success). */
6442 return N_("%sUser Action 2%s");
6444 /* TRANS: _User Action 3 (100% chance of success). */
6445 return N_("%sUser Action 3%s");
6447 /* TRANS: _User Action 4 (100% chance of success). */
6448 return N_("%sUser Action 4%s");
6450 return N_("%sGain Veterancy%s");
6451 case ACTION_ESCAPE:
6452 return N_("%sEscape%s");
6453 case ACTION_CIVIL_WAR:
6454 return N_("%sCivil War%s");
6455 case ACTION_COUNT:
6456 fc_assert(act != ACTION_COUNT);
6457 break;
6458 }
6459
6460 return NULL;
6461}
6462
6463/**********************************************************************/
6470{
6471 switch ((enum gen_action)act) {
6472 case ACTION_SPY_POISON:
6497 case ACTION_STEAL_MAPS:
6499 case ACTION_TRADE_ROUTE:
6500 case ACTION_MARKETPLACE:
6501 case ACTION_HELP_WONDER:
6503 case ACTION_EXPEL_UNIT:
6504 case ACTION_FOUND_CITY:
6505 case ACTION_JOIN_CITY:
6506 case ACTION_SPY_NUKE:
6511 case ACTION_HOME_CITY:
6512 case ACTION_HOMELESS:
6514 case ACTION_PARADROP:
6520 case ACTION_AIRLIFT:
6521 case ACTION_ATTACK:
6522 case ACTION_ATTACK2:
6525 case ACTION_WIPE_UNITS:
6533 case ACTION_HEAL_UNIT:
6534 case ACTION_HEAL_UNIT2:
6537 case ACTION_CULTIVATE:
6538 case ACTION_CULTIVATE2:
6539 case ACTION_PLANT:
6540 case ACTION_PLANT2:
6541 case ACTION_PILLAGE:
6542 case ACTION_PILLAGE2:
6543 case ACTION_CLEAN:
6544 case ACTION_CLEAN2:
6545 case ACTION_FORTIFY:
6546 case ACTION_FORTIFY2:
6547 case ACTION_ROAD:
6548 case ACTION_ROAD2:
6549 case ACTION_CONVERT:
6550 case ACTION_BASE:
6551 case ACTION_BASE2:
6552 case ACTION_MINE:
6553 case ACTION_MINE2:
6554 case ACTION_IRRIGATE:
6555 case ACTION_IRRIGATE2:
6572 case ACTION_BOMBARD:
6573 case ACTION_BOMBARD2:
6574 case ACTION_BOMBARD3:
6575 case ACTION_BOMBARD4:
6578 case ACTION_SPY_ATTACK:
6583 case ACTION_HUT_ENTER:
6584 case ACTION_HUT_ENTER2:
6585 case ACTION_HUT_ENTER3:
6586 case ACTION_HUT_ENTER4:
6591 case ACTION_UNIT_MOVE:
6592 case ACTION_UNIT_MOVE2:
6593 case ACTION_UNIT_MOVE3:
6594 case ACTION_SPY_ESCAPE:
6596 case ACTION_ESCAPE:
6597 case ACTION_CIVIL_WAR:
6598 /* Min range is not ruleset changeable */
6599 return NULL;
6600 case ACTION_NUKE:
6601 return "explode_nuclear_min_range";
6602 case ACTION_NUKE_CITY:
6603 return "nuke_city_min_range";
6604 case ACTION_NUKE_UNITS:
6605 return "nuke_units_min_range";
6606 case ACTION_TELEPORT:
6607 return "teleport_min_range";
6608 case ACTION_TELEPORT2:
6609 return "teleport_2_min_range";
6610 case ACTION_TELEPORT3:
6611 return "teleport_3_min_range";
6613 return "teleport_conquer_min_range";
6615 return "teleport_frighten_min_range";
6617 return "teleport_frighten_conquer_min_range";
6619 return "teleport_enter_min_range";
6621 return "teleport_enter_conquer_min_range";
6623 return "user_action_1_min_range";
6625 return "user_action_2_min_range";
6627 return "user_action_3_min_range";
6629 return "user_action_4_min_range";
6630 case ACTION_COUNT:
6631 break;
6632
6634 }
6635
6636 fc_assert(act >= 0 && act < ACTION_COUNT);
6637
6638 return NULL;
6639}
6640
6641/**********************************************************************/
6648{
6649 switch ((enum gen_action)act) {
6650 case ACTION_SPY_POISON:
6675 case ACTION_STEAL_MAPS:
6677 case ACTION_TRADE_ROUTE:
6678 case ACTION_MARKETPLACE:
6680 case ACTION_EXPEL_UNIT:
6681 case ACTION_FOUND_CITY:
6682 case ACTION_JOIN_CITY:
6683 case ACTION_SPY_NUKE:
6687 case ACTION_HOME_CITY:
6688 case ACTION_HOMELESS:
6690 case ACTION_PARADROP:
6696 case ACTION_ATTACK:
6697 case ACTION_ATTACK2:
6700 case ACTION_WIPE_UNITS:
6708 case ACTION_HEAL_UNIT:
6709 case ACTION_HEAL_UNIT2:
6712 case ACTION_CULTIVATE:
6713 case ACTION_CULTIVATE2:
6714 case ACTION_PLANT:
6715 case ACTION_PLANT2:
6716 case ACTION_PILLAGE:
6717 case ACTION_PILLAGE2:
6718 case ACTION_CLEAN:
6719 case ACTION_CLEAN2:
6720 case ACTION_FORTIFY:
6721 case ACTION_FORTIFY2:
6722 case ACTION_ROAD:
6723 case ACTION_ROAD2:
6724 case ACTION_CONVERT:
6725 case ACTION_BASE:
6726 case ACTION_BASE2:
6727 case ACTION_MINE:
6728 case ACTION_MINE2:
6729 case ACTION_IRRIGATE:
6730 case ACTION_IRRIGATE2:
6747 case ACTION_SPY_ATTACK:
6752 case ACTION_HUT_ENTER:
6753 case ACTION_HUT_ENTER2:
6754 case ACTION_HUT_ENTER3:
6755 case ACTION_HUT_ENTER4:
6760 case ACTION_UNIT_MOVE:
6761 case ACTION_UNIT_MOVE2:
6762 case ACTION_UNIT_MOVE3:
6763 case ACTION_SPY_ESCAPE:
6765 case ACTION_ESCAPE:
6766 case ACTION_CIVIL_WAR:
6767 /* Max range is not ruleset changeable */
6768 return NULL;
6769 case ACTION_HELP_WONDER:
6770 return "help_wonder_max_range";
6772 return "disband_unit_recover_max_range";
6773 case ACTION_BOMBARD:
6774 return "bombard_max_range";
6775 case ACTION_BOMBARD2:
6776 return "bombard_2_max_range";
6777 case ACTION_BOMBARD3:
6778 return "bombard_3_max_range";
6779 case ACTION_BOMBARD4:
6780 return "bombard_4_max_range";
6782 return "bombard_lethal_max_range";
6784 return "bombard_lethal_2_max_range";
6785 case ACTION_NUKE:
6786 return "explode_nuclear_max_range";
6787 case ACTION_NUKE_CITY:
6788 return "nuke_city_max_range";
6789 case ACTION_NUKE_UNITS:
6790 return "nuke_units_max_range";
6791 case ACTION_AIRLIFT:
6792 return "airlift_max_range";
6793 case ACTION_TELEPORT:
6794 return "teleport_max_range";
6795 case ACTION_TELEPORT2:
6796 return "teleport_2_max_range";
6797 case ACTION_TELEPORT3:
6798 return "teleport_3_max_range";
6800 return "teleport_conquer_max_range";
6802 return "teleport_frighten_max_range";
6804 return "teleport_frighten_conquer_max_range";
6806 return "teleport_enter_max_range";
6808 return "teleport_enter_conquer_max_range";
6810 return "user_action_1_max_range";
6812 return "user_action_2_max_range";
6814 return "user_action_3_max_range";
6816 return "user_action_4_max_range";
6817 case ACTION_COUNT:
6818 break;
6819
6821 }
6822
6823 fc_assert(act >= 0 && act < ACTION_COUNT);
6824
6825 return NULL;
6826}
6827
6828/**********************************************************************/
6835{
6836 switch ((enum gen_action)act) {
6837 case ACTION_SPY_POISON:
6862 case ACTION_STEAL_MAPS:
6864 case ACTION_TRADE_ROUTE:
6865 case ACTION_MARKETPLACE:
6866 case ACTION_HELP_WONDER:
6868 case ACTION_EXPEL_UNIT:
6869 case ACTION_FOUND_CITY:
6870 case ACTION_JOIN_CITY:
6871 case ACTION_SPY_NUKE:
6873 case ACTION_NUKE_UNITS:
6877 case ACTION_HOME_CITY:
6878 case ACTION_HOMELESS:
6880 case ACTION_PARADROP:
6886 case ACTION_AIRLIFT:
6887 case ACTION_ATTACK:
6888 case ACTION_ATTACK2:
6891 case ACTION_WIPE_UNITS:
6899 case ACTION_HEAL_UNIT:
6900 case ACTION_HEAL_UNIT2:
6903 case ACTION_CULTIVATE:
6904 case ACTION_CULTIVATE2:
6905 case ACTION_PLANT:
6906 case ACTION_PLANT2:
6907 case ACTION_CLEAN:
6908 case ACTION_CLEAN2:
6909 case ACTION_FORTIFY:
6910 case ACTION_FORTIFY2:
6911 case ACTION_ROAD:
6912 case ACTION_ROAD2:
6913 case ACTION_CONVERT:
6914 case ACTION_BASE:
6915 case ACTION_BASE2:
6916 case ACTION_MINE:
6917 case ACTION_MINE2:
6918 case ACTION_IRRIGATE:
6919 case ACTION_IRRIGATE2:
6936 case ACTION_BOMBARD:
6937 case ACTION_BOMBARD2:
6938 case ACTION_BOMBARD3:
6939 case ACTION_BOMBARD4:
6942 case ACTION_SPY_ATTACK:
6947 case ACTION_HUT_ENTER:
6948 case ACTION_HUT_ENTER2:
6949 case ACTION_HUT_ENTER3:
6950 case ACTION_HUT_ENTER4:
6955 case ACTION_UNIT_MOVE:
6956 case ACTION_UNIT_MOVE2:
6957 case ACTION_UNIT_MOVE3:
6958 case ACTION_TELEPORT:
6959 case ACTION_TELEPORT2:
6960 case ACTION_TELEPORT3:
6966 case ACTION_SPY_ESCAPE:
6968 case ACTION_ESCAPE:
6969 case ACTION_CIVIL_WAR:
6970 /* Target kind is not ruleset changeable */
6971 return NULL;
6972 case ACTION_NUKE:
6973 return "explode_nuclear_target_kind";
6974 case ACTION_NUKE_CITY:
6975 return "nuke_city_target_kind";
6976 case ACTION_PILLAGE:
6977 return "pillage_target_kind";
6978 case ACTION_PILLAGE2:
6979 return "pillage_2_target_kind";
6981 return "user_action_1_target_kind";
6983 return "user_action_2_target_kind";
6985 return "user_action_3_target_kind";
6987 return "user_action_4_target_kind";
6988 case ACTION_COUNT:
6989 break;
6990
6992 }
6993
6994 fc_assert(act >= 0 && act < ACTION_COUNT);
6995
6996 return NULL;
6997}
6998
6999/**********************************************************************/
7007{
7008 switch ((enum gen_action)act) {
7009 case ACTION_SPY_POISON:
7033 case ACTION_STEAL_MAPS:
7035 case ACTION_TRADE_ROUTE:
7036 case ACTION_MARKETPLACE:
7037 case ACTION_HELP_WONDER:
7039 case ACTION_EXPEL_UNIT:
7040 case ACTION_JOIN_CITY:
7041 case ACTION_SPY_NUKE:
7046 case ACTION_HOME_CITY:
7047 case ACTION_HOMELESS:
7049 case ACTION_PARADROP:
7055 case ACTION_AIRLIFT:
7056 case ACTION_ATTACK:
7057 case ACTION_ATTACK2:
7060 case ACTION_WIPE_UNITS:
7068 case ACTION_HEAL_UNIT:
7069 case ACTION_HEAL_UNIT2:
7072 case ACTION_CULTIVATE:
7073 case ACTION_CULTIVATE2:
7074 case ACTION_PLANT:
7075 case ACTION_PLANT2:
7076 case ACTION_PILLAGE:
7077 case ACTION_PILLAGE2:
7078 case ACTION_CLEAN:
7079 case ACTION_CLEAN2:
7080 case ACTION_FORTIFY:
7081 case ACTION_FORTIFY2:
7082 case ACTION_ROAD:
7083 case ACTION_ROAD2:
7084 case ACTION_CONVERT:
7085 case ACTION_BASE:
7086 case ACTION_BASE2:
7087 case ACTION_MINE:
7088 case ACTION_MINE2:
7089 case ACTION_IRRIGATE:
7090 case ACTION_IRRIGATE2:
7107 case ACTION_BOMBARD:
7108 case ACTION_BOMBARD2:
7109 case ACTION_BOMBARD3:
7110 case ACTION_BOMBARD4:
7113 case ACTION_SPY_ATTACK:
7118 case ACTION_HUT_ENTER:
7119 case ACTION_HUT_ENTER2:
7120 case ACTION_HUT_ENTER3:
7121 case ACTION_HUT_ENTER4:
7126 case ACTION_UNIT_MOVE:
7127 case ACTION_UNIT_MOVE2:
7128 case ACTION_UNIT_MOVE3:
7129 case ACTION_TELEPORT:
7130 case ACTION_TELEPORT2:
7131 case ACTION_TELEPORT3:
7137 case ACTION_SPY_ESCAPE:
7139 case ACTION_ESCAPE:
7140 case ACTION_CIVIL_WAR:
7141 /* Actor consuming always is not ruleset changeable */
7142 return NULL;
7143 case ACTION_FOUND_CITY:
7144 return "found_city_consuming_always";
7145 case ACTION_NUKE:
7146 return "explode_nuclear_consuming_always";
7147 case ACTION_NUKE_CITY:
7148 return "nuke_city_consuming_always";
7149 case ACTION_NUKE_UNITS:
7150 return "nuke_units_consuming_always";
7152 return "spread_plague_actor_consuming_always";
7154 return "user_action_1_actor_consuming_always";
7156 return "user_action_2_actor_consuming_always";
7158 return "user_action_3_actor_consuming_always";
7160 return "user_action_4_actor_consuming_always";
7161 case ACTION_COUNT:
7162 break;
7163
7165 }
7166
7167 fc_assert(act >= 0 && act < ACTION_COUNT);
7168
7169 return NULL;
7170}
7171
7172/**********************************************************************/
7179const char *action_blocked_by_ruleset_var_name(const struct action *act)
7180{
7181 fc_assert_ret_val(act != NULL, NULL);
7182
7183 switch ((enum gen_action)action_number(act)) {
7184 case ACTION_MARKETPLACE:
7185 return "enter_marketplace_blocked_by";
7186 case ACTION_BOMBARD:
7187 return "bombard_blocked_by";
7188 case ACTION_BOMBARD2:
7189 return "bombard_2_blocked_by";
7190 case ACTION_BOMBARD3:
7191 return "bombard_3_blocked_by";
7192 case ACTION_BOMBARD4:
7193 return "bombard_4_blocked_by";
7195 return "bombard_lethal_blocked_by";
7197 return "bombard_lethal_2_blocked_by";
7198 case ACTION_NUKE:
7199 return "explode_nuclear_blocked_by";
7200 case ACTION_NUKE_CITY:
7201 return "nuke_city_blocked_by";
7202 case ACTION_NUKE_UNITS:
7203 return "nuke_units_blocked_by";
7204 case ACTION_ATTACK:
7205 return "attack_blocked_by";
7206 case ACTION_ATTACK2:
7207 return "attack_2_blocked_by";
7209 return "suicide_attack_blocked_by";
7211 return "suicide_attack_2_blocked_by";
7212 case ACTION_WIPE_UNITS:
7213 return "wipe_units_blocked_by";
7215 return "collect_ransom_blocked_by";
7217 return "conquer_city_shrink_blocked_by";
7219 return "conquer_city_shrink_2_blocked_by";
7221 return "conquer_city_shrink_3_blocked_by";
7223 return "conquer_city_shrink_4_blocked_by";
7224 case ACTION_UNIT_MOVE:
7225 return "move_blocked_by";
7226 case ACTION_UNIT_MOVE2:
7227 return "move_2_blocked_by";
7228 case ACTION_UNIT_MOVE3:
7229 return "move_3_blocked_by";
7230 case ACTION_TELEPORT:
7231 return "teleport_blocked_by";
7232 case ACTION_TELEPORT2:
7233 return "teleport_2_blocked_by";
7234 case ACTION_TELEPORT3:
7235 return "teleport_3_blocked_by";
7237 return "teleport_conquer_blocked_by";
7239 return "teleport_frighten_blocked_by";
7241 return "teleport_frighten_conquer_blocked_by";
7243 return "teleport_enter_blocked_by";
7245 return "teleport_enter_conquer_blocked_by";
7246 case ACTION_SPY_ESCAPE:
7247 case ACTION_SPY_POISON:
7271 case ACTION_STEAL_MAPS:
7273 case ACTION_TRADE_ROUTE:
7274 case ACTION_HELP_WONDER:
7276 case ACTION_EXPEL_UNIT:
7277 case ACTION_FOUND_CITY:
7278 case ACTION_JOIN_CITY:
7279 case ACTION_SPY_NUKE:
7284 case ACTION_HOME_CITY:
7285 case ACTION_HOMELESS:
7287 case ACTION_PARADROP:
7293 case ACTION_AIRLIFT:
7296 case ACTION_HEAL_UNIT:
7297 case ACTION_HEAL_UNIT2:
7300 case ACTION_CULTIVATE:
7301 case ACTION_CULTIVATE2:
7302 case ACTION_PLANT:
7303 case ACTION_PLANT2:
7304 case ACTION_PILLAGE:
7305 case ACTION_PILLAGE2:
7306 case ACTION_CLEAN:
7307 case ACTION_CLEAN2:
7308 case ACTION_FORTIFY:
7309 case ACTION_FORTIFY2:
7310 case ACTION_ROAD:
7311 case ACTION_ROAD2:
7312 case ACTION_CONVERT:
7313 case ACTION_BASE:
7314 case ACTION_BASE2:
7315 case ACTION_MINE:
7316 case ACTION_MINE2:
7317 case ACTION_IRRIGATE:
7318 case ACTION_IRRIGATE2:
7336 case ACTION_SPY_ATTACK:
7341 case ACTION_HUT_ENTER:
7342 case ACTION_HUT_ENTER2:
7343 case ACTION_HUT_ENTER3:
7344 case ACTION_HUT_ENTER4:
7350 case ACTION_CIVIL_WAR:
7351 case ACTION_ESCAPE:
7356 /* blocked_by is not ruleset changeable */
7357 return NULL;
7358 case ACTION_COUNT:
7360 break;
7361
7363 }
7364
7365 return NULL;
7366}
7367
7368/**********************************************************************/
7372const char *
7374{
7375 fc_assert_ret_val(act != NULL, NULL);
7376
7382 /* No support in the action performer function */
7383 return NULL;
7384 }
7385
7386 switch ((enum gen_action)action_number(act)) {
7388 return "bribe_unit_post_success_forced_actions";
7390 return "bribe_stack_post_success_forced_actions";
7391 case ACTION_ATTACK:
7392 return "attack_post_success_forced_actions";
7393 case ACTION_ATTACK2:
7394 return "attack_2_post_success_forced_actions";
7395 case ACTION_WIPE_UNITS:
7396 return "wipe_units_post_success_forced_actions";
7398 return "collect_ransom_post_success_forced_actions";
7399 case ACTION_MARKETPLACE:
7400 case ACTION_BOMBARD:
7401 case ACTION_BOMBARD2:
7402 case ACTION_BOMBARD3:
7403 case ACTION_BOMBARD4:
7406 case ACTION_NUKE:
7407 case ACTION_NUKE_CITY:
7408 case ACTION_NUKE_UNITS:
7415 case ACTION_SPY_POISON:
7437 case ACTION_STEAL_MAPS:
7439 case ACTION_TRADE_ROUTE:
7440 case ACTION_HELP_WONDER:
7442 case ACTION_EXPEL_UNIT:
7443 case ACTION_FOUND_CITY:
7444 case ACTION_JOIN_CITY:
7445 case ACTION_SPY_NUKE:
7450 case ACTION_HOME_CITY:
7451 case ACTION_HOMELESS:
7453 case ACTION_PARADROP:
7459 case ACTION_AIRLIFT:
7462 case ACTION_HEAL_UNIT:
7463 case ACTION_HEAL_UNIT2:
7466 case ACTION_CULTIVATE:
7467 case ACTION_CULTIVATE2:
7468 case ACTION_PLANT:
7469 case ACTION_PLANT2:
7470 case ACTION_PILLAGE:
7471 case ACTION_PILLAGE2:
7472 case ACTION_CLEAN:
7473 case ACTION_CLEAN2:
7474 case ACTION_FORTIFY:
7475 case ACTION_FORTIFY2:
7476 case ACTION_ROAD:
7477 case ACTION_ROAD2:
7478 case ACTION_CONVERT:
7479 case ACTION_BASE:
7480 case ACTION_BASE2:
7481 case ACTION_MINE:
7482 case ACTION_MINE2:
7483 case ACTION_IRRIGATE:
7484 case ACTION_IRRIGATE2:
7502 case ACTION_SPY_ATTACK:
7507 case ACTION_HUT_ENTER:
7508 case ACTION_HUT_ENTER2:
7509 case ACTION_HUT_ENTER3:
7510 case ACTION_HUT_ENTER4:
7515 case ACTION_UNIT_MOVE:
7516 case ACTION_UNIT_MOVE2:
7517 case ACTION_UNIT_MOVE3:
7518 case ACTION_TELEPORT:
7519 case ACTION_TELEPORT2:
7520 case ACTION_TELEPORT3:
7526 case ACTION_SPY_ESCAPE:
7528 case ACTION_ESCAPE:
7529 case ACTION_CIVIL_WAR:
7534 /* Not ruleset changeable */
7535 return NULL;
7536 case ACTION_COUNT:
7538 break;
7539
7541 }
7542
7543 return NULL;
7544}
7545
7546/**********************************************************************/
7554
7555/**********************************************************************/
7558const char *gen_action_name_update_cb(const char *old_name)
7559{
7560 if (is_ruleset_compat_mode()) {
7561 if (!fc_strcasecmp("Conquer City", old_name)) {
7562 return "Conquer City Shrink";
7563 }
7564 if (!fc_strcasecmp("Conquer City 2", old_name)) {
7565 return "Conquer City Shrink 2";
7566 }
7567 if (!fc_strcasecmp("Conquer City 3", old_name)) {
7568 return "Conquer City Shrink 3";
7569 }
7570 if (!fc_strcasecmp("Conquer City 4", old_name)) {
7571 return "Conquer City Shrink 4";
7572 }
7573 }
7574
7575 return old_name;
7576}
7577
7579{
7580 N_("individual cities"), /* ATK_CITY */
7581 N_("individual units"), /* ATK_UNIT */
7582 N_("unit stacks"), /* ATK_STACK */
7583 N_("tiles"), /* ATK_TILE */
7584 N_("tile extras"), /* ATK_EXTRAS */
7585 N_("itself") /* ATK_SELF */
7586};
7587
7588/**********************************************************************/
7593{
7594 fc_assert(kind >= 0 && kind < ATK_COUNT);
7595
7596 return _(atk_helpnames[kind]);
7597}
7598
7599/************************************************************************/
7603{
7604 fc_assert(result < ACTRES_LAST);
7605
7606 return actlist_by_result[result];
7607}
7608
7609/************************************************************************/
7613{
7614 fc_assert(activity < ACTIVITY_LAST);
7615
7616 return actlist_by_activity[activity];
7617}
bool is_action_possible_on_city(action_id act_id, const struct player *actor_player, const struct city *target_city)
Definition actions.c:5491
static struct action * actions[MAX_NUM_ACTIONS]
Definition actions.c:57
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:4979
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:2814
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:5569
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:3797
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:3429
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:5101
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:5722
req_vec_num_in_item action_enabler_vector_number(const void *enabler, const struct requirement_vector *vec)
Definition actions.c:2052
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:2399
struct req_vec_problem * action_enabler_suggest_repair(const struct action_enabler *enabler)
Definition actions.c:1922
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:3274
bool action_prob_possible(const struct act_prob probability)
Definition actions.c:5091
#define ACTPROB_VAL_NOT_IMPL
Definition actions.c:55
struct action_auto_perf auto_perfs[MAX_NUM_ACTION_AUTO_PERFORMERS]
Definition actions.c:59
bool action_actor_utype_hard_reqs_ok(const struct action *paction, const struct unit_type *actor_unittype)
Definition actions.c:2607
struct act_prob action_prob_new_not_impl(void)
Definition actions.c:5070
struct req_vec_problem * action_enabler_suggest_improvement(const struct action_enabler *enabler)
Definition actions.c:1988
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:3524
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:4912
void actions_rs_pre_san_gen(void)
Definition actions.c:890
const char * action_min_range_ruleset_var_name(int act)
Definition actions.c:6469
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:5013
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:3571
const char * action_blocked_by_ruleset_var_name(const struct action *act)
Definition actions.c:7179
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:2987
#define ACTPROB_VAL_MAX
Definition actions.c:49
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:3845
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:5787
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:5391
void action_array_end(action_id *act_array, int size)
Definition actions.c:5770
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:4612
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:3749
const char * atk_helpnames[ATK_COUNT]
Definition actions.c:7578
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:2627
static void hard_code_actions(void)
Definition actions.c:107
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:3026
bool action_is_in_use(struct action *paction)
Definition actions.c:5676
static struct req_vec_problem * enabler_tile_tgt_local_diplrel_implies_claimed(const struct action_enabler *enabler)
Definition actions.c:1777
bool action_ever_possible(action_id action)
Definition actions.c:7550
const char * action_enabler_vector_by_number_name(req_vec_num_in_item vec)
Definition actions.c:2099
bool are_action_probabilitys_equal(const struct act_prob *ap1, const struct act_prob *ap2)
Definition actions.c:5142
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:4712
const char * action_post_success_forced_ruleset_var_name(const struct action *act)
Definition actions.c:7373
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:5650
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:2167
static bool action_prob_not_relevant(const struct act_prob probability)
Definition actions.c:5112
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:3703
void actions_free(void)
Definition actions.c:900
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:3351
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:3256
static enum fc_tristate tech_can_be_stolen(const struct player *actor_player, const struct player *target_player)
Definition actions.c:3590
static struct action_list * actlist_by_result[ACTRES_LAST]
Definition actions.c:100
struct action_list * action_list_by_activity(enum unit_activity activity)
Definition actions.c:7612
int action_number(const struct action *action)
Definition actions.c:1208
struct act_prob action_prob_new_unknown(void)
Definition actions.c:5080
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:53
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:1970
static bool action_prob_not_impl(const struct act_prob probability)
Definition actions.c:5123
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:3332
struct act_prob action_prob_and(const struct act_prob *ap1, const struct act_prob *ap2)
Definition actions.c:5229
static bool actions_initialized
Definition actions.c:60
const char * action_actor_consuming_always_ruleset_var_name(action_id act)
Definition actions.c:7006
bool action_immune_government(struct government *gov, action_id act)
Definition actions.c:5447
static bool is_target_possible(const action_id wanted_action, const struct player *actor_player, const struct req_context *target)
Definition actions.c:5470
static struct act_prob ap_dipl_battle_win(const struct unit *pattacker, const struct unit *pdefender)
Definition actions.c:3626
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:4354
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:4695
struct act_prob action_prob_new_certain(void)
Definition actions.c:5050
const char * action_max_range_ruleset_var_name(int act)
Definition actions.c:6647
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:4167
bool action_is_internal(struct action *paction)
Definition actions.c:5702
int action_dice_roll_initial_odds(const struct action *paction)
Definition actions.c:5367
struct act_prob action_prob_self(const struct civ_map *nmap, const struct unit *actor_unit, const action_id act_id)
Definition actions.c:4765
struct act_prob action_prob_fall_back(const struct act_prob *ap1, const struct act_prob *ap2)
Definition actions.c:5299
static const struct unit_type * tgt_city_local_utype(const struct city *target_city)
Definition actions.c:2142
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:4546
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:3091
struct action_list * action_list_by_result(enum action_result result)
Definition actions.c:7602
bool action_univs_not_blocking(const struct action *paction, struct universal *actor_uni, struct universal *target_uni)
Definition actions.c:5746
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:4844
static struct requirement * req_vec_first_contradiction_in_vec(const struct requirement *req, const struct requirement_vector *vec)
Definition actions.c:1754
bool actions_are_ready(void)
Definition actions.c:942
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:3168
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:4945
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:4254
const char * action_target_kind_ruleset_var_name(int act)
Definition actions.c:6834
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:4270
bool action_maybe_possible_actor_unit(const struct civ_map *nmap, const action_id act_id, const struct unit *actor_unit)
Definition actions.c:5514
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:2286
static bool is_enabler_active(const struct action_enabler *enabler, const struct req_context *actor, const struct req_context *target)
Definition actions.c:2970
static struct action_enabler_list * action_enablers_by_action[MAX_NUM_ACTIONS]
Definition actions.c:62
void action_enabler_add(struct action_enabler *enabler)
Definition actions.c:1526
const char * action_ui_name_default(int act)
Definition actions.c:6105
#define ACTPROB_VAL_1_PCT
Definition actions.c:51
bool action_enabler_utype_possible_actor(const struct action_enabler *ae, const struct unit_type *act_utype)
Definition actions.c:5592
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:3731
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:5060
const char * action_target_kind_help(enum action_target_kind kind)
Definition actions.c:7592
static struct req_vec_problem * enabler_first_self_contradiction(const struct action_enabler *enabler)
Definition actions.c:1850
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:4879
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:5738
struct act_prob action_prob_new_impossible(void)
Definition actions.c:5040
bool action_enabler_possible_actor(const struct action_enabler *ae)
Definition actions.c:5619
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:2227
struct action ** _actions
Definition actions.c:58
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:4787
static bool action_prob_is_signal(const struct act_prob probability)
Definition actions.c:5134
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:5151
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:4529
bool action_id_is_internal(action_id act)
Definition actions.c:5714
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:3481
bool action_id_is_rare_pop_up(action_id act_id)
Definition actions.c:1160
void actions_init(void)
Definition actions.c:841
static struct action * action_new(action_id id, enum action_result result, const int min_distance, const int max_distance, bool actor_consuming_always)
Definition actions.c:966
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:4337
bool is_action_enabled_player(const struct civ_map *nmap, const action_id wanted_action, const struct player *actor_plr)
Definition actions.c:3494
static const struct impr_type * tgt_city_local_building(const struct city *target_city)
Definition actions.c:2119
static struct astring ui_name_str
Definition actions.c:64
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:3409
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:3109
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:3186
double action_prob_to_0_to_1_pessimist(const struct act_prob ap)
Definition actions.c:5202
const char * gen_action_name_update_cb(const char *old_name)
Definition actions.c:7558
static struct action_list * actlist_by_activity[ACTIVITY_LAST]
Definition actions.c:101
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:2075
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:4629
const char * action_ui_name_ruleset_var_name(int act)
Definition actions.c:5807
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:47
#define action_noninternal_iterate_end
Definition actions.h:236
#define ACTION_DISTANCE_MAX
Definition actions.h:103
#define enabler_get_action(_enabler_)
Definition actions.h:182
#define ASSERT_UNUSED_ACTION_CASES
Definition actions.h:38
#define ACTPROB_CERTAIN
Definition actions.h:688
#define enabler_get_action_id(_enabler_)
Definition actions.h:183
#define ACTPROB_NA
Definition actions.h:689
static struct action * action_by_number(action_id act_id)
Definition actions.h:396
#define action_enabler_list_re_iterate_end
Definition actions.h:196
#define ACTION_DISTANCE_LAST_NON_SIGNAL
Definition actions.h:99
#define action_enabler_list_re_iterate(action_enabler_list, aenabler)
Definition actions.h:192
#define action_has_result(_act_, _res_)
Definition actions.h:180
#define action_enabler_list_iterate_end
Definition actions.h:190
#define ACTION_DISTANCE_UNLIMITED
Definition actions.h:101
#define action_iterate_end
Definition actions.h:214
#define MAX_NUM_ACTIONS
Definition actions.h:58
#define action_iterate_all(_act_)
Definition actions.h:200
#define action_id_get_actor_kind(act_id)
Definition actions.h:409
#define action_iterate_all_end
Definition actions.h:205
#define ACTPROB_NOT_KNOWN
Definition actions.h:691
#define action_enabler_list_iterate(action_enabler_list, aenabler)
Definition actions.h:188
#define action_id_distance_accepted(act_id, distance)
Definition actions.h:445
#define ACTPROB_IMPOSSIBLE
Definition actions.h:687
#define ACTPROB_NOT_IMPLEMENTED
Definition actions.h:690
#define action_iterate(_act_)
Definition actions.h:210
#define ACTION_ANY
Definition actions.h:52
#define action_noninternal_iterate(_act_)
Definition actions.h:231
#define action_id_get_target_kind(act_id)
Definition actions.h:413
#define action_id_has_result_safe(act_id, result)
Definition actions.h:426
#define ACTION_ODDS_PCT_DICE_ROLL_NA
Definition actions.h:694
#define ACTION_NONE
Definition actions.h:55
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:236
@ RPT_CERTAIN
Definition fc_types.h:533
@ RPT_POSSIBLE
Definition fc_types.h:532
int action_id
Definition fc_types.h:248
#define ACTRES_NONE
Definition fc_types.h:186
#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:318
bool is_native_tile(const struct unit_type *punittype, const struct tile *ptile)
Definition movement.c:330
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:912
bool can_unit_type_transport(const struct unit_type *transporter, const struct unit_class *transported)
Definition movement.c:869
bool can_attack_non_native(const struct unit_type *utype)
Definition movement.c:213
void oblig_hard_reqs_init(void)
Definition oblig_reqs.c:807
void oblig_hard_reqs_free(void)
Definition oblig_reqs.c:827
void hard_code_oblig_hard_reqs_ruleset(void)
Definition oblig_reqs.c:770
void hard_code_oblig_hard_reqs(void)
Definition oblig_reqs.c:250
struct obligatory_req_vector * oblig_hard_reqs_get(enum action_result res)
Definition oblig_reqs.c:852
struct obligatory_req_vector * oblig_hard_reqs_get_sub(enum action_sub_result res)
Definition oblig_reqs.c:863
#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)
bool are_requirements_contradictions(const struct requirement *req1, const struct requirement *req2)
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)
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:950
int min
Definition fc_types.h:949
enum action_auto_perf_cause cause
Definition actions.h:323
action_id alternatives[MAX_NUM_ACTIONS]
Definition actions.h:331
action_id action
Definition actions.h:167
struct requirement_vector actor_reqs
Definition actions.h:168
struct requirement_vector target_reqs
Definition actions.h:169
bool unitwaittime_controlled
Definition actions.h:156
action_id id
Definition actions.h:107
bool actor_consuming_always
Definition actions.h:140
bool rare_pop_up
Definition actions.h:153
int max_distance
Definition actions.h:123
bool quiet
Definition actions.h:130
enum action_sub_target_kind sub_target_kind
Definition actions.h:115
enum moves_actor_kind moves_actor
Definition actions.h:160
struct action::@12::@13 is_unit
enum action_result result
Definition actions.h:110
char ui_name[MAX_LEN_NAME]
Definition actions.h:126
bv_action_sub_results sub_results
Definition actions.h:111
enum action_actor_kind actor_kind
Definition actions.h:113
enum act_tgt_compl target_complexity
Definition actions.h:118
bv_actions blocked_by
Definition actions.h:134
bool configured
Definition actions.h:108
union action::@12 actor
enum action_target_kind target_kind
Definition actions.h:114
int min_distance
Definition actions.h:123
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:551
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:608
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:2518
bool unit_can_do_action(const struct unit *punit, const action_id act_id)
Definition unit.c:383
bool unit_transported(const struct unit *pcargo)
Definition unit.c:2502
bool can_unit_unload(const struct unit *pcargo, const struct unit *ptrans)
Definition unit.c:776
bool unit_can_convert(const struct civ_map *nmap, const struct unit *punit)
Definition unit.c:2072
#define unit_tile(_pu)
Definition unit.h:404
#define unit_owner(_pu)
Definition unit.h:403
#define unit_home(_pu_)
Definition unit.h:401
#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:1064
const struct veteran_level * utype_veteran_level(const struct unit_type *punittype, int level)
Definition unittype.c:2603
bool unit_has_type_flag(const struct unit *punit, enum unit_type_flag_id flag)
Definition unittype.c:196
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:1002
bool utype_can_do_action(const struct unit_type *putype, const action_id act_id)
Definition unittype.c:377
#define utype_class(_t_)
Definition unittype.h:756
#define L_LAST
Definition unittype.h:446
#define unit_type_iterate(_p)
Definition unittype.h:862
#define unit_type_iterate_end
Definition unittype.h:869
#define U_NOT_OBSOLETED
Definition unittype.h:535