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++) {
939 }
940 for (i = 0; i < ACTIVITY_LAST; i++) {
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 NULL;
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{
1156
1157 return paction->target_complexity >= ACT_TGT_COMPL_FLEXIBLE;
1158}
1159
1160/**********************************************************************/
1167{
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, NULL);
1274}
1275
1276/**********************************************************************/
1280 const char *mnemonic)
1281{
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 NULL;
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 == NULL || 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 != NULL && custom != NULL) {
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 != NULL) {
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 != NULL) {
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. */
1608
1609 /* Sanity check: a non existing action doesn't have any obligatory hard
1610 * requirements. */
1613
1614 /* No obligatory hard requirements. */
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 NULL;
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. */
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 != NULL) {
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 != NULL) {
1739 return out;
1740 }
1741 }
1742
1743 /* No obligatory req problems found. */
1744 return NULL;
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 NULL;
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 NULL;
1787 }
1788
1790 if (local_diplrel == NULL) {
1791 /* No local diplrel */
1792 return NULL;
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 NULL;
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 NULL;
1859 }
1860
1862 if (local_diplrel == NULL) {
1863 /* No local diplrel */
1864 return NULL;
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 == NULL) {
1878 /* No unclaimed req */
1879 return NULL;
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 != NULL) {
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 != NULL) {
1932 return out;
1933 }
1934
1935 out = req_vec_suggest_repair(&enabler->target_reqs,
1937 enabler);
1938 if (out != NULL) {
1939 return out;
1940 }
1941
1942 /* Enabler specific contradictions. */
1944 if (out != NULL) {
1945 return out;
1946 }
1947
1948 /* Needed in action not enabled explanation finding. */
1950 if (out != NULL) {
1951 return out;
1952 }
1953
1954 /* No problems found. */
1955 return NULL;
1956}
1957
1958/**********************************************************************/
1965static struct req_vec_problem *
1967{
1968 struct req_vec_problem *out;
1969
1970 out = NULL;
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 != NULL) {
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, NULL);
2077
2078 switch (number) {
2079 case 0:
2080 return &ae->actor_reqs;
2081 case 1:
2082 return &ae->target_reqs;
2083 default:
2084 return NULL;
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 NULL;
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 NULL;
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 NULL;
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 != NULL) {
2170 /* Trust the caller. */
2171 return target_tile_arg;
2172 }
2173
2174 /* Action should always be set */
2175 fc_assert_ret_val(act, NULL);
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 == NULL) {
2184 return NULL;
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 != NULL) {
2230 /* Trust the caller. */
2231 return target_city_arg;
2232 }
2233
2234 /* action should always be set */
2235 fc_assert_ret_val(act, NULL);
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 NULL;
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 }
2347 return blocker;
2348 }
2349 break;
2350 case ATK_EXTRAS:
2351 if (!target_tile) {
2352 /* Can't be enabled. No target. */
2353 continue;
2354 }
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 NULL;
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 != NULL) {
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 == NULL) {
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 == NULL) {
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
3011 enabler) {
3012 if (is_enabler_active(enabler, actor, target)) {
3013 return TRUE;
3014 }
3016
3017 return FALSE;
3018}
3019
3020/**********************************************************************/
3026static bool
3029 const struct unit *actor_unit,
3030 const struct city *actor_home,
3031 const struct tile *actor_tile,
3032 const struct city *target_city)
3033{
3034 const struct impr_type *target_building;
3035 const struct unit_type *target_utype;
3036
3037 if (actor_unit == NULL || target_city == NULL) {
3038 /* Can't do an action when actor or target are missing. */
3039 return FALSE;
3040 }
3041
3043 FALSE, "Action %s is performed by %s not %s",
3048
3051 FALSE, "Action %s is against %s not %s",
3056
3058
3060 /* No point in continuing. */
3061 return FALSE;
3062 }
3063
3066
3068 &(const struct req_context) {
3069 .player = unit_owner(actor_unit),
3070 .city = tile_city(actor_tile),
3071 .tile = actor_tile,
3072 .unit = actor_unit,
3073 .unittype = unit_type_get(actor_unit),
3074 },
3075 &(const struct req_context) {
3076 .player = city_owner(target_city),
3077 .city = target_city,
3078 .building = target_building,
3080 .unittype = target_utype,
3081 },
3082 NULL,
3083 actor_home);
3084}
3085
3086/**********************************************************************/
3102
3103/**********************************************************************/
3109static bool
3112 const struct unit *actor_unit,
3113 const struct city *actor_home,
3114 const struct tile *actor_tile,
3115 const struct unit *target_unit)
3116{
3117 if (actor_unit == NULL || target_unit == NULL) {
3118 /* Can't do an action when actor or target are missing. */
3119 return FALSE;
3120 }
3121
3123 FALSE, "Action %s is performed by %s not %s",
3128
3131 FALSE, "Action %s is against %s not %s",
3136
3138
3140 /* No point in continuing. */
3141 return FALSE;
3142 }
3143
3145 &(const struct req_context) {
3146 .player = unit_owner(actor_unit),
3147 .city = tile_city(actor_tile),
3148 .tile = actor_tile,
3149 .unit = actor_unit,
3150 .unittype = unit_type_get(actor_unit),
3151 },
3152 &(const struct req_context) {
3153 .player = unit_owner(target_unit),
3156 .unit = target_unit,
3157 .unittype = unit_type_get(target_unit),
3158 },
3159 NULL,
3160 actor_home);
3161}
3162
3163/**********************************************************************/
3179
3180/**********************************************************************/
3186static bool
3189 const struct unit *actor_unit,
3190 const struct city *actor_home,
3191 const struct tile *actor_tile,
3192 const struct tile *target_tile)
3193{
3194 const struct req_context *actor_ctxt;
3195
3196 if (actor_unit == NULL || target_tile == NULL
3197 || unit_list_size(target_tile->units) == 0) {
3198 /* Can't do an action when actor or target are missing. */
3199 return FALSE;
3200 }
3201
3203 FALSE, "Action %s is performed by %s not %s",
3208
3211 FALSE, "Action %s is against %s not %s",
3216
3218
3220 /* No point in continuing. */
3221 return FALSE;
3222 }
3223
3224 actor_ctxt = &(const struct req_context) {
3225 .player = unit_owner(actor_unit),
3226 .city = tile_city(actor_tile),
3227 .tile = actor_tile,
3228 .unit = actor_unit,
3229 .unittype = unit_type_get(actor_unit),
3230 };
3231
3234 &(const struct req_context) {
3235 .player = unit_owner(target_unit),
3238 .unit = target_unit,
3239 .unittype = unit_type_get(target_unit),
3240 },
3241 NULL, actor_home)) {
3242 /* One unit makes it impossible for all units. */
3243 return FALSE;
3244 }
3246
3247 /* Not impossible for any of the units at the tile. */
3248 return TRUE;
3249}
3250
3251/**********************************************************************/
3267
3268/**********************************************************************/
3274static bool
3277 const struct unit *actor_unit,
3278 const struct city *actor_home,
3279 const struct tile *actor_tile,
3280 const struct tile *target_tile,
3281 const struct extra_type *target_extra)
3282{
3283 if (actor_unit == NULL || target_tile == NULL) {
3284 /* Can't do an action when actor or target are missing. */
3285 return FALSE;
3286 }
3287
3289 FALSE, "Action %s is performed by %s not %s",
3294
3297 FALSE, "Action %s is against %s not %s",
3302
3304
3306 /* No point in continuing. */
3307 return FALSE;
3308 }
3309
3311 &(const struct req_context) {
3312 .player = unit_owner(actor_unit),
3313 .city = tile_city(actor_tile),
3314 .tile = actor_tile,
3315 .unit = actor_unit,
3316 .unittype = unit_type_get(actor_unit),
3317 },
3318 &(const struct req_context) {
3319 .player = tile_owner(target_tile),
3320 .city = tile_city(target_tile),
3321 .tile = target_tile,
3322 },
3324 actor_home);
3325}
3326
3327/**********************************************************************/
3335 const struct unit *actor_unit,
3336 const struct tile *target_tile,
3337 const struct extra_type *target_extra)
3338{
3343}
3344
3345/**********************************************************************/
3351static bool
3354 const struct unit *actor_unit,
3355 const struct city *actor_home,
3356 const struct tile *actor_tile,
3357 const struct tile *target_tile,
3358 const struct extra_type *target_extra)
3359{
3360 if (actor_unit == NULL || target_tile == NULL) {
3361 /* Can't do an action when actor or target are missing. */
3362 return FALSE;
3363 }
3364
3366 FALSE, "Action %s is performed by %s not %s",
3371
3374 FALSE, "Action %s is against %s not %s",
3379
3381
3383 /* No point in continuing. */
3384 return FALSE;
3385 }
3386
3388 &(const struct req_context) {
3389 .player = unit_owner(actor_unit),
3390 .city = tile_city(actor_tile),
3391 .tile = actor_tile,
3392 .unit = actor_unit,
3393 .unittype = unit_type_get(actor_unit),
3394 },
3395 &(const struct req_context) {
3396 .player = target_tile->extras_owner,
3397 .city = tile_city(target_tile),
3398 .tile = target_tile,
3399 },
3401 actor_home);
3402}
3403
3404/**********************************************************************/
3421
3422/**********************************************************************/
3429static bool
3432 const struct unit *actor_unit,
3433 const struct city *actor_home,
3434 const struct tile *actor_tile)
3435{
3436 if (actor_unit == NULL) {
3437 /* Can't do an action when the actor is missing. */
3438 return FALSE;
3439 }
3440
3442 FALSE, "Action %s is performed by %s not %s",
3447
3450 FALSE, "Action %s is against %s not %s",
3455
3457
3459 /* No point in continuing. */
3460 return FALSE;
3461 }
3462
3464 &(const struct req_context) {
3465 .player = unit_owner(actor_unit),
3466 .city = tile_city(actor_tile),
3467 .tile = actor_tile,
3468 .unit = actor_unit,
3469 .unittype = unit_type_get(actor_unit),
3470 },
3471 NULL, NULL,
3472 actor_home);
3473}
3474
3475/**********************************************************************/
3490
3491#define ASSERT_PLAYER_ACTION(_atk) \
3492 fc_assert_ret_val_msg(AAK_PLAYER == action_id_get_actor_kind(wanted_action),\
3493 FALSE, "Action %s is performed by %s not %s", \
3494 action_id_rule_name(wanted_action), \
3495 action_actor_kind_name( \
3496 action_id_get_actor_kind(wanted_action)), \
3497 action_actor_kind_name(AAK_PLAYER)); \
3498 fc_assert_ret_val_msg(_atk \
3499 == action_id_get_target_kind(wanted_action), \
3500 FALSE, "Action %s is against %s not %s", \
3501 action_id_rule_name(wanted_action), \
3502 action_target_kind_name( \
3503 action_id_get_target_kind(wanted_action)), \
3504 action_target_kind_name(_atk));
3505
3506/**********************************************************************/
3512 const struct player *actor_plr)
3513{
3514 if (actor_plr == nullptr) {
3515 /* Can't do an action when the actor is missing. */
3516 return FALSE;
3517 }
3518
3520
3522 &(const struct req_context) {
3523 .player = actor_plr,
3524 },
3525 nullptr, nullptr, nullptr);
3526}
3527
3528/**********************************************************************/
3534 const struct player *actor_plr,
3535 const struct city *target_city)
3536{
3537 const struct impr_type *target_building;
3538 const struct unit_type *target_utype;
3539
3540 if (actor_plr == nullptr || target_city == nullptr) {
3541 /* Can't do an action when the actor or the target is missing. */
3542 return FALSE;
3543 }
3544
3546
3549
3551 &(const struct req_context) {
3552 .player = actor_plr,
3553 },
3554 &(const struct req_context) {
3555 .player = city_owner(target_city),
3556 .city = target_city,
3557 .building = target_building,
3559 .unittype = target_utype,
3560 }, nullptr, nullptr);
3561}
3562
3563/**********************************************************************/
3569bool
3572 const struct player *actor_plr,
3573 const struct tile *target_tile,
3574 const struct extra_type *target_extra)
3575{
3576 if (actor_plr == nullptr || target_tile == nullptr) {
3577 /* Can't do an action when actor or target are missing. */
3578 return FALSE;
3579 }
3580
3582
3584 &(const struct req_context) {
3585 .player = actor_plr,
3586 },
3587 &(const struct req_context) {
3588 .player = target_tile->extras_owner,
3589 .city = tile_city(target_tile),
3590 .tile = target_tile,
3591 },
3592 target_extra, nullptr);
3593}
3594
3595/**********************************************************************/
3603 const struct player *actor_plr,
3604 const struct tile *target_tile,
3605 const struct extra_type *target_extra)
3606{
3607 const struct req_context actor_ctxt = {
3608 .player = actor_plr,
3609 };
3610 const struct city *tcity;
3611
3612 if (actor_plr == nullptr || target_tile == nullptr
3613 || unit_list_size(target_tile->units) == 0) {
3614 /* Can't do an action when actor or target are missing. */
3615 return FALSE;
3616 }
3617
3619
3623 &(const struct req_context) {
3624 .player = unit_owner(target_unit),
3625 .city = tcity,
3626 .tile = target_tile,
3627 .unit = target_unit,
3628 .unittype = unit_type_get(target_unit),
3629 },
3630 nullptr, nullptr)) {
3631 /* One unit makes it impossible for all units. */
3632 return FALSE;
3633 }
3635
3636 /* Not impossible for any of the units at the tile. */
3637 return TRUE;
3638}
3639
3640/**********************************************************************/
3648 const struct player *actor_plr,
3649 const struct tile *target_tile,
3650 const struct extra_type *target_extra)
3651{
3652 if (actor_plr == nullptr || target_tile == nullptr) {
3653 /* Can't do an action when actor or target are missing. */
3654 return FALSE;
3655 }
3656
3658
3660 &(const struct req_context) {
3661 .player = actor_plr,
3662 },
3663 &(const struct req_context) {
3664 .player = tile_owner(target_tile),
3665 .city = tile_city(target_tile),
3666 .tile = target_tile,
3667 },
3668 target_extra, nullptr);
3669}
3670
3671/**********************************************************************/
3679 const struct player *actor_plr,
3680 const struct unit *target_unit)
3681{
3682 if (actor_plr == nullptr || target_unit == nullptr) {
3683 /* Can't do an action when actor or target are missing. */
3684 return FALSE;
3685 }
3686
3688
3690 &(const struct req_context) {
3691 .player = actor_plr,
3692 },
3693 &(const struct req_context) {
3694 .player = unit_owner(target_unit),
3697 .unit = target_unit,
3698 .unittype = unit_type_get(target_unit),
3699 },
3700 nullptr, nullptr);
3701}
3702
3703/**********************************************************************/
3709 const struct city *actor_city)
3710{
3712 &(const struct req_context) {
3713 .player = city_owner(actor_city),
3714 .city = actor_city,
3715 .tile = city_tile(actor_city)
3716 },
3717 nullptr, nullptr, nullptr);
3718}
3719
3720/**********************************************************************/
3738static enum fc_tristate
3740 const struct req_context *actor,
3741 const struct req_context *target)
3742{
3743 enum fc_tristate current;
3744 enum fc_tristate result;
3745
3746 if (actor == NULL || actor->player == NULL) {
3747 /* Need actor->player for point of view */
3748 return TRI_MAYBE;
3749 }
3750
3751 if (target == NULL) {
3752 target = req_context_empty();
3753 }
3754
3755 result = TRI_NO;
3757 enabler) {
3758 current = fc_tristate_and(mke_eval_reqs(actor->player,
3759 actor, target,
3760 &enabler->actor_reqs,
3761 RPT_CERTAIN),
3762 mke_eval_reqs(actor->player,
3763 target, actor,
3764 &enabler->target_reqs,
3765 RPT_CERTAIN));
3766 if (current == TRI_YES) {
3767 return TRI_YES;
3768 } else if (current == TRI_MAYBE) {
3769 result = TRI_MAYBE;
3770 }
3772
3773 return result;
3774}
3775
3776/**********************************************************************/
3786static bool is_effect_val_known(enum effect_type effect_type,
3787 const struct player *pov_player,
3788 const struct req_context *context,
3789 const struct req_context *other_context)
3790{
3791 effect_list_iterate(get_effects(effect_type), peffect) {
3793 &(peffect->reqs), RPT_CERTAIN)) {
3794 return FALSE;
3795 }
3797
3798 return TRUE;
3799}
3800
3801/**********************************************************************/
3804static enum fc_tristate
3832
3833/**********************************************************************/
3842 const struct unit *pdefender)
3843{
3844 /* Keep unconverted until the end to avoid scaling each step */
3845 int chance;
3846 struct act_prob out;
3847
3848 /* Superspy always win */
3850 /* A defending UTYF_SUPERSPY will defeat every possible attacker. */
3851 return ACTPROB_IMPOSSIBLE;
3852 }
3854 /* An attacking UTYF_SUPERSPY will defeat every possible defender
3855 * except another UTYF_SUPERSPY. */
3856 return ACTPROB_CERTAIN;
3857 }
3858
3859 /* Base chance is 50% */
3860 chance = 50;
3861
3862 /* Spy attack bonus */
3864 chance += 25;
3865 }
3866
3867 /* Spy defense bonus */
3869 chance -= 25;
3870 }
3871
3872 /* Veteran attack and defense bonus */
3873 {
3874 const struct veteran_level *vatt
3876 const struct veteran_level *vdef
3878
3879 chance += vatt->power_fact - vdef->power_fact;
3880 }
3881
3882 /* Defense bonus. */
3883 {
3884 const struct req_context defender_ctxt = {
3885 .player = tile_owner(pdefender->tile),
3886 .city = tile_city(pdefender->tile),
3887 .tile = pdefender->tile,
3888 };
3891 NULL)) {
3892 return ACTPROB_NOT_KNOWN;
3893 }
3894
3895 /* Reduce the chance of an attack by EFT_SPY_RESISTANT percent. */
3897 NULL,
3899 NULL,
3901 ) / 100;
3902 }
3903
3904 chance = CLIP(0, chance, 100);
3905
3906 /* Convert to action probability */
3909
3910 return out;
3911}
3912
3913/**********************************************************************/
3919 const struct unit *pvictim,
3920 const struct tile *tgt_tile,
3921 const struct action *paction)
3922{
3923 struct unit *pdefender;
3924
3926 tgt_tile)) {
3927 /* Don't leak information about unseen defenders. */
3928 return ACTPROB_NOT_KNOWN;
3929 }
3930
3932 paction);
3933
3934 if (pdefender) {
3935 /* There will be a diplomatic battle instead of an action. */
3937 };
3938
3939 /* No diplomatic battle will occur. */
3940 return ACTPROB_CERTAIN;
3941}
3942
3943/**********************************************************************/
3947 action_id act_id,
3948 const struct unit *actor_unit)
3949{
3951 /* Unknown because the target is unseen. */
3952 return ACTPROB_NOT_KNOWN;
3953 } else {
3954 /* The actor it self can't do this. */
3955 return ACTPROB_IMPOSSIBLE;
3956 }
3957}
3958
3959/**********************************************************************/
3963static struct act_prob
3965 const struct unit *act_unit,
3966 const struct city *tgt_city,
3967 const struct player *tgt_player,
3968 const struct action *paction)
3969{
3971 &(const struct req_context) {
3972 .player = act_player,
3973 .city = tgt_city,
3974 .unit = act_unit,
3975 .unittype = unit_type_get(act_unit),
3976 },
3977 &(const struct req_context) {
3978 .player = tgt_player,
3979 })
3981 &(const struct req_context) {
3982 .player = tgt_player,
3983 .city = tgt_city,
3984 .unit = act_unit,
3985 },
3986 &(const struct req_context) {
3987 .player = act_player,
3988 })) {
3991 struct act_prob result = { .min = unconverted * ACTPROB_VAL_1_PCT,
3992 .max = unconverted * ACTPROB_VAL_1_PCT };
3993
3994 return result;
3995 } else {
3996 /* Could be improved to return a more exact probability in some cases.
3997 * Example: The player has enough information to know that the
3998 * probability always will be above 25% and always under 75% because
3999 * the only effect with unknown requirements that may apply adds (or
4000 * subtracts) 50% while all the requirements of the other effects that
4001 * may apply are known. */
4002 return ACTPROB_NOT_KNOWN;
4003 }
4004}
4005
4006/**********************************************************************/
4011static struct act_prob
4013 const struct unit *act_unit,
4014 const struct city *tgt_city,
4015 const struct unit *tgt_unit,
4016 const struct tile *tgt_tile,
4017 const struct player *tgt_player,
4018 const struct action *paction)
4019{
4020 struct act_prob battle;
4021 struct act_prob dice_roll;
4022
4023 battle = ACTPROB_CERTAIN;
4024 switch (actres_get_battle_kind(paction->result)) {
4025 case ABK_NONE:
4026 /* No pre action battle. */
4027 break;
4028 case ABK_DIPLOMATIC:
4030 paction);
4031 break;
4032 case ABK_STANDARD:
4033 /* Not supported here yet. Implement when users appear. */
4035 break;
4036 case ABK_COUNT:
4038 break;
4039 }
4040
4043 paction);
4044
4045 return action_prob_and(&battle, &dice_roll);
4046}
4047
4048/**********************************************************************/
4059static struct act_prob
4062 const struct req_context *actor,
4063 const struct city *actor_home,
4064 const struct req_context *target,
4065 const struct extra_type *target_extra)
4066{
4067 enum fc_tristate known;
4068 struct act_prob chance;
4070
4071 if (actor == NULL) {
4073 }
4074 if (target == NULL) {
4075 target = req_context_empty();
4076 }
4077
4078 known = is_action_possible(nmap, wanted_action, actor, target,
4080 FALSE, actor_home);
4081
4082 if (known == TRI_NO) {
4083 /* The action enablers are irrelevant since the action it self is
4084 * impossible. */
4085 return ACTPROB_IMPOSSIBLE;
4086 }
4087
4089
4090 known = fc_tristate_and(known,
4092 actor, target));
4093
4094 switch (paction->result) {
4095 case ACTRES_SPY_POISON:
4096 /* All uncertainty comes from potential diplomatic battles and the
4097 * (diplchance server setting and the) Action_Odds_Pct effect controlled
4098 * dice roll before the action. */
4100 target->city, target->unit,
4101 target->tile, target->player,
4102 paction);
4103 break;
4105 /* TODO */
4106 break;
4108 /* TODO */
4109 break;
4110 case ACTRES_STEAL_MAPS:
4111 /* TODO */
4112 break;
4114 /* All uncertainty comes from potential diplomatic battles. */
4115 chance = ap_diplomat_battle(actor->unit, target->unit, target->tile,
4116 paction);
4117 break;
4120 /* All uncertainty comes from potential diplomatic battles. */
4121 chance = ap_diplomat_battle(actor->unit, target->unit, target->tile,
4122 paction);
4123 break;
4124 case ACTRES_SPY_ATTACK:
4125 /* All uncertainty comes from potential diplomatic battles. */
4126 chance = ap_diplomat_battle(actor->unit, NULL, target->tile,
4127 paction);
4128 break;
4130 /* TODO */
4131 break;
4133 /* TODO */
4134 break;
4136 /* TODO */
4137 break;
4139 /* TODO */
4140 break;
4143 break;
4145 /* Do the victim have anything worth taking? */
4146 known = fc_tristate_and(known,
4147 tech_can_be_stolen(actor->player,
4148 target->player));
4149
4150 /* TODO: Calculate actual chance */
4151
4152 break;
4154 /* Do the victim have anything worth taking? */
4155 known = fc_tristate_and(known,
4156 tech_can_be_stolen(actor->player,
4157 target->player));
4158
4159 /* TODO: Calculate actual chance */
4160
4161 break;
4163 /* There is no risk that the city won't get investigated. */
4165 break;
4166 case ACTRES_SPY_ESCAPE:
4167 /* TODO */
4168 break;
4169 case ACTRES_TRADE_ROUTE:
4170 /* TODO */
4171 break;
4172 case ACTRES_MARKETPLACE:
4173 /* Possible when not blocked by is_action_possible() */
4175 break;
4176 case ACTRES_HELP_WONDER:
4177 /* Possible when not blocked by is_action_possible() */
4179 break;
4181 /* No battle is fought first. */
4183 break;
4184 case ACTRES_EXPEL_UNIT:
4185 /* No battle is fought first. */
4187 break;
4188 case ACTRES_BOMBARD:
4189 /* No battle is fought first. */
4191 break;
4192 case ACTRES_FOUND_CITY:
4193 /* Possible when not blocked by is_action_possible() */
4195 break;
4196 case ACTRES_JOIN_CITY:
4197 /* Possible when not blocked by is_action_possible() */
4199 break;
4200 case ACTRES_SPY_NUKE:
4201 /* All uncertainty comes from potential diplomatic battles and the
4202 * (diplchance server setting and the) Action_Odds_Pct effect controlled
4203 * dice roll before the action. */
4205 target->city, target->unit,
4206 target->tile,
4207 target->player,
4208 paction);
4209 break;
4210 case ACTRES_NUKE:
4211 /* TODO */
4212 break;
4213 case ACTRES_NUKE_UNITS:
4214 /* TODO */
4215 break;
4217 /* No battle is fought first. */
4219 break;
4221 /* No battle is fought first. */
4223 break;
4225 /* No battle is fought first. */
4227 break;
4228 case ACTRES_HOME_CITY:
4229 /* No battle is fought first. */
4231 break;
4232 case ACTRES_HOMELESS:
4233 /* No battle is fought first. */
4235 break;
4237 /* No battle is fought first. */
4239 break;
4240 case ACTRES_PARADROP:
4242 /* TODO */
4243 break;
4244 case ACTRES_AIRLIFT:
4245 /* Possible when not blocked by is_action_possible() */
4247 break;
4248 case ACTRES_ATTACK:
4250 {
4251 struct unit *defender_unit = get_defender(nmap, actor->unit,
4252 target->tile, paction);
4253
4254 if (can_player_see_unit(actor->player, defender_unit)) {
4255 double unconverted = unit_win_chance(nmap, actor->unit,
4257
4259 floor((double)ACTPROB_VAL_MAX * unconverted));
4261 ceil((double)ACTPROB_VAL_MAX * unconverted));
4262 } else if (known == TRI_YES) {
4263 known = TRI_MAYBE;
4264 }
4265 }
4266 break;
4267 case ACTRES_WIPE_UNITS:
4269 break;
4271 /* TODO: not implemented yet because:
4272 * - dice roll 100% * Action_Odds_Pct could be handled with
4273 * action_prob_pre_action_dice_roll().
4274 * - sub target building may be missing. May be missing without player
4275 * knowledge if it isn't visible. See is_improvement_visible() and
4276 * can_player_see_city_internals(). */
4277 break;
4279 /* All uncertainty comes from the (diplchance server setting and the)
4280 * Action_Odds_Pct effect controlled dice roll before the action. */
4282 target->city, target->player,
4283 paction);
4284 break;
4286 /* No battle is fought first. */
4288 break;
4290 /* No battle is fought first. */
4292 break;
4293 case ACTRES_HEAL_UNIT:
4294 /* No battle is fought first. */
4296 break;
4298 case ACTRES_CULTIVATE:
4299 case ACTRES_PLANT:
4300 case ACTRES_PILLAGE:
4301 case ACTRES_CLEAN:
4302 case ACTRES_FORTIFY:
4303 case ACTRES_ROAD:
4304 case ACTRES_CONVERT:
4305 case ACTRES_BASE:
4306 case ACTRES_MINE:
4307 case ACTRES_IRRIGATE:
4309 break;
4312 break;
4315 break;
4318 break;
4321 break;
4324 break;
4327 break;
4328 case ACTRES_HUT_ENTER:
4330 /* Entering the hut happens with a probability of 100%. What happens
4331 * next is probably up to dice rolls in Lua. */
4333 break;
4334 case ACTRES_UNIT_MOVE:
4335 case ACTRES_TELEPORT:
4338 break;
4339 /* Not UI action, so chance is meaningless */
4342 break;
4343 case ACTRES_NONE:
4344 /* Accommodate ruleset authors that wishes to roll the dice in Lua.
4345 * Would be ACTPROB_CERTAIN if not for that. */
4346 /* TODO: maybe allow the ruleset author to give a probability from
4347 * Lua? */
4349 break;
4350 }
4351
4352 /* Non signal action probabilities should be in range. */
4354 || chance.max <= ACTPROB_VAL_MAX),
4355 chance.max = ACTPROB_VAL_MAX);
4357 || chance.min >= ACTPROB_VAL_MIN),
4358 chance.min = ACTPROB_VAL_MIN);
4359
4360 switch (known) {
4361 case TRI_NO:
4362 return ACTPROB_IMPOSSIBLE;
4363 break;
4364 case TRI_MAYBE:
4365 return ACTPROB_NOT_KNOWN;
4366 break;
4367 case TRI_YES:
4368 return chance;
4369 break;
4370 };
4371
4372 fc_assert_msg(FALSE, "Should be yes, maybe or no");
4373
4375}
4376
4377/**********************************************************************/
4381static struct act_prob
4383 const struct unit *actor_unit,
4384 const struct city *actor_home,
4385 const struct tile *actor_tile,
4386 const action_id act_id,
4387 const struct city *target_city)
4388{
4389 const struct impr_type *target_building;
4390 const struct unit_type *target_utype;
4391 const struct action *act = action_by_number(act_id);
4392
4393 if (actor_unit == NULL || target_city == NULL) {
4394 /* Can't do an action when actor or target are missing. */
4395 return ACTPROB_IMPOSSIBLE;
4396 }
4397
4400 "Action %s is performed by %s not %s",
4401 action_id_rule_name(act_id),
4403 action_id_get_actor_kind(act_id)),
4405
4408 "Action %s is against %s not %s",
4409 action_id_rule_name(act_id),
4413
4415
4416 if (!unit_can_do_action(actor_unit, act_id)) {
4417 /* No point in continuing. */
4418 return ACTPROB_IMPOSSIBLE;
4419 }
4420
4421 /* Doesn't leak information about city position since an unknown city
4422 * can't be targeted and a city can't move. */
4423 if (!action_id_distance_accepted(act_id,
4426 /* No point in continuing. */
4427 return ACTPROB_IMPOSSIBLE;
4428 }
4429
4430 /* Doesn't leak information since it must be 100% certain from the
4431 * player's perspective that the blocking action is legal. */
4434 /* Don't offer to perform an action known to be blocked. */
4435 return ACTPROB_IMPOSSIBLE;
4436 }
4437
4439 /* The invisible city at this tile may, as far as the player knows, not
4440 * exist anymore. */
4441 return act_prob_unseen_target(nmap, act_id, actor_unit);
4442 }
4443
4446
4447 return action_prob(nmap, act_id,
4448 &(const struct req_context) {
4449 .player = unit_owner(actor_unit),
4450 .city = tile_city(actor_tile),
4451 .tile = actor_tile,
4452 .unit = actor_unit,
4453 .unittype = unit_type_get(actor_unit),
4454 },
4455 actor_home,
4456 &(const struct req_context) {
4457 .player = city_owner(target_city),
4458 .city = target_city,
4459 .building = target_building,
4461 .unittype = target_utype,
4462 }, NULL);
4463}
4464
4465/**********************************************************************/
4470 const struct unit *actor_unit,
4471 const action_id act_id,
4472 const struct city *target_city)
4473{
4477 act_id, target_city);
4478}
4479
4480/**********************************************************************/
4484static struct act_prob
4486 const struct unit *actor_unit,
4487 const struct city *actor_home,
4488 const struct tile *actor_tile,
4489 const action_id act_id,
4490 const struct unit *target_unit)
4491{
4492 if (actor_unit == NULL || target_unit == NULL) {
4493 /* Can't do an action when actor or target are missing. */
4494 return ACTPROB_IMPOSSIBLE;
4495 }
4496
4499 "Action %s is performed by %s not %s",
4500 action_id_rule_name(act_id),
4502 action_id_get_actor_kind(act_id)),
4504
4507 "Action %s is against %s not %s",
4508 action_id_rule_name(act_id),
4512
4514
4515 if (!unit_can_do_action(actor_unit, act_id)) {
4516 /* No point in continuing. */
4517 return ACTPROB_IMPOSSIBLE;
4518 }
4519
4520 /* Doesn't leak information about unit position since an unseen unit can't
4521 * be targeted. */
4522 if (!action_id_distance_accepted(act_id,
4525 /* No point in continuing. */
4526 return ACTPROB_IMPOSSIBLE;
4527 }
4528
4529 return action_prob(nmap, act_id,
4530 &(const struct req_context) {
4531 .player = unit_owner(actor_unit),
4532 .city = tile_city(actor_tile),
4533 .tile = actor_tile,
4534 .unit = actor_unit,
4535 .unittype = unit_type_get(actor_unit),
4536 },
4537 actor_home,
4538 &(const struct req_context) {
4539 .player = unit_owner(target_unit),
4542 .unit = target_unit,
4543 .unittype = unit_type_get(target_unit),
4544 },
4545 NULL);
4546}
4547
4548/**********************************************************************/
4553 const struct unit *actor_unit,
4554 const action_id act_id,
4555 const struct unit *target_unit)
4556{
4560 act_id,
4561 target_unit);
4562}
4563
4564/**********************************************************************/
4568static struct act_prob
4570 const struct unit *actor_unit,
4571 const struct city *actor_home,
4572 const struct tile *actor_tile,
4573 const action_id act_id,
4574 const struct tile *target_tile)
4575{
4576 struct act_prob prob_all;
4577 const struct req_context *actor_ctxt;
4578 const struct action *act = action_by_number(act_id);
4579
4580 if (actor_unit == NULL || target_tile == NULL) {
4581 /* Can't do an action when actor or target are missing. */
4582 return ACTPROB_IMPOSSIBLE;
4583 }
4584
4587 "Action %s is performed by %s not %s",
4588 action_id_rule_name(act_id),
4590 action_id_get_actor_kind(act_id)),
4592
4595 "Action %s is against %s not %s",
4596 action_id_rule_name(act_id),
4600
4602
4603 if (!unit_can_do_action(actor_unit, act_id)) {
4604 /* No point in continuing. */
4605 return ACTPROB_IMPOSSIBLE;
4606 }
4607
4608 /* Doesn't leak information about unit stack position since it is
4609 * specified as a tile and an unknown tile's position is known. */
4610 if (!action_id_distance_accepted(act_id,
4612 target_tile))) {
4613 /* No point in continuing. */
4614 return ACTPROB_IMPOSSIBLE;
4615 }
4616
4617 /* Doesn't leak information since the actor player can see the target
4618 * tile. */
4622 act_id,
4623 CITYT_CENTER, TRUE)) {
4624 /* Don't offer to perform actions that never can target a unit stack in
4625 * a city. */
4626 return ACTPROB_IMPOSSIBLE;
4627 }
4628
4629 /* Doesn't leak information since it must be 100% certain from the
4630 * player's perspective that the blocking action is legal. */
4634 target_unit)) {
4635 /* Don't offer to perform an action known to be blocked. */
4636 return ACTPROB_IMPOSSIBLE;
4637 }
4639
4640 /* Must be done here since an empty unseen tile will result in
4641 * ACTPROB_IMPOSSIBLE. */
4642 if (unit_list_size(target_tile->units) == 0) {
4643 /* Can't act against an empty tile. */
4644
4646 target_tile)) {
4647 /* Known empty tile. */
4648 return ACTPROB_IMPOSSIBLE;
4649 } else {
4650 /* The player doesn't know that the tile is empty. */
4651 return act_prob_unseen_target(nmap, act_id, actor_unit);
4652 }
4653 }
4654
4661 /* Hard coded rule: can't "Bombard", "Suicide Attack", or "Attack"
4662 * units in non enemy cities. */
4663 return ACTPROB_IMPOSSIBLE;
4664 }
4665
4672 /* Hard coded rule: can't "Nuke Units", "Wipe Units", "Suicide Attack",
4673 * or "Attack" units on non native tile without "AttackNonNative" and
4674 * not "Only_Native_Attack". */
4675 return ACTPROB_IMPOSSIBLE;
4676 }
4677
4678 /* Invisible units at this tile can make the action legal or illegal.
4679 * Invisible units can be stacked with visible units. The possible
4680 * existence of invisible units therefore makes the result uncertain. */
4684
4685 actor_ctxt = &(const struct req_context) {
4686 .player = unit_owner(actor_unit),
4687 .city = tile_city(actor_tile),
4688 .tile = actor_tile,
4689 .unit = actor_unit,
4690 .unittype = unit_type_get(actor_unit),
4691 };
4692
4694 struct act_prob prob_unit;
4695
4697 /* Only visible units are considered. The invisible units contributed
4698 * their uncertainty to prob_all above. */
4699 continue;
4700 }
4701
4703 &(const struct req_context) {
4704 .player = unit_owner(target_unit),
4707 .unit = target_unit,
4708 .unittype = unit_type_get(target_unit),
4709 },
4710 NULL);
4711
4713 /* One unit makes it impossible for all units. */
4714 return ACTPROB_IMPOSSIBLE;
4715 } else if (action_prob_not_impl(prob_unit)) {
4716 /* Not implemented dominates all except impossible. */
4718 } else {
4720 "Invalid probability [%d, %d]",
4721 prob_unit.min, prob_unit.max);
4722
4724 /* Special values dominate regular values. */
4725 continue;
4726 }
4727
4728 /* Probability against all target units considered until this moment
4729 * and the probability against this target unit. */
4730 prob_all.min = (prob_all.min * prob_unit.min) / ACTPROB_VAL_MAX;
4731 prob_all.max = (prob_all.max * prob_unit.max) / ACTPROB_VAL_MAX;
4732 break;
4733 }
4735
4736 /* Not impossible for any of the units at the tile. */
4737 return prob_all;
4738}
4739
4740/**********************************************************************/
4745 const struct unit *actor_unit,
4746 const action_id act_id,
4747 const struct tile *target_tile)
4748{
4752 act_id,
4753 target_tile);
4754}
4755
4756/**********************************************************************/
4760static struct act_prob
4762 const struct unit *actor_unit,
4763 const struct city *actor_home,
4764 const struct tile *actor_tile,
4765 const action_id act_id,
4766 const struct tile *target_tile,
4767 const struct extra_type *target_extra)
4768{
4769 if (actor_unit == NULL || target_tile == NULL) {
4770 /* Can't do an action when actor or target are missing. */
4771 return ACTPROB_IMPOSSIBLE;
4772 }
4773
4776 "Action %s is performed by %s not %s",
4777 action_id_rule_name(act_id),
4779 action_id_get_actor_kind(act_id)),
4781
4784 "Action %s is against %s not %s",
4785 action_id_rule_name(act_id),
4789
4791
4792 if (!unit_can_do_action(actor_unit, act_id)) {
4793 /* No point in continuing. */
4794 return ACTPROB_IMPOSSIBLE;
4795 }
4796
4797 /* Doesn't leak information about tile position since an unknown tile's
4798 * position is known. */
4799 if (!action_id_distance_accepted(act_id,
4801 target_tile))) {
4802 /* No point in continuing. */
4803 return ACTPROB_IMPOSSIBLE;
4804 }
4805
4806 return action_prob(nmap, act_id,
4807 &(const struct req_context) {
4808 .player = unit_owner(actor_unit),
4809 .city = tile_city(actor_tile),
4810 .tile = actor_tile,
4811 .unit = actor_unit,
4812 .unittype = unit_type_get(actor_unit),
4813 },
4814 actor_home,
4815 &(const struct req_context) {
4816 .player = tile_owner(target_tile),
4817 .city = tile_city(target_tile),
4818 .tile = target_tile,
4819 },
4820 target_extra);
4821}
4822
4823/**********************************************************************/
4828 const struct unit *actor_unit,
4829 const action_id act_id,
4830 const struct tile *target_tile,
4831 const struct extra_type *target_extra)
4832{
4836 act_id, target_tile, target_extra);
4837}
4838
4839/**********************************************************************/
4843static struct act_prob
4845 const struct unit *actor_unit,
4846 const struct city *actor_home,
4847 const struct tile *actor_tile,
4848 const action_id act_id,
4849 const struct tile *target_tile,
4850 const struct extra_type *target_extra)
4851{
4852 if (actor_unit == NULL || target_tile == NULL) {
4853 /* Can't do an action when actor or target are missing. */
4854 return ACTPROB_IMPOSSIBLE;
4855 }
4856
4859 "Action %s is performed by %s not %s",
4860 action_id_rule_name(act_id),
4862 action_id_get_actor_kind(act_id)),
4864
4867 "Action %s is against %s not %s",
4868 action_id_rule_name(act_id),
4872
4874
4875 if (!unit_can_do_action(actor_unit, act_id)) {
4876 /* No point in continuing. */
4877 return ACTPROB_IMPOSSIBLE;
4878 }
4879
4880 /* Doesn't leak information about tile position since an unknown tile's
4881 * position is known. */
4882 if (!action_id_distance_accepted(act_id,
4884 target_tile))) {
4885 /* No point in continuing. */
4886 return ACTPROB_IMPOSSIBLE;
4887 }
4888
4889 return action_prob(nmap, act_id,
4890 &(const struct req_context) {
4891 .player = unit_owner(actor_unit),
4892 .city = tile_city(actor_tile),
4893 .tile = actor_tile,
4894 .unit = actor_unit,
4895 .unittype = unit_type_get(actor_unit),
4896 },
4897 actor_home,
4898 &(const struct req_context) {
4899 .player = target_tile->extras_owner,
4900 .city = tile_city(target_tile),
4901 .tile = target_tile,
4902 },
4903 target_extra);
4904}
4905
4906/**********************************************************************/
4911 const struct unit *actor_unit,
4912 const action_id act_id,
4913 const struct tile *target_tile,
4914 const struct extra_type *target_extra)
4915{
4919 act_id, target_tile, target_extra);
4920}
4921
4922/**********************************************************************/
4926static struct act_prob
4928 const struct unit *actor_unit,
4929 const struct city *actor_home,
4930 const struct tile *actor_tile,
4931 const action_id act_id)
4932{
4933 if (actor_unit == NULL) {
4934 /* Can't do the action when the actor is missing. */
4935 return ACTPROB_IMPOSSIBLE;
4936 }
4937
4938 /* No point in checking distance to target. It is always 0. */
4939
4942 "Action %s is performed by %s not %s",
4943 action_id_rule_name(act_id),
4945 action_id_get_actor_kind(act_id)),
4947
4950 "Action %s is against %s not %s",
4951 action_id_rule_name(act_id),
4955
4957
4958 if (!unit_can_do_action(actor_unit, act_id)) {
4959 /* No point in continuing. */
4960 return ACTPROB_IMPOSSIBLE;
4961 }
4962
4963 return action_prob(nmap, act_id,
4964 &(const struct req_context) {
4965 .player = unit_owner(actor_unit),
4966 .city = tile_city(actor_tile),
4967 .tile = actor_tile,
4968 .unit = actor_unit,
4969 .unittype = unit_type_get(actor_unit),
4970 },
4971 actor_home,
4972 NULL,
4973 NULL);
4974}
4975
4976/**********************************************************************/
4981 const struct unit *actor_unit,
4982 const action_id act_id)
4983{
4987 act_id);
4988}
4989
4990/**********************************************************************/
5003 const struct action *paction,
5004 const struct unit *act_unit,
5005 const struct city *tgt_city,
5006 const struct unit *tgt_unit,
5007 const struct tile *tgt_tile,
5008 const struct extra_type *extra_tgt)
5009{
5010 /* Assume impossible until told otherwise. */
5011 struct act_prob prob = ACTPROB_IMPOSSIBLE;
5012
5015
5017 case ATK_STACK:
5018 if (tgt_tile) {
5020 }
5021 break;
5022 case ATK_TILE:
5023 if (tgt_tile) {
5025 }
5026 break;
5027 case ATK_EXTRAS:
5028 if (tgt_tile) {
5031 }
5032 break;
5033 case ATK_CITY:
5034 if (tgt_city) {
5036 }
5037 break;
5038 case ATK_UNIT:
5039 if (tgt_unit) {
5041 }
5042 break;
5043 case ATK_SELF:
5044 prob = action_prob_self(nmap, act_unit, paction->id);
5045 break;
5046 case ATK_COUNT:
5047 log_error("Invalid action target kind");
5048 break;
5049 }
5050
5051 return prob;
5052}
5053
5054/**********************************************************************/
5060 const action_id act_id,
5061 const struct unit *actor,
5062 const struct city *actor_home,
5063 const struct tile *actor_tile,
5064 const bool omniscient_cheat,
5065 const struct city* target)
5066{
5067 /* FIXME: some unit state requirements still depend on the actor unit's
5068 * current position rather than on actor_tile. Maybe this function should
5069 * return ACTPROB_NOT_IMPLEMENTED when one of those is detected and no
5070 * other requirement makes the action ACTPROB_IMPOSSIBLE? */
5071
5072 if (omniscient_cheat) {
5075 target)) {
5076 return ACTPROB_CERTAIN;
5077 } else {
5078 return ACTPROB_IMPOSSIBLE;
5079 }
5080 } else {
5081 /* FIXME: this branch result depends _directly_ on actor's position.
5082 * I.e., like, not adjacent, no action. Other branch ignores radius. */
5084 act_id, target);
5085 }
5086}
5087
5088/**********************************************************************/
5093struct act_prob
5095 action_id act_id,
5096 const struct unit *actor,
5097 const struct city *actor_home,
5098 const struct tile *actor_tile,
5099 bool omniscient_cheat,
5100 const struct unit *target)
5101{
5102 /* FIXME: some unit state requirements still depend on the actor unit's
5103 * current position rather than on actor_tile. Maybe this function should
5104 * return ACTPROB_NOT_IMPLEMENTED when one of those is detected and no
5105 * other requirement makes the action ACTPROB_IMPOSSIBLE? */
5106
5107 if (omniscient_cheat) {
5110 target)) {
5111 return ACTPROB_CERTAIN;
5112 } else {
5113 return ACTPROB_IMPOSSIBLE;
5114 }
5115 } else {
5117 act_id, target);
5118 }
5119}
5120
5121/**********************************************************************/
5126struct act_prob
5128 action_id act_id,
5129 const struct unit *actor,
5130 const struct city *actor_home,
5131 const struct tile *actor_tile,
5132 bool omniscient_cheat,
5133 const struct tile *target)
5134{
5135 /* FIXME: some unit state requirements still depend on the actor unit's
5136 * current position rather than on actor_tile. Maybe this function should
5137 * return ACTPROB_NOT_IMPLEMENTED when one of those is detected and no
5138 * other requirement makes the action ACTPROB_IMPOSSIBLE? */
5139
5140 if (omniscient_cheat) {
5143 target)) {
5144 return ACTPROB_CERTAIN;
5145 } else {
5146 return ACTPROB_IMPOSSIBLE;
5147 }
5148 } else {
5150 act_id, target);
5151 }
5152}
5153
5154/**********************************************************************/
5159struct act_prob
5161 action_id act_id,
5162 const struct unit *actor,
5163 const struct city *actor_home,
5164 const struct tile *actor_tile,
5165 bool omniscient_cheat,
5166 const struct tile *target_tile,
5167 const struct extra_type *target_extra)
5168{
5169 /* FIXME: some unit state requirements still depend on the actor unit's
5170 * current position rather than on actor_tile. Maybe this function should
5171 * return ACTPROB_NOT_IMPLEMENTED when one of those is detected and no
5172 * other requirement makes the action ACTPROB_IMPOSSIBLE? */
5173
5174 if (omniscient_cheat) {
5178 return ACTPROB_CERTAIN;
5179 } else {
5180 return ACTPROB_IMPOSSIBLE;
5181 }
5182 } else {
5184 act_id, target_tile, target_extra);
5185 }
5186}
5187
5188/**********************************************************************/
5193struct act_prob
5195 action_id act_id,
5196 const struct unit *actor,
5197 const struct city *actor_home,
5198 const struct tile *actor_tile,
5199 bool omniscient_cheat,
5200 const struct tile *target_tile,
5201 const struct extra_type *target_extra)
5202{
5203 /* FIXME: some unit state requirements still depend on the actor unit's
5204 * current position rather than on actor_tile. Maybe this function should
5205 * return ACTPROB_NOT_IMPLEMENTED when one of those is detected and no
5206 * other requirement makes the action ACTPROB_IMPOSSIBLE? */
5207
5208 if (omniscient_cheat) {
5212 return ACTPROB_CERTAIN;
5213 } else {
5214 return ACTPROB_IMPOSSIBLE;
5215 }
5216 } else {
5218 act_id, target_tile, target_extra);
5219 }
5220}
5221
5222/**********************************************************************/
5227struct act_prob
5229 action_id act_id,
5230 const struct unit *actor,
5231 const struct city *actor_home,
5232 const struct tile *actor_tile,
5233 bool omniscient_cheat)
5234{
5235 /* FIXME: some unit state requirements still depend on the actor unit's
5236 * current position rather than on actor_tile. Maybe this function should
5237 * return ACTPROB_NOT_IMPLEMENTED when one of those is detected and no
5238 * other requirement makes the action ACTPROB_IMPOSSIBLE? */
5239 if (omniscient_cheat) {
5242 return ACTPROB_CERTAIN;
5243 } else {
5244 return ACTPROB_IMPOSSIBLE;
5245 }
5246 } else {
5248 act_id);
5249 }
5250}
5251
5252/**********************************************************************/
5256{
5258
5259 return out;
5260}
5261
5262/**********************************************************************/
5266{
5268
5269 return out;
5270}
5271
5272/**********************************************************************/
5276{
5278
5279 return out;
5280}
5281
5282/**********************************************************************/
5286{
5288
5289 return out;
5290}
5291
5292/**********************************************************************/
5296{
5298
5299 return out;
5300}
5301
5302/**********************************************************************/
5307{
5308 return (ACTPROB_VAL_MIN < probability.max
5310}
5311
5312/**********************************************************************/
5317{
5318 return (ACTPROB_VAL_MAX == probability.min
5319 && ACTPROB_VAL_MAX == probability.max);
5320}
5321
5322/**********************************************************************/
5326static inline bool
5332
5333/**********************************************************************/
5337static inline bool
5339{
5340 return probability.min == ACTPROB_VAL_NOT_IMPL
5341 && probability.max == ACTPROB_VAL_MIN;
5342}
5343
5344/**********************************************************************/
5348static inline bool
5350{
5351 return probability.max < probability.min;
5352}
5353
5354/**********************************************************************/
5358 const struct act_prob *ap2)
5359{
5360 return ap1->min == ap2->min && ap1->max == ap2->max;
5361}
5362
5363/**********************************************************************/
5367 const struct act_prob ap2)
5368{
5369 struct act_prob my_ap1;
5370 struct act_prob my_ap2;
5371
5372 /* The action probabilities are real. */
5375
5376 /* Convert any signals to ACTPROB_NOT_KNOWN. */
5378 /* Assert that it is OK to convert the signal. */
5380
5382 } else {
5383 my_ap1 = ap1;
5384 }
5385
5387 /* Assert that it is OK to convert the signal. */
5389
5391 } else {
5392 my_ap2 = ap2;
5393 }
5394
5395 /* The action probabilities now have a comparison friendly form. */
5398
5399 /* Do the comparison. Start with min. Continue with max. */
5400 if (my_ap1.min < my_ap2.min) {
5401 return -1;
5402 } else if (my_ap1.min > my_ap2.min) {
5403 return 1;
5404 } else if (my_ap1.max < my_ap2.max) {
5405 return -1;
5406 } else if (my_ap1.max > my_ap2.max) {
5407 return 1;
5408 } else {
5409 return 0;
5410 }
5411}
5412
5413/**********************************************************************/
5418{
5419 struct act_prob my_ap;
5420
5421 /* The action probability is real. */
5423
5424 /* Convert any signals to ACTPROB_NOT_KNOWN. */
5426 /* Assert that it is OK to convert the signal. */
5428
5430 } else {
5431 my_ap = ap;
5432 }
5433
5434 /* The action probability now has a math friendly form. */
5436
5437 return (double)my_ap.min / (double) ACTPROB_VAL_MAX;
5438}
5439
5440/**********************************************************************/
5445 const struct act_prob *ap2)
5446{
5447 struct act_prob my_ap1;
5448 struct act_prob my_ap2;
5449 struct act_prob out;
5450
5451 /* The action probabilities are real. */
5454
5457 /* Keep the information rather than converting the signal to
5458 * ACTPROB_NOT_KNOWN. */
5459
5460 /* Assert that it is OK to convert the signal. */
5462
5463 out.min = ap1->min;
5464 out.max = ap2->max;
5465
5466 return out;
5467 }
5468
5469 /* Convert any signals to ACTPROB_NOT_KNOWN. */
5470 if (action_prob_is_signal(*ap1)) {
5471 /* Assert that it is OK to convert the signal. */
5473
5474 my_ap1.min = ACTPROB_VAL_MIN;
5475 my_ap1.max = ACTPROB_VAL_MAX;
5476 } else {
5477 my_ap1.min = ap1->min;
5478 my_ap1.max = ap1->max;
5479 }
5480
5481 if (action_prob_is_signal(*ap2)) {
5482 /* Assert that it is OK to convert the signal. */
5484
5485 my_ap2.min = ACTPROB_VAL_MIN;
5486 my_ap2.max = ACTPROB_VAL_MAX;
5487 } else {
5488 my_ap2.min = ap2->min;
5489 my_ap2.max = ap2->max;
5490 }
5491
5492 /* The action probabilities now have a math friendly form. */
5495
5496 /* Do the math. */
5497 out.min = (my_ap1.min * my_ap2.min) / ACTPROB_VAL_MAX;
5498 out.max = (my_ap1.max * my_ap2.max) / ACTPROB_VAL_MAX;
5499
5500 /* Cap at 100%. */
5501 out.min = MIN(out.min, ACTPROB_VAL_MAX);
5502 out.max = MIN(out.max, ACTPROB_VAL_MAX);
5503
5504 return out;
5505}
5506
5507/**********************************************************************/
5515 const struct act_prob *ap2)
5516{
5517 struct act_prob my_ap1;
5518 struct act_prob my_ap2;
5519 struct act_prob out;
5520
5521 /* The action probabilities are real. */
5524
5527 /* Keep the information rather than converting the signal to
5528 * ACTPROB_NOT_KNOWN. */
5529
5530 /* Assert that it is OK to convert the signal. */
5532
5533 out.min = ap1->min;
5534 out.max = ap2->max;
5535
5536 return out;
5537 }
5538
5539 /* Convert any signals to ACTPROB_NOT_KNOWN. */
5540 if (action_prob_is_signal(*ap1)) {
5541 /* Assert that it is OK to convert the signal. */
5543
5544 my_ap1.min = ACTPROB_VAL_MIN;
5545 my_ap1.max = ACTPROB_VAL_MAX;
5546 } else {
5547 my_ap1.min = ap1->min;
5548 my_ap1.max = ap1->max;
5549 }
5550
5551 if (action_prob_is_signal(*ap2)) {
5552 /* Assert that it is OK to convert the signal. */
5554
5555 my_ap2.min = ACTPROB_VAL_MIN;
5556 my_ap2.max = ACTPROB_VAL_MAX;
5557 } else {
5558 my_ap2.min = ap2->min;
5559 my_ap2.max = ap2->max;
5560 }
5561
5562 /* The action probabilities now have a math friendly form. */
5565
5566 /* Do the math. */
5567 out.min = my_ap1.min + (((ACTPROB_VAL_MAX - my_ap1.min) * my_ap2.min)
5568 / ACTPROB_VAL_MAX);
5569 out.max = my_ap1.max + (((ACTPROB_VAL_MAX - my_ap1.max) * my_ap2.max)
5570 / ACTPROB_VAL_MAX);
5571
5572 /* Cap at 100%. */
5573 out.min = MIN(out.min, ACTPROB_VAL_MAX);
5574 out.max = MIN(out.max, ACTPROB_VAL_MAX);
5575
5576 return out;
5577}
5578
5579/**********************************************************************/
5583{
5584 switch (actres_dice_type(paction->result)) {
5585 case DRT_DIPLCHANCE:
5587 /* Take the initial odds from the diplchance setting. */
5589 server_setting_by_name("diplchance"));
5590 }
5592 case DRT_CERTAIN:
5593 return 100;
5594 case DRT_NONE:
5595 break;
5596 }
5597
5598 /* The odds of the action not being stopped by its dice roll when the dice
5599 * isn't thrown is 100%. ACTION_ODDS_PCT_DICE_ROLL_NA is above 100% */
5601}
5602
5603/**********************************************************************/
5607 const struct unit *act_unit,
5608 const struct city *tgt_city,
5609 const struct player *tgt_player,
5610 const struct action *paction)
5611{
5613 const struct unit_type *actu_type = unit_type_get(act_unit);
5614
5615 fc_assert_action_msg(odds >= 0 && odds <= 100,
5616 odds = 100,
5617 "Bad initial odds for action number %d."
5618 " Does it roll the dice at all?",
5619 paction->id);
5620
5621 /* Let the Action_Odds_Pct effect modify the odds. The advantage of doing
5622 * it this way instead of rolling twice is that Action_Odds_Pct can
5623 * increase the odds. */
5624 odds = odds
5625 + ((odds
5627 &(const struct req_context) {
5628 .player = act_player,
5629 .city = tgt_city,
5630 .unit = act_unit,
5631 .unittype = actu_type,
5632 .action = paction,
5633 },
5634 &(const struct req_context) {
5635 .player = tgt_player,
5636 },
5638 / 100)
5639 - ((odds
5641 &(const struct req_context) {
5642 .player = tgt_player,
5643 .city = tgt_city,
5644 .unit = act_unit,
5645 .unittype = actu_type,
5646 .action = paction,
5647 },
5648 &(const struct req_context) {
5649 .player = act_player,
5650 },
5652 / 100);
5653
5654
5655 /* Odds are between 0% and 100%. */
5656 return CLIP(0, odds, 100);
5657}
5658
5659/**********************************************************************/
5663{
5664 struct action *paction = action_by_number(act);
5665
5666 /* Always immune since its not enabled. Doesn't count. */
5667 if (!action_is_in_use(paction)) {
5668 return FALSE;
5669 }
5670
5672 if (requirement_fulfilled_by_government(gov, &(enabler->target_reqs))) {
5673 return FALSE;
5674 }
5676
5677 return TRUE;
5678}
5679
5680/**********************************************************************/
5686 const struct player *actor_player,
5687 const struct req_context *target)
5688{
5690 enabler) {
5691 if (are_reqs_active(target,
5692 &(const struct req_context) {
5694 },
5695 &enabler->target_reqs, RPT_POSSIBLE)) {
5696 return TRUE;
5697 }
5699
5700 return FALSE;
5701}
5702
5703/**********************************************************************/
5707 const struct player *actor_player,
5708 const struct city* target_city)
5709{
5711 FALSE, "Action %s is against %s not cities",
5712 action_id_rule_name(act_id),
5714 action_id_get_target_kind(act_id)));
5715
5716 return is_target_possible(act_id, actor_player,
5717 &(const struct req_context) {
5718 .player = city_owner(target_city),
5719 .city = target_city,
5721 });
5722}
5723
5724/**********************************************************************/
5730 const action_id act_id,
5731 const struct unit *actor_unit)
5732{
5733 const struct player *actor_player = unit_owner(actor_unit);
5734 const struct req_context actor_ctxt = {
5736 .city = tile_city(unit_tile(actor_unit)),
5738 .unit = actor_unit,
5739 .unittype = unit_type_get(actor_unit),
5740 };
5741 const struct action *paction = action_by_number(act_id);
5742
5743 enum fc_tristate result;
5744
5746
5747 if (!utype_can_do_action(actor_unit->utype, act_id)) {
5748 /* The unit type can't perform the action. */
5749 return FALSE;
5750 }
5751
5754
5755 if (result == TRI_NO) {
5756 /* The hard requirements aren't fulfilled. */
5757 return FALSE;
5758 }
5759
5761 enabler) {
5762 const enum fc_tristate current
5764 &enabler->actor_reqs,
5765 /* Needed since no player to evaluate DiplRel
5766 * requirements against. */
5767 RPT_POSSIBLE);
5768
5769 if (current == TRI_YES
5770 || current == TRI_MAYBE) {
5771 /* The ruleset requirements may be fulfilled. */
5772 return TRUE;
5773 }
5775
5776 /* No action enabler allows this action. */
5777 return FALSE;
5778}
5779
5780/**********************************************************************/
5785 const action_id act_id)
5786{
5787 fc_assert(action_id_exists(act_id) || act_id == ACTION_ANY);
5788
5789 /* Check if full movement points may enable the specified action. */
5791 act_id,
5794 act_id,
5796}
5797
5798/**********************************************************************/
5823
5824/**********************************************************************/
5835{
5836 const struct action *paction = enabler_get_action(ae);
5837
5838 switch (action_get_actor_kind(paction)) {
5839 case AAK_UNIT:
5842 /* A possible actor unit type has been found. */
5843 return TRUE;
5844 }
5846
5847 /* No actor detected. */
5848 return FALSE;
5849 case AAK_CITY:
5850 case AAK_PLAYER:
5851 /* Currently can't detect */
5852 return TRUE;
5853 case AAK_COUNT:
5855 break;
5856 }
5857
5858 /* No actor detected. */
5859 return FALSE;
5860}
5861
5862/**********************************************************************/
5870{
5871 switch (action_get_actor_kind(paction)) {
5872 case AAK_UNIT:
5875 return TRUE;
5876 }
5878 break;
5879 case AAK_CITY:
5880 case AAK_PLAYER:
5881 /* No ruleset hard reqs atm */
5882 return TRUE;
5883 case AAK_COUNT:
5885 break;
5886 }
5887
5888 /* No actor detected. */
5889 return FALSE;
5890}
5891
5892/**********************************************************************/
5900{
5902
5904 /* Hard requirements not fulfilled. */
5905 return FALSE;
5906 }
5907
5909
5911 /* If this iteration finds any entries, action is enabled. */
5912 return TRUE;
5914
5915 /* No non deleted action enabler. */
5916 return FALSE;
5917}
5918
5919/**********************************************************************/
5926{
5927 return paction != nullptr
5929}
5930
5931/**********************************************************************/
5941
5942/**********************************************************************/
5946{
5947 fc_assert_ret_val(num >= 0, NULL);
5949
5950 return &auto_perfs[num];
5951}
5952
5953/**********************************************************************/
5962{
5963 return action_auto_perf_slot_number(num);
5964}
5965
5966/**********************************************************************/
5970 struct universal *actor_uni,
5971 struct universal *target_uni)
5972{
5974 enab) {
5975 if ((actor_uni == NULL
5976 || universal_fulfills_requirements(FALSE, &(enab->actor_reqs),
5977 actor_uni))
5978 && (target_uni == NULL
5979 || universal_fulfills_requirements(FALSE, &(enab->target_reqs),
5980 target_uni))) {
5981 return TRUE;
5982 }
5984
5985 return FALSE;
5986}
5987
5988/**********************************************************************/
5994{
5996
5997 if (size < MAX_NUM_ACTIONS) {
5998 /* An action array is terminated by ACTION_NONE */
6000 }
6001}
6002
6003/**********************************************************************/
6011 int *position,
6012 enum action_result result)
6013{
6014 action_iterate(act) {
6015 struct action *paction = action_by_number(act);
6016 if (paction->result == result) {
6017 /* Assume one result for each action. */
6018 fc_assert_ret(*position < MAX_NUM_ACTIONS);
6019
6020 act_array[(*position)++] = paction->id;
6021 }
6023}
6024
6025/**********************************************************************/
6028const char *action_ui_name_default(int act)
6029{
6030 switch ((enum gen_action)act) {
6031 case ACTION_SPY_POISON:
6032 /* TRANS: _Poison City (3% chance of success). */
6033 return N_("%sPoison City%s");
6035 /* TRANS: _Poison City and Escape (3% chance of success). */
6036 return N_("%sPoison City and Escape%s");
6038 /* TRANS: S_abotage Enemy Unit (3% chance of success). */
6039 return N_("S%sabotage Enemy Unit%s");
6041 /* TRANS: S_abotage Enemy Unit and Escape (3% chance of success). */
6042 return N_("S%sabotage Enemy Unit and Escape%s");
6044 /* TRANS: Bribe Enemy _Unit (3% chance of success). */
6045 return N_("Bribe Enemy %sUnit%s");
6047 /* TRANS: Bribe Enemy _Stack (3% chance of success). */
6048 return N_("Bribe Enemy %sStack%s");
6050 /* TRANS: _Sabotage City (3% chance of success). */
6051 return N_("%sSabotage City%s");
6053 /* TRANS: _Sabotage City and Escape (3% chance of success). */
6054 return N_("%sSabotage City and Escape%s");
6056 /* TRANS: Industria_l Sabotage (3% chance of success). */
6057 return N_("Industria%sl Sabotage%s");
6059 /* TRANS: Industria_l Sabotage Production (3% chance of success). */
6060 return N_("Industria%sl Sabotage Production%s");
6062 /* TRANS: Industria_l Sabotage and Escape (3% chance of success). */
6063 return N_("Industria%sl Sabotage and Escape%s");
6065 /* TRANS: Industria_l Sabotage Production and Escape (3% chance of success). */
6066 return N_("Industria%sl Sabotage Production and Escape%s");
6068 /* TRANS: Incite a Re_volt (3% chance of success). */
6069 return N_("Incite a Re%svolt%s");
6071 /* TRANS: Incite a Re_volt and Escape (3% chance of success). */
6072 return N_("Incite a Re%svolt and Escape%s");
6074 /* TRANS: Establish _Embassy (100% chance of success). */
6075 return N_("Establish %sEmbassy%s");
6077 /* TRANS: Becom_e Ambassador (100% chance of success). */
6078 return N_("Becom%se Ambassador%s");
6080 /* TRANS: Steal _Technology (3% chance of success). */
6081 return N_("Steal %sTechnology%s");
6083 /* TRANS: Steal _Technology and Escape (3% chance of success). */
6084 return N_("Steal %sTechnology and Escape%s");
6086 /* TRANS: In_dustrial Espionage (3% chance of success). */
6087 return N_("In%sdustrial Espionage%s");
6089 /* TRANS: In_dustrial Espionage and Escape (3% chance of success). */
6090 return N_("In%sdustrial Espionage and Escape%s");
6092 /* TRANS: _Investigate City (100% chance of success). */
6093 return N_("%sInvestigate City%s");
6095 /* TRANS: _Investigate City (spends the unit) (100% chance of
6096 * success). */
6097 return N_("%sInvestigate City (spends the unit)%s");
6099 /* TRANS: Steal _Gold (100% chance of success). */
6100 return N_("Steal %sGold%s");
6102 /* TRANS: Steal _Gold and Escape (100% chance of success). */
6103 return N_("Steal %sGold and Escape%s");
6105 /* TRANS: Spread _Plague (100% chance of success). */
6106 return N_("Spread %sPlague%s");
6107 case ACTION_STEAL_MAPS:
6108 /* TRANS: Steal _Maps (100% chance of success). */
6109 return N_("Steal %sMaps%s");
6111 /* TRANS: Steal _Maps and Escape (100% chance of success). */
6112 return N_("Steal %sMaps and Escape%s");
6113 case ACTION_TRADE_ROUTE:
6114 /* TRANS: Establish Trade _Route (100% chance of success). */
6115 return N_("Establish Trade %sRoute%s");
6116 case ACTION_MARKETPLACE:
6117 /* TRANS: Enter _Marketplace (100% chance of success). */
6118 return N_("Enter %sMarketplace%s");
6119 case ACTION_HELP_WONDER:
6120 /* TRANS: Help _build Wonder (100% chance of success). */
6121 return N_("Help %sbuild Wonder%s");
6123 /* TRANS: _Capture Units (100% chance of success). */
6124 return N_("%sCapture Units%s");
6125 case ACTION_EXPEL_UNIT:
6126 /* TRANS: _Expel Unit (100% chance of success). */
6127 return N_("%sExpel Unit%s");
6128 case ACTION_FOUND_CITY:
6129 /* TRANS: _Found City (100% chance of success). */
6130 return N_("%sFound City%s");
6131 case ACTION_JOIN_CITY:
6132 /* TRANS: _Join City (100% chance of success). */
6133 return N_("%sJoin City%s");
6134 case ACTION_BOMBARD:
6135 /* TRANS: B_ombard (100% chance of success). */
6136 return N_("B%sombard%s");
6137 case ACTION_BOMBARD2:
6138 /* TRANS: B_ombard 2 (100% chance of success). */
6139 return N_("B%sombard 2%s");
6140 case ACTION_BOMBARD3:
6141 /* TRANS: B_ombard 3 (100% chance of success). */
6142 return N_("B%sombard 3%s");
6143 case ACTION_BOMBARD4:
6144 /* TRANS: B_ombard 4 (100% chance of success). */
6145 return N_("B%sombard 4%s");
6148 /* TRANS: Lethal B_ombard (100% chance of success). */
6149 return N_("Lethal B%sombard%s");
6150 case ACTION_SPY_NUKE:
6151 /* TRANS: Suitcase _Nuke (100% chance of success). */
6152 return N_("Suitcase %sNuke%s");
6154 /* TRANS: Suitcase _Nuke and Escape (100% chance of success). */
6155 return N_("Suitcase %sNuke and Escape%s");
6156 case ACTION_NUKE:
6157 /* TRANS: Explode _Nuclear (100% chance of success). */
6158 return N_("Explode %sNuclear%s");
6159 case ACTION_NUKE_CITY:
6160 /* TRANS: _Nuke City (100% chance of success). */
6161 return N_("%sNuke City%s");
6162 case ACTION_NUKE_UNITS:
6163 /* TRANS: _Nuke Units (100% chance of success). */
6164 return N_("%sNuke Units%s");
6166 /* TRANS: Destroy _City (100% chance of success). */
6167 return N_("Destroy %sCity%s");
6169 /* TRANS: Dis_band recovering production (100% chance of success). */
6170 return N_("Dis%sband recovering production%s");
6172 /* TRANS: Dis_band without recovering production (100% chance of success). */
6173 return N_("Dis%sband without recovering production%s");
6174 case ACTION_HOME_CITY:
6175 /* TRANS: Set _Home City (100% chance of success). */
6176 return N_("Set %sHome City%s");
6177 case ACTION_HOMELESS:
6178 /* TRANS: Make _Homeless (100% chance of success). */
6179 return N_("Make %sHomeless%s");
6181 /* TRANS: _Upgrade Unit (100% chance of success). */
6182 return N_("%sUpgrade Unit%s");
6183 case ACTION_PARADROP:
6184 /* TRANS: Drop _Paratrooper (100% chance of success). */
6185 return N_("Drop %sParatrooper%s");
6187 /* TRANS: Drop _Paratrooper (100% chance of success). */
6188 return N_("Drop %sParatrooper%s");
6190 /* TRANS: Drop _Paratrooper (100% chance of success). */
6191 return N_("Drop %sParatrooper%s");
6193 /* TRANS: Drop _Paratrooper (100% chance of success). */
6194 return N_("Drop %sParatrooper%s");
6196 /* TRANS: Drop _Paratrooper (100% chance of success). */
6197 return N_("Drop %sParatrooper%s");
6199 /* TRANS: Drop _Paratrooper (100% chance of success). */
6200 return N_("Drop %sParatrooper%s");
6201 case ACTION_AIRLIFT:
6202 /* TRANS: _Airlift to City (100% chance of success). */
6203 return N_("%sAirlift to City%s");
6204 case ACTION_ATTACK:
6205 case ACTION_ATTACK2:
6206 /* TRANS: _Attack (100% chance of success). */
6207 return N_("%sAttack%s");
6210 /* TRANS: _Suicide Attack (100% chance of success). */
6211 return N_("%sSuicide Attack%s");
6212 case ACTION_WIPE_UNITS:
6213 /* TRANS: _Wipe Units (100% chance of success). */
6214 return N_("%sWipe Units%s");
6216 /* TRANS: Collect _Ransom (100% chance of success). */
6217 return N_("Collect %sRansom%s");
6219 /* TRANS: Surgical Str_ike Building (100% chance of success). */
6220 return N_("Surgical Str%sike Building%s");
6222 /* TRANS: Surgical Str_ike Production (100% chance of success). */
6223 return N_("Surgical Str%sike Production%s");
6227 /* TRANS: _Conquer City (100% chance of success). */
6228 return N_("%sConquer City%s");
6230 /* TRANS: _Conquer City 2 (100% chance of success). */
6231 return N_("%sConquer City 2%s");
6235 /* TRANS: _Conquer Extras (100% chance of success). */
6236 return N_("%sConquer Extras%s");
6238 /* TRANS: _Conquer Extras 2 (100% chance of success). */
6239 return N_("%sConquer Extras 2%s");
6240 case ACTION_HEAL_UNIT:
6241 case ACTION_HEAL_UNIT2:
6242 /* TRANS: Heal _Unit (3% chance of success). */
6243 return N_("Heal %sUnit%s");
6246 /* TRANS: _Transform Terrain (3% chance of success). */
6247 return N_("%sTransform Terrain%s");
6248 case ACTION_CULTIVATE:
6249 case ACTION_CULTIVATE2:
6250 /* TRANS: Transform by _Cultivating (3% chance of success). */
6251 return N_("Transform by %sCultivating%s");
6252 case ACTION_PLANT:
6253 case ACTION_PLANT2:
6254 /* TRANS: Transform by _Planting (3% chance of success). */
6255 return N_("Transform by %sPlanting%s");
6256 case ACTION_PILLAGE:
6257 case ACTION_PILLAGE2:
6258 /* TRANS: Pilla_ge (100% chance of success). */
6259 return N_("Pilla%sge%s");
6260 case ACTION_CLEAN:
6261 case ACTION_CLEAN2:
6262 /* TRANS: Clean (100% chance of success). */
6263 return N_("%sClean%s");
6264 case ACTION_FORTIFY:
6265 case ACTION_FORTIFY2:
6266 /* TRANS: _Fortify (100% chance of success). */
6267 return N_("%sFortify%s");
6268 case ACTION_ROAD:
6269 case ACTION_ROAD2:
6270 /* TRANS: Build _Road (100% chance of success). */
6271 return N_("Build %sRoad%s");
6272 case ACTION_CONVERT:
6273 /* TRANS: _Convert Unit (100% chance of success). */
6274 return N_("%sConvert Unit%s");
6275 case ACTION_BASE:
6276 case ACTION_BASE2:
6277 /* TRANS: _Build Base (100% chance of success). */
6278 return N_("%sBuild Base%s");
6279 case ACTION_MINE:
6280 case ACTION_MINE2:
6281 /* TRANS: Build _Mine (100% chance of success). */
6282 return N_("Build %sMine%s");
6283 case ACTION_IRRIGATE:
6284 case ACTION_IRRIGATE2:
6285 /* TRANS: Build _Irrigation (100% chance of success). */
6286 return N_("Build %sIrrigation%s");
6288 /* TRANS: _Deboard (100% chance of success). */
6289 return N_("%sDeboard%s");
6293 /* TRANS: _Board (100% chance of success). */
6294 return N_("%sBoard%s");
6299 /* TRANS: _Embark (100% chance of success). */
6300 return N_("%sEmbark%s");
6302 /* TRANS: _Unload (100% chance of success). */
6303 return N_("%sUnload%s");
6307 /* TRANS: _Load (100% chance of success). */
6308 return N_("%sLoad%s");
6312 /* TRANS: _Disembark (100% chance of success). */
6313 return N_("%sDisembark%s");
6315 /* TRANS: _Disembark 2 (100% chance of success). */
6316 return N_("%sDisembark 2%s");
6317 case ACTION_SPY_ATTACK:
6318 /* TRANS: _Eliminate Diplomat (100% chance of success). */
6319 return N_("%sEliminate Diplomat%s");
6320 case ACTION_HUT_ENTER:
6321 case ACTION_HUT_ENTER2:
6322 case ACTION_HUT_ENTER3:
6323 case ACTION_HUT_ENTER4:
6324 /* TRANS: Enter _Hut (100% chance of success). */
6325 return N_("Enter %sHut%s");
6330 /* TRANS: Frighten _Hut (100% chance of success). */
6331 return N_("Frighten %sHut%s");
6332 case ACTION_UNIT_MOVE:
6333 case ACTION_UNIT_MOVE2:
6334 case ACTION_UNIT_MOVE3:
6335 /* TRANS: Regular _Move (100% chance of success). */
6336 return N_("Regular %sMove%s");
6337 case ACTION_TELEPORT:
6338 case ACTION_TELEPORT2:
6339 case ACTION_TELEPORT3:
6340 /* TRANS: _Teleport (100% chance of success). */
6341 return N_("%sTeleport%s");
6343 /* TRANS: _Teleport (100% chance of success). */
6344 return N_("%sTeleport%s");
6346 /* TRANS: _Teleport (100% chance of success). */
6347 return N_("%sTeleport%s");
6349 /* TRANS: _Teleport (100% chance of success). */
6350 return N_("%sTeleport%s");
6352 /* TRANS: _Teleport (100% chance of success). */
6353 return N_("%sTeleport%s");
6355 /* TRANS: _Teleport (100% chance of success). */
6356 return N_("%sTeleport%s");
6357 case ACTION_SPY_ESCAPE:
6358 /* TRANS: _Escape To Nearest City (100% chance of success). */
6359 return N_("%sEscape To Nearest City%s");
6361 /* TRANS: _User Action 1 (100% chance of success). */
6362 return N_("%sUser Action 1%s");
6364 /* TRANS: _User Action 2 (100% chance of success). */
6365 return N_("%sUser Action 2%s");
6367 /* TRANS: _User Action 3 (100% chance of success). */
6368 return N_("%sUser Action 3%s");
6370 /* TRANS: _User Action 4 (100% chance of success). */
6371 return N_("%sUser Action 4%s");
6373 return N_("%sGain Veterancy%s");
6374 case ACTION_ESCAPE:
6375 return N_("%sEscape%s");
6376 case ACTION_CIVIL_WAR:
6377 return N_("%sCivil War%s");
6378 case ACTION_FINISH_UNIT:
6379 return N_("Finish %sUnit%s");
6381 return N_("Finish %sBuilding%s");
6382 case ACTION_COUNT:
6383 fc_assert(act != ACTION_COUNT);
6384 break;
6385 }
6386
6387 return NULL;
6388}
6389
6390/**********************************************************************/
6397{
6398 switch ((enum gen_action)act) {
6399 case ACTION_SPY_POISON:
6424 case ACTION_STEAL_MAPS:
6426 case ACTION_TRADE_ROUTE:
6427 case ACTION_MARKETPLACE:
6428 case ACTION_HELP_WONDER:
6430 case ACTION_EXPEL_UNIT:
6431 case ACTION_FOUND_CITY:
6432 case ACTION_JOIN_CITY:
6433 case ACTION_SPY_NUKE:
6438 case ACTION_HOME_CITY:
6439 case ACTION_HOMELESS:
6441 case ACTION_PARADROP:
6447 case ACTION_AIRLIFT:
6448 case ACTION_ATTACK:
6449 case ACTION_ATTACK2:
6452 case ACTION_WIPE_UNITS:
6460 case ACTION_HEAL_UNIT:
6461 case ACTION_HEAL_UNIT2:
6464 case ACTION_CULTIVATE:
6465 case ACTION_CULTIVATE2:
6466 case ACTION_PLANT:
6467 case ACTION_PLANT2:
6468 case ACTION_PILLAGE:
6469 case ACTION_PILLAGE2:
6470 case ACTION_CLEAN:
6471 case ACTION_CLEAN2:
6472 case ACTION_FORTIFY:
6473 case ACTION_FORTIFY2:
6474 case ACTION_ROAD:
6475 case ACTION_ROAD2:
6476 case ACTION_CONVERT:
6477 case ACTION_BASE:
6478 case ACTION_BASE2:
6479 case ACTION_MINE:
6480 case ACTION_MINE2:
6481 case ACTION_IRRIGATE:
6482 case ACTION_IRRIGATE2:
6499 case ACTION_BOMBARD:
6500 case ACTION_BOMBARD2:
6501 case ACTION_BOMBARD3:
6502 case ACTION_BOMBARD4:
6505 case ACTION_SPY_ATTACK:
6510 case ACTION_HUT_ENTER:
6511 case ACTION_HUT_ENTER2:
6512 case ACTION_HUT_ENTER3:
6513 case ACTION_HUT_ENTER4:
6518 case ACTION_UNIT_MOVE:
6519 case ACTION_UNIT_MOVE2:
6520 case ACTION_UNIT_MOVE3:
6521 case ACTION_SPY_ESCAPE:
6523 case ACTION_ESCAPE:
6524 case ACTION_CIVIL_WAR:
6525 case ACTION_FINISH_UNIT:
6527 /* Min range is not ruleset changeable */
6528 return NULL;
6529 case ACTION_NUKE:
6530 return "explode_nuclear_min_range";
6531 case ACTION_NUKE_CITY:
6532 return "nuke_city_min_range";
6533 case ACTION_NUKE_UNITS:
6534 return "nuke_units_min_range";
6535 case ACTION_TELEPORT:
6536 return "teleport_min_range";
6537 case ACTION_TELEPORT2:
6538 return "teleport_2_min_range";
6539 case ACTION_TELEPORT3:
6540 return "teleport_3_min_range";
6542 return "teleport_conquer_min_range";
6544 return "teleport_frighten_min_range";
6546 return "teleport_frighten_conquer_min_range";
6548 return "teleport_enter_min_range";
6550 return "teleport_enter_conquer_min_range";
6552 return "user_action_1_min_range";
6554 return "user_action_2_min_range";
6556 return "user_action_3_min_range";
6558 return "user_action_4_min_range";
6559 case ACTION_COUNT:
6560 break;
6561
6563 }
6564
6565 fc_assert(act >= 0 && act < ACTION_COUNT);
6566
6567 return NULL;
6568}
6569
6570/**********************************************************************/
6577{
6578 switch ((enum gen_action)act) {
6579 case ACTION_SPY_POISON:
6604 case ACTION_STEAL_MAPS:
6606 case ACTION_TRADE_ROUTE:
6607 case ACTION_MARKETPLACE:
6609 case ACTION_EXPEL_UNIT:
6610 case ACTION_FOUND_CITY:
6611 case ACTION_JOIN_CITY:
6612 case ACTION_SPY_NUKE:
6616 case ACTION_HOME_CITY:
6617 case ACTION_HOMELESS:
6619 case ACTION_PARADROP:
6625 case ACTION_ATTACK:
6626 case ACTION_ATTACK2:
6629 case ACTION_WIPE_UNITS:
6637 case ACTION_HEAL_UNIT:
6638 case ACTION_HEAL_UNIT2:
6641 case ACTION_CULTIVATE:
6642 case ACTION_CULTIVATE2:
6643 case ACTION_PLANT:
6644 case ACTION_PLANT2:
6645 case ACTION_PILLAGE:
6646 case ACTION_PILLAGE2:
6647 case ACTION_CLEAN:
6648 case ACTION_CLEAN2:
6649 case ACTION_FORTIFY:
6650 case ACTION_FORTIFY2:
6651 case ACTION_ROAD:
6652 case ACTION_ROAD2:
6653 case ACTION_CONVERT:
6654 case ACTION_BASE:
6655 case ACTION_BASE2:
6656 case ACTION_MINE:
6657 case ACTION_MINE2:
6658 case ACTION_IRRIGATE:
6659 case ACTION_IRRIGATE2:
6676 case ACTION_SPY_ATTACK:
6681 case ACTION_HUT_ENTER:
6682 case ACTION_HUT_ENTER2:
6683 case ACTION_HUT_ENTER3:
6684 case ACTION_HUT_ENTER4:
6689 case ACTION_UNIT_MOVE:
6690 case ACTION_UNIT_MOVE2:
6691 case ACTION_UNIT_MOVE3:
6692 case ACTION_SPY_ESCAPE:
6694 case ACTION_ESCAPE:
6695 case ACTION_CIVIL_WAR:
6696 case ACTION_FINISH_UNIT:
6698 /* Max range is not ruleset changeable */
6699 return NULL;
6700 case ACTION_HELP_WONDER:
6701 return "help_wonder_max_range";
6703 return "disband_unit_recover_max_range";
6704 case ACTION_BOMBARD:
6705 return "bombard_max_range";
6706 case ACTION_BOMBARD2:
6707 return "bombard_2_max_range";
6708 case ACTION_BOMBARD3:
6709 return "bombard_3_max_range";
6710 case ACTION_BOMBARD4:
6711 return "bombard_4_max_range";
6713 return "bombard_lethal_max_range";
6715 return "bombard_lethal_2_max_range";
6716 case ACTION_NUKE:
6717 return "explode_nuclear_max_range";
6718 case ACTION_NUKE_CITY:
6719 return "nuke_city_max_range";
6720 case ACTION_NUKE_UNITS:
6721 return "nuke_units_max_range";
6722 case ACTION_AIRLIFT:
6723 return "airlift_max_range";
6724 case ACTION_TELEPORT:
6725 return "teleport_max_range";
6726 case ACTION_TELEPORT2:
6727 return "teleport_2_max_range";
6728 case ACTION_TELEPORT3:
6729 return "teleport_3_max_range";
6731 return "teleport_conquer_max_range";
6733 return "teleport_frighten_max_range";
6735 return "teleport_frighten_conquer_max_range";
6737 return "teleport_enter_max_range";
6739 return "teleport_enter_conquer_max_range";
6741 return "user_action_1_max_range";
6743 return "user_action_2_max_range";
6745 return "user_action_3_max_range";
6747 return "user_action_4_max_range";
6748 case ACTION_COUNT:
6749 break;
6750
6752 }
6753
6754 fc_assert(act >= 0 && act < ACTION_COUNT);
6755
6756 return NULL;
6757}
6758
6759/**********************************************************************/
6766{
6767 switch ((enum gen_action)act) {
6768 case ACTION_SPY_POISON:
6793 case ACTION_STEAL_MAPS:
6795 case ACTION_TRADE_ROUTE:
6796 case ACTION_MARKETPLACE:
6797 case ACTION_HELP_WONDER:
6799 case ACTION_EXPEL_UNIT:
6800 case ACTION_FOUND_CITY:
6801 case ACTION_JOIN_CITY:
6802 case ACTION_SPY_NUKE:
6804 case ACTION_NUKE_UNITS:
6808 case ACTION_HOME_CITY:
6809 case ACTION_HOMELESS:
6811 case ACTION_PARADROP:
6817 case ACTION_AIRLIFT:
6818 case ACTION_ATTACK:
6819 case ACTION_ATTACK2:
6822 case ACTION_WIPE_UNITS:
6830 case ACTION_HEAL_UNIT:
6831 case ACTION_HEAL_UNIT2:
6834 case ACTION_CULTIVATE:
6835 case ACTION_CULTIVATE2:
6836 case ACTION_PLANT:
6837 case ACTION_PLANT2:
6838 case ACTION_CLEAN:
6839 case ACTION_CLEAN2:
6840 case ACTION_FORTIFY:
6841 case ACTION_FORTIFY2:
6842 case ACTION_ROAD:
6843 case ACTION_ROAD2:
6844 case ACTION_CONVERT:
6845 case ACTION_BASE:
6846 case ACTION_BASE2:
6847 case ACTION_MINE:
6848 case ACTION_MINE2:
6849 case ACTION_IRRIGATE:
6850 case ACTION_IRRIGATE2:
6867 case ACTION_BOMBARD:
6868 case ACTION_BOMBARD2:
6869 case ACTION_BOMBARD3:
6870 case ACTION_BOMBARD4:
6873 case ACTION_SPY_ATTACK:
6878 case ACTION_HUT_ENTER:
6879 case ACTION_HUT_ENTER2:
6880 case ACTION_HUT_ENTER3:
6881 case ACTION_HUT_ENTER4:
6886 case ACTION_UNIT_MOVE:
6887 case ACTION_UNIT_MOVE2:
6888 case ACTION_UNIT_MOVE3:
6889 case ACTION_TELEPORT:
6890 case ACTION_TELEPORT2:
6891 case ACTION_TELEPORT3:
6897 case ACTION_SPY_ESCAPE:
6899 case ACTION_ESCAPE:
6900 case ACTION_CIVIL_WAR:
6901 case ACTION_FINISH_UNIT:
6903 /* Target kind is not ruleset changeable */
6904 return NULL;
6905 case ACTION_NUKE:
6906 return "explode_nuclear_target_kind";
6907 case ACTION_NUKE_CITY:
6908 return "nuke_city_target_kind";
6909 case ACTION_PILLAGE:
6910 return "pillage_target_kind";
6911 case ACTION_PILLAGE2:
6912 return "pillage_2_target_kind";
6914 return "user_action_1_target_kind";
6916 return "user_action_2_target_kind";
6918 return "user_action_3_target_kind";
6920 return "user_action_4_target_kind";
6921 case ACTION_COUNT:
6922 break;
6923
6925 }
6926
6927 fc_assert(act >= 0 && act < ACTION_COUNT);
6928
6929 return NULL;
6930}
6931
6932/**********************************************************************/
6940{
6941 switch ((enum gen_action)act) {
6942 case ACTION_SPY_POISON:
6966 case ACTION_STEAL_MAPS:
6968 case ACTION_TRADE_ROUTE:
6969 case ACTION_MARKETPLACE:
6970 case ACTION_HELP_WONDER:
6972 case ACTION_EXPEL_UNIT:
6973 case ACTION_JOIN_CITY:
6974 case ACTION_SPY_NUKE:
6979 case ACTION_HOME_CITY:
6980 case ACTION_HOMELESS:
6982 case ACTION_PARADROP:
6988 case ACTION_AIRLIFT:
6989 case ACTION_ATTACK:
6990 case ACTION_ATTACK2:
6993 case ACTION_WIPE_UNITS:
7001 case ACTION_HEAL_UNIT:
7002 case ACTION_HEAL_UNIT2:
7005 case ACTION_CULTIVATE:
7006 case ACTION_CULTIVATE2:
7007 case ACTION_PLANT:
7008 case ACTION_PLANT2:
7009 case ACTION_PILLAGE:
7010 case ACTION_PILLAGE2:
7011 case ACTION_CLEAN:
7012 case ACTION_CLEAN2:
7013 case ACTION_FORTIFY:
7014 case ACTION_FORTIFY2:
7015 case ACTION_ROAD:
7016 case ACTION_ROAD2:
7017 case ACTION_CONVERT:
7018 case ACTION_BASE:
7019 case ACTION_BASE2:
7020 case ACTION_MINE:
7021 case ACTION_MINE2:
7022 case ACTION_IRRIGATE:
7023 case ACTION_IRRIGATE2:
7040 case ACTION_BOMBARD:
7041 case ACTION_BOMBARD2:
7042 case ACTION_BOMBARD3:
7043 case ACTION_BOMBARD4:
7046 case ACTION_SPY_ATTACK:
7051 case ACTION_HUT_ENTER:
7052 case ACTION_HUT_ENTER2:
7053 case ACTION_HUT_ENTER3:
7054 case ACTION_HUT_ENTER4:
7059 case ACTION_UNIT_MOVE:
7060 case ACTION_UNIT_MOVE2:
7061 case ACTION_UNIT_MOVE3:
7062 case ACTION_TELEPORT:
7063 case ACTION_TELEPORT2:
7064 case ACTION_TELEPORT3:
7070 case ACTION_SPY_ESCAPE:
7072 case ACTION_ESCAPE:
7073 case ACTION_CIVIL_WAR:
7074 case ACTION_FINISH_UNIT:
7076 /* Actor consuming always is not ruleset changeable */
7077 return NULL;
7078 case ACTION_FOUND_CITY:
7079 return "found_city_consuming_always";
7080 case ACTION_NUKE:
7081 return "explode_nuclear_consuming_always";
7082 case ACTION_NUKE_CITY:
7083 return "nuke_city_consuming_always";
7084 case ACTION_NUKE_UNITS:
7085 return "nuke_units_consuming_always";
7087 return "spread_plague_actor_consuming_always";
7089 return "user_action_1_actor_consuming_always";
7091 return "user_action_2_actor_consuming_always";
7093 return "user_action_3_actor_consuming_always";
7095 return "user_action_4_actor_consuming_always";
7096 case ACTION_COUNT:
7097 break;
7098
7100 }
7101
7102 fc_assert(act >= 0 && act < ACTION_COUNT);
7103
7104 return NULL;
7105}
7106
7107/**********************************************************************/
7114const char *action_blocked_by_ruleset_var_name(const struct action *act)
7115{
7116 fc_assert_ret_val(act != NULL, NULL);
7117
7118 switch ((enum gen_action)action_number(act)) {
7119 case ACTION_MARKETPLACE:
7120 return "enter_marketplace_blocked_by";
7121 case ACTION_BOMBARD:
7122 return "bombard_blocked_by";
7123 case ACTION_BOMBARD2:
7124 return "bombard_2_blocked_by";
7125 case ACTION_BOMBARD3:
7126 return "bombard_3_blocked_by";
7127 case ACTION_BOMBARD4:
7128 return "bombard_4_blocked_by";
7130 return "bombard_lethal_blocked_by";
7132 return "bombard_lethal_2_blocked_by";
7133 case ACTION_NUKE:
7134 return "explode_nuclear_blocked_by";
7135 case ACTION_NUKE_CITY:
7136 return "nuke_city_blocked_by";
7137 case ACTION_NUKE_UNITS:
7138 return "nuke_units_blocked_by";
7139 case ACTION_ATTACK:
7140 return "attack_blocked_by";
7141 case ACTION_ATTACK2:
7142 return "attack_2_blocked_by";
7144 return "suicide_attack_blocked_by";
7146 return "suicide_attack_2_blocked_by";
7147 case ACTION_WIPE_UNITS:
7148 return "wipe_units_blocked_by";
7150 return "collect_ransom_blocked_by";
7152 return "conquer_city_shrink_blocked_by";
7154 return "conquer_city_shrink_2_blocked_by";
7156 return "conquer_city_shrink_3_blocked_by";
7158 return "conquer_city_shrink_4_blocked_by";
7159 case ACTION_UNIT_MOVE:
7160 return "move_blocked_by";
7161 case ACTION_UNIT_MOVE2:
7162 return "move_2_blocked_by";
7163 case ACTION_UNIT_MOVE3:
7164 return "move_3_blocked_by";
7165 case ACTION_TELEPORT:
7166 return "teleport_blocked_by";
7167 case ACTION_TELEPORT2:
7168 return "teleport_2_blocked_by";
7169 case ACTION_TELEPORT3:
7170 return "teleport_3_blocked_by";
7172 return "teleport_conquer_blocked_by";
7174 return "teleport_frighten_blocked_by";
7176 return "teleport_frighten_conquer_blocked_by";
7178 return "teleport_enter_blocked_by";
7180 return "teleport_enter_conquer_blocked_by";
7181 case ACTION_SPY_ESCAPE:
7182 case ACTION_SPY_POISON:
7206 case ACTION_STEAL_MAPS:
7208 case ACTION_TRADE_ROUTE:
7209 case ACTION_HELP_WONDER:
7211 case ACTION_EXPEL_UNIT:
7212 case ACTION_FOUND_CITY:
7213 case ACTION_JOIN_CITY:
7214 case ACTION_SPY_NUKE:
7219 case ACTION_HOME_CITY:
7220 case ACTION_HOMELESS:
7222 case ACTION_PARADROP:
7228 case ACTION_AIRLIFT:
7231 case ACTION_HEAL_UNIT:
7232 case ACTION_HEAL_UNIT2:
7235 case ACTION_CULTIVATE:
7236 case ACTION_CULTIVATE2:
7237 case ACTION_PLANT:
7238 case ACTION_PLANT2:
7239 case ACTION_PILLAGE:
7240 case ACTION_PILLAGE2:
7241 case ACTION_CLEAN:
7242 case ACTION_CLEAN2:
7243 case ACTION_FORTIFY:
7244 case ACTION_FORTIFY2:
7245 case ACTION_ROAD:
7246 case ACTION_ROAD2:
7247 case ACTION_CONVERT:
7248 case ACTION_BASE:
7249 case ACTION_BASE2:
7250 case ACTION_MINE:
7251 case ACTION_MINE2:
7252 case ACTION_IRRIGATE:
7253 case ACTION_IRRIGATE2:
7271 case ACTION_SPY_ATTACK:
7276 case ACTION_HUT_ENTER:
7277 case ACTION_HUT_ENTER2:
7278 case ACTION_HUT_ENTER3:
7279 case ACTION_HUT_ENTER4:
7285 case ACTION_CIVIL_WAR:
7286 case ACTION_FINISH_UNIT:
7288 case ACTION_ESCAPE:
7293 /* blocked_by is not ruleset changeable */
7294 return NULL;
7295 case ACTION_COUNT:
7297 break;
7298
7300 }
7301
7302 return NULL;
7303}
7304
7305/**********************************************************************/
7309const char *
7311{
7312 fc_assert_ret_val(act != NULL, NULL);
7313
7319 /* No support in the action performer function */
7320 return NULL;
7321 }
7322
7323 switch ((enum gen_action)action_number(act)) {
7325 return "bribe_unit_post_success_forced_actions";
7327 return "bribe_stack_post_success_forced_actions";
7328 case ACTION_ATTACK:
7329 return "attack_post_success_forced_actions";
7330 case ACTION_ATTACK2:
7331 return "attack_2_post_success_forced_actions";
7332 case ACTION_WIPE_UNITS:
7333 return "wipe_units_post_success_forced_actions";
7335 return "collect_ransom_post_success_forced_actions";
7336 case ACTION_MARKETPLACE:
7337 case ACTION_BOMBARD:
7338 case ACTION_BOMBARD2:
7339 case ACTION_BOMBARD3:
7340 case ACTION_BOMBARD4:
7343 case ACTION_NUKE:
7344 case ACTION_NUKE_CITY:
7345 case ACTION_NUKE_UNITS:
7352 case ACTION_SPY_POISON:
7374 case ACTION_STEAL_MAPS:
7376 case ACTION_TRADE_ROUTE:
7377 case ACTION_HELP_WONDER:
7379 case ACTION_EXPEL_UNIT:
7380 case ACTION_FOUND_CITY:
7381 case ACTION_JOIN_CITY:
7382 case ACTION_SPY_NUKE:
7387 case ACTION_HOME_CITY:
7388 case ACTION_HOMELESS:
7390 case ACTION_PARADROP:
7396 case ACTION_AIRLIFT:
7399 case ACTION_HEAL_UNIT:
7400 case ACTION_HEAL_UNIT2:
7403 case ACTION_CULTIVATE:
7404 case ACTION_CULTIVATE2:
7405 case ACTION_PLANT:
7406 case ACTION_PLANT2:
7407 case ACTION_PILLAGE:
7408 case ACTION_PILLAGE2:
7409 case ACTION_CLEAN:
7410 case ACTION_CLEAN2:
7411 case ACTION_FORTIFY:
7412 case ACTION_FORTIFY2:
7413 case ACTION_ROAD:
7414 case ACTION_ROAD2:
7415 case ACTION_CONVERT:
7416 case ACTION_BASE:
7417 case ACTION_BASE2:
7418 case ACTION_MINE:
7419 case ACTION_MINE2:
7420 case ACTION_IRRIGATE:
7421 case ACTION_IRRIGATE2:
7439 case ACTION_SPY_ATTACK:
7444 case ACTION_HUT_ENTER:
7445 case ACTION_HUT_ENTER2:
7446 case ACTION_HUT_ENTER3:
7447 case ACTION_HUT_ENTER4:
7452 case ACTION_UNIT_MOVE:
7453 case ACTION_UNIT_MOVE2:
7454 case ACTION_UNIT_MOVE3:
7455 case ACTION_TELEPORT:
7456 case ACTION_TELEPORT2:
7457 case ACTION_TELEPORT3:
7463 case ACTION_SPY_ESCAPE:
7465 case ACTION_ESCAPE:
7466 case ACTION_CIVIL_WAR:
7467 case ACTION_FINISH_UNIT:
7473 /* Not ruleset changeable */
7474 return NULL;
7475 case ACTION_COUNT:
7477 break;
7478
7480 }
7481
7482 return NULL;
7483}
7484
7485/**********************************************************************/
7493
7494/**********************************************************************/
7497const char *gen_action_name_update_cb(const char *old_name)
7498{
7499 if (is_ruleset_compat_mode()) {
7500 }
7501
7502 return old_name;
7503}
7504
7506{
7507 N_("individual cities"), /* ATK_CITY */
7508 N_("individual units"), /* ATK_UNIT */
7509 N_("unit stacks"), /* ATK_STACK */
7510 N_("tiles"), /* ATK_TILE */
7511 N_("tile extras"), /* ATK_EXTRAS */
7512 N_("itself") /* ATK_SELF */
7513};
7514
7515/**********************************************************************/
7520{
7521 fc_assert(kind >= 0 && kind < ATK_COUNT);
7522
7523 return _(atk_helpnames[kind]);
7524}
7525
7526/************************************************************************/
7530{
7531 fc_assert(result < ACTRES_LAST);
7532
7533 return actlist_by_result[result];
7534}
7535
7536/************************************************************************/
7540{
7541 fc_assert(activity < ACTIVITY_LAST);
7542
7543 return actlist_by_activity[activity];
7544}
bool is_action_possible_on_city(action_id act_id, const struct player *actor_player, const struct city *target_city)
Definition actions.c:5706
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:5194
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:5784
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:4012
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:3430
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:5316
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:5945
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:3491
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:3275
bool action_prob_possible(const struct act_prob probability)
Definition actions.c:5306
#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:5285
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:3739
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:5127
void actions_rs_pre_san_gen(void)
Definition actions.c:899
const char * action_min_range_ruleset_var_name(int act)
Definition actions.c:6396
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:5228
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:3786
const char * action_blocked_by_ruleset_var_name(const struct action *act)
Definition actions.c:7114
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:4060
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:6010
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:5606
void action_array_end(action_id *act_array, int size)
Definition actions.c:5993
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:4827
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:3964
const char * atk_helpnames[ATK_COUNT]
Definition actions.c:7505
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:3027
bool action_is_in_use(struct action *paction)
Definition actions.c:5899
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:7489
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:5357
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:3646
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:4927
const char * action_post_success_forced_ruleset_var_name(const struct action *act)
Definition actions.c:7310
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:5869
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:5327
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:3918
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:3352
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:3257
static enum fc_tristate tech_can_be_stolen(const struct player *actor_player, const struct player *target_player)
Definition actions.c:3805
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:7539
int action_number(const struct action *action)
Definition actions.c:1229
struct act_prob action_prob_new_unknown(void)
Definition actions.c:5295
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:5338
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:3333
struct act_prob action_prob_and(const struct act_prob *ap1, const struct act_prob *ap2)
Definition actions.c:5444
static bool actions_initialized
Definition actions.c:60
const char * action_actor_consuming_always_ruleset_var_name(action_id act)
Definition actions.c:6939
bool action_immune_government(struct government *gov, action_id act)
Definition actions.c:5662
static bool is_target_possible(const action_id wanted_action, const struct player *actor_player, const struct req_context *target)
Definition actions.c:5685
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:3841
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:4569
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:4910
struct act_prob action_prob_new_certain(void)
Definition actions.c:5265
const char * action_max_range_ruleset_var_name(int act)
Definition actions.c:6576
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:4382
bool action_is_internal(struct action *paction)
Definition actions.c:5925
int action_dice_roll_initial_odds(const struct action *paction)
Definition actions.c:5582
struct act_prob action_prob_self(const struct civ_map *nmap, const struct unit *actor_unit, const action_id act_id)
Definition actions.c:4980
struct act_prob action_prob_fall_back(const struct act_prob *ap1, const struct act_prob *ap2)
Definition actions.c:5514
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:3707
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:3601
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:4761
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:3532
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:3092
struct action_list * action_list_by_result(enum action_result result)
Definition actions.c:7529
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:3510
bool action_univs_not_blocking(const struct action *paction, struct universal *actor_uni, struct universal *target_uni)
Definition actions.c:5969
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:5059
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:3169
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:5160
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:4469
const char * action_target_kind_ruleset_var_name(int act)
Definition actions.c:6765
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:4485
bool action_maybe_possible_actor_unit(const struct civ_map *nmap, const action_id act_id, const struct unit *actor_unit)
Definition actions.c:5729
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:3570
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:3677
const char * action_ui_name_default(int act)
Definition actions.c:6028
#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:5807
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:3946
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:5275
const char * action_target_kind_help(enum action_target_kind kind)
Definition actions.c:7519
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:5094
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:5961
struct act_prob action_prob_new_impossible(void)
Definition actions.c:5255
bool action_enabler_possible_actor(const struct action_enabler *ae)
Definition actions.c:5834
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:5002
static bool action_prob_is_signal(const struct act_prob probability)
Definition actions.c:5349
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:5366
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:4744
bool action_id_is_internal(action_id act)
Definition actions.c:5937
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:3482
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:4552
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:3410
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:3110
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:3187
double action_prob_to_0_to_1_pessimist(const struct act_prob ap)
Definition actions.c:5417
const char * gen_action_name_update_cb(const char *old_name)
Definition actions.c:7497
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:4844
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:162
#define BV_CLR_ALL(bv)
Definition bitvector.h:103
#define BV_ISSET(bv, bit)
Definition bitvector.h:86
static bool is_non_attack_city_tile(const struct tile *ptile, const struct player *pplayer)
Definition city.h: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:58
char * incite_cost
Definition comments.c:76
struct unit struct city struct unit * target_unit
Definition dialogs_g.h:56
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit * actor
Definition dialogs_g.h:73
struct unit * actor_unit
Definition dialogs_g.h:55
struct unit struct city struct unit struct tile * target_tile
Definition dialogs_g.h:57
struct unit struct city * target_city
Definition dialogs_g.h:56
struct unit struct city struct unit struct tile struct extra_type * target_extra
Definition dialogs_g.h:57
int int id
Definition editgui_g.h:28
struct @22::@23 reqs
int get_target_bonus_effects(struct effect_list *plist, const struct req_context *context, const struct req_context *other_context, enum effect_type effect_type)
Definition effects.c:744
struct effect_list * get_effects(enum effect_type effect_type)
Definition effects.c:143
#define effect_list_iterate_end
Definition effects.h:81
#define effect_list_iterate(effect_list, peffect)
Definition effects.h:79
struct extra_type_list * extra_type_list_of_terr_claimers(void)
Definition extras.c:275
bool is_native_extra_to_uclass(const struct extra_type *pextra, const struct unit_class *pclass)
Definition extras.c:857
#define extra_type_list_iterate(extralist, pextra)
Definition extras.h:165
#define extra_type_list_iterate_end
Definition extras.h:167
const struct functions * fc_funcs
int Tech_type_id
Definition fc_types.h:237
@ RPT_CERTAIN
Definition fc_types.h:515
@ RPT_POSSIBLE
Definition fc_types.h:514
int action_id
Definition fc_types.h:249
#define ACTRES_NONE
Definition fc_types.h:187
#define MAX_NUM_ACTION_AUTO_PERFORMERS
Definition fc_types.h:54
#define _(String)
Definition fcintl.h:67
#define N_(String)
Definition fcintl.h:69
struct civ_game game
Definition game.c: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:944
bool can_unit_type_transport(const struct unit_type *transporter, const struct unit_class *transported)
Definition movement.c:901
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:1099
bool can_player_see_unit(const struct player *pplayer, const struct unit *punit)
Definition player.c:1112
bool pplayers_at_war(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1396
bool player_can_see_city_externals(const struct player *pow_player, const struct city *target_city)
Definition player.c:1172
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1417
bool can_player_see_hypotetic_units_at(const struct player *pplayer, const struct tile *ptile)
Definition player.c:1001
bool player_can_trust_tile_has_no_units(const struct player *pplayer, const struct tile *ptile)
Definition player.c:975
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:935
int min
Definition fc_types.h:934
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:593
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