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:
2578 case ACTRES_NONE:
2579 /* No hard unit type requirements. */
2580 break;
2581
2583 }
2584
2585 return TRUE;
2586}
2587
2588/**********************************************************************/
2604bool
2611
2612/**********************************************************************/
2624static enum fc_tristate
2626 const struct action *paction,
2627 const struct req_context *actor,
2628 const bool omniscient,
2629 const struct city *homecity)
2630{
2631 enum action_result result = paction->result;
2632
2633 if (actor == nullptr) {
2635 }
2636
2638 TRUE)) {
2639 /* Info leak: The actor player knows the type of their unit. */
2640 /* The actor unit type can't perform the action because of hard
2641 * unit type requirements. */
2642 return TRI_NO;
2643 }
2644
2645 switch (result) {
2646 case ACTRES_PARADROP:
2648 /* Reason: Keep the old rules. */
2649 /* Info leak: The player knows if their unit already has paradropped this
2650 * turn. */
2651 if (actor->unit->paradropped) {
2652 return TRI_NO;
2653 }
2654
2655 break;
2656
2657 case ACTRES_AIRLIFT:
2658 {
2659 /* Obligatory hard requirement. Checked here too since
2660 * action_hard_reqs_actor() may be called before any
2661 * action enablers are checked. */
2662 if (actor->city == nullptr) {
2663 /* No city to airlift from. */
2664 return TRI_NO;
2665 }
2666
2667 if (actor->player != city_owner(actor->city)
2669 && pplayers_allied(actor->player,
2670 city_owner(actor->city)))) {
2671 /* Not allowed to airlift from this source. */
2672 return TRI_NO;
2673 }
2674
2675 if (!(omniscient || city_owner(actor->city) == actor->player)) {
2676 /* Can't check for airlifting capacity. */
2677 return TRI_MAYBE;
2678 }
2679
2680 if (0 >= actor->city->airlift
2683 /* The source cannot airlift for this turn (maybe already airlifted
2684 * or no airport).
2685 *
2686 * See also do_airline() in server/unittools.h. */
2687 return TRI_NO;
2688 }
2689 }
2690 break;
2691
2692 case ACTRES_CONVERT:
2693 /* Reason: Keep the old rules. */
2694 /* Info leak: The player knows their unit's cargo and location. */
2695 if (!unit_can_convert(nmap, actor->unit)) {
2696 return TRI_NO;
2697 }
2698 break;
2699
2702 if (unit_transported(actor->unit)) {
2703 if (!can_unit_unload(actor->unit, unit_transport_get(actor->unit))) {
2704 /* Can't leave current transport. */
2705 return TRI_NO;
2706 }
2707 }
2708 break;
2709
2711 if (!can_unit_unload(actor->unit, unit_transport_get(actor->unit))) {
2712 /* Keep the old rules about Unreachable and disembarks. */
2713 return TRI_NO;
2714 }
2715 break;
2716
2717 case ACTRES_HOMELESS:
2718 case ACTRES_UNIT_MOVE:
2719 case ACTRES_TELEPORT:
2723 case ACTRES_SPY_POISON:
2732 case ACTRES_SPY_ESCAPE:
2733 case ACTRES_TRADE_ROUTE:
2734 case ACTRES_MARKETPLACE:
2735 case ACTRES_HELP_WONDER:
2740 case ACTRES_FOUND_CITY:
2741 case ACTRES_JOIN_CITY:
2742 case ACTRES_STEAL_MAPS:
2743 case ACTRES_BOMBARD:
2744 case ACTRES_SPY_NUKE:
2745 case ACTRES_NUKE:
2746 case ACTRES_NUKE_UNITS:
2748 case ACTRES_EXPEL_UNIT:
2751 case ACTRES_HOME_CITY:
2753 case ACTRES_ATTACK:
2754 case ACTRES_WIPE_UNITS:
2760 case ACTRES_HEAL_UNIT:
2762 case ACTRES_CULTIVATE:
2763 case ACTRES_PLANT:
2764 case ACTRES_PILLAGE:
2765 case ACTRES_CLEAN:
2766 case ACTRES_FORTIFY:
2767 case ACTRES_ROAD:
2768 case ACTRES_BASE:
2769 case ACTRES_MINE:
2770 case ACTRES_IRRIGATE:
2774 case ACTRES_SPY_ATTACK:
2775 case ACTRES_HUT_ENTER:
2778 case ACTRES_NONE:
2779 /* No hard unit requirements. */
2780 break;
2781
2783 }
2784
2785 return TRI_YES;
2786}
2787
2788/**********************************************************************/
2811static enum fc_tristate
2814 const struct req_context *actor,
2815 const struct req_context *target,
2816 const struct extra_type *target_extra,
2817 const bool omniscient,
2818 const struct city *homecity)
2819{
2820 enum fc_tristate out;
2823 const struct tile *atile = nullptr, *ttile = nullptr;
2824
2825 if (actor == nullptr) {
2827 } else {
2828 atile = actor->tile;
2829 }
2830 if (target == nullptr) {
2831 target = req_context_empty();
2832 } else {
2833 ttile = target->tile;
2834 }
2835
2836 fc_assert_msg((tkind == ATK_CITY && target->city != nullptr)
2837 || (tkind == ATK_TILE && ttile != nullptr)
2838 || (tkind == ATK_EXTRAS && ttile != nullptr)
2839 || (tkind == ATK_UNIT && target->unit != nullptr)
2840 /* At this level each individual unit is tested. */
2841 || (tkind == ATK_STACK && target->unit != nullptr)
2842 || (tkind == ATK_SELF),
2843 "Missing target!");
2844
2845 /* Info leak: The player knows where their unit/city is. */
2846 if (nullptr != atile && nullptr != ttile
2849 /* The distance between the actor and the target isn't inside the
2850 * action's accepted range. */
2851 return TRI_NO;
2852 }
2853
2854 switch (tkind) {
2855 case ATK_UNIT:
2856 /* The Freeciv code for all actions that is controlled by action
2857 * enablers and targets a unit assumes that the acting
2858 * player can see the target unit.
2859 * Examples:
2860 * - action_prob_vs_unit()'s quick check that the distance between actor
2861 * and target is acceptable would leak distance to target unit if the
2862 * target unit can't be seen.
2863 */
2864 if (!can_player_see_unit(actor->player, target->unit)) {
2865 return TRI_NO;
2866 }
2867 break;
2868 case ATK_CITY:
2869 /* The Freeciv code assumes that the player is aware of the target
2870 * city's existence. (How can you order an airlift to a city when you
2871 * don't know its city ID?) */
2873 actor->player)
2874 != target->city->id) {
2875 return TRI_NO;
2876 }
2877 break;
2878 case ATK_STACK:
2879 case ATK_TILE:
2880 case ATK_EXTRAS:
2881 case ATK_SELF:
2882 /* No special player knowledge checks. */
2883 break;
2884 case ATK_COUNT:
2886 break;
2887 }
2888
2890 ttile, target->city, target->unit)) {
2891 /* Allows an action to block an other action. If a blocking action is
2892 * legal the actions it blocks becomes illegal. */
2893 return TRI_NO;
2894 }
2895
2896 /* Actor specific hard requirements. */
2898
2899 if (out == TRI_NO) {
2900 /* Illegal because of a hard actor requirement. */
2901 return TRI_NO;
2902 }
2903
2904 /* Quick checks for action itself */
2905 if (paction->result == ACTRES_ATTACK
2906 || paction->result == ACTRES_WIPE_UNITS
2907 || paction->result == ACTRES_COLLECT_RANSOM) {
2908 /* Reason: Keep the old rules. */
2909 if (!can_unit_attack_tile(actor->unit, paction, ttile)) {
2910 return TRI_NO;
2911 }
2912 }
2913
2914 /* Hard requirements for results. */
2916 paction->result, actor,
2917 target, target_extra, out, omniscient,
2918 homecity);
2919
2920 if (out == TRI_NO) {
2921 /* Illegal because of a hard actor requirement. */
2922 return TRI_NO;
2923 }
2924
2925 if (paction->result == ACTRES_NUKE_UNITS) {
2927 != ATT_OK) {
2928 /* Unreachable. */
2929 return TRI_NO;
2930 }
2931 } else if (paction->result == ACTRES_PARADROP
2932 || paction->result == ACTRES_PARADROP_CONQUER) {
2933 if (can_player_see_tile(actor->player, ttile)) {
2934 /* Check for seen stuff that may kill the actor unit. */
2935
2936 /* Reason: Keep the old rules. Be merciful. */
2937 /* Info leak: The player sees the target tile. */
2939 && (!BV_ISSET(paction->sub_results, ACT_SUB_RES_MAY_EMBARK)
2940 || !unit_could_load_at(actor->unit, ttile))) {
2941 return TRI_NO;
2942 }
2943
2944 /* Reason: Keep the old rules. Be merciful. */
2945 /* Info leak: The player sees the target tile. */
2946 if (is_non_attack_city_tile(ttile, actor->player)) {
2947 return TRI_NO;
2948 }
2949
2950 /* Reason: Be merciful. */
2951 /* Info leak: The player sees all units checked. Invisible units are
2952 * ignored. */
2953 unit_list_iterate(ttile->units, pother) {
2954 if (can_player_see_unit(actor->player, pother)
2955 && !pplayers_allied(actor->player, unit_owner(pother))) {
2956 return TRI_NO;
2957 }
2959 }
2960 }
2961
2962 return out;
2963}
2964
2965/**********************************************************************/
2971static bool is_enabler_active(const struct action_enabler *enabler,
2972 const struct req_context *actor,
2973 const struct req_context *target)
2974{
2975 return are_reqs_active(actor, target, &enabler->actor_reqs, RPT_CERTAIN)
2976 && are_reqs_active(target, actor, &enabler->target_reqs, RPT_CERTAIN);
2977}
2978
2979/**********************************************************************/
2988static bool is_action_enabled(const struct civ_map *nmap,
2990 const struct req_context *actor,
2991 const struct req_context *target,
2992 const struct extra_type *target_extra,
2993 const struct city *actor_home)
2994{
2995 enum fc_tristate possible;
2996
2998 TRUE, actor_home);
2999
3000 if (possible != TRI_YES) {
3001 /* This context is omniscient. Should be yes or no. */
3003 "Is omniscient, should get yes or no.");
3004
3005 /* The action enablers are irrelevant since the action it self is
3006 * impossible. */
3007 return FALSE;
3008 }
3009
3010 return action_enablers_allow(wanted_action, actor, target);
3011}
3012
3013/**********************************************************************/
3018 const struct req_context *actor,
3019 const struct req_context *target)
3020{
3022 enabler) {
3023 if (is_enabler_active(enabler, actor, target)) {
3024 return TRUE;
3025 }
3027
3028 return FALSE;
3029}
3030
3031/**********************************************************************/
3037static bool
3040 const struct unit *actor_unit,
3041 const struct city *actor_home,
3042 const struct tile *actor_tile,
3043 const struct city *target_city)
3044{
3045 const struct impr_type *target_building;
3046 const struct unit_type *target_utype;
3047
3048 if (actor_unit == nullptr || target_city == nullptr) {
3049 /* Can't do an action when actor or target are missing. */
3050 return FALSE;
3051 }
3052
3054 FALSE, "Action %s is performed by %s not %s",
3059
3062 FALSE, "Action %s is against %s not %s",
3067
3069
3071 /* No point in continuing. */
3072 return FALSE;
3073 }
3074
3077
3079 &(const struct req_context) {
3080 .player = unit_owner(actor_unit),
3081 .city = tile_city(actor_tile),
3082 .tile = actor_tile,
3083 .unit = actor_unit,
3084 .unittype = unit_type_get(actor_unit),
3085 },
3086 &(const struct req_context) {
3087 .player = city_owner(target_city),
3088 .city = target_city,
3089 .building = target_building,
3091 .unittype = target_utype,
3092 },
3093 nullptr,
3094 actor_home);
3095}
3096
3097/**********************************************************************/
3113
3114/**********************************************************************/
3120static bool
3123 const struct unit *actor_unit,
3124 const struct city *actor_home,
3125 const struct tile *actor_tile,
3126 const struct unit *target_unit)
3127{
3128 if (actor_unit == nullptr || target_unit == nullptr) {
3129 /* Can't do an action when actor or target are missing. */
3130 return FALSE;
3131 }
3132
3134 FALSE, "Action %s is performed by %s not %s",
3139
3142 FALSE, "Action %s is against %s not %s",
3147
3149
3151 /* No point in continuing. */
3152 return FALSE;
3153 }
3154
3156 &(const struct req_context) {
3157 .player = unit_owner(actor_unit),
3158 .city = tile_city(actor_tile),
3159 .tile = actor_tile,
3160 .unit = actor_unit,
3161 .unittype = unit_type_get(actor_unit),
3162 },
3163 &(const struct req_context) {
3164 .player = unit_owner(target_unit),
3167 .unit = target_unit,
3168 .unittype = unit_type_get(target_unit),
3169 },
3170 nullptr,
3171 actor_home);
3172}
3173
3174/**********************************************************************/
3190
3191/**********************************************************************/
3197static bool
3200 const struct unit *actor_unit,
3201 const struct city *actor_home,
3202 const struct tile *actor_tile,
3203 const struct tile *target_tile)
3204{
3205 const struct req_context *actor_ctxt;
3206
3207 if (actor_unit == nullptr || target_tile == nullptr
3208 || unit_list_size(target_tile->units) == 0) {
3209 /* Can't do an action when actor or target are missing. */
3210 return FALSE;
3211 }
3212
3214 FALSE, "Action %s is performed by %s not %s",
3219
3222 FALSE, "Action %s is against %s not %s",
3227
3229
3231 /* No point in continuing. */
3232 return FALSE;
3233 }
3234
3235 actor_ctxt = &(const struct req_context) {
3236 .player = unit_owner(actor_unit),
3237 .city = tile_city(actor_tile),
3238 .tile = actor_tile,
3239 .unit = actor_unit,
3240 .unittype = unit_type_get(actor_unit),
3241 };
3242
3245 &(const struct req_context) {
3246 .player = unit_owner(target_unit),
3249 .unit = target_unit,
3250 .unittype = unit_type_get(target_unit),
3251 },
3252 nullptr, actor_home)) {
3253 /* One unit makes it impossible for all units. */
3254 return FALSE;
3255 }
3257
3258 /* Not impossible for any of the units at the tile. */
3259 return TRUE;
3260}
3261
3262/**********************************************************************/
3278
3279/**********************************************************************/
3285static bool
3288 const struct unit *actor_unit,
3289 const struct city *actor_home,
3290 const struct tile *actor_tile,
3291 const struct tile *target_tile,
3292 const struct extra_type *target_extra)
3293{
3294 if (actor_unit == nullptr || target_tile == nullptr) {
3295 /* Can't do an action when actor or target are missing. */
3296 return FALSE;
3297 }
3298
3300 FALSE, "Action %s is performed by %s not %s",
3305
3308 FALSE, "Action %s is against %s not %s",
3313
3315
3317 /* No point in continuing. */
3318 return FALSE;
3319 }
3320
3322 &(const struct req_context) {
3323 .player = unit_owner(actor_unit),
3324 .city = tile_city(actor_tile),
3325 .tile = actor_tile,
3326 .unit = actor_unit,
3327 .unittype = unit_type_get(actor_unit),
3328 },
3329 &(const struct req_context) {
3330 .player = tile_owner(target_tile),
3331 .city = tile_city(target_tile),
3332 .tile = target_tile,
3333 },
3335 actor_home);
3336}
3337
3338/**********************************************************************/
3346 const struct unit *actor_unit,
3347 const struct tile *target_tile,
3348 const struct extra_type *target_extra)
3349{
3354}
3355
3356/**********************************************************************/
3362static bool
3365 const struct unit *actor_unit,
3366 const struct city *actor_home,
3367 const struct tile *actor_tile,
3368 const struct tile *target_tile,
3369 const struct extra_type *target_extra)
3370{
3371 if (actor_unit == nullptr || target_tile == nullptr) {
3372 /* Can't do an action when actor or target are missing. */
3373 return FALSE;
3374 }
3375
3377 FALSE, "Action %s is performed by %s not %s",
3382
3385 FALSE, "Action %s is against %s not %s",
3390
3392
3394 /* No point in continuing. */
3395 return FALSE;
3396 }
3397
3399 &(const struct req_context) {
3400 .player = unit_owner(actor_unit),
3401 .city = tile_city(actor_tile),
3402 .tile = actor_tile,
3403 .unit = actor_unit,
3404 .unittype = unit_type_get(actor_unit),
3405 },
3406 &(const struct req_context) {
3407 .player = target_tile->extras_owner,
3408 .city = tile_city(target_tile),
3409 .tile = target_tile,
3410 },
3412 actor_home);
3413}
3414
3415/**********************************************************************/
3432
3433/**********************************************************************/
3440static bool
3443 const struct unit *actor_unit,
3444 const struct city *actor_home,
3445 const struct tile *actor_tile)
3446{
3447 if (actor_unit == nullptr) {
3448 /* Can't do an action when the actor is missing. */
3449 return FALSE;
3450 }
3451
3453 FALSE, "Action %s is performed by %s not %s",
3458
3461 FALSE, "Action %s is against %s not %s",
3466
3468
3470 /* No point in continuing. */
3471 return FALSE;
3472 }
3473
3475 &(const struct req_context) {
3476 .player = unit_owner(actor_unit),
3477 .city = tile_city(actor_tile),
3478 .tile = actor_tile,
3479 .unit = actor_unit,
3480 .unittype = unit_type_get(actor_unit),
3481 },
3482 nullptr, nullptr,
3483 actor_home);
3484}
3485
3486/**********************************************************************/
3501
3502#define ASSERT_PLAYER_ACTION(_atk) \
3503 fc_assert_ret_val_msg(AAK_PLAYER == action_id_get_actor_kind(wanted_action),\
3504 FALSE, "Action %s is performed by %s not %s", \
3505 action_id_rule_name(wanted_action), \
3506 action_actor_kind_name( \
3507 action_id_get_actor_kind(wanted_action)), \
3508 action_actor_kind_name(AAK_PLAYER)); \
3509 fc_assert_ret_val_msg(_atk \
3510 == action_id_get_target_kind(wanted_action), \
3511 FALSE, "Action %s is against %s not %s", \
3512 action_id_rule_name(wanted_action), \
3513 action_target_kind_name( \
3514 action_id_get_target_kind(wanted_action)), \
3515 action_target_kind_name(_atk));
3516
3517/**********************************************************************/
3523 const struct player *actor_plr)
3524{
3525 if (actor_plr == nullptr) {
3526 /* Can't do an action when the actor is missing. */
3527 return FALSE;
3528 }
3529
3531
3533 &(const struct req_context) {
3534 .player = actor_plr,
3535 },
3536 nullptr, nullptr, nullptr);
3537}
3538
3539/**********************************************************************/
3545 const struct player *actor_plr,
3546 const struct city *target_city)
3547{
3548 const struct impr_type *target_building;
3549 const struct unit_type *target_utype;
3550
3551 if (actor_plr == nullptr || target_city == nullptr) {
3552 /* Can't do an action when the actor or the target is missing. */
3553 return FALSE;
3554 }
3555
3557
3560
3562 &(const struct req_context) {
3563 .player = actor_plr,
3564 },
3565 &(const struct req_context) {
3566 .player = city_owner(target_city),
3567 .city = target_city,
3568 .building = target_building,
3570 .unittype = target_utype,
3571 }, nullptr, nullptr);
3572}
3573
3574/**********************************************************************/
3580bool
3583 const struct player *actor_plr,
3584 const struct tile *target_tile,
3585 const struct extra_type *target_extra)
3586{
3587 if (actor_plr == nullptr || target_tile == nullptr) {
3588 /* Can't do an action when actor or target are missing. */
3589 return FALSE;
3590 }
3591
3593
3595 &(const struct req_context) {
3596 .player = actor_plr,
3597 },
3598 &(const struct req_context) {
3599 .player = target_tile->extras_owner,
3600 .city = tile_city(target_tile),
3601 .tile = target_tile,
3602 },
3603 target_extra, nullptr);
3604}
3605
3606/**********************************************************************/
3614 const struct player *actor_plr,
3615 const struct tile *target_tile,
3616 const struct extra_type *target_extra)
3617{
3618 const struct req_context actor_ctxt = {
3619 .player = actor_plr,
3620 };
3621 const struct city *tcity;
3622
3623 if (actor_plr == nullptr || target_tile == nullptr
3624 || unit_list_size(target_tile->units) == 0) {
3625 /* Can't do an action when actor or target are missing. */
3626 return FALSE;
3627 }
3628
3630
3634 &(const struct req_context) {
3635 .player = unit_owner(target_unit),
3636 .city = tcity,
3637 .tile = target_tile,
3638 .unit = target_unit,
3639 .unittype = unit_type_get(target_unit),
3640 },
3641 nullptr, nullptr)) {
3642 /* One unit makes it impossible for all units. */
3643 return FALSE;
3644 }
3646
3647 /* Not impossible for any of the units at the tile. */
3648 return TRUE;
3649}
3650
3651/**********************************************************************/
3659 const struct player *actor_plr,
3660 const struct tile *target_tile,
3661 const struct extra_type *target_extra)
3662{
3663 if (actor_plr == nullptr || target_tile == nullptr) {
3664 /* Can't do an action when actor or target are missing. */
3665 return FALSE;
3666 }
3667
3669
3671 &(const struct req_context) {
3672 .player = actor_plr,
3673 },
3674 &(const struct req_context) {
3675 .player = tile_owner(target_tile),
3676 .city = tile_city(target_tile),
3677 .tile = target_tile,
3678 },
3679 target_extra, nullptr);
3680}
3681
3682/**********************************************************************/
3690 const struct player *actor_plr,
3691 const struct unit *target_unit)
3692{
3693 if (actor_plr == nullptr || target_unit == nullptr) {
3694 /* Can't do an action when actor or target are missing. */
3695 return FALSE;
3696 }
3697
3699
3701 &(const struct req_context) {
3702 .player = actor_plr,
3703 },
3704 &(const struct req_context) {
3705 .player = unit_owner(target_unit),
3708 .unit = target_unit,
3709 .unittype = unit_type_get(target_unit),
3710 },
3711 nullptr, nullptr);
3712}
3713
3714/**********************************************************************/
3720 const struct city *actor_city)
3721{
3723 &(const struct req_context) {
3724 .player = city_owner(actor_city),
3725 .city = actor_city,
3726 .tile = city_tile(actor_city)
3727 },
3728 nullptr, nullptr, nullptr);
3729}
3730
3731/**********************************************************************/
3749static enum fc_tristate
3751 const struct req_context *actor,
3752 const struct req_context *target)
3753{
3754 enum fc_tristate current;
3755 enum fc_tristate result;
3756
3757 if (actor == nullptr || actor->player == nullptr) {
3758 /* Need actor->player for point of view */
3759 return TRI_MAYBE;
3760 }
3761
3762 if (target == nullptr) {
3763 target = req_context_empty();
3764 }
3765
3766 result = TRI_NO;
3768 enabler) {
3769 current = fc_tristate_and(mke_eval_reqs(actor->player,
3770 actor, target,
3771 &enabler->actor_reqs,
3772 RPT_CERTAIN),
3773 mke_eval_reqs(actor->player,
3774 target, actor,
3775 &enabler->target_reqs,
3776 RPT_CERTAIN));
3777 if (current == TRI_YES) {
3778 return TRI_YES;
3779 } else if (current == TRI_MAYBE) {
3780 result = TRI_MAYBE;
3781 }
3783
3784 return result;
3785}
3786
3787/**********************************************************************/
3797static bool is_effect_val_known(enum effect_type effect_type,
3798 const struct player *pov_player,
3799 const struct req_context *context,
3800 const struct req_context *other_context)
3801{
3802 effect_list_iterate(get_effects(effect_type), peffect) {
3804 &(peffect->reqs), RPT_CERTAIN)) {
3805 return FALSE;
3806 }
3808
3809 return TRUE;
3810}
3811
3812/**********************************************************************/
3815static enum fc_tristate
3843
3844/**********************************************************************/
3853 const struct unit *pdefender)
3854{
3855 /* Keep unconverted until the end to avoid scaling each step */
3856 int chance;
3857 struct act_prob out;
3858
3859 /* Superspy always win */
3861 /* A defending UTYF_SUPERSPY will defeat every possible attacker. */
3862 return ACTPROB_IMPOSSIBLE;
3863 }
3865 /* An attacking UTYF_SUPERSPY will defeat every possible defender
3866 * except another UTYF_SUPERSPY. */
3867 return ACTPROB_CERTAIN;
3868 }
3869
3870 /* Base chance is 50% */
3871 chance = 50;
3872
3873 /* Spy attack bonus */
3875 chance += 25;
3876 }
3877
3878 /* Spy defense bonus */
3880 chance -= 25;
3881 }
3882
3883 /* Veteran attack and defense bonus */
3884 {
3885 const struct veteran_level *vatt
3887 const struct veteran_level *vdef
3889
3890 chance += vatt->power_fact - vdef->power_fact;
3891 }
3892
3893 /* Defense bonus. */
3894 {
3895 const struct req_context defender_ctxt = {
3896 .player = tile_owner(pdefender->tile),
3897 .city = tile_city(pdefender->tile),
3898 .tile = pdefender->tile,
3899 };
3902 nullptr)) {
3903 return ACTPROB_NOT_KNOWN;
3904 }
3905
3906 /* Reduce the chance of an attack by EFT_SPY_RESISTANT percent. */
3908 nullptr,
3910 nullptr,
3912 ) / 100;
3913 }
3914
3915 chance = CLIP(0, chance, 100);
3916
3917 /* Convert to action probability */
3920
3921 return out;
3922}
3923
3924/**********************************************************************/
3930 const struct unit *pvictim,
3931 const struct tile *tgt_tile,
3932 const struct action *paction)
3933{
3934 struct unit *pdefender;
3935
3937 tgt_tile)) {
3938 /* Don't leak information about unseen defenders. */
3939 return ACTPROB_NOT_KNOWN;
3940 }
3941
3943 paction);
3944
3945 if (pdefender) {
3946 /* There will be a diplomatic battle instead of an action. */
3948 };
3949
3950 /* No diplomatic battle will occur. */
3951 return ACTPROB_CERTAIN;
3952}
3953
3954/**********************************************************************/
3958 action_id act_id,
3959 const struct unit *actor_unit)
3960{
3962 /* Unknown because the target is unseen. */
3963 return ACTPROB_NOT_KNOWN;
3964 } else {
3965 /* The actor it self can't do this. */
3966 return ACTPROB_IMPOSSIBLE;
3967 }
3968}
3969
3970/**********************************************************************/
3974static struct act_prob
3976 const struct unit *act_unit,
3977 const struct city *tgt_city,
3978 const struct player *tgt_player,
3979 const struct action *paction)
3980{
3982 &(const struct req_context) {
3983 .player = act_player,
3984 .city = tgt_city,
3985 .unit = act_unit,
3986 .unittype = unit_type_get(act_unit),
3987 },
3988 &(const struct req_context) {
3989 .player = tgt_player,
3990 })
3992 &(const struct req_context) {
3993 .player = tgt_player,
3994 .city = tgt_city,
3995 .unit = act_unit,
3996 },
3997 &(const struct req_context) {
3998 .player = act_player,
3999 })) {
4002 struct act_prob result = { .min = unconverted * ACTPROB_VAL_1_PCT,
4003 .max = unconverted * ACTPROB_VAL_1_PCT };
4004
4005 return result;
4006 } else {
4007 /* Could be improved to return a more exact probability in some cases.
4008 * Example: The player has enough information to know that the
4009 * probability always will be above 25% and always under 75% because
4010 * the only effect with unknown requirements that may apply adds (or
4011 * subtracts) 50% while all the requirements of the other effects that
4012 * may apply are known. */
4013 return ACTPROB_NOT_KNOWN;
4014 }
4015}
4016
4017/**********************************************************************/
4022static struct act_prob
4024 const struct unit *act_unit,
4025 const struct city *tgt_city,
4026 const struct unit *tgt_unit,
4027 const struct tile *tgt_tile,
4028 const struct player *tgt_player,
4029 const struct action *paction)
4030{
4031 struct act_prob battle;
4032 struct act_prob dice_roll;
4033
4034 battle = ACTPROB_CERTAIN;
4035 switch (actres_get_battle_kind(paction->result)) {
4036 case ABK_NONE:
4037 /* No pre action battle. */
4038 break;
4039 case ABK_DIPLOMATIC:
4041 paction);
4042 break;
4043 case ABK_STANDARD:
4044 /* Not supported here yet. Implement when users appear. */
4046 break;
4047 case ABK_COUNT:
4049 break;
4050 }
4051
4054 paction);
4055
4056 return action_prob_and(&battle, &dice_roll);
4057}
4058
4059/**********************************************************************/
4070static struct act_prob
4073 const struct req_context *actor,
4074 const struct city *actor_home,
4075 const struct req_context *target,
4076 const struct extra_type *target_extra)
4077{
4078 enum fc_tristate known;
4079 struct act_prob chance;
4081
4082 if (actor == nullptr) {
4084 }
4085 if (target == nullptr) {
4086 target = req_context_empty();
4087 }
4088
4089 known = is_action_possible(nmap, wanted_action, actor, target,
4091 FALSE, actor_home);
4092
4093 if (known == TRI_NO) {
4094 /* The action enablers are irrelevant since the action it self is
4095 * impossible. */
4096 return ACTPROB_IMPOSSIBLE;
4097 }
4098
4100
4101 known = fc_tristate_and(known,
4103 actor, target));
4104
4105 switch (paction->result) {
4106 case ACTRES_SPY_POISON:
4107 /* All uncertainty comes from potential diplomatic battles and the
4108 * (diplchance server setting and the) Action_Odds_Pct effect controlled
4109 * dice roll before the action. */
4111 target->city, target->unit,
4112 target->tile, target->player,
4113 paction);
4114 break;
4116 /* TODO */
4117 break;
4119 /* TODO */
4120 break;
4121 case ACTRES_STEAL_MAPS:
4122 /* TODO */
4123 break;
4125 /* All uncertainty comes from potential diplomatic battles. */
4126 chance = ap_diplomat_battle(actor->unit, target->unit, target->tile,
4127 paction);
4128 break;
4131 /* All uncertainty comes from potential diplomatic battles. */
4132 chance = ap_diplomat_battle(actor->unit, target->unit, target->tile,
4133 paction);
4134 break;
4135 case ACTRES_SPY_ATTACK:
4136 /* All uncertainty comes from potential diplomatic battles. */
4137 chance = ap_diplomat_battle(actor->unit, nullptr, target->tile,
4138 paction);
4139 break;
4141 /* TODO */
4142 break;
4144 /* TODO */
4145 break;
4147 /* TODO */
4148 break;
4150 /* TODO */
4151 break;
4154 break;
4156 /* Do the victim have anything worth taking? */
4157 known = fc_tristate_and(known,
4158 tech_can_be_stolen(actor->player,
4159 target->player));
4160
4161 /* TODO: Calculate actual chance */
4162
4163 break;
4165 /* Do the victim have anything worth taking? */
4166 known = fc_tristate_and(known,
4167 tech_can_be_stolen(actor->player,
4168 target->player));
4169
4170 /* TODO: Calculate actual chance */
4171
4172 break;
4174 /* There is no risk that the city won't get investigated. */
4176 break;
4177 case ACTRES_SPY_ESCAPE:
4178 /* TODO */
4179 break;
4180 case ACTRES_TRADE_ROUTE:
4181 /* TODO */
4182 break;
4183 case ACTRES_MARKETPLACE:
4184 /* Possible when not blocked by is_action_possible() */
4186 break;
4187 case ACTRES_HELP_WONDER:
4188 /* Possible when not blocked by is_action_possible() */
4190 break;
4192 /* No battle is fought first. */
4194 break;
4195 case ACTRES_EXPEL_UNIT:
4196 /* No battle is fought first. */
4198 break;
4199 case ACTRES_BOMBARD:
4200 /* No battle is fought first. */
4202 break;
4203 case ACTRES_FOUND_CITY:
4204 /* Possible when not blocked by is_action_possible() */
4206 break;
4207 case ACTRES_JOIN_CITY:
4208 /* Possible when not blocked by is_action_possible() */
4210 break;
4211 case ACTRES_SPY_NUKE:
4212 /* All uncertainty comes from potential diplomatic battles and the
4213 * (diplchance server setting and the) Action_Odds_Pct effect controlled
4214 * dice roll before the action. */
4216 target->city, target->unit,
4217 target->tile,
4218 target->player,
4219 paction);
4220 break;
4221 case ACTRES_NUKE:
4222 /* TODO */
4223 break;
4224 case ACTRES_NUKE_UNITS:
4225 /* TODO */
4226 break;
4228 /* No battle is fought first. */
4230 break;
4232 /* No battle is fought first. */
4234 break;
4236 /* No battle is fought first. */
4238 break;
4239 case ACTRES_HOME_CITY:
4240 /* No battle is fought first. */
4242 break;
4243 case ACTRES_HOMELESS:
4244 /* No battle is fought first. */
4246 break;
4248 /* No battle is fought first. */
4250 break;
4251 case ACTRES_PARADROP:
4253 /* TODO */
4254 break;
4255 case ACTRES_AIRLIFT:
4256 /* Possible when not blocked by is_action_possible() */
4258 break;
4259 case ACTRES_ATTACK:
4261 {
4262 struct unit *defender_unit = get_defender(nmap, actor->unit,
4263 target->tile, paction);
4264
4265 if (can_player_see_unit(actor->player, defender_unit)) {
4266 double unconverted = unit_win_chance(nmap, actor->unit,
4268
4270 floor((double)ACTPROB_VAL_MAX * unconverted));
4272 ceil((double)ACTPROB_VAL_MAX * unconverted));
4273 } else if (known == TRI_YES) {
4274 known = TRI_MAYBE;
4275 }
4276 }
4277 break;
4278 case ACTRES_WIPE_UNITS:
4280 break;
4282 /* TODO: not implemented yet because:
4283 * - dice roll 100% * Action_Odds_Pct could be handled with
4284 * action_prob_pre_action_dice_roll().
4285 * - sub target building may be missing. May be missing without player
4286 * knowledge if it isn't visible. See is_improvement_visible() and
4287 * can_player_see_city_internals(). */
4288 break;
4290 /* All uncertainty comes from the (diplchance server setting and the)
4291 * Action_Odds_Pct effect controlled dice roll before the action. */
4293 target->city, target->player,
4294 paction);
4295 break;
4297 /* No battle is fought first. */
4299 break;
4301 /* No battle is fought first. */
4303 break;
4304 case ACTRES_HEAL_UNIT:
4305 /* No battle is fought first. */
4307 break;
4309 case ACTRES_CULTIVATE:
4310 case ACTRES_PLANT:
4311 case ACTRES_PILLAGE:
4312 case ACTRES_CLEAN:
4313 case ACTRES_FORTIFY:
4314 case ACTRES_ROAD:
4315 case ACTRES_CONVERT:
4316 case ACTRES_BASE:
4317 case ACTRES_MINE:
4318 case ACTRES_IRRIGATE:
4320 break;
4323 break;
4326 break;
4329 break;
4332 break;
4335 break;
4338 break;
4339 case ACTRES_HUT_ENTER:
4341 /* Entering the hut happens with a probability of 100%. What happens
4342 * next is probably up to dice rolls in Lua. */
4344 break;
4345 case ACTRES_UNIT_MOVE:
4346 case ACTRES_TELEPORT:
4349 break;
4350 /* Not UI action, so chance is meaningless */
4353 break;
4354 case ACTRES_NONE:
4355 /* Accommodate ruleset authors that wishes to roll the dice in Lua.
4356 * Would be ACTPROB_CERTAIN if not for that. */
4357 /* TODO: maybe allow the ruleset author to give a probability from
4358 * Lua? */
4360 break;
4361 }
4362
4363 /* Non signal action probabilities should be in range. */
4365 || chance.max <= ACTPROB_VAL_MAX),
4366 chance.max = ACTPROB_VAL_MAX);
4368 || chance.min >= ACTPROB_VAL_MIN),
4369 chance.min = ACTPROB_VAL_MIN);
4370
4371 switch (known) {
4372 case TRI_NO:
4373 return ACTPROB_IMPOSSIBLE;
4374 break;
4375 case TRI_MAYBE:
4376 return ACTPROB_NOT_KNOWN;
4377 break;
4378 case TRI_YES:
4379 return chance;
4380 break;
4381 };
4382
4383 fc_assert_msg(FALSE, "Should be yes, maybe or no");
4384
4386}
4387
4388/**********************************************************************/
4392static struct act_prob
4394 const struct unit *actor_unit,
4395 const struct city *actor_home,
4396 const struct tile *actor_tile,
4397 const action_id act_id,
4398 const struct city *target_city)
4399{
4400 const struct impr_type *target_building;
4401 const struct unit_type *target_utype;
4402 const struct action *act = action_by_number(act_id);
4403
4404 if (actor_unit == nullptr || target_city == nullptr) {
4405 /* Can't do an action when actor or target are missing. */
4406 return ACTPROB_IMPOSSIBLE;
4407 }
4408
4411 "Action %s is performed by %s not %s",
4412 action_id_rule_name(act_id),
4414 action_id_get_actor_kind(act_id)),
4416
4419 "Action %s is against %s not %s",
4420 action_id_rule_name(act_id),
4424
4426
4427 if (!unit_can_do_action(actor_unit, act_id)) {
4428 /* No point in continuing. */
4429 return ACTPROB_IMPOSSIBLE;
4430 }
4431
4432 /* Doesn't leak information about city position since an unknown city
4433 * can't be targeted and a city can't move. */
4434 if (!action_id_distance_accepted(act_id,
4437 /* No point in continuing. */
4438 return ACTPROB_IMPOSSIBLE;
4439 }
4440
4441 /* Doesn't leak information since it must be 100% certain from the
4442 * player's perspective that the blocking action is legal. */
4444 city_tile(target_city), target_city, nullptr)) {
4445 /* Don't offer to perform an action known to be blocked. */
4446 return ACTPROB_IMPOSSIBLE;
4447 }
4448
4450 /* The invisible city at this tile may, as far as the player knows, not
4451 * exist anymore. */
4452 return act_prob_unseen_target(nmap, act_id, actor_unit);
4453 }
4454
4457
4458 return action_prob(nmap, act_id,
4459 &(const struct req_context) {
4460 .player = unit_owner(actor_unit),
4461 .city = tile_city(actor_tile),
4462 .tile = actor_tile,
4463 .unit = actor_unit,
4464 .unittype = unit_type_get(actor_unit),
4465 },
4466 actor_home,
4467 &(const struct req_context) {
4468 .player = city_owner(target_city),
4469 .city = target_city,
4470 .building = target_building,
4472 .unittype = target_utype,
4473 }, nullptr);
4474}
4475
4476/**********************************************************************/
4481 const struct unit *actor_unit,
4482 const action_id act_id,
4483 const struct city *target_city)
4484{
4488 act_id, target_city);
4489}
4490
4491/**********************************************************************/
4495static struct act_prob
4497 const struct unit *actor_unit,
4498 const struct city *actor_home,
4499 const struct tile *actor_tile,
4500 const action_id act_id,
4501 const struct unit *target_unit)
4502{
4503 if (actor_unit == nullptr || target_unit == nullptr) {
4504 /* Can't do an action when actor or target are missing. */
4505 return ACTPROB_IMPOSSIBLE;
4506 }
4507
4510 "Action %s is performed by %s not %s",
4511 action_id_rule_name(act_id),
4513 action_id_get_actor_kind(act_id)),
4515
4518 "Action %s is against %s not %s",
4519 action_id_rule_name(act_id),
4523
4525
4526 if (!unit_can_do_action(actor_unit, act_id)) {
4527 /* No point in continuing. */
4528 return ACTPROB_IMPOSSIBLE;
4529 }
4530
4531 /* Doesn't leak information about unit position since an unseen unit can't
4532 * be targeted. */
4533 if (!action_id_distance_accepted(act_id,
4536 /* No point in continuing. */
4537 return ACTPROB_IMPOSSIBLE;
4538 }
4539
4540 return action_prob(nmap, act_id,
4541 &(const struct req_context) {
4542 .player = unit_owner(actor_unit),
4543 .city = tile_city(actor_tile),
4544 .tile = actor_tile,
4545 .unit = actor_unit,
4546 .unittype = unit_type_get(actor_unit),
4547 },
4548 actor_home,
4549 &(const struct req_context) {
4550 .player = unit_owner(target_unit),
4553 .unit = target_unit,
4554 .unittype = unit_type_get(target_unit),
4555 },
4556 nullptr);
4557}
4558
4559/**********************************************************************/
4564 const struct unit *actor_unit,
4565 const action_id act_id,
4566 const struct unit *target_unit)
4567{
4571 act_id,
4572 target_unit);
4573}
4574
4575/**********************************************************************/
4579static struct act_prob
4581 const struct unit *actor_unit,
4582 const struct city *actor_home,
4583 const struct tile *actor_tile,
4584 const action_id act_id,
4585 const struct tile *target_tile)
4586{
4587 struct act_prob prob_all;
4588 const struct req_context *actor_ctxt;
4589 const struct action *act = action_by_number(act_id);
4590
4591 if (actor_unit == nullptr || target_tile == nullptr) {
4592 /* Can't do an action when actor or target are missing. */
4593 return ACTPROB_IMPOSSIBLE;
4594 }
4595
4598 "Action %s is performed by %s not %s",
4599 action_id_rule_name(act_id),
4601 action_id_get_actor_kind(act_id)),
4603
4606 "Action %s is against %s not %s",
4607 action_id_rule_name(act_id),
4611
4613
4614 if (!unit_can_do_action(actor_unit, act_id)) {
4615 /* No point in continuing. */
4616 return ACTPROB_IMPOSSIBLE;
4617 }
4618
4619 /* Doesn't leak information about unit stack position since it is
4620 * specified as a tile and an unknown tile's position is known. */
4621 if (!action_id_distance_accepted(act_id,
4623 target_tile))) {
4624 /* No point in continuing. */
4625 return ACTPROB_IMPOSSIBLE;
4626 }
4627
4628 /* Doesn't leak information since the actor player can see the target
4629 * tile. */
4631 && tile_city(target_tile) != nullptr
4633 act_id,
4634 CITYT_CENTER, TRUE)) {
4635 /* Don't offer to perform actions that never can target a unit stack in
4636 * a city. */
4637 return ACTPROB_IMPOSSIBLE;
4638 }
4639
4640 /* Doesn't leak information since it must be 100% certain from the
4641 * player's perspective that the blocking action is legal. */
4645 target_unit)) {
4646 /* Don't offer to perform an action known to be blocked. */
4647 return ACTPROB_IMPOSSIBLE;
4648 }
4650
4651 /* Must be done here since an empty unseen tile will result in
4652 * ACTPROB_IMPOSSIBLE. */
4653 if (unit_list_size(target_tile->units) == 0) {
4654 /* Can't act against an empty tile. */
4655
4657 target_tile)) {
4658 /* Known empty tile. */
4659 return ACTPROB_IMPOSSIBLE;
4660 } else {
4661 /* The player doesn't know that the tile is empty. */
4662 return act_prob_unseen_target(nmap, act_id, actor_unit);
4663 }
4664 }
4665
4669 && tile_city(target_tile) != nullptr
4672 /* Hard coded rule: can't "Bombard", "Suicide Attack", or "Attack"
4673 * units in non enemy cities. */
4674 return ACTPROB_IMPOSSIBLE;
4675 }
4676
4683 /* Hard coded rule: can't "Nuke Units", "Wipe Units", "Suicide Attack",
4684 * or "Attack" units on non native tile without "AttackNonNative" and
4685 * not "Only_Native_Attack". */
4686 return ACTPROB_IMPOSSIBLE;
4687 }
4688
4689 /* Invisible units at this tile can make the action legal or illegal.
4690 * Invisible units can be stacked with visible units. The possible
4691 * existence of invisible units therefore makes the result uncertain. */
4695
4696 actor_ctxt = &(const struct req_context) {
4697 .player = unit_owner(actor_unit),
4698 .city = tile_city(actor_tile),
4699 .tile = actor_tile,
4700 .unit = actor_unit,
4701 .unittype = unit_type_get(actor_unit),
4702 };
4703
4705 struct act_prob prob_unit;
4706
4708 /* Only visible units are considered. The invisible units contributed
4709 * their uncertainty to prob_all above. */
4710 continue;
4711 }
4712
4714 &(const struct req_context) {
4715 .player = unit_owner(target_unit),
4718 .unit = target_unit,
4719 .unittype = unit_type_get(target_unit),
4720 },
4721 nullptr);
4722
4724 /* One unit makes it impossible for all units. */
4725 return ACTPROB_IMPOSSIBLE;
4726 } else if (action_prob_not_impl(prob_unit)) {
4727 /* Not implemented dominates all except impossible. */
4729 } else {
4731 "Invalid probability [%d, %d]",
4732 prob_unit.min, prob_unit.max);
4733
4735 /* Special values dominate regular values. */
4736 continue;
4737 }
4738
4739 /* Probability against all target units considered until this moment
4740 * and the probability against this target unit. */
4741 prob_all.min = (prob_all.min * prob_unit.min) / ACTPROB_VAL_MAX;
4742 prob_all.max = (prob_all.max * prob_unit.max) / ACTPROB_VAL_MAX;
4743 break;
4744 }
4746
4747 /* Not impossible for any of the units at the tile. */
4748 return prob_all;
4749}
4750
4751/**********************************************************************/
4756 const struct unit *actor_unit,
4757 const action_id act_id,
4758 const struct tile *target_tile)
4759{
4763 act_id,
4764 target_tile);
4765}
4766
4767/**********************************************************************/
4771static struct act_prob
4773 const struct unit *actor_unit,
4774 const struct city *actor_home,
4775 const struct tile *actor_tile,
4776 const action_id act_id,
4777 const struct tile *target_tile,
4778 const struct extra_type *target_extra)
4779{
4780 if (actor_unit == nullptr || target_tile == nullptr) {
4781 /* Can't do an action when actor or target are missing. */
4782 return ACTPROB_IMPOSSIBLE;
4783 }
4784
4787 "Action %s is performed by %s not %s",
4788 action_id_rule_name(act_id),
4790 action_id_get_actor_kind(act_id)),
4792
4795 "Action %s is against %s not %s",
4796 action_id_rule_name(act_id),
4800
4802
4803 if (!unit_can_do_action(actor_unit, act_id)) {
4804 /* No point in continuing. */
4805 return ACTPROB_IMPOSSIBLE;
4806 }
4807
4808 /* Doesn't leak information about tile position since an unknown tile's
4809 * position is known. */
4810 if (!action_id_distance_accepted(act_id,
4812 target_tile))) {
4813 /* No point in continuing. */
4814 return ACTPROB_IMPOSSIBLE;
4815 }
4816
4817 return action_prob(nmap, act_id,
4818 &(const struct req_context) {
4819 .player = unit_owner(actor_unit),
4820 .city = tile_city(actor_tile),
4821 .tile = actor_tile,
4822 .unit = actor_unit,
4823 .unittype = unit_type_get(actor_unit),
4824 },
4825 actor_home,
4826 &(const struct req_context) {
4827 .player = tile_owner(target_tile),
4828 .city = tile_city(target_tile),
4829 .tile = target_tile,
4830 },
4831 target_extra);
4832}
4833
4834/**********************************************************************/
4839 const struct unit *actor_unit,
4840 const action_id act_id,
4841 const struct tile *target_tile,
4842 const struct extra_type *target_extra)
4843{
4847 act_id, target_tile, target_extra);
4848}
4849
4850/**********************************************************************/
4854static struct act_prob
4856 const struct unit *actor_unit,
4857 const struct city *actor_home,
4858 const struct tile *actor_tile,
4859 const action_id act_id,
4860 const struct tile *target_tile,
4861 const struct extra_type *target_extra)
4862{
4863 if (actor_unit == nullptr || target_tile == nullptr) {
4864 /* Can't do an action when actor or target are missing. */
4865 return ACTPROB_IMPOSSIBLE;
4866 }
4867
4870 "Action %s is performed by %s not %s",
4871 action_id_rule_name(act_id),
4873 action_id_get_actor_kind(act_id)),
4875
4878 "Action %s is against %s not %s",
4879 action_id_rule_name(act_id),
4883
4885
4886 if (!unit_can_do_action(actor_unit, act_id)) {
4887 /* No point in continuing. */
4888 return ACTPROB_IMPOSSIBLE;
4889 }
4890
4891 /* Doesn't leak information about tile position since an unknown tile's
4892 * position is known. */
4893 if (!action_id_distance_accepted(act_id,
4895 target_tile))) {
4896 /* No point in continuing. */
4897 return ACTPROB_IMPOSSIBLE;
4898 }
4899
4900 return action_prob(nmap, act_id,
4901 &(const struct req_context) {
4902 .player = unit_owner(actor_unit),
4903 .city = tile_city(actor_tile),
4904 .tile = actor_tile,
4905 .unit = actor_unit,
4906 .unittype = unit_type_get(actor_unit),
4907 },
4908 actor_home,
4909 &(const struct req_context) {
4910 .player = target_tile->extras_owner,
4911 .city = tile_city(target_tile),
4912 .tile = target_tile,
4913 },
4914 target_extra);
4915}
4916
4917/**********************************************************************/
4922 const struct unit *actor_unit,
4923 const action_id act_id,
4924 const struct tile *target_tile,
4925 const struct extra_type *target_extra)
4926{
4930 act_id, target_tile, target_extra);
4931}
4932
4933/**********************************************************************/
4937static struct act_prob
4939 const struct unit *actor_unit,
4940 const struct city *actor_home,
4941 const struct tile *actor_tile,
4942 const action_id act_id)
4943{
4944 if (actor_unit == nullptr) {
4945 /* Can't do the action when the actor is missing. */
4946 return ACTPROB_IMPOSSIBLE;
4947 }
4948
4949 /* No point in checking distance to target. It is always 0. */
4950
4953 "Action %s is performed by %s not %s",
4954 action_id_rule_name(act_id),
4956 action_id_get_actor_kind(act_id)),
4958
4961 "Action %s is against %s not %s",
4962 action_id_rule_name(act_id),
4966
4968
4969 if (!unit_can_do_action(actor_unit, act_id)) {
4970 /* No point in continuing. */
4971 return ACTPROB_IMPOSSIBLE;
4972 }
4973
4974 return action_prob(nmap, act_id,
4975 &(const struct req_context) {
4976 .player = unit_owner(actor_unit),
4977 .city = tile_city(actor_tile),
4978 .tile = actor_tile,
4979 .unit = actor_unit,
4980 .unittype = unit_type_get(actor_unit),
4981 },
4982 actor_home,
4983 nullptr,
4984 nullptr);
4985}
4986
4987/**********************************************************************/
4992 const struct unit *actor_unit,
4993 const action_id act_id)
4994{
4998 act_id);
4999}
5000
5001/**********************************************************************/
5014 const struct action *paction,
5015 const struct unit *act_unit,
5016 const struct city *tgt_city,
5017 const struct unit *tgt_unit,
5018 const struct tile *tgt_tile,
5019 const struct extra_type *extra_tgt)
5020{
5021 /* Assume impossible until told otherwise. */
5022 struct act_prob prob = ACTPROB_IMPOSSIBLE;
5023
5026
5028 case ATK_STACK:
5029 if (tgt_tile) {
5031 }
5032 break;
5033 case ATK_TILE:
5034 if (tgt_tile) {
5036 }
5037 break;
5038 case ATK_EXTRAS:
5039 if (tgt_tile) {
5042 }
5043 break;
5044 case ATK_CITY:
5045 if (tgt_city) {
5047 }
5048 break;
5049 case ATK_UNIT:
5050 if (tgt_unit) {
5052 }
5053 break;
5054 case ATK_SELF:
5055 prob = action_prob_self(nmap, act_unit, paction->id);
5056 break;
5057 case ATK_COUNT:
5058 log_error("Invalid action target kind");
5059 break;
5060 }
5061
5062 return prob;
5063}
5064
5065/**********************************************************************/
5071 const action_id act_id,
5072 const struct unit *actor,
5073 const struct city *actor_home,
5074 const struct tile *actor_tile,
5075 const bool omniscient_cheat,
5076 const struct city* target)
5077{
5078 /* FIXME: some unit state requirements still depend on the actor unit's
5079 * current position rather than on actor_tile. Maybe this function should
5080 * return ACTPROB_NOT_IMPLEMENTED when one of those is detected and no
5081 * other requirement makes the action ACTPROB_IMPOSSIBLE? */
5082
5083 if (omniscient_cheat) {
5086 target)) {
5087 return ACTPROB_CERTAIN;
5088 } else {
5089 return ACTPROB_IMPOSSIBLE;
5090 }
5091 } else {
5092 /* FIXME: this branch result depends _directly_ on actor's position.
5093 * I.e., like, not adjacent, no action. Other branch ignores radius. */
5095 act_id, target);
5096 }
5097}
5098
5099/**********************************************************************/
5104struct act_prob
5106 action_id act_id,
5107 const struct unit *actor,
5108 const struct city *actor_home,
5109 const struct tile *actor_tile,
5110 bool omniscient_cheat,
5111 const struct unit *target)
5112{
5113 /* FIXME: some unit state requirements still depend on the actor unit's
5114 * current position rather than on actor_tile. Maybe this function should
5115 * return ACTPROB_NOT_IMPLEMENTED when one of those is detected and no
5116 * other requirement makes the action ACTPROB_IMPOSSIBLE? */
5117
5118 if (omniscient_cheat) {
5121 target)) {
5122 return ACTPROB_CERTAIN;
5123 } else {
5124 return ACTPROB_IMPOSSIBLE;
5125 }
5126 } else {
5128 act_id, target);
5129 }
5130}
5131
5132/**********************************************************************/
5137struct act_prob
5139 action_id act_id,
5140 const struct unit *actor,
5141 const struct city *actor_home,
5142 const struct tile *actor_tile,
5143 bool omniscient_cheat,
5144 const struct tile *target)
5145{
5146 /* FIXME: some unit state requirements still depend on the actor unit's
5147 * current position rather than on actor_tile. Maybe this function should
5148 * return ACTPROB_NOT_IMPLEMENTED when one of those is detected and no
5149 * other requirement makes the action ACTPROB_IMPOSSIBLE? */
5150
5151 if (omniscient_cheat) {
5154 target)) {
5155 return ACTPROB_CERTAIN;
5156 } else {
5157 return ACTPROB_IMPOSSIBLE;
5158 }
5159 } else {
5161 act_id, target);
5162 }
5163}
5164
5165/**********************************************************************/
5170struct act_prob
5172 action_id act_id,
5173 const struct unit *actor,
5174 const struct city *actor_home,
5175 const struct tile *actor_tile,
5176 bool omniscient_cheat,
5177 const struct tile *target_tile,
5178 const struct extra_type *target_extra)
5179{
5180 /* FIXME: some unit state requirements still depend on the actor unit's
5181 * current position rather than on actor_tile. Maybe this function should
5182 * return ACTPROB_NOT_IMPLEMENTED when one of those is detected and no
5183 * other requirement makes the action ACTPROB_IMPOSSIBLE? */
5184
5185 if (omniscient_cheat) {
5189 return ACTPROB_CERTAIN;
5190 } else {
5191 return ACTPROB_IMPOSSIBLE;
5192 }
5193 } else {
5195 act_id, target_tile, target_extra);
5196 }
5197}
5198
5199/**********************************************************************/
5204struct act_prob
5206 action_id act_id,
5207 const struct unit *actor,
5208 const struct city *actor_home,
5209 const struct tile *actor_tile,
5210 bool omniscient_cheat,
5211 const struct tile *target_tile,
5212 const struct extra_type *target_extra)
5213{
5214 /* FIXME: some unit state requirements still depend on the actor unit's
5215 * current position rather than on actor_tile. Maybe this function should
5216 * return ACTPROB_NOT_IMPLEMENTED when one of those is detected and no
5217 * other requirement makes the action ACTPROB_IMPOSSIBLE? */
5218
5219 if (omniscient_cheat) {
5223 return ACTPROB_CERTAIN;
5224 } else {
5225 return ACTPROB_IMPOSSIBLE;
5226 }
5227 } else {
5229 act_id, target_tile, target_extra);
5230 }
5231}
5232
5233/**********************************************************************/
5238struct act_prob
5240 action_id act_id,
5241 const struct unit *actor,
5242 const struct city *actor_home,
5243 const struct tile *actor_tile,
5244 bool omniscient_cheat)
5245{
5246 /* FIXME: some unit state requirements still depend on the actor unit's
5247 * current position rather than on actor_tile. Maybe this function should
5248 * return ACTPROB_NOT_IMPLEMENTED when one of those is detected and no
5249 * other requirement makes the action ACTPROB_IMPOSSIBLE? */
5250 if (omniscient_cheat) {
5253 return ACTPROB_CERTAIN;
5254 } else {
5255 return ACTPROB_IMPOSSIBLE;
5256 }
5257 } else {
5259 act_id);
5260 }
5261}
5262
5263/**********************************************************************/
5267{
5269
5270 return out;
5271}
5272
5273/**********************************************************************/
5277{
5279
5280 return out;
5281}
5282
5283/**********************************************************************/
5287{
5289
5290 return out;
5291}
5292
5293/**********************************************************************/
5297{
5299
5300 return out;
5301}
5302
5303/**********************************************************************/
5307{
5309
5310 return out;
5311}
5312
5313/**********************************************************************/
5318{
5319 return (ACTPROB_VAL_MIN < probability.max
5321}
5322
5323/**********************************************************************/
5328{
5329 return (ACTPROB_VAL_MAX == probability.min
5330 && ACTPROB_VAL_MAX == probability.max);
5331}
5332
5333/**********************************************************************/
5337static inline bool
5343
5344/**********************************************************************/
5348static inline bool
5350{
5351 return probability.min == ACTPROB_VAL_NOT_IMPL
5352 && probability.max == ACTPROB_VAL_MIN;
5353}
5354
5355/**********************************************************************/
5359static inline bool
5361{
5362 return probability.max < probability.min;
5363}
5364
5365/**********************************************************************/
5369 const struct act_prob *ap2)
5370{
5371 return ap1->min == ap2->min && ap1->max == ap2->max;
5372}
5373
5374/**********************************************************************/
5378 const struct act_prob ap2)
5379{
5380 struct act_prob my_ap1;
5381 struct act_prob my_ap2;
5382
5383 /* The action probabilities are real. */
5386
5387 /* Convert any signals to ACTPROB_NOT_KNOWN. */
5389 /* Assert that it is OK to convert the signal. */
5391
5393 } else {
5394 my_ap1 = ap1;
5395 }
5396
5398 /* Assert that it is OK to convert the signal. */
5400
5402 } else {
5403 my_ap2 = ap2;
5404 }
5405
5406 /* The action probabilities now have a comparison friendly form. */
5409
5410 /* Do the comparison. Start with min. Continue with max. */
5411 if (my_ap1.min < my_ap2.min) {
5412 return -1;
5413 } else if (my_ap1.min > my_ap2.min) {
5414 return 1;
5415 } else if (my_ap1.max < my_ap2.max) {
5416 return -1;
5417 } else if (my_ap1.max > my_ap2.max) {
5418 return 1;
5419 } else {
5420 return 0;
5421 }
5422}
5423
5424/**********************************************************************/
5429{
5430 struct act_prob my_ap;
5431
5432 /* The action probability is real. */
5434
5435 /* Convert any signals to ACTPROB_NOT_KNOWN. */
5437 /* Assert that it is OK to convert the signal. */
5439
5441 } else {
5442 my_ap = ap;
5443 }
5444
5445 /* The action probability now has a math friendly form. */
5447
5448 return (double)my_ap.min / (double) ACTPROB_VAL_MAX;
5449}
5450
5451/**********************************************************************/
5456 const struct act_prob *ap2)
5457{
5458 struct act_prob my_ap1;
5459 struct act_prob my_ap2;
5460 struct act_prob out;
5461
5462 /* The action probabilities are real. */
5465
5468 /* Keep the information rather than converting the signal to
5469 * ACTPROB_NOT_KNOWN. */
5470
5471 /* Assert that it is OK to convert the signal. */
5473
5474 out.min = ap1->min;
5475 out.max = ap2->max;
5476
5477 return out;
5478 }
5479
5480 /* Convert any signals to ACTPROB_NOT_KNOWN. */
5481 if (action_prob_is_signal(*ap1)) {
5482 /* Assert that it is OK to convert the signal. */
5484
5485 my_ap1.min = ACTPROB_VAL_MIN;
5486 my_ap1.max = ACTPROB_VAL_MAX;
5487 } else {
5488 my_ap1.min = ap1->min;
5489 my_ap1.max = ap1->max;
5490 }
5491
5492 if (action_prob_is_signal(*ap2)) {
5493 /* Assert that it is OK to convert the signal. */
5495
5496 my_ap2.min = ACTPROB_VAL_MIN;
5497 my_ap2.max = ACTPROB_VAL_MAX;
5498 } else {
5499 my_ap2.min = ap2->min;
5500 my_ap2.max = ap2->max;
5501 }
5502
5503 /* The action probabilities now have a math friendly form. */
5506
5507 /* Do the math. */
5508 out.min = (my_ap1.min * my_ap2.min) / ACTPROB_VAL_MAX;
5509 out.max = (my_ap1.max * my_ap2.max) / ACTPROB_VAL_MAX;
5510
5511 /* Cap at 100%. */
5512 out.min = MIN(out.min, ACTPROB_VAL_MAX);
5513 out.max = MIN(out.max, ACTPROB_VAL_MAX);
5514
5515 return out;
5516}
5517
5518/**********************************************************************/
5526 const struct act_prob *ap2)
5527{
5528 struct act_prob my_ap1;
5529 struct act_prob my_ap2;
5530 struct act_prob out;
5531
5532 /* The action probabilities are real. */
5535
5538 /* Keep the information rather than converting the signal to
5539 * ACTPROB_NOT_KNOWN. */
5540
5541 /* Assert that it is OK to convert the signal. */
5543
5544 out.min = ap1->min;
5545 out.max = ap2->max;
5546
5547 return out;
5548 }
5549
5550 /* Convert any signals to ACTPROB_NOT_KNOWN. */
5551 if (action_prob_is_signal(*ap1)) {
5552 /* Assert that it is OK to convert the signal. */
5554
5555 my_ap1.min = ACTPROB_VAL_MIN;
5556 my_ap1.max = ACTPROB_VAL_MAX;
5557 } else {
5558 my_ap1.min = ap1->min;
5559 my_ap1.max = ap1->max;
5560 }
5561
5562 if (action_prob_is_signal(*ap2)) {
5563 /* Assert that it is OK to convert the signal. */
5565
5566 my_ap2.min = ACTPROB_VAL_MIN;
5567 my_ap2.max = ACTPROB_VAL_MAX;
5568 } else {
5569 my_ap2.min = ap2->min;
5570 my_ap2.max = ap2->max;
5571 }
5572
5573 /* The action probabilities now have a math friendly form. */
5576
5577 /* Do the math. */
5578 out.min = my_ap1.min + (((ACTPROB_VAL_MAX - my_ap1.min) * my_ap2.min)
5579 / ACTPROB_VAL_MAX);
5580 out.max = my_ap1.max + (((ACTPROB_VAL_MAX - my_ap1.max) * my_ap2.max)
5581 / ACTPROB_VAL_MAX);
5582
5583 /* Cap at 100%. */
5584 out.min = MIN(out.min, ACTPROB_VAL_MAX);
5585 out.max = MIN(out.max, ACTPROB_VAL_MAX);
5586
5587 return out;
5588}
5589
5590/**********************************************************************/
5594{
5595 switch (actres_dice_type(paction->result)) {
5596 case DRT_DIPLCHANCE:
5598 /* Take the initial odds from the diplchance setting. */
5600 server_setting_by_name("diplchance"));
5601 }
5603 case DRT_CERTAIN:
5604 return 100;
5605 case DRT_NONE:
5606 break;
5607 }
5608
5609 /* The odds of the action not being stopped by its dice roll when the dice
5610 * isn't thrown is 100%. ACTION_ODDS_PCT_DICE_ROLL_NA is above 100% */
5612}
5613
5614/**********************************************************************/
5618 const struct unit *act_unit,
5619 const struct city *tgt_city,
5620 const struct player *tgt_player,
5621 const struct action *paction)
5622{
5624 const struct unit_type *actu_type = unit_type_get(act_unit);
5625
5626 fc_assert_action_msg(odds >= 0 && odds <= 100,
5627 odds = 100,
5628 "Bad initial odds for action number %d."
5629 " Does it roll the dice at all?",
5630 paction->id);
5631
5632 /* Let the Action_Odds_Pct effect modify the odds. The advantage of doing
5633 * it this way instead of rolling twice is that Action_Odds_Pct can
5634 * increase the odds. */
5635 odds = odds
5636 + ((odds
5637 * get_target_bonus_effects(nullptr,
5638 &(const struct req_context) {
5639 .player = act_player,
5640 .city = tgt_city,
5641 .unit = act_unit,
5642 .unittype = actu_type,
5643 .action = paction,
5644 },
5645 &(const struct req_context) {
5646 .player = tgt_player,
5647 },
5649 / 100)
5650 - ((odds
5651 * get_target_bonus_effects(nullptr,
5652 &(const struct req_context) {
5653 .player = tgt_player,
5654 .city = tgt_city,
5655 .unit = act_unit,
5656 .unittype = actu_type,
5657 .action = paction,
5658 },
5659 &(const struct req_context) {
5660 .player = act_player,
5661 },
5663 / 100);
5664
5665
5666 /* Odds are between 0% and 100%. */
5667 return CLIP(0, odds, 100);
5668}
5669
5670/**********************************************************************/
5674{
5675 struct action *paction = action_by_number(act);
5676
5677 /* Always immune since its not enabled. Doesn't count. */
5678 if (!action_is_in_use(paction)) {
5679 return FALSE;
5680 }
5681
5683 if (requirement_fulfilled_by_government(gov, &(enabler->target_reqs))) {
5684 return FALSE;
5685 }
5687
5688 return TRUE;
5689}
5690
5691/**********************************************************************/
5697 const struct player *actor_player,
5698 const struct req_context *target)
5699{
5701 enabler) {
5702 if (are_reqs_active(target,
5703 &(const struct req_context) {
5705 },
5706 &enabler->target_reqs, RPT_POSSIBLE)) {
5707 return TRUE;
5708 }
5710
5711 return FALSE;
5712}
5713
5714/**********************************************************************/
5718 const struct player *actor_player,
5719 const struct city* target_city)
5720{
5722 FALSE, "Action %s is against %s not cities",
5723 action_id_rule_name(act_id),
5725 action_id_get_target_kind(act_id)));
5726
5727 return is_target_possible(act_id, actor_player,
5728 &(const struct req_context) {
5729 .player = city_owner(target_city),
5730 .city = target_city,
5732 });
5733}
5734
5735/**********************************************************************/
5741 const action_id act_id,
5742 const struct unit *actor_unit)
5743{
5744 const struct player *actor_player = unit_owner(actor_unit);
5745 const struct req_context actor_ctxt = {
5747 .city = tile_city(unit_tile(actor_unit)),
5749 .unit = actor_unit,
5750 .unittype = unit_type_get(actor_unit),
5751 };
5752 const struct action *paction = action_by_number(act_id);
5753
5754 enum fc_tristate result;
5755
5757
5758 if (!utype_can_do_action(actor_unit->utype, act_id)) {
5759 /* The unit type can't perform the action. */
5760 return FALSE;
5761 }
5762
5765
5766 if (result == TRI_NO) {
5767 /* The hard requirements aren't fulfilled. */
5768 return FALSE;
5769 }
5770
5772 enabler) {
5773 const enum fc_tristate current
5775 &enabler->actor_reqs,
5776 /* Needed since no player to evaluate DiplRel
5777 * requirements against. */
5778 RPT_POSSIBLE);
5779
5780 if (current == TRI_YES
5781 || current == TRI_MAYBE) {
5782 /* The ruleset requirements may be fulfilled. */
5783 return TRUE;
5784 }
5786
5787 /* No action enabler allows this action. */
5788 return FALSE;
5789}
5790
5791/**********************************************************************/
5796 const action_id act_id)
5797{
5798 fc_assert(action_id_exists(act_id) || act_id == ACTION_ANY);
5799
5800 /* Check if full movement points may enable the specified action. */
5802 act_id,
5805 act_id,
5807}
5808
5809/**********************************************************************/
5819 const struct unit_type *act_utype)
5820{
5821 const struct action *paction = enabler_get_action(ae);
5822 struct universal actor_univ = { .kind = VUT_UTYPE,
5823 .value.utype = act_utype };
5824
5825 fc_assert_ret_val(paction != nullptr, FALSE);
5827 fc_assert_ret_val(act_utype != nullptr, FALSE);
5828
5830 && !req_vec_is_impossible_to_fulfill(&ae->actor_reqs)
5831 && universal_fulfills_requirements(FALSE, &ae->actor_reqs,
5832 &actor_univ));
5833}
5834
5835/**********************************************************************/
5846{
5847 const struct action *paction = enabler_get_action(ae);
5848
5849 switch (action_get_actor_kind(paction)) {
5850 case AAK_UNIT:
5853 /* A possible actor unit type has been found. */
5854 return TRUE;
5855 }
5857
5858 /* No actor detected. */
5859 return FALSE;
5860 case AAK_CITY:
5861 case AAK_PLAYER:
5862 /* Currently can't detect */
5863 return TRUE;
5864 case AAK_COUNT:
5866 break;
5867 }
5868
5869 /* No actor detected. */
5870 return FALSE;
5871}
5872
5873/**********************************************************************/
5881{
5882 switch (action_get_actor_kind(paction)) {
5883 case AAK_UNIT:
5886 return TRUE;
5887 }
5889 break;
5890 case AAK_CITY:
5891 case AAK_PLAYER:
5892 /* No ruleset hard reqs atm */
5893 return TRUE;
5894 case AAK_COUNT:
5896 break;
5897 }
5898
5899 /* No actor detected. */
5900 return FALSE;
5901}
5902
5903/**********************************************************************/
5911{
5913
5915 /* Hard requirements not fulfilled. */
5916 return FALSE;
5917 }
5918
5920
5922 /* If this iteration finds any entries, action is enabled. */
5923 return TRUE;
5925
5926 /* No non deleted action enabler. */
5927 return FALSE;
5928}
5929
5930/**********************************************************************/
5937{
5938 return paction != nullptr
5940}
5941
5942/**********************************************************************/
5952
5953/**********************************************************************/
5957{
5958 fc_assert_ret_val(num >= 0, nullptr);
5960
5961 return &auto_perfs[num];
5962}
5963
5964/**********************************************************************/
5973{
5974 return action_auto_perf_slot_number(num);
5975}
5976
5977/**********************************************************************/
5981 struct universal *actor_uni,
5982 struct universal *target_uni)
5983{
5985 enab) {
5986 if ((actor_uni == nullptr
5987 || universal_fulfills_requirements(FALSE, &(enab->actor_reqs),
5988 actor_uni))
5989 && (target_uni == nullptr
5990 || universal_fulfills_requirements(FALSE, &(enab->target_reqs),
5991 target_uni))) {
5992 return TRUE;
5993 }
5995
5996 return FALSE;
5997}
5998
5999/**********************************************************************/
6005{
6007
6008 if (size < MAX_NUM_ACTIONS) {
6009 /* An action array is terminated by ACTION_NONE */
6011 }
6012}
6013
6014/**********************************************************************/
6022 int *position,
6023 enum action_result result)
6024{
6025 action_iterate(act) {
6026 struct action *paction = action_by_number(act);
6027 if (paction->result == result) {
6028 /* Assume one result for each action. */
6029 fc_assert_ret(*position < MAX_NUM_ACTIONS);
6030
6031 act_array[(*position)++] = paction->id;
6032 }
6034}
6035
6036/**********************************************************************/
6039const char *action_ui_name_default(int act)
6040{
6041 switch ((enum gen_action)act) {
6042 case ACTION_SPY_POISON:
6043 /* TRANS: _Poison City (3% chance of success). */
6044 return N_("%sPoison City%s");
6046 /* TRANS: _Poison City and Escape (3% chance of success). */
6047 return N_("%sPoison City and Escape%s");
6049 /* TRANS: S_abotage Enemy Unit (3% chance of success). */
6050 return N_("S%sabotage Enemy Unit%s");
6052 /* TRANS: S_abotage Enemy Unit and Escape (3% chance of success). */
6053 return N_("S%sabotage Enemy Unit and Escape%s");
6055 /* TRANS: Bribe Enemy _Unit (3% chance of success). */
6056 return N_("Bribe Enemy %sUnit%s");
6058 /* TRANS: Bribe Enemy _Stack (3% chance of success). */
6059 return N_("Bribe Enemy %sStack%s");
6061 /* TRANS: _Sabotage City (3% chance of success). */
6062 return N_("%sSabotage City%s");
6064 /* TRANS: _Sabotage City and Escape (3% chance of success). */
6065 return N_("%sSabotage City and Escape%s");
6067 /* TRANS: Industria_l Sabotage (3% chance of success). */
6068 return N_("Industria%sl Sabotage%s");
6070 /* TRANS: Industria_l Sabotage Production (3% chance of success). */
6071 return N_("Industria%sl Sabotage Production%s");
6073 /* TRANS: Industria_l Sabotage and Escape (3% chance of success). */
6074 return N_("Industria%sl Sabotage and Escape%s");
6076 /* TRANS: Industria_l Sabotage Production and Escape (3% chance of success). */
6077 return N_("Industria%sl Sabotage Production and Escape%s");
6079 /* TRANS: Incite a Re_volt (3% chance of success). */
6080 return N_("Incite a Re%svolt%s");
6082 /* TRANS: Incite a Re_volt and Escape (3% chance of success). */
6083 return N_("Incite a Re%svolt and Escape%s");
6085 /* TRANS: Establish _Embassy (100% chance of success). */
6086 return N_("Establish %sEmbassy%s");
6088 /* TRANS: Becom_e Ambassador (100% chance of success). */
6089 return N_("Becom%se Ambassador%s");
6091 /* TRANS: Steal _Technology (3% chance of success). */
6092 return N_("Steal %sTechnology%s");
6094 /* TRANS: Steal _Technology and Escape (3% chance of success). */
6095 return N_("Steal %sTechnology and Escape%s");
6097 /* TRANS: In_dustrial Espionage (3% chance of success). */
6098 return N_("In%sdustrial Espionage%s");
6100 /* TRANS: In_dustrial Espionage and Escape (3% chance of success). */
6101 return N_("In%sdustrial Espionage and Escape%s");
6103 /* TRANS: _Investigate City (100% chance of success). */
6104 return N_("%sInvestigate City%s");
6106 /* TRANS: _Investigate City (spends the unit) (100% chance of
6107 * success). */
6108 return N_("%sInvestigate City (spends the unit)%s");
6110 /* TRANS: Steal _Gold (100% chance of success). */
6111 return N_("Steal %sGold%s");
6113 /* TRANS: Steal _Gold and Escape (100% chance of success). */
6114 return N_("Steal %sGold and Escape%s");
6116 /* TRANS: Spread _Plague (100% chance of success). */
6117 return N_("Spread %sPlague%s");
6118 case ACTION_STEAL_MAPS:
6119 /* TRANS: Steal _Maps (100% chance of success). */
6120 return N_("Steal %sMaps%s");
6122 /* TRANS: Steal _Maps and Escape (100% chance of success). */
6123 return N_("Steal %sMaps and Escape%s");
6124 case ACTION_TRADE_ROUTE:
6125 /* TRANS: Establish Trade _Route (100% chance of success). */
6126 return N_("Establish Trade %sRoute%s");
6127 case ACTION_MARKETPLACE:
6128 /* TRANS: Enter _Marketplace (100% chance of success). */
6129 return N_("Enter %sMarketplace%s");
6130 case ACTION_HELP_WONDER:
6131 /* TRANS: Help _build Wonder (100% chance of success). */
6132 return N_("Help %sbuild Wonder%s");
6134 /* TRANS: _Capture Units (100% chance of success). */
6135 return N_("%sCapture Units%s");
6136 case ACTION_EXPEL_UNIT:
6137 /* TRANS: _Expel Unit (100% chance of success). */
6138 return N_("%sExpel Unit%s");
6139 case ACTION_FOUND_CITY:
6140 /* TRANS: _Found City (100% chance of success). */
6141 return N_("%sFound City%s");
6142 case ACTION_JOIN_CITY:
6143 /* TRANS: _Join City (100% chance of success). */
6144 return N_("%sJoin City%s");
6145 case ACTION_BOMBARD:
6146 /* TRANS: B_ombard (100% chance of success). */
6147 return N_("B%sombard%s");
6148 case ACTION_BOMBARD2:
6149 /* TRANS: B_ombard 2 (100% chance of success). */
6150 return N_("B%sombard 2%s");
6151 case ACTION_BOMBARD3:
6152 /* TRANS: B_ombard 3 (100% chance of success). */
6153 return N_("B%sombard 3%s");
6154 case ACTION_BOMBARD4:
6155 /* TRANS: B_ombard 4 (100% chance of success). */
6156 return N_("B%sombard 4%s");
6159 /* TRANS: Lethal B_ombard (100% chance of success). */
6160 return N_("Lethal B%sombard%s");
6161 case ACTION_SPY_NUKE:
6162 /* TRANS: Suitcase _Nuke (100% chance of success). */
6163 return N_("Suitcase %sNuke%s");
6165 /* TRANS: Suitcase _Nuke and Escape (100% chance of success). */
6166 return N_("Suitcase %sNuke and Escape%s");
6167 case ACTION_NUKE:
6168 /* TRANS: Explode _Nuclear (100% chance of success). */
6169 return N_("Explode %sNuclear%s");
6170 case ACTION_NUKE_CITY:
6171 /* TRANS: _Nuke City (100% chance of success). */
6172 return N_("%sNuke City%s");
6173 case ACTION_NUKE_UNITS:
6174 /* TRANS: _Nuke Units (100% chance of success). */
6175 return N_("%sNuke Units%s");
6177 /* TRANS: Destroy _City (100% chance of success). */
6178 return N_("Destroy %sCity%s");
6180 /* TRANS: Dis_band recovering production (100% chance of success). */
6181 return N_("Dis%sband recovering production%s");
6183 /* TRANS: Dis_band without recovering production (100% chance of success). */
6184 return N_("Dis%sband without recovering production%s");
6185 case ACTION_HOME_CITY:
6186 /* TRANS: Set _Home City (100% chance of success). */
6187 return N_("Set %sHome City%s");
6188 case ACTION_HOMELESS:
6189 /* TRANS: Make _Homeless (100% chance of success). */
6190 return N_("Make %sHomeless%s");
6192 /* TRANS: _Upgrade Unit (100% chance of success). */
6193 return N_("%sUpgrade Unit%s");
6194 case ACTION_PARADROP:
6195 /* TRANS: Drop _Paratrooper (100% chance of success). */
6196 return N_("Drop %sParatrooper%s");
6198 /* TRANS: Drop _Paratrooper (100% chance of success). */
6199 return N_("Drop %sParatrooper%s");
6201 /* TRANS: Drop _Paratrooper (100% chance of success). */
6202 return N_("Drop %sParatrooper%s");
6204 /* TRANS: Drop _Paratrooper (100% chance of success). */
6205 return N_("Drop %sParatrooper%s");
6207 /* TRANS: Drop _Paratrooper (100% chance of success). */
6208 return N_("Drop %sParatrooper%s");
6210 /* TRANS: Drop _Paratrooper (100% chance of success). */
6211 return N_("Drop %sParatrooper%s");
6212 case ACTION_AIRLIFT:
6213 /* TRANS: _Airlift to City (100% chance of success). */
6214 return N_("%sAirlift to City%s");
6215 case ACTION_ATTACK:
6216 case ACTION_ATTACK2:
6217 /* TRANS: _Attack (100% chance of success). */
6218 return N_("%sAttack%s");
6221 /* TRANS: _Suicide Attack (100% chance of success). */
6222 return N_("%sSuicide Attack%s");
6223 case ACTION_WIPE_UNITS:
6224 /* TRANS: _Wipe Units (100% chance of success). */
6225 return N_("%sWipe Units%s");
6227 /* TRANS: Collect _Ransom (100% chance of success). */
6228 return N_("Collect %sRansom%s");
6230 /* TRANS: Surgical Str_ike Building (100% chance of success). */
6231 return N_("Surgical Str%sike Building%s");
6233 /* TRANS: Surgical Str_ike Production (100% chance of success). */
6234 return N_("Surgical Str%sike Production%s");
6238 /* TRANS: _Conquer City (100% chance of success). */
6239 return N_("%sConquer City%s");
6241 /* TRANS: _Conquer City 2 (100% chance of success). */
6242 return N_("%sConquer City 2%s");
6246 /* TRANS: _Conquer Extras (100% chance of success). */
6247 return N_("%sConquer Extras%s");
6249 /* TRANS: _Conquer Extras 2 (100% chance of success). */
6250 return N_("%sConquer Extras 2%s");
6251 case ACTION_HEAL_UNIT:
6252 case ACTION_HEAL_UNIT2:
6253 /* TRANS: Heal _Unit (3% chance of success). */
6254 return N_("Heal %sUnit%s");
6257 /* TRANS: _Transform Terrain (3% chance of success). */
6258 return N_("%sTransform Terrain%s");
6259 case ACTION_CULTIVATE:
6260 case ACTION_CULTIVATE2:
6261 /* TRANS: Transform by _Cultivating (3% chance of success). */
6262 return N_("Transform by %sCultivating%s");
6263 case ACTION_PLANT:
6264 case ACTION_PLANT2:
6265 /* TRANS: Transform by _Planting (3% chance of success). */
6266 return N_("Transform by %sPlanting%s");
6267 case ACTION_PILLAGE:
6268 case ACTION_PILLAGE2:
6269 /* TRANS: Pilla_ge (100% chance of success). */
6270 return N_("Pilla%sge%s");
6271 case ACTION_CLEAN:
6272 case ACTION_CLEAN2:
6273 /* TRANS: Clean (100% chance of success). */
6274 return N_("%sClean%s");
6275 case ACTION_FORTIFY:
6276 case ACTION_FORTIFY2:
6277 /* TRANS: _Fortify (100% chance of success). */
6278 return N_("%sFortify%s");
6279 case ACTION_ROAD:
6280 case ACTION_ROAD2:
6281 /* TRANS: Build _Road (100% chance of success). */
6282 return N_("Build %sRoad%s");
6283 case ACTION_CONVERT:
6284 /* TRANS: _Convert Unit (100% chance of success). */
6285 return N_("%sConvert Unit%s");
6286 case ACTION_BASE:
6287 case ACTION_BASE2:
6288 /* TRANS: _Build Base (100% chance of success). */
6289 return N_("%sBuild Base%s");
6290 case ACTION_MINE:
6291 case ACTION_MINE2:
6292 /* TRANS: Build _Mine (100% chance of success). */
6293 return N_("Build %sMine%s");
6294 case ACTION_IRRIGATE:
6295 case ACTION_IRRIGATE2:
6296 /* TRANS: Build _Irrigation (100% chance of success). */
6297 return N_("Build %sIrrigation%s");
6299 /* TRANS: _Deboard (100% chance of success). */
6300 return N_("%sDeboard%s");
6304 /* TRANS: _Board (100% chance of success). */
6305 return N_("%sBoard%s");
6310 /* TRANS: _Embark (100% chance of success). */
6311 return N_("%sEmbark%s");
6313 /* TRANS: _Unload (100% chance of success). */
6314 return N_("%sUnload%s");
6318 /* TRANS: _Load (100% chance of success). */
6319 return N_("%sLoad%s");
6323 /* TRANS: _Disembark (100% chance of success). */
6324 return N_("%sDisembark%s");
6326 /* TRANS: _Disembark 2 (100% chance of success). */
6327 return N_("%sDisembark 2%s");
6328 case ACTION_SPY_ATTACK:
6329 /* TRANS: _Eliminate Diplomat (100% chance of success). */
6330 return N_("%sEliminate Diplomat%s");
6331 case ACTION_HUT_ENTER:
6332 case ACTION_HUT_ENTER2:
6333 case ACTION_HUT_ENTER3:
6334 case ACTION_HUT_ENTER4:
6335 /* TRANS: Enter _Hut (100% chance of success). */
6336 return N_("Enter %sHut%s");
6341 /* TRANS: Frighten _Hut (100% chance of success). */
6342 return N_("Frighten %sHut%s");
6343 case ACTION_UNIT_MOVE:
6344 case ACTION_UNIT_MOVE2:
6345 case ACTION_UNIT_MOVE3:
6346 /* TRANS: Regular _Move (100% chance of success). */
6347 return N_("Regular %sMove%s");
6348 case ACTION_TELEPORT:
6349 case ACTION_TELEPORT2:
6350 case ACTION_TELEPORT3:
6351 /* TRANS: _Teleport (100% chance of success). */
6352 return N_("%sTeleport%s");
6354 /* TRANS: _Teleport (100% chance of success). */
6355 return N_("%sTeleport%s");
6357 /* TRANS: _Teleport (100% chance of success). */
6358 return N_("%sTeleport%s");
6360 /* TRANS: _Teleport (100% chance of success). */
6361 return N_("%sTeleport%s");
6363 /* TRANS: _Teleport (100% chance of success). */
6364 return N_("%sTeleport%s");
6366 /* TRANS: _Teleport (100% chance of success). */
6367 return N_("%sTeleport%s");
6368 case ACTION_SPY_ESCAPE:
6369 /* TRANS: _Escape To Nearest City (100% chance of success). */
6370 return N_("%sEscape To Nearest City%s");
6372 /* TRANS: _User Action 1 (100% chance of success). */
6373 return N_("%sUser Action 1%s");
6375 /* TRANS: _User Action 2 (100% chance of success). */
6376 return N_("%sUser Action 2%s");
6378 /* TRANS: _User Action 3 (100% chance of success). */
6379 return N_("%sUser Action 3%s");
6381 /* TRANS: _User Action 4 (100% chance of success). */
6382 return N_("%sUser Action 4%s");
6384 return N_("%sGain Veterancy%s");
6385 case ACTION_ESCAPE:
6386 return N_("%sEscape%s");
6387 case ACTION_CIVIL_WAR:
6388 return N_("%sCivil War%s");
6389 case ACTION_FINISH_UNIT:
6390 return N_("Finish %sUnit%s");
6392 return N_("Finish %sBuilding%s");
6393 case ACTION_COUNT:
6394 fc_assert(act != ACTION_COUNT);
6395 break;
6396 }
6397
6398 return nullptr;
6399}
6400
6401/**********************************************************************/
6408{
6409 switch ((enum gen_action)act) {
6410 case ACTION_SPY_POISON:
6435 case ACTION_STEAL_MAPS:
6437 case ACTION_TRADE_ROUTE:
6438 case ACTION_MARKETPLACE:
6439 case ACTION_HELP_WONDER:
6441 case ACTION_EXPEL_UNIT:
6442 case ACTION_FOUND_CITY:
6443 case ACTION_JOIN_CITY:
6444 case ACTION_SPY_NUKE:
6449 case ACTION_HOME_CITY:
6450 case ACTION_HOMELESS:
6452 case ACTION_PARADROP:
6458 case ACTION_AIRLIFT:
6459 case ACTION_ATTACK:
6460 case ACTION_ATTACK2:
6463 case ACTION_WIPE_UNITS:
6471 case ACTION_HEAL_UNIT:
6472 case ACTION_HEAL_UNIT2:
6475 case ACTION_CULTIVATE:
6476 case ACTION_CULTIVATE2:
6477 case ACTION_PLANT:
6478 case ACTION_PLANT2:
6479 case ACTION_PILLAGE:
6480 case ACTION_PILLAGE2:
6481 case ACTION_CLEAN:
6482 case ACTION_CLEAN2:
6483 case ACTION_FORTIFY:
6484 case ACTION_FORTIFY2:
6485 case ACTION_ROAD:
6486 case ACTION_ROAD2:
6487 case ACTION_CONVERT:
6488 case ACTION_BASE:
6489 case ACTION_BASE2:
6490 case ACTION_MINE:
6491 case ACTION_MINE2:
6492 case ACTION_IRRIGATE:
6493 case ACTION_IRRIGATE2:
6510 case ACTION_BOMBARD:
6511 case ACTION_BOMBARD2:
6512 case ACTION_BOMBARD3:
6513 case ACTION_BOMBARD4:
6516 case ACTION_SPY_ATTACK:
6521 case ACTION_HUT_ENTER:
6522 case ACTION_HUT_ENTER2:
6523 case ACTION_HUT_ENTER3:
6524 case ACTION_HUT_ENTER4:
6529 case ACTION_UNIT_MOVE:
6530 case ACTION_UNIT_MOVE2:
6531 case ACTION_UNIT_MOVE3:
6532 case ACTION_SPY_ESCAPE:
6534 case ACTION_ESCAPE:
6535 case ACTION_CIVIL_WAR:
6536 case ACTION_FINISH_UNIT:
6538 /* Min range is not ruleset changeable */
6539 return nullptr;
6540 case ACTION_NUKE:
6541 return "explode_nuclear_min_range";
6542 case ACTION_NUKE_CITY:
6543 return "nuke_city_min_range";
6544 case ACTION_NUKE_UNITS:
6545 return "nuke_units_min_range";
6546 case ACTION_TELEPORT:
6547 return "teleport_min_range";
6548 case ACTION_TELEPORT2:
6549 return "teleport_2_min_range";
6550 case ACTION_TELEPORT3:
6551 return "teleport_3_min_range";
6553 return "teleport_conquer_min_range";
6555 return "teleport_frighten_min_range";
6557 return "teleport_frighten_conquer_min_range";
6559 return "teleport_enter_min_range";
6561 return "teleport_enter_conquer_min_range";
6563 return "user_action_1_min_range";
6565 return "user_action_2_min_range";
6567 return "user_action_3_min_range";
6569 return "user_action_4_min_range";
6570 case ACTION_COUNT:
6571 break;
6572
6574 }
6575
6576 fc_assert(act >= 0 && act < ACTION_COUNT);
6577
6578 return nullptr;
6579}
6580
6581/**********************************************************************/
6588{
6589 switch ((enum gen_action)act) {
6590 case ACTION_SPY_POISON:
6615 case ACTION_STEAL_MAPS:
6617 case ACTION_TRADE_ROUTE:
6618 case ACTION_MARKETPLACE:
6620 case ACTION_EXPEL_UNIT:
6621 case ACTION_FOUND_CITY:
6622 case ACTION_JOIN_CITY:
6623 case ACTION_SPY_NUKE:
6627 case ACTION_HOME_CITY:
6628 case ACTION_HOMELESS:
6630 case ACTION_PARADROP:
6636 case ACTION_ATTACK:
6637 case ACTION_ATTACK2:
6640 case ACTION_WIPE_UNITS:
6648 case ACTION_HEAL_UNIT:
6649 case ACTION_HEAL_UNIT2:
6652 case ACTION_CULTIVATE:
6653 case ACTION_CULTIVATE2:
6654 case ACTION_PLANT:
6655 case ACTION_PLANT2:
6656 case ACTION_PILLAGE:
6657 case ACTION_PILLAGE2:
6658 case ACTION_CLEAN:
6659 case ACTION_CLEAN2:
6660 case ACTION_FORTIFY:
6661 case ACTION_FORTIFY2:
6662 case ACTION_ROAD:
6663 case ACTION_ROAD2:
6664 case ACTION_CONVERT:
6665 case ACTION_BASE:
6666 case ACTION_BASE2:
6667 case ACTION_MINE:
6668 case ACTION_MINE2:
6669 case ACTION_IRRIGATE:
6670 case ACTION_IRRIGATE2:
6687 case ACTION_SPY_ATTACK:
6692 case ACTION_HUT_ENTER:
6693 case ACTION_HUT_ENTER2:
6694 case ACTION_HUT_ENTER3:
6695 case ACTION_HUT_ENTER4:
6700 case ACTION_UNIT_MOVE:
6701 case ACTION_UNIT_MOVE2:
6702 case ACTION_UNIT_MOVE3:
6703 case ACTION_SPY_ESCAPE:
6705 case ACTION_ESCAPE:
6706 case ACTION_CIVIL_WAR:
6707 case ACTION_FINISH_UNIT:
6709 /* Max range is not ruleset changeable */
6710 return nullptr;
6711 case ACTION_HELP_WONDER:
6712 return "help_wonder_max_range";
6714 return "disband_unit_recover_max_range";
6715 case ACTION_BOMBARD:
6716 return "bombard_max_range";
6717 case ACTION_BOMBARD2:
6718 return "bombard_2_max_range";
6719 case ACTION_BOMBARD3:
6720 return "bombard_3_max_range";
6721 case ACTION_BOMBARD4:
6722 return "bombard_4_max_range";
6724 return "bombard_lethal_max_range";
6726 return "bombard_lethal_2_max_range";
6727 case ACTION_NUKE:
6728 return "explode_nuclear_max_range";
6729 case ACTION_NUKE_CITY:
6730 return "nuke_city_max_range";
6731 case ACTION_NUKE_UNITS:
6732 return "nuke_units_max_range";
6733 case ACTION_AIRLIFT:
6734 return "airlift_max_range";
6735 case ACTION_TELEPORT:
6736 return "teleport_max_range";
6737 case ACTION_TELEPORT2:
6738 return "teleport_2_max_range";
6739 case ACTION_TELEPORT3:
6740 return "teleport_3_max_range";
6742 return "teleport_conquer_max_range";
6744 return "teleport_frighten_max_range";
6746 return "teleport_frighten_conquer_max_range";
6748 return "teleport_enter_max_range";
6750 return "teleport_enter_conquer_max_range";
6752 return "user_action_1_max_range";
6754 return "user_action_2_max_range";
6756 return "user_action_3_max_range";
6758 return "user_action_4_max_range";
6759 case ACTION_COUNT:
6760 break;
6761
6763 }
6764
6765 fc_assert(act >= 0 && act < ACTION_COUNT);
6766
6767 return nullptr;
6768}
6769
6770/**********************************************************************/
6777{
6778 switch ((enum gen_action)act) {
6779 case ACTION_SPY_POISON:
6804 case ACTION_STEAL_MAPS:
6806 case ACTION_TRADE_ROUTE:
6807 case ACTION_MARKETPLACE:
6808 case ACTION_HELP_WONDER:
6810 case ACTION_EXPEL_UNIT:
6811 case ACTION_FOUND_CITY:
6812 case ACTION_JOIN_CITY:
6813 case ACTION_SPY_NUKE:
6815 case ACTION_NUKE_UNITS:
6819 case ACTION_HOME_CITY:
6820 case ACTION_HOMELESS:
6822 case ACTION_PARADROP:
6828 case ACTION_AIRLIFT:
6829 case ACTION_ATTACK:
6830 case ACTION_ATTACK2:
6833 case ACTION_WIPE_UNITS:
6841 case ACTION_HEAL_UNIT:
6842 case ACTION_HEAL_UNIT2:
6845 case ACTION_CULTIVATE:
6846 case ACTION_CULTIVATE2:
6847 case ACTION_PLANT:
6848 case ACTION_PLANT2:
6849 case ACTION_CLEAN:
6850 case ACTION_CLEAN2:
6851 case ACTION_FORTIFY:
6852 case ACTION_FORTIFY2:
6853 case ACTION_ROAD:
6854 case ACTION_ROAD2:
6855 case ACTION_CONVERT:
6856 case ACTION_BASE:
6857 case ACTION_BASE2:
6858 case ACTION_MINE:
6859 case ACTION_MINE2:
6860 case ACTION_IRRIGATE:
6861 case ACTION_IRRIGATE2:
6878 case ACTION_BOMBARD:
6879 case ACTION_BOMBARD2:
6880 case ACTION_BOMBARD3:
6881 case ACTION_BOMBARD4:
6884 case ACTION_SPY_ATTACK:
6889 case ACTION_HUT_ENTER:
6890 case ACTION_HUT_ENTER2:
6891 case ACTION_HUT_ENTER3:
6892 case ACTION_HUT_ENTER4:
6897 case ACTION_UNIT_MOVE:
6898 case ACTION_UNIT_MOVE2:
6899 case ACTION_UNIT_MOVE3:
6900 case ACTION_TELEPORT:
6901 case ACTION_TELEPORT2:
6902 case ACTION_TELEPORT3:
6908 case ACTION_SPY_ESCAPE:
6910 case ACTION_ESCAPE:
6911 case ACTION_CIVIL_WAR:
6912 case ACTION_FINISH_UNIT:
6914 /* Target kind is not ruleset changeable */
6915 return nullptr;
6916 case ACTION_NUKE:
6917 return "explode_nuclear_target_kind";
6918 case ACTION_NUKE_CITY:
6919 return "nuke_city_target_kind";
6920 case ACTION_PILLAGE:
6921 return "pillage_target_kind";
6922 case ACTION_PILLAGE2:
6923 return "pillage_2_target_kind";
6925 return "user_action_1_target_kind";
6927 return "user_action_2_target_kind";
6929 return "user_action_3_target_kind";
6931 return "user_action_4_target_kind";
6932 case ACTION_COUNT:
6933 break;
6934
6936 }
6937
6938 fc_assert(act >= 0 && act < ACTION_COUNT);
6939
6940 return nullptr;
6941}
6942
6943/**********************************************************************/
6951{
6952 switch ((enum gen_action)act) {
6953 case ACTION_SPY_POISON:
6977 case ACTION_STEAL_MAPS:
6979 case ACTION_TRADE_ROUTE:
6980 case ACTION_MARKETPLACE:
6981 case ACTION_HELP_WONDER:
6983 case ACTION_EXPEL_UNIT:
6984 case ACTION_JOIN_CITY:
6985 case ACTION_SPY_NUKE:
6990 case ACTION_HOME_CITY:
6991 case ACTION_HOMELESS:
6993 case ACTION_PARADROP:
6999 case ACTION_AIRLIFT:
7000 case ACTION_ATTACK:
7001 case ACTION_ATTACK2:
7004 case ACTION_WIPE_UNITS:
7012 case ACTION_HEAL_UNIT:
7013 case ACTION_HEAL_UNIT2:
7016 case ACTION_CULTIVATE:
7017 case ACTION_CULTIVATE2:
7018 case ACTION_PLANT:
7019 case ACTION_PLANT2:
7020 case ACTION_PILLAGE:
7021 case ACTION_PILLAGE2:
7022 case ACTION_CLEAN:
7023 case ACTION_CLEAN2:
7024 case ACTION_FORTIFY:
7025 case ACTION_FORTIFY2:
7026 case ACTION_ROAD:
7027 case ACTION_ROAD2:
7028 case ACTION_CONVERT:
7029 case ACTION_BASE:
7030 case ACTION_BASE2:
7031 case ACTION_MINE:
7032 case ACTION_MINE2:
7033 case ACTION_IRRIGATE:
7034 case ACTION_IRRIGATE2:
7051 case ACTION_BOMBARD:
7052 case ACTION_BOMBARD2:
7053 case ACTION_BOMBARD3:
7054 case ACTION_BOMBARD4:
7057 case ACTION_SPY_ATTACK:
7062 case ACTION_HUT_ENTER:
7063 case ACTION_HUT_ENTER2:
7064 case ACTION_HUT_ENTER3:
7065 case ACTION_HUT_ENTER4:
7070 case ACTION_UNIT_MOVE:
7071 case ACTION_UNIT_MOVE2:
7072 case ACTION_UNIT_MOVE3:
7073 case ACTION_TELEPORT:
7074 case ACTION_TELEPORT2:
7075 case ACTION_TELEPORT3:
7081 case ACTION_SPY_ESCAPE:
7083 case ACTION_ESCAPE:
7084 case ACTION_CIVIL_WAR:
7085 case ACTION_FINISH_UNIT:
7087 /* Actor consuming always is not ruleset changeable */
7088 return nullptr;
7089 case ACTION_FOUND_CITY:
7090 return "found_city_consuming_always";
7091 case ACTION_NUKE:
7092 return "explode_nuclear_consuming_always";
7093 case ACTION_NUKE_CITY:
7094 return "nuke_city_consuming_always";
7095 case ACTION_NUKE_UNITS:
7096 return "nuke_units_consuming_always";
7098 return "spread_plague_actor_consuming_always";
7100 return "user_action_1_actor_consuming_always";
7102 return "user_action_2_actor_consuming_always";
7104 return "user_action_3_actor_consuming_always";
7106 return "user_action_4_actor_consuming_always";
7107 case ACTION_COUNT:
7108 break;
7109
7111 }
7112
7113 fc_assert(act >= 0 && act < ACTION_COUNT);
7114
7115 return nullptr;
7116}
7117
7118/**********************************************************************/
7125const char *action_blocked_by_ruleset_var_name(const struct action *act)
7126{
7127 fc_assert_ret_val(act != nullptr, nullptr);
7128
7129 switch ((enum gen_action)action_number(act)) {
7130 case ACTION_MARKETPLACE:
7131 return "enter_marketplace_blocked_by";
7132 case ACTION_BOMBARD:
7133 return "bombard_blocked_by";
7134 case ACTION_BOMBARD2:
7135 return "bombard_2_blocked_by";
7136 case ACTION_BOMBARD3:
7137 return "bombard_3_blocked_by";
7138 case ACTION_BOMBARD4:
7139 return "bombard_4_blocked_by";
7141 return "bombard_lethal_blocked_by";
7143 return "bombard_lethal_2_blocked_by";
7144 case ACTION_NUKE:
7145 return "explode_nuclear_blocked_by";
7146 case ACTION_NUKE_CITY:
7147 return "nuke_city_blocked_by";
7148 case ACTION_NUKE_UNITS:
7149 return "nuke_units_blocked_by";
7150 case ACTION_ATTACK:
7151 return "attack_blocked_by";
7152 case ACTION_ATTACK2:
7153 return "attack_2_blocked_by";
7155 return "suicide_attack_blocked_by";
7157 return "suicide_attack_2_blocked_by";
7158 case ACTION_WIPE_UNITS:
7159 return "wipe_units_blocked_by";
7161 return "collect_ransom_blocked_by";
7163 return "conquer_city_shrink_blocked_by";
7165 return "conquer_city_shrink_2_blocked_by";
7167 return "conquer_city_shrink_3_blocked_by";
7169 return "conquer_city_shrink_4_blocked_by";
7170 case ACTION_UNIT_MOVE:
7171 return "move_blocked_by";
7172 case ACTION_UNIT_MOVE2:
7173 return "move_2_blocked_by";
7174 case ACTION_UNIT_MOVE3:
7175 return "move_3_blocked_by";
7176 case ACTION_TELEPORT:
7177 return "teleport_blocked_by";
7178 case ACTION_TELEPORT2:
7179 return "teleport_2_blocked_by";
7180 case ACTION_TELEPORT3:
7181 return "teleport_3_blocked_by";
7183 return "teleport_conquer_blocked_by";
7185 return "teleport_frighten_blocked_by";
7187 return "teleport_frighten_conquer_blocked_by";
7189 return "teleport_enter_blocked_by";
7191 return "teleport_enter_conquer_blocked_by";
7192 case ACTION_SPY_ESCAPE:
7193 case ACTION_SPY_POISON:
7217 case ACTION_STEAL_MAPS:
7219 case ACTION_TRADE_ROUTE:
7220 case ACTION_HELP_WONDER:
7222 case ACTION_EXPEL_UNIT:
7223 case ACTION_FOUND_CITY:
7224 case ACTION_JOIN_CITY:
7225 case ACTION_SPY_NUKE:
7230 case ACTION_HOME_CITY:
7231 case ACTION_HOMELESS:
7233 case ACTION_PARADROP:
7239 case ACTION_AIRLIFT:
7242 case ACTION_HEAL_UNIT:
7243 case ACTION_HEAL_UNIT2:
7246 case ACTION_CULTIVATE:
7247 case ACTION_CULTIVATE2:
7248 case ACTION_PLANT:
7249 case ACTION_PLANT2:
7250 case ACTION_PILLAGE:
7251 case ACTION_PILLAGE2:
7252 case ACTION_CLEAN:
7253 case ACTION_CLEAN2:
7254 case ACTION_FORTIFY:
7255 case ACTION_FORTIFY2:
7256 case ACTION_ROAD:
7257 case ACTION_ROAD2:
7258 case ACTION_CONVERT:
7259 case ACTION_BASE:
7260 case ACTION_BASE2:
7261 case ACTION_MINE:
7262 case ACTION_MINE2:
7263 case ACTION_IRRIGATE:
7264 case ACTION_IRRIGATE2:
7282 case ACTION_SPY_ATTACK:
7287 case ACTION_HUT_ENTER:
7288 case ACTION_HUT_ENTER2:
7289 case ACTION_HUT_ENTER3:
7290 case ACTION_HUT_ENTER4:
7296 case ACTION_CIVIL_WAR:
7297 case ACTION_FINISH_UNIT:
7299 case ACTION_ESCAPE:
7304 /* blocked_by is not ruleset changeable */
7305 return nullptr;
7306 case ACTION_COUNT:
7308 break;
7309
7311 }
7312
7313 return nullptr;
7314}
7315
7316/**********************************************************************/
7320const char *
7322{
7323 fc_assert_ret_val(act != nullptr, nullptr);
7324
7330 /* No support in the action performer function */
7331 return nullptr;
7332 }
7333
7334 switch ((enum gen_action)action_number(act)) {
7336 return "bribe_unit_post_success_forced_actions";
7338 return "bribe_stack_post_success_forced_actions";
7339 case ACTION_ATTACK:
7340 return "attack_post_success_forced_actions";
7341 case ACTION_ATTACK2:
7342 return "attack_2_post_success_forced_actions";
7343 case ACTION_WIPE_UNITS:
7344 return "wipe_units_post_success_forced_actions";
7346 return "collect_ransom_post_success_forced_actions";
7347 case ACTION_MARKETPLACE:
7348 case ACTION_BOMBARD:
7349 case ACTION_BOMBARD2:
7350 case ACTION_BOMBARD3:
7351 case ACTION_BOMBARD4:
7354 case ACTION_NUKE:
7355 case ACTION_NUKE_CITY:
7356 case ACTION_NUKE_UNITS:
7363 case ACTION_SPY_POISON:
7385 case ACTION_STEAL_MAPS:
7387 case ACTION_TRADE_ROUTE:
7388 case ACTION_HELP_WONDER:
7390 case ACTION_EXPEL_UNIT:
7391 case ACTION_FOUND_CITY:
7392 case ACTION_JOIN_CITY:
7393 case ACTION_SPY_NUKE:
7398 case ACTION_HOME_CITY:
7399 case ACTION_HOMELESS:
7401 case ACTION_PARADROP:
7407 case ACTION_AIRLIFT:
7410 case ACTION_HEAL_UNIT:
7411 case ACTION_HEAL_UNIT2:
7414 case ACTION_CULTIVATE:
7415 case ACTION_CULTIVATE2:
7416 case ACTION_PLANT:
7417 case ACTION_PLANT2:
7418 case ACTION_PILLAGE:
7419 case ACTION_PILLAGE2:
7420 case ACTION_CLEAN:
7421 case ACTION_CLEAN2:
7422 case ACTION_FORTIFY:
7423 case ACTION_FORTIFY2:
7424 case ACTION_ROAD:
7425 case ACTION_ROAD2:
7426 case ACTION_CONVERT:
7427 case ACTION_BASE:
7428 case ACTION_BASE2:
7429 case ACTION_MINE:
7430 case ACTION_MINE2:
7431 case ACTION_IRRIGATE:
7432 case ACTION_IRRIGATE2:
7450 case ACTION_SPY_ATTACK:
7455 case ACTION_HUT_ENTER:
7456 case ACTION_HUT_ENTER2:
7457 case ACTION_HUT_ENTER3:
7458 case ACTION_HUT_ENTER4:
7463 case ACTION_UNIT_MOVE:
7464 case ACTION_UNIT_MOVE2:
7465 case ACTION_UNIT_MOVE3:
7466 case ACTION_TELEPORT:
7467 case ACTION_TELEPORT2:
7468 case ACTION_TELEPORT3:
7474 case ACTION_SPY_ESCAPE:
7476 case ACTION_ESCAPE:
7477 case ACTION_CIVIL_WAR:
7478 case ACTION_FINISH_UNIT:
7484 /* Not ruleset changeable */
7485 return nullptr;
7486 case ACTION_COUNT:
7488 break;
7489
7491 }
7492
7493 return nullptr;
7494}
7495
7496/**********************************************************************/
7504
7505/**********************************************************************/
7508const char *gen_action_name_update_cb(const char *old_name)
7509{
7510 if (is_ruleset_compat_mode()) {
7511 }
7512
7513 return old_name;
7514}
7515
7517{
7518 N_("individual cities"), /* ATK_CITY */
7519 N_("individual units"), /* ATK_UNIT */
7520 N_("unit stacks"), /* ATK_STACK */
7521 N_("tiles"), /* ATK_TILE */
7522 N_("tile extras"), /* ATK_EXTRAS */
7523 N_("itself") /* ATK_SELF */
7524};
7525
7526/**********************************************************************/
7531{
7532 fc_assert(kind >= 0 && kind < ATK_COUNT);
7533
7534 return _(atk_helpnames[kind]);
7535}
7536
7537/************************************************************************/
7541{
7542 fc_assert(result < ACTRES_LAST);
7543
7544 return actlist_by_result[result];
7545}
7546
7547/************************************************************************/
7551{
7552 fc_assert(activity < ACTIVITY_LAST);
7553
7554 return actlist_by_activity[activity];
7555}
bool is_action_possible_on_city(action_id act_id, const struct player *actor_player, const struct city *target_city)
Definition actions.c:5717
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:5205
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:2812
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:5795
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:4023
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:3441
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:5327
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:5956
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:3502
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:3286
bool action_prob_possible(const struct act_prob probability)
Definition actions.c:5317
#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:2605
struct act_prob action_prob_new_not_impl(void)
Definition actions.c:5296
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:3750
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:5138
void actions_rs_pre_san_gen(void)
Definition actions.c:899
const char * action_min_range_ruleset_var_name(int act)
Definition actions.c:6407
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:5239
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:3797
const char * action_blocked_by_ruleset_var_name(const struct action *act)
Definition actions.c:7125
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:2988
#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:4071
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:6021
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:5617
void action_array_end(action_id *act_array, int size)
Definition actions.c:6004
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:4838
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:3975
const char * atk_helpnames[ATK_COUNT]
Definition actions.c:7516
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:2625
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:3038
bool action_is_in_use(struct action *paction)
Definition actions.c:5910
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:7500
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:5368
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:3657
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:4938
const char * action_post_success_forced_ruleset_var_name(const struct action *act)
Definition actions.c:7321
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:5880
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:5338
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:3929
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:3363
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:3268
static enum fc_tristate tech_can_be_stolen(const struct player *actor_player, const struct player *target_player)
Definition actions.c:3816
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:7550
int action_number(const struct action *action)
Definition actions.c:1229
struct act_prob action_prob_new_unknown(void)
Definition actions.c:5306
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:5349
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:3344
struct act_prob action_prob_and(const struct act_prob *ap1, const struct act_prob *ap2)
Definition actions.c:5455
static bool actions_initialized
Definition actions.c:60
const char * action_actor_consuming_always_ruleset_var_name(action_id act)
Definition actions.c:6950
bool action_immune_government(struct government *gov, action_id act)
Definition actions.c:5673
static bool is_target_possible(const action_id wanted_action, const struct player *actor_player, const struct req_context *target)
Definition actions.c:5696
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:3852
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:4580
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:4921
struct act_prob action_prob_new_certain(void)
Definition actions.c:5276
const char * action_max_range_ruleset_var_name(int act)
Definition actions.c:6587
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:4393
bool action_is_internal(struct action *paction)
Definition actions.c:5936
int action_dice_roll_initial_odds(const struct action *paction)
Definition actions.c:5593
struct act_prob action_prob_self(const struct civ_map *nmap, const struct unit *actor_unit, const action_id act_id)
Definition actions.c:4991
struct act_prob action_prob_fall_back(const struct act_prob *ap1, const struct act_prob *ap2)
Definition actions.c:5525
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:3718
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:3612
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:4772
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:3543
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:3103
struct action_list * action_list_by_result(enum action_result result)
Definition actions.c:7540
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:3521
bool action_univs_not_blocking(const struct action *paction, struct universal *actor_uni, struct universal *target_uni)
Definition actions.c:5980
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:5070
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:3180
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:5171
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:4480
const char * action_target_kind_ruleset_var_name(int act)
Definition actions.c:6776
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:4496
bool action_maybe_possible_actor_unit(const struct civ_map *nmap, const action_id act_id, const struct unit *actor_unit)
Definition actions.c:5740
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:2971
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:3581
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:3688
const char * action_ui_name_default(int act)
Definition actions.c:6039
bool action_enablers_allow(const action_id wanted_action, const struct req_context *actor, const struct req_context *target)
Definition actions.c:3017
#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:5818
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:3957
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:5286
const char * action_target_kind_help(enum action_target_kind kind)
Definition actions.c:7530
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:5105
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:5972
struct act_prob action_prob_new_impossible(void)
Definition actions.c:5266
bool action_enabler_possible_actor(const struct action_enabler *ae)
Definition actions.c:5845
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:5013
static bool action_prob_is_signal(const struct act_prob probability)
Definition actions.c:5360
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:5377
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:4755
bool action_id_is_internal(action_id act)
Definition actions.c:5948
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:3493
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:4563
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:3421
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:3121
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:3198
double action_prob_to_0_to_1_pessimist(const struct act_prob ap)
Definition actions.c:5428
const char * gen_action_name_update_cb(const char *old_name)
Definition actions.c:7508
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:4855
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_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_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:673
enum act_tgt_compl actres_target_compl_calc(enum action_result result)
Definition actres.c:259
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:836
enum unit_activity actres_activity_result(enum action_result result)
Definition actres.c:302
enum dice_roll_type actres_dice_type(enum action_result result)
Definition actres.c:365
enum action_battle_kind actres_get_battle_kind(enum action_result result)
Definition actres.c:273
enum action_target_kind actres_target_kind_default(enum action_result result)
Definition actres.c:771
#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:759
#define city_tile(_pcity_)
Definition city.h:564
#define city_owner(_pcity_)
Definition city.h:563
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:56
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit * actor
Definition dialogs_g.h:73
struct unit * actor_unit
Definition dialogs_g.h:55
struct unit struct city struct unit struct tile * target_tile
Definition dialogs_g.h:57
struct unit struct city * target_city
Definition dialogs_g.h:56
struct unit struct city struct unit struct tile struct extra_type * target_extra
Definition dialogs_g.h:57
int int id
Definition editgui_g.h:28
struct @22::@23 reqs
int get_target_bonus_effects(struct effect_list *plist, const struct req_context *context, const struct req_context *other_context, enum effect_type effect_type)
Definition effects.c:744
struct effect_list * get_effects(enum effect_type effect_type)
Definition effects.c:143
#define effect_list_iterate_end
Definition effects.h:81
#define effect_list_iterate(effect_list, peffect)
Definition effects.h:79
struct extra_type_list * extra_type_list_of_terr_claimers(void)
Definition extras.c:275
bool is_native_extra_to_uclass(const struct extra_type *pextra, const struct unit_class *pclass)
Definition extras.c:857
#define extra_type_list_iterate(extralist, pextra)
Definition extras.h:165
#define extra_type_list_iterate_end
Definition extras.h:167
const struct functions * fc_funcs
int Tech_type_id
Definition fc_types.h: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:674
#define FC_FREE(ptr)
Definition mem.h:41
#define fc_malloc(sz)
Definition mem.h:34
bool can_see_techs_of_target(const struct player *pow_player, const struct player *target_player)
enum fc_tristate mke_eval_reqs(const struct player *pov_player, const struct req_context *context, const struct req_context *other_context, const struct requirement_vector *reqs, const enum req_problem_type prob_type)
bool can_unit_exist_at_tile(const struct civ_map *nmap, const struct unit *punit, const struct tile *ptile)
Definition movement.c:350
bool is_native_tile(const struct unit_type *punittype, const struct tile *ptile)
Definition movement.c:362
int unit_move_rate(const struct unit *punit)
Definition movement.c:89
bool unit_could_load_at(const struct unit *punit, const struct tile *ptile)
Definition movement.c:962
bool can_unit_type_transport(const struct unit_type *transporter, const struct unit_class *transported)
Definition movement.c:919
bool can_attack_non_native(const struct unit_type *utype)
Definition movement.c:213
void oblig_hard_reqs_init(void)
Definition oblig_reqs.c:809
void oblig_hard_reqs_free(void)
Definition oblig_reqs.c:829
void hard_code_oblig_hard_reqs_ruleset(void)
Definition oblig_reqs.c:772
void hard_code_oblig_hard_reqs(void)
Definition oblig_reqs.c:252
struct obligatory_req_vector * oblig_hard_reqs_get(enum action_result res)
Definition oblig_reqs.c:854
struct obligatory_req_vector * oblig_hard_reqs_get_sub(enum action_sub_result res)
Definition oblig_reqs.c:865
#define obligatory_req_vector_iterate_end
Definition oblig_reqs.h:48
#define obligatory_req_vector_iterate(obreq_vec, pobreq)
Definition oblig_reqs.h:46
bool can_player_see_tile(const struct player *plr, const struct tile *ptile)
Definition player.c: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:140
int moves_left
Definition unit.h:152
struct tile * tile
Definition unit.h:142
bool paradropped
Definition unit.h:177
const struct unit_type * utype
Definition unit.h:141
enum universals_n kind
Definition fc_types.h: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:98
#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:2545
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:2529
bool can_unit_unload(const struct unit *pcargo, const struct unit *ptrans)
Definition unit.c:795
bool unit_can_convert(const struct civ_map *nmap, const struct unit *punit)
Definition unit.c:2099
#define unit_tile(_pu)
Definition unit.h:407
#define unit_owner(_pu)
Definition unit.h:406
#define unit_home(_pu_)
Definition unit.h:404
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
#define unit_list_iterate_end
Definition unitlist.h:33
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c: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:2629
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:863
#define unit_type_iterate_end
Definition unittype.h:870
#define U_NOT_OBSOLETED
Definition unittype.h:535