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."),
525
526 /* Why this is a hard requirement: Preserve semantics of the rule that a
527 * *_time of 0 disables the action. */
529 FALSE, FALSE, FALSE,
531 TRUE,
532 N_("All action enablers for %s must require"
533 " that the target"
534 " tile's terrain's irrigation_time"
535 " is above 0. (See \"TerrainAlter\"'s"
536 " \"CanIrrigate\")"),
540 FALSE, FALSE, FALSE,
542 TRUE,
543 N_("All action enablers for %s must require"
544 " that the target"
545 " tile's terrain's mining_time"
546 " is above 0. (See \"TerrainAlter\"'s"
547 " \"CanMine\")"),
551 FALSE, FALSE, FALSE,
553 TRUE,
554 N_("All action enablers for %s must require"
555 " that the target"
556 " tile's terrain's road_time"
557 " is above 0. (See \"TerrainAlter\"'s"
558 " \"CanRoad\")"),
562 FALSE, FALSE, FALSE,
564 TRUE,
565 N_("All action enablers for %s must require"
566 " that the target"
567 " tile's terrain's base_time"
568 " is above 0. (See \"TerrainAlter\"'s"
569 " \"CanBase\")"),
572
573 /* Why this is a hard requirement: Preserve semantics of the NoCities
574 * terrain flag. */
576 FALSE, TRUE, TRUE,
578 TRUE,
579 N_("All action enablers for %s must require that"
580 " the target doesn't have"
581 " the NoCities terrain flag."),
584
585 /* It isn't possible to establish a trade route from a non existing
586 * city. The Freeciv code assumes this applies to Enter Marketplace
587 * too. */
589 FALSE, FALSE, TRUE,
591 FALSE,
592 N_("All action enablers for %s must require"
593 " that the actor has a home city."),
597
598 /* Why this is a hard requirement:
599 * - preserve the semantics of the NonMil unit type flag. */
601 3,
603 FALSE, FALSE, TRUE,
605 FALSE,
608 FALSE,
610 FALSE, TRUE, TRUE,
612 TRUE),
613 /* TRANS: error message for ruledit */
614 N_("All action enablers for %s must require"
615 " that the actor has the NonMil utype flag"
616 " or that the target tile is unclaimed"
617 " or that the diplomatic relation to"
618 " the target tile owner isn't peace."),
622
623 /* Why this is a hard requirement: Preserve semantics of NonMil
624 * flag. Need to replace other uses in game engine before this can
625 * be demoted to a regular unit flag. */
628 FALSE,
629 N_("All action enablers for %s must require"
630 " that the actor doesn't have"
631 " the NonMil utype flag."),
637 2,
640 FALSE,
642 FALSE, TRUE, TRUE,
644 TRUE),
645 /* TRANS: error message for ruledit */
646 N_("All action enablers for %s must require"
647 " no city at the target tile or"
648 " that the actor doesn't have"
649 " the NonMil utype flag."),
652
653 /* Why this is a hard requirement: Preserve semantics of
654 * CanOccupyCity unit class flag. */
656 FALSE, FALSE, TRUE,
658 FALSE,
659 N_("All action enablers for %s must require"
660 " that the actor has"
661 " the CanOccupyCity uclass flag."),
665 2,
667 FALSE, FALSE, TRUE,
669 FALSE,
671 FALSE, TRUE, TRUE,
673 TRUE),
674 /* TRANS: error message for ruledit */
675 N_("All action enablers for %s must require"
676 " no city at the target tile or"
677 " that the actor has"
678 " the CanOccupyCity uclass flag."),
681
682 /* Why this is a hard requirement: Consistency with ACTRES_ATTACK.
683 * Assumed by other locations in the Freeciv code. Examples:
684 * unit_move_to_tile_test(), unit_conquer_city() and do_paradrop(). */
687 FALSE,
688 N_("All action enablers for %s must require"
689 " that the actor is at war with the target."),
693 2,
696 FALSE,
698 FALSE, TRUE, TRUE,
700 TRUE),
701 /* TRANS: error message for ruledit */
702 N_("All action enablers for %s must require"
703 " no city at the target tile or"
704 " that the actor is at war with the target."),
707
708 /* Why this is a hard requirement: a unit must move into a city to
709 * conquer it, move into a transport to embark, move out of a transport
710 * to disembark from it, move into an extra to conquer it and move into a
711 * hut to enter/frighten it. */
713 FALSE, FALSE, TRUE, 1),
714 FALSE,
715 N_("All action enablers for %s must require"
716 " that the actor has a movement point left."),
725
726 /* Why this is a hard requirement: this eliminates the need to
727 * check if units transported by the actor unit can exist at the
728 * same tile as all the units in the occupied city.
729 *
730 * This makes an implicit rule explicit:
731 * 1. A unit must move into a city to conquer it.
732 * 2. It can't move into the city if the tile contains a non-allied
733 * unit (see unit_move_to_tile_test()).
734 * 3. A city could, at the time this rule was made explicit, only
735 * contain units allied to its owner.
736 * 3. A player could, at the time this rule was made explicit, not
737 * be allied to a player that is at war with another ally.
738 * 4. A player could, at the time this rule was made explicit, only
739 * conquer a city belonging to someone they were at war with.
740 * Conclusion: the conquered city had to be empty.
741 */
743 FALSE, FALSE, TRUE, 0),
744 TRUE,
745 N_("All action enablers for %s must require"
746 " that the target city is empty."),
749
750 /* Why this is a hard requirement: Assumed in the code. Corner case
751 * where diplomacy prevents a transported unit to go to the target
752 * tile. The paradrop code doesn't check if transported units can
753 * coexist with the target tile city and units. */
755 FALSE, TRUE, TRUE,
757 FALSE,
758 N_("All action enablers for %s must require"
759 " that the actor isn't transporting"
760 " another unit."),
765
766 /* Why this is a hard requirement: sanity. */
768 FALSE, FALSE, FALSE,
770 FALSE,
771 N_("All action enablers for %s must require"
772 " that the actor has a home city."),
774
775 /* Why this is a hard requirement: Assumed in the code.
776 * See hrm Bug #772516 - https://www.hostedredmine.com/issues/772516 */
778 FALSE, TRUE, TRUE,
780 TRUE,
781 N_("All action enablers for %s must require"
782 " that the target isn't transporting another"
783 " unit."),
785
786 /* Why this is a hard requirement: sanity. */
788 FALSE, FALSE, TRUE,
790 TRUE,
791 N_("All action enablers for %s must require"
792 " that the target is transporting a unit."),
795 FALSE, FALSE, TRUE,
797 FALSE,
798 N_("All action enablers for %s must require"
799 " that the actor is transported."),
804 FALSE, FALSE, TRUE,
806 FALSE,
807 N_("All action enablers for %s must require"
808 " that the actor is on a livable tile."),
810
811 /* Why this is a hard requirement: sanity. */
813 FALSE, FALSE, TRUE,
815 FALSE,
816 N_("All action enablers for %s must require"
817 " that the actor is transporting a unit."),
820 FALSE, FALSE, TRUE,
822 TRUE,
823 N_("All action enablers for %s must require"
824 " that the target is transported."),
827 FALSE, FALSE, TRUE,
829 TRUE,
830 N_("All action enablers for %s must require"
831 " that the target is on a livable tile."),
833
834 /* Why this is a hard requirement: Use ACTRES_TRANSPORT_DISEMBARK to
835 * disembark. Assumed by the Freeciv code. */
837 FALSE, TRUE, TRUE,
839 FALSE,
840 N_("All action enablers for %s must require"
841 " that the actor isn't transported."),
845
846 /* Why this is a hard requirement: assumed by the Freeciv code. */
848 FALSE, FALSE, TRUE,
850 FALSE,
851 N_("All action enablers for %s must require"
852 " that the actor unit is in a city."),
855
856 /* Why this is a hard requirement: Give meaning to the HutFrighten unit
857 * class flag. The point of it is to keep our options open for how both
858 * entering and frightening a hut at the same tile should be handled.
859 * See hrm Feature #920427 */
861 1,
863 FALSE, TRUE, FALSE,
865 FALSE),
866 N_("All action enablers for %s must require"
867 " that the actor unit doesn't have the"
868 " HutFrighten unit class flag."),
872 1,
874 FALSE, FALSE, FALSE,
876 FALSE),
877 N_("All action enablers for %s must require"
878 " that the actor unit has the HutFrighten"
879 " unit class flag."),
882}
883
884/**********************************************************************/
889{
890 /* Why this is a hard requirement: the "animal can't conquer a city"
891 * rule. Assumed in unit_can_take_over(). */
892 nations_iterate(pnation) {
893 if (nation_barbarian_type(pnation) == ANIMAL_BARBARIAN) {
895 FALSE, TRUE, TRUE,
896 nation_number(pnation)),
897 FALSE,
898 N_("All action enablers for %s must require"
899 " a non animal player actor."),
903 2,
905 FALSE, TRUE, TRUE,
906 nation_number(pnation)),
907 FALSE,
909 FALSE, TRUE, TRUE,
911 TRUE),
912 /* TRANS: error message for ruledit */
913 N_("All action enablers for %s must require"
914 " no city at the target tile or"
915 " a non animal player actor."),
918 }
920}
921
922/**********************************************************************/
925static void hard_code_actions(void)
926{
929 FALSE, TRUE,
930 MAK_ESCAPE, 0, 1, TRUE);
933 FALSE, TRUE,
934 MAK_ESCAPE, 0, 1, FALSE);
937 FALSE, TRUE,
938 MAK_ESCAPE, 0, 1, TRUE);
941 FALSE, TRUE,
942 MAK_ESCAPE, 0, 1, FALSE);
945 FALSE, TRUE,
946 /* Tries a forced move if the target unit is alone at
947 * its tile and not in a city. Takes all movement if
948 * the forced move fails. */
950 0, 1, FALSE);
953 FALSE, TRUE,
954 MAK_ESCAPE, 0, 1, TRUE);
957 FALSE, TRUE,
958 MAK_ESCAPE, 0, 1, FALSE);
962 FALSE, TRUE,
963 MAK_ESCAPE, 0, 1, TRUE);
967 FALSE, TRUE,
968 MAK_ESCAPE, 0, 1, TRUE);
972 FALSE, TRUE,
973 MAK_ESCAPE, 0, 1, FALSE);
977 FALSE, TRUE,
978 MAK_ESCAPE, 0, 1, FALSE);
981 FALSE, TRUE,
982 MAK_ESCAPE, 0, 1, TRUE);
985 FALSE, TRUE,
986 MAK_ESCAPE, 0, 1, FALSE);
990 FALSE, TRUE,
991 MAK_STAYS, 0, 1, FALSE);
995 FALSE, TRUE,
996 MAK_STAYS, 0, 1, TRUE);
1000 FALSE, TRUE,
1001 MAK_ESCAPE, 0, 1, TRUE);
1005 FALSE, TRUE,
1006 MAK_ESCAPE, 0, 1, FALSE);
1010 FALSE, TRUE,
1011 MAK_ESCAPE, 0, 1, TRUE);
1015 FALSE, TRUE,
1016 MAK_ESCAPE, 0, 1, FALSE);
1020 FALSE, TRUE,
1021 MAK_STAYS, 0, 1, FALSE);
1025 FALSE, TRUE,
1026 MAK_STAYS, 0, 1, TRUE);
1030 FALSE, TRUE,
1031 MAK_ESCAPE, 0, 1, TRUE);
1035 FALSE, TRUE,
1036 MAK_ESCAPE, 0, 1, FALSE);
1040 FALSE, TRUE,
1041 MAK_ESCAPE, 0, 1, FALSE);
1045 FALSE, TRUE,
1046 MAK_ESCAPE, 0, 1, FALSE);
1049 FALSE, TRUE,
1050 MAK_STAYS, 0, 1, TRUE);
1053 FALSE, TRUE,
1054 MAK_STAYS, 0, 1, TRUE);
1057 FALSE, TRUE,
1058 MAK_STAYS, 0, 1, TRUE);
1062 /* A single domestic unit at the target tile will make
1063 * the action illegal. It must therefore be performed
1064 * from another tile. */
1065 1, 1,
1066 FALSE);
1070 /* Illegal to perform to a target on another tile.
1071 * Reason: The Freeciv code assumes that the city
1072 * founding unit is located at the tile were the new
1073 * city is founded. */
1074 0, 0,
1075 TRUE);
1078 TRUE, TRUE,
1079 MAK_STAYS, 0, 1, TRUE);
1082 FALSE, TRUE,
1083 MAK_ESCAPE, 0, 1, TRUE);
1086 FALSE, TRUE,
1087 MAK_ESCAPE, 0, 1, FALSE);
1091 /* A single domestic unit at the target tile will make
1092 * the action illegal. It must therefore be performed
1093 * from another tile. */
1094 1,
1095 /* Overwritten by the ruleset's bombard_max_range */
1096 1,
1097 FALSE);
1100 FALSE, TRUE,
1101 MAK_STAYS,
1102 /* A single domestic unit at the target tile will make
1103 * the action illegal. It must therefore be performed
1104 * from another tile. */
1105 1,
1106 /* Overwritten by the ruleset's bombard_2_max_range */
1107 1,
1108 FALSE);
1112 /* A single domestic unit at the target tile will make
1113 * the action illegal. It must therefore be performed
1114 * from another tile. */
1115 1,
1116 /* Overwritten by the ruleset's bombard_3_max_range */
1117 1,
1118 FALSE);
1122 /* A single domestic unit at the target tile will make
1123 * the action illegal. It must therefore be performed
1124 * from another tile. */
1125 1,
1126 /* Overwritten by the ruleset's bombard_lethal_max_range */
1127 1,
1128 FALSE);
1132 /* A single domestic unit at the target tile will make
1133 * the action illegal. It must therefore be performed
1134 * from another tile. */
1135 1,
1136 /* Overwritten by the ruleset's bombard_lethal_2_max_range */
1137 1,
1138 FALSE);
1141 FALSE, TRUE,
1142 MAK_ESCAPE, 0, 1, TRUE);
1145 FALSE, TRUE,
1146 MAK_ESCAPE, 0, 1, FALSE);
1149 TRUE, TRUE,
1150 MAK_STAYS, 0,
1151 /* Overwritten by the ruleset's
1152 * explode_nuclear_max_range */
1153 0,
1154 TRUE);
1157 TRUE, TRUE,
1158 MAK_STAYS, 1, 1, TRUE);
1161 TRUE, TRUE,
1162 MAK_STAYS, 1, 1, TRUE);
1165 TRUE, TRUE,
1166 MAK_STAYS, 0, 1, FALSE);
1169 FALSE, TRUE,
1170 MAK_STAYS, 0, 1, FALSE);
1174 /* Illegal to perform to a target on another tile to
1175 * keep the rules exactly as they were for now. */
1176 0, 1,
1177 TRUE);
1180 /* Can't be ACTRES_NONE because
1181 * action_success_actor_consume() sets unit lost
1182 * reason based on action result. */
1184 TRUE, TRUE,
1185 MAK_STAYS, 0, 0, TRUE);
1188 TRUE, FALSE,
1189 /* Illegal to perform to a target on another tile to
1190 * keep the rules exactly as they were for now. */
1191 MAK_STAYS, 0, 0, FALSE);
1194 TRUE, FALSE,
1195 MAK_STAYS, 0, 0, FALSE);
1199 /* Illegal to perform to a target on another tile to
1200 * keep the rules exactly as they were for now. */
1201 0, 0,
1202 FALSE);
1205 TRUE, TRUE,
1207 1,
1208 /* Still limited by each unit type's
1209 * paratroopers_range field. */
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);
1233 TRUE, TRUE,
1235 1,
1236 /* Still limited by each unit type's
1237 * paratroopers_range field. */
1239 FALSE);
1242 TRUE, TRUE,
1244 1,
1245 /* Still limited by each unit type's
1246 * paratroopers_range field. */
1248 FALSE);
1252 TRUE, TRUE,
1254 1,
1255 /* Still limited by each unit type's
1256 * paratroopers_range field. */
1258 FALSE);
1261 TRUE, TRUE,
1263 1,
1264 /* Overwritten by the ruleset's airlift_max_range. */
1266 FALSE);
1269 FALSE, TRUE,
1270 /* Tries a forced move if the target unit's tile has
1271 * no non-allied units and the occupychance dice roll
1272 * tells it to move. */
1273 MAK_FORCED,
1274 1, 1, FALSE);
1277 FALSE, TRUE,
1278 /* Tries a forced move if the target unit's tile has
1279 * no non-allied units and the occupychance dice roll
1280 * tells it to move. */
1281 MAK_FORCED,
1282 1, 1, FALSE);
1285 FALSE, TRUE,
1286 MAK_FORCED, 1, 1, TRUE);
1289 FALSE, TRUE,
1290 MAK_FORCED, 1, 1, TRUE);
1293 FALSE, TRUE,
1294 MAK_FORCED,
1295 1, 1, FALSE);
1298 FALSE, FALSE,
1299 MAK_STAYS, 1, 1, FALSE);
1302 FALSE, FALSE,
1303 MAK_STAYS, 1, 1, FALSE);
1306 FALSE, TRUE,
1307 MAK_REGULAR, 1, 1, FALSE);
1310 FALSE, TRUE,
1311 MAK_REGULAR, 1, 1, FALSE);
1314 FALSE, TRUE,
1315 MAK_REGULAR, 1, 1, FALSE);
1318 FALSE, TRUE,
1319 MAK_REGULAR, 1, 1, FALSE);
1322 FALSE, TRUE,
1323 MAK_REGULAR, 1, 1, FALSE);
1326 FALSE, TRUE,
1327 MAK_REGULAR, 1, 1, FALSE);
1330 FALSE, TRUE,
1331 MAK_REGULAR, 1, 1, FALSE);
1334 FALSE, TRUE,
1335 MAK_REGULAR, 1, 1, FALSE);
1338 FALSE, TRUE,
1339 MAK_STAYS, 0, 1, FALSE);
1342 FALSE, TRUE,
1343 MAK_STAYS, 0, 1, FALSE);
1346 TRUE, FALSE,
1347 MAK_STAYS, 0, 0, FALSE);
1350 TRUE, FALSE,
1351 MAK_STAYS, 0, 0, FALSE);
1354 TRUE, FALSE,
1355 MAK_STAYS, 0, 0, FALSE);
1358 TRUE, FALSE,
1359 MAK_STAYS, 0, 0, FALSE);
1362 TRUE, FALSE,
1363 MAK_STAYS, 0, 0, FALSE);
1366 TRUE, FALSE,
1367 MAK_STAYS, 0, 0, FALSE);
1370 TRUE, FALSE,
1371 MAK_STAYS, 0, 0, FALSE);
1374 TRUE, FALSE,
1375 MAK_STAYS, 0, 0, FALSE);
1378 TRUE, FALSE,
1379 MAK_STAYS, 0, 0, FALSE);
1382 TRUE, FALSE,
1383 MAK_STAYS, 0, 0, FALSE);
1386 TRUE, FALSE,
1387 MAK_STAYS, 0, 0, FALSE);
1390 TRUE, FALSE,
1391 MAK_STAYS, 0, 0, FALSE);
1394 TRUE, FALSE,
1395 MAK_STAYS, 0, 0, FALSE);
1398 TRUE, FALSE,
1399 MAK_STAYS, 0, 0, FALSE);
1402 TRUE, FALSE,
1403 MAK_STAYS, 0, 0, FALSE);
1406 TRUE, FALSE,
1407 MAK_STAYS, 0, 0, FALSE);
1410 TRUE, FALSE,
1411 MAK_STAYS, 0, 0, FALSE);
1414 TRUE, FALSE,
1415 MAK_STAYS, 0, 0, FALSE);
1418 TRUE, FALSE,
1419 MAK_STAYS, 0, 0, FALSE);
1423 FALSE, TRUE,
1424 MAK_REGULAR, 1, 1, FALSE);
1428 FALSE, TRUE,
1429 MAK_REGULAR, 1, 1, FALSE);
1433 FALSE, TRUE,
1434 MAK_REGULAR, 1, 1, FALSE);
1438 FALSE, TRUE,
1439 MAK_REGULAR, 1, 1, FALSE);
1442 TRUE, TRUE,
1443 MAK_REGULAR, 1, 1, FALSE);
1446 TRUE, TRUE,
1447 MAK_REGULAR, 1, 1, FALSE);
1450 TRUE, TRUE,
1451 MAK_REGULAR, 1, 1, FALSE);
1454 TRUE, TRUE,
1455 MAK_REGULAR, 1, 1, FALSE);
1458 FALSE, TRUE,
1459 MAK_STAYS, 1, 1, FALSE);
1462 FALSE, TRUE,
1463 MAK_REGULAR, 1, 1, FALSE);
1466 FALSE, TRUE,
1467 MAK_REGULAR, 1, 1, FALSE);
1470 FALSE, TRUE,
1471 MAK_REGULAR, 1, 1, FALSE);
1474 FALSE, TRUE,
1475 MAK_REGULAR, 1, 1, FALSE);
1478 FALSE, TRUE,
1479 MAK_REGULAR, 1, 1, FALSE);
1482 FALSE, TRUE,
1483 MAK_REGULAR, 1, 1, FALSE);
1486 FALSE, TRUE,
1487 MAK_REGULAR, 1, 1, FALSE);
1490 FALSE, TRUE,
1491 MAK_REGULAR, 1, 1, FALSE);
1494 TRUE, TRUE,
1495 MAK_REGULAR, 1, 1, FALSE);
1498 TRUE, TRUE,
1499 MAK_REGULAR, 1, 1, FALSE);
1502 TRUE, TRUE,
1503 MAK_REGULAR, 1, 1, FALSE);
1506 TRUE, TRUE,
1507 MAK_TELEPORT, 1, 1, FALSE);
1510 TRUE, TRUE,
1511 MAK_TELEPORT, 1,
1516 TRUE, TRUE,
1517 MAK_TELEPORT, 1,
1522 TRUE, TRUE,
1523 MAK_TELEPORT, 1,
1528 TRUE, TRUE,
1529 MAK_TELEPORT, 1,
1534 TRUE, TRUE,
1535 MAK_TELEPORT, 1,
1539 FALSE, TRUE,
1541 /* Overwritten by the ruleset */
1542 0, 1, FALSE);
1545 FALSE, TRUE,
1547 /* Overwritten by the ruleset */
1548 0, 1, FALSE);
1551 FALSE, TRUE,
1553 /* Overwritten by the ruleset */
1554 0, 1, FALSE);
1557 FALSE, TRUE,
1559 /* Overwritten by the ruleset */
1560 0, 1, FALSE);
1563 FALSE, TRUE,
1564 /* Tries a forced move if the target unit's tile has
1565 * no non-allied units and the occupychance dice roll
1566 * tells it to move. */
1567 MAK_FORCED,
1568 1, 1, FALSE);
1569
1570 /* The structure even for these need to be created, for
1571 * the action_id_rule_name() to work on iterations. */
1572
1573 /*
1574 actions[ACTION_UNUSED_1]
1575 = unit_action_new(ACTION_UNUSED_1, ACTRES_NONE,
1576 FALSE, FALSE,
1577 MAK_UNREPRESENTABLE,
1578 0, 0, FALSE);
1579 */
1580}
1581
1582/**********************************************************************/
1586{
1587 int i, j;
1588
1589 for (i = 0; i < ACTRES_LAST; i++) {
1591 }
1592 for (i = 0; i < ACTIVITY_LAST; i++) {
1594 }
1595
1596 /* Hard code the actions */
1598
1599 /* Initialize the action enabler list */
1600 action_iterate_all(act) {
1603
1604 /* Initialize action obligatory hard requirements. */
1605
1606 /* Obligatory hard requirements sorted by action result in memory. */
1607 for (i = 0; i < ACTRES_NONE; i++) {
1608 /* Prepare each action result's storage area. */
1610 }
1611
1612 /* Obligatory hard requirements sorted by action sub result in memory. */
1613 for (i = 0; i < ACT_SUB_RES_COUNT; i++) {
1614 /* Prepare each action sub result's storage area. */
1616 }
1617
1618 /* Obligatory hard requirements are sorted by requirement in the source
1619 * code. This makes it easy to read, modify and explain it. */
1621
1622 /* Initialize the action auto performers. */
1623 for (i = 0; i < MAX_NUM_ACTION_AUTO_PERFORMERS; i++) {
1624 /* Nothing here. Nothing after this point. */
1626
1627 /* The criteria to pick *this* auto performer for its cause. */
1629
1630 for (j = 0; j < MAX_NUM_ACTIONS; j++) {
1631 /* Nothing here. Nothing after this point. */
1633 }
1634 }
1635
1636 /* The actions them self are now initialized. */
1638}
1639
1640/**********************************************************************/
1646{
1647 /* Some obligatory hard requirements needs access to the rest of the
1648 * ruleset. */
1650}
1651
1652/**********************************************************************/
1656{
1657 int i;
1658
1659 /* Don't consider the actions to be initialized any longer. */
1661
1662 action_iterate_all(act) {
1666
1668
1669 FC_FREE(actions[act]);
1671
1672 /* Free the obligatory hard action requirements. */
1673 for (i = 0; i < ACTRES_NONE; i++) {
1675 ae_contra_close(oreq->contras);
1678 }
1679 for (i = 0; i < ACT_SUB_RES_COUNT; i++) {
1681 ae_contra_close(oreq->contras);
1684 }
1685
1686 /* Free the action auto performers. */
1687 for (i = 0; i < MAX_NUM_ACTION_AUTO_PERFORMERS; i++) {
1689 }
1690
1692
1693 for (i = 0; i < ACTRES_LAST; i++) {
1696 }
1697 for (i = 0; i < ACTIVITY_LAST; i++) {
1700 }
1701}
1702
1703/**********************************************************************/
1709{
1710 if (!actions_initialized) {
1711 /* The actions them self aren't initialized yet. */
1712 return FALSE;
1713 }
1714
1715 action_iterate(act) {
1716 if (actions[act]->ui_name[0] == '\0') {
1717 /* An action without a UI name exists means that the ruleset haven't
1718 * loaded yet. The ruleset loading will assign a default name to
1719 * any actions not named by the ruleset. The client will get this
1720 * name from the server. */
1721 return FALSE;
1722 }
1724
1725 /* The actions should be ready for use. */
1726 return TRUE;
1727}
1728
1729/**********************************************************************/
1732static struct action *action_new(action_id id,
1733 enum action_result result,
1734 const int min_distance,
1735 const int max_distance,
1737{
1738 struct action *action;
1739
1740 action = fc_malloc(sizeof(*action));
1741
1742 action->id = id;
1743
1744 action->result = result;
1745
1746 if (result != ACTRES_LAST) {
1748
1750
1751 if (act != ACTIVITY_LAST) {
1753 }
1754 }
1755
1756 /* Not set here */
1758
1763
1764 /* ASTK_NONE implies ACT_TGT_COMPL_SIMPLE and
1765 * !ASTK_NONE implies !ACT_TGT_COMPL_SIMPLE */
1770 "%s contradicts itself regarding sub targets.",
1772
1773 /* The distance between the actor and itself is always 0. */
1775 || (min_distance == 0 && max_distance == 0));
1776
1779
1781
1782 /* Loaded from the ruleset. Until generalized actions are ready it has to
1783 * be defined separately from other action data. */
1784 action->ui_name[0] = '\0';
1785 action->quiet = FALSE;
1787
1788 return action;
1789}
1790
1791/**********************************************************************/
1794static struct action *
1796 enum action_result result,
1797 bool rare_pop_up,
1800 const int min_distance,
1801 const int max_distance,
1803{
1804 struct action *act = action_new(id, result,
1807
1809
1811
1813
1814 return act;
1815}
1816
1817/**********************************************************************/
1820bool action_id_exists(const action_id act_id)
1821{
1822 /* Actions are still hard coded. */
1823 return gen_action_is_valid(act_id) && actions[act_id];
1824}
1825
1826/**********************************************************************/
1831struct action *action_by_rule_name(const char *name)
1832{
1833 /* Actions are still hard coded in the gen_action enum. */
1835
1836 if (!action_id_exists(act_id)) {
1837 /* Nothing to return. */
1838
1839 log_verbose("Asked for non existing action named %s", name);
1840
1841 return NULL;
1842 }
1843
1844 return action_by_number(act_id);
1845}
1846
1847/**********************************************************************/
1851{
1852 fc_assert_ret_val_msg(paction, AAK_COUNT, "Action doesn't exist.");
1853
1854 return paction->actor_kind;
1855}
1856
1857/**********************************************************************/
1861 const struct action *paction)
1862{
1863 fc_assert_ret_val_msg(paction, ATK_COUNT, "Action doesn't exist.");
1864
1865 return paction->target_kind;
1866}
1867
1868/**********************************************************************/
1872 const struct action *paction)
1873{
1874 fc_assert_ret_val_msg(paction, ASTK_COUNT, "Action doesn't exist.");
1875
1876 return paction->sub_target_kind;
1877}
1878
1879/**********************************************************************/
1885{
1887
1888 return paction->target_complexity >= ACT_TGT_COMPL_FLEXIBLE;
1889}
1890
1891/**********************************************************************/
1898{
1900
1901 return paction->target_complexity >= ACT_TGT_COMPL_MANDATORY;
1902}
1903
1904/**********************************************************************/
1913{
1915 FALSE, "Action %d don't exist.", act_id);
1917
1918 return actions[act_id]->actor.is_unit.rare_pop_up;
1919}
1920
1921/**********************************************************************/
1926 const int distance)
1927{
1930}
1931
1932/**********************************************************************/
1937 const int distance)
1938{
1940
1941 return (distance >= action->min_distance
1942 && action_distance_inside_max(action, distance));
1943}
1944
1945/**********************************************************************/
1948bool action_would_be_blocked_by(const struct action *blocked,
1949 const struct action *blocker)
1950{
1951 fc_assert_ret_val(blocked, FALSE);
1952 fc_assert_ret_val(blocker, FALSE);
1953
1954 return BV_ISSET(blocked->blocked_by, action_number(blocker));
1955}
1956
1957/**********************************************************************/
1960int action_number(const struct action *action)
1961{
1962 return action->id;
1963}
1964
1965/**********************************************************************/
1968const char *action_rule_name(const struct action *action)
1969{
1970 /* Rule name is still hard coded. */
1971 return action_id_rule_name(action->id);
1972}
1973
1974/**********************************************************************/
1982const char *action_name_translation(const struct action *action)
1983{
1984 /* Use action_id_name_translation() to format the UI name. */
1986}
1987
1988/**********************************************************************/
1992{
1993 fc_assert_msg(actions[act_id], "Action %d don't exist.", act_id);
1994
1995 return gen_action_name(act_id);
1996}
1997
1998/**********************************************************************/
2003{
2004 return action_prepare_ui_name(act_id, "", ACTPROB_NA, NULL);
2005}
2006
2007/**********************************************************************/
2011 const char *mnemonic)
2012{
2014}
2015
2016/**********************************************************************/
2023static const char *action_prob_to_text(const struct act_prob prob)
2024{
2025 static struct astring chance = ASTRING_INIT;
2026
2027 /* How to interpret action probabilities like prob is documented in
2028 * fc_types.h */
2029 if (action_prob_is_signal(prob)) {
2031 || action_prob_not_relevant(prob));
2032
2033 /* Unknown because of missing server support or should not exits. */
2034 return NULL;
2035 }
2036
2037 if (prob.min == prob.max) {
2038 /* Only one probability in range. */
2039
2040 /* TRANS: the probability that an action will succeed. Given in
2041 * percentage. Resolution is 0.5%. */
2042 astr_set(&chance, _("%.1f%%"), (double)prob.max / ACTPROB_VAL_1_PCT);
2043 } else {
2044 /* TRANS: the interval (end points included) where the probability of
2045 * the action's success is. Given in percentage. Resolution is 0.5%. */
2046 astr_set(&chance, _("[%.1f%%, %.1f%%]"),
2047 (double)prob.min / ACTPROB_VAL_1_PCT,
2048 (double)prob.max / ACTPROB_VAL_1_PCT);
2049 }
2050
2051 return astr_str(&chance);
2052}
2053
2054/**********************************************************************/
2064const char *action_prepare_ui_name(action_id act_id, const char *mnemonic,
2065 const struct act_prob prob,
2066 const char *custom)
2067{
2068 struct astring chance = ASTRING_INIT;
2069
2070 /* Text representation of the probability. */
2071 const char *probtxt;
2072
2073 if (!actions_are_ready()) {
2074 /* Could be a client who haven't gotten the ruleset yet */
2075
2076 /* so there shouldn't be any action probability to show */
2078
2079 /* but the action should be valid */
2081 "Invalid action",
2082 "Invalid action %d", act_id);
2083
2084 /* and no custom text will be inserted */
2085 fc_assert(custom == NULL || custom[0] == '\0');
2086
2087 /* Make the best of what is known */
2088 astr_set(&ui_name_str, _("%s%s (name may be wrong)"),
2089 mnemonic, action_id_rule_name(act_id));
2090
2091 /* Return the guess. */
2092 return astr_str(&ui_name_str);
2093 }
2094
2096
2097 /* Format the info part of the action's UI name. */
2098 if (probtxt != NULL && custom != NULL) {
2099 /* TRANS: action UI name's info part with custom info and probability.
2100 * Hint: you can move the paren handling from this sting to the action
2101 * names if you need to add extra information (like a mnemonic letter
2102 * that doesn't appear in the action UI name) to it. In that case you
2103 * must do so for all strings with this comment and for every action
2104 * name. To avoid a `()` when no UI name info part is added you have
2105 * to add the extra information to every action name or remove the
2106 * surrounding parens. */
2107 astr_set(&chance, _(" (%s; %s)"), custom, probtxt);
2108 } else if (probtxt != NULL) {
2109 /* TRANS: action UI name's info part with probability.
2110 * Hint: you can move the paren handling from this sting to the action
2111 * names if you need to add extra information (like a mnemonic letter
2112 * that doesn't appear in the action UI name) to it. In that case you
2113 * must do so for all strings with this comment and for every action
2114 * name. To avoid a `()` when no UI name info part is added you have
2115 * to add the extra information to every action name or remove the
2116 * surrounding parens. */
2117 astr_set(&chance, _(" (%s)"), probtxt);
2118 } else if (custom != NULL) {
2119 /* TRANS: action UI name's info part with custom info.
2120 * Hint: you can move the paren handling from this sting to the action
2121 * names if you need to add extra information (like a mnemonic letter
2122 * that doesn't appear in the action UI name) to it. In that case you
2123 * must do so for all strings with this comment and for every action
2124 * name. To avoid a `()` when no UI name info part is added you have
2125 * to add the extra information to every action name or remove the
2126 * surrounding parens. */
2127 astr_set(&chance, _(" (%s)"), custom);
2128 } else {
2129 /* No info part to display. */
2131 }
2132
2133 fc_assert_msg(actions[act_id], "Action %d don't exist.", act_id);
2134
2135 /* Escape any instances of the mnemonic in the action's UI format string.
2136 * (Assumes any mnemonic can be escaped by doubling, and that they are
2137 * unlikely to appear in a format specifier. True for clients seen so
2138 * far: Gtk's _ and Qt's &) */
2139 {
2140 struct astring fmtstr = ASTRING_INIT;
2141 const char *ui_name = _(actions[act_id]->ui_name);
2142
2143 if (mnemonic[0] != '\0') {
2144 const char *hit;
2145
2146 fc_assert(!strchr(mnemonic, '%'));
2147 while ((hit = strstr(ui_name, mnemonic))) {
2148 astr_add(&fmtstr, "%.*s%s%s", (int)(hit - ui_name), ui_name,
2150 ui_name = hit + strlen(mnemonic);
2151 }
2152 }
2153 astr_add(&fmtstr, "%s", ui_name);
2154
2155 /* Use the modified format string */
2157 astr_str(&chance));
2158
2159 astr_free(&fmtstr);
2160 }
2161
2162 astr_free(&chance);
2163
2164 return astr_str(&ui_name_str);
2165}
2166
2167/**********************************************************************/
2175const char *action_prob_explain(const struct act_prob prob)
2176{
2177 static struct astring tool_tip = ASTRING_INIT;
2178
2179 if (action_prob_is_signal(prob)) {
2181
2182 /* Missing server support. No in game action will change this. */
2184 } else if (prob.min == prob.max) {
2185 /* TRANS: action probability of success. Given in percentage.
2186 * Resolution is 0.5%. */
2187 astr_set(&tool_tip, _("The probability of success is %.1f%%."),
2188 (double)prob.max / ACTPROB_VAL_1_PCT);
2189 } else {
2191 /* TRANS: action probability interval (min to max). Given in
2192 * percentage. Resolution is 0.5%. The string at the end is
2193 * shown when the interval is wide enough to not be caused by
2194 * rounding. It explains that the interval is imprecise because
2195 * the player doesn't have enough information. */
2196 _("The probability of success is %.1f%%, %.1f%% or somewhere"
2197 " in between.%s"),
2198 (double)prob.min / ACTPROB_VAL_1_PCT,
2199 (double)prob.max / ACTPROB_VAL_1_PCT,
2200 prob.max - prob.min > 1 ?
2201 /* TRANS: explanation used in the action probability tooltip
2202 * above. Preserve leading space. */
2203 _(" (This is the most precise interval I can calculate "
2204 "given the information our nation has access to.)") :
2205 "");
2206 }
2207
2208 return astr_str(&tool_tip);
2209}
2210
2211/**********************************************************************/
2216{
2218 "Action %s isn't performed by a unit",
2220
2221 return paction->id + L_LAST;
2222}
2223
2224/**********************************************************************/
2228{
2229 struct action_enabler *enabler;
2230
2231 enabler = fc_malloc(sizeof(*enabler));
2232 enabler->ruledit_disabled = FALSE;
2233 requirement_vector_init(&enabler->actor_reqs);
2234 requirement_vector_init(&enabler->target_reqs);
2235
2236 /* Make sure that action doesn't end up as a random value that happens to
2237 * be a valid action id. */
2238 enabler->action = ACTION_NONE;
2239
2240 return enabler;
2241}
2242
2243/**********************************************************************/
2247{
2248 requirement_vector_free(&enabler->actor_reqs);
2249 requirement_vector_free(&enabler->target_reqs);
2250
2251 free(enabler);
2252}
2253
2254/**********************************************************************/
2257struct action_enabler *
2259{
2261
2262 enabler->action = original->action;
2263
2264 requirement_vector_copy(&enabler->actor_reqs, &original->actor_reqs);
2265 requirement_vector_copy(&enabler->target_reqs, &original->target_reqs);
2266
2267 return enabler;
2268}
2269
2270/**********************************************************************/
2274{
2275 /* Sanity check: a non existing action enabler can't be added. */
2277 /* Sanity check: a non existing action doesn't have enablers. */
2279
2282 enabler);
2283}
2284
2285/**********************************************************************/
2291{
2292 /* Sanity check: a non existing action enabler can't be removed. */
2294 /* Sanity check: a non existing action doesn't have enablers. */
2296
2299 enabler);
2300}
2301
2302/**********************************************************************/
2305struct action_enabler_list *
2307{
2308 /* Sanity check: a non existing action doesn't have enablers. */
2310
2312}
2313
2314/**********************************************************************/
2325static struct req_vec_problem *
2327 const struct obligatory_req_vector *oblig)
2328{
2329 struct action *paction;
2330
2331 /* Sanity check: a non existing action enabler is missing but it doesn't
2332 * miss any obligatory hard requirements. */
2334
2335 /* Sanity check: a non existing action doesn't have any obligatory hard
2336 * requirements. */
2339
2340 /* No obligatory hard requirements. */
2342
2344 struct req_vec_problem *out;
2345 int i;
2346 bool fulfilled = FALSE;
2347
2348 /* Check each alternative. */
2349 for (i = 0; i < obreq->contras->alternatives; i++) {
2350 const struct requirement_vector *ae_vec;
2351
2352 /* Select action enabler requirement vector. */
2353 ae_vec = (obreq->contras->alternative[i].is_target
2354 ? &enabler->target_reqs
2355 : &enabler->actor_reqs);
2356
2357 if (does_req_contradicts_reqs(&obreq->contras->alternative[i].req,
2358 ae_vec)
2359 /* Consider the hard requirement fulfilled since a universal that
2360 * never is there always will be absent in this ruleset. */
2361 || (obreq->contras->alternative[i].req.present
2363 &obreq->contras->alternative[i].req.source))) {
2364 /* It is enough that one alternative accepts the enabler. */
2365 fulfilled = TRUE;
2366 break;
2367 }
2368
2369 /* Fall back to the next alternative */
2370 }
2371
2372 if (fulfilled) {
2373 /* This obligatory hard requirement isn't a problem. */
2374 continue;
2375 }
2376
2377 /* Missing hard obligatory requirement detected */
2378
2379 out = req_vec_problem_new(obreq->contras->alternatives,
2380 obreq->error_msg,
2382
2383 for (i = 0; i < obreq->contras->alternatives; i++) {
2384 const struct requirement_vector *ae_vec;
2385
2386 /* Select action enabler requirement vector. */
2387 ae_vec = (obreq->contras->alternative[i].is_target
2388 ? &enabler->target_reqs
2389 : &enabler->actor_reqs);
2390
2391 /* The suggested fix is to append a requirement that makes the enabler
2392 * contradict the missing hard obligatory requirement detector. */
2393 out->suggested_solutions[i].operation = RVCO_APPEND;
2394 out->suggested_solutions[i].vector_number
2396
2397 /* Change the requirement from what should conflict to what is
2398 * wanted. */
2399 out->suggested_solutions[i].req.present
2400 = !obreq->contras->alternative[i].req.present;
2401 out->suggested_solutions[i].req.source
2402 = obreq->contras->alternative[i].req.source;
2403 out->suggested_solutions[i].req.range
2404 = obreq->contras->alternative[i].req.range;
2405 out->suggested_solutions[i].req.survives
2406 = obreq->contras->alternative[i].req.survives;
2407 out->suggested_solutions[i].req.quiet
2408 = obreq->contras->alternative[i].req.quiet;
2409 }
2410
2411 /* Return the first problem found. The next problem will be detected
2412 * during the next call. */
2413 return out;
2415
2416 /* No obligatory req problems found. */
2417 return NULL;
2418}
2419
2420/**********************************************************************/
2429struct req_vec_problem *
2431{
2432 struct action *paction;
2434 struct req_vec_problem *out;
2435
2436 /* Sanity check: a non existing action enabler is missing but it doesn't
2437 * miss any obligatory hard requirements. */
2439
2440 /* Sanity check: a non existing action doesn't have any obligatory hard
2441 * requirements. */
2444
2445 if (paction->result != ACTRES_NONE) {
2446 /* A hard coded action result may mean obligatory requirements. */
2448 &oblig_hard_reqs_r[paction->result]);
2449 if (out != NULL) {
2450 return out;
2451 }
2452 }
2453
2457 if (!BV_ISSET(paction->sub_results, sub_res)) {
2458 /* Not relevant */
2459 continue;
2460 }
2461
2462 /* The action has this sub result. Check its hard requirements. */
2465 if (out != NULL) {
2466 return out;
2467 }
2468 }
2469
2470 /* No obligatory req problems found. */
2471 return NULL;
2472}
2473
2474/**********************************************************************/
2480static struct requirement *
2482{
2484 if (preq->source.kind == VUT_DIPLREL
2485 && preq->range == REQ_RANGE_LOCAL) {
2486 return preq;
2487 }
2489
2490 return NULL;
2491}
2492
2493/**********************************************************************/
2501static struct requirement *
2503 const struct requirement_vector *vec)
2504{
2505 /* If the requirement is contradicted by any requirement in the vector it
2506 * contradicts the entire requirement vector. */
2509 return preq;
2510 }
2512
2513 /* Not a singe requirement in the requirement vector is contradicted be
2514 * the specified requirement. */
2515 return NULL;
2516}
2517
2518/**********************************************************************/
2524static struct req_vec_problem *
2526 const struct action_enabler *enabler)
2527{
2528 struct req_vec_problem *out;
2529 struct requirement *local_diplrel;
2530 struct requirement *claimed_req;
2534 struct astring astr;
2535
2537 /* Not tile targeted */
2538 return NULL;
2539 }
2540
2542 if (local_diplrel == NULL) {
2543 /* No local diplrel */
2544 return NULL;
2545 }
2546
2547 /* Tile is unclaimed as a requirement. */
2549 tile_is_unclaimed.survives = FALSE;
2550 tile_is_unclaimed.source.kind = VUT_CITYTILE;
2551 tile_is_unclaimed.present = FALSE;
2552 tile_is_unclaimed.source.value.citytile = CITYT_CLAIMED;
2553
2555 &enabler->target_reqs);
2556
2557 if (claimed_req) {
2558 /* Already clear */
2559 return NULL;
2560 }
2561
2562 /* Tile is claimed as a requirement. */
2564 tile_is_claimed.survives = FALSE;
2565 tile_is_claimed.source.kind = VUT_CITYTILE;
2566 tile_is_claimed.present = TRUE;
2567 tile_is_claimed.source.value.citytile = CITYT_CLAIMED;
2568
2570 1,
2571 /* TRANS: ruledit shows this when an enabler for a tile targeted
2572 * action requires that the actor has a diplomatic relationship to
2573 * the target but doesn't require that the target tile is claimed.
2574 * (DiplRel requirements to an unclaimed tile are never fulfilled
2575 * so this is implicit.) */
2576 N_("Requirement {%s} of action \"%s\" implies a claimed "
2577 "tile. No diplomatic relation to Nature."),
2579
2580 astr_free(&astr);
2581
2582 /* The solution is to add the requirement that the tile is claimed */
2583 out->suggested_solutions[0].req = tile_is_claimed;
2584 out->suggested_solutions[0].vector_number
2586 out->suggested_solutions[0].operation = RVCO_APPEND;
2587
2588 return out;
2589}
2590
2591/**********************************************************************/
2597static struct req_vec_problem *
2599{
2600 struct req_vec_problem *out;
2601 struct requirement *local_diplrel;
2602 struct requirement *unclaimed_req;
2605 struct astring astr1;
2606 struct astring astr2;
2607
2609 /* Not tile targeted */
2610 return NULL;
2611 }
2612
2614 if (local_diplrel == NULL) {
2615 /* No local diplrel */
2616 return NULL;
2617 }
2618
2619 /* Tile is claimed as a requirement. */
2621 tile_is_claimed.survives = FALSE;
2622 tile_is_claimed.source.kind = VUT_CITYTILE;
2623 tile_is_claimed.present = TRUE;
2624 tile_is_claimed.source.value.citytile = CITYT_CLAIMED;
2625
2627 &enabler->target_reqs);
2628
2629 if (unclaimed_req == NULL) {
2630 /* No unclaimed req */
2631 return NULL;
2632 }
2633
2635 2,
2636 /* TRANS: ruledit shows this when an enabler for a tile targeted
2637 * action requires that the target tile is unclaimed and that the
2638 * actor has a diplomatic relationship to the target. (DiplRel
2639 * requirements to an unclaimed tile are never fulfilled.) */
2640 N_("In enabler for \"%s\": No diplomatic relation to Nature."
2641 " Requirements {%s} and {%s} contradict each other."),
2645
2646 astr_free(&astr1);
2647 astr_free(&astr2);
2648
2649 /* The first suggestion is to remove the diplrel */
2650 out->suggested_solutions[0].req = *local_diplrel;
2651 out->suggested_solutions[0].vector_number
2653 out->suggested_solutions[0].operation = RVCO_REMOVE;
2654
2655 /* The 2nd is to remove the requirement that the tile is unclaimed */
2656 out->suggested_solutions[1].req = *unclaimed_req;
2657 out->suggested_solutions[1].vector_number
2659 out->suggested_solutions[1].operation = RVCO_REMOVE;
2660
2661 return out;
2662}
2663
2664/**********************************************************************/
2669struct req_vec_problem *
2671{
2672 struct req_vec_problem *out;
2673
2675 if (out != NULL) {
2676 return out;
2677 }
2678
2679 /* Look for errors in the requirement vectors. */
2680 out = req_vec_suggest_repair(&enabler->actor_reqs,
2682 enabler);
2683 if (out != NULL) {
2684 return out;
2685 }
2686
2687 out = req_vec_suggest_repair(&enabler->target_reqs,
2689 enabler);
2690 if (out != NULL) {
2691 return out;
2692 }
2693
2694 /* Enabler specific contradictions. */
2696 if (out != NULL) {
2697 return out;
2698 }
2699
2700 /* Needed in action not enabled explanation finding. */
2702 if (out != NULL) {
2703 return out;
2704 }
2705
2706 /* No problems found. */
2707 return NULL;
2708}
2709
2710/**********************************************************************/
2717static struct req_vec_problem *
2719{
2720 struct req_vec_problem *out;
2721
2722 out = NULL;
2723
2724 return out;
2725}
2726
2727/**********************************************************************/
2735struct req_vec_problem *
2737{
2738 struct action *paction;
2739 struct req_vec_problem *out;
2740
2742 if (out) {
2743 /* A bug, not just a potential improvement */
2744 return out;
2745 }
2746
2748
2749 /* Look for improvement suggestions to the requirement vectors. */
2752 enabler);
2753 if (out) {
2754 return out;
2755 }
2756 out = req_vec_suggest_improvement(&enabler->target_reqs,
2758 enabler);
2759 if (out) {
2760 return out;
2761 }
2762
2763 /* Detect unused action enablers. */
2765 bool has_user = FALSE;
2766
2770 &(enabler->actor_reqs))) {
2771 has_user = TRUE;
2772 break;
2773 }
2775
2776 if (!has_user) {
2777 /* TRANS: ruledit warns a user about an unused action enabler */
2778 out = req_vec_problem_new(0, N_("Action enabler for \"%s\" is never"
2779 " used by any unit."),
2781 }
2782 }
2783 if (out != NULL) {
2784 return out;
2785 }
2786
2788
2789 return out;
2790}
2791
2792/**********************************************************************/
2801 const struct requirement_vector *vec)
2802{
2803 struct action_enabler *ae = (struct action_enabler *)enabler;
2804
2805 if (vec == &ae->actor_reqs) {
2806 return 0;
2807 } else if (vec == &ae->target_reqs) {
2808 return 1;
2809 } else {
2810 return -1;
2811 }
2812}
2813
2814/********************************************************************/
2822struct requirement_vector *
2824 req_vec_num_in_item number)
2825{
2826 struct action_enabler *ae = (struct action_enabler *)enabler;
2827
2828 fc_assert_ret_val(number >= 0, NULL);
2829
2830 switch (number) {
2831 case 0:
2832 return &ae->actor_reqs;
2833 case 1:
2834 return &ae->target_reqs;
2835 default:
2836 return NULL;
2837 }
2838}
2839
2840/*********************************************************************/
2848{
2849 switch (vec) {
2850 case 0:
2851 /* TRANS: requirement vector in an action enabler (ruledit) */
2852 return _("actor_reqs");
2853 case 1:
2854 /* TRANS: requirement vector in an action enabler (ruledit) */
2855 return _("target_reqs");
2856 default:
2857 return NULL;
2858 }
2859}
2860
2861/**********************************************************************/
2866static const struct impr_type *
2868{
2869 /* Only used with city targets */
2871
2872 if (target_city->production.kind == VUT_IMPROVEMENT) {
2873 /* The local building is what the target city currently is building. */
2874 return target_city->production.value.building;
2875 } else {
2876 /* In the current semantic the local building is always the building
2877 * being built. */
2878 /* TODO: Consider making the local building the target building for
2879 * actions that allows specifying a building target. */
2880 return NULL;
2881 }
2882}
2883
2884/**********************************************************************/
2889static const struct unit_type *
2891{
2892 /* Only used with city targets */
2894
2895 if (target_city->production.kind == VUT_UTYPE) {
2896 /* The local unit type is what the target city currently is
2897 * building. */
2898 return target_city->production.value.utype;
2899 } else {
2900 /* In the current semantic the local utype is always the type of the
2901 * unit being built. */
2902 return NULL;
2903 }
2904}
2905
2906/**********************************************************************/
2914static const struct tile *
2916 const struct unit *actor_unit,
2917 const struct tile *target_tile_arg,
2918 const struct city *target_city,
2919 const struct unit *target_unit)
2920{
2921 if (target_tile_arg != NULL) {
2922 /* Trust the caller. */
2923 return target_tile_arg;
2924 }
2925
2926 /* Action should always be set */
2927 fc_assert_ret_val(act, NULL);
2928
2929 switch (action_get_target_kind(act)) {
2930 case ATK_CITY:
2932 return city_tile(target_city);
2933 case ATK_UNIT:
2934 if (target_unit == NULL) {
2936 return NULL;
2937 }
2938 return unit_tile(target_unit);
2939 case ATK_UNITS:
2941 if (target_unit) {
2942 return unit_tile(target_unit);
2943 }
2944
2946 case ATK_TILE:
2947 case ATK_EXTRAS:
2949 return target_tile_arg;
2950 case ATK_SELF:
2952 return unit_tile(actor_unit);
2953 case ATK_COUNT:
2954 /* Handled below. */
2955 break;
2956 }
2957
2958 fc_assert_msg(FALSE, "Bad action target kind %d for action %s",
2960 return NULL;
2961}
2962
2963/**********************************************************************/
2972static const struct city *
2974 const struct unit *actor_unit,
2975 const struct tile *target_tile,
2976 const struct city *target_city_arg,
2977 const struct unit *target_unit)
2978{
2979 if (target_city_arg != NULL) {
2980 /* Trust the caller. */
2981 return target_city_arg;
2982 }
2983
2984 /* action should always be set */
2985 fc_assert_ret_val(act, NULL);
2986
2987 switch (action_get_target_kind(act)) {
2988 case ATK_CITY:
2990 return target_city_arg;
2991 case ATK_UNIT:
2995 case ATK_UNITS:
2997 if (target_unit) {
3000 }
3001
3003 case ATK_TILE:
3004 case ATK_EXTRAS:
3006 return tile_city(target_tile);
3007 case ATK_SELF:
3011 case ATK_COUNT:
3012 /* Handled below. */
3013 break;
3014 }
3015
3016 fc_assert_msg(FALSE, "Bad action target kind %d for action %s",
3018 return NULL;
3019}
3020
3021/**********************************************************************/
3027struct action *action_is_blocked_by(const struct action *act,
3028 const struct unit *actor_unit,
3029 const struct tile *target_tile_arg,
3030 const struct city *target_city_arg,
3031 const struct unit *target_unit)
3032{
3033 const struct tile *target_tile
3036 const struct city *target_city
3039 const struct civ_map *nmap = &(wld.map);
3040
3042 struct action *blocker = action_by_number(blocker_id);
3043
3045 continue);
3046
3047 if (!action_would_be_blocked_by(act, blocker)) {
3048 /* It doesn't matter if it is legal. It won't block the action. */
3049 continue;
3050 }
3051
3052 switch (action_get_target_kind(blocker)) {
3053 case ATK_CITY:
3054 if (!target_city) {
3055 /* Can't be enabled. No target. */
3056 continue;
3057 }
3060 return blocker;
3061 }
3062 break;
3063 case ATK_UNIT:
3064 if (!target_unit) {
3065 /* Can't be enabled. No target. */
3066 continue;
3067 }
3070 return blocker;
3071 }
3072 break;
3073 case ATK_UNITS:
3074 if (!target_tile) {
3075 /* Can't be enabled. No target. */
3076 continue;
3077 }
3080 return blocker;
3081 }
3082 break;
3083 case ATK_TILE:
3084 if (!target_tile) {
3085 /* Can't be enabled. No target. */
3086 continue;
3087 }
3090 return blocker;
3091 }
3092 break;
3093 case ATK_EXTRAS:
3094 if (!target_tile) {
3095 /* Can't be enabled. No target. */
3096 continue;
3097 }
3100 return blocker;
3101 }
3102 break;
3103 case ATK_SELF:
3105 return blocker;
3106 }
3107 break;
3108 case ATK_COUNT:
3110 continue);
3111 break;
3112 }
3114
3115 /* Not blocked. */
3116 return NULL;
3117}
3118
3119/**********************************************************************/
3139static bool
3141 const struct unit_type *actor_unittype,
3142 bool ignore_third_party)
3143{
3144 switch (paction->result) {
3145 case ACTRES_JOIN_CITY:
3146 if (actor_unittype->pop_cost <= 0) {
3147 /* Reason: Must have population to add. */
3148 return FALSE;
3149 }
3150 break;
3151
3152 case ACTRES_BOMBARD:
3153 if (actor_unittype->bombard_rate <= 0) {
3154 /* Reason: Can't bombard if it never fires. */
3155 return FALSE;
3156 }
3157
3158 if (actor_unittype->attack_strength <= 0) {
3159 /* Reason: Can't bombard without attack strength. */
3160 return FALSE;
3161 }
3162
3163 break;
3164
3166 if (actor_unittype->obsoleted_by == U_NOT_OBSOLETED) {
3167 /* Reason: Nothing to upgrade to. */
3168 return FALSE;
3169 }
3170 break;
3171
3172 case ACTRES_ATTACK:
3173 case ACTRES_WIPE_UNITS:
3175 if (actor_unittype->attack_strength <= 0) {
3176 /* Reason: Can't attack without strength. */
3177 return FALSE;
3178 }
3179 break;
3180
3181 case ACTRES_CONVERT:
3182 if (!actor_unittype->converted_to) {
3183 /* Reason: must be able to convert to something. */
3184 return FALSE;
3185 }
3186 break;
3187
3189 if (actor_unittype->transport_capacity < 1) {
3190 /* Reason: can't transport anything to unload. */
3191 return FALSE;
3192 }
3193 break;
3194
3196 if (actor_unittype->transport_capacity < 1) {
3197 /* Reason: can't transport anything to load. */
3198 return FALSE;
3199 }
3200 break;
3201
3206 if (!ignore_third_party) {
3207 bool has_transporter = FALSE;
3208
3212 break;
3213 }
3215
3216 if (!has_transporter) {
3217 /* Reason: no other unit can transport this unit. */
3218 return FALSE;
3219 }
3220 }
3221 break;
3222
3224 if (!ignore_third_party) {
3225 bool has_target = FALSE;
3227
3228 /* Use cache when it has been initialized */
3229 if (pclass->cache.native_bases != NULL) {
3230 /* Extra being native one is a hard requirement */
3231 extra_type_list_iterate(pclass->cache.native_bases, pextra) {
3232 if (!territory_claiming_base(pextra->data.base)) {
3233 /* Hard requirement */
3234 continue;
3235 }
3236
3237 has_target = TRUE;
3238 break;
3240 } else {
3242
3244 if (!is_native_extra_to_uclass(pextra, pclass)) {
3245 /* Hard requirement */
3246 continue;
3247 }
3248
3249 has_target = TRUE;
3250 break;
3252 }
3253
3254 if (!has_target) {
3255 /* Reason: no extras can be conquered by this unit. */
3256 return FALSE;
3257 }
3258 }
3259 break;
3260
3261 case ACTRES_PARADROP:
3263 if (actor_unittype->paratroopers_range <= 0) {
3264 /* Reason: Can't paradrop 0 tiles. */
3265 return FALSE;
3266 }
3267 break;
3268
3269 case ACTRES_HUT_ENTER:
3273 case ACTRES_SPY_POISON:
3282 case ACTRES_SPY_ESCAPE:
3283 case ACTRES_TRADE_ROUTE:
3284 case ACTRES_MARKETPLACE:
3285 case ACTRES_HELP_WONDER:
3289 case ACTRES_FOUND_CITY:
3290 case ACTRES_STEAL_MAPS:
3291 case ACTRES_SPY_NUKE:
3292 case ACTRES_NUKE:
3293 case ACTRES_NUKE_UNITS:
3295 case ACTRES_EXPEL_UNIT:
3298 case ACTRES_HOME_CITY:
3299 case ACTRES_HOMELESS:
3300 case ACTRES_AIRLIFT:
3304 case ACTRES_HEAL_UNIT:
3305 case ACTRES_PILLAGE:
3306 case ACTRES_CLEAN:
3307 case ACTRES_FORTIFY:
3309 case ACTRES_CULTIVATE:
3310 case ACTRES_PLANT:
3311 case ACTRES_ROAD:
3312 case ACTRES_BASE:
3313 case ACTRES_MINE:
3314 case ACTRES_IRRIGATE:
3315 case ACTRES_SPY_ATTACK:
3316 case ACTRES_UNIT_MOVE:
3317 case ACTRES_TELEPORT:
3320 case ACTRES_NONE:
3321 /* No hard unit type requirements. */
3322 break;
3323
3325 }
3326
3327 return TRUE;
3328}
3329
3330/**********************************************************************/
3346bool
3353
3354/**********************************************************************/
3366static enum fc_tristate
3368 const struct action *paction,
3369 const struct req_context *actor,
3370 const bool omniscient,
3371 const struct city *homecity)
3372{
3373 enum action_result result = paction->result;
3374
3375 if (actor == NULL) {
3377 }
3378
3380 TRUE)) {
3381 /* Info leak: The actor player knows the type of their unit. */
3382 /* The actor unit type can't perform the action because of hard
3383 * unit type requirements. */
3384 return TRI_NO;
3385 }
3386
3387 switch (result) {
3388 case ACTRES_PARADROP:
3390 /* Reason: Keep the old rules. */
3391 /* Info leak: The player knows if their unit already has paradropped this
3392 * turn. */
3393 if (actor->unit->paradropped) {
3394 return TRI_NO;
3395 }
3396
3397 break;
3398
3399 case ACTRES_AIRLIFT:
3400 {
3401 /* Obligatory hard requirement. Checked here too since
3402 * action_hard_reqs_actor() may be called before any
3403 * action enablers are checked. */
3404 if (actor->city == NULL) {
3405 /* No city to airlift from. */
3406 return TRI_NO;
3407 }
3408
3409 if (actor->player != city_owner(actor->city)
3411 && pplayers_allied(actor->player,
3412 city_owner(actor->city)))) {
3413 /* Not allowed to airlift from this source. */
3414 return TRI_NO;
3415 }
3416
3417 if (!(omniscient || city_owner(actor->city) == actor->player)) {
3418 /* Can't check for airlifting capacity. */
3419 return TRI_MAYBE;
3420 }
3421
3422 if (0 >= actor->city->airlift
3425 /* The source cannot airlift for this turn (maybe already airlifted
3426 * or no airport).
3427 *
3428 * See also do_airline() in server/unittools.h. */
3429 return TRI_NO;
3430 }
3431 }
3432 break;
3433
3434 case ACTRES_CONVERT:
3435 /* Reason: Keep the old rules. */
3436 /* Info leak: The player knows their unit's cargo and location. */
3437 if (!unit_can_convert(nmap, actor->unit)) {
3438 return TRI_NO;
3439 }
3440 break;
3441
3444 if (unit_transported(actor->unit)) {
3445 if (!can_unit_unload(actor->unit, unit_transport_get(actor->unit))) {
3446 /* Can't leave current transport. */
3447 return TRI_NO;
3448 }
3449 }
3450 break;
3451
3453 if (!can_unit_unload(actor->unit, unit_transport_get(actor->unit))) {
3454 /* Keep the old rules about Unreachable and disembarks. */
3455 return TRI_NO;
3456 }
3457 break;
3458
3459 case ACTRES_HOMELESS:
3460 case ACTRES_UNIT_MOVE:
3461 case ACTRES_TELEPORT:
3465 case ACTRES_SPY_POISON:
3474 case ACTRES_SPY_ESCAPE:
3475 case ACTRES_TRADE_ROUTE:
3476 case ACTRES_MARKETPLACE:
3477 case ACTRES_HELP_WONDER:
3481 case ACTRES_FOUND_CITY:
3482 case ACTRES_JOIN_CITY:
3483 case ACTRES_STEAL_MAPS:
3484 case ACTRES_BOMBARD:
3485 case ACTRES_SPY_NUKE:
3486 case ACTRES_NUKE:
3487 case ACTRES_NUKE_UNITS:
3489 case ACTRES_EXPEL_UNIT:
3492 case ACTRES_HOME_CITY:
3494 case ACTRES_ATTACK:
3495 case ACTRES_WIPE_UNITS:
3501 case ACTRES_HEAL_UNIT:
3503 case ACTRES_CULTIVATE:
3504 case ACTRES_PLANT:
3505 case ACTRES_PILLAGE:
3506 case ACTRES_CLEAN:
3507 case ACTRES_FORTIFY:
3508 case ACTRES_ROAD:
3509 case ACTRES_BASE:
3510 case ACTRES_MINE:
3511 case ACTRES_IRRIGATE:
3515 case ACTRES_SPY_ATTACK:
3516 case ACTRES_HUT_ENTER:
3519 case ACTRES_NONE:
3520 /* No hard unit requirements. */
3521 break;
3522
3524 }
3525
3526 return TRI_YES;
3527}
3528
3529/**********************************************************************/
3552static enum fc_tristate
3555 const struct req_context *actor,
3556 const struct req_context *target,
3557 const struct extra_type *target_extra,
3558 const bool omniscient,
3559 const struct city *homecity)
3560{
3561 enum fc_tristate out;
3564
3565 if (actor == NULL) {
3567 }
3568 if (target == NULL) {
3569 target = req_context_empty();
3570 }
3571
3572 fc_assert_msg((tkind == ATK_CITY && target->city != NULL)
3573 || (tkind == ATK_TILE && target->tile != NULL)
3574 || (tkind == ATK_EXTRAS && target->tile != NULL)
3575 || (tkind == ATK_UNIT && target->unit != NULL)
3576 /* At this level each individual unit is tested. */
3577 || (tkind == ATK_UNITS && target->unit != NULL)
3578 || (tkind == ATK_SELF),
3579 "Missing target!");
3580
3581 /* Info leak: The player knows where their unit is. */
3582 if (tkind != ATK_SELF
3585 target->tile))) {
3586 /* The distance between the actor and the target isn't inside the
3587 * action's accepted range. */
3588 return TRI_NO;
3589 }
3590
3591 switch (tkind) {
3592 case ATK_UNIT:
3593 /* The Freeciv code for all actions that is controlled by action
3594 * enablers and targets a unit assumes that the acting
3595 * player can see the target unit.
3596 * Examples:
3597 * - action_prob_vs_unit()'s quick check that the distance between actor
3598 * and target is acceptable would leak distance to target unit if the
3599 * target unit can't be seen.
3600 */
3601 if (!can_player_see_unit(actor->player, target->unit)) {
3602 return TRI_NO;
3603 }
3604 break;
3605 case ATK_CITY:
3606 /* The Freeciv code assumes that the player is aware of the target
3607 * city's existence. (How can you order an airlift to a city when you
3608 * don't know its city ID?) */
3610 actor->player)
3611 != target->city->id) {
3612 return TRI_NO;
3613 }
3614 break;
3615 case ATK_UNITS:
3616 case ATK_TILE:
3617 case ATK_EXTRAS:
3618 case ATK_SELF:
3619 /* No special player knowledge checks. */
3620 break;
3621 case ATK_COUNT:
3623 break;
3624 }
3625
3627 target->tile, target->city, target->unit)) {
3628 /* Allows an action to block an other action. If a blocking action is
3629 * legal the actions it blocks becomes illegal. */
3630 return TRI_NO;
3631 }
3632
3633 /* Actor specific hard requirements. */
3634 out = action_hard_reqs_actor(nmap, paction, actor, omniscient, homecity);
3635
3636 if (out == TRI_NO) {
3637 /* Illegal because of a hard actor requirement. */
3638 return TRI_NO;
3639 }
3640
3641 /* Quick checks for action itself */
3642 if (paction->result == ACTRES_ATTACK
3643 || paction->result == ACTRES_WIPE_UNITS
3644 || paction->result == ACTRES_COLLECT_RANSOM) {
3645 /* Reason: Keep the old rules. */
3646 if (!can_unit_attack_tile(actor->unit, paction, target->tile)) {
3647 return TRI_NO;
3648 }
3649 }
3650
3651 /* Hard requirements for results. */
3653 paction->result, actor,
3654 target, target_extra, out, omniscient,
3655 homecity);
3656
3657 if (out == TRI_NO) {
3658 /* Illegal because of a hard actor requirement. */
3659 return TRI_NO;
3660 }
3661
3662 if (paction->result == ACTRES_NUKE_UNITS) {
3664 target->tile)
3665 != ATT_OK) {
3666 /* Unreachable. */
3667 return TRI_NO;
3668 }
3669 } else if (paction->result == ACTRES_PARADROP
3670 || paction->result == ACTRES_PARADROP_CONQUER) {
3671 if (can_player_see_tile(actor->player, target->tile)) {
3672 /* Check for seen stuff that may kill the actor unit. */
3673
3674 /* Reason: Keep the old rules. Be merciful. */
3675 /* Info leak: The player sees the target tile. */
3676 if (!can_unit_exist_at_tile(nmap, actor->unit, target->tile)
3677 && (!BV_ISSET(paction->sub_results, ACT_SUB_RES_MAY_EMBARK)
3678 || !unit_could_load_at(actor->unit, target->tile))) {
3679 return TRI_NO;
3680 }
3681
3682 /* Reason: Keep the old rules. Be merciful. */
3683 /* Info leak: The player sees the target tile. */
3684 if (is_non_attack_city_tile(target->tile, actor->player)) {
3685 return TRI_NO;
3686 }
3687
3688 /* Reason: Be merciful. */
3689 /* Info leak: The player sees all units checked. Invisible units are
3690 * ignored. */
3691 unit_list_iterate(target->tile->units, pother) {
3692 if (can_player_see_unit(actor->player, pother)
3693 && !pplayers_allied(actor->player, unit_owner(pother))) {
3694 return TRI_NO;
3695 }
3697 }
3698 }
3699
3700 return out;
3701}
3702
3703/**********************************************************************/
3709static bool is_enabler_active(const struct action_enabler *enabler,
3710 const struct req_context *actor,
3711 const struct req_context *target)
3712{
3713 return are_reqs_active(actor, target != NULL ? target->player : NULL,
3714 &enabler->actor_reqs, RPT_CERTAIN)
3715 && are_reqs_active(target, actor != NULL ? actor->player : NULL,
3716 &enabler->target_reqs, RPT_CERTAIN);
3717}
3718
3719/**********************************************************************/
3728static bool is_action_enabled(const struct civ_map *nmap,
3730 const struct req_context *actor,
3731 const struct req_context *target,
3732 const struct extra_type *target_extra,
3733 const struct city *actor_home)
3734{
3735 enum fc_tristate possible;
3736
3738 TRUE, actor_home);
3739
3740 if (possible != TRI_YES) {
3741 /* This context is omniscient. Should be yes or no. */
3743 "Is omniscient, should get yes or no.");
3744
3745 /* The action enablers are irrelevant since the action it self is
3746 * impossible. */
3747 return FALSE;
3748 }
3749
3751 enabler) {
3752 if (is_enabler_active(enabler, actor, target)) {
3753 return TRUE;
3754 }
3756
3757 return FALSE;
3758}
3759
3760/**********************************************************************/
3766static bool
3769 const struct unit *actor_unit,
3770 const struct city *actor_home,
3771 const struct tile *actor_tile,
3772 const struct city *target_city)
3773{
3774 const struct impr_type *target_building;
3775 const struct unit_type *target_utype;
3776
3777 if (actor_unit == NULL || target_city == NULL) {
3778 /* Can't do an action when actor or target are missing. */
3779 return FALSE;
3780 }
3781
3783 FALSE, "Action %s is performed by %s not %s",
3788
3791 FALSE, "Action %s is against %s not %s",
3796
3798
3800 /* No point in continuing. */
3801 return FALSE;
3802 }
3803
3806
3808 &(const struct req_context) {
3809 .player = unit_owner(actor_unit),
3810 .city = tile_city(actor_tile),
3811 .tile = actor_tile,
3812 .unit = actor_unit,
3813 .unittype = unit_type_get(actor_unit),
3814 },
3815 &(const struct req_context) {
3816 .player = city_owner(target_city),
3817 .city = target_city,
3818 .building = target_building,
3820 .unittype = target_utype,
3821 },
3822 NULL,
3823 actor_home);
3824}
3825
3826/**********************************************************************/
3842
3843/**********************************************************************/
3849static bool
3852 const struct unit *actor_unit,
3853 const struct city *actor_home,
3854 const struct tile *actor_tile,
3855 const struct unit *target_unit)
3856{
3857 if (actor_unit == NULL || target_unit == NULL) {
3858 /* Can't do an action when actor or target are missing. */
3859 return FALSE;
3860 }
3861
3863 FALSE, "Action %s is performed by %s not %s",
3868
3871 FALSE, "Action %s is against %s not %s",
3876
3878
3880 /* No point in continuing. */
3881 return FALSE;
3882 }
3883
3885 &(const struct req_context) {
3886 .player = unit_owner(actor_unit),
3887 .city = tile_city(actor_tile),
3888 .tile = actor_tile,
3889 .unit = actor_unit,
3890 .unittype = unit_type_get(actor_unit),
3891 },
3892 &(const struct req_context) {
3893 .player = unit_owner(target_unit),
3896 .unit = target_unit,
3897 .unittype = unit_type_get(target_unit),
3898 },
3899 NULL,
3900 actor_home);
3901}
3902
3903/**********************************************************************/
3919
3920/**********************************************************************/
3926static bool
3929 const struct unit *actor_unit,
3930 const struct city *actor_home,
3931 const struct tile *actor_tile,
3932 const struct tile *target_tile)
3933{
3934 const struct req_context *actor_ctxt;
3935
3936 if (actor_unit == NULL || target_tile == NULL
3937 || unit_list_size(target_tile->units) == 0) {
3938 /* Can't do an action when actor or target are missing. */
3939 return FALSE;
3940 }
3941
3943 FALSE, "Action %s is performed by %s not %s",
3948
3951 FALSE, "Action %s is against %s not %s",
3956
3958
3960 /* No point in continuing. */
3961 return FALSE;
3962 }
3963
3964 actor_ctxt = &(const struct req_context) {
3965 .player = unit_owner(actor_unit),
3966 .city = tile_city(actor_tile),
3967 .tile = actor_tile,
3968 .unit = actor_unit,
3969 .unittype = unit_type_get(actor_unit),
3970 };
3971
3974 &(const struct req_context) {
3975 .player = unit_owner(target_unit),
3978 .unit = target_unit,
3979 .unittype = unit_type_get(target_unit),
3980 },
3981 NULL, actor_home)) {
3982 /* One unit makes it impossible for all units. */
3983 return FALSE;
3984 }
3986
3987 /* Not impossible for any of the units at the tile. */
3988 return TRUE;
3989}
3990
3991/**********************************************************************/
4007
4008/**********************************************************************/
4014static bool
4017 const struct unit *actor_unit,
4018 const struct city *actor_home,
4019 const struct tile *actor_tile,
4020 const struct tile *target_tile,
4021 const struct extra_type *target_extra)
4022{
4023 if (actor_unit == NULL || target_tile == NULL) {
4024 /* Can't do an action when actor or target are missing. */
4025 return FALSE;
4026 }
4027
4029 FALSE, "Action %s is performed by %s not %s",
4034
4037 FALSE, "Action %s is against %s not %s",
4042
4044
4046 /* No point in continuing. */
4047 return FALSE;
4048 }
4049
4051 &(const struct req_context) {
4052 .player = unit_owner(actor_unit),
4053 .city = tile_city(actor_tile),
4054 .tile = actor_tile,
4055 .unit = actor_unit,
4056 .unittype = unit_type_get(actor_unit),
4057 },
4058 &(const struct req_context) {
4059 .player = tile_owner(target_tile),
4060 .city = tile_city(target_tile),
4061 .tile = target_tile,
4062 },
4064 actor_home);
4065}
4066
4067/**********************************************************************/
4075 const struct unit *actor_unit,
4076 const struct tile *target_tile,
4077 const struct extra_type *target_extra)
4078{
4083}
4084
4085/**********************************************************************/
4091static bool
4094 const struct unit *actor_unit,
4095 const struct city *actor_home,
4096 const struct tile *actor_tile,
4097 const struct tile *target_tile,
4098 const struct extra_type *target_extra)
4099{
4100 if (actor_unit == NULL || target_tile == NULL) {
4101 /* Can't do an action when actor or target are missing. */
4102 return FALSE;
4103 }
4104
4106 FALSE, "Action %s is performed by %s not %s",
4111
4114 FALSE, "Action %s is against %s not %s",
4119
4121
4123 /* No point in continuing. */
4124 return FALSE;
4125 }
4126
4128 &(const struct req_context) {
4129 .player = unit_owner(actor_unit),
4130 .city = tile_city(actor_tile),
4131 .tile = actor_tile,
4132 .unit = actor_unit,
4133 .unittype = unit_type_get(actor_unit),
4134 },
4135 &(const struct req_context) {
4136 .player = target_tile->extras_owner,
4137 .city = tile_city(target_tile),
4138 .tile = target_tile,
4139 },
4141 actor_home);
4142}
4143
4144/**********************************************************************/
4151 const struct unit *actor_unit,
4152 const struct tile *target_tile,
4153 const struct extra_type *target_extra)
4154{
4155 const struct civ_map *nmap = &(wld.map);
4156
4161}
4162
4163/**********************************************************************/
4170static bool
4173 const struct unit *actor_unit,
4174 const struct city *actor_home,
4175 const struct tile *actor_tile)
4176{
4177 if (actor_unit == NULL) {
4178 /* Can't do an action when the actor is missing. */
4179 return FALSE;
4180 }
4181
4183 FALSE, "Action %s is performed by %s not %s",
4188
4191 FALSE, "Action %s is against %s not %s",
4196
4198
4200 /* No point in continuing. */
4201 return FALSE;
4202 }
4203
4205 &(const struct req_context) {
4206 .player = unit_owner(actor_unit),
4207 .city = tile_city(actor_tile),
4208 .tile = actor_tile,
4209 .unit = actor_unit,
4210 .unittype = unit_type_get(actor_unit),
4211 },
4212 NULL, NULL,
4213 actor_home);
4214}
4215
4216/**********************************************************************/
4232
4233/**********************************************************************/
4251static enum fc_tristate
4253 const struct req_context *actor,
4254 const struct req_context *target)
4255{
4256 enum fc_tristate current;
4257 enum fc_tristate result;
4258
4259 if (actor == NULL || actor->player == NULL) {
4260 /* Need actor->player for point of view */
4261 return TRI_MAYBE;
4262 }
4263
4264 if (target == NULL) {
4265 target = req_context_empty();
4266 }
4267
4268 result = TRI_NO;
4270 enabler) {
4271 current = fc_tristate_and(mke_eval_reqs(actor->player, actor,
4272 target->player,
4273 &enabler->actor_reqs,
4274 RPT_CERTAIN),
4275 mke_eval_reqs(actor->player, target,
4276 actor->player,
4277 &enabler->target_reqs,
4278 RPT_CERTAIN));
4279 if (current == TRI_YES) {
4280 return TRI_YES;
4281 } else if (current == TRI_MAYBE) {
4282 result = TRI_MAYBE;
4283 }
4285
4286 return result;
4287}
4288
4289/**********************************************************************/
4298static bool is_effect_val_known(enum effect_type effect_type,
4299 const struct player *pov_player,
4300 const struct req_context *context,
4301 const struct player *other_player)
4302{
4303 effect_list_iterate(get_effects(effect_type), peffect) {
4305 other_player,
4306 &(peffect->reqs), RPT_CERTAIN)) {
4307 return FALSE;
4308 }
4310
4311 return TRUE;
4312}
4313
4314/**********************************************************************/
4317static enum fc_tristate
4345
4346/**********************************************************************/
4355 const struct unit *pdefender)
4356{
4357 /* Keep unconverted until the end to avoid scaling each step */
4358 int chance;
4359 struct act_prob out;
4360
4361 /* Superspy always win */
4363 /* A defending UTYF_SUPERSPY will defeat every possible attacker. */
4364 return ACTPROB_IMPOSSIBLE;
4365 }
4367 /* An attacking UTYF_SUPERSPY will defeat every possible defender
4368 * except another UTYF_SUPERSPY. */
4369 return ACTPROB_CERTAIN;
4370 }
4371
4372 /* Base chance is 50% */
4373 chance = 50;
4374
4375 /* Spy attack bonus */
4377 chance += 25;
4378 }
4379
4380 /* Spy defense bonus */
4382 chance -= 25;
4383 }
4384
4385 /* Veteran attack and defense bonus */
4386 {
4387 const struct veteran_level *vatt =
4389 const struct veteran_level *vdef =
4391
4392 chance += vatt->power_fact - vdef->power_fact;
4393 }
4394
4395 /* Defense bonus. */
4396 {
4397 const struct req_context defender_ctxt = {
4398 .player = tile_owner(pdefender->tile),
4399 .city = tile_city(pdefender->tile),
4400 .tile = pdefender->tile,
4401 };
4404 NULL)) {
4405 return ACTPROB_NOT_KNOWN;
4406 }
4407
4408 /* Reduce the chance of an attack by EFT_SPY_RESISTANT percent. */
4410 NULL,
4412 NULL,
4414 ) / 100;
4415 }
4416
4417 chance = CLIP(0, chance, 100);
4418
4419 /* Convert to action probability */
4422
4423 return out;
4424}
4425
4426/**********************************************************************/
4432 const struct unit *pvictim,
4433 const struct tile *tgt_tile,
4434 const struct action *paction)
4435{
4436 struct unit *pdefender;
4437
4439 tgt_tile)) {
4440 /* Don't leak information about unseen defenders. */
4441 return ACTPROB_NOT_KNOWN;
4442 }
4443
4445 paction);
4446
4447 if (pdefender) {
4448 /* There will be a diplomatic battle instead of an action. */
4450 };
4451
4452 /* No diplomatic battle will occur. */
4453 return ACTPROB_CERTAIN;
4454}
4455
4456/**********************************************************************/
4460 action_id act_id,
4461 const struct unit *actor_unit)
4462{
4464 /* Unknown because the target is unseen. */
4465 return ACTPROB_NOT_KNOWN;
4466 } else {
4467 /* The actor it self can't do this. */
4468 return ACTPROB_IMPOSSIBLE;
4469 }
4470}
4471
4472/**********************************************************************/
4476static struct act_prob
4478 const struct unit *act_unit,
4479 const struct city *tgt_city,
4480 const struct player *tgt_player,
4481 const struct action *paction)
4482{
4484 &(const struct req_context) {
4485 .player = act_player,
4486 .city = tgt_city,
4487 .unit = act_unit,
4488 .unittype = unit_type_get(act_unit),
4489 },
4490 tgt_player)
4492 &(const struct req_context) {
4493 .player = tgt_player,
4494 .city = tgt_city,
4495 .unit = act_unit,
4496 },
4497 act_player)) {
4500 struct act_prob result = { .min = unconverted * ACTPROB_VAL_1_PCT,
4501 .max = unconverted * ACTPROB_VAL_1_PCT };
4502
4503 return result;
4504 } else {
4505 /* Could be improved to return a more exact probability in some cases.
4506 * Example: The player has enough information to know that the
4507 * probability always will be above 25% and always under 75% because
4508 * the only effect with unknown requirements that may apply adds (or
4509 * subtracts) 50% while all the requirements of the other effects that
4510 * may apply are known. */
4511 return ACTPROB_NOT_KNOWN;
4512 }
4513}
4514
4515/**********************************************************************/
4520static struct act_prob
4522 const struct unit *act_unit,
4523 const struct city *tgt_city,
4524 const struct unit *tgt_unit,
4525 const struct tile *tgt_tile,
4526 const struct player *tgt_player,
4527 const struct action *paction)
4528{
4529 struct act_prob battle;
4530 struct act_prob dice_roll;
4531
4532 battle = ACTPROB_CERTAIN;
4533 switch (actres_get_battle_kind(paction->result)) {
4534 case ABK_NONE:
4535 /* No pre action battle. */
4536 break;
4537 case ABK_DIPLOMATIC:
4539 paction);
4540 break;
4541 case ABK_STANDARD:
4542 /* Not supported here yet. Implement when users appear. */
4544 break;
4545 case ABK_COUNT:
4547 break;
4548 }
4549
4552 paction);
4553
4554 return action_prob_and(&battle, &dice_roll);
4555}
4556
4557/**********************************************************************/
4568static struct act_prob
4571 const struct req_context *actor,
4572 const struct city *actor_home,
4573 const struct req_context *target,
4574 const struct extra_type *target_extra)
4575{
4576 int known;
4577 struct act_prob chance;
4579
4580 if (actor == NULL) {
4582 }
4583 if (target == NULL) {
4584 target = req_context_empty();
4585 }
4586
4587 known = is_action_possible(nmap, wanted_action, actor, target,
4589 FALSE, actor_home);
4590
4591 if (known == TRI_NO) {
4592 /* The action enablers are irrelevant since the action it self is
4593 * impossible. */
4594 return ACTPROB_IMPOSSIBLE;
4595 }
4596
4598
4599 known = fc_tristate_and(known,
4601 actor, target));
4602
4603 switch (paction->result) {
4604 case ACTRES_SPY_POISON:
4605 /* All uncertainty comes from potential diplomatic battles and the
4606 * (diplchance server setting and the) Action_Odds_Pct effect controlled
4607 * dice roll before the action. */
4609 target->city, target->unit,
4610 target->tile, target->player,
4611 paction);
4612 break;
4614 /* TODO */
4615 break;
4617 /* TODO */
4618 break;
4619 case ACTRES_STEAL_MAPS:
4620 /* TODO */
4621 break;
4623 /* All uncertainty comes from potential diplomatic battles. */
4624 chance = ap_diplomat_battle(actor->unit, target->unit, target->tile,
4625 paction);
4626 break;
4628 /* All uncertainty comes from potential diplomatic battles. */
4629 chance = ap_diplomat_battle(actor->unit, target->unit, target->tile,
4630 paction);
4631 break;
4632 case ACTRES_SPY_ATTACK:
4633 /* All uncertainty comes from potential diplomatic battles. */
4634 chance = ap_diplomat_battle(actor->unit, NULL, target->tile,
4635 paction);
4636 break;
4638 /* TODO */
4639 break;
4641 /* TODO */
4642 break;
4644 /* TODO */
4645 break;
4647 /* TODO */
4648 break;
4651 break;
4653 /* Do the victim have anything worth taking? */
4654 known = fc_tristate_and(known,
4655 tech_can_be_stolen(actor->player,
4656 target->player));
4657
4658 /* TODO: Calculate actual chance */
4659
4660 break;
4662 /* Do the victim have anything worth taking? */
4663 known = fc_tristate_and(known,
4664 tech_can_be_stolen(actor->player,
4665 target->player));
4666
4667 /* TODO: Calculate actual chance */
4668
4669 break;
4671 /* There is no risk that the city won't get investigated. */
4673 break;
4674 case ACTRES_SPY_ESCAPE:
4675 /* TODO */
4676 break;
4677 case ACTRES_TRADE_ROUTE:
4678 /* TODO */
4679 break;
4680 case ACTRES_MARKETPLACE:
4681 /* Possible when not blocked by is_action_possible() */
4683 break;
4684 case ACTRES_HELP_WONDER:
4685 /* Possible when not blocked by is_action_possible() */
4687 break;
4689 /* No battle is fought first. */
4691 break;
4692 case ACTRES_EXPEL_UNIT:
4693 /* No battle is fought first. */
4695 break;
4696 case ACTRES_BOMBARD:
4697 /* No battle is fought first. */
4699 break;
4700 case ACTRES_FOUND_CITY:
4701 /* Possible when not blocked by is_action_possible() */
4703 break;
4704 case ACTRES_JOIN_CITY:
4705 /* Possible when not blocked by is_action_possible() */
4707 break;
4708 case ACTRES_SPY_NUKE:
4709 /* All uncertainty comes from potential diplomatic battles and the
4710 * (diplchance server setting and the) Action_Odds_Pct effect controlled
4711 * dice roll before the action. */
4713 target->city, target->unit,
4714 target->tile,
4715 target->player,
4716 paction);
4717 break;
4718 case ACTRES_NUKE:
4719 /* TODO */
4720 break;
4721 case ACTRES_NUKE_UNITS:
4722 /* TODO */
4723 break;
4725 /* No battle is fought first. */
4727 break;
4729 /* No battle is fought first. */
4731 break;
4733 /* No battle is fought first. */
4735 break;
4736 case ACTRES_HOME_CITY:
4737 /* No battle is fought first. */
4739 break;
4740 case ACTRES_HOMELESS:
4741 /* No battle is fought first. */
4743 break;
4745 /* No battle is fought first. */
4747 break;
4748 case ACTRES_PARADROP:
4750 /* TODO */
4751 break;
4752 case ACTRES_AIRLIFT:
4753 /* Possible when not blocked by is_action_possible() */
4755 break;
4756 case ACTRES_ATTACK:
4758 {
4759 struct unit *defender_unit = get_defender(nmap, actor->unit,
4760 target->tile, paction);
4761
4762 if (can_player_see_unit(actor->player, defender_unit)) {
4763 double unconverted = unit_win_chance(nmap, actor->unit,
4765
4767 floor((double)ACTPROB_VAL_MAX * unconverted));
4769 ceil((double)ACTPROB_VAL_MAX * unconverted));
4770 } else if (known == TRI_YES) {
4771 known = TRI_MAYBE;
4772 }
4773 }
4774 break;
4775 case ACTRES_WIPE_UNITS:
4777 break;
4779 /* TODO: not implemented yet because:
4780 * - dice roll 100% * Action_Odds_Pct could be handled with
4781 * action_prob_pre_action_dice_roll().
4782 * - sub target building may be missing. May be missing without player
4783 * knowledge if it isn't visible. See is_improvement_visible() and
4784 * can_player_see_city_internals(). */
4785 break;
4787 /* All uncertainty comes from the (diplchance server setting and the)
4788 * Action_Odds_Pct effect controlled dice roll before the action. */
4790 target->city, target->player,
4791 paction);
4792 break;
4794 /* No battle is fought first. */
4796 break;
4798 /* No battle is fought first. */
4800 break;
4801 case ACTRES_HEAL_UNIT:
4802 /* No battle is fought first. */
4804 break;
4806 case ACTRES_CULTIVATE:
4807 case ACTRES_PLANT:
4808 case ACTRES_PILLAGE:
4809 case ACTRES_CLEAN:
4810 case ACTRES_FORTIFY:
4811 case ACTRES_ROAD:
4812 case ACTRES_CONVERT:
4813 case ACTRES_BASE:
4814 case ACTRES_MINE:
4815 case ACTRES_IRRIGATE:
4817 break;
4820 break;
4823 break;
4826 break;
4829 break;
4832 break;
4835 break;
4836 case ACTRES_HUT_ENTER:
4838 /* Entering the hut happens with a probability of 100%. What happens
4839 * next is probably up to dice rolls in Lua. */
4841 break;
4842 case ACTRES_UNIT_MOVE:
4843 case ACTRES_TELEPORT:
4846 break;
4847 /* Not UI action, so chance is meaningless */
4850 break;
4851 case ACTRES_NONE:
4852 /* Accommodate ruleset authors that wishes to roll the dice in Lua.
4853 * Would be ACTPROB_CERTAIN if not for that. */
4854 /* TODO: maybe allow the ruleset author to give a probability from
4855 * Lua? */
4857 break;
4858
4859 case ACTRES_UNUSED_1:
4861 break;
4862 }
4863
4864 /* Non signal action probabilities should be in range. */
4866 || chance.max <= ACTPROB_VAL_MAX),
4867 chance.max = ACTPROB_VAL_MAX);
4869 || chance.min >= ACTPROB_VAL_MIN),
4870 chance.min = ACTPROB_VAL_MIN);
4871
4872 switch (known) {
4873 case TRI_NO:
4874 return ACTPROB_IMPOSSIBLE;
4875 break;
4876 case TRI_MAYBE:
4877 return ACTPROB_NOT_KNOWN;
4878 break;
4879 case TRI_YES:
4880 return chance;
4881 break;
4882 };
4883
4884 fc_assert_msg(FALSE, "Should be yes, maybe or no");
4885
4887}
4888
4889/**********************************************************************/
4893static struct act_prob
4895 const struct unit *actor_unit,
4896 const struct city *actor_home,
4897 const struct tile *actor_tile,
4898 const action_id act_id,
4899 const struct city *target_city)
4900{
4901 const struct impr_type *target_building;
4902 const struct unit_type *target_utype;
4903 const struct action *act = action_by_number(act_id);
4904
4905 if (actor_unit == NULL || target_city == NULL) {
4906 /* Can't do an action when actor or target are missing. */
4907 return ACTPROB_IMPOSSIBLE;
4908 }
4909
4912 "Action %s is performed by %s not %s",
4913 action_id_rule_name(act_id),
4915 action_id_get_actor_kind(act_id)),
4917
4920 "Action %s is against %s not %s",
4921 action_id_rule_name(act_id),
4925
4927
4928 if (!unit_can_do_action(actor_unit, act_id)) {
4929 /* No point in continuing. */
4930 return ACTPROB_IMPOSSIBLE;
4931 }
4932
4933 /* Doesn't leak information about city position since an unknown city
4934 * can't be targeted and a city can't move. */
4935 if (!action_id_distance_accepted(act_id,
4938 /* No point in continuing. */
4939 return ACTPROB_IMPOSSIBLE;
4940 }
4941
4942 /* Doesn't leak information since it must be 100% certain from the
4943 * player's perspective that the blocking action is legal. */
4946 /* Don't offer to perform an action known to be blocked. */
4947 return ACTPROB_IMPOSSIBLE;
4948 }
4949
4951 /* The invisible city at this tile may, as far as the player knows, not
4952 * exist anymore. */
4953 return act_prob_unseen_target(nmap, act_id, actor_unit);
4954 }
4955
4958
4959 return action_prob(nmap, act_id,
4960 &(const struct req_context) {
4961 .player = unit_owner(actor_unit),
4962 .city = tile_city(actor_tile),
4963 .tile = actor_tile,
4964 .unit = actor_unit,
4965 .unittype = unit_type_get(actor_unit),
4966 },
4967 actor_home,
4968 &(const struct req_context) {
4969 .player = city_owner(target_city),
4970 .city = target_city,
4971 .building = target_building,
4973 .unittype = target_utype,
4974 }, NULL);
4975}
4976
4977/**********************************************************************/
4982 const action_id act_id,
4983 const struct city *target_city)
4984{
4985 const struct civ_map *nmap = &(wld.map);
4986
4990 act_id, target_city);
4991}
4992
4993/**********************************************************************/
4997static struct act_prob
4999 const struct unit *actor_unit,
5000 const struct city *actor_home,
5001 const struct tile *actor_tile,
5002 const action_id act_id,
5003 const struct unit *target_unit)
5004{
5005 if (actor_unit == NULL || target_unit == NULL) {
5006 /* Can't do an action when actor or target are missing. */
5007 return ACTPROB_IMPOSSIBLE;
5008 }
5009
5012 "Action %s is performed by %s not %s",
5013 action_id_rule_name(act_id),
5015 action_id_get_actor_kind(act_id)),
5017
5020 "Action %s is against %s not %s",
5021 action_id_rule_name(act_id),
5025
5027
5028 if (!unit_can_do_action(actor_unit, act_id)) {
5029 /* No point in continuing. */
5030 return ACTPROB_IMPOSSIBLE;
5031 }
5032
5033 /* Doesn't leak information about unit position since an unseen unit can't
5034 * be targeted. */
5035 if (!action_id_distance_accepted(act_id,
5038 /* No point in continuing. */
5039 return ACTPROB_IMPOSSIBLE;
5040 }
5041
5042 return action_prob(nmap, act_id,
5043 &(const struct req_context) {
5044 .player = unit_owner(actor_unit),
5045 .city = tile_city(actor_tile),
5046 .tile = actor_tile,
5047 .unit = actor_unit,
5048 .unittype = unit_type_get(actor_unit),
5049 },
5050 actor_home,
5051 &(const struct req_context) {
5052 .player = unit_owner(target_unit),
5055 .unit = target_unit,
5056 .unittype = unit_type_get(target_unit),
5057 },
5058 NULL);
5059}
5060
5061/**********************************************************************/
5066 const action_id act_id,
5067 const struct unit *target_unit)
5068{
5069 const struct civ_map *nmap = &(wld.map);
5070
5074 act_id,
5075 target_unit);
5076}
5077
5078/**********************************************************************/
5082static struct act_prob
5084 const struct unit *actor_unit,
5085 const struct city *actor_home,
5086 const struct tile *actor_tile,
5087 const action_id act_id,
5088 const struct tile *target_tile)
5089{
5090 struct act_prob prob_all;
5091 const struct req_context *actor_ctxt;
5092 const struct action *act = action_by_number(act_id);
5093
5094 if (actor_unit == NULL || target_tile == NULL) {
5095 /* Can't do an action when actor or target are missing. */
5096 return ACTPROB_IMPOSSIBLE;
5097 }
5098
5101 "Action %s is performed by %s not %s",
5102 action_id_rule_name(act_id),
5104 action_id_get_actor_kind(act_id)),
5106
5109 "Action %s is against %s not %s",
5110 action_id_rule_name(act_id),
5114
5116
5117 if (!unit_can_do_action(actor_unit, act_id)) {
5118 /* No point in continuing. */
5119 return ACTPROB_IMPOSSIBLE;
5120 }
5121
5122 /* Doesn't leak information about unit stack position since it is
5123 * specified as a tile and an unknown tile's position is known. */
5124 if (!action_id_distance_accepted(act_id,
5126 target_tile))) {
5127 /* No point in continuing. */
5128 return ACTPROB_IMPOSSIBLE;
5129 }
5130
5131 /* Doesn't leak information since the actor player can see the target
5132 * tile. */
5136 act_id,
5137 CITYT_CENTER, TRUE)) {
5138 /* Don't offer to perform actions that never can target a unit stack in
5139 * a city. */
5140 return ACTPROB_IMPOSSIBLE;
5141 }
5142
5143 /* Doesn't leak information since it must be 100% certain from the
5144 * player's perspective that the blocking action is legal. */
5148 target_unit)) {
5149 /* Don't offer to perform an action known to be blocked. */
5150 return ACTPROB_IMPOSSIBLE;
5151 }
5153
5154 /* Must be done here since an empty unseen tile will result in
5155 * ACTPROB_IMPOSSIBLE. */
5156 if (unit_list_size(target_tile->units) == 0) {
5157 /* Can't act against an empty tile. */
5158
5160 target_tile)) {
5161 /* Known empty tile. */
5162 return ACTPROB_IMPOSSIBLE;
5163 } else {
5164 /* The player doesn't know that the tile is empty. */
5165 return act_prob_unseen_target(nmap, act_id, actor_unit);
5166 }
5167 }
5168
5175 /* Hard coded rule: can't "Bombard", "Suicide Attack", or "Attack"
5176 * units in non enemy cities. */
5177 return ACTPROB_IMPOSSIBLE;
5178 }
5179
5186 /* Hard coded rule: can't "Nuke Units", "Wipe Units", "Suicide Attack",
5187 * or "Attack" units on non native tile without "AttackNonNative" and
5188 * not "Only_Native_Attack". */
5189 return ACTPROB_IMPOSSIBLE;
5190 }
5191
5192 /* Invisible units at this tile can make the action legal or illegal.
5193 * Invisible units can be stacked with visible units. The possible
5194 * existence of invisible units therefore makes the result uncertain. */
5198
5199 actor_ctxt = &(const struct req_context) {
5200 .player = unit_owner(actor_unit),
5201 .city = tile_city(actor_tile),
5202 .tile = actor_tile,
5203 .unit = actor_unit,
5204 .unittype = unit_type_get(actor_unit),
5205 };
5206
5208 struct act_prob prob_unit;
5209
5211 /* Only visible units are considered. The invisible units contributed
5212 * their uncertainty to prob_all above. */
5213 continue;
5214 }
5215
5217 &(const struct req_context) {
5218 .player = unit_owner(target_unit),
5221 .unit = target_unit,
5222 .unittype = unit_type_get(target_unit),
5223 },
5224 NULL);
5225
5227 /* One unit makes it impossible for all units. */
5228 return ACTPROB_IMPOSSIBLE;
5229 } else if (action_prob_not_impl(prob_unit)) {
5230 /* Not implemented dominates all except impossible. */
5232 } else {
5234 "Invalid probability [%d, %d]",
5235 prob_unit.min, prob_unit.max);
5236
5238 /* Special values dominate regular values. */
5239 continue;
5240 }
5241
5242 /* Probability against all target units considered until this moment
5243 * and the probability against this target unit. */
5244 prob_all.min = (prob_all.min * prob_unit.min) / ACTPROB_VAL_MAX;
5245 prob_all.max = (prob_all.max * prob_unit.max) / ACTPROB_VAL_MAX;
5246 break;
5247 }
5249
5250 /* Not impossible for any of the units at the tile. */
5251 return prob_all;
5252}
5253
5254/**********************************************************************/
5259 const action_id act_id,
5260 const struct tile *target_tile)
5261{
5262 const struct civ_map *nmap = &(wld.map);
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 action_id act_id,
5344 const struct tile *target_tile,
5345 const struct extra_type *target_extra)
5346{
5347 const struct civ_map *nmap = &(wld.map);
5348
5352 act_id, target_tile, target_extra);
5353}
5354
5355/**********************************************************************/
5359static struct act_prob
5361 const struct unit *actor_unit,
5362 const struct city *actor_home,
5363 const struct tile *actor_tile,
5364 const action_id act_id,
5365 const struct tile *target_tile,
5366 const struct extra_type *target_extra)
5367{
5368 if (actor_unit == NULL || target_tile == NULL) {
5369 /* Can't do an action when actor or target are missing. */
5370 return ACTPROB_IMPOSSIBLE;
5371 }
5372
5375 "Action %s is performed by %s not %s",
5376 action_id_rule_name(act_id),
5378 action_id_get_actor_kind(act_id)),
5380
5383 "Action %s is against %s not %s",
5384 action_id_rule_name(act_id),
5388
5390
5391 if (!unit_can_do_action(actor_unit, act_id)) {
5392 /* No point in continuing. */
5393 return ACTPROB_IMPOSSIBLE;
5394 }
5395
5396 /* Doesn't leak information about tile position since an unknown tile's
5397 * position is known. */
5398 if (!action_id_distance_accepted(act_id,
5400 target_tile))) {
5401 /* No point in continuing. */
5402 return ACTPROB_IMPOSSIBLE;
5403 }
5404
5405 return action_prob(nmap, act_id,
5406 &(const struct req_context) {
5407 .player = unit_owner(actor_unit),
5408 .city = tile_city(actor_tile),
5409 .tile = actor_tile,
5410 .unit = actor_unit,
5411 .unittype = unit_type_get(actor_unit),
5412 },
5413 actor_home,
5414 &(const struct req_context) {
5415 .player = target_tile->extras_owner,
5416 .city = tile_city(target_tile),
5417 .tile = target_tile,
5418 },
5419 target_extra);
5420}
5421
5422/**********************************************************************/
5427 const action_id act_id,
5428 const struct tile *target_tile,
5429 const struct extra_type *target_extra)
5430{
5431 const struct civ_map *nmap = &(wld.map);
5432
5436 act_id, target_tile, target_extra);
5437}
5438
5439/**********************************************************************/
5443static struct act_prob
5445 const struct unit *actor_unit,
5446 const struct city *actor_home,
5447 const struct tile *actor_tile,
5448 const action_id act_id)
5449{
5450 if (actor_unit == NULL) {
5451 /* Can't do the action when the actor is missing. */
5452 return ACTPROB_IMPOSSIBLE;
5453 }
5454
5455 /* No point in checking distance to target. It is always 0. */
5456
5459 "Action %s is performed by %s not %s",
5460 action_id_rule_name(act_id),
5462 action_id_get_actor_kind(act_id)),
5464
5467 "Action %s is against %s not %s",
5468 action_id_rule_name(act_id),
5472
5474
5475 if (!unit_can_do_action(actor_unit, act_id)) {
5476 /* No point in continuing. */
5477 return ACTPROB_IMPOSSIBLE;
5478 }
5479
5480 return action_prob(nmap, act_id,
5481 &(const struct req_context) {
5482 .player = unit_owner(actor_unit),
5483 .city = tile_city(actor_tile),
5484 .tile = actor_tile,
5485 .unit = actor_unit,
5486 .unittype = unit_type_get(actor_unit),
5487 },
5488 actor_home,
5489 NULL,
5490 NULL);
5491}
5492
5493/**********************************************************************/
5498 const action_id act_id)
5499{
5500 const struct civ_map *nmap = &(wld.map);
5501
5505 act_id);
5506}
5507
5508/**********************************************************************/
5520 const struct unit *act_unit,
5521 const struct city *tgt_city,
5522 const struct unit *tgt_unit,
5523 const struct tile *tgt_tile,
5524 const struct extra_type *extra_tgt)
5525{
5526 /* Assume impossible until told otherwise. */
5527 struct act_prob prob = ACTPROB_IMPOSSIBLE;
5528
5531
5533 case ATK_UNITS:
5534 if (tgt_tile) {
5536 }
5537 break;
5538 case ATK_TILE:
5539 if (tgt_tile) {
5541 }
5542 break;
5543 case ATK_EXTRAS:
5544 if (tgt_tile) {
5547 }
5548 break;
5549 case ATK_CITY:
5550 if (tgt_city) {
5552 }
5553 break;
5554 case ATK_UNIT:
5555 if (tgt_unit) {
5557 }
5558 break;
5559 case ATK_SELF:
5560 prob = action_prob_self(act_unit, paction->id);
5561 break;
5562 case ATK_COUNT:
5563 log_error("Invalid action target kind");
5564 break;
5565 }
5566
5567 return prob;
5568}
5569
5570/**********************************************************************/
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 const struct civ_map *nmap = &(wld.map);
5587
5588 if (omniscient_cheat) {
5591 target)) {
5592 return ACTPROB_CERTAIN;
5593 } else {
5594 return ACTPROB_IMPOSSIBLE;
5595 }
5596 } else {
5597 /* FIXME: this branch result depends _directly_ on actor's position.
5598 * I.e., like, not adjacent, no action. Other branch ignores radius. */
5600 act_id, target);
5601 }
5602}
5603
5604/**********************************************************************/
5609struct act_prob
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 const struct civ_map *nmap = &(wld.map);
5622
5623 if (omniscient_cheat) {
5626 target)) {
5627 return ACTPROB_CERTAIN;
5628 } else {
5629 return ACTPROB_IMPOSSIBLE;
5630 }
5631 } else {
5633 act_id, target);
5634 }
5635}
5636
5637/**********************************************************************/
5642struct act_prob
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 const struct civ_map *nmap = &(wld.map);
5655
5656 if (omniscient_cheat) {
5659 target)) {
5660 return ACTPROB_CERTAIN;
5661 } else {
5662 return ACTPROB_IMPOSSIBLE;
5663 }
5664 } else {
5666 act_id, target);
5667 }
5668}
5669
5670/**********************************************************************/
5675struct act_prob
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 const struct civ_map *nmap = &(wld.map);
5689
5690 if (omniscient_cheat) {
5694 return ACTPROB_CERTAIN;
5695 } else {
5696 return ACTPROB_IMPOSSIBLE;
5697 }
5698 } else {
5700 act_id, target_tile, target_extra);
5701 }
5702}
5703
5704/**********************************************************************/
5709struct act_prob
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 const struct civ_map *nmap = &(wld.map);
5723
5724 if (omniscient_cheat) {
5728 return ACTPROB_CERTAIN;
5729 } else {
5730 return ACTPROB_IMPOSSIBLE;
5731 }
5732 } else {
5734 act_id, target_tile, target_extra);
5735 }
5736}
5737
5738/**********************************************************************/
5743struct act_prob
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 const struct civ_map *nmap = &(wld.map);
5755
5756 if (omniscient_cheat) {
5759 return ACTPROB_CERTAIN;
5760 } else {
5761 return ACTPROB_IMPOSSIBLE;
5762 }
5763 } else {
5765 act_id);
5766 }
5767}
5768
5769/**********************************************************************/
5773{
5775
5776 return out;
5777}
5778
5779/**********************************************************************/
5783{
5785
5786 return out;
5787}
5788
5789/**********************************************************************/
5793{
5795
5796 return out;
5797}
5798
5799/**********************************************************************/
5803{
5805
5806 return out;
5807}
5808
5809/**********************************************************************/
5813{
5815
5816 return out;
5817}
5818
5819/**********************************************************************/
5824{
5825 return (ACTPROB_VAL_MIN < probability.max
5827}
5828
5829/**********************************************************************/
5834{
5835 return (ACTPROB_VAL_MAX == probability.min
5836 && ACTPROB_VAL_MAX == probability.max);
5837}
5838
5839/**********************************************************************/
5843static inline bool
5849
5850/**********************************************************************/
5854static inline bool
5856{
5857 return probability.min == ACTPROB_VAL_NOT_IMPL
5858 && probability.max == ACTPROB_VAL_MIN;
5859}
5860
5861/**********************************************************************/
5865static inline bool
5867{
5868 return probability.max < probability.min;
5869}
5870
5871/**********************************************************************/
5875 const struct act_prob *ap2)
5876{
5877 return ap1->min == ap2->min && ap1->max == ap2->max;
5878}
5879
5880/**********************************************************************/
5884 const struct act_prob ap2)
5885{
5886 struct act_prob my_ap1;
5887 struct act_prob my_ap2;
5888
5889 /* The action probabilities are real. */
5892
5893 /* Convert any signals to ACTPROB_NOT_KNOWN. */
5895 /* Assert that it is OK to convert the signal. */
5897
5899 } else {
5900 my_ap1 = ap1;
5901 }
5902
5904 /* Assert that it is OK to convert the signal. */
5906
5908 } else {
5909 my_ap2 = ap2;
5910 }
5911
5912 /* The action probabilities now have a comparison friendly form. */
5915
5916 /* Do the comparison. Start with min. Continue with max. */
5917 if (my_ap1.min < my_ap2.min) {
5918 return -1;
5919 } else if (my_ap1.min > my_ap2.min) {
5920 return 1;
5921 } else if (my_ap1.max < my_ap2.max) {
5922 return -1;
5923 } else if (my_ap1.max > my_ap2.max) {
5924 return 1;
5925 } else {
5926 return 0;
5927 }
5928}
5929
5930/**********************************************************************/
5935{
5936 struct act_prob my_ap;
5937
5938 /* The action probability is real. */
5940
5941 /* Convert any signals to ACTPROB_NOT_KNOWN. */
5943 /* Assert that it is OK to convert the signal. */
5945
5947 } else {
5948 my_ap = ap;
5949 }
5950
5951 /* The action probability now has a math friendly form. */
5953
5954 return (double)my_ap.min / (double) ACTPROB_VAL_MAX;
5955}
5956
5957/**********************************************************************/
5962 const struct act_prob *ap2)
5963{
5964 struct act_prob my_ap1;
5965 struct act_prob my_ap2;
5966 struct act_prob out;
5967
5968 /* The action probabilities are real. */
5971
5974 /* Keep the information rather than converting the signal to
5975 * ACTPROB_NOT_KNOWN. */
5976
5977 /* Assert that it is OK to convert the signal. */
5979
5980 out.min = ap1->min;
5981 out.max = ap2->max;
5982
5983 return out;
5984 }
5985
5986 /* Convert any signals to ACTPROB_NOT_KNOWN. */
5987 if (action_prob_is_signal(*ap1)) {
5988 /* Assert that it is OK to convert the signal. */
5990
5991 my_ap1.min = ACTPROB_VAL_MIN;
5992 my_ap1.max = ACTPROB_VAL_MAX;
5993 } else {
5994 my_ap1.min = ap1->min;
5995 my_ap1.max = ap1->max;
5996 }
5997
5998 if (action_prob_is_signal(*ap2)) {
5999 /* Assert that it is OK to convert the signal. */
6001
6002 my_ap2.min = ACTPROB_VAL_MIN;
6003 my_ap2.max = ACTPROB_VAL_MAX;
6004 } else {
6005 my_ap2.min = ap2->min;
6006 my_ap2.max = ap2->max;
6007 }
6008
6009 /* The action probabilities now have a math friendly form. */
6012
6013 /* Do the math. */
6014 out.min = (my_ap1.min * my_ap2.min) / ACTPROB_VAL_MAX;
6015 out.max = (my_ap1.max * my_ap2.max) / ACTPROB_VAL_MAX;
6016
6017 /* Cap at 100%. */
6018 out.min = MIN(out.min, ACTPROB_VAL_MAX);
6019 out.max = MIN(out.max, ACTPROB_VAL_MAX);
6020
6021 return out;
6022}
6023
6024/**********************************************************************/
6032 const struct act_prob *ap2)
6033{
6034 struct act_prob my_ap1;
6035 struct act_prob my_ap2;
6036 struct act_prob out;
6037
6038 /* The action probabilities are real. */
6041
6044 /* Keep the information rather than converting the signal to
6045 * ACTPROB_NOT_KNOWN. */
6046
6047 /* Assert that it is OK to convert the signal. */
6049
6050 out.min = ap1->min;
6051 out.max = ap2->max;
6052
6053 return out;
6054 }
6055
6056 /* Convert any signals to ACTPROB_NOT_KNOWN. */
6057 if (action_prob_is_signal(*ap1)) {
6058 /* Assert that it is OK to convert the signal. */
6060
6061 my_ap1.min = ACTPROB_VAL_MIN;
6062 my_ap1.max = ACTPROB_VAL_MAX;
6063 } else {
6064 my_ap1.min = ap1->min;
6065 my_ap1.max = ap1->max;
6066 }
6067
6068 if (action_prob_is_signal(*ap2)) {
6069 /* Assert that it is OK to convert the signal. */
6071
6072 my_ap2.min = ACTPROB_VAL_MIN;
6073 my_ap2.max = ACTPROB_VAL_MAX;
6074 } else {
6075 my_ap2.min = ap2->min;
6076 my_ap2.max = ap2->max;
6077 }
6078
6079 /* The action probabilities now have a math friendly form. */
6082
6083 /* Do the math. */
6084 out.min = my_ap1.min + (((ACTPROB_VAL_MAX - my_ap1.min) * my_ap2.min)
6085 / ACTPROB_VAL_MAX);
6086 out.max = my_ap1.max + (((ACTPROB_VAL_MAX - my_ap1.max) * my_ap2.max)
6087 / ACTPROB_VAL_MAX);
6088
6089 /* Cap at 100%. */
6090 out.min = MIN(out.min, ACTPROB_VAL_MAX);
6091 out.max = MIN(out.max, ACTPROB_VAL_MAX);
6092
6093 return out;
6094}
6095
6096/**********************************************************************/
6100{
6101 switch (actres_dice_type(paction->result)) {
6102 case DRT_DIPLCHANCE:
6104 /* Take the initial odds from the diplchance setting. */
6106 server_setting_by_name("diplchance"));
6107 }
6109 case DRT_CERTAIN:
6110 return 100;
6111 case DRT_NONE:
6112 break;
6113 }
6114
6115 /* The odds of the action not being stopped by its dice roll when the dice
6116 * isn't thrown is 100%. ACTION_ODDS_PCT_DICE_ROLL_NA is above 100% */
6118}
6119
6120/**********************************************************************/
6124 const struct unit *act_unit,
6125 const struct city *tgt_city,
6126 const struct player *tgt_player,
6127 const struct action *paction)
6128{
6130 const struct unit_type *actu_type = unit_type_get(act_unit);
6131
6132 fc_assert_action_msg(odds >= 0 && odds <= 100,
6133 odds = 100,
6134 "Bad initial odds for action number %d."
6135 " Does it roll the dice at all?",
6136 paction->id);
6137
6138 /* Let the Action_Odds_Pct effect modify the odds. The advantage of doing
6139 * it this way instead of rolling twice is that Action_Odds_Pct can
6140 * increase the odds. */
6141 odds = odds
6142 + ((odds
6144 &(const struct req_context) {
6145 .player = act_player,
6146 .city = tgt_city,
6147 .unit = act_unit,
6148 .unittype = actu_type,
6149 .action = paction,
6150 },
6151 tgt_player,
6153 / 100)
6154 - ((odds
6156 &(const struct req_context) {
6157 .player = tgt_player,
6158 .city = tgt_city,
6159 .unit = act_unit,
6160 .unittype = actu_type,
6161 .action = paction,
6162 },
6163 act_player,
6165 / 100);
6166
6167
6168 /* Odds are between 0% and 100%. */
6169 return CLIP(0, odds, 100);
6170}
6171
6172/**********************************************************************/
6176{
6177 struct action *paction = action_by_number(act);
6178
6179 /* Always immune since its not enabled. Doesn't count. */
6180 if (!action_is_in_use(paction)) {
6181 return FALSE;
6182 }
6183
6185 if (requirement_fulfilled_by_government(gov, &(enabler->target_reqs))) {
6186 return FALSE;
6187 }
6189
6190 return TRUE;
6191}
6192
6193/**********************************************************************/
6199 const struct player *actor_player,
6200 const struct req_context *target)
6201{
6203 enabler) {
6204 if (are_reqs_active(target, actor_player,
6205 &enabler->target_reqs, RPT_POSSIBLE)) {
6206 return TRUE;
6207 }
6209
6210 return FALSE;
6211}
6212
6213/**********************************************************************/
6217 const struct player *actor_player,
6218 const struct city* target_city)
6219{
6221 FALSE, "Action %s is against %s not cities",
6222 action_id_rule_name(act_id),
6224 action_id_get_target_kind(act_id)));
6225
6226 return is_target_possible(act_id, actor_player,
6227 &(const struct req_context) {
6228 .player = city_owner(target_city),
6229 .city = target_city,
6231 });
6232}
6233
6234/**********************************************************************/
6240 const action_id act_id,
6241 const struct unit *actor_unit)
6242{
6243 const struct player *actor_player = unit_owner(actor_unit);
6244 const struct req_context actor_ctxt = {
6246 .city = tile_city(unit_tile(actor_unit)),
6248 .unit = actor_unit,
6249 .unittype = unit_type_get(actor_unit),
6250 };
6251 const struct action *paction = action_by_number(act_id);
6252
6253 enum fc_tristate result;
6254
6256
6257 if (!utype_can_do_action(actor_unit->utype, act_id)) {
6258 /* The unit type can't perform the action. */
6259 return FALSE;
6260 }
6261
6264
6265 if (result == TRI_NO) {
6266 /* The hard requirements aren't fulfilled. */
6267 return FALSE;
6268 }
6269
6271 enabler) {
6272 const enum fc_tristate current
6274 &enabler->actor_reqs,
6275 /* Needed since no player to evaluate DiplRel
6276 * requirements against. */
6277 RPT_POSSIBLE);
6278
6279 if (current == TRI_YES
6280 || current == TRI_MAYBE) {
6281 /* The ruleset requirements may be fulfilled. */
6282 return TRUE;
6283 }
6285
6286 /* No action enabler allows this action. */
6287 return FALSE;
6288}
6289
6290/**********************************************************************/
6295 const action_id act_id)
6296{
6297 fc_assert(action_id_exists(act_id) || act_id == ACTION_ANY);
6298
6299 /* Check if full movement points may enable the specified action. */
6301 act_id,
6304 act_id,
6306}
6307
6308/**********************************************************************/
6333
6334/**********************************************************************/
6345{
6346 const struct action *paction = enabler_get_action(ae);
6347
6348 switch (action_get_actor_kind(paction)) {
6349 case AAK_UNIT:
6352 /* A possible actor unit type has been found. */
6353 return TRUE;
6354 }
6356
6357 /* No actor detected. */
6358 return FALSE;
6359 case AAK_COUNT:
6361 break;
6362 }
6363
6364 /* No actor detected. */
6365 return FALSE;
6366}
6367
6368/**********************************************************************/
6376{
6377 switch (action_get_actor_kind(paction)) {
6378 case AAK_UNIT:
6381 return TRUE;
6382 }
6384 break;
6385 case AAK_COUNT:
6387 break;
6388 }
6389
6390 /* No actor detected. */
6391 return FALSE;
6392}
6393
6394/**********************************************************************/
6401{
6403
6405 /* Hard requirements not fulfilled. */
6406 return FALSE;
6407 }
6408
6410
6412 /* If this iteration finds any entries, action is enabled. */
6413 return TRUE;
6415
6416 /* No non deleted action enabler. */
6417 return FALSE;
6418}
6419
6420/**********************************************************************/
6424{
6425 fc_assert_ret_val(num >= 0, NULL);
6427
6428 return &auto_perfs[num];
6429}
6430
6431/**********************************************************************/
6440{
6441 return action_auto_perf_slot_number(num);
6442}
6443
6444/**********************************************************************/
6448 struct universal *actor_uni,
6449 struct universal *target_uni)
6450{
6452 enab) {
6453 if ((actor_uni == NULL
6454 || universal_fulfills_requirements(FALSE, &(enab->actor_reqs),
6455 actor_uni))
6456 && (target_uni == NULL
6457 || universal_fulfills_requirements(FALSE, &(enab->target_reqs),
6458 target_uni))) {
6459 return TRUE;
6460 }
6462
6463 return FALSE;
6464}
6465
6466/**********************************************************************/
6472{
6474
6475 if (size < MAX_NUM_ACTIONS) {
6476 /* An action array is terminated by ACTION_NONE */
6478 }
6479}
6480
6481/**********************************************************************/
6489 int *position,
6490 enum action_result result)
6491{
6492 action_iterate(act) {
6493 struct action *paction = action_by_number(act);
6494 if (paction->result == result) {
6495 /* Assume one result for each action. */
6496 fc_assert_ret(*position < MAX_NUM_ACTIONS);
6497
6498 act_array[(*position)++] = paction->id;
6499 }
6501}
6502
6503/**********************************************************************/
6509{
6510 switch ((enum gen_action)act) {
6511 case ACTION_SPY_POISON:
6512 return "ui_name_poison_city";
6514 return "ui_name_poison_city_escape";
6516 return "ui_name_sabotage_unit";
6518 return "ui_name_sabotage_unit_escape";
6520 return "ui_name_bribe_unit";
6522 return "ui_name_sabotage_city";
6524 return "ui_name_sabotage_city_escape";
6526 return "ui_name_targeted_sabotage_city";
6528 return "ui_name_sabotage_city_production";
6530 return "ui_name_targeted_sabotage_city_escape";
6532 return "ui_name_sabotage_city_production_escape";
6534 return "ui_name_incite_city";
6536 return "ui_name_incite_city_escape";
6538 return "ui_name_establish_embassy";
6540 return "ui_name_establish_embassy_stay";
6542 return "ui_name_steal_tech";
6544 return "ui_name_steal_tech_escape";
6546 return "ui_name_targeted_steal_tech";
6548 return "ui_name_targeted_steal_tech_escape";
6550 return "ui_name_investigate_city";
6552 return "ui_name_investigate_city_spend_unit";
6554 return "ui_name_steal_gold";
6556 return "ui_name_steal_gold_escape";
6558 return "ui_name_spread_plague";
6559 case ACTION_STEAL_MAPS:
6560 return "ui_name_steal_maps";
6562 return "ui_name_steal_maps_escape";
6563 case ACTION_TRADE_ROUTE:
6564 return "ui_name_establish_trade_route";
6565 case ACTION_MARKETPLACE:
6566 return "ui_name_enter_marketplace";
6567 case ACTION_HELP_WONDER:
6568 return "ui_name_help_wonder";
6570 return "ui_name_capture_units";
6571 case ACTION_EXPEL_UNIT:
6572 return "ui_name_expel_unit";
6573 case ACTION_FOUND_CITY:
6574 return "ui_name_found_city";
6575 case ACTION_JOIN_CITY:
6576 return "ui_name_join_city";
6577 case ACTION_BOMBARD:
6578 return "ui_name_bombard";
6579 case ACTION_BOMBARD2:
6580 return "ui_name_bombard_2";
6581 case ACTION_BOMBARD3:
6582 return "ui_name_bombard_3";
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");
6887 /* TRANS: Lethal B_ombard (100% chance of success). */
6888 return N_("Lethal B%sombard%s");
6889 case ACTION_SPY_NUKE:
6890 /* TRANS: Suitcase _Nuke (100% chance of success). */
6891 return N_("Suitcase %sNuke%s");
6893 /* TRANS: Suitcase _Nuke and Escape (100% chance of success). */
6894 return N_("Suitcase %sNuke and Escape%s");
6895 case ACTION_NUKE:
6896 /* TRANS: Explode _Nuclear (100% chance of success). */
6897 return N_("Explode %sNuclear%s");
6898 case ACTION_NUKE_CITY:
6899 /* TRANS: _Nuke City (100% chance of success). */
6900 return N_("%sNuke City%s");
6901 case ACTION_NUKE_UNITS:
6902 /* TRANS: _Nuke Units (100% chance of success). */
6903 return N_("%sNuke Units%s");
6905 /* TRANS: Destroy _City (100% chance of success). */
6906 return N_("Destroy %sCity%s");
6908 /* TRANS: Dis_band recovering production (100% chance of success). */
6909 return N_("Dis%sband recovering production%s");
6911 /* TRANS: Dis_band without recovering production (100% chance of success). */
6912 return N_("Dis%sband without recovering production%s");
6913 case ACTION_HOME_CITY:
6914 /* TRANS: Set _Home City (100% chance of success). */
6915 return N_("Set %sHome City%s");
6916 case ACTION_HOMELESS:
6917 /* TRANS: Make _Homeless (100% chance of success). */
6918 return N_("Make %sHomeless%s");
6920 /* TRANS: _Upgrade Unit (100% chance of success). */
6921 return N_("%sUpgrade Unit%s");
6922 case ACTION_PARADROP:
6923 /* TRANS: Drop _Paratrooper (100% chance of success). */
6924 return N_("Drop %sParatrooper%s");
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");
6940 case ACTION_AIRLIFT:
6941 /* TRANS: _Airlift to City (100% chance of success). */
6942 return N_("%sAirlift to City%s");
6943 case ACTION_ATTACK:
6944 case ACTION_ATTACK2:
6945 /* TRANS: _Attack (100% chance of success). */
6946 return N_("%sAttack%s");
6949 /* TRANS: _Suicide Attack (100% chance of success). */
6950 return N_("%sSuicide Attack%s");
6951 case ACTION_WIPE_UNITS:
6952 /* TRANS: _Wipe Units (100% chance of success). */
6953 return N_("%sWipe Units%s");
6955 /* TRANS: Collect _Ransom (100% chance of success). */
6956 return N_("Collect %sRansom%s");
6958 /* TRANS: Surgical Str_ike Building (100% chance of success). */
6959 return N_("Surgical Str%sike Building%s");
6961 /* TRANS: Surgical Str_ike Production (100% chance of success). */
6962 return N_("Surgical Str%sike Production%s");
6966 /* TRANS: _Conquer City (100% chance of success). */
6967 return N_("%sConquer City%s");
6969 /* TRANS: _Conquer City 2 (100% chance of success). */
6970 return N_("%sConquer City 2%s");
6974 /* TRANS: _Conquer Extras (100% chance of success). */
6975 return N_("%sConquer Extras%s");
6977 /* TRANS: _Conquer Extras 2 (100% chance of success). */
6978 return N_("%sConquer Extras 2%s");
6979 case ACTION_HEAL_UNIT:
6980 case ACTION_HEAL_UNIT2:
6981 /* TRANS: Heal _Unit (3% chance of success). */
6982 return N_("Heal %sUnit%s");
6984 /* TRANS: _Transform Terrain (3% chance of success). */
6985 return N_("%sTransform Terrain%s");
6986 case ACTION_CULTIVATE:
6987 /* TRANS: Transform by _Cultivating (3% chance of success). */
6988 return N_("Transform by %sCultivating%s");
6989 case ACTION_PLANT:
6990 /* TRANS: Transform by _Planting (3% chance of success). */
6991 return N_("Transform by %sPlanting%s");
6992 case ACTION_PILLAGE:
6993 /* TRANS: Pilla_ge (100% chance of success). */
6994 return N_("Pilla%sge%s");
6995 case ACTION_CLEAN:
6996 /* TRANS: Clean (100% chance of success). */
6997 return N_("%sClean%s");
6998 case ACTION_FORTIFY:
6999 /* TRANS: _Fortify (100% chance of success). */
7000 return N_("%sFortify%s");
7001 case ACTION_ROAD:
7002 /* TRANS: Build _Road (100% chance of success). */
7003 return N_("Build %sRoad%s");
7004 case ACTION_CONVERT:
7005 /* TRANS: _Convert Unit (100% chance of success). */
7006 return N_("%sConvert Unit%s");
7007 case ACTION_BASE:
7008 /* TRANS: _Build Base (100% chance of success). */
7009 return N_("%sBuild Base%s");
7010 case ACTION_MINE:
7011 /* TRANS: Build _Mine (100% chance of success). */
7012 return N_("Build %sMine%s");
7013 case ACTION_IRRIGATE:
7014 /* TRANS: Build _Irrigation (100% chance of success). */
7015 return N_("Build %sIrrigation%s");
7017 /* TRANS: _Deboard (100% chance of success). */
7018 return N_("%sDeboard%s");
7022 /* TRANS: _Board (100% chance of success). */
7023 return N_("%sBoard%s");
7028 /* TRANS: _Embark (100% chance of success). */
7029 return N_("%sEmbark%s");
7031 /* TRANS: _Unload (100% chance of success). */
7032 return N_("%sUnload%s");
7036 /* TRANS: _Load (100% chance of success). */
7037 return N_("%sLoad%s");
7041 /* TRANS: _Disembark (100% chance of success). */
7042 return N_("%sDisembark%s");
7044 /* TRANS: _Disembark 2 (100% chance of success). */
7045 return N_("%sDisembark 2%s");
7046 case ACTION_SPY_ATTACK:
7047 /* TRANS: _Eliminate Diplomat (100% chance of success). */
7048 return N_("%sEliminate Diplomat%s");
7049 case ACTION_HUT_ENTER:
7050 case ACTION_HUT_ENTER2:
7051 case ACTION_HUT_ENTER3:
7052 case ACTION_HUT_ENTER4:
7053 /* TRANS: Enter _Hut (100% chance of success). */
7054 return N_("Enter %sHut%s");
7059 /* TRANS: Frighten _Hut (100% chance of success). */
7060 return N_("Frighten %sHut%s");
7061 case ACTION_UNIT_MOVE:
7062 case ACTION_UNIT_MOVE2:
7063 case ACTION_UNIT_MOVE3:
7064 /* TRANS: Regular _Move (100% chance of success). */
7065 return N_("Regular %sMove%s");
7066 case ACTION_TELEPORT:
7067 /* TRANS: _Teleport (100% chance of success). */
7068 return N_("%sTeleport%s");
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");
7084 case ACTION_SPY_ESCAPE:
7085 /* TRANS: _Escape To Nearest City (100% chance of success). */
7086 return N_("%sEscape To Nearest City%s");
7088 /* TRANS: _User Action 1 (100% chance of success). */
7089 return N_("%sUser Action 1%s");
7091 /* TRANS: _User Action 2 (100% chance of success). */
7092 return N_("%sUser Action 2%s");
7094 /* TRANS: _User Action 3 (100% chance of success). */
7095 return N_("%sUser Action 3%s");
7097 /* TRANS: _User Action 4 (100% chance of success). */
7098 return N_("%sUser Action 4%s");
7099 case ACTION_COUNT:
7100 fc_assert(act != ACTION_COUNT);
7101 break;
7102 }
7103
7104 return NULL;
7105}
7106
7107/**********************************************************************/
7114{
7115 switch ((enum gen_action)act) {
7116 case ACTION_SPY_POISON:
7140 case ACTION_STEAL_MAPS:
7142 case ACTION_TRADE_ROUTE:
7143 case ACTION_MARKETPLACE:
7144 case ACTION_HELP_WONDER:
7146 case ACTION_EXPEL_UNIT:
7147 case ACTION_FOUND_CITY:
7148 case ACTION_JOIN_CITY:
7149 case ACTION_SPY_NUKE:
7154 case ACTION_HOME_CITY:
7155 case ACTION_HOMELESS:
7157 case ACTION_PARADROP:
7163 case ACTION_AIRLIFT:
7164 case ACTION_ATTACK:
7165 case ACTION_ATTACK2:
7168 case ACTION_WIPE_UNITS:
7176 case ACTION_HEAL_UNIT:
7177 case ACTION_HEAL_UNIT2:
7179 case ACTION_CULTIVATE:
7180 case ACTION_PLANT:
7181 case ACTION_PILLAGE:
7182 case ACTION_CLEAN:
7183 case ACTION_FORTIFY:
7184 case ACTION_ROAD:
7185 case ACTION_CONVERT:
7186 case ACTION_BASE:
7187 case ACTION_MINE:
7188 case ACTION_IRRIGATE:
7205 case ACTION_BOMBARD:
7206 case ACTION_BOMBARD2:
7207 case ACTION_BOMBARD3:
7210 case ACTION_SPY_ATTACK:
7215 case ACTION_HUT_ENTER:
7216 case ACTION_HUT_ENTER2:
7217 case ACTION_HUT_ENTER3:
7218 case ACTION_HUT_ENTER4:
7223 case ACTION_UNIT_MOVE:
7224 case ACTION_UNIT_MOVE2:
7225 case ACTION_UNIT_MOVE3:
7226 case ACTION_SPY_ESCAPE:
7227 /* Min range is not ruleset changeable */
7228 return NULL;
7229 case ACTION_NUKE:
7230 return "explode_nuclear_min_range";
7231 case ACTION_NUKE_CITY:
7232 return "nuke_city_min_range";
7233 case ACTION_NUKE_UNITS:
7234 return "nuke_units_min_range";
7235 case ACTION_TELEPORT:
7236 return "teleport_min_range";
7238 return "teleport_conquer_min_range";
7240 return "teleport_frighten_min_range";
7242 return "teleport_frighten_conquer_min_range";
7244 return "teleport_enter_min_range";
7246 return "teleport_enter_conquer_min_range";
7248 return "user_action_1_min_range";
7250 return "user_action_2_min_range";
7252 return "user_action_3_min_range";
7254 return "user_action_4_min_range";
7255 case ACTION_COUNT:
7256 break;
7257
7259 }
7260
7261 fc_assert(act >= 0 && act < ACTION_COUNT);
7262
7263 return NULL;
7264}
7265
7266/**********************************************************************/
7273{
7274 switch ((enum gen_action)act) {
7275 case ACTION_SPY_POISON:
7299 case ACTION_STEAL_MAPS:
7301 case ACTION_TRADE_ROUTE:
7302 case ACTION_MARKETPLACE:
7304 case ACTION_EXPEL_UNIT:
7305 case ACTION_FOUND_CITY:
7306 case ACTION_JOIN_CITY:
7307 case ACTION_SPY_NUKE:
7311 case ACTION_HOME_CITY:
7312 case ACTION_HOMELESS:
7314 case ACTION_PARADROP:
7320 case ACTION_ATTACK:
7321 case ACTION_ATTACK2:
7324 case ACTION_WIPE_UNITS:
7332 case ACTION_HEAL_UNIT:
7333 case ACTION_HEAL_UNIT2:
7335 case ACTION_CULTIVATE:
7336 case ACTION_PLANT:
7337 case ACTION_PILLAGE:
7338 case ACTION_CLEAN:
7339 case ACTION_FORTIFY:
7340 case ACTION_ROAD:
7341 case ACTION_CONVERT:
7342 case ACTION_BASE:
7343 case ACTION_MINE:
7344 case ACTION_IRRIGATE:
7361 case ACTION_SPY_ATTACK:
7366 case ACTION_HUT_ENTER:
7367 case ACTION_HUT_ENTER2:
7368 case ACTION_HUT_ENTER3:
7369 case ACTION_HUT_ENTER4:
7374 case ACTION_UNIT_MOVE:
7375 case ACTION_UNIT_MOVE2:
7376 case ACTION_UNIT_MOVE3:
7377 case ACTION_SPY_ESCAPE:
7378 /* Max range is not ruleset changeable */
7379 return NULL;
7380 case ACTION_HELP_WONDER:
7381 return "help_wonder_max_range";
7383 return "disband_unit_recover_max_range";
7384 case ACTION_BOMBARD:
7385 return "bombard_max_range";
7386 case ACTION_BOMBARD2:
7387 return "bombard_2_max_range";
7388 case ACTION_BOMBARD3:
7389 return "bombard_3_max_range";
7391 return "bombard_lethal_max_range";
7393 return "bombard_lethal_2_max_range";
7394 case ACTION_NUKE:
7395 return "explode_nuclear_max_range";
7396 case ACTION_NUKE_CITY:
7397 return "nuke_city_max_range";
7398 case ACTION_NUKE_UNITS:
7399 return "nuke_units_max_range";
7400 case ACTION_AIRLIFT:
7401 return "airlift_max_range";
7402 case ACTION_TELEPORT:
7403 return "teleport_max_range";
7405 return "teleport_conquer_max_range";
7407 return "teleport_frighten_max_range";
7409 return "teleport_frighten_conquer_max_range";
7411 return "teleport_enter_max_range";
7413 return "teleport_enter_conquer_max_range";
7415 return "user_action_1_max_range";
7417 return "user_action_2_max_range";
7419 return "user_action_3_max_range";
7421 return "user_action_4_max_range";
7422 case ACTION_COUNT:
7423 break;
7424
7426 }
7427
7428 fc_assert(act >= 0 && act < ACTION_COUNT);
7429
7430 return NULL;
7431}
7432
7433/**********************************************************************/
7440{
7441 switch ((enum gen_action)act) {
7442 case ACTION_SPY_POISON:
7466 case ACTION_STEAL_MAPS:
7468 case ACTION_TRADE_ROUTE:
7469 case ACTION_MARKETPLACE:
7470 case ACTION_HELP_WONDER:
7472 case ACTION_EXPEL_UNIT:
7473 case ACTION_FOUND_CITY:
7474 case ACTION_JOIN_CITY:
7475 case ACTION_SPY_NUKE:
7477 case ACTION_NUKE_UNITS:
7481 case ACTION_HOME_CITY:
7482 case ACTION_HOMELESS:
7484 case ACTION_PARADROP:
7490 case ACTION_AIRLIFT:
7491 case ACTION_ATTACK:
7492 case ACTION_ATTACK2:
7495 case ACTION_WIPE_UNITS:
7503 case ACTION_HEAL_UNIT:
7504 case ACTION_HEAL_UNIT2:
7506 case ACTION_CULTIVATE:
7507 case ACTION_PLANT:
7508 case ACTION_CLEAN:
7509 case ACTION_FORTIFY:
7510 case ACTION_ROAD:
7511 case ACTION_CONVERT:
7512 case ACTION_BASE:
7513 case ACTION_MINE:
7514 case ACTION_IRRIGATE:
7531 case ACTION_BOMBARD:
7532 case ACTION_BOMBARD2:
7533 case ACTION_BOMBARD3:
7536 case ACTION_SPY_ATTACK:
7541 case ACTION_HUT_ENTER:
7542 case ACTION_HUT_ENTER2:
7543 case ACTION_HUT_ENTER3:
7544 case ACTION_HUT_ENTER4:
7549 case ACTION_UNIT_MOVE:
7550 case ACTION_UNIT_MOVE2:
7551 case ACTION_UNIT_MOVE3:
7552 case ACTION_TELEPORT:
7558 case ACTION_SPY_ESCAPE:
7559 /* Target kind is not ruleset changeable */
7560 return NULL;
7561 case ACTION_NUKE:
7562 return "explode_nuclear_target_kind";
7563 case ACTION_NUKE_CITY:
7564 return "nuke_city_target_kind";
7565 case ACTION_PILLAGE:
7566 return "pillage_target_kind";
7568 return "user_action_1_target_kind";
7570 return "user_action_2_target_kind";
7572 return "user_action_3_target_kind";
7574 return "user_action_4_target_kind";
7575 case ACTION_COUNT:
7576 break;
7577
7579 }
7580
7581 fc_assert(act >= 0 && act < ACTION_COUNT);
7582
7583 return NULL;
7584}
7585
7586/**********************************************************************/
7594{
7595 switch ((enum gen_action)act) {
7596 case ACTION_SPY_POISON:
7619 case ACTION_STEAL_MAPS:
7621 case ACTION_TRADE_ROUTE:
7622 case ACTION_MARKETPLACE:
7623 case ACTION_HELP_WONDER:
7625 case ACTION_EXPEL_UNIT:
7626 case ACTION_JOIN_CITY:
7627 case ACTION_SPY_NUKE:
7632 case ACTION_HOME_CITY:
7633 case ACTION_HOMELESS:
7635 case ACTION_PARADROP:
7641 case ACTION_AIRLIFT:
7642 case ACTION_ATTACK:
7643 case ACTION_ATTACK2:
7646 case ACTION_WIPE_UNITS:
7654 case ACTION_HEAL_UNIT:
7655 case ACTION_HEAL_UNIT2:
7657 case ACTION_CULTIVATE:
7658 case ACTION_PLANT:
7659 case ACTION_PILLAGE:
7660 case ACTION_CLEAN:
7661 case ACTION_FORTIFY:
7662 case ACTION_ROAD:
7663 case ACTION_CONVERT:
7664 case ACTION_BASE:
7665 case ACTION_MINE:
7666 case ACTION_IRRIGATE:
7683 case ACTION_BOMBARD:
7684 case ACTION_BOMBARD2:
7685 case ACTION_BOMBARD3:
7688 case ACTION_SPY_ATTACK:
7693 case ACTION_HUT_ENTER:
7694 case ACTION_HUT_ENTER2:
7695 case ACTION_HUT_ENTER3:
7696 case ACTION_HUT_ENTER4:
7701 case ACTION_UNIT_MOVE:
7702 case ACTION_UNIT_MOVE2:
7703 case ACTION_UNIT_MOVE3:
7704 case ACTION_TELEPORT:
7710 case ACTION_SPY_ESCAPE:
7711 /* Actor consuming always is not ruleset changeable */
7712 return NULL;
7713 case ACTION_FOUND_CITY:
7714 return "found_city_consuming_always";
7715 case ACTION_NUKE:
7716 return "explode_nuclear_consuming_always";
7717 case ACTION_NUKE_CITY:
7718 return "nuke_city_consuming_always";
7719 case ACTION_NUKE_UNITS:
7720 return "nuke_units_consuming_always";
7722 return "spread_plague_actor_consuming_always";
7724 return "user_action_1_actor_consuming_always";
7726 return "user_action_2_actor_consuming_always";
7728 return "user_action_3_actor_consuming_always";
7730 return "user_action_4_actor_consuming_always";
7731 case ACTION_COUNT:
7732 break;
7733
7735 }
7736
7737 fc_assert(act >= 0 && act < ACTION_COUNT);
7738
7739 return NULL;
7740}
7741
7742/**********************************************************************/
7749const char *action_blocked_by_ruleset_var_name(const struct action *act)
7750{
7751 fc_assert_ret_val(act != NULL, NULL);
7752
7753 switch ((enum gen_action)action_number(act)) {
7754 case ACTION_MARKETPLACE:
7755 return "enter_marketplace_blocked_by";
7756 case ACTION_BOMBARD:
7757 return "bombard_blocked_by";
7758 case ACTION_BOMBARD2:
7759 return "bombard_2_blocked_by";
7760 case ACTION_BOMBARD3:
7761 return "bombard_3_blocked_by";
7763 return "bombard_lethal_blocked_by";
7765 return "bombard_lethal_2_blocked_by";
7766 case ACTION_NUKE:
7767 return "explode_nuclear_blocked_by";
7768 case ACTION_NUKE_CITY:
7769 return "nuke_city_blocked_by";
7770 case ACTION_NUKE_UNITS:
7771 return "nuke_units_blocked_by";
7772 case ACTION_ATTACK:
7773 return "attack_blocked_by";
7774 case ACTION_ATTACK2:
7775 return "attack_2_blocked_by";
7777 return "suicide_attack_blocked_by";
7779 return "suicide_attack_2_blocked_by";
7780 case ACTION_WIPE_UNITS:
7781 return "wipe_units_blocked_by";
7783 return "collect_ransom_blocked_by";
7785 return "conquer_city_blocked_by";
7787 return "conquer_city_2_blocked_by";
7789 return "conquer_city_3_blocked_by";
7791 return "conquer_city_4_blocked_by";
7792 case ACTION_UNIT_MOVE:
7793 return "move_blocked_by";
7794 case ACTION_UNIT_MOVE2:
7795 return "move_2_blocked_by";
7796 case ACTION_UNIT_MOVE3:
7797 return "move_3_blocked_by";
7798 case ACTION_TELEPORT:
7799 return "teleport_blocked_by";
7801 return "teleport_conquer_blocked_by";
7803 return "teleport_frighten_blocked_by";
7805 return "teleport_frighten_conquer_blocked_by";
7807 return "teleport_enter_blocked_by";
7809 return "teleport_enter_conquer_blocked_by";
7810 case ACTION_SPY_ESCAPE:
7811 case ACTION_SPY_POISON:
7834 case ACTION_STEAL_MAPS:
7836 case ACTION_TRADE_ROUTE:
7837 case ACTION_HELP_WONDER:
7839 case ACTION_EXPEL_UNIT:
7840 case ACTION_FOUND_CITY:
7841 case ACTION_JOIN_CITY:
7842 case ACTION_SPY_NUKE:
7847 case ACTION_HOME_CITY:
7848 case ACTION_HOMELESS:
7850 case ACTION_PARADROP:
7856 case ACTION_AIRLIFT:
7859 case ACTION_HEAL_UNIT:
7860 case ACTION_HEAL_UNIT2:
7862 case ACTION_CULTIVATE:
7863 case ACTION_PLANT:
7864 case ACTION_PILLAGE:
7865 case ACTION_CLEAN:
7866 case ACTION_FORTIFY:
7867 case ACTION_ROAD:
7868 case ACTION_CONVERT:
7869 case ACTION_BASE:
7870 case ACTION_MINE:
7871 case ACTION_IRRIGATE:
7889 case ACTION_SPY_ATTACK:
7894 case ACTION_HUT_ENTER:
7895 case ACTION_HUT_ENTER2:
7896 case ACTION_HUT_ENTER3:
7897 case ACTION_HUT_ENTER4:
7906 /* blocked_by is not ruleset changeable */
7907 return NULL;
7908 case ACTION_COUNT:
7910 break;
7911
7913 }
7914
7915 return NULL;
7916}
7917
7918/**********************************************************************/
7922const char *
7924{
7925 fc_assert_ret_val(act != NULL, NULL);
7926
7931 /* No support in the action performer function */
7932 return NULL;
7933 }
7934
7935 switch ((enum gen_action)action_number(act)) {
7937 return "bribe_unit_post_success_forced_actions";
7938 case ACTION_ATTACK:
7939 return "attack_post_success_forced_actions";
7940 case ACTION_ATTACK2:
7941 return "attack_2_post_success_forced_actions";
7942 case ACTION_WIPE_UNITS:
7943 return "wipe_units_post_success_forced_actions";
7945 return "collect_ransom_post_success_forced_actions";
7946 case ACTION_MARKETPLACE:
7947 case ACTION_BOMBARD:
7948 case ACTION_BOMBARD2:
7949 case ACTION_BOMBARD3:
7952 case ACTION_NUKE:
7953 case ACTION_NUKE_CITY:
7954 case ACTION_NUKE_UNITS:
7961 case ACTION_SPY_POISON:
7983 case ACTION_STEAL_MAPS:
7985 case ACTION_TRADE_ROUTE:
7986 case ACTION_HELP_WONDER:
7988 case ACTION_EXPEL_UNIT:
7989 case ACTION_FOUND_CITY:
7990 case ACTION_JOIN_CITY:
7991 case ACTION_SPY_NUKE:
7996 case ACTION_HOME_CITY:
7997 case ACTION_HOMELESS:
7999 case ACTION_PARADROP:
8005 case ACTION_AIRLIFT:
8008 case ACTION_HEAL_UNIT:
8009 case ACTION_HEAL_UNIT2:
8011 case ACTION_CULTIVATE:
8012 case ACTION_PLANT:
8013 case ACTION_PILLAGE:
8014 case ACTION_CLEAN:
8015 case ACTION_FORTIFY:
8016 case ACTION_ROAD:
8017 case ACTION_CONVERT:
8018 case ACTION_BASE:
8019 case ACTION_MINE:
8020 case ACTION_IRRIGATE:
8038 case ACTION_SPY_ATTACK:
8043 case ACTION_HUT_ENTER:
8044 case ACTION_HUT_ENTER2:
8045 case ACTION_HUT_ENTER3:
8046 case ACTION_HUT_ENTER4:
8051 case ACTION_UNIT_MOVE:
8052 case ACTION_UNIT_MOVE2:
8053 case ACTION_UNIT_MOVE3:
8054 case ACTION_TELEPORT:
8060 case ACTION_SPY_ESCAPE:
8065 /* Not ruleset changeable */
8066 return NULL;
8067 case ACTION_COUNT:
8069 break;
8070
8072 }
8073
8074 return NULL;
8075}
8076
8077/**********************************************************************/
8085
8086/**********************************************************************/
8089const char *gen_action_name_update_cb(const char *old_name)
8090{
8091 if (is_ruleset_compat_mode()) {
8092 if (!fc_strcasecmp("Transport Alight", old_name)) {
8093 return "Transport Deboard";
8094 }
8095 }
8096
8097 return old_name;
8098}
8099
8101{
8102 N_("individual cities"), /* ATK_CITY */
8103 N_("individual units"), /* ATK_UNIT */
8104 N_("unit stacks"), /* ATK_UNITS */
8105 N_("tiles"), /* ATK_TILE */
8106 N_("tile extras"), /* ATK_EXTRAS */
8107 N_("itself") /* ATK_SELF */
8108};
8109
8110/**********************************************************************/
8115{
8116 fc_assert(kind >= 0 && kind < ATK_COUNT);
8117
8118 return _(atk_helpnames[kind]);
8119}
8120
8121/************************************************************************/
8125{
8126 fc_assert(result < ACTRES_LAST);
8127
8128 return actlist_by_result[result];
8129}
8130
8131/************************************************************************/
8135{
8136 fc_assert(activity < ACTIVITY_LAST);
8137
8138 return actlist_by_activity[activity];
8139}
bool is_action_possible_on_city(action_id act_id, const struct player *actor_player, const struct city *target_city)
Definition actions.c:6216
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:2064
const char * action_name_translation(const struct action *action)
Definition actions.c:1982
bool action_distance_inside_max(const struct action *action, const int distance)
Definition actions.c:1925
static void oblig_hard_req_reg(struct ae_contra_or *contras, const char *error_message,...)
Definition actions.c:247
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:3553
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:2175
bool action_mp_full_makes_legal(const struct unit *actor, const action_id act_id)
Definition actions.c:6294
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:4521
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:4171
enum action_actor_kind action_get_actor_kind(const struct action *paction)
Definition actions.c:1850
bool action_prob_certain(const struct act_prob probability)
Definition actions.c:5833
const char * action_id_name_translation(action_id act_id)
Definition actions.c:2002
struct action_auto_perf * action_auto_perf_slot_number(const int num)
Definition actions.c:6423
req_vec_num_in_item action_enabler_vector_number(const void *enabler, const struct requirement_vector *vec)
Definition actions.c:2800
bool action_has_complex_target(const struct action *paction)
Definition actions.c:1884
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:3140
static struct obligatory_req_vector oblig_hard_reqs_r[ACTRES_NONE]
Definition actions.c:105
struct act_prob action_prob_self(const struct unit *actor_unit, const action_id act_id)
Definition actions.c:5497
struct req_vec_problem * action_enabler_suggest_repair(const struct action_enabler *enabler)
Definition actions.c:2670
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:4015
bool action_prob_possible(const struct act_prob probability)
Definition actions.c:5823
#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:3347
struct act_prob action_prob_new_not_impl(void)
Definition actions.c:5802
struct req_vec_problem * action_enabler_suggest_improvement(const struct action_enabler *enabler)
Definition actions.c:2736
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:4252
void actions_rs_pre_san_gen(void)
Definition actions.c:1645
const char * action_min_range_ruleset_var_name(int act)
Definition actions.c:7113
const char * action_blocked_by_ruleset_var_name(const struct action *act)
Definition actions.c:7749
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:3728
#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:4569
struct req_vec_problem * action_enabler_suggest_repair_oblig(const struct action_enabler *enabler)
Definition actions.c:2430
void action_array_add_all_by_result(action_id *act_array, int *position, enum action_result result)
Definition actions.c:6488
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:6123
void action_array_end(action_id *act_array, int size)
Definition actions.c:6471
static struct ae_contra_or * req_contradiction_or(int alternatives,...)
Definition actions.c:155
bool is_action_enabled_unit_on_self(const action_id wanted_action, const struct unit *actor_unit)
Definition actions.c:4223
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:4477
const char * atk_helpnames[ATK_COUNT]
Definition actions.c:8100
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:3367
static void hard_code_actions(void)
Definition actions.c:925
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:3767
bool action_is_in_use(struct action *paction)
Definition actions.c:6400
struct act_prob action_prob_unit_vs_tgt(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:5519
static struct req_vec_problem * enabler_tile_tgt_local_diplrel_implies_claimed(const struct action_enabler *enabler)
Definition actions.c:2525
bool action_ever_possible(action_id action)
Definition actions.c:8081
const char * action_enabler_vector_by_number_name(req_vec_num_in_item vec)
Definition actions.c:2847
bool are_action_probabilitys_equal(const struct act_prob *ap1, const struct act_prob *ap2)
Definition actions.c:5874
struct act_prob action_prob_vs_city(const struct unit *actor_unit, const action_id act_id, const struct city *target_city)
Definition actions.c:4981
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:5444
const char * action_post_success_forced_ruleset_var_name(const struct action *act)
Definition actions.c:7923
struct act_prob action_prob_vs_unit(const struct unit *actor_unit, const action_id act_id, const struct unit *target_unit)
Definition actions.c:5065
struct action * action_by_rule_name(const char *name)
Definition actions.c:1831
static bool action_has_possible_actor_hard_reqs(struct action *paction)
Definition actions.c:6375
const char * action_rule_name(const struct action *action)
Definition actions.c:1968
const char * action_id_rule_name(action_id act_id)
Definition actions.c:1991
enum action_sub_target_kind action_get_sub_target_kind(const struct action *paction)
Definition actions.c:1871
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:2915
static bool action_prob_not_relevant(const struct act_prob probability)
Definition actions.c:5844
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:4431
void actions_free(void)
Definition actions.c:1655
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:4092
void action_enabler_free(struct action_enabler *enabler)
Definition actions.c:2246
struct act_prob action_prob_vs_tile(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
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:3997
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:4318
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:8134
int action_number(const struct action *action)
Definition actions.c:1960
struct act_prob action_prob_new_unknown(void)
Definition actions.c:5812
bool action_would_be_blocked_by(const struct action *blocked, const struct action *blocker)
Definition actions.c:1948
#define ACTPROB_VAL_NA
Definition actions.c:93
static struct req_vec_problem * enabler_first_clarification(const struct action_enabler *enabler)
Definition actions.c:2718
struct act_prob action_speculate_unit_on_self(action_id act_id, const struct unit *actor, const struct city *actor_home, const struct tile *actor_tile, bool omniscient_cheat)
Definition actions.c:5744
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:4298
static bool action_prob_not_impl(const struct act_prob probability)
Definition actions.c:5855
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:4073
struct act_prob action_prob_and(const struct act_prob *ap1, const struct act_prob *ap2)
Definition actions.c:5961
static bool actions_initialized
Definition actions.c:100
const char * action_actor_consuming_always_ruleset_var_name(action_id act)
Definition actions.c:7593
bool action_immune_government(struct government *gov, action_id act)
Definition actions.c:6175
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:6198
static struct act_prob ap_dipl_battle_win(const struct unit *pattacker, const struct unit *pdefender)
Definition actions.c:4354
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:5083
struct action * action_is_blocked_by(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:3027
struct act_prob action_prob_new_certain(void)
Definition actions.c:5782
const char * action_max_range_ruleset_var_name(int act)
Definition actions.c:7272
struct act_prob action_speculate_unit_on_stack(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:5643
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:4894
int action_dice_roll_initial_odds(const struct action *paction)
Definition actions.c:6099
struct act_prob action_prob_fall_back(const struct act_prob *ap1, const struct act_prob *ap2)
Definition actions.c:6031
#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:2890
static struct requirement * req_vec_first_local_diplrel(const struct requirement_vector *vec)
Definition actions.c:2481
struct act_prob action_prob_vs_stack(const struct unit *actor_unit, const action_id act_id, const struct tile *target_tile)
Definition actions.c:5258
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
struct act_prob action_speculate_unit_on_extras(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:5710
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:3832
bool is_action_enabled_unit_on_extras(const action_id wanted_action, const struct unit *actor_unit, const struct tile *target_tile, const struct extra_type *target_extra)
Definition actions.c:4150
struct action_list * action_list_by_result(enum action_result result)
Definition actions.c:8124
bool action_univs_not_blocking(const struct action *paction, struct universal *actor_uni, struct universal *target_uni)
Definition actions.c:6447
static struct requirement * req_vec_first_contradiction_in_vec(const struct requirement *req, const struct requirement_vector *vec)
Definition actions.c:2502
bool actions_are_ready(void)
Definition actions.c:1708
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:3909
struct act_prob action_speculate_unit_on_city(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:5575
const char * action_target_kind_ruleset_var_name(int act)
Definition actions.c:7439
#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:4998
bool action_maybe_possible_actor_unit(const struct civ_map *nmap, const action_id act_id, const struct unit *actor_unit)
Definition actions.c:6239
static bool is_enabler_active(const struct action_enabler *enabler, const struct req_context *actor, const struct req_context *target)
Definition actions.c:3709
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:2273
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:6317
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:4459
struct action_enabler * action_enabler_new(void)
Definition actions.c:2227
bool action_requires_details(const struct action *paction)
Definition actions.c:1897
struct act_prob action_prob_new_not_relevant(void)
Definition actions.c:5792
const char * action_target_kind_help(enum action_target_kind kind)
Definition actions.c:8114
static struct req_vec_problem * enabler_first_self_contradiction(const struct action_enabler *enabler)
Definition actions.c:2598
int action_get_role(const struct action *paction)
Definition actions.c:2215
struct act_prob action_prob_vs_extras(const struct unit *actor_unit, const action_id act_id, const struct tile *target_tile, const struct extra_type *target_extra)
Definition actions.c:5426
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:1795
struct act_prob action_speculate_unit_on_unit(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:5610
const struct action_auto_perf * action_auto_perf_by_number(const int num)
Definition actions.c:6439
struct act_prob action_prob_new_impossible(void)
Definition actions.c:5772
bool action_enabler_possible_actor(const struct action_enabler *ae)
Definition actions.c:6344
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:2973
struct action ** _actions
Definition actions.c:98
bool action_id_exists(const action_id act_id)
Definition actions.c:1820
bool action_enabler_remove(struct action_enabler *enabler)
Definition actions.c:2290
enum action_target_kind action_get_target_kind(const struct action *paction)
Definition actions.c:1860
static bool action_prob_is_signal(const struct act_prob probability)
Definition actions.c:5866
struct action_enabler * action_enabler_copy(const struct action_enabler *original)
Definition actions.c:2258
static const char * action_prob_to_text(const struct act_prob prob)
Definition actions.c:2023
int action_prob_cmp_pessimist(const struct act_prob ap1, const struct act_prob ap2)
Definition actions.c:5883
bool action_id_is_rare_pop_up(action_id act_id)
Definition actions.c:1912
void actions_init(void)
Definition actions.c:1585
struct act_prob action_speculate_unit_on_tile(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:5676
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:1732
static void hard_code_oblig_hard_reqs_ruleset(void)
Definition actions.c:888
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:2326
static const struct impr_type * tgt_city_local_building(const struct city *target_city)
Definition actions.c:2867
static struct astring ui_name_str
Definition actions.c:108
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:3850
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:3927
double action_prob_to_0_to_1_pessimist(const struct act_prob ap)
Definition actions.c:5934
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:8089
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:2306
struct requirement_vector * action_enabler_vector_by_number(const void *enabler, req_vec_num_in_item number)
Definition actions.c:2823
bool action_distance_accepted(const struct action *action, const int distance)
Definition actions.c:1936
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:5360
const char * action_ui_name_ruleset_var_name(int act)
Definition actions.c:6508
const char * action_get_ui_name_mnemonic(action_id act_id, const char *mnemonic)
Definition actions.c:2010
#define ACTPROB_VAL_MIN
Definition actions.c:87
#define ACTION_DISTANCE_MAX
Definition actions.h:357
#define enabler_get_action(_enabler_)
Definition actions.h:431
#define ASSERT_UNUSED_ACTION_CASES
Definition actions.h:38
#define ACTPROB_CERTAIN
Definition actions.h:905
#define enabler_get_action_id(_enabler_)
Definition actions.h:432
#define ACTPROB_NA
Definition actions.h:906
static struct action * action_by_number(action_id act_id)
Definition actions.h:633
#define action_enabler_list_re_iterate_end
Definition actions.h:445
#define ACTION_DISTANCE_LAST_NON_SIGNAL
Definition actions.h:353
#define action_enabler_list_re_iterate(action_enabler_list, aenabler)
Definition actions.h:441
#define action_has_result(_act_, _res_)
Definition actions.h:429
#define action_enabler_list_iterate_end
Definition actions.h:439
#define ACTION_DISTANCE_UNLIMITED
Definition actions.h:355
#define action_iterate_end
Definition actions.h:463
#define MAX_NUM_ACTIONS
Definition actions.h:312
#define action_iterate_all(_act_)
Definition actions.h:449
#define action_id_get_actor_kind(act_id)
Definition actions.h:646
#define action_iterate_all_end
Definition actions.h:454
#define ACTPROB_NOT_KNOWN
Definition actions.h:908
#define action_enabler_list_iterate(action_enabler_list, aenabler)
Definition actions.h:437
#define action_id_distance_accepted(act_id, distance)
Definition actions.h:682
#define ACTPROB_IMPOSSIBLE
Definition actions.h:904
#define ACTPROB_NOT_IMPLEMENTED
Definition actions.h:907
#define action_iterate(_act_)
Definition actions.h:459
#define ACTION_ANY
Definition actions.h:306
#define action_id_get_target_kind(act_id)
Definition actions.h:650
#define action_id_has_result_safe(act_id, result)
Definition actions.h:663
#define ACTION_ODDS_PCT_DICE_ROLL_NA
Definition actions.h:911
#define ACTION_NONE
Definition actions.h:309
enum action_sub_target_kind actres_sub_target_kind_default(enum action_result result)
Definition actres.c:669
enum act_tgt_compl actres_target_compl_calc(enum action_result result)
Definition actres.c:258
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:831
enum unit_activity actres_activity_result(enum action_result result)
Definition actres.c:301
enum dice_roll_type actres_dice_type(enum action_result result)
Definition actres.c:364
enum action_battle_kind actres_get_battle_kind(enum action_result result)
Definition actres.c:272
enum action_target_kind actres_target_kind_default(enum action_result result)
Definition actres.c:766
#define ASSERT_UNUSED_ACTRES_CASES
Definition actres.h:37
@ DRT_DIPLCHANCE
Definition actres.h:110
@ DRT_CERTAIN
Definition actres.h:110
@ DRT_NONE
Definition actres.h:110
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:750
#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:834
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:940
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:55
char * incite_cost
Definition comments.c:74
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:380
@ RPT_CERTAIN
Definition fc_types.h:704
@ RPT_POSSIBLE
Definition fc_types.h:703
int action_id
Definition fc_types.h:392
#define ACTRES_NONE
Definition fc_types.h:330
#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
struct world wld
Definition game.c:63
static bool is_ruleset_compat_mode(void)
Definition game.h:361
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:561
action_id alternatives[MAX_NUM_ACTIONS]
Definition actions.h:569
struct requirement req
Definition actions.c:43
action_id action
Definition actions.h:420
struct requirement_vector actor_reqs
Definition actions.h:421
struct requirement_vector target_reqs
Definition actions.h:422
bool unitwaittime_controlled
Definition actions.h:409
action_id id
Definition actions.h:361
bool actor_consuming_always
Definition actions.h:393
bool rare_pop_up
Definition actions.h:406
int max_distance
Definition actions.h:376
bool quiet
Definition actions.h:383
enum action_sub_target_kind sub_target_kind
Definition actions.h:368
enum moves_actor_kind moves_actor
Definition actions.h:413
struct action::@12::@13 is_unit
enum action_result result
Definition actions.h:363
char ui_name[MAX_LEN_NAME]
Definition actions.h:379
bv_action_sub_results sub_results
Definition actions.h:364
enum action_actor_kind actor_kind
Definition actions.h:366
enum act_tgt_compl target_complexity
Definition actions.h:371
bv_actions blocked_by
Definition actions.h:387
union action::@12 actor
enum action_target_kind target_kind
Definition actions.h:367
int min_distance
Definition actions.h:376
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:903
struct civ_map map
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:2437
bool unit_can_do_action(const struct unit *punit, const action_id act_id)
Definition unit.c:361
bool unit_transported(const struct unit *pcargo)
Definition unit.c:2421
bool can_unit_unload(const struct unit *pcargo, const struct unit *ptrans)
Definition unit.c:748
bool unit_can_convert(const struct civ_map *nmap, const struct unit *punit)
Definition unit.c:2031
#define unit_tile(_pu)
Definition unit.h:390
#define unit_owner(_pu)
Definition unit.h:389
#define unit_home(_pu_)
Definition unit.h:387
#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:2583
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:852
#define unit_type_iterate_end
Definition unittype.h:859
#define U_NOT_OBSOLETED
Definition unittype.h:528