Freeciv-3.2
Loading...
Searching...
No Matches
actions.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996-2013 - Freeciv Development Team
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18#include <math.h> /* ceil, floor */
19#include <stdarg.h>
20
21/* utility */
22#include "astring.h"
23
24/* common */
25#include "actions.h"
26#include "city.h"
27#include "combat.h"
28#include "fc_interface.h"
29#include "game.h"
30#include "map.h"
31#include "metaknowledge.h"
32#include "movement.h"
33#include "nation.h"
34#include "research.h"
35#include "server_settings.h"
36#include "unit.h"
37
38/* Custom data types for obligatory hard action requirements. */
39
40/* A contradiction to an obligatory hard requirement. */
42 /* A requirement that contradicts the obligatory hard requirement. */
44
45 /* Is the obligatory hard requirement in the action enabler's target
46 * requirement vector? If FALSE it is in its actor requirement vector. */
48};
49
50/* One or more alternative obligatory hard requirement contradictions. */
53 /* The obligatory hard requirement is fulfilled if a contradiction exists
54 * that doesn't contradict the action enabler. */
56
57 /* How many obligatory reqs use this */
58 int users;
59};
60
61/* An obligatory hard action requirement */
63 /* The requirement is fulfilled if the action enabler doesn't contradict
64 * one of the contradictions listed here. */
66
67 /* The error message to show when the hard obligatory requirement is
68 * missing. Must be there. */
69 const char *error_msg;
70};
71
72#define SPECVEC_TAG obligatory_req
73#define SPECVEC_TYPE struct obligatory_req
74#include "specvec.h"
75#define obligatory_req_vector_iterate(obreq_vec, pobreq) \
76 TYPED_VECTOR_ITERATE(struct obligatory_req, obreq_vec, pobreq)
77#define obligatory_req_vector_iterate_end VECTOR_ITERATE_END
78
79/* Values used to interpret action probabilities.
80 *
81 * Action probabilities are sent over the network. A change in a value here
82 * will therefore change the network protocol.
83 *
84 * A change in a value here should also update the action probability
85 * format documentation in fc_types.h */
86/* The lowest possible probability value (0%) */
87#define ACTPROB_VAL_MIN 0
88/* The highest possible probability value (100%) */
89#define ACTPROB_VAL_MAX 200
90/* A probability increase of 1% corresponds to this increase. */
91#define ACTPROB_VAL_1_PCT (ACTPROB_VAL_MAX / 100)
92/* Action probability doesn't apply when min is this. */
93#define ACTPROB_VAL_NA 253
94/* Action probability unsupported when min is this. */
95#define ACTPROB_VAL_NOT_IMPL 254
96
101
103
104/* Hard requirements relates to action result. */
107
109
110static struct action *
113 bool rare_pop_up,
116 const int min_distance,
117 const int max_distance,
119
120static bool is_enabler_active(const struct action_enabler *enabler,
121 const struct req_context *actor,
122 const struct req_context *target);
123
124static inline bool
126static inline bool
128static inline bool
130
132 const struct unit *pvictim,
133 const struct tile *tgt_tile,
134 const struct action *paction)
136
137/* Make sure that an action distance can target the whole map. */
140
143
144/**********************************************************************/
156{
157 struct ae_contra_or *out;
158 int i;
159 va_list args;
160
162 out = fc_malloc(sizeof(*out));
163 out->users = 0;
164 out->alternatives = alternatives;
165 out->alternative = fc_malloc(sizeof(out->alternative[0]) * alternatives);
166
167 va_start(args, alternatives);
168 for (i = 0; i < alternatives; i++) {
169 struct requirement contradiction = va_arg(args, struct requirement);
170 bool is_target = va_arg(args, int);
171
172 out->alternative[i].req = contradiction;
173 out->alternative[i].is_target = is_target;
174 }
175 va_end(args);
176
177 return out;
178}
179
180/**********************************************************************/
185{
186 contra->users--;
187
188 if (contra->users < 1) {
189 /* No users left. Delete. */
190 FC_FREE(contra->alternative);
192 }
193}
194
195/**********************************************************************/
203static void voblig_hard_req_reg(struct ae_contra_or *contras,
204 const char *error_message,
205 va_list args)
206{
207 struct obligatory_req oreq;
208 enum action_result res;
209 int users = 0;
210
211 /* A non null action message is used to indicate that an obligatory hard
212 * requirement is missing. */
214
215 /* Pack the obligatory hard requirement. */
216 oreq.contras = contras;
217 oreq.error_msg = error_message;
218
219 /* Add the obligatory hard requirement to each action result it applies
220 * to. */
221 while (ACTRES_NONE != (res = va_arg(args, enum action_result))) {
222 /* Any invalid action result should terminate the loop before this
223 * assertion. */
225 "Invalid action result %d", res);
226
227 /* Add to list for action result */
229
230 /* Register the new user. */
231 users++;
232 }
233
234 fc_assert(users > 0);
235
236 oreq.contras->users += users;
237}
238
239/**********************************************************************/
248 const char *error_message,
249 ...)
250{
251 va_list args;
252
253 /* Add the obligatory hard requirement to each action result it applies
254 * to. */
255 va_start(args, error_message);
257 va_end(args);
258}
259
260/**********************************************************************/
268 bool is_target,
269 const char *error_message,
270 ...)
271{
272 struct ae_contra_or *contra;
273 va_list args;
274
275 /* Pack the obligatory hard requirement. */
277
278 /* Add the obligatory hard requirement to each action result it applies
279 * to. */
280 va_start(args, error_message);
282 va_end(args);
283}
284
285/**********************************************************************/
294static void voblig_hard_req_reg_sub_res(struct ae_contra_or *contras,
295 const char *error_message,
296 va_list args)
297{
298 struct obligatory_req oreq;
300
301 /* A non null action message is used to indicate that an obligatory hard
302 * requirement is missing. */
304
305 /* Pack the obligatory hard requirement. */
306 oreq.contras = contras;
307 oreq.error_msg = error_message;
308
309 /* Add the obligatory hard requirement to each action sub result it
310 * applies to. */
311 while (ACT_SUB_RES_COUNT != (res = va_arg(args,
312 enum action_sub_result))) {
313 /* Any invalid action sub result should terminate the loop before this
314 * assertion. */
316 "Invalid action result %d", res);
317
318 /* Add to list for action result */
320
321 /* Register the new user. */
322 oreq.contras->users++;
323 }
324}
325
326/**********************************************************************/
337 const char *error_message,
338 ...)
339{
340 va_list args;
341
342 /* Add the obligatory hard requirement to each action result it applies
343 * to. */
344 va_start(args, error_message);
346 va_end(args);
347}
348
349/**********************************************************************/
355{
356 /* Why this is a hard requirement: There is currently no point in
357 * allowing the listed actions against domestic targets.
358 * (Possible counter argument: crazy hack involving the Lua
359 * callback action_started_callback() to use an action to do
360 * something else. */
361 /* TODO: Unhardcode as a part of false flag operation support. */
364 FALSE,
365 N_("All action enablers for %s must require a "
366 "foreign target."),
379 /* The same for tile targeted actions that also can be done to unclaimed
380 * tiles. */
382 2,
385 FALSE,
387 FALSE, TRUE, TRUE,
389 TRUE),
390 /* TRANS: error message for ruledit */
391 N_("All action enablers for %s must require a "
392 "non domestic target."),
395 /* The same for tile extras targeted actions that also can be done to
396 * unowned extras. */
398 2,
401 FALSE,
403 FALSE, TRUE, TRUE,
405 TRUE),
406 /* TRANS: error message for ruledit */
407 N_("All action enablers for %s must require a "
408 "non domestic target."),
411
412 /* Why this is a hard requirement: There is currently no point in
413 * establishing an embassy when a real embassy already exists.
414 * (Possible exception: crazy hack using the Lua callback
415 * action_started_callback() to make establish embassy do something
416 * else even if the UI still call the action Establish Embassy) */
418 FALSE, TRUE, TRUE,
420 FALSE,
421 N_("All action enablers for %s must require the"
422 " absence of a real embassy."),
425
426 /* Why this is a hard requirement: There is currently no point in
427 * fortifying an already fortified unit. */
429 FALSE, TRUE, TRUE,
431 FALSE,
432 N_("All action enablers for %s must require that"
433 " the actor unit isn't already fortified."),
436
437 /* Why this is a hard requirement: there is a hard requirement that
438 * the actor player is at war with the owner of any city on the
439 * target tile.
440 * The Freeciv code assumes that ACTRES_ATTACK has this. */
443 FALSE,
444 N_("All action enablers for %s must require"
445 " that the actor is at war with the target."),
449
450 /* Why this is a hard requirement: Keep the old rules. Need to work
451 * out corner cases. */
454 FALSE,
455 N_("All action enablers for %s must require"
456 " a domestic target."),
458
459 /* Why this is a hard requirement: The code expects that only domestic and
460 * allied transports can be boarded. */
463 FALSE,
464 N_("All action enablers for %s must require"
465 " a domestic or allied target."),
471 FALSE, TRUE, TRUE, DS_WAR),
472 FALSE,
473 N_("All action enablers for %s must require"
474 " a domestic or allied target."),
481 FALSE,
482 N_("All action enablers for %s must require"
483 " a domestic or allied target."),
490 FALSE,
491 N_("All action enablers for %s must require"
492 " a domestic or allied target."),
499 FALSE,
500 N_("All action enablers for %s must require"
501 " a domestic or allied target."),
506
507 /* Why this is a hard requirement: Preserve semantics of the Settlers
508 * unit type flag. */
510 FALSE, FALSE, TRUE,
512 FALSE,
513 N_("All action enablers for %s must require"
514 " that the actor has"
515 " the Settlers utype flag."),
524
525 /* Why this is a hard requirement: Preserve semantics of the rule that a
526 * *_time of 0 disables the action. */
528 FALSE, FALSE, FALSE,
530 TRUE,
531 N_("All action enablers for %s must require"
532 " that the target"
533 " tile's terrain's irrigation_time"
534 " is above 0. (See \"TerrainAlter\"'s"
535 " \"CanIrrigate\")"),
539 FALSE, FALSE, FALSE,
541 TRUE,
542 N_("All action enablers for %s must require"
543 " that the target"
544 " tile's terrain's mining_time"
545 " is above 0. (See \"TerrainAlter\"'s"
546 " \"CanMine\")"),
550 FALSE, FALSE, FALSE,
552 TRUE,
553 N_("All action enablers for %s must require"
554 " that the target"
555 " tile's terrain's road_time"
556 " is above 0. (See \"TerrainAlter\"'s"
557 " \"CanRoad\")"),
561 FALSE, FALSE, FALSE,
563 TRUE,
564 N_("All action enablers for %s must require"
565 " that the target"
566 " tile's terrain's base_time"
567 " is above 0. (See \"TerrainAlter\"'s"
568 " \"CanBase\")"),
571
572 /* Why this is a hard requirement: Preserve semantics of the NoCities
573 * terrain flag. */
575 FALSE, TRUE, TRUE,
577 TRUE,
578 N_("All action enablers for %s must require that"
579 " the target doesn't have"
580 " the NoCities terrain flag."),
583
584 /* It isn't possible to establish a trade route from a non existing
585 * city. The Freeciv code assumes this applies to Enter Marketplace
586 * too. */
588 FALSE, FALSE, TRUE,
590 FALSE,
591 N_("All action enablers for %s must require"
592 " that the actor has a home city."),
596
597 /* Why this is a hard requirement:
598 * - preserve the semantics of the NonMil unit type flag. */
600 3,
602 FALSE, FALSE, TRUE,
604 FALSE,
607 FALSE,
609 FALSE, TRUE, TRUE,
611 TRUE),
612 /* TRANS: error message for ruledit */
613 N_("All action enablers for %s must require"
614 " that the actor has the NonMil utype flag"
615 " or that the target tile is unclaimed"
616 " or that the diplomatic relation to"
617 " the target tile owner isn't peace."),
621
622 /* Why this is a hard requirement: Preserve semantics of NonMil
623 * flag. Need to replace other uses in game engine before this can
624 * be demoted to a regular unit flag. */
627 FALSE,
628 N_("All action enablers for %s must require"
629 " that the actor doesn't have"
630 " the NonMil utype flag."),
636 2,
639 FALSE,
641 FALSE, TRUE, TRUE,
643 TRUE),
644 /* TRANS: error message for ruledit */
645 N_("All action enablers for %s must require"
646 " no city at the target tile or"
647 " that the actor doesn't have"
648 " the NonMil utype flag."),
651
652 /* Why this is a hard requirement: Preserve semantics of
653 * CanOccupyCity unit class flag. */
655 FALSE, FALSE, TRUE,
657 FALSE,
658 N_("All action enablers for %s must require"
659 " that the actor has"
660 " the CanOccupyCity uclass flag."),
664 2,
666 FALSE, FALSE, TRUE,
668 FALSE,
670 FALSE, TRUE, TRUE,
672 TRUE),
673 /* TRANS: error message for ruledit */
674 N_("All action enablers for %s must require"
675 " no city at the target tile or"
676 " that the actor has"
677 " the CanOccupyCity uclass flag."),
680
681 /* Why this is a hard requirement: Consistency with ACTRES_ATTACK.
682 * Assumed by other locations in the Freeciv code. Examples:
683 * unit_move_to_tile_test(), unit_conquer_city() and do_paradrop(). */
686 FALSE,
687 N_("All action enablers for %s must require"
688 " that the actor is at war with the target."),
692 2,
695 FALSE,
697 FALSE, TRUE, TRUE,
699 TRUE),
700 /* TRANS: error message for ruledit */
701 N_("All action enablers for %s must require"
702 " no city at the target tile or"
703 " that the actor is at war with the target."),
706
707 /* Why this is a hard requirement: a unit must move into a city to
708 * conquer it, move into a transport to embark, move out of a transport
709 * to disembark from it, move into an extra to conquer it and move into a
710 * hut to enter/frighten it. */
712 FALSE, FALSE, TRUE, 1),
713 FALSE,
714 N_("All action enablers for %s must require"
715 " that the actor has a movement point left."),
724
725 /* Why this is a hard requirement: this eliminates the need to
726 * check if units transported by the actor unit can exist at the
727 * same tile as all the units in the occupied city.
728 *
729 * This makes an implicit rule explicit:
730 * 1. A unit must move into a city to conquer it.
731 * 2. It can't move into the city if the tile contains a non-allied
732 * unit (see unit_move_to_tile_test()).
733 * 3. A city could, at the time this rule was made explicit, only
734 * contain units allied to its owner.
735 * 3. A player could, at the time this rule was made explicit, not
736 * be allied to a player that is at war with another ally.
737 * 4. A player could, at the time this rule was made explicit, only
738 * conquer a city belonging to someone they were at war with.
739 * Conclusion: the conquered city had to be empty.
740 */
742 FALSE, FALSE, TRUE, 0),
743 TRUE,
744 N_("All action enablers for %s must require"
745 " that the target city is empty."),
748
749 /* Why this is a hard requirement: Assumed in the code. Corner case
750 * where diplomacy prevents a transported unit to go to the target
751 * tile. The paradrop code doesn't check if transported units can
752 * coexist with the target tile city and units. */
754 FALSE, TRUE, TRUE,
756 FALSE,
757 N_("All action enablers for %s must require"
758 " that the actor isn't transporting"
759 " another unit."),
764
765 /* Why this is a hard requirement: sanity. */
767 FALSE, FALSE, FALSE,
769 FALSE,
770 N_("All action enablers for %s must require"
771 " that the actor has a home city."),
773
774 /* Why this is a hard requirement: Assumed in the code.
775 * See hrm Bug #772516 - https://www.hostedredmine.com/issues/772516 */
777 FALSE, TRUE, TRUE,
779 TRUE,
780 N_("All action enablers for %s must require"
781 " that the target isn't transporting another"
782 " unit."),
784
785 /* Why this is a hard requirement: sanity. */
787 FALSE, FALSE, TRUE,
789 TRUE,
790 N_("All action enablers for %s must require"
791 " that the target is transporting a unit."),
794 FALSE, FALSE, TRUE,
796 FALSE,
797 N_("All action enablers for %s must require"
798 " that the actor is transported."),
803 FALSE, FALSE, TRUE,
805 FALSE,
806 N_("All action enablers for %s must require"
807 " that the actor is on a livable tile."),
809
810 /* Why this is a hard requirement: sanity. */
812 FALSE, FALSE, TRUE,
814 FALSE,
815 N_("All action enablers for %s must require"
816 " that the actor is transporting a unit."),
819 FALSE, FALSE, TRUE,
821 TRUE,
822 N_("All action enablers for %s must require"
823 " that the target is transported."),
826 FALSE, FALSE, TRUE,
828 TRUE,
829 N_("All action enablers for %s must require"
830 " that the target is on a livable tile."),
832
833 /* Why this is a hard requirement: Use ACTRES_TRANSPORT_DISEMBARK to
834 * disembark. Assumed by the Freeciv code. */
836 FALSE, TRUE, TRUE,
838 FALSE,
839 N_("All action enablers for %s must require"
840 " that the actor isn't transported."),
844
845 /* Why this is a hard requirement: assumed by the Freeciv code. */
847 FALSE, FALSE, TRUE,
849 FALSE,
850 N_("All action enablers for %s must require"
851 " that the actor unit is in a city."),
854
855 /* Why this is a hard requirement: Give meaning to the HutFrighten unit
856 * class flag. The point of it is to keep our options open for how both
857 * entering and frightening a hut at the same tile should be handled.
858 * See hrm Feature #920427 */
860 1,
862 FALSE, TRUE, FALSE,
864 FALSE),
865 N_("All action enablers for %s must require"
866 " that the actor unit doesn't have the"
867 " HutFrighten unit class flag."),
871 1,
873 FALSE, FALSE, FALSE,
875 FALSE),
876 N_("All action enablers for %s must require"
877 " that the actor unit has the HutFrighten"
878 " unit class flag."),
881}
882
883/**********************************************************************/
888{
889 /* Why this is a hard requirement: the "animal can't conquer a city"
890 * rule. Assumed in unit_can_take_over(). */
891 nations_iterate(pnation) {
892 if (nation_barbarian_type(pnation) == ANIMAL_BARBARIAN) {
894 FALSE, TRUE, TRUE,
895 nation_number(pnation)),
896 FALSE,
897 N_("All action enablers for %s must require"
898 " a non animal player actor."),
902 2,
904 FALSE, TRUE, TRUE,
905 nation_number(pnation)),
906 FALSE,
908 FALSE, TRUE, TRUE,
910 TRUE),
911 /* TRANS: error message for ruledit */
912 N_("All action enablers for %s must require"
913 " no city at the target tile or"
914 " a non animal player actor."),
917 }
919}
920
921/**********************************************************************/
924static void hard_code_actions(void)
925{
928 FALSE, TRUE,
929 MAK_ESCAPE, 0, 1, TRUE);
932 FALSE, TRUE,
933 MAK_ESCAPE, 0, 1, FALSE);
936 FALSE, TRUE,
937 MAK_ESCAPE, 0, 1, TRUE);
940 FALSE, TRUE,
941 MAK_ESCAPE, 0, 1, FALSE);
944 FALSE, TRUE,
945 /* Tries a forced move if the target unit is alone at
946 * its tile and not in a city. Takes all movement if
947 * the forced move fails. */
949 0, 1, FALSE);
952 FALSE, TRUE,
953 MAK_ESCAPE, 0, 1, TRUE);
956 FALSE, TRUE,
957 MAK_ESCAPE, 0, 1, FALSE);
961 FALSE, TRUE,
962 MAK_ESCAPE, 0, 1, TRUE);
966 FALSE, TRUE,
967 MAK_ESCAPE, 0, 1, TRUE);
971 FALSE, TRUE,
972 MAK_ESCAPE, 0, 1, FALSE);
976 FALSE, TRUE,
977 MAK_ESCAPE, 0, 1, FALSE);
980 FALSE, TRUE,
981 MAK_ESCAPE, 0, 1, TRUE);
984 FALSE, TRUE,
985 MAK_ESCAPE, 0, 1, FALSE);
989 FALSE, TRUE,
990 MAK_STAYS, 0, 1, FALSE);
994 FALSE, TRUE,
995 MAK_STAYS, 0, 1, TRUE);
999 FALSE, TRUE,
1000 MAK_ESCAPE, 0, 1, TRUE);
1004 FALSE, TRUE,
1005 MAK_ESCAPE, 0, 1, FALSE);
1009 FALSE, TRUE,
1010 MAK_ESCAPE, 0, 1, TRUE);
1014 FALSE, TRUE,
1015 MAK_ESCAPE, 0, 1, FALSE);
1019 FALSE, TRUE,
1020 MAK_STAYS, 0, 1, FALSE);
1024 FALSE, TRUE,
1025 MAK_STAYS, 0, 1, TRUE);
1029 FALSE, TRUE,
1030 MAK_ESCAPE, 0, 1, TRUE);
1034 FALSE, TRUE,
1035 MAK_ESCAPE, 0, 1, FALSE);
1039 FALSE, TRUE,
1040 MAK_ESCAPE, 0, 1, FALSE);
1044 FALSE, TRUE,
1045 MAK_ESCAPE, 0, 1, FALSE);
1048 FALSE, TRUE,
1049 MAK_STAYS, 0, 1, TRUE);
1052 FALSE, TRUE,
1053 MAK_STAYS, 0, 1, TRUE);
1056 FALSE, TRUE,
1057 MAK_STAYS, 0, 1, TRUE);
1061 /* A single domestic unit at the target tile will make
1062 * the action illegal. It must therefore be performed
1063 * from another tile. */
1064 1, 1,
1065 FALSE);
1069 /* Illegal to perform to a target on another tile.
1070 * Reason: The Freeciv code assumes that the city
1071 * founding unit is located at the tile were the new
1072 * city is founded. */
1073 0, 0,
1074 TRUE);
1077 TRUE, TRUE,
1078 MAK_STAYS, 0, 1, TRUE);
1081 FALSE, TRUE,
1082 MAK_ESCAPE, 0, 1, TRUE);
1085 FALSE, TRUE,
1086 MAK_ESCAPE, 0, 1, FALSE);
1090 /* A single domestic unit at the target tile will make
1091 * the action illegal. It must therefore be performed
1092 * from another tile. */
1093 1,
1094 /* Overwritten by the ruleset's bombard_max_range */
1095 1,
1096 FALSE);
1099 FALSE, TRUE,
1100 MAK_STAYS,
1101 /* A single domestic unit at the target tile will make
1102 * the action illegal. It must therefore be performed
1103 * from another tile. */
1104 1,
1105 /* Overwritten by the ruleset's bombard_2_max_range */
1106 1,
1107 FALSE);
1111 /* A single domestic unit at the target tile will make
1112 * the action illegal. It must therefore be performed
1113 * from another tile. */
1114 1,
1115 /* Overwritten by the ruleset's bombard_3_max_range */
1116 1,
1117 FALSE);
1121 /* A single domestic unit at the target tile will make
1122 * the action illegal. It must therefore be performed
1123 * from another tile. */
1124 1,
1125 /* Overwritten by the ruleset's bombard_4_max_range */
1126 1,
1127 FALSE);
1131 /* A single domestic unit at the target tile will make
1132 * the action illegal. It must therefore be performed
1133 * from another tile. */
1134 1,
1135 /* Overwritten by the ruleset's bombard_lethal_max_range */
1136 1,
1137 FALSE);
1141 /* A single domestic unit at the target tile will make
1142 * the action illegal. It must therefore be performed
1143 * from another tile. */
1144 1,
1145 /* Overwritten by the ruleset's bombard_lethal_2_max_range */
1146 1,
1147 FALSE);
1150 FALSE, TRUE,
1151 MAK_ESCAPE, 0, 1, TRUE);
1154 FALSE, TRUE,
1155 MAK_ESCAPE, 0, 1, FALSE);
1158 TRUE, TRUE,
1159 MAK_STAYS, 0,
1160 /* Overwritten by the ruleset's
1161 * explode_nuclear_max_range */
1162 0,
1163 TRUE);
1166 TRUE, TRUE,
1167 MAK_STAYS, 1, 1, TRUE);
1170 TRUE, TRUE,
1171 MAK_STAYS, 1, 1, TRUE);
1174 TRUE, TRUE,
1175 MAK_STAYS, 0, 1, FALSE);
1178 FALSE, TRUE,
1179 MAK_STAYS, 0, 1, FALSE);
1183 /* Illegal to perform to a target on another tile to
1184 * keep the rules exactly as they were for now. */
1185 0, 1,
1186 TRUE);
1189 /* Can't be ACTRES_NONE because
1190 * action_success_actor_consume() sets unit lost
1191 * reason based on action result. */
1193 TRUE, TRUE,
1194 MAK_STAYS, 0, 0, TRUE);
1197 TRUE, FALSE,
1198 /* Illegal to perform to a target on another tile to
1199 * keep the rules exactly as they were for now. */
1200 MAK_STAYS, 0, 0, FALSE);
1203 TRUE, FALSE,
1204 MAK_STAYS, 0, 0, FALSE);
1208 /* Illegal to perform to a target on another tile to
1209 * keep the rules exactly as they were for now. */
1210 0, 0,
1211 FALSE);
1214 TRUE, TRUE,
1216 1,
1217 /* Still limited by each unit type's
1218 * paratroopers_range field. */
1220 FALSE);
1223 TRUE, TRUE,
1225 1,
1226 /* Still limited by each unit type's
1227 * paratroopers_range field. */
1229 FALSE);
1232 TRUE, TRUE,
1234 1,
1235 /* Still limited by each unit type's
1236 * paratroopers_range field. */
1238 FALSE);
1242 TRUE, TRUE,
1244 1,
1245 /* Still limited by each unit type's
1246 * paratroopers_range field. */
1248 FALSE);
1251 TRUE, TRUE,
1253 1,
1254 /* Still limited by each unit type's
1255 * paratroopers_range field. */
1257 FALSE);
1261 TRUE, TRUE,
1263 1,
1264 /* Still limited by each unit type's
1265 * paratroopers_range field. */
1267 FALSE);
1270 TRUE, TRUE,
1272 1,
1273 /* Overwritten by the ruleset's airlift_max_range. */
1275 FALSE);
1278 FALSE, TRUE,
1279 /* Tries a forced move if the target unit's tile has
1280 * no non-allied units and the occupychance dice roll
1281 * tells it to move. */
1282 MAK_FORCED,
1283 1, 1, FALSE);
1286 FALSE, TRUE,
1287 /* Tries a forced move if the target unit's tile has
1288 * no non-allied units and the occupychance dice roll
1289 * tells it to move. */
1290 MAK_FORCED,
1291 1, 1, FALSE);
1294 FALSE, TRUE,
1295 MAK_FORCED, 1, 1, TRUE);
1298 FALSE, TRUE,
1299 MAK_FORCED, 1, 1, TRUE);
1302 FALSE, TRUE,
1303 MAK_FORCED,
1304 1, 1, FALSE);
1307 FALSE, FALSE,
1308 MAK_STAYS, 1, 1, FALSE);
1311 FALSE, FALSE,
1312 MAK_STAYS, 1, 1, FALSE);
1315 FALSE, TRUE,
1316 MAK_REGULAR, 1, 1, FALSE);
1319 FALSE, TRUE,
1320 MAK_REGULAR, 1, 1, FALSE);
1323 FALSE, TRUE,
1324 MAK_REGULAR, 1, 1, FALSE);
1327 FALSE, TRUE,
1328 MAK_REGULAR, 1, 1, FALSE);
1331 FALSE, TRUE,
1332 MAK_REGULAR, 1, 1, FALSE);
1335 FALSE, TRUE,
1336 MAK_REGULAR, 1, 1, FALSE);
1339 FALSE, TRUE,
1340 MAK_REGULAR, 1, 1, FALSE);
1343 FALSE, TRUE,
1344 MAK_REGULAR, 1, 1, FALSE);
1347 FALSE, TRUE,
1348 MAK_STAYS, 0, 1, FALSE);
1351 FALSE, TRUE,
1352 MAK_STAYS, 0, 1, FALSE);
1355 TRUE, FALSE,
1356 MAK_STAYS, 0, 0, FALSE);
1359 TRUE, FALSE,
1360 MAK_STAYS, 0, 0, FALSE);
1363 TRUE, FALSE,
1364 MAK_STAYS, 0, 0, FALSE);
1367 TRUE, FALSE,
1368 MAK_STAYS, 0, 0, FALSE);
1371 TRUE, FALSE,
1372 MAK_STAYS, 0, 0, FALSE);
1375 TRUE, FALSE,
1376 MAK_STAYS, 0, 0, FALSE);
1379 TRUE, FALSE,
1380 MAK_STAYS, 0, 0, FALSE);
1383 TRUE, FALSE,
1384 MAK_STAYS, 0, 0, FALSE);
1387 TRUE, FALSE,
1388 MAK_STAYS, 0, 0, FALSE);
1391 TRUE, FALSE,
1392 MAK_STAYS, 0, 0, FALSE);
1395 TRUE, FALSE,
1396 MAK_STAYS, 0, 0, FALSE);
1399 TRUE, FALSE,
1400 MAK_STAYS, 0, 0, FALSE);
1403 TRUE, FALSE,
1404 MAK_STAYS, 0, 0, FALSE);
1407 TRUE, FALSE,
1408 MAK_STAYS, 0, 0, FALSE);
1411 TRUE, FALSE,
1412 MAK_STAYS, 0, 0, FALSE);
1415 TRUE, FALSE,
1416 MAK_STAYS, 0, 0, FALSE);
1419 TRUE, FALSE,
1420 MAK_STAYS, 0, 0, FALSE);
1423 TRUE, FALSE,
1424 MAK_STAYS, 0, 0, FALSE);
1427 TRUE, FALSE,
1428 MAK_STAYS, 0, 0, FALSE);
1432 FALSE, TRUE,
1433 MAK_REGULAR, 1, 1, FALSE);
1437 FALSE, TRUE,
1438 MAK_REGULAR, 1, 1, FALSE);
1442 FALSE, TRUE,
1443 MAK_REGULAR, 1, 1, FALSE);
1447 FALSE, TRUE,
1448 MAK_REGULAR, 1, 1, FALSE);
1451 TRUE, TRUE,
1452 MAK_REGULAR, 1, 1, FALSE);
1455 TRUE, TRUE,
1456 MAK_REGULAR, 1, 1, FALSE);
1459 TRUE, TRUE,
1460 MAK_REGULAR, 1, 1, FALSE);
1463 TRUE, TRUE,
1464 MAK_REGULAR, 1, 1, FALSE);
1467 FALSE, TRUE,
1468 MAK_STAYS, 1, 1, FALSE);
1471 FALSE, TRUE,
1472 MAK_REGULAR, 1, 1, FALSE);
1475 FALSE, TRUE,
1476 MAK_REGULAR, 1, 1, FALSE);
1479 FALSE, TRUE,
1480 MAK_REGULAR, 1, 1, FALSE);
1483 FALSE, TRUE,
1484 MAK_REGULAR, 1, 1, FALSE);
1487 FALSE, TRUE,
1488 MAK_REGULAR, 1, 1, FALSE);
1491 FALSE, TRUE,
1492 MAK_REGULAR, 1, 1, FALSE);
1495 FALSE, TRUE,
1496 MAK_REGULAR, 1, 1, FALSE);
1499 FALSE, TRUE,
1500 MAK_REGULAR, 1, 1, FALSE);
1503 TRUE, TRUE,
1504 MAK_REGULAR, 1, 1, FALSE);
1507 TRUE, TRUE,
1508 MAK_REGULAR, 1, 1, FALSE);
1511 TRUE, TRUE,
1512 MAK_REGULAR, 1, 1, FALSE);
1515 TRUE, TRUE,
1516 MAK_TELEPORT, 1, 1, FALSE);
1519 TRUE, TRUE,
1520 MAK_TELEPORT, 1,
1525 TRUE, TRUE,
1526 MAK_TELEPORT, 1,
1531 TRUE, TRUE,
1532 MAK_TELEPORT, 1,
1537 TRUE, TRUE,
1538 MAK_TELEPORT, 1,
1543 TRUE, TRUE,
1544 MAK_TELEPORT, 1,
1548 FALSE, TRUE,
1550 /* Overwritten by the ruleset */
1551 0, 1, FALSE);
1554 FALSE, TRUE,
1556 /* Overwritten by the ruleset */
1557 0, 1, FALSE);
1560 FALSE, TRUE,
1562 /* Overwritten by the ruleset */
1563 0, 1, FALSE);
1566 FALSE, TRUE,
1568 /* Overwritten by the ruleset */
1569 0, 1, FALSE);
1572 FALSE, TRUE,
1573 /* Tries a forced move if the target unit's tile has
1574 * no non-allied units and the occupychance dice roll
1575 * tells it to move. */
1576 MAK_FORCED,
1577 1, 1, FALSE);
1578
1579 /* The structure even for these need to be created, for
1580 * the action_id_rule_name() to work on iterations. */
1581
1582 /*
1583 actions[ACTION_UNUSED_1]
1584 = unit_action_new(ACTION_UNUSED_1, ACTRES_NONE,
1585 FALSE, FALSE,
1586 MAK_UNREPRESENTABLE,
1587 0, 0, FALSE);
1588 */
1589}
1590
1591/**********************************************************************/
1595{
1596 int i, j;
1597
1598 for (i = 0; i < ACTRES_LAST; i++) {
1600 }
1601 for (i = 0; i < ACTIVITY_LAST; i++) {
1603 }
1604
1605 /* Hard code the actions */
1607
1608 /* Initialize the action enabler list */
1609 action_iterate_all(act) {
1612
1613 /* Initialize action obligatory hard requirements. */
1614
1615 /* Obligatory hard requirements sorted by action result in memory. */
1616 for (i = 0; i < ACTRES_NONE; i++) {
1617 /* Prepare each action result's storage area. */
1619 }
1620
1621 /* Obligatory hard requirements sorted by action sub result in memory. */
1622 for (i = 0; i < ACT_SUB_RES_COUNT; i++) {
1623 /* Prepare each action sub result's storage area. */
1625 }
1626
1627 /* Obligatory hard requirements are sorted by requirement in the source
1628 * code. This makes it easy to read, modify and explain it. */
1630
1631 /* Initialize the action auto performers. */
1632 for (i = 0; i < MAX_NUM_ACTION_AUTO_PERFORMERS; i++) {
1633 /* Nothing here. Nothing after this point. */
1635
1636 /* The criteria to pick *this* auto performer for its cause. */
1638
1639 for (j = 0; j < MAX_NUM_ACTIONS; j++) {
1640 /* Nothing here. Nothing after this point. */
1642 }
1643 }
1644
1645 /* The actions them self are now initialized. */
1647}
1648
1649/**********************************************************************/
1655{
1656 /* Some obligatory hard requirements needs access to the rest of the
1657 * ruleset. */
1659}
1660
1661/**********************************************************************/
1665{
1666 int i;
1667
1668 /* Don't consider the actions to be initialized any longer. */
1670
1671 action_iterate_all(act) {
1675
1677
1678 FC_FREE(actions[act]);
1680
1681 /* Free the obligatory hard action requirements. */
1682 for (i = 0; i < ACTRES_NONE; i++) {
1684 ae_contra_close(oreq->contras);
1687 }
1688 for (i = 0; i < ACT_SUB_RES_COUNT; i++) {
1690 ae_contra_close(oreq->contras);
1693 }
1694
1695 /* Free the action auto performers. */
1696 for (i = 0; i < MAX_NUM_ACTION_AUTO_PERFORMERS; i++) {
1698 }
1699
1701
1702 for (i = 0; i < ACTRES_LAST; i++) {
1705 }
1706 for (i = 0; i < ACTIVITY_LAST; i++) {
1709 }
1710}
1711
1712/**********************************************************************/
1718{
1719 if (!actions_initialized) {
1720 /* The actions them self aren't initialized yet. */
1721 return FALSE;
1722 }
1723
1724 action_iterate(act) {
1725 if (actions[act]->ui_name[0] == '\0') {
1726 /* An action without a UI name exists means that the ruleset haven't
1727 * loaded yet. The ruleset loading will assign a default name to
1728 * any actions not named by the ruleset. The client will get this
1729 * name from the server. */
1730 return FALSE;
1731 }
1733
1734 /* The actions should be ready for use. */
1735 return TRUE;
1736}
1737
1738/**********************************************************************/
1741static struct action *action_new(action_id id,
1742 enum action_result result,
1743 const int min_distance,
1744 const int max_distance,
1746{
1747 struct action *action;
1748
1749 action = fc_malloc(sizeof(*action));
1750
1751 action->id = id;
1752
1753 action->result = result;
1754
1755 if (result != ACTRES_LAST) {
1757
1759
1760 if (act != ACTIVITY_LAST) {
1762 }
1763 }
1764
1765 /* Not set here */
1767
1772
1773 /* ASTK_NONE implies ACT_TGT_COMPL_SIMPLE and
1774 * !ASTK_NONE implies !ACT_TGT_COMPL_SIMPLE */
1779 "%s contradicts itself regarding sub targets.",
1781
1782 /* The distance between the actor and itself is always 0. */
1784 || (min_distance == 0 && max_distance == 0));
1785
1788
1790
1791 /* Loaded from the ruleset. Until generalized actions are ready it has to
1792 * be defined separately from other action data. */
1793 action->ui_name[0] = '\0';
1794 action->quiet = FALSE;
1796
1797 return action;
1798}
1799
1800/**********************************************************************/
1803static struct action *
1805 enum action_result result,
1806 bool rare_pop_up,
1809 const int min_distance,
1810 const int max_distance,
1812{
1813 struct action *act = action_new(id, result,
1816
1818
1820
1822
1823 return act;
1824}
1825
1826/**********************************************************************/
1829bool action_id_exists(const action_id act_id)
1830{
1831 /* Actions are still hard coded. */
1832 return gen_action_is_valid(act_id) && actions[act_id];
1833}
1834
1835/**********************************************************************/
1840struct action *action_by_rule_name(const char *name)
1841{
1842 /* Actions are still hard coded in the gen_action enum. */
1844
1845 if (!action_id_exists(act_id)) {
1846 /* Nothing to return. */
1847
1848 log_verbose("Asked for non existing action named %s", name);
1849
1850 return NULL;
1851 }
1852
1853 return action_by_number(act_id);
1854}
1855
1856/**********************************************************************/
1860{
1861 fc_assert_ret_val_msg(paction, AAK_COUNT, "Action doesn't exist.");
1862
1863 return paction->actor_kind;
1864}
1865
1866/**********************************************************************/
1870 const struct action *paction)
1871{
1872 fc_assert_ret_val_msg(paction, ATK_COUNT, "Action doesn't exist.");
1873
1874 return paction->target_kind;
1875}
1876
1877/**********************************************************************/
1881 const struct action *paction)
1882{
1883 fc_assert_ret_val_msg(paction, ASTK_COUNT, "Action doesn't exist.");
1884
1885 return paction->sub_target_kind;
1886}
1887
1888/**********************************************************************/
1894{
1896
1897 return paction->target_complexity >= ACT_TGT_COMPL_FLEXIBLE;
1898}
1899
1900/**********************************************************************/
1907{
1909
1910 return paction->target_complexity >= ACT_TGT_COMPL_MANDATORY;
1911}
1912
1913/**********************************************************************/
1922{
1924 FALSE, "Action %d don't exist.", act_id);
1926
1927 return actions[act_id]->actor.is_unit.rare_pop_up;
1928}
1929
1930/**********************************************************************/
1935 const int distance)
1936{
1939}
1940
1941/**********************************************************************/
1946 const int distance)
1947{
1949
1950 return (distance >= action->min_distance
1951 && action_distance_inside_max(action, distance));
1952}
1953
1954/**********************************************************************/
1957bool action_would_be_blocked_by(const struct action *blocked,
1958 const struct action *blocker)
1959{
1960 fc_assert_ret_val(blocked, FALSE);
1961 fc_assert_ret_val(blocker, FALSE);
1962
1963 return BV_ISSET(blocked->blocked_by, action_number(blocker));
1964}
1965
1966/**********************************************************************/
1969int action_number(const struct action *action)
1970{
1971 return action->id;
1972}
1973
1974/**********************************************************************/
1977const char *action_rule_name(const struct action *action)
1978{
1979 /* Rule name is still hard coded. */
1980 return action_id_rule_name(action->id);
1981}
1982
1983/**********************************************************************/
1991const char *action_name_translation(const struct action *action)
1992{
1993 /* Use action_id_name_translation() to format the UI name. */
1995}
1996
1997/**********************************************************************/
2001{
2002 fc_assert_msg(actions[act_id], "Action %d don't exist.", act_id);
2003
2004 return gen_action_name(act_id);
2005}
2006
2007/**********************************************************************/
2012{
2013 return action_prepare_ui_name(act_id, "", ACTPROB_NA, NULL);
2014}
2015
2016/**********************************************************************/
2020 const char *mnemonic)
2021{
2023}
2024
2025/**********************************************************************/
2032static const char *action_prob_to_text(const struct act_prob prob)
2033{
2034 static struct astring chance = ASTRING_INIT;
2035
2036 /* How to interpret action probabilities like prob is documented in
2037 * fc_types.h */
2038 if (action_prob_is_signal(prob)) {
2040 || action_prob_not_relevant(prob));
2041
2042 /* Unknown because of missing server support or should not exits. */
2043 return NULL;
2044 }
2045
2046 if (prob.min == prob.max) {
2047 /* Only one probability in range. */
2048
2049 /* TRANS: the probability that an action will succeed. Given in
2050 * percentage. Resolution is 0.5%. */
2051 astr_set(&chance, _("%.1f%%"), (double)prob.max / ACTPROB_VAL_1_PCT);
2052 } else {
2053 /* TRANS: the interval (end points included) where the probability of
2054 * the action's success is. Given in percentage. Resolution is 0.5%. */
2055 astr_set(&chance, _("[%.1f%%, %.1f%%]"),
2056 (double)prob.min / ACTPROB_VAL_1_PCT,
2057 (double)prob.max / ACTPROB_VAL_1_PCT);
2058 }
2059
2060 return astr_str(&chance);
2061}
2062
2063/**********************************************************************/
2073const char *action_prepare_ui_name(action_id act_id, const char *mnemonic,
2074 const struct act_prob prob,
2075 const char *custom)
2076{
2077 struct astring chance = ASTRING_INIT;
2078
2079 /* Text representation of the probability. */
2080 const char *probtxt;
2081
2082 if (!actions_are_ready()) {
2083 /* Could be a client who haven't gotten the ruleset yet */
2084
2085 /* so there shouldn't be any action probability to show */
2087
2088 /* but the action should be valid */
2090 "Invalid action",
2091 "Invalid action %d", act_id);
2092
2093 /* and no custom text will be inserted */
2094 fc_assert(custom == NULL || custom[0] == '\0');
2095
2096 /* Make the best of what is known */
2097 astr_set(&ui_name_str, _("%s%s (name may be wrong)"),
2098 mnemonic, action_id_rule_name(act_id));
2099
2100 /* Return the guess. */
2101 return astr_str(&ui_name_str);
2102 }
2103
2105
2106 /* Format the info part of the action's UI name. */
2107 if (probtxt != NULL && custom != NULL) {
2108 /* TRANS: action UI name's info part with custom info and probability.
2109 * Hint: you can move the paren handling from this string to the action
2110 * names if you need to add extra information (like a mnemonic letter
2111 * that doesn't appear in the action UI name) to it. In that case you
2112 * must do so for all strings with this comment and for every action
2113 * name. To avoid a `()` when no UI name info part is added you have
2114 * to add the extra information to every action name or remove the
2115 * surrounding parens. */
2116 astr_set(&chance, _(" (%s; %s)"), custom, probtxt);
2117 } else if (probtxt != NULL) {
2118 /* TRANS: action UI name's info part with probability.
2119 * Hint: you can move the paren handling from this string to the action
2120 * names if you need to add extra information (like a mnemonic letter
2121 * that doesn't appear in the action UI name) to it. In that case you
2122 * must do so for all strings with this comment and for every action
2123 * name. To avoid a `()` when no UI name info part is added you have
2124 * to add the extra information to every action name or remove the
2125 * surrounding parens. */
2126 astr_set(&chance, _(" (%s)"), probtxt);
2127 } else if (custom != NULL) {
2128 /* TRANS: action UI name's info part with custom info.
2129 * Hint: you can move the paren handling from this string to the action
2130 * names if you need to add extra information (like a mnemonic letter
2131 * that doesn't appear in the action UI name) to it. In that case you
2132 * must do so for all strings with this comment and for every action
2133 * name. To avoid a `()` when no UI name info part is added you have
2134 * to add the extra information to every action name or remove the
2135 * surrounding parens. */
2136 astr_set(&chance, _(" (%s)"), custom);
2137 } else {
2138 /* No info part to display. */
2140 }
2141
2142 fc_assert_msg(actions[act_id], "Action %d don't exist.", act_id);
2143
2144 /* Escape any instances of the mnemonic in the action's UI format string.
2145 * (Assumes any mnemonic can be escaped by doubling, and that they are
2146 * unlikely to appear in a format specifier. True for clients seen so
2147 * far: Gtk's _ and Qt's &) */
2148 {
2149 struct astring fmtstr = ASTRING_INIT;
2150 const char *ui_name = _(actions[act_id]->ui_name);
2151
2152 if (mnemonic[0] != '\0') {
2153 const char *hit;
2154
2155 fc_assert(!strchr(mnemonic, '%'));
2156 while ((hit = strstr(ui_name, mnemonic))) {
2157 astr_add(&fmtstr, "%.*s%s%s", (int)(hit - ui_name), ui_name,
2159 ui_name = hit + strlen(mnemonic);
2160 }
2161 }
2162 astr_add(&fmtstr, "%s", ui_name);
2163
2164 /* Use the modified format string */
2166 astr_str(&chance));
2167
2168 astr_free(&fmtstr);
2169 }
2170
2171 astr_free(&chance);
2172
2173 return astr_str(&ui_name_str);
2174}
2175
2176/**********************************************************************/
2184const char *action_prob_explain(const struct act_prob prob)
2185{
2186 static struct astring tool_tip = ASTRING_INIT;
2187
2188 if (action_prob_is_signal(prob)) {
2190
2191 /* Missing server support. No in game action will change this. */
2193 } else if (prob.min == prob.max) {
2194 /* TRANS: action probability of success. Given in percentage.
2195 * Resolution is 0.5%. */
2196 astr_set(&tool_tip, _("The probability of success is %.1f%%."),
2197 (double)prob.max / ACTPROB_VAL_1_PCT);
2198 } else {
2200 /* TRANS: action probability interval (min to max). Given in
2201 * percentage. Resolution is 0.5%. The string at the end is
2202 * shown when the interval is wide enough to not be caused by
2203 * rounding. It explains that the interval is imprecise because
2204 * the player doesn't have enough information. */
2205 _("The probability of success is %.1f%%, %.1f%% or somewhere"
2206 " in between.%s"),
2207 (double)prob.min / ACTPROB_VAL_1_PCT,
2208 (double)prob.max / ACTPROB_VAL_1_PCT,
2209 prob.max - prob.min > 1 ?
2210 /* TRANS: explanation used in the action probability tooltip
2211 * above. Preserve leading space. */
2212 _(" (This is the most precise interval I can calculate "
2213 "given the information our nation has access to.)") :
2214 "");
2215 }
2216
2217 return astr_str(&tool_tip);
2218}
2219
2220/**********************************************************************/
2225{
2227 "Action %s isn't performed by a unit",
2229
2230 return paction->id + L_LAST;
2231}
2232
2233/**********************************************************************/
2237{
2238 struct action_enabler *enabler;
2239
2240 enabler = fc_malloc(sizeof(*enabler));
2241 enabler->ruledit_disabled = FALSE;
2242 requirement_vector_init(&enabler->actor_reqs);
2243 requirement_vector_init(&enabler->target_reqs);
2244
2245 /* Make sure that action doesn't end up as a random value that happens to
2246 * be a valid action id. */
2247 enabler->action = ACTION_NONE;
2248
2249 return enabler;
2250}
2251
2252/**********************************************************************/
2256{
2257 requirement_vector_free(&enabler->actor_reqs);
2258 requirement_vector_free(&enabler->target_reqs);
2259
2260 free(enabler);
2261}
2262
2263/**********************************************************************/
2266struct action_enabler *
2268{
2270
2271 enabler->action = original->action;
2272
2273 requirement_vector_copy(&enabler->actor_reqs, &original->actor_reqs);
2274 requirement_vector_copy(&enabler->target_reqs, &original->target_reqs);
2275
2276 return enabler;
2277}
2278
2279/**********************************************************************/
2283{
2284 /* Sanity check: a non existing action enabler can't be added. */
2286 /* Sanity check: a non existing action doesn't have enablers. */
2288
2291 enabler);
2292}
2293
2294/**********************************************************************/
2300{
2301 /* Sanity check: a non existing action enabler can't be removed. */
2303 /* Sanity check: a non existing action doesn't have enablers. */
2305
2308 enabler);
2309}
2310
2311/**********************************************************************/
2314struct action_enabler_list *
2316{
2317 /* Sanity check: a non existing action doesn't have enablers. */
2319
2321}
2322
2323/**********************************************************************/
2334static struct req_vec_problem *
2336 const struct obligatory_req_vector *oblig)
2337{
2338 struct action *paction;
2339
2340 /* Sanity check: a non existing action enabler is missing but it doesn't
2341 * miss any obligatory hard requirements. */
2343
2344 /* Sanity check: a non existing action doesn't have any obligatory hard
2345 * requirements. */
2348
2349 /* No obligatory hard requirements. */
2351
2353 struct req_vec_problem *out;
2354 int i;
2355 bool fulfilled = FALSE;
2356
2357 /* Check each alternative. */
2358 for (i = 0; i < obreq->contras->alternatives; i++) {
2359 const struct requirement_vector *ae_vec;
2360
2361 /* Select action enabler requirement vector. */
2362 ae_vec = (obreq->contras->alternative[i].is_target
2363 ? &enabler->target_reqs
2364 : &enabler->actor_reqs);
2365
2366 if (does_req_contradicts_reqs(&obreq->contras->alternative[i].req,
2367 ae_vec)
2368 /* Consider the hard requirement fulfilled since a universal that
2369 * never is there always will be absent in this ruleset. */
2370 || (obreq->contras->alternative[i].req.present
2372 &obreq->contras->alternative[i].req.source))) {
2373 /* It is enough that one alternative accepts the enabler. */
2374 fulfilled = TRUE;
2375 break;
2376 }
2377
2378 /* Fall back to the next alternative */
2379 }
2380
2381 if (fulfilled) {
2382 /* This obligatory hard requirement isn't a problem. */
2383 continue;
2384 }
2385
2386 /* Missing hard obligatory requirement detected */
2387
2388 out = req_vec_problem_new(obreq->contras->alternatives,
2389 obreq->error_msg,
2391
2392 for (i = 0; i < obreq->contras->alternatives; i++) {
2393 const struct requirement_vector *ae_vec;
2394
2395 /* Select action enabler requirement vector. */
2396 ae_vec = (obreq->contras->alternative[i].is_target
2397 ? &enabler->target_reqs
2398 : &enabler->actor_reqs);
2399
2400 /* The suggested fix is to append a requirement that makes the enabler
2401 * contradict the missing hard obligatory requirement detector. */
2402 out->suggested_solutions[i].operation = RVCO_APPEND;
2403 out->suggested_solutions[i].vector_number
2405
2406 /* Change the requirement from what should conflict to what is
2407 * wanted. */
2408 out->suggested_solutions[i].req.present
2409 = !obreq->contras->alternative[i].req.present;
2410 out->suggested_solutions[i].req.source
2411 = obreq->contras->alternative[i].req.source;
2412 out->suggested_solutions[i].req.range
2413 = obreq->contras->alternative[i].req.range;
2414 out->suggested_solutions[i].req.survives
2415 = obreq->contras->alternative[i].req.survives;
2416 out->suggested_solutions[i].req.quiet
2417 = obreq->contras->alternative[i].req.quiet;
2418 }
2419
2420 /* Return the first problem found. The next problem will be detected
2421 * during the next call. */
2422 return out;
2424
2425 /* No obligatory req problems found. */
2426 return NULL;
2427}
2428
2429/**********************************************************************/
2438struct req_vec_problem *
2440{
2441 struct action *paction;
2443 struct req_vec_problem *out;
2444
2445 /* Sanity check: a non existing action enabler is missing but it doesn't
2446 * miss any obligatory hard requirements. */
2448
2449 /* Sanity check: a non existing action doesn't have any obligatory hard
2450 * requirements. */
2453
2454 if (paction->result != ACTRES_NONE) {
2455 /* A hard coded action result may mean obligatory requirements. */
2457 &oblig_hard_reqs_r[paction->result]);
2458 if (out != NULL) {
2459 return out;
2460 }
2461 }
2462
2466 if (!BV_ISSET(paction->sub_results, sub_res)) {
2467 /* Not relevant */
2468 continue;
2469 }
2470
2471 /* The action has this sub result. Check its hard requirements. */
2474 if (out != NULL) {
2475 return out;
2476 }
2477 }
2478
2479 /* No obligatory req problems found. */
2480 return NULL;
2481}
2482
2483/**********************************************************************/
2489static struct requirement *
2491{
2493 if (preq->source.kind == VUT_DIPLREL
2494 && preq->range == REQ_RANGE_LOCAL) {
2495 return preq;
2496 }
2498
2499 return NULL;
2500}
2501
2502/**********************************************************************/
2510static struct requirement *
2512 const struct requirement_vector *vec)
2513{
2514 /* If the requirement is contradicted by any requirement in the vector it
2515 * contradicts the entire requirement vector. */
2518 return preq;
2519 }
2521
2522 /* Not a singe requirement in the requirement vector is contradicted be
2523 * the specified requirement. */
2524 return NULL;
2525}
2526
2527/**********************************************************************/
2533static struct req_vec_problem *
2535 const struct action_enabler *enabler)
2536{
2537 struct req_vec_problem *out;
2538 struct requirement *local_diplrel;
2539 struct requirement *claimed_req;
2543 struct astring astr;
2544
2546 /* Not tile targeted */
2547 return NULL;
2548 }
2549
2551 if (local_diplrel == NULL) {
2552 /* No local diplrel */
2553 return NULL;
2554 }
2555
2556 /* Tile is unclaimed as a requirement. */
2558 tile_is_unclaimed.survives = FALSE;
2559 tile_is_unclaimed.source.kind = VUT_CITYTILE;
2560 tile_is_unclaimed.present = FALSE;
2561 tile_is_unclaimed.source.value.citytile = CITYT_CLAIMED;
2562
2564 &enabler->target_reqs);
2565
2566 if (claimed_req) {
2567 /* Already clear */
2568 return NULL;
2569 }
2570
2571 /* Tile is claimed as a requirement. */
2573 tile_is_claimed.survives = FALSE;
2574 tile_is_claimed.source.kind = VUT_CITYTILE;
2575 tile_is_claimed.present = TRUE;
2576 tile_is_claimed.source.value.citytile = CITYT_CLAIMED;
2577
2579 1,
2580 /* TRANS: ruledit shows this when an enabler for a tile targeted
2581 * action requires that the actor has a diplomatic relationship to
2582 * the target but doesn't require that the target tile is claimed.
2583 * (DiplRel requirements to an unclaimed tile are never fulfilled
2584 * so this is implicit.) */
2585 N_("Requirement {%s} of action \"%s\" implies a claimed "
2586 "tile. No diplomatic relation to Nature."),
2588
2589 astr_free(&astr);
2590
2591 /* The solution is to add the requirement that the tile is claimed */
2592 out->suggested_solutions[0].req = tile_is_claimed;
2593 out->suggested_solutions[0].vector_number
2595 out->suggested_solutions[0].operation = RVCO_APPEND;
2596
2597 return out;
2598}
2599
2600/**********************************************************************/
2606static struct req_vec_problem *
2608{
2609 struct req_vec_problem *out;
2610 struct requirement *local_diplrel;
2611 struct requirement *unclaimed_req;
2614 struct astring astr1;
2615 struct astring astr2;
2616
2618 /* Not tile targeted */
2619 return NULL;
2620 }
2621
2623 if (local_diplrel == NULL) {
2624 /* No local diplrel */
2625 return NULL;
2626 }
2627
2628 /* Tile is claimed as a requirement. */
2630 tile_is_claimed.survives = FALSE;
2631 tile_is_claimed.source.kind = VUT_CITYTILE;
2632 tile_is_claimed.present = TRUE;
2633 tile_is_claimed.source.value.citytile = CITYT_CLAIMED;
2634
2636 &enabler->target_reqs);
2637
2638 if (unclaimed_req == NULL) {
2639 /* No unclaimed req */
2640 return NULL;
2641 }
2642
2644 2,
2645 /* TRANS: ruledit shows this when an enabler for a tile targeted
2646 * action requires that the target tile is unclaimed and that the
2647 * actor has a diplomatic relationship to the target. (DiplRel
2648 * requirements to an unclaimed tile are never fulfilled.) */
2649 N_("In enabler for \"%s\": No diplomatic relation to Nature."
2650 " Requirements {%s} and {%s} contradict each other."),
2654
2655 astr_free(&astr1);
2656 astr_free(&astr2);
2657
2658 /* The first suggestion is to remove the diplrel */
2659 out->suggested_solutions[0].req = *local_diplrel;
2660 out->suggested_solutions[0].vector_number
2662 out->suggested_solutions[0].operation = RVCO_REMOVE;
2663
2664 /* The 2nd is to remove the requirement that the tile is unclaimed */
2665 out->suggested_solutions[1].req = *unclaimed_req;
2666 out->suggested_solutions[1].vector_number
2668 out->suggested_solutions[1].operation = RVCO_REMOVE;
2669
2670 return out;
2671}
2672
2673/**********************************************************************/
2678struct req_vec_problem *
2680{
2681 struct req_vec_problem *out;
2682
2684 if (out != NULL) {
2685 return out;
2686 }
2687
2688 /* Look for errors in the requirement vectors. */
2689 out = req_vec_suggest_repair(&enabler->actor_reqs,
2691 enabler);
2692 if (out != NULL) {
2693 return out;
2694 }
2695
2696 out = req_vec_suggest_repair(&enabler->target_reqs,
2698 enabler);
2699 if (out != NULL) {
2700 return out;
2701 }
2702
2703 /* Enabler specific contradictions. */
2705 if (out != NULL) {
2706 return out;
2707 }
2708
2709 /* Needed in action not enabled explanation finding. */
2711 if (out != NULL) {
2712 return out;
2713 }
2714
2715 /* No problems found. */
2716 return NULL;
2717}
2718
2719/**********************************************************************/
2726static struct req_vec_problem *
2728{
2729 struct req_vec_problem *out;
2730
2731 out = NULL;
2732
2733 return out;
2734}
2735
2736/**********************************************************************/
2744struct req_vec_problem *
2746{
2747 struct action *paction;
2748 struct req_vec_problem *out;
2749
2751 if (out) {
2752 /* A bug, not just a potential improvement */
2753 return out;
2754 }
2755
2757
2758 /* Look for improvement suggestions to the requirement vectors. */
2761 enabler);
2762 if (out) {
2763 return out;
2764 }
2765 out = req_vec_suggest_improvement(&enabler->target_reqs,
2767 enabler);
2768 if (out) {
2769 return out;
2770 }
2771
2772 /* Detect unused action enablers. */
2774 bool has_user = FALSE;
2775
2779 &(enabler->actor_reqs))) {
2780 has_user = TRUE;
2781 break;
2782 }
2784
2785 if (!has_user) {
2786 /* TRANS: ruledit warns a user about an unused action enabler */
2787 out = req_vec_problem_new(0, N_("Action enabler for \"%s\" is never"
2788 " used by any unit."),
2790 }
2791 }
2792 if (out != NULL) {
2793 return out;
2794 }
2795
2797
2798 return out;
2799}
2800
2801/**********************************************************************/
2810 const struct requirement_vector *vec)
2811{
2812 struct action_enabler *ae = (struct action_enabler *)enabler;
2813
2814 if (vec == &ae->actor_reqs) {
2815 return 0;
2816 } else if (vec == &ae->target_reqs) {
2817 return 1;
2818 } else {
2819 return -1;
2820 }
2821}
2822
2823/********************************************************************/
2831struct requirement_vector *
2833 req_vec_num_in_item number)
2834{
2835 struct action_enabler *ae = (struct action_enabler *)enabler;
2836
2837 fc_assert_ret_val(number >= 0, NULL);
2838
2839 switch (number) {
2840 case 0:
2841 return &ae->actor_reqs;
2842 case 1:
2843 return &ae->target_reqs;
2844 default:
2845 return NULL;
2846 }
2847}
2848
2849/*********************************************************************/
2857{
2858 switch (vec) {
2859 case 0:
2860 /* TRANS: requirement vector in an action enabler (ruledit) */
2861 return _("actor_reqs");
2862 case 1:
2863 /* TRANS: requirement vector in an action enabler (ruledit) */
2864 return _("target_reqs");
2865 default:
2866 return NULL;
2867 }
2868}
2869
2870/**********************************************************************/
2875static const struct impr_type *
2877{
2878 /* Only used with city targets */
2880
2881 if (target_city->production.kind == VUT_IMPROVEMENT) {
2882 /* The local building is what the target city currently is building. */
2883 return target_city->production.value.building;
2884 } else {
2885 /* In the current semantic the local building is always the building
2886 * being built. */
2887 /* TODO: Consider making the local building the target building for
2888 * actions that allows specifying a building target. */
2889 return NULL;
2890 }
2891}
2892
2893/**********************************************************************/
2898static const struct unit_type *
2900{
2901 /* Only used with city targets */
2903
2904 if (target_city->production.kind == VUT_UTYPE) {
2905 /* The local unit type is what the target city currently is
2906 * building. */
2907 return target_city->production.value.utype;
2908 } else {
2909 /* In the current semantic the local utype is always the type of the
2910 * unit being built. */
2911 return NULL;
2912 }
2913}
2914
2915/**********************************************************************/
2923static const struct tile *
2925 const struct unit *actor_unit,
2926 const struct tile *target_tile_arg,
2927 const struct city *target_city,
2928 const struct unit *target_unit)
2929{
2930 if (target_tile_arg != NULL) {
2931 /* Trust the caller. */
2932 return target_tile_arg;
2933 }
2934
2935 /* Action should always be set */
2936 fc_assert_ret_val(act, NULL);
2937
2938 switch (action_get_target_kind(act)) {
2939 case ATK_CITY:
2941 return city_tile(target_city);
2942 case ATK_UNIT:
2943 if (target_unit == NULL) {
2945 return NULL;
2946 }
2947 return unit_tile(target_unit);
2948 case ATK_UNITS:
2950 if (target_unit) {
2951 return unit_tile(target_unit);
2952 }
2953
2955 case ATK_TILE:
2956 case ATK_EXTRAS:
2958 return target_tile_arg;
2959 case ATK_SELF:
2961 return unit_tile(actor_unit);
2962 case ATK_COUNT:
2963 /* Handled below. */
2964 break;
2965 }
2966
2967 fc_assert_msg(FALSE, "Bad action target kind %d for action %s",
2969 return NULL;
2970}
2971
2972/**********************************************************************/
2981static const struct city *
2983 const struct unit *actor_unit,
2984 const struct tile *target_tile,
2985 const struct city *target_city_arg,
2986 const struct unit *target_unit)
2987{
2988 if (target_city_arg != NULL) {
2989 /* Trust the caller. */
2990 return target_city_arg;
2991 }
2992
2993 /* action should always be set */
2994 fc_assert_ret_val(act, NULL);
2995
2996 switch (action_get_target_kind(act)) {
2997 case ATK_CITY:
2999 return target_city_arg;
3000 case ATK_UNIT:
3004 case ATK_UNITS:
3006 if (target_unit) {
3009 }
3010
3012 case ATK_TILE:
3013 case ATK_EXTRAS:
3015 return tile_city(target_tile);
3016 case ATK_SELF:
3020 case ATK_COUNT:
3021 /* Handled below. */
3022 break;
3023 }
3024
3025 fc_assert_msg(FALSE, "Bad action target kind %d for action %s",
3027 return NULL;
3028}
3029
3030/**********************************************************************/
3037 const struct action *act,
3038 const struct unit *actor_unit,
3039 const struct tile *target_tile_arg,
3040 const struct city *target_city_arg,
3041 const struct unit *target_unit)
3042{
3043 const struct tile *target_tile
3046 const struct city *target_city
3049
3051 struct action *blocker = action_by_number(blocker_id);
3052
3054 continue);
3055
3056 if (!action_would_be_blocked_by(act, blocker)) {
3057 /* It doesn't matter if it is legal. It won't block the action. */
3058 continue;
3059 }
3060
3061 switch (action_get_target_kind(blocker)) {
3062 case ATK_CITY:
3063 if (!target_city) {
3064 /* Can't be enabled. No target. */
3065 continue;
3066 }
3069 return blocker;
3070 }
3071 break;
3072 case ATK_UNIT:
3073 if (!target_unit) {
3074 /* Can't be enabled. No target. */
3075 continue;
3076 }
3079 return blocker;
3080 }
3081 break;
3082 case ATK_UNITS:
3083 if (!target_tile) {
3084 /* Can't be enabled. No target. */
3085 continue;
3086 }
3089 return blocker;
3090 }
3091 break;
3092 case ATK_TILE:
3093 if (!target_tile) {
3094 /* Can't be enabled. No target. */
3095 continue;
3096 }
3099 return blocker;
3100 }
3101 break;
3102 case ATK_EXTRAS:
3103 if (!target_tile) {
3104 /* Can't be enabled. No target. */
3105 continue;
3106 }
3109 return blocker;
3110 }
3111 break;
3112 case ATK_SELF:
3114 return blocker;
3115 }
3116 break;
3117 case ATK_COUNT:
3119 continue);
3120 break;
3121 }
3123
3124 /* Not blocked. */
3125 return NULL;
3126}
3127
3128/**********************************************************************/
3148static bool
3150 const struct unit_type *actor_unittype,
3151 bool ignore_third_party)
3152{
3153 switch (paction->result) {
3154 case ACTRES_JOIN_CITY:
3155 if (actor_unittype->pop_cost <= 0) {
3156 /* Reason: Must have population to add. */
3157 return FALSE;
3158 }
3159 break;
3160
3161 case ACTRES_BOMBARD:
3162 if (actor_unittype->bombard_rate <= 0) {
3163 /* Reason: Can't bombard if it never fires. */
3164 return FALSE;
3165 }
3166
3167 if (actor_unittype->attack_strength <= 0) {
3168 /* Reason: Can't bombard without attack strength. */
3169 return FALSE;
3170 }
3171
3172 break;
3173
3175 if (actor_unittype->obsoleted_by == U_NOT_OBSOLETED) {
3176 /* Reason: Nothing to upgrade to. */
3177 return FALSE;
3178 }
3179 break;
3180
3181 case ACTRES_ATTACK:
3182 case ACTRES_WIPE_UNITS:
3184 if (actor_unittype->attack_strength <= 0) {
3185 /* Reason: Can't attack without strength. */
3186 return FALSE;
3187 }
3188 break;
3189
3190 case ACTRES_CONVERT:
3191 if (!actor_unittype->converted_to) {
3192 /* Reason: must be able to convert to something. */
3193 return FALSE;
3194 }
3195 break;
3196
3198 if (actor_unittype->transport_capacity < 1) {
3199 /* Reason: can't transport anything to unload. */
3200 return FALSE;
3201 }
3202 break;
3203
3205 if (actor_unittype->transport_capacity < 1) {
3206 /* Reason: can't transport anything to load. */
3207 return FALSE;
3208 }
3209 break;
3210
3215 if (!ignore_third_party) {
3216 bool has_transporter = FALSE;
3217
3221 break;
3222 }
3224
3225 if (!has_transporter) {
3226 /* Reason: no other unit can transport this unit. */
3227 return FALSE;
3228 }
3229 }
3230 break;
3231
3233 if (!ignore_third_party) {
3234 bool has_target = FALSE;
3236
3237 /* Use cache when it has been initialized */
3238 if (pclass->cache.native_bases != NULL) {
3239 /* Extra being native one is a hard requirement */
3240 extra_type_list_iterate(pclass->cache.native_bases, pextra) {
3241 if (!territory_claiming_base(pextra->data.base)) {
3242 /* Hard requirement */
3243 continue;
3244 }
3245
3246 has_target = TRUE;
3247 break;
3249 } else {
3251
3253 if (!is_native_extra_to_uclass(pextra, pclass)) {
3254 /* Hard requirement */
3255 continue;
3256 }
3257
3258 has_target = TRUE;
3259 break;
3261 }
3262
3263 if (!has_target) {
3264 /* Reason: no extras can be conquered by this unit. */
3265 return FALSE;
3266 }
3267 }
3268 break;
3269
3270 case ACTRES_PARADROP:
3272 if (actor_unittype->paratroopers_range <= 0) {
3273 /* Reason: Can't paradrop 0 tiles. */
3274 return FALSE;
3275 }
3276 break;
3277
3278 case ACTRES_HUT_ENTER:
3282 case ACTRES_SPY_POISON:
3291 case ACTRES_SPY_ESCAPE:
3292 case ACTRES_TRADE_ROUTE:
3293 case ACTRES_MARKETPLACE:
3294 case ACTRES_HELP_WONDER:
3298 case ACTRES_FOUND_CITY:
3299 case ACTRES_STEAL_MAPS:
3300 case ACTRES_SPY_NUKE:
3301 case ACTRES_NUKE:
3302 case ACTRES_NUKE_UNITS:
3304 case ACTRES_EXPEL_UNIT:
3307 case ACTRES_HOME_CITY:
3308 case ACTRES_HOMELESS:
3309 case ACTRES_AIRLIFT:
3313 case ACTRES_HEAL_UNIT:
3314 case ACTRES_PILLAGE:
3315 case ACTRES_CLEAN:
3316 case ACTRES_FORTIFY:
3318 case ACTRES_CULTIVATE:
3319 case ACTRES_PLANT:
3320 case ACTRES_ROAD:
3321 case ACTRES_BASE:
3322 case ACTRES_MINE:
3323 case ACTRES_IRRIGATE:
3324 case ACTRES_SPY_ATTACK:
3325 case ACTRES_UNIT_MOVE:
3326 case ACTRES_TELEPORT:
3329 case ACTRES_NONE:
3330 /* No hard unit type requirements. */
3331 break;
3332
3334 }
3335
3336 return TRUE;
3337}
3338
3339/**********************************************************************/
3355bool
3362
3363/**********************************************************************/
3375static enum fc_tristate
3377 const struct action *paction,
3378 const struct req_context *actor,
3379 const bool omniscient,
3380 const struct city *homecity)
3381{
3382 enum action_result result = paction->result;
3383
3384 if (actor == NULL) {
3386 }
3387
3389 TRUE)) {
3390 /* Info leak: The actor player knows the type of their unit. */
3391 /* The actor unit type can't perform the action because of hard
3392 * unit type requirements. */
3393 return TRI_NO;
3394 }
3395
3396 switch (result) {
3397 case ACTRES_PARADROP:
3399 /* Reason: Keep the old rules. */
3400 /* Info leak: The player knows if their unit already has paradropped this
3401 * turn. */
3402 if (actor->unit->paradropped) {
3403 return TRI_NO;
3404 }
3405
3406 break;
3407
3408 case ACTRES_AIRLIFT:
3409 {
3410 /* Obligatory hard requirement. Checked here too since
3411 * action_hard_reqs_actor() may be called before any
3412 * action enablers are checked. */
3413 if (actor->city == NULL) {
3414 /* No city to airlift from. */
3415 return TRI_NO;
3416 }
3417
3418 if (actor->player != city_owner(actor->city)
3420 && pplayers_allied(actor->player,
3421 city_owner(actor->city)))) {
3422 /* Not allowed to airlift from this source. */
3423 return TRI_NO;
3424 }
3425
3426 if (!(omniscient || city_owner(actor->city) == actor->player)) {
3427 /* Can't check for airlifting capacity. */
3428 return TRI_MAYBE;
3429 }
3430
3431 if (0 >= actor->city->airlift
3434 /* The source cannot airlift for this turn (maybe already airlifted
3435 * or no airport).
3436 *
3437 * See also do_airline() in server/unittools.h. */
3438 return TRI_NO;
3439 }
3440 }
3441 break;
3442
3443 case ACTRES_CONVERT:
3444 /* Reason: Keep the old rules. */
3445 /* Info leak: The player knows their unit's cargo and location. */
3446 if (!unit_can_convert(nmap, actor->unit)) {
3447 return TRI_NO;
3448 }
3449 break;
3450
3453 if (unit_transported(actor->unit)) {
3454 if (!can_unit_unload(actor->unit, unit_transport_get(actor->unit))) {
3455 /* Can't leave current transport. */
3456 return TRI_NO;
3457 }
3458 }
3459 break;
3460
3462 if (!can_unit_unload(actor->unit, unit_transport_get(actor->unit))) {
3463 /* Keep the old rules about Unreachable and disembarks. */
3464 return TRI_NO;
3465 }
3466 break;
3467
3468 case ACTRES_HOMELESS:
3469 case ACTRES_UNIT_MOVE:
3470 case ACTRES_TELEPORT:
3474 case ACTRES_SPY_POISON:
3483 case ACTRES_SPY_ESCAPE:
3484 case ACTRES_TRADE_ROUTE:
3485 case ACTRES_MARKETPLACE:
3486 case ACTRES_HELP_WONDER:
3490 case ACTRES_FOUND_CITY:
3491 case ACTRES_JOIN_CITY:
3492 case ACTRES_STEAL_MAPS:
3493 case ACTRES_BOMBARD:
3494 case ACTRES_SPY_NUKE:
3495 case ACTRES_NUKE:
3496 case ACTRES_NUKE_UNITS:
3498 case ACTRES_EXPEL_UNIT:
3501 case ACTRES_HOME_CITY:
3503 case ACTRES_ATTACK:
3504 case ACTRES_WIPE_UNITS:
3510 case ACTRES_HEAL_UNIT:
3512 case ACTRES_CULTIVATE:
3513 case ACTRES_PLANT:
3514 case ACTRES_PILLAGE:
3515 case ACTRES_CLEAN:
3516 case ACTRES_FORTIFY:
3517 case ACTRES_ROAD:
3518 case ACTRES_BASE:
3519 case ACTRES_MINE:
3520 case ACTRES_IRRIGATE:
3524 case ACTRES_SPY_ATTACK:
3525 case ACTRES_HUT_ENTER:
3528 case ACTRES_NONE:
3529 /* No hard unit requirements. */
3530 break;
3531
3533 }
3534
3535 return TRI_YES;
3536}
3537
3538/**********************************************************************/
3561static enum fc_tristate
3564 const struct req_context *actor,
3565 const struct req_context *target,
3566 const struct extra_type *target_extra,
3567 const bool omniscient,
3568 const struct city *homecity)
3569{
3570 enum fc_tristate out;
3573
3574 if (actor == NULL) {
3576 }
3577 if (target == NULL) {
3578 target = req_context_empty();
3579 }
3580
3581 fc_assert_msg((tkind == ATK_CITY && target->city != NULL)
3582 || (tkind == ATK_TILE && target->tile != NULL)
3583 || (tkind == ATK_EXTRAS && target->tile != NULL)
3584 || (tkind == ATK_UNIT && target->unit != NULL)
3585 /* At this level each individual unit is tested. */
3586 || (tkind == ATK_UNITS && target->unit != NULL)
3587 || (tkind == ATK_SELF),
3588 "Missing target!");
3589
3590 /* Info leak: The player knows where their unit is. */
3591 if (tkind != ATK_SELF
3594 target->tile))) {
3595 /* The distance between the actor and the target isn't inside the
3596 * action's accepted range. */
3597 return TRI_NO;
3598 }
3599
3600 switch (tkind) {
3601 case ATK_UNIT:
3602 /* The Freeciv code for all actions that is controlled by action
3603 * enablers and targets a unit assumes that the acting
3604 * player can see the target unit.
3605 * Examples:
3606 * - action_prob_vs_unit()'s quick check that the distance between actor
3607 * and target is acceptable would leak distance to target unit if the
3608 * target unit can't be seen.
3609 */
3610 if (!can_player_see_unit(actor->player, target->unit)) {
3611 return TRI_NO;
3612 }
3613 break;
3614 case ATK_CITY:
3615 /* The Freeciv code assumes that the player is aware of the target
3616 * city's existence. (How can you order an airlift to a city when you
3617 * don't know its city ID?) */
3619 actor->player)
3620 != target->city->id) {
3621 return TRI_NO;
3622 }
3623 break;
3624 case ATK_UNITS:
3625 case ATK_TILE:
3626 case ATK_EXTRAS:
3627 case ATK_SELF:
3628 /* No special player knowledge checks. */
3629 break;
3630 case ATK_COUNT:
3632 break;
3633 }
3634
3636 target->tile, target->city, target->unit)) {
3637 /* Allows an action to block an other action. If a blocking action is
3638 * legal the actions it blocks becomes illegal. */
3639 return TRI_NO;
3640 }
3641
3642 /* Actor specific hard requirements. */
3643 out = action_hard_reqs_actor(nmap, paction, actor, omniscient, homecity);
3644
3645 if (out == TRI_NO) {
3646 /* Illegal because of a hard actor requirement. */
3647 return TRI_NO;
3648 }
3649
3650 /* Quick checks for action itself */
3651 if (paction->result == ACTRES_ATTACK
3652 || paction->result == ACTRES_WIPE_UNITS
3653 || paction->result == ACTRES_COLLECT_RANSOM) {
3654 /* Reason: Keep the old rules. */
3655 if (!can_unit_attack_tile(actor->unit, paction, target->tile)) {
3656 return TRI_NO;
3657 }
3658 }
3659
3660 /* Hard requirements for results. */
3662 paction->result, actor,
3663 target, target_extra, out, omniscient,
3664 homecity);
3665
3666 if (out == TRI_NO) {
3667 /* Illegal because of a hard actor requirement. */
3668 return TRI_NO;
3669 }
3670
3671 if (paction->result == ACTRES_NUKE_UNITS) {
3673 target->tile)
3674 != ATT_OK) {
3675 /* Unreachable. */
3676 return TRI_NO;
3677 }
3678 } else if (paction->result == ACTRES_PARADROP
3679 || paction->result == ACTRES_PARADROP_CONQUER) {
3680 if (can_player_see_tile(actor->player, target->tile)) {
3681 /* Check for seen stuff that may kill the actor unit. */
3682
3683 /* Reason: Keep the old rules. Be merciful. */
3684 /* Info leak: The player sees the target tile. */
3685 if (!can_unit_exist_at_tile(nmap, actor->unit, target->tile)
3686 && (!BV_ISSET(paction->sub_results, ACT_SUB_RES_MAY_EMBARK)
3687 || !unit_could_load_at(actor->unit, target->tile))) {
3688 return TRI_NO;
3689 }
3690
3691 /* Reason: Keep the old rules. Be merciful. */
3692 /* Info leak: The player sees the target tile. */
3693 if (is_non_attack_city_tile(target->tile, actor->player)) {
3694 return TRI_NO;
3695 }
3696
3697 /* Reason: Be merciful. */
3698 /* Info leak: The player sees all units checked. Invisible units are
3699 * ignored. */
3700 unit_list_iterate(target->tile->units, pother) {
3701 if (can_player_see_unit(actor->player, pother)
3702 && !pplayers_allied(actor->player, unit_owner(pother))) {
3703 return TRI_NO;
3704 }
3706 }
3707 }
3708
3709 return out;
3710}
3711
3712/**********************************************************************/
3718static bool is_enabler_active(const struct action_enabler *enabler,
3719 const struct req_context *actor,
3720 const struct req_context *target)
3721{
3722 return are_reqs_active(actor, target != NULL ? target->player : NULL,
3723 &enabler->actor_reqs, RPT_CERTAIN)
3724 && are_reqs_active(target, actor != NULL ? actor->player : NULL,
3725 &enabler->target_reqs, RPT_CERTAIN);
3726}
3727
3728/**********************************************************************/
3737static bool is_action_enabled(const struct civ_map *nmap,
3739 const struct req_context *actor,
3740 const struct req_context *target,
3741 const struct extra_type *target_extra,
3742 const struct city *actor_home)
3743{
3744 enum fc_tristate possible;
3745
3747 TRUE, actor_home);
3748
3749 if (possible != TRI_YES) {
3750 /* This context is omniscient. Should be yes or no. */
3752 "Is omniscient, should get yes or no.");
3753
3754 /* The action enablers are irrelevant since the action it self is
3755 * impossible. */
3756 return FALSE;
3757 }
3758
3760 enabler) {
3761 if (is_enabler_active(enabler, actor, target)) {
3762 return TRUE;
3763 }
3765
3766 return FALSE;
3767}
3768
3769/**********************************************************************/
3775static bool
3778 const struct unit *actor_unit,
3779 const struct city *actor_home,
3780 const struct tile *actor_tile,
3781 const struct city *target_city)
3782{
3783 const struct impr_type *target_building;
3784 const struct unit_type *target_utype;
3785
3786 if (actor_unit == NULL || target_city == NULL) {
3787 /* Can't do an action when actor or target are missing. */
3788 return FALSE;
3789 }
3790
3792 FALSE, "Action %s is performed by %s not %s",
3797
3800 FALSE, "Action %s is against %s not %s",
3805
3807
3809 /* No point in continuing. */
3810 return FALSE;
3811 }
3812
3815
3817 &(const struct req_context) {
3818 .player = unit_owner(actor_unit),
3819 .city = tile_city(actor_tile),
3820 .tile = actor_tile,
3821 .unit = actor_unit,
3822 .unittype = unit_type_get(actor_unit),
3823 },
3824 &(const struct req_context) {
3825 .player = city_owner(target_city),
3826 .city = target_city,
3827 .building = target_building,
3829 .unittype = target_utype,
3830 },
3831 NULL,
3832 actor_home);
3833}
3834
3835/**********************************************************************/
3851
3852/**********************************************************************/
3858static bool
3861 const struct unit *actor_unit,
3862 const struct city *actor_home,
3863 const struct tile *actor_tile,
3864 const struct unit *target_unit)
3865{
3866 if (actor_unit == NULL || target_unit == NULL) {
3867 /* Can't do an action when actor or target are missing. */
3868 return FALSE;
3869 }
3870
3872 FALSE, "Action %s is performed by %s not %s",
3877
3880 FALSE, "Action %s is against %s not %s",
3885
3887
3889 /* No point in continuing. */
3890 return FALSE;
3891 }
3892
3894 &(const struct req_context) {
3895 .player = unit_owner(actor_unit),
3896 .city = tile_city(actor_tile),
3897 .tile = actor_tile,
3898 .unit = actor_unit,
3899 .unittype = unit_type_get(actor_unit),
3900 },
3901 &(const struct req_context) {
3902 .player = unit_owner(target_unit),
3905 .unit = target_unit,
3906 .unittype = unit_type_get(target_unit),
3907 },
3908 NULL,
3909 actor_home);
3910}
3911
3912/**********************************************************************/
3928
3929/**********************************************************************/
3935static bool
3938 const struct unit *actor_unit,
3939 const struct city *actor_home,
3940 const struct tile *actor_tile,
3941 const struct tile *target_tile)
3942{
3943 const struct req_context *actor_ctxt;
3944
3945 if (actor_unit == NULL || target_tile == NULL
3946 || unit_list_size(target_tile->units) == 0) {
3947 /* Can't do an action when actor or target are missing. */
3948 return FALSE;
3949 }
3950
3952 FALSE, "Action %s is performed by %s not %s",
3957
3960 FALSE, "Action %s is against %s not %s",
3965
3967
3969 /* No point in continuing. */
3970 return FALSE;
3971 }
3972
3973 actor_ctxt = &(const struct req_context) {
3974 .player = unit_owner(actor_unit),
3975 .city = tile_city(actor_tile),
3976 .tile = actor_tile,
3977 .unit = actor_unit,
3978 .unittype = unit_type_get(actor_unit),
3979 };
3980
3983 &(const struct req_context) {
3984 .player = unit_owner(target_unit),
3987 .unit = target_unit,
3988 .unittype = unit_type_get(target_unit),
3989 },
3990 NULL, actor_home)) {
3991 /* One unit makes it impossible for all units. */
3992 return FALSE;
3993 }
3995
3996 /* Not impossible for any of the units at the tile. */
3997 return TRUE;
3998}
3999
4000/**********************************************************************/
4016
4017/**********************************************************************/
4023static bool
4026 const struct unit *actor_unit,
4027 const struct city *actor_home,
4028 const struct tile *actor_tile,
4029 const struct tile *target_tile,
4030 const struct extra_type *target_extra)
4031{
4032 if (actor_unit == NULL || target_tile == NULL) {
4033 /* Can't do an action when actor or target are missing. */
4034 return FALSE;
4035 }
4036
4038 FALSE, "Action %s is performed by %s not %s",
4043
4046 FALSE, "Action %s is against %s not %s",
4051
4053
4055 /* No point in continuing. */
4056 return FALSE;
4057 }
4058
4060 &(const struct req_context) {
4061 .player = unit_owner(actor_unit),
4062 .city = tile_city(actor_tile),
4063 .tile = actor_tile,
4064 .unit = actor_unit,
4065 .unittype = unit_type_get(actor_unit),
4066 },
4067 &(const struct req_context) {
4068 .player = tile_owner(target_tile),
4069 .city = tile_city(target_tile),
4070 .tile = target_tile,
4071 },
4073 actor_home);
4074}
4075
4076/**********************************************************************/
4084 const struct unit *actor_unit,
4085 const struct tile *target_tile,
4086 const struct extra_type *target_extra)
4087{
4092}
4093
4094/**********************************************************************/
4100static bool
4103 const struct unit *actor_unit,
4104 const struct city *actor_home,
4105 const struct tile *actor_tile,
4106 const struct tile *target_tile,
4107 const struct extra_type *target_extra)
4108{
4109 if (actor_unit == NULL || target_tile == NULL) {
4110 /* Can't do an action when actor or target are missing. */
4111 return FALSE;
4112 }
4113
4115 FALSE, "Action %s is performed by %s not %s",
4120
4123 FALSE, "Action %s is against %s not %s",
4128
4130
4132 /* No point in continuing. */
4133 return FALSE;
4134 }
4135
4137 &(const struct req_context) {
4138 .player = unit_owner(actor_unit),
4139 .city = tile_city(actor_tile),
4140 .tile = actor_tile,
4141 .unit = actor_unit,
4142 .unittype = unit_type_get(actor_unit),
4143 },
4144 &(const struct req_context) {
4145 .player = target_tile->extras_owner,
4146 .city = tile_city(target_tile),
4147 .tile = target_tile,
4148 },
4150 actor_home);
4151}
4152
4153/**********************************************************************/
4170
4171/**********************************************************************/
4178static bool
4181 const struct unit *actor_unit,
4182 const struct city *actor_home,
4183 const struct tile *actor_tile)
4184{
4185 if (actor_unit == NULL) {
4186 /* Can't do an action when the actor is missing. */
4187 return FALSE;
4188 }
4189
4191 FALSE, "Action %s is performed by %s not %s",
4196
4199 FALSE, "Action %s is against %s not %s",
4204
4206
4208 /* No point in continuing. */
4209 return FALSE;
4210 }
4211
4213 &(const struct req_context) {
4214 .player = unit_owner(actor_unit),
4215 .city = tile_city(actor_tile),
4216 .tile = actor_tile,
4217 .unit = actor_unit,
4218 .unittype = unit_type_get(actor_unit),
4219 },
4220 NULL, NULL,
4221 actor_home);
4222}
4223
4224/**********************************************************************/
4239
4240/**********************************************************************/
4258static enum fc_tristate
4260 const struct req_context *actor,
4261 const struct req_context *target)
4262{
4263 enum fc_tristate current;
4264 enum fc_tristate result;
4265
4266 if (actor == NULL || actor->player == NULL) {
4267 /* Need actor->player for point of view */
4268 return TRI_MAYBE;
4269 }
4270
4271 if (target == NULL) {
4272 target = req_context_empty();
4273 }
4274
4275 result = TRI_NO;
4277 enabler) {
4278 current = fc_tristate_and(mke_eval_reqs(actor->player, actor,
4279 target->player,
4280 &enabler->actor_reqs,
4281 RPT_CERTAIN),
4282 mke_eval_reqs(actor->player, target,
4283 actor->player,
4284 &enabler->target_reqs,
4285 RPT_CERTAIN));
4286 if (current == TRI_YES) {
4287 return TRI_YES;
4288 } else if (current == TRI_MAYBE) {
4289 result = TRI_MAYBE;
4290 }
4292
4293 return result;
4294}
4295
4296/**********************************************************************/
4305static bool is_effect_val_known(enum effect_type effect_type,
4306 const struct player *pov_player,
4307 const struct req_context *context,
4308 const struct player *other_player)
4309{
4310 effect_list_iterate(get_effects(effect_type), peffect) {
4312 other_player,
4313 &(peffect->reqs), RPT_CERTAIN)) {
4314 return FALSE;
4315 }
4317
4318 return TRUE;
4319}
4320
4321/**********************************************************************/
4324static enum fc_tristate
4352
4353/**********************************************************************/
4362 const struct unit *pdefender)
4363{
4364 /* Keep unconverted until the end to avoid scaling each step */
4365 int chance;
4366 struct act_prob out;
4367
4368 /* Superspy always win */
4370 /* A defending UTYF_SUPERSPY will defeat every possible attacker. */
4371 return ACTPROB_IMPOSSIBLE;
4372 }
4374 /* An attacking UTYF_SUPERSPY will defeat every possible defender
4375 * except another UTYF_SUPERSPY. */
4376 return ACTPROB_CERTAIN;
4377 }
4378
4379 /* Base chance is 50% */
4380 chance = 50;
4381
4382 /* Spy attack bonus */
4384 chance += 25;
4385 }
4386
4387 /* Spy defense bonus */
4389 chance -= 25;
4390 }
4391
4392 /* Veteran attack and defense bonus */
4393 {
4394 const struct veteran_level *vatt
4396 const struct veteran_level *vdef
4398
4399 chance += vatt->power_fact - vdef->power_fact;
4400 }
4401
4402 /* Defense bonus. */
4403 {
4404 const struct req_context defender_ctxt = {
4405 .player = tile_owner(pdefender->tile),
4406 .city = tile_city(pdefender->tile),
4407 .tile = pdefender->tile,
4408 };
4411 NULL)) {
4412 return ACTPROB_NOT_KNOWN;
4413 }
4414
4415 /* Reduce the chance of an attack by EFT_SPY_RESISTANT percent. */
4417 NULL,
4419 NULL,
4421 ) / 100;
4422 }
4423
4424 chance = CLIP(0, chance, 100);
4425
4426 /* Convert to action probability */
4429
4430 return out;
4431}
4432
4433/**********************************************************************/
4439 const struct unit *pvictim,
4440 const struct tile *tgt_tile,
4441 const struct action *paction)
4442{
4443 struct unit *pdefender;
4444
4446 tgt_tile)) {
4447 /* Don't leak information about unseen defenders. */
4448 return ACTPROB_NOT_KNOWN;
4449 }
4450
4452 paction);
4453
4454 if (pdefender) {
4455 /* There will be a diplomatic battle instead of an action. */
4457 };
4458
4459 /* No diplomatic battle will occur. */
4460 return ACTPROB_CERTAIN;
4461}
4462
4463/**********************************************************************/
4467 action_id act_id,
4468 const struct unit *actor_unit)
4469{
4471 /* Unknown because the target is unseen. */
4472 return ACTPROB_NOT_KNOWN;
4473 } else {
4474 /* The actor it self can't do this. */
4475 return ACTPROB_IMPOSSIBLE;
4476 }
4477}
4478
4479/**********************************************************************/
4483static struct act_prob
4485 const struct unit *act_unit,
4486 const struct city *tgt_city,
4487 const struct player *tgt_player,
4488 const struct action *paction)
4489{
4491 &(const struct req_context) {
4492 .player = act_player,
4493 .city = tgt_city,
4494 .unit = act_unit,
4495 .unittype = unit_type_get(act_unit),
4496 },
4497 tgt_player)
4499 &(const struct req_context) {
4500 .player = tgt_player,
4501 .city = tgt_city,
4502 .unit = act_unit,
4503 },
4504 act_player)) {
4507 struct act_prob result = { .min = unconverted * ACTPROB_VAL_1_PCT,
4508 .max = unconverted * ACTPROB_VAL_1_PCT };
4509
4510 return result;
4511 } else {
4512 /* Could be improved to return a more exact probability in some cases.
4513 * Example: The player has enough information to know that the
4514 * probability always will be above 25% and always under 75% because
4515 * the only effect with unknown requirements that may apply adds (or
4516 * subtracts) 50% while all the requirements of the other effects that
4517 * may apply are known. */
4518 return ACTPROB_NOT_KNOWN;
4519 }
4520}
4521
4522/**********************************************************************/
4527static struct act_prob
4529 const struct unit *act_unit,
4530 const struct city *tgt_city,
4531 const struct unit *tgt_unit,
4532 const struct tile *tgt_tile,
4533 const struct player *tgt_player,
4534 const struct action *paction)
4535{
4536 struct act_prob battle;
4537 struct act_prob dice_roll;
4538
4539 battle = ACTPROB_CERTAIN;
4540 switch (actres_get_battle_kind(paction->result)) {
4541 case ABK_NONE:
4542 /* No pre action battle. */
4543 break;
4544 case ABK_DIPLOMATIC:
4546 paction);
4547 break;
4548 case ABK_STANDARD:
4549 /* Not supported here yet. Implement when users appear. */
4551 break;
4552 case ABK_COUNT:
4554 break;
4555 }
4556
4559 paction);
4560
4561 return action_prob_and(&battle, &dice_roll);
4562}
4563
4564/**********************************************************************/
4575static struct act_prob
4578 const struct req_context *actor,
4579 const struct city *actor_home,
4580 const struct req_context *target,
4581 const struct extra_type *target_extra)
4582{
4583 enum fc_tristate known;
4584 struct act_prob chance;
4586
4587 if (actor == NULL) {
4589 }
4590 if (target == NULL) {
4591 target = req_context_empty();
4592 }
4593
4594 known = is_action_possible(nmap, wanted_action, actor, target,
4596 FALSE, actor_home);
4597
4598 if (known == TRI_NO) {
4599 /* The action enablers are irrelevant since the action it self is
4600 * impossible. */
4601 return ACTPROB_IMPOSSIBLE;
4602 }
4603
4605
4606 known = fc_tristate_and(known,
4608 actor, target));
4609
4610 switch (paction->result) {
4611 case ACTRES_SPY_POISON:
4612 /* All uncertainty comes from potential diplomatic battles and the
4613 * (diplchance server setting and the) Action_Odds_Pct effect controlled
4614 * dice roll before the action. */
4616 target->city, target->unit,
4617 target->tile, target->player,
4618 paction);
4619 break;
4621 /* TODO */
4622 break;
4624 /* TODO */
4625 break;
4626 case ACTRES_STEAL_MAPS:
4627 /* TODO */
4628 break;
4630 /* All uncertainty comes from potential diplomatic battles. */
4631 chance = ap_diplomat_battle(actor->unit, target->unit, target->tile,
4632 paction);
4633 break;
4635 /* All uncertainty comes from potential diplomatic battles. */
4636 chance = ap_diplomat_battle(actor->unit, target->unit, target->tile,
4637 paction);
4638 break;
4639 case ACTRES_SPY_ATTACK:
4640 /* All uncertainty comes from potential diplomatic battles. */
4641 chance = ap_diplomat_battle(actor->unit, NULL, target->tile,
4642 paction);
4643 break;
4645 /* TODO */
4646 break;
4648 /* TODO */
4649 break;
4651 /* TODO */
4652 break;
4654 /* TODO */
4655 break;
4658 break;
4660 /* Do the victim have anything worth taking? */
4661 known = fc_tristate_and(known,
4662 tech_can_be_stolen(actor->player,
4663 target->player));
4664
4665 /* TODO: Calculate actual chance */
4666
4667 break;
4669 /* Do the victim have anything worth taking? */
4670 known = fc_tristate_and(known,
4671 tech_can_be_stolen(actor->player,
4672 target->player));
4673
4674 /* TODO: Calculate actual chance */
4675
4676 break;
4678 /* There is no risk that the city won't get investigated. */
4680 break;
4681 case ACTRES_SPY_ESCAPE:
4682 /* TODO */
4683 break;
4684 case ACTRES_TRADE_ROUTE:
4685 /* TODO */
4686 break;
4687 case ACTRES_MARKETPLACE:
4688 /* Possible when not blocked by is_action_possible() */
4690 break;
4691 case ACTRES_HELP_WONDER:
4692 /* Possible when not blocked by is_action_possible() */
4694 break;
4696 /* No battle is fought first. */
4698 break;
4699 case ACTRES_EXPEL_UNIT:
4700 /* No battle is fought first. */
4702 break;
4703 case ACTRES_BOMBARD:
4704 /* No battle is fought first. */
4706 break;
4707 case ACTRES_FOUND_CITY:
4708 /* Possible when not blocked by is_action_possible() */
4710 break;
4711 case ACTRES_JOIN_CITY:
4712 /* Possible when not blocked by is_action_possible() */
4714 break;
4715 case ACTRES_SPY_NUKE:
4716 /* All uncertainty comes from potential diplomatic battles and the
4717 * (diplchance server setting and the) Action_Odds_Pct effect controlled
4718 * dice roll before the action. */
4720 target->city, target->unit,
4721 target->tile,
4722 target->player,
4723 paction);
4724 break;
4725 case ACTRES_NUKE:
4726 /* TODO */
4727 break;
4728 case ACTRES_NUKE_UNITS:
4729 /* TODO */
4730 break;
4732 /* No battle is fought first. */
4734 break;
4736 /* No battle is fought first. */
4738 break;
4740 /* No battle is fought first. */
4742 break;
4743 case ACTRES_HOME_CITY:
4744 /* No battle is fought first. */
4746 break;
4747 case ACTRES_HOMELESS:
4748 /* No battle is fought first. */
4750 break;
4752 /* No battle is fought first. */
4754 break;
4755 case ACTRES_PARADROP:
4757 /* TODO */
4758 break;
4759 case ACTRES_AIRLIFT:
4760 /* Possible when not blocked by is_action_possible() */
4762 break;
4763 case ACTRES_ATTACK:
4765 {
4766 struct unit *defender_unit = get_defender(nmap, actor->unit,
4767 target->tile, paction);
4768
4769 if (can_player_see_unit(actor->player, defender_unit)) {
4770 double unconverted = unit_win_chance(nmap, actor->unit,
4772
4774 floor((double)ACTPROB_VAL_MAX * unconverted));
4776 ceil((double)ACTPROB_VAL_MAX * unconverted));
4777 } else if (known == TRI_YES) {
4778 known = TRI_MAYBE;
4779 }
4780 }
4781 break;
4782 case ACTRES_WIPE_UNITS:
4784 break;
4786 /* TODO: not implemented yet because:
4787 * - dice roll 100% * Action_Odds_Pct could be handled with
4788 * action_prob_pre_action_dice_roll().
4789 * - sub target building may be missing. May be missing without player
4790 * knowledge if it isn't visible. See is_improvement_visible() and
4791 * can_player_see_city_internals(). */
4792 break;
4794 /* All uncertainty comes from the (diplchance server setting and the)
4795 * Action_Odds_Pct effect controlled dice roll before the action. */
4797 target->city, target->player,
4798 paction);
4799 break;
4801 /* No battle is fought first. */
4803 break;
4805 /* No battle is fought first. */
4807 break;
4808 case ACTRES_HEAL_UNIT:
4809 /* No battle is fought first. */
4811 break;
4813 case ACTRES_CULTIVATE:
4814 case ACTRES_PLANT:
4815 case ACTRES_PILLAGE:
4816 case ACTRES_CLEAN:
4817 case ACTRES_FORTIFY:
4818 case ACTRES_ROAD:
4819 case ACTRES_CONVERT:
4820 case ACTRES_BASE:
4821 case ACTRES_MINE:
4822 case ACTRES_IRRIGATE:
4824 break;
4827 break;
4830 break;
4833 break;
4836 break;
4839 break;
4842 break;
4843 case ACTRES_HUT_ENTER:
4845 /* Entering the hut happens with a probability of 100%. What happens
4846 * next is probably up to dice rolls in Lua. */
4848 break;
4849 case ACTRES_UNIT_MOVE:
4850 case ACTRES_TELEPORT:
4853 break;
4854 /* Not UI action, so chance is meaningless */
4857 break;
4858 case ACTRES_NONE:
4859 /* Accommodate ruleset authors that wishes to roll the dice in Lua.
4860 * Would be ACTPROB_CERTAIN if not for that. */
4861 /* TODO: maybe allow the ruleset author to give a probability from
4862 * Lua? */
4864 break;
4865 }
4866
4867 /* Non signal action probabilities should be in range. */
4869 || chance.max <= ACTPROB_VAL_MAX),
4870 chance.max = ACTPROB_VAL_MAX);
4872 || chance.min >= ACTPROB_VAL_MIN),
4873 chance.min = ACTPROB_VAL_MIN);
4874
4875 switch (known) {
4876 case TRI_NO:
4877 return ACTPROB_IMPOSSIBLE;
4878 break;
4879 case TRI_MAYBE:
4880 return ACTPROB_NOT_KNOWN;
4881 break;
4882 case TRI_YES:
4883 return chance;
4884 break;
4885 };
4886
4887 fc_assert_msg(FALSE, "Should be yes, maybe or no");
4888
4890}
4891
4892/**********************************************************************/
4896static struct act_prob
4898 const struct unit *actor_unit,
4899 const struct city *actor_home,
4900 const struct tile *actor_tile,
4901 const action_id act_id,
4902 const struct city *target_city)
4903{
4904 const struct impr_type *target_building;
4905 const struct unit_type *target_utype;
4906 const struct action *act = action_by_number(act_id);
4907
4908 if (actor_unit == NULL || target_city == NULL) {
4909 /* Can't do an action when actor or target are missing. */
4910 return ACTPROB_IMPOSSIBLE;
4911 }
4912
4915 "Action %s is performed by %s not %s",
4916 action_id_rule_name(act_id),
4918 action_id_get_actor_kind(act_id)),
4920
4923 "Action %s is against %s not %s",
4924 action_id_rule_name(act_id),
4928
4930
4931 if (!unit_can_do_action(actor_unit, act_id)) {
4932 /* No point in continuing. */
4933 return ACTPROB_IMPOSSIBLE;
4934 }
4935
4936 /* Doesn't leak information about city position since an unknown city
4937 * can't be targeted and a city can't move. */
4938 if (!action_id_distance_accepted(act_id,
4941 /* No point in continuing. */
4942 return ACTPROB_IMPOSSIBLE;
4943 }
4944
4945 /* Doesn't leak information since it must be 100% certain from the
4946 * player's perspective that the blocking action is legal. */
4949 /* Don't offer to perform an action known to be blocked. */
4950 return ACTPROB_IMPOSSIBLE;
4951 }
4952
4954 /* The invisible city at this tile may, as far as the player knows, not
4955 * exist anymore. */
4956 return act_prob_unseen_target(nmap, act_id, actor_unit);
4957 }
4958
4961
4962 return action_prob(nmap, act_id,
4963 &(const struct req_context) {
4964 .player = unit_owner(actor_unit),
4965 .city = tile_city(actor_tile),
4966 .tile = actor_tile,
4967 .unit = actor_unit,
4968 .unittype = unit_type_get(actor_unit),
4969 },
4970 actor_home,
4971 &(const struct req_context) {
4972 .player = city_owner(target_city),
4973 .city = target_city,
4974 .building = target_building,
4976 .unittype = target_utype,
4977 }, NULL);
4978}
4979
4980/**********************************************************************/
4985 const struct unit *actor_unit,
4986 const action_id act_id,
4987 const struct city *target_city)
4988{
4992 act_id, target_city);
4993}
4994
4995/**********************************************************************/
4999static struct act_prob
5001 const struct unit *actor_unit,
5002 const struct city *actor_home,
5003 const struct tile *actor_tile,
5004 const action_id act_id,
5005 const struct unit *target_unit)
5006{
5007 if (actor_unit == NULL || target_unit == NULL) {
5008 /* Can't do an action when actor or target are missing. */
5009 return ACTPROB_IMPOSSIBLE;
5010 }
5011
5014 "Action %s is performed by %s not %s",
5015 action_id_rule_name(act_id),
5017 action_id_get_actor_kind(act_id)),
5019
5022 "Action %s is against %s not %s",
5023 action_id_rule_name(act_id),
5027
5029
5030 if (!unit_can_do_action(actor_unit, act_id)) {
5031 /* No point in continuing. */
5032 return ACTPROB_IMPOSSIBLE;
5033 }
5034
5035 /* Doesn't leak information about unit position since an unseen unit can't
5036 * be targeted. */
5037 if (!action_id_distance_accepted(act_id,
5040 /* No point in continuing. */
5041 return ACTPROB_IMPOSSIBLE;
5042 }
5043
5044 return action_prob(nmap, act_id,
5045 &(const struct req_context) {
5046 .player = unit_owner(actor_unit),
5047 .city = tile_city(actor_tile),
5048 .tile = actor_tile,
5049 .unit = actor_unit,
5050 .unittype = unit_type_get(actor_unit),
5051 },
5052 actor_home,
5053 &(const struct req_context) {
5054 .player = unit_owner(target_unit),
5057 .unit = target_unit,
5058 .unittype = unit_type_get(target_unit),
5059 },
5060 NULL);
5061}
5062
5063/**********************************************************************/
5068 const struct unit *actor_unit,
5069 const action_id act_id,
5070 const struct unit *target_unit)
5071{
5075 act_id,
5076 target_unit);
5077}
5078
5079/**********************************************************************/
5083static struct act_prob
5085 const struct unit *actor_unit,
5086 const struct city *actor_home,
5087 const struct tile *actor_tile,
5088 const action_id act_id,
5089 const struct tile *target_tile)
5090{
5091 struct act_prob prob_all;
5092 const struct req_context *actor_ctxt;
5093 const struct action *act = action_by_number(act_id);
5094
5095 if (actor_unit == NULL || target_tile == NULL) {
5096 /* Can't do an action when actor or target are missing. */
5097 return ACTPROB_IMPOSSIBLE;
5098 }
5099
5102 "Action %s is performed by %s not %s",
5103 action_id_rule_name(act_id),
5105 action_id_get_actor_kind(act_id)),
5107
5110 "Action %s is against %s not %s",
5111 action_id_rule_name(act_id),
5115
5117
5118 if (!unit_can_do_action(actor_unit, act_id)) {
5119 /* No point in continuing. */
5120 return ACTPROB_IMPOSSIBLE;
5121 }
5122
5123 /* Doesn't leak information about unit stack position since it is
5124 * specified as a tile and an unknown tile's position is known. */
5125 if (!action_id_distance_accepted(act_id,
5127 target_tile))) {
5128 /* No point in continuing. */
5129 return ACTPROB_IMPOSSIBLE;
5130 }
5131
5132 /* Doesn't leak information since the actor player can see the target
5133 * tile. */
5137 act_id,
5138 CITYT_CENTER, TRUE)) {
5139 /* Don't offer to perform actions that never can target a unit stack in
5140 * a city. */
5141 return ACTPROB_IMPOSSIBLE;
5142 }
5143
5144 /* Doesn't leak information since it must be 100% certain from the
5145 * player's perspective that the blocking action is legal. */
5149 target_unit)) {
5150 /* Don't offer to perform an action known to be blocked. */
5151 return ACTPROB_IMPOSSIBLE;
5152 }
5154
5155 /* Must be done here since an empty unseen tile will result in
5156 * ACTPROB_IMPOSSIBLE. */
5157 if (unit_list_size(target_tile->units) == 0) {
5158 /* Can't act against an empty tile. */
5159
5161 target_tile)) {
5162 /* Known empty tile. */
5163 return ACTPROB_IMPOSSIBLE;
5164 } else {
5165 /* The player doesn't know that the tile is empty. */
5166 return act_prob_unseen_target(nmap, act_id, actor_unit);
5167 }
5168 }
5169
5176 /* Hard coded rule: can't "Bombard", "Suicide Attack", or "Attack"
5177 * units in non enemy cities. */
5178 return ACTPROB_IMPOSSIBLE;
5179 }
5180
5187 /* Hard coded rule: can't "Nuke Units", "Wipe Units", "Suicide Attack",
5188 * or "Attack" units on non native tile without "AttackNonNative" and
5189 * not "Only_Native_Attack". */
5190 return ACTPROB_IMPOSSIBLE;
5191 }
5192
5193 /* Invisible units at this tile can make the action legal or illegal.
5194 * Invisible units can be stacked with visible units. The possible
5195 * existence of invisible units therefore makes the result uncertain. */
5199
5200 actor_ctxt = &(const struct req_context) {
5201 .player = unit_owner(actor_unit),
5202 .city = tile_city(actor_tile),
5203 .tile = actor_tile,
5204 .unit = actor_unit,
5205 .unittype = unit_type_get(actor_unit),
5206 };
5207
5209 struct act_prob prob_unit;
5210
5212 /* Only visible units are considered. The invisible units contributed
5213 * their uncertainty to prob_all above. */
5214 continue;
5215 }
5216
5218 &(const struct req_context) {
5219 .player = unit_owner(target_unit),
5222 .unit = target_unit,
5223 .unittype = unit_type_get(target_unit),
5224 },
5225 NULL);
5226
5228 /* One unit makes it impossible for all units. */
5229 return ACTPROB_IMPOSSIBLE;
5230 } else if (action_prob_not_impl(prob_unit)) {
5231 /* Not implemented dominates all except impossible. */
5233 } else {
5235 "Invalid probability [%d, %d]",
5236 prob_unit.min, prob_unit.max);
5237
5239 /* Special values dominate regular values. */
5240 continue;
5241 }
5242
5243 /* Probability against all target units considered until this moment
5244 * and the probability against this target unit. */
5245 prob_all.min = (prob_all.min * prob_unit.min) / ACTPROB_VAL_MAX;
5246 prob_all.max = (prob_all.max * prob_unit.max) / ACTPROB_VAL_MAX;
5247 break;
5248 }
5250
5251 /* Not impossible for any of the units at the tile. */
5252 return prob_all;
5253}
5254
5255/**********************************************************************/
5260 const struct unit *actor_unit,
5261 const action_id act_id,
5262 const struct tile *target_tile)
5263{
5267 act_id,
5268 target_tile);
5269}
5270
5271/**********************************************************************/
5275static struct act_prob
5277 const struct unit *actor_unit,
5278 const struct city *actor_home,
5279 const struct tile *actor_tile,
5280 const action_id act_id,
5281 const struct tile *target_tile,
5282 const struct extra_type *target_extra)
5283{
5284 if (actor_unit == NULL || target_tile == NULL) {
5285 /* Can't do an action when actor or target are missing. */
5286 return ACTPROB_IMPOSSIBLE;
5287 }
5288
5291 "Action %s is performed by %s not %s",
5292 action_id_rule_name(act_id),
5294 action_id_get_actor_kind(act_id)),
5296
5299 "Action %s is against %s not %s",
5300 action_id_rule_name(act_id),
5304
5306
5307 if (!unit_can_do_action(actor_unit, act_id)) {
5308 /* No point in continuing. */
5309 return ACTPROB_IMPOSSIBLE;
5310 }
5311
5312 /* Doesn't leak information about tile position since an unknown tile's
5313 * position is known. */
5314 if (!action_id_distance_accepted(act_id,
5316 target_tile))) {
5317 /* No point in continuing. */
5318 return ACTPROB_IMPOSSIBLE;
5319 }
5320
5321 return action_prob(nmap, act_id,
5322 &(const struct req_context) {
5323 .player = unit_owner(actor_unit),
5324 .city = tile_city(actor_tile),
5325 .tile = actor_tile,
5326 .unit = actor_unit,
5327 .unittype = unit_type_get(actor_unit),
5328 },
5329 actor_home,
5330 &(const struct req_context) {
5331 .player = tile_owner(target_tile),
5332 .city = tile_city(target_tile),
5333 .tile = target_tile,
5334 },
5335 target_extra);
5336}
5337
5338/**********************************************************************/
5343 const struct unit *actor_unit,
5344 const action_id act_id,
5345 const struct tile *target_tile,
5346 const struct extra_type *target_extra)
5347{
5351 act_id, target_tile, target_extra);
5352}
5353
5354/**********************************************************************/
5358static struct act_prob
5360 const struct unit *actor_unit,
5361 const struct city *actor_home,
5362 const struct tile *actor_tile,
5363 const action_id act_id,
5364 const struct tile *target_tile,
5365 const struct extra_type *target_extra)
5366{
5367 if (actor_unit == NULL || target_tile == NULL) {
5368 /* Can't do an action when actor or target are missing. */
5369 return ACTPROB_IMPOSSIBLE;
5370 }
5371
5374 "Action %s is performed by %s not %s",
5375 action_id_rule_name(act_id),
5377 action_id_get_actor_kind(act_id)),
5379
5382 "Action %s is against %s not %s",
5383 action_id_rule_name(act_id),
5387
5389
5390 if (!unit_can_do_action(actor_unit, act_id)) {
5391 /* No point in continuing. */
5392 return ACTPROB_IMPOSSIBLE;
5393 }
5394
5395 /* Doesn't leak information about tile position since an unknown tile's
5396 * position is known. */
5397 if (!action_id_distance_accepted(act_id,
5399 target_tile))) {
5400 /* No point in continuing. */
5401 return ACTPROB_IMPOSSIBLE;
5402 }
5403
5404 return action_prob(nmap, act_id,
5405 &(const struct req_context) {
5406 .player = unit_owner(actor_unit),
5407 .city = tile_city(actor_tile),
5408 .tile = actor_tile,
5409 .unit = actor_unit,
5410 .unittype = unit_type_get(actor_unit),
5411 },
5412 actor_home,
5413 &(const struct req_context) {
5414 .player = target_tile->extras_owner,
5415 .city = tile_city(target_tile),
5416 .tile = target_tile,
5417 },
5418 target_extra);
5419}
5420
5421/**********************************************************************/
5426 const struct unit *actor_unit,
5427 const action_id act_id,
5428 const struct tile *target_tile,
5429 const struct extra_type *target_extra)
5430{
5434 act_id, target_tile, target_extra);
5435}
5436
5437/**********************************************************************/
5441static struct act_prob
5443 const struct unit *actor_unit,
5444 const struct city *actor_home,
5445 const struct tile *actor_tile,
5446 const action_id act_id)
5447{
5448 if (actor_unit == NULL) {
5449 /* Can't do the action when the actor is missing. */
5450 return ACTPROB_IMPOSSIBLE;
5451 }
5452
5453 /* No point in checking distance to target. It is always 0. */
5454
5457 "Action %s is performed by %s not %s",
5458 action_id_rule_name(act_id),
5460 action_id_get_actor_kind(act_id)),
5462
5465 "Action %s is against %s not %s",
5466 action_id_rule_name(act_id),
5470
5472
5473 if (!unit_can_do_action(actor_unit, act_id)) {
5474 /* No point in continuing. */
5475 return ACTPROB_IMPOSSIBLE;
5476 }
5477
5478 return action_prob(nmap, act_id,
5479 &(const struct req_context) {
5480 .player = unit_owner(actor_unit),
5481 .city = tile_city(actor_tile),
5482 .tile = actor_tile,
5483 .unit = actor_unit,
5484 .unittype = unit_type_get(actor_unit),
5485 },
5486 actor_home,
5487 NULL,
5488 NULL);
5489}
5490
5491/**********************************************************************/
5496 const struct unit *actor_unit,
5497 const action_id act_id)
5498{
5502 act_id);
5503}
5504
5505/**********************************************************************/
5518 const struct action *paction,
5519 const struct unit *act_unit,
5520 const struct city *tgt_city,
5521 const struct unit *tgt_unit,
5522 const struct tile *tgt_tile,
5523 const struct extra_type *extra_tgt)
5524{
5525 /* Assume impossible until told otherwise. */
5526 struct act_prob prob = ACTPROB_IMPOSSIBLE;
5527
5530
5532 case ATK_UNITS:
5533 if (tgt_tile) {
5535 }
5536 break;
5537 case ATK_TILE:
5538 if (tgt_tile) {
5540 }
5541 break;
5542 case ATK_EXTRAS:
5543 if (tgt_tile) {
5546 }
5547 break;
5548 case ATK_CITY:
5549 if (tgt_city) {
5551 }
5552 break;
5553 case ATK_UNIT:
5554 if (tgt_unit) {
5556 }
5557 break;
5558 case ATK_SELF:
5559 prob = action_prob_self(nmap, act_unit, paction->id);
5560 break;
5561 case ATK_COUNT:
5562 log_error("Invalid action target kind");
5563 break;
5564 }
5565
5566 return prob;
5567}
5568
5569/**********************************************************************/
5575 const action_id act_id,
5576 const struct unit *actor,
5577 const struct city *actor_home,
5578 const struct tile *actor_tile,
5579 const bool omniscient_cheat,
5580 const struct city* target)
5581{
5582 /* FIXME: some unit state requirements still depend on the actor unit's
5583 * current position rather than on actor_tile. Maybe this function should
5584 * return ACTPROB_NOT_IMPLEMENTED when one of those is detected and no
5585 * other requirement makes the action ACTPROB_IMPOSSIBLE? */
5586
5587 if (omniscient_cheat) {
5590 target)) {
5591 return ACTPROB_CERTAIN;
5592 } else {
5593 return ACTPROB_IMPOSSIBLE;
5594 }
5595 } else {
5596 /* FIXME: this branch result depends _directly_ on actor's position.
5597 * I.e., like, not adjacent, no action. Other branch ignores radius. */
5599 act_id, target);
5600 }
5601}
5602
5603/**********************************************************************/
5608struct act_prob
5610 action_id act_id,
5611 const struct unit *actor,
5612 const struct city *actor_home,
5613 const struct tile *actor_tile,
5614 bool omniscient_cheat,
5615 const struct unit *target)
5616{
5617 /* FIXME: some unit state requirements still depend on the actor unit's
5618 * current position rather than on actor_tile. Maybe this function should
5619 * return ACTPROB_NOT_IMPLEMENTED when one of those is detected and no
5620 * other requirement makes the action ACTPROB_IMPOSSIBLE? */
5621
5622 if (omniscient_cheat) {
5625 target)) {
5626 return ACTPROB_CERTAIN;
5627 } else {
5628 return ACTPROB_IMPOSSIBLE;
5629 }
5630 } else {
5632 act_id, target);
5633 }
5634}
5635
5636/**********************************************************************/
5641struct act_prob
5643 action_id act_id,
5644 const struct unit *actor,
5645 const struct city *actor_home,
5646 const struct tile *actor_tile,
5647 bool omniscient_cheat,
5648 const struct tile *target)
5649{
5650 /* FIXME: some unit state requirements still depend on the actor unit's
5651 * current position rather than on actor_tile. Maybe this function should
5652 * return ACTPROB_NOT_IMPLEMENTED when one of those is detected and no
5653 * other requirement makes the action ACTPROB_IMPOSSIBLE? */
5654
5655 if (omniscient_cheat) {
5658 target)) {
5659 return ACTPROB_CERTAIN;
5660 } else {
5661 return ACTPROB_IMPOSSIBLE;
5662 }
5663 } else {
5665 act_id, target);
5666 }
5667}
5668
5669/**********************************************************************/
5674struct act_prob
5676 action_id act_id,
5677 const struct unit *actor,
5678 const struct city *actor_home,
5679 const struct tile *actor_tile,
5680 bool omniscient_cheat,
5681 const struct tile *target_tile,
5682 const struct extra_type *target_extra)
5683{
5684 /* FIXME: some unit state requirements still depend on the actor unit's
5685 * current position rather than on actor_tile. Maybe this function should
5686 * return ACTPROB_NOT_IMPLEMENTED when one of those is detected and no
5687 * other requirement makes the action ACTPROB_IMPOSSIBLE? */
5688
5689 if (omniscient_cheat) {
5693 return ACTPROB_CERTAIN;
5694 } else {
5695 return ACTPROB_IMPOSSIBLE;
5696 }
5697 } else {
5699 act_id, target_tile, target_extra);
5700 }
5701}
5702
5703/**********************************************************************/
5708struct act_prob
5710 action_id act_id,
5711 const struct unit *actor,
5712 const struct city *actor_home,
5713 const struct tile *actor_tile,
5714 bool omniscient_cheat,
5715 const struct tile *target_tile,
5716 const struct extra_type *target_extra)
5717{
5718 /* FIXME: some unit state requirements still depend on the actor unit's
5719 * current position rather than on actor_tile. Maybe this function should
5720 * return ACTPROB_NOT_IMPLEMENTED when one of those is detected and no
5721 * other requirement makes the action ACTPROB_IMPOSSIBLE? */
5722
5723 if (omniscient_cheat) {
5727 return ACTPROB_CERTAIN;
5728 } else {
5729 return ACTPROB_IMPOSSIBLE;
5730 }
5731 } else {
5733 act_id, target_tile, target_extra);
5734 }
5735}
5736
5737/**********************************************************************/
5742struct act_prob
5744 action_id act_id,
5745 const struct unit *actor,
5746 const struct city *actor_home,
5747 const struct tile *actor_tile,
5748 bool omniscient_cheat)
5749{
5750 /* FIXME: some unit state requirements still depend on the actor unit's
5751 * current position rather than on actor_tile. Maybe this function should
5752 * return ACTPROB_NOT_IMPLEMENTED when one of those is detected and no
5753 * other requirement makes the action ACTPROB_IMPOSSIBLE? */
5754 if (omniscient_cheat) {
5757 return ACTPROB_CERTAIN;
5758 } else {
5759 return ACTPROB_IMPOSSIBLE;
5760 }
5761 } else {
5763 act_id);
5764 }
5765}
5766
5767/**********************************************************************/
5771{
5773
5774 return out;
5775}
5776
5777/**********************************************************************/
5781{
5783
5784 return out;
5785}
5786
5787/**********************************************************************/
5791{
5793
5794 return out;
5795}
5796
5797/**********************************************************************/
5801{
5803
5804 return out;
5805}
5806
5807/**********************************************************************/
5811{
5813
5814 return out;
5815}
5816
5817/**********************************************************************/
5822{
5823 return (ACTPROB_VAL_MIN < probability.max
5825}
5826
5827/**********************************************************************/
5832{
5833 return (ACTPROB_VAL_MAX == probability.min
5834 && ACTPROB_VAL_MAX == probability.max);
5835}
5836
5837/**********************************************************************/
5841static inline bool
5847
5848/**********************************************************************/
5852static inline bool
5854{
5855 return probability.min == ACTPROB_VAL_NOT_IMPL
5856 && probability.max == ACTPROB_VAL_MIN;
5857}
5858
5859/**********************************************************************/
5863static inline bool
5865{
5866 return probability.max < probability.min;
5867}
5868
5869/**********************************************************************/
5873 const struct act_prob *ap2)
5874{
5875 return ap1->min == ap2->min && ap1->max == ap2->max;
5876}
5877
5878/**********************************************************************/
5882 const struct act_prob ap2)
5883{
5884 struct act_prob my_ap1;
5885 struct act_prob my_ap2;
5886
5887 /* The action probabilities are real. */
5890
5891 /* Convert any signals to ACTPROB_NOT_KNOWN. */
5893 /* Assert that it is OK to convert the signal. */
5895
5897 } else {
5898 my_ap1 = ap1;
5899 }
5900
5902 /* Assert that it is OK to convert the signal. */
5904
5906 } else {
5907 my_ap2 = ap2;
5908 }
5909
5910 /* The action probabilities now have a comparison friendly form. */
5913
5914 /* Do the comparison. Start with min. Continue with max. */
5915 if (my_ap1.min < my_ap2.min) {
5916 return -1;
5917 } else if (my_ap1.min > my_ap2.min) {
5918 return 1;
5919 } else if (my_ap1.max < my_ap2.max) {
5920 return -1;
5921 } else if (my_ap1.max > my_ap2.max) {
5922 return 1;
5923 } else {
5924 return 0;
5925 }
5926}
5927
5928/**********************************************************************/
5933{
5934 struct act_prob my_ap;
5935
5936 /* The action probability is real. */
5938
5939 /* Convert any signals to ACTPROB_NOT_KNOWN. */
5941 /* Assert that it is OK to convert the signal. */
5943
5945 } else {
5946 my_ap = ap;
5947 }
5948
5949 /* The action probability now has a math friendly form. */
5951
5952 return (double)my_ap.min / (double) ACTPROB_VAL_MAX;
5953}
5954
5955/**********************************************************************/
5960 const struct act_prob *ap2)
5961{
5962 struct act_prob my_ap1;
5963 struct act_prob my_ap2;
5964 struct act_prob out;
5965
5966 /* The action probabilities are real. */
5969
5972 /* Keep the information rather than converting the signal to
5973 * ACTPROB_NOT_KNOWN. */
5974
5975 /* Assert that it is OK to convert the signal. */
5977
5978 out.min = ap1->min;
5979 out.max = ap2->max;
5980
5981 return out;
5982 }
5983
5984 /* Convert any signals to ACTPROB_NOT_KNOWN. */
5985 if (action_prob_is_signal(*ap1)) {
5986 /* Assert that it is OK to convert the signal. */
5988
5989 my_ap1.min = ACTPROB_VAL_MIN;
5990 my_ap1.max = ACTPROB_VAL_MAX;
5991 } else {
5992 my_ap1.min = ap1->min;
5993 my_ap1.max = ap1->max;
5994 }
5995
5996 if (action_prob_is_signal(*ap2)) {
5997 /* Assert that it is OK to convert the signal. */
5999
6000 my_ap2.min = ACTPROB_VAL_MIN;
6001 my_ap2.max = ACTPROB_VAL_MAX;
6002 } else {
6003 my_ap2.min = ap2->min;
6004 my_ap2.max = ap2->max;
6005 }
6006
6007 /* The action probabilities now have a math friendly form. */
6010
6011 /* Do the math. */
6012 out.min = (my_ap1.min * my_ap2.min) / ACTPROB_VAL_MAX;
6013 out.max = (my_ap1.max * my_ap2.max) / ACTPROB_VAL_MAX;
6014
6015 /* Cap at 100%. */
6016 out.min = MIN(out.min, ACTPROB_VAL_MAX);
6017 out.max = MIN(out.max, ACTPROB_VAL_MAX);
6018
6019 return out;
6020}
6021
6022/**********************************************************************/
6030 const struct act_prob *ap2)
6031{
6032 struct act_prob my_ap1;
6033 struct act_prob my_ap2;
6034 struct act_prob out;
6035
6036 /* The action probabilities are real. */
6039
6042 /* Keep the information rather than converting the signal to
6043 * ACTPROB_NOT_KNOWN. */
6044
6045 /* Assert that it is OK to convert the signal. */
6047
6048 out.min = ap1->min;
6049 out.max = ap2->max;
6050
6051 return out;
6052 }
6053
6054 /* Convert any signals to ACTPROB_NOT_KNOWN. */
6055 if (action_prob_is_signal(*ap1)) {
6056 /* Assert that it is OK to convert the signal. */
6058
6059 my_ap1.min = ACTPROB_VAL_MIN;
6060 my_ap1.max = ACTPROB_VAL_MAX;
6061 } else {
6062 my_ap1.min = ap1->min;
6063 my_ap1.max = ap1->max;
6064 }
6065
6066 if (action_prob_is_signal(*ap2)) {
6067 /* Assert that it is OK to convert the signal. */
6069
6070 my_ap2.min = ACTPROB_VAL_MIN;
6071 my_ap2.max = ACTPROB_VAL_MAX;
6072 } else {
6073 my_ap2.min = ap2->min;
6074 my_ap2.max = ap2->max;
6075 }
6076
6077 /* The action probabilities now have a math friendly form. */
6080
6081 /* Do the math. */
6082 out.min = my_ap1.min + (((ACTPROB_VAL_MAX - my_ap1.min) * my_ap2.min)
6083 / ACTPROB_VAL_MAX);
6084 out.max = my_ap1.max + (((ACTPROB_VAL_MAX - my_ap1.max) * my_ap2.max)
6085 / ACTPROB_VAL_MAX);
6086
6087 /* Cap at 100%. */
6088 out.min = MIN(out.min, ACTPROB_VAL_MAX);
6089 out.max = MIN(out.max, ACTPROB_VAL_MAX);
6090
6091 return out;
6092}
6093
6094/**********************************************************************/
6098{
6099 switch (actres_dice_type(paction->result)) {
6100 case DRT_DIPLCHANCE:
6102 /* Take the initial odds from the diplchance setting. */
6104 server_setting_by_name("diplchance"));
6105 }
6107 case DRT_CERTAIN:
6108 return 100;
6109 case DRT_NONE:
6110 break;
6111 }
6112
6113 /* The odds of the action not being stopped by its dice roll when the dice
6114 * isn't thrown is 100%. ACTION_ODDS_PCT_DICE_ROLL_NA is above 100% */
6116}
6117
6118/**********************************************************************/
6122 const struct unit *act_unit,
6123 const struct city *tgt_city,
6124 const struct player *tgt_player,
6125 const struct action *paction)
6126{
6128 const struct unit_type *actu_type = unit_type_get(act_unit);
6129
6130 fc_assert_action_msg(odds >= 0 && odds <= 100,
6131 odds = 100,
6132 "Bad initial odds for action number %d."
6133 " Does it roll the dice at all?",
6134 paction->id);
6135
6136 /* Let the Action_Odds_Pct effect modify the odds. The advantage of doing
6137 * it this way instead of rolling twice is that Action_Odds_Pct can
6138 * increase the odds. */
6139 odds = odds
6140 + ((odds
6142 &(const struct req_context) {
6143 .player = act_player,
6144 .city = tgt_city,
6145 .unit = act_unit,
6146 .unittype = actu_type,
6147 .action = paction,
6148 },
6149 tgt_player,
6151 / 100)
6152 - ((odds
6154 &(const struct req_context) {
6155 .player = tgt_player,
6156 .city = tgt_city,
6157 .unit = act_unit,
6158 .unittype = actu_type,
6159 .action = paction,
6160 },
6161 act_player,
6163 / 100);
6164
6165
6166 /* Odds are between 0% and 100%. */
6167 return CLIP(0, odds, 100);
6168}
6169
6170/**********************************************************************/
6174{
6175 struct action *paction = action_by_number(act);
6176
6177 /* Always immune since its not enabled. Doesn't count. */
6178 if (!action_is_in_use(paction)) {
6179 return FALSE;
6180 }
6181
6183 if (requirement_fulfilled_by_government(gov, &(enabler->target_reqs))) {
6184 return FALSE;
6185 }
6187
6188 return TRUE;
6189}
6190
6191/**********************************************************************/
6197 const struct player *actor_player,
6198 const struct req_context *target)
6199{
6201 enabler) {
6202 if (are_reqs_active(target, actor_player,
6203 &enabler->target_reqs, RPT_POSSIBLE)) {
6204 return TRUE;
6205 }
6207
6208 return FALSE;
6209}
6210
6211/**********************************************************************/
6215 const struct player *actor_player,
6216 const struct city* target_city)
6217{
6219 FALSE, "Action %s is against %s not cities",
6220 action_id_rule_name(act_id),
6222 action_id_get_target_kind(act_id)));
6223
6224 return is_target_possible(act_id, actor_player,
6225 &(const struct req_context) {
6226 .player = city_owner(target_city),
6227 .city = target_city,
6229 });
6230}
6231
6232/**********************************************************************/
6238 const action_id act_id,
6239 const struct unit *actor_unit)
6240{
6241 const struct player *actor_player = unit_owner(actor_unit);
6242 const struct req_context actor_ctxt = {
6244 .city = tile_city(unit_tile(actor_unit)),
6246 .unit = actor_unit,
6247 .unittype = unit_type_get(actor_unit),
6248 };
6249 const struct action *paction = action_by_number(act_id);
6250
6251 enum fc_tristate result;
6252
6254
6255 if (!utype_can_do_action(actor_unit->utype, act_id)) {
6256 /* The unit type can't perform the action. */
6257 return FALSE;
6258 }
6259
6262
6263 if (result == TRI_NO) {
6264 /* The hard requirements aren't fulfilled. */
6265 return FALSE;
6266 }
6267
6269 enabler) {
6270 const enum fc_tristate current
6272 &enabler->actor_reqs,
6273 /* Needed since no player to evaluate DiplRel
6274 * requirements against. */
6275 RPT_POSSIBLE);
6276
6277 if (current == TRI_YES
6278 || current == TRI_MAYBE) {
6279 /* The ruleset requirements may be fulfilled. */
6280 return TRUE;
6281 }
6283
6284 /* No action enabler allows this action. */
6285 return FALSE;
6286}
6287
6288/**********************************************************************/
6293 const action_id act_id)
6294{
6295 fc_assert(action_id_exists(act_id) || act_id == ACTION_ANY);
6296
6297 /* Check if full movement points may enable the specified action. */
6299 act_id,
6302 act_id,
6304}
6305
6306/**********************************************************************/
6331
6332/**********************************************************************/
6343{
6344 const struct action *paction = enabler_get_action(ae);
6345
6346 switch (action_get_actor_kind(paction)) {
6347 case AAK_UNIT:
6350 /* A possible actor unit type has been found. */
6351 return TRUE;
6352 }
6354
6355 /* No actor detected. */
6356 return FALSE;
6357 case AAK_COUNT:
6359 break;
6360 }
6361
6362 /* No actor detected. */
6363 return FALSE;
6364}
6365
6366/**********************************************************************/
6374{
6375 switch (action_get_actor_kind(paction)) {
6376 case AAK_UNIT:
6379 return TRUE;
6380 }
6382 break;
6383 case AAK_COUNT:
6385 break;
6386 }
6387
6388 /* No actor detected. */
6389 return FALSE;
6390}
6391
6392/**********************************************************************/
6399{
6401
6403 /* Hard requirements not fulfilled. */
6404 return FALSE;
6405 }
6406
6408
6410 /* If this iteration finds any entries, action is enabled. */
6411 return TRUE;
6413
6414 /* No non deleted action enabler. */
6415 return FALSE;
6416}
6417
6418/**********************************************************************/
6422{
6423 fc_assert_ret_val(num >= 0, NULL);
6425
6426 return &auto_perfs[num];
6427}
6428
6429/**********************************************************************/
6438{
6439 return action_auto_perf_slot_number(num);
6440}
6441
6442/**********************************************************************/
6446 struct universal *actor_uni,
6447 struct universal *target_uni)
6448{
6450 enab) {
6451 if ((actor_uni == NULL
6452 || universal_fulfills_requirements(FALSE, &(enab->actor_reqs),
6453 actor_uni))
6454 && (target_uni == NULL
6455 || universal_fulfills_requirements(FALSE, &(enab->target_reqs),
6456 target_uni))) {
6457 return TRUE;
6458 }
6460
6461 return FALSE;
6462}
6463
6464/**********************************************************************/
6470{
6472
6473 if (size < MAX_NUM_ACTIONS) {
6474 /* An action array is terminated by ACTION_NONE */
6476 }
6477}
6478
6479/**********************************************************************/
6487 int *position,
6488 enum action_result result)
6489{
6490 action_iterate(act) {
6491 struct action *paction = action_by_number(act);
6492 if (paction->result == result) {
6493 /* Assume one result for each action. */
6494 fc_assert_ret(*position < MAX_NUM_ACTIONS);
6495
6496 act_array[(*position)++] = paction->id;
6497 }
6499}
6500
6501/**********************************************************************/
6507{
6508 switch ((enum gen_action)act) {
6509 case ACTION_SPY_POISON:
6510 return "ui_name_poison_city";
6512 return "ui_name_poison_city_escape";
6514 return "ui_name_sabotage_unit";
6516 return "ui_name_sabotage_unit_escape";
6518 return "ui_name_bribe_unit";
6520 return "ui_name_sabotage_city";
6522 return "ui_name_sabotage_city_escape";
6524 return "ui_name_targeted_sabotage_city";
6526 return "ui_name_sabotage_city_production";
6528 return "ui_name_targeted_sabotage_city_escape";
6530 return "ui_name_sabotage_city_production_escape";
6532 return "ui_name_incite_city";
6534 return "ui_name_incite_city_escape";
6536 return "ui_name_establish_embassy";
6538 return "ui_name_establish_embassy_stay";
6540 return "ui_name_steal_tech";
6542 return "ui_name_steal_tech_escape";
6544 return "ui_name_targeted_steal_tech";
6546 return "ui_name_targeted_steal_tech_escape";
6548 return "ui_name_investigate_city";
6550 return "ui_name_investigate_city_spend_unit";
6552 return "ui_name_steal_gold";
6554 return "ui_name_steal_gold_escape";
6556 return "ui_name_spread_plague";
6557 case ACTION_STEAL_MAPS:
6558 return "ui_name_steal_maps";
6560 return "ui_name_steal_maps_escape";
6561 case ACTION_TRADE_ROUTE:
6562 return "ui_name_establish_trade_route";
6563 case ACTION_MARKETPLACE:
6564 return "ui_name_enter_marketplace";
6565 case ACTION_HELP_WONDER:
6566 return "ui_name_help_wonder";
6568 return "ui_name_capture_units";
6569 case ACTION_EXPEL_UNIT:
6570 return "ui_name_expel_unit";
6571 case ACTION_FOUND_CITY:
6572 return "ui_name_found_city";
6573 case ACTION_JOIN_CITY:
6574 return "ui_name_join_city";
6575 case ACTION_BOMBARD:
6576 return "ui_name_bombard";
6577 case ACTION_BOMBARD2:
6578 return "ui_name_bombard_2";
6579 case ACTION_BOMBARD3:
6580 return "ui_name_bombard_3";
6581 case ACTION_BOMBARD4:
6582 return "ui_name_bombard_4";
6584 return "ui_name_bombard_lethal";
6586 return "ui_name_bombard_lethal_2";
6587 case ACTION_SPY_NUKE:
6588 return "ui_name_suitcase_nuke";
6590 return "ui_name_suitcase_nuke_escape";
6591 case ACTION_NUKE:
6592 return "ui_name_explode_nuclear";
6593 case ACTION_NUKE_CITY:
6594 return "ui_name_nuke_city";
6595 case ACTION_NUKE_UNITS:
6596 return "ui_name_nuke_units";
6598 return "ui_name_destroy_city";
6600 return "ui_name_disband_unit_recover";
6602 return "ui_name_disband_unit";
6603 case ACTION_HOME_CITY:
6604 return "ui_name_home_city";
6605 case ACTION_HOMELESS:
6606 return "ui_name_homeless";
6608 return "ui_name_upgrade_unit";
6609 case ACTION_PARADROP:
6610 return "ui_name_paradrop_unit";
6612 return "ui_name_paradrop_unit_conquer";
6614 return "ui_name_paradrop_unit_frighten";
6616 return "ui_name_paradrop_unit_frighten_conquer";
6618 return "ui_name_paradrop_unit_enter";
6620 return "ui_name_paradrop_unit_enter_conquer";
6621 case ACTION_AIRLIFT:
6622 return "ui_name_airlift_unit";
6623 case ACTION_ATTACK:
6624 return "ui_name_attack";
6625 case ACTION_ATTACK2:
6626 return "ui_name_attack_2";
6628 return "ui_name_suicide_attack";
6630 return "ui_name_suicide_attack_2";
6631 case ACTION_WIPE_UNITS:
6632 return "ui_name_wipe_units";
6634 return "ui_name_collect_ransom";
6636 return "ui_name_surgical_strike_building";
6638 return "ui_name_surgical_strike_production";
6640 return "ui_name_conquer_city";
6642 return "ui_name_conquer_city_2";
6644 return "ui_name_conquer_city_3";
6646 return "ui_name_conquer_city_4";
6648 return "ui_name_conquer_extras";
6650 return "ui_name_conquer_extras_2";
6652 return "ui_name_conquer_extras_3";
6654 return "ui_name_conquer_extras_4";
6655 case ACTION_HEAL_UNIT:
6656 return "ui_name_heal_unit";
6657 case ACTION_HEAL_UNIT2:
6658 return "ui_name_heal_unit_2";
6660 return "ui_name_transform_terrain";
6661 case ACTION_CULTIVATE:
6662 return "ui_name_cultivate";
6663 case ACTION_PLANT:
6664 return "ui_name_plant";
6665 case ACTION_PILLAGE:
6666 return "ui_name_pillage";
6667 case ACTION_CLEAN:
6668 return "ui_name_clean";
6669 case ACTION_FORTIFY:
6670 return "ui_name_fortify";
6671 case ACTION_ROAD:
6672 return "ui_name_build_road";
6673 case ACTION_CONVERT:
6674 return "ui_name_convert_unit";
6675 case ACTION_BASE:
6676 return "ui_name_build_base";
6677 case ACTION_MINE:
6678 return "ui_name_build_mine";
6679 case ACTION_IRRIGATE:
6680 return "ui_name_irrigate";
6682 return "ui_name_transport_deboard";
6684 return "ui_name_transport_board";
6686 return "ui_name_transport_board_2";
6688 return "ui_name_transport_board_3";
6690 return "ui_name_transport_embark";
6692 return "ui_name_transport_embark_2";
6694 return "ui_name_transport_embark_3";
6696 return "ui_name_transport_embark_4";
6698 return "ui_name_transport_unload";
6700 return "ui_name_transport_load";
6702 return "ui_name_transport_load_2";
6704 return "ui_name_transport_load_3";
6706 return "ui_name_transport_disembark";
6708 return "ui_name_transport_disembark_2";
6710 return "ui_name_transport_disembark_3";
6712 return "ui_name_transport_disembark_4";
6713 case ACTION_HUT_ENTER:
6714 return "ui_name_enter_hut";
6715 case ACTION_HUT_ENTER2:
6716 return "ui_name_enter_hut_2";
6717 case ACTION_HUT_ENTER3:
6718 return "ui_name_enter_hut_3";
6719 case ACTION_HUT_ENTER4:
6720 return "ui_name_enter_hut_4";
6722 return "ui_name_frighten_hut";
6724 return "ui_name_frighten_hut_2";
6726 return "ui_name_frighten_hut_3";
6728 return "ui_name_frighten_hut_4";
6729 case ACTION_SPY_ATTACK:
6730 return "ui_name_spy_attack";
6731 case ACTION_UNIT_MOVE:
6732 return "ui_name_unit_move";
6733 case ACTION_UNIT_MOVE2:
6734 return "ui_name_unit_move_2";
6735 case ACTION_UNIT_MOVE3:
6736 return "ui_name_unit_move_3";
6737 case ACTION_TELEPORT:
6738 return "ui_name_teleport";
6740 return "ui_name_teleport_conquer";
6742 return "ui_name_teleport_frighten";
6744 return "ui_name_teleport_frighten_conquer";
6746 return "ui_name_teleport_enter";
6748 return "ui_name_teleport_enter_conquer";
6749 case ACTION_SPY_ESCAPE:
6750 return "ui_name_escape";
6752 return "ui_name_user_action_1";
6754 return "ui_name_user_action_2";
6756 return "ui_name_user_action_3";
6758 return "ui_name_user_action_4";
6759 case ACTION_COUNT:
6760 break;
6761
6763 }
6764
6765 fc_assert(act >= 0 && act < ACTION_COUNT);
6766
6767 return NULL;
6768}
6769
6770/**********************************************************************/
6773const char *action_ui_name_default(int act)
6774{
6775 switch ((enum gen_action)act) {
6776 case ACTION_SPY_POISON:
6777 /* TRANS: _Poison City (3% chance of success). */
6778 return N_("%sPoison City%s");
6780 /* TRANS: _Poison City and Escape (3% chance of success). */
6781 return N_("%sPoison City and Escape%s");
6783 /* TRANS: S_abotage Enemy Unit (3% chance of success). */
6784 return N_("S%sabotage Enemy Unit%s");
6786 /* TRANS: S_abotage Enemy Unit and Escape (3% chance of success). */
6787 return N_("S%sabotage Enemy Unit and Escape%s");
6789 /* TRANS: Bribe Enemy _Unit (3% chance of success). */
6790 return N_("Bribe Enemy %sUnit%s");
6792 /* TRANS: _Sabotage City (3% chance of success). */
6793 return N_("%sSabotage City%s");
6795 /* TRANS: _Sabotage City and Escape (3% chance of success). */
6796 return N_("%sSabotage City and Escape%s");
6798 /* TRANS: Industria_l Sabotage (3% chance of success). */
6799 return N_("Industria%sl Sabotage%s");
6801 /* TRANS: Industria_l Sabotage Production (3% chance of success). */
6802 return N_("Industria%sl Sabotage Production%s");
6804 /* TRANS: Industria_l Sabotage and Escape (3% chance of success). */
6805 return N_("Industria%sl Sabotage and Escape%s");
6807 /* TRANS: Industria_l Sabotage Production and Escape (3% chance of success). */
6808 return N_("Industria%sl Sabotage Production and Escape%s");
6810 /* TRANS: Incite a Re_volt (3% chance of success). */
6811 return N_("Incite a Re%svolt%s");
6813 /* TRANS: Incite a Re_volt and Escape (3% chance of success). */
6814 return N_("Incite a Re%svolt and Escape%s");
6816 /* TRANS: Establish _Embassy (100% chance of success). */
6817 return N_("Establish %sEmbassy%s");
6819 /* TRANS: Becom_e Ambassador (100% chance of success). */
6820 return N_("Becom%se Ambassador%s");
6822 /* TRANS: Steal _Technology (3% chance of success). */
6823 return N_("Steal %sTechnology%s");
6825 /* TRANS: Steal _Technology and Escape (3% chance of success). */
6826 return N_("Steal %sTechnology and Escape%s");
6828 /* TRANS: In_dustrial Espionage (3% chance of success). */
6829 return N_("In%sdustrial Espionage%s");
6831 /* TRANS: In_dustrial Espionage and Escape (3% chance of success). */
6832 return N_("In%sdustrial Espionage and Escape%s");
6834 /* TRANS: _Investigate City (100% chance of success). */
6835 return N_("%sInvestigate City%s");
6837 /* TRANS: _Investigate City (spends the unit) (100% chance of
6838 * success). */
6839 return N_("%sInvestigate City (spends the unit)%s");
6841 /* TRANS: Steal _Gold (100% chance of success). */
6842 return N_("Steal %sGold%s");
6844 /* TRANS: Steal _Gold and Escape (100% chance of success). */
6845 return N_("Steal %sGold and Escape%s");
6847 /* TRANS: Spread _Plague (100% chance of success). */
6848 return N_("Spread %sPlague%s");
6849 case ACTION_STEAL_MAPS:
6850 /* TRANS: Steal _Maps (100% chance of success). */
6851 return N_("Steal %sMaps%s");
6853 /* TRANS: Steal _Maps and Escape (100% chance of success). */
6854 return N_("Steal %sMaps and Escape%s");
6855 case ACTION_TRADE_ROUTE:
6856 /* TRANS: Establish Trade _Route (100% chance of success). */
6857 return N_("Establish Trade %sRoute%s");
6858 case ACTION_MARKETPLACE:
6859 /* TRANS: Enter _Marketplace (100% chance of success). */
6860 return N_("Enter %sMarketplace%s");
6861 case ACTION_HELP_WONDER:
6862 /* TRANS: Help _build Wonder (100% chance of success). */
6863 return N_("Help %sbuild Wonder%s");
6865 /* TRANS: _Capture Units (100% chance of success). */
6866 return N_("%sCapture Units%s");
6867 case ACTION_EXPEL_UNIT:
6868 /* TRANS: _Expel Unit (100% chance of success). */
6869 return N_("%sExpel Unit%s");
6870 case ACTION_FOUND_CITY:
6871 /* TRANS: _Found City (100% chance of success). */
6872 return N_("%sFound City%s");
6873 case ACTION_JOIN_CITY:
6874 /* TRANS: _Join City (100% chance of success). */
6875 return N_("%sJoin City%s");
6876 case ACTION_BOMBARD:
6877 /* TRANS: B_ombard (100% chance of success). */
6878 return N_("B%sombard%s");
6879 case ACTION_BOMBARD2:
6880 /* TRANS: B_ombard 2 (100% chance of success). */
6881 return N_("B%sombard 2%s");
6882 case ACTION_BOMBARD3:
6883 /* TRANS: B_ombard 3 (100% chance of success). */
6884 return N_("B%sombard 3%s");
6885 case ACTION_BOMBARD4:
6886 /* TRANS: B_ombard 4 (100% chance of success). */
6887 return N_("B%sombard 4%s");
6890 /* TRANS: Lethal B_ombard (100% chance of success). */
6891 return N_("Lethal B%sombard%s");
6892 case ACTION_SPY_NUKE:
6893 /* TRANS: Suitcase _Nuke (100% chance of success). */
6894 return N_("Suitcase %sNuke%s");
6896 /* TRANS: Suitcase _Nuke and Escape (100% chance of success). */
6897 return N_("Suitcase %sNuke and Escape%s");
6898 case ACTION_NUKE:
6899 /* TRANS: Explode _Nuclear (100% chance of success). */
6900 return N_("Explode %sNuclear%s");
6901 case ACTION_NUKE_CITY:
6902 /* TRANS: _Nuke City (100% chance of success). */
6903 return N_("%sNuke City%s");
6904 case ACTION_NUKE_UNITS:
6905 /* TRANS: _Nuke Units (100% chance of success). */
6906 return N_("%sNuke Units%s");
6908 /* TRANS: Destroy _City (100% chance of success). */
6909 return N_("Destroy %sCity%s");
6911 /* TRANS: Dis_band recovering production (100% chance of success). */
6912 return N_("Dis%sband recovering production%s");
6914 /* TRANS: Dis_band without recovering production (100% chance of success). */
6915 return N_("Dis%sband without recovering production%s");
6916 case ACTION_HOME_CITY:
6917 /* TRANS: Set _Home City (100% chance of success). */
6918 return N_("Set %sHome City%s");
6919 case ACTION_HOMELESS:
6920 /* TRANS: Make _Homeless (100% chance of success). */
6921 return N_("Make %sHomeless%s");
6923 /* TRANS: _Upgrade Unit (100% chance of success). */
6924 return N_("%sUpgrade Unit%s");
6925 case ACTION_PARADROP:
6926 /* TRANS: Drop _Paratrooper (100% chance of success). */
6927 return N_("Drop %sParatrooper%s");
6929 /* TRANS: Drop _Paratrooper (100% chance of success). */
6930 return N_("Drop %sParatrooper%s");
6932 /* TRANS: Drop _Paratrooper (100% chance of success). */
6933 return N_("Drop %sParatrooper%s");
6935 /* TRANS: Drop _Paratrooper (100% chance of success). */
6936 return N_("Drop %sParatrooper%s");
6938 /* TRANS: Drop _Paratrooper (100% chance of success). */
6939 return N_("Drop %sParatrooper%s");
6941 /* TRANS: Drop _Paratrooper (100% chance of success). */
6942 return N_("Drop %sParatrooper%s");
6943 case ACTION_AIRLIFT:
6944 /* TRANS: _Airlift to City (100% chance of success). */
6945 return N_("%sAirlift to City%s");
6946 case ACTION_ATTACK:
6947 case ACTION_ATTACK2:
6948 /* TRANS: _Attack (100% chance of success). */
6949 return N_("%sAttack%s");
6952 /* TRANS: _Suicide Attack (100% chance of success). */
6953 return N_("%sSuicide Attack%s");
6954 case ACTION_WIPE_UNITS:
6955 /* TRANS: _Wipe Units (100% chance of success). */
6956 return N_("%sWipe Units%s");
6958 /* TRANS: Collect _Ransom (100% chance of success). */
6959 return N_("Collect %sRansom%s");
6961 /* TRANS: Surgical Str_ike Building (100% chance of success). */
6962 return N_("Surgical Str%sike Building%s");
6964 /* TRANS: Surgical Str_ike Production (100% chance of success). */
6965 return N_("Surgical Str%sike Production%s");
6969 /* TRANS: _Conquer City (100% chance of success). */
6970 return N_("%sConquer City%s");
6972 /* TRANS: _Conquer City 2 (100% chance of success). */
6973 return N_("%sConquer City 2%s");
6977 /* TRANS: _Conquer Extras (100% chance of success). */
6978 return N_("%sConquer Extras%s");
6980 /* TRANS: _Conquer Extras 2 (100% chance of success). */
6981 return N_("%sConquer Extras 2%s");
6982 case ACTION_HEAL_UNIT:
6983 case ACTION_HEAL_UNIT2:
6984 /* TRANS: Heal _Unit (3% chance of success). */
6985 return N_("Heal %sUnit%s");
6987 /* TRANS: _Transform Terrain (3% chance of success). */
6988 return N_("%sTransform Terrain%s");
6989 case ACTION_CULTIVATE:
6990 /* TRANS: Transform by _Cultivating (3% chance of success). */
6991 return N_("Transform by %sCultivating%s");
6992 case ACTION_PLANT:
6993 /* TRANS: Transform by _Planting (3% chance of success). */
6994 return N_("Transform by %sPlanting%s");
6995 case ACTION_PILLAGE:
6996 /* TRANS: Pilla_ge (100% chance of success). */
6997 return N_("Pilla%sge%s");
6998 case ACTION_CLEAN:
6999 /* TRANS: Clean (100% chance of success). */
7000 return N_("%sClean%s");
7001 case ACTION_FORTIFY:
7002 /* TRANS: _Fortify (100% chance of success). */
7003 return N_("%sFortify%s");
7004 case ACTION_ROAD:
7005 /* TRANS: Build _Road (100% chance of success). */
7006 return N_("Build %sRoad%s");
7007 case ACTION_CONVERT:
7008 /* TRANS: _Convert Unit (100% chance of success). */
7009 return N_("%sConvert Unit%s");
7010 case ACTION_BASE:
7011 /* TRANS: _Build Base (100% chance of success). */
7012 return N_("%sBuild Base%s");
7013 case ACTION_MINE:
7014 /* TRANS: Build _Mine (100% chance of success). */
7015 return N_("Build %sMine%s");
7016 case ACTION_IRRIGATE:
7017 /* TRANS: Build _Irrigation (100% chance of success). */
7018 return N_("Build %sIrrigation%s");
7020 /* TRANS: _Deboard (100% chance of success). */
7021 return N_("%sDeboard%s");
7025 /* TRANS: _Board (100% chance of success). */
7026 return N_("%sBoard%s");
7031 /* TRANS: _Embark (100% chance of success). */
7032 return N_("%sEmbark%s");
7034 /* TRANS: _Unload (100% chance of success). */
7035 return N_("%sUnload%s");
7039 /* TRANS: _Load (100% chance of success). */
7040 return N_("%sLoad%s");
7044 /* TRANS: _Disembark (100% chance of success). */
7045 return N_("%sDisembark%s");
7047 /* TRANS: _Disembark 2 (100% chance of success). */
7048 return N_("%sDisembark 2%s");
7049 case ACTION_SPY_ATTACK:
7050 /* TRANS: _Eliminate Diplomat (100% chance of success). */
7051 return N_("%sEliminate Diplomat%s");
7052 case ACTION_HUT_ENTER:
7053 case ACTION_HUT_ENTER2:
7054 case ACTION_HUT_ENTER3:
7055 case ACTION_HUT_ENTER4:
7056 /* TRANS: Enter _Hut (100% chance of success). */
7057 return N_("Enter %sHut%s");
7062 /* TRANS: Frighten _Hut (100% chance of success). */
7063 return N_("Frighten %sHut%s");
7064 case ACTION_UNIT_MOVE:
7065 case ACTION_UNIT_MOVE2:
7066 case ACTION_UNIT_MOVE3:
7067 /* TRANS: Regular _Move (100% chance of success). */
7068 return N_("Regular %sMove%s");
7069 case ACTION_TELEPORT:
7070 /* TRANS: _Teleport (100% chance of success). */
7071 return N_("%sTeleport%s");
7073 /* TRANS: _Teleport (100% chance of success). */
7074 return N_("%sTeleport%s");
7076 /* TRANS: _Teleport (100% chance of success). */
7077 return N_("%sTeleport%s");
7079 /* TRANS: _Teleport (100% chance of success). */
7080 return N_("%sTeleport%s");
7082 /* TRANS: _Teleport (100% chance of success). */
7083 return N_("%sTeleport%s");
7085 /* TRANS: _Teleport (100% chance of success). */
7086 return N_("%sTeleport%s");
7087 case ACTION_SPY_ESCAPE:
7088 /* TRANS: _Escape To Nearest City (100% chance of success). */
7089 return N_("%sEscape To Nearest City%s");
7091 /* TRANS: _User Action 1 (100% chance of success). */
7092 return N_("%sUser Action 1%s");
7094 /* TRANS: _User Action 2 (100% chance of success). */
7095 return N_("%sUser Action 2%s");
7097 /* TRANS: _User Action 3 (100% chance of success). */
7098 return N_("%sUser Action 3%s");
7100 /* TRANS: _User Action 4 (100% chance of success). */
7101 return N_("%sUser Action 4%s");
7102 case ACTION_COUNT:
7103 fc_assert(act != ACTION_COUNT);
7104 break;
7105 }
7106
7107 return NULL;
7108}
7109
7110/**********************************************************************/
7117{
7118 switch ((enum gen_action)act) {
7119 case ACTION_SPY_POISON:
7143 case ACTION_STEAL_MAPS:
7145 case ACTION_TRADE_ROUTE:
7146 case ACTION_MARKETPLACE:
7147 case ACTION_HELP_WONDER:
7149 case ACTION_EXPEL_UNIT:
7150 case ACTION_FOUND_CITY:
7151 case ACTION_JOIN_CITY:
7152 case ACTION_SPY_NUKE:
7157 case ACTION_HOME_CITY:
7158 case ACTION_HOMELESS:
7160 case ACTION_PARADROP:
7166 case ACTION_AIRLIFT:
7167 case ACTION_ATTACK:
7168 case ACTION_ATTACK2:
7171 case ACTION_WIPE_UNITS:
7179 case ACTION_HEAL_UNIT:
7180 case ACTION_HEAL_UNIT2:
7182 case ACTION_CULTIVATE:
7183 case ACTION_PLANT:
7184 case ACTION_PILLAGE:
7185 case ACTION_CLEAN:
7186 case ACTION_FORTIFY:
7187 case ACTION_ROAD:
7188 case ACTION_CONVERT:
7189 case ACTION_BASE:
7190 case ACTION_MINE:
7191 case ACTION_IRRIGATE:
7208 case ACTION_BOMBARD:
7209 case ACTION_BOMBARD2:
7210 case ACTION_BOMBARD3:
7211 case ACTION_BOMBARD4:
7214 case ACTION_SPY_ATTACK:
7219 case ACTION_HUT_ENTER:
7220 case ACTION_HUT_ENTER2:
7221 case ACTION_HUT_ENTER3:
7222 case ACTION_HUT_ENTER4:
7227 case ACTION_UNIT_MOVE:
7228 case ACTION_UNIT_MOVE2:
7229 case ACTION_UNIT_MOVE3:
7230 case ACTION_SPY_ESCAPE:
7231 /* Min range is not ruleset changeable */
7232 return NULL;
7233 case ACTION_NUKE:
7234 return "explode_nuclear_min_range";
7235 case ACTION_NUKE_CITY:
7236 return "nuke_city_min_range";
7237 case ACTION_NUKE_UNITS:
7238 return "nuke_units_min_range";
7239 case ACTION_TELEPORT:
7240 return "teleport_min_range";
7242 return "teleport_conquer_min_range";
7244 return "teleport_frighten_min_range";
7246 return "teleport_frighten_conquer_min_range";
7248 return "teleport_enter_min_range";
7250 return "teleport_enter_conquer_min_range";
7252 return "user_action_1_min_range";
7254 return "user_action_2_min_range";
7256 return "user_action_3_min_range";
7258 return "user_action_4_min_range";
7259 case ACTION_COUNT:
7260 break;
7261
7263 }
7264
7265 fc_assert(act >= 0 && act < ACTION_COUNT);
7266
7267 return NULL;
7268}
7269
7270/**********************************************************************/
7277{
7278 switch ((enum gen_action)act) {
7279 case ACTION_SPY_POISON:
7303 case ACTION_STEAL_MAPS:
7305 case ACTION_TRADE_ROUTE:
7306 case ACTION_MARKETPLACE:
7308 case ACTION_EXPEL_UNIT:
7309 case ACTION_FOUND_CITY:
7310 case ACTION_JOIN_CITY:
7311 case ACTION_SPY_NUKE:
7315 case ACTION_HOME_CITY:
7316 case ACTION_HOMELESS:
7318 case ACTION_PARADROP:
7324 case ACTION_ATTACK:
7325 case ACTION_ATTACK2:
7328 case ACTION_WIPE_UNITS:
7336 case ACTION_HEAL_UNIT:
7337 case ACTION_HEAL_UNIT2:
7339 case ACTION_CULTIVATE:
7340 case ACTION_PLANT:
7341 case ACTION_PILLAGE:
7342 case ACTION_CLEAN:
7343 case ACTION_FORTIFY:
7344 case ACTION_ROAD:
7345 case ACTION_CONVERT:
7346 case ACTION_BASE:
7347 case ACTION_MINE:
7348 case ACTION_IRRIGATE:
7365 case ACTION_SPY_ATTACK:
7370 case ACTION_HUT_ENTER:
7371 case ACTION_HUT_ENTER2:
7372 case ACTION_HUT_ENTER3:
7373 case ACTION_HUT_ENTER4:
7378 case ACTION_UNIT_MOVE:
7379 case ACTION_UNIT_MOVE2:
7380 case ACTION_UNIT_MOVE3:
7381 case ACTION_SPY_ESCAPE:
7382 /* Max range is not ruleset changeable */
7383 return NULL;
7384 case ACTION_HELP_WONDER:
7385 return "help_wonder_max_range";
7387 return "disband_unit_recover_max_range";
7388 case ACTION_BOMBARD:
7389 return "bombard_max_range";
7390 case ACTION_BOMBARD2:
7391 return "bombard_2_max_range";
7392 case ACTION_BOMBARD3:
7393 return "bombard_3_max_range";
7394 case ACTION_BOMBARD4:
7395 return "bombard_4_max_range";
7397 return "bombard_lethal_max_range";
7399 return "bombard_lethal_2_max_range";
7400 case ACTION_NUKE:
7401 return "explode_nuclear_max_range";
7402 case ACTION_NUKE_CITY:
7403 return "nuke_city_max_range";
7404 case ACTION_NUKE_UNITS:
7405 return "nuke_units_max_range";
7406 case ACTION_AIRLIFT:
7407 return "airlift_max_range";
7408 case ACTION_TELEPORT:
7409 return "teleport_max_range";
7411 return "teleport_conquer_max_range";
7413 return "teleport_frighten_max_range";
7415 return "teleport_frighten_conquer_max_range";
7417 return "teleport_enter_max_range";
7419 return "teleport_enter_conquer_max_range";
7421 return "user_action_1_max_range";
7423 return "user_action_2_max_range";
7425 return "user_action_3_max_range";
7427 return "user_action_4_max_range";
7428 case ACTION_COUNT:
7429 break;
7430
7432 }
7433
7434 fc_assert(act >= 0 && act < ACTION_COUNT);
7435
7436 return NULL;
7437}
7438
7439/**********************************************************************/
7446{
7447 switch ((enum gen_action)act) {
7448 case ACTION_SPY_POISON:
7472 case ACTION_STEAL_MAPS:
7474 case ACTION_TRADE_ROUTE:
7475 case ACTION_MARKETPLACE:
7476 case ACTION_HELP_WONDER:
7478 case ACTION_EXPEL_UNIT:
7479 case ACTION_FOUND_CITY:
7480 case ACTION_JOIN_CITY:
7481 case ACTION_SPY_NUKE:
7483 case ACTION_NUKE_UNITS:
7487 case ACTION_HOME_CITY:
7488 case ACTION_HOMELESS:
7490 case ACTION_PARADROP:
7496 case ACTION_AIRLIFT:
7497 case ACTION_ATTACK:
7498 case ACTION_ATTACK2:
7501 case ACTION_WIPE_UNITS:
7509 case ACTION_HEAL_UNIT:
7510 case ACTION_HEAL_UNIT2:
7512 case ACTION_CULTIVATE:
7513 case ACTION_PLANT:
7514 case ACTION_CLEAN:
7515 case ACTION_FORTIFY:
7516 case ACTION_ROAD:
7517 case ACTION_CONVERT:
7518 case ACTION_BASE:
7519 case ACTION_MINE:
7520 case ACTION_IRRIGATE:
7537 case ACTION_BOMBARD:
7538 case ACTION_BOMBARD2:
7539 case ACTION_BOMBARD3:
7540 case ACTION_BOMBARD4:
7543 case ACTION_SPY_ATTACK:
7548 case ACTION_HUT_ENTER:
7549 case ACTION_HUT_ENTER2:
7550 case ACTION_HUT_ENTER3:
7551 case ACTION_HUT_ENTER4:
7556 case ACTION_UNIT_MOVE:
7557 case ACTION_UNIT_MOVE2:
7558 case ACTION_UNIT_MOVE3:
7559 case ACTION_TELEPORT:
7565 case ACTION_SPY_ESCAPE:
7566 /* Target kind is not ruleset changeable */
7567 return NULL;
7568 case ACTION_NUKE:
7569 return "explode_nuclear_target_kind";
7570 case ACTION_NUKE_CITY:
7571 return "nuke_city_target_kind";
7572 case ACTION_PILLAGE:
7573 return "pillage_target_kind";
7575 return "user_action_1_target_kind";
7577 return "user_action_2_target_kind";
7579 return "user_action_3_target_kind";
7581 return "user_action_4_target_kind";
7582 case ACTION_COUNT:
7583 break;
7584
7586 }
7587
7588 fc_assert(act >= 0 && act < ACTION_COUNT);
7589
7590 return NULL;
7591}
7592
7593/**********************************************************************/
7601{
7602 switch ((enum gen_action)act) {
7603 case ACTION_SPY_POISON:
7626 case ACTION_STEAL_MAPS:
7628 case ACTION_TRADE_ROUTE:
7629 case ACTION_MARKETPLACE:
7630 case ACTION_HELP_WONDER:
7632 case ACTION_EXPEL_UNIT:
7633 case ACTION_JOIN_CITY:
7634 case ACTION_SPY_NUKE:
7639 case ACTION_HOME_CITY:
7640 case ACTION_HOMELESS:
7642 case ACTION_PARADROP:
7648 case ACTION_AIRLIFT:
7649 case ACTION_ATTACK:
7650 case ACTION_ATTACK2:
7653 case ACTION_WIPE_UNITS:
7661 case ACTION_HEAL_UNIT:
7662 case ACTION_HEAL_UNIT2:
7664 case ACTION_CULTIVATE:
7665 case ACTION_PLANT:
7666 case ACTION_PILLAGE:
7667 case ACTION_CLEAN:
7668 case ACTION_FORTIFY:
7669 case ACTION_ROAD:
7670 case ACTION_CONVERT:
7671 case ACTION_BASE:
7672 case ACTION_MINE:
7673 case ACTION_IRRIGATE:
7690 case ACTION_BOMBARD:
7691 case ACTION_BOMBARD2:
7692 case ACTION_BOMBARD3:
7693 case ACTION_BOMBARD4:
7696 case ACTION_SPY_ATTACK:
7701 case ACTION_HUT_ENTER:
7702 case ACTION_HUT_ENTER2:
7703 case ACTION_HUT_ENTER3:
7704 case ACTION_HUT_ENTER4:
7709 case ACTION_UNIT_MOVE:
7710 case ACTION_UNIT_MOVE2:
7711 case ACTION_UNIT_MOVE3:
7712 case ACTION_TELEPORT:
7718 case ACTION_SPY_ESCAPE:
7719 /* Actor consuming always is not ruleset changeable */
7720 return NULL;
7721 case ACTION_FOUND_CITY:
7722 return "found_city_consuming_always";
7723 case ACTION_NUKE:
7724 return "explode_nuclear_consuming_always";
7725 case ACTION_NUKE_CITY:
7726 return "nuke_city_consuming_always";
7727 case ACTION_NUKE_UNITS:
7728 return "nuke_units_consuming_always";
7730 return "spread_plague_actor_consuming_always";
7732 return "user_action_1_actor_consuming_always";
7734 return "user_action_2_actor_consuming_always";
7736 return "user_action_3_actor_consuming_always";
7738 return "user_action_4_actor_consuming_always";
7739 case ACTION_COUNT:
7740 break;
7741
7743 }
7744
7745 fc_assert(act >= 0 && act < ACTION_COUNT);
7746
7747 return NULL;
7748}
7749
7750/**********************************************************************/
7757const char *action_blocked_by_ruleset_var_name(const struct action *act)
7758{
7759 fc_assert_ret_val(act != NULL, NULL);
7760
7761 switch ((enum gen_action)action_number(act)) {
7762 case ACTION_MARKETPLACE:
7763 return "enter_marketplace_blocked_by";
7764 case ACTION_BOMBARD:
7765 return "bombard_blocked_by";
7766 case ACTION_BOMBARD2:
7767 return "bombard_2_blocked_by";
7768 case ACTION_BOMBARD3:
7769 return "bombard_3_blocked_by";
7770 case ACTION_BOMBARD4:
7771 return "bombard_4_blocked_by";
7773 return "bombard_lethal_blocked_by";
7775 return "bombard_lethal_2_blocked_by";
7776 case ACTION_NUKE:
7777 return "explode_nuclear_blocked_by";
7778 case ACTION_NUKE_CITY:
7779 return "nuke_city_blocked_by";
7780 case ACTION_NUKE_UNITS:
7781 return "nuke_units_blocked_by";
7782 case ACTION_ATTACK:
7783 return "attack_blocked_by";
7784 case ACTION_ATTACK2:
7785 return "attack_2_blocked_by";
7787 return "suicide_attack_blocked_by";
7789 return "suicide_attack_2_blocked_by";
7790 case ACTION_WIPE_UNITS:
7791 return "wipe_units_blocked_by";
7793 return "collect_ransom_blocked_by";
7795 return "conquer_city_blocked_by";
7797 return "conquer_city_2_blocked_by";
7799 return "conquer_city_3_blocked_by";
7801 return "conquer_city_4_blocked_by";
7802 case ACTION_UNIT_MOVE:
7803 return "move_blocked_by";
7804 case ACTION_UNIT_MOVE2:
7805 return "move_2_blocked_by";
7806 case ACTION_UNIT_MOVE3:
7807 return "move_3_blocked_by";
7808 case ACTION_TELEPORT:
7809 return "teleport_blocked_by";
7811 return "teleport_conquer_blocked_by";
7813 return "teleport_frighten_blocked_by";
7815 return "teleport_frighten_conquer_blocked_by";
7817 return "teleport_enter_blocked_by";
7819 return "teleport_enter_conquer_blocked_by";
7820 case ACTION_SPY_ESCAPE:
7821 case ACTION_SPY_POISON:
7844 case ACTION_STEAL_MAPS:
7846 case ACTION_TRADE_ROUTE:
7847 case ACTION_HELP_WONDER:
7849 case ACTION_EXPEL_UNIT:
7850 case ACTION_FOUND_CITY:
7851 case ACTION_JOIN_CITY:
7852 case ACTION_SPY_NUKE:
7857 case ACTION_HOME_CITY:
7858 case ACTION_HOMELESS:
7860 case ACTION_PARADROP:
7866 case ACTION_AIRLIFT:
7869 case ACTION_HEAL_UNIT:
7870 case ACTION_HEAL_UNIT2:
7872 case ACTION_CULTIVATE:
7873 case ACTION_PLANT:
7874 case ACTION_PILLAGE:
7875 case ACTION_CLEAN:
7876 case ACTION_FORTIFY:
7877 case ACTION_ROAD:
7878 case ACTION_CONVERT:
7879 case ACTION_BASE:
7880 case ACTION_MINE:
7881 case ACTION_IRRIGATE:
7899 case ACTION_SPY_ATTACK:
7904 case ACTION_HUT_ENTER:
7905 case ACTION_HUT_ENTER2:
7906 case ACTION_HUT_ENTER3:
7907 case ACTION_HUT_ENTER4:
7916 /* blocked_by is not ruleset changeable */
7917 return NULL;
7918 case ACTION_COUNT:
7920 break;
7921
7923 }
7924
7925 return NULL;
7926}
7927
7928/**********************************************************************/
7932const char *
7934{
7935 fc_assert_ret_val(act != NULL, NULL);
7936
7941 /* No support in the action performer function */
7942 return NULL;
7943 }
7944
7945 switch ((enum gen_action)action_number(act)) {
7947 return "bribe_unit_post_success_forced_actions";
7948 case ACTION_ATTACK:
7949 return "attack_post_success_forced_actions";
7950 case ACTION_ATTACK2:
7951 return "attack_2_post_success_forced_actions";
7952 case ACTION_WIPE_UNITS:
7953 return "wipe_units_post_success_forced_actions";
7955 return "collect_ransom_post_success_forced_actions";
7956 case ACTION_MARKETPLACE:
7957 case ACTION_BOMBARD:
7958 case ACTION_BOMBARD2:
7959 case ACTION_BOMBARD3:
7960 case ACTION_BOMBARD4:
7963 case ACTION_NUKE:
7964 case ACTION_NUKE_CITY:
7965 case ACTION_NUKE_UNITS:
7972 case ACTION_SPY_POISON:
7994 case ACTION_STEAL_MAPS:
7996 case ACTION_TRADE_ROUTE:
7997 case ACTION_HELP_WONDER:
7999 case ACTION_EXPEL_UNIT:
8000 case ACTION_FOUND_CITY:
8001 case ACTION_JOIN_CITY:
8002 case ACTION_SPY_NUKE:
8007 case ACTION_HOME_CITY:
8008 case ACTION_HOMELESS:
8010 case ACTION_PARADROP:
8016 case ACTION_AIRLIFT:
8019 case ACTION_HEAL_UNIT:
8020 case ACTION_HEAL_UNIT2:
8022 case ACTION_CULTIVATE:
8023 case ACTION_PLANT:
8024 case ACTION_PILLAGE:
8025 case ACTION_CLEAN:
8026 case ACTION_FORTIFY:
8027 case ACTION_ROAD:
8028 case ACTION_CONVERT:
8029 case ACTION_BASE:
8030 case ACTION_MINE:
8031 case ACTION_IRRIGATE:
8049 case ACTION_SPY_ATTACK:
8054 case ACTION_HUT_ENTER:
8055 case ACTION_HUT_ENTER2:
8056 case ACTION_HUT_ENTER3:
8057 case ACTION_HUT_ENTER4:
8062 case ACTION_UNIT_MOVE:
8063 case ACTION_UNIT_MOVE2:
8064 case ACTION_UNIT_MOVE3:
8065 case ACTION_TELEPORT:
8071 case ACTION_SPY_ESCAPE:
8076 /* Not ruleset changeable */
8077 return NULL;
8078 case ACTION_COUNT:
8080 break;
8081
8083 }
8084
8085 return NULL;
8086}
8087
8088/**********************************************************************/
8096
8097/**********************************************************************/
8100const char *gen_action_name_update_cb(const char *old_name)
8101{
8102 if (is_ruleset_compat_mode()) {
8103 if (!fc_strcasecmp("Transport Alight", old_name)) {
8104 return "Transport Deboard";
8105 }
8106 }
8107
8108 return old_name;
8109}
8110
8112{
8113 N_("individual cities"), /* ATK_CITY */
8114 N_("individual units"), /* ATK_UNIT */
8115 N_("unit stacks"), /* ATK_UNITS */
8116 N_("tiles"), /* ATK_TILE */
8117 N_("tile extras"), /* ATK_EXTRAS */
8118 N_("itself") /* ATK_SELF */
8119};
8120
8121/**********************************************************************/
8126{
8127 fc_assert(kind >= 0 && kind < ATK_COUNT);
8128
8129 return _(atk_helpnames[kind]);
8130}
8131
8132/************************************************************************/
8136{
8137 fc_assert(result < ACTRES_LAST);
8138
8139 return actlist_by_result[result];
8140}
8141
8142/************************************************************************/
8146{
8147 fc_assert(activity < ACTIVITY_LAST);
8148
8149 return actlist_by_activity[activity];
8150}
bool is_action_possible_on_city(action_id act_id, const struct player *actor_player, const struct city *target_city)
Definition actions.c:6214
static struct action * actions[MAX_NUM_ACTIONS]
Definition actions.c:97
const char * action_prepare_ui_name(action_id act_id, const char *mnemonic, const struct act_prob prob, const char *custom)
Definition actions.c:2073
const char * action_name_translation(const struct action *action)
Definition actions.c:1991
bool action_distance_inside_max(const struct action *action, const int distance)
Definition actions.c:1934
static void oblig_hard_req_reg(struct ae_contra_or *contras, const char *error_message,...)
Definition actions.c:247
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:5709
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:3562
static void voblig_hard_req_reg(struct ae_contra_or *contras, const char *error_message, va_list args)
Definition actions.c:203
const char * action_prob_explain(const struct act_prob prob)
Definition actions.c:2184
bool action_mp_full_makes_legal(const struct unit *actor, const action_id act_id)
Definition actions.c:6292
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:4528
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:4179
enum action_actor_kind action_get_actor_kind(const struct action *paction)
Definition actions.c:1859
bool action_prob_certain(const struct act_prob probability)
Definition actions.c:5831
const char * action_id_name_translation(action_id act_id)
Definition actions.c:2011
struct action_auto_perf * action_auto_perf_slot_number(const int num)
Definition actions.c:6421
req_vec_num_in_item action_enabler_vector_number(const void *enabler, const struct requirement_vector *vec)
Definition actions.c:2809
bool action_has_complex_target(const struct action *paction)
Definition actions.c:1893
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:3149
static struct obligatory_req_vector oblig_hard_reqs_r[ACTRES_NONE]
Definition actions.c:105
struct req_vec_problem * action_enabler_suggest_repair(const struct action_enabler *enabler)
Definition actions.c:2679
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:4024
bool action_prob_possible(const struct act_prob probability)
Definition actions.c:5821
#define ACTPROB_VAL_NOT_IMPL
Definition actions.c:95
struct action_auto_perf auto_perfs[MAX_NUM_ACTION_AUTO_PERFORMERS]
Definition actions.c:99
bool action_actor_utype_hard_reqs_ok(const struct action *paction, const struct unit_type *actor_unittype)
Definition actions.c:3356
struct act_prob action_prob_new_not_impl(void)
Definition actions.c:5800
struct req_vec_problem * action_enabler_suggest_improvement(const struct action_enabler *enabler)
Definition actions.c:2745
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:4259
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:5642
void actions_rs_pre_san_gen(void)
Definition actions.c:1654
const char * action_min_range_ruleset_var_name(int act)
Definition actions.c:7116
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:5743
const char * action_blocked_by_ruleset_var_name(const struct action *act)
Definition actions.c:7757
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:3737
#define ACTPROB_VAL_MAX
Definition actions.c:89
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:4576
struct req_vec_problem * action_enabler_suggest_repair_oblig(const struct action_enabler *enabler)
Definition actions.c:2439
void action_array_add_all_by_result(action_id *act_array, int *position, enum action_result result)
Definition actions.c:6486
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:6121
void action_array_end(action_id *act_array, int size)
Definition actions.c:6469
static struct ae_contra_or * req_contradiction_or(int alternatives,...)
Definition actions.c:155
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:5342
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:4484
const char * atk_helpnames[ATK_COUNT]
Definition actions.c:8111
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:3376
static void hard_code_actions(void)
Definition actions.c:924
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:3776
bool action_is_in_use(struct action *paction)
Definition actions.c:6398
static struct req_vec_problem * enabler_tile_tgt_local_diplrel_implies_claimed(const struct action_enabler *enabler)
Definition actions.c:2534
bool action_ever_possible(action_id action)
Definition actions.c:8092
const char * action_enabler_vector_by_number_name(req_vec_num_in_item vec)
Definition actions.c:2856
bool are_action_probabilitys_equal(const struct act_prob *ap1, const struct act_prob *ap2)
Definition actions.c:5872
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:5442
const char * action_post_success_forced_ruleset_var_name(const struct action *act)
Definition actions.c:7933
struct action * action_by_rule_name(const char *name)
Definition actions.c:1840
static bool action_has_possible_actor_hard_reqs(struct action *paction)
Definition actions.c:6373
const char * action_rule_name(const struct action *action)
Definition actions.c:1977
const char * action_id_rule_name(action_id act_id)
Definition actions.c:2000
enum action_sub_target_kind action_get_sub_target_kind(const struct action *paction)
Definition actions.c:1880
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:2924
static bool action_prob_not_relevant(const struct act_prob probability)
Definition actions.c:5842
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:4438
void actions_free(void)
Definition actions.c:1664
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:4101
void action_enabler_free(struct action_enabler *enabler)
Definition actions.c:2255
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:4006
static void ae_contra_close(struct ae_contra_or *contra)
Definition actions.c:184
static enum fc_tristate tech_can_be_stolen(const struct player *actor_player, const struct player *target_player)
Definition actions.c:4325
static struct action_list * actlist_by_result[ACTRES_LAST]
Definition actions.c:141
static struct obligatory_req_vector oblig_hard_reqs_sr[ACT_SUB_RES_COUNT]
Definition actions.c:106
static void oblig_hard_req_reg_sub_res(struct ae_contra_or *contras, const char *error_message,...)
Definition actions.c:336
struct action_list * action_list_by_activity(enum unit_activity activity)
Definition actions.c:8145
int action_number(const struct action *action)
Definition actions.c:1969
struct act_prob action_prob_new_unknown(void)
Definition actions.c:5810
bool action_would_be_blocked_by(const struct action *blocked, const struct action *blocker)
Definition actions.c:1957
#define ACTPROB_VAL_NA
Definition actions.c:93
static struct req_vec_problem * enabler_first_clarification(const struct action_enabler *enabler)
Definition actions.c:2727
static bool is_effect_val_known(enum effect_type effect_type, const struct player *pov_player, const struct req_context *context, const struct player *other_player)
Definition actions.c:4305
static bool action_prob_not_impl(const struct act_prob probability)
Definition actions.c:5853
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:4082
struct act_prob action_prob_and(const struct act_prob *ap1, const struct act_prob *ap2)
Definition actions.c:5959
static bool actions_initialized
Definition actions.c:100
const char * action_actor_consuming_always_ruleset_var_name(action_id act)
Definition actions.c:7600
bool action_immune_government(struct government *gov, action_id act)
Definition actions.c:6173
static void voblig_hard_req_reg_sub_res(struct ae_contra_or *contras, const char *error_message, va_list args)
Definition actions.c:294
static bool is_target_possible(const action_id wanted_action, const struct player *actor_player, const struct req_context *target)
Definition actions.c:6196
static struct act_prob ap_dipl_battle_win(const struct unit *pattacker, const struct unit *pdefender)
Definition actions.c:4361
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:5084
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:5425
struct act_prob action_prob_new_certain(void)
Definition actions.c:5780
const char * action_max_range_ruleset_var_name(int act)
Definition actions.c:7276
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:4897
int action_dice_roll_initial_odds(const struct action *paction)
Definition actions.c:6097
struct act_prob action_prob_self(const struct civ_map *nmap, const struct unit *actor_unit, const action_id act_id)
Definition actions.c:5495
struct act_prob action_prob_fall_back(const struct act_prob *ap1, const struct act_prob *ap2)
Definition actions.c:6029
#define obligatory_req_vector_iterate_end
Definition actions.c:77
static const struct unit_type * tgt_city_local_utype(const struct city *target_city)
Definition actions.c:2899
static struct requirement * req_vec_first_local_diplrel(const struct requirement_vector *vec)
Definition actions.c:2490
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:5276
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:3841
struct action_list * action_list_by_result(enum action_result result)
Definition actions.c:8135
bool action_univs_not_blocking(const struct action *paction, struct universal *actor_uni, struct universal *target_uni)
Definition actions.c:6445
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:5574
static struct requirement * req_vec_first_contradiction_in_vec(const struct requirement *req, const struct requirement_vector *vec)
Definition actions.c:2511
bool actions_are_ready(void)
Definition actions.c:1717
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:3918
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:5675
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:4984
const char * action_target_kind_ruleset_var_name(int act)
Definition actions.c:7445
#define obligatory_req_vector_iterate(obreq_vec, pobreq)
Definition actions.c:75
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:5000
bool action_maybe_possible_actor_unit(const struct civ_map *nmap, const action_id act_id, const struct unit *actor_unit)
Definition actions.c:6237
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:3036
static bool is_enabler_active(const struct action_enabler *enabler, const struct req_context *actor, const struct req_context *target)
Definition actions.c:3718
static struct action_enabler_list * action_enablers_by_action[MAX_NUM_ACTIONS]
Definition actions.c:102
void action_enabler_add(struct action_enabler *enabler)
Definition actions.c:2282
static void hard_code_oblig_hard_reqs(void)
Definition actions.c:354
const char * action_ui_name_default(int act)
Definition actions.c:6773
#define ACTPROB_VAL_1_PCT
Definition actions.c:91
bool action_enabler_utype_possible_actor(const struct action_enabler *ae, const struct unit_type *act_utype)
Definition actions.c:6315
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:4466
struct action_enabler * action_enabler_new(void)
Definition actions.c:2236
bool action_requires_details(const struct action *paction)
Definition actions.c:1906
struct act_prob action_prob_new_not_relevant(void)
Definition actions.c:5790
const char * action_target_kind_help(enum action_target_kind kind)
Definition actions.c:8125
static struct req_vec_problem * enabler_first_self_contradiction(const struct action_enabler *enabler)
Definition actions.c:2607
int action_get_role(const struct action *paction)
Definition actions.c:2224
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:5609
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:1804
const struct action_auto_perf * action_auto_perf_by_number(const int num)
Definition actions.c:6437
struct act_prob action_prob_new_impossible(void)
Definition actions.c:5770
bool action_enabler_possible_actor(const struct action_enabler *ae)
Definition actions.c:6342
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:2982
struct action ** _actions
Definition actions.c:98
bool action_id_exists(const action_id act_id)
Definition actions.c:1829
bool action_enabler_remove(struct action_enabler *enabler)
Definition actions.c:2299
enum action_target_kind action_get_target_kind(const struct action *paction)
Definition actions.c:1869
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:5517
static bool action_prob_is_signal(const struct act_prob probability)
Definition actions.c:5864
struct action_enabler * action_enabler_copy(const struct action_enabler *original)
Definition actions.c:2267
static const char * action_prob_to_text(const struct act_prob prob)
Definition actions.c:2032
int action_prob_cmp_pessimist(const struct act_prob ap1, const struct act_prob ap2)
Definition actions.c:5881
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:5259
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:4231
bool action_id_is_rare_pop_up(action_id act_id)
Definition actions.c:1921
void actions_init(void)
Definition actions.c:1594
static struct action * action_new(action_id id, enum action_result result, const int min_distance, const int max_distance, bool actor_consuming_always)
Definition actions.c:1741
static void hard_code_oblig_hard_reqs_ruleset(void)
Definition actions.c:887
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:2335
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:5067
static const struct impr_type * tgt_city_local_building(const struct city *target_city)
Definition actions.c:2876
static struct astring ui_name_str
Definition actions.c:108
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:4159
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:3859
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:3936
double action_prob_to_0_to_1_pessimist(const struct act_prob ap)
Definition actions.c:5932
static void oblig_hard_req_register(struct requirement contradiction, bool is_target, const char *error_message,...)
Definition actions.c:267
const char * gen_action_name_update_cb(const char *old_name)
Definition actions.c:8100
static struct action_list * actlist_by_activity[ACTIVITY_LAST]
Definition actions.c:142
struct action_enabler_list * action_enablers_for_action(action_id action)
Definition actions.c:2315
struct requirement_vector * action_enabler_vector_by_number(const void *enabler, req_vec_num_in_item number)
Definition actions.c:2832
bool action_distance_accepted(const struct action *action, const int distance)
Definition actions.c:1945
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:5359
const char * action_ui_name_ruleset_var_name(int act)
Definition actions.c:6506
const char * action_get_ui_name_mnemonic(action_id act_id, const char *mnemonic)
Definition actions.c:2019
#define ACTPROB_VAL_MIN
Definition actions.c:87
#define ACTION_DISTANCE_MAX
Definition actions.h:359
#define enabler_get_action(_enabler_)
Definition actions.h:433
#define ASSERT_UNUSED_ACTION_CASES
Definition actions.h:38
#define ACTPROB_CERTAIN
Definition actions.h:923
#define enabler_get_action_id(_enabler_)
Definition actions.h:434
#define ACTPROB_NA
Definition actions.h:924
static struct action * action_by_number(action_id act_id)
Definition actions.h:635
#define action_enabler_list_re_iterate_end
Definition actions.h:447
#define ACTION_DISTANCE_LAST_NON_SIGNAL
Definition actions.h:355
#define action_enabler_list_re_iterate(action_enabler_list, aenabler)
Definition actions.h:443
#define action_has_result(_act_, _res_)
Definition actions.h:431
#define action_enabler_list_iterate_end
Definition actions.h:441
#define ACTION_DISTANCE_UNLIMITED
Definition actions.h:357
#define action_iterate_end
Definition actions.h:465
#define MAX_NUM_ACTIONS
Definition actions.h:314
#define action_iterate_all(_act_)
Definition actions.h:451
#define action_id_get_actor_kind(act_id)
Definition actions.h:648
#define action_iterate_all_end
Definition actions.h:456
#define ACTPROB_NOT_KNOWN
Definition actions.h:926
#define action_enabler_list_iterate(action_enabler_list, aenabler)
Definition actions.h:439
#define action_id_distance_accepted(act_id, distance)
Definition actions.h:684
#define ACTPROB_IMPOSSIBLE
Definition actions.h:922
#define ACTPROB_NOT_IMPLEMENTED
Definition actions.h:925
#define action_iterate(_act_)
Definition actions.h:461
#define ACTION_ANY
Definition actions.h:308
#define action_id_get_target_kind(act_id)
Definition actions.h:652
#define action_id_has_result_safe(act_id, result)
Definition actions.h:665
#define ACTION_ODDS_PCT_DICE_ROLL_NA
Definition actions.h:929
#define ACTION_NONE
Definition actions.h:311
enum action_sub_target_kind actres_sub_target_kind_default(enum action_result result)
Definition actres.c:666
enum act_tgt_compl actres_target_compl_calc(enum action_result result)
Definition actres.c:255
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:828
enum unit_activity actres_activity_result(enum action_result result)
Definition actres.c:298
enum dice_roll_type actres_dice_type(enum action_result result)
Definition actres.c:361
enum action_battle_kind actres_get_battle_kind(enum action_result result)
Definition actres.c:269
enum action_target_kind actres_target_kind_default(enum action_result result)
Definition actres.c:763
#define ASSERT_UNUSED_ACTRES_CASES
Definition actres.h:37
@ DRT_DIPLCHANCE
Definition actres.h:108
@ DRT_CERTAIN
Definition actres.h:108
@ DRT_NONE
Definition actres.h:108
void astr_free(struct astring *astr)
Definition astring.c:153
void astr_set(struct astring *astr, const char *format,...)
Definition astring.c:267
void astr_clear(struct astring *astr)
Definition astring.c:205
void astr_add(struct astring *astr, const char *format,...)
Definition astring.c:287
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:158
#define BV_CLR_ALL(bv)
Definition bitvector.h:95
#define BV_ISSET(bv, bit)
Definition bitvector.h:78
static bool is_non_attack_city_tile(const struct tile *ptile, const struct player *pplayer)
Definition city.h:758
#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:478
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:256
struct unit * get_defender(const struct civ_map *nmap, const struct unit *attacker, const struct tile *ptile, const struct action *paction)
Definition combat.c:836
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:942
bool can_unit_attack_tile(const struct unit *punit, const struct action *paction, const struct tile *dest_tile)
Definition combat.c:311
@ ATT_OK
Definition combat.h:35
char * enablers
Definition comments.c:56
char * incite_cost
Definition comments.c:75
struct unit struct city struct unit * target_unit
Definition dialogs_g.h:56
struct unit * actor_unit
Definition dialogs_g.h:55
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit * actor
Definition dialogs_g.h:73
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 @21::@22 reqs
int get_target_bonus_effects(struct effect_list *plist, const struct req_context *context, const struct player *other_player, enum effect_type effect_type)
Definition effects.c:748
struct effect_list * get_effects(enum effect_type effect_type)
Definition effects.c:143
#define effect_list_iterate_end
Definition effects.h:406
#define effect_list_iterate(effect_list, peffect)
Definition effects.h:404
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:843
#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:377
@ RPT_CERTAIN
Definition fc_types.h:701
@ RPT_POSSIBLE
Definition fc_types.h:700
int action_id
Definition fc_types.h:389
#define ACTRES_NONE
Definition fc_types.h:327
#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:365
const char * name
Definition inputfile.c:127
#define fc_assert_msg(condition, message,...)
Definition log.h:181
#define fc_assert_ret(condition)
Definition log.h:191
#define log_verbose(message,...)
Definition log.h:109
#define fc_assert(condition)
Definition log.h:176
#define fc_assert_ret_msg(condition, message,...)
Definition log.h:205
#define fc_assert_action_msg(condition, action, message,...)
Definition log.h:201
#define fc_assert_ret_val(condition, val)
Definition log.h:194
#define fc_assert_action(condition, action)
Definition log.h:187
#define log_error(message,...)
Definition log.h:103
#define FC_STATIC_ASSERT(cond, tag)
Definition log.h:235
#define fc_assert_ret_val_msg(condition, val, message,...)
Definition log.h:208
int real_map_distance(const struct tile *tile0, const struct tile *tile1)
Definition map.c:630
#define MAP_DISTANCE_MAX
Definition map.h:646
#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 player *other_player, 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:319
bool is_native_tile(const struct unit_type *punittype, const struct tile *ptile)
Definition movement.c:331
int unit_move_rate(const struct unit *punit)
Definition movement.c:90
bool unit_could_load_at(const struct unit *punit, const struct tile *ptile)
Definition movement.c:911
bool can_unit_type_transport(const struct unit_type *transporter, const struct unit_class *transported)
Definition movement.c:868
bool can_attack_non_native(const struct unit_type *utype)
Definition movement.c:214
Nation_type_id nation_number(const struct nation_type *pnation)
Definition nation.c:486
enum barbarian_type nation_barbarian_type(const struct nation_type *nation)
Definition nation.c:211
#define nations_iterate_end
Definition nation.h:336
#define nations_iterate(NAME_pnation)
Definition nation.h:333
bool can_player_see_tile(const struct player *plr, const struct tile *ptile)
Definition player.c:1091
bool can_player_see_unit(const struct player *pplayer, const struct unit *punit)
Definition player.c:1104
bool pplayers_at_war(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1388
bool player_can_see_city_externals(const struct player *pow_player, const struct city *target_city)
Definition player.c:1164
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1405
bool can_player_see_hypotetic_units_at(const struct player *pplayer, const struct tile *ptile)
Definition player.c:993
bool player_can_trust_tile_has_no_units(const struct player *pplayer, const struct tile *ptile)
Definition player.c:967
bool universal_never_there(const struct universal *source)
const struct req_context * req_context_empty(void)
const char * req_to_fstring(const struct requirement *req, struct astring *astr)
bool universal_fulfills_requirements(bool check_necessary, const struct requirement_vector *reqs, const struct universal *source)
struct req_vec_problem * req_vec_suggest_repair(const struct requirement_vector *vec, requirement_vector_number get_num, const void *parent_item)
struct requirement req_from_values(int type, int range, bool survives, bool present, bool quiet, int value)
bool are_reqs_active(const struct req_context *context, const struct player *other_player, const struct requirement_vector *reqs, const enum req_problem_type prob_type)
bool are_requirements_contradictions(const struct requirement *req1, const struct requirement *req2)
struct req_vec_problem * req_vec_problem_new(int num_suggested_solutions, const char *descr,...)
bool does_req_contradicts_reqs(const struct requirement *req, const struct requirement_vector *vec)
bool req_vec_is_impossible_to_fulfill(const struct requirement_vector *reqs)
struct req_vec_problem * req_vec_suggest_improvement(const struct requirement_vector *vec, requirement_vector_number get_num, const void *parent_item)
#define requirement_fulfilled_by_unit_type(_ut_, _rqs_)
signed char req_vec_num_in_item
req_vec_num_in_item a requirement vectors number in an item.
#define requirement_vector_iterate_end
#define requirement_fulfilled_by_government(_gov_, _rqs_)
#define requirement_vector_iterate(req_vec, preq)
struct research * research_get(const struct player *pplayer)
Definition research.c:128
enum tech_state research_invention_state(const struct research *presearch, Tech_type_id tech)
Definition research.c:619
bool research_invention_gettable(const struct research *presearch, const Tech_type_id tech, bool allow_holes)
Definition research.c:693
server_setting_id server_setting_by_name(const char *name)
int server_setting_value_int_get(server_setting_id id)
enum fc_tristate fc_tristate_and(enum fc_tristate one, enum fc_tristate two)
Definition shared.c:124
fc_tristate
Definition shared.h:46
@ TRI_YES
Definition shared.h:46
@ TRI_NO
Definition shared.h:46
@ TRI_MAYBE
Definition shared.h:46
#define CLIP(lower, current, upper)
Definition shared.h:57
#define MIN(x, y)
Definition shared.h:55
#define MAX(x, y)
Definition shared.h:54
size_t size
Definition specvec.h:72
enum action_auto_perf_cause cause
Definition actions.h:563
action_id alternatives[MAX_NUM_ACTIONS]
Definition actions.h:571
struct requirement req
Definition actions.c:43
action_id action
Definition actions.h:422
struct requirement_vector actor_reqs
Definition actions.h:423
struct requirement_vector target_reqs
Definition actions.h:424
bool unitwaittime_controlled
Definition actions.h:411
action_id id
Definition actions.h:363
bool actor_consuming_always
Definition actions.h:395
bool rare_pop_up
Definition actions.h:408
int max_distance
Definition actions.h:378
bool quiet
Definition actions.h:385
enum action_sub_target_kind sub_target_kind
Definition actions.h:370
enum moves_actor_kind moves_actor
Definition actions.h:415
struct action::@12::@13 is_unit
enum action_result result
Definition actions.h:365
char ui_name[MAX_LEN_NAME]
Definition actions.h:381
bv_action_sub_results sub_results
Definition actions.h:366
enum action_actor_kind actor_kind
Definition actions.h:368
enum act_tgt_compl target_complexity
Definition actions.h:373
bv_actions blocked_by
Definition actions.h:389
union action::@12 actor
enum action_target_kind target_kind
Definition actions.h:369
int min_distance
Definition actions.h:378
struct action_enabler_contradiction * alternative
Definition actions.c:55
int alternatives
Definition actions.c:52
Definition city.h:320
int id
Definition city.h:326
struct tile * tile
Definition city.h:322
struct packet_game_info info
Definition game.h:89
int(* player_tile_city_id_get)(const struct tile *ptile, const struct player *pplayer)
struct ae_contra_or * contras
Definition actions.c:65
const char * error_msg
Definition actions.c:69
bool tech_steal_allow_holes
enum airlifting_style airlifting_style
bool airlift_from_always_enabled
bv_actions diplchance_initial_odds
const struct tile * tile
const struct player * player
const struct unit * unit
const struct city * city
Definition tile.h:50
struct unit_list * units
Definition tile.h:58
struct veteran_system * veteran
Definition unittype.h:544
Definition unit.h:138
int moves_left
Definition unit.h:150
struct tile * tile
Definition unit.h:140
bool paradropped
Definition unit.h:174
const struct unit_type * utype
Definition unit.h:139
enum universals_n kind
Definition fc_types.h:902
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:189
#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:275
#define advance_iterate_end
Definition tech.h:276
bool tile_is_seen(const struct tile *target_tile, const struct player *pow_player)
Definition tile.c:407
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
#define tile_owner(_tile)
Definition tile.h:96
struct unit * unit_transport_get(const struct unit *pcargo)
Definition unit.c:2441
bool unit_can_do_action(const struct unit *punit, const action_id act_id)
Definition unit.c:359
bool unit_transported(const struct unit *pcargo)
Definition unit.c:2425
bool can_unit_unload(const struct unit *pcargo, const struct unit *ptrans)
Definition unit.c:752
bool unit_can_convert(const struct civ_map *nmap, const struct unit *punit)
Definition unit.c:2035
#define unit_tile(_pu)
Definition unit.h:397
#define unit_owner(_pu)
Definition unit.h:396
#define unit_home(_pu_)
Definition unit.h:394
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
#define unit_list_iterate_end
Definition unitlist.h:33
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:123
bool utype_may_act_move_frags(const struct unit_type *punit_type, const action_id act_id, const int move_fragments)
Definition unittype.c:1058
const struct veteran_level * utype_veteran_level(const struct unit_type *punittype, int level)
Definition unittype.c:2597
bool unit_has_type_flag(const struct unit *punit, enum unit_type_flag_id flag)
Definition unittype.c:190
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:996
bool utype_can_do_action(const struct unit_type *putype, const action_id act_id)
Definition unittype.c:371
#define utype_class(_t_)
Definition unittype.h:749
#define L_LAST
Definition unittype.h:439
#define unit_type_iterate(_p)
Definition unittype.h:855
#define unit_type_iterate_end
Definition unittype.h:862
#define U_NOT_OBSOLETED
Definition unittype.h:528