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, FALSE,
788 MAK_STAYS, 0, 0, FALSE);
791 TRUE, FALSE,
792 MAK_STAYS, 0, 0, FALSE);
795 FALSE, TRUE,
797 /* Overwritten by the ruleset */
798 0, 1, FALSE);
801 FALSE, TRUE,
803 /* Overwritten by the ruleset */
804 0, 1, FALSE);
807 FALSE, TRUE,
809 /* Overwritten by the ruleset */
810 0, 1, FALSE);
813 FALSE, TRUE,
815 /* Overwritten by the ruleset */
816 0, 1, FALSE);
819 FALSE, TRUE,
820 /* Tries a forced move if the target unit's tile has
821 * no non-allied units and the occupychance dice roll
822 * tells it to move. */
824 1, 1, FALSE);
825
828
831
834
835 /* The structure even for these need to be created, for
836 * the action_id_rule_name() to work on iterations. */
837
838 /*
839 actions[ACTION_UNUSED_1]
840 = unit_action_new(ACTION_UNUSED_1, ACTRES_NONE,
841 FALSE, FALSE,
842 MAK_UNREPRESENTABLE,
843 0, 0, FALSE);
844 */
845}
846
847/**********************************************************************/
850void actions_init(void)
851{
852 int i, j;
853
854 for (i = 0; i < ACTRES_LAST; i++) {
856 }
857 for (i = 0; i < ACTIVITY_LAST; i++) {
859 }
860
861 /* Hard code the actions */
863
864 /* Initialize the action enabler list */
865 action_iterate_all(act) {
868
869 /* Initialize action obligatory hard requirements. */
871
872 /* Obligatory hard requirements are sorted by requirement in the source
873 * code. This makes it easy to read, modify and explain it. */
875
876 /* Initialize the action auto performers. */
877 for (i = 0; i < MAX_NUM_ACTION_AUTO_PERFORMERS; i++) {
878 /* Nothing here. Nothing after this point. */
880
881 /* The criteria to pick *this* auto performer for its cause. */
883
884 for (j = 0; j < MAX_NUM_ACTIONS; j++) {
885 /* Nothing here. Nothing after this point. */
887 }
888 }
889
890 /* The actions them self are now initialized. */
892}
893
894/**********************************************************************/
900{
901 /* Some obligatory hard requirements needs access to the rest of the
902 * ruleset. */
904}
905
906/**********************************************************************/
909void actions_free(void)
910{
911 int i;
912
913 /* Don't consider the actions to be initialized any longer. */
915
916 action_iterate_all(act) {
920
922
923 FC_FREE(actions[act]);
925
926 /* Free the obligatory hard action requirements. */
928
929 /* Free the action auto performers. */
930 for (i = 0; i < MAX_NUM_ACTION_AUTO_PERFORMERS; i++) {
932 }
933
935
936 for (i = 0; i < ACTRES_LAST; i++) {
938 actlist_by_result[i] = nullptr;
939 }
940 for (i = 0; i < ACTIVITY_LAST; i++) {
942 actlist_by_activity[i] = nullptr;
943 }
944}
945
946/**********************************************************************/
952{
953 if (!actions_initialized) {
954 /* The actions them self aren't initialized yet. */
955 return FALSE;
956 }
957
959 if (actions[act]->ui_name[0] == '\0') {
960 /* A noninternal action without a UI name exists means that
961 * the ruleset haven't loaded yet. The ruleset loading will assign
962 * a default name to any actions not named by the ruleset.
963 * The client will get this name from the server. */
964 return FALSE;
965 }
967
968 /* The actions should be ready for use. */
969 return TRUE;
970}
971
972/**********************************************************************/
975static struct action *action_new(action_id id,
978 const int min_distance,
979 const int max_distance,
981{
982 struct action *action;
983
984 action = fc_malloc(sizeof(*action));
985
986 action->id = id;
988
990
991 if (result != ACTRES_LAST) {
993
995
996 if (act != ACTIVITY_LAST) {
998 }
999 }
1000
1001 /* Not set here */
1003
1008
1009 /* ASTK_NONE implies ACT_TGT_COMPL_SIMPLE and
1010 * !ASTK_NONE implies !ACT_TGT_COMPL_SIMPLE */
1015 "%s contradicts itself regarding sub targets.",
1017
1018 /* The distance between the actor and itself is always 0. */
1020 || (min_distance == 0 && max_distance == 0));
1021
1024
1026
1027 /* Loaded from the ruleset. Until generalized actions are ready it has to
1028 * be defined separately from other action data. */
1029 action->ui_name[0] = '\0';
1030 action->quiet = FALSE;
1032
1033 return action;
1034}
1035
1036/**********************************************************************/
1039static struct action *
1041 enum action_result result,
1042 bool rare_pop_up,
1045 const int min_distance,
1046 const int max_distance,
1048{
1049 struct action *act = action_new(id, AAK_UNIT, result,
1052
1054
1056
1058
1059 return act;
1060}
1061
1062/**********************************************************************/
1066 enum action_result result)
1067{
1068 struct action *act = action_new(id, AAK_PLAYER, result,
1069 0, 0, FALSE);
1070
1071 return act;
1072}
1073
1074/**********************************************************************/
1078 enum action_result result)
1079{
1080 struct action *act = action_new(id, AAK_CITY, result,
1081 0, 0, FALSE);
1082
1083 return act;
1084}
1085
1086/**********************************************************************/
1089bool action_id_exists(const action_id act_id)
1090{
1091 /* Actions are still hard coded. */
1092 return gen_action_is_valid(act_id) && actions[act_id];
1093}
1094
1095/**********************************************************************/
1100struct action *action_by_rule_name(const char *name)
1101{
1102 /* Actions are still hard coded in the gen_action enum. */
1104
1105 if (!action_id_exists(act_id)) {
1106 /* Nothing to return. */
1107
1108 log_verbose("Asked for non existing action named %s", name);
1109
1110 return nullptr;
1111 }
1112
1113 return action_by_number(act_id);
1114}
1115
1116/**********************************************************************/
1120{
1121 fc_assert_ret_val_msg(paction, AAK_COUNT, "Action doesn't exist.");
1122
1123 return paction->actor_kind;
1124}
1125
1126/**********************************************************************/
1130 const struct action *paction)
1131{
1132 fc_assert_ret_val_msg(paction, ATK_COUNT, "Action doesn't exist.");
1133
1134 return paction->target_kind;
1135}
1136
1137/**********************************************************************/
1141 const struct action *paction)
1142{
1143 fc_assert_ret_val_msg(paction, ASTK_COUNT, "Action doesn't exist.");
1144
1145 return paction->sub_target_kind;
1146}
1147
1148/**********************************************************************/
1154{
1155 fc_assert_ret_val(paction != nullptr, FALSE);
1156
1157 return paction->target_complexity >= ACT_TGT_COMPL_FLEXIBLE;
1158}
1159
1160/**********************************************************************/
1167{
1168 fc_assert_ret_val(paction != nullptr, FALSE);
1169
1170 return paction->target_complexity >= ACT_TGT_COMPL_MANDATORY;
1171}
1172
1173/**********************************************************************/
1182{
1184 FALSE, "Action %d don't exist.", act_id);
1186
1187 return actions[act_id]->actor.is_unit.rare_pop_up;
1188}
1189
1190/**********************************************************************/
1195 const int distance)
1196{
1199}
1200
1201/**********************************************************************/
1206 const int distance)
1207{
1209
1210 return (distance >= action->min_distance
1211 && action_distance_inside_max(action, distance));
1212}
1213
1214/**********************************************************************/
1217bool action_would_be_blocked_by(const struct action *blocked,
1218 const struct action *blocker)
1219{
1220 fc_assert_ret_val(blocked, FALSE);
1221 fc_assert_ret_val(blocker, FALSE);
1222
1223 return BV_ISSET(blocked->blocked_by, action_number(blocker));
1224}
1225
1226/**********************************************************************/
1229int action_number(const struct action *action)
1230{
1231 return action->id;
1232}
1233
1234/**********************************************************************/
1237const char *action_rule_name(const struct action *action)
1238{
1239 /* Rule name is still hard coded. */
1240 return action_id_rule_name(action->id);
1241}
1242
1243/**********************************************************************/
1251const char *action_name_translation(const struct action *paction)
1252{
1253 /* Use action_id_name_translation() to format the UI name. */
1255}
1256
1257/**********************************************************************/
1261{
1262 fc_assert_msg(actions[act_id], "Action %d don't exist.", act_id);
1263
1264 return gen_action_name(act_id);
1265}
1266
1267/**********************************************************************/
1272{
1273 return action_prepare_ui_name(act_id, "", ACTPROB_NA, nullptr);
1274}
1275
1276/**********************************************************************/
1280 const char *mnemonic)
1281{
1282 return action_prepare_ui_name(act_id, mnemonic, ACTPROB_NA, nullptr);
1283}
1284
1285/**********************************************************************/
1292static const char *action_prob_to_text(const struct act_prob prob)
1293{
1294 static struct astring chance = ASTRING_INIT;
1295
1296 /* How to interpret action probabilities like prob is documented in
1297 * fc_types.h */
1298 if (action_prob_is_signal(prob)) {
1300 || action_prob_not_relevant(prob));
1301
1302 /* Unknown because of missing server support or should not exits. */
1303 return nullptr;
1304 }
1305
1306 if (prob.min == prob.max) {
1307 /* Only one probability in range. */
1308
1309 /* TRANS: the probability that an action will succeed. Given in
1310 * percentage. Resolution is 0.5%. */
1311 astr_set(&chance, _("%.1f%%"), (double)prob.max / ACTPROB_VAL_1_PCT);
1312 } else {
1313 /* TRANS: the interval (end points included) where the probability of
1314 * the action's success is. Given in percentage. Resolution is 0.5%. */
1315 astr_set(&chance, _("[%.1f%%, %.1f%%]"),
1316 (double)prob.min / ACTPROB_VAL_1_PCT,
1317 (double)prob.max / ACTPROB_VAL_1_PCT);
1318 }
1319
1320 return astr_str(&chance);
1321}
1322
1323/**********************************************************************/
1333const char *action_prepare_ui_name(action_id act_id, const char *mnemonic,
1334 const struct act_prob prob,
1335 const char *custom)
1336{
1337 struct astring chance = ASTRING_INIT;
1338
1339 /* Text representation of the probability. */
1340 const char *probtxt;
1341
1342 if (!actions_are_ready()) {
1343 /* Could be a client who haven't gotten the ruleset yet */
1344
1345 /* so there shouldn't be any action probability to show */
1347
1348 /* but the action should be valid */
1350 "Invalid action",
1351 "Invalid action %d", act_id);
1352
1353 /* and no custom text will be inserted */
1354 fc_assert(custom == nullptr || custom[0] == '\0');
1355
1356 /* Make the best of what is known */
1357 astr_set(&ui_name_str, _("%s%s (name may be wrong)"),
1358 mnemonic, action_id_rule_name(act_id));
1359
1360 /* Return the guess. */
1361 return astr_str(&ui_name_str);
1362 }
1363
1365
1366 /* Format the info part of the action's UI name. */
1367 if (probtxt != nullptr && custom != nullptr) {
1368 /* TRANS: action UI name's info part with custom info and probability.
1369 * Hint: you can move the paren handling from this string to the action
1370 * names if you need to add extra information (like a mnemonic letter
1371 * that doesn't appear in the action UI name) to it. In that case you
1372 * must do so for all strings with this comment and for every action
1373 * name. To avoid a `()` when no UI name info part is added you have
1374 * to add the extra information to every action name or remove the
1375 * surrounding parens. */
1376 astr_set(&chance, _(" (%s; %s)"), custom, probtxt);
1377 } else if (probtxt != nullptr) {
1378 /* TRANS: action UI name's info part with probability.
1379 * Hint: you can move the paren handling from this string to the action
1380 * names if you need to add extra information (like a mnemonic letter
1381 * that doesn't appear in the action UI name) to it. In that case you
1382 * must do so for all strings with this comment and for every action
1383 * name. To avoid a `()` when no UI name info part is added you have
1384 * to add the extra information to every action name or remove the
1385 * surrounding parens. */
1386 astr_set(&chance, _(" (%s)"), probtxt);
1387 } else if (custom != nullptr) {
1388 /* TRANS: action UI name's info part with custom info.
1389 * Hint: you can move the paren handling from this string to the action
1390 * names if you need to add extra information (like a mnemonic letter
1391 * that doesn't appear in the action UI name) to it. In that case you
1392 * must do so for all strings with this comment and for every action
1393 * name. To avoid a `()` when no UI name info part is added you have
1394 * to add the extra information to every action name or remove the
1395 * surrounding parens. */
1396 astr_set(&chance, _(" (%s)"), custom);
1397 } else {
1398 /* No info part to display. */
1400 }
1401
1402 fc_assert_msg(actions[act_id], "Action %d don't exist.", act_id);
1403
1404 /* Escape any instances of the mnemonic in the action's UI format string.
1405 * (Assumes any mnemonic can be escaped by doubling, and that they are
1406 * unlikely to appear in a format specifier. True for clients seen so
1407 * far: Gtk's _ and Qt's &) */
1408 {
1409 struct astring fmtstr = ASTRING_INIT;
1410 const char *ui_name = _(actions[act_id]->ui_name);
1411
1412 if (mnemonic[0] != '\0') {
1413 const char *hit;
1414
1415 fc_assert(!strchr(mnemonic, '%'));
1416 while ((hit = strstr(ui_name, mnemonic))) {
1417 astr_add(&fmtstr, "%.*s%s%s", (int)(hit - ui_name), ui_name,
1419 ui_name = hit + strlen(mnemonic);
1420 }
1421 }
1422 astr_add(&fmtstr, "%s", ui_name);
1423
1424 /* Use the modified format string */
1426 astr_str(&chance));
1427
1428 astr_free(&fmtstr);
1429 }
1430
1431 astr_free(&chance);
1432
1433 return astr_str(&ui_name_str);
1434}
1435
1436/**********************************************************************/
1444const char *action_prob_explain(const struct act_prob prob)
1445{
1446 static struct astring tool_tip = ASTRING_INIT;
1447
1448 if (action_prob_is_signal(prob)) {
1450
1451 /* Missing server support. No in game action will change this. */
1453 } else if (prob.min == prob.max) {
1454 /* TRANS: action probability of success. Given in percentage.
1455 * Resolution is 0.5%. */
1456 astr_set(&tool_tip, _("The probability of success is %.1f%%."),
1457 (double)prob.max / ACTPROB_VAL_1_PCT);
1458 } else {
1460 /* TRANS: action probability interval (min to max). Given in
1461 * percentage. Resolution is 0.5%. The string at the end is
1462 * shown when the interval is wide enough to not be caused by
1463 * rounding. It explains that the interval is imprecise because
1464 * the player doesn't have enough information. */
1465 _("The probability of success is %.1f%%, %.1f%% or somewhere"
1466 " in between.%s"),
1467 (double)prob.min / ACTPROB_VAL_1_PCT,
1468 (double)prob.max / ACTPROB_VAL_1_PCT,
1469 prob.max - prob.min > 1 ?
1470 /* TRANS: explanation used in the action probability tooltip
1471 * above. Preserve leading space. */
1472 _(" (This is the most precise interval I can calculate "
1473 "given the information our nation has access to.)") :
1474 "");
1475 }
1476
1477 return astr_str(&tool_tip);
1478}
1479
1480/**********************************************************************/
1485{
1487 "Action %s isn't performed by a unit",
1489
1490 return paction->id + L_LAST;
1491}
1492
1493/**********************************************************************/
1497{
1498 struct action_enabler *enabler;
1499
1500 enabler = fc_malloc(sizeof(*enabler));
1501 enabler->rulesave.ruledit_disabled = FALSE;
1502 enabler->rulesave.comment = nullptr;
1503 requirement_vector_init(&enabler->actor_reqs);
1504 requirement_vector_init(&enabler->target_reqs);
1505
1506 /* Make sure that action doesn't end up as a random value that happens to
1507 * be a valid action id. */
1508 enabler->action = ACTION_NONE;
1509
1510 return enabler;
1511}
1512
1513/**********************************************************************/
1517{
1518 if (enabler->rulesave.comment != nullptr) {
1519 free(enabler->rulesave.comment);
1520 }
1521
1522 requirement_vector_free(&enabler->actor_reqs);
1523 requirement_vector_free(&enabler->target_reqs);
1524
1525 free(enabler);
1526}
1527
1528/**********************************************************************/
1531struct action_enabler *
1533{
1535
1536 enabler->action = original->action;
1537
1538 requirement_vector_copy(&enabler->actor_reqs, &original->actor_reqs);
1539 requirement_vector_copy(&enabler->target_reqs, &original->target_reqs);
1540
1541 return enabler;
1542}
1543
1544/**********************************************************************/
1548{
1549 /* Sanity check: a non existing action enabler can't be added. */
1551 /* Sanity check: a non existing action doesn't have enablers. */
1553
1556 enabler);
1557}
1558
1559/**********************************************************************/
1565{
1566 /* Sanity check: a non existing action enabler can't be removed. */
1568 /* Sanity check: a non existing action doesn't have enablers. */
1570
1573 enabler);
1574}
1575
1576/**********************************************************************/
1579struct action_enabler_list *
1581{
1582 /* Sanity check: a non existing action doesn't have enablers. */
1584
1586}
1587
1588/**********************************************************************/
1599static struct req_vec_problem *
1601 const struct obligatory_req_vector *oblig)
1602{
1603 struct action *paction;
1604
1605 /* Sanity check: a non existing action enabler is missing but it doesn't
1606 * miss any obligatory hard requirements. */
1607 fc_assert_ret_val(enabler, nullptr);
1608
1609 /* Sanity check: a non existing action doesn't have any obligatory hard
1610 * requirements. */
1613
1614 /* No obligatory hard requirements. */
1615 fc_assert_ret_val(oblig, nullptr);
1616
1618 struct req_vec_problem *out;
1619 int i;
1620 bool fulfilled = FALSE;
1621
1622 /* Check each alternative. */
1623 for (i = 0; i < obreq->contras->alternatives; i++) {
1624 const struct requirement_vector *ae_vec;
1625
1626 /* Select action enabler requirement vector. */
1627 ae_vec = (obreq->contras->alternative[i].is_target
1628 ? &enabler->target_reqs
1629 : &enabler->actor_reqs);
1630
1631 if (does_req_contradicts_reqs(&obreq->contras->alternative[i].req,
1632 ae_vec)
1633 /* Consider the hard requirement fulfilled since a universal that
1634 * never is there always will be absent in this ruleset. */
1635 || (obreq->contras->alternative[i].req.present
1637 &obreq->contras->alternative[i].req.source))) {
1638 /* It is enough that one alternative accepts the enabler. */
1639 fulfilled = TRUE;
1640 break;
1641 }
1642
1643 /* Fall back to the next alternative */
1644 }
1645
1646 if (fulfilled) {
1647 /* This obligatory hard requirement isn't a problem. */
1648 continue;
1649 }
1650
1651 /* Missing hard obligatory requirement detected */
1652
1653 out = req_vec_problem_new(obreq->contras->alternatives,
1654 obreq->error_msg,
1656
1657 for (i = 0; i < obreq->contras->alternatives; i++) {
1658 const struct requirement_vector *ae_vec;
1659
1660 /* Select action enabler requirement vector. */
1661 ae_vec = (obreq->contras->alternative[i].is_target
1662 ? &enabler->target_reqs
1663 : &enabler->actor_reqs);
1664
1665 /* The suggested fix is to append a requirement that makes the enabler
1666 * contradict the missing hard obligatory requirement detector. */
1667 out->suggested_solutions[i].operation = RVCO_APPEND;
1668 out->suggested_solutions[i].vector_number
1670
1671 /* Change the requirement from what should conflict to what is
1672 * wanted. */
1673 out->suggested_solutions[i].req.present
1674 = !obreq->contras->alternative[i].req.present;
1675 out->suggested_solutions[i].req.source
1676 = obreq->contras->alternative[i].req.source;
1677 out->suggested_solutions[i].req.range
1678 = obreq->contras->alternative[i].req.range;
1679 out->suggested_solutions[i].req.survives
1680 = obreq->contras->alternative[i].req.survives;
1681 out->suggested_solutions[i].req.quiet
1682 = obreq->contras->alternative[i].req.quiet;
1683 }
1684
1685 /* Return the first problem found. The next problem will be detected
1686 * during the next call. */
1687 return out;
1689
1690 /* No obligatory req problems found. */
1691 return nullptr;
1692}
1693
1694/**********************************************************************/
1703struct req_vec_problem *
1705{
1706 struct action *paction;
1708 struct req_vec_problem *out;
1709
1710 /* Sanity check: a non existing action enabler is missing but it doesn't
1711 * miss any obligatory hard requirements. */
1712 fc_assert_ret_val(enabler, nullptr);
1713
1714 /* Sanity check: a non existing action doesn't have any obligatory hard
1715 * requirements. */
1718
1719 if (paction->result != ACTRES_NONE) {
1720 /* A hard coded action result may mean obligatory requirements. */
1722 if (out != nullptr) {
1723 return out;
1724 }
1725 }
1726
1730 if (!BV_ISSET(paction->sub_results, sub_res)) {
1731 /* Not relevant */
1732 continue;
1733 }
1734
1735 /* The action has this sub result. Check its hard requirements. */
1738 if (out != nullptr) {
1739 return out;
1740 }
1741 }
1742
1743 /* No obligatory req problems found. */
1744 return nullptr;
1745}
1746
1747/**********************************************************************/
1753static struct requirement *
1755{
1757 if (preq->source.kind == VUT_DIPLREL
1758 && preq->range == REQ_RANGE_LOCAL) {
1759 return preq;
1760 }
1762
1763 return nullptr;
1764}
1765
1766/**********************************************************************/
1772static struct req_vec_problem *
1774 const struct action_enabler *enabler)
1775{
1776 struct req_vec_problem *out;
1777 struct requirement *local_diplrel;
1778 struct requirement *claimed_req;
1782 struct astring astr;
1783
1785 /* Not tile targeted */
1786 return nullptr;
1787 }
1788
1790 if (local_diplrel == nullptr) {
1791 /* No local diplrel */
1792 return nullptr;
1793 }
1794
1795 /* Tile is unclaimed as a requirement. */
1797 tile_is_unclaimed.survives = FALSE;
1798 tile_is_unclaimed.source.kind = VUT_CITYTILE;
1799 tile_is_unclaimed.present = FALSE;
1800 tile_is_unclaimed.source.value.citytile = CITYT_CLAIMED;
1801
1803 &enabler->target_reqs);
1804
1805 if (claimed_req) {
1806 /* Already clear */
1807 return nullptr;
1808 }
1809
1810 /* Tile is claimed as a requirement. */
1812 tile_is_claimed.survives = FALSE;
1813 tile_is_claimed.source.kind = VUT_CITYTILE;
1814 tile_is_claimed.present = TRUE;
1815 tile_is_claimed.source.value.citytile = CITYT_CLAIMED;
1816
1818 1,
1819 /* TRANS: ruledit shows this when an enabler for a tile targeted
1820 * action requires that the actor has a diplomatic relationship to
1821 * the target but doesn't require that the target tile is claimed.
1822 * (DiplRel requirements to an unclaimed tile are never fulfilled
1823 * so this is implicit.) */
1824 N_("Requirement {%s} of action \"%s\" implies a claimed "
1825 "tile. No diplomatic relation to Nature."),
1827
1828 astr_free(&astr);
1829
1830 /* The solution is to add the requirement that the tile is claimed */
1831 out->suggested_solutions[0].req = tile_is_claimed;
1832 out->suggested_solutions[0].vector_number
1834 out->suggested_solutions[0].operation = RVCO_APPEND;
1835
1836 return out;
1837}
1838
1839/**********************************************************************/
1845static struct req_vec_problem *
1847{
1848 struct req_vec_problem *out;
1849 struct requirement *local_diplrel;
1850 struct requirement *unclaimed_req;
1853 struct astring astr1;
1854 struct astring astr2;
1855
1857 /* Not tile targeted */
1858 return nullptr;
1859 }
1860
1862 if (local_diplrel == nullptr) {
1863 /* No local diplrel */
1864 return nullptr;
1865 }
1866
1867 /* Tile is claimed as a requirement. */
1869 tile_is_claimed.survives = FALSE;
1870 tile_is_claimed.source.kind = VUT_CITYTILE;
1871 tile_is_claimed.present = TRUE;
1872 tile_is_claimed.source.value.citytile = CITYT_CLAIMED;
1873
1875 &enabler->target_reqs);
1876
1877 if (unclaimed_req == nullptr) {
1878 /* No unclaimed req */
1879 return nullptr;
1880 }
1881
1883 2,
1884 /* TRANS: ruledit shows this when an enabler for a tile targeted
1885 * action requires that the target tile is unclaimed and that the
1886 * actor has a diplomatic relationship to the target. (DiplRel
1887 * requirements to an unclaimed tile are never fulfilled.) */
1888 N_("In enabler for \"%s\": No diplomatic relation to Nature."
1889 " Requirements {%s} and {%s} contradict each other."),
1893
1894 astr_free(&astr1);
1895 astr_free(&astr2);
1896
1897 /* The first suggestion is to remove the diplrel */
1898 out->suggested_solutions[0].req = *local_diplrel;
1899 out->suggested_solutions[0].vector_number
1901 out->suggested_solutions[0].operation = RVCO_REMOVE;
1902
1903 /* The 2nd is to remove the requirement that the tile is unclaimed */
1904 out->suggested_solutions[1].req = *unclaimed_req;
1905 out->suggested_solutions[1].vector_number
1907 out->suggested_solutions[1].operation = RVCO_REMOVE;
1908
1909 return out;
1910}
1911
1912/**********************************************************************/
1917struct req_vec_problem *
1919{
1920 struct req_vec_problem *out;
1921
1923 if (out != nullptr) {
1924 return out;
1925 }
1926
1927 /* Look for errors in the requirement vectors. */
1928 out = req_vec_suggest_repair(&enabler->actor_reqs,
1930 enabler);
1931 if (out != nullptr) {
1932 return out;
1933 }
1934
1935 out = req_vec_suggest_repair(&enabler->target_reqs,
1937 enabler);
1938 if (out != nullptr) {
1939 return out;
1940 }
1941
1942 /* Enabler specific contradictions. */
1944 if (out != nullptr) {
1945 return out;
1946 }
1947
1948 /* Needed in action not enabled explanation finding. */
1950 if (out != nullptr) {
1951 return out;
1952 }
1953
1954 /* No problems found. */
1955 return nullptr;
1956}
1957
1958/**********************************************************************/
1965static struct req_vec_problem *
1967{
1968 struct req_vec_problem *out;
1969
1970 out = nullptr;
1971
1972 return out;
1973}
1974
1975/**********************************************************************/
1983struct req_vec_problem *
1985{
1986 struct action *paction;
1987 struct req_vec_problem *out;
1988
1990 if (out) {
1991 /* A bug, not just a potential improvement */
1992 return out;
1993 }
1994
1996
1997 /* Look for improvement suggestions to the requirement vectors. */
2000 enabler);
2001 if (out) {
2002 return out;
2003 }
2004 out = req_vec_suggest_improvement(&enabler->target_reqs,
2006 enabler);
2007 if (out) {
2008 return out;
2009 }
2010
2011 /* Detect unused action enablers. */
2013 bool has_user = FALSE;
2014
2018 &(enabler->actor_reqs))) {
2019 has_user = TRUE;
2020 break;
2021 }
2023
2024 if (!has_user) {
2025 /* TRANS: ruledit warns a user about an unused action enabler */
2026 out = req_vec_problem_new(0, N_("Action enabler for \"%s\" is never"
2027 " used by any unit."),
2029 }
2030 }
2031 if (out != nullptr) {
2032 return out;
2033 }
2034
2036
2037 return out;
2038}
2039
2040/**********************************************************************/
2049 const struct requirement_vector *vec)
2050{
2051 struct action_enabler *ae = (struct action_enabler *)enabler;
2052
2053 if (vec == &ae->actor_reqs) {
2054 return 0;
2055 } else if (vec == &ae->target_reqs) {
2056 return 1;
2057 } else {
2058 return -1;
2059 }
2060}
2061
2062/********************************************************************/
2070struct requirement_vector *
2072 req_vec_num_in_item number)
2073{
2074 struct action_enabler *ae = (struct action_enabler *)enabler;
2075
2076 fc_assert_ret_val(number >= 0, nullptr);
2077
2078 switch (number) {
2079 case 0:
2080 return &ae->actor_reqs;
2081 case 1:
2082 return &ae->target_reqs;
2083 default:
2084 return nullptr;
2085 }
2086}
2087
2088/*********************************************************************/
2096{
2097 switch (vec) {
2098 case 0:
2099 /* TRANS: requirement vector in an action enabler (ruledit) */
2100 return _("actor_reqs");
2101 case 1:
2102 /* TRANS: requirement vector in an action enabler (ruledit) */
2103 return _("target_reqs");
2104 default:
2105 return nullptr;
2106 }
2107}
2108
2109/**********************************************************************/
2114static const struct impr_type *
2116{
2117 /* Only used with city targets */
2119
2120 if (target_city->production.kind == VUT_IMPROVEMENT) {
2121 /* The local building is what the target city currently is building. */
2122 return target_city->production.value.building;
2123 } else {
2124 /* In the current semantic the local building is always the building
2125 * being built. */
2126 /* TODO: Consider making the local building the target building for
2127 * actions that allows specifying a building target. */
2128 return nullptr;
2129 }
2130}
2131
2132/**********************************************************************/
2137static const struct unit_type *
2139{
2140 /* Only used with city targets */
2142
2143 if (target_city->production.kind == VUT_UTYPE) {
2144 /* The local unit type is what the target city currently is
2145 * building. */
2146 return target_city->production.value.utype;
2147 } else {
2148 /* In the current semantic the local utype is always the type of the
2149 * unit being built. */
2150 return nullptr;
2151 }
2152}
2153
2154/**********************************************************************/
2162static const struct tile *
2164 const struct unit *actor_unit,
2165 const struct tile *target_tile_arg,
2166 const struct city *target_city,
2167 const struct unit *target_unit)
2168{
2169 if (target_tile_arg != nullptr) {
2170 /* Trust the caller. */
2171 return target_tile_arg;
2172 }
2173
2174 /* Action should always be set */
2175 fc_assert_ret_val(act, nullptr);
2176
2177 switch (action_get_target_kind(act)) {
2178 case ATK_CITY:
2180 return city_tile(target_city);
2181 case ATK_UNIT:
2182 if (target_unit == nullptr) {
2183 fc_assert(target_unit != nullptr);
2184 return nullptr;
2185 }
2186 return unit_tile(target_unit);
2187 case ATK_STACK:
2189 if (target_unit) {
2190 return unit_tile(target_unit);
2191 }
2192
2194 case ATK_TILE:
2195 case ATK_EXTRAS:
2197 return target_tile_arg;
2198 case ATK_SELF:
2199 if (actor_unit != nullptr) {
2200 return unit_tile(actor_unit);
2201 }
2202 return nullptr;
2203 case ATK_COUNT:
2204 /* Handled below. */
2205 break;
2206 }
2207
2208 fc_assert_msg(FALSE, "Bad action target kind %d for action %s",
2210 return nullptr;
2211}
2212
2213/**********************************************************************/
2222static const struct city *
2224 const struct unit *actor_unit,
2225 const struct tile *target_tile,
2226 const struct city *target_city_arg,
2227 const struct unit *target_unit)
2228{
2229 if (target_city_arg != nullptr) {
2230 /* Trust the caller. */
2231 return target_city_arg;
2232 }
2233
2234 /* action should always be set */
2235 fc_assert_ret_val(act, nullptr);
2236
2237 switch (action_get_target_kind(act)) {
2238 case ATK_CITY:
2240 return target_city_arg;
2241 case ATK_UNIT:
2245 case ATK_STACK:
2247 if (target_unit) {
2250 }
2251
2253 case ATK_TILE:
2254 case ATK_EXTRAS:
2256 return tile_city(target_tile);
2257 case ATK_SELF:
2258 if (actor_unit != nullptr) {
2259 struct tile *ptile = unit_tile(actor_unit);
2260
2261 if (ptile != nullptr) {
2262 return tile_city(ptile);
2263 }
2264 }
2265 return nullptr;
2266 case ATK_COUNT:
2267 /* Handled below. */
2268 break;
2269 }
2270
2271 fc_assert_msg(FALSE, "Bad action target kind %d for action %s",
2273 return nullptr;
2274}
2275
2276/**********************************************************************/
2283 const struct action *act,
2284 const struct unit *actor_unit,
2285 const struct tile *target_tile_arg,
2286 const struct city *target_city_arg,
2287 const struct unit *target_unit)
2288{
2289 const struct tile *target_tile
2292 const struct city *target_city
2295
2297 struct action *blocker = action_by_number(blocker_id);
2298
2299 if (action_get_actor_kind(blocker) != AAK_UNIT) {
2300 /* Currently, only unit's actions may block each other */
2301 continue;
2302 }
2303
2304 if (!action_would_be_blocked_by(act, blocker)) {
2305 /* It doesn't matter if it is legal. It won't block the action. */
2306 continue;
2307 }
2308
2309 switch (action_get_target_kind(blocker)) {
2310 case ATK_CITY:
2311 if (!target_city) {
2312 /* Can't be enabled. No target. */
2313 continue;
2314 }
2317 return blocker;
2318 }
2319 break;
2320 case ATK_UNIT:
2321 if (!target_unit) {
2322 /* Can't be enabled. No target. */
2323 continue;
2324 }
2327 return blocker;
2328 }
2329 break;
2330 case ATK_STACK:
2331 if (!target_tile) {
2332 /* Can't be enabled. No target. */
2333 continue;
2334 }
2337 return blocker;
2338 }
2339 break;
2340 case ATK_TILE:
2341 if (!target_tile) {
2342 /* Can't be enabled. No target. */
2343 continue;
2344 }
2346 actor_unit, target_tile, nullptr)) {
2347 return blocker;
2348 }
2349 break;
2350 case ATK_EXTRAS:
2351 if (!target_tile) {
2352 /* Can't be enabled. No target. */
2353 continue;
2354 }
2356 actor_unit, target_tile, nullptr)) {
2357 return blocker;
2358 }
2359 break;
2360 case ATK_SELF:
2362 return blocker;
2363 }
2364 break;
2365 case ATK_COUNT:
2367 continue);
2368 break;
2369 }
2371
2372 /* Not blocked. */
2373 return nullptr;
2374}
2375
2376/**********************************************************************/
2396static bool
2398 const struct unit_type *actor_unittype,
2399 bool ignore_third_party)
2400{
2401 switch (paction->result) {
2402 case ACTRES_JOIN_CITY:
2403 if (actor_unittype->pop_cost <= 0 && !is_super_specialist(actor_unittype->spec_type)) {
2404 /* Reason: Must have something to add. */
2405 return FALSE;
2406 }
2407 break;
2408
2409 case ACTRES_BOMBARD:
2410 if (actor_unittype->bombard_rate <= 0) {
2411 /* Reason: Can't bombard if it never fires. */
2412 return FALSE;
2413 }
2414
2415 if (actor_unittype->attack_strength <= 0) {
2416 /* Reason: Can't bombard without attack strength. */
2417 return FALSE;
2418 }
2419
2420 break;
2421
2423 if (actor_unittype->obsoleted_by == U_NOT_OBSOLETED) {
2424 /* Reason: Nothing to upgrade to. */
2425 return FALSE;
2426 }
2427 break;
2428
2429 case ACTRES_ATTACK:
2430 case ACTRES_WIPE_UNITS:
2432 if (actor_unittype->attack_strength <= 0) {
2433 /* Reason: Can't attack without strength. */
2434 return FALSE;
2435 }
2436 break;
2437
2438 case ACTRES_CONVERT:
2439 if (!actor_unittype->converted_to) {
2440 /* Reason: must be able to convert to something. */
2441 return FALSE;
2442 }
2443 break;
2444
2446 if (actor_unittype->transport_capacity < 1) {
2447 /* Reason: can't transport anything to unload. */
2448 return FALSE;
2449 }
2450 break;
2451
2453 if (actor_unittype->transport_capacity < 1) {
2454 /* Reason: can't transport anything to load. */
2455 return FALSE;
2456 }
2457 break;
2458
2463 if (!ignore_third_party) {
2464 bool has_transporter = FALSE;
2465
2469 break;
2470 }
2472
2473 if (!has_transporter) {
2474 /* Reason: no other unit can transport this unit. */
2475 return FALSE;
2476 }
2477 }
2478 break;
2479
2481 if (!ignore_third_party) {
2482 bool has_target = FALSE;
2484
2485 /* Use cache when it has been initialized */
2486 if (pclass->cache.native_bases != nullptr) {
2487 /* Extra being native one is a hard requirement */
2488 extra_type_list_iterate(pclass->cache.native_bases, pextra) {
2489 if (!territory_claiming_base(pextra->data.base)) {
2490 /* Hard requirement */
2491 continue;
2492 }
2493
2494 has_target = TRUE;
2495 break;
2497 } else {
2499
2501 if (!is_native_extra_to_uclass(pextra, pclass)) {
2502 /* Hard requirement */
2503 continue;
2504 }
2505
2506 has_target = TRUE;
2507 break;
2509 }
2510
2511 if (!has_target) {
2512 /* Reason: no extras can be conquered by this unit. */
2513 return FALSE;
2514 }
2515 }
2516 break;
2517
2518 case ACTRES_PARADROP:
2520 if (actor_unittype->paratroopers_range <= 0) {
2521 /* Reason: Can't paradrop 0 tiles. */
2522 return FALSE;
2523 }
2524 break;
2525
2526 case ACTRES_HUT_ENTER:
2530 case ACTRES_SPY_POISON:
2539 case ACTRES_SPY_ESCAPE:
2540 case ACTRES_TRADE_ROUTE:
2541 case ACTRES_MARKETPLACE:
2542 case ACTRES_HELP_WONDER:
2547 case ACTRES_FOUND_CITY:
2548 case ACTRES_STEAL_MAPS:
2549 case ACTRES_SPY_NUKE:
2550 case ACTRES_NUKE:
2551 case ACTRES_NUKE_UNITS:
2553 case ACTRES_EXPEL_UNIT:
2556 case ACTRES_HOME_CITY:
2557 case ACTRES_HOMELESS:
2558 case ACTRES_AIRLIFT:
2562 case ACTRES_HEAL_UNIT:
2563 case ACTRES_PILLAGE:
2564 case ACTRES_CLEAN:
2565 case ACTRES_FORTIFY:
2567 case ACTRES_CULTIVATE:
2568 case ACTRES_PLANT:
2569 case ACTRES_ROAD:
2570 case ACTRES_BASE:
2571 case ACTRES_MINE:
2572 case ACTRES_IRRIGATE:
2573 case ACTRES_SPY_ATTACK:
2574 case ACTRES_UNIT_MOVE:
2575 case ACTRES_TELEPORT:
2577 case ACTRES_SCOUT:
2579 case ACTRES_NONE:
2580 /* No hard unit type requirements. */
2581 break;
2582
2584 }
2585
2586 return TRUE;
2587}
2588
2589/**********************************************************************/
2605bool
2612
2613/**********************************************************************/
2625static enum fc_tristate
2627 const struct action *paction,
2628 const struct req_context *actor,
2629 const bool omniscient,
2630 const struct city *homecity)
2631{
2632 enum action_result result = paction->result;
2633
2634 if (actor == nullptr) {
2636 }
2637
2639 TRUE)) {
2640 /* Info leak: The actor player knows the type of their unit. */
2641 /* The actor unit type can't perform the action because of hard
2642 * unit type requirements. */
2643 return TRI_NO;
2644 }
2645
2646 switch (result) {
2647 case ACTRES_PARADROP:
2649 /* Reason: Keep the old rules. */
2650 /* Info leak: The player knows if their unit already has paradropped this
2651 * turn. */
2652 if (actor->unit->paradropped) {
2653 return TRI_NO;
2654 }
2655
2656 break;
2657
2658 case ACTRES_AIRLIFT:
2659 {
2660 /* Obligatory hard requirement. Checked here too since
2661 * action_hard_reqs_actor() may be called before any
2662 * action enablers are checked. */
2663 if (actor->city == nullptr) {
2664 /* No city to airlift from. */
2665 return TRI_NO;
2666 }
2667
2668 if (actor->player != city_owner(actor->city)
2670 && pplayers_allied(actor->player,
2671 city_owner(actor->city)))) {
2672 /* Not allowed to airlift from this source. */
2673 return TRI_NO;
2674 }
2675
2676 if (!(omniscient || city_owner(actor->city) == actor->player)) {
2677 /* Can't check for airlifting capacity. */
2678 return TRI_MAYBE;
2679 }
2680
2681 if (0 >= actor->city->airlift
2684 /* The source cannot airlift for this turn (maybe already airlifted
2685 * or no airport).
2686 *
2687 * See also do_airline() in server/unittools.h. */
2688 return TRI_NO;
2689 }
2690 }
2691 break;
2692
2693 case ACTRES_CONVERT:
2694 /* Reason: Keep the old rules. */
2695 /* Info leak: The player knows their unit's cargo and location. */
2696 if (!unit_can_convert(nmap, actor->unit)) {
2697 return TRI_NO;
2698 }
2699 break;
2700
2703 if (unit_transported(actor->unit)) {
2704 if (!can_unit_unload(actor->unit, unit_transport_get(actor->unit))) {
2705 /* Can't leave current transport. */
2706 return TRI_NO;
2707 }
2708 }
2709 break;
2710
2712 if (!can_unit_unload(actor->unit, unit_transport_get(actor->unit))) {
2713 /* Keep the old rules about Unreachable and disembarks. */
2714 return TRI_NO;
2715 }
2716 break;
2717
2718 case ACTRES_HOMELESS:
2719 case ACTRES_UNIT_MOVE:
2720 case ACTRES_TELEPORT:
2724 case ACTRES_SPY_POISON:
2733 case ACTRES_SPY_ESCAPE:
2734 case ACTRES_TRADE_ROUTE:
2735 case ACTRES_MARKETPLACE:
2736 case ACTRES_HELP_WONDER:
2741 case ACTRES_FOUND_CITY:
2742 case ACTRES_JOIN_CITY:
2743 case ACTRES_STEAL_MAPS:
2744 case ACTRES_BOMBARD:
2745 case ACTRES_SPY_NUKE:
2746 case ACTRES_NUKE:
2747 case ACTRES_NUKE_UNITS:
2749 case ACTRES_EXPEL_UNIT:
2752 case ACTRES_HOME_CITY:
2754 case ACTRES_ATTACK:
2755 case ACTRES_WIPE_UNITS:
2761 case ACTRES_HEAL_UNIT:
2763 case ACTRES_CULTIVATE:
2764 case ACTRES_PLANT:
2765 case ACTRES_PILLAGE:
2766 case ACTRES_CLEAN:
2767 case ACTRES_FORTIFY:
2768 case ACTRES_ROAD:
2769 case ACTRES_BASE:
2770 case ACTRES_MINE:
2771 case ACTRES_IRRIGATE:
2775 case ACTRES_SPY_ATTACK:
2776 case ACTRES_HUT_ENTER:
2778 case ACTRES_SCOUT:
2780 case ACTRES_NONE:
2781 /* No hard unit requirements. */
2782 break;
2783
2785 }
2786
2787 return TRI_YES;
2788}
2789
2790/**********************************************************************/
2813static enum fc_tristate
2816 const struct req_context *actor,
2817 const struct req_context *target,
2818 const struct extra_type *target_extra,
2819 const bool omniscient,
2820 const struct city *homecity)
2821{
2822 enum fc_tristate out;
2825 const struct tile *atile = nullptr, *ttile = nullptr;
2826
2827 if (actor == nullptr) {
2829 } else {
2830 atile = actor->tile;
2831 }
2832 if (target == nullptr) {
2833 target = req_context_empty();
2834 } else {
2835 ttile = target->tile;
2836 }
2837
2838 fc_assert_msg((tkind == ATK_CITY && target->city != nullptr)
2839 || (tkind == ATK_TILE && ttile != nullptr)
2840 || (tkind == ATK_EXTRAS && ttile != nullptr)
2841 || (tkind == ATK_UNIT && target->unit != nullptr)
2842 /* At this level each individual unit is tested. */
2843 || (tkind == ATK_STACK && target->unit != nullptr)
2844 || (tkind == ATK_SELF),
2845 "Missing target!");
2846
2847 /* Info leak: The player knows where their unit/city is. */
2848 if (nullptr != atile && nullptr != ttile
2851 /* The distance between the actor and the target isn't inside the
2852 * action's accepted range. */
2853 return TRI_NO;
2854 }
2855
2856 switch (tkind) {
2857 case ATK_UNIT:
2858 /* The Freeciv code for all actions that is controlled by action
2859 * enablers and targets a unit assumes that the acting
2860 * player can see the target unit.
2861 * Examples:
2862 * - action_prob_vs_unit()'s quick check that the distance between actor
2863 * and target is acceptable would leak distance to target unit if the
2864 * target unit can't be seen.
2865 */
2866 if (!can_player_see_unit(actor->player, target->unit)) {
2867 return TRI_NO;
2868 }
2869 break;
2870 case ATK_CITY:
2871 /* The Freeciv code assumes that the player is aware of the target
2872 * city's existence. (How can you order an airlift to a city when you
2873 * don't know its city ID?) */
2875 actor->player)
2876 != target->city->id) {
2877 return TRI_NO;
2878 }
2879 break;
2880 case ATK_STACK:
2881 case ATK_TILE:
2882 case ATK_EXTRAS:
2883 case ATK_SELF:
2884 /* No special player knowledge checks. */
2885 break;
2886 case ATK_COUNT:
2888 break;
2889 }
2890
2892 ttile, target->city, target->unit)) {
2893 /* Allows an action to block an other action. If a blocking action is
2894 * legal the actions it blocks becomes illegal. */
2895 return TRI_NO;
2896 }
2897
2898 /* Actor specific hard requirements. */
2900
2901 if (out == TRI_NO) {
2902 /* Illegal because of a hard actor requirement. */
2903 return TRI_NO;
2904 }
2905
2906 /* Quick checks for action itself */
2907 if (paction->result == ACTRES_ATTACK
2908 || paction->result == ACTRES_WIPE_UNITS
2909 || paction->result == ACTRES_COLLECT_RANSOM) {
2910 /* Reason: Keep the old rules. */
2911 if (!can_unit_attack_tile(actor->unit, paction, ttile)) {
2912 return TRI_NO;
2913 }
2914 }
2915
2916 /* Hard requirements for results. */
2918 paction->result, actor,
2919 target, target_extra, out, omniscient,
2920 homecity);
2921
2922 if (out == TRI_NO) {
2923 /* Illegal because of a hard actor requirement. */
2924 return TRI_NO;
2925 }
2926
2927 if (paction->result == ACTRES_NUKE_UNITS) {
2929 != ATT_OK) {
2930 /* Unreachable. */
2931 return TRI_NO;
2932 }
2933 } else if (paction->result == ACTRES_PARADROP
2934 || paction->result == ACTRES_PARADROP_CONQUER) {
2935 if (can_player_see_tile(actor->player, ttile)) {
2936 /* Check for seen stuff that may kill the actor unit. */
2937
2938 /* Reason: Keep the old rules. Be merciful. */
2939 /* Info leak: The player sees the target tile. */
2941 && (!BV_ISSET(paction->sub_results, ACT_SUB_RES_MAY_EMBARK)
2942 || !unit_could_load_at(actor->unit, ttile))) {
2943 return TRI_NO;
2944 }
2945
2946 /* Reason: Keep the old rules. Be merciful. */
2947 /* Info leak: The player sees the target tile. */
2948 if (is_non_attack_city_tile(ttile, actor->player)) {
2949 return TRI_NO;
2950 }
2951
2952 /* Reason: Be merciful. */
2953 /* Info leak: The player sees all units checked. Invisible units are
2954 * ignored. */
2955 unit_list_iterate(ttile->units, pother) {
2956 if (can_player_see_unit(actor->player, pother)
2957 && !pplayers_allied(actor->player, unit_owner(pother))) {
2958 return TRI_NO;
2959 }
2961 }
2962 }
2963
2964 return out;
2965}
2966
2967/**********************************************************************/
2973static bool is_enabler_active(const struct action_enabler *enabler,
2974 const struct req_context *actor,
2975 const struct req_context *target)
2976{
2977 return are_reqs_active(actor, target, &enabler->actor_reqs, RPT_CERTAIN)
2978 && are_reqs_active(target, actor, &enabler->target_reqs, RPT_CERTAIN);
2979}
2980
2981/**********************************************************************/
2990static bool is_action_enabled(const struct civ_map *nmap,
2992 const struct req_context *actor,
2993 const struct req_context *target,
2994 const struct extra_type *target_extra,
2995 const struct city *actor_home)
2996{
2997 enum fc_tristate possible;
2998
3000 TRUE, actor_home);
3001
3002 if (possible != TRI_YES) {
3003 /* This context is omniscient. Should be yes or no. */
3005 "Is omniscient, should get yes or no.");
3006
3007 /* The action enablers are irrelevant since the action it self is
3008 * impossible. */
3009 return FALSE;
3010 }
3011
3012 return action_enablers_allow(wanted_action, actor, target);
3013}
3014
3015/**********************************************************************/
3020 const struct req_context *actor,
3021 const struct req_context *target)
3022{
3024 enabler) {
3025 if (is_enabler_active(enabler, actor, target)) {
3026 return TRUE;
3027 }
3029
3030 return FALSE;
3031}
3032
3033/**********************************************************************/
3039static bool
3042 const struct unit *actor_unit,
3043 const struct city *actor_home,
3044 const struct tile *actor_tile,
3045 const struct city *target_city)
3046{
3047 const struct impr_type *target_building;
3048 const struct unit_type *target_utype;
3049
3050 if (actor_unit == nullptr || target_city == nullptr) {
3051 /* Can't do an action when actor or target are missing. */
3052 return FALSE;
3053 }
3054
3056 FALSE, "Action %s is performed by %s not %s",
3061
3064 FALSE, "Action %s is against %s not %s",
3069
3071
3073 /* No point in continuing. */
3074 return FALSE;
3075 }
3076
3079
3081 &(const struct req_context) {
3082 .player = unit_owner(actor_unit),
3083 .city = tile_city(actor_tile),
3084 .tile = actor_tile,
3085 .unit = actor_unit,
3086 .unittype = unit_type_get(actor_unit),
3087 },
3088 &(const struct req_context) {
3089 .player = city_owner(target_city),
3090 .city = target_city,
3091 .building = target_building,
3093 .unittype = target_utype,
3094 },
3095 nullptr,
3096 actor_home);
3097}
3098
3099/**********************************************************************/
3115
3116/**********************************************************************/
3122static bool
3125 const struct unit *actor_unit,
3126 const struct city *actor_home,
3127 const struct tile *actor_tile,
3128 const struct unit *target_unit)
3129{
3130 if (actor_unit == nullptr || target_unit == nullptr) {
3131 /* Can't do an action when actor or target are missing. */
3132 return FALSE;
3133 }
3134
3136 FALSE, "Action %s is performed by %s not %s",
3141
3144 FALSE, "Action %s is against %s not %s",
3149
3151
3153 /* No point in continuing. */
3154 return FALSE;
3155 }
3156
3158 &(const struct req_context) {
3159 .player = unit_owner(actor_unit),
3160 .city = tile_city(actor_tile),
3161 .tile = actor_tile,
3162 .unit = actor_unit,
3163 .unittype = unit_type_get(actor_unit),
3164 },
3165 &(const struct req_context) {
3166 .player = unit_owner(target_unit),
3169 .unit = target_unit,
3170 .unittype = unit_type_get(target_unit),
3171 },
3172 nullptr,
3173 actor_home);
3174}
3175
3176/**********************************************************************/
3192
3193/**********************************************************************/
3199static bool
3202 const struct unit *actor_unit,
3203 const struct city *actor_home,
3204 const struct tile *actor_tile,
3205 const struct tile *target_tile)
3206{
3207 const struct req_context *actor_ctxt;
3208
3209 if (actor_unit == nullptr || target_tile == nullptr
3210 || unit_list_size(target_tile->units) == 0) {
3211 /* Can't do an action when actor or target are missing. */
3212 return FALSE;
3213 }
3214
3216 FALSE, "Action %s is performed by %s not %s",
3221
3224 FALSE, "Action %s is against %s not %s",
3229
3231
3233 /* No point in continuing. */
3234 return FALSE;
3235 }
3236
3237 actor_ctxt = &(const struct req_context) {
3238 .player = unit_owner(actor_unit),
3239 .city = tile_city(actor_tile),
3240 .tile = actor_tile,
3241 .unit = actor_unit,
3242 .unittype = unit_type_get(actor_unit),
3243 };
3244
3247 &(const struct req_context) {
3248 .player = unit_owner(target_unit),
3251 .unit = target_unit,
3252 .unittype = unit_type_get(target_unit),
3253 },
3254 nullptr, actor_home)) {
3255 /* One unit makes it impossible for all units. */
3256 return FALSE;
3257 }
3259
3260 /* Not impossible for any of the units at the tile. */
3261 return TRUE;
3262}
3263
3264/**********************************************************************/
3280
3281/**********************************************************************/
3287static bool
3290 const struct unit *actor_unit,
3291 const struct city *actor_home,
3292 const struct tile *actor_tile,
3293 const struct tile *target_tile,
3294 const struct extra_type *target_extra)
3295{
3296 if (actor_unit == nullptr || target_tile == nullptr) {
3297 /* Can't do an action when actor or target are missing. */
3298 return FALSE;
3299 }
3300
3302 FALSE, "Action %s is performed by %s not %s",
3307
3310 FALSE, "Action %s is against %s not %s",
3315
3317
3319 /* No point in continuing. */
3320 return FALSE;
3321 }
3322
3324 &(const struct req_context) {
3325 .player = unit_owner(actor_unit),
3326 .city = tile_city(actor_tile),
3327 .tile = actor_tile,
3328 .unit = actor_unit,
3329 .unittype = unit_type_get(actor_unit),
3330 },
3331 &(const struct req_context) {
3332 .player = tile_owner(target_tile),
3333 .city = tile_city(target_tile),
3334 .tile = target_tile,
3335 },
3337 actor_home);
3338}
3339
3340/**********************************************************************/
3348 const struct unit *actor_unit,
3349 const struct tile *target_tile,
3350 const struct extra_type *target_extra)
3351{
3356}
3357
3358/**********************************************************************/
3364static bool
3367 const struct unit *actor_unit,
3368 const struct city *actor_home,
3369 const struct tile *actor_tile,
3370 const struct tile *target_tile,
3371 const struct extra_type *target_extra)
3372{
3373 if (actor_unit == nullptr || target_tile == nullptr) {
3374 /* Can't do an action when actor or target are missing. */
3375 return FALSE;
3376 }
3377
3379 FALSE, "Action %s is performed by %s not %s",
3384
3387 FALSE, "Action %s is against %s not %s",
3392
3394
3396 /* No point in continuing. */
3397 return FALSE;
3398 }
3399
3401 &(const struct req_context) {
3402 .player = unit_owner(actor_unit),
3403 .city = tile_city(actor_tile),
3404 .tile = actor_tile,
3405 .unit = actor_unit,
3406 .unittype = unit_type_get(actor_unit),
3407 },
3408 &(const struct req_context) {
3409 .player = target_tile->extras_owner,
3410 .city = tile_city(target_tile),
3411 .tile = target_tile,
3412 },
3414 actor_home);
3415}
3416
3417/**********************************************************************/
3434
3435/**********************************************************************/
3442static bool
3445 const struct unit *actor_unit,
3446 const struct city *actor_home,
3447 const struct tile *actor_tile)
3448{
3449 if (actor_unit == nullptr) {
3450 /* Can't do an action when the actor is missing. */
3451 return FALSE;
3452 }
3453
3455 FALSE, "Action %s is performed by %s not %s",
3460
3463 FALSE, "Action %s is against %s not %s",
3468
3470
3472 /* No point in continuing. */
3473 return FALSE;
3474 }
3475
3477 &(const struct req_context) {
3478 .player = unit_owner(actor_unit),
3479 .city = tile_city(actor_tile),
3480 .tile = actor_tile,
3481 .unit = actor_unit,
3482 .unittype = unit_type_get(actor_unit),
3483 },
3484 nullptr, nullptr,
3485 actor_home);
3486}
3487
3488/**********************************************************************/
3503
3504#define ASSERT_PLAYER_ACTION(_atk) \
3505 fc_assert_ret_val_msg(AAK_PLAYER == action_id_get_actor_kind(wanted_action),\
3506 FALSE, "Action %s is performed by %s not %s", \
3507 action_id_rule_name(wanted_action), \
3508 action_actor_kind_name( \
3509 action_id_get_actor_kind(wanted_action)), \
3510 action_actor_kind_name(AAK_PLAYER)); \
3511 fc_assert_ret_val_msg(_atk \
3512 == action_id_get_target_kind(wanted_action), \
3513 FALSE, "Action %s is against %s not %s", \
3514 action_id_rule_name(wanted_action), \
3515 action_target_kind_name( \
3516 action_id_get_target_kind(wanted_action)), \
3517 action_target_kind_name(_atk));
3518
3519/**********************************************************************/
3525 const struct player *actor_plr)
3526{
3527 if (actor_plr == nullptr) {
3528 /* Can't do an action when the actor is missing. */
3529 return FALSE;
3530 }
3531
3533
3535 &(const struct req_context) {
3536 .player = actor_plr,
3537 },
3538 nullptr, nullptr, nullptr);
3539}
3540
3541/**********************************************************************/
3547 const struct player *actor_plr,
3548 const struct city *target_city)
3549{
3550 const struct impr_type *target_building;
3551 const struct unit_type *target_utype;
3552
3553 if (actor_plr == nullptr || target_city == nullptr) {
3554 /* Can't do an action when the actor or the target is missing. */
3555 return FALSE;
3556 }
3557
3559
3562
3564 &(const struct req_context) {
3565 .player = actor_plr,
3566 },
3567 &(const struct req_context) {
3568 .player = city_owner(target_city),
3569 .city = target_city,
3570 .building = target_building,
3572 .unittype = target_utype,
3573 }, nullptr, nullptr);
3574}
3575
3576/**********************************************************************/
3582bool
3585 const struct player *actor_plr,
3586 const struct tile *target_tile,
3587 const struct extra_type *target_extra)
3588{
3589 if (actor_plr == nullptr || target_tile == nullptr) {
3590 /* Can't do an action when actor or target are missing. */
3591 return FALSE;
3592 }
3593
3595
3597 &(const struct req_context) {
3598 .player = actor_plr,
3599 },
3600 &(const struct req_context) {
3601 .player = target_tile->extras_owner,
3602 .city = tile_city(target_tile),
3603 .tile = target_tile,
3604 },
3605 target_extra, nullptr);
3606}
3607
3608/**********************************************************************/
3616 const struct player *actor_plr,
3617 const struct tile *target_tile,
3618 const struct extra_type *target_extra)
3619{
3620 const struct req_context actor_ctxt = {
3621 .player = actor_plr,
3622 };
3623 const struct city *tcity;
3624
3625 if (actor_plr == nullptr || target_tile == nullptr
3626 || unit_list_size(target_tile->units) == 0) {
3627 /* Can't do an action when actor or target are missing. */
3628 return FALSE;
3629 }
3630
3632
3636 &(const struct req_context) {
3637 .player = unit_owner(target_unit),
3638 .city = tcity,
3639 .tile = target_tile,
3640 .unit = target_unit,
3641 .unittype = unit_type_get(target_unit),
3642 },
3643 nullptr, nullptr)) {
3644 /* One unit makes it impossible for all units. */
3645 return FALSE;
3646 }
3648
3649 /* Not impossible for any of the units at the tile. */
3650 return TRUE;
3651}
3652
3653/**********************************************************************/
3661 const struct player *actor_plr,
3662 const struct tile *target_tile,
3663 const struct extra_type *target_extra)
3664{
3665 if (actor_plr == nullptr || target_tile == nullptr) {
3666 /* Can't do an action when actor or target are missing. */
3667 return FALSE;
3668 }
3669
3671
3673 &(const struct req_context) {
3674 .player = actor_plr,
3675 },
3676 &(const struct req_context) {
3677 .player = tile_owner(target_tile),
3678 .city = tile_city(target_tile),
3679 .tile = target_tile,
3680 },
3681 target_extra, nullptr);
3682}
3683
3684/**********************************************************************/
3692 const struct player *actor_plr,
3693 const struct unit *target_unit)
3694{
3695 if (actor_plr == nullptr || target_unit == nullptr) {
3696 /* Can't do an action when actor or target are missing. */
3697 return FALSE;
3698 }
3699
3701
3703 &(const struct req_context) {
3704 .player = actor_plr,
3705 },
3706 &(const struct req_context) {
3707 .player = unit_owner(target_unit),
3710 .unit = target_unit,
3711 .unittype = unit_type_get(target_unit),
3712 },
3713 nullptr, nullptr);
3714}
3715
3716/**********************************************************************/
3722 const struct city *actor_city)
3723{
3725 &(const struct req_context) {
3726 .player = city_owner(actor_city),
3727 .city = actor_city,
3728 .tile = city_tile(actor_city)
3729 },
3730 nullptr, nullptr, nullptr);
3731}
3732
3733/**********************************************************************/
3751static enum fc_tristate
3753 const struct req_context *actor,
3754 const struct req_context *target)
3755{
3756 enum fc_tristate current;
3757 enum fc_tristate result;
3758
3759 if (actor == nullptr || actor->player == nullptr) {
3760 /* Need actor->player for point of view */
3761 return TRI_MAYBE;
3762 }
3763
3764 if (target == nullptr) {
3765 target = req_context_empty();
3766 }
3767
3768 result = TRI_NO;
3770 enabler) {
3771 current = fc_tristate_and(mke_eval_reqs(actor->player,
3772 actor, target,
3773 &enabler->actor_reqs,
3774 RPT_CERTAIN),
3775 mke_eval_reqs(actor->player,
3776 target, actor,
3777 &enabler->target_reqs,
3778 RPT_CERTAIN));
3779 if (current == TRI_YES) {
3780 return TRI_YES;
3781 } else if (current == TRI_MAYBE) {
3782 result = TRI_MAYBE;
3783 }
3785
3786 return result;
3787}
3788
3789/**********************************************************************/
3799static bool is_effect_val_known(enum effect_type effect_type,
3800 const struct player *pov_player,
3801 const struct req_context *context,
3802 const struct req_context *other_context)
3803{
3804 effect_list_iterate(get_effects(effect_type), peffect) {
3806 &(peffect->reqs), RPT_CERTAIN)) {
3807 return FALSE;
3808 }
3810
3811 return TRUE;
3812}
3813
3814/**********************************************************************/
3817static enum fc_tristate
3845
3846/**********************************************************************/
3855 const struct unit *pdefender)
3856{
3857 /* Keep unconverted until the end to avoid scaling each step */
3858 int chance;
3859 struct act_prob out;
3860
3861 /* Superspy always win */
3863 /* A defending UTYF_SUPERSPY will defeat every possible attacker. */
3864 return ACTPROB_IMPOSSIBLE;
3865 }
3867 /* An attacking UTYF_SUPERSPY will defeat every possible defender
3868 * except another UTYF_SUPERSPY. */
3869 return ACTPROB_CERTAIN;
3870 }
3871
3872 /* Base chance is 50% */
3873 chance = 50;
3874
3875 /* Spy attack bonus */
3877 chance += 25;
3878 }
3879
3880 /* Spy defense bonus */
3882 chance -= 25;
3883 }
3884
3885 /* Veteran attack and defense bonus */
3886 {
3887 const struct veteran_level *vatt
3889 const struct veteran_level *vdef
3891
3892 chance += vatt->power_fact - vdef->power_fact;
3893 }
3894
3895 /* Defense bonus. */
3896 {
3897 const struct req_context defender_ctxt = {
3898 .player = tile_owner(pdefender->tile),
3899 .city = tile_city(pdefender->tile),
3900 .tile = pdefender->tile,
3901 };
3904 nullptr)) {
3905 return ACTPROB_NOT_KNOWN;
3906 }
3907
3908 /* Reduce the chance of an attack by EFT_SPY_RESISTANT percent. */
3910 nullptr,
3912 nullptr,
3914 ) / 100;
3915 }
3916
3917 chance = CLIP(0, chance, 100);
3918
3919 /* Convert to action probability */
3922
3923 return out;
3924}
3925
3926/**********************************************************************/
3932 const struct unit *pvictim,
3933 const struct tile *tgt_tile,
3934 const struct action *paction)
3935{
3936 struct unit *pdefender;
3937
3939 tgt_tile)) {
3940 /* Don't leak information about unseen defenders. */
3941 return ACTPROB_NOT_KNOWN;
3942 }
3943
3945 paction);
3946
3947 if (pdefender) {
3948 /* There will be a diplomatic battle instead of an action. */
3950 };
3951
3952 /* No diplomatic battle will occur. */
3953 return ACTPROB_CERTAIN;
3954}
3955
3956/**********************************************************************/
3960 action_id act_id,
3961 const struct unit *actor_unit)
3962{
3964 /* Unknown because the target is unseen. */
3965 return ACTPROB_NOT_KNOWN;
3966 } else {
3967 /* The actor it self can't do this. */
3968 return ACTPROB_IMPOSSIBLE;
3969 }
3970}
3971
3972/**********************************************************************/
3976static struct act_prob
3978 const struct unit *act_unit,
3979 const struct city *tgt_city,
3980 const struct player *tgt_player,
3981 const struct action *paction)
3982{
3984 &(const struct req_context) {
3985 .player = act_player,
3986 .city = tgt_city,
3987 .unit = act_unit,
3988 .unittype = unit_type_get(act_unit),
3989 },
3990 &(const struct req_context) {
3991 .player = tgt_player,
3992 })
3994 &(const struct req_context) {
3995 .player = tgt_player,
3996 .city = tgt_city,
3997 .unit = act_unit,
3998 },
3999 &(const struct req_context) {
4000 .player = act_player,
4001 })) {
4004 struct act_prob result = { .min = unconverted * ACTPROB_VAL_1_PCT,
4005 .max = unconverted * ACTPROB_VAL_1_PCT };
4006
4007 return result;
4008 } else {
4009 /* Could be improved to return a more exact probability in some cases.
4010 * Example: The player has enough information to know that the
4011 * probability always will be above 25% and always under 75% because
4012 * the only effect with unknown requirements that may apply adds (or
4013 * subtracts) 50% while all the requirements of the other effects that
4014 * may apply are known. */
4015 return ACTPROB_NOT_KNOWN;
4016 }
4017}
4018
4019/**********************************************************************/
4024static struct act_prob
4026 const struct unit *act_unit,
4027 const struct city *tgt_city,
4028 const struct unit *tgt_unit,
4029 const struct tile *tgt_tile,
4030 const struct player *tgt_player,
4031 const struct action *paction)
4032{
4033 struct act_prob battle;
4034 struct act_prob dice_roll;
4035
4036 battle = ACTPROB_CERTAIN;
4037 switch (actres_get_battle_kind(paction->result)) {
4038 case ABK_NONE:
4039 /* No pre action battle. */
4040 break;
4041 case ABK_DIPLOMATIC:
4043 paction);
4044 break;
4045 case ABK_STANDARD:
4046 /* Not supported here yet. Implement when users appear. */
4048 break;
4049 case ABK_COUNT:
4051 break;
4052 }
4053
4056 paction);
4057
4058 return action_prob_and(&battle, &dice_roll);
4059}
4060
4061/**********************************************************************/
4072static struct act_prob
4075 const struct req_context *actor,
4076 const struct city *actor_home,
4077 const struct req_context *target,
4078 const struct extra_type *target_extra)
4079{
4080 enum fc_tristate known;
4081 struct act_prob chance;
4083
4084 if (actor == nullptr) {
4086 }
4087 if (target == nullptr) {
4088 target = req_context_empty();
4089 }
4090
4091 known = is_action_possible(nmap, wanted_action, actor, target,
4093 FALSE, actor_home);
4094
4095 if (known == TRI_NO) {
4096 /* The action enablers are irrelevant since the action it self is
4097 * impossible. */
4098 return ACTPROB_IMPOSSIBLE;
4099 }
4100
4102
4103 known = fc_tristate_and(known,
4105 actor, target));
4106
4107 switch (paction->result) {
4108 case ACTRES_SPY_POISON:
4109 /* All uncertainty comes from potential diplomatic battles and the
4110 * (diplchance server setting and the) Action_Odds_Pct effect controlled
4111 * dice roll before the action. */
4113 target->city, target->unit,
4114 target->tile, target->player,
4115 paction);
4116 break;
4118 /* TODO */
4119 break;
4121 /* TODO */
4122 break;
4123 case ACTRES_STEAL_MAPS:
4124 /* TODO */
4125 break;
4127 /* All uncertainty comes from potential diplomatic battles. */
4128 chance = ap_diplomat_battle(actor->unit, target->unit, target->tile,
4129 paction);
4130 break;
4133 /* All uncertainty comes from potential diplomatic battles. */
4134 chance = ap_diplomat_battle(actor->unit, target->unit, target->tile,
4135 paction);
4136 break;
4137 case ACTRES_SPY_ATTACK:
4138 /* All uncertainty comes from potential diplomatic battles. */
4139 chance = ap_diplomat_battle(actor->unit, nullptr, target->tile,
4140 paction);
4141 break;
4143 /* TODO */
4144 break;
4146 /* TODO */
4147 break;
4149 /* TODO */
4150 break;
4152 /* TODO */
4153 break;
4156 break;
4158 /* Do the victim have anything worth taking? */
4159 known = fc_tristate_and(known,
4160 tech_can_be_stolen(actor->player,
4161 target->player));
4162
4163 /* TODO: Calculate actual chance */
4164
4165 break;
4167 /* Do the victim have anything worth taking? */
4168 known = fc_tristate_and(known,
4169 tech_can_be_stolen(actor->player,
4170 target->player));
4171
4172 /* TODO: Calculate actual chance */
4173
4174 break;
4176 /* There is no risk that the city won't get investigated. */
4178 break;
4179 case ACTRES_SPY_ESCAPE:
4180 /* TODO */
4181 break;
4182 case ACTRES_TRADE_ROUTE:
4183 /* TODO */
4184 break;
4185 case ACTRES_MARKETPLACE:
4186 /* Possible when not blocked by is_action_possible() */
4188 break;
4189 case ACTRES_HELP_WONDER:
4190 /* Possible when not blocked by is_action_possible() */
4192 break;
4194 /* No battle is fought first. */
4196 break;
4197 case ACTRES_EXPEL_UNIT:
4198 /* No battle is fought first. */
4200 break;
4201 case ACTRES_BOMBARD:
4202 /* No battle is fought first. */
4204 break;
4205 case ACTRES_FOUND_CITY:
4206 /* Possible when not blocked by is_action_possible() */
4208 break;
4209 case ACTRES_JOIN_CITY:
4210 /* Possible when not blocked by is_action_possible() */
4212 break;
4213 case ACTRES_SPY_NUKE:
4214 /* All uncertainty comes from potential diplomatic battles and the
4215 * (diplchance server setting and the) Action_Odds_Pct effect controlled
4216 * dice roll before the action. */
4218 target->city, target->unit,
4219 target->tile,
4220 target->player,
4221 paction);
4222 break;
4223 case ACTRES_NUKE:
4224 /* TODO */
4225 break;
4226 case ACTRES_NUKE_UNITS:
4227 /* TODO */
4228 break;
4230 /* No battle is fought first. */
4232 break;
4234 /* No battle is fought first. */
4236 break;
4238 /* No battle is fought first. */
4240 break;
4241 case ACTRES_HOME_CITY:
4242 /* No battle is fought first. */
4244 break;
4245 case ACTRES_HOMELESS:
4246 /* No battle is fought first. */
4248 break;
4250 /* No battle is fought first. */
4252 break;
4253 case ACTRES_PARADROP:
4255 /* TODO */
4256 break;
4257 case ACTRES_AIRLIFT:
4258 /* Possible when not blocked by is_action_possible() */
4260 break;
4261 case ACTRES_ATTACK:
4263 {
4264 struct unit *defender_unit = get_defender(nmap, actor->unit,
4265 target->tile, paction);
4266
4267 if (can_player_see_unit(actor->player, defender_unit)) {
4268 double unconverted = unit_win_chance(nmap, actor->unit,
4270
4272 floor((double)ACTPROB_VAL_MAX * unconverted));
4274 ceil((double)ACTPROB_VAL_MAX * unconverted));
4275 } else if (known == TRI_YES) {
4276 known = TRI_MAYBE;
4277 }
4278 }
4279 break;
4280 case ACTRES_WIPE_UNITS:
4282 break;
4284 /* TODO: not implemented yet because:
4285 * - dice roll 100% * Action_Odds_Pct could be handled with
4286 * action_prob_pre_action_dice_roll().
4287 * - sub target building may be missing. May be missing without player
4288 * knowledge if it isn't visible. See is_improvement_visible() and
4289 * can_player_see_city_internals(). */
4290 break;
4292 /* All uncertainty comes from the (diplchance server setting and the)
4293 * Action_Odds_Pct effect controlled dice roll before the action. */
4295 target->city, target->player,
4296 paction);
4297 break;
4299 /* No battle is fought first. */
4301 break;
4303 /* No battle is fought first. */
4305 break;
4306 case ACTRES_HEAL_UNIT:
4307 /* No battle is fought first. */
4309 break;
4311 case ACTRES_CULTIVATE:
4312 case ACTRES_PLANT:
4313 case ACTRES_PILLAGE:
4314 case ACTRES_CLEAN:
4315 case ACTRES_FORTIFY:
4316 case ACTRES_ROAD:
4317 case ACTRES_CONVERT:
4318 case ACTRES_BASE:
4319 case ACTRES_MINE:
4320 case ACTRES_IRRIGATE:
4322 break;
4325 break;
4328 break;
4331 break;
4334 break;
4337 break;
4340 break;
4341 case ACTRES_HUT_ENTER:
4343 /* Entering the hut happens with a probability of 100%. What happens
4344 * next is probably up to dice rolls in Lua. */
4346 break;
4347 case ACTRES_UNIT_MOVE:
4348 case ACTRES_TELEPORT:
4351 break;
4352 case ACTRES_SCOUT:
4354 break;
4355 /* Not UI action, so chance is meaningless */
4358 break;
4359 case ACTRES_NONE:
4360 /* Accommodate ruleset authors that wishes to roll the dice in Lua.
4361 * Would be ACTPROB_CERTAIN if not for that. */
4362 /* TODO: maybe allow the ruleset author to give a probability from
4363 * Lua? */
4365 break;
4366 }
4367
4368 /* Non signal action probabilities should be in range. */
4370 || chance.max <= ACTPROB_VAL_MAX),
4371 chance.max = ACTPROB_VAL_MAX);
4373 || chance.min >= ACTPROB_VAL_MIN),
4374 chance.min = ACTPROB_VAL_MIN);
4375
4376 switch (known) {
4377 case TRI_NO:
4378 return ACTPROB_IMPOSSIBLE;
4379 break;
4380 case TRI_MAYBE:
4381 return ACTPROB_NOT_KNOWN;
4382 break;
4383 case TRI_YES:
4384 return chance;
4385 break;
4386 };
4387
4388 fc_assert_msg(FALSE, "Should be yes, maybe or no");
4389
4391}
4392
4393/**********************************************************************/
4397static struct act_prob
4399 const struct unit *actor_unit,
4400 const struct city *actor_home,
4401 const struct tile *actor_tile,
4402 const action_id act_id,
4403 const struct city *target_city)
4404{
4405 const struct impr_type *target_building;
4406 const struct unit_type *target_utype;
4407 const struct action *act = action_by_number(act_id);
4408
4409 if (actor_unit == nullptr || target_city == nullptr) {
4410 /* Can't do an action when actor or target are missing. */
4411 return ACTPROB_IMPOSSIBLE;
4412 }
4413
4416 "Action %s is performed by %s not %s",
4417 action_id_rule_name(act_id),
4419 action_id_get_actor_kind(act_id)),
4421
4424 "Action %s is against %s not %s",
4425 action_id_rule_name(act_id),
4429
4431
4432 if (!unit_can_do_action(actor_unit, act_id)) {
4433 /* No point in continuing. */
4434 return ACTPROB_IMPOSSIBLE;
4435 }
4436
4437 /* Doesn't leak information about city position since an unknown city
4438 * can't be targeted and a city can't move. */
4439 if (!action_id_distance_accepted(act_id,
4442 /* No point in continuing. */
4443 return ACTPROB_IMPOSSIBLE;
4444 }
4445
4446 /* Doesn't leak information since it must be 100% certain from the
4447 * player's perspective that the blocking action is legal. */
4449 city_tile(target_city), target_city, nullptr)) {
4450 /* Don't offer to perform an action known to be blocked. */
4451 return ACTPROB_IMPOSSIBLE;
4452 }
4453
4455 /* The invisible city at this tile may, as far as the player knows, not
4456 * exist anymore. */
4457 return act_prob_unseen_target(nmap, act_id, actor_unit);
4458 }
4459
4462
4463 return action_prob(nmap, act_id,
4464 &(const struct req_context) {
4465 .player = unit_owner(actor_unit),
4466 .city = tile_city(actor_tile),
4467 .tile = actor_tile,
4468 .unit = actor_unit,
4469 .unittype = unit_type_get(actor_unit),
4470 },
4471 actor_home,
4472 &(const struct req_context) {
4473 .player = city_owner(target_city),
4474 .city = target_city,
4475 .building = target_building,
4477 .unittype = target_utype,
4478 }, nullptr);
4479}
4480
4481/**********************************************************************/
4486 const struct unit *actor_unit,
4487 const action_id act_id,
4488 const struct city *target_city)
4489{
4493 act_id, target_city);
4494}
4495
4496/**********************************************************************/
4500static struct act_prob
4502 const struct unit *actor_unit,
4503 const struct city *actor_home,
4504 const struct tile *actor_tile,
4505 const action_id act_id,
4506 const struct unit *target_unit)
4507{
4508 if (actor_unit == nullptr || target_unit == nullptr) {
4509 /* Can't do an action when actor or target are missing. */
4510 return ACTPROB_IMPOSSIBLE;
4511 }
4512
4515 "Action %s is performed by %s not %s",
4516 action_id_rule_name(act_id),
4518 action_id_get_actor_kind(act_id)),
4520
4523 "Action %s is against %s not %s",
4524 action_id_rule_name(act_id),
4528
4530
4531 if (!unit_can_do_action(actor_unit, act_id)) {
4532 /* No point in continuing. */
4533 return ACTPROB_IMPOSSIBLE;
4534 }
4535
4536 /* Doesn't leak information about unit position since an unseen unit can't
4537 * be targeted. */
4538 if (!action_id_distance_accepted(act_id,
4541 /* No point in continuing. */
4542 return ACTPROB_IMPOSSIBLE;
4543 }
4544
4545 return action_prob(nmap, act_id,
4546 &(const struct req_context) {
4547 .player = unit_owner(actor_unit),
4548 .city = tile_city(actor_tile),
4549 .tile = actor_tile,
4550 .unit = actor_unit,
4551 .unittype = unit_type_get(actor_unit),
4552 },
4553 actor_home,
4554 &(const struct req_context) {
4555 .player = unit_owner(target_unit),
4558 .unit = target_unit,
4559 .unittype = unit_type_get(target_unit),
4560 },
4561 nullptr);
4562}
4563
4564/**********************************************************************/
4569 const struct unit *actor_unit,
4570 const action_id act_id,
4571 const struct unit *target_unit)
4572{
4576 act_id,
4577 target_unit);
4578}
4579
4580/**********************************************************************/
4584static struct act_prob
4586 const struct unit *actor_unit,
4587 const struct city *actor_home,
4588 const struct tile *actor_tile,
4589 const action_id act_id,
4590 const struct tile *target_tile)
4591{
4592 struct act_prob prob_all;
4593 const struct req_context *actor_ctxt;
4594 const struct action *act = action_by_number(act_id);
4595
4596 if (actor_unit == nullptr || target_tile == nullptr) {
4597 /* Can't do an action when actor or target are missing. */
4598 return ACTPROB_IMPOSSIBLE;
4599 }
4600
4603 "Action %s is performed by %s not %s",
4604 action_id_rule_name(act_id),
4606 action_id_get_actor_kind(act_id)),
4608
4611 "Action %s is against %s not %s",
4612 action_id_rule_name(act_id),
4616
4618
4619 if (!unit_can_do_action(actor_unit, act_id)) {
4620 /* No point in continuing. */
4621 return ACTPROB_IMPOSSIBLE;
4622 }
4623
4624 /* Doesn't leak information about unit stack position since it is
4625 * specified as a tile and an unknown tile's position is known. */
4626 if (!action_id_distance_accepted(act_id,
4628 target_tile))) {
4629 /* No point in continuing. */
4630 return ACTPROB_IMPOSSIBLE;
4631 }
4632
4633 /* Doesn't leak information since the actor player can see the target
4634 * tile. */
4636 && tile_city(target_tile) != nullptr
4638 act_id,
4639 CITYT_CENTER, TRUE)) {
4640 /* Don't offer to perform actions that never can target a unit stack in
4641 * a city. */
4642 return ACTPROB_IMPOSSIBLE;
4643 }
4644
4645 /* Doesn't leak information since it must be 100% certain from the
4646 * player's perspective that the blocking action is legal. */
4650 target_unit)) {
4651 /* Don't offer to perform an action known to be blocked. */
4652 return ACTPROB_IMPOSSIBLE;
4653 }
4655
4656 /* Must be done here since an empty unseen tile will result in
4657 * ACTPROB_IMPOSSIBLE. */
4658 if (unit_list_size(target_tile->units) == 0) {
4659 /* Can't act against an empty tile. */
4660
4662 target_tile)) {
4663 /* Known empty tile. */
4664 return ACTPROB_IMPOSSIBLE;
4665 } else {
4666 /* The player doesn't know that the tile is empty. */
4667 return act_prob_unseen_target(nmap, act_id, actor_unit);
4668 }
4669 }
4670
4674 && tile_city(target_tile) != nullptr
4677 /* Hard coded rule: can't "Bombard", "Suicide Attack", or "Attack"
4678 * units in non enemy cities. */
4679 return ACTPROB_IMPOSSIBLE;
4680 }
4681
4688 /* Hard coded rule: can't "Nuke Units", "Wipe Units", "Suicide Attack",
4689 * or "Attack" units on non native tile without "AttackNonNative" and
4690 * not "Only_Native_Attack". */
4691 return ACTPROB_IMPOSSIBLE;
4692 }
4693
4694 /* Invisible units at this tile can make the action legal or illegal.
4695 * Invisible units can be stacked with visible units. The possible
4696 * existence of invisible units therefore makes the result uncertain. */
4700
4701 actor_ctxt = &(const struct req_context) {
4702 .player = unit_owner(actor_unit),
4703 .city = tile_city(actor_tile),
4704 .tile = actor_tile,
4705 .unit = actor_unit,
4706 .unittype = unit_type_get(actor_unit),
4707 };
4708
4710 struct act_prob prob_unit;
4711
4713 /* Only visible units are considered. The invisible units contributed
4714 * their uncertainty to prob_all above. */
4715 continue;
4716 }
4717
4719 &(const struct req_context) {
4720 .player = unit_owner(target_unit),
4723 .unit = target_unit,
4724 .unittype = unit_type_get(target_unit),
4725 },
4726 nullptr);
4727
4729 /* One unit makes it impossible for all units. */
4730 return ACTPROB_IMPOSSIBLE;
4731 } else if (action_prob_not_impl(prob_unit)) {
4732 /* Not implemented dominates all except impossible. */
4734 } else {
4736 "Invalid probability [%d, %d]",
4737 prob_unit.min, prob_unit.max);
4738
4740 /* Special values dominate regular values. */
4741 continue;
4742 }
4743
4744 /* Probability against all target units considered until this moment
4745 * and the probability against this target unit. */
4746 prob_all.min = (prob_all.min * prob_unit.min) / ACTPROB_VAL_MAX;
4747 prob_all.max = (prob_all.max * prob_unit.max) / ACTPROB_VAL_MAX;
4748 break;
4749 }
4751
4752 /* Not impossible for any of the units at the tile. */
4753 return prob_all;
4754}
4755
4756/**********************************************************************/
4761 const struct unit *actor_unit,
4762 const action_id act_id,
4763 const struct tile *target_tile)
4764{
4768 act_id,
4769 target_tile);
4770}
4771
4772/**********************************************************************/
4776static struct act_prob
4778 const struct unit *actor_unit,
4779 const struct city *actor_home,
4780 const struct tile *actor_tile,
4781 const action_id act_id,
4782 const struct tile *target_tile,
4783 const struct extra_type *target_extra)
4784{
4785 if (actor_unit == nullptr || target_tile == nullptr) {
4786 /* Can't do an action when actor or target are missing. */
4787 return ACTPROB_IMPOSSIBLE;
4788 }
4789
4792 "Action %s is performed by %s not %s",
4793 action_id_rule_name(act_id),
4795 action_id_get_actor_kind(act_id)),
4797
4800 "Action %s is against %s not %s",
4801 action_id_rule_name(act_id),
4805
4807
4808 if (!unit_can_do_action(actor_unit, act_id)) {
4809 /* No point in continuing. */
4810 return ACTPROB_IMPOSSIBLE;
4811 }
4812
4813 /* Doesn't leak information about tile position since an unknown tile's
4814 * position is known. */
4815 if (!action_id_distance_accepted(act_id,
4817 target_tile))) {
4818 /* No point in continuing. */
4819 return ACTPROB_IMPOSSIBLE;
4820 }
4821
4822 return action_prob(nmap, act_id,
4823 &(const struct req_context) {
4824 .player = unit_owner(actor_unit),
4825 .city = tile_city(actor_tile),
4826 .tile = actor_tile,
4827 .unit = actor_unit,
4828 .unittype = unit_type_get(actor_unit),
4829 },
4830 actor_home,
4831 &(const struct req_context) {
4832 .player = tile_owner(target_tile),
4833 .city = tile_city(target_tile),
4834 .tile = target_tile,
4835 },
4836 target_extra);
4837}
4838
4839/**********************************************************************/
4844 const struct unit *actor_unit,
4845 const action_id act_id,
4846 const struct tile *target_tile,
4847 const struct extra_type *target_extra)
4848{
4852 act_id, target_tile, target_extra);
4853}
4854
4855/**********************************************************************/
4859static struct act_prob
4861 const struct unit *actor_unit,
4862 const struct city *actor_home,
4863 const struct tile *actor_tile,
4864 const action_id act_id,
4865 const struct tile *target_tile,
4866 const struct extra_type *target_extra)
4867{
4868 if (actor_unit == nullptr || target_tile == nullptr) {
4869 /* Can't do an action when actor or target are missing. */
4870 return ACTPROB_IMPOSSIBLE;
4871 }
4872
4875 "Action %s is performed by %s not %s",
4876 action_id_rule_name(act_id),
4878 action_id_get_actor_kind(act_id)),
4880
4883 "Action %s is against %s not %s",
4884 action_id_rule_name(act_id),
4888
4890
4891 if (!unit_can_do_action(actor_unit, act_id)) {
4892 /* No point in continuing. */
4893 return ACTPROB_IMPOSSIBLE;
4894 }
4895
4896 /* Doesn't leak information about tile position since an unknown tile's
4897 * position is known. */
4898 if (!action_id_distance_accepted(act_id,
4900 target_tile))) {
4901 /* No point in continuing. */
4902 return ACTPROB_IMPOSSIBLE;
4903 }
4904
4905 return action_prob(nmap, act_id,
4906 &(const struct req_context) {
4907 .player = unit_owner(actor_unit),
4908 .city = tile_city(actor_tile),
4909 .tile = actor_tile,
4910 .unit = actor_unit,
4911 .unittype = unit_type_get(actor_unit),
4912 },
4913 actor_home,
4914 &(const struct req_context) {
4915 .player = target_tile->extras_owner,
4916 .city = tile_city(target_tile),
4917 .tile = target_tile,
4918 },
4919 target_extra);
4920}
4921
4922/**********************************************************************/
4927 const struct unit *actor_unit,
4928 const action_id act_id,
4929 const struct tile *target_tile,
4930 const struct extra_type *target_extra)
4931{
4935 act_id, target_tile, target_extra);
4936}
4937
4938/**********************************************************************/
4942static struct act_prob
4944 const struct unit *actor_unit,
4945 const struct city *actor_home,
4946 const struct tile *actor_tile,
4947 const action_id act_id)
4948{
4949 if (actor_unit == nullptr) {
4950 /* Can't do the action when the actor is missing. */
4951 return ACTPROB_IMPOSSIBLE;
4952 }
4953
4954 /* No point in checking distance to target. It is always 0. */
4955
4958 "Action %s is performed by %s not %s",
4959 action_id_rule_name(act_id),
4961 action_id_get_actor_kind(act_id)),
4963
4966 "Action %s is against %s not %s",
4967 action_id_rule_name(act_id),
4971
4973
4974 if (!unit_can_do_action(actor_unit, act_id)) {
4975 /* No point in continuing. */
4976 return ACTPROB_IMPOSSIBLE;
4977 }
4978
4979 return action_prob(nmap, act_id,
4980 &(const struct req_context) {
4981 .player = unit_owner(actor_unit),
4982 .city = tile_city(actor_tile),
4983 .tile = actor_tile,
4984 .unit = actor_unit,
4985 .unittype = unit_type_get(actor_unit),
4986 },
4987 actor_home,
4988 nullptr,
4989 nullptr);
4990}
4991
4992/**********************************************************************/
4997 const struct unit *actor_unit,
4998 const action_id act_id)
4999{
5003 act_id);
5004}
5005
5006/**********************************************************************/
5019 const struct action *paction,
5020 const struct unit *act_unit,
5021 const struct city *tgt_city,
5022 const struct unit *tgt_unit,
5023 const struct tile *tgt_tile,
5024 const struct extra_type *extra_tgt)
5025{
5026 /* Assume impossible until told otherwise. */
5027 struct act_prob prob = ACTPROB_IMPOSSIBLE;
5028
5031
5033 case ATK_STACK:
5034 if (tgt_tile) {
5036 }
5037 break;
5038 case ATK_TILE:
5039 if (tgt_tile) {
5041 }
5042 break;
5043 case ATK_EXTRAS:
5044 if (tgt_tile) {
5047 }
5048 break;
5049 case ATK_CITY:
5050 if (tgt_city) {
5052 }
5053 break;
5054 case ATK_UNIT:
5055 if (tgt_unit) {
5057 }
5058 break;
5059 case ATK_SELF:
5060 prob = action_prob_self(nmap, act_unit, paction->id);
5061 break;
5062 case ATK_COUNT:
5063 log_error("Invalid action target kind");
5064 break;
5065 }
5066
5067 return prob;
5068}
5069
5070/**********************************************************************/
5076 const action_id act_id,
5077 const struct unit *actor,
5078 const struct city *actor_home,
5079 const struct tile *actor_tile,
5080 const bool omniscient_cheat,
5081 const struct city* target)
5082{
5083 /* FIXME: some unit state requirements still depend on the actor unit's
5084 * current position rather than on actor_tile. Maybe this function should
5085 * return ACTPROB_NOT_IMPLEMENTED when one of those is detected and no
5086 * other requirement makes the action ACTPROB_IMPOSSIBLE? */
5087
5088 if (omniscient_cheat) {
5091 target)) {
5092 return ACTPROB_CERTAIN;
5093 } else {
5094 return ACTPROB_IMPOSSIBLE;
5095 }
5096 } else {
5097 /* FIXME: this branch result depends _directly_ on actor's position.
5098 * I.e., like, not adjacent, no action. Other branch ignores radius. */
5100 act_id, target);
5101 }
5102}
5103
5104/**********************************************************************/
5109struct act_prob
5111 action_id act_id,
5112 const struct unit *actor,
5113 const struct city *actor_home,
5114 const struct tile *actor_tile,
5115 bool omniscient_cheat,
5116 const struct unit *target)
5117{
5118 /* FIXME: some unit state requirements still depend on the actor unit's
5119 * current position rather than on actor_tile. Maybe this function should
5120 * return ACTPROB_NOT_IMPLEMENTED when one of those is detected and no
5121 * other requirement makes the action ACTPROB_IMPOSSIBLE? */
5122
5123 if (omniscient_cheat) {
5126 target)) {
5127 return ACTPROB_CERTAIN;
5128 } else {
5129 return ACTPROB_IMPOSSIBLE;
5130 }
5131 } else {
5133 act_id, target);
5134 }
5135}
5136
5137/**********************************************************************/
5142struct act_prob
5144 action_id act_id,
5145 const struct unit *actor,
5146 const struct city *actor_home,
5147 const struct tile *actor_tile,
5148 bool omniscient_cheat,
5149 const struct tile *target)
5150{
5151 /* FIXME: some unit state requirements still depend on the actor unit's
5152 * current position rather than on actor_tile. Maybe this function should
5153 * return ACTPROB_NOT_IMPLEMENTED when one of those is detected and no
5154 * other requirement makes the action ACTPROB_IMPOSSIBLE? */
5155
5156 if (omniscient_cheat) {
5159 target)) {
5160 return ACTPROB_CERTAIN;
5161 } else {
5162 return ACTPROB_IMPOSSIBLE;
5163 }
5164 } else {
5166 act_id, target);
5167 }
5168}
5169
5170/**********************************************************************/
5175struct act_prob
5177 action_id act_id,
5178 const struct unit *actor,
5179 const struct city *actor_home,
5180 const struct tile *actor_tile,
5181 bool omniscient_cheat,
5182 const struct tile *target_tile,
5183 const struct extra_type *target_extra)
5184{
5185 /* FIXME: some unit state requirements still depend on the actor unit's
5186 * current position rather than on actor_tile. Maybe this function should
5187 * return ACTPROB_NOT_IMPLEMENTED when one of those is detected and no
5188 * other requirement makes the action ACTPROB_IMPOSSIBLE? */
5189
5190 if (omniscient_cheat) {
5194 return ACTPROB_CERTAIN;
5195 } else {
5196 return ACTPROB_IMPOSSIBLE;
5197 }
5198 } else {
5200 act_id, target_tile, target_extra);
5201 }
5202}
5203
5204/**********************************************************************/
5209struct act_prob
5211 action_id act_id,
5212 const struct unit *actor,
5213 const struct city *actor_home,
5214 const struct tile *actor_tile,
5215 bool omniscient_cheat,
5216 const struct tile *target_tile,
5217 const struct extra_type *target_extra)
5218{
5219 /* FIXME: some unit state requirements still depend on the actor unit's
5220 * current position rather than on actor_tile. Maybe this function should
5221 * return ACTPROB_NOT_IMPLEMENTED when one of those is detected and no
5222 * other requirement makes the action ACTPROB_IMPOSSIBLE? */
5223
5224 if (omniscient_cheat) {
5228 return ACTPROB_CERTAIN;
5229 } else {
5230 return ACTPROB_IMPOSSIBLE;
5231 }
5232 } else {
5234 act_id, target_tile, target_extra);
5235 }
5236}
5237
5238/**********************************************************************/
5243struct act_prob
5245 action_id act_id,
5246 const struct unit *actor,
5247 const struct city *actor_home,
5248 const struct tile *actor_tile,
5249 bool omniscient_cheat)
5250{
5251 /* FIXME: some unit state requirements still depend on the actor unit's
5252 * current position rather than on actor_tile. Maybe this function should
5253 * return ACTPROB_NOT_IMPLEMENTED when one of those is detected and no
5254 * other requirement makes the action ACTPROB_IMPOSSIBLE? */
5255 if (omniscient_cheat) {
5258 return ACTPROB_CERTAIN;
5259 } else {
5260 return ACTPROB_IMPOSSIBLE;
5261 }
5262 } else {
5264 act_id);
5265 }
5266}
5267
5268/**********************************************************************/
5272{
5274
5275 return out;
5276}
5277
5278/**********************************************************************/
5282{
5284
5285 return out;
5286}
5287
5288/**********************************************************************/
5292{
5294
5295 return out;
5296}
5297
5298/**********************************************************************/
5302{
5304
5305 return out;
5306}
5307
5308/**********************************************************************/
5312{
5314
5315 return out;
5316}
5317
5318/**********************************************************************/
5323{
5324 return (ACTPROB_VAL_MIN < probability.max
5326}
5327
5328/**********************************************************************/
5333{
5334 return (ACTPROB_VAL_MAX == probability.min
5335 && ACTPROB_VAL_MAX == probability.max);
5336}
5337
5338/**********************************************************************/
5342static inline bool
5348
5349/**********************************************************************/
5353static inline bool
5355{
5356 return probability.min == ACTPROB_VAL_NOT_IMPL
5357 && probability.max == ACTPROB_VAL_MIN;
5358}
5359
5360/**********************************************************************/
5364static inline bool
5366{
5367 return probability.max < probability.min;
5368}
5369
5370/**********************************************************************/
5374 const struct act_prob *ap2)
5375{
5376 return ap1->min == ap2->min && ap1->max == ap2->max;
5377}
5378
5379/**********************************************************************/
5383 const struct act_prob ap2)
5384{
5385 struct act_prob my_ap1;
5386 struct act_prob my_ap2;
5387
5388 /* The action probabilities are real. */
5391
5392 /* Convert any signals to ACTPROB_NOT_KNOWN. */
5394 /* Assert that it is OK to convert the signal. */
5396
5398 } else {
5399 my_ap1 = ap1;
5400 }
5401
5403 /* Assert that it is OK to convert the signal. */
5405
5407 } else {
5408 my_ap2 = ap2;
5409 }
5410
5411 /* The action probabilities now have a comparison friendly form. */
5414
5415 /* Do the comparison. Start with min. Continue with max. */
5416 if (my_ap1.min < my_ap2.min) {
5417 return -1;
5418 } else if (my_ap1.min > my_ap2.min) {
5419 return 1;
5420 } else if (my_ap1.max < my_ap2.max) {
5421 return -1;
5422 } else if (my_ap1.max > my_ap2.max) {
5423 return 1;
5424 } else {
5425 return 0;
5426 }
5427}
5428
5429/**********************************************************************/
5434{
5435 struct act_prob my_ap;
5436
5437 /* The action probability is real. */
5439
5440 /* Convert any signals to ACTPROB_NOT_KNOWN. */
5442 /* Assert that it is OK to convert the signal. */
5444
5446 } else {
5447 my_ap = ap;
5448 }
5449
5450 /* The action probability now has a math friendly form. */
5452
5453 return (double)my_ap.min / (double) ACTPROB_VAL_MAX;
5454}
5455
5456/**********************************************************************/
5461 const struct act_prob *ap2)
5462{
5463 struct act_prob my_ap1;
5464 struct act_prob my_ap2;
5465 struct act_prob out;
5466
5467 /* The action probabilities are real. */
5470
5473 /* Keep the information rather than converting the signal to
5474 * ACTPROB_NOT_KNOWN. */
5475
5476 /* Assert that it is OK to convert the signal. */
5478
5479 out.min = ap1->min;
5480 out.max = ap2->max;
5481
5482 return out;
5483 }
5484
5485 /* Convert any signals to ACTPROB_NOT_KNOWN. */
5486 if (action_prob_is_signal(*ap1)) {
5487 /* Assert that it is OK to convert the signal. */
5489
5490 my_ap1.min = ACTPROB_VAL_MIN;
5491 my_ap1.max = ACTPROB_VAL_MAX;
5492 } else {
5493 my_ap1.min = ap1->min;
5494 my_ap1.max = ap1->max;
5495 }
5496
5497 if (action_prob_is_signal(*ap2)) {
5498 /* Assert that it is OK to convert the signal. */
5500
5501 my_ap2.min = ACTPROB_VAL_MIN;
5502 my_ap2.max = ACTPROB_VAL_MAX;
5503 } else {
5504 my_ap2.min = ap2->min;
5505 my_ap2.max = ap2->max;
5506 }
5507
5508 /* The action probabilities now have a math friendly form. */
5511
5512 /* Do the math. */
5513 out.min = (my_ap1.min * my_ap2.min) / ACTPROB_VAL_MAX;
5514 out.max = (my_ap1.max * my_ap2.max) / ACTPROB_VAL_MAX;
5515
5516 /* Cap at 100%. */
5517 out.min = MIN(out.min, ACTPROB_VAL_MAX);
5518 out.max = MIN(out.max, ACTPROB_VAL_MAX);
5519
5520 return out;
5521}
5522
5523/**********************************************************************/
5531 const struct act_prob *ap2)
5532{
5533 struct act_prob my_ap1;
5534 struct act_prob my_ap2;
5535 struct act_prob out;
5536
5537 /* The action probabilities are real. */
5540
5543 /* Keep the information rather than converting the signal to
5544 * ACTPROB_NOT_KNOWN. */
5545
5546 /* Assert that it is OK to convert the signal. */
5548
5549 out.min = ap1->min;
5550 out.max = ap2->max;
5551
5552 return out;
5553 }
5554
5555 /* Convert any signals to ACTPROB_NOT_KNOWN. */
5556 if (action_prob_is_signal(*ap1)) {
5557 /* Assert that it is OK to convert the signal. */
5559
5560 my_ap1.min = ACTPROB_VAL_MIN;
5561 my_ap1.max = ACTPROB_VAL_MAX;
5562 } else {
5563 my_ap1.min = ap1->min;
5564 my_ap1.max = ap1->max;
5565 }
5566
5567 if (action_prob_is_signal(*ap2)) {
5568 /* Assert that it is OK to convert the signal. */
5570
5571 my_ap2.min = ACTPROB_VAL_MIN;
5572 my_ap2.max = ACTPROB_VAL_MAX;
5573 } else {
5574 my_ap2.min = ap2->min;
5575 my_ap2.max = ap2->max;
5576 }
5577
5578 /* The action probabilities now have a math friendly form. */
5581
5582 /* Do the math. */
5583 out.min = my_ap1.min + (((ACTPROB_VAL_MAX - my_ap1.min) * my_ap2.min)
5584 / ACTPROB_VAL_MAX);
5585 out.max = my_ap1.max + (((ACTPROB_VAL_MAX - my_ap1.max) * my_ap2.max)
5586 / ACTPROB_VAL_MAX);
5587
5588 /* Cap at 100%. */
5589 out.min = MIN(out.min, ACTPROB_VAL_MAX);
5590 out.max = MIN(out.max, ACTPROB_VAL_MAX);
5591
5592 return out;
5593}
5594
5595/**********************************************************************/
5599{
5600 switch (actres_dice_type(paction->result)) {
5601 case DRT_DIPLCHANCE:
5603 /* Take the initial odds from the diplchance setting. */
5605 server_setting_by_name("diplchance"));
5606 }
5608 case DRT_CERTAIN:
5609 return 100;
5610 case DRT_NONE:
5611 break;
5612 }
5613
5614 /* The odds of the action not being stopped by its dice roll when the dice
5615 * isn't thrown is 100%. ACTION_ODDS_PCT_DICE_ROLL_NA is above 100% */
5617}
5618
5619/**********************************************************************/
5623 const struct unit *act_unit,
5624 const struct city *tgt_city,
5625 const struct player *tgt_player,
5626 const struct action *paction)
5627{
5629 const struct unit_type *actu_type = unit_type_get(act_unit);
5630
5631 fc_assert_action_msg(odds >= 0 && odds <= 100,
5632 odds = 100,
5633 "Bad initial odds for action number %d."
5634 " Does it roll the dice at all?",
5635 paction->id);
5636
5637 /* Let the Action_Odds_Pct effect modify the odds. The advantage of doing
5638 * it this way instead of rolling twice is that Action_Odds_Pct can
5639 * increase the odds. */
5640 odds = odds
5641 + ((odds
5642 * get_target_bonus_effects(nullptr,
5643 &(const struct req_context) {
5644 .player = act_player,
5645 .city = tgt_city,
5646 .unit = act_unit,
5647 .unittype = actu_type,
5648 .action = paction,
5649 },
5650 &(const struct req_context) {
5651 .player = tgt_player,
5652 },
5654 / 100)
5655 - ((odds
5656 * get_target_bonus_effects(nullptr,
5657 &(const struct req_context) {
5658 .player = tgt_player,
5659 .city = tgt_city,
5660 .unit = act_unit,
5661 .unittype = actu_type,
5662 .action = paction,
5663 },
5664 &(const struct req_context) {
5665 .player = act_player,
5666 },
5668 / 100);
5669
5670
5671 /* Odds are between 0% and 100%. */
5672 return CLIP(0, odds, 100);
5673}
5674
5675/**********************************************************************/
5679{
5680 struct action *paction = action_by_number(act);
5681
5682 /* Always immune since its not enabled. Doesn't count. */
5683 if (!action_is_in_use(paction)) {
5684 return FALSE;
5685 }
5686
5688 if (requirement_fulfilled_by_government(gov, &(enabler->target_reqs))) {
5689 return FALSE;
5690 }
5692
5693 return TRUE;
5694}
5695
5696/**********************************************************************/
5702 const struct player *actor_player,
5703 const struct req_context *target)
5704{
5706 enabler) {
5707 if (are_reqs_active(target,
5708 &(const struct req_context) {
5710 },
5711 &enabler->target_reqs, RPT_POSSIBLE)) {
5712 return TRUE;
5713 }
5715
5716 return FALSE;
5717}
5718
5719/**********************************************************************/
5723 const struct player *actor_player,
5724 const struct city* target_city)
5725{
5727 FALSE, "Action %s is against %s not cities",
5728 action_id_rule_name(act_id),
5730 action_id_get_target_kind(act_id)));
5731
5732 return is_target_possible(act_id, actor_player,
5733 &(const struct req_context) {
5734 .player = city_owner(target_city),
5735 .city = target_city,
5737 });
5738}
5739
5740/**********************************************************************/
5746 const action_id act_id,
5747 const struct unit *actor_unit)
5748{
5749 const struct player *actor_player = unit_owner(actor_unit);
5750 const struct req_context actor_ctxt = {
5752 .city = tile_city(unit_tile(actor_unit)),
5754 .unit = actor_unit,
5755 .unittype = unit_type_get(actor_unit),
5756 };
5757 const struct action *paction = action_by_number(act_id);
5758
5759 enum fc_tristate result;
5760
5762
5763 if (!utype_can_do_action(actor_unit->utype, act_id)) {
5764 /* The unit type can't perform the action. */
5765 return FALSE;
5766 }
5767
5770
5771 if (result == TRI_NO) {
5772 /* The hard requirements aren't fulfilled. */
5773 return FALSE;
5774 }
5775
5777 enabler) {
5778 const enum fc_tristate current
5780 &enabler->actor_reqs,
5781 /* Needed since no player to evaluate DiplRel
5782 * requirements against. */
5783 RPT_POSSIBLE);
5784
5785 if (current == TRI_YES
5786 || current == TRI_MAYBE) {
5787 /* The ruleset requirements may be fulfilled. */
5788 return TRUE;
5789 }
5791
5792 /* No action enabler allows this action. */
5793 return FALSE;
5794}
5795
5796/**********************************************************************/
5801 const action_id act_id)
5802{
5803 fc_assert(action_id_exists(act_id) || act_id == ACTION_ANY);
5804
5805 /* Check if full movement points may enable the specified action. */
5807 act_id,
5810 act_id,
5812}
5813
5814/**********************************************************************/
5824 const struct unit_type *act_utype)
5825{
5826 const struct action *paction = enabler_get_action(ae);
5827 struct universal actor_univ = { .kind = VUT_UTYPE,
5828 .value.utype = act_utype };
5829
5830 fc_assert_ret_val(paction != nullptr, FALSE);
5832 fc_assert_ret_val(act_utype != nullptr, FALSE);
5833
5835 && !req_vec_is_impossible_to_fulfill(&ae->actor_reqs)
5836 && universal_fulfills_requirements(FALSE, &ae->actor_reqs,
5837 &actor_univ));
5838}
5839
5840/**********************************************************************/
5851{
5852 const struct action *paction = enabler_get_action(ae);
5853
5854 switch (action_get_actor_kind(paction)) {
5855 case AAK_UNIT:
5858 /* A possible actor unit type has been found. */
5859 return TRUE;
5860 }
5862
5863 /* No actor detected. */
5864 return FALSE;
5865 case AAK_CITY:
5866 case AAK_PLAYER:
5867 /* Currently can't detect */
5868 return TRUE;
5869 case AAK_COUNT:
5871 break;
5872 }
5873
5874 /* No actor detected. */
5875 return FALSE;
5876}
5877
5878/**********************************************************************/
5886{
5887 switch (action_get_actor_kind(paction)) {
5888 case AAK_UNIT:
5891 return TRUE;
5892 }
5894 break;
5895 case AAK_CITY:
5896 case AAK_PLAYER:
5897 /* No ruleset hard reqs atm */
5898 return TRUE;
5899 case AAK_COUNT:
5901 break;
5902 }
5903
5904 /* No actor detected. */
5905 return FALSE;
5906}
5907
5908/**********************************************************************/
5916{
5918
5920 /* Hard requirements not fulfilled. */
5921 return FALSE;
5922 }
5923
5925
5927 /* If this iteration finds any entries, action is enabled. */
5928 return TRUE;
5930
5931 /* No non deleted action enabler. */
5932 return FALSE;
5933}
5934
5935/**********************************************************************/
5942{
5943 return paction != nullptr
5945}
5946
5947/**********************************************************************/
5957
5958/**********************************************************************/
5962{
5963 fc_assert_ret_val(num >= 0, nullptr);
5965
5966 return &auto_perfs[num];
5967}
5968
5969/**********************************************************************/
5978{
5979 return action_auto_perf_slot_number(num);
5980}
5981
5982/**********************************************************************/
5986 struct universal *actor_uni,
5987 struct universal *target_uni)
5988{
5990 enab) {
5991 if ((actor_uni == nullptr
5992 || universal_fulfills_requirements(FALSE, &(enab->actor_reqs),
5993 actor_uni))
5994 && (target_uni == nullptr
5995 || universal_fulfills_requirements(FALSE, &(enab->target_reqs),
5996 target_uni))) {
5997 return TRUE;
5998 }
6000
6001 return FALSE;
6002}
6003
6004/**********************************************************************/
6010{
6012
6013 if (size < MAX_NUM_ACTIONS) {
6014 /* An action array is terminated by ACTION_NONE */
6016 }
6017}
6018
6019/**********************************************************************/
6027 int *position,
6028 enum action_result result)
6029{
6030 action_iterate(act) {
6031 struct action *paction = action_by_number(act);
6032 if (paction->result == result) {
6033 /* Assume one result for each action. */
6034 fc_assert_ret(*position < MAX_NUM_ACTIONS);
6035
6036 act_array[(*position)++] = paction->id;
6037 }
6039}
6040
6041/**********************************************************************/
6044const char *action_ui_name_default(int act)
6045{
6046 switch ((enum gen_action)act) {
6047 case ACTION_SPY_POISON:
6048 /* TRANS: _Poison City (3% chance of success). */
6049 return N_("%sPoison City%s");
6051 /* TRANS: _Poison City and Escape (3% chance of success). */
6052 return N_("%sPoison City and Escape%s");
6054 /* TRANS: S_abotage Enemy Unit (3% chance of success). */
6055 return N_("S%sabotage Enemy Unit%s");
6057 /* TRANS: S_abotage Enemy Unit and Escape (3% chance of success). */
6058 return N_("S%sabotage Enemy Unit and Escape%s");
6060 /* TRANS: Bribe Enemy _Unit (3% chance of success). */
6061 return N_("Bribe Enemy %sUnit%s");
6063 /* TRANS: Bribe Enemy _Stack (3% chance of success). */
6064 return N_("Bribe Enemy %sStack%s");
6066 /* TRANS: _Sabotage City (3% chance of success). */
6067 return N_("%sSabotage City%s");
6069 /* TRANS: _Sabotage City and Escape (3% chance of success). */
6070 return N_("%sSabotage City and Escape%s");
6072 /* TRANS: Industria_l Sabotage (3% chance of success). */
6073 return N_("Industria%sl Sabotage%s");
6075 /* TRANS: Industria_l Sabotage Production (3% chance of success). */
6076 return N_("Industria%sl Sabotage Production%s");
6078 /* TRANS: Industria_l Sabotage and Escape (3% chance of success). */
6079 return N_("Industria%sl Sabotage and Escape%s");
6081 /* TRANS: Industria_l Sabotage Production and Escape (3% chance of success). */
6082 return N_("Industria%sl Sabotage Production and Escape%s");
6084 /* TRANS: Incite a Re_volt (3% chance of success). */
6085 return N_("Incite a Re%svolt%s");
6087 /* TRANS: Incite a Re_volt and Escape (3% chance of success). */
6088 return N_("Incite a Re%svolt and Escape%s");
6090 /* TRANS: Establish _Embassy (100% chance of success). */
6091 return N_("Establish %sEmbassy%s");
6093 /* TRANS: Becom_e Ambassador (100% chance of success). */
6094 return N_("Becom%se Ambassador%s");
6096 /* TRANS: Steal _Technology (3% chance of success). */
6097 return N_("Steal %sTechnology%s");
6099 /* TRANS: Steal _Technology and Escape (3% chance of success). */
6100 return N_("Steal %sTechnology and Escape%s");
6102 /* TRANS: In_dustrial Espionage (3% chance of success). */
6103 return N_("In%sdustrial Espionage%s");
6105 /* TRANS: In_dustrial Espionage and Escape (3% chance of success). */
6106 return N_("In%sdustrial Espionage and Escape%s");
6108 /* TRANS: _Investigate City (100% chance of success). */
6109 return N_("%sInvestigate City%s");
6111 /* TRANS: _Investigate City (spends the unit) (100% chance of
6112 * success). */
6113 return N_("%sInvestigate City (spends the unit)%s");
6115 /* TRANS: Steal _Gold (100% chance of success). */
6116 return N_("Steal %sGold%s");
6118 /* TRANS: Steal _Gold and Escape (100% chance of success). */
6119 return N_("Steal %sGold and Escape%s");
6121 /* TRANS: Spread _Plague (100% chance of success). */
6122 return N_("Spread %sPlague%s");
6123 case ACTION_STEAL_MAPS:
6124 /* TRANS: Steal _Maps (100% chance of success). */
6125 return N_("Steal %sMaps%s");
6127 /* TRANS: Steal _Maps and Escape (100% chance of success). */
6128 return N_("Steal %sMaps and Escape%s");
6129 case ACTION_TRADE_ROUTE:
6130 /* TRANS: Establish Trade _Route (100% chance of success). */
6131 return N_("Establish Trade %sRoute%s");
6132 case ACTION_MARKETPLACE:
6133 /* TRANS: Enter _Marketplace (100% chance of success). */
6134 return N_("Enter %sMarketplace%s");
6135 case ACTION_HELP_WONDER:
6136 /* TRANS: Help _build Wonder (100% chance of success). */
6137 return N_("Help %sbuild Wonder%s");
6139 /* TRANS: _Capture Units (100% chance of success). */
6140 return N_("%sCapture Units%s");
6141 case ACTION_EXPEL_UNIT:
6142 /* TRANS: _Expel Unit (100% chance of success). */
6143 return N_("%sExpel Unit%s");
6144 case ACTION_FOUND_CITY:
6145 /* TRANS: _Found City (100% chance of success). */
6146 return N_("%sFound City%s");
6147 case ACTION_JOIN_CITY:
6148 /* TRANS: _Join City (100% chance of success). */
6149 return N_("%sJoin City%s");
6150 case ACTION_BOMBARD:
6151 /* TRANS: B_ombard (100% chance of success). */
6152 return N_("B%sombard%s");
6153 case ACTION_BOMBARD2:
6154 /* TRANS: B_ombard 2 (100% chance of success). */
6155 return N_("B%sombard 2%s");
6156 case ACTION_BOMBARD3:
6157 /* TRANS: B_ombard 3 (100% chance of success). */
6158 return N_("B%sombard 3%s");
6159 case ACTION_BOMBARD4:
6160 /* TRANS: B_ombard 4 (100% chance of success). */
6161 return N_("B%sombard 4%s");
6164 /* TRANS: Lethal B_ombard (100% chance of success). */
6165 return N_("Lethal B%sombard%s");
6166 case ACTION_SPY_NUKE:
6167 /* TRANS: Suitcase _Nuke (100% chance of success). */
6168 return N_("Suitcase %sNuke%s");
6170 /* TRANS: Suitcase _Nuke and Escape (100% chance of success). */
6171 return N_("Suitcase %sNuke and Escape%s");
6172 case ACTION_NUKE:
6173 /* TRANS: Explode _Nuclear (100% chance of success). */
6174 return N_("Explode %sNuclear%s");
6175 case ACTION_NUKE_CITY:
6176 /* TRANS: _Nuke City (100% chance of success). */
6177 return N_("%sNuke City%s");
6178 case ACTION_NUKE_UNITS:
6179 /* TRANS: _Nuke Units (100% chance of success). */
6180 return N_("%sNuke Units%s");
6182 /* TRANS: Destroy _City (100% chance of success). */
6183 return N_("Destroy %sCity%s");
6185 /* TRANS: Dis_band recovering production (100% chance of success). */
6186 return N_("Dis%sband recovering production%s");
6188 /* TRANS: Dis_band without recovering production (100% chance of success). */
6189 return N_("Dis%sband without recovering production%s");
6190 case ACTION_HOME_CITY:
6191 /* TRANS: Set _Home City (100% chance of success). */
6192 return N_("Set %sHome City%s");
6193 case ACTION_HOMELESS:
6194 /* TRANS: Make _Homeless (100% chance of success). */
6195 return N_("Make %sHomeless%s");
6197 /* TRANS: _Upgrade Unit (100% chance of success). */
6198 return N_("%sUpgrade Unit%s");
6199 case ACTION_PARADROP:
6200 /* TRANS: Drop _Paratrooper (100% chance of success). */
6201 return N_("Drop %sParatrooper%s");
6203 /* TRANS: Drop _Paratrooper (100% chance of success). */
6204 return N_("Drop %sParatrooper%s");
6206 /* TRANS: Drop _Paratrooper (100% chance of success). */
6207 return N_("Drop %sParatrooper%s");
6209 /* TRANS: Drop _Paratrooper (100% chance of success). */
6210 return N_("Drop %sParatrooper%s");
6212 /* TRANS: Drop _Paratrooper (100% chance of success). */
6213 return N_("Drop %sParatrooper%s");
6215 /* TRANS: Drop _Paratrooper (100% chance of success). */
6216 return N_("Drop %sParatrooper%s");
6217 case ACTION_AIRLIFT:
6218 /* TRANS: _Airlift to City (100% chance of success). */
6219 return N_("%sAirlift to City%s");
6220 case ACTION_ATTACK:
6221 case ACTION_ATTACK2:
6222 /* TRANS: _Attack (100% chance of success). */
6223 return N_("%sAttack%s");
6226 /* TRANS: _Suicide Attack (100% chance of success). */
6227 return N_("%sSuicide Attack%s");
6228 case ACTION_WIPE_UNITS:
6229 /* TRANS: _Wipe Units (100% chance of success). */
6230 return N_("%sWipe Units%s");
6232 /* TRANS: Collect _Ransom (100% chance of success). */
6233 return N_("Collect %sRansom%s");
6235 /* TRANS: Surgical Str_ike Building (100% chance of success). */
6236 return N_("Surgical Str%sike Building%s");
6238 /* TRANS: Surgical Str_ike Production (100% chance of success). */
6239 return N_("Surgical Str%sike Production%s");
6243 /* TRANS: _Conquer City (100% chance of success). */
6244 return N_("%sConquer City%s");
6246 /* TRANS: _Conquer City 2 (100% chance of success). */
6247 return N_("%sConquer City 2%s");
6251 /* TRANS: _Conquer Extras (100% chance of success). */
6252 return N_("%sConquer Extras%s");
6254 /* TRANS: _Conquer Extras 2 (100% chance of success). */
6255 return N_("%sConquer Extras 2%s");
6256 case ACTION_HEAL_UNIT:
6257 case ACTION_HEAL_UNIT2:
6258 /* TRANS: Heal _Unit (3% chance of success). */
6259 return N_("Heal %sUnit%s");
6262 /* TRANS: _Transform Terrain (3% chance of success). */
6263 return N_("%sTransform Terrain%s");
6264 case ACTION_CULTIVATE:
6265 case ACTION_CULTIVATE2:
6266 /* TRANS: Transform by _Cultivating (3% chance of success). */
6267 return N_("Transform by %sCultivating%s");
6268 case ACTION_PLANT:
6269 case ACTION_PLANT2:
6270 /* TRANS: Transform by _Planting (3% chance of success). */
6271 return N_("Transform by %sPlanting%s");
6272 case ACTION_PILLAGE:
6273 case ACTION_PILLAGE2:
6274 /* TRANS: Pilla_ge (100% chance of success). */
6275 return N_("Pilla%sge%s");
6276 case ACTION_CLEAN:
6277 case ACTION_CLEAN2:
6278 /* TRANS: Clean (100% chance of success). */
6279 return N_("%sClean%s");
6280 case ACTION_FORTIFY:
6281 case ACTION_FORTIFY2:
6282 /* TRANS: _Fortify (100% chance of success). */
6283 return N_("%sFortify%s");
6284 case ACTION_ROAD:
6285 case ACTION_ROAD2:
6286 /* TRANS: Build _Road (100% chance of success). */
6287 return N_("Build %sRoad%s");
6288 case ACTION_CONVERT:
6289 /* TRANS: _Convert Unit (100% chance of success). */
6290 return N_("%sConvert Unit%s");
6291 case ACTION_BASE:
6292 case ACTION_BASE2:
6293 /* TRANS: _Build Base (100% chance of success). */
6294 return N_("%sBuild Base%s");
6295 case ACTION_MINE:
6296 case ACTION_MINE2:
6297 /* TRANS: Build _Mine (100% chance of success). */
6298 return N_("Build %sMine%s");
6299 case ACTION_IRRIGATE:
6300 case ACTION_IRRIGATE2:
6301 /* TRANS: Build _Irrigation (100% chance of success). */
6302 return N_("Build %sIrrigation%s");
6304 /* TRANS: _Deboard (100% chance of success). */
6305 return N_("%sDeboard%s");
6309 /* TRANS: _Board (100% chance of success). */
6310 return N_("%sBoard%s");
6315 /* TRANS: _Embark (100% chance of success). */
6316 return N_("%sEmbark%s");
6318 /* TRANS: _Unload (100% chance of success). */
6319 return N_("%sUnload%s");
6323 /* TRANS: _Load (100% chance of success). */
6324 return N_("%sLoad%s");
6328 /* TRANS: _Disembark (100% chance of success). */
6329 return N_("%sDisembark%s");
6331 /* TRANS: _Disembark 2 (100% chance of success). */
6332 return N_("%sDisembark 2%s");
6333 case ACTION_SPY_ATTACK:
6334 /* TRANS: _Eliminate Diplomat (100% chance of success). */
6335 return N_("%sEliminate Diplomat%s");
6336 case ACTION_HUT_ENTER:
6337 case ACTION_HUT_ENTER2:
6338 case ACTION_HUT_ENTER3:
6339 case ACTION_HUT_ENTER4:
6340 /* TRANS: Enter _Hut (100% chance of success). */
6341 return N_("Enter %sHut%s");
6346 /* TRANS: Frighten _Hut (100% chance of success). */
6347 return N_("Frighten %sHut%s");
6348 case ACTION_UNIT_MOVE:
6349 case ACTION_UNIT_MOVE2:
6350 case ACTION_UNIT_MOVE3:
6351 /* TRANS: Regular _Move (100% chance of success). */
6352 return N_("Regular %sMove%s");
6353 case ACTION_TELEPORT:
6354 case ACTION_TELEPORT2:
6355 case ACTION_TELEPORT3:
6356 /* TRANS: _Teleport (100% chance of success). */
6357 return N_("%sTeleport%s");
6359 /* TRANS: _Teleport (100% chance of success). */
6360 return N_("%sTeleport%s");
6362 /* TRANS: _Teleport (100% chance of success). */
6363 return N_("%sTeleport%s");
6365 /* TRANS: _Teleport (100% chance of success). */
6366 return N_("%sTeleport%s");
6368 /* TRANS: _Teleport (100% chance of success). */
6369 return N_("%sTeleport%s");
6371 /* TRANS: _Teleport (100% chance of success). */
6372 return N_("%sTeleport%s");
6373 case ACTION_SPY_ESCAPE:
6374 /* TRANS: _Escape To Nearest City (100% chance of success). */
6375 return N_("%sEscape To Nearest City%s");
6377 /* TRANS: _User Action 1 (100% chance of success). */
6378 return N_("%sUser Action 1%s");
6380 /* TRANS: _User Action 2 (100% chance of success). */
6381 return N_("%sUser Action 2%s");
6383 /* TRANS: _User Action 3 (100% chance of success). */
6384 return N_("%sUser Action 3%s");
6386 /* TRANS: _User Action 4 (100% chance of success). */
6387 return N_("%sUser Action 4%s");
6389 return N_("%sGain Veterancy%s");
6390 case ACTION_ESCAPE:
6391 return N_("%sEscape%s");
6392 case ACTION_CIVIL_WAR:
6393 return N_("%sCivil War%s");
6394 case ACTION_FINISH_UNIT:
6395 return N_("Finish %sUnit%s");
6397 return N_("Finish %sBuilding%s");
6398 case ACTION_COUNT:
6399 fc_assert(act != ACTION_COUNT);
6400 break;
6401 }
6402
6403 return nullptr;
6404}
6405
6406/**********************************************************************/
6413{
6414 switch ((enum gen_action)act) {
6415 case ACTION_SPY_POISON:
6440 case ACTION_STEAL_MAPS:
6442 case ACTION_TRADE_ROUTE:
6443 case ACTION_MARKETPLACE:
6444 case ACTION_HELP_WONDER:
6446 case ACTION_EXPEL_UNIT:
6447 case ACTION_FOUND_CITY:
6448 case ACTION_JOIN_CITY:
6449 case ACTION_SPY_NUKE:
6454 case ACTION_HOME_CITY:
6455 case ACTION_HOMELESS:
6457 case ACTION_PARADROP:
6463 case ACTION_AIRLIFT:
6464 case ACTION_ATTACK:
6465 case ACTION_ATTACK2:
6468 case ACTION_WIPE_UNITS:
6476 case ACTION_HEAL_UNIT:
6477 case ACTION_HEAL_UNIT2:
6480 case ACTION_CULTIVATE:
6481 case ACTION_CULTIVATE2:
6482 case ACTION_PLANT:
6483 case ACTION_PLANT2:
6484 case ACTION_PILLAGE:
6485 case ACTION_PILLAGE2:
6486 case ACTION_CLEAN:
6487 case ACTION_CLEAN2:
6488 case ACTION_FORTIFY:
6489 case ACTION_FORTIFY2:
6490 case ACTION_ROAD:
6491 case ACTION_ROAD2:
6492 case ACTION_CONVERT:
6493 case ACTION_BASE:
6494 case ACTION_BASE2:
6495 case ACTION_MINE:
6496 case ACTION_MINE2:
6497 case ACTION_IRRIGATE:
6498 case ACTION_IRRIGATE2:
6515 case ACTION_BOMBARD:
6516 case ACTION_BOMBARD2:
6517 case ACTION_BOMBARD3:
6518 case ACTION_BOMBARD4:
6521 case ACTION_SPY_ATTACK:
6526 case ACTION_HUT_ENTER:
6527 case ACTION_HUT_ENTER2:
6528 case ACTION_HUT_ENTER3:
6529 case ACTION_HUT_ENTER4:
6534 case ACTION_UNIT_MOVE:
6535 case ACTION_UNIT_MOVE2:
6536 case ACTION_UNIT_MOVE3:
6537 case ACTION_SPY_ESCAPE:
6539 case ACTION_ESCAPE:
6540 case ACTION_CIVIL_WAR:
6541 case ACTION_FINISH_UNIT:
6543 /* Min range is not ruleset changeable */
6544 return nullptr;
6545 case ACTION_NUKE:
6546 return "explode_nuclear_min_range";
6547 case ACTION_NUKE_CITY:
6548 return "nuke_city_min_range";
6549 case ACTION_NUKE_UNITS:
6550 return "nuke_units_min_range";
6551 case ACTION_TELEPORT:
6552 return "teleport_min_range";
6553 case ACTION_TELEPORT2:
6554 return "teleport_2_min_range";
6555 case ACTION_TELEPORT3:
6556 return "teleport_3_min_range";
6558 return "teleport_conquer_min_range";
6560 return "teleport_frighten_min_range";
6562 return "teleport_frighten_conquer_min_range";
6564 return "teleport_enter_min_range";
6566 return "teleport_enter_conquer_min_range";
6568 return "user_action_1_min_range";
6570 return "user_action_2_min_range";
6572 return "user_action_3_min_range";
6574 return "user_action_4_min_range";
6575 case ACTION_COUNT:
6576 break;
6577
6579 }
6580
6581 fc_assert(act >= 0 && act < ACTION_COUNT);
6582
6583 return nullptr;
6584}
6585
6586/**********************************************************************/
6593{
6594 switch ((enum gen_action)act) {
6595 case ACTION_SPY_POISON:
6620 case ACTION_STEAL_MAPS:
6622 case ACTION_TRADE_ROUTE:
6623 case ACTION_MARKETPLACE:
6625 case ACTION_EXPEL_UNIT:
6626 case ACTION_FOUND_CITY:
6627 case ACTION_JOIN_CITY:
6628 case ACTION_SPY_NUKE:
6632 case ACTION_HOME_CITY:
6633 case ACTION_HOMELESS:
6635 case ACTION_PARADROP:
6641 case ACTION_ATTACK:
6642 case ACTION_ATTACK2:
6645 case ACTION_WIPE_UNITS:
6653 case ACTION_HEAL_UNIT:
6654 case ACTION_HEAL_UNIT2:
6657 case ACTION_CULTIVATE:
6658 case ACTION_CULTIVATE2:
6659 case ACTION_PLANT:
6660 case ACTION_PLANT2:
6661 case ACTION_PILLAGE:
6662 case ACTION_PILLAGE2:
6663 case ACTION_CLEAN:
6664 case ACTION_CLEAN2:
6665 case ACTION_FORTIFY:
6666 case ACTION_FORTIFY2:
6667 case ACTION_ROAD:
6668 case ACTION_ROAD2:
6669 case ACTION_CONVERT:
6670 case ACTION_BASE:
6671 case ACTION_BASE2:
6672 case ACTION_MINE:
6673 case ACTION_MINE2:
6674 case ACTION_IRRIGATE:
6675 case ACTION_IRRIGATE2:
6692 case ACTION_SPY_ATTACK:
6697 case ACTION_HUT_ENTER:
6698 case ACTION_HUT_ENTER2:
6699 case ACTION_HUT_ENTER3:
6700 case ACTION_HUT_ENTER4:
6705 case ACTION_UNIT_MOVE:
6706 case ACTION_UNIT_MOVE2:
6707 case ACTION_UNIT_MOVE3:
6708 case ACTION_SPY_ESCAPE:
6710 case ACTION_ESCAPE:
6711 case ACTION_CIVIL_WAR:
6712 case ACTION_FINISH_UNIT:
6714 /* Max range is not ruleset changeable */
6715 return nullptr;
6716 case ACTION_HELP_WONDER:
6717 return "help_wonder_max_range";
6719 return "disband_unit_recover_max_range";
6720 case ACTION_BOMBARD:
6721 return "bombard_max_range";
6722 case ACTION_BOMBARD2:
6723 return "bombard_2_max_range";
6724 case ACTION_BOMBARD3:
6725 return "bombard_3_max_range";
6726 case ACTION_BOMBARD4:
6727 return "bombard_4_max_range";
6729 return "bombard_lethal_max_range";
6731 return "bombard_lethal_2_max_range";
6732 case ACTION_NUKE:
6733 return "explode_nuclear_max_range";
6734 case ACTION_NUKE_CITY:
6735 return "nuke_city_max_range";
6736 case ACTION_NUKE_UNITS:
6737 return "nuke_units_max_range";
6738 case ACTION_AIRLIFT:
6739 return "airlift_max_range";
6740 case ACTION_TELEPORT:
6741 return "teleport_max_range";
6742 case ACTION_TELEPORT2:
6743 return "teleport_2_max_range";
6744 case ACTION_TELEPORT3:
6745 return "teleport_3_max_range";
6747 return "teleport_conquer_max_range";
6749 return "teleport_frighten_max_range";
6751 return "teleport_frighten_conquer_max_range";
6753 return "teleport_enter_max_range";
6755 return "teleport_enter_conquer_max_range";
6757 return "user_action_1_max_range";
6759 return "user_action_2_max_range";
6761 return "user_action_3_max_range";
6763 return "user_action_4_max_range";
6764 case ACTION_COUNT:
6765 break;
6766
6768 }
6769
6770 fc_assert(act >= 0 && act < ACTION_COUNT);
6771
6772 return nullptr;
6773}
6774
6775/**********************************************************************/
6782{
6783 switch ((enum gen_action)act) {
6784 case ACTION_SPY_POISON:
6809 case ACTION_STEAL_MAPS:
6811 case ACTION_TRADE_ROUTE:
6812 case ACTION_MARKETPLACE:
6813 case ACTION_HELP_WONDER:
6815 case ACTION_EXPEL_UNIT:
6816 case ACTION_FOUND_CITY:
6817 case ACTION_JOIN_CITY:
6818 case ACTION_SPY_NUKE:
6820 case ACTION_NUKE_UNITS:
6824 case ACTION_HOME_CITY:
6825 case ACTION_HOMELESS:
6827 case ACTION_PARADROP:
6833 case ACTION_AIRLIFT:
6834 case ACTION_ATTACK:
6835 case ACTION_ATTACK2:
6838 case ACTION_WIPE_UNITS:
6846 case ACTION_HEAL_UNIT:
6847 case ACTION_HEAL_UNIT2:
6850 case ACTION_CULTIVATE:
6851 case ACTION_CULTIVATE2:
6852 case ACTION_PLANT:
6853 case ACTION_PLANT2:
6854 case ACTION_CLEAN:
6855 case ACTION_CLEAN2:
6856 case ACTION_FORTIFY:
6857 case ACTION_FORTIFY2:
6858 case ACTION_ROAD:
6859 case ACTION_ROAD2:
6860 case ACTION_CONVERT:
6861 case ACTION_BASE:
6862 case ACTION_BASE2:
6863 case ACTION_MINE:
6864 case ACTION_MINE2:
6865 case ACTION_IRRIGATE:
6866 case ACTION_IRRIGATE2:
6883 case ACTION_BOMBARD:
6884 case ACTION_BOMBARD2:
6885 case ACTION_BOMBARD3:
6886 case ACTION_BOMBARD4:
6889 case ACTION_SPY_ATTACK:
6894 case ACTION_HUT_ENTER:
6895 case ACTION_HUT_ENTER2:
6896 case ACTION_HUT_ENTER3:
6897 case ACTION_HUT_ENTER4:
6902 case ACTION_UNIT_MOVE:
6903 case ACTION_UNIT_MOVE2:
6904 case ACTION_UNIT_MOVE3:
6905 case ACTION_TELEPORT:
6906 case ACTION_TELEPORT2:
6907 case ACTION_TELEPORT3:
6913 case ACTION_SPY_ESCAPE:
6915 case ACTION_ESCAPE:
6916 case ACTION_CIVIL_WAR:
6917 case ACTION_FINISH_UNIT:
6919 /* Target kind is not ruleset changeable */
6920 return nullptr;
6921 case ACTION_NUKE:
6922 return "explode_nuclear_target_kind";
6923 case ACTION_NUKE_CITY:
6924 return "nuke_city_target_kind";
6925 case ACTION_PILLAGE:
6926 return "pillage_target_kind";
6927 case ACTION_PILLAGE2:
6928 return "pillage_2_target_kind";
6930 return "user_action_1_target_kind";
6932 return "user_action_2_target_kind";
6934 return "user_action_3_target_kind";
6936 return "user_action_4_target_kind";
6937 case ACTION_COUNT:
6938 break;
6939
6941 }
6942
6943 fc_assert(act >= 0 && act < ACTION_COUNT);
6944
6945 return nullptr;
6946}
6947
6948/**********************************************************************/
6956{
6957 switch ((enum gen_action)act) {
6958 case ACTION_SPY_POISON:
6982 case ACTION_STEAL_MAPS:
6984 case ACTION_TRADE_ROUTE:
6985 case ACTION_MARKETPLACE:
6986 case ACTION_HELP_WONDER:
6988 case ACTION_EXPEL_UNIT:
6989 case ACTION_JOIN_CITY:
6990 case ACTION_SPY_NUKE:
6995 case ACTION_HOME_CITY:
6996 case ACTION_HOMELESS:
6998 case ACTION_PARADROP:
7004 case ACTION_AIRLIFT:
7005 case ACTION_ATTACK:
7006 case ACTION_ATTACK2:
7009 case ACTION_WIPE_UNITS:
7017 case ACTION_HEAL_UNIT:
7018 case ACTION_HEAL_UNIT2:
7021 case ACTION_CULTIVATE:
7022 case ACTION_CULTIVATE2:
7023 case ACTION_PLANT:
7024 case ACTION_PLANT2:
7025 case ACTION_PILLAGE:
7026 case ACTION_PILLAGE2:
7027 case ACTION_CLEAN:
7028 case ACTION_CLEAN2:
7029 case ACTION_FORTIFY:
7030 case ACTION_FORTIFY2:
7031 case ACTION_ROAD:
7032 case ACTION_ROAD2:
7033 case ACTION_CONVERT:
7034 case ACTION_BASE:
7035 case ACTION_BASE2:
7036 case ACTION_MINE:
7037 case ACTION_MINE2:
7038 case ACTION_IRRIGATE:
7039 case ACTION_IRRIGATE2:
7056 case ACTION_BOMBARD:
7057 case ACTION_BOMBARD2:
7058 case ACTION_BOMBARD3:
7059 case ACTION_BOMBARD4:
7062 case ACTION_SPY_ATTACK:
7067 case ACTION_HUT_ENTER:
7068 case ACTION_HUT_ENTER2:
7069 case ACTION_HUT_ENTER3:
7070 case ACTION_HUT_ENTER4:
7075 case ACTION_UNIT_MOVE:
7076 case ACTION_UNIT_MOVE2:
7077 case ACTION_UNIT_MOVE3:
7078 case ACTION_TELEPORT:
7079 case ACTION_TELEPORT2:
7080 case ACTION_TELEPORT3:
7086 case ACTION_SPY_ESCAPE:
7088 case ACTION_ESCAPE:
7089 case ACTION_CIVIL_WAR:
7090 case ACTION_FINISH_UNIT:
7092 /* Actor consuming always is not ruleset changeable */
7093 return nullptr;
7094 case ACTION_FOUND_CITY:
7095 return "found_city_consuming_always";
7096 case ACTION_NUKE:
7097 return "explode_nuclear_consuming_always";
7098 case ACTION_NUKE_CITY:
7099 return "nuke_city_consuming_always";
7100 case ACTION_NUKE_UNITS:
7101 return "nuke_units_consuming_always";
7103 return "spread_plague_actor_consuming_always";
7105 return "user_action_1_actor_consuming_always";
7107 return "user_action_2_actor_consuming_always";
7109 return "user_action_3_actor_consuming_always";
7111 return "user_action_4_actor_consuming_always";
7112 case ACTION_COUNT:
7113 break;
7114
7116 }
7117
7118 fc_assert(act >= 0 && act < ACTION_COUNT);
7119
7120 return nullptr;
7121}
7122
7123/**********************************************************************/
7130const char *action_blocked_by_ruleset_var_name(const struct action *act)
7131{
7132 fc_assert_ret_val(act != nullptr, nullptr);
7133
7134 switch ((enum gen_action)action_number(act)) {
7135 case ACTION_MARKETPLACE:
7136 return "enter_marketplace_blocked_by";
7137 case ACTION_BOMBARD:
7138 return "bombard_blocked_by";
7139 case ACTION_BOMBARD2:
7140 return "bombard_2_blocked_by";
7141 case ACTION_BOMBARD3:
7142 return "bombard_3_blocked_by";
7143 case ACTION_BOMBARD4:
7144 return "bombard_4_blocked_by";
7146 return "bombard_lethal_blocked_by";
7148 return "bombard_lethal_2_blocked_by";
7149 case ACTION_NUKE:
7150 return "explode_nuclear_blocked_by";
7151 case ACTION_NUKE_CITY:
7152 return "nuke_city_blocked_by";
7153 case ACTION_NUKE_UNITS:
7154 return "nuke_units_blocked_by";
7155 case ACTION_ATTACK:
7156 return "attack_blocked_by";
7157 case ACTION_ATTACK2:
7158 return "attack_2_blocked_by";
7160 return "suicide_attack_blocked_by";
7162 return "suicide_attack_2_blocked_by";
7163 case ACTION_WIPE_UNITS:
7164 return "wipe_units_blocked_by";
7166 return "collect_ransom_blocked_by";
7168 return "conquer_city_shrink_blocked_by";
7170 return "conquer_city_shrink_2_blocked_by";
7172 return "conquer_city_shrink_3_blocked_by";
7174 return "conquer_city_shrink_4_blocked_by";
7175 case ACTION_UNIT_MOVE:
7176 return "move_blocked_by";
7177 case ACTION_UNIT_MOVE2:
7178 return "move_2_blocked_by";
7179 case ACTION_UNIT_MOVE3:
7180 return "move_3_blocked_by";
7181 case ACTION_TELEPORT:
7182 return "teleport_blocked_by";
7183 case ACTION_TELEPORT2:
7184 return "teleport_2_blocked_by";
7185 case ACTION_TELEPORT3:
7186 return "teleport_3_blocked_by";
7188 return "teleport_conquer_blocked_by";
7190 return "teleport_frighten_blocked_by";
7192 return "teleport_frighten_conquer_blocked_by";
7194 return "teleport_enter_blocked_by";
7196 return "teleport_enter_conquer_blocked_by";
7197 case ACTION_SPY_ESCAPE:
7198 case ACTION_SPY_POISON:
7222 case ACTION_STEAL_MAPS:
7224 case ACTION_TRADE_ROUTE:
7225 case ACTION_HELP_WONDER:
7227 case ACTION_EXPEL_UNIT:
7228 case ACTION_FOUND_CITY:
7229 case ACTION_JOIN_CITY:
7230 case ACTION_SPY_NUKE:
7235 case ACTION_HOME_CITY:
7236 case ACTION_HOMELESS:
7238 case ACTION_PARADROP:
7244 case ACTION_AIRLIFT:
7247 case ACTION_HEAL_UNIT:
7248 case ACTION_HEAL_UNIT2:
7251 case ACTION_CULTIVATE:
7252 case ACTION_CULTIVATE2:
7253 case ACTION_PLANT:
7254 case ACTION_PLANT2:
7255 case ACTION_PILLAGE:
7256 case ACTION_PILLAGE2:
7257 case ACTION_CLEAN:
7258 case ACTION_CLEAN2:
7259 case ACTION_FORTIFY:
7260 case ACTION_FORTIFY2:
7261 case ACTION_ROAD:
7262 case ACTION_ROAD2:
7263 case ACTION_CONVERT:
7264 case ACTION_BASE:
7265 case ACTION_BASE2:
7266 case ACTION_MINE:
7267 case ACTION_MINE2:
7268 case ACTION_IRRIGATE:
7269 case ACTION_IRRIGATE2:
7287 case ACTION_SPY_ATTACK:
7292 case ACTION_HUT_ENTER:
7293 case ACTION_HUT_ENTER2:
7294 case ACTION_HUT_ENTER3:
7295 case ACTION_HUT_ENTER4:
7301 case ACTION_CIVIL_WAR:
7302 case ACTION_FINISH_UNIT:
7304 case ACTION_ESCAPE:
7309 /* blocked_by is not ruleset changeable */
7310 return nullptr;
7311 case ACTION_COUNT:
7313 break;
7314
7316 }
7317
7318 return nullptr;
7319}
7320
7321/**********************************************************************/
7325const char *
7327{
7328 fc_assert_ret_val(act != nullptr, nullptr);
7329
7335 /* No support in the action performer function */
7336 return nullptr;
7337 }
7338
7339 switch ((enum gen_action)action_number(act)) {
7341 return "bribe_unit_post_success_forced_actions";
7343 return "bribe_stack_post_success_forced_actions";
7344 case ACTION_ATTACK:
7345 return "attack_post_success_forced_actions";
7346 case ACTION_ATTACK2:
7347 return "attack_2_post_success_forced_actions";
7348 case ACTION_WIPE_UNITS:
7349 return "wipe_units_post_success_forced_actions";
7351 return "collect_ransom_post_success_forced_actions";
7352 case ACTION_MARKETPLACE:
7353 case ACTION_BOMBARD:
7354 case ACTION_BOMBARD2:
7355 case ACTION_BOMBARD3:
7356 case ACTION_BOMBARD4:
7359 case ACTION_NUKE:
7360 case ACTION_NUKE_CITY:
7361 case ACTION_NUKE_UNITS:
7368 case ACTION_SPY_POISON:
7390 case ACTION_STEAL_MAPS:
7392 case ACTION_TRADE_ROUTE:
7393 case ACTION_HELP_WONDER:
7395 case ACTION_EXPEL_UNIT:
7396 case ACTION_FOUND_CITY:
7397 case ACTION_JOIN_CITY:
7398 case ACTION_SPY_NUKE:
7403 case ACTION_HOME_CITY:
7404 case ACTION_HOMELESS:
7406 case ACTION_PARADROP:
7412 case ACTION_AIRLIFT:
7415 case ACTION_HEAL_UNIT:
7416 case ACTION_HEAL_UNIT2:
7419 case ACTION_CULTIVATE:
7420 case ACTION_CULTIVATE2:
7421 case ACTION_PLANT:
7422 case ACTION_PLANT2:
7423 case ACTION_PILLAGE:
7424 case ACTION_PILLAGE2:
7425 case ACTION_CLEAN:
7426 case ACTION_CLEAN2:
7427 case ACTION_FORTIFY:
7428 case ACTION_FORTIFY2:
7429 case ACTION_ROAD:
7430 case ACTION_ROAD2:
7431 case ACTION_CONVERT:
7432 case ACTION_BASE:
7433 case ACTION_BASE2:
7434 case ACTION_MINE:
7435 case ACTION_MINE2:
7436 case ACTION_IRRIGATE:
7437 case ACTION_IRRIGATE2:
7455 case ACTION_SPY_ATTACK:
7460 case ACTION_HUT_ENTER:
7461 case ACTION_HUT_ENTER2:
7462 case ACTION_HUT_ENTER3:
7463 case ACTION_HUT_ENTER4:
7468 case ACTION_UNIT_MOVE:
7469 case ACTION_UNIT_MOVE2:
7470 case ACTION_UNIT_MOVE3:
7471 case ACTION_TELEPORT:
7472 case ACTION_TELEPORT2:
7473 case ACTION_TELEPORT3:
7479 case ACTION_SPY_ESCAPE:
7481 case ACTION_ESCAPE:
7482 case ACTION_CIVIL_WAR:
7483 case ACTION_FINISH_UNIT:
7489 /* Not ruleset changeable */
7490 return nullptr;
7491 case ACTION_COUNT:
7493 break;
7494
7496 }
7497
7498 return nullptr;
7499}
7500
7501/**********************************************************************/
7509
7510/**********************************************************************/
7513const char *gen_action_name_update_cb(const char *old_name)
7514{
7515 if (is_ruleset_compat_mode()) {
7516 }
7517
7518 return old_name;
7519}
7520
7522{
7523 N_("individual cities"), /* ATK_CITY */
7524 N_("individual units"), /* ATK_UNIT */
7525 N_("unit stacks"), /* ATK_STACK */
7526 N_("tiles"), /* ATK_TILE */
7527 N_("tile extras"), /* ATK_EXTRAS */
7528 N_("itself") /* ATK_SELF */
7529};
7530
7531/**********************************************************************/
7536{
7537 fc_assert(kind >= 0 && kind < ATK_COUNT);
7538
7539 return _(atk_helpnames[kind]);
7540}
7541
7542/************************************************************************/
7546{
7547 fc_assert(result < ACTRES_LAST);
7548
7549 return actlist_by_result[result];
7550}
7551
7552/************************************************************************/
7556{
7557 fc_assert(activity < ACTIVITY_LAST);
7558
7559 return actlist_by_activity[activity];
7560}
7561
7562/************************************************************************/
7567 enum action_result actres,
7568 struct unit *punit,
7569 struct tile *ptile)
7570{
7571 if (actres >= ACTRES_LAST) {
7572 return ACTION_NONE;
7573 }
7574
7576 enum gen_action act = action_number(paction);
7577
7578 if (is_action_enabled_unit_on_stack(nmap, act, punit, ptile)) {
7579 return act;
7580 }
7582
7583 return ACTION_NONE;
7584}
7585
7586/************************************************************************/
7591 enum action_result actres,
7592 struct unit *punit,
7593 struct tile *ptile)
7594{
7595 if (actres >= ACTRES_LAST) {
7596 return ACTION_NONE;
7597 }
7598
7600 enum gen_action act = action_number(paction);
7601
7603 && is_action_enabled_unit_on_tile(nmap, act, punit, ptile, nullptr)) {
7604 return act;
7605 }
7607
7608 return ACTION_NONE;
7609}
7610
7611/************************************************************************/
7616 enum action_result actres,
7617 struct unit *punit,
7618 struct city *pcity)
7619{
7620 if (actres >= ACTRES_LAST) {
7621 return ACTION_NONE;
7622 }
7623
7625 enum gen_action act = action_number(paction);
7626
7629 return act;
7630 }
7632
7633 return ACTION_NONE;
7634}
bool is_action_possible_on_city(action_id act_id, const struct player *actor_player, const struct city *target_city)
Definition actions.c:5722
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:1333
bool action_distance_inside_max(const struct action *action, const int distance)
Definition actions.c:1194
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:5210
static enum fc_tristate is_action_possible(const struct civ_map *nmap, const action_id wanted_action, const struct req_context *actor, const struct req_context *target, const struct extra_type *target_extra, const bool omniscient, const struct city *homecity)
Definition actions.c:2814
const char * action_prob_explain(const struct act_prob prob)
Definition actions.c:1444
bool action_mp_full_makes_legal(const struct unit *actor, const action_id act_id)
Definition actions.c:5800
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:4025
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:3443
enum action_actor_kind action_get_actor_kind(const struct action *paction)
Definition actions.c:1119
bool action_prob_certain(const struct act_prob probability)
Definition actions.c:5332
const char * action_id_name_translation(action_id act_id)
Definition actions.c:1271
struct action_auto_perf * action_auto_perf_slot_number(const int num)
Definition actions.c:5961
req_vec_num_in_item action_enabler_vector_number(const void *enabler, const struct requirement_vector *vec)
Definition actions.c:2048
bool action_has_complex_target(const struct action *paction)
Definition actions.c:1153
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:2397
#define ASSERT_PLAYER_ACTION(_atk)
Definition actions.c:3504
struct req_vec_problem * action_enabler_suggest_repair(const struct action_enabler *enabler)
Definition actions.c:1918
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:3288
bool action_prob_possible(const struct act_prob probability)
Definition actions.c:5322
#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:2606
struct act_prob action_prob_new_not_impl(void)
Definition actions.c:5301
struct req_vec_problem * action_enabler_suggest_improvement(const struct action_enabler *enabler)
Definition actions.c:1984
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:3752
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:5143
void actions_rs_pre_san_gen(void)
Definition actions.c:899
const char * action_min_range_ruleset_var_name(int act)
Definition actions.c:6412
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:5244
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:3799
const char * action_blocked_by_ruleset_var_name(const struct action *act)
Definition actions.c:7130
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:2990
#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:4073
struct req_vec_problem * action_enabler_suggest_repair_oblig(const struct action_enabler *enabler)
Definition actions.c:1704
void action_array_add_all_by_result(action_id *act_array, int *position, enum action_result result)
Definition actions.c:6026
const char * action_name_translation(const struct action *paction)
Definition actions.c:1251
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:5622
void action_array_end(action_id *act_array, int size)
Definition actions.c:6009
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:4843
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:3977
const char * atk_helpnames[ATK_COUNT]
Definition actions.c:7521
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:2626
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:3040
bool action_is_in_use(struct action *paction)
Definition actions.c:5915
static struct req_vec_problem * enabler_tile_tgt_local_diplrel_implies_claimed(const struct action_enabler *enabler)
Definition actions.c:1773
bool action_ever_possible(action_id action)
Definition actions.c:7505
const char * action_enabler_vector_by_number_name(req_vec_num_in_item vec)
Definition actions.c:2095
bool are_action_probabilitys_equal(const struct act_prob *ap1, const struct act_prob *ap2)
Definition actions.c:5373
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:3659
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:4943
const char * action_post_success_forced_ruleset_var_name(const struct action *act)
Definition actions.c:7326
struct action * action_by_rule_name(const char *name)
Definition actions.c:1100
static bool action_has_possible_actor_hard_reqs(struct action *paction)
Definition actions.c:5885
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:7566
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:975
const char * action_rule_name(const struct action *action)
Definition actions.c:1237
const char * action_id_rule_name(action_id act_id)
Definition actions.c:1260
enum action_sub_target_kind action_get_sub_target_kind(const struct action *paction)
Definition actions.c:1140
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:2163
static bool action_prob_not_relevant(const struct act_prob probability)
Definition actions.c:5343
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:3931
void actions_free(void)
Definition actions.c:909
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:3365
void action_enabler_free(struct action_enabler *enabler)
Definition actions.c:1516
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:3270
static enum fc_tristate tech_can_be_stolen(const struct player *actor_player, const struct player *target_player)
Definition actions.c:3818
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:7555
int action_number(const struct action *action)
Definition actions.c:1229
struct act_prob action_prob_new_unknown(void)
Definition actions.c:5311
bool action_would_be_blocked_by(const struct action *blocked, const struct action *blocker)
Definition actions.c:1217
#define ACTPROB_VAL_NA
Definition actions.c:53
static struct action * player_action_new(action_id id, enum action_result result)
Definition actions.c:1065
static struct req_vec_problem * enabler_first_clarification(const struct action_enabler *enabler)
Definition actions.c:1966
static bool action_prob_not_impl(const struct act_prob probability)
Definition actions.c:5354
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:3346
struct act_prob action_prob_and(const struct act_prob *ap1, const struct act_prob *ap2)
Definition actions.c:5460
static bool actions_initialized
Definition actions.c:60
const char * action_actor_consuming_always_ruleset_var_name(action_id act)
Definition actions.c:6955
bool action_immune_government(struct government *gov, action_id act)
Definition actions.c:5678
static bool is_target_possible(const action_id wanted_action, const struct player *actor_player, const struct req_context *target)
Definition actions.c:5701
static struct action * city_action_new(action_id id, enum action_result result)
Definition actions.c:1077
static struct act_prob ap_dipl_battle_win(const struct unit *pattacker, const struct unit *pdefender)
Definition actions.c:3854
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:4585
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:4926
struct act_prob action_prob_new_certain(void)
Definition actions.c:5281
const char * action_max_range_ruleset_var_name(int act)
Definition actions.c:6592
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:4398
bool action_is_internal(struct action *paction)
Definition actions.c:5941
int action_dice_roll_initial_odds(const struct action *paction)
Definition actions.c:5598
struct act_prob action_prob_self(const struct civ_map *nmap, const struct unit *actor_unit, const action_id act_id)
Definition actions.c:4996
struct act_prob action_prob_fall_back(const struct act_prob *ap1, const struct act_prob *ap2)
Definition actions.c:5530
static const struct unit_type * tgt_city_local_utype(const struct city *target_city)
Definition actions.c:2138
bool is_action_enabled_city(const struct civ_map *nmap, const action_id wanted_action, const struct city *actor_city)
Definition actions.c:3720
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:3614
static struct requirement * req_vec_first_local_diplrel(const struct requirement_vector *vec)
Definition actions.c:1754
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:4777
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:3545
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:3105
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:7590
struct action_list * action_list_by_result(enum action_result result)
Definition actions.c:7545
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:3523
bool action_univs_not_blocking(const struct action *paction, struct universal *actor_uni, struct universal *target_uni)
Definition actions.c:5985
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:5075
bool actions_are_ready(void)
Definition actions.c:951
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:3182
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:5176
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:4485
const char * action_target_kind_ruleset_var_name(int act)
Definition actions.c:6781
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:4501
bool action_maybe_possible_actor_unit(const struct civ_map *nmap, const action_id act_id, const struct unit *actor_unit)
Definition actions.c:5745
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:2282
static bool is_enabler_active(const struct action_enabler *enabler, const struct req_context *actor, const struct req_context *target)
Definition actions.c:2973
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:1547
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:3583
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:3690
const char * action_ui_name_default(int act)
Definition actions.c:6044
bool action_enablers_allow(const action_id wanted_action, const struct req_context *actor, const struct req_context *target)
Definition actions.c:3019
#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:5823
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:3959
struct action_enabler * action_enabler_new(void)
Definition actions.c:1496
bool action_requires_details(const struct action *paction)
Definition actions.c:1166
struct act_prob action_prob_new_not_relevant(void)
Definition actions.c:5291
const char * action_target_kind_help(enum action_target_kind kind)
Definition actions.c:7535
static struct req_vec_problem * enabler_first_self_contradiction(const struct action_enabler *enabler)
Definition actions.c:1846
int action_get_role(const struct action *paction)
Definition actions.c:1484
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:5110
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:1040
const struct action_auto_perf * action_auto_perf_by_number(const int num)
Definition actions.c:5977
struct act_prob action_prob_new_impossible(void)
Definition actions.c:5271
bool action_enabler_possible_actor(const struct action_enabler *ae)
Definition actions.c:5850
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:2223
struct action ** _actions
Definition actions.c:58
bool action_id_exists(const action_id act_id)
Definition actions.c:1089
bool action_enabler_remove(struct action_enabler *enabler)
Definition actions.c:1564
enum action_target_kind action_get_target_kind(const struct action *paction)
Definition actions.c:1129
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:5018
static bool action_prob_is_signal(const struct act_prob probability)
Definition actions.c:5365
struct action_enabler * action_enabler_copy(const struct action_enabler *original)
Definition actions.c:1532
static const char * action_prob_to_text(const struct act_prob prob)
Definition actions.c:1292
int action_prob_cmp_pessimist(const struct act_prob ap1, const struct act_prob ap2)
Definition actions.c:5382
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:4760
bool action_id_is_internal(action_id act)
Definition actions.c:5953
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:3495
bool action_id_is_rare_pop_up(action_id act_id)
Definition actions.c:1181
void actions_init(void)
Definition actions.c:850
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:1600
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:4568
static const struct impr_type * tgt_city_local_building(const struct city *target_city)
Definition actions.c:2115
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:3423
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:3123
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:3200
double action_prob_to_0_to_1_pessimist(const struct act_prob ap)
Definition actions.c:5433
const char * gen_action_name_update_cb(const char *old_name)
Definition actions.c:7513
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:7615
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:1580
struct requirement_vector * action_enabler_vector_by_number(const void *enabler, req_vec_num_in_item number)
Definition actions.c:2071
bool action_distance_accepted(const struct action *action, const int distance)
Definition actions.c:1205
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:4860
const char * action_get_ui_name_mnemonic(action_id act_id, const char *mnemonic)
Definition actions.c:1279
#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:208
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