Freeciv-3.4
Loading...
Searching...
No Matches
actions.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996-2013 - Freeciv Development Team
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18#include <math.h> /* ceil(), floor() */
19
20/* utility */
21#include "astring.h"
22
23/* common */
24#include "actions.h"
25#include "city.h"
26#include "combat.h"
27#include "fc_interface.h"
28#include "game.h"
29#include "map.h"
30#include "metaknowledge.h"
31#include "movement.h"
32#include "oblig_reqs.h"
33#include "research.h"
34#include "server_settings.h"
35#include "specialist.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 *
78static struct action *
81
82static bool is_enabler_active(const struct action_enabler *enabler,
83 const struct req_context *actor,
84 const struct req_context *target);
85
86static inline bool
88static inline bool
90static inline bool
92
94 const struct unit *pvictim,
95 const struct tile *tgt_tile,
96 const struct action *paction)
98
99/* Make sure that an action distance can target the whole map. */
102
105
106
107/**********************************************************************/
110static void hard_code_actions(void)
111{
114 FALSE, TRUE,
115 MAK_ESCAPE, 0, 1, TRUE);
118 FALSE, TRUE,
119 MAK_ESCAPE, 0, 1, FALSE);
122 FALSE, TRUE,
123 MAK_ESCAPE, 0, 1, TRUE);
126 FALSE, TRUE,
127 MAK_ESCAPE, 0, 1, FALSE);
130 FALSE, TRUE,
131 /* Tries a forced move if the target unit is alone at
132 * its tile and not in a city. Takes all movement if
133 * the forced move fails. */
135 0, 1, FALSE);
138 FALSE, TRUE,
140 0, 1, FALSE);
143 FALSE, TRUE,
144 MAK_ESCAPE, 0, 1, TRUE);
147 FALSE, TRUE,
148 MAK_ESCAPE, 0, 1, FALSE);
152 FALSE, TRUE,
153 MAK_ESCAPE, 0, 1, TRUE);
157 FALSE, TRUE,
158 MAK_ESCAPE, 0, 1, TRUE);
162 FALSE, TRUE,
163 MAK_ESCAPE, 0, 1, FALSE);
167 FALSE, TRUE,
168 MAK_ESCAPE, 0, 1, FALSE);
171 FALSE, TRUE,
172 MAK_ESCAPE, 0, 1, TRUE);
175 FALSE, TRUE,
176 MAK_ESCAPE, 0, 1, FALSE);
180 FALSE, TRUE,
181 MAK_STAYS, 0, 1, FALSE);
185 FALSE, TRUE,
186 MAK_STAYS, 0, 1, TRUE);
190 FALSE, TRUE,
191 MAK_ESCAPE, 0, 1, TRUE);
195 FALSE, TRUE,
196 MAK_ESCAPE, 0, 1, FALSE);
200 FALSE, TRUE,
201 MAK_ESCAPE, 0, 1, TRUE);
205 FALSE, TRUE,
206 MAK_ESCAPE, 0, 1, FALSE);
210 FALSE, TRUE,
211 MAK_STAYS, 0, 1, FALSE);
215 FALSE, TRUE,
216 MAK_STAYS, 0, 1, TRUE);
220 FALSE, TRUE,
221 MAK_ESCAPE, 0, 1, TRUE);
225 FALSE, TRUE,
226 MAK_ESCAPE, 0, 1, FALSE);
230 FALSE, TRUE,
231 MAK_ESCAPE, 0, 1, FALSE);
235 FALSE, TRUE,
236 MAK_ESCAPE, 0, 1, FALSE);
239 FALSE, TRUE,
240 MAK_STAYS, 0, 1, TRUE);
243 FALSE, TRUE,
244 MAK_STAYS, 0, 1, TRUE);
247 FALSE, TRUE,
248 MAK_STAYS, 0, 1, TRUE);
252 /* A single domestic unit at the target tile will make
253 * the action illegal. It must therefore be performed
254 * from another tile. */
255 1, 1,
256 FALSE);
260 /* Illegal to perform to a target on another tile.
261 * Reason: The Freeciv code assumes that the city
262 * founding unit is located at the tile were the new
263 * city is founded. */
264 0, 0,
265 TRUE);
268 TRUE, TRUE,
269 MAK_STAYS, 0, 1, TRUE);
272 FALSE, TRUE,
273 MAK_ESCAPE, 0, 1, TRUE);
276 FALSE, TRUE,
277 MAK_ESCAPE, 0, 1, FALSE);
281 /* A single domestic unit at the target tile will make
282 * the action illegal. It must therefore be performed
283 * from another tile. */
284 1,
285 /* Overwritten by the ruleset's bombard_max_range */
286 1,
287 FALSE);
290 FALSE, TRUE,
291 MAK_STAYS,
292 /* A single domestic unit at the target tile will make
293 * the action illegal. It must therefore be performed
294 * from another tile. */
295 1,
296 /* Overwritten by the ruleset's bombard_2_max_range */
297 1,
298 FALSE);
302 /* A single domestic unit at the target tile will make
303 * the action illegal. It must therefore be performed
304 * from another tile. */
305 1,
306 /* Overwritten by the ruleset's bombard_3_max_range */
307 1,
308 FALSE);
312 /* A single domestic unit at the target tile will make
313 * the action illegal. It must therefore be performed
314 * from another tile. */
315 1,
316 /* Overwritten by the ruleset's bombard_4_max_range */
317 1,
318 FALSE);
322 /* A single domestic unit at the target tile will make
323 * the action illegal. It must therefore be performed
324 * from another tile. */
325 1,
326 /* Overwritten by the ruleset's bombard_lethal_max_range */
327 1,
328 FALSE);
332 /* A single domestic unit at the target tile will make
333 * the action illegal. It must therefore be performed
334 * from another tile. */
335 1,
336 /* Overwritten by the ruleset's bombard_lethal_2_max_range */
337 1,
338 FALSE);
341 FALSE, TRUE,
342 MAK_ESCAPE, 0, 1, TRUE);
345 FALSE, TRUE,
346 MAK_ESCAPE, 0, 1, FALSE);
349 TRUE, TRUE,
350 MAK_STAYS, 0,
351 /* Overwritten by the ruleset's
352 * explode_nuclear_max_range */
353 0,
354 TRUE);
357 TRUE, TRUE,
358 MAK_STAYS, 1, 1, TRUE);
361 TRUE, TRUE,
362 MAK_STAYS, 1, 1, TRUE);
365 TRUE, TRUE,
366 MAK_STAYS, 0, 1, FALSE);
369 FALSE, TRUE,
370 MAK_STAYS, 0, 1, FALSE);
374 /* Illegal to perform to a target on another tile to
375 * keep the rules exactly as they were for now. */
376 0, 1,
377 TRUE);
380 /* Can't be ACTRES_NONE because
381 * action_success_actor_consume() sets unit lost
382 * reason based on action result. */
384 TRUE, TRUE,
385 MAK_STAYS, 0, 0, TRUE);
388 TRUE, FALSE,
389 /* Illegal to perform to a target on another tile to
390 * keep the rules exactly as they were for now. */
391 MAK_STAYS, 0, 0, FALSE);
394 TRUE, FALSE,
395 MAK_STAYS, 0, 0, FALSE);
399 /* Illegal to perform to a target on another tile to
400 * keep the rules exactly as they were for now. */
401 0, 0,
402 FALSE);
405 TRUE, TRUE,
407 1,
408 /* Still limited by each unit type's
409 * paratroopers_range field. */
411 FALSE);
414 TRUE, TRUE,
416 1,
417 /* Still limited by each unit type's
418 * paratroopers_range field. */
420 FALSE);
423 TRUE, TRUE,
425 1,
426 /* Still limited by each unit type's
427 * paratroopers_range field. */
429 FALSE);
433 TRUE, TRUE,
435 1,
436 /* Still limited by each unit type's
437 * paratroopers_range field. */
439 FALSE);
442 TRUE, TRUE,
444 1,
445 /* Still limited by each unit type's
446 * paratroopers_range field. */
448 FALSE);
452 TRUE, TRUE,
454 1,
455 /* Still limited by each unit type's
456 * paratroopers_range field. */
458 FALSE);
461 TRUE, TRUE,
463 1,
464 /* Overwritten by the ruleset's airlift_max_range. */
466 FALSE);
469 FALSE, TRUE,
470 /* Tries a forced move if the target unit's tile has
471 * no non-allied units and the occupychance dice roll
472 * tells it to move. */
474 1, 1, FALSE);
477 FALSE, TRUE,
478 /* Tries a forced move if the target unit's tile has
479 * no non-allied units and the occupychance dice roll
480 * tells it to move. */
482 1, 1, FALSE);
485 FALSE, TRUE,
486 MAK_FORCED, 1, 1, TRUE);
489 FALSE, TRUE,
490 MAK_FORCED, 1, 1, TRUE);
493 FALSE, TRUE,
495 1, 1, FALSE);
498 FALSE, FALSE,
499 MAK_STAYS, 1, 1, FALSE);
502 FALSE, FALSE,
503 MAK_STAYS, 1, 1, FALSE);
506 FALSE, TRUE,
507 MAK_REGULAR, 1, 1, FALSE);
510 FALSE, TRUE,
511 MAK_REGULAR, 1, 1, FALSE);
514 FALSE, TRUE,
515 MAK_REGULAR, 1, 1, FALSE);
518 FALSE, TRUE,
519 MAK_REGULAR, 1, 1, FALSE);
522 FALSE, TRUE,
523 MAK_REGULAR, 1, 1, FALSE);
526 FALSE, TRUE,
527 MAK_REGULAR, 1, 1, FALSE);
530 FALSE, TRUE,
531 MAK_REGULAR, 1, 1, FALSE);
534 FALSE, TRUE,
535 MAK_REGULAR, 1, 1, FALSE);
538 FALSE, TRUE,
539 MAK_STAYS, 0, 1, FALSE);
542 FALSE, TRUE,
543 MAK_STAYS, 0, 1, FALSE);
546 TRUE, FALSE,
547 MAK_STAYS, 0, 0, FALSE);
550 TRUE, FALSE,
551 MAK_STAYS, 0, 0, FALSE);
554 TRUE, FALSE,
555 MAK_STAYS, 0, 0, FALSE);
558 TRUE, FALSE,
559 MAK_STAYS, 0, 0, FALSE);
562 TRUE, FALSE,
563 MAK_STAYS, 0, 0, FALSE);
566 TRUE, FALSE,
567 MAK_STAYS, 0, 0, FALSE);
570 TRUE, FALSE,
571 MAK_STAYS, 0, 0, FALSE);
574 TRUE, FALSE,
575 MAK_STAYS, 0, 0, FALSE);
578 TRUE, FALSE,
579 MAK_STAYS, 0, 0, FALSE);
582 TRUE, FALSE,
583 MAK_STAYS, 0, 0, FALSE);
586 TRUE, FALSE,
587 MAK_STAYS, 0, 0, FALSE);
590 TRUE, FALSE,
591 MAK_STAYS, 0, 0, FALSE);
594 TRUE, FALSE,
595 MAK_STAYS, 0, 0, FALSE);
598 TRUE, FALSE,
599 MAK_STAYS, 0, 0, FALSE);
602 TRUE, FALSE,
603 MAK_STAYS, 0, 0, FALSE);
606 TRUE, FALSE,
607 MAK_STAYS, 0, 0, FALSE);
610 TRUE, FALSE,
611 MAK_STAYS, 0, 0, FALSE);
614 TRUE, FALSE,
615 MAK_STAYS, 0, 0, FALSE);
618 TRUE, FALSE,
619 MAK_STAYS, 0, 0, FALSE);
622 TRUE, FALSE,
623 MAK_STAYS, 0, 0, FALSE);
626 TRUE, FALSE,
627 MAK_STAYS, 0, 0, FALSE);
630 TRUE, FALSE,
631 MAK_STAYS, 0, 0, FALSE);
634 TRUE, FALSE,
635 MAK_STAYS, 0, 0, FALSE);
638 TRUE, FALSE,
639 MAK_STAYS, 0, 0, FALSE);
642 TRUE, FALSE,
643 MAK_STAYS, 0, 0, FALSE);
646 TRUE, FALSE,
647 MAK_STAYS, 0, 0, FALSE);
650 TRUE, FALSE,
651 MAK_STAYS, 0, 0, FALSE);
654 TRUE, FALSE,
655 MAK_STAYS, 0, 0, FALSE);
658 TRUE, FALSE,
659 MAK_STAYS, 0, 0, FALSE);
663 FALSE, TRUE,
664 MAK_REGULAR, 1, 1, FALSE);
668 FALSE, TRUE,
669 MAK_REGULAR, 1, 1, FALSE);
673 FALSE, TRUE,
674 MAK_REGULAR, 1, 1, FALSE);
678 FALSE, TRUE,
679 MAK_REGULAR, 1, 1, FALSE);
682 TRUE, TRUE,
683 MAK_REGULAR, 1, 1, FALSE);
686 TRUE, TRUE,
687 MAK_REGULAR, 1, 1, FALSE);
690 TRUE, TRUE,
691 MAK_REGULAR, 1, 1, FALSE);
694 TRUE, TRUE,
695 MAK_REGULAR, 1, 1, FALSE);
698 FALSE, TRUE,
699 MAK_STAYS, 1, 1, FALSE);
702 FALSE, TRUE,
703 MAK_REGULAR, 1, 1, FALSE);
706 FALSE, TRUE,
707 MAK_REGULAR, 1, 1, FALSE);
710 FALSE, TRUE,
711 MAK_REGULAR, 1, 1, FALSE);
714 FALSE, TRUE,
715 MAK_REGULAR, 1, 1, FALSE);
718 FALSE, TRUE,
719 MAK_REGULAR, 1, 1, FALSE);
722 FALSE, TRUE,
723 MAK_REGULAR, 1, 1, FALSE);
726 FALSE, TRUE,
727 MAK_REGULAR, 1, 1, FALSE);
730 FALSE, TRUE,
731 MAK_REGULAR, 1, 1, FALSE);
734 TRUE, TRUE,
735 MAK_REGULAR, 1, 1, FALSE);
738 TRUE, TRUE,
739 MAK_REGULAR, 1, 1, FALSE);
742 TRUE, TRUE,
743 MAK_REGULAR, 1, 1, FALSE);
746 TRUE, TRUE,
747 MAK_TELEPORT, 1, 1, FALSE);
750 TRUE, TRUE,
751 MAK_TELEPORT, 1, 1, FALSE);
754 TRUE, TRUE,
755 MAK_TELEPORT, 1, 1, FALSE);
758 TRUE, TRUE,
759 MAK_TELEPORT, 1,
764 TRUE, TRUE,
765 MAK_TELEPORT, 1,
770 TRUE, TRUE,
771 MAK_TELEPORT, 1,
776 TRUE, TRUE,
777 MAK_TELEPORT, 1,
782 TRUE, TRUE,
783 MAK_TELEPORT, 1,
787 TRUE, TRUE,
788 MAK_TELEPORT, 1,
792 TRUE, FALSE,
793 MAK_STAYS, 0, 0, FALSE);
796 TRUE, FALSE,
797 MAK_STAYS, 0, 0, FALSE);
800 FALSE, TRUE,
802 /* Overwritten by the ruleset */
803 0, 1, FALSE);
806 FALSE, TRUE,
808 /* Overwritten by the ruleset */
809 0, 1, FALSE);
812 FALSE, TRUE,
814 /* Overwritten by the ruleset */
815 0, 1, FALSE);
818 FALSE, TRUE,
820 /* Overwritten by the ruleset */
821 0, 1, FALSE);
824 FALSE, TRUE,
825 /* Tries a forced move if the target unit's tile has
826 * no non-allied units and the occupychance dice roll
827 * tells it to move. */
829 1, 1, FALSE);
830
833
836
839
840 /* The structure even for these need to be created, for
841 * the action_id_rule_name() to work on iterations. */
842
843 /*
844 actions[ACTION_UNUSED_1]
845 = unit_action_new(ACTION_UNUSED_1, ACTRES_NONE,
846 FALSE, FALSE,
847 MAK_UNREPRESENTABLE,
848 0, 0, FALSE);
849 */
850}
851
852/**********************************************************************/
855void actions_init(void)
856{
857 int i, j;
858
859 for (i = 0; i < ACTRES_LAST; i++) {
861 }
862 for (i = 0; i < ACTIVITY_LAST; i++) {
864 }
865
866 /* Hard code the actions */
868
869 /* Initialize the action enabler list */
870 action_iterate_all(act) {
873
874 /* Initialize action obligatory hard requirements. */
876
877 /* Obligatory hard requirements are sorted by requirement in the source
878 * code. This makes it easy to read, modify and explain it. */
880
881 /* Initialize the action auto performers. */
882 for (i = 0; i < MAX_NUM_ACTION_AUTO_PERFORMERS; i++) {
883 /* Nothing here. Nothing after this point. */
885
886 /* The criteria to pick *this* auto performer for its cause. */
888
889 for (j = 0; j < MAX_NUM_ACTIONS; j++) {
890 /* Nothing here. Nothing after this point. */
892 }
893 }
894
895 /* The actions them self are now initialized. */
897}
898
899/**********************************************************************/
905{
906 /* Some obligatory hard requirements needs access to the rest of the
907 * ruleset. */
909}
910
911/**********************************************************************/
914void actions_free(void)
915{
916 int i;
917
918 /* Don't consider the actions to be initialized any longer. */
920
921 action_iterate_all(act) {
925
927
928 FC_FREE(actions[act]);
930
931 /* Free the obligatory hard action requirements. */
933
934 /* Free the action auto performers. */
935 for (i = 0; i < MAX_NUM_ACTION_AUTO_PERFORMERS; i++) {
937 }
938
940
941 for (i = 0; i < ACTRES_LAST; i++) {
943 actlist_by_result[i] = nullptr;
944 }
945 for (i = 0; i < ACTIVITY_LAST; i++) {
947 actlist_by_activity[i] = nullptr;
948 }
949}
950
951/**********************************************************************/
957{
958 if (!actions_initialized) {
959 /* The actions them self aren't initialized yet. */
960 return FALSE;
961 }
962
964 if (actions[act]->ui_name[0] == '\0') {
965 /* A noninternal action without a UI name exists means that
966 * the ruleset haven't loaded yet. The ruleset loading will assign
967 * a default name to any actions not named by the ruleset.
968 * The client will get this name from the server. */
969 return FALSE;
970 }
972
973 /* The actions should be ready for use. */
974 return TRUE;
975}
976
977/**********************************************************************/
980static struct action *action_new(action_id id,
983 const int min_distance,
984 const int max_distance,
986{
987 struct action *action;
988
989 action = fc_malloc(sizeof(*action));
990
991 action->id = id;
993
995
996 if (result != ACTRES_LAST) {
998
1000
1001 if (act != ACTIVITY_LAST) {
1003 }
1004 }
1005
1006 /* Not set here */
1008
1013
1014 /* ASTK_NONE implies ACT_TGT_COMPL_SIMPLE and
1015 * !ASTK_NONE implies !ACT_TGT_COMPL_SIMPLE */
1020 "%s contradicts itself regarding sub targets.",
1022
1023 /* The distance between the actor and itself is always 0. */
1025 || (min_distance == 0 && max_distance == 0));
1026
1029
1031
1032 /* Loaded from the ruleset. Until generalized actions are ready it has to
1033 * be defined separately from other action data. */
1034 action->ui_name[0] = '\0';
1035 action->quiet = FALSE;
1037
1038 return action;
1039}
1040
1041/**********************************************************************/
1044static struct action *
1046 enum action_result result,
1047 bool rare_pop_up,
1050 const int min_distance,
1051 const int max_distance,
1053{
1054 struct action *act = action_new(id, AAK_UNIT, result,
1057
1059
1061
1063
1064 return act;
1065}
1066
1067/**********************************************************************/
1071 enum action_result result)
1072{
1073 struct action *act = action_new(id, AAK_PLAYER, result,
1074 0, 0, FALSE);
1075
1076 return act;
1077}
1078
1079/**********************************************************************/
1083 enum action_result result)
1084{
1085 struct action *act = action_new(id, AAK_CITY, result,
1086 0, 0, FALSE);
1087
1088 return act;
1089}
1090
1091/**********************************************************************/
1094bool action_id_exists(const action_id act_id)
1095{
1096 /* Actions are still hard coded. */
1097 return gen_action_is_valid(act_id) && actions[act_id];
1098}
1099
1100/**********************************************************************/
1105struct action *action_by_rule_name(const char *name)
1106{
1107 /* Actions are still hard coded in the gen_action enum. */
1109
1110 if (!action_id_exists(act_id)) {
1111 /* Nothing to return. */
1112
1113 log_verbose("Asked for non existing action named %s", name);
1114
1115 return nullptr;
1116 }
1117
1118 return action_by_number(act_id);
1119}
1120
1121/**********************************************************************/
1125{
1126 fc_assert_ret_val_msg(paction, AAK_COUNT, "Action doesn't exist.");
1127
1128 return paction->actor_kind;
1129}
1130
1131/**********************************************************************/
1135 const struct action *paction)
1136{
1137 fc_assert_ret_val_msg(paction, ATK_COUNT, "Action doesn't exist.");
1138
1139 return paction->target_kind;
1140}
1141
1142/**********************************************************************/
1146 const struct action *paction)
1147{
1148 fc_assert_ret_val_msg(paction, ASTK_COUNT, "Action doesn't exist.");
1149
1150 return paction->sub_target_kind;
1151}
1152
1153/**********************************************************************/
1159{
1160 fc_assert_ret_val(paction != nullptr, FALSE);
1161
1162 return paction->target_complexity >= ACT_TGT_COMPL_FLEXIBLE;
1163}
1164
1165/**********************************************************************/
1172{
1173 fc_assert_ret_val(paction != nullptr, FALSE);
1174
1175 return paction->target_complexity >= ACT_TGT_COMPL_MANDATORY;
1176}
1177
1178/**********************************************************************/
1187{
1189 FALSE, "Action %d don't exist.", act_id);
1191
1192 return actions[act_id]->actor.is_unit.rare_pop_up;
1193}
1194
1195/**********************************************************************/
1200 const int distance)
1201{
1204}
1205
1206/**********************************************************************/
1211 const int distance)
1212{
1214
1215 return (distance >= action->min_distance
1216 && action_distance_inside_max(action, distance));
1217}
1218
1219/**********************************************************************/
1222bool action_would_be_blocked_by(const struct action *blocked,
1223 const struct action *blocker)
1224{
1225 fc_assert_ret_val(blocked, FALSE);
1226 fc_assert_ret_val(blocker, FALSE);
1227
1228 return BV_ISSET(blocked->blocked_by, action_number(blocker));
1229}
1230
1231/**********************************************************************/
1234int action_number(const struct action *action)
1235{
1236 return action->id;
1237}
1238
1239/**********************************************************************/
1242const char *action_rule_name(const struct action *action)
1243{
1244 /* Rule name is still hard coded. */
1245 return action_id_rule_name(action->id);
1246}
1247
1248/**********************************************************************/
1256const char *action_name_translation(const struct action *paction)
1257{
1258 /* Use action_id_name_translation() to format the UI name. */
1260}
1261
1262/**********************************************************************/
1266{
1267 fc_assert_msg(actions[act_id], "Action %d don't exist.", act_id);
1268
1269 return gen_action_name(act_id);
1270}
1271
1272/**********************************************************************/
1277{
1278 return action_prepare_ui_name(act_id, "", ACTPROB_NA, nullptr);
1279}
1280
1281/**********************************************************************/
1285 const char *mnemonic)
1286{
1287 return action_prepare_ui_name(act_id, mnemonic, ACTPROB_NA, nullptr);
1288}
1289
1290/**********************************************************************/
1297static const char *action_prob_to_text(const struct act_prob prob)
1298{
1299 static struct astring chance = ASTRING_INIT;
1300
1301 /* How to interpret action probabilities like prob is documented in
1302 * fc_types.h */
1303 if (action_prob_is_signal(prob)) {
1305 || action_prob_not_relevant(prob));
1306
1307 /* Unknown because of missing server support or should not exits. */
1308 return nullptr;
1309 }
1310
1311 if (prob.min == prob.max) {
1312 /* Only one probability in range. */
1313
1314 /* TRANS: the probability that an action will succeed. Given in
1315 * percentage. Resolution is 0.5%. */
1316 astr_set(&chance, _("%.1f%%"), (double)prob.max / ACTPROB_VAL_1_PCT);
1317 } else {
1318 /* TRANS: the interval (end points included) where the probability of
1319 * the action's success is. Given in percentage. Resolution is 0.5%. */
1320 astr_set(&chance, _("[%.1f%%, %.1f%%]"),
1321 (double)prob.min / ACTPROB_VAL_1_PCT,
1322 (double)prob.max / ACTPROB_VAL_1_PCT);
1323 }
1324
1325 return astr_str(&chance);
1326}
1327
1328/**********************************************************************/
1338const char *action_prepare_ui_name(action_id act_id, const char *mnemonic,
1339 const struct act_prob prob,
1340 const char *custom)
1341{
1342 struct astring chance = ASTRING_INIT;
1343
1344 /* Text representation of the probability. */
1345 const char *probtxt;
1346
1347 if (!actions_are_ready()) {
1348 /* Could be a client who haven't gotten the ruleset yet */
1349
1350 /* so there shouldn't be any action probability to show */
1352
1353 /* but the action should be valid */
1355 "Invalid action",
1356 "Invalid action %d", act_id);
1357
1358 /* and no custom text will be inserted */
1359 fc_assert(custom == nullptr || custom[0] == '\0');
1360
1361 /* Make the best of what is known */
1362 astr_set(&ui_name_str, _("%s%s (name may be wrong)"),
1363 mnemonic, action_id_rule_name(act_id));
1364
1365 /* Return the guess. */
1366 return astr_str(&ui_name_str);
1367 }
1368
1370
1371 /* Format the info part of the action's UI name. */
1372 if (probtxt != nullptr && custom != nullptr) {
1373 /* TRANS: action UI name's info part with custom info and probability.
1374 * Hint: you can move the paren handling from this string to the action
1375 * names if you need to add extra information (like a mnemonic letter
1376 * that doesn't appear in the action UI name) to it. In that case you
1377 * must do so for all strings with this comment and for every action
1378 * name. To avoid a `()` when no UI name info part is added you have
1379 * to add the extra information to every action name or remove the
1380 * surrounding parens. */
1381 astr_set(&chance, _(" (%s; %s)"), custom, probtxt);
1382 } else if (probtxt != nullptr) {
1383 /* TRANS: action UI name's info part with probability.
1384 * Hint: you can move the paren handling from this string to the action
1385 * names if you need to add extra information (like a mnemonic letter
1386 * that doesn't appear in the action UI name) to it. In that case you
1387 * must do so for all strings with this comment and for every action
1388 * name. To avoid a `()` when no UI name info part is added you have
1389 * to add the extra information to every action name or remove the
1390 * surrounding parens. */
1391 astr_set(&chance, _(" (%s)"), probtxt);
1392 } else if (custom != nullptr) {
1393 /* TRANS: action UI name's info part with custom info.
1394 * Hint: you can move the paren handling from this string to the action
1395 * names if you need to add extra information (like a mnemonic letter
1396 * that doesn't appear in the action UI name) to it. In that case you
1397 * must do so for all strings with this comment and for every action
1398 * name. To avoid a `()` when no UI name info part is added you have
1399 * to add the extra information to every action name or remove the
1400 * surrounding parens. */
1401 astr_set(&chance, _(" (%s)"), custom);
1402 } else {
1403 /* No info part to display. */
1405 }
1406
1407 fc_assert_msg(actions[act_id], "Action %d don't exist.", act_id);
1408
1409 /* Escape any instances of the mnemonic in the action's UI format string.
1410 * (Assumes any mnemonic can be escaped by doubling, and that they are
1411 * unlikely to appear in a format specifier. True for clients seen so
1412 * far: Gtk's _ and Qt's &) */
1413 {
1414 struct astring fmtstr = ASTRING_INIT;
1415 const char *ui_name = _(actions[act_id]->ui_name);
1416
1417 if (mnemonic[0] != '\0') {
1418 const char *hit;
1419
1420 fc_assert(!strchr(mnemonic, '%'));
1421 while ((hit = strstr(ui_name, mnemonic))) {
1422 astr_add(&fmtstr, "%.*s%s%s", (int)(hit - ui_name), ui_name,
1424 ui_name = hit + strlen(mnemonic);
1425 }
1426 }
1427 astr_add(&fmtstr, "%s", ui_name);
1428
1429 /* Use the modified format string */
1431 astr_str(&chance));
1432
1433 astr_free(&fmtstr);
1434 }
1435
1436 astr_free(&chance);
1437
1438 return astr_str(&ui_name_str);
1439}
1440
1441/**********************************************************************/
1449const char *action_prob_explain(const struct act_prob prob)
1450{
1451 static struct astring tool_tip = ASTRING_INIT;
1452
1453 if (action_prob_is_signal(prob)) {
1455
1456 /* Missing server support. No in game action will change this. */
1458 } else if (prob.min == prob.max) {
1459 /* TRANS: action probability of success. Given in percentage.
1460 * Resolution is 0.5%. */
1461 astr_set(&tool_tip, _("The probability of success is %.1f%%."),
1462 (double)prob.max / ACTPROB_VAL_1_PCT);
1463 } else {
1465 /* TRANS: action probability interval (min to max). Given in
1466 * percentage. Resolution is 0.5%. The string at the end is
1467 * shown when the interval is wide enough to not be caused by
1468 * rounding. It explains that the interval is imprecise because
1469 * the player doesn't have enough information. */
1470 _("The probability of success is %.1f%%, %.1f%% or somewhere"
1471 " in between.%s"),
1472 (double)prob.min / ACTPROB_VAL_1_PCT,
1473 (double)prob.max / ACTPROB_VAL_1_PCT,
1474 prob.max - prob.min > 1 ?
1475 /* TRANS: explanation used in the action probability tooltip
1476 * above. Preserve leading space. */
1477 _(" (This is the most precise interval I can calculate "
1478 "given the information our nation has access to.)") :
1479 "");
1480 }
1481
1482 return astr_str(&tool_tip);
1483}
1484
1485/**********************************************************************/
1490{
1492 "Action %s isn't performed by a unit",
1494
1495 return paction->id + L_LAST;
1496}
1497
1498/**********************************************************************/
1502{
1503 struct action_enabler *enabler;
1504
1505 enabler = fc_malloc(sizeof(*enabler));
1506 enabler->rulesave.ruledit_disabled = FALSE;
1507 enabler->rulesave.comment = nullptr;
1508 requirement_vector_init(&enabler->actor_reqs);
1509 requirement_vector_init(&enabler->target_reqs);
1510
1511 /* Make sure that action doesn't end up as a random value that happens to
1512 * be a valid action id. */
1513 enabler->action = ACTION_NONE;
1514
1515 return enabler;
1516}
1517
1518/**********************************************************************/
1522{
1523 if (enabler->rulesave.comment != nullptr) {
1524 free(enabler->rulesave.comment);
1525 }
1526
1527 requirement_vector_free(&enabler->actor_reqs);
1528 requirement_vector_free(&enabler->target_reqs);
1529
1530 free(enabler);
1531}
1532
1533/**********************************************************************/
1536struct action_enabler *
1538{
1540
1541 enabler->action = original->action;
1542
1543 requirement_vector_copy(&enabler->actor_reqs, &original->actor_reqs);
1544 requirement_vector_copy(&enabler->target_reqs, &original->target_reqs);
1545
1546 return enabler;
1547}
1548
1549/**********************************************************************/
1553{
1554 /* Sanity check: a non existing action enabler can't be added. */
1556 /* Sanity check: a non existing action doesn't have enablers. */
1558
1561 enabler);
1562}
1563
1564/**********************************************************************/
1570{
1571 /* Sanity check: a non existing action enabler can't be removed. */
1573 /* Sanity check: a non existing action doesn't have enablers. */
1575
1578 enabler);
1579}
1580
1581/**********************************************************************/
1584struct action_enabler_list *
1586{
1587 /* Sanity check: a non existing action doesn't have enablers. */
1589
1591}
1592
1593/**********************************************************************/
1604static struct req_vec_problem *
1606 const struct obligatory_req_vector *oblig)
1607{
1608 struct action *paction;
1609
1610 /* Sanity check: a non existing action enabler is missing but it doesn't
1611 * miss any obligatory hard requirements. */
1612 fc_assert_ret_val(enabler, nullptr);
1613
1614 /* Sanity check: a non existing action doesn't have any obligatory hard
1615 * requirements. */
1618
1619 /* No obligatory hard requirements. */
1620 fc_assert_ret_val(oblig, nullptr);
1621
1623 struct req_vec_problem *out;
1624 int i;
1625 bool fulfilled = FALSE;
1626
1627 /* Check each alternative. */
1628 for (i = 0; i < obreq->contras->alternatives; i++) {
1629 const struct requirement_vector *ae_vec;
1630
1631 /* Select action enabler requirement vector. */
1632 ae_vec = (obreq->contras->alternative[i].is_target
1633 ? &enabler->target_reqs
1634 : &enabler->actor_reqs);
1635
1636 if (does_req_contradicts_reqs(&obreq->contras->alternative[i].req,
1637 ae_vec)
1638 /* Consider the hard requirement fulfilled since a universal that
1639 * never is there always will be absent in this ruleset. */
1640 || (obreq->contras->alternative[i].req.present
1642 &obreq->contras->alternative[i].req.source))) {
1643 /* It is enough that one alternative accepts the enabler. */
1644 fulfilled = TRUE;
1645 break;
1646 }
1647
1648 /* Fall back to the next alternative */
1649 }
1650
1651 if (fulfilled) {
1652 /* This obligatory hard requirement isn't a problem. */
1653 continue;
1654 }
1655
1656 /* Missing hard obligatory requirement detected */
1657
1658 out = req_vec_problem_new(obreq->contras->alternatives,
1659 obreq->error_msg,
1661
1662 for (i = 0; i < obreq->contras->alternatives; i++) {
1663 const struct requirement_vector *ae_vec;
1664
1665 /* Select action enabler requirement vector. */
1666 ae_vec = (obreq->contras->alternative[i].is_target
1667 ? &enabler->target_reqs
1668 : &enabler->actor_reqs);
1669
1670 /* The suggested fix is to append a requirement that makes the enabler
1671 * contradict the missing hard obligatory requirement detector. */
1672 out->suggested_solutions[i].operation = RVCO_APPEND;
1673 out->suggested_solutions[i].vector_number
1675
1676 /* Change the requirement from what should conflict to what is
1677 * wanted. */
1678 out->suggested_solutions[i].req.present
1679 = !obreq->contras->alternative[i].req.present;
1680 out->suggested_solutions[i].req.source
1681 = obreq->contras->alternative[i].req.source;
1682 out->suggested_solutions[i].req.range
1683 = obreq->contras->alternative[i].req.range;
1684 out->suggested_solutions[i].req.survives
1685 = obreq->contras->alternative[i].req.survives;
1686 out->suggested_solutions[i].req.quiet
1687 = obreq->contras->alternative[i].req.quiet;
1688 }
1689
1690 /* Return the first problem found. The next problem will be detected
1691 * during the next call. */
1692 return out;
1694
1695 /* No obligatory req problems found. */
1696 return nullptr;
1697}
1698
1699/**********************************************************************/
1708struct req_vec_problem *
1710{
1711 struct action *paction;
1713 struct req_vec_problem *out;
1714
1715 /* Sanity check: a non existing action enabler is missing but it doesn't
1716 * miss any obligatory hard requirements. */
1717 fc_assert_ret_val(enabler, nullptr);
1718
1719 /* Sanity check: a non existing action doesn't have any obligatory hard
1720 * requirements. */
1723
1724 if (paction->result != ACTRES_NONE) {
1725 /* A hard coded action result may mean obligatory requirements. */
1727 if (out != nullptr) {
1728 return out;
1729 }
1730 }
1731
1735 if (!BV_ISSET(paction->sub_results, sub_res)) {
1736 /* Not relevant */
1737 continue;
1738 }
1739
1740 /* The action has this sub result. Check its hard requirements. */
1743 if (out != nullptr) {
1744 return out;
1745 }
1746 }
1747
1748 /* No obligatory req problems found. */
1749 return nullptr;
1750}
1751
1752/**********************************************************************/
1758static struct requirement *
1760{
1762 if (preq->source.kind == VUT_DIPLREL
1763 && preq->range == REQ_RANGE_LOCAL) {
1764 return preq;
1765 }
1767
1768 return nullptr;
1769}
1770
1771/**********************************************************************/
1777static struct req_vec_problem *
1779 const struct action_enabler *enabler)
1780{
1781 struct req_vec_problem *out;
1782 struct requirement *local_diplrel;
1783 struct requirement *claimed_req;
1787 struct astring astr;
1788
1790 /* Not tile targeted */
1791 return nullptr;
1792 }
1793
1795 if (local_diplrel == nullptr) {
1796 /* No local diplrel */
1797 return nullptr;
1798 }
1799
1800 /* Tile is unclaimed as a requirement. */
1802 tile_is_unclaimed.survives = FALSE;
1803 tile_is_unclaimed.source.kind = VUT_CITYTILE;
1804 tile_is_unclaimed.present = FALSE;
1805 tile_is_unclaimed.source.value.citytile = CITYT_CLAIMED;
1806
1808 &enabler->target_reqs);
1809
1810 if (claimed_req) {
1811 /* Already clear */
1812 return nullptr;
1813 }
1814
1815 /* Tile is claimed as a requirement. */
1817 tile_is_claimed.survives = FALSE;
1818 tile_is_claimed.source.kind = VUT_CITYTILE;
1819 tile_is_claimed.present = TRUE;
1820 tile_is_claimed.source.value.citytile = CITYT_CLAIMED;
1821
1823 1,
1824 /* TRANS: ruledit shows this when an enabler for a tile targeted
1825 * action requires that the actor has a diplomatic relationship to
1826 * the target but doesn't require that the target tile is claimed.
1827 * (DiplRel requirements to an unclaimed tile are never fulfilled
1828 * so this is implicit.) */
1829 N_("Requirement {%s} of action \"%s\" implies a claimed "
1830 "tile. No diplomatic relation to Nature."),
1832
1833 astr_free(&astr);
1834
1835 /* The solution is to add the requirement that the tile is claimed */
1836 out->suggested_solutions[0].req = tile_is_claimed;
1837 out->suggested_solutions[0].vector_number
1839 out->suggested_solutions[0].operation = RVCO_APPEND;
1840
1841 return out;
1842}
1843
1844/**********************************************************************/
1850static struct req_vec_problem *
1852{
1853 struct req_vec_problem *out;
1854 struct requirement *local_diplrel;
1855 struct requirement *unclaimed_req;
1858 struct astring astr1;
1859 struct astring astr2;
1860
1862 /* Not tile targeted */
1863 return nullptr;
1864 }
1865
1867 if (local_diplrel == nullptr) {
1868 /* No local diplrel */
1869 return nullptr;
1870 }
1871
1872 /* Tile is claimed as a requirement. */
1874 tile_is_claimed.survives = FALSE;
1875 tile_is_claimed.source.kind = VUT_CITYTILE;
1876 tile_is_claimed.present = TRUE;
1877 tile_is_claimed.source.value.citytile = CITYT_CLAIMED;
1878
1880 &enabler->target_reqs);
1881
1882 if (unclaimed_req == nullptr) {
1883 /* No unclaimed req */
1884 return nullptr;
1885 }
1886
1888 2,
1889 /* TRANS: ruledit shows this when an enabler for a tile targeted
1890 * action requires that the target tile is unclaimed and that the
1891 * actor has a diplomatic relationship to the target. (DiplRel
1892 * requirements to an unclaimed tile are never fulfilled.) */
1893 N_("In enabler for \"%s\": No diplomatic relation to Nature."
1894 " Requirements {%s} and {%s} contradict each other."),
1898
1899 astr_free(&astr1);
1900 astr_free(&astr2);
1901
1902 /* The first suggestion is to remove the diplrel */
1903 out->suggested_solutions[0].req = *local_diplrel;
1904 out->suggested_solutions[0].vector_number
1906 out->suggested_solutions[0].operation = RVCO_REMOVE;
1907
1908 /* The 2nd is to remove the requirement that the tile is unclaimed */
1909 out->suggested_solutions[1].req = *unclaimed_req;
1910 out->suggested_solutions[1].vector_number
1912 out->suggested_solutions[1].operation = RVCO_REMOVE;
1913
1914 return out;
1915}
1916
1917/**********************************************************************/
1922struct req_vec_problem *
1924{
1925 struct req_vec_problem *out;
1926
1928 if (out != nullptr) {
1929 return out;
1930 }
1931
1932 /* Look for errors in the requirement vectors. */
1933 out = req_vec_suggest_repair(&enabler->actor_reqs,
1935 enabler);
1936 if (out != nullptr) {
1937 return out;
1938 }
1939
1940 out = req_vec_suggest_repair(&enabler->target_reqs,
1942 enabler);
1943 if (out != nullptr) {
1944 return out;
1945 }
1946
1947 /* Enabler specific contradictions. */
1949 if (out != nullptr) {
1950 return out;
1951 }
1952
1953 /* Needed in action not enabled explanation finding. */
1955 if (out != nullptr) {
1956 return out;
1957 }
1958
1959 /* No problems found. */
1960 return nullptr;
1961}
1962
1963/**********************************************************************/
1970static struct req_vec_problem *
1972{
1973 struct req_vec_problem *out;
1974
1975 out = nullptr;
1976
1977 return out;
1978}
1979
1980/**********************************************************************/
1988struct req_vec_problem *
1990{
1991 struct action *paction;
1992 struct req_vec_problem *out;
1993
1995 if (out) {
1996 /* A bug, not just a potential improvement */
1997 return out;
1998 }
1999
2001
2002 /* Look for improvement suggestions to the requirement vectors. */
2005 enabler);
2006 if (out) {
2007 return out;
2008 }
2009 out = req_vec_suggest_improvement(&enabler->target_reqs,
2011 enabler);
2012 if (out) {
2013 return out;
2014 }
2015
2016 /* Detect unused action enablers. */
2018 bool has_user = FALSE;
2019
2023 &(enabler->actor_reqs))) {
2024 has_user = TRUE;
2025 break;
2026 }
2028
2029 if (!has_user) {
2030 /* TRANS: ruledit warns a user about an unused action enabler */
2031 out = req_vec_problem_new(0, N_("Action enabler for \"%s\" is never"
2032 " used by any unit."),
2034 }
2035 }
2036 if (out != nullptr) {
2037 return out;
2038 }
2039
2041
2042 return out;
2043}
2044
2045/**********************************************************************/
2054 const struct requirement_vector *vec)
2055{
2056 struct action_enabler *ae = (struct action_enabler *)enabler;
2057
2058 if (vec == &ae->actor_reqs) {
2059 return 0;
2060 } else if (vec == &ae->target_reqs) {
2061 return 1;
2062 } else {
2063 return -1;
2064 }
2065}
2066
2067/********************************************************************/
2075struct requirement_vector *
2077 req_vec_num_in_item number)
2078{
2079 struct action_enabler *ae = (struct action_enabler *)enabler;
2080
2081 fc_assert_ret_val(number >= 0, nullptr);
2082
2083 switch (number) {
2084 case 0:
2085 return &ae->actor_reqs;
2086 case 1:
2087 return &ae->target_reqs;
2088 default:
2089 return nullptr;
2090 }
2091}
2092
2093/*********************************************************************/
2101{
2102 switch (vec) {
2103 case 0:
2104 /* TRANS: requirement vector in an action enabler (ruledit) */
2105 return _("actor_reqs");
2106 case 1:
2107 /* TRANS: requirement vector in an action enabler (ruledit) */
2108 return _("target_reqs");
2109 default:
2110 return nullptr;
2111 }
2112}
2113
2114/**********************************************************************/
2119static const struct impr_type *
2121{
2122 /* Only used with city targets */
2124
2125 if (target_city->production.kind == VUT_IMPROVEMENT) {
2126 /* The local building is what the target city currently is building. */
2127 return target_city->production.value.building;
2128 } else {
2129 /* In the current semantic the local building is always the building
2130 * being built. */
2131 /* TODO: Consider making the local building the target building for
2132 * actions that allows specifying a building target. */
2133 return nullptr;
2134 }
2135}
2136
2137/**********************************************************************/
2142static const struct unit_type *
2144{
2145 /* Only used with city targets */
2147
2148 if (target_city->production.kind == VUT_UTYPE) {
2149 /* The local unit type is what the target city currently is
2150 * building. */
2151 return target_city->production.value.utype;
2152 } else {
2153 /* In the current semantic the local utype is always the type of the
2154 * unit being built. */
2155 return nullptr;
2156 }
2157}
2158
2159/**********************************************************************/
2167static const struct tile *
2169 const struct unit *actor_unit,
2170 const struct tile *target_tile_arg,
2171 const struct city *target_city,
2172 const struct unit *target_unit)
2173{
2174 if (target_tile_arg != nullptr) {
2175 /* Trust the caller. */
2176 return target_tile_arg;
2177 }
2178
2179 /* Action should always be set */
2180 fc_assert_ret_val(act, nullptr);
2181
2182 switch (action_get_target_kind(act)) {
2183 case ATK_CITY:
2185 return city_tile(target_city);
2186 case ATK_UNIT:
2187 if (target_unit == nullptr) {
2188 fc_assert(target_unit != nullptr);
2189 return nullptr;
2190 }
2191 return unit_tile(target_unit);
2192 case ATK_STACK:
2194 if (target_unit) {
2195 return unit_tile(target_unit);
2196 }
2197
2199 case ATK_TILE:
2200 case ATK_EXTRAS:
2202 return target_tile_arg;
2203 case ATK_SELF:
2204 if (actor_unit != nullptr) {
2205 return unit_tile(actor_unit);
2206 }
2207 return nullptr;
2208 case ATK_COUNT:
2209 /* Handled below. */
2210 break;
2211 }
2212
2213 fc_assert_msg(FALSE, "Bad action target kind %d for action %s",
2215 return nullptr;
2216}
2217
2218/**********************************************************************/
2227static const struct city *
2229 const struct unit *actor_unit,
2230 const struct tile *target_tile,
2231 const struct city *target_city_arg,
2232 const struct unit *target_unit)
2233{
2234 if (target_city_arg != nullptr) {
2235 /* Trust the caller. */
2236 return target_city_arg;
2237 }
2238
2239 /* action should always be set */
2240 fc_assert_ret_val(act, nullptr);
2241
2242 switch (action_get_target_kind(act)) {
2243 case ATK_CITY:
2245 return target_city_arg;
2246 case ATK_UNIT:
2250 case ATK_STACK:
2252 if (target_unit) {
2255 }
2256
2258 case ATK_TILE:
2259 case ATK_EXTRAS:
2261 return tile_city(target_tile);
2262 case ATK_SELF:
2263 if (actor_unit != nullptr) {
2264 struct tile *ptile = unit_tile(actor_unit);
2265
2266 if (ptile != nullptr) {
2267 return tile_city(ptile);
2268 }
2269 }
2270 return nullptr;
2271 case ATK_COUNT:
2272 /* Handled below. */
2273 break;
2274 }
2275
2276 fc_assert_msg(FALSE, "Bad action target kind %d for action %s",
2278 return nullptr;
2279}
2280
2281/**********************************************************************/
2288 const struct action *act,
2289 const struct unit *actor_unit,
2290 const struct tile *target_tile_arg,
2291 const struct city *target_city_arg,
2292 const struct unit *target_unit)
2293{
2294 const struct tile *target_tile
2297 const struct city *target_city
2300
2302 struct action *blocker = action_by_number(blocker_id);
2303
2304 if (action_get_actor_kind(blocker) != AAK_UNIT) {
2305 /* Currently, only unit's actions may block each other */
2306 continue;
2307 }
2308
2309 if (!action_would_be_blocked_by(act, blocker)) {
2310 /* It doesn't matter if it is legal. It won't block the action. */
2311 continue;
2312 }
2313
2314 switch (action_get_target_kind(blocker)) {
2315 case ATK_CITY:
2316 if (!target_city) {
2317 /* Can't be enabled. No target. */
2318 continue;
2319 }
2322 return blocker;
2323 }
2324 break;
2325 case ATK_UNIT:
2326 if (!target_unit) {
2327 /* Can't be enabled. No target. */
2328 continue;
2329 }
2332 return blocker;
2333 }
2334 break;
2335 case ATK_STACK:
2336 if (!target_tile) {
2337 /* Can't be enabled. No target. */
2338 continue;
2339 }
2342 return blocker;
2343 }
2344 break;
2345 case ATK_TILE:
2346 if (!target_tile) {
2347 /* Can't be enabled. No target. */
2348 continue;
2349 }
2351 actor_unit, target_tile, nullptr)) {
2352 return blocker;
2353 }
2354 break;
2355 case ATK_EXTRAS:
2356 if (!target_tile) {
2357 /* Can't be enabled. No target. */
2358 continue;
2359 }
2361 actor_unit, target_tile, nullptr)) {
2362 return blocker;
2363 }
2364 break;
2365 case ATK_SELF:
2367 return blocker;
2368 }
2369 break;
2370 case ATK_COUNT:
2372 continue);
2373 break;
2374 }
2376
2377 /* Not blocked. */
2378 return nullptr;
2379}
2380
2381/**********************************************************************/
2401static bool
2403 const struct unit_type *actor_unittype,
2404 bool ignore_third_party)
2405{
2406 switch (paction->result) {
2407 case ACTRES_JOIN_CITY:
2408 if (actor_unittype->pop_cost <= 0 && !is_super_specialist(actor_unittype->spec_type)) {
2409 /* Reason: Must have something to add. */
2410 return FALSE;
2411 }
2412 break;
2413
2414 case ACTRES_BOMBARD:
2415 if (actor_unittype->bombard_rate <= 0) {
2416 /* Reason: Can't bombard if it never fires. */
2417 return FALSE;
2418 }
2419
2420 if (actor_unittype->attack_strength <= 0) {
2421 /* Reason: Can't bombard without attack strength. */
2422 return FALSE;
2423 }
2424
2425 break;
2426
2428 if (actor_unittype->obsoleted_by == U_NOT_OBSOLETED) {
2429 /* Reason: Nothing to upgrade to. */
2430 return FALSE;
2431 }
2432 break;
2433
2434 case ACTRES_ATTACK:
2435 case ACTRES_WIPE_UNITS:
2437 if (actor_unittype->attack_strength <= 0) {
2438 /* Reason: Can't attack without strength. */
2439 return FALSE;
2440 }
2441 break;
2442
2443 case ACTRES_CONVERT:
2444 if (!actor_unittype->converted_to) {
2445 /* Reason: must be able to convert to something. */
2446 return FALSE;
2447 }
2448 break;
2449
2451 if (actor_unittype->transport_capacity < 1) {
2452 /* Reason: can't transport anything to unload. */
2453 return FALSE;
2454 }
2455 break;
2456
2458 if (actor_unittype->transport_capacity < 1) {
2459 /* Reason: can't transport anything to load. */
2460 return FALSE;
2461 }
2462 break;
2463
2468 if (!ignore_third_party) {
2469 bool has_transporter = FALSE;
2470
2474 break;
2475 }
2477
2478 if (!has_transporter) {
2479 /* Reason: no other unit can transport this unit. */
2480 return FALSE;
2481 }
2482 }
2483 break;
2484
2486 if (!ignore_third_party) {
2487 bool has_target = FALSE;
2489
2490 /* Use cache when it has been initialized */
2491 if (pclass->cache.native_bases != nullptr) {
2492 /* Extra being native one is a hard requirement */
2493 extra_type_list_iterate(pclass->cache.native_bases, pextra) {
2494 if (!territory_claiming_base(pextra->data.base)) {
2495 /* Hard requirement */
2496 continue;
2497 }
2498
2499 has_target = TRUE;
2500 break;
2502 } else {
2504
2506 if (!is_native_extra_to_uclass(pextra, pclass)) {
2507 /* Hard requirement */
2508 continue;
2509 }
2510
2511 has_target = TRUE;
2512 break;
2514 }
2515
2516 if (!has_target) {
2517 /* Reason: no extras can be conquered by this unit. */
2518 return FALSE;
2519 }
2520 }
2521 break;
2522
2523 case ACTRES_PARADROP:
2525 if (actor_unittype->paratroopers_range <= 0) {
2526 /* Reason: Can't paradrop 0 tiles. */
2527 return FALSE;
2528 }
2529 break;
2530
2531 case ACTRES_HUT_ENTER:
2535 case ACTRES_SPY_POISON:
2544 case ACTRES_SPY_ESCAPE:
2545 case ACTRES_TRADE_ROUTE:
2546 case ACTRES_MARKETPLACE:
2547 case ACTRES_HELP_WONDER:
2552 case ACTRES_FOUND_CITY:
2553 case ACTRES_STEAL_MAPS:
2554 case ACTRES_SPY_NUKE:
2555 case ACTRES_NUKE:
2556 case ACTRES_NUKE_UNITS:
2558 case ACTRES_EXPEL_UNIT:
2561 case ACTRES_HOME_CITY:
2562 case ACTRES_HOMELESS:
2563 case ACTRES_AIRLIFT:
2567 case ACTRES_HEAL_UNIT:
2568 case ACTRES_PILLAGE:
2569 case ACTRES_CLEAN:
2570 case ACTRES_FORTIFY:
2572 case ACTRES_CULTIVATE:
2573 case ACTRES_PLANT:
2574 case ACTRES_ROAD:
2575 case ACTRES_BASE:
2576 case ACTRES_MINE:
2577 case ACTRES_IRRIGATE:
2578 case ACTRES_SPY_ATTACK:
2579 case ACTRES_UNIT_MOVE:
2580 case ACTRES_TELEPORT:
2582 case ACTRES_SCOUT:
2584 case ACTRES_NONE:
2585 /* No hard unit type requirements. */
2586 break;
2587
2589 }
2590
2591 return TRUE;
2592}
2593
2594/**********************************************************************/
2610bool
2617
2618/**********************************************************************/
2630static enum fc_tristate
2632 const struct action *paction,
2633 const struct req_context *actor,
2634 const bool omniscient,
2635 const struct city *homecity)
2636{
2637 enum action_result result = paction->result;
2638
2639 if (actor == nullptr) {
2641 }
2642
2644 TRUE)) {
2645 /* Info leak: The actor player knows the type of their unit. */
2646 /* The actor unit type can't perform the action because of hard
2647 * unit type requirements. */
2648 return TRI_NO;
2649 }
2650
2651 switch (result) {
2652 case ACTRES_PARADROP:
2654 /* Reason: Keep the old rules. */
2655 /* Info leak: The player knows if their unit already has paradropped this
2656 * turn. */
2657 if (actor->unit->paradropped) {
2658 return TRI_NO;
2659 }
2660
2661 break;
2662
2663 case ACTRES_AIRLIFT:
2664 {
2665 /* Obligatory hard requirement. Checked here too since
2666 * action_hard_reqs_actor() may be called before any
2667 * action enablers are checked. */
2668 if (actor->city == nullptr) {
2669 /* No city to airlift from. */
2670 return TRI_NO;
2671 }
2672
2673 if (actor->player != city_owner(actor->city)
2675 && pplayers_allied(actor->player,
2676 city_owner(actor->city)))) {
2677 /* Not allowed to airlift from this source. */
2678 return TRI_NO;
2679 }
2680
2681 if (!(omniscient || city_owner(actor->city) == actor->player)) {
2682 /* Can't check for airlifting capacity. */
2683 return TRI_MAYBE;
2684 }
2685
2686 if (0 >= actor->city->airlift
2689 /* The source cannot airlift for this turn (maybe already airlifted
2690 * or no airport).
2691 *
2692 * See also do_airline() in server/unittools.h. */
2693 return TRI_NO;
2694 }
2695 }
2696 break;
2697
2698 case ACTRES_CONVERT:
2699 /* Reason: Keep the old rules. */
2700 /* Info leak: The player knows their unit's cargo and location. */
2701 if (!unit_can_convert(nmap, actor->unit)) {
2702 return TRI_NO;
2703 }
2704 break;
2705
2708 if (unit_transported(actor->unit)) {
2709 if (!can_unit_unload(actor->unit, unit_transport_get(actor->unit))) {
2710 /* Can't leave current transport. */
2711 return TRI_NO;
2712 }
2713 }
2714 break;
2715
2717 if (!can_unit_unload(actor->unit, unit_transport_get(actor->unit))) {
2718 /* Keep the old rules about Unreachable and disembarks. */
2719 return TRI_NO;
2720 }
2721 break;
2722
2723 case ACTRES_HOMELESS:
2724 case ACTRES_UNIT_MOVE:
2725 case ACTRES_TELEPORT:
2729 case ACTRES_SPY_POISON:
2738 case ACTRES_SPY_ESCAPE:
2739 case ACTRES_TRADE_ROUTE:
2740 case ACTRES_MARKETPLACE:
2741 case ACTRES_HELP_WONDER:
2746 case ACTRES_FOUND_CITY:
2747 case ACTRES_JOIN_CITY:
2748 case ACTRES_STEAL_MAPS:
2749 case ACTRES_BOMBARD:
2750 case ACTRES_SPY_NUKE:
2751 case ACTRES_NUKE:
2752 case ACTRES_NUKE_UNITS:
2754 case ACTRES_EXPEL_UNIT:
2757 case ACTRES_HOME_CITY:
2759 case ACTRES_ATTACK:
2760 case ACTRES_WIPE_UNITS:
2766 case ACTRES_HEAL_UNIT:
2768 case ACTRES_CULTIVATE:
2769 case ACTRES_PLANT:
2770 case ACTRES_PILLAGE:
2771 case ACTRES_CLEAN:
2772 case ACTRES_FORTIFY:
2773 case ACTRES_ROAD:
2774 case ACTRES_BASE:
2775 case ACTRES_MINE:
2776 case ACTRES_IRRIGATE:
2780 case ACTRES_SPY_ATTACK:
2781 case ACTRES_HUT_ENTER:
2783 case ACTRES_SCOUT:
2785 case ACTRES_NONE:
2786 /* No hard unit requirements. */
2787 break;
2788
2790 }
2791
2792 return TRI_YES;
2793}
2794
2795/**********************************************************************/
2818static enum fc_tristate
2821 const struct req_context *actor,
2822 const struct req_context *target,
2823 const struct extra_type *target_extra,
2824 const bool omniscient,
2825 const struct city *homecity)
2826{
2827 enum fc_tristate out;
2830 const struct tile *atile = nullptr, *ttile = nullptr;
2831
2832 if (actor == nullptr) {
2834 } else {
2835 atile = actor->tile;
2836 }
2837 if (target == nullptr) {
2838 target = req_context_empty();
2839 } else {
2840 ttile = target->tile;
2841 }
2842
2843 fc_assert_msg((tkind == ATK_CITY && target->city != nullptr)
2844 || (tkind == ATK_TILE && ttile != nullptr)
2845 || (tkind == ATK_EXTRAS && ttile != nullptr)
2846 || (tkind == ATK_UNIT && target->unit != nullptr)
2847 /* At this level each individual unit is tested. */
2848 || (tkind == ATK_STACK && target->unit != nullptr)
2849 || (tkind == ATK_SELF),
2850 "Missing target!");
2851
2852 /* Info leak: The player knows where their unit/city is. */
2853 if (nullptr != atile && nullptr != ttile
2856 /* The distance between the actor and the target isn't inside the
2857 * action's accepted range. */
2858 return TRI_NO;
2859 }
2860
2861 switch (tkind) {
2862 case ATK_UNIT:
2863 /* The Freeciv code for all actions that is controlled by action
2864 * enablers and targets a unit assumes that the acting
2865 * player can see the target unit.
2866 * Examples:
2867 * - action_prob_vs_unit()'s quick check that the distance between actor
2868 * and target is acceptable would leak distance to target unit if the
2869 * target unit can't be seen.
2870 */
2871 if (!can_player_see_unit(actor->player, target->unit)) {
2872 return TRI_NO;
2873 }
2874 break;
2875 case ATK_CITY:
2876 /* The Freeciv code assumes that the player is aware of the target
2877 * city's existence. (How can you order an airlift to a city when you
2878 * don't know its city ID?) */
2880 actor->player)
2881 != target->city->id) {
2882 return TRI_NO;
2883 }
2884 break;
2885 case ATK_STACK:
2886 case ATK_TILE:
2887 case ATK_EXTRAS:
2888 case ATK_SELF:
2889 /* No special player knowledge checks. */
2890 break;
2891 case ATK_COUNT:
2893 break;
2894 }
2895
2897 ttile, target->city, target->unit)) {
2898 /* Allows an action to block an other action. If a blocking action is
2899 * legal the actions it blocks becomes illegal. */
2900 return TRI_NO;
2901 }
2902
2903 /* Actor specific hard requirements. */
2905
2906 if (out == TRI_NO) {
2907 /* Illegal because of a hard actor requirement. */
2908 return TRI_NO;
2909 }
2910
2911 /* Quick checks for action itself */
2912 if (paction->result == ACTRES_ATTACK
2913 || paction->result == ACTRES_WIPE_UNITS
2914 || paction->result == ACTRES_COLLECT_RANSOM) {
2915 /* Reason: Keep the old rules. */
2916 if (!can_unit_attack_tile(actor->unit, paction, ttile)) {
2917 return TRI_NO;
2918 }
2919 }
2920
2921 /* Hard requirements for results. */
2923 paction->result, actor,
2924 target, target_extra, out, omniscient,
2925 homecity);
2926
2927 if (out == TRI_NO) {
2928 /* Illegal because of a hard actor requirement. */
2929 return TRI_NO;
2930 }
2931
2932 if (paction->result == ACTRES_NUKE_UNITS) {
2934 != ATT_OK) {
2935 /* Unreachable. */
2936 return TRI_NO;
2937 }
2938 } else if (paction->result == ACTRES_PARADROP
2939 || paction->result == ACTRES_PARADROP_CONQUER) {
2940 if (can_player_see_tile(actor->player, ttile)) {
2941 /* Check for seen stuff that may kill the actor unit. */
2942
2943 /* Reason: Keep the old rules. Be merciful. */
2944 /* Info leak: The player sees the target tile. */
2946 && (!BV_ISSET(paction->sub_results, ACT_SUB_RES_MAY_EMBARK)
2947 || !unit_could_load_at(actor->unit, ttile))) {
2948 return TRI_NO;
2949 }
2950
2951 /* Reason: Keep the old rules. Be merciful. */
2952 /* Info leak: The player sees the target tile. */
2953 if (is_non_attack_city_tile(ttile, actor->player)) {
2954 return TRI_NO;
2955 }
2956
2957 /* Reason: Be merciful. */
2958 /* Info leak: The player sees all units checked. Invisible units are
2959 * ignored. */
2960 unit_list_iterate(ttile->units, pother) {
2961 if (can_player_see_unit(actor->player, pother)
2962 && !pplayers_allied(actor->player, unit_owner(pother))) {
2963 return TRI_NO;
2964 }
2966 }
2967 }
2968
2969 return out;
2970}
2971
2972/**********************************************************************/
2978static bool is_enabler_active(const struct action_enabler *enabler,
2979 const struct req_context *actor,
2980 const struct req_context *target)
2981{
2982 return are_reqs_active(actor, target, &enabler->actor_reqs, RPT_CERTAIN)
2983 && are_reqs_active(target, actor, &enabler->target_reqs, RPT_CERTAIN);
2984}
2985
2986/**********************************************************************/
2995static bool is_action_enabled(const struct civ_map *nmap,
2997 const struct req_context *actor,
2998 const struct req_context *target,
2999 const struct extra_type *target_extra,
3000 const struct city *actor_home)
3001{
3002 enum fc_tristate possible;
3003
3005 TRUE, actor_home);
3006
3007 if (possible != TRI_YES) {
3008 /* This context is omniscient. Should be yes or no. */
3010 "Is omniscient, should get yes or no.");
3011
3012 /* The action enablers are irrelevant since the action it self is
3013 * impossible. */
3014 return FALSE;
3015 }
3016
3017 return action_enablers_allow(wanted_action, actor, target);
3018}
3019
3020/**********************************************************************/
3025 const struct req_context *actor,
3026 const struct req_context *target)
3027{
3029 enabler) {
3030 if (is_enabler_active(enabler, actor, target)) {
3031 return TRUE;
3032 }
3034
3035 return FALSE;
3036}
3037
3038/**********************************************************************/
3044static bool
3047 const struct unit *actor_unit,
3048 const struct city *actor_home,
3049 const struct tile *actor_tile,
3050 const struct city *target_city)
3051{
3052 const struct impr_type *target_building;
3053 const struct unit_type *target_utype;
3054
3055 if (actor_unit == nullptr || target_city == nullptr) {
3056 /* Can't do an action when actor or target are missing. */
3057 return FALSE;
3058 }
3059
3061 FALSE, "Action %s is performed by %s not %s",
3066
3069 FALSE, "Action %s is against %s not %s",
3074
3076
3078 /* No point in continuing. */
3079 return FALSE;
3080 }
3081
3084
3086 &(const struct req_context) {
3087 .player = unit_owner(actor_unit),
3088 .city = tile_city(actor_tile),
3089 .tile = actor_tile,
3090 .unit = actor_unit,
3091 .unittype = unit_type_get(actor_unit),
3092 },
3093 &(const struct req_context) {
3094 .player = city_owner(target_city),
3095 .city = target_city,
3096 .building = target_building,
3098 .unittype = target_utype,
3099 },
3100 nullptr,
3101 actor_home);
3102}
3103
3104/**********************************************************************/
3120
3121/**********************************************************************/
3127static bool
3130 const struct unit *actor_unit,
3131 const struct city *actor_home,
3132 const struct tile *actor_tile,
3133 const struct unit *target_unit)
3134{
3135 if (actor_unit == nullptr || target_unit == nullptr) {
3136 /* Can't do an action when actor or target are missing. */
3137 return FALSE;
3138 }
3139
3141 FALSE, "Action %s is performed by %s not %s",
3146
3149 FALSE, "Action %s is against %s not %s",
3154
3156
3158 /* No point in continuing. */
3159 return FALSE;
3160 }
3161
3163 &(const struct req_context) {
3164 .player = unit_owner(actor_unit),
3165 .city = tile_city(actor_tile),
3166 .tile = actor_tile,
3167 .unit = actor_unit,
3168 .unittype = unit_type_get(actor_unit),
3169 },
3170 &(const struct req_context) {
3171 .player = unit_owner(target_unit),
3174 .unit = target_unit,
3175 .unittype = unit_type_get(target_unit),
3176 },
3177 nullptr,
3178 actor_home);
3179}
3180
3181/**********************************************************************/
3197
3198/**********************************************************************/
3204static bool
3207 const struct unit *actor_unit,
3208 const struct city *actor_home,
3209 const struct tile *actor_tile,
3210 const struct tile *target_tile)
3211{
3212 const struct req_context *actor_ctxt;
3213
3214 if (actor_unit == nullptr || target_tile == nullptr
3215 || unit_list_size(target_tile->units) == 0) {
3216 /* Can't do an action when actor or target are missing. */
3217 return FALSE;
3218 }
3219
3221 FALSE, "Action %s is performed by %s not %s",
3226
3229 FALSE, "Action %s is against %s not %s",
3234
3236
3238 /* No point in continuing. */
3239 return FALSE;
3240 }
3241
3242 actor_ctxt = &(const struct req_context) {
3243 .player = unit_owner(actor_unit),
3244 .city = tile_city(actor_tile),
3245 .tile = actor_tile,
3246 .unit = actor_unit,
3247 .unittype = unit_type_get(actor_unit),
3248 };
3249
3252 &(const struct req_context) {
3253 .player = unit_owner(target_unit),
3256 .unit = target_unit,
3257 .unittype = unit_type_get(target_unit),
3258 },
3259 nullptr, actor_home)) {
3260 /* One unit makes it impossible for all units. */
3261 return FALSE;
3262 }
3264
3265 /* Not impossible for any of the units at the tile. */
3266 return TRUE;
3267}
3268
3269/**********************************************************************/
3285
3286/**********************************************************************/
3292static bool
3295 const struct unit *actor_unit,
3296 const struct city *actor_home,
3297 const struct tile *actor_tile,
3298 const struct tile *target_tile,
3299 const struct extra_type *target_extra)
3300{
3301 if (actor_unit == nullptr || target_tile == nullptr) {
3302 /* Can't do an action when actor or target are missing. */
3303 return FALSE;
3304 }
3305
3307 FALSE, "Action %s is performed by %s not %s",
3312
3315 FALSE, "Action %s is against %s not %s",
3320
3322
3324 /* No point in continuing. */
3325 return FALSE;
3326 }
3327
3329 &(const struct req_context) {
3330 .player = unit_owner(actor_unit),
3331 .city = tile_city(actor_tile),
3332 .tile = actor_tile,
3333 .unit = actor_unit,
3334 .unittype = unit_type_get(actor_unit),
3335 },
3336 &(const struct req_context) {
3337 .player = tile_owner(target_tile),
3338 .city = tile_city(target_tile),
3339 .tile = target_tile,
3340 },
3342 actor_home);
3343}
3344
3345/**********************************************************************/
3353 const struct unit *actor_unit,
3354 const struct tile *target_tile,
3355 const struct extra_type *target_extra)
3356{
3361}
3362
3363/**********************************************************************/
3369static bool
3372 const struct unit *actor_unit,
3373 const struct city *actor_home,
3374 const struct tile *actor_tile,
3375 const struct tile *target_tile,
3376 const struct extra_type *target_extra)
3377{
3378 if (actor_unit == nullptr || target_tile == nullptr) {
3379 /* Can't do an action when actor or target are missing. */
3380 return FALSE;
3381 }
3382
3384 FALSE, "Action %s is performed by %s not %s",
3389
3392 FALSE, "Action %s is against %s not %s",
3397
3399
3401 /* No point in continuing. */
3402 return FALSE;
3403 }
3404
3406 &(const struct req_context) {
3407 .player = unit_owner(actor_unit),
3408 .city = tile_city(actor_tile),
3409 .tile = actor_tile,
3410 .unit = actor_unit,
3411 .unittype = unit_type_get(actor_unit),
3412 },
3413 &(const struct req_context) {
3414 .player = target_tile->extras_owner,
3415 .city = tile_city(target_tile),
3416 .tile = target_tile,
3417 },
3419 actor_home);
3420}
3421
3422/**********************************************************************/
3439
3440/**********************************************************************/
3447static bool
3450 const struct unit *actor_unit,
3451 const struct city *actor_home,
3452 const struct tile *actor_tile)
3453{
3454 if (actor_unit == nullptr) {
3455 /* Can't do an action when the actor is missing. */
3456 return FALSE;
3457 }
3458
3460 FALSE, "Action %s is performed by %s not %s",
3465
3468 FALSE, "Action %s is against %s not %s",
3473
3475
3477 /* No point in continuing. */
3478 return FALSE;
3479 }
3480
3482 &(const struct req_context) {
3483 .player = unit_owner(actor_unit),
3484 .city = tile_city(actor_tile),
3485 .tile = actor_tile,
3486 .unit = actor_unit,
3487 .unittype = unit_type_get(actor_unit),
3488 },
3489 nullptr, nullptr,
3490 actor_home);
3491}
3492
3493/**********************************************************************/
3508
3509#define ASSERT_PLAYER_ACTION(_atk) \
3510 fc_assert_ret_val_msg(AAK_PLAYER == action_id_get_actor_kind(wanted_action),\
3511 FALSE, "Action %s is performed by %s not %s", \
3512 action_id_rule_name(wanted_action), \
3513 action_actor_kind_name( \
3514 action_id_get_actor_kind(wanted_action)), \
3515 action_actor_kind_name(AAK_PLAYER)); \
3516 fc_assert_ret_val_msg(_atk \
3517 == action_id_get_target_kind(wanted_action), \
3518 FALSE, "Action %s is against %s not %s", \
3519 action_id_rule_name(wanted_action), \
3520 action_target_kind_name( \
3521 action_id_get_target_kind(wanted_action)), \
3522 action_target_kind_name(_atk));
3523
3524/**********************************************************************/
3530 const struct player *actor_plr)
3531{
3532 if (actor_plr == nullptr) {
3533 /* Can't do an action when the actor is missing. */
3534 return FALSE;
3535 }
3536
3538
3540 &(const struct req_context) {
3541 .player = actor_plr,
3542 },
3543 nullptr, nullptr, nullptr);
3544}
3545
3546/**********************************************************************/
3552 const struct player *actor_plr,
3553 const struct city *target_city)
3554{
3555 const struct impr_type *target_building;
3556 const struct unit_type *target_utype;
3557
3558 if (actor_plr == nullptr || target_city == nullptr) {
3559 /* Can't do an action when the actor or the target is missing. */
3560 return FALSE;
3561 }
3562
3564
3567
3569 &(const struct req_context) {
3570 .player = actor_plr,
3571 },
3572 &(const struct req_context) {
3573 .player = city_owner(target_city),
3574 .city = target_city,
3575 .building = target_building,
3577 .unittype = target_utype,
3578 }, nullptr, nullptr);
3579}
3580
3581/**********************************************************************/
3587bool
3590 const struct player *actor_plr,
3591 const struct tile *target_tile,
3592 const struct extra_type *target_extra)
3593{
3594 if (actor_plr == nullptr || target_tile == nullptr) {
3595 /* Can't do an action when actor or target are missing. */
3596 return FALSE;
3597 }
3598
3600
3602 &(const struct req_context) {
3603 .player = actor_plr,
3604 },
3605 &(const struct req_context) {
3606 .player = target_tile->extras_owner,
3607 .city = tile_city(target_tile),
3608 .tile = target_tile,
3609 },
3610 target_extra, nullptr);
3611}
3612
3613/**********************************************************************/
3621 const struct player *actor_plr,
3622 const struct tile *target_tile,
3623 const struct extra_type *target_extra)
3624{
3625 const struct req_context actor_ctxt = {
3626 .player = actor_plr,
3627 };
3628 const struct city *tcity;
3629
3630 if (actor_plr == nullptr || target_tile == nullptr
3631 || unit_list_size(target_tile->units) == 0) {
3632 /* Can't do an action when actor or target are missing. */
3633 return FALSE;
3634 }
3635
3637
3641 &(const struct req_context) {
3642 .player = unit_owner(target_unit),
3643 .city = tcity,
3644 .tile = target_tile,
3645 .unit = target_unit,
3646 .unittype = unit_type_get(target_unit),
3647 },
3648 nullptr, nullptr)) {
3649 /* One unit makes it impossible for all units. */
3650 return FALSE;
3651 }
3653
3654 /* Not impossible for any of the units at the tile. */
3655 return TRUE;
3656}
3657
3658/**********************************************************************/
3666 const struct player *actor_plr,
3667 const struct tile *target_tile,
3668 const struct extra_type *target_extra)
3669{
3670 if (actor_plr == nullptr || target_tile == nullptr) {
3671 /* Can't do an action when actor or target are missing. */
3672 return FALSE;
3673 }
3674
3676
3678 &(const struct req_context) {
3679 .player = actor_plr,
3680 },
3681 &(const struct req_context) {
3682 .player = tile_owner(target_tile),
3683 .city = tile_city(target_tile),
3684 .tile = target_tile,
3685 },
3686 target_extra, nullptr);
3687}
3688
3689/**********************************************************************/
3697 const struct player *actor_plr,
3698 const struct unit *target_unit)
3699{
3700 if (actor_plr == nullptr || target_unit == nullptr) {
3701 /* Can't do an action when actor or target are missing. */
3702 return FALSE;
3703 }
3704
3706
3708 &(const struct req_context) {
3709 .player = actor_plr,
3710 },
3711 &(const struct req_context) {
3712 .player = unit_owner(target_unit),
3715 .unit = target_unit,
3716 .unittype = unit_type_get(target_unit),
3717 },
3718 nullptr, nullptr);
3719}
3720
3721/**********************************************************************/
3727 const struct city *actor_city)
3728{
3730 &(const struct req_context) {
3731 .player = city_owner(actor_city),
3732 .city = actor_city,
3733 .tile = city_tile(actor_city)
3734 },
3735 nullptr, nullptr, nullptr);
3736}
3737
3738/**********************************************************************/
3756static enum fc_tristate
3758 const struct req_context *actor,
3759 const struct req_context *target)
3760{
3761 enum fc_tristate current;
3762 enum fc_tristate result;
3763
3764 if (actor == nullptr || actor->player == nullptr) {
3765 /* Need actor->player for point of view */
3766 return TRI_MAYBE;
3767 }
3768
3769 if (target == nullptr) {
3770 target = req_context_empty();
3771 }
3772
3773 result = TRI_NO;
3775 enabler) {
3776 current = fc_tristate_and(mke_eval_reqs(actor->player,
3777 actor, target,
3778 &enabler->actor_reqs,
3779 RPT_CERTAIN),
3780 mke_eval_reqs(actor->player,
3781 target, actor,
3782 &enabler->target_reqs,
3783 RPT_CERTAIN));
3784 if (current == TRI_YES) {
3785 return TRI_YES;
3786 } else if (current == TRI_MAYBE) {
3787 result = TRI_MAYBE;
3788 }
3790
3791 return result;
3792}
3793
3794/**********************************************************************/
3804static bool is_effect_val_known(enum effect_type effect_type,
3805 const struct player *pov_player,
3806 const struct req_context *context,
3807 const struct req_context *other_context)
3808{
3809 effect_list_iterate(get_effects(effect_type), peffect) {
3811 &(peffect->reqs), RPT_CERTAIN)) {
3812 return FALSE;
3813 }
3815
3816 return TRUE;
3817}
3818
3819/**********************************************************************/
3822static enum fc_tristate
3850
3851/**********************************************************************/
3860 const struct unit *pdefender)
3861{
3862 /* Keep unconverted until the end to avoid scaling each step */
3863 int chance;
3864 struct act_prob out;
3865
3866 /* Superspy always win */
3868 /* A defending UTYF_SUPERSPY will defeat every possible attacker. */
3869 return ACTPROB_IMPOSSIBLE;
3870 }
3872 /* An attacking UTYF_SUPERSPY will defeat every possible defender
3873 * except another UTYF_SUPERSPY. */
3874 return ACTPROB_CERTAIN;
3875 }
3876
3877 /* Base chance is 50% */
3878 chance = 50;
3879
3880 /* Spy attack bonus */
3882 chance += 25;
3883 }
3884
3885 /* Spy defense bonus */
3887 chance -= 25;
3888 }
3889
3890 /* Veteran attack and defense bonus */
3891 {
3892 const struct veteran_level *vatt
3894 const struct veteran_level *vdef
3896
3897 chance += vatt->power_fact - vdef->power_fact;
3898 }
3899
3900 /* Defense bonus. */
3901 {
3902 const struct req_context defender_ctxt = {
3903 .player = tile_owner(pdefender->tile),
3904 .city = tile_city(pdefender->tile),
3905 .tile = pdefender->tile,
3906 };
3909 nullptr)) {
3910 return ACTPROB_NOT_KNOWN;
3911 }
3912
3913 /* Reduce the chance of an attack by EFT_SPY_RESISTANT percent. */
3915 nullptr,
3917 nullptr,
3919 ) / 100;
3920 }
3921
3922 chance = CLIP(0, chance, 100);
3923
3924 /* Convert to action probability */
3927
3928 return out;
3929}
3930
3931/**********************************************************************/
3937 const struct unit *pvictim,
3938 const struct tile *tgt_tile,
3939 const struct action *paction)
3940{
3941 struct unit *pdefender;
3942
3944 tgt_tile)) {
3945 /* Don't leak information about unseen defenders. */
3946 return ACTPROB_NOT_KNOWN;
3947 }
3948
3950 paction);
3951
3952 if (pdefender) {
3953 /* There will be a diplomatic battle instead of an action. */
3955 };
3956
3957 /* No diplomatic battle will occur. */
3958 return ACTPROB_CERTAIN;
3959}
3960
3961/**********************************************************************/
3965 action_id act_id,
3966 const struct unit *actor_unit)
3967{
3969 /* Unknown because the target is unseen. */
3970 return ACTPROB_NOT_KNOWN;
3971 } else {
3972 /* The actor it self can't do this. */
3973 return ACTPROB_IMPOSSIBLE;
3974 }
3975}
3976
3977/**********************************************************************/
3981static struct act_prob
3983 const struct unit *act_unit,
3984 const struct city *tgt_city,
3985 const struct player *tgt_player,
3986 const struct action *paction)
3987{
3989 &(const struct req_context) {
3990 .player = act_player,
3991 .city = tgt_city,
3992 .unit = act_unit,
3993 .unittype = unit_type_get(act_unit),
3994 },
3995 &(const struct req_context) {
3996 .player = tgt_player,
3997 })
3999 &(const struct req_context) {
4000 .player = tgt_player,
4001 .city = tgt_city,
4002 .unit = act_unit,
4003 },
4004 &(const struct req_context) {
4005 .player = act_player,
4006 })) {
4009 struct act_prob result = { .min = unconverted * ACTPROB_VAL_1_PCT,
4010 .max = unconverted * ACTPROB_VAL_1_PCT };
4011
4012 return result;
4013 } else {
4014 /* Could be improved to return a more exact probability in some cases.
4015 * Example: The player has enough information to know that the
4016 * probability always will be above 25% and always under 75% because
4017 * the only effect with unknown requirements that may apply adds (or
4018 * subtracts) 50% while all the requirements of the other effects that
4019 * may apply are known. */
4020 return ACTPROB_NOT_KNOWN;
4021 }
4022}
4023
4024/**********************************************************************/
4029static struct act_prob
4031 const struct unit *act_unit,
4032 const struct city *tgt_city,
4033 const struct unit *tgt_unit,
4034 const struct tile *tgt_tile,
4035 const struct player *tgt_player,
4036 const struct action *paction)
4037{
4038 struct act_prob battle;
4039 struct act_prob dice_roll;
4040
4041 battle = ACTPROB_CERTAIN;
4042 switch (actres_get_battle_kind(paction->result)) {
4043 case ABK_NONE:
4044 /* No pre action battle. */
4045 break;
4046 case ABK_DIPLOMATIC:
4048 paction);
4049 break;
4050 case ABK_STANDARD:
4051 /* Not supported here yet. Implement when users appear. */
4053 break;
4054 case ABK_COUNT:
4056 break;
4057 }
4058
4061 paction);
4062
4063 return action_prob_and(&battle, &dice_roll);
4064}
4065
4066/**********************************************************************/
4077static struct act_prob
4080 const struct req_context *actor,
4081 const struct city *actor_home,
4082 const struct req_context *target,
4083 const struct extra_type *target_extra)
4084{
4085 enum fc_tristate known;
4086 struct act_prob chance;
4088
4089 if (actor == nullptr) {
4091 }
4092 if (target == nullptr) {
4093 target = req_context_empty();
4094 }
4095
4096 known = is_action_possible(nmap, wanted_action, actor, target,
4098 FALSE, actor_home);
4099
4100 if (known == TRI_NO) {
4101 /* The action enablers are irrelevant since the action it self is
4102 * impossible. */
4103 return ACTPROB_IMPOSSIBLE;
4104 }
4105
4107
4108 known = fc_tristate_and(known,
4110 actor, target));
4111
4112 switch (paction->result) {
4113 case ACTRES_SPY_POISON:
4114 /* All uncertainty comes from potential diplomatic battles and the
4115 * (diplchance server setting and the) Action_Odds_Pct effect controlled
4116 * dice roll before the action. */
4118 target->city, target->unit,
4119 target->tile, target->player,
4120 paction);
4121 break;
4123 /* TODO */
4124 break;
4126 /* TODO */
4127 break;
4128 case ACTRES_STEAL_MAPS:
4129 /* TODO */
4130 break;
4132 /* All uncertainty comes from potential diplomatic battles. */
4133 chance = ap_diplomat_battle(actor->unit, target->unit, target->tile,
4134 paction);
4135 break;
4138 /* All uncertainty comes from potential diplomatic battles. */
4139 chance = ap_diplomat_battle(actor->unit, target->unit, target->tile,
4140 paction);
4141 break;
4142 case ACTRES_SPY_ATTACK:
4143 /* All uncertainty comes from potential diplomatic battles. */
4144 chance = ap_diplomat_battle(actor->unit, nullptr, target->tile,
4145 paction);
4146 break;
4148 /* TODO */
4149 break;
4151 /* TODO */
4152 break;
4154 /* TODO */
4155 break;
4157 /* TODO */
4158 break;
4161 break;
4163 /* Do the victim have anything worth taking? */
4164 known = fc_tristate_and(known,
4165 tech_can_be_stolen(actor->player,
4166 target->player));
4167
4168 /* TODO: Calculate actual chance */
4169
4170 break;
4172 /* Do the victim have anything worth taking? */
4173 known = fc_tristate_and(known,
4174 tech_can_be_stolen(actor->player,
4175 target->player));
4176
4177 /* TODO: Calculate actual chance */
4178
4179 break;
4181 /* There is no risk that the city won't get investigated. */
4183 break;
4184 case ACTRES_SPY_ESCAPE:
4185 /* TODO */
4186 break;
4187 case ACTRES_TRADE_ROUTE:
4188 /* TODO */
4189 break;
4190 case ACTRES_MARKETPLACE:
4191 /* Possible when not blocked by is_action_possible() */
4193 break;
4194 case ACTRES_HELP_WONDER:
4195 /* Possible when not blocked by is_action_possible() */
4197 break;
4199 /* No battle is fought first. */
4201 break;
4202 case ACTRES_EXPEL_UNIT:
4203 /* No battle is fought first. */
4205 break;
4206 case ACTRES_BOMBARD:
4207 /* No battle is fought first. */
4209 break;
4210 case ACTRES_FOUND_CITY:
4211 /* Possible when not blocked by is_action_possible() */
4213 break;
4214 case ACTRES_JOIN_CITY:
4215 /* Possible when not blocked by is_action_possible() */
4217 break;
4218 case ACTRES_SPY_NUKE:
4219 /* All uncertainty comes from potential diplomatic battles and the
4220 * (diplchance server setting and the) Action_Odds_Pct effect controlled
4221 * dice roll before the action. */
4223 target->city, target->unit,
4224 target->tile,
4225 target->player,
4226 paction);
4227 break;
4228 case ACTRES_NUKE:
4229 /* TODO */
4230 break;
4231 case ACTRES_NUKE_UNITS:
4232 /* TODO */
4233 break;
4235 /* No battle is fought first. */
4237 break;
4239 /* No battle is fought first. */
4241 break;
4243 /* No battle is fought first. */
4245 break;
4246 case ACTRES_HOME_CITY:
4247 /* No battle is fought first. */
4249 break;
4250 case ACTRES_HOMELESS:
4251 /* No battle is fought first. */
4253 break;
4255 /* No battle is fought first. */
4257 break;
4258 case ACTRES_PARADROP:
4260 /* TODO */
4261 break;
4262 case ACTRES_AIRLIFT:
4263 /* Possible when not blocked by is_action_possible() */
4265 break;
4266 case ACTRES_ATTACK:
4268 {
4269 struct unit *defender_unit = get_defender(nmap, actor->unit,
4270 target->tile, paction);
4271
4272 if (can_player_see_unit(actor->player, defender_unit)) {
4273 double unconverted = unit_win_chance(nmap, actor->unit,
4275
4277 floor((double)ACTPROB_VAL_MAX * unconverted));
4279 ceil((double)ACTPROB_VAL_MAX * unconverted));
4280 } else if (known == TRI_YES) {
4281 known = TRI_MAYBE;
4282 }
4283 }
4284 break;
4285 case ACTRES_WIPE_UNITS:
4287 break;
4289 /* TODO: not implemented yet because:
4290 * - dice roll 100% * Action_Odds_Pct could be handled with
4291 * action_prob_pre_action_dice_roll().
4292 * - sub target building may be missing. May be missing without player
4293 * knowledge if it isn't visible. See is_improvement_visible() and
4294 * can_player_see_city_internals(). */
4295 break;
4297 /* All uncertainty comes from the (diplchance server setting and the)
4298 * Action_Odds_Pct effect controlled dice roll before the action. */
4300 target->city, target->player,
4301 paction);
4302 break;
4304 /* No battle is fought first. */
4306 break;
4308 /* No battle is fought first. */
4310 break;
4311 case ACTRES_HEAL_UNIT:
4312 /* No battle is fought first. */
4314 break;
4316 case ACTRES_CULTIVATE:
4317 case ACTRES_PLANT:
4318 case ACTRES_PILLAGE:
4319 case ACTRES_CLEAN:
4320 case ACTRES_FORTIFY:
4321 case ACTRES_ROAD:
4322 case ACTRES_CONVERT:
4323 case ACTRES_BASE:
4324 case ACTRES_MINE:
4325 case ACTRES_IRRIGATE:
4327 break;
4330 break;
4333 break;
4336 break;
4339 break;
4342 break;
4345 break;
4346 case ACTRES_HUT_ENTER:
4348 /* Entering the hut happens with a probability of 100%. What happens
4349 * next is probably up to dice rolls in Lua. */
4351 break;
4352 case ACTRES_UNIT_MOVE:
4353 case ACTRES_TELEPORT:
4356 break;
4357 case ACTRES_SCOUT:
4359 break;
4360 /* Not UI action, so chance is meaningless */
4363 break;
4364 case ACTRES_NONE:
4365 /* Accommodate ruleset authors that wishes to roll the dice in Lua.
4366 * Would be ACTPROB_CERTAIN if not for that. */
4367 /* TODO: maybe allow the ruleset author to give a probability from
4368 * Lua? */
4370 break;
4371 }
4372
4373 /* Non signal action probabilities should be in range. */
4375 || chance.max <= ACTPROB_VAL_MAX),
4376 chance.max = ACTPROB_VAL_MAX);
4378 || chance.min >= ACTPROB_VAL_MIN),
4379 chance.min = ACTPROB_VAL_MIN);
4380
4381 switch (known) {
4382 case TRI_NO:
4383 return ACTPROB_IMPOSSIBLE;
4384 break;
4385 case TRI_MAYBE:
4386 return ACTPROB_NOT_KNOWN;
4387 break;
4388 case TRI_YES:
4389 return chance;
4390 break;
4391 };
4392
4393 fc_assert_msg(FALSE, "Should be yes, maybe or no");
4394
4396}
4397
4398/**********************************************************************/
4402static struct act_prob
4404 const struct unit *actor_unit,
4405 const struct city *actor_home,
4406 const struct tile *actor_tile,
4407 const action_id act_id,
4408 const struct city *target_city)
4409{
4410 const struct impr_type *target_building;
4411 const struct unit_type *target_utype;
4412 const struct action *act = action_by_number(act_id);
4413
4414 if (actor_unit == nullptr || target_city == nullptr) {
4415 /* Can't do an action when actor or target are missing. */
4416 return ACTPROB_IMPOSSIBLE;
4417 }
4418
4421 "Action %s is performed by %s not %s",
4422 action_id_rule_name(act_id),
4424 action_id_get_actor_kind(act_id)),
4426
4429 "Action %s is against %s not %s",
4430 action_id_rule_name(act_id),
4434
4436
4437 if (!unit_can_do_action(actor_unit, act_id)) {
4438 /* No point in continuing. */
4439 return ACTPROB_IMPOSSIBLE;
4440 }
4441
4442 /* Doesn't leak information about city position since an unknown city
4443 * can't be targeted and a city can't move. */
4444 if (!action_id_distance_accepted(act_id,
4447 /* No point in continuing. */
4448 return ACTPROB_IMPOSSIBLE;
4449 }
4450
4451 /* Doesn't leak information since it must be 100% certain from the
4452 * player's perspective that the blocking action is legal. */
4454 city_tile(target_city), target_city, nullptr)) {
4455 /* Don't offer to perform an action known to be blocked. */
4456 return ACTPROB_IMPOSSIBLE;
4457 }
4458
4460 /* The invisible city at this tile may, as far as the player knows, not
4461 * exist anymore. */
4462 return act_prob_unseen_target(nmap, act_id, actor_unit);
4463 }
4464
4467
4468 return action_prob(nmap, act_id,
4469 &(const struct req_context) {
4470 .player = unit_owner(actor_unit),
4471 .city = tile_city(actor_tile),
4472 .tile = actor_tile,
4473 .unit = actor_unit,
4474 .unittype = unit_type_get(actor_unit),
4475 },
4476 actor_home,
4477 &(const struct req_context) {
4478 .player = city_owner(target_city),
4479 .city = target_city,
4480 .building = target_building,
4482 .unittype = target_utype,
4483 }, nullptr);
4484}
4485
4486/**********************************************************************/
4491 const struct unit *actor_unit,
4492 const action_id act_id,
4493 const struct city *target_city)
4494{
4498 act_id, target_city);
4499}
4500
4501/**********************************************************************/
4505static struct act_prob
4507 const struct unit *actor_unit,
4508 const struct city *actor_home,
4509 const struct tile *actor_tile,
4510 const action_id act_id,
4511 const struct unit *target_unit)
4512{
4513 if (actor_unit == nullptr || target_unit == nullptr) {
4514 /* Can't do an action when actor or target are missing. */
4515 return ACTPROB_IMPOSSIBLE;
4516 }
4517
4520 "Action %s is performed by %s not %s",
4521 action_id_rule_name(act_id),
4523 action_id_get_actor_kind(act_id)),
4525
4528 "Action %s is against %s not %s",
4529 action_id_rule_name(act_id),
4533
4535
4536 if (!unit_can_do_action(actor_unit, act_id)) {
4537 /* No point in continuing. */
4538 return ACTPROB_IMPOSSIBLE;
4539 }
4540
4541 /* Doesn't leak information about unit position since an unseen unit can't
4542 * be targeted. */
4543 if (!action_id_distance_accepted(act_id,
4546 /* No point in continuing. */
4547 return ACTPROB_IMPOSSIBLE;
4548 }
4549
4550 return action_prob(nmap, act_id,
4551 &(const struct req_context) {
4552 .player = unit_owner(actor_unit),
4553 .city = tile_city(actor_tile),
4554 .tile = actor_tile,
4555 .unit = actor_unit,
4556 .unittype = unit_type_get(actor_unit),
4557 },
4558 actor_home,
4559 &(const struct req_context) {
4560 .player = unit_owner(target_unit),
4563 .unit = target_unit,
4564 .unittype = unit_type_get(target_unit),
4565 },
4566 nullptr);
4567}
4568
4569/**********************************************************************/
4574 const struct unit *actor_unit,
4575 const action_id act_id,
4576 const struct unit *target_unit)
4577{
4581 act_id,
4582 target_unit);
4583}
4584
4585/**********************************************************************/
4589static struct act_prob
4591 const struct unit *actor_unit,
4592 const struct city *actor_home,
4593 const struct tile *actor_tile,
4594 const action_id act_id,
4595 const struct tile *target_tile)
4596{
4597 struct act_prob prob_all;
4598 const struct req_context *actor_ctxt;
4599 const struct action *act = action_by_number(act_id);
4600
4601 if (actor_unit == nullptr || target_tile == nullptr) {
4602 /* Can't do an action when actor or target are missing. */
4603 return ACTPROB_IMPOSSIBLE;
4604 }
4605
4608 "Action %s is performed by %s not %s",
4609 action_id_rule_name(act_id),
4611 action_id_get_actor_kind(act_id)),
4613
4616 "Action %s is against %s not %s",
4617 action_id_rule_name(act_id),
4621
4623
4624 if (!unit_can_do_action(actor_unit, act_id)) {
4625 /* No point in continuing. */
4626 return ACTPROB_IMPOSSIBLE;
4627 }
4628
4629 /* Doesn't leak information about unit stack position since it is
4630 * specified as a tile and an unknown tile's position is known. */
4631 if (!action_id_distance_accepted(act_id,
4633 target_tile))) {
4634 /* No point in continuing. */
4635 return ACTPROB_IMPOSSIBLE;
4636 }
4637
4638 /* Doesn't leak information since the actor player can see the target
4639 * tile. */
4641 && tile_city(target_tile) != nullptr
4643 act_id,
4644 CITYT_CENTER, TRUE)) {
4645 /* Don't offer to perform actions that never can target a unit stack in
4646 * a city. */
4647 return ACTPROB_IMPOSSIBLE;
4648 }
4649
4650 /* Doesn't leak information since it must be 100% certain from the
4651 * player's perspective that the blocking action is legal. */
4655 target_unit)) {
4656 /* Don't offer to perform an action known to be blocked. */
4657 return ACTPROB_IMPOSSIBLE;
4658 }
4660
4661 /* Must be done here since an empty unseen tile will result in
4662 * ACTPROB_IMPOSSIBLE. */
4663 if (unit_list_size(target_tile->units) == 0) {
4664 /* Can't act against an empty tile. */
4665
4667 target_tile)) {
4668 /* Known empty tile. */
4669 return ACTPROB_IMPOSSIBLE;
4670 } else {
4671 /* The player doesn't know that the tile is empty. */
4672 return act_prob_unseen_target(nmap, act_id, actor_unit);
4673 }
4674 }
4675
4679 && tile_city(target_tile) != nullptr
4682 /* Hard coded rule: can't "Bombard", "Suicide Attack", or "Attack"
4683 * units in non enemy cities. */
4684 return ACTPROB_IMPOSSIBLE;
4685 }
4686
4693 /* Hard coded rule: can't "Nuke Units", "Wipe Units", "Suicide Attack",
4694 * or "Attack" units on non native tile without "AttackNonNative" and
4695 * not "Only_Native_Attack". */
4696 return ACTPROB_IMPOSSIBLE;
4697 }
4698
4699 /* Invisible units at this tile can make the action legal or illegal.
4700 * Invisible units can be stacked with visible units. The possible
4701 * existence of invisible units therefore makes the result uncertain. */
4705
4706 actor_ctxt = &(const struct req_context) {
4707 .player = unit_owner(actor_unit),
4708 .city = tile_city(actor_tile),
4709 .tile = actor_tile,
4710 .unit = actor_unit,
4711 .unittype = unit_type_get(actor_unit),
4712 };
4713
4715 struct act_prob prob_unit;
4716
4718 /* Only visible units are considered. The invisible units contributed
4719 * their uncertainty to prob_all above. */
4720 continue;
4721 }
4722
4724 &(const struct req_context) {
4725 .player = unit_owner(target_unit),
4728 .unit = target_unit,
4729 .unittype = unit_type_get(target_unit),
4730 },
4731 nullptr);
4732
4734 /* One unit makes it impossible for all units. */
4735 return ACTPROB_IMPOSSIBLE;
4736 } else if (action_prob_not_impl(prob_unit)) {
4737 /* Not implemented dominates all except impossible. */
4739 } else {
4741 "Invalid probability [%d, %d]",
4742 prob_unit.min, prob_unit.max);
4743
4745 /* Special values dominate regular values. */
4746 continue;
4747 }
4748
4749 /* Probability against all target units considered until this moment
4750 * and the probability against this target unit. */
4751 prob_all.min = (prob_all.min * prob_unit.min) / ACTPROB_VAL_MAX;
4752 prob_all.max = (prob_all.max * prob_unit.max) / ACTPROB_VAL_MAX;
4753 break;
4754 }
4756
4757 /* Not impossible for any of the units at the tile. */
4758 return prob_all;
4759}
4760
4761/**********************************************************************/
4766 const struct unit *actor_unit,
4767 const action_id act_id,
4768 const struct tile *target_tile)
4769{
4773 act_id,
4774 target_tile);
4775}
4776
4777/**********************************************************************/
4781static struct act_prob
4783 const struct unit *actor_unit,
4784 const struct city *actor_home,
4785 const struct tile *actor_tile,
4786 const action_id act_id,
4787 const struct tile *target_tile,
4788 const struct extra_type *target_extra)
4789{
4790 if (actor_unit == nullptr || target_tile == nullptr) {
4791 /* Can't do an action when actor or target are missing. */
4792 return ACTPROB_IMPOSSIBLE;
4793 }
4794
4797 "Action %s is performed by %s not %s",
4798 action_id_rule_name(act_id),
4800 action_id_get_actor_kind(act_id)),
4802
4805 "Action %s is against %s not %s",
4806 action_id_rule_name(act_id),
4810
4812
4813 if (!unit_can_do_action(actor_unit, act_id)) {
4814 /* No point in continuing. */
4815 return ACTPROB_IMPOSSIBLE;
4816 }
4817
4818 /* Doesn't leak information about tile position since an unknown tile's
4819 * position is known. */
4820 if (!action_id_distance_accepted(act_id,
4822 target_tile))) {
4823 /* No point in continuing. */
4824 return ACTPROB_IMPOSSIBLE;
4825 }
4826
4827 return action_prob(nmap, act_id,
4828 &(const struct req_context) {
4829 .player = unit_owner(actor_unit),
4830 .city = tile_city(actor_tile),
4831 .tile = actor_tile,
4832 .unit = actor_unit,
4833 .unittype = unit_type_get(actor_unit),
4834 },
4835 actor_home,
4836 &(const struct req_context) {
4837 .player = tile_owner(target_tile),
4838 .city = tile_city(target_tile),
4839 .tile = target_tile,
4840 },
4841 target_extra);
4842}
4843
4844/**********************************************************************/
4849 const struct unit *actor_unit,
4850 const action_id act_id,
4851 const struct tile *target_tile,
4852 const struct extra_type *target_extra)
4853{
4857 act_id, target_tile, target_extra);
4858}
4859
4860/**********************************************************************/
4864static struct act_prob
4866 const struct unit *actor_unit,
4867 const struct city *actor_home,
4868 const struct tile *actor_tile,
4869 const action_id act_id,
4870 const struct tile *target_tile,
4871 const struct extra_type *target_extra)
4872{
4873 if (actor_unit == nullptr || target_tile == nullptr) {
4874 /* Can't do an action when actor or target are missing. */
4875 return ACTPROB_IMPOSSIBLE;
4876 }
4877
4880 "Action %s is performed by %s not %s",
4881 action_id_rule_name(act_id),
4883 action_id_get_actor_kind(act_id)),
4885
4888 "Action %s is against %s not %s",
4889 action_id_rule_name(act_id),
4893
4895
4896 if (!unit_can_do_action(actor_unit, act_id)) {
4897 /* No point in continuing. */
4898 return ACTPROB_IMPOSSIBLE;
4899 }
4900
4901 /* Doesn't leak information about tile position since an unknown tile's
4902 * position is known. */
4903 if (!action_id_distance_accepted(act_id,
4905 target_tile))) {
4906 /* No point in continuing. */
4907 return ACTPROB_IMPOSSIBLE;
4908 }
4909
4910 return action_prob(nmap, act_id,
4911 &(const struct req_context) {
4912 .player = unit_owner(actor_unit),
4913 .city = tile_city(actor_tile),
4914 .tile = actor_tile,
4915 .unit = actor_unit,
4916 .unittype = unit_type_get(actor_unit),
4917 },
4918 actor_home,
4919 &(const struct req_context) {
4920 .player = target_tile->extras_owner,
4921 .city = tile_city(target_tile),
4922 .tile = target_tile,
4923 },
4924 target_extra);
4925}
4926
4927/**********************************************************************/
4932 const struct unit *actor_unit,
4933 const action_id act_id,
4934 const struct tile *target_tile,
4935 const struct extra_type *target_extra)
4936{
4940 act_id, target_tile, target_extra);
4941}
4942
4943/**********************************************************************/
4947static struct act_prob
4949 const struct unit *actor_unit,
4950 const struct city *actor_home,
4951 const struct tile *actor_tile,
4952 const action_id act_id)
4953{
4954 if (actor_unit == nullptr) {
4955 /* Can't do the action when the actor is missing. */
4956 return ACTPROB_IMPOSSIBLE;
4957 }
4958
4959 /* No point in checking distance to target. It is always 0. */
4960
4963 "Action %s is performed by %s not %s",
4964 action_id_rule_name(act_id),
4966 action_id_get_actor_kind(act_id)),
4968
4971 "Action %s is against %s not %s",
4972 action_id_rule_name(act_id),
4976
4978
4979 if (!unit_can_do_action(actor_unit, act_id)) {
4980 /* No point in continuing. */
4981 return ACTPROB_IMPOSSIBLE;
4982 }
4983
4984 return action_prob(nmap, act_id,
4985 &(const struct req_context) {
4986 .player = unit_owner(actor_unit),
4987 .city = tile_city(actor_tile),
4988 .tile = actor_tile,
4989 .unit = actor_unit,
4990 .unittype = unit_type_get(actor_unit),
4991 },
4992 actor_home,
4993 nullptr,
4994 nullptr);
4995}
4996
4997/**********************************************************************/
5002 const struct unit *actor_unit,
5003 const action_id act_id)
5004{
5008 act_id);
5009}
5010
5011/**********************************************************************/
5024 const struct action *paction,
5025 const struct unit *act_unit,
5026 const struct city *tgt_city,
5027 const struct unit *tgt_unit,
5028 const struct tile *tgt_tile,
5029 const struct extra_type *extra_tgt)
5030{
5031 /* Assume impossible until told otherwise. */
5032 struct act_prob prob = ACTPROB_IMPOSSIBLE;
5033
5036
5038 case ATK_STACK:
5039 if (tgt_tile) {
5041 }
5042 break;
5043 case ATK_TILE:
5044 if (tgt_tile) {
5046 }
5047 break;
5048 case ATK_EXTRAS:
5049 if (tgt_tile) {
5052 }
5053 break;
5054 case ATK_CITY:
5055 if (tgt_city) {
5057 }
5058 break;
5059 case ATK_UNIT:
5060 if (tgt_unit) {
5062 }
5063 break;
5064 case ATK_SELF:
5065 prob = action_prob_self(nmap, act_unit, paction->id);
5066 break;
5067 case ATK_COUNT:
5068 log_error("Invalid action target kind");
5069 break;
5070 }
5071
5072 return prob;
5073}
5074
5075/**********************************************************************/
5081 const action_id act_id,
5082 const struct unit *actor,
5083 const struct city *actor_home,
5084 const struct tile *actor_tile,
5085 const bool omniscient_cheat,
5086 const struct city* target)
5087{
5088 /* FIXME: some unit state requirements still depend on the actor unit's
5089 * current position rather than on actor_tile. Maybe this function should
5090 * return ACTPROB_NOT_IMPLEMENTED when one of those is detected and no
5091 * other requirement makes the action ACTPROB_IMPOSSIBLE? */
5092
5093 if (omniscient_cheat) {
5096 target)) {
5097 return ACTPROB_CERTAIN;
5098 } else {
5099 return ACTPROB_IMPOSSIBLE;
5100 }
5101 } else {
5102 /* FIXME: this branch result depends _directly_ on actor's position.
5103 * I.e., like, not adjacent, no action. Other branch ignores radius. */
5105 act_id, target);
5106 }
5107}
5108
5109/**********************************************************************/
5114struct act_prob
5116 action_id act_id,
5117 const struct unit *actor,
5118 const struct city *actor_home,
5119 const struct tile *actor_tile,
5120 bool omniscient_cheat,
5121 const struct unit *target)
5122{
5123 /* FIXME: some unit state requirements still depend on the actor unit's
5124 * current position rather than on actor_tile. Maybe this function should
5125 * return ACTPROB_NOT_IMPLEMENTED when one of those is detected and no
5126 * other requirement makes the action ACTPROB_IMPOSSIBLE? */
5127
5128 if (omniscient_cheat) {
5131 target)) {
5132 return ACTPROB_CERTAIN;
5133 } else {
5134 return ACTPROB_IMPOSSIBLE;
5135 }
5136 } else {
5138 act_id, target);
5139 }
5140}
5141
5142/**********************************************************************/
5147struct act_prob
5149 action_id act_id,
5150 const struct unit *actor,
5151 const struct city *actor_home,
5152 const struct tile *actor_tile,
5153 bool omniscient_cheat,
5154 const struct tile *target)
5155{
5156 /* FIXME: some unit state requirements still depend on the actor unit's
5157 * current position rather than on actor_tile. Maybe this function should
5158 * return ACTPROB_NOT_IMPLEMENTED when one of those is detected and no
5159 * other requirement makes the action ACTPROB_IMPOSSIBLE? */
5160
5161 if (omniscient_cheat) {
5164 target)) {
5165 return ACTPROB_CERTAIN;
5166 } else {
5167 return ACTPROB_IMPOSSIBLE;
5168 }
5169 } else {
5171 act_id, target);
5172 }
5173}
5174
5175/**********************************************************************/
5180struct act_prob
5182 action_id act_id,
5183 const struct unit *actor,
5184 const struct city *actor_home,
5185 const struct tile *actor_tile,
5186 bool omniscient_cheat,
5187 const struct tile *target_tile,
5188 const struct extra_type *target_extra)
5189{
5190 /* FIXME: some unit state requirements still depend on the actor unit's
5191 * current position rather than on actor_tile. Maybe this function should
5192 * return ACTPROB_NOT_IMPLEMENTED when one of those is detected and no
5193 * other requirement makes the action ACTPROB_IMPOSSIBLE? */
5194
5195 if (omniscient_cheat) {
5199 return ACTPROB_CERTAIN;
5200 } else {
5201 return ACTPROB_IMPOSSIBLE;
5202 }
5203 } else {
5205 act_id, target_tile, target_extra);
5206 }
5207}
5208
5209/**********************************************************************/
5214struct act_prob
5216 action_id act_id,
5217 const struct unit *actor,
5218 const struct city *actor_home,
5219 const struct tile *actor_tile,
5220 bool omniscient_cheat,
5221 const struct tile *target_tile,
5222 const struct extra_type *target_extra)
5223{
5224 /* FIXME: some unit state requirements still depend on the actor unit's
5225 * current position rather than on actor_tile. Maybe this function should
5226 * return ACTPROB_NOT_IMPLEMENTED when one of those is detected and no
5227 * other requirement makes the action ACTPROB_IMPOSSIBLE? */
5228
5229 if (omniscient_cheat) {
5233 return ACTPROB_CERTAIN;
5234 } else {
5235 return ACTPROB_IMPOSSIBLE;
5236 }
5237 } else {
5239 act_id, target_tile, target_extra);
5240 }
5241}
5242
5243/**********************************************************************/
5248struct act_prob
5250 action_id act_id,
5251 const struct unit *actor,
5252 const struct city *actor_home,
5253 const struct tile *actor_tile,
5254 bool omniscient_cheat)
5255{
5256 /* FIXME: some unit state requirements still depend on the actor unit's
5257 * current position rather than on actor_tile. Maybe this function should
5258 * return ACTPROB_NOT_IMPLEMENTED when one of those is detected and no
5259 * other requirement makes the action ACTPROB_IMPOSSIBLE? */
5260 if (omniscient_cheat) {
5263 return ACTPROB_CERTAIN;
5264 } else {
5265 return ACTPROB_IMPOSSIBLE;
5266 }
5267 } else {
5269 act_id);
5270 }
5271}
5272
5273/**********************************************************************/
5277{
5279
5280 return out;
5281}
5282
5283/**********************************************************************/
5287{
5289
5290 return out;
5291}
5292
5293/**********************************************************************/
5297{
5299
5300 return out;
5301}
5302
5303/**********************************************************************/
5307{
5309
5310 return out;
5311}
5312
5313/**********************************************************************/
5317{
5319
5320 return out;
5321}
5322
5323/**********************************************************************/
5328{
5329 return (ACTPROB_VAL_MIN < probability.max
5331}
5332
5333/**********************************************************************/
5338{
5339 return (ACTPROB_VAL_MAX == probability.min
5340 && ACTPROB_VAL_MAX == probability.max);
5341}
5342
5343/**********************************************************************/
5347static inline bool
5353
5354/**********************************************************************/
5358static inline bool
5360{
5361 return probability.min == ACTPROB_VAL_NOT_IMPL
5362 && probability.max == ACTPROB_VAL_MIN;
5363}
5364
5365/**********************************************************************/
5369static inline bool
5371{
5372 return probability.max < probability.min;
5373}
5374
5375/**********************************************************************/
5379 const struct act_prob *ap2)
5380{
5381 return ap1->min == ap2->min && ap1->max == ap2->max;
5382}
5383
5384/**********************************************************************/
5388 const struct act_prob ap2)
5389{
5390 struct act_prob my_ap1;
5391 struct act_prob my_ap2;
5392
5393 /* The action probabilities are real. */
5396
5397 /* Convert any signals to ACTPROB_NOT_KNOWN. */
5399 /* Assert that it is OK to convert the signal. */
5401
5403 } else {
5404 my_ap1 = ap1;
5405 }
5406
5408 /* Assert that it is OK to convert the signal. */
5410
5412 } else {
5413 my_ap2 = ap2;
5414 }
5415
5416 /* The action probabilities now have a comparison friendly form. */
5419
5420 /* Do the comparison. Start with min. Continue with max. */
5421 if (my_ap1.min < my_ap2.min) {
5422 return -1;
5423 } else if (my_ap1.min > my_ap2.min) {
5424 return 1;
5425 } else if (my_ap1.max < my_ap2.max) {
5426 return -1;
5427 } else if (my_ap1.max > my_ap2.max) {
5428 return 1;
5429 } else {
5430 return 0;
5431 }
5432}
5433
5434/**********************************************************************/
5439{
5440 struct act_prob my_ap;
5441
5442 /* The action probability is real. */
5444
5445 /* Convert any signals to ACTPROB_NOT_KNOWN. */
5447 /* Assert that it is OK to convert the signal. */
5449
5451 } else {
5452 my_ap = ap;
5453 }
5454
5455 /* The action probability now has a math friendly form. */
5457
5458 return (double)my_ap.min / (double) ACTPROB_VAL_MAX;
5459}
5460
5461/**********************************************************************/
5466 const struct act_prob *ap2)
5467{
5468 struct act_prob my_ap1;
5469 struct act_prob my_ap2;
5470 struct act_prob out;
5471
5472 /* The action probabilities are real. */
5475
5478 /* Keep the information rather than converting the signal to
5479 * ACTPROB_NOT_KNOWN. */
5480
5481 /* Assert that it is OK to convert the signal. */
5483
5484 out.min = ap1->min;
5485 out.max = ap2->max;
5486
5487 return out;
5488 }
5489
5490 /* Convert any signals to ACTPROB_NOT_KNOWN. */
5491 if (action_prob_is_signal(*ap1)) {
5492 /* Assert that it is OK to convert the signal. */
5494
5495 my_ap1.min = ACTPROB_VAL_MIN;
5496 my_ap1.max = ACTPROB_VAL_MAX;
5497 } else {
5498 my_ap1.min = ap1->min;
5499 my_ap1.max = ap1->max;
5500 }
5501
5502 if (action_prob_is_signal(*ap2)) {
5503 /* Assert that it is OK to convert the signal. */
5505
5506 my_ap2.min = ACTPROB_VAL_MIN;
5507 my_ap2.max = ACTPROB_VAL_MAX;
5508 } else {
5509 my_ap2.min = ap2->min;
5510 my_ap2.max = ap2->max;
5511 }
5512
5513 /* The action probabilities now have a math friendly form. */
5516
5517 /* Do the math. */
5518 out.min = (my_ap1.min * my_ap2.min) / ACTPROB_VAL_MAX;
5519 out.max = (my_ap1.max * my_ap2.max) / ACTPROB_VAL_MAX;
5520
5521 /* Cap at 100%. */
5522 out.min = MIN(out.min, ACTPROB_VAL_MAX);
5523 out.max = MIN(out.max, ACTPROB_VAL_MAX);
5524
5525 return out;
5526}
5527
5528/**********************************************************************/
5536 const struct act_prob *ap2)
5537{
5538 struct act_prob my_ap1;
5539 struct act_prob my_ap2;
5540 struct act_prob out;
5541
5542 /* The action probabilities are real. */
5545
5548 /* Keep the information rather than converting the signal to
5549 * ACTPROB_NOT_KNOWN. */
5550
5551 /* Assert that it is OK to convert the signal. */
5553
5554 out.min = ap1->min;
5555 out.max = ap2->max;
5556
5557 return out;
5558 }
5559
5560 /* Convert any signals to ACTPROB_NOT_KNOWN. */
5561 if (action_prob_is_signal(*ap1)) {
5562 /* Assert that it is OK to convert the signal. */
5564
5565 my_ap1.min = ACTPROB_VAL_MIN;
5566 my_ap1.max = ACTPROB_VAL_MAX;
5567 } else {
5568 my_ap1.min = ap1->min;
5569 my_ap1.max = ap1->max;
5570 }
5571
5572 if (action_prob_is_signal(*ap2)) {
5573 /* Assert that it is OK to convert the signal. */
5575
5576 my_ap2.min = ACTPROB_VAL_MIN;
5577 my_ap2.max = ACTPROB_VAL_MAX;
5578 } else {
5579 my_ap2.min = ap2->min;
5580 my_ap2.max = ap2->max;
5581 }
5582
5583 /* The action probabilities now have a math friendly form. */
5586
5587 /* Do the math. */
5588 out.min = my_ap1.min + (((ACTPROB_VAL_MAX - my_ap1.min) * my_ap2.min)
5589 / ACTPROB_VAL_MAX);
5590 out.max = my_ap1.max + (((ACTPROB_VAL_MAX - my_ap1.max) * my_ap2.max)
5591 / ACTPROB_VAL_MAX);
5592
5593 /* Cap at 100%. */
5594 out.min = MIN(out.min, ACTPROB_VAL_MAX);
5595 out.max = MIN(out.max, ACTPROB_VAL_MAX);
5596
5597 return out;
5598}
5599
5600/**********************************************************************/
5604{
5605 switch (actres_dice_type(paction->result)) {
5606 case DRT_DIPLCHANCE:
5608 /* Take the initial odds from the diplchance setting. */
5610 server_setting_by_name("diplchance"));
5611 }
5613 case DRT_CERTAIN:
5614 return 100;
5615 case DRT_NONE:
5616 break;
5617 }
5618
5619 /* The odds of the action not being stopped by its dice roll when the dice
5620 * isn't thrown is 100%. ACTION_ODDS_PCT_DICE_ROLL_NA is above 100% */
5622}
5623
5624/**********************************************************************/
5628 const struct unit *act_unit,
5629 const struct city *tgt_city,
5630 const struct player *tgt_player,
5631 const struct action *paction)
5632{
5634 const struct unit_type *actu_type = unit_type_get(act_unit);
5635
5636 fc_assert_action_msg(odds >= 0 && odds <= 100,
5637 odds = 100,
5638 "Bad initial odds for action number %d."
5639 " Does it roll the dice at all?",
5640 paction->id);
5641
5642 /* Let the Action_Odds_Pct effect modify the odds. The advantage of doing
5643 * it this way instead of rolling twice is that Action_Odds_Pct can
5644 * increase the odds. */
5645 odds = odds
5646 + ((odds
5647 * get_target_bonus_effects(nullptr,
5648 &(const struct req_context) {
5649 .player = act_player,
5650 .city = tgt_city,
5651 .unit = act_unit,
5652 .unittype = actu_type,
5653 .action = paction,
5654 },
5655 &(const struct req_context) {
5656 .player = tgt_player,
5657 },
5659 / 100)
5660 - ((odds
5661 * get_target_bonus_effects(nullptr,
5662 &(const struct req_context) {
5663 .player = tgt_player,
5664 .city = tgt_city,
5665 .unit = act_unit,
5666 .unittype = actu_type,
5667 .action = paction,
5668 },
5669 &(const struct req_context) {
5670 .player = act_player,
5671 },
5673 / 100);
5674
5675
5676 /* Odds are between 0% and 100%. */
5677 return CLIP(0, odds, 100);
5678}
5679
5680/**********************************************************************/
5684{
5685 struct action *paction = action_by_number(act);
5686
5687 /* Always immune since its not enabled. Doesn't count. */
5688 if (!action_is_in_use(paction)) {
5689 return FALSE;
5690 }
5691
5693 if (requirement_fulfilled_by_government(gov, &(enabler->target_reqs))) {
5694 return FALSE;
5695 }
5697
5698 return TRUE;
5699}
5700
5701/**********************************************************************/
5707 const struct player *actor_player,
5708 const struct req_context *target)
5709{
5711 enabler) {
5712 if (are_reqs_active(target,
5713 &(const struct req_context) {
5715 },
5716 &enabler->target_reqs, RPT_POSSIBLE)) {
5717 return TRUE;
5718 }
5720
5721 return FALSE;
5722}
5723
5724/**********************************************************************/
5728 const struct player *actor_player,
5729 const struct city* target_city)
5730{
5732 FALSE, "Action %s is against %s not cities",
5733 action_id_rule_name(act_id),
5735 action_id_get_target_kind(act_id)));
5736
5737 return is_target_possible(act_id, actor_player,
5738 &(const struct req_context) {
5739 .player = city_owner(target_city),
5740 .city = target_city,
5742 });
5743}
5744
5745/**********************************************************************/
5751 const action_id act_id,
5752 const struct unit *actor_unit)
5753{
5754 const struct player *actor_player = unit_owner(actor_unit);
5755 const struct req_context actor_ctxt = {
5757 .city = tile_city(unit_tile(actor_unit)),
5759 .unit = actor_unit,
5760 .unittype = unit_type_get(actor_unit),
5761 };
5762 const struct action *paction = action_by_number(act_id);
5763
5764 enum fc_tristate result;
5765
5767
5768 if (!utype_can_do_action(actor_unit->utype, act_id)) {
5769 /* The unit type can't perform the action. */
5770 return FALSE;
5771 }
5772
5775
5776 if (result == TRI_NO) {
5777 /* The hard requirements aren't fulfilled. */
5778 return FALSE;
5779 }
5780
5782 enabler) {
5783 const enum fc_tristate current
5785 &enabler->actor_reqs,
5786 /* Needed since no player to evaluate DiplRel
5787 * requirements against. */
5788 RPT_POSSIBLE);
5789
5790 if (current == TRI_YES
5791 || current == TRI_MAYBE) {
5792 /* The ruleset requirements may be fulfilled. */
5793 return TRUE;
5794 }
5796
5797 /* No action enabler allows this action. */
5798 return FALSE;
5799}
5800
5801/**********************************************************************/
5806 const action_id act_id)
5807{
5808 fc_assert(action_id_exists(act_id) || act_id == ACTION_ANY);
5809
5810 /* Check if full movement points may enable the specified action. */
5812 act_id,
5815 act_id,
5817}
5818
5819/**********************************************************************/
5829 const struct unit_type *act_utype)
5830{
5831 const struct action *paction = enabler_get_action(ae);
5832 struct universal actor_univ = { .kind = VUT_UTYPE,
5833 .value.utype = act_utype };
5834
5835 fc_assert_ret_val(paction != nullptr, FALSE);
5837 fc_assert_ret_val(act_utype != nullptr, FALSE);
5838
5840 && !req_vec_is_impossible_to_fulfill(&ae->actor_reqs)
5841 && universal_fulfills_requirements(FALSE, &ae->actor_reqs,
5842 &actor_univ));
5843}
5844
5845/**********************************************************************/
5856{
5857 const struct action *paction = enabler_get_action(ae);
5858
5859 switch (action_get_actor_kind(paction)) {
5860 case AAK_UNIT:
5863 /* A possible actor unit type has been found. */
5864 return TRUE;
5865 }
5867
5868 /* No actor detected. */
5869 return FALSE;
5870 case AAK_CITY:
5871 case AAK_PLAYER:
5872 /* Currently can't detect */
5873 return TRUE;
5874 case AAK_COUNT:
5876 break;
5877 }
5878
5879 /* No actor detected. */
5880 return FALSE;
5881}
5882
5883/**********************************************************************/
5891{
5892 switch (action_get_actor_kind(paction)) {
5893 case AAK_UNIT:
5896 return TRUE;
5897 }
5899 break;
5900 case AAK_CITY:
5901 case AAK_PLAYER:
5902 /* No ruleset hard reqs atm */
5903 return TRUE;
5904 case AAK_COUNT:
5906 break;
5907 }
5908
5909 /* No actor detected. */
5910 return FALSE;
5911}
5912
5913/**********************************************************************/
5921{
5923
5925 /* Hard requirements not fulfilled. */
5926 return FALSE;
5927 }
5928
5930
5932 /* If this iteration finds any entries, action is enabled. */
5933 return TRUE;
5935
5936 /* No non deleted action enabler. */
5937 return FALSE;
5938}
5939
5940/**********************************************************************/
5947{
5948 return paction != nullptr
5950}
5951
5952/**********************************************************************/
5962
5963/**********************************************************************/
5967{
5968 fc_assert_ret_val(num >= 0, nullptr);
5970
5971 return &auto_perfs[num];
5972}
5973
5974/**********************************************************************/
5983{
5984 return action_auto_perf_slot_number(num);
5985}
5986
5987/**********************************************************************/
5991 struct universal *actor_uni,
5992 struct universal *target_uni)
5993{
5995 enab) {
5996 if ((actor_uni == nullptr
5997 || universal_fulfills_requirements(FALSE, &(enab->actor_reqs),
5998 actor_uni))
5999 && (target_uni == nullptr
6000 || universal_fulfills_requirements(FALSE, &(enab->target_reqs),
6001 target_uni))) {
6002 return TRUE;
6003 }
6005
6006 return FALSE;
6007}
6008
6009/**********************************************************************/
6015{
6017
6018 if (size < MAX_NUM_ACTIONS) {
6019 /* An action array is terminated by ACTION_NONE */
6021 }
6022}
6023
6024/**********************************************************************/
6032 int *position,
6033 enum action_result result)
6034{
6035 action_iterate(act) {
6036 struct action *paction = action_by_number(act);
6037 if (paction->result == result) {
6038 /* Assume one result for each action. */
6039 fc_assert_ret(*position < MAX_NUM_ACTIONS);
6040
6041 act_array[(*position)++] = paction->id;
6042 }
6044}
6045
6046/**********************************************************************/
6049const char *action_ui_name_default(int act)
6050{
6051 switch ((enum gen_action)act) {
6052 case ACTION_SPY_POISON:
6053 /* TRANS: _Poison City (3% chance of success). */
6054 return N_("%sPoison City%s");
6056 /* TRANS: _Poison City and Escape (3% chance of success). */
6057 return N_("%sPoison City and Escape%s");
6059 /* TRANS: S_abotage Enemy Unit (3% chance of success). */
6060 return N_("S%sabotage Enemy Unit%s");
6062 /* TRANS: S_abotage Enemy Unit and Escape (3% chance of success). */
6063 return N_("S%sabotage Enemy Unit and Escape%s");
6065 /* TRANS: Bribe Enemy _Unit (3% chance of success). */
6066 return N_("Bribe Enemy %sUnit%s");
6068 /* TRANS: Bribe Enemy _Stack (3% chance of success). */
6069 return N_("Bribe Enemy %sStack%s");
6071 /* TRANS: _Sabotage City (3% chance of success). */
6072 return N_("%sSabotage City%s");
6074 /* TRANS: _Sabotage City and Escape (3% chance of success). */
6075 return N_("%sSabotage City and Escape%s");
6077 /* TRANS: Industria_l Sabotage (3% chance of success). */
6078 return N_("Industria%sl Sabotage%s");
6080 /* TRANS: Industria_l Sabotage Production (3% chance of success). */
6081 return N_("Industria%sl Sabotage Production%s");
6083 /* TRANS: Industria_l Sabotage and Escape (3% chance of success). */
6084 return N_("Industria%sl Sabotage and Escape%s");
6086 /* TRANS: Industria_l Sabotage Production and Escape (3% chance of success). */
6087 return N_("Industria%sl Sabotage Production and Escape%s");
6089 /* TRANS: Incite a Re_volt (3% chance of success). */
6090 return N_("Incite a Re%svolt%s");
6092 /* TRANS: Incite a Re_volt and Escape (3% chance of success). */
6093 return N_("Incite a Re%svolt and Escape%s");
6095 /* TRANS: Establish _Embassy (100% chance of success). */
6096 return N_("Establish %sEmbassy%s");
6098 /* TRANS: Becom_e Ambassador (100% chance of success). */
6099 return N_("Becom%se Ambassador%s");
6101 /* TRANS: Steal _Technology (3% chance of success). */
6102 return N_("Steal %sTechnology%s");
6104 /* TRANS: Steal _Technology and Escape (3% chance of success). */
6105 return N_("Steal %sTechnology and Escape%s");
6107 /* TRANS: In_dustrial Espionage (3% chance of success). */
6108 return N_("In%sdustrial Espionage%s");
6110 /* TRANS: In_dustrial Espionage and Escape (3% chance of success). */
6111 return N_("In%sdustrial Espionage and Escape%s");
6113 /* TRANS: _Investigate City (100% chance of success). */
6114 return N_("%sInvestigate City%s");
6116 /* TRANS: _Investigate City (spends the unit) (100% chance of
6117 * success). */
6118 return N_("%sInvestigate City (spends the unit)%s");
6120 /* TRANS: Steal _Gold (100% chance of success). */
6121 return N_("Steal %sGold%s");
6123 /* TRANS: Steal _Gold and Escape (100% chance of success). */
6124 return N_("Steal %sGold and Escape%s");
6126 /* TRANS: Spread _Plague (100% chance of success). */
6127 return N_("Spread %sPlague%s");
6128 case ACTION_STEAL_MAPS:
6129 /* TRANS: Steal _Maps (100% chance of success). */
6130 return N_("Steal %sMaps%s");
6132 /* TRANS: Steal _Maps and Escape (100% chance of success). */
6133 return N_("Steal %sMaps and Escape%s");
6134 case ACTION_TRADE_ROUTE:
6135 /* TRANS: Establish Trade _Route (100% chance of success). */
6136 return N_("Establish Trade %sRoute%s");
6137 case ACTION_MARKETPLACE:
6138 /* TRANS: Enter _Marketplace (100% chance of success). */
6139 return N_("Enter %sMarketplace%s");
6140 case ACTION_HELP_WONDER:
6141 /* TRANS: Help _build Wonder (100% chance of success). */
6142 return N_("Help %sbuild Wonder%s");
6144 /* TRANS: _Capture Units (100% chance of success). */
6145 return N_("%sCapture Units%s");
6146 case ACTION_EXPEL_UNIT:
6147 /* TRANS: _Expel Unit (100% chance of success). */
6148 return N_("%sExpel Unit%s");
6149 case ACTION_FOUND_CITY:
6150 /* TRANS: _Found City (100% chance of success). */
6151 return N_("%sFound City%s");
6152 case ACTION_JOIN_CITY:
6153 /* TRANS: _Join City (100% chance of success). */
6154 return N_("%sJoin City%s");
6155 case ACTION_BOMBARD:
6156 /* TRANS: B_ombard (100% chance of success). */
6157 return N_("B%sombard%s");
6158 case ACTION_BOMBARD2:
6159 /* TRANS: B_ombard 2 (100% chance of success). */
6160 return N_("B%sombard 2%s");
6161 case ACTION_BOMBARD3:
6162 /* TRANS: B_ombard 3 (100% chance of success). */
6163 return N_("B%sombard 3%s");
6164 case ACTION_BOMBARD4:
6165 /* TRANS: B_ombard 4 (100% chance of success). */
6166 return N_("B%sombard 4%s");
6169 /* TRANS: Lethal B_ombard (100% chance of success). */
6170 return N_("Lethal B%sombard%s");
6171 case ACTION_SPY_NUKE:
6172 /* TRANS: Suitcase _Nuke (100% chance of success). */
6173 return N_("Suitcase %sNuke%s");
6175 /* TRANS: Suitcase _Nuke and Escape (100% chance of success). */
6176 return N_("Suitcase %sNuke and Escape%s");
6177 case ACTION_NUKE:
6178 /* TRANS: Explode _Nuclear (100% chance of success). */
6179 return N_("Explode %sNuclear%s");
6180 case ACTION_NUKE_CITY:
6181 /* TRANS: _Nuke City (100% chance of success). */
6182 return N_("%sNuke City%s");
6183 case ACTION_NUKE_UNITS:
6184 /* TRANS: _Nuke Units (100% chance of success). */
6185 return N_("%sNuke Units%s");
6187 /* TRANS: Destroy _City (100% chance of success). */
6188 return N_("Destroy %sCity%s");
6190 /* TRANS: Dis_band recovering production (100% chance of success). */
6191 return N_("Dis%sband recovering production%s");
6193 /* TRANS: Dis_band without recovering production (100% chance of success). */
6194 return N_("Dis%sband without recovering production%s");
6195 case ACTION_HOME_CITY:
6196 /* TRANS: Set _Home City (100% chance of success). */
6197 return N_("Set %sHome City%s");
6198 case ACTION_HOMELESS:
6199 /* TRANS: Make _Homeless (100% chance of success). */
6200 return N_("Make %sHomeless%s");
6202 /* TRANS: _Upgrade Unit (100% chance of success). */
6203 return N_("%sUpgrade Unit%s");
6204 case ACTION_PARADROP:
6205 /* TRANS: Drop _Paratrooper (100% chance of success). */
6206 return N_("Drop %sParatrooper%s");
6208 /* TRANS: Drop _Paratrooper (100% chance of success). */
6209 return N_("Drop %sParatrooper%s");
6211 /* TRANS: Drop _Paratrooper (100% chance of success). */
6212 return N_("Drop %sParatrooper%s");
6214 /* TRANS: Drop _Paratrooper (100% chance of success). */
6215 return N_("Drop %sParatrooper%s");
6217 /* TRANS: Drop _Paratrooper (100% chance of success). */
6218 return N_("Drop %sParatrooper%s");
6220 /* TRANS: Drop _Paratrooper (100% chance of success). */
6221 return N_("Drop %sParatrooper%s");
6222 case ACTION_AIRLIFT:
6223 /* TRANS: _Airlift to City (100% chance of success). */
6224 return N_("%sAirlift to City%s");
6225 case ACTION_ATTACK:
6226 case ACTION_ATTACK2:
6227 /* TRANS: _Attack (100% chance of success). */
6228 return N_("%sAttack%s");
6231 /* TRANS: _Suicide Attack (100% chance of success). */
6232 return N_("%sSuicide Attack%s");
6233 case ACTION_WIPE_UNITS:
6234 /* TRANS: _Wipe Units (100% chance of success). */
6235 return N_("%sWipe Units%s");
6237 /* TRANS: Collect _Ransom (100% chance of success). */
6238 return N_("Collect %sRansom%s");
6240 /* TRANS: Surgical Str_ike Building (100% chance of success). */
6241 return N_("Surgical Str%sike Building%s");
6243 /* TRANS: Surgical Str_ike Production (100% chance of success). */
6244 return N_("Surgical Str%sike Production%s");
6248 /* TRANS: _Conquer City (100% chance of success). */
6249 return N_("%sConquer City%s");
6251 /* TRANS: _Conquer City 2 (100% chance of success). */
6252 return N_("%sConquer City 2%s");
6256 /* TRANS: _Conquer Extras (100% chance of success). */
6257 return N_("%sConquer Extras%s");
6259 /* TRANS: _Conquer Extras 2 (100% chance of success). */
6260 return N_("%sConquer Extras 2%s");
6261 case ACTION_HEAL_UNIT:
6262 case ACTION_HEAL_UNIT2:
6263 /* TRANS: Heal _Unit (3% chance of success). */
6264 return N_("Heal %sUnit%s");
6267 /* TRANS: _Transform Terrain (3% chance of success). */
6268 return N_("%sTransform Terrain%s");
6269 case ACTION_CULTIVATE:
6270 case ACTION_CULTIVATE2:
6271 /* TRANS: Transform by _Cultivating (3% chance of success). */
6272 return N_("Transform by %sCultivating%s");
6273 case ACTION_PLANT:
6274 case ACTION_PLANT2:
6275 /* TRANS: Transform by _Planting (3% chance of success). */
6276 return N_("Transform by %sPlanting%s");
6277 case ACTION_PILLAGE:
6278 case ACTION_PILLAGE2:
6279 /* TRANS: Pilla_ge (100% chance of success). */
6280 return N_("Pilla%sge%s");
6281 case ACTION_CLEAN:
6282 case ACTION_CLEAN2:
6283 /* TRANS: Clean (100% chance of success). */
6284 return N_("%sClean%s");
6285 case ACTION_FORTIFY:
6286 case ACTION_FORTIFY2:
6287 /* TRANS: _Fortify (100% chance of success). */
6288 return N_("%sFortify%s");
6289 case ACTION_ROAD:
6290 case ACTION_ROAD2:
6291 /* TRANS: Build _Road (100% chance of success). */
6292 return N_("Build %sRoad%s");
6293 case ACTION_CONVERT:
6294 /* TRANS: _Convert Unit (100% chance of success). */
6295 return N_("%sConvert Unit%s");
6296 case ACTION_BASE:
6297 case ACTION_BASE2:
6298 /* TRANS: _Build Base (100% chance of success). */
6299 return N_("%sBuild Base%s");
6300 case ACTION_MINE:
6301 case ACTION_MINE2:
6302 /* TRANS: Build _Mine (100% chance of success). */
6303 return N_("Build %sMine%s");
6304 case ACTION_IRRIGATE:
6305 case ACTION_IRRIGATE2:
6306 /* TRANS: Build _Irrigation (100% chance of success). */
6307 return N_("Build %sIrrigation%s");
6309 /* TRANS: _Deboard (100% chance of success). */
6310 return N_("%sDeboard%s");
6314 /* TRANS: _Board (100% chance of success). */
6315 return N_("%sBoard%s");
6320 /* TRANS: _Embark (100% chance of success). */
6321 return N_("%sEmbark%s");
6323 /* TRANS: _Unload (100% chance of success). */
6324 return N_("%sUnload%s");
6328 /* TRANS: _Load (100% chance of success). */
6329 return N_("%sLoad%s");
6333 /* TRANS: _Disembark (100% chance of success). */
6334 return N_("%sDisembark%s");
6336 /* TRANS: _Disembark 2 (100% chance of success). */
6337 return N_("%sDisembark 2%s");
6338 case ACTION_SPY_ATTACK:
6339 /* TRANS: _Eliminate Diplomat (100% chance of success). */
6340 return N_("%sEliminate Diplomat%s");
6341 case ACTION_HUT_ENTER:
6342 case ACTION_HUT_ENTER2:
6343 case ACTION_HUT_ENTER3:
6344 case ACTION_HUT_ENTER4:
6345 /* TRANS: Enter _Hut (100% chance of success). */
6346 return N_("Enter %sHut%s");
6351 /* TRANS: Frighten _Hut (100% chance of success). */
6352 return N_("Frighten %sHut%s");
6353 case ACTION_UNIT_MOVE:
6354 case ACTION_UNIT_MOVE2:
6355 case ACTION_UNIT_MOVE3:
6356 /* TRANS: Regular _Move (100% chance of success). */
6357 return N_("Regular %sMove%s");
6358 case ACTION_TELEPORT:
6359 case ACTION_TELEPORT2:
6360 case ACTION_TELEPORT3:
6361 /* TRANS: _Teleport (100% chance of success). */
6362 return N_("%sTeleport%s");
6364 /* TRANS: _Teleport (100% chance of success). */
6365 return N_("%sTeleport%s");
6367 /* TRANS: _Teleport (100% chance of success). */
6368 return N_("%sTeleport%s");
6370 /* TRANS: _Teleport (100% chance of success). */
6371 return N_("%sTeleport%s");
6373 /* TRANS: _Teleport (100% chance of success). */
6374 return N_("%sTeleport%s");
6376 /* TRANS: _Teleport (100% chance of success). */
6377 return N_("%sTeleport%s");
6378 case ACTION_SPY_ESCAPE:
6379 /* TRANS: _Escape To Nearest City (100% chance of success). */
6380 return N_("%sEscape To Nearest City%s");
6381 case ACTION_SCOUT:
6382 /* TRANS: _Scout (100% chance of success). */
6383 return N_("%sScout%s");
6385 /* TRANS: _User Action 1 (100% chance of success). */
6386 return N_("%sUser Action 1%s");
6388 /* TRANS: _User Action 2 (100% chance of success). */
6389 return N_("%sUser Action 2%s");
6391 /* TRANS: _User Action 3 (100% chance of success). */
6392 return N_("%sUser Action 3%s");
6394 /* TRANS: _User Action 4 (100% chance of success). */
6395 return N_("%sUser Action 4%s");
6397 return N_("%sGain Veterancy%s");
6398 case ACTION_ESCAPE:
6399 return N_("%sEscape%s");
6400 case ACTION_CIVIL_WAR:
6401 return N_("%sCivil War%s");
6402 case ACTION_FINISH_UNIT:
6403 return N_("Finish %sUnit%s");
6405 return N_("Finish %sBuilding%s");
6406 case ACTION_COUNT:
6407 fc_assert(act != ACTION_COUNT);
6408 break;
6409 }
6410
6411 return nullptr;
6412}
6413
6414/**********************************************************************/
6421{
6422 switch ((enum gen_action)act) {
6423 case ACTION_SPY_POISON:
6448 case ACTION_STEAL_MAPS:
6450 case ACTION_TRADE_ROUTE:
6451 case ACTION_MARKETPLACE:
6452 case ACTION_HELP_WONDER:
6454 case ACTION_EXPEL_UNIT:
6455 case ACTION_FOUND_CITY:
6456 case ACTION_JOIN_CITY:
6457 case ACTION_SPY_NUKE:
6462 case ACTION_HOME_CITY:
6463 case ACTION_HOMELESS:
6465 case ACTION_PARADROP:
6471 case ACTION_AIRLIFT:
6472 case ACTION_ATTACK:
6473 case ACTION_ATTACK2:
6476 case ACTION_WIPE_UNITS:
6484 case ACTION_HEAL_UNIT:
6485 case ACTION_HEAL_UNIT2:
6488 case ACTION_CULTIVATE:
6489 case ACTION_CULTIVATE2:
6490 case ACTION_PLANT:
6491 case ACTION_PLANT2:
6492 case ACTION_PILLAGE:
6493 case ACTION_PILLAGE2:
6494 case ACTION_CLEAN:
6495 case ACTION_CLEAN2:
6496 case ACTION_FORTIFY:
6497 case ACTION_FORTIFY2:
6498 case ACTION_ROAD:
6499 case ACTION_ROAD2:
6500 case ACTION_CONVERT:
6501 case ACTION_BASE:
6502 case ACTION_BASE2:
6503 case ACTION_MINE:
6504 case ACTION_MINE2:
6505 case ACTION_IRRIGATE:
6506 case ACTION_IRRIGATE2:
6523 case ACTION_BOMBARD:
6524 case ACTION_BOMBARD2:
6525 case ACTION_BOMBARD3:
6526 case ACTION_BOMBARD4:
6529 case ACTION_SPY_ATTACK:
6534 case ACTION_HUT_ENTER:
6535 case ACTION_HUT_ENTER2:
6536 case ACTION_HUT_ENTER3:
6537 case ACTION_HUT_ENTER4:
6542 case ACTION_UNIT_MOVE:
6543 case ACTION_UNIT_MOVE2:
6544 case ACTION_UNIT_MOVE3:
6545 case ACTION_SPY_ESCAPE:
6546 case ACTION_SCOUT:
6548 case ACTION_ESCAPE:
6549 case ACTION_CIVIL_WAR:
6550 case ACTION_FINISH_UNIT:
6552 /* Min range is not ruleset changeable */
6553 return nullptr;
6554 case ACTION_NUKE:
6555 return "explode_nuclear_min_range";
6556 case ACTION_NUKE_CITY:
6557 return "nuke_city_min_range";
6558 case ACTION_NUKE_UNITS:
6559 return "nuke_units_min_range";
6560 case ACTION_TELEPORT:
6561 return "teleport_min_range";
6562 case ACTION_TELEPORT2:
6563 return "teleport_2_min_range";
6564 case ACTION_TELEPORT3:
6565 return "teleport_3_min_range";
6567 return "teleport_conquer_min_range";
6569 return "teleport_frighten_min_range";
6571 return "teleport_frighten_conquer_min_range";
6573 return "teleport_enter_min_range";
6575 return "teleport_enter_conquer_min_range";
6577 return "user_action_1_min_range";
6579 return "user_action_2_min_range";
6581 return "user_action_3_min_range";
6583 return "user_action_4_min_range";
6584 case ACTION_COUNT:
6585 break;
6586
6588 }
6589
6590 fc_assert(act >= 0 && act < ACTION_COUNT);
6591
6592 return nullptr;
6593}
6594
6595/**********************************************************************/
6602{
6603 switch ((enum gen_action)act) {
6604 case ACTION_SPY_POISON:
6629 case ACTION_STEAL_MAPS:
6631 case ACTION_TRADE_ROUTE:
6632 case ACTION_MARKETPLACE:
6634 case ACTION_EXPEL_UNIT:
6635 case ACTION_FOUND_CITY:
6636 case ACTION_JOIN_CITY:
6637 case ACTION_SPY_NUKE:
6641 case ACTION_HOME_CITY:
6642 case ACTION_HOMELESS:
6644 case ACTION_PARADROP:
6650 case ACTION_ATTACK:
6651 case ACTION_ATTACK2:
6654 case ACTION_WIPE_UNITS:
6662 case ACTION_HEAL_UNIT:
6663 case ACTION_HEAL_UNIT2:
6666 case ACTION_CULTIVATE:
6667 case ACTION_CULTIVATE2:
6668 case ACTION_PLANT:
6669 case ACTION_PLANT2:
6670 case ACTION_PILLAGE:
6671 case ACTION_PILLAGE2:
6672 case ACTION_CLEAN:
6673 case ACTION_CLEAN2:
6674 case ACTION_FORTIFY:
6675 case ACTION_FORTIFY2:
6676 case ACTION_ROAD:
6677 case ACTION_ROAD2:
6678 case ACTION_CONVERT:
6679 case ACTION_BASE:
6680 case ACTION_BASE2:
6681 case ACTION_MINE:
6682 case ACTION_MINE2:
6683 case ACTION_IRRIGATE:
6684 case ACTION_IRRIGATE2:
6701 case ACTION_SPY_ATTACK:
6706 case ACTION_HUT_ENTER:
6707 case ACTION_HUT_ENTER2:
6708 case ACTION_HUT_ENTER3:
6709 case ACTION_HUT_ENTER4:
6714 case ACTION_UNIT_MOVE:
6715 case ACTION_UNIT_MOVE2:
6716 case ACTION_UNIT_MOVE3:
6717 case ACTION_SPY_ESCAPE:
6719 case ACTION_ESCAPE:
6720 case ACTION_CIVIL_WAR:
6721 case ACTION_FINISH_UNIT:
6723 /* Max range is not ruleset changeable */
6724 return nullptr;
6725 case ACTION_HELP_WONDER:
6726 return "help_wonder_max_range";
6728 return "disband_unit_recover_max_range";
6729 case ACTION_BOMBARD:
6730 return "bombard_max_range";
6731 case ACTION_BOMBARD2:
6732 return "bombard_2_max_range";
6733 case ACTION_BOMBARD3:
6734 return "bombard_3_max_range";
6735 case ACTION_BOMBARD4:
6736 return "bombard_4_max_range";
6738 return "bombard_lethal_max_range";
6740 return "bombard_lethal_2_max_range";
6741 case ACTION_NUKE:
6742 return "explode_nuclear_max_range";
6743 case ACTION_NUKE_CITY:
6744 return "nuke_city_max_range";
6745 case ACTION_NUKE_UNITS:
6746 return "nuke_units_max_range";
6747 case ACTION_AIRLIFT:
6748 return "airlift_max_range";
6749 case ACTION_TELEPORT:
6750 return "teleport_max_range";
6751 case ACTION_TELEPORT2:
6752 return "teleport_2_max_range";
6753 case ACTION_TELEPORT3:
6754 return "teleport_3_max_range";
6756 return "teleport_conquer_max_range";
6758 return "teleport_frighten_max_range";
6760 return "teleport_frighten_conquer_max_range";
6762 return "teleport_enter_max_range";
6764 return "teleport_enter_conquer_max_range";
6765 case ACTION_SCOUT:
6766 return "scout_max_range";
6768 return "user_action_1_max_range";
6770 return "user_action_2_max_range";
6772 return "user_action_3_max_range";
6774 return "user_action_4_max_range";
6775 case ACTION_COUNT:
6776 break;
6777
6779 }
6780
6781 fc_assert(act >= 0 && act < ACTION_COUNT);
6782
6783 return nullptr;
6784}
6785
6786/**********************************************************************/
6793{
6794 switch ((enum gen_action)act) {
6795 case ACTION_SPY_POISON:
6820 case ACTION_STEAL_MAPS:
6822 case ACTION_TRADE_ROUTE:
6823 case ACTION_MARKETPLACE:
6824 case ACTION_HELP_WONDER:
6826 case ACTION_EXPEL_UNIT:
6827 case ACTION_FOUND_CITY:
6828 case ACTION_JOIN_CITY:
6829 case ACTION_SPY_NUKE:
6831 case ACTION_NUKE_UNITS:
6835 case ACTION_HOME_CITY:
6836 case ACTION_HOMELESS:
6838 case ACTION_PARADROP:
6844 case ACTION_AIRLIFT:
6845 case ACTION_ATTACK:
6846 case ACTION_ATTACK2:
6849 case ACTION_WIPE_UNITS:
6857 case ACTION_HEAL_UNIT:
6858 case ACTION_HEAL_UNIT2:
6861 case ACTION_CULTIVATE:
6862 case ACTION_CULTIVATE2:
6863 case ACTION_PLANT:
6864 case ACTION_PLANT2:
6865 case ACTION_CLEAN:
6866 case ACTION_CLEAN2:
6867 case ACTION_FORTIFY:
6868 case ACTION_FORTIFY2:
6869 case ACTION_ROAD:
6870 case ACTION_ROAD2:
6871 case ACTION_CONVERT:
6872 case ACTION_BASE:
6873 case ACTION_BASE2:
6874 case ACTION_MINE:
6875 case ACTION_MINE2:
6876 case ACTION_IRRIGATE:
6877 case ACTION_IRRIGATE2:
6894 case ACTION_BOMBARD:
6895 case ACTION_BOMBARD2:
6896 case ACTION_BOMBARD3:
6897 case ACTION_BOMBARD4:
6900 case ACTION_SPY_ATTACK:
6905 case ACTION_HUT_ENTER:
6906 case ACTION_HUT_ENTER2:
6907 case ACTION_HUT_ENTER3:
6908 case ACTION_HUT_ENTER4:
6913 case ACTION_UNIT_MOVE:
6914 case ACTION_UNIT_MOVE2:
6915 case ACTION_UNIT_MOVE3:
6916 case ACTION_TELEPORT:
6917 case ACTION_TELEPORT2:
6918 case ACTION_TELEPORT3:
6924 case ACTION_SPY_ESCAPE:
6925 case ACTION_SCOUT:
6927 case ACTION_ESCAPE:
6928 case ACTION_CIVIL_WAR:
6929 case ACTION_FINISH_UNIT:
6931 /* Target kind is not ruleset changeable */
6932 return nullptr;
6933 case ACTION_NUKE:
6934 return "explode_nuclear_target_kind";
6935 case ACTION_NUKE_CITY:
6936 return "nuke_city_target_kind";
6937 case ACTION_PILLAGE:
6938 return "pillage_target_kind";
6939 case ACTION_PILLAGE2:
6940 return "pillage_2_target_kind";
6942 return "user_action_1_target_kind";
6944 return "user_action_2_target_kind";
6946 return "user_action_3_target_kind";
6948 return "user_action_4_target_kind";
6949 case ACTION_COUNT:
6950 break;
6951
6953 }
6954
6955 fc_assert(act >= 0 && act < ACTION_COUNT);
6956
6957 return nullptr;
6958}
6959
6960/**********************************************************************/
6968{
6969 switch ((enum gen_action)act) {
6970 case ACTION_SPY_POISON:
6994 case ACTION_STEAL_MAPS:
6996 case ACTION_TRADE_ROUTE:
6997 case ACTION_MARKETPLACE:
6998 case ACTION_HELP_WONDER:
7000 case ACTION_EXPEL_UNIT:
7001 case ACTION_JOIN_CITY:
7002 case ACTION_SPY_NUKE:
7007 case ACTION_HOME_CITY:
7008 case ACTION_HOMELESS:
7010 case ACTION_PARADROP:
7016 case ACTION_AIRLIFT:
7017 case ACTION_ATTACK:
7018 case ACTION_ATTACK2:
7021 case ACTION_WIPE_UNITS:
7029 case ACTION_HEAL_UNIT:
7030 case ACTION_HEAL_UNIT2:
7033 case ACTION_CULTIVATE:
7034 case ACTION_CULTIVATE2:
7035 case ACTION_PLANT:
7036 case ACTION_PLANT2:
7037 case ACTION_PILLAGE:
7038 case ACTION_PILLAGE2:
7039 case ACTION_CLEAN:
7040 case ACTION_CLEAN2:
7041 case ACTION_FORTIFY:
7042 case ACTION_FORTIFY2:
7043 case ACTION_ROAD:
7044 case ACTION_ROAD2:
7045 case ACTION_CONVERT:
7046 case ACTION_BASE:
7047 case ACTION_BASE2:
7048 case ACTION_MINE:
7049 case ACTION_MINE2:
7050 case ACTION_IRRIGATE:
7051 case ACTION_IRRIGATE2:
7068 case ACTION_BOMBARD:
7069 case ACTION_BOMBARD2:
7070 case ACTION_BOMBARD3:
7071 case ACTION_BOMBARD4:
7074 case ACTION_SPY_ATTACK:
7079 case ACTION_HUT_ENTER:
7080 case ACTION_HUT_ENTER2:
7081 case ACTION_HUT_ENTER3:
7082 case ACTION_HUT_ENTER4:
7087 case ACTION_UNIT_MOVE:
7088 case ACTION_UNIT_MOVE2:
7089 case ACTION_UNIT_MOVE3:
7090 case ACTION_TELEPORT:
7091 case ACTION_TELEPORT2:
7092 case ACTION_TELEPORT3:
7098 case ACTION_SPY_ESCAPE:
7099 case ACTION_SCOUT:
7101 case ACTION_ESCAPE:
7102 case ACTION_CIVIL_WAR:
7103 case ACTION_FINISH_UNIT:
7105 /* Actor consuming always is not ruleset changeable */
7106 return nullptr;
7107 case ACTION_FOUND_CITY:
7108 return "found_city_consuming_always";
7109 case ACTION_NUKE:
7110 return "explode_nuclear_consuming_always";
7111 case ACTION_NUKE_CITY:
7112 return "nuke_city_consuming_always";
7113 case ACTION_NUKE_UNITS:
7114 return "nuke_units_consuming_always";
7116 return "spread_plague_actor_consuming_always";
7118 return "user_action_1_actor_consuming_always";
7120 return "user_action_2_actor_consuming_always";
7122 return "user_action_3_actor_consuming_always";
7124 return "user_action_4_actor_consuming_always";
7125 case ACTION_COUNT:
7126 break;
7127
7129 }
7130
7131 fc_assert(act >= 0 && act < ACTION_COUNT);
7132
7133 return nullptr;
7134}
7135
7136/**********************************************************************/
7143const char *action_blocked_by_ruleset_var_name(const struct action *act)
7144{
7145 fc_assert_ret_val(act != nullptr, nullptr);
7146
7147 switch ((enum gen_action)action_number(act)) {
7148 case ACTION_MARKETPLACE:
7149 return "enter_marketplace_blocked_by";
7150 case ACTION_BOMBARD:
7151 return "bombard_blocked_by";
7152 case ACTION_BOMBARD2:
7153 return "bombard_2_blocked_by";
7154 case ACTION_BOMBARD3:
7155 return "bombard_3_blocked_by";
7156 case ACTION_BOMBARD4:
7157 return "bombard_4_blocked_by";
7159 return "bombard_lethal_blocked_by";
7161 return "bombard_lethal_2_blocked_by";
7162 case ACTION_NUKE:
7163 return "explode_nuclear_blocked_by";
7164 case ACTION_NUKE_CITY:
7165 return "nuke_city_blocked_by";
7166 case ACTION_NUKE_UNITS:
7167 return "nuke_units_blocked_by";
7168 case ACTION_ATTACK:
7169 return "attack_blocked_by";
7170 case ACTION_ATTACK2:
7171 return "attack_2_blocked_by";
7173 return "suicide_attack_blocked_by";
7175 return "suicide_attack_2_blocked_by";
7176 case ACTION_WIPE_UNITS:
7177 return "wipe_units_blocked_by";
7179 return "collect_ransom_blocked_by";
7181 return "conquer_city_shrink_blocked_by";
7183 return "conquer_city_shrink_2_blocked_by";
7185 return "conquer_city_shrink_3_blocked_by";
7187 return "conquer_city_shrink_4_blocked_by";
7188 case ACTION_UNIT_MOVE:
7189 return "move_blocked_by";
7190 case ACTION_UNIT_MOVE2:
7191 return "move_2_blocked_by";
7192 case ACTION_UNIT_MOVE3:
7193 return "move_3_blocked_by";
7194 case ACTION_TELEPORT:
7195 return "teleport_blocked_by";
7196 case ACTION_TELEPORT2:
7197 return "teleport_2_blocked_by";
7198 case ACTION_TELEPORT3:
7199 return "teleport_3_blocked_by";
7201 return "teleport_conquer_blocked_by";
7203 return "teleport_frighten_blocked_by";
7205 return "teleport_frighten_conquer_blocked_by";
7207 return "teleport_enter_blocked_by";
7209 return "teleport_enter_conquer_blocked_by";
7210 case ACTION_SPY_ESCAPE:
7211 case ACTION_SPY_POISON:
7235 case ACTION_STEAL_MAPS:
7237 case ACTION_TRADE_ROUTE:
7238 case ACTION_HELP_WONDER:
7240 case ACTION_EXPEL_UNIT:
7241 case ACTION_FOUND_CITY:
7242 case ACTION_JOIN_CITY:
7243 case ACTION_SPY_NUKE:
7248 case ACTION_HOME_CITY:
7249 case ACTION_HOMELESS:
7251 case ACTION_PARADROP:
7257 case ACTION_AIRLIFT:
7260 case ACTION_HEAL_UNIT:
7261 case ACTION_HEAL_UNIT2:
7264 case ACTION_CULTIVATE:
7265 case ACTION_CULTIVATE2:
7266 case ACTION_PLANT:
7267 case ACTION_PLANT2:
7268 case ACTION_PILLAGE:
7269 case ACTION_PILLAGE2:
7270 case ACTION_CLEAN:
7271 case ACTION_CLEAN2:
7272 case ACTION_FORTIFY:
7273 case ACTION_FORTIFY2:
7274 case ACTION_ROAD:
7275 case ACTION_ROAD2:
7276 case ACTION_CONVERT:
7277 case ACTION_BASE:
7278 case ACTION_BASE2:
7279 case ACTION_MINE:
7280 case ACTION_MINE2:
7281 case ACTION_IRRIGATE:
7282 case ACTION_IRRIGATE2:
7300 case ACTION_SPY_ATTACK:
7305 case ACTION_HUT_ENTER:
7306 case ACTION_HUT_ENTER2:
7307 case ACTION_HUT_ENTER3:
7308 case ACTION_HUT_ENTER4:
7313 case ACTION_SCOUT:
7315 case ACTION_CIVIL_WAR:
7316 case ACTION_FINISH_UNIT:
7318 case ACTION_ESCAPE:
7323 /* blocked_by is not ruleset changeable */
7324 return nullptr;
7325 case ACTION_COUNT:
7327 break;
7328
7330 }
7331
7332 return nullptr;
7333}
7334
7335/**********************************************************************/
7339const char *
7341{
7342 fc_assert_ret_val(act != nullptr, nullptr);
7343
7349 /* No support in the action performer function */
7350 return nullptr;
7351 }
7352
7353 switch ((enum gen_action)action_number(act)) {
7355 return "bribe_unit_post_success_forced_actions";
7357 return "bribe_stack_post_success_forced_actions";
7358 case ACTION_ATTACK:
7359 return "attack_post_success_forced_actions";
7360 case ACTION_ATTACK2:
7361 return "attack_2_post_success_forced_actions";
7362 case ACTION_WIPE_UNITS:
7363 return "wipe_units_post_success_forced_actions";
7365 return "collect_ransom_post_success_forced_actions";
7366 case ACTION_MARKETPLACE:
7367 case ACTION_BOMBARD:
7368 case ACTION_BOMBARD2:
7369 case ACTION_BOMBARD3:
7370 case ACTION_BOMBARD4:
7373 case ACTION_NUKE:
7374 case ACTION_NUKE_CITY:
7375 case ACTION_NUKE_UNITS:
7382 case ACTION_SPY_POISON:
7404 case ACTION_STEAL_MAPS:
7406 case ACTION_TRADE_ROUTE:
7407 case ACTION_HELP_WONDER:
7409 case ACTION_EXPEL_UNIT:
7410 case ACTION_FOUND_CITY:
7411 case ACTION_JOIN_CITY:
7412 case ACTION_SPY_NUKE:
7417 case ACTION_HOME_CITY:
7418 case ACTION_HOMELESS:
7420 case ACTION_PARADROP:
7426 case ACTION_AIRLIFT:
7429 case ACTION_HEAL_UNIT:
7430 case ACTION_HEAL_UNIT2:
7433 case ACTION_CULTIVATE:
7434 case ACTION_CULTIVATE2:
7435 case ACTION_PLANT:
7436 case ACTION_PLANT2:
7437 case ACTION_PILLAGE:
7438 case ACTION_PILLAGE2:
7439 case ACTION_CLEAN:
7440 case ACTION_CLEAN2:
7441 case ACTION_FORTIFY:
7442 case ACTION_FORTIFY2:
7443 case ACTION_ROAD:
7444 case ACTION_ROAD2:
7445 case ACTION_CONVERT:
7446 case ACTION_BASE:
7447 case ACTION_BASE2:
7448 case ACTION_MINE:
7449 case ACTION_MINE2:
7450 case ACTION_IRRIGATE:
7451 case ACTION_IRRIGATE2:
7469 case ACTION_SPY_ATTACK:
7474 case ACTION_HUT_ENTER:
7475 case ACTION_HUT_ENTER2:
7476 case ACTION_HUT_ENTER3:
7477 case ACTION_HUT_ENTER4:
7482 case ACTION_UNIT_MOVE:
7483 case ACTION_UNIT_MOVE2:
7484 case ACTION_UNIT_MOVE3:
7485 case ACTION_TELEPORT:
7486 case ACTION_TELEPORT2:
7487 case ACTION_TELEPORT3:
7493 case ACTION_SPY_ESCAPE:
7494 case ACTION_SCOUT:
7496 case ACTION_ESCAPE:
7497 case ACTION_CIVIL_WAR:
7498 case ACTION_FINISH_UNIT:
7504 /* Not ruleset changeable */
7505 return nullptr;
7506 case ACTION_COUNT:
7508 break;
7509
7511 }
7512
7513 return nullptr;
7514}
7515
7516/**********************************************************************/
7524
7525/**********************************************************************/
7528const char *gen_action_name_update_cb(const char *old_name)
7529{
7530 if (is_ruleset_compat_mode()) {
7531 }
7532
7533 return old_name;
7534}
7535
7537{
7538 N_("individual cities"), /* ATK_CITY */
7539 N_("individual units"), /* ATK_UNIT */
7540 N_("unit stacks"), /* ATK_STACK */
7541 N_("tiles"), /* ATK_TILE */
7542 N_("tile extras"), /* ATK_EXTRAS */
7543 N_("itself") /* ATK_SELF */
7544};
7545
7546/**********************************************************************/
7551{
7552 fc_assert(kind >= 0 && kind < ATK_COUNT);
7553
7554 return _(atk_helpnames[kind]);
7555}
7556
7557/************************************************************************/
7561{
7562 fc_assert(result < ACTRES_LAST);
7563
7564 return actlist_by_result[result];
7565}
7566
7567/************************************************************************/
7571{
7572 fc_assert(activity < ACTIVITY_LAST);
7573
7574 return actlist_by_activity[activity];
7575}
7576
7577/************************************************************************/
7582 enum action_result actres,
7583 struct unit *punit,
7584 struct tile *ptile)
7585{
7586 if (actres >= ACTRES_LAST) {
7587 return ACTION_NONE;
7588 }
7589
7591 enum gen_action act = action_number(paction);
7592
7593 if (is_action_enabled_unit_on_stack(nmap, act, punit, ptile)) {
7594 return act;
7595 }
7597
7598 return ACTION_NONE;
7599}
7600
7601/************************************************************************/
7606 enum action_result actres,
7607 struct unit *punit,
7608 struct tile *ptile)
7609{
7610 if (actres >= ACTRES_LAST) {
7611 return ACTION_NONE;
7612 }
7613
7615 enum gen_action act = action_number(paction);
7616
7618 && is_action_enabled_unit_on_tile(nmap, act, punit, ptile, nullptr)) {
7619 return act;
7620 }
7622
7623 return ACTION_NONE;
7624}
7625
7626/************************************************************************/
7631 enum action_result actres,
7632 struct unit *punit,
7633 struct city *pcity)
7634{
7635 if (actres >= ACTRES_LAST) {
7636 return ACTION_NONE;
7637 }
7638
7640 enum gen_action act = action_number(paction);
7641
7644 return act;
7645 }
7647
7648 return ACTION_NONE;
7649}
bool is_action_possible_on_city(action_id act_id, const struct player *actor_player, const struct city *target_city)
Definition actions.c:5727
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:1338
bool action_distance_inside_max(const struct action *action, const int distance)
Definition actions.c:1199
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:5215
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:2819
const char * action_prob_explain(const struct act_prob prob)
Definition actions.c:1449
bool action_mp_full_makes_legal(const struct unit *actor, const action_id act_id)
Definition actions.c:5805
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:4030
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:3448
enum action_actor_kind action_get_actor_kind(const struct action *paction)
Definition actions.c:1124
bool action_prob_certain(const struct act_prob probability)
Definition actions.c:5337
const char * action_id_name_translation(action_id act_id)
Definition actions.c:1276
struct action_auto_perf * action_auto_perf_slot_number(const int num)
Definition actions.c:5966
req_vec_num_in_item action_enabler_vector_number(const void *enabler, const struct requirement_vector *vec)
Definition actions.c:2053
bool action_has_complex_target(const struct action *paction)
Definition actions.c:1158
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:2402
#define ASSERT_PLAYER_ACTION(_atk)
Definition actions.c:3509
struct req_vec_problem * action_enabler_suggest_repair(const struct action_enabler *enabler)
Definition actions.c:1923
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:3293
bool action_prob_possible(const struct act_prob probability)
Definition actions.c:5327
#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:2611
struct act_prob action_prob_new_not_impl(void)
Definition actions.c:5306
struct req_vec_problem * action_enabler_suggest_improvement(const struct action_enabler *enabler)
Definition actions.c:1989
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:3757
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:5148
void actions_rs_pre_san_gen(void)
Definition actions.c:904
const char * action_min_range_ruleset_var_name(int act)
Definition actions.c:6420
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:5249
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:3804
const char * action_blocked_by_ruleset_var_name(const struct action *act)
Definition actions.c:7143
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:2995
#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:4078
struct req_vec_problem * action_enabler_suggest_repair_oblig(const struct action_enabler *enabler)
Definition actions.c:1709
void action_array_add_all_by_result(action_id *act_array, int *position, enum action_result result)
Definition actions.c:6031
const char * action_name_translation(const struct action *paction)
Definition actions.c:1256
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:5627
void action_array_end(action_id *act_array, int size)
Definition actions.c:6014
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:4848
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:3982
const char * atk_helpnames[ATK_COUNT]
Definition actions.c:7536
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:2631
static void hard_code_actions(void)
Definition actions.c:110
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:3045
bool action_is_in_use(struct action *paction)
Definition actions.c:5920
static struct req_vec_problem * enabler_tile_tgt_local_diplrel_implies_claimed(const struct action_enabler *enabler)
Definition actions.c:1778
bool action_ever_possible(action_id action)
Definition actions.c:7520
const char * action_enabler_vector_by_number_name(req_vec_num_in_item vec)
Definition actions.c:2100
bool are_action_probabilitys_equal(const struct act_prob *ap1, const struct act_prob *ap2)
Definition actions.c:5378
bool is_action_enabled_player_on_tile(const struct civ_map *nmap, const action_id wanted_action, const struct player *actor_plr, const struct tile *target_tile, const struct extra_type *target_extra)
Definition actions.c:3664
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:4948
const char * action_post_success_forced_ruleset_var_name(const struct action *act)
Definition actions.c:7340
struct action * action_by_rule_name(const char *name)
Definition actions.c:1105
static bool action_has_possible_actor_hard_reqs(struct action *paction)
Definition actions.c:5890
enum gen_action select_actres_action_unit_on_stack(struct civ_map *nmap, enum action_result actres, struct unit *punit, struct tile *ptile)
Definition actions.c:7581
static struct action * action_new(action_id id, enum action_actor_kind aak, enum action_result result, const int min_distance, const int max_distance, bool actor_consuming_always)
Definition actions.c:980
const char * action_rule_name(const struct action *action)
Definition actions.c:1242
const char * action_id_rule_name(action_id act_id)
Definition actions.c:1265
enum action_sub_target_kind action_get_sub_target_kind(const struct action *paction)
Definition actions.c:1145
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:2168
static bool action_prob_not_relevant(const struct act_prob probability)
Definition actions.c:5348
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:3936
void actions_free(void)
Definition actions.c:914
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:3370
void action_enabler_free(struct action_enabler *enabler)
Definition actions.c:1521
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:3275
static enum fc_tristate tech_can_be_stolen(const struct player *actor_player, const struct player *target_player)
Definition actions.c:3823
static struct action_list * actlist_by_result[ACTRES_LAST]
Definition actions.c:103
struct action_list * action_list_by_activity(enum unit_activity activity)
Definition actions.c:7570
int action_number(const struct action *action)
Definition actions.c:1234
struct act_prob action_prob_new_unknown(void)
Definition actions.c:5316
bool action_would_be_blocked_by(const struct action *blocked, const struct action *blocker)
Definition actions.c:1222
#define ACTPROB_VAL_NA
Definition actions.c:53
static struct action * player_action_new(action_id id, enum action_result result)
Definition actions.c:1070
static struct req_vec_problem * enabler_first_clarification(const struct action_enabler *enabler)
Definition actions.c:1971
static bool action_prob_not_impl(const struct act_prob probability)
Definition actions.c:5359
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:3351
struct act_prob action_prob_and(const struct act_prob *ap1, const struct act_prob *ap2)
Definition actions.c:5465
static bool actions_initialized
Definition actions.c:60
const char * action_actor_consuming_always_ruleset_var_name(action_id act)
Definition actions.c:6967
bool action_immune_government(struct government *gov, action_id act)
Definition actions.c:5683
static bool is_target_possible(const action_id wanted_action, const struct player *actor_player, const struct req_context *target)
Definition actions.c:5706
static struct action * city_action_new(action_id id, enum action_result result)
Definition actions.c:1082
static struct act_prob ap_dipl_battle_win(const struct unit *pattacker, const struct unit *pdefender)
Definition actions.c:3859
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:4590
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:4931
struct act_prob action_prob_new_certain(void)
Definition actions.c:5286
const char * action_max_range_ruleset_var_name(int act)
Definition actions.c:6601
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:4403
bool action_is_internal(struct action *paction)
Definition actions.c:5946
int action_dice_roll_initial_odds(const struct action *paction)
Definition actions.c:5603
struct act_prob action_prob_self(const struct civ_map *nmap, const struct unit *actor_unit, const action_id act_id)
Definition actions.c:5001
struct act_prob action_prob_fall_back(const struct act_prob *ap1, const struct act_prob *ap2)
Definition actions.c:5535
static const struct unit_type * tgt_city_local_utype(const struct city *target_city)
Definition actions.c:2143
bool is_action_enabled_city(const struct civ_map *nmap, const action_id wanted_action, const struct city *actor_city)
Definition actions.c:3725
bool is_action_enabled_player_on_stack(const struct civ_map *nmap, const action_id wanted_action, const struct player *actor_plr, const struct tile *target_tile, const struct extra_type *target_extra)
Definition actions.c:3619
static struct requirement * req_vec_first_local_diplrel(const struct requirement_vector *vec)
Definition actions.c:1759
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:4782
bool is_action_enabled_player_on_city(const struct civ_map *nmap, const action_id wanted_action, const struct player *actor_plr, const struct city *target_city)
Definition actions.c:3550
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:3110
enum gen_action select_actres_action_unit_on_tile(struct civ_map *nmap, enum action_result actres, struct unit *punit, struct tile *ptile)
Definition actions.c:7605
struct action_list * action_list_by_result(enum action_result result)
Definition actions.c:7560
bool is_action_enabled_player_on_self(const struct civ_map *nmap, const action_id wanted_action, const struct player *actor_plr)
Definition actions.c:3528
bool action_univs_not_blocking(const struct action *paction, struct universal *actor_uni, struct universal *target_uni)
Definition actions.c:5990
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:5080
bool actions_are_ready(void)
Definition actions.c:956
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:3187
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:5181
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:4490
const char * action_target_kind_ruleset_var_name(int act)
Definition actions.c:6792
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:4506
bool action_maybe_possible_actor_unit(const struct civ_map *nmap, const action_id act_id, const struct unit *actor_unit)
Definition actions.c:5750
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:2287
static bool is_enabler_active(const struct action_enabler *enabler, const struct req_context *actor, const struct req_context *target)
Definition actions.c:2978
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:1552
bool is_action_enabled_player_on_extras(const struct civ_map *nmap, const action_id wanted_action, const struct player *actor_plr, const struct tile *target_tile, const struct extra_type *target_extra)
Definition actions.c:3588
bool is_action_enabled_player_on_unit(const struct civ_map *nmap, const action_id wanted_action, const struct player *actor_plr, const struct unit *target_unit)
Definition actions.c:3695
const char * action_ui_name_default(int act)
Definition actions.c:6049
bool action_enablers_allow(const action_id wanted_action, const struct req_context *actor, const struct req_context *target)
Definition actions.c:3024
#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:5828
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:3964
struct action_enabler * action_enabler_new(void)
Definition actions.c:1501
bool action_requires_details(const struct action *paction)
Definition actions.c:1171
struct act_prob action_prob_new_not_relevant(void)
Definition actions.c:5296
const char * action_target_kind_help(enum action_target_kind kind)
Definition actions.c:7550
static struct req_vec_problem * enabler_first_self_contradiction(const struct action_enabler *enabler)
Definition actions.c:1851
int action_get_role(const struct action *paction)
Definition actions.c:1489
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:5115
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:1045
const struct action_auto_perf * action_auto_perf_by_number(const int num)
Definition actions.c:5982
struct act_prob action_prob_new_impossible(void)
Definition actions.c:5276
bool action_enabler_possible_actor(const struct action_enabler *ae)
Definition actions.c:5855
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:2228
struct action ** _actions
Definition actions.c:58
bool action_id_exists(const action_id act_id)
Definition actions.c:1094
bool action_enabler_remove(struct action_enabler *enabler)
Definition actions.c:1569
enum action_target_kind action_get_target_kind(const struct action *paction)
Definition actions.c:1134
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:5023
static bool action_prob_is_signal(const struct act_prob probability)
Definition actions.c:5370
struct action_enabler * action_enabler_copy(const struct action_enabler *original)
Definition actions.c:1537
static const char * action_prob_to_text(const struct act_prob prob)
Definition actions.c:1297
int action_prob_cmp_pessimist(const struct act_prob ap1, const struct act_prob ap2)
Definition actions.c:5387
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:4765
bool action_id_is_internal(action_id act)
Definition actions.c:5958
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:3500
bool action_id_is_rare_pop_up(action_id act_id)
Definition actions.c:1186
void actions_init(void)
Definition actions.c:855
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:1605
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:4573
static const struct impr_type * tgt_city_local_building(const struct city *target_city)
Definition actions.c:2120
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:3428
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:3128
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:3205
double action_prob_to_0_to_1_pessimist(const struct act_prob ap)
Definition actions.c:5438
const char * gen_action_name_update_cb(const char *old_name)
Definition actions.c:7528
enum gen_action select_actres_action_unit_on_city(struct civ_map *nmap, enum action_result actres, struct unit *punit, struct city *pcity)
Definition actions.c:7630
static struct action_list * actlist_by_activity[ACTIVITY_LAST]
Definition actions.c:104
struct action_enabler_list * action_enablers_for_action(action_id action)
Definition actions.c:1585
struct requirement_vector * action_enabler_vector_by_number(const void *enabler, req_vec_num_in_item number)
Definition actions.c:2076
bool action_distance_accepted(const struct action *action, const int distance)
Definition actions.c:1210
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:4865
const char * action_get_ui_name_mnemonic(action_id act_id, const char *mnemonic)
Definition actions.c:1284
#define ACTPROB_VAL_MIN
Definition actions.c:47
#define action_list_iterate_end
Definition actions.h:229
#define action_noninternal_iterate_end
Definition actions.h:240
#define ACTION_DISTANCE_MAX
Definition actions.h:107
#define enabler_get_action(_enabler_)
Definition actions.h:186
#define ASSERT_UNUSED_ACTION_CASES
Definition actions.h:38
#define ACTPROB_CERTAIN
Definition actions.h:718
#define enabler_get_action_id(_enabler_)
Definition actions.h:187
#define ACTPROB_NA
Definition actions.h:719
static struct action * action_by_number(action_id act_id)
Definition actions.h:400
#define action_enabler_list_re_iterate_end
Definition actions.h:200
#define ACTION_DISTANCE_LAST_NON_SIGNAL
Definition actions.h:103
#define action_enabler_list_re_iterate(action_enabler_list, aenabler)
Definition actions.h:196
#define action_has_result(_act_, _res_)
Definition actions.h:184
#define action_enabler_list_iterate_end
Definition actions.h:194
#define ACTION_DISTANCE_UNLIMITED
Definition actions.h:105
#define action_iterate_end
Definition actions.h:218
#define MAX_NUM_ACTIONS
Definition actions.h:62
#define action_iterate_all(_act_)
Definition actions.h:204
#define action_id_get_actor_kind(act_id)
Definition actions.h:413
#define action_iterate_all_end
Definition actions.h:209
#define ACTPROB_NOT_KNOWN
Definition actions.h:721
#define action_enabler_list_iterate(action_enabler_list, aenabler)
Definition actions.h:192
#define action_id_distance_accepted(act_id, distance)
Definition actions.h:449
#define ACTPROB_IMPOSSIBLE
Definition actions.h:717
#define ACTPROB_NOT_IMPLEMENTED
Definition actions.h:720
#define action_iterate(_act_)
Definition actions.h:214
#define ACTION_ANY
Definition actions.h:56
#define action_noninternal_iterate(_act_)
Definition actions.h:235
#define action_list_iterate(_list_, _act_)
Definition actions.h:227
#define action_id_get_target_kind(act_id)
Definition actions.h:417
#define action_id_has_result_safe(act_id, result)
Definition actions.h:430
#define ACTION_ODDS_PCT_DICE_ROLL_NA
Definition actions.h:724
#define ACTION_NONE
Definition actions.h:59
enum action_sub_target_kind actres_sub_target_kind_default(enum action_result result)
Definition actres.c:679
enum act_tgt_compl actres_target_compl_calc(enum action_result result)
Definition actres.c:262
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:843
enum unit_activity actres_activity_result(enum action_result result)
Definition actres.c:305
enum dice_roll_type actres_dice_type(enum action_result result)
Definition actres.c:368
enum action_battle_kind actres_get_battle_kind(enum action_result result)
Definition actres.c:276
enum action_target_kind actres_target_kind_default(enum action_result result)
Definition actres.c:778
#define ASSERT_UNUSED_ACTRES_CASES
Definition actres.h:37
@ DRT_DIPLCHANCE
Definition actres.h:109
@ DRT_CERTAIN
Definition actres.h:109
@ DRT_NONE
Definition actres.h:109
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:163
#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:766
#define city_tile(_pcity_)
Definition city.h:565
#define city_owner(_pcity_)
Definition city.h:564
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:59
char * incite_cost
Definition comments.c:77
struct unit struct city struct unit * target_unit
Definition dialogs_g.h:55
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:72
struct unit * actor_unit
Definition dialogs_g.h:54
struct unit struct city struct unit struct tile * target_tile
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 struct unit * punit
Definition dialogs_g.h:73
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit int const struct action *paction struct unit struct city * pcity
Definition dialogs_g.h:77
struct unit struct city * target_city
Definition dialogs_g.h:55
struct unit struct city struct unit struct tile struct extra_type * target_extra
Definition dialogs_g.h:56
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:238
@ RPT_CERTAIN
Definition fc_types.h:516
@ RPT_POSSIBLE
Definition fc_types.h:515
int action_id
Definition fc_types.h:250
#define ACTRES_NONE
Definition fc_types.h:188
#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:62
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:683
#define FC_FREE(ptr)
Definition mem.h:41
#define fc_malloc(sz)
Definition mem.h:34
bool can_see_techs_of_target(const struct player *pow_player, const struct player *target_player)
enum fc_tristate mke_eval_reqs(const struct player *pov_player, const struct req_context *context, const struct req_context *other_context, const struct requirement_vector *reqs, const enum req_problem_type prob_type)
bool can_unit_exist_at_tile(const struct civ_map *nmap, const struct unit *punit, const struct tile *ptile)
Definition movement.c:350
bool is_native_tile(const struct unit_type *punittype, const struct tile *ptile)
Definition movement.c:362
int unit_move_rate(const struct unit *punit)
Definition movement.c:89
bool unit_could_load_at(const struct unit *punit, const struct tile *ptile)
Definition movement.c:962
bool can_unit_type_transport(const struct unit_type *transporter, const struct unit_class *transported)
Definition movement.c:919
bool can_attack_non_native(const struct unit_type *utype)
Definition movement.c:213
void oblig_hard_reqs_init(void)
Definition oblig_reqs.c:810
void oblig_hard_reqs_free(void)
Definition oblig_reqs.c:830
void hard_code_oblig_hard_reqs_ruleset(void)
Definition oblig_reqs.c:773
void hard_code_oblig_hard_reqs(void)
Definition oblig_reqs.c:253
struct obligatory_req_vector * oblig_hard_reqs_get(enum action_result res)
Definition oblig_reqs.c:855
struct obligatory_req_vector * oblig_hard_reqs_get_sub(enum action_sub_result res)
Definition oblig_reqs.c:866
#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:1082
bool can_player_see_unit(const struct player *pplayer, const struct unit *punit)
Definition player.c:1095
bool pplayers_at_war(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1376
bool player_can_see_city_externals(const struct player *pow_player, const struct city *target_city)
Definition player.c:1155
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1397
bool can_player_see_hypotetic_units_at(const struct player *pplayer, const struct tile *ptile)
Definition player.c:984
bool player_can_trust_tile_has_no_units(const struct player *pplayer, const struct tile *ptile)
Definition player.c:958
bool universal_never_there(const struct universal *source)
const struct req_context * req_context_empty(void)
const char * req_to_fstring(const struct requirement *req, struct astring *astr)
bool universal_fulfills_requirements(bool check_necessary, const struct requirement_vector *reqs, const struct universal *source)
struct req_vec_problem * req_vec_suggest_repair(const struct requirement_vector *vec, requirement_vector_number get_num, const void *parent_item)
struct req_vec_problem * req_vec_problem_new(int num_suggested_solutions, const char *descr,...)
bool are_reqs_active(const struct req_context *context, const struct req_context *other_context, const struct requirement_vector *reqs, const enum req_problem_type prob_type)
struct requirement * req_vec_first_contradiction_in_vec(const struct requirement *req, const struct requirement_vector *vec)
bool does_req_contradicts_reqs(const struct requirement *req, const struct requirement_vector *vec)
bool req_vec_is_impossible_to_fulfill(const struct requirement_vector *reqs)
struct req_vec_problem * req_vec_suggest_improvement(const struct requirement_vector *vec, requirement_vector_number get_num, const void *parent_item)
#define requirement_fulfilled_by_unit_type(_ut_, _rqs_)
signed char req_vec_num_in_item
req_vec_num_in_item a requirement vectors number in an item.
#define requirement_vector_iterate_end
#define requirement_fulfilled_by_government(_gov_, _rqs_)
#define requirement_vector_iterate(req_vec, preq)
struct research * research_get(const struct player *pplayer)
Definition research.c:130
enum tech_state research_invention_state(const struct research *presearch, Tech_type_id tech)
Definition research.c:622
bool research_invention_gettable(const struct research *presearch, const Tech_type_id tech, bool allow_holes)
Definition research.c:696
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
bool is_super_specialist(const struct specialist *sp)
Definition specialist.c:212
size_t size
Definition specvec.h:72
int max
Definition fc_types.h:937
int min
Definition fc_types.h:936
enum action_auto_perf_cause cause
Definition actions.h:327
action_id alternatives[MAX_NUM_ACTIONS]
Definition actions.h:335
action_id action
Definition actions.h:171
struct requirement_vector actor_reqs
Definition actions.h:172
struct requirement_vector target_reqs
Definition actions.h:173
bool unitwaittime_controlled
Definition actions.h:160
action_id id
Definition actions.h:111
bool actor_consuming_always
Definition actions.h:144
bool rare_pop_up
Definition actions.h:157
int max_distance
Definition actions.h:127
bool quiet
Definition actions.h:134
enum action_sub_target_kind sub_target_kind
Definition actions.h:119
enum moves_actor_kind moves_actor
Definition actions.h:164
struct action::@12::@13 is_unit
enum action_result result
Definition actions.h:114
char ui_name[MAX_LEN_NAME]
Definition actions.h:130
bv_action_sub_results sub_results
Definition actions.h:115
enum action_actor_kind actor_kind
Definition actions.h:117
enum act_tgt_compl target_complexity
Definition actions.h:122
bv_actions blocked_by
Definition actions.h:138
bool configured
Definition actions.h:112
union action::@12 actor
enum action_target_kind target_kind
Definition actions.h:118
int min_distance
Definition actions.h:127
Definition city.h:318
int id
Definition city.h:324
struct tile * tile
Definition city.h:320
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 veteran_system * veteran
Definition unittype.h:551
Definition unit.h:139
int moves_left
Definition unit.h:151
struct tile * tile
Definition unit.h:141
bool paradropped
Definition unit.h:176
const struct unit_type * utype
Definition unit.h:140
enum universals_n kind
Definition fc_types.h:595
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:100
#define advance_iterate(_p)
Definition tech.h:273
#define advance_iterate_end
Definition tech.h:274
bool tile_is_seen(const struct tile *target_tile, const struct player *pow_player)
Definition tile.c:408
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:2526
bool unit_can_do_action(const struct unit *punit, const action_id act_id)
Definition unit.c:402
bool unit_transported(const struct unit *pcargo)
Definition unit.c:2512
bool can_unit_unload(const struct unit *pcargo, const struct unit *ptrans)
Definition unit.c:793
bool unit_can_convert(const struct civ_map *nmap, const struct unit *punit)
Definition unit.c:2089
#define unit_tile(_pu)
Definition unit.h:408
#define unit_owner(_pu)
Definition unit.h:407
#define unit_home(_pu_)
Definition unit.h:405
#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:126
bool utype_may_act_move_frags(const struct unit_type *punit_type, const action_id act_id, const int move_fragments)
Definition unittype.c:1083
const struct veteran_level * utype_veteran_level(const struct unit_type *punittype, int level)
Definition unittype.c:2634
bool unit_has_type_flag(const struct unit *punit, enum unit_type_flag_id flag)
Definition unittype.c:215
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:1021
bool utype_can_do_action(const struct unit_type *putype, const action_id act_id)
Definition unittype.c:396
#define utype_class(_t_)
Definition unittype.h:756
#define L_LAST
Definition unittype.h:444
#define unit_type_iterate(_p)
Definition unittype.h:865
#define unit_type_iterate_end
Definition unittype.h:872
#define U_NOT_OBSOLETED
Definition unittype.h:535