Freeciv21
Develop your civilization from humble roots to a global empire
actions.cpp
Go to the documentation of this file.
1 /*
2 Copyright (c) 1996-2020 Freeciv21 and Freeciv contributors. This file is
3  /\/\ part of Freeciv21. Freeciv21 is free software: you can
4  \_\ _..._ redistribute it and/or modify it under the terms of the
5  (" )(_..._) GNU General Public License as published by the Free
6  ^^ // \\ Software Foundation, either version 3 of the License,
7  or (at your option) any later version. You should have
8 received a copy of the GNU General Public License along with Freeciv21.
9  If not, see https://www.gnu.org/licenses/.
10  */
11 
12 #include <cmath> // ceil, floor
13 #include <cstdarg>
14 
15 // utility
16 #include "fcintl.h"
17 
18 // common
19 #include "actions.h"
20 #include "city.h"
21 #include "combat.h"
22 #include "fc_interface.h"
23 #include "game.h"
24 #include "map.h"
25 #include "movement.h"
26 #include "nation.h"
27 #include "research.h"
28 #include "server_settings.h"
29 #include "tile.h"
30 #include "unit.h"
31 
32 // Custom data types for obligatory hard action requirements.
33 
34 // A contradiction to an obligatory hard requirement.
36  // A requirement that contradicts the obligatory hard requirement.
37  struct requirement req;
38 
39  /* Is the obligatory hard requirement in the action enabler's target
40  * requirement vector? If FALSE it is in its actor requirement vector. */
41  bool is_target;
42 };
43 
44 // One or more alternative obligatory hard requirement contradictions.
45 struct ae_contra_or {
47  /* The obligatory hard requirement is fulfilled if a contradiction exists
48  * that doesn't contradict the action enabler. */
50 
51  // How many obligatory reqs use this
52  int users;
53 };
54 
55 // An obligatory hard action requirement
57  /* The requirement is fulfilled if the action enabler doesn't contradict
58  * one of the contradictions listed here. */
60 
61  /* The error message to show when the hard obligatory requirement is
62  * missing. Must be there. */
63  const char *error_msg;
64 };
65 
66 #define SPECVEC_TAG obligatory_req
67 #define SPECVEC_TYPE struct obligatory_req
68 #include "specvec.h"
69 #define obligatory_req_vector_iterate(obreq_vec, pobreq) \
70  TYPED_VECTOR_ITERATE(struct obligatory_req, obreq_vec, pobreq)
71 #define obligatory_req_vector_iterate_end VECTOR_ITERATE_END
72 
73 /* Values used to interpret action probabilities.
74  *
75  * Action probabilities are sent over the network. A change in a value here
76  * will therefore change the network protocol.
77  *
78  * A change in a value here should also update the action probability
79  * format documentation in fc_types.h */
80 // The lowest possible probability value (0%)
81 #define ACTPROB_VAL_MIN 0
82 // The highest possible probability value (100%)
83 #define ACTPROB_VAL_MAX 200
84 // A probability increase of 1% corresponds to this increase.
85 #define ACTPROB_VAL_1_PCT (ACTPROB_VAL_MAX / 100)
86 // Action probability doesn't apply when min is this.
87 #define ACTPROB_VAL_NA 253
88 // Action probability unsupported when min is this.
89 #define ACTPROB_VAL_NOT_IMPL 254
90 
91 static struct action *actions[MAX_NUM_ACTIONS];
93 static bool actions_initialized = false;
94 
95 static struct action_enabler_list
97 
98 // Hard requirements relates to action result.
99 static struct obligatory_req_vector obligatory_hard_reqs[ACTRES_NONE];
100 
101 static struct action *
102 unit_action_new(action_id id, enum action_result result,
103  enum action_target_kind target_kind,
104  enum action_sub_target_kind sub_target_kind,
105  enum act_tgt_compl tgt_compl, bool rare_pop_up,
107  enum moves_actor_kind moves_actor, const int min_distance,
108  const int max_distance, bool actor_consuming_always);
109 
110 static bool is_enabler_active(
111  const struct action_enabler *enabler, const struct player *actor_player,
112  const struct city *actor_city, const struct impr_type *actor_building,
113  const struct tile *actor_tile, const struct unit *actor_unit,
114  const struct unit_type *actor_unittype,
115  const struct output_type *actor_output,
116  const struct specialist *actor_specialist,
117  const struct player *target_player, const struct city *target_city,
118  const struct impr_type *target_building, const struct tile *target_tile,
119  const struct unit *target_unit, const struct unit_type *target_unittype,
120  const struct output_type *target_output,
121  const struct specialist *target_specialist);
122 
123 static inline bool action_prob_is_signal(const struct act_prob probability);
124 static inline bool
125 action_prob_not_relevant(const struct act_prob probability);
126 static inline bool action_prob_not_impl(const struct act_prob probability);
127 
128 // Make sure that an action distance can target the whole map.
130  action_range_can_not_cover_the_whole_map);
131 
144 {
145  int i;
146  va_list args;
147 
148  fc_assert_ret_val(alternatives > 0, nullptr);
149  auto *out = new ae_contra_or;
150  out->users = 0;
151  out->alternatives = alternatives;
152  out->alternative = new action_enabler_contradiction[alternatives];
153 
154  va_start(args, alternatives);
155  for (i = 0; i < alternatives; i++) {
156  struct requirement contradiction = va_arg(args, struct requirement);
157  bool is_target = va_arg(args, int);
158 
159  out->alternative[i].req = contradiction;
160  out->alternative[i].is_target = is_target;
161  }
162  va_end(args);
163 
164  return out;
165 }
166 
171 static void ae_contra_close(struct ae_contra_or *contra)
172 {
173  contra->users--;
174 
175  if (contra->users < 1) {
176  // No users left. Delete.
177  delete[] contra->alternative;
178  delete contra;
179  }
180 }
181 
190 static void voblig_hard_req_reg(struct ae_contra_or *contras,
191  const char *error_message, va_list args)
192 {
193  struct obligatory_req oreq;
194  enum action_result res;
195 
196  /* A non null action message is used to indicate that an obligatory hard
197  * requirement is missing. */
198  fc_assert_ret(error_message);
199 
200  // Pack the obligatory hard requirement.
201  oreq.contras = contras;
202  oreq.error_msg = error_message;
203 
204  /* Add the obligatory hard requirement to each action result it applies
205  * to. */
206  while (ACTRES_NONE != (res = action_result(va_arg(args, int)))) {
207  /* Any invalid action result should terminate the loop before this
208  * assertion. */
209  fc_assert_ret_msg(action_result_is_valid(res),
210  "Invalid action result %d", res);
211 
212  // Add to list for action result
213  obligatory_req_vector_append(&obligatory_hard_reqs[res], oreq);
214 
215  // Register the new user.
216  oreq.contras->users++;
217  }
218 }
219 
229  const char *error_message, ...)
230 {
231  va_list args;
232 
233  /* Add the obligatory hard requirement to each action result it applies
234  * to. */
235  va_start(args, error_message);
236  voblig_hard_req_reg(contras, error_message, args);
237  va_end(args);
238 }
239 
247 static void oblig_hard_req_register(const struct requirement &contradiction,
248  bool is_target,
249  const char *error_message, ...)
250 {
251  struct ae_contra_or *contra;
252  va_list args;
253 
254  // Pack the obligatory hard requirement.
255  contra = req_contradiction_or(1, contradiction, is_target);
256 
257  /* Add the obligatory hard requirement to each action result it applies
258  * to. */
259  va_start(args, error_message);
260  voblig_hard_req_reg(contra, error_message, args);
261  va_end(args);
262 }
263 
270 {
271  /* Why this is a hard requirement: There is currently no point in
272  * allowing the listed actions against domestic targets.
273  * (Possible counter argument: crazy hack involving the Lua
274  * callback action_started_callback() to use an action to do
275  * something else. */
276  // TODO: Unhardcode as a part of false flag operation support.
278  req_from_values(VUT_DIPLREL, REQ_RANGE_LOCAL, false, false, true,
279  DRO_FOREIGN),
280  false,
281  N_("All action enablers for %s must require a "
282  "foreign target."),
283  ACTRES_ESTABLISH_EMBASSY, ACTRES_SPY_INVESTIGATE_CITY,
284  ACTRES_SPY_STEAL_GOLD, ACTRES_STEAL_MAPS, ACTRES_SPY_STEAL_TECH,
285  ACTRES_SPY_TARGETED_STEAL_TECH, ACTRES_SPY_INCITE_CITY,
286  ACTRES_SPY_BRIBE_UNIT, ACTRES_CAPTURE_UNITS, ACTRES_CONQUER_CITY,
287  ACTRES_NONE);
288 
289  /* Why this is a hard requirement: There is currently no point in
290  * establishing an embassy when a real embassy already exists.
291  * (Possible exception: crazy hack using the Lua callback
292  * action_started_callback() to make establish embassy do something
293  * else even if the UI still call the action Establish Embassy) */
294  oblig_hard_req_register(req_from_values(VUT_DIPLREL, REQ_RANGE_LOCAL,
295  false, true, true,
296  DRO_HAS_REAL_EMBASSY),
297  false,
298  N_("All action enablers for %s must require the"
299  " absence of a real embassy."),
300  ACTRES_ESTABLISH_EMBASSY, ACTRES_NONE);
301 
302  /* Why this is a hard requirement: There is currently no point in
303  * fortifying an already fortified unit. */
304  oblig_hard_req_register(req_from_values(VUT_ACTIVITY, REQ_RANGE_LOCAL,
305  false, true, true,
306  ACTIVITY_FORTIFIED),
307  false,
308  N_("All action enablers for %s must require that"
309  " the actor unit isn't already fortified."),
310  ACTRES_FORTIFY, ACTRES_NONE);
311 
312  /* Why this is a hard requirement: there is a hard requirement that
313  * the actor player is at war with the owner of any city on the
314  * target tile. It can't move to the ruleset as long as Bombard and Attack
315  * are targeted at unit stacks only. Having the same requirement
316  * against each unit in the stack as against any city at the tile
317  * ensures compatibility with any future solution that allows the
318  * requirement against any city on the target tile to move to the
319  * ruleset. The Freeciv code assumes that ACTRES_ATTACK has this. */
320  oblig_hard_req_register(req_from_values(VUT_DIPLREL, REQ_RANGE_LOCAL,
321  false, false, true, DS_WAR),
322  false,
323  N_("All action enablers for %s must require"
324  " a target the actor is at war with."),
325  ACTRES_BOMBARD, ACTRES_ATTACK, ACTRES_NONE);
326 
327  /* Why this is a hard requirement: Keep the old rules. Need to work
328  * out corner cases. */
329  oblig_hard_req_register(req_from_values(VUT_DIPLREL, REQ_RANGE_LOCAL,
330  false, true, true, DRO_FOREIGN),
331  false,
332  N_("All action enablers for %s must require"
333  " a domestic target."),
334  ACTRES_UPGRADE_UNIT, ACTRES_NONE);
335 
336  /* Why this is a hard requirement: The code expects that only domestic and
337  * allied transports can be boarded. */
338  oblig_hard_req_register(req_from_values(VUT_DIPLREL, REQ_RANGE_LOCAL,
339  false, true, true, DS_ARMISTICE),
340  false,
341  N_("All action enablers for %s must require"
342  " a domestic or allied target."),
343  ACTRES_TRANSPORT_EMBARK, ACTRES_TRANSPORT_BOARD,
344  ACTRES_NONE);
345  oblig_hard_req_register(req_from_values(VUT_DIPLREL, REQ_RANGE_LOCAL,
346  false, true, true, DS_WAR),
347  false,
348  N_("All action enablers for %s must require"
349  " a domestic or allied target."),
350  ACTRES_TRANSPORT_EMBARK, ACTRES_TRANSPORT_BOARD,
351  ACTRES_NONE);
352  oblig_hard_req_register(req_from_values(VUT_DIPLREL, REQ_RANGE_LOCAL,
353  false, true, true, DS_CEASEFIRE),
354  false,
355  N_("All action enablers for %s must require"
356  " a domestic or allied target."),
357  ACTRES_TRANSPORT_EMBARK, ACTRES_TRANSPORT_BOARD,
358  ACTRES_NONE);
359  oblig_hard_req_register(req_from_values(VUT_DIPLREL, REQ_RANGE_LOCAL,
360  false, true, true, DS_PEACE),
361  false,
362  N_("All action enablers for %s must require"
363  " a domestic or allied target."),
364  ACTRES_TRANSPORT_EMBARK, ACTRES_TRANSPORT_BOARD,
365  ACTRES_NONE);
366  oblig_hard_req_register(req_from_values(VUT_DIPLREL, REQ_RANGE_LOCAL,
367  false, true, true, DS_NO_CONTACT),
368  false,
369  N_("All action enablers for %s must require"
370  " a domestic or allied target."),
371  ACTRES_TRANSPORT_EMBARK, ACTRES_TRANSPORT_BOARD,
372  ACTRES_NONE);
373 
374  /* Why this is a hard requirement: Preserve semantics of the Settlers
375  * unit type flag. */
377  req_from_values(VUT_UTFLAG, REQ_RANGE_LOCAL, false, false, true,
378  UTYF_SETTLERS),
379  false,
380  N_("All action enablers for %s must require"
381  " that the actor has"
382  " the Settlers utype flag."),
383  ACTRES_TRANSFORM_TERRAIN, ACTRES_CULTIVATE, ACTRES_PLANT, ACTRES_ROAD,
384  ACTRES_BASE, ACTRES_MINE, ACTRES_IRRIGATE, ACTRES_CLEAN_POLLUTION,
385  ACTRES_CLEAN_FALLOUT, ACTRES_NONE);
386 
387  /* Why this is a hard requirement: Preserve semantics of the NoCities
388  * terrain flag. */
389  oblig_hard_req_register(req_from_values(VUT_TERRFLAG, REQ_RANGE_LOCAL,
390  false, true, true, TER_NO_CITIES),
391  true,
392  N_("All action enablers for %s must require that"
393  " the target doesn't has"
394  " the NoCities terrain flag."),
395  ACTRES_FOUND_CITY, ACTRES_NONE);
396 
397  /* It isn't possible to establish a trade route from a non existing
398  * city. The Freeciv code assumes this applies to Enter Marketplace
399  * too. */
401  req_from_values(VUT_UNITSTATE, REQ_RANGE_LOCAL, false, false, true,
402  USP_HAS_HOME_CITY),
403  false,
404  N_("All action enablers for %s must require"
405  " that the actor has a home city."),
406  ACTRES_TRADE_ROUTE, ACTRES_MARKETPLACE, ACTRES_NONE);
407 
408  /* Why this is a hard requirement: Preserve semantics of NoHome
409  * flag. Need to replace other uses in game engine before this can
410  * be demoted to a regular unit flag. */
411  oblig_hard_req_register(req_from_values(VUT_UTFLAG, REQ_RANGE_LOCAL, false,
412  true, true, UTYF_NOHOME),
413  false,
414  N_("All action enablers for %s must require"
415  " that the actor doesn't have"
416  " the NoHome utype flag."),
417  ACTRES_HOME_CITY, ACTRES_NONE);
418 
419  /* Why this is a hard requirement:
420  * - preserve the semantics of the NonMil unit type flag. */
422  3,
423  req_from_values(VUT_UTFLAG, REQ_RANGE_LOCAL, false,
424  false, true, UTYF_CIVILIAN),
425  false,
426  req_from_values(VUT_DIPLREL, REQ_RANGE_LOCAL, false,
427  true, true, DS_PEACE),
428  false,
429  req_from_values(VUT_CITYTILE, REQ_RANGE_LOCAL,
430  false, true, true, CITYT_CLAIMED),
431  true),
432  // TRANS: error message for ruledit
433  N_("All action enablers for %s must require"
434  " that the actor has the NonMil utype flag"
435  " or that the target tile is unclaimed"
436  " or that the diplomatic relation to"
437  " the target tile owner isn't peace."),
438  ACTRES_PARADROP, ACTRES_NONE);
439 
440  /* Why this is a hard requirement: Preserve semantics of NonMil
441  * flag. Need to replace other uses in game engine before this can
442  * be demoted to a regular unit flag. */
443  oblig_hard_req_register(req_from_values(VUT_UTFLAG, REQ_RANGE_LOCAL, false,
444  true, true, UTYF_CIVILIAN),
445  false,
446  N_("All action enablers for %s must require"
447  " that the actor doesn't have"
448  " the NonMil utype flag."),
449  ACTRES_ATTACK, ACTRES_CONQUER_CITY, ACTRES_NONE);
450 
451  /* Why this is a hard requirement: Preserve semantics of
452  * CanOccupyCity unit class flag. */
453  oblig_hard_req_register(req_from_values(VUT_UCFLAG, REQ_RANGE_LOCAL, false,
454  false, true, UCF_CAN_OCCUPY_CITY),
455  false,
456  N_("All action enablers for %s must require"
457  " that the actor has"
458  " the CanOccupyCity uclass flag."),
459  ACTRES_CONQUER_CITY, ACTRES_NONE);
460 
461  /* Why this is a hard requirement: Consistency with ACTRES_ATTACK.
462  * Assumed by other locations in the Freeciv code. Examples:
463  * unit_move_to_tile_test() and unit_conquer_city(). */
464  oblig_hard_req_register(req_from_values(VUT_DIPLREL, REQ_RANGE_LOCAL,
465  false, false, true, DS_WAR),
466  false,
467  N_("All action enablers for %s must require"
468  " that the actor is at war with the target."),
469  ACTRES_CONQUER_CITY, ACTRES_NONE);
470 
471  /* Why this is a hard requirement: a unit must move into a city to
472  * conquer it, move into a transport to embark and move out of a transport
473  * to disembark from it. */
475  req_from_values(VUT_MINMOVES, REQ_RANGE_LOCAL, false, false, true, 1),
476  false,
477  N_("All action enablers for %s must require"
478  " that the actor has a movement point left."),
479  ACTRES_CONQUER_CITY, ACTRES_TRANSPORT_DISEMBARK,
480  ACTRES_TRANSPORT_EMBARK, ACTRES_NONE);
481 
482  /* Why this is a hard requirement: this eliminates the need to
483  * check if units transported by the actor unit can exist at the
484  * same tile as all the units in the occupied city.
485  *
486  * This makes an implicit rule explicit:
487  * 1. A unit must move into a city to conquer it.
488  * 2. It can't move into the city if the tile contains a non allied
489  * unit (see unit_move_to_tile_test()).
490  * 3. A city could, at the time this rule was made explicit, only
491  * contain units allied to its owner.
492  * 3. A player could, at the time this rule was made explicit, not
493  * be allied to a player that is at war with another ally.
494  * 4. A player could, at the time this rule was made explicit, only
495  * conquer a city belonging to someone he was at war with.
496  * Conclusion: the conquered city had to be empty.
497  */
498  oblig_hard_req_register(req_from_values(VUT_MAXTILEUNITS, REQ_RANGE_LOCAL,
499  false, false, true, 0),
500  true,
501  N_("All action enablers for %s must require"
502  " that the target city is empty."),
503  ACTRES_CONQUER_CITY, ACTRES_NONE);
504 
505  /* Why this is a hard requirement: Assumed in the code. Corner case
506  * where diplomacy prevents a transported unit to go to the target
507  * tile. The paradrop code doesn't check if transported units can
508  * coexist with the target tile city and units. */
509  oblig_hard_req_register(req_from_values(VUT_UNITSTATE, REQ_RANGE_LOCAL,
510  false, true, true,
511  USP_TRANSPORTING),
512  false,
513  N_("All action enablers for %s must require"
514  " that the actor isn't transporting"
515  " another unit."),
516  ACTRES_PARADROP, ACTRES_AIRLIFT, ACTRES_NONE);
517 
518  // Why this is a hard requirement: Assumed in the code.
519  oblig_hard_req_register(req_from_values(VUT_UNITSTATE, REQ_RANGE_LOCAL,
520  false, true, true,
521  USP_TRANSPORTING),
522  true,
523  N_("All action enablers for %s must require"
524  " that the target isn't transporting another"
525  " unit."),
526  ACTRES_CAPTURE_UNITS, ACTRES_NONE);
527 
528  // Why this is a hard requirement: sanity.
529  oblig_hard_req_register(req_from_values(VUT_UNITSTATE, REQ_RANGE_LOCAL,
530  false, false, true,
531  USP_TRANSPORTING),
532  true,
533  N_("All action enablers for %s must require"
534  " that the target is transporting a unit."),
535  ACTRES_TRANSPORT_ALIGHT, ACTRES_NONE);
537  req_from_values(VUT_UNITSTATE, REQ_RANGE_LOCAL, false, false, true,
538  USP_TRANSPORTED),
539  false,
540  N_("All action enablers for %s must require"
541  " that the actor is transported."),
542  ACTRES_TRANSPORT_ALIGHT, ACTRES_TRANSPORT_DISEMBARK, ACTRES_NONE);
543  oblig_hard_req_register(req_from_values(VUT_UNITSTATE, REQ_RANGE_LOCAL,
544  false, false, true,
545  USP_LIVABLE_TILE),
546  false,
547  N_("All action enablers for %s must require"
548  " that the actor is on a livable tile."),
549  ACTRES_TRANSPORT_ALIGHT, ACTRES_NONE);
550 
551  // Why this is a hard requirement: sanity.
552  oblig_hard_req_register(req_from_values(VUT_UNITSTATE, REQ_RANGE_LOCAL,
553  false, false, true,
554  USP_TRANSPORTING),
555  false,
556  N_("All action enablers for %s must require"
557  " that the actor is transporting a unit."),
558  ACTRES_TRANSPORT_UNLOAD, ACTRES_NONE);
559  oblig_hard_req_register(req_from_values(VUT_UNITSTATE, REQ_RANGE_LOCAL,
560  false, false, true,
561  USP_TRANSPORTED),
562  true,
563  N_("All action enablers for %s must require"
564  " that the target is transported."),
565  ACTRES_TRANSPORT_UNLOAD, ACTRES_NONE);
566  oblig_hard_req_register(req_from_values(VUT_UNITSTATE, REQ_RANGE_LOCAL,
567  false, false, true,
568  USP_LIVABLE_TILE),
569  true,
570  N_("All action enablers for %s must require"
571  " that the target is on a livable tile."),
572  ACTRES_TRANSPORT_UNLOAD, ACTRES_NONE);
573 
574  // Why this is a hard requirement: assumed by the Freeciv code.
575  oblig_hard_req_register(req_from_values(VUT_CITYTILE, REQ_RANGE_LOCAL,
576  false, false, true, CITYT_CENTER),
577  false,
578  N_("All action enablers for %s must require"
579  " that the actor unit is in a city."),
580  ACTRES_AIRLIFT, ACTRES_NONE);
581 }
582 
588 {
589  /* Why this is a hard requirement: the "animal can't conquer a city"
590  * rule. Assumed in unit_can_take_over(). */
591  for (const auto &pnation : nations) {
592  if (nation_barbarian_type(&pnation) == ANIMAL_BARBARIAN) {
593  oblig_hard_req_register(req_from_values(VUT_NATION, REQ_RANGE_PLAYER,
594  false, true, true,
595  nation_index(&pnation)),
596  true,
597  N_("All action enablers for %s must require"
598  " a non animal player actor."),
599  ACTRES_CONQUER_CITY, ACTRES_NONE);
600  }
601  } // iterate over nations - pnation
602 }
603 
607 static void hard_code_actions()
608 {
609  actions[ACTION_SPY_POISON] = unit_action_new(
610  ACTION_SPY_POISON, ACTRES_SPY_POISON, ATK_CITY, ASTK_NONE,
611  ACT_TGT_COMPL_SIMPLE, false, true, MAK_ESCAPE, 0, 1, true);
612  actions[ACTION_SPY_POISON_ESC] = unit_action_new(
613  ACTION_SPY_POISON_ESC, ACTRES_SPY_POISON, ATK_CITY, ASTK_NONE,
614  ACT_TGT_COMPL_SIMPLE, false, true, MAK_ESCAPE, 0, 1, false);
615  actions[ACTION_SPY_SABOTAGE_UNIT] = unit_action_new(
616  ACTION_SPY_SABOTAGE_UNIT, ACTRES_SPY_SABOTAGE_UNIT, ATK_UNIT,
617  ASTK_NONE, ACT_TGT_COMPL_SIMPLE, false, true, MAK_ESCAPE, 0, 1, true);
618  actions[ACTION_SPY_SABOTAGE_UNIT_ESC] = unit_action_new(
619  ACTION_SPY_SABOTAGE_UNIT_ESC, ACTRES_SPY_SABOTAGE_UNIT, ATK_UNIT,
620  ASTK_NONE, ACT_TGT_COMPL_SIMPLE, false, true, MAK_ESCAPE, 0, 1, false);
621  actions[ACTION_SPY_BRIBE_UNIT] =
622  unit_action_new(ACTION_SPY_BRIBE_UNIT, ACTRES_SPY_BRIBE_UNIT, ATK_UNIT,
623  ASTK_NONE, ACT_TGT_COMPL_SIMPLE, false, true,
624  /* Tries a forced move if the target unit is alone at
625  * its tile and not in a city. Takes all movement if
626  * the forced move fails. */
627  MAK_FORCED, 0, 1, false);
628  actions[ACTION_SPY_SABOTAGE_CITY] = unit_action_new(
629  ACTION_SPY_SABOTAGE_CITY, ACTRES_SPY_SABOTAGE_CITY, ATK_CITY,
630  ASTK_NONE, ACT_TGT_COMPL_SIMPLE, false, true, MAK_ESCAPE, 0, 1, true);
631  actions[ACTION_SPY_SABOTAGE_CITY_ESC] = unit_action_new(
632  ACTION_SPY_SABOTAGE_CITY_ESC, ACTRES_SPY_SABOTAGE_CITY, ATK_CITY,
633  ASTK_NONE, ACT_TGT_COMPL_SIMPLE, false, true, MAK_ESCAPE, 0, 1, false);
634  actions[ACTION_SPY_TARGETED_SABOTAGE_CITY] = unit_action_new(
635  ACTION_SPY_TARGETED_SABOTAGE_CITY, ACTRES_SPY_TARGETED_SABOTAGE_CITY,
636  ATK_CITY, ASTK_BUILDING, ACT_TGT_COMPL_MANDATORY, false, true,
637  MAK_ESCAPE, 0, 1, true);
638  actions[ACTION_SPY_SABOTAGE_CITY_PRODUCTION] = unit_action_new(
639  ACTION_SPY_SABOTAGE_CITY_PRODUCTION,
640  ACTRES_SPY_SABOTAGE_CITY_PRODUCTION, ATK_CITY, ASTK_NONE,
641  ACT_TGT_COMPL_SIMPLE, false, true, MAK_ESCAPE, 0, 1, true);
642  actions[ACTION_SPY_TARGETED_SABOTAGE_CITY_ESC] = unit_action_new(
643  ACTION_SPY_TARGETED_SABOTAGE_CITY_ESC,
644  ACTRES_SPY_TARGETED_SABOTAGE_CITY, ATK_CITY, ASTK_BUILDING,
645  ACT_TGT_COMPL_MANDATORY, false, true, MAK_ESCAPE, 0, 1, false);
646  actions[ACTION_SPY_SABOTAGE_CITY_PRODUCTION_ESC] = unit_action_new(
647  ACTION_SPY_SABOTAGE_CITY_PRODUCTION_ESC,
648  ACTRES_SPY_SABOTAGE_CITY_PRODUCTION, ATK_CITY, ASTK_NONE,
649  ACT_TGT_COMPL_SIMPLE, false, true, MAK_ESCAPE, 0, 1, false);
650  actions[ACTION_SPY_INCITE_CITY] = unit_action_new(
651  ACTION_SPY_INCITE_CITY, ACTRES_SPY_INCITE_CITY, ATK_CITY, ASTK_NONE,
652  ACT_TGT_COMPL_SIMPLE, false, true, MAK_ESCAPE, 0, 1, true);
653  actions[ACTION_SPY_INCITE_CITY_ESC] = unit_action_new(
654  ACTION_SPY_INCITE_CITY_ESC, ACTRES_SPY_INCITE_CITY, ATK_CITY,
655  ASTK_NONE, ACT_TGT_COMPL_SIMPLE, false, true, MAK_ESCAPE, 0, 1, false);
656  actions[ACTION_ESTABLISH_EMBASSY] = unit_action_new(
657  ACTION_ESTABLISH_EMBASSY, ACTRES_ESTABLISH_EMBASSY, ATK_CITY,
658  ASTK_NONE, ACT_TGT_COMPL_SIMPLE, false, true, MAK_ESCAPE, 0, 1, false);
659  actions[ACTION_ESTABLISH_EMBASSY_STAY] = unit_action_new(
660  ACTION_ESTABLISH_EMBASSY_STAY, ACTRES_ESTABLISH_EMBASSY, ATK_CITY,
661  ASTK_NONE, ACT_TGT_COMPL_SIMPLE, false, true, MAK_ESCAPE, 0, 1, true);
662  actions[ACTION_SPY_STEAL_TECH] = unit_action_new(
663  ACTION_SPY_STEAL_TECH, ACTRES_SPY_STEAL_TECH, ATK_CITY, ASTK_NONE,
664  ACT_TGT_COMPL_SIMPLE, false, true, MAK_ESCAPE, 0, 1, true);
665  actions[ACTION_SPY_STEAL_TECH_ESC] = unit_action_new(
666  ACTION_SPY_STEAL_TECH_ESC, ACTRES_SPY_STEAL_TECH, ATK_CITY, ASTK_NONE,
667  ACT_TGT_COMPL_SIMPLE, false, true, MAK_ESCAPE, 0, 1, false);
668  actions[ACTION_SPY_TARGETED_STEAL_TECH] = unit_action_new(
669  ACTION_SPY_TARGETED_STEAL_TECH, ACTRES_SPY_TARGETED_STEAL_TECH,
670  ATK_CITY, ASTK_TECH, ACT_TGT_COMPL_MANDATORY, false, true, MAK_ESCAPE,
671  0, 1, true);
672  actions[ACTION_SPY_TARGETED_STEAL_TECH_ESC] = unit_action_new(
673  ACTION_SPY_TARGETED_STEAL_TECH_ESC, ACTRES_SPY_TARGETED_STEAL_TECH,
674  ATK_CITY, ASTK_TECH, ACT_TGT_COMPL_MANDATORY, false, true, MAK_ESCAPE,
675  0, 1, false);
676  actions[ACTION_SPY_INVESTIGATE_CITY] = unit_action_new(
677  ACTION_SPY_INVESTIGATE_CITY, ACTRES_SPY_INVESTIGATE_CITY, ATK_CITY,
678  ASTK_NONE, ACT_TGT_COMPL_SIMPLE, false, true, MAK_ESCAPE, 0, 1, false);
679  actions[ACTION_INV_CITY_SPEND] = unit_action_new(
680  ACTION_INV_CITY_SPEND, ACTRES_SPY_INVESTIGATE_CITY, ATK_CITY,
681  ASTK_NONE, ACT_TGT_COMPL_SIMPLE, false, true, MAK_ESCAPE, 0, 1, true);
682  actions[ACTION_SPY_STEAL_GOLD] = unit_action_new(
683  ACTION_SPY_STEAL_GOLD, ACTRES_SPY_STEAL_GOLD, ATK_CITY, ASTK_NONE,
684  ACT_TGT_COMPL_SIMPLE, false, true, MAK_ESCAPE, 0, 1, true);
685  actions[ACTION_SPY_STEAL_GOLD_ESC] = unit_action_new(
686  ACTION_SPY_STEAL_GOLD_ESC, ACTRES_SPY_STEAL_GOLD, ATK_CITY, ASTK_NONE,
687  ACT_TGT_COMPL_SIMPLE, false, true, MAK_ESCAPE, 0, 1, false);
688  actions[ACTION_SPY_SPREAD_PLAGUE] = unit_action_new(
689  ACTION_SPY_SPREAD_PLAGUE, ACTRES_SPY_SPREAD_PLAGUE, ATK_CITY,
690  ASTK_NONE, ACT_TGT_COMPL_SIMPLE, false, true, MAK_ESCAPE, 0, 1, false);
691  actions[ACTION_TRADE_ROUTE] = unit_action_new(
692  ACTION_TRADE_ROUTE, ACTRES_TRADE_ROUTE, ATK_CITY, ASTK_NONE,
693  ACT_TGT_COMPL_SIMPLE, false, true, MAK_STAYS, 0, 1, true);
694  actions[ACTION_MARKETPLACE] = unit_action_new(
695  ACTION_MARKETPLACE, ACTRES_MARKETPLACE, ATK_CITY, ASTK_NONE,
696  ACT_TGT_COMPL_SIMPLE, false, true, MAK_STAYS, 0, 1, true);
697  actions[ACTION_HELP_WONDER] = unit_action_new(
698  ACTION_HELP_WONDER, ACTRES_HELP_WONDER, ATK_CITY, ASTK_NONE,
699  ACT_TGT_COMPL_SIMPLE, false, true, MAK_STAYS, 0, 1, true);
700  actions[ACTION_CAPTURE_UNITS] = unit_action_new(
701  ACTION_CAPTURE_UNITS, ACTRES_CAPTURE_UNITS, ATK_UNITS, ASTK_NONE,
702  ACT_TGT_COMPL_SIMPLE, false, true, MAK_STAYS,
703  /* A single domestic unit at the target tile will make
704  * the action illegal. It must therefore be performed
705  * from another tile. */
706  1, 1, false);
707  actions[ACTION_FOUND_CITY] =
708  unit_action_new(ACTION_FOUND_CITY, ACTRES_FOUND_CITY, ATK_TILE,
709  ASTK_NONE, ACT_TGT_COMPL_SIMPLE, true, true, MAK_STAYS,
710  /* Illegal to perform to a target on another tile.
711  * Reason: The Freeciv code assumes that the city
712  * founding unit is located at the tile were the new
713  * city is founded. */
714  0, 0, true);
715  actions[ACTION_JOIN_CITY] = unit_action_new(
716  ACTION_JOIN_CITY, ACTRES_JOIN_CITY, ATK_CITY, ASTK_NONE,
717  ACT_TGT_COMPL_SIMPLE, true, true, MAK_STAYS, 0, 1, true);
718  actions[ACTION_STEAL_MAPS] = unit_action_new(
719  ACTION_STEAL_MAPS, ACTRES_STEAL_MAPS, ATK_CITY, ASTK_NONE,
720  ACT_TGT_COMPL_SIMPLE, false, true, MAK_ESCAPE, 0, 1, true);
721  actions[ACTION_STEAL_MAPS_ESC] = unit_action_new(
722  ACTION_STEAL_MAPS_ESC, ACTRES_STEAL_MAPS, ATK_CITY, ASTK_NONE,
723  ACT_TGT_COMPL_SIMPLE, false, true, MAK_ESCAPE, 0, 1, false);
724  actions[ACTION_BOMBARD] = unit_action_new(
725  ACTION_BOMBARD, ACTRES_BOMBARD,
726  // FIXME: Target is actually Units + City
727  ATK_UNITS, ASTK_NONE, ACT_TGT_COMPL_SIMPLE, false, true, MAK_STAYS,
728  /* A single domestic unit at the target tile will make
729  * the action illegal. It must therefore be performed
730  * from another tile. */
731  1,
732  // Overwritten by the ruleset's bombard_max_range
733  1, false);
734  actions[ACTION_BOMBARD2] = unit_action_new(
735  ACTION_BOMBARD2, ACTRES_BOMBARD,
736  // FIXME: Target is actually Units + City
737  ATK_UNITS, ASTK_NONE, ACT_TGT_COMPL_SIMPLE, false, true, MAK_STAYS,
738  /* A single domestic unit at the target tile will make
739  * the action illegal. It must therefore be performed
740  * from another tile. */
741  1,
742  // Overwritten by the ruleset's bombard_2_max_range
743  1, false);
744  actions[ACTION_BOMBARD3] = unit_action_new(
745  ACTION_BOMBARD3, ACTRES_BOMBARD,
746  // FIXME: Target is actually Units + City
747  ATK_UNITS, ASTK_NONE, ACT_TGT_COMPL_SIMPLE, false, true, MAK_STAYS,
748  /* A single domestic unit at the target tile will make
749  * the action illegal. It must therefore be performed
750  * from another tile. */
751  1,
752  // Overwritten by the ruleset's bombard_3_max_range
753  1, false);
754  actions[ACTION_SPY_NUKE] = unit_action_new(
755  ACTION_SPY_NUKE, ACTRES_SPY_NUKE, ATK_CITY, ASTK_NONE,
756  ACT_TGT_COMPL_SIMPLE, false, true, MAK_ESCAPE, 0, 1, true);
757  actions[ACTION_SPY_NUKE_ESC] = unit_action_new(
758  ACTION_SPY_NUKE_ESC, ACTRES_SPY_NUKE, ATK_CITY, ASTK_NONE,
759  ACT_TGT_COMPL_SIMPLE, false, true, MAK_ESCAPE, 0, 1, false);
760  actions[ACTION_NUKE] =
761  unit_action_new(ACTION_NUKE, ACTRES_NUKE, ATK_TILE, ASTK_NONE,
762  ACT_TGT_COMPL_SIMPLE, true, true, MAK_STAYS, 0,
763  /* Overwritten by the ruleset's
764  * explode_nuclear_max_range */
765  0, true);
766  actions[ACTION_NUKE_CITY] = unit_action_new(
767  ACTION_NUKE_CITY, ACTRES_NUKE_CITY, ATK_CITY, ASTK_NONE,
768  ACT_TGT_COMPL_SIMPLE, true, true, MAK_STAYS, 1, 1, true);
769  actions[ACTION_NUKE_UNITS] = unit_action_new(
770  ACTION_NUKE_UNITS, ACTRES_NUKE_UNITS, ATK_UNITS, ASTK_NONE,
771  ACT_TGT_COMPL_SIMPLE, true, true, MAK_STAYS, 1, 1, true);
772  actions[ACTION_DESTROY_CITY] = unit_action_new(
773  ACTION_DESTROY_CITY, ACTRES_DESTROY_CITY, ATK_CITY, ASTK_NONE,
774  ACT_TGT_COMPL_SIMPLE, true, true, MAK_STAYS, 0, 1, false);
775  actions[ACTION_EXPEL_UNIT] = unit_action_new(
776  ACTION_EXPEL_UNIT, ACTRES_EXPEL_UNIT, ATK_UNIT, ASTK_NONE,
777  ACT_TGT_COMPL_SIMPLE, false, true, MAK_STAYS, 0, 1, false);
778  actions[ACTION_RECYCLE_UNIT] =
779  unit_action_new(ACTION_RECYCLE_UNIT, ACTRES_RECYCLE_UNIT, ATK_CITY,
780  ASTK_NONE, ACT_TGT_COMPL_SIMPLE, true, true, MAK_STAYS,
781  /* Illegal to perform to a target on another tile to
782  * keep the rules exactly as they were for now. */
783  0, 1, true);
784  actions[ACTION_DISBAND_UNIT] = unit_action_new(
785  ACTION_DISBAND_UNIT,
786  /* Can't be ACTRES_NONE because
787  * action_success_actor_consume() sets unit lost
788  * reason based on action result. */
789  ACTRES_DISBAND_UNIT, ATK_SELF, ASTK_NONE, ACT_TGT_COMPL_SIMPLE, true,
790  true, MAK_STAYS, 0, 0, true);
791  actions[ACTION_HOME_CITY] =
792  unit_action_new(ACTION_HOME_CITY, ACTRES_HOME_CITY, ATK_CITY,
793  ASTK_NONE, ACT_TGT_COMPL_SIMPLE, true, false,
794  /* Illegal to perform to a target on another tile to
795  * keep the rules exactly as they were for now. */
796  MAK_STAYS, 0, 0, false);
797  actions[ACTION_UPGRADE_UNIT] =
798  unit_action_new(ACTION_UPGRADE_UNIT, ACTRES_UPGRADE_UNIT, ATK_CITY,
799  ASTK_NONE, ACT_TGT_COMPL_SIMPLE, true, true, MAK_STAYS,
800  /* Illegal to perform to a target on another tile to
801  * keep the rules exactly as they were for now. */
802  0, 0, false);
803  actions[ACTION_PARADROP] =
804  unit_action_new(ACTION_PARADROP, ACTRES_PARADROP, ATK_TILE, ASTK_NONE,
805  ACT_TGT_COMPL_SIMPLE, true, true, MAK_TELEPORT, 1,
806  /* Still limited by each unit type's
807  * paratroopers_range field. */
808  ACTION_DISTANCE_MAX, false);
809  actions[ACTION_AIRLIFT] =
810  unit_action_new(ACTION_AIRLIFT, ACTRES_AIRLIFT, ATK_CITY, ASTK_NONE,
811  ACT_TGT_COMPL_SIMPLE, true, true, MAK_TELEPORT, 1,
812  // Overwritten by the ruleset's airlift_max_range.
814  actions[ACTION_ATTACK] = unit_action_new(
815  ACTION_ATTACK, ACTRES_ATTACK,
816  /* FIXME: Target is actually City, each unit at the
817  * target tile (Units) and, depending on the
818  * unreachable_protects setting, each or any
819  * *non transported* unit at the target tile. */
820  ATK_UNITS, ASTK_NONE, ACT_TGT_COMPL_SIMPLE, false, true,
821  /* Tries a forced move if the target unit's tile has
822  * no non allied units and the occupychance dice roll
823  * tells it to move. */
824  MAK_FORCED, 1, 1, false);
825  actions[ACTION_SUICIDE_ATTACK] =
826  unit_action_new(ACTION_SUICIDE_ATTACK, ACTRES_ATTACK,
827  /* FIXME: Target is actually City, each unit at the
828  * target tile (Units) and, depending on the
829  * unreachable_protects setting, each or any
830  * *non transported* unit at the target tile. */
831  ATK_UNITS, ASTK_NONE, ACT_TGT_COMPL_SIMPLE, false,
832  true, MAK_FORCED, 1, 1, true);
833  actions[ACTION_STRIKE_BUILDING] =
834  unit_action_new(ACTION_STRIKE_BUILDING, ACTRES_STRIKE_BUILDING,
835  ATK_CITY, ASTK_BUILDING, ACT_TGT_COMPL_MANDATORY,
836  false, false, MAK_STAYS, 1, 1, false);
837  actions[ACTION_STRIKE_PRODUCTION] = unit_action_new(
838  ACTION_STRIKE_PRODUCTION, ACTRES_STRIKE_PRODUCTION, ATK_CITY,
839  ASTK_NONE, ACT_TGT_COMPL_SIMPLE, false, false, MAK_STAYS, 1, 1, false);
840  actions[ACTION_CONQUER_CITY] = unit_action_new(
841  ACTION_CONQUER_CITY, ACTRES_CONQUER_CITY, ATK_CITY, ASTK_NONE,
842  ACT_TGT_COMPL_SIMPLE, false, true, MAK_REGULAR, 1, 1, false);
843  actions[ACTION_CONQUER_CITY2] = unit_action_new(
844  ACTION_CONQUER_CITY2, ACTRES_CONQUER_CITY, ATK_CITY, ASTK_NONE,
845  ACT_TGT_COMPL_SIMPLE, false, true, MAK_REGULAR, 1, 1, false);
846  actions[ACTION_HEAL_UNIT] = unit_action_new(
847  ACTION_HEAL_UNIT, ACTRES_HEAL_UNIT, ATK_UNIT, ASTK_NONE,
848  ACT_TGT_COMPL_SIMPLE, false, true, MAK_STAYS, 0, 1, false);
849  actions[ACTION_TRANSFORM_TERRAIN] = unit_action_new(
850  ACTION_TRANSFORM_TERRAIN, ACTRES_TRANSFORM_TERRAIN, ATK_TILE,
851  ASTK_NONE, ACT_TGT_COMPL_SIMPLE, true, false, MAK_STAYS, 0, 0, false);
852  actions[ACTION_CULTIVATE] = unit_action_new(
853  ACTION_CULTIVATE, ACTRES_CULTIVATE, ATK_TILE, ASTK_NONE,
854  ACT_TGT_COMPL_SIMPLE, true, false, MAK_STAYS, 0, 0, false);
855  actions[ACTION_PLANT] = unit_action_new(
856  ACTION_PLANT, ACTRES_PLANT, ATK_TILE, ASTK_NONE, ACT_TGT_COMPL_SIMPLE,
857  true, false, MAK_STAYS, 0, 0, false);
858  actions[ACTION_PILLAGE] = unit_action_new(
859  ACTION_PILLAGE, ACTRES_PILLAGE, ATK_TILE, ASTK_EXTRA,
860  ACT_TGT_COMPL_FLEXIBLE, true, false, MAK_STAYS, 0, 0, false);
861  actions[ACTION_CLEAN_POLLUTION] = unit_action_new(
862  ACTION_CLEAN_POLLUTION, ACTRES_CLEAN_POLLUTION, ATK_TILE, ASTK_EXTRA,
863  ACT_TGT_COMPL_FLEXIBLE, true, false, MAK_STAYS, 0, 0, false);
864  actions[ACTION_CLEAN_FALLOUT] = unit_action_new(
865  ACTION_CLEAN_FALLOUT, ACTRES_CLEAN_FALLOUT, ATK_TILE, ASTK_EXTRA,
866  ACT_TGT_COMPL_FLEXIBLE, true, false, MAK_STAYS, 0, 0, false);
867  actions[ACTION_FORTIFY] = unit_action_new(
868  ACTION_FORTIFY, ACTRES_FORTIFY, ATK_SELF, ASTK_NONE,
869  ACT_TGT_COMPL_SIMPLE, true, false, MAK_STAYS, 0, 0, false);
870  actions[ACTION_ROAD] = unit_action_new(
871  ACTION_ROAD, ACTRES_ROAD, ATK_TILE, ASTK_EXTRA_NOT_THERE,
872  ACT_TGT_COMPL_MANDATORY, true, false, MAK_STAYS, 0, 0, false);
873  actions[ACTION_CONVERT] = unit_action_new(
874  ACTION_CONVERT, ACTRES_CONVERT, ATK_SELF, ASTK_NONE,
875  ACT_TGT_COMPL_SIMPLE, true, false, MAK_STAYS, 0, 0, false);
876  actions[ACTION_BASE] = unit_action_new(
877  ACTION_BASE, ACTRES_BASE, ATK_TILE, ASTK_EXTRA_NOT_THERE,
878  ACT_TGT_COMPL_MANDATORY, true, false, MAK_STAYS, 0, 0, false);
879  actions[ACTION_MINE] = unit_action_new(
880  ACTION_MINE, ACTRES_MINE, ATK_TILE, ASTK_EXTRA_NOT_THERE,
881  ACT_TGT_COMPL_MANDATORY, true, false, MAK_STAYS, 0, 0, false);
882  actions[ACTION_IRRIGATE] = unit_action_new(
883  ACTION_IRRIGATE, ACTRES_IRRIGATE, ATK_TILE, ASTK_EXTRA_NOT_THERE,
884  ACT_TGT_COMPL_MANDATORY, true, false, MAK_STAYS, 0, 0, false);
885  actions[ACTION_TRANSPORT_ALIGHT] = unit_action_new(
886  ACTION_TRANSPORT_ALIGHT, ACTRES_TRANSPORT_ALIGHT, ATK_UNIT, ASTK_NONE,
887  ACT_TGT_COMPL_SIMPLE, true, false, MAK_STAYS, 0, 0, false);
888  actions[ACTION_TRANSPORT_BOARD] = unit_action_new(
889  ACTION_TRANSPORT_BOARD, ACTRES_TRANSPORT_BOARD, ATK_UNIT, ASTK_NONE,
890  ACT_TGT_COMPL_SIMPLE, true, false, MAK_STAYS, 0, 0, false);
891  actions[ACTION_TRANSPORT_UNLOAD] = unit_action_new(
892  ACTION_TRANSPORT_UNLOAD, ACTRES_TRANSPORT_UNLOAD, ATK_UNIT, ASTK_NONE,
893  ACT_TGT_COMPL_SIMPLE, true, false, MAK_STAYS, 0, 0, false);
894  actions[ACTION_TRANSPORT_DISEMBARK1] = unit_action_new(
895  ACTION_TRANSPORT_DISEMBARK1, ACTRES_TRANSPORT_DISEMBARK, ATK_TILE,
896  ASTK_NONE, ACT_TGT_COMPL_SIMPLE, false, true, MAK_REGULAR, 1, 1,
897  false);
898  actions[ACTION_TRANSPORT_DISEMBARK2] = unit_action_new(
899  ACTION_TRANSPORT_DISEMBARK2, ACTRES_TRANSPORT_DISEMBARK, ATK_TILE,
900  ASTK_NONE, ACT_TGT_COMPL_SIMPLE, false, true, MAK_REGULAR, 1, 1,
901  false);
902  actions[ACTION_TRANSPORT_EMBARK] = unit_action_new(
903  ACTION_TRANSPORT_EMBARK, ACTRES_TRANSPORT_EMBARK, ATK_UNIT, ASTK_NONE,
904  ACT_TGT_COMPL_SIMPLE, false, true, MAK_REGULAR, 1, 1, false);
905  actions[ACTION_SPY_ATTACK] = unit_action_new(
906  ACTION_SPY_ATTACK, ACTRES_SPY_ATTACK, ATK_UNITS, ASTK_NONE,
907  ACT_TGT_COMPL_SIMPLE, false, true, MAK_STAYS, 1, 1, false);
908  actions[ACTION_USER_ACTION1] =
909  unit_action_new(ACTION_USER_ACTION1, ACTRES_NONE,
910  // Overwritten by the ruleset
911  ATK_CITY, ASTK_NONE, ACT_TGT_COMPL_SIMPLE, false, true,
912  MAK_UNREPRESENTABLE,
913  // Overwritten by the ruleset
914  0, 1, false);
915  actions[ACTION_USER_ACTION2] =
916  unit_action_new(ACTION_USER_ACTION2, ACTRES_NONE,
917  // Overwritten by the ruleset
918  ATK_CITY, ASTK_NONE, ACT_TGT_COMPL_SIMPLE, false, true,
919  MAK_UNREPRESENTABLE,
920  // Overwritten by the ruleset
921  0, 1, false);
922  actions[ACTION_USER_ACTION3] =
923  unit_action_new(ACTION_USER_ACTION3, ACTRES_NONE,
924  // Overwritten by the ruleset
925  ATK_CITY, ASTK_NONE, ACT_TGT_COMPL_SIMPLE, false, true,
926  MAK_UNREPRESENTABLE,
927  // Overwritten by the ruleset
928  0, 1, false);
929 }
930 
935 {
936  int i, j;
937 
938  // Hard code the actions
940 
941  // Initialize the action enabler list
942  action_iterate(act)
943  {
944  action_enablers_by_action[act] = action_enabler_list_new();
945  }
947 
948  // Initialize action obligatory hard requirements.
949 
950  /* Obligatory hard requirements are sorted by action result in memory.
951  * This makes it easy to access the data. */
952  for (i = 0; i < ACTRES_NONE; i++) {
953  // Prepare each action result's storage area.
954  obligatory_req_vector_init(&obligatory_hard_reqs[i]);
955  }
956 
957  /* Obligatory hard requirements are sorted by requirement in the source
958  * code. This makes it easy to read, modify and explain it. */
960 
961  // Initialize the action auto performers.
962  for (i = 0; i < MAX_NUM_ACTION_AUTO_PERFORMERS; i++) {
963  // Nothing here. Nothing after this point.
964  auto_perfs[i].cause = AAPC_COUNT;
965 
966  // The criteria to pick *this* auto performer for its cause.
967  requirement_vector_init(&auto_perfs[i].reqs);
968 
969  for (j = 0; j < MAX_NUM_ACTIONS; j++) {
970  // Nothing here. Nothing after this point.
972  }
973  }
974 
975  // The actions them self are now initialized.
976  actions_initialized = true;
977 }
978 
985 {
986  /* Some obligatory hard requirements needs access to the rest of the
987  * ruleset. */
989 }
990 
995 {
996  int i;
997 
998  // Don't consider the actions to be initialized any longer.
999  actions_initialized = false;
1000 
1001  action_iterate(act)
1002  {
1004  {
1005  action_enabler_free(enabler);
1006  }
1008 
1009  action_enabler_list_destroy(action_enablers_by_action[act]);
1010 
1011  delete actions[act];
1012  actions[act] = nullptr;
1013  }
1015 
1016  // Free the obligatory hard action requirements.
1017  for (i = 0; i < ACTRES_NONE; i++) {
1019  {
1020  ae_contra_close(oreq->contras);
1021  }
1023  obligatory_req_vector_free(&obligatory_hard_reqs[i]);
1024  }
1025 
1026  // Free the action auto performers.
1027  for (i = 0; i < MAX_NUM_ACTION_AUTO_PERFORMERS; i++) {
1028  requirement_vector_free(&auto_perfs[i].reqs);
1029  }
1030 }
1031 
1038 {
1039  if (!actions_initialized) {
1040  // The actions them self aren't initialized yet.
1041  return false;
1042  }
1043 
1044  action_iterate(act)
1045  {
1046  if (actions[act]->ui_name[0] == '\0') {
1047  /* An action without a UI name exists means that the ruleset haven't
1048  * loaded yet. The ruleset loading will assign a default name to
1049  * any actions not named by the ruleset. The client will get this
1050  * name from the server. */
1051  return false;
1052  }
1053  }
1055 
1056  // The actions should be ready for use.
1057  return true;
1058 }
1059 
1063 static struct action *action_new(action_id id, enum action_result result,
1064  enum action_target_kind target_kind,
1065  enum action_sub_target_kind sub_target_kind,
1066  enum act_tgt_compl tgt_compl,
1067  const int min_distance,
1068  const int max_distance,
1070 {
1071  auto *action = new struct action;
1072 
1073  action->id = id;
1074 
1075  action->result = result;
1076 
1077  action->actor_kind = AAK_UNIT;
1080 
1081  /* ASTK_NONE implies ACT_TGT_COMPL_SIMPLE and
1082  * !ASTK_NONE implies !ACT_TGT_COMPL_SIMPLE */
1083  fc_assert_msg(
1084  ((sub_target_kind == ASTK_NONE && tgt_compl == ACT_TGT_COMPL_SIMPLE)
1085  || (sub_target_kind != ASTK_NONE
1086  && tgt_compl != ACT_TGT_COMPL_SIMPLE)),
1087  "%s contradicts itself regarding sub targets.",
1089 
1090  action->target_complexity = tgt_compl;
1091 
1092  // The distance between the actor and itself is always 0.
1093  fc_assert(target_kind != ATK_SELF
1094  || (min_distance == 0 && max_distance == 0));
1095 
1098 
1100 
1101  /* Loaded from the ruleset. Until generalized actions are ready it has to
1102  * be defined seperatly from other action data. */
1103  action->ui_name[0] = '\0';
1104  action->quiet = false;
1106 
1107  return action;
1108 }
1109 
1113 static struct action *
1114 unit_action_new(action_id id, enum action_result result,
1115  enum action_target_kind target_kind,
1116  enum action_sub_target_kind sub_target_kind,
1117  enum act_tgt_compl tgt_compl, bool rare_pop_up,
1119  enum moves_actor_kind moves_actor, const int min_distance,
1120  const int max_distance, bool actor_consuming_always)
1121 {
1122  struct action *act =
1123  action_new(id, result, target_kind, sub_target_kind, tgt_compl,
1125 
1126  act->actor.is_unit.rare_pop_up = rare_pop_up;
1127 
1128  act->actor.is_unit.unitwaittime_controlled = unitwaittime_controlled;
1129 
1130  act->actor.is_unit.moves_actor = moves_actor;
1131 
1132  return act;
1133 }
1134 
1138 bool action_id_exists(const action_id act_id)
1139 {
1140  // Actions are still hard coded.
1141  return gen_action_is_valid(gen_action(act_id)) && actions[act_id];
1142 }
1143 
1150 {
1151  if (!action_id_exists(act_id)) {
1152  // Nothing to return.
1153 
1154  qDebug("Asked for non existing action numbered %d", act_id);
1155 
1156  return nullptr;
1157  }
1158 
1159  fc_assert_msg(actions[act_id], "Action %d don't exist.", act_id);
1160 
1161  return actions[act_id];
1162 }
1163 
1169 struct action *action_by_rule_name(const char *name)
1170 {
1171  // Actions are still hard coded in the gen_action enum.
1172  action_id act_id = gen_action_by_name(name, fc_strcasecmp);
1173 
1174  if (!action_id_exists(act_id)) {
1175  // Nothing to return.
1176 
1177  qDebug("Asked for non existing action named %s", name);
1178 
1179  return nullptr;
1180  }
1181 
1182  return action_by_number(act_id);
1183 }
1184 
1188 enum action_actor_kind action_get_actor_kind(const struct action *paction)
1189 {
1190  fc_assert_ret_val_msg(paction, AAK_COUNT, "Action doesn't exist.");
1191 
1192  return paction->actor_kind;
1193 }
1194 
1198 enum action_target_kind action_get_target_kind(const struct action *paction)
1199 {
1200  fc_assert_ret_val_msg(paction, ATK_COUNT, "Action doesn't exist.");
1201 
1202  return paction->target_kind;
1203 }
1204 
1208 enum action_sub_target_kind
1209 action_get_sub_target_kind(const struct action *paction)
1210 {
1211  fc_assert_ret_val_msg(paction, ASTK_COUNT, "Action doesn't exist.");
1212 
1213  return paction->sub_target_kind;
1214 }
1215 
1219 enum action_battle_kind action_get_battle_kind(const struct action *pact)
1220 {
1221  switch (pact->result) {
1222  case ACTRES_ATTACK:
1223  return ABK_STANDARD;
1224  case ACTRES_SPY_ATTACK:
1225  case ACTRES_SPY_POISON:
1226  case ACTRES_SPY_STEAL_GOLD:
1227  case ACTRES_SPY_SABOTAGE_CITY:
1228  case ACTRES_SPY_TARGETED_SABOTAGE_CITY:
1229  case ACTRES_SPY_SABOTAGE_CITY_PRODUCTION:
1230  case ACTRES_SPY_STEAL_TECH:
1231  case ACTRES_SPY_TARGETED_STEAL_TECH:
1232  case ACTRES_SPY_INCITE_CITY:
1233  case ACTRES_SPY_BRIBE_UNIT:
1234  case ACTRES_SPY_SABOTAGE_UNIT:
1235  case ACTRES_STEAL_MAPS:
1236  case ACTRES_SPY_NUKE:
1237  case ACTRES_SPY_SPREAD_PLAGUE:
1238  return ABK_DIPLOMATIC;
1239  default:
1240  return ABK_NONE;
1241  }
1242 }
1243 
1248 bool action_has_result(const struct action *paction,
1249  enum action_result result)
1250 {
1251  fc_assert_ret_val(paction, false);
1252  fc_assert_ret_val(action_result_is_valid(result), false);
1253 
1254  return paction->result == result;
1255 }
1256 
1262 bool action_has_complex_target(const struct action *paction)
1263 {
1264  fc_assert_ret_val(paction != nullptr, false);
1265 
1266  return paction->target_complexity >= ACT_TGT_COMPL_FLEXIBLE;
1267 }
1268 
1275 bool action_requires_details(const struct action *paction)
1276 {
1277  fc_assert_ret_val(paction != nullptr, false);
1278 
1279  return paction->target_complexity >= ACT_TGT_COMPL_MANDATORY;
1280 }
1281 
1291 {
1292  fc_assert_ret_val_msg((action_id_exists(act_id)), false,
1293  "Action %d don't exist.", act_id);
1294  fc_assert_ret_val(action_id_get_actor_kind(act_id) == AAK_UNIT, false);
1295 
1296  return actions[act_id]->actor.is_unit.rare_pop_up;
1297 }
1298 
1304  const int distance)
1305 {
1306  return (distance <= action->max_distance
1308 }
1309 
1315  const int distance)
1316 {
1317  fc_assert_ret_val(action, false);
1318 
1319  return (distance >= action->min_distance
1320  && action_distance_inside_max(action, distance));
1321 }
1322 
1326 bool action_would_be_blocked_by(const struct action *blocked,
1327  const struct action *blocker)
1328 {
1329  fc_assert_ret_val(blocked, false);
1330  fc_assert_ret_val(blocker, false);
1331 
1332  return BV_ISSET(blocked->blocked_by, action_number(blocker));
1333 }
1334 
1338 int action_number(const struct action *action) { return action->id; }
1339 
1343 const char *action_rule_name(const struct action *action)
1344 {
1345  // Rule name is still hard coded.
1346  return action_id_rule_name(action->id);
1347 }
1348 
1353 const QString action_name_translation(const struct action *action)
1354 {
1355  // Use action_id_name_translation() to format the UI name.
1357 }
1358 
1362 const char *action_id_rule_name(action_id act_id)
1363 {
1364  fc_assert_msg(actions[act_id], "Action %d don't exist.", act_id);
1365 
1366  return gen_action_name(gen_action(act_id));
1367 }
1368 
1374 {
1375  return action_prepare_ui_name(gen_action(act_id), "", ACTPROB_NA, nullptr);
1376 }
1377 
1382 static QString action_prob_to_text(const struct act_prob prob)
1383 {
1384  /* How to interpret action probabilities like prob is documented in
1385  * fc_types.h */
1386  if (action_prob_is_signal(prob)) {
1388 
1389  // Unknown because of missing server support or should not exits.
1390  return nullptr;
1391  }
1392 
1393  if (prob.min == prob.max) {
1394  // Only one probability in range.
1395 
1396  return QString(_("%1%")).arg(
1397  QString::number(prob.max / ACTPROB_VAL_1_PCT));
1398  } else {
1399  return QString(_("[%1% - %2%]"))
1400  .arg(QString::number(prob.min / ACTPROB_VAL_1_PCT),
1401  QString::number(prob.max / ACTPROB_VAL_1_PCT));
1402  }
1403 }
1404 
1412 const QString action_prepare_ui_name(action_id act_id, const char *mnemonic,
1413  const struct act_prob prob,
1414  const QString &custom)
1415 {
1416  QString str, chance, probtxt;
1417 
1418  if (!actions_are_ready()) {
1419  // Could be a client who haven't gotten the ruleset yet
1420 
1421  // so there shouldn't be any action probability to show
1423 
1424  // but the action should be valid
1425  fc_assert_ret_val_msg(action_id_exists(act_id), "Invalid action",
1426  "Invalid action %d", act_id);
1427 
1428  // and no custom text will be inserted
1429  fc_assert(custom == nullptr || custom[0] == '\0');
1430 
1431  // Make the best of what is known
1432  str = QString(_("%1%2 (name may be wrong)"))
1433  .arg(mnemonic, action_id_rule_name(act_id));
1434 
1435  // Return the guess.
1436  return str;
1437  }
1438 
1439  probtxt = action_prob_to_text(prob);
1440 
1441  // Format the info part of the action's UI name.
1442  if (!probtxt.isEmpty() && !custom.isEmpty()) {
1443  /* TRANS: action UI name's info part with custom info and probability.
1444  * Hint: you can move the paren handling from this sting to the action
1445  * names if you need to add extra information (like a mnemonic letter
1446  * that doesn't appear in the action UI name) to it. In that case you
1447  * must do so for all strings with this comment and for every action
1448  * name. To avoid a `()` when no UI name info part is added you have
1449  * to add the extra information to every action name or remove the
1450  * surrounding parens. */
1451  chance = QString(_(" (%1; %2)")).arg(custom, probtxt);
1452  } else if (!probtxt.isEmpty()) {
1453  /* TRANS: action UI name's info part with probability.
1454  * Hint: you can move the paren handling from this sting to the action
1455  * names if you need to add extra information (like a mnemonic letter
1456  * that doesn't appear in the action UI name) to it. In that case you
1457  * must do so for all strings with this comment and for every action
1458  * name. To avoid a `()` when no UI name info part is added you have
1459  * to add the extra information to every action name or remove the
1460  * surrounding parens. */
1461  chance = QString(_(" (%1)")).arg(probtxt);
1462  } else if (!custom.isEmpty()) {
1463  /* TRANS: action UI name's info part with custom info.
1464  * Hint: you can move the paren handling from this sting to the action
1465  * names if you need to add extra information (like a mnemonic letter
1466  * that doesn't appear in the action UI name) to it. In that case you
1467  * must do so for all strings with this comment and for every action
1468  * name. To avoid a `()` when no UI name info part is added you have
1469  * to add the extra information to every action name or remove the
1470  * surrounding parens. */
1471  chance = QString(_(" (%1)")).arg(custom);
1472  } else {
1473  // No info part to display.
1474  }
1475 
1476  fc_assert_msg(actions[act_id], "Action %d don't exist.", act_id);
1477 
1478  /* Escape any instances of the mnemonic in the action's UI format string.
1479  * (Assumes any mnemonic can be escaped by doubling, and that they are
1480  * unlikely to appear in a format specifier. True for clients seen so
1481  * far: Gtk's _ and Qt's &) */
1482  {
1483  QString fmtstr;
1484  QString ui_name = _(actions[act_id]->ui_name);
1485  int k = ui_name.indexOf(QLatin1String("%s"));
1486  if (k >= 0) {
1487  ui_name = ui_name.remove(k, 2);
1488  }
1489  ui_name.replace(QLatin1String("%s"), QLatin1String("%1"));
1490  fmtstr += QStringLiteral("%1").arg(ui_name);
1491 
1492  // Use the modified format string
1493  str = QString(fmtstr).arg(chance);
1494  }
1495 
1496  return str;
1497 }
1498 
1504 const QString action_prob_explain(const struct act_prob prob)
1505 {
1506  QString tool_tip;
1507 
1508  if (action_prob_is_signal(prob)) {
1510  } else if (prob.min == prob.max) {
1511  /* TRANS: action probability of success. Given in percentage.
1512  * Resolution is 0.5%. */
1513  tool_tip = QString(_("The probability of success is %1%."))
1514  .arg(QString::number(static_cast<double>(prob.max)
1515  / ACTPROB_VAL_1_PCT));
1516  } else {
1517  tool_tip =
1518  QString(
1519  /* TRANS: action probability interval (min to max). Given in
1520  * percentage. Resolution is 0.5%. The string at the end is
1521  * shown when the interval is wide enough to not be caused by
1522  * rounding. It explains that the interval is imprecise because
1523  * the player doesn't have enough information. */
1524  _("The probability of success is %1%, %2% or somewhere"
1525  " in between.%3"))
1526  .arg(static_cast<double>(prob.min) / ACTPROB_VAL_1_PCT)
1527  .arg(static_cast<double>(prob.max) / ACTPROB_VAL_1_PCT)
1528  .arg(prob.max - prob.min > 1
1529  ?
1530  /* TRANS: explanation used in the action probability
1531  * tooltip above. Preserve leading space. */
1532  _(" (This is the most precise interval I can calculate "
1533  "given the information our nation has access to.)")
1534  : "");
1535  }
1536 
1537  return tool_tip;
1538 }
1539 
1544 int action_get_role(const struct action *paction)
1545 {
1546  fc_assert_msg(AAK_UNIT == action_get_actor_kind(paction),
1547  "Action %s isn't performed by a unit",
1548  action_rule_name(paction));
1549 
1550  return paction->id + L_LAST;
1551 }
1552 
1557 enum unit_activity action_get_activity(const struct action *paction)
1558 {
1559  fc_assert_msg(AAK_UNIT == action_get_actor_kind(paction),
1560  "Action %s isn't performed by a unit",
1561  action_rule_name(paction));
1562 
1563  if (action_has_result(paction, ACTRES_FORTIFY)) {
1564  return ACTIVITY_FORTIFYING;
1565  } else if (action_has_result(paction, ACTRES_BASE)) {
1566  return ACTIVITY_BASE;
1567  } else if (action_has_result(paction, ACTRES_ROAD)) {
1568  return ACTIVITY_GEN_ROAD;
1569  } else if (action_has_result(paction, ACTRES_PILLAGE)) {
1570  return ACTIVITY_PILLAGE;
1571  } else if (action_has_result(paction, ACTRES_CLEAN_POLLUTION)) {
1572  return ACTIVITY_POLLUTION;
1573  } else if (action_has_result(paction, ACTRES_CLEAN_FALLOUT)) {
1574  return ACTIVITY_FALLOUT;
1575  } else if (action_has_result(paction, ACTRES_TRANSFORM_TERRAIN)) {
1576  return ACTIVITY_TRANSFORM;
1577  } else if (action_has_result(paction, ACTRES_CONVERT)) {
1578  return ACTIVITY_CONVERT;
1579  } else if (action_has_result(paction, ACTRES_PLANT)) {
1580  return ACTIVITY_PLANT;
1581  } else if (action_has_result(paction, ACTRES_MINE)) {
1582  return ACTIVITY_MINE;
1583  } else if (action_has_result(paction, ACTRES_CULTIVATE)) {
1584  return ACTIVITY_CULTIVATE;
1585  } else if (action_has_result(paction, ACTRES_IRRIGATE)) {
1586  return ACTIVITY_IRRIGATE;
1587  } else {
1588  return ACTIVITY_LAST;
1589  }
1590 }
1591 
1598 int action_get_act_time(const struct action *paction,
1599  const struct unit *actor_unit,
1600  const struct tile *tgt_tile,
1601  const struct extra_type *tgt_extra)
1602 {
1603  enum unit_activity pactivity = action_get_activity(paction);
1604 
1605  if (pactivity == ACTIVITY_LAST) {
1606  // Happens instantaneous, not at turn change.
1607  return ACT_TIME_INSTANTANEOUS;
1608  }
1609 
1610  switch (pactivity) {
1611  case ACTIVITY_PILLAGE:
1612  case ACTIVITY_POLLUTION:
1613  case ACTIVITY_FALLOUT:
1614  case ACTIVITY_BASE:
1615  case ACTIVITY_GEN_ROAD:
1616  case ACTIVITY_IRRIGATE:
1617  case ACTIVITY_MINE:
1618  case ACTIVITY_CULTIVATE:
1619  case ACTIVITY_PLANT:
1620  case ACTIVITY_TRANSFORM:
1621  return tile_activity_time(pactivity, tgt_tile, tgt_extra);
1622  case ACTIVITY_FORTIFYING:
1623  return 1;
1624  case ACTIVITY_CONVERT:
1625  return unit_type_get(actor_unit)->convert_time * ACTIVITY_FACTOR;
1626  case ACTIVITY_EXPLORE:
1627  case ACTIVITY_IDLE:
1628  case ACTIVITY_FORTIFIED:
1629  case ACTIVITY_SENTRY:
1630  case ACTIVITY_GOTO:
1631  case ACTIVITY_UNKNOWN:
1632  case ACTIVITY_PATROL_UNUSED:
1633  case ACTIVITY_LAST:
1634  case ACTIVITY_OLD_ROAD:
1635  case ACTIVITY_OLD_RAILROAD:
1636  case ACTIVITY_FORTRESS:
1637  case ACTIVITY_AIRBASE:
1638  // Should not happen. Caught by the assertion below.
1639  break;
1640  }
1641 
1642  fc_assert(false);
1643  return ACT_TIME_INSTANTANEOUS;
1644 }
1645 
1649 bool action_creates_extra(const struct action *paction,
1650  const struct extra_type *pextra)
1651 {
1652  fc_assert(paction != nullptr);
1653  if (pextra == nullptr) {
1654  return false;
1655  }
1656 
1657  if (!pextra->buildable) {
1658  return false;
1659  }
1660 
1661  switch (paction->result) {
1662  case ACTRES_ROAD:
1663  return is_extra_caused_by(pextra, EC_ROAD);
1664  case ACTRES_BASE:
1665  return is_extra_caused_by(pextra, EC_BASE);
1666  case ACTRES_MINE:
1667  return is_extra_caused_by(pextra, EC_MINE);
1668  case ACTRES_IRRIGATE:
1669  return is_extra_caused_by(pextra, EC_IRRIGATION);
1670  case ACTRES_ESTABLISH_EMBASSY:
1671  case ACTRES_SPY_INVESTIGATE_CITY:
1672  case ACTRES_SPY_POISON:
1673  case ACTRES_SPY_STEAL_GOLD:
1674  case ACTRES_SPY_SABOTAGE_CITY:
1675  case ACTRES_SPY_TARGETED_SABOTAGE_CITY:
1676  case ACTRES_SPY_SABOTAGE_CITY_PRODUCTION:
1677  case ACTRES_SPY_STEAL_TECH:
1678  case ACTRES_SPY_TARGETED_STEAL_TECH:
1679  case ACTRES_SPY_INCITE_CITY:
1680  case ACTRES_TRADE_ROUTE:
1681  case ACTRES_MARKETPLACE:
1682  case ACTRES_HELP_WONDER:
1683  case ACTRES_SPY_BRIBE_UNIT:
1684  case ACTRES_SPY_SABOTAGE_UNIT:
1685  case ACTRES_CAPTURE_UNITS:
1686  case ACTRES_FOUND_CITY:
1687  case ACTRES_JOIN_CITY:
1688  case ACTRES_STEAL_MAPS:
1689  case ACTRES_BOMBARD:
1690  case ACTRES_SPY_NUKE:
1691  case ACTRES_NUKE:
1692  case ACTRES_NUKE_CITY:
1693  case ACTRES_NUKE_UNITS:
1694  case ACTRES_DESTROY_CITY:
1695  case ACTRES_EXPEL_UNIT:
1696  case ACTRES_RECYCLE_UNIT:
1697  case ACTRES_DISBAND_UNIT:
1698  case ACTRES_HOME_CITY:
1699  case ACTRES_UPGRADE_UNIT:
1700  case ACTRES_PARADROP:
1701  case ACTRES_AIRLIFT:
1702  case ACTRES_STRIKE_BUILDING:
1703  case ACTRES_STRIKE_PRODUCTION:
1704  case ACTRES_ATTACK:
1705  case ACTRES_CONQUER_CITY:
1706  case ACTRES_HEAL_UNIT:
1707  case ACTRES_TRANSFORM_TERRAIN:
1708  case ACTRES_CULTIVATE:
1709  case ACTRES_PLANT:
1710  case ACTRES_PILLAGE:
1711  case ACTRES_CLEAN_POLLUTION:
1712  case ACTRES_CLEAN_FALLOUT:
1713  case ACTRES_FORTIFY:
1714  case ACTRES_CONVERT:
1715  case ACTRES_TRANSPORT_ALIGHT:
1716  case ACTRES_TRANSPORT_UNLOAD:
1717  case ACTRES_TRANSPORT_DISEMBARK:
1718  case ACTRES_TRANSPORT_BOARD:
1719  case ACTRES_TRANSPORT_EMBARK:
1720  case ACTRES_SPY_ATTACK:
1721  case ACTRES_SPY_SPREAD_PLAGUE:
1722  case ACTRES_NONE:
1723  break;
1724  }
1725 
1726  return false;
1727 }
1728 
1732 bool action_removes_extra(const struct action *paction,
1733  const struct extra_type *pextra)
1734 {
1735  fc_assert(paction != nullptr);
1736  if (pextra == nullptr) {
1737  return false;
1738  }
1739 
1740  switch (paction->result) {
1741  case ACTRES_PILLAGE:
1742  return is_extra_removed_by(pextra, ERM_PILLAGE);
1743  case ACTRES_CLEAN_POLLUTION:
1744  return is_extra_removed_by(pextra, ERM_CLEANPOLLUTION);
1745  case ACTRES_CLEAN_FALLOUT:
1746  return is_extra_removed_by(pextra, ERM_CLEANFALLOUT);
1747  case ACTRES_ESTABLISH_EMBASSY:
1748  case ACTRES_SPY_INVESTIGATE_CITY:
1749  case ACTRES_SPY_POISON:
1750  case ACTRES_SPY_STEAL_GOLD:
1751  case ACTRES_SPY_SABOTAGE_CITY:
1752  case ACTRES_SPY_TARGETED_SABOTAGE_CITY:
1753  case ACTRES_SPY_SABOTAGE_CITY_PRODUCTION:
1754  case ACTRES_SPY_STEAL_TECH:
1755  case ACTRES_SPY_TARGETED_STEAL_TECH:
1756  case ACTRES_SPY_INCITE_CITY:
1757  case ACTRES_TRADE_ROUTE:
1758  case ACTRES_MARKETPLACE:
1759  case ACTRES_HELP_WONDER:
1760  case ACTRES_SPY_BRIBE_UNIT:
1761  case ACTRES_SPY_SABOTAGE_UNIT:
1762  case ACTRES_CAPTURE_UNITS:
1763  case ACTRES_FOUND_CITY:
1764  case ACTRES_JOIN_CITY:
1765  case ACTRES_STEAL_MAPS:
1766  case ACTRES_BOMBARD:
1767  case ACTRES_SPY_NUKE:
1768  case ACTRES_NUKE:
1769  case ACTRES_NUKE_CITY:
1770  case ACTRES_NUKE_UNITS:
1771  case ACTRES_DESTROY_CITY:
1772  case ACTRES_EXPEL_UNIT:
1773  case ACTRES_RECYCLE_UNIT:
1774  case ACTRES_DISBAND_UNIT:
1775  case ACTRES_HOME_CITY:
1776  case ACTRES_UPGRADE_UNIT:
1777  case ACTRES_PARADROP:
1778  case ACTRES_AIRLIFT:
1779  case ACTRES_STRIKE_BUILDING:
1780  case ACTRES_STRIKE_PRODUCTION:
1781  case ACTRES_ATTACK:
1782  case ACTRES_CONQUER_CITY:
1783  case ACTRES_HEAL_UNIT:
1784  case ACTRES_TRANSFORM_TERRAIN:
1785  case ACTRES_CULTIVATE:
1786  case ACTRES_PLANT:
1787  case ACTRES_FORTIFY:
1788  case ACTRES_ROAD:
1789  case ACTRES_CONVERT:
1790  case ACTRES_BASE:
1791  case ACTRES_MINE:
1792  case ACTRES_IRRIGATE:
1793  case ACTRES_TRANSPORT_ALIGHT:
1794  case ACTRES_TRANSPORT_UNLOAD:
1795  case ACTRES_TRANSPORT_DISEMBARK:
1796  case ACTRES_TRANSPORT_BOARD:
1797  case ACTRES_TRANSPORT_EMBARK:
1798  case ACTRES_SPY_ATTACK:
1799  case ACTRES_SPY_SPREAD_PLAGUE:
1800  case ACTRES_NONE:
1801  break;
1802  }
1803 
1804  return false;
1805 }
1806 
1811 {
1812  auto *enabler = new action_enabler;
1813  enabler->disabled = false;
1814  requirement_vector_init(&enabler->actor_reqs);
1815  requirement_vector_init(&enabler->target_reqs);
1816 
1817  /* Make sure that action doesn't end up as a random value that happens to
1818  * be a valid action id. */
1819  enabler->action = ACTION_NONE;
1820 
1821  return enabler;
1822 }
1823 
1828 {
1829  requirement_vector_free(&enabler->actor_reqs);
1830  requirement_vector_free(&enabler->target_reqs);
1831 
1832  delete enabler;
1833 }
1834 
1838 struct action_enabler *
1839 action_enabler_copy(const struct action_enabler *original)
1840 {
1841  struct action_enabler *enabler = action_enabler_new();
1842 
1843  enabler->action = original->action;
1844 
1845  requirement_vector_copy(&enabler->actor_reqs, &original->actor_reqs);
1846  requirement_vector_copy(&enabler->target_reqs, &original->target_reqs);
1847 
1848  return enabler;
1849 }
1850 
1854 void action_enabler_add(struct action_enabler *enabler)
1855 {
1856  // Sanity check: a non existing action enabler can't be added.
1857  fc_assert_ret(enabler);
1858  // Sanity check: a non existing action doesn't have enablers.
1860 
1861  action_enabler_list_append(action_enablers_for_action(enabler->action),
1862  enabler);
1863 }
1864 
1871 {
1872  // Sanity check: a non existing action enabler can't be removed.
1873  fc_assert_ret_val(enabler, false);
1874  // Sanity check: a non existing action doesn't have enablers.
1875  fc_assert_ret_val(action_id_exists(enabler->action), false);
1876 
1877  return action_enabler_list_remove(
1878  action_enablers_for_action(enabler->action), enabler);
1879 }
1880 
1884 struct action_enabler_list *action_enablers_for_action(action_id action)
1885 {
1886  // Sanity check: a non existing action doesn't have enablers.
1888 
1890 }
1891 
1901 struct req_vec_problem *
1903 {
1904  struct action *paction;
1905 
1906  /* Sanity check: a non existing action enabler is missing but it doesn't
1907  * miss any obligatory hard requirements. */
1908  fc_assert_ret_val(enabler, nullptr);
1909 
1910  /* Sanity check: a non existing action doesn't have any obligatory hard
1911  * requirements. */
1912  fc_assert_ret_val(action_id_exists(enabler->action), nullptr);
1913  paction = action_by_number(enabler->action);
1914 
1915  if (paction->result == ACTRES_NONE) {
1916  // No hard coded results means no obiligatory requirements.
1917  return nullptr;
1918  }
1919 
1921  obreq)
1922  {
1923  struct req_vec_problem *out;
1924  int i;
1925  bool fulfilled = false;
1926 
1927  // Check each alternative.
1928  for (i = 0; i < obreq->contras->alternatives; i++) {
1929  const struct requirement_vector *ae_vec;
1930 
1931  // Select action enabler requirement vector.
1932  ae_vec =
1933  (obreq->contras->alternative[i].is_target ? &enabler->target_reqs
1934  : &enabler->actor_reqs);
1935 
1936  if (does_req_contradicts_reqs(&obreq->contras->alternative[i].req,
1937  ae_vec)) {
1938  // It is enough that one alternative accepts the enabler.
1939  fulfilled = true;
1940  break;
1941  }
1942 
1943  // Fall back to the next alternative
1944  }
1945 
1946  if (fulfilled) {
1947  // This obligatory hard requirement isn't a problem.
1948  continue;
1949  }
1950 
1951  // Missing hard obligatory requirement detected
1952 
1953  out = req_vec_problem_new(obreq->contras->alternatives, obreq->error_msg,
1954  action_rule_name(paction));
1955 
1956  for (i = 0; i < obreq->contras->alternatives; i++) {
1957  const struct requirement_vector *ae_vec;
1958 
1959  // Select action enabler requirement vector.
1960  ae_vec =
1961  (obreq->contras->alternative[i].is_target ? &enabler->target_reqs
1962  : &enabler->actor_reqs);
1963 
1964  /* The suggested fix is to append a requirement that makes the enabler
1965  * contradict the missing hard obligatory requirement detector. */
1966  out->suggested_solutions[i].operation = RVCO_APPEND;
1968  action_enabler_vector_number(enabler, ae_vec);
1969 
1970  /* Change the requirement from what should conflict to what is
1971  * wanted. */
1972  out->suggested_solutions[i].req.present =
1973  !obreq->contras->alternative[i].req.present;
1974  out->suggested_solutions[i].req.source =
1975  obreq->contras->alternative[i].req.source;
1976  out->suggested_solutions[i].req.range =
1977  obreq->contras->alternative[i].req.range;
1978  out->suggested_solutions[i].req.survives =
1979  obreq->contras->alternative[i].req.survives;
1980  out->suggested_solutions[i].req.quiet =
1981  obreq->contras->alternative[i].req.quiet;
1982  }
1983 
1984  /* Return the first problem found. The next problem will be detected
1985  * during the next call. */
1986  return out;
1987  }
1989 
1990  // No obligatory req problems found.
1991  return nullptr;
1992 }
1993 
2000 static struct requirement *
2001 req_vec_first_local_diplrel(const struct requirement_vector *vec)
2002 {
2003  requirement_vector_iterate(vec, preq)
2004  {
2005  if (preq->source.kind == VUT_DIPLREL && preq->range == REQ_RANGE_LOCAL) {
2006  return preq;
2007  }
2008  }
2010 
2011  return nullptr;
2012 }
2013 
2022 static struct requirement *
2024  const struct requirement_vector *vec)
2025 {
2026  /* If the requirement is contradicted by any requirement in the vector it
2027  * contradicts the entire requirement vector. */
2028  requirement_vector_iterate(vec, preq)
2029  {
2030  if (are_requirements_contradictions(req, preq)) {
2031  return preq;
2032  }
2033  }
2035 
2036  /* Not a singe requirement in the requirement vector is contradicted be
2037  * the specified requirement. */
2038  return nullptr;
2039 }
2040 
2047 static struct req_vec_problem *
2049  const struct action_enabler *enabler)
2050 {
2051  struct req_vec_problem *out;
2052  struct requirement *local_diplrel;
2053  struct requirement *claimed_req;
2054  struct requirement tile_is_claimed;
2055  struct requirement tile_is_unclaimed;
2056 
2057  struct action *paction = action_by_number(enabler->action);
2058 
2059  if (action_get_target_kind(paction) != ATK_TILE) {
2060  // Not tile targeted
2061  return nullptr;
2062  }
2063 
2064  local_diplrel = req_vec_first_local_diplrel(&enabler->actor_reqs);
2065  if (local_diplrel == nullptr) {
2066  // No local diplrel
2067  return nullptr;
2068  }
2069 
2070  // Tile is unclaimed as a requirement.
2071  tile_is_claimed.quiet = false;
2072  tile_is_unclaimed.range = REQ_RANGE_LOCAL;
2073  tile_is_unclaimed.survives = false;
2074  tile_is_unclaimed.source.kind = VUT_CITYTILE;
2075  tile_is_unclaimed.present = false;
2076  tile_is_unclaimed.source.value.citytile = CITYT_CLAIMED;
2077 
2078  claimed_req = req_vec_first_contradiction_in_vec(&tile_is_unclaimed,
2079  &enabler->target_reqs);
2080 
2081  if (claimed_req) {
2082  // Already clear
2083  return nullptr;
2084  }
2085 
2086  // Tile is claimed as a requirement.
2087  tile_is_claimed.range = REQ_RANGE_LOCAL;
2088  tile_is_claimed.survives = false;
2089  tile_is_claimed.source.kind = VUT_CITYTILE;
2090  tile_is_claimed.present = true;
2091  tile_is_claimed.source.value.citytile = CITYT_CLAIMED;
2092 
2093  out = req_vec_problem_new(
2094  1,
2095  /* TRANS: ruledit shows this when an enabler for a tile targeted
2096  * action requires that the actor has a diplomatic relationship to
2097  * the target but doesn't require that the target tile is claimed.
2098  * (DiplRel requirements to an unclaimed tile are never fulfilled
2099  * so this is implicit.) */
2100  N_("Requirement {%s} implies a claimed "
2101  "tile. No diplomatic relation to Nature."),
2102  qUtf8Printable(req_to_fstring(local_diplrel)));
2103 
2104  // The solution is to add the requirement that the tile is claimed
2105  out->suggested_solutions[0].req = tile_is_claimed;
2107  action_enabler_vector_number(enabler, &enabler->target_reqs);
2108  out->suggested_solutions[0].operation = RVCO_APPEND;
2109 
2110  return out;
2111 }
2112 
2119 static struct req_vec_problem *
2121 {
2122  struct req_vec_problem *out;
2123  struct requirement *local_diplrel;
2124  struct requirement *unclaimed_req;
2125  struct requirement tile_is_claimed;
2126 
2127  struct action *paction = action_by_number(enabler->action);
2128 
2129  if (action_get_target_kind(paction) != ATK_TILE) {
2130  // Not tile targeted
2131  return nullptr;
2132  }
2133 
2134  local_diplrel = req_vec_first_local_diplrel(&enabler->actor_reqs);
2135  if (local_diplrel == nullptr) {
2136  // No local diplrel
2137  return nullptr;
2138  }
2139 
2140  // Tile is claimed as a requirement.
2141  tile_is_claimed.range = REQ_RANGE_LOCAL;
2142  tile_is_claimed.survives = false;
2143  tile_is_claimed.source.kind = VUT_CITYTILE;
2144  tile_is_claimed.present = true;
2145  tile_is_claimed.source.value.citytile = CITYT_CLAIMED;
2146 
2147  unclaimed_req = req_vec_first_contradiction_in_vec(&tile_is_claimed,
2148  &enabler->target_reqs);
2149 
2150  if (unclaimed_req == nullptr) {
2151  // No unclaimed req
2152  return nullptr;
2153  }
2154 
2155  out = req_vec_problem_new(
2156  2,
2157  /* TRANS: ruledit shows this when an enabler for a tile targeted
2158  * action requires that the target tile is unclaimed and that the
2159  * actor has a diplomatic relationship to the target. (DiplRel
2160  * requirements to an unclaimed tile are never fulfilled.) */
2161  N_("No diplomatic relation to Nature."
2162  " Requirements {%s} and {%s} contradict each other."),
2163  qUtf8Printable(req_to_fstring(local_diplrel)),
2164  qUtf8Printable(req_to_fstring(unclaimed_req)));
2165 
2166  // The first suggestion is to remove the diplrel
2167  out->suggested_solutions[0].req = *local_diplrel;
2169  action_enabler_vector_number(enabler, &enabler->actor_reqs);
2170  out->suggested_solutions[0].operation = RVCO_REMOVE;
2171 
2172  // The 2nd is to remove the requirement that the tile is unclaimed
2173  out->suggested_solutions[1].req = *unclaimed_req;
2175  action_enabler_vector_number(enabler, &enabler->target_reqs);
2176  out->suggested_solutions[1].operation = RVCO_REMOVE;
2177 
2178  return out;
2179 }
2180 
2186 struct req_vec_problem *
2188 {
2189  struct req_vec_problem *out;
2190 
2191  out = action_enabler_suggest_repair_oblig(enabler);
2192  if (out != nullptr) {
2193  return out;
2194  }
2195 
2197  &enabler->actor_reqs, action_enabler_vector_number, enabler);
2198  if (out != nullptr) {
2199  return out;
2200  }
2201 
2203  &enabler->target_reqs, action_enabler_vector_number, enabler);
2204  if (out != nullptr) {
2205  return out;
2206  }
2207 
2208  // Enabler specific contradictions.
2209  out = enabler_first_self_contradiction(enabler);
2210  if (out != nullptr) {
2211  return out;
2212  }
2213 
2214  // Needed in action not enabled explanation finding.
2216  if (out != nullptr) {
2217  return out;
2218  }
2219 
2220  // No problems found.
2221  return nullptr;
2222 }
2223 
2231 static struct req_vec_problem *
2233 {
2234  Q_UNUSED(enabler)
2235  struct req_vec_problem *out;
2236 
2237  out = nullptr;
2238 
2239  return out;
2240 }
2241 
2250 struct req_vec_problem *
2252 {
2253  struct action *paction;
2254  struct req_vec_problem *out;
2255 
2256  out = action_enabler_suggest_repair(enabler);
2257  if (out) {
2258  // A bug, not just a potential improvement
2259  return out;
2260  }
2261 
2262  paction = action_by_number(enabler->action);
2263 
2264  // Detect unused action enablers.
2265  if (action_get_actor_kind(paction) == AAK_UNIT) {
2266  bool has_user = false;
2267 
2268  unit_type_iterate(pactor)
2269  {
2270  if (action_actor_utype_hard_reqs_ok(paction->result, pactor)
2272  &(enabler->actor_reqs))) {
2273  has_user = true;
2274  break;
2275  }
2276  }
2278 
2279  if (!has_user) {
2280  // TRANS: ruledit warns a user about an unused action enabler
2281  out = req_vec_problem_new(0, N_("This action enabler is never used"
2282  " by any unit."));
2283  }
2284  }
2285  if (out != nullptr) {
2286  return out;
2287  }
2288 
2289  out = enabler_first_clarification(enabler);
2290 
2291  return out;
2292 }
2293 
2302 action_enabler_vector_number(const void *enabler,
2303  const struct requirement_vector *vec)
2304 {
2305  struct action_enabler *ae = (struct action_enabler *) enabler;
2306 
2307  if (vec == &ae->actor_reqs) {
2308  return 0;
2309  } else if (vec == &ae->target_reqs) {
2310  return 1;
2311  } else {
2312  return -1;
2313  }
2314 }
2315 
2324 struct requirement_vector *
2326  req_vec_num_in_item number)
2327 {
2328  struct action_enabler *ae = (struct action_enabler *) enabler;
2329 
2330  fc_assert_ret_val(number >= 0, nullptr);
2331 
2332  switch (number) {
2333  case 0:
2334  return &ae->actor_reqs;
2335  case 1:
2336  return &ae->target_reqs;
2337  default:
2338  return nullptr;
2339  }
2340 }
2341 
2350 {
2351  switch (vec) {
2352  case 0:
2353  // TRANS: requirement vector in an action enabler (ruledit)
2354  return _("actor_reqs");
2355  case 1:
2356  // TRANS: requirement vector in an action enabler (ruledit)
2357  return _("target_reqs");
2358  default:
2359  return nullptr;
2360  }
2361 }
2362 
2367 static bool plr_knows_tile(const struct player *plr,
2368  const struct tile *ttile)
2369 {
2370  return plr && ttile && (tile_get_known(ttile, plr) != TILE_UNKNOWN);
2371 }
2372 
2376 static bool plr_sees_tile(const struct player *plr, const struct tile *ttile)
2377 {
2378  return plr && ttile && (tile_get_known(ttile, plr) == TILE_KNOWN_SEEN);
2379 }
2380 
2386 static const struct impr_type *
2387 tgt_city_local_building(const struct city *target_city)
2388 {
2389  // Only used with city targets
2390  fc_assert_ret_val(target_city, nullptr);
2391 
2392  if (target_city->production.kind == VUT_IMPROVEMENT) {
2393  // The local building is what the target city currently is building.
2394  return target_city->production.value.building;
2395  } else {
2396  /* In the current semantic the local building is always the building
2397  * being built. */
2398  /* TODO: Consider making the local building the target building for
2399  * actions that allows specifying a building target. */
2400  return nullptr;
2401  }
2402 }
2403 
2409 static const struct unit_type *
2410 tgt_city_local_utype(const struct city *target_city)
2411 {
2412  // Only used with city targets
2413  fc_assert_ret_val(target_city, nullptr);
2414 
2415  if (target_city->production.kind == VUT_UTYPE) {
2416  /* The local unit type is what the target city currently is
2417  * building. */
2418  return target_city->production.value.utype;
2419  } else {
2420  /* In the current semantic the local utype is always the type of the
2421  * unit being built. */
2422  return nullptr;
2423  }
2424 }
2425 
2434 static const struct tile *blocked_find_target_tile(
2435  const action_id act_id, const struct unit *actor_unit,
2436  const struct tile *target_tile_arg, const struct city *target_city,
2437  const struct unit *target_unit)
2438 {
2439  if (target_tile_arg != nullptr) {
2440  // Trust the caller.
2441  return target_tile_arg;
2442  }
2443 
2444  switch (action_id_get_target_kind(act_id)) {
2445  case ATK_CITY:
2446  fc_assert_ret_val(target_city, nullptr);
2447  return city_tile(target_city);
2448  case ATK_UNIT:
2449  fc_assert_ret_val(target_unit, nullptr);
2450  return unit_tile(target_unit);
2451  case ATK_UNITS:
2452  fc_assert_ret_val(target_unit || target_tile_arg, nullptr);
2453  if (target_unit) {
2454  return unit_tile(target_unit);
2455  }
2456  // Fall through.
2457  case ATK_TILE:
2458  fc_assert_ret_val(target_tile_arg, nullptr);
2459  return target_tile_arg;
2460  case ATK_SELF:
2461  fc_assert_ret_val(actor_unit, nullptr);
2462  return unit_tile(actor_unit);
2463  case ATK_COUNT:
2464  // Handled below.
2465  break;
2466  }
2467 
2468  fc_assert_msg(false, "Bad action target kind %d for action %d",
2469  action_id_get_target_kind(act_id), act_id);
2470  return nullptr;
2471 }
2472 
2482 static const struct city *blocked_find_target_city(
2483  const action_id act_id, const struct unit *actor_unit,
2484  const struct tile *target_tile, const struct city *target_city_arg,
2485  const struct unit *target_unit)
2486 {
2487  if (target_city_arg != nullptr) {
2488  // Trust the caller.
2489  return target_city_arg;
2490  }
2491 
2492  switch (action_id_get_target_kind(act_id)) {
2493  case ATK_CITY:
2494  fc_assert_ret_val(target_city_arg, nullptr);
2495  return target_city_arg;
2496  case ATK_UNIT:
2497  fc_assert_ret_val(target_unit, nullptr);
2498  fc_assert_ret_val(unit_tile(target_unit), nullptr);
2499  return tile_city(unit_tile(target_unit));
2500  case ATK_UNITS:
2501  fc_assert_ret_val(target_unit || target_tile, nullptr);
2502  if (target_unit) {
2503  fc_assert_ret_val(unit_tile(target_unit), nullptr);
2504  return tile_city(unit_tile(target_unit));
2505  }
2506  // Fall through.
2507  case ATK_TILE:
2508  fc_assert_ret_val(target_tile, nullptr);
2509  return tile_city(target_tile);
2510  case ATK_SELF:
2511  fc_assert_ret_val(actor_unit, nullptr);
2512  fc_assert_ret_val(unit_tile(actor_unit), nullptr);
2513  return tile_city(unit_tile(actor_unit));
2514  case ATK_COUNT:
2515  // Handled below.
2516  break;
2517  }
2518 
2519  fc_assert_msg(false, "Bad action target kind %d for action %d",
2520  action_id_get_target_kind(act_id), act_id);
2521  return nullptr;
2522 }
2523 
2531  const struct unit *actor_unit,
2532  const struct tile *target_tile_arg,
2533  const struct city *target_city_arg,
2534  const struct unit *target_unit)
2535 {
2536  const struct tile *target_tile = blocked_find_target_tile(
2537  act_id, actor_unit, target_tile_arg, target_city_arg, target_unit);
2538  const struct city *target_city = blocked_find_target_city(
2539  act_id, actor_unit, target_tile, target_city_arg, target_unit);
2540 
2541  action_iterate(blocker_id)
2542  {
2543  fc_assert_action(action_id_get_actor_kind(blocker_id) == AAK_UNIT,
2544  continue);
2545 
2546  if (!action_id_would_be_blocked_by(act_id, blocker_id)) {
2547  // It doesn't matter if it is legal. It won't block the action.
2548  continue;
2549  }
2550 
2551  switch (action_id_get_target_kind(blocker_id)) {
2552  case ATK_CITY:
2553  if (!target_city) {
2554  // Can't be enabled. No target.
2555  continue;
2556  }
2557  if (is_action_enabled_unit_on_city(blocker_id, actor_unit,
2558  target_city)) {
2559  return action_by_number(blocker_id);
2560  }
2561  break;
2562  case ATK_UNIT:
2563  if (!target_unit) {
2564  // Can't be enabled. No target.
2565  continue;
2566  }
2567  if (is_action_enabled_unit_on_unit(blocker_id, actor_unit,
2568  target_unit)) {
2569  return action_by_number(blocker_id);
2570  }
2571  break;
2572  case ATK_UNITS:
2573  if (!target_tile) {
2574  // Can't be enabled. No target.
2575  continue;
2576  }
2577  if (is_action_enabled_unit_on_units(blocker_id, actor_unit,
2578  target_tile)) {
2579  return action_by_number(blocker_id);
2580  }
2581  break;
2582  case ATK_TILE:
2583  if (!target_tile) {
2584  // Can't be enabled. No target.
2585  continue;
2586  }
2587  if (is_action_enabled_unit_on_tile(blocker_id, actor_unit, target_tile,
2588  nullptr)) {
2589  return action_by_number(blocker_id);
2590  }
2591  break;
2592  case ATK_SELF:
2593  if (is_action_enabled_unit_on_self(blocker_id, actor_unit)) {
2594  return action_by_number(blocker_id);
2595  }
2596  break;
2597  case ATK_COUNT:
2598  fc_assert_action(action_id_get_target_kind(blocker_id) != ATK_COUNT,
2599  continue);
2600  break;
2601  }
2602  }
2604 
2605  // Not blocked.
2606  return nullptr;
2607 }
2608 
2629 static bool
2630 action_actor_utype_hard_reqs_ok_full(enum action_result result,
2631  const struct unit_type *actor_unittype,
2632  bool ignore_third_party)
2633 {
2634  switch (result) {
2635  case ACTRES_JOIN_CITY:
2636  if (utype_pop_value(actor_unittype) <= 0) {
2637  // Reason: Must have population to add.
2638  return false;
2639  }
2640  break;
2641 
2642  case ACTRES_BOMBARD:
2643  if (actor_unittype->bombard_rate <= 0) {
2644  // Reason: Can't bombard if it never fires.
2645  return false;
2646  }
2647 
2648  if (actor_unittype->attack_strength <= 0) {
2649  // Reason: Can't bombard without attack strength.
2650  return false;
2651  }
2652 
2653  break;
2654 
2655  case ACTRES_UPGRADE_UNIT:
2656  if (actor_unittype->obsoleted_by == U_NOT_OBSOLETED) {
2657  // Reason: Nothing to upgrade to.
2658  return false;
2659  }
2660  break;
2661 
2662  case ACTRES_ATTACK:
2663  if (actor_unittype->attack_strength <= 0) {
2664  // Reason: Can't attack without strength.
2665  return false;
2666  }
2667  break;
2668 
2669  case ACTRES_CONVERT:
2670  if (!actor_unittype->converted_to) {
2671  // Reason: must be able to convert to something.
2672  return false;
2673  }
2674  break;
2675 
2676  case ACTRES_TRANSPORT_UNLOAD:
2677  if (actor_unittype->transport_capacity < 1) {
2678  // Reason: can't transport anything to unload.
2679  return false;
2680  }
2681  break;
2682 
2683  case ACTRES_TRANSPORT_BOARD:
2684  case ACTRES_TRANSPORT_EMBARK:
2685  case ACTRES_TRANSPORT_ALIGHT:
2686  case ACTRES_TRANSPORT_DISEMBARK:
2687  if (!ignore_third_party) {
2688  bool has_transporter = false;
2689 
2690  unit_type_iterate(utrans)
2691  {
2692  if (can_unit_type_transport(utrans, utype_class(actor_unittype))) {
2693  has_transporter = true;
2694  break;
2695  }
2696  }
2698 
2699  if (!has_transporter) {
2700  // Reason: no other unit can transport this unit.
2701  return false;
2702  }
2703  }
2704  break;
2705 
2706  case ACTRES_ESTABLISH_EMBASSY:
2707  case ACTRES_SPY_INVESTIGATE_CITY:
2708  case ACTRES_SPY_POISON:
2709  case ACTRES_SPY_STEAL_GOLD:
2710  case ACTRES_SPY_SPREAD_PLAGUE:
2711  case ACTRES_SPY_SABOTAGE_CITY:
2712  case ACTRES_SPY_TARGETED_SABOTAGE_CITY:
2713  case ACTRES_SPY_SABOTAGE_CITY_PRODUCTION:
2714  case ACTRES_SPY_STEAL_TECH:
2715  case ACTRES_SPY_TARGETED_STEAL_TECH:
2716  case ACTRES_SPY_INCITE_CITY:
2717  case ACTRES_TRADE_ROUTE:
2718  case ACTRES_MARKETPLACE:
2719  case ACTRES_HELP_WONDER:
2720  case ACTRES_SPY_BRIBE_UNIT:
2721  case ACTRES_SPY_SABOTAGE_UNIT:
2722  case ACTRES_CAPTURE_UNITS:
2723  case ACTRES_FOUND_CITY:
2724  case ACTRES_STEAL_MAPS:
2725  case ACTRES_SPY_NUKE:
2726  case ACTRES_NUKE:
2727  case ACTRES_NUKE_CITY:
2728  case ACTRES_NUKE_UNITS:
2729  case ACTRES_DESTROY_CITY:
2730  case ACTRES_EXPEL_UNIT:
2731  case ACTRES_RECYCLE_UNIT:
2732  case ACTRES_DISBAND_UNIT:
2733  case ACTRES_HOME_CITY:
2734  case ACTRES_PARADROP:
2735  case ACTRES_AIRLIFT:
2736  case ACTRES_STRIKE_BUILDING:
2737  case ACTRES_STRIKE_PRODUCTION:
2738  case ACTRES_CONQUER_CITY:
2739  case ACTRES_HEAL_UNIT:
2740  case ACTRES_PILLAGE:
2741  case ACTRES_CLEAN_POLLUTION:
2742  case ACTRES_CLEAN_FALLOUT:
2743  case ACTRES_FORTIFY:
2744  case ACTRES_TRANSFORM_TERRAIN:
2745  case ACTRES_CULTIVATE:
2746  case ACTRES_PLANT:
2747  case ACTRES_ROAD:
2748  case ACTRES_BASE:
2749  case ACTRES_MINE:
2750  case ACTRES_IRRIGATE:
2751  case ACTRES_SPY_ATTACK:
2752  case ACTRES_NONE:
2753  // No hard unit type requirements.
2754  break;
2755  }
2756 
2757  return true;
2758 }
2759 
2776 bool action_actor_utype_hard_reqs_ok(enum action_result result,
2777  const struct unit_type *actor_unittype)
2778 {
2779  return action_actor_utype_hard_reqs_ok_full(result, actor_unittype, false);
2780 }
2781 
2791  enum action_result result, const struct player *actor_player,
2792  const struct city *actor_city, const struct impr_type *actor_building,
2793  const struct tile *actor_tile, const struct unit *actor_unit,
2794  const struct unit_type *actor_unittype,
2795  const struct output_type *actor_output,
2796  const struct specialist *actor_specialist, const bool omniscient,
2797  const struct city *homecity)
2798 {
2799  Q_UNUSED(actor_building)
2800  Q_UNUSED(actor_tile)
2801  Q_UNUSED(actor_output)
2802  Q_UNUSED(homecity)
2803  Q_UNUSED(actor_specialist)
2804  if (!action_actor_utype_hard_reqs_ok_full(result, actor_unittype, true)) {
2805  // Info leak: The actor player knows the type of his unit.
2806  /* The actor unit type can't perform the action because of hard
2807  * unit type requirements. */
2808  return TRI_NO;
2809  }
2810 
2811  switch (result) {
2812  case ACTRES_PARADROP:
2813  // Reason: Keep the old rules.
2814  /* Info leak: The player knows if his unit already has paradropped this
2815  * turn. */
2816  if (actor_unit->paradropped) {
2817  return TRI_NO;
2818  }
2819 
2820  break;
2821 
2822  case ACTRES_AIRLIFT: {
2823  /* Obligatory hard requirement. Checked here too since
2824  * action_hard_reqs_actor() may be called before any
2825  * action enablers are checked. */
2826  if (actor_city == nullptr) {
2827  // No city to airlift from.
2828  return TRI_NO;
2829  }
2830 
2831  if (actor_player != city_owner(actor_city)
2832  && !(game.info.airlifting_style & AIRLIFTING_ALLIED_SRC
2833  && pplayers_allied(actor_player, city_owner(actor_city)))) {
2834  // Not allowed to airlift from this source.
2835  return TRI_NO;
2836  }
2837 
2838  if (!(omniscient || city_owner(actor_city) == actor_player)) {
2839  // Can't check for airlifting capacity.
2840  return TRI_MAYBE;
2841  }
2842 
2843  if (0 >= actor_city->airlift) {
2844  /* The source cannot airlift for this turn (maybe already airlifted
2845  * or no airport).
2846  *
2847  * Note that (game.info.airlifting_style & AIRLIFTING_UNLIMITED_SRC)
2848  * is not handled here because it applies only when the source city
2849  * has at least one remaining airlift.
2850  * See also do_airline() in server/unittools.h. */
2851  return TRI_NO;
2852  }
2853  } break;
2854 
2855  case ACTRES_CONVERT:
2856  // Reason: Keep the old rules.
2857  // Info leak: The player knows his unit's cargo and location.
2858  if (!unit_can_convert(actor_unit)) {
2859  return TRI_NO;
2860  }
2861  break;
2862 
2863  case ACTRES_TRANSPORT_BOARD:
2864  case ACTRES_TRANSPORT_EMBARK:
2865  if (unit_transported(actor_unit)) {
2866  if (!can_unit_unload(actor_unit, unit_transport_get(actor_unit))) {
2867  // Can't leave current transport.
2868  return TRI_NO;
2869  }
2870  }
2871  break;
2872 
2873  case ACTRES_TRANSPORT_DISEMBARK:
2874  if (!can_unit_unload(actor_unit, unit_transport_get(actor_unit))) {
2875  // Keep the old rules about Unreachable and disembarks.
2876  return TRI_NO;
2877  }
2878  break;
2879 
2880  case ACTRES_ESTABLISH_EMBASSY:
2881  case ACTRES_SPY_INVESTIGATE_CITY:
2882  case ACTRES_SPY_POISON:
2883  case ACTRES_SPY_STEAL_GOLD:
2884  case ACTRES_SPY_SPREAD_PLAGUE:
2885  case ACTRES_SPY_SABOTAGE_CITY:
2886  case ACTRES_SPY_TARGETED_SABOTAGE_CITY:
2887  case ACTRES_SPY_SABOTAGE_CITY_PRODUCTION:
2888  case ACTRES_SPY_STEAL_TECH:
2889  case ACTRES_SPY_TARGETED_STEAL_TECH:
2890  case ACTRES_SPY_INCITE_CITY:
2891  case ACTRES_TRADE_ROUTE:
2892  case ACTRES_MARKETPLACE:
2893  case ACTRES_HELP_WONDER:
2894  case ACTRES_SPY_BRIBE_UNIT:
2895  case ACTRES_SPY_SABOTAGE_UNIT:
2896  case ACTRES_CAPTURE_UNITS:
2897  case ACTRES_FOUND_CITY:
2898  case ACTRES_JOIN_CITY:
2899  case ACTRES_STEAL_MAPS:
2900  case ACTRES_BOMBARD:
2901  case ACTRES_SPY_NUKE:
2902  case ACTRES_NUKE:
2903  case ACTRES_NUKE_CITY:
2904  case ACTRES_NUKE_UNITS:
2905  case ACTRES_DESTROY_CITY:
2906  case ACTRES_EXPEL_UNIT:
2907  case ACTRES_RECYCLE_UNIT:
2908  case ACTRES_DISBAND_UNIT:
2909  case ACTRES_HOME_CITY:
2910  case ACTRES_UPGRADE_UNIT:
2911  case ACTRES_ATTACK:
2912  case ACTRES_STRIKE_BUILDING:
2913  case ACTRES_STRIKE_PRODUCTION:
2914  case ACTRES_CONQUER_CITY:
2915  case ACTRES_HEAL_UNIT:
2916  case ACTRES_TRANSFORM_TERRAIN:
2917  case ACTRES_CULTIVATE:
2918  case ACTRES_PLANT:
2919  case ACTRES_PILLAGE:
2920  case ACTRES_CLEAN_POLLUTION:
2921  case ACTRES_CLEAN_FALLOUT:
2922  case ACTRES_FORTIFY:
2923  case ACTRES_ROAD:
2924  case ACTRES_BASE:
2925  case ACTRES_MINE:
2926  case ACTRES_IRRIGATE:
2927  case ACTRES_TRANSPORT_ALIGHT:
2928  case ACTRES_TRANSPORT_UNLOAD:
2929  case ACTRES_SPY_ATTACK:
2930  case ACTRES_NONE:
2931  // No hard unit requirements.
2932  break;
2933  }
2934 
2935  return TRI_YES;
2936 }
2937 
2958 static enum fc_tristate is_action_possible(
2959  const action_id wanted_action, const struct player *actor_player,
2960  const struct city *actor_city, const struct impr_type *actor_building,
2961  const struct tile *actor_tile, const struct unit *actor_unit,
2962  const struct unit_type *actor_unittype,
2963  const struct output_type *actor_output,
2964  const struct specialist *actor_specialist,
2965  const struct player *target_player, const struct city *target_city,
2966  const struct impr_type *target_building, const struct tile *target_tile,
2967  const struct unit *target_unit, const struct unit_type *target_unittype,
2968  const struct output_type *target_output,
2969  const struct specialist *target_specialist,
2970  const struct extra_type *target_extra, const bool omniscient,
2971  const struct city *homecity)
2972 {
2973  Q_UNUSED(target_output)
2974  Q_UNUSED(target_building)
2975  Q_UNUSED(target_specialist)
2976  bool can_see_tgt_unit;
2977  bool can_see_tgt_tile;
2978  enum fc_tristate out;
2979  struct terrain *pterrain;
2980  struct action *paction;
2981 
2982  fc_assert_msg(
2983  (action_id_get_target_kind(wanted_action) == ATK_CITY
2984  && target_city != nullptr)
2985  || (action_id_get_target_kind(wanted_action) == ATK_TILE
2986  && target_tile != nullptr)
2987  || (action_id_get_target_kind(wanted_action) == ATK_UNIT
2988  && target_unit != nullptr)
2989  || (action_id_get_target_kind(wanted_action) == ATK_UNITS
2990  // At this level each individual unit is tested.
2991  && target_unit != nullptr)
2992  || (action_id_get_target_kind(wanted_action) == ATK_SELF),
2993  "Missing target!");
2994 
2995  paction = action_by_number(wanted_action);
2996 
2997  /* Only check requirement against the target unit if the actor can see it
2998  * or if the evaluator is omniscient. The game checking the rules is
2999  * omniscient. The player asking about his odds isn't. */
3000  can_see_tgt_unit =
3001  (omniscient
3002  || (target_unit && can_player_see_unit(actor_player, target_unit)));
3003 
3004  /* Only check requirement against the target tile if the actor can see it
3005  * or if the evaluator is omniscient. The game checking the rules is
3006  * omniscient. The player asking about his odds isn't. */
3007  can_see_tgt_tile =
3008  (omniscient || plr_sees_tile(actor_player, target_tile));
3009 
3010  // Info leak: The player knows where his unit is.
3011  if (action_get_target_kind(paction) != ATK_SELF
3013  paction, real_map_distance(actor_tile, target_tile))) {
3014  /* The distance between the actor and the target isn't inside the
3015  * action's accepted range. */
3016  return TRI_NO;
3017  }
3018 
3019  switch (action_get_target_kind(paction)) {
3020  case ATK_UNIT:
3021  /* The Freeciv code for all actions that is controlled by action
3022  * enablers and targets a unit assumes that the acting
3023  * player can see the target unit.
3024  * Examples:
3025  * - action_prob_vs_unit()'s quick check that the distance between actor
3026  * and target is acceptable would leak distance to target unit if the
3027  * target unit can't be seen.
3028  */
3029  if (!can_player_see_unit(actor_player, target_unit)) {
3030  return TRI_NO;
3031  }
3032  break;
3033  case ATK_CITY:
3034  /* The Freeciv code assumes that the player is aware of the target
3035  * city's existence. (How can you order an airlift to a city when you
3036  * don't know its city ID?) */
3037  if (fc_funcs->player_tile_city_id_get(city_tile(target_city),
3038  actor_player)
3039  != target_city->id) {
3040  return TRI_NO;
3041  }
3042  break;
3043  case ATK_UNITS:
3044  case ATK_TILE:
3045  case ATK_SELF:
3046  // No special player knowledge checks.
3047  break;
3048  case ATK_COUNT:
3049  fc_assert(action_get_target_kind(paction) != ATK_COUNT);
3050  break;
3051  }
3052 
3053  if (action_is_blocked_by(wanted_action, actor_unit, target_tile,
3054  target_city, target_unit)) {
3055  /* Allows an action to block an other action. If a blocking action is
3056  * legal the actions it blocks becomes illegal. */
3057  return TRI_NO;
3058  }
3059 
3060  // Actor specific hard requirements.
3061  out = action_hard_reqs_actor(paction->result, actor_player, actor_city,
3062  actor_building, actor_tile, actor_unit,
3063  actor_unittype, actor_output,
3064  actor_specialist, omniscient, homecity);
3065 
3066  if (out == TRI_NO) {
3067  // Illegal because of a hard actor requirement.
3068  return TRI_NO;
3069  }
3070 
3071  // Hard requirements for individual actions.
3072  switch (paction->result) {
3073  case ACTRES_CAPTURE_UNITS:
3074  case ACTRES_SPY_BRIBE_UNIT:
3075  /* Why this is a hard requirement: Can't transfer a unique unit if the
3076  * actor player already has one. */
3077  /* Info leak: This is only checked for when the actor player can see
3078  * the target unit. Since the target unit is seen its type is known.
3079  * The fact that a city hiding the unseen unit is occupied is known. */
3080 
3081  if (!can_see_tgt_unit) {
3082  // An omniscient player can see the target unit.
3083  fc_assert(!omniscient);
3084 
3085  return TRI_MAYBE;
3086  }
3087 
3088  if (utype_player_already_has_this_unique(actor_player,
3089  target_unittype)) {
3090  return TRI_NO;
3091  }
3092 
3093  /* FIXME: Capture Unit may want to look for more than one unique unit
3094  * of the same kind at the target tile. Currently caught by sanity
3095  * check in do_capture_units(). */
3096 
3097  break;
3098 
3099  case ACTRES_SPY_TARGETED_STEAL_TECH:
3100  /* Reason: The Freeciv code don't support selecting a target tech
3101  * unless it is known that the victim player has it. */
3102  // Info leak: The actor player knowns who's techs he can see.
3103  if (!can_see_techs_of_target(actor_player, target_player)) {
3104  return TRI_NO;
3105  }
3106 
3107  break;
3108 
3109  case ACTRES_SPY_STEAL_GOLD:
3110  /* If actor_unit can do the action the actor_player can see how much
3111  * gold target_player have. Not requireing it is therefore pointless.
3112  */
3113  if (target_player->economic.gold <= 0) {
3114  return TRI_NO;
3115  }
3116 
3117  break;
3118 
3119  case ACTRES_TRADE_ROUTE:
3120  case ACTRES_MARKETPLACE: {
3121  // Checked in action_hard_reqs_actor()
3122  fc_assert_ret_val(homecity != nullptr, TRI_NO);
3123 
3124  /* Can't establish a trade route or enter the market place if the
3125  * cities can't trade at all. */
3126  /* TODO: Should this restriction (and the above restriction that the
3127  * actor unit must have a home city) be kept for Enter Marketplace? */
3128  if (!can_cities_trade(homecity, target_city)) {
3129  return TRI_NO;
3130  }
3131 
3132  /* There are more restrictions on establishing a trade route than on
3133  * entering the market place. */
3134  if (action_has_result(paction, ACTRES_TRADE_ROUTE)
3135  && !can_establish_trade_route(homecity, target_city)) {
3136  return TRI_NO;
3137  }
3138  }
3139 
3140  break;
3141 
3142  case ACTRES_HELP_WONDER:
3143  case ACTRES_RECYCLE_UNIT:
3144  /* It is only possible to help the production if the production needs
3145  * the help. (If not it would be possible to add shields for something
3146  * that can't legally receive help if it is build later) */
3147  /* Info leak: The player knows that the production in his own city has
3148  * been hurried (bought or helped). The information isn't revealed when
3149  * asking for action probabilities since omniscient is FALSE. */
3150  if (!omniscient
3151  && !can_player_see_city_internals(actor_player, target_city)) {
3152  return TRI_MAYBE;
3153  }
3154 
3155  if (target_city->shield_stock
3156  >= city_production_build_shield_cost(target_city)) {
3157  return TRI_NO;
3158  }
3159 
3160  break;
3161 
3162  case ACTRES_FOUND_CITY:
3163  if (game.scenario.prevent_new_cities) {
3164  // Reason: allow scenarios to disable city founding.
3165  // Info leak: the setting is public knowledge.
3166  return TRI_NO;
3167  }
3168 
3169  if (can_see_tgt_tile && tile_city(target_tile)) {
3170  // Reason: a tile can have 0 or 1 cities.
3171  return TRI_NO;
3172  }
3173 
3174  if (citymindist_prevents_city_on_tile(target_tile)) {
3175  if (omniscient) {
3176  // No need to check again.
3177  return TRI_NO;
3178  } else {
3179  square_iterate(&(wld.map), target_tile, game.info.citymindist - 1,
3180  otile)
3181  {
3182  if (tile_city(otile) != nullptr
3183  && plr_sees_tile(actor_player, otile)) {
3184  // Known to be blocked by citymindist
3185  return TRI_NO;
3186  }
3187  }
3189  }
3190  }
3191 
3192  // The player may not have enough information to be certain.
3193 
3194  if (!can_see_tgt_tile) {
3195  /* Need to know if target tile already has a city, has TER_NO_CITIES
3196  * terrain, is non native to the actor or is owned by a foreigner. */
3197  return TRI_MAYBE;
3198  }
3199 
3200  if (!omniscient) {
3201  /* The player may not have enough information to find out if
3202  * citymindist blocks or not. This doesn't depend on if it blocks. */
3203  square_iterate(&(wld.map), target_tile, game.info.citymindist - 1,
3204  otile)
3205  {
3206  if (!plr_sees_tile(actor_player, otile)) {
3207  /* Could have a city that blocks via citymindist. Even if this
3208  * tile has TER_NO_CITIES terrain the player don't know that it
3209  * didn't change and had a city built on it. */
3210  return TRI_MAYBE;
3211  }
3212  }
3214  }
3215 
3216  break;
3217 
3218  case ACTRES_JOIN_CITY: {
3219  int new_pop;
3220 
3221  if (!omniscient
3222  && !player_can_see_city_externals(actor_player, target_city)) {
3223  return TRI_MAYBE;
3224  }
3225 
3226  new_pop = city_size_get(target_city) + unit_pop_value(actor_unit);
3227 
3228  if (new_pop > game.info.add_to_size_limit) {
3229  // Reason: Make the add_to_size_limit setting work.
3230  return TRI_NO;
3231  }
3232 
3233  if (!city_can_grow_to(target_city, new_pop)) {
3234  // Reason: respect city size limits.
3235  /* Info leak: when it is legal to join a foreign city is legal and
3236  * the EFT_SIZE_UNLIMIT effect or the EFT_SIZE_ADJ effect depends on
3237  * something the actor player don't have access to.
3238  * Example: depends on a building (like Aqueduct) that isn't
3239  * VisibleByOthers. */
3240  return TRI_NO;
3241  }
3242  }
3243 
3244  break;
3245 
3246  case ACTRES_BOMBARD:
3247  // FIXME: Target of Bombard should be city and units.
3248  if (tile_city(target_tile)
3249  && !pplayers_at_war(city_owner(tile_city(target_tile)),
3250  actor_player)) {
3251  return TRI_NO;
3252  }
3253 
3254  break;
3255 
3256  case ACTRES_NUKE_UNITS:
3257  if (unit_attack_units_at_tile_result(actor_unit, target_tile)
3258  != ATT_OK) {
3259  // Unreachable.
3260  return TRI_NO;
3261  }
3262 
3263  break;
3264 
3265  case ACTRES_HOME_CITY:
3266  // Reason: can't change to what is.
3267  // Info leak: The player knows his unit's current home city.
3268  if (homecity != nullptr && homecity->id == target_city->id) {
3269  // This is already the unit's home city.
3270  return TRI_NO;
3271  }
3272 
3273  {
3274  int nslots = unit_type_get(actor_unit)->city_slots;
3275 
3276  if (nslots > 0 && city_unit_slots_available(target_city) < nslots) {
3277  return TRI_NO;
3278  }
3279  }
3280 
3281  break;
3282 
3283  case ACTRES_UPGRADE_UNIT:
3284  // Reason: Keep the old rules.
3285  /* Info leak: The player knows his unit's type. He knows if he can
3286  * build the unit type upgraded to. If the upgrade happens in a foreign
3287  * city that fact may leak. This can be seen as a price for changing
3288  * the rules to allow upgrading in a foreign city.
3289  * The player knows how much gold he has. If the Upgrade_Price_Pct
3290  * effect depends on information he don't have that information may
3291  * leak. The player knows the location of his unit. He knows if the
3292  * tile has a city and if the unit can exist there outside a transport.
3293  * The player knows his unit's cargo. By knowing their number and type
3294  * he can predict if there will be room for them in the unit upgraded
3295  * to as long as he knows what unit type his unit will end up as. */
3296  if (unit_upgrade_test(actor_unit, false) != UU_OK) {
3297  return TRI_NO;
3298  }
3299 
3300  break;
3301 
3302  case ACTRES_PARADROP:
3303  // Reason: Keep the old rules.
3304  // Info leak: The player knows if he knows the target tile.
3305  if (!plr_knows_tile(actor_player, target_tile)) {
3306  return TRI_NO;
3307  }
3308 
3309  if (plr_sees_tile(actor_player, target_tile)) {
3310  // Check for seen stuff that may kill the actor unit.
3311 
3312  // Reason: Keep the old rules. Be merciful.
3313  // Info leak: The player sees the target tile.
3314  if (!can_unit_exist_at_tile(&(wld.map), actor_unit, target_tile)
3315  && (!game.info.paradrop_to_transport
3316  || !unit_could_load_at(actor_unit, target_tile))) {
3317  return TRI_NO;
3318  }
3319 
3320  // Reason: Keep the old rules. Be merciful.
3321  // Info leak: The player sees the target tile.
3322  if (is_non_attack_city_tile(target_tile, actor_player)) {
3323  return TRI_NO;
3324  }
3325 
3326  // Reason: Keep the old rules. Be merciful.
3327  /* Info leak: The player sees all units checked. Invisible units are
3328  * igonered. */
3329  unit_list_iterate(target_tile->units, pother)
3330  {
3331  if (can_player_see_unit(actor_player, pother)
3332  && pplayers_non_attack(actor_player, unit_owner(pother))) {
3333  return TRI_NO;
3334  }
3335  }
3337  }
3338 
3339  // Reason: Keep paratroopers_range working.
3340  /* Info leak: The player knows the location of the actor and of the
3341  * target tile. */
3342  if (unit_type_get(actor_unit)->paratroopers_range
3343  < real_map_distance(actor_tile, target_tile)) {
3344  return TRI_NO;
3345  }
3346 
3347  break;
3348 
3349  case ACTRES_AIRLIFT:
3350  // Reason: Keep the old rules.
3351  // Info leak: same as test_unit_can_airlift_to()
3352  switch (test_unit_can_airlift_to(omniscient ? nullptr : actor_player,
3353  actor_unit, target_city)) {
3354  case AR_OK:
3355  return TRI_YES;
3356  case AR_OK_SRC_UNKNOWN:
3357  case AR_OK_DST_UNKNOWN:
3358  return TRI_MAYBE;
3359  case AR_NO_MOVES:
3360  case AR_WRONG_UNITTYPE:
3361  case AR_OCCUPIED:
3362  case AR_NOT_IN_CITY:
3363  case AR_BAD_SRC_CITY:
3364  case AR_BAD_DST_CITY:
3365  case AR_SRC_NO_FLIGHTS:
3366  case AR_DST_NO_FLIGHTS:
3367  return TRI_NO;
3368  }
3369 
3370  break;
3371 
3372  case ACTRES_ATTACK:
3373  // Reason: Keep the old rules.
3374  if (!can_unit_attack_tile(actor_unit, target_tile)) {
3375  return TRI_NO;
3376  }
3377  break;
3378 
3379  case ACTRES_CONQUER_CITY:
3380  // Reason: "Conquer City" involves moving into the city.
3381  if (!unit_can_move_to_tile(&(wld.map), actor_unit, target_tile, false,
3382  true)) {
3383  return TRI_NO;
3384  }
3385 
3386  break;
3387 
3388  case ACTRES_HEAL_UNIT:
3389  // Reason: It is not the healthy who need a doctor, but the sick.
3390  // Info leak: the actor can see the target's HP.
3391  if (!(target_unit->hp < target_unittype->hp)) {
3392  return TRI_NO;
3393  }
3394  break;
3395 
3396  case ACTRES_TRANSFORM_TERRAIN:
3397  pterrain = tile_terrain(target_tile);
3398  if (pterrain->transform_result == T_NONE
3399  || pterrain == pterrain->transform_result
3400  || !terrain_surroundings_allow_change(target_tile,
3401  pterrain->transform_result)
3402  || (terrain_has_flag(pterrain->transform_result, TER_NO_CITIES)
3403  && (tile_city(target_tile)))) {
3404  return TRI_NO;
3405  }
3406  break;
3407 
3408  case ACTRES_CULTIVATE:
3409  pterrain = tile_terrain(target_tile);
3410  if (pterrain->irrigation_result == pterrain
3411  || pterrain->irrigation_result == T_NONE) {
3412  return TRI_NO;
3413  }
3414  if (!terrain_surroundings_allow_change(target_tile,
3415  pterrain->irrigation_result)
3416  || (terrain_has_flag(pterrain->irrigation_result, TER_NO_CITIES)
3417  && tile_city(target_tile))) {
3418  return TRI_NO;
3419  }
3420  break;
3421 
3422  case ACTRES_PLANT:
3423  pterrain = tile_terrain(target_tile);
3424  if (pterrain->mining_result == pterrain
3425  || pterrain->mining_result == T_NONE) {
3426  return TRI_NO;
3427  }
3428  if (!terrain_surroundings_allow_change(target_tile,
3429  pterrain->mining_result)
3430  || (terrain_has_flag(pterrain->mining_result, TER_NO_CITIES)
3431  && tile_city(target_tile))) {
3432  return TRI_NO;
3433  }
3434  break;
3435 
3436  case ACTRES_ROAD:
3437  if (target_extra == nullptr) {
3438  return TRI_NO;
3439  }
3440  if (!is_extra_caused_by(target_extra, EC_ROAD)) {
3441  // Reason: This is not a road.
3442  return TRI_NO;
3443  }
3444  if (!can_build_road(extra_road_get(target_extra), actor_unit,
3445  target_tile)) {
3446  return TRI_NO;
3447  }
3448  break;
3449 
3450  case ACTRES_BASE:
3451  if (target_extra == nullptr) {
3452  return TRI_NO;
3453  }
3454  if (!is_extra_caused_by(target_extra, EC_BASE)) {
3455  // Reason: This is not a base.
3456  return TRI_NO;
3457  }
3458  if (!can_build_base(actor_unit, extra_base_get(target_extra),
3459  target_tile)) {
3460  return TRI_NO;
3461  }
3462  break;
3463 
3464  case ACTRES_MINE:
3465  if (target_extra == nullptr) {
3466  return TRI_NO;
3467  }
3468  if (!is_extra_caused_by(target_extra, EC_MINE)) {
3469  // Reason: This is not a mine.
3470  return TRI_NO;
3471  }
3472 
3473  pterrain = tile_terrain(target_tile);
3474  if (pterrain->mining_time == 0) {
3475  return TRI_NO;
3476  }
3477  if (pterrain->mining_result != pterrain) {
3478  // Mining is forbidden or will result in a terrain transformation.
3479  return TRI_NO;
3480  }
3481 
3482  if (!can_build_extra(target_extra, actor_unit, target_tile)) {
3483  return TRI_NO;
3484  }
3485  break;
3486 
3487  case ACTRES_IRRIGATE:
3488  if (target_extra == nullptr) {
3489  return TRI_NO;
3490  }
3491  if (!is_extra_caused_by(target_extra, EC_IRRIGATION)) {
3492  // Reason: This is not an irrigation.
3493  return TRI_NO;
3494  }
3495 
3496  pterrain = tile_terrain(target_tile);
3497  if (pterrain->irrigation_time == 0) {
3498  return TRI_NO;
3499  }
3500  if (pterrain->irrigation_result != pterrain) {
3501  /* Irrigation is forbidden or will result in a terrain
3502  * transformation. */
3503  return TRI_NO;
3504  }
3505 
3506  if (!can_build_extra(target_extra, actor_unit, target_tile)) {
3507  return TRI_NO;
3508  }
3509  break;
3510 
3511  case ACTRES_PILLAGE:
3512  pterrain = tile_terrain(target_tile);
3513  if (pterrain->pillage_time == 0) {
3514  return TRI_NO;
3515  }
3516 
3517  {
3518  bv_extras pspresent =
3519  get_tile_infrastructure_set(target_tile, nullptr);
3520  bv_extras psworking = get_unit_tile_pillage_set(target_tile);
3521  bv_extras pspossible;
3522 
3523  BV_CLR_ALL(pspossible);
3524  extra_type_iterate(pextra)
3525  {
3526  int idx = extra_index(pextra);
3527 
3528  // Only one unit can pillage a given improvement at a time
3529  if (BV_ISSET(pspresent, idx)
3530  && (!BV_ISSET(psworking, idx)
3531  || actor_unit->activity_target == pextra)
3532  && can_remove_extra(pextra, actor_unit, target_tile)) {
3533  bool required = false;
3534 
3535  extra_type_iterate(pdepending)
3536  {
3537  if (BV_ISSET(pspresent, extra_index(pdepending))) {
3538  extra_deps_iterate(&(pdepending->reqs), pdep)
3539  {
3540  if (pdep == pextra) {
3541  required = true;
3542  break;
3543  }
3544  }
3546  }
3547  if (required) {
3548  break;
3549  }
3550  }
3552 
3553  if (!required) {
3554  BV_SET(pspossible, idx);
3555  }
3556  }
3557  }
3559 
3560  if (!BV_ISSET_ANY(pspossible)) {
3561  // Nothing available to pillage
3562  return TRI_NO;
3563  }
3564 
3565  if (target_extra != nullptr) {
3566  if (!game.info.pillage_select) {
3567  // Hobson's choice (this case mostly exists for old clients)
3568  // Needs to match what unit_activity_assign_target chooses
3569  struct extra_type *tgt;
3570 
3571  tgt = get_preferred_pillage(pspossible);
3572 
3573  if (tgt != target_extra) {
3574  // Only one target allowed, which wasn't the requested one
3575  return TRI_NO;
3576  }
3577  }
3578 
3579  if (!BV_ISSET(pspossible, extra_index(target_extra))) {
3580  return TRI_NO;
3581  }
3582  }
3583  }
3584  break;
3585 
3586  case ACTRES_CLEAN_POLLUTION: {
3587  const struct extra_type *pextra;
3588 
3589  pterrain = tile_terrain(target_tile);
3590  if (pterrain->clean_pollution_time == 0) {
3591  return TRI_NO;
3592  }
3593 
3594  if (target_extra != nullptr) {
3595  pextra = target_extra;
3596  } else {
3597  /* TODO: Make sure that all callers set target so that
3598  * we don't need this fallback. */
3599  pextra = prev_extra_in_tile(target_tile, ERM_CLEANPOLLUTION,
3600  actor_player, actor_unit);
3601  if (pextra == nullptr) {
3602  // No available pollution extras
3603  return TRI_NO;
3604  }
3605  }
3606 
3607  if (!is_extra_removed_by(pextra, ERM_CLEANPOLLUTION)) {
3608  return TRI_NO;
3609  }
3610 
3611  if (!can_remove_extra(pextra, actor_unit, target_tile)) {
3612  return TRI_NO;
3613  }
3614 
3615  if (tile_has_extra(target_tile, pextra)) {
3616  return TRI_YES;
3617  }
3618 
3619  return TRI_NO;
3620  } break;
3621 
3622  case ACTRES_CLEAN_FALLOUT: {
3623  const struct extra_type *pextra;
3624 
3625  pterrain = tile_terrain(target_tile);
3626  if (pterrain->clean_fallout_time == 0) {
3627  return TRI_NO;
3628  }
3629 
3630  if (target_extra != nullptr) {
3631  pextra = target_extra;
3632  } else {
3633  /* TODO: Make sure that all callers set target so that
3634  * we don't need this fallback. */
3635  pextra = prev_extra_in_tile(target_tile, ERM_CLEANFALLOUT,
3636  actor_player, actor_unit);
3637  if (pextra == nullptr) {
3638  // No available pollution extras
3639  return TRI_NO;
3640  }
3641  }
3642 
3643  if (!is_extra_removed_by(pextra, ERM_CLEANFALLOUT)) {
3644  return TRI_NO;
3645  }
3646 
3647  if (!can_remove_extra(pextra, actor_unit, target_tile)) {
3648  return TRI_NO;
3649  }
3650 
3651  if (tile_has_extra(target_tile, pextra)) {
3652  return TRI_YES;
3653  }
3654 
3655  return TRI_NO;
3656  } break;
3657 
3658  case ACTRES_TRANSPORT_ALIGHT:
3659  if (!can_unit_unload(actor_unit, target_unit)) {
3660  // Keep the old rules about Unreachable and disembarks.
3661  return TRI_NO;
3662  }
3663  break;
3664 
3665  case ACTRES_TRANSPORT_BOARD:
3666  if (unit_transported(actor_unit)) {
3667  if (target_unit == unit_transport_get(actor_unit)) {
3668  // Already inside this transport.
3669  return TRI_NO;
3670  }
3671  }
3672  if (!could_unit_load(actor_unit, target_unit)) {
3673  // Keep the old rules.
3674  return TRI_NO;
3675  }
3676  break;
3677 
3678  case ACTRES_TRANSPORT_UNLOAD:
3679  if (!can_unit_unload(target_unit, actor_unit)) {
3680  // Keep the old rules about Unreachable and disembarks.
3681  return TRI_NO;
3682  }
3683  break;
3684 
3685  case ACTRES_TRANSPORT_DISEMBARK:
3686  if (!unit_can_move_to_tile(&(wld.map), actor_unit, target_tile, false,
3687  false)) {
3688  // Reason: involves moving to the tile.
3689  return TRI_NO;
3690  }
3691 
3692  /* We cannot move a transport into a tile that holds
3693  * units or cities not allied with all of our cargo. */
3694  if (get_transporter_capacity(actor_unit) > 0) {
3695  unit_list_iterate(unit_tile(actor_unit)->units, pcargo)
3696  {
3697  if (unit_contained_in(pcargo, actor_unit)
3698  && (is_non_allied_unit_tile(target_tile, unit_owner(pcargo))
3699  || is_non_allied_city_tile(target_tile,
3700  unit_owner(pcargo)))) {
3701  return TRI_NO;
3702  }
3703  }
3705  }
3706  break;
3707 
3708  case ACTRES_TRANSPORT_EMBARK:
3709  if (unit_transported(actor_unit)) {
3710  if (target_unit == unit_transport_get(actor_unit)) {
3711  // Already inside this transport.
3712  return TRI_NO;
3713  }
3714  }
3715  if (!could_unit_load(actor_unit, target_unit)) {
3716  // Keep the old rules.
3717  return TRI_NO;
3718  }
3719  if (!unit_can_move_to_tile(&(wld.map), actor_unit, target_tile, false,
3720  false)) {
3721  // Reason: involves moving to the tile.
3722  return TRI_NO;
3723  }
3724  /* We cannot move a transport into a tile that holds
3725  * units or cities not allied with all of our cargo. */
3726  if (get_transporter_capacity(actor_unit) > 0) {
3727  unit_list_iterate(unit_tile(actor_unit)->units, pcargo)
3728  {
3729  if (unit_contained_in(pcargo, actor_unit)
3730  && (is_non_allied_unit_tile(target_tile, unit_owner(pcargo))
3731  || is_non_allied_city_tile(target_tile,
3732  unit_owner(pcargo)))) {
3733  return TRI_NO;
3734  }
3735  }
3737  }
3738  break;
3739 
3740  case ACTRES_SPY_ATTACK: {
3741  bool found;
3742 
3743  if (!omniscient
3744  && !can_player_see_hypotetic_units_at(actor_player, target_tile)) {
3745  // May have a hidden diplomatic defender.
3746  return TRI_MAYBE;
3747  }
3748 
3749  found = false;
3750  unit_list_iterate(target_tile->units, punit)
3751  {
3752  struct player *uplayer = unit_owner(punit);
3753 
3754  if (uplayer == actor_player) {
3755  // Won't defend against its owner.
3756  continue;
3757  }
3758 
3759  if (unit_has_type_flag(punit, UTYF_SUPERSPY)) {
3760  /* This unbeatable diplomatic defender will defend before any
3761  * that can be beaten. */
3762  found = false;
3763  break;
3764  }
3765 
3766  if (unit_has_type_flag(punit, UTYF_DIPLOMAT)) {
3767  // Found a beatable diplomatic defender.
3768  found = true;
3769  break;
3770  }
3771  }
3773 
3774  if (!found) {
3775  return TRI_NO;
3776  }
3777  } break;
3778 
3779  case ACTRES_SPY_SPREAD_PLAGUE:
3780  // Enabling this action with illness_on = FALSE prevents spread.
3781  break;
3782  case ACTRES_ESTABLISH_EMBASSY:
3783  case ACTRES_SPY_INVESTIGATE_CITY:
3784  case ACTRES_SPY_POISON:
3785  case ACTRES_SPY_SABOTAGE_CITY:
3786  case ACTRES_SPY_TARGETED_SABOTAGE_CITY:
3787  case ACTRES_SPY_SABOTAGE_CITY_PRODUCTION:
3788  case ACTRES_SPY_STEAL_TECH:
3789  case ACTRES_SPY_INCITE_CITY:
3790  case ACTRES_SPY_SABOTAGE_UNIT:
3791  case ACTRES_STEAL_MAPS:
3792  case ACTRES_SPY_NUKE:
3793  case ACTRES_NUKE:
3794  case ACTRES_NUKE_CITY:
3795  case ACTRES_DESTROY_CITY:
3796  case ACTRES_EXPEL_UNIT:
3797  case ACTRES_DISBAND_UNIT:
3798  case ACTRES_CONVERT:
3799  case ACTRES_STRIKE_BUILDING:
3800  case ACTRES_STRIKE_PRODUCTION:
3801  case ACTRES_FORTIFY:
3802  case ACTRES_NONE:
3803  // No known hard coded requirements.
3804  break;
3805  }
3806 
3807  return out;
3808 }
3809 
3813 static bool is_enabler_active(
3814  const struct action_enabler *enabler, const struct player *actor_player,
3815  const struct city *actor_city, const struct impr_type *actor_building,
3816  const struct tile *actor_tile, const struct unit *actor_unit,
3817  const struct unit_type *actor_unittype,
3818  const struct output_type *actor_output,
3819  const struct specialist *actor_specialist,
3820  const struct player *target_player, const struct city *target_city,
3821  const struct impr_type *target_building, const struct tile *target_tile,
3822  const struct unit *target_unit, const struct unit_type *target_unittype,
3823  const struct output_type *target_output,
3824  const struct specialist *target_specialist)
3825 {
3826  return are_reqs_active(actor_player, target_player, actor_city,
3827  actor_building, actor_tile, actor_unit,
3828  actor_unittype, actor_output, actor_specialist,
3829  nullptr, &enabler->actor_reqs, RPT_CERTAIN)
3830  && are_reqs_active(
3831  target_player, actor_player, target_city, target_building,
3832  target_tile, target_unit, target_unittype, target_output,
3833  target_specialist, nullptr, &enabler->target_reqs, RPT_CERTAIN);
3834 }
3835 
3842 static bool is_action_enabled(
3843  const action_id wanted_action, const struct player *actor_player,
3844  const struct city *actor_city, const struct impr_type *actor_building,
3845  const struct tile *actor_tile, const struct unit *actor_unit,
3846  const struct unit_type *actor_unittype,
3847  const struct output_type *actor_output,
3848  const struct specialist *actor_specialist,
3849  const struct player *target_player, const struct city *target_city,
3850  const struct impr_type *target_building, const struct tile *target_tile,
3851  const struct unit *target_unit, const struct unit_type *target_unittype,
3852  const struct output_type *target_output,
3853  const struct specialist *target_specialist,
3854  const struct extra_type *target_extra, const struct city *actor_home)
3855 {
3856  enum fc_tristate possible;
3857 
3858  possible = is_action_possible(
3859  wanted_action, actor_player, actor_city, actor_building, actor_tile,
3860  actor_unit, actor_unittype, actor_output, actor_specialist,
3861  target_player, target_city, target_building, target_tile, target_unit,
3862  target_unittype, target_output, target_specialist, target_extra, true,
3863  actor_home);
3864 
3865  if (possible != TRI_YES) {
3866  // This context is omniscient. Should be yes or no.
3867  fc_assert_msg(possible != TRI_MAYBE,
3868  "Is omniscient, should get yes or no.");
3869 
3870  /* The action enablers are irrelevant since the action it self is
3871  * impossible. */
3872  return false;
3873  }
3874 
3876  enabler)
3877  {
3878  if (is_enabler_active(enabler, actor_player, actor_city, actor_building,
3879  actor_tile, actor_unit, actor_unittype,
3880  actor_output, actor_specialist, target_player,
3881  target_city, target_building, target_tile,
3882  target_unit, target_unittype, target_output,
3883  target_specialist)) {
3884  return true;
3885  }
3886  }
3888 
3889  return false;
3890 }
3891 
3899  const action_id wanted_action, const struct unit *actor_unit,
3900  const struct city *actor_home, const struct tile *actor_tile,
3901  const struct city *target_city)
3902 {
3903  const struct impr_type *target_building;
3904  const struct unit_type *target_utype;
3905 
3906  if (actor_unit == nullptr || target_city == nullptr) {
3907  // Can't do an action when actor or target are missing.
3908  return false;
3909  }
3910 
3912  AAK_UNIT == action_id_get_actor_kind(wanted_action), false,
3913  "Action %s is performed by %s not %s",
3914  action_id_rule_name(wanted_action),
3915  action_actor_kind_name(action_id_get_actor_kind(wanted_action)),
3916  action_actor_kind_name(AAK_UNIT));
3917 
3919  ATK_CITY == action_id_get_target_kind(wanted_action), false,
3920  "Action %s is against %s not %s", action_id_rule_name(wanted_action),
3921  action_target_kind_name(action_id_get_target_kind(wanted_action)),
3922  action_target_kind_name(ATK_CITY));
3923 
3924  fc_assert_ret_val(actor_tile, false);
3925 
3926  if (!unit_can_do_action(actor_unit, wanted_action)) {
3927  // No point in continuing.
3928  return false;
3929  }
3930 
3931  target_building = tgt_city_local_building(target_city);
3932  target_utype = tgt_city_local_utype(target_city);
3933 
3934  return is_action_enabled(
3935  wanted_action, unit_owner(actor_unit), tile_city(actor_tile), nullptr,
3936  actor_tile, actor_unit, unit_type_get(actor_unit), nullptr, nullptr,
3937  city_owner(target_city), target_city, target_building,
3938  city_tile(target_city), nullptr, target_utype, nullptr, nullptr,
3939  nullptr, actor_home);
3940 }
3941 
3949  const struct unit *actor_unit,
3950  const struct city *target_city)
3951 {
3953  wanted_action, actor_unit, unit_home(actor_unit),
3954  unit_tile(actor_unit), target_city);
3955 }
3956 
3964  const action_id wanted_action, const struct unit *actor_unit,
3965  const struct city *actor_home, const struct tile *actor_tile,
3966  const struct unit *target_unit)
3967 {
3968  if (actor_unit == nullptr || target_unit == nullptr) {
3969  // Can't do an action when actor or target are missing.
3970  return false;
3971  }
3972 
3974  AAK_UNIT == action_id_get_actor_kind(wanted_action), false,
3975  "Action %s is performed by %s not %s",
3976  action_id_rule_name(wanted_action),
3977  action_actor_kind_name(action_id_get_actor_kind(wanted_action)),
3978  action_actor_kind_name(AAK_UNIT));
3979 
3981  ATK_UNIT == action_id_get_target_kind(wanted_action), false,
3982  "Action %s is against %s not %s", action_id_rule_name(wanted_action),
3983  action_target_kind_name(action_id_get_target_kind(wanted_action)),
3984  action_target_kind_name(ATK_UNIT));
3985 
3986  fc_assert_ret_val(actor_tile, false);
3987 
3988  if (!unit_can_do_action(actor_unit, wanted_action)) {
3989  // No point in continuing.
3990  return false;
3991  }
3992 
3993  return is_action_enabled(
3994  wanted_action, unit_owner(actor_unit), tile_city(actor_tile), nullptr,
3995  actor_tile, actor_unit, unit_type_get(actor_unit), nullptr, nullptr,
3996  unit_owner(target_unit), tile_city(unit_tile(target_unit)), nullptr,
3997  unit_tile(target_unit), target_unit, unit_type_get(target_unit),
3998  nullptr, nullptr, nullptr, actor_home);
3999 }
4000 
4008  const struct unit *actor_unit,
4009  const struct unit *target_unit)
4010 {
4012  wanted_action, actor_unit, unit_home(actor_unit),
4013  unit_tile(actor_unit), target_unit);
4014 }
4015 
4023  const action_id wanted_action, const struct unit *actor_unit,
4024  const struct city *actor_home, const struct tile *actor_tile,
4025  const struct tile *target_tile)
4026 {
4027  if (actor_unit == nullptr || target_tile == nullptr
4028  || unit_list_size(target_tile->units) == 0) {
4029  // Can't do an action when actor or target are missing.
4030  return false;
4031  }
4032 
4034  AAK_UNIT == action_id_get_actor_kind(wanted_action), false,
4035  "Action %s is performed by %s not %s",
4036  action_id_rule_name(wanted_action),
4037  action_actor_kind_name(action_id_get_actor_kind(wanted_action)),
4038  action_actor_kind_name(AAK_UNIT));
4039 
4041  ATK_UNITS == action_id_get_target_kind(wanted_action), false,
4042  "Action %s is against %s not %s", action_id_rule_name(wanted_action),
4043  action_target_kind_name(action_id_get_target_kind(wanted_action)),
4044  action_target_kind_name(ATK_UNITS));
4045 
4046  fc_assert_ret_val(actor_tile, false);
4047 
4048  if (!unit_can_do_action(actor_unit, wanted_action)) {
4049  // No point in continuing.
4050  return false;
4051  }
4052 
4053  unit_list_iterate(target_tile->units, target_unit)
4054  {
4055  if (!is_action_enabled(
4056  wanted_action, unit_owner(actor_unit), tile_city(actor_tile),
4057  nullptr, actor_tile, actor_unit, unit_type_get(actor_unit),
4058  nullptr, nullptr, unit_owner(target_unit),
4059  tile_city(unit_tile(target_unit)), nullptr,
4060  unit_tile(target_unit), target_unit, unit_type_get(target_unit),
4061  nullptr, nullptr, nullptr, actor_home)) {
4062  // One unit makes it impossible for all units.
4063  return false;
4064  }
4065  }
4067 
4068  // Not impossible for any of the units at the tile.
4069  return true;
4070 }
4071 
4079  const struct unit *actor_unit,
4080  const struct tile *target_tile)
4081 {
4083  wanted_action, actor_unit, unit_home(actor_unit),
4084  unit_tile(actor_unit), target_tile);
4085 }
4086 
4094  const action_id wanted_action, const struct unit *actor_unit,
4095  const struct city *actor_home, const struct tile *actor_tile,
4096  const struct tile *target_tile, const struct extra_type *target_extra)
4097 {
4098  if (actor_unit == nullptr || target_tile == nullptr) {
4099  // Can't do an action when actor or target are missing.
4100  return false;
4101  }
4102 
4104  AAK_UNIT == action_id_get_actor_kind(wanted_action), false,
4105  "Action %s is performed by %s not %s",
4106  action_id_rule_name(wanted_action),
4107  action_actor_kind_name(action_id_get_actor_kind(wanted_action)),
4108  action_actor_kind_name(AAK_UNIT));
4109 
4111  ATK_TILE == action_id_get_target_kind(wanted_action), false,
4112  "Action %s is against %s not %s", action_id_rule_name(wanted_action),
4113  action_target_kind_name(action_id_get_target_kind(wanted_action)),
4114  action_target_kind_name(ATK_TILE));
4115 
4116  fc_assert_ret_val(actor_tile, false);
4117 
4118  if (!unit_can_do_action(actor_unit, wanted_action)) {
4119  // No point in continuing.
4120  return false;
4121  }
4122 
4123  return is_action_enabled(
4124  wanted_action, unit_owner(actor_unit), tile_city(actor_tile), nullptr,
4125  actor_tile, actor_unit, unit_type_get(actor_unit), nullptr, nullptr,
4126  tile_owner(target_tile), tile_city(target_tile), nullptr, target_tile,
4127  nullptr, nullptr, nullptr, nullptr, target_extra, actor_home);
4128 }
4129 
4137  const struct unit *actor_unit,
4138  const struct tile *target_tile,
4139  const struct extra_type *target_extra)
4140 {
4142  wanted_action, actor_unit, unit_home(actor_unit),
4143  unit_tile(actor_unit), target_tile, target_extra);
4144 }
4145 
4154  const action_id wanted_action, const struct unit *actor_unit,
4155  const struct city *actor_home, const struct tile *actor_tile)
4156 {
4157  if (actor_unit == nullptr) {
4158  // Can't do an action when the actor is missing.
4159  return false;
4160  }
4161 
4163  AAK_UNIT == action_id_get_actor_kind(wanted_action), false,
4164  "Action %s is performed by %s not %s",
4165  action_id_rule_name(wanted_action),
4166  action_actor_kind_name(action_id_get_actor_kind(wanted_action)),
4167  action_actor_kind_name(AAK_UNIT));
4168 
4170  ATK_SELF == action_id_get_target_kind(wanted_action), false,
4171  "Action %s is against %s not %s", action_id_rule_name(wanted_action),
4172  action_target_kind_name(action_id_get_target_kind(wanted_action)),
4173  action_target_kind_name(ATK_SELF));
4174 
4175  fc_assert_ret_val(actor_tile, false);
4176 
4177  if (!unit_can_do_action(actor_unit, wanted_action)) {
4178  // No point in continuing.
4179  return false;
4180  }
4181 
4182  return is_action_enabled(
4183  wanted_action, unit_owner(actor_unit), tile_city(actor_tile), nullptr,
4184  actor_tile, actor_unit, unit_type_get(actor_unit), nullptr, nullptr,
4185  nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
4186  nullptr, actor_home);
4187 }
4188 
4197  const struct unit *actor_unit)
4198 {
4199  return is_action_enabled_unit_on_self_full(wanted_action, actor_unit,
4200  unit_home(actor_unit),
4201  unit_tile(actor_unit));
4202 }
4203 
4220 static enum fc_tristate action_enabled_local(
4221  const action_id wanted_action, const struct player *actor_player,
4222  const struct city *actor_city, const struct impr_type *actor_building,
4223  const struct tile *actor_tile, const struct unit *actor_unit,
4224  const struct output_type *actor_output,
4225  const struct specialist *actor_specialist,
4226  const struct player *target_player, const struct city *target_city,
4227  const struct impr_type *target_building, const struct tile *target_tile,
4228  const struct unit *target_unit, const struct output_type *target_output,
4229  const struct specialist *target_specialist)
4230 {
4231  enum fc_tristate current;
4232  enum fc_tristate result;
4233 
4234  result = TRI_NO;
4236  enabler)
4237  {
4238  current = fc_tristate_and(
4239  mke_eval_reqs(actor_player, actor_player, target_player, actor_city,
4240  actor_building, actor_tile, actor_unit, actor_output,
4241  actor_specialist, &enabler->actor_reqs, RPT_CERTAIN),
4242  mke_eval_reqs(actor_player, target_player, actor_player, target_city,
4243  target_building, target_tile, target_unit,
4244  target_output, target_specialist,
4245  &enabler->target_reqs, RPT_CERTAIN));
4246  if (current == TRI_YES) {
4247  return TRI_YES;
4248  } else if (current == TRI_MAYBE) {
4249  result = TRI_MAYBE;
4250  }
4251  }
4253 
4254  return result;
4255 }
4256 
4265  enum effect_type effect_type, const struct player *pow_player,
4266  const struct player *target_player, const struct player *other_player,
4267  const struct city *target_city, const struct impr_type *target_building,
4268  const struct tile *target_tile, const struct unit *target_unit,
4269  const struct output_type *target_output,
4270  const struct specialist *target_specialist)
4271 {
4272  effect_list_iterate(get_effects(effect_type), peffect)
4273  {
4274  if (TRI_MAYBE
4275  == mke_eval_reqs(pow_player, target_player, other_player,
4276  target_city, target_building, target_tile,
4277  target_unit, target_output, target_specialist,
4278  &(peffect->reqs), RPT_CERTAIN)) {
4279  return false;
4280  }
4281  }
4283 
4284  return true;
4285 }
4286 
4290 static enum fc_tristate
4291 tech_can_be_stolen(const struct player *actor_player,
4292  const struct player *target_player)
4293 {
4294  const struct research *actor_research = research_get(actor_player);
4295  const struct research *target_research = research_get(target_player);
4296 
4297  if (actor_research != target_research) {
4298  if (can_see_techs_of_target(actor_player, target_player)) {
4299  advance_iterate(A_FIRST, padvance)
4300  {
4301  Tech_type_id i = advance_number(padvance);
4302 
4303  if (research_invention_state(target_research, i) == TECH_KNOWN
4304  && research_invention_gettable(actor_research, i,
4305  game.info.tech_steal_allow_holes)
4306  && (research_invention_state(actor_research, i) == TECH_UNKNOWN
4307  || (research_invention_state(actor_research, i)
4308  == TECH_PREREQS_KNOWN))) {
4309  return TRI_YES;
4310  }
4311  }
4313  } else {
4314  return TRI_MAYBE;
4315  }
4316  }
4317 
4318  return TRI_NO;
4319 }
4320 
4329 static struct act_prob ap_dipl_battle_win(const struct unit *pattacker,
4330  const struct unit *pdefender)
4331 {
4332  // Keep unconverted until the end to avoid scaling each step
4333  int chance;
4334  struct act_prob out;
4335 
4336  // Superspy always win
4337  if (unit_has_type_flag(pdefender, UTYF_SUPERSPY)) {
4338  // A defending UTYF_SUPERSPY will defeat every possible attacker.
4339  return ACTPROB_IMPOSSIBLE;
4340  }
4341  if (unit_has_type_flag(pattacker, UTYF_SUPERSPY)) {
4342  /* An attacking UTYF_SUPERSPY will defeat every possible defender
4343  * except another UTYF_SUPERSPY. */
4344  return ACTPROB_CERTAIN;
4345  }
4346 
4347  // Base chance is 50%
4348  chance = 50;
4349 
4350  // Spy attack bonus
4351  if (unit_has_type_flag(pattacker, UTYF_SPY)) {
4352  chance += 25;
4353  }
4354 
4355  // Spy defense bonus
4356  if (unit_has_type_flag(pdefender, UTYF_SPY)) {
4357  chance -= 25;
4358  }
4359 
4360  // Veteran attack and defense bonus
4361  {
4362  const struct veteran_level *vatt =
4363  utype_veteran_level(unit_type_get(pattacker), pattacker->veteran);
4364  const struct veteran_level *vdef =
4365  utype_veteran_level(unit_type_get(pdefender), pdefender->veteran);
4366 
4367  chance += vatt->power_fact - vdef->power_fact;
4368  }
4369 
4370  // Defense bonus.
4371  {
4372  if (!is_effect_val_known(EFT_SPY_RESISTANT, unit_owner(pattacker),
4373  tile_owner(pdefender->tile), nullptr,
4374  tile_city(pdefender->tile), nullptr,
4375  pdefender->tile, nullptr, nullptr, nullptr)) {
4376  return ACTPROB_NOT_KNOWN;
4377  }
4378 
4379  // Reduce the chance of an attack by EFT_SPY_RESISTANT percent.
4380  chance -=
4381  chance
4383  nullptr, tile_owner(pdefender->tile), nullptr,
4384  tile_city(pdefender->tile), nullptr, pdefender->tile, nullptr,
4385  nullptr, nullptr, nullptr, nullptr, EFT_SPY_RESISTANT)
4386  / 100;
4387  }
4388 
4389  // Convert to action probability
4390  out.min = std::max(ACTPROB_VAL_MIN, chance * ACTPROB_VAL_1_PCT);
4391  out.max = std::min(ACTPROB_VAL_MAX, chance * ACTPROB_VAL_1_PCT);
4392 
4393  return out;
4394 }
4395 
4401 static struct act_prob ap_diplomat_battle(const struct unit *pattacker,
4402  const struct unit *pvictim,
4403  const struct tile *tgt_tile)
4404 {
4405  struct unit *pdefender;
4406 
4408 
4409  if (!can_player_see_hypotetic_units_at(unit_owner(pattacker), tgt_tile)) {
4410  // Don't leak information about unseen defenders.
4411  return ACTPROB_NOT_KNOWN;
4412  }
4413 
4414  pdefender = get_diplomatic_defender(pattacker, pvictim, tgt_tile);
4415 
4416  if (pdefender) {
4417  // There will be a diplomatic battle in stead of an action.
4418  return ap_dipl_battle_win(pattacker, pdefender);
4419  };
4420 
4421  // No diplomatic battle will occur.
4422  return ACTPROB_CERTAIN;
4423 }
4424 
4428 static struct act_prob act_prob_unseen_target(action_id act_id,
4429  const struct unit *actor_unit)
4430 {
4431  if (action_maybe_possible_actor_unit(act_id, actor_unit)) {
4432  // Unknown because the target is unseen.
4433  return ACTPROB_NOT_KNOWN;
4434  } else {
4435  // The actor it self can't do this.
4436  return ACTPROB_IMPOSSIBLE;
4437  }
4438 }
4439 
4448 static struct act_prob action_prob(
4449  const action_id wanted_action, const struct player *actor_player,
4450  const struct city *actor_city, const struct impr_type *actor_building,
4451  const struct tile *actor_tile, const struct unit *actor_unit,
4452  const struct unit_type *actor_unittype_p,
4453  const struct output_type *actor_output,
4454  const struct specialist *actor_specialist, const struct city *actor_home,
4455  const struct player *target_player, const struct city *target_city,
4456  const struct impr_type *target_building, const struct tile *target_tile,
4457  const struct unit *target_unit,
4458  const struct unit_type *target_unittype_p,
4459  const struct output_type *target_output,
4460  const struct specialist *target_specialist,
4461  const struct extra_type *target_extra)
4462 {
4463  int known;
4464  struct act_prob chance;
4465  const struct unit_type *actor_unittype;
4466  const struct unit_type *target_unittype;
4467 
4468  const struct action *paction = action_by_number(wanted_action);
4469 
4470  if (actor_unittype_p == nullptr && actor_unit != nullptr) {
4471  actor_unittype = unit_type_get(actor_unit);
4472  } else {
4473  actor_unittype = actor_unittype_p;
4474  }
4475 
4476  if (target_unittype_p == nullptr && target_unit != nullptr) {
4477  target_unittype = unit_type_get(target_unit);
4478  } else {
4479  target_unittype = target_unittype_p;
4480  }
4481 
4482  known = is_action_possible(
4483  wanted_action, actor_player, actor_city, actor_building, actor_tile,
4484  actor_unit, actor_unittype, actor_output, actor_specialist,
4485  target_player, target_city, target_building, target_tile, target_unit,
4486  target_unittype, target_output, target_specialist, target_extra, false,
4487  actor_home);
4488 
4489  if (known == TRI_NO) {
4490  /* The action enablers are irrelevant since the action it self is
4491  * impossible. */
4492  return ACTPROB_IMPOSSIBLE;
4493  }
4494 
4495  chance = ACTPROB_NOT_IMPLEMENTED;
4496 
4497  known = fc_tristate_and(
4498  BOOL_TO_TRISTATE(known),
4499  action_enabled_local(wanted_action, actor_player, actor_city,
4500  actor_building, actor_tile, actor_unit,
4501  actor_output, actor_specialist, target_player,
4502  target_city, target_building, target_tile,
4503  target_unit, target_output, target_specialist));
4504 
4505  switch (paction->result) {
4506  case ACTRES_SPY_POISON:
4507  // All uncertainty comes from potential diplomatic battles.
4508  chance = ap_diplomat_battle(actor_unit, nullptr, target_tile);
4509  break;
4510  case ACTRES_SPY_STEAL_GOLD:
4511  // TODO
4512  break;
4513  case ACTRES_SPY_SPREAD_PLAGUE:
4514  // TODO
4515  break;
4516  case ACTRES_STEAL_MAPS:
4517  // TODO
4518  break;
4519  case ACTRES_SPY_SABOTAGE_UNIT:
4520  // All uncertainty comes from potential diplomatic battles.
4521  chance = ap_diplomat_battle(actor_unit, target_unit, target_tile);
4522  break;
4523  case ACTRES_SPY_BRIBE_UNIT:
4524  // All uncertainty comes from potential diplomatic battles.
4525  chance = ap_diplomat_battle(actor_unit, target_unit, target_tile);
4526  break;
4527  case ACTRES_SPY_ATTACK:
4528  // All uncertainty comes from potential diplomatic battles.
4529  chance = ap_diplomat_battle(actor_unit, nullptr, target_tile);
4530  break;
4531  case ACTRES_SPY_SABOTAGE_CITY:
4532  // TODO
4533  break;
4534  case ACTRES_SPY_TARGETED_SABOTAGE_CITY:
4535  // TODO
4536  break;
4537  case ACTRES_SPY_SABOTAGE_CITY_PRODUCTION:
4538  // TODO
4539  break;
4540  case ACTRES_SPY_INCITE_CITY:
4541  // TODO
4542  break;
4543  case ACTRES_ESTABLISH_EMBASSY:
4544  chance = ACTPROB_CERTAIN;
4545  break;
4546  case ACTRES_SPY_STEAL_TECH:
4547  // Do the victim have anything worth taking?
4548  known = fc_tristate_and(BOOL_TO_TRISTATE(known),
4549  tech_can_be_stolen(actor_player, target_player));
4550 
4551  // TODO: Calculate actual chance
4552 
4553  break;
4554  case ACTRES_SPY_TARGETED_STEAL_TECH:
4555  // Do the victim have anything worth taking?
4556  known = fc_tristate_and(BOOL_TO_TRISTATE(known),
4557  tech_can_be_stolen(actor_player, target_player));
4558 
4559  // TODO: Calculate actual chance
4560 
4561  break;
4562  case ACTRES_SPY_INVESTIGATE_CITY:
4563  // There is no risk that the city won't get investigated.
4564  chance = ACTPROB_CERTAIN;
4565  break;
4566  case ACTRES_TRADE_ROUTE:
4567  // TODO
4568  break;
4569  case ACTRES_MARKETPLACE:
4570  // Possible when not blocked by is_action_possible()
4571  chance = ACTPROB_CERTAIN;
4572  break;
4573  case ACTRES_HELP_WONDER:
4574  // Possible when not blocked by is_action_possible()
4575  chance = ACTPROB_CERTAIN;
4576  break;
4577  case ACTRES_CAPTURE_UNITS:
4578  // No battle is fought first.
4579  chance = ACTPROB_CERTAIN;
4580  break;
4581  case ACTRES_EXPEL_UNIT:
4582  // No battle is fought first.
4583  chance = ACTPROB_CERTAIN;
4584  break;
4585  case ACTRES_BOMBARD:
4586  // No battle is fought first.
4587  chance = ACTPROB_CERTAIN;
4588  break;
4589  case ACTRES_FOUND_CITY:
4590  // Possible when not blocked by is_action_possible()
4591  chance = ACTPROB_CERTAIN;
4592  break;
4593  case ACTRES_JOIN_CITY:
4594  // Possible when not blocked by is_action_possible()
4595  chance = ACTPROB_CERTAIN;
4596  break;
4597  case ACTRES_SPY_NUKE:
4598  /* TODO: not implemented yet because:
4599  * - possible diplomatic battle could be handled with
4600  * ap_diplomat_battle() so not a problem.
4601  * - dice roll diplchance * Action_Odds_Pct has no action probability
4602  * calculation function yet. */
4603  break;
4604  case ACTRES_NUKE:
4605  // TODO
4606  break;
4607  case ACTRES_NUKE_CITY:
4608  // TODO
4609  break;
4610  case ACTRES_NUKE_UNITS:
4611  // TODO
4612  break;
4613  case ACTRES_DESTROY_CITY:
4614  // No battle is fought first.
4615  chance = ACTPROB_CERTAIN;
4616  break;
4617  case ACTRES_RECYCLE_UNIT:
4618  // No battle is fought first.
4619  chance = ACTPROB_CERTAIN;
4620  break;
4621  case ACTRES_DISBAND_UNIT:
4622  // No battle is fought first.
4623  chance = ACTPROB_CERTAIN;
4624  break;
4625  case ACTRES_HOME_CITY:
4626  // No battle is fought first.
4627  chance = ACTPROB_CERTAIN;
4628  break;
4629  case ACTRES_UPGRADE_UNIT:
4630  // No battle is fought first.
4631  chance = ACTPROB_CERTAIN;
4632  break;
4633  case ACTRES_PARADROP:
4634  // TODO
4635  break;
4636  case ACTRES_AIRLIFT:
4637  // Possible when not blocked by is_action_possible()
4638  chance = ACTPROB_CERTAIN;
4639  break;
4640  case ACTRES_ATTACK: {
4641  struct unit *defender_unit = get_defender(actor_unit, target_tile);
4642 
4643  if (can_player_see_unit(actor_player, defender_unit)) {
4644  double unconverted = unit_win_chance(actor_unit, defender_unit);
4645 
4646  chance.min = MAX(ACTPROB_VAL_MIN,
4647  floor((double) ACTPROB_VAL_MAX * unconverted));
4648  chance.max =
4649  MIN(ACTPROB_VAL_MAX, ceil((double) ACTPROB_VAL_MAX * unconverted));
4650  } else if (known == TRI_YES) {
4651  known = TRI_MAYBE;
4652  }
4653  } break;
4654  case ACTRES_STRIKE_BUILDING:
4655  /* TODO: not implemented yet because:
4656  * - dice roll 100% * Action_Odds_Pct has no action probability
4657  * calculation function yet.
4658  * - sub target building may be missing. May be missing without player
4659  * knowledge if it isn't visible. See is_improvement_visible() and
4660  * can_player_see_city_internals(). */
4661  break;
4662  case ACTRES_STRIKE_PRODUCTION:
4663  /* TODO: not implemented yet because:
4664  * - dice roll 100% * Action_Odds_Pct has no action probability
4665  * calculation function yet. */
4666  break;
4667  case ACTRES_CONQUER_CITY:
4668  // No battle is fought first.
4669  chance = ACTPROB_CERTAIN;
4670  break;
4671  case ACTRES_HEAL_UNIT:
4672  // No battle is fought first.
4673  chance = ACTPROB_CERTAIN;
4674  break;
4675  case ACTRES_TRANSFORM_TERRAIN:
4676  case ACTRES_CULTIVATE:
4677  case ACTRES_PLANT:
4678  case ACTRES_PILLAGE:
4679  case ACTRES_CLEAN_POLLUTION:
4680  case ACTRES_CLEAN_FALLOUT:
4681  case ACTRES_FORTIFY:
4682  case ACTRES_ROAD:
4683  case ACTRES_CONVERT:
4684  case ACTRES_BASE:
4685  case ACTRES_MINE:
4686  case ACTRES_IRRIGATE:
4687  chance = ACTPROB_CERTAIN;
4688  break;
4689  case ACTRES_TRANSPORT_ALIGHT:
4690  chance = ACTPROB_CERTAIN;
4691  break;
4692  case ACTRES_TRANSPORT_BOARD:
4693  chance = ACTPROB_CERTAIN;
4694  break;
4695  case ACTRES_TRANSPORT_EMBARK:
4696  chance = ACTPROB_CERTAIN;
4697  break;
4698  case ACTRES_TRANSPORT_UNLOAD:
4699  chance = ACTPROB_CERTAIN;
4700  break;
4701  case ACTRES_TRANSPORT_DISEMBARK:
4702  chance = ACTPROB_CERTAIN;
4703  break;
4704  case ACTRES_NONE:
4705  /* Accommodate ruleset authors that wishes to roll the dice in Lua.
4706  * Would be ACTPROB_CERTAIN if not for that. */
4707  /* TODO: maybe allow the ruleset author to give a probability from
4708  * Lua? */
4709  chance = ACTPROB_NOT_IMPLEMENTED;
4710  break;
4711  }
4712 
4713  // Non signal action probabilities should be in range.
4715  (action_prob_is_signal(chance) || chance.max <= ACTPROB_VAL_MAX),
4716  chance.max = ACTPROB_VAL_MAX);
4718  (action_prob_is_signal(chance) || chance.min >= ACTPROB_VAL_MIN),
4719  chance.min = ACTPROB_VAL_MIN);
4720 
4721  switch (known) {
4722  case TRI_NO:
4723  return ACTPROB_IMPOSSIBLE;
4724  break;
4725  case TRI_MAYBE:
4726  return ACTPROB_NOT_KNOWN;
4727  break;
4728  case TRI_YES:
4729  return chance;
4730  break;
4731  };
4732 
4733  fc_assert_msg(false, "Should be yes, maybe or no");
4734  return ACTPROB_NOT_IMPLEMENTED;
4735 }
4736 
4741 static struct act_prob action_prob_vs_city_full(
4742  const struct unit *actor_unit, const struct city *actor_home,
4743  const struct tile *actor_tile, const action_id act_id,
4744  const struct city *target_city)
4745 {
4746  const struct impr_type *target_building;
4747  const struct unit_type *target_utype;
4748 
4749  if (actor_unit == nullptr || target_city == nullptr) {
4750  // Can't do an action when actor or target are missing.
4751  return ACTPROB_IMPOSSIBLE;
4752  }
4753 
4755  AAK_UNIT == action_id_get_actor_kind(act_id), ACTPROB_IMPOSSIBLE,
4756  "Action %s is performed by %s not %s", action_id_rule_name(act_id),
4757  action_actor_kind_name(action_id_get_actor_kind(act_id)),
4758  action_actor_kind_name(AAK_UNIT));
4759 
4761  ATK_CITY == action_id_get_target_kind(act_id), ACTPROB_IMPOSSIBLE,
4762  "Action %s is against %s not %s", action_id_rule_name(act_id),
4763  action_target_kind_name(action_id_get_target_kind(act_id)),
4764  action_target_kind_name(ATK_CITY));
4765 
4767 
4768  if (!unit_can_do_action(actor_unit, act_id)) {
4769  // No point in continuing.
4770  return ACTPROB_IMPOSSIBLE;
4771  }
4772 
4773  /* Doesn't leak information about city position since an unknown city
4774  * can't be targeted and a city can't move. */
4776  act_id, real_map_distance(actor_tile, city_tile(target_city)))) {
4777  // No point in continuing.
4778  return ACTPROB_IMPOSSIBLE;
4779  }
4780 
4781  /* Doesn't leak information since it must be 100% certain from the
4782  * player's perspective that the blocking action is legal. */
4783  if (action_is_blocked_by(act_id, actor_unit, city_tile(target_city),
4784  target_city, nullptr)) {
4785  // Don't offer to perform an action known to be blocked.
4786  return ACTPROB_IMPOSSIBLE;
4787  }
4788 
4789  if (!player_can_see_city_externals(unit_owner(actor_unit), target_city)) {
4790  /* The invisible city at this tile may, as far as the player knows, not
4791  * exist anymore. */
4792  return act_prob_unseen_target(act_id, actor_unit);
4793  }
4794 
4795  target_building = tgt_city_local_building(target_city);
4796  target_utype = tgt_city_local_utype(target_city);
4797 
4798  return action_prob(act_id, unit_owner(actor_unit), tile_city(actor_tile),
4799  nullptr, actor_tile, actor_unit, nullptr, nullptr,
4800  nullptr, actor_home, city_owner(target_city),
4801  target_city, target_building, city_tile(target_city),
4802  nullptr, target_utype, nullptr, nullptr, nullptr);
4803 }
4804 
4809 struct act_prob action_prob_vs_city(const struct unit *actor_unit,
4810  const action_id act_id,
4811  const struct city *target_city)
4812 {
4813  return action_prob_vs_city_full(actor_unit, unit_home(actor_unit),
4814  unit_tile(actor_unit), act_id,
4815  target_city);
4816 }
4817 
4822 static struct act_prob action_prob_vs_unit_full(
4823  const struct unit *actor_unit, const struct city *actor_home,
4824  const struct tile *actor_tile, const action_id act_id,
4825  const struct unit *target_unit)
4826 {
4827  if (actor_unit == nullptr || target_unit == nullptr) {
4828  // Can't do an action when actor or target are missing.
4829  return ACTPROB_IMPOSSIBLE;
4830  }
4831 
4833  AAK_UNIT == action_id_get_actor_kind(act_id), ACTPROB_IMPOSSIBLE,
4834  "Action %s is performed by %s not %s", action_id_rule_name(act_id),
4835  action_actor_kind_name(action_id_get_actor_kind(act_id)),
4836  action_actor_kind_name(AAK_UNIT));
4837 
4839  ATK_UNIT == action_id_get_target_kind(act_id), ACTPROB_IMPOSSIBLE,
4840  "Action %s is against %s not %s", action_id_rule_name(act_id),
4841  action_target_kind_name(action_id_get_target_kind(act_id)),
4842  action_target_kind_name(ATK_UNIT));
4843 
4845 
4846  if (!unit_can_do_action(actor_unit, act_id)) {
4847  // No point in continuing.
4848  return ACTPROB_IMPOSSIBLE;
4849  }
4850 
4851  /* Doesn't leak information about unit position since an unseen unit can't
4852  * be targeted. */
4854  act_id, real_map_distance(actor_tile, unit_tile(target_unit)))) {
4855  // No point in continuing.
4856  return ACTPROB_IMPOSSIBLE;
4857  }
4858 
4859  return action_prob(act_id, unit_owner(actor_unit), tile_city(actor_tile),
4860  nullptr, actor_tile, actor_unit, nullptr, nullptr,
4861  nullptr, actor_home, unit_owner(target_unit),
4862  tile_city(unit_tile(target_unit)), nullptr,
4863  unit_tile(target_unit), target_unit, nullptr, nullptr,
4864  nullptr, nullptr);
4865 }
4866 
4871 struct act_prob action_prob_vs_unit(const struct unit *actor_unit,
4872  const action_id act_id,
4873  const struct unit *target_unit)
4874 {
4875  return action_prob_vs_unit_full(actor_unit, unit_home(actor_unit),
4876  unit_tile(actor_unit), act_id,
4877  target_unit);
4878 }
4879 
4884 static struct act_prob action_prob_vs_units_full(
4885  const struct unit *actor_unit, const struct city *actor_home,
4886  const struct tile *actor_tile, const action_id act_id,
4887  const struct tile *target_tile)
4888 {
4889  struct act_prob prob_all;
4890 
4891  if (actor_unit == nullptr || target_tile == nullptr) {
4892  // Can't do an action when actor or target are missing.
4893  return ACTPROB_IMPOSSIBLE;
4894  }
4895 
4897  AAK_UNIT == action_id_get_actor_kind(act_id), ACTPROB_IMPOSSIBLE,
4898  "Action %s is performed by %s not %s", action_id_rule_name(act_id),
4899  action_actor_kind_name(action_id_get_actor_kind(act_id)),
4900  action_actor_kind_name(AAK_UNIT));
4901 
4903  ATK_UNITS == action_id_get_target_kind(act_id), ACTPROB_IMPOSSIBLE,
4904  "Action %s is against %s not %s", action_id_rule_name(act_id),
4905  action_target_kind_name(action_id_get_target_kind(act_id)),
4906  action_target_kind_name(ATK_UNITS));
4907 
4909 
4910  if (!unit_can_do_action(actor_unit, act_id)) {
4911  // No point in continuing.
4912  return ACTPROB_IMPOSSIBLE;
4913  }
4914 
4915  /* Doesn't leak information about unit stack position since it is
4916  * specified as a tile and an unknown tile's position is known. */
4918  act_id, real_map_distance(actor_tile, target_tile))) {
4919  // No point in continuing.
4920  return ACTPROB_IMPOSSIBLE;
4921  }
4922 
4923  /* Doesn't leak information since the actor player can see the target
4924  * tile. */
4925  if (tile_is_seen(target_tile, unit_owner(actor_unit))
4926  && tile_city(target_tile) != nullptr
4927  && !utype_can_do_act_if_tgt_citytile(unit_type_get(actor_unit), act_id,
4928  CITYT_CENTER, true)) {
4929  /* Don't offer to perform actions that never can target a unit stack in
4930  * a city. */
4931  return ACTPROB_IMPOSSIBLE;
4932  }
4933 
4934  /* Doesn't leak information since it must be 100% certain from the
4935  * player's perspective that the blocking action is legal. */
4936  unit_list_iterate(target_tile->units, target_unit)
4937  {
4938  if (action_is_blocked_by(act_id, actor_unit, target_tile,
4939  tile_city(target_tile), target_unit)) {
4940  // Don't offer to perform an action known to be blocked.
4941  return ACTPROB_IMPOSSIBLE;
4942  }
4943  }
4945 
4946  /* Must be done here since an empty unseen tile will result in
4947  * ACTPROB_IMPOSSIBLE. */
4948  if (unit_list_size(target_tile->units) == 0) {
4949  // Can't act against an empty tile.
4950 
4952  target_tile)) {
4953  // Known empty tile.
4954  return ACTPROB_IMPOSSIBLE;
4955  } else {
4956  // The player doesn't know that the tile is empty.
4957  return act_prob_unseen_target(act_id, actor_unit);
4958  }
4959  }
4960 
4961  if ((action_id_has_result_safe(act_id, ACTRES_ATTACK)
4962  || action_id_has_result_safe(act_id, ACTRES_BOMBARD))
4963  && tile_city(target_tile) != nullptr
4964  && !pplayers_at_war(city_owner(tile_city(target_tile)),
4965  unit_owner(actor_unit))) {
4966  /* Hard coded rule: can't "Bombard", "Suicide Attack", or "Attack"
4967  * units in non enemy cities. */
4968  return ACTPROB_IMPOSSIBLE;
4969  }
4970 
4971  /* Invisible units at this tile can make the action legal or illegal.
4972  * Invisible units can be stacked with visible units. The possible
4973  * existence of invisible units therefore makes the result uncertain. */
4974  prob_all =
4975  (can_player_see_hypotetic_units_at(unit_owner(actor_unit), target_tile)
4976  ? ACTPROB_CERTAIN
4977  : ACTPROB_NOT_KNOWN);
4978 
4979  unit_list_iterate(target_tile->units, target_unit)
4980  {
4981  struct act_prob prob_unit;
4982 
4983  if (!can_player_see_unit(unit_owner(actor_unit), target_unit)) {
4984  /* Only visible units are considered. The invisible units contributed
4985  * their uncertainty to prob_all above. */
4986  continue;
4987  }
4988 
4989  prob_unit = action_prob(
4990  act_id, unit_owner(actor_unit), tile_city(actor_tile), nullptr,
4991  actor_tile, actor_unit, nullptr, nullptr, nullptr, actor_home,
4992  unit_owner(target_unit), tile_city(unit_tile(target_unit)), nullptr,
4993  unit_tile(target_unit), target_unit, nullptr, nullptr, nullptr,
4994  nullptr);
4995 
4996  if (!action_prob_possible(prob_unit)) {
4997  // One unit makes it impossible for all units.
4998  return ACTPROB_IMPOSSIBLE;
4999  } else if (action_prob_not_impl(prob_unit)) {
5000  // Not implemented dominates all except impossible.
5001  prob_all = ACTPROB_NOT_IMPLEMENTED;
5002  } else {
5004  "Invalid probability [%d, %d]", prob_unit.min,
5005  prob_unit.max);
5006 
5007  if (action_prob_is_signal(prob_all)) {
5008  // Special values dominate regular values.
5009  continue;
5010  }
5011 
5012  /* Probability against all target units considered until this moment
5013  * and the probability against this target unit. */
5014  prob_all.min = (prob_all.min * prob_unit.min) / ACTPROB_VAL_MAX;
5015  prob_all.max = (prob_all.max * prob_unit.max) / ACTPROB_VAL_MAX;
5016  break;
5017  }
5018  }
5020 
5021  // Not impossible for any of the units at the tile.
5022  return prob_all;
5023 }
5024 
5029 struct act_prob action_prob_vs_units(const struct unit *actor_unit,
5030  const action_id act_id,
5031  const struct tile *target_tile)
5032 {
5033  return action_prob_vs_units_full(actor_unit, unit_home(actor_unit),
5034  unit_tile(actor_unit), act_id,
5035  target_tile);
5036 }
5037 
5042 static struct act_prob action_prob_vs_tile_full(
5043  const struct unit *actor_unit, const struct city *actor_home,
5044  const struct tile *actor_tile, const action_id act_id,
5045  const struct tile *target_tile, const struct extra_type *target_extra)
5046 {
5047  if (actor_unit == nullptr || target_tile == nullptr) {
5048  // Can't do an action when actor or target are missing.
5049  return ACTPROB_IMPOSSIBLE;
5050  }
5051 
5053  AAK_UNIT == action_id_get_actor_kind(act_id), ACTPROB_IMPOSSIBLE,
5054  "Action %s is performed by %s not %s", action_id_rule_name(act_id),
5055  action_actor_kind_name(action_id_get_actor_kind(act_id)),
5056  action_actor_kind_name(AAK_UNIT));
5057 
5059  ATK_TILE == action_id_get_target_kind(act_id), ACTPROB_IMPOSSIBLE,
5060  "Action %s is against %s not %s", action_id_rule_name(act_id),
5061  action_target_kind_name(action_id_get_target_kind(act_id)),
5062  action_target_kind_name(ATK_TILE));
5063 
5065 
5066  if (!unit_can_do_action(actor_unit, act_id)) {
5067  // No point in continuing.
5068  return ACTPROB_IMPOSSIBLE;
5069  }
5070 
5071  /* Doesn't leak information about tile position since an unknown tile's
5072  * position is known. */
5074  act_id, real_map_distance(actor_tile, target_tile))) {
5075  // No point in continuing.
5076  return ACTPROB_IMPOSSIBLE;
5077  }
5078 
5079  return action_prob(act_id, unit_owner(actor_unit), tile_city(actor_tile),
5080  nullptr, actor_tile, actor_unit, nullptr, nullptr,
5081  nullptr, actor_home, tile_owner(target_tile),
5082  tile_city(target_tile), nullptr, target_tile, nullptr,
5083  nullptr, nullptr, nullptr, target_extra);
5084 }
5085 
5090 struct act_prob action_prob_vs_tile(const struct unit *actor_unit,
5091  const action_id act_id,
5092  const struct tile *target_tile,
5093  const struct extra_type *target_extra)
5094 {
5095  return action_prob_vs_tile_full(actor_unit, unit_home(actor_unit),
5096  unit_tile(actor_unit), act_id, target_tile,
5097  target_extra);
5098 }
5099 
5104 static struct act_prob action_prob_self_full(const struct unit *actor_unit,
5105  const struct city *actor_home,
5106  const struct tile *actor_tile,
5107  const action_id act_id)
5108 {
5109  if (actor_unit == nullptr) {
5110  // Can't do the action when the actor is missing.
5111  return ACTPROB_IMPOSSIBLE;
5112  }
5113 
5114  // No point in checking distance to target. It is always 0.
5115 
5117  AAK_UNIT == action_id_get_actor_kind(act_id), ACTPROB_IMPOSSIBLE,
5118  "Action %s is performed by %s not %s", action_id_rule_name(act_id),
5119  action_actor_kind_name(action_id_get_actor_kind(act_id)),
5120  action_actor_kind_name(AAK_UNIT));
5121 
5123  ATK_SELF == action_id_get_target_kind(act_id), ACTPROB_IMPOSSIBLE,
5124  "Action %s is against %s not %s", action_id_rule_name(act_id),
5125  action_target_kind_name(action_id_get_target_kind(act_id)),
5126  action_target_kind_name(ATK_SELF));
5127 
5129 
5130  if (!unit_can_do_action(actor_unit, act_id)) {
5131  // No point in continuing.
5132  return ACTPROB_IMPOSSIBLE;
5133  }
5134 
5135  return action_prob(act_id, unit_owner(actor_unit), tile_city(actor_tile),
5136  nullptr, actor_tile, actor_unit, nullptr, nullptr,
5137  nullptr, actor_home, nullptr, nullptr, nullptr, nullptr,
5138  nullptr, nullptr, nullptr, nullptr, nullptr);
5139 }
5140 
5145 struct act_prob action_prob_self(const struct unit *actor_unit,
5146  const action_id act_id)
5147 {
5148  return action_prob_self_full(actor_unit, unit_home(actor_unit),
5149  unit_tile(actor_unit), act_id);
5150 }
5151 
5163 struct act_prob action_prob_unit_vs_tgt(const struct action *paction,
5164  const struct unit *act_unit,
5165  const struct city *tgt_city,
5166  const struct unit *tgt_unit,
5167  const struct tile *tgt_tile,
5168  const struct extra_type *extra_tgt)
5169 {
5170  // Assume impossible until told otherwise.
5171  struct act_prob prob = ACTPROB_IMPOSSIBLE;
5172 
5175 
5176  switch (action_get_target_kind(paction)) {
5177  case ATK_UNITS:
5178  if (tgt_tile) {
5179  prob = action_prob_vs_units(act_unit, paction->id, tgt_tile);
5180  }
5181  break;
5182  case ATK_TILE:
5183  if (tgt_tile) {
5184  prob = action_prob_vs_tile(act_unit, paction->id, tgt_tile, extra_tgt);
5185  }
5186  break;
5187  case ATK_CITY:
5188  if (tgt_city) {
5189  prob = action_prob_vs_city(act_unit, paction->id, tgt_city);
5190  }
5191  break;
5192  case ATK_UNIT:
5193  if (tgt_unit) {
5194  prob = action_prob_vs_unit(act_unit, paction->id, tgt_unit);
5195  }
5196  break;
5197  case ATK_SELF:
5198  prob = action_prob_self(act_unit, paction->id);
5199  break;
5200  case ATK_COUNT:
5201  qCritical("Invalid action target kind");
5202  break;
5203  }
5204 
5205  return prob;
5206 }
5207 
5214  const struct unit *actor,
5215  const struct city *actor_home,
5216  const struct tile *actor_tile,
5217  const bool omniscient_cheat,
5218  const struct city *target)
5219 {
5220  /* FIXME: some unit state requirements still depend on the actor unit's
5221  * current position rather than on actor_tile. Maybe this function should
5222  * return ACTPROB_NOT_IMPLEMENTED when one of those is detected and no
5223  * other requirement makes the action ACTPROB_IMPOSSIBLE? */
5224 
5225  if (omniscient_cheat) {
5226  if (is_action_enabled_unit_on_city_full(act_id, actor, actor_home,
5227  actor_tile, target)) {
5228  return ACTPROB_CERTAIN;
5229  } else {
5230  return ACTPROB_IMPOSSIBLE;
5231  }
5232  } else {
5233  return action_prob_vs_city_full(actor, actor_home, actor_tile, act_id,
5234  target);
5235  }
5236 }
5237 
5244  const struct unit *actor,
5245  const struct city *actor_home,
5246  const struct tile *actor_tile,
5247  bool omniscient_cheat,
5248  const struct tile *target)
5249 {
5250  /* FIXME: some unit state requirements still depend on the actor unit's
5251  * current position rather than on actor_tile. Maybe this function should
5252  * return ACTPROB_NOT_IMPLEMENTED when one of those is detected and no
5253  * other requirement makes the action ACTPROB_IMPOSSIBLE? */
5254 
5255  if (omniscient_cheat) {
5256  if (is_action_enabled_unit_on_units_full(act_id, actor, actor_home,
5257  actor_tile, target)) {
5258  return ACTPROB_CERTAIN;
5259  } else {
5260  return ACTPROB_IMPOSSIBLE;
5261  }
5262  } else {
5263  return action_prob_vs_units_full(actor, actor_home, actor_tile, act_id,
5264  target);
5265  }
5266 }
5267 
5274  action_id act_id, const struct unit *actor,
5275  const struct city *actor_home, const struct tile *actor_tile,
5276  bool omniscient_cheat, const struct tile *target_tile,
5277  const struct extra_type *target_extra)
5278 {
5279  /* FIXME: some unit state requirements still depend on the actor unit's
5280  * current position rather than on actor_tile. Maybe this function should
5281  * return ACTPROB_NOT_IMPLEMENTED when one of those is detected and no
5282  * other requirement makes the action ACTPROB_IMPOSSIBLE? */
5283 
5284  if (omniscient_cheat) {
5285  if (is_action_enabled_unit_on_tile_full(act_id, actor, actor_home,
5286  actor_tile, target_tile,
5287  target_extra)) {
5288  return ACTPROB_CERTAIN;
5289  } else {
5290  return ACTPROB_IMPOSSIBLE;
5291  }
5292  } else {
5293  return action_prob_vs_tile_full(actor, actor_home, actor_tile, act_id,
5294  target_tile, target_extra);
5295  }
5296 }
5297 
5304  const struct unit *actor,
5305  const struct city *actor_home,
5306  const struct tile *actor_tile,
5307  bool omniscient_cheat)
5308 {
5309  /* FIXME: some unit state requirements still depend on the actor unit's
5310  * current position rather than on actor_tile. Maybe this function should
5311  * return ACTPROB_NOT_IMPLEMENTED when one of those is detected and no
5312  * other requirement makes the action ACTPROB_IMPOSSIBLE? */
5313 
5314  if (omniscient_cheat) {
5315  if (is_action_enabled_unit_on_self_full(act_id, actor, actor_home,
5316  actor_tile)) {
5317  return ACTPROB_CERTAIN;
5318  } else {
5319  return ACTPROB_IMPOSSIBLE;
5320  }
5321  } else {
5322  return action_prob_self_full(actor, actor_home, actor_tile, act_id);
5323  }
5324 }
5325 
5330 {
5331  struct act_prob out = {ACTPROB_VAL_MIN, ACTPROB_VAL_MIN};
5332 
5333  return out;
5334 }
5335 
5340 {
5341  struct act_prob out = {ACTPROB_VAL_MAX, ACTPROB_VAL_MAX};
5342 
5343  return out;
5344 }
5345 
5350 {
5351  struct act_prob out = {ACTPROB_VAL_NA, ACTPROB_VAL_MIN};
5352 
5353  return out;
5354 }
5355 
5360 {
5362 
5363  return out;
5364 }
5365 
5370 {
5371  struct act_prob out = {ACTPROB_VAL_MIN, ACTPROB_VAL_MAX};
5372 
5373  return out;
5374 }
5375 
5380 bool action_prob_possible(const struct act_prob probability)
5381 {
5382  return (ACTPROB_VAL_MIN < probability.max
5383  || action_prob_not_impl(probability));
5384 }
5385 
5390 static inline bool
5391 action_prob_not_relevant(const struct act_prob probability)
5392 {
5393  return probability.min == ACTPROB_VAL_NA
5394  && probability.max == ACTPROB_VAL_MIN;
5395 }
5396 
5401 static inline bool action_prob_not_impl(const struct act_prob probability)
5402 {
5403  return probability.min == ACTPROB_VAL_NOT_IMPL
5404  && probability.max == ACTPROB_VAL_MIN;
5405 }
5406 
5411 static inline bool action_prob_is_signal(const struct act_prob probability)
5412 {
5413  return probability.max < probability.min;
5414 }
5415 
5420  const struct act_prob *ap2)
5421 {
5422  return ap1->min == ap2->min && ap1->max == ap2->max;
5423 }
5424 
5429  const struct act_prob ap2)
5430 {
5431  struct act_prob my_ap1;
5432  struct act_prob my_ap2;
5433 
5434  // The action probabilities are real.
5437 
5438  // Convert any signals to ACTPROB_NOT_KNOWN.
5439  if (action_prob_is_signal(ap1)) {
5440  // Assert that it is OK to convert the signal.
5442 
5443  my_ap1 = ACTPROB_NOT_KNOWN;
5444  } else {
5445  my_ap1 = ap1;
5446  }
5447 
5448  if (action_prob_is_signal(ap2)) {
5449  // Assert that it is OK to convert the signal.
5451 
5452  my_ap2 = ACTPROB_NOT_KNOWN;
5453  } else {
5454  my_ap2 = ap2;
5455  }
5456 
5457  // The action probabilities now have a comparison friendly form.
5458  fc_assert(!action_prob_is_signal(my_ap1));
5459  fc_assert(!action_prob_is_signal(my_ap2));
5460 
5461  // Do the comparison. Start with min. Continue with max.
5462  if (my_ap1.min < my_ap2.min) {
5463  return -1;
5464  } else if (my_ap1.min > my_ap2.min) {
5465  return 1;
5466  } else if (my_ap1.max < my_ap2.max) {
5467  return -1;
5468  } else if (my_ap1.max > my_ap2.max) {
5469  return 1;
5470  } else {
5471  return 0;
5472  }
5473 }
5474 
5480 {
5481  struct act_prob my_ap;
5482 
5483  // The action probability is real.
5485 
5486  // Convert any signals to ACTPROB_NOT_KNOWN.
5487  if (action_prob_is_signal(ap)) {
5488  // Assert that it is OK to convert the signal.
5490 
5491  my_ap = ACTPROB_NOT_KNOWN;
5492  } else {
5493  my_ap = ap;
5494  }
5495 
5496  // The action probability now has a math friendly form.
5498 
5499  return static_cast<double>(my_ap.min)
5500  / static_cast<double>(ACTPROB_VAL_MAX);
5501 }
5502 
5510 struct act_prob action_prob_fall_back(const struct act_prob *ap1,
5511  const struct act_prob *ap2)
5512 {
5513  struct act_prob my_ap1;
5514  struct act_prob my_ap2;
5515  struct act_prob out;
5516 
5517  // The action probabilities are real.
5518  fc_assert(ap1 && !action_prob_not_relevant(*ap1));
5519  fc_assert(ap2 && !action_prob_not_relevant(*ap2));
5520 
5521  if (action_prob_is_signal(*ap1)
5522  && are_action_probabilitys_equal(ap1, ap2)) {
5523  /* Keep the information rather than converting the signal to
5524  * ACTPROB_NOT_KNOWN. */
5525 
5526  // Assert that it is OK to convert the signal.
5528 
5529  out.min = ap1->min;
5530  out.max = ap2->max;
5531 
5532  return out;
5533  }
5534 
5535  // Convert any signals to ACTPROB_NOT_KNOWN.
5536  if (action_prob_is_signal(*ap1)) {
5537  // Assert that it is OK to convert the signal.
5539 
5540  my_ap1.min = ACTPROB_VAL_MIN;
5541  my_ap1.max = ACTPROB_VAL_MAX;
5542  } else {
5543  my_ap1.min = ap1->min;
5544  my_ap1.max = ap1->max;
5545  }
5546 
5547  if (action_prob_is_signal(*ap2)) {
5548  // Assert that it is OK to convert the signal.
5550 
5551  my_ap2.min = ACTPROB_VAL_MIN;
5552  my_ap2.max = ACTPROB_VAL_MAX;
5553  } else {
5554  my_ap2.min = ap2->min;
5555  my_ap2.max = ap2->max;
5556  }
5557 
5558  // The action probabilities now have a math friendly form.
5559  fc_assert(!action_prob_is_signal(my_ap1));
5560  fc_assert(!action_prob_is_signal(my_ap2));
5561 
5562  // Do the math.
5563  out.min =
5564  my_ap1.min
5565  + (((ACTPROB_VAL_MAX - my_ap1.min) * my_ap2.min) / ACTPROB_VAL_MAX);
5566  out.max =
5567  my_ap1.max
5568  + (((ACTPROB_VAL_MAX - my_ap1.max) * my_ap2.max) / ACTPROB_VAL_MAX);
5569 
5570  // Cap at 100%.
5571  out.min = MIN(out.min, ACTPROB_VAL_MAX);
5572  out.max = MIN(out.max, ACTPROB_VAL_MAX);
5573 
5574  return out;
5575 }
5576 
5580 int action_dice_roll_initial_odds(const struct action *paction)
5581 {
5582  switch (paction->result) {
5583  case ACTRES_STRIKE_BUILDING:
5584  case ACTRES_STRIKE_PRODUCTION:
5585  // No initial odds.
5586  return 100;
5587  case ACTRES_SPY_SPREAD_PLAGUE:
5588  case ACTRES_SPY_STEAL_TECH:
5589  case ACTRES_SPY_TARGETED_STEAL_TECH:
5590  case ACTRES_SPY_INCITE_CITY:
5591  case ACTRES_SPY_SABOTAGE_CITY:
5592  case ACTRES_SPY_TARGETED_SABOTAGE_CITY:
5593  case ACTRES_SPY_SABOTAGE_CITY_PRODUCTION:
5594  case ACTRES_SPY_STEAL_GOLD:
5595  case ACTRES_STEAL_MAPS:
5596  case ACTRES_SPY_NUKE:
5597  // Take the initial odds from the diplchance setting.
5599  server_setting_by_name("diplchance"));
5600  case ACTRES_ESTABLISH_EMBASSY:
5601  case ACTRES_SPY_INVESTIGATE_CITY:
5602  case ACTRES_SPY_POISON:
5603  case ACTRES_TRADE_ROUTE:
5604  case ACTRES_MARKETPLACE:
5605  case ACTRES_HELP_WONDER:
5606  case ACTRES_SPY_BRIBE_UNIT:
5607  case ACTRES_SPY_SABOTAGE_UNIT:
5608  case ACTRES_CAPTURE_UNITS:
5609  case ACTRES_FOUND_CITY:
5610  case ACTRES_JOIN_CITY:
5611  case ACTRES_BOMBARD:
5612  case ACTRES_NUKE:
5613  case ACTRES_NUKE_CITY:
5614  case ACTRES_NUKE_UNITS:
5615  case ACTRES_DESTROY_CITY:
5616  case ACTRES_EXPEL_UNIT:
5617  case ACTRES_RECYCLE_UNIT:
5618  case ACTRES_DISBAND_UNIT:
5619  case ACTRES_HOME_CITY:
5620  case ACTRES_UPGRADE_UNIT:
5621  case ACTRES_PARADROP:
5622  case ACTRES_AIRLIFT:
5623  case ACTRES_ATTACK:
5624  case ACTRES_CONQUER_CITY:
5625  case ACTRES_HEAL_UNIT:
5626  case ACTRES_TRANSFORM_TERRAIN:
5627  case ACTRES_CULTIVATE:
5628  case ACTRES_PLANT:
5629  case ACTRES_PILLAGE:
5630  case ACTRES_CLEAN_POLLUTION:
5631  case ACTRES_CLEAN_FALLOUT:
5632  case ACTRES_FORTIFY:
5633  case ACTRES_ROAD:
5634  case ACTRES_CONVERT:
5635  case ACTRES_BASE:
5636  case ACTRES_MINE:
5637  case ACTRES_IRRIGATE:
5638  case ACTRES_TRANSPORT_ALIGHT:
5639  case ACTRES_TRANSPORT_UNLOAD:
5640  case ACTRES_TRANSPORT_DISEMBARK:
5641  case ACTRES_TRANSPORT_BOARD:
5642  case ACTRES_TRANSPORT_EMBARK:
5643  case ACTRES_SPY_ATTACK:
5644  case ACTRES_NONE:
5645  // No additional dice roll.
5646  break;
5647  }
5648 
5649  /* The odds of the action not being stopped by its dice roll when the dice
5650  * isn't thrown is 100%. ACTION_ODDS_PCT_DICE_ROLL_NA is above 100% */
5652 }
5653 
5657 int action_dice_roll_odds(const struct player *act_player,
5658  const struct unit *act_unit,
5659  const struct city *tgt_city,
5660  const struct player *tgt_player,
5661  const struct action *paction)
5662 {
5663  int odds = action_dice_roll_initial_odds(paction);
5664 
5665  fc_assert_action_msg(odds >= 0 && odds <= 100, odds = 100,
5666  "Bad initial odds for action number %d."
5667  " Does it roll the dice at all?",
5668  paction->id);
5669 
5670  /* Let the Action_Odds_Pct effect modify the odds. The advantage of doing
5671  * it this way in stead of rolling twice is that Action_Odds_Pct can
5672  * increase the odds. */
5673  odds += ((odds
5675  nullptr, act_player, tgt_player, tgt_city, nullptr, nullptr,
5676  act_unit, unit_type_get(act_unit), nullptr, nullptr, paction,
5677  EFT_ACTION_ODDS_PCT))
5678  / 100);
5679 
5680  // Odds are between 0% and 100%.
5681  return CLIP(0, odds, 100);
5682 }
5683 
5688 {
5689  // Always immune since its not enabled. Doesn't count.
5690  if (action_enabler_list_size(action_enablers_for_action(act)) == 0) {
5691  return false;
5692  }
5693 
5695  {
5696  if (requirement_fulfilled_by_government(gov, &(enabler->target_reqs))) {
5697  return false;
5698  }
5699  }
5701 
5702  return true;
5703 }
5704 
5709  const action_id wanted_action, const struct player *actor_player,
5710  const struct player *target_player, const struct city *target_city,
5711  const struct impr_type *target_building, const struct tile *target_tile,
5712  const struct unit *target_unit, const struct unit_type *target_unittype,
5713  const struct output_type *target_output,
5714  const struct specialist *target_specialist)
5715 {
5717  enabler)
5718  {
5719  if (are_reqs_active(target_player, actor_player, target_city,
5720  target_building, target_tile, target_unit,
5721  target_unittype, target_output, target_specialist,
5722  nullptr, &enabler->target_reqs, RPT_POSSIBLE)) {
5723  return true;
5724  }
5725  }
5727 
5728  return false;
5729 }
5730 
5735  const struct player *actor_player,
5736  const struct city *target_city)
5737 {
5739  ATK_CITY == action_id_get_target_kind(act_id), false,
5740  "Action %s is against %s not cities", action_id_rule_name(act_id),
5741  action_target_kind_name(action_id_get_target_kind(act_id)));
5742 
5743  return is_target_possible(act_id, actor_player, city_owner(target_city),
5744  target_city, nullptr, city_tile(target_city),
5745  nullptr, nullptr, nullptr, nullptr);
5746 }
5747 
5752 bool is_action_possible_on_unit(action_id act_id, const unit *target_unit)
5753 {
5754  return is_target_possible(act_id, nullptr, unit_owner(target_unit),
5755  unit_home(target_unit), nullptr,
5756  unit_tile(target_unit), target_unit,
5757  unit_type_get(target_unit), nullptr, nullptr);
5758 }
5759 
5766  const struct unit *actor_unit)
5767 {
5768  const struct player *actor_player = unit_owner(actor_unit);
5769  const struct tile *actor_tile = unit_tile(actor_unit);
5770  const struct city *actor_city = tile_city(actor_tile);
5771  const struct unit_type *actor_unittype = unit_type_get(actor_unit);
5772  const struct action *paction = action_by_number(act_id);
5773 
5774  enum fc_tristate result;
5775 
5776  fc_assert_ret_val(actor_unit, false);
5777 
5778  if (!utype_can_do_action(actor_unit->utype, act_id)) {
5779  // The unit type can't perform the action.
5780  return false;
5781  }
5782 
5783  result = action_hard_reqs_actor(paction->result, actor_player, actor_city,
5784  nullptr, actor_tile, actor_unit,
5785  actor_unittype, nullptr, nullptr, false,
5786  game_city_by_number(actor_unit->homecity));
5787 
5788  if (result == TRI_NO) {
5789  // The hard requirements aren't fulfilled.
5790  return false;
5791  }
5792 
5794  {
5795  const enum fc_tristate current = mke_eval_reqs(
5796  actor_player, actor_player, nullptr, actor_city, nullptr, actor_tile,
5797  actor_unit, nullptr, nullptr, &enabler->actor_reqs,
5798  /* Needed since no player to evaluate DiplRel
5799  * requirements against. */
5800  RPT_POSSIBLE);
5801 
5802  if (current == TRI_YES || current == TRI_MAYBE) {
5803  // The ruleset requirements may be fulfilled.
5804  return true;
5805  }
5806  }
5808 
5809  // No action enabler allows this action.
5810  return false;
5811 }
5812 
5818  const action_id act_id)
5819 {
5820  fc_assert(action_id_exists(act_id) || act_id == ACTION_ANY);
5821 
5822  // Check if full movement points may enable the specified action.
5823  return !utype_may_act_move_frags(unit_type_get(actor), act_id,
5824  actor->moves_left)
5827 }
5828 
5833 {
5834  fc_assert_ret_val(num >= 0, nullptr);
5836 
5837  return &auto_perfs[num];
5838 }
5839 
5848 const struct action_auto_perf *action_auto_perf_by_number(const int num)
5849 {
5850  return action_auto_perf_slot_number(num);
5851 }
5852 
5856 bool action_univs_not_blocking(const struct action *paction,
5857  struct universal *actor_uni,
5858  struct universal *target_uni)
5859 {
5861  {
5862  if ((actor_uni == nullptr
5863  || universal_fulfills_requirements(false, &(enab->actor_reqs),
5864  actor_uni))
5865  && (target_uni == nullptr
5866  || universal_fulfills_requirements(false, &(enab->target_reqs),
5867  target_uni))) {
5868  return true;
5869  }
5870  }
5872 
5873  return false;
5874 }
5875 
5881 void action_list_end(action_id *act_list, int size)
5882 {
5884 
5885  if (size < MAX_NUM_ACTIONS) {
5886  // An action list is terminated by ACTION_NONE
5887  act_list[size] = ACTION_NONE;
5888  }
5889 }
5890 
5898 void action_list_add_all_by_result(action_id *act_list, int *position,
5899  enum action_result result)
5900 {
5901  action_iterate(act)
5902  {
5903  struct action *paction = action_by_number(act);
5904  if (paction->result == result) {
5905  // Assume one result for each action.
5906  fc_assert_ret(*position < MAX_NUM_ACTIONS);
5907 
5908  act_list[(*position)++] = paction->id;
5909  }
5910  }
5912 }
5913 
5920 {
5921  switch (static_cast<enum gen_action>(act)) {
5922  case ACTION_SPY_POISON:
5923  return "ui_name_poison_city";
5924  case ACTION_SPY_POISON_ESC:
5925  return "ui_name_poison_city_escape";
5926  case ACTION_SPY_SABOTAGE_UNIT:
5927  return "ui_name_sabotage_unit";
5928  case ACTION_SPY_SABOTAGE_UNIT_ESC:
5929  return "ui_name_sabotage_unit_escape";
5930  case ACTION_SPY_BRIBE_UNIT:
5931  return "ui_name_bribe_unit";
5932  case ACTION_SPY_SABOTAGE_CITY:
5933  return "ui_name_sabotage_city";
5934  case ACTION_SPY_SABOTAGE_CITY_ESC:
5935  return "ui_name_sabotage_city_escape";
5936  case ACTION_SPY_TARGETED_SABOTAGE_CITY:
5937  return "ui_name_targeted_sabotage_city";
5938  case ACTION_SPY_SABOTAGE_CITY_PRODUCTION:
5939  return "ui_name_sabotage_city_production";
5940  case ACTION_SPY_TARGETED_SABOTAGE_CITY_ESC:
5941  return "ui_name_targeted_sabotage_city_escape";
5942  case ACTION_SPY_SABOTAGE_CITY_PRODUCTION_ESC:
5943  return "ui_name_sabotage_city_production_escape";
5944  case ACTION_SPY_INCITE_CITY:
5945  return "ui_name_incite_city";
5946  case ACTION_SPY_INCITE_CITY_ESC:
5947  return "ui_name_incite_city_escape";
5948  case ACTION_ESTABLISH_EMBASSY:
5949  return "ui_name_establish_embassy";
5950  case ACTION_ESTABLISH_EMBASSY_STAY:
5951  return "ui_name_establish_embassy_stay";
5952  case ACTION_SPY_STEAL_TECH:
5953  return "ui_name_steal_tech";
5954  case ACTION_SPY_STEAL_TECH_ESC:
5955  return "ui_name_steal_tech_escape";
5956  case ACTION_SPY_TARGETED_STEAL_TECH:
5957  return "ui_name_targeted_steal_tech";
5958  case ACTION_SPY_TARGETED_STEAL_TECH_ESC:
5959  return "ui_name_targeted_steal_tech_escape";
5960  case ACTION_SPY_INVESTIGATE_CITY:
5961  return "ui_name_investigate_city";
5962  case ACTION_INV_CITY_SPEND:
5963  return "ui_name_investigate_city_spend_unit";
5964  case ACTION_SPY_STEAL_GOLD:
5965  return "ui_name_steal_gold";
5966  case ACTION_SPY_STEAL_GOLD_ESC:
5967  return "ui_name_steal_gold_escape";
5968  case ACTION_SPY_SPREAD_PLAGUE:
5969  return "ui_name_spread_plague";
5970  case ACTION_STEAL_MAPS:
5971  return "ui_name_steal_maps";
5972  case ACTION_STEAL_MAPS_ESC:
5973  return "ui_name_steal_maps_escape";
5974  case ACTION_TRADE_ROUTE:
5975  return "ui_name_establish_trade_route";
5976  case ACTION_MARKETPLACE:
5977  return "ui_name_enter_marketplace";
5978  case ACTION_HELP_WONDER:
5979  return "ui_name_help_wonder";
5980  case ACTION_CAPTURE_UNITS:
5981  return "ui_name_capture_units";
5982  case ACTION_EXPEL_UNIT:
5983  return "ui_name_expel_unit";
5984  case ACTION_FOUND_CITY:
5985  return "ui_name_found_city";
5986  case ACTION_JOIN_CITY:
5987  return "ui_name_join_city";
5988  case ACTION_BOMBARD:
5989  return "ui_name_bombard";
5990  case ACTION_BOMBARD2:
5991  return "ui_name_bombard_2";
5992  case ACTION_BOMBARD3:
5993  return "ui_name_bombard_3";
5994  case ACTION_SPY_NUKE:
5995  return "ui_name_suitcase_nuke";
5996  case ACTION_SPY_NUKE_ESC:
5997  return "ui_name_suitcase_nuke_escape";
5998  case ACTION_NUKE:
5999  return "ui_name_explode_nuclear";
6000  case ACTION_NUKE_CITY:
6001  return "ui_name_nuke_city";
6002  case ACTION_NUKE_UNITS:
6003  return "ui_name_nuke_units";
6004  case ACTION_DESTROY_CITY:
6005  return "ui_name_destroy_city";
6006  case ACTION_RECYCLE_UNIT:
6007  return "ui_name_recycle_unit";
6008  case ACTION_DISBAND_UNIT:
6009  return "ui_name_disband_unit";
6010  case ACTION_HOME_CITY:
6011  return "ui_name_home_city";
6012  case ACTION_UPGRADE_UNIT:
6013  return "ui_name_upgrade_unit";
6014  case ACTION_PARADROP:
6015  return "ui_name_paradrop_unit";
6016  case ACTION_AIRLIFT:
6017  return "ui_name_airlift_unit";
6018  case ACTION_ATTACK:
6019  return "ui_name_attack";
6020  case ACTION_SUICIDE_ATTACK:
6021  return "ui_name_suicide_attack";
6022  case ACTION_STRIKE_BUILDING:
6023  return "ui_name_surgical_strike_building";
6024  case ACTION_STRIKE_PRODUCTION:
6025  return "ui_name_surgical_strike_production";
6026  case ACTION_CONQUER_CITY:
6027  return "ui_name_conquer_city";
6028  case ACTION_CONQUER_CITY2:
6029  return "ui_name_conquer_city_2";
6030  case ACTION_HEAL_UNIT:
6031  return "ui_name_heal_unit";
6032  case ACTION_TRANSFORM_TERRAIN:
6033  return "ui_name_transform_terrain";
6034  case ACTION_CULTIVATE:
6035  return "ui_name_cultivate";
6036  case ACTION_PLANT:
6037  return "ui_name_plant";
6038  case ACTION_PILLAGE:
6039  return "ui_name_pillage";
6040  case ACTION_CLEAN_POLLUTION:
6041  return "ui_name_clean_pollution";
6042  case ACTION_CLEAN_FALLOUT:
6043  return "ui_name_clean_fallout";
6044  case ACTION_FORTIFY:
6045  return "ui_name_fortify";
6046  case ACTION_ROAD:
6047  return "ui_name_road";
6048  case ACTION_CONVERT:
6049  return "ui_name_convert_unit";
6050  case ACTION_BASE:
6051  return "ui_name_build_base";
6052  case ACTION_MINE:
6053  return "ui_name_build_mine";
6054  case ACTION_IRRIGATE:
6055  return "ui_name_irrigate";
6056  case ACTION_TRANSPORT_ALIGHT:
6057  return "ui_name_transport_alight";
6058  case ACTION_TRANSPORT_BOARD:
6059  return "ui_name_transport_board";
6060  case ACTION_TRANSPORT_EMBARK:
6061  return "ui_name_transport_embark";
6062  case ACTION_TRANSPORT_UNLOAD:
6063  return "ui_name_transport_unload";
6064  case ACTION_TRANSPORT_DISEMBARK1:
6065  return "ui_name_transport_disembark";
6066  case ACTION_TRANSPORT_DISEMBARK2:
6067  return "ui_name_transport_disembark_2";
6068  case ACTION_SPY_ATTACK:
6069  return "ui_name_spy_attack";
6070  case ACTION_USER_ACTION1:
6071  return "ui_name_user_action_1";
6072  case ACTION_USER_ACTION2:
6073  return "ui_name_user_action_2";
6074  case ACTION_USER_ACTION3:
6075  return "ui_name_user_action_3";
6076  case ACTION_COUNT:
6077  break;
6078  }
6079 
6080  fc_assert(act >= 0 && act < ACTION_COUNT);
6081  return nullptr;
6082 }
6083 
6087 const char *action_ui_name_default(int act)
6088 {
6089  switch (act) {
6090  case ACTION_SPY_POISON:
6091  // TRANS: _Poison City (3% chance of success).
6092  return N_("%sPoison City%s");
6093  case ACTION_SPY_POISON_ESC:
6094  // TRANS: _Poison City and Escape (3% chance of success).
6095  return N_("%sPoison City and Escape%s");
6096  case ACTION_SPY_SABOTAGE_UNIT:
6097  // TRANS: S_abotage Enemy Unit (3% chance of success).
6098  return N_("S%sabotage Enemy Unit%s");
6099  case ACTION_SPY_SABOTAGE_UNIT_ESC:
6100  // TRANS: S_abotage Enemy Unit and Escape (3% chance of success).
6101  return N_("S%sabotage Enemy Unit and Escape%s");
6102  case ACTION_SPY_BRIBE_UNIT:
6103  // TRANS: Bribe Enemy _Unit (3% chance of success).
6104  return N_("Bribe Enemy %sUnit%s");
6105  case ACTION_SPY_SABOTAGE_CITY:
6106  // TRANS: _Sabotage City (3% chance of success).
6107  return N_("%sSabotage City%s");
6108  case ACTION_SPY_SABOTAGE_CITY_ESC:
6109  // TRANS: _Sabotage City and Escape (3% chance of success).
6110  return N_("%sSabotage City and Escape%s");
6111  case ACTION_SPY_TARGETED_SABOTAGE_CITY:
6112  // TRANS: Industria_l Sabotage (3% chance of success).
6113  return N_("Industria%sl Sabotage%s");
6114  case ACTION_SPY_SABOTAGE_CITY_PRODUCTION:
6115  // TRANS: Industria_l Sabotage Production (3% chance of success).
6116  return N_("Industria%sl Sabotage Production%s");
6117  case ACTION_SPY_TARGETED_SABOTAGE_CITY_ESC:
6118  // TRANS: Industria_l Sabotage and Escape (3% chance of success).
6119  return N_("Industria%sl Sabotage and Escape%s");
6120  case ACTION_SPY_SABOTAGE_CITY_PRODUCTION_ESC:
6121  /* TRANS: Industria_l Sabotage Production and Escape (3% chance of
6122  * success). */
6123  return N_("Industria%sl Sabotage Production and Escape%s");
6124  case ACTION_SPY_INCITE_CITY:
6125  // TRANS: Incite a Re_volt (3% chance of success).
6126  return N_("Incite a Re%svolt%s");
6127  case ACTION_SPY_INCITE_CITY_ESC:
6128  // TRANS: Incite a Re_volt and Escape (3% chance of success).
6129  return N_("Incite a Re%svolt and Escape%s");
6130  case ACTION_ESTABLISH_EMBASSY:
6131  // TRANS: Establish _Embassy (100% chance of success).
6132  return N_("Establish %sEmbassy%s");
6133  case ACTION_ESTABLISH_EMBASSY_STAY:
6134  // TRANS: Becom_e Ambassador (100% chance of success).
6135  return N_("Becom%se Ambassador%s");
6136  case ACTION_SPY_STEAL_TECH:
6137  // TRANS: Steal _Technology (3% chance of success).
6138  return N_("Steal %sTechnology%s");
6139  case ACTION_SPY_STEAL_TECH_ESC:
6140  // TRANS: Steal _Technology and Escape (3% chance of success).
6141  return N_("Steal %sTechnology and Escape%s");
6142  case ACTION_SPY_TARGETED_STEAL_TECH:
6143  // TRANS: In_dustrial Espionage (3% chance of success).
6144  return N_("In%sdustrial Espionage%s");
6145  case ACTION_SPY_TARGETED_STEAL_TECH_ESC:
6146  // TRANS: In_dustrial Espionage and Escape (3% chance of success).
6147  return N_("In%sdustrial Espionage and Escape%s");
6148  case ACTION_SPY_INVESTIGATE_CITY:
6149  // TRANS: _Investigate City (100% chance of success).
6150  return N_("%sInvestigate City%s");
6151  case ACTION_INV_CITY_SPEND:
6152  /* TRANS: _Investigate City (spends the unit) (100% chance of
6153  * success). */
6154  return N_("%sInvestigate City (spends the unit)%s");
6155  case ACTION_SPY_STEAL_GOLD:
6156  // TRANS: Steal _Gold (100% chance of success).
6157  return N_("Steal %sGold%s");
6158  case ACTION_SPY_STEAL_GOLD_ESC:
6159  // TRANS: Steal _Gold and Escape (100% chance of success).
6160  return N_("Steal %sGold and Escape%s");
6161  case ACTION_SPY_SPREAD_PLAGUE:
6162  // TRANS: Spread _Plague (100% chance of success).
6163  return N_("Spread %sPlague%s");
6164  case ACTION_STEAL_MAPS:
6165  // TRANS: Steal _Maps (100% chance of success).
6166  return N_("Steal %sMaps%s");
6167  case ACTION_STEAL_MAPS_ESC:
6168  // TRANS: Steal _Maps and Escape (100% chance of success).
6169  return N_("Steal %sMaps and Escape%s");
6170  case ACTION_TRADE_ROUTE:
6171  // TRANS: Establish Trade _Route (100% chance of success).
6172  return N_("Establish Trade %sRoute%s");
6173  case ACTION_MARKETPLACE:
6174  // TRANS: Enter _Marketplace (100% chance of success).
6175  return N_("Enter %sMarketplace%s");
6176  case ACTION_HELP_WONDER:
6177  // TRANS: Help _build Wonder (100% chance of success).
6178  return N_("Help %sBuild Wonder%s");
6179  case ACTION_CAPTURE_UNITS:
6180  // TRANS: _Capture Units (100% chance of success).
6181  return N_("%sCapture Units%s");
6182  case ACTION_EXPEL_UNIT:
6183  // TRANS: _Expel Unit (100% chance of success).
6184  return N_("%sExpel Unit%s");
6185  case ACTION_FOUND_CITY:
6186  // TRANS: _Found City (100% chance of success).
6187  return N_("%sFound City%s");
6188  case ACTION_JOIN_CITY:
6189  // TRANS: _Join City (100% chance of success).
6190  return N_("%sJoin City%s");
6191  case ACTION_BOMBARD:
6192  // TRANS: B_ombard (100% chance of success).
6193  return N_("B%sombard%s");
6194  case ACTION_BOMBARD2:
6195  // TRANS: B_ombard 2 (100% chance of success).
6196  return N_("B%sombard 2%s");
6197  case ACTION_BOMBARD3:
6198  // TRANS: B_ombard 3 (100% chance of success).
6199  return N_("B%sombard 3%s");
6200  case ACTION_SPY_NUKE:
6201  // TRANS: Suitcase _Nuke (100% chance of success).
6202  return N_("Suitcase %sNuke%s");
6203  case ACTION_SPY_NUKE_ESC:
6204  // TRANS: Suitcase _Nuke and Escape (100% chance of success).
6205  return N_("Suitcase %sNuke and Escape%s");
6206  case ACTION_NUKE:
6207  // TRANS: Explode _Nuclear (100% chance of success).
6208  return N_("Explode %sNuclear%s");
6209  case ACTION_NUKE_CITY:
6210  // TRANS: _Nuke City (100% chance of success).
6211  return N_("%sNuke City%s");
6212  case ACTION_NUKE_UNITS:
6213  // TRANS: _Nuke Units (100% chance of success).
6214  return N_("%sNuke Units%s");
6215  case ACTION_DESTROY_CITY:
6216  // TRANS: Destroy _City (100% chance of success).
6217  return N_("Destroy %sCity%s");
6218  case ACTION_RECYCLE_UNIT:
6219  // TRANS: Rec_ycle Unit (100% chance of success).
6220  return N_("Rec%sycle Unit%s");
6221  case ACTION_DISBAND_UNIT:
6222  // TRANS: _Disband Unit (100% chance of success).
6223  return N_("%sDisband Unit%s");
6224  case ACTION_HOME_CITY:
6225  // TRANS: Set _Home City (100% chance of success).
6226  return N_("Set %sHome City%s");
6227  case ACTION_UPGRADE_UNIT:
6228  // TRANS: _Upgrade Unit (100% chance of success).
6229  return N_("%sUpgrade Unit%s");
6230  case ACTION_PARADROP:
6231  // TRANS: Drop _Paratrooper (100% chance of success).
6232  return N_("Drop %sParatrooper%s");
6233  case ACTION_AIRLIFT:
6234  // TRANS: _Airlift to City (100% chance of success).
6235  return N_("%sAirlift to City%s");
6236  case ACTION_ATTACK:
6237  // TRANS: _Attack (100% chance of success).
6238  return N_("%sAttack%s");
6239  case ACTION_SUICIDE_ATTACK:
6240  // TRANS: _Suicide Attack (100% chance of success).
6241  return N_("%sSuicide Attack%s");
6242  case ACTION_STRIKE_BUILDING:
6243  // TRANS: Surgical Str_ike Building (100% chance of success).
6244  return N_("Surgical Str%sike Building%s");
6245  case ACTION_STRIKE_PRODUCTION:
6246  // TRANS: Surgical Str_ike Production (100% chance of success).
6247  return N_("Surgical Str%sike Production%s");
6248  case ACTION_CONQUER_CITY:
6249  // TRANS: _Conquer City (100% chance of success).
6250  return N_("%sConquer City%s");
6251  case ACTION_CONQUER_CITY2:
6252  // TRANS: _Conquer City 2 (100% chance of success).
6253  return N_("%sConquer City 2%s");
6254  case ACTION_HEAL_UNIT:
6255  // TRANS: Heal _Unit (3% chance of success).
6256  return N_("Heal %sUnit%s");
6257  case ACTION_TRANSFORM_TERRAIN:
6258  // TRANS: _Transform Terrain (3% chance of success).
6259  return N_("%sTransform Terrain%s");
6260  case ACTION_CULTIVATE:
6261  // TRANS: Transform by _Cultivating (3% chance of success).
6262  return N_("Transform by %sCultivating%s");
6263  case ACTION_PLANT:
6264  // TRANS: Transform by _Planting (3% chance of success).
6265  return N_("Transform by %sPlanting%s");
6266  case ACTION_PILLAGE:
6267  // TRANS: Pilla_ge (100% chance of success).
6268  return N_("Pilla%sge%s");
6269  case ACTION_CLEAN_POLLUTION:
6270  // TRANS: Clean _Pollution (100% chance of success).
6271  return N_("Clean %sPollution%s");
6272  case ACTION_CLEAN_FALLOUT:
6273  // TRANS: Clean _Fallout (100% chance of success).
6274  return N_("Clean %sFallout%s");
6275  case ACTION_FORTIFY:
6276  // TRANS: _Fortify (100% chance of success).
6277  return N_("%sFortify%s");
6278  case ACTION_ROAD:
6279  // TRANS: Build _Road (100% chance of success).
6280  return N_("Build %sRoad%s");
6281  case ACTION_CONVERT:
6282  // TRANS: _Convert Unit (100% chance of success).
6283  return N_("%sConvert Unit%s");
6284  case ACTION_BASE:
6285  // TRANS: _Build Base (100% chance of success).
6286  return N_("%sBuild Base%s");
6287  case ACTION_MINE:
6288  // TRANS: Build _Mine (100% chance of success).
6289  return N_("Build %sMine%s");
6290  case ACTION_IRRIGATE:
6291  // TRANS: Build _Irrigation (100% chance of success).
6292  return N_("Build %sIrrigation%s");
6293  case ACTION_TRANSPORT_ALIGHT:
6294  // TRANS: _Alight (100% chance of success).
6295  return N_("%sAlight%s");
6296  case ACTION_TRANSPORT_BOARD:
6297  // TRANS: _Board (100% chance of success).
6298  return N_("%sBoard%s");
6299  case ACTION_TRANSPORT_EMBARK:
6300  // TRANS: _Embark (100% chance of success).
6301  return N_("%sEmbark%s");
6302  case ACTION_TRANSPORT_UNLOAD:
6303  // TRANS: _Unload (100% chance of success).
6304  return N_("%sUnload%s");
6305  case ACTION_TRANSPORT_DISEMBARK1:
6306  // TRANS: _Disembark (100% chance of success).
6307  return N_("%sDisembark%s");
6308  case ACTION_TRANSPORT_DISEMBARK2:
6309  // TRANS: _Disembark 2 (100% chance of success).
6310  return N_("%sDisembark 2%s");
6311  case ACTION_SPY_ATTACK:
6312  // TRANS: _Eliminate Diplomat (100% chance of success).
6313  return N_("%sEliminate Diplomat%s");
6314  case ACTION_USER_ACTION1:
6315  // TRANS: _User Action 1 (100% chance of success).
6316  return N_("%sUser Action 1%s");
6317  case ACTION_USER_ACTION2:
6318  // TRANS: _User Action 2 (100% chance of success).
6319  return N_("%sUser Action 2%s");
6320  case ACTION_USER_ACTION3:
6321  // TRANS: _User Action 3 (100% chance of success).
6322  return N_("%sUser Action 3%s");
6323  }
6324 
6325  return nullptr;
6326 }
6327 
6335 {
6336  switch (static_cast<enum gen_action>(act)) {
6337  case ACTION_SPY_POISON:
6338  case ACTION_SPY_POISON_ESC:
6339  case ACTION_SPY_SABOTAGE_UNIT:
6340  case ACTION_SPY_SABOTAGE_UNIT_ESC:
6341  case ACTION_SPY_BRIBE_UNIT:
6342  case ACTION_SPY_SABOTAGE_CITY:
6343  case ACTION_SPY_SABOTAGE_CITY_ESC:
6344  case ACTION_SPY_TARGETED_SABOTAGE_CITY:
6345  case ACTION_SPY_SABOTAGE_CITY_PRODUCTION:
6346  case ACTION_SPY_TARGETED_SABOTAGE_CITY_ESC:
6347  case ACTION_SPY_SABOTAGE_CITY_PRODUCTION_ESC:
6348  case ACTION_SPY_INCITE_CITY:
6349  case ACTION_SPY_INCITE_CITY_ESC:
6350  case ACTION_ESTABLISH_EMBASSY:
6351  case ACTION_ESTABLISH_EMBASSY_STAY:
6352  case ACTION_SPY_STEAL_TECH:
6353  case ACTION_SPY_STEAL_TECH_ESC:
6354  case ACTION_SPY_TARGETED_STEAL_TECH:
6355  case ACTION_SPY_TARGETED_STEAL_TECH_ESC:
6356  case ACTION_SPY_INVESTIGATE_CITY:
6357  case ACTION_INV_CITY_SPEND:
6358  case ACTION_SPY_STEAL_GOLD:
6359  case ACTION_SPY_STEAL_GOLD_ESC:
6360  case ACTION_SPY_SPREAD_PLAGUE:
6361  case ACTION_STEAL_MAPS:
6362  case ACTION_STEAL_MAPS_ESC:
6363  case ACTION_TRADE_ROUTE:
6364  case ACTION_MARKETPLACE:
6365  case ACTION_HELP_WONDER:
6366  case ACTION_CAPTURE_UNITS:
6367  case ACTION_EXPEL_UNIT:
6368  case ACTION_FOUND_CITY:
6369  case ACTION_JOIN_CITY:
6370  case ACTION_SPY_NUKE:
6371  case ACTION_SPY_NUKE_ESC:
6372  case ACTION_NUKE_CITY:
6373  case ACTION_NUKE_UNITS:
6374  case ACTION_DESTROY_CITY:
6375  case ACTION_RECYCLE_UNIT:
6376  case ACTION_DISBAND_UNIT:
6377  case ACTION_HOME_CITY:
6378  case ACTION_UPGRADE_UNIT:
6379  case ACTION_PARADROP:
6380  case ACTION_AIRLIFT:
6381  case ACTION_ATTACK:
6382  case ACTION_SUICIDE_ATTACK:
6383  case ACTION_STRIKE_BUILDING:
6384  case ACTION_STRIKE_PRODUCTION:
6385  case ACTION_CONQUER_CITY:
6386  case ACTION_CONQUER_CITY2:
6387  case ACTION_HEAL_UNIT:
6388  case ACTION_TRANSFORM_TERRAIN:
6389  case ACTION_CULTIVATE:
6390  case ACTION_PLANT:
6391  case ACTION_PILLAGE:
6392  case ACTION_CLEAN_POLLUTION:
6393  case ACTION_CLEAN_FALLOUT:
6394  case ACTION_FORTIFY:
6395  case ACTION_ROAD:
6396  case ACTION_CONVERT:
6397  case ACTION_BASE:
6398  case ACTION_MINE:
6399  case ACTION_IRRIGATE:
6400  case ACTION_TRANSPORT_ALIGHT:
6401  case ACTION_TRANSPORT_BOARD:
6402  case ACTION_TRANSPORT_EMBARK:
6403  case ACTION_TRANSPORT_UNLOAD:
6404  case ACTION_TRANSPORT_DISEMBARK1:
6405  case ACTION_TRANSPORT_DISEMBARK2:
6406  case ACTION_BOMBARD:
6407  case ACTION_BOMBARD2:
6408  case ACTION_BOMBARD3:
6409  case ACTION_NUKE:
6410  case ACTION_SPY_ATTACK:
6411  // Min range is not ruleset changeable
6412  return nullptr;
6413  case ACTION_USER_ACTION1:
6414  return "user_action_1_min_range";
6415  case ACTION_USER_ACTION2:
6416  return "user_action_2_min_range";
6417  case ACTION_USER_ACTION3:
6418  return "user_action_3_min_range";
6419  case ACTION_COUNT:
6420  break;
6421  }
6422 
6423  fc_assert(act >= 0 && act < ACTION_COUNT);
6424  return nullptr;
6425 }
6426 
6431 {
6432  switch (static_cast<enum gen_action>(act)) {
6433  case ACTION_SPY_POISON:
6434  case ACTION_SPY_POISON_ESC:
6435  case ACTION_SPY_SABOTAGE_UNIT:
6436  case ACTION_SPY_SABOTAGE_UNIT_ESC:
6437  case ACTION_SPY_BRIBE_UNIT:
6438  case ACTION_SPY_SABOTAGE_CITY:
6439  case ACTION_SPY_SABOTAGE_CITY_ESC:
6440  case ACTION_SPY_TARGETED_SABOTAGE_CITY:
6441  case ACTION_SPY_SABOTAGE_CITY_PRODUCTION:
6442  case ACTION_SPY_TARGETED_SABOTAGE_CITY_ESC:
6443  case ACTION_SPY_SABOTAGE_CITY_PRODUCTION_ESC:
6444  case ACTION_SPY_INCITE_CITY:
6445  case ACTION_SPY_INCITE_CITY_ESC:
6446  case ACTION_ESTABLISH_EMBASSY:
6447  case ACTION_ESTABLISH_EMBASSY_STAY:
6448  case ACTION_SPY_STEAL_TECH:
6449  case ACTION_SPY_STEAL_TECH_ESC:
6450  case ACTION_SPY_TARGETED_STEAL_TECH:
6451  case ACTION_SPY_TARGETED_STEAL_TECH_ESC:
6452  case ACTION_SPY_INVESTIGATE_CITY:
6453  case ACTION_INV_CITY_SPEND:
6454  case ACTION_SPY_STEAL_GOLD:
6455  case ACTION_SPY_STEAL_GOLD_ESC:
6456  case ACTION_SPY_SPREAD_PLAGUE:
6457  case ACTION_STEAL_MAPS:
6458  case ACTION_STEAL_MAPS_ESC:
6459  case ACTION_TRADE_ROUTE:
6460  case ACTION_MARKETPLACE:
6461  case ACTION_HELP_WONDER:
6462  case ACTION_CAPTURE_UNITS:
6463  case ACTION_EXPEL_UNIT:
6464  case ACTION_FOUND_CITY:
6465  case ACTION_JOIN_CITY:
6466  case ACTION_SPY_NUKE:
6467  case ACTION_SPY_NUKE_ESC:
6468  case ACTION_NUKE_CITY:
6469  case ACTION_NUKE_UNITS:
6470  case ACTION_DESTROY_CITY:
6471  case ACTION_RECYCLE_UNIT:
6472  case ACTION_DISBAND_UNIT:
6473  case ACTION_HOME_CITY:
6474  case ACTION_UPGRADE_UNIT:
6475  case ACTION_PARADROP:
6476  case ACTION_AIRLIFT:
6477  case ACTION_ATTACK:
6478  case ACTION_SUICIDE_ATTACK:
6479  case ACTION_STRIKE_BUILDING:
6480  case ACTION_STRIKE_PRODUCTION:
6481  case ACTION_CONQUER_CITY:
6482  case ACTION_CONQUER_CITY2:
6483  case ACTION_HEAL_UNIT:
6484  case ACTION_TRANSFORM_TERRAIN:
6485  case ACTION_CULTIVATE:
6486  case ACTION_PLANT:
6487  case ACTION_PILLAGE:
6488  case ACTION_CLEAN_POLLUTION:
6489  case ACTION_CLEAN_FALLOUT:
6490  case ACTION_FORTIFY:
6491  case ACTION_ROAD:
6492  case ACTION_CONVERT:
6493  case ACTION_BASE:
6494  case ACTION_MINE:
6495  case ACTION_IRRIGATE:
6496  case ACTION_TRANSPORT_ALIGHT:
6497  case ACTION_TRANSPORT_BOARD:
6498  case ACTION_TRANSPORT_EMBARK:
6499  case ACTION_TRANSPORT_UNLOAD:
6500  case ACTION_TRANSPORT_DISEMBARK1:
6501  case ACTION_TRANSPORT_DISEMBARK2:
6502  case ACTION_BOMBARD:
6503  case ACTION_BOMBARD2:
6504  case ACTION_BOMBARD3:
6505  case ACTION_NUKE:
6506  case ACTION_SPY_ATTACK:
6507  // Non ruleset defined action min range not supported here
6508  fc_assert_msg(false, "Probably wrong value.");
6510  case ACTION_USER_ACTION1:
6511  case ACTION_USER_ACTION2:
6512  case ACTION_USER_ACTION3:
6514  case ACTION_COUNT:
6515  break;
6516  }
6517 
6518  fc_assert(act >= 0 && act < ACTION_COUNT);
6519  return 0;
6520 }
6521 
6529 {
6530  switch (static_cast<enum gen_action>(act)) {
6531  case ACTION_SPY_POISON:
6532  case ACTION_SPY_POISON_ESC:
6533  case ACTION_SPY_SABOTAGE_UNIT:
6534  case ACTION_SPY_SABOTAGE_UNIT_ESC:
6535  case ACTION_SPY_BRIBE_UNIT:
6536  case ACTION_SPY_SABOTAGE_CITY:
6537  case ACTION_SPY_SABOTAGE_CITY_ESC:
6538  case ACTION_SPY_TARGETED_SABOTAGE_CITY:
6539  case ACTION_SPY_SABOTAGE_CITY_PRODUCTION:
6540  case ACTION_SPY_TARGETED_SABOTAGE_CITY_ESC:
6541  case ACTION_SPY_SABOTAGE_CITY_PRODUCTION_ESC:
6542  case ACTION_SPY_INCITE_CITY:
6543  case ACTION_SPY_INCITE_CITY_ESC:
6544  case ACTION_ESTABLISH_EMBASSY:
6545  case ACTION_ESTABLISH_EMBASSY_STAY:
6546  case ACTION_SPY_STEAL_TECH:
6547  case ACTION_SPY_STEAL_TECH_ESC:
6548  case ACTION_SPY_TARGETED_STEAL_TECH:
6549  case ACTION_SPY_TARGETED_STEAL_TECH_ESC:
6550  case ACTION_SPY_INVESTIGATE_CITY:
6551  case ACTION_INV_CITY_SPEND:
6552  case ACTION_SPY_STEAL_GOLD:
6553  case ACTION_SPY_STEAL_GOLD_ESC:
6554  case ACTION_SPY_SPREAD_PLAGUE:
6555  case ACTION_STEAL_MAPS:
6556  case ACTION_STEAL_MAPS_ESC:
6557  case ACTION_TRADE_ROUTE:
6558  case ACTION_MARKETPLACE:
6559  case ACTION_CAPTURE_UNITS:
6560  case ACTION_EXPEL_UNIT:
6561  case ACTION_FOUND_CITY:
6562  case ACTION_JOIN_CITY:
6563  case ACTION_SPY_NUKE:
6564  case ACTION_SPY_NUKE_ESC:
6565  case ACTION_DESTROY_CITY:
6566  case ACTION_DISBAND_UNIT:
6567  case ACTION_HOME_CITY:
6568  case ACTION_UPGRADE_UNIT:
6569  case ACTION_PARADROP:
6570  case ACTION_ATTACK:
6571  case ACTION_SUICIDE_ATTACK:
6572  case ACTION_STRIKE_BUILDING:
6573  case ACTION_STRIKE_PRODUCTION:
6574  case ACTION_CONQUER_CITY:
6575  case ACTION_CONQUER_CITY2:
6576  case ACTION_HEAL_UNIT:
6577  case ACTION_TRANSFORM_TERRAIN:
6578  case ACTION_CULTIVATE:
6579  case ACTION_PLANT:
6580  case ACTION_PILLAGE:
6581  case ACTION_CLEAN_POLLUTION:
6582  case ACTION_CLEAN_FALLOUT:
6583  case ACTION_FORTIFY:
6584  case ACTION_ROAD:
6585  case ACTION_CONVERT:
6586  case ACTION_BASE:
6587  case ACTION_MINE:
6588  case ACTION_IRRIGATE:
6589  case ACTION_TRANSPORT_ALIGHT:
6590  case ACTION_TRANSPORT_BOARD:
6591  case ACTION_TRANSPORT_EMBARK:
6592  case ACTION_TRANSPORT_UNLOAD:
6593  case ACTION_TRANSPORT_DISEMBARK1:
6594  case ACTION_TRANSPORT_DISEMBARK2:
6595  case ACTION_SPY_ATTACK:
6596  // Max range is not ruleset changeable
6597  return nullptr;
6598  case ACTION_HELP_WONDER:
6599  return "help_wonder_max_range";
6600  case ACTION_RECYCLE_UNIT:
6601  return "recycle_unit_max_range";
6602  case ACTION_BOMBARD:
6603  return "bombard_max_range";
6604  case ACTION_BOMBARD2:
6605  return "bombard_2_max_range";
6606  case ACTION_BOMBARD3:
6607  return "bombard_3_max_range";
6608  case ACTION_NUKE:
6609  return "explode_nuclear_max_range";
6610  case ACTION_NUKE_CITY:
6611  return "nuke_city_max_range";
6612  case ACTION_NUKE_UNITS:
6613  return "nuke_units_max_range";
6614  case ACTION_AIRLIFT:
6615  return "airlift_max_range";
6616  case ACTION_USER_ACTION1:
6617  return "user_action_1_max_range";
6618  case ACTION_USER_ACTION2:
6619  return "user_action_2_max_range";
6620  case ACTION_USER_ACTION3:
6621  return "user_action_3_max_range";
6622  case ACTION_COUNT:
6623  break;
6624  }
6625 
6626  fc_assert(act >= 0 && act < ACTION_COUNT);
6627  return nullptr;
6628 }
6629 
6634 {
6635  switch (static_cast<enum gen_action>(act)) {
6636  case ACTION_SPY_POISON:
6637  case ACTION_SPY_POISON_ESC:
6638  case ACTION_SPY_SABOTAGE_UNIT:
6639  case ACTION_SPY_SABOTAGE_UNIT_ESC:
6640  case ACTION_SPY_BRIBE_UNIT:
6641  case ACTION_SPY_SABOTAGE_CITY:
6642  case ACTION_SPY_SABOTAGE_CITY_ESC:
6643  case ACTION_SPY_TARGETED_SABOTAGE_CITY:
6644  case ACTION_SPY_SABOTAGE_CITY_PRODUCTION:
6645  case ACTION_SPY_TARGETED_SABOTAGE_CITY_ESC:
6646  case ACTION_SPY_SABOTAGE_CITY_PRODUCTION_ESC:
6647  case ACTION_SPY_INCITE_CITY:
6648  case ACTION_SPY_INCITE_CITY_ESC:
6649  case ACTION_ESTABLISH_EMBASSY:
6650  case ACTION_ESTABLISH_EMBASSY_STAY:
6651  case ACTION_SPY_STEAL_TECH:
6652  case ACTION_SPY_STEAL_TECH_ESC:
6653  case ACTION_SPY_TARGETED_STEAL_TECH:
6654  case ACTION_SPY_TARGETED_STEAL_TECH_ESC:
6655  case ACTION_SPY_INVESTIGATE_CITY:
6656  case ACTION_INV_CITY_SPEND:
6657  case ACTION_SPY_STEAL_GOLD:
6658  case ACTION_SPY_STEAL_GOLD_ESC:
6659  case ACTION_STEAL_MAPS:
6660  case ACTION_STEAL_MAPS_ESC:
6661  case ACTION_SPY_SPREAD_PLAGUE:
6662  case ACTION_TRADE_ROUTE:
6663  case ACTION_MARKETPLACE:
6664  case ACTION_CAPTURE_UNITS:
6665  case ACTION_EXPEL_UNIT:
6666  case ACTION_FOUND_CITY:
6667  case ACTION_JOIN_CITY:
6668  case ACTION_SPY_NUKE:
6669  case ACTION_SPY_NUKE_ESC:
6670  case ACTION_DESTROY_CITY:
6671  case ACTION_DISBAND_UNIT:
6672  case ACTION_HOME_CITY:
6673  case ACTION_UPGRADE_UNIT:
6674  case ACTION_PARADROP:
6675  case ACTION_ATTACK:
6676  case ACTION_SUICIDE_ATTACK:
6677  case ACTION_STRIKE_BUILDING:
6678  case ACTION_STRIKE_PRODUCTION:
6679  case ACTION_CONQUER_CITY:
6680  case ACTION_CONQUER_CITY2:
6681  case ACTION_HEAL_UNIT:
6682  case ACTION_TRANSFORM_TERRAIN:
6683  case ACTION_CULTIVATE:
6684  case ACTION_PLANT:
6685  case ACTION_PILLAGE:
6686  case ACTION_CLEAN_POLLUTION:
6687  case ACTION_CLEAN_FALLOUT:
6688  case ACTION_FORTIFY:
6689  case ACTION_ROAD:
6690  case ACTION_CONVERT:
6691  case ACTION_BASE:
6692  case ACTION_MINE:
6693  case ACTION_IRRIGATE:
6694  case ACTION_TRANSPORT_ALIGHT:
6695  case ACTION_TRANSPORT_BOARD:
6696  case ACTION_TRANSPORT_EMBARK:
6697  case ACTION_TRANSPORT_UNLOAD:
6698  case ACTION_TRANSPORT_DISEMBARK1:
6699  case ACTION_TRANSPORT_DISEMBARK2:
6700  case ACTION_SPY_ATTACK:
6701  // Non ruleset defined action max range not supported here
6702  fc_assert_msg(false, "Probably wrong value.");
6704  case ACTION_HELP_WONDER:
6705  case ACTION_RECYCLE_UNIT:
6707  case ACTION_BOMBARD:
6708  case ACTION_BOMBARD2:
6709  case ACTION_BOMBARD3:
6711  case ACTION_NUKE:
6713  case ACTION_NUKE_CITY:
6714  case ACTION_NUKE_UNITS:
6716  case ACTION_AIRLIFT:
6718  case ACTION_USER_ACTION1:
6719  case ACTION_USER_ACTION2:
6720  case ACTION_USER_ACTION3:
6722  case ACTION_COUNT:
6723  break;
6724  }
6725 
6726  fc_assert(act >= 0 && act < ACTION_COUNT);
6727  return 0;
6728 }
6729 
6737 {
6738  switch (static_cast<enum gen_action>(act)) {
6739  case ACTION_SPY_POISON:
6740  case ACTION_SPY_POISON_ESC:
6741  case ACTION_SPY_SABOTAGE_UNIT:
6742  case ACTION_SPY_SABOTAGE_UNIT_ESC:
6743  case ACTION_SPY_BRIBE_UNIT:
6744  case ACTION_SPY_SABOTAGE_CITY:
6745  case ACTION_SPY_SABOTAGE_CITY_ESC:
6746  case ACTION_SPY_TARGETED_SABOTAGE_CITY:
6747  case ACTION_SPY_SABOTAGE_CITY_PRODUCTION:
6748  case ACTION_SPY_TARGETED_SABOTAGE_CITY_ESC:
6749  case ACTION_SPY_SABOTAGE_CITY_PRODUCTION_ESC:
6750  case ACTION_SPY_INCITE_CITY:
6751  case ACTION_SPY_INCITE_CITY_ESC:
6752  case ACTION_ESTABLISH_EMBASSY:
6753  case ACTION_ESTABLISH_EMBASSY_STAY:
6754  case ACTION_SPY_STEAL_TECH:
6755  case ACTION_SPY_STEAL_TECH_ESC:
6756  case ACTION_SPY_TARGETED_STEAL_TECH:
6757  case ACTION_SPY_TARGETED_STEAL_TECH_ESC:
6758  case ACTION_SPY_INVESTIGATE_CITY:
6759  case ACTION_INV_CITY_SPEND:
6760  case ACTION_SPY_STEAL_GOLD:
6761  case ACTION_SPY_STEAL_GOLD_ESC:
6762  case ACTION_SPY_SPREAD_PLAGUE:
6763  case ACTION_STEAL_MAPS:
6764  case ACTION_STEAL_MAPS_ESC:
6765  case ACTION_TRADE_ROUTE:
6766  case ACTION_MARKETPLACE:
6767  case ACTION_HELP_WONDER:
6768  case ACTION_CAPTURE_UNITS:
6769  case ACTION_EXPEL_UNIT:
6770  case ACTION_FOUND_CITY:
6771  case ACTION_JOIN_CITY:
6772  case ACTION_SPY_NUKE:
6773  case ACTION_SPY_NUKE_ESC:
6774  case ACTION_NUKE_CITY:
6775  case ACTION_NUKE_UNITS:
6776  case ACTION_DESTROY_CITY:
6777  case ACTION_RECYCLE_UNIT:
6778  case ACTION_DISBAND_UNIT:
6779  case ACTION_HOME_CITY:
6780  case ACTION_UPGRADE_UNIT:
6781  case ACTION_PARADROP:
6782  case ACTION_AIRLIFT:
6783  case ACTION_ATTACK:
6784  case ACTION_SUICIDE_ATTACK:
6785  case ACTION_STRIKE_BUILDING:
6786  case ACTION_STRIKE_PRODUCTION:
6787  case ACTION_CONQUER_CITY:
6788  case ACTION_CONQUER_CITY2:
6789  case ACTION_HEAL_UNIT:
6790  case ACTION_TRANSFORM_TERRAIN:
6791  case ACTION_CULTIVATE:
6792  case ACTION_PLANT:
6793  case ACTION_PILLAGE:
6794  case ACTION_CLEAN_POLLUTION:
6795  case ACTION_CLEAN_FALLOUT:
6796  case ACTION_FORTIFY:
6797  case ACTION_ROAD:
6798  case ACTION_CONVERT:
6799  case ACTION_BASE:
6800  case ACTION_MINE:
6801  case ACTION_IRRIGATE:
6802  case ACTION_TRANSPORT_ALIGHT:
6803  case ACTION_TRANSPORT_BOARD:
6804  case ACTION_TRANSPORT_EMBARK:
6805  case ACTION_TRANSPORT_UNLOAD:
6806  case ACTION_TRANSPORT_DISEMBARK1:
6807  case ACTION_TRANSPORT_DISEMBARK2:
6808  case ACTION_BOMBARD:
6809  case ACTION_BOMBARD2:
6810  case ACTION_BOMBARD3:
6811  case ACTION_NUKE:
6812  case ACTION_SPY_ATTACK:
6813  // Target kind is not ruleset changeable
6814  return nullptr;
6815  case ACTION_USER_ACTION1:
6816  return "user_action_1_target_kind";
6817  case ACTION_USER_ACTION2:
6818  return "user_action_2_target_kind";
6819  case ACTION_USER_ACTION3:
6820  return "user_action_3_target_kind";
6821  case ACTION_COUNT:
6822  break;
6823  }
6824 
6825  fc_assert(act >= 0 && act < ACTION_COUNT);
6826  return nullptr;
6827 }
6828 
6837 {
6838  switch (static_cast<enum gen_action>(act)) {
6839  case ACTION_SPY_POISON:
6840  case ACTION_SPY_POISON_ESC:
6841  case ACTION_SPY_SABOTAGE_UNIT:
6842  case ACTION_SPY_SABOTAGE_UNIT_ESC:
6843  case ACTION_SPY_BRIBE_UNIT:
6844  case ACTION_SPY_SABOTAGE_CITY:
6845  case ACTION_SPY_SABOTAGE_CITY_ESC:
6846  case ACTION_SPY_TARGETED_SABOTAGE_CITY:
6847  case ACTION_SPY_SABOTAGE_CITY_PRODUCTION:
6848  case ACTION_SPY_TARGETED_SABOTAGE_CITY_ESC:
6849  case ACTION_SPY_SABOTAGE_CITY_PRODUCTION_ESC:
6850  case ACTION_SPY_INCITE_CITY:
6851  case ACTION_SPY_INCITE_CITY_ESC:
6852  case ACTION_ESTABLISH_EMBASSY:
6853  case ACTION_ESTABLISH_EMBASSY_STAY:
6854  case ACTION_SPY_STEAL_TECH:
6855  case ACTION_SPY_STEAL_TECH_ESC:
6856  case ACTION_SPY_TARGETED_STEAL_TECH:
6857  case ACTION_SPY_TARGETED_STEAL_TECH_ESC:
6858  case ACTION_SPY_INVESTIGATE_CITY:
6859  case ACTION_INV_CITY_SPEND:
6860  case ACTION_SPY_STEAL_GOLD:
6861  case ACTION_SPY_STEAL_GOLD_ESC:
6862  case ACTION_STEAL_MAPS:
6863  case ACTION_STEAL_MAPS_ESC:
6864  case ACTION_TRADE_ROUTE:
6865  case ACTION_MARKETPLACE:
6866  case ACTION_HELP_WONDER:
6867  case ACTION_CAPTURE_UNITS:
6868  case ACTION_EXPEL_UNIT:
6869  case ACTION_FOUND_CITY:
6870  case ACTION_JOIN_CITY:
6871  case ACTION_SPY_NUKE:
6872  case ACTION_SPY_NUKE_ESC:
6873  case ACTION_NUKE_CITY:
6874  case ACTION_NUKE_UNITS:
6875  case ACTION_DESTROY_CITY:
6876  case ACTION_RECYCLE_UNIT:
6877  case ACTION_DISBAND_UNIT:
6878  case ACTION_HOME_CITY:
6879  case ACTION_UPGRADE_UNIT:
6880  case ACTION_PARADROP:
6881  case ACTION_AIRLIFT:
6882  case ACTION_ATTACK:
6883  case ACTION_SUICIDE_ATTACK:
6884  case ACTION_STRIKE_BUILDING:
6885  case ACTION_STRIKE_PRODUCTION:
6886  case ACTION_CONQUER_CITY:
6887  case ACTION_CONQUER_CITY2:
6888  case ACTION_HEAL_UNIT:
6889  case ACTION_TRANSFORM_TERRAIN:
6890  case ACTION_CULTIVATE:
6891  case ACTION_PLANT:
6892  case ACTION_PILLAGE:
6893  case ACTION_CLEAN_POLLUTION:
6894  case ACTION_CLEAN_FALLOUT:
6895  case ACTION_FORTIFY:
6896  case ACTION_ROAD:
6897  case ACTION_CONVERT:
6898  case ACTION_BASE:
6899  case ACTION_MINE:
6900  case ACTION_IRRIGATE:
6901  case ACTION_TRANSPORT_ALIGHT:
6902  case ACTION_TRANSPORT_BOARD:
6903  case ACTION_TRANSPORT_EMBARK:
6904  case ACTION_TRANSPORT_UNLOAD:
6905  case ACTION_TRANSPORT_DISEMBARK1:
6906  case ACTION_TRANSPORT_DISEMBARK2:
6907  case ACTION_BOMBARD:
6908  case ACTION_BOMBARD2:
6909  case ACTION_BOMBARD3:
6910  case ACTION_NUKE:
6911  case ACTION_SPY_ATTACK:
6912  // actor consuming always is not ruleset changeable
6913  return nullptr;
6914  case ACTION_SPY_SPREAD_PLAGUE:
6915  return "spread_plague_actor_consuming_always";
6916  case ACTION_USER_ACTION1:
6917  return "user_action_1_actor_consuming_always";
6918  case ACTION_USER_ACTION2:
6919  return "user_action_2_actor_consuming_always";
6920  case ACTION_USER_ACTION3:
6921  return "user_action_3_actor_consuming_always";
6922  case ACTION_COUNT:
6923  break;
6924  }
6925 
6926  fc_assert(act >= 0 && act < ACTION_COUNT);
6927  return nullptr;
6928 }
6929 
6942 static bool may_unit_act_vs_city(struct unit *actor, struct city *target,
6943  bool accept_all_actions)
6944 {
6945  if (actor == nullptr || target == nullptr) {
6946  // Can't do any actions if actor or target are missing.
6947  return false;
6948  }
6949 
6950  action_iterate(act)
6951  {
6952  if (!(action_id_get_actor_kind(act) == AAK_UNIT
6953  && action_id_get_target_kind(act) == ATK_CITY)) {
6954  // Not a relevant action.
6955  continue;
6956  }
6957 
6958  if (action_id_is_rare_pop_up(act) && !accept_all_actions) {
6959  // Not relevant since not accepted here.
6960  continue;
6961  }
6962 
6963  if (action_prob_possible(action_prob_vs_city(actor, act, target))) {
6964  /* The actor unit may be able to do this action to the target
6965  * city. */
6966  return true;
6967  }
6968  }
6970 
6971  return false;
6972 }
6973 
6983 struct city *action_tgt_city(struct unit *actor, struct tile *target_tile,
6984  bool accept_all_actions)
6985 {
6986  struct city *target = tile_city(target_tile);
6987 
6988  if (target && may_unit_act_vs_city(actor, target, accept_all_actions)) {
6989  // It may be possible to act against this city.
6990  return target;
6991  }
6992 
6993  return nullptr;
6994 }
6995 
7008 static bool may_unit_act_vs_unit(struct unit *actor, struct unit *target,
7009  bool accept_all_actions)
7010 {
7011  if (actor == nullptr || target == nullptr) {
7012  // Can't do any actions if actor or target are missing.
7013  return false;
7014  }
7015 
7016  action_iterate(act)
7017  {
7018  if (!(action_id_get_actor_kind(act) == AAK_UNIT
7019  && action_id_get_target_kind(act) == ATK_UNIT)) {
7020  // Not a relevant action.
7021  continue;
7022  }
7023 
7024  if (action_id_is_rare_pop_up(act) && !accept_all_actions) {
7025  // Not relevant since not accepted here.
7026  continue;
7027  }
7028 
7029  if (action_prob_possible(action_prob_vs_unit(actor, act, target))) {
7030  /* The actor unit may be able to do this action to the target
7031  * unit. */
7032  return true;
7033  }
7034  }
7036 
7037  return false;
7038 }
7039 
7050 struct unit *action_tgt_unit(struct unit *actor, struct tile *target_tile,
7051  bool accept_all_actions)
7052 {
7053  unit_list_iterate(target_tile->units, target)
7054  {
7055  if (may_unit_act_vs_unit(actor, target, accept_all_actions)) {
7056  return target;
7057  }
7058  }
7060 
7061  return nullptr;
7062 }
7063 
7078 struct tile *action_tgt_tile(struct unit *actor, struct tile *target,
7079  const struct extra_type *target_extra,
7080  bool accept_all_actions)
7081 {
7082  if (actor == nullptr || target == nullptr) {
7083  // Can't do any actions if actor or target are missing.
7084  return nullptr;
7085  }
7086 
7087  action_iterate(act)
7088  {
7089  struct act_prob prob;
7090 
7091  if (action_id_get_actor_kind(act) != AAK_UNIT) {
7092  // Not a relevant action.
7093  continue;
7094  }
7095 
7096  if (action_id_is_rare_pop_up(act) && !accept_all_actions) {
7097  // Not relevant since not accepted here.
7098  continue;
7099  }
7100 
7101  switch (action_id_get_target_kind(act)) {
7102  case ATK_TILE:
7103  prob = action_prob_vs_tile(actor, act, target, target_extra);
7104  break;
7105  case ATK_UNITS:
7106  prob = action_prob_vs_units(actor, act, target);
7107  break;
7108  case ATK_CITY:
7109  case ATK_UNIT:
7110  case ATK_SELF:
7111  // Target not specified by tile.
7112  continue;
7113  case ATK_COUNT:
7114  // Invalid target kind
7115  fc_assert(action_id_get_target_kind(act) != ATK_COUNT);
7116  continue;
7117  }
7118 
7119  if (action_prob_possible(prob)) {
7120  /* The actor unit may be able to do this action to the target
7121  * tile. */
7122  return target;
7123  }
7124  }
7126 
7127  return nullptr;
7128 }
7129 
7142 static bool may_unit_act_vs_tile_extra(const struct unit *actor,
7143  const struct tile *tgt_tile,
7144  const struct extra_type *tgt_extra,
7145  bool accept_all_actions)
7146 {
7147  if (actor == nullptr || tgt_tile == nullptr || tgt_extra == nullptr) {
7148  // Can't do any actions if actor or target are missing.
7149  return false;
7150  }
7151 
7152  action_iterate(act)
7153  {
7154  auto action = action_by_number(act);
7155  if (!(action_get_actor_kind(action) == AAK_UNIT
7156  && action_get_target_kind(action) == ATK_TILE
7158  // Not a relevant action.
7159  continue;
7160  }
7161 
7162  if (action_id_is_rare_pop_up(act) && !accept_all_actions) {
7163  // Not relevant since not accepted here.
7164  continue;
7165  }
7166 
7168  action_prob_vs_tile(actor, act, tgt_tile, tgt_extra))) {
7169  /* The actor unit may be able to do this action to the target
7170  * extra. */
7171  return true;
7172  }
7173  }
7175 
7176  return false;
7177 }
7178 
7191 struct extra_type *action_tgt_tile_extra(const struct unit *actor,
7192  const struct tile *target_tile,
7193  bool accept_all_actions)
7194 {
7196  {
7197  if (may_unit_act_vs_tile_extra(actor, target_tile, target,
7198  accept_all_actions)) {
7199  return target;
7200  }
7201  }
7203 
7204  return nullptr;
7205 }
bool action_removes_extra(const struct action *paction, const struct extra_type *pextra)
Returns TRUE iff the specified action can remove the specified extra.
Definition: actions.cpp:1732
bool is_action_possible_on_city(action_id act_id, const struct player *actor_player, const struct city *target_city)
Returns TRUE if the wanted action can be done to the target city.
Definition: actions.cpp:5734
static struct action * actions[MAX_NUM_ACTIONS]
Definition: actions.cpp:91
static struct req_vec_problem * enabler_tile_tgt_local_diplrel_implies_claimed(const struct action_enabler *enabler)
Detects a local DiplRel requirement in a tile targeted action without an explicit claimed requirement...
Definition: actions.cpp:2048
bool is_action_enabled_unit_on_unit(const action_id wanted_action, const struct unit *actor_unit, const struct unit *target_unit)
Returns TRUE if actor_unit can do wanted_action to target_unit as far as action enablers are concerne...
Definition: actions.cpp:4007
bool action_distance_inside_max(const struct action *action, const int distance)
Returns TRUE iff the specified distance between actor and target is sm,aller or equal to the max rang...
Definition: actions.cpp:1303
static void oblig_hard_req_reg(struct ae_contra_or *contras, const char *error_message,...)
Register an obligatory hard requirement for the specified action results.
Definition: actions.cpp:228
static bool is_enabler_active(const struct action_enabler *enabler, const struct player *actor_player, const struct city *actor_city, const struct impr_type *actor_building, const struct tile *actor_tile, const struct unit *actor_unit, const struct unit_type *actor_unittype, const struct output_type *actor_output, const struct specialist *actor_specialist, const struct player *target_player, const struct city *target_city, const struct impr_type *target_building, const struct tile *target_tile, const struct unit *target_unit, const struct unit_type *target_unittype, const struct output_type *target_output, const struct specialist *target_specialist)
Return TRUE iff the action enabler is active.
Definition: actions.cpp:3813
static void voblig_hard_req_reg(struct ae_contra_or *contras, const char *error_message, va_list args)
Register an obligatory hard requirement for the specified action results.
Definition: actions.cpp:190
const char * action_max_range_ruleset_var_name(int act)
Return max range ruleset variable name for the action or nullptr if max range can't be set in the rul...
Definition: actions.cpp:6528
bool action_mp_full_makes_legal(const struct unit *actor, const action_id act_id)
Returns TRUE if the specified action can't be done now but would have been legal if the unit had full...
Definition: actions.cpp:5817
static struct act_prob act_prob_unseen_target(action_id act_id, const struct unit *actor_unit)
Returns the action probability for when a target is unseen.
Definition: actions.cpp:4428
enum action_actor_kind action_get_actor_kind(const struct action *paction)
Get the actor kind of an action.
Definition: actions.cpp:1188
const char * action_rule_name(const struct action *action)
Get the rule name of the action.
Definition: actions.cpp:1343
static struct action * action_new(action_id id, enum action_result result, enum action_target_kind target_kind, enum action_sub_target_kind sub_target_kind, enum act_tgt_compl tgt_compl, const int min_distance, const int max_distance, bool actor_consuming_always)
Create a new action.
Definition: actions.cpp:1063
void actions_init()
Initialize the actions and the action enablers.
Definition: actions.cpp:934
req_vec_num_in_item action_enabler_vector_number(const void *enabler, const struct requirement_vector *vec)
Returns the requirement vector number of the specified requirement vector in the specified action ena...
Definition: actions.cpp:2302
const QString action_prepare_ui_name(action_id act_id, const char *mnemonic, const struct act_prob prob, const QString &custom)
Get the UI name ready to show the action in the UI.
Definition: actions.cpp:1412
bool action_has_complex_target(const struct action *paction)
Returns TRUE iff the specified action allows the player to provide details in addition to actor and t...
Definition: actions.cpp:1262
struct act_prob action_prob_self(const struct unit *actor_unit, const action_id act_id)
Get the actor unit's probability of successfully performing the chosen action on itself.
Definition: actions.cpp:5145
bool action_prob_possible(const struct act_prob probability)
Returns TRUE iff the given action probability belongs to an action that may be possible.
Definition: actions.cpp:5380
#define ACTPROB_VAL_NOT_IMPL
Definition: actions.cpp:89
struct action_auto_perf auto_perfs[MAX_NUM_ACTION_AUTO_PERFORMERS]
Definition: actions.cpp:92
struct act_prob action_prob_new_certain()
Returns the certain action probability.
Definition: actions.cpp:5339
static struct act_prob action_prob_vs_units_full(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)
Get the actor unit's probability of successfully performing the chosen action on all units at the tar...
Definition: actions.cpp:4884
static bool is_action_enabled(const action_id wanted_action, const struct player *actor_player, const struct city *actor_city, const struct impr_type *actor_building, const struct tile *actor_tile, const struct unit *actor_unit, const struct unit_type *actor_unittype, const struct output_type *actor_output, const struct specialist *actor_specialist, const struct player *target_player, const struct city *target_city, const struct impr_type *target_building, const struct tile *target_tile, const struct unit *target_unit, const struct unit_type *target_unittype, const struct output_type *target_output, const struct specialist *target_specialist, const struct extra_type *target_extra, const struct city *actor_home)
Returns TRUE if the wanted action is enabled.
Definition: actions.cpp:3842
struct extra_type * action_tgt_tile_extra(const struct unit *actor, const struct tile *target_tile, bool accept_all_actions)
Find an extra to target for an action at the specified tile.
Definition: actions.cpp:7191
struct action_enabler * action_enabler_copy(const struct action_enabler *original)
Create a new copy of an existing action enabler.
Definition: actions.cpp:1839
void action_list_end(action_id *act_list, int size)
Terminate an action list of the specified size.
Definition: actions.cpp:5881
struct unit * action_tgt_unit(struct unit *actor, struct tile *target_tile, bool accept_all_actions)
Find a unit to target for an action at the specified tile.
Definition: actions.cpp:7050
#define ACTPROB_VAL_MAX
Definition: actions.cpp:83
struct city * action_tgt_city(struct unit *actor, struct tile *target_tile, bool accept_all_actions)
Find a city to target for an action on the specified tile.
Definition: actions.cpp:6983
static bool is_action_enabled_unit_on_self_full(const action_id wanted_action, const struct unit *actor_unit, const struct city *actor_home, const struct tile *actor_tile)
Returns TRUE if actor_unit can do wanted_action to itself as far as action enablers are concerned.
Definition: actions.cpp:4153
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)
Returns the odds of an action not failing its dice roll.
Definition: actions.cpp:5657
bool is_action_enabled_unit_on_self(const action_id wanted_action, const struct unit *actor_unit)
Returns TRUE if actor_unit can do wanted_action to itself as far as action enablers are concerned.
Definition: actions.cpp:4196
int action_get_act_time(const struct action *paction, const struct unit *actor_unit, const struct tile *tgt_tile, const struct extra_type *tgt_extra)
Returns the unit activity time (work) this action takes (requires) or ACT_TIME_INSTANTANEOUS if the a...
Definition: actions.cpp:1598
bool is_action_enabled_unit_on_city(const action_id wanted_action, const struct unit *actor_unit, const struct city *target_city)
Returns TRUE if actor_unit can do wanted_action to target_city as far as action enablers are concerne...
Definition: actions.cpp:3948
static QString action_prob_to_text(const struct act_prob prob)
Returns a text representation of the action probability prob unless it is a signal.
Definition: actions.cpp:1382
static bool is_target_possible(const action_id wanted_action, const struct player *actor_player, const struct player *target_player, const struct city *target_city, const struct impr_type *target_building, const struct tile *target_tile, const struct unit *target_unit, const struct unit_type *target_unittype, const struct output_type *target_output, const struct specialist *target_specialist)
Returns TRUE if the wanted action can be done to the target.
Definition: actions.cpp:5708
struct req_vec_problem * action_enabler_suggest_repair(const struct action_enabler *enabler)
Returns a suggestion to fix the specified action enabler or nullptr if no fix is found to be needed.
Definition: actions.cpp:2187
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)
Returns the actor unit's probability of successfully performing the specified action against the acti...
Definition: actions.cpp:5163
static bool may_unit_act_vs_city(struct unit *actor, struct city *target, bool accept_all_actions)
Returns TRUE iff, from the point of view of the owner of the actor unit, it looks like the actor unit...
Definition: actions.cpp:6942
struct act_prob action_prob_new_not_relevant()
Returns the n/a action probability.
Definition: actions.cpp:5349
const char * action_ui_name_ruleset_var_name(int act)
Return ui_name ruleset variable name for the action.
Definition: actions.cpp:5919
void actions_free()
Free the actions and the action enablers.
Definition: actions.cpp:994
bool are_action_probabilitys_equal(const struct act_prob *ap1, const struct act_prob *ap2)
Returns TRUE iff ap1 and ap2 are equal.
Definition: actions.cpp:5419
struct act_prob action_prob_vs_city(const struct unit *actor_unit, const action_id act_id, const struct city *target_city)
Get the actor unit's probability of successfully performing the chosen action on the target city.
Definition: actions.cpp:4809
const QString action_prob_explain(const struct act_prob prob)
Explain an action probability in a way suitable for a tool tip for the button that starts it.
Definition: actions.cpp:1504
static bool is_action_enabled_unit_on_units_full(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)
Returns TRUE if actor_unit can do wanted_action to all units on the target_tile as far as action enab...
Definition: actions.cpp:4022
struct act_prob action_prob_vs_unit(const struct unit *actor_unit, const action_id act_id, const struct unit *target_unit)
Get the actor unit's probability of successfully performing the chosen action on the target unit.
Definition: actions.cpp:4871
struct act_prob action_prob_new_not_impl()
Returns the "not implemented" action probability.
Definition: actions.cpp:5359
const char * action_ui_name_default(int act)
Return default ui_name for the action.
Definition: actions.cpp:6087
enum action_battle_kind action_get_battle_kind(const struct action *pact)
Get the battle kind that can prevent an action.
Definition: actions.cpp:1219
struct req_vec_problem * action_enabler_suggest_repair_oblig(const struct action_enabler *enabler)
Returns a suggestion to add an obligatory hard requirement to an action enabler or nullptr if no hard...
Definition: actions.cpp:1902
enum action_sub_target_kind action_get_sub_target_kind(const struct action *paction)
Get the sub target kind of an action.
Definition: actions.cpp:1209
static bool action_prob_not_relevant(const struct act_prob probability)
Returns TRUE iff the given action probability represents the lack of an action probability.
Definition: actions.cpp:5391
void action_enabler_free(struct action_enabler *enabler)
Free resources allocated for the action enabler.
Definition: actions.cpp:1827
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)
Get the actor unit's probability of successfully performing the chosen action on the target tile.
Definition: actions.cpp:5090
static void ae_contra_close(struct ae_contra_or *contra)
Tell an ae_contra_or that one of its users is done with it.
Definition: actions.cpp:171
static enum fc_tristate action_enabled_local(const action_id wanted_action, const struct player *actor_player, const struct city *actor_city, const struct impr_type *actor_building, const struct tile *actor_tile, const struct unit *actor_unit, const struct output_type *actor_output, const struct specialist *actor_specialist, const struct player *target_player, const struct city *target_city, const struct impr_type *target_building, const struct tile *target_tile, const struct unit *target_unit, const struct output_type *target_output, const struct specialist *target_specialist)
Find out if the action is enabled, may be enabled or isn't enabled given what the player owning the a...
Definition: actions.cpp:4220
static void hard_code_oblig_hard_reqs()
Hard code the obligatory hard requirements that don't depend on the rest of the ruleset.
Definition: actions.cpp:269
static struct act_prob action_prob_vs_city_full(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)
Get the actor unit's probability of successfully performing the chosen action on the target city.
Definition: actions.cpp:4741
int action_max_range_default(int act)
Return default max range for the action if it is ruleset settable.
Definition: actions.cpp:6633
static enum fc_tristate tech_can_be_stolen(const struct player *actor_player, const struct player *target_player)
Does the target has any techs the actor don't?
Definition: actions.cpp:4291
struct tile * action_tgt_tile(struct unit *actor, struct tile *target, const struct extra_type *target_extra, bool accept_all_actions)
Returns the tile iff it, from the point of view of the owner of the actor unit, looks like a target t...
Definition: actions.cpp:7078
struct act_prob action_prob_vs_units(const struct unit *actor_unit, const action_id act_id, const struct tile *target_tile)
Get the actor unit's probability of successfully performing the chosen action on all units at the tar...
Definition: actions.cpp:5029
static struct act_prob action_prob_vs_unit_full(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)
Get the actor unit's probability of successfully performing the chosen action on the target unit.
Definition: actions.cpp:4822
int action_number(const struct action *action)
Get the universal number of the action.
Definition: actions.cpp:1338
const char * action_actor_consuming_always_ruleset_var_name(action_id act)
Return actor consuming always ruleset variable name for the action or nullptr if actor consuming alwa...
Definition: actions.cpp:6836
bool is_action_enabled_unit_on_units(const action_id wanted_action, const struct unit *actor_unit, const struct tile *target_tile)
Returns TRUE if actor_unit can do wanted_action to all units on the target_tile as far as action enab...
Definition: actions.cpp:4078
const char * action_min_range_ruleset_var_name(int act)
Return min range ruleset variable name for the action or nullptr if min range can't be set in the rul...
Definition: actions.cpp:6334
bool action_would_be_blocked_by(const struct action *blocked, const struct action *blocker)
Returns TRUE iff blocked will be illegal if blocker is legal.
Definition: actions.cpp:1326
#define ACTPROB_VAL_NA
Definition: actions.cpp:87
static struct obligatory_req_vector obligatory_hard_reqs[ACTRES_NONE]
Definition: actions.cpp:99
struct action * action_by_rule_name(const char *name)
Return the action with the given name.
Definition: actions.cpp:1169
const QString action_name_translation(const struct action *action)
Get the action name used when displaying the action in the UI.
Definition: actions.cpp:1353
static void oblig_hard_req_register(const struct requirement &contradiction, bool is_target, const char *error_message,...)
Register an obligatory hard requirement for the action results it applies to.
Definition: actions.cpp:247
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)
Returns a speculation about the actor unit's probability of successfully performing the chosen action...
Definition: actions.cpp:5303
FC_STATIC_ASSERT(MAP_DISTANCE_MAX<=ACTION_DISTANCE_LAST_NON_SIGNAL, action_range_can_not_cover_the_whole_map)
static struct action * unit_action_new(action_id id, enum action_result result, enum action_target_kind target_kind, enum action_sub_target_kind sub_target_kind, enum act_tgt_compl tgt_compl, 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)
Create a new action performed by a unit actor.
Definition: actions.cpp:1114
static bool action_prob_not_impl(const struct act_prob probability)
Returns TRUE iff the given action probability represents that support for finding this action probabi...
Definition: actions.cpp:5401
bool action_maybe_possible_actor_unit(const action_id act_id, const struct unit *actor_unit)
Returns TRUE if the wanted action (as far as the player knows) can be performed right now by the spec...
Definition: actions.cpp:5765
static bool actions_initialized
Definition: actions.cpp:93
bool action_immune_government(struct government *gov, action_id act)
Will a player with the government gov be immune to the action act?
Definition: actions.cpp:5687
struct action * action_is_blocked_by(const action_id act_id, const struct unit *actor_unit, const struct tile *target_tile_arg, const struct city *target_city_arg, const struct unit *target_unit)
Returns the action that blocks the specified action or nullptr if the specified action isn't blocked.
Definition: actions.cpp:2530
static const struct tile * blocked_find_target_tile(const action_id act_id, const struct unit *actor_unit, const struct tile *target_tile_arg, const struct city *target_city, const struct unit *target_unit)
Returns the target tile for actions that may block the specified action.
Definition: actions.cpp:2434
static bool is_effect_val_known(enum effect_type effect_type, const struct player *pow_player, const struct player *target_player, const struct player *other_player, const struct city *target_city, const struct impr_type *target_building, const struct tile *target_tile, const struct unit *target_unit, const struct output_type *target_output, const struct specialist *target_specialist)
Find out if the effect value is known.
Definition: actions.cpp:4264
static struct req_vec_problem * enabler_first_self_contradiction(const struct action_enabler *enabler)
Returns the first action enabler specific contradiction in the specified enabler or nullptr if no ena...
Definition: actions.cpp:2120
static struct act_prob ap_dipl_battle_win(const struct unit *pattacker, const struct unit *pdefender)
The action probability that pattacker will win a diplomatic battle.
Definition: actions.cpp:4329
static bool action_actor_utype_hard_reqs_ok_full(enum action_result result, const struct unit_type *actor_unittype, bool ignore_third_party)
Returns TRUE if the specified unit type can perform an action with the wanted result given that an ac...
Definition: actions.cpp:2630
static const struct impr_type * tgt_city_local_building(const struct city *target_city)
Returns the local building type of a city target.
Definition: actions.cpp:2387
int action_dice_roll_initial_odds(const struct action *paction)
Returns the initial odds of an action not failing its dice roll.
Definition: actions.cpp:5580
struct act_prob action_prob_fall_back(const struct act_prob *ap1, const struct act_prob *ap2)
Returns ap1 with ap2 as fall back in cases where ap1 doesn't happen.
Definition: actions.cpp:5510
#define obligatory_req_vector_iterate_end
Definition: actions.cpp:71
bool actions_are_ready()
Returns TRUE iff the actions are initialized.
Definition: actions.cpp:1037
static void hard_code_oblig_hard_reqs_ruleset()
Hard code the obligatory hard requirements that needs access to the ruleset before they can be genera...
Definition: actions.cpp:587
static bool plr_sees_tile(const struct player *plr, const struct tile *ttile)
Returns TRUE iff the specified player can see the specified tile.
Definition: actions.cpp:2376
struct requirement_vector * action_enabler_vector_by_number(const void *enabler, req_vec_num_in_item number)
Returns a writable pointer to the specified requirement vector in the action enabler or nullptr if th...
Definition: actions.cpp:2325
void action_list_add_all_by_result(action_id *act_list, int *position, enum action_result result)
Add all actions with the specified result to the specified action list starting at the specified posi...
Definition: actions.cpp:5898
static struct act_prob action_prob_self_full(const struct unit *actor_unit, const struct city *actor_home, const struct tile *actor_tile, const action_id act_id)
Get the actor unit's probability of successfully performing the chosen action on itself.
Definition: actions.cpp:5104
struct act_prob action_speculate_unit_on_units(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)
Returns a speculation about the actor unit's probability of successfully performing the chosen action...
Definition: actions.cpp:5243
bool action_univs_not_blocking(const struct action *paction, struct universal *actor_uni, struct universal *target_uni)
Is there any action enablers of the given type not blocked by universals?
Definition: actions.cpp:5856
static const struct unit_type * tgt_city_local_utype(const struct city *target_city)
Returns the local unit type of a city target.
Definition: actions.cpp:2410
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)
Returns a speculation about the actor unit's probability of successfully performing the chosen action...
Definition: actions.cpp:5213
bool is_action_enabled_unit_on_tile(const action_id wanted_action, const struct unit *actor_unit, const struct tile *target_tile, const struct extra_type *target_extra)
Returns TRUE if actor_unit can do wanted_action to the target_tile as far as action enablers are conc...
Definition: actions.cpp:4136
static struct act_prob action_prob(const action_id wanted_action, const struct player *actor_player, const struct city *actor_city, const struct impr_type *actor_building, const struct tile *actor_tile, const struct unit *actor_unit, const struct unit_type *actor_unittype_p, const struct output_type *actor_output, const struct specialist *actor_specialist, const struct city *actor_home, const struct player *target_player, const struct city *target_city, const struct impr_type *target_building, const struct tile *target_tile, const struct unit *target_unit, const struct unit_type *target_unittype_p, const struct output_type *target_output, const struct specialist *target_specialist, const struct extra_type *target_extra)
An action's probability of success.
Definition: actions.cpp:4448
const struct action_auto_perf * action_auto_perf_by_number(const int num)
Returns action auto performer rule number num.
Definition: actions.cpp:5848
const QString action_id_name_translation(action_id act_id)
Get the action name used when displaying the action in the UI.
Definition: actions.cpp:1373
#define obligatory_req_vector_iterate(obreq_vec, pobreq)
Definition: actions.cpp:69
const char * action_target_kind_ruleset_var_name(int act)
Return target kind ruleset variable name for the action or nullptr if min range can't be set in the r...
Definition: actions.cpp:6736
struct action_enabler * action_enabler_new()
Create a new action enabler.
Definition: actions.cpp:1810
static struct action_enabler_list * action_enablers_by_action[MAX_NUM_ACTIONS]
Definition: actions.cpp:95
void action_enabler_add(struct action_enabler *enabler)
Add an action enabler to the current ruleset.
Definition: actions.cpp:1854
static struct requirement * req_vec_first_contradiction_in_vec(const struct requirement *req, const struct requirement_vector *vec)
Returns the first requirement in the specified requirement vector that contradicts the specified requ...
Definition: actions.cpp:2023
struct action * action_by_number(action_id act_id)
Return the action with the given id.
Definition: actions.cpp:1149
enum unit_activity action_get_activity(const struct action *paction)
Returns the unit activity this action may cause or ACTIVITY_LAST if the action doesn't result in a un...
Definition: actions.cpp:1557
#define ACTPROB_VAL_1_PCT
Definition: actions.cpp:85
bool action_actor_utype_hard_reqs_ok(enum action_result result, const struct unit_type *actor_unittype)
Returns TRUE if the specified unit type can perform an action with the wanted result given that an ac...
Definition: actions.cpp:2776
bool action_requires_details(const struct action *paction)
Returns TRUE iff the specified action REQUIRES the player to provide details in addition to actor and...
Definition: actions.cpp:1275
static struct ae_contra_or * req_contradiction_or(int alternatives,...)
Returns a new array of alternative action enabler contradictions.
Definition: actions.cpp:143
int action_get_role(const struct action *paction)
Get the unit type role corresponding to the ability to do the specified action.
Definition: actions.cpp:1544
int action_min_range_default(int act)
Return default min range for the action if it is ruleset settable.
Definition: actions.cpp:6430
static const struct city * blocked_find_target_city(const action_id act_id, const struct unit *actor_unit, const struct tile *target_tile, const struct city *target_city_arg, const struct unit *target_unit)
Returns the target city for actions that may block the specified action.
Definition: actions.cpp:2482
struct req_vec_problem * action_enabler_suggest_improvement(const struct action_enabler *enabler)
Returns a suggestion to improve the specified action enabler or nullptr if nothing to improve is foun...
Definition: actions.cpp:2251
struct act_prob action_prob_new_impossible()
Returns the impossible action probability.
Definition: actions.cpp:5329
bool action_id_exists(const action_id act_id)
Returns TRUE iff the specified action ID refers to a valid action.
Definition: actions.cpp:1138
static bool may_unit_act_vs_unit(struct unit *actor, struct unit *target, bool accept_all_actions)
Returns TRUE iff, from the point of view of the owner of the actor unit, it looks like the actor unit...
Definition: actions.cpp:7008
static struct requirement * req_vec_first_local_diplrel(const struct requirement_vector *vec)
Returns the first local DiplRel requirement in the specified requirement vector or nullptr if it does...
Definition: actions.cpp:2001
bool action_enabler_remove(struct action_enabler *enabler)
Remove an action enabler from the current ruleset.
Definition: actions.cpp:1870
enum action_target_kind action_get_target_kind(const struct action *paction)
Get the target kind of an action.
Definition: actions.cpp:1198
static bool is_action_enabled_unit_on_city_full(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)
Returns TRUE if actor_unit can do wanted_action to target_city as far as action enablers are concerne...
Definition: actions.cpp:3898
bool action_has_result(const struct action *paction, enum action_result result)
Returns TRUE iff performing the specified action has the specified result.
Definition: actions.cpp:1248
static bool action_prob_is_signal(const struct act_prob probability)
Returns TRUE iff the given action probability represents a special signal value rather than a regular...
Definition: actions.cpp:5411
static struct act_prob ap_diplomat_battle(const struct unit *pattacker, const struct unit *pvictim, const struct tile *tgt_tile)
The action probability that pattacker will win a diplomatic battle.
Definition: actions.cpp:4401
const char * action_enabler_vector_by_number_name(req_vec_num_in_item vec)
Returns the name of the given requirement vector number n in an action enabler or nullptr if enablers...
Definition: actions.cpp:2349
static bool plr_knows_tile(const struct player *plr, const struct tile *ttile)
Returns TRUE iff the specified player knows (has seen) the specified tile.
Definition: actions.cpp:2367
bool action_creates_extra(const struct action *paction, const struct extra_type *pextra)
Returns TRUE iff the specified action can create the specified extra.
Definition: actions.cpp:1649
void actions_rs_pre_san_gen()
Generate action related data based on the currently loaded ruleset.
Definition: actions.cpp:984
int action_prob_cmp_pessimist(const struct act_prob ap1, const struct act_prob ap2)
Compare action probabilities.
Definition: actions.cpp:5428
static bool is_action_enabled_unit_on_tile_full(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)
Returns TRUE if actor_unit can do wanted_action to the target_tile as far as action enablers are conc...
Definition: actions.cpp:4093
bool action_id_is_rare_pop_up(action_id act_id)
Returns TRUE iff a unit's ability to perform this action will pop up the action selection dialog befo...
Definition: actions.cpp:1290
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)
Returns a speculation about the actor unit's probability of successfully performing the chosen action...
Definition: actions.cpp:5273
static enum fc_tristate action_hard_reqs_actor(enum action_result result, const struct player *actor_player, const struct city *actor_city, const struct impr_type *actor_building, const struct tile *actor_tile, const struct unit *actor_unit, const struct unit_type *actor_unittype, const struct output_type *actor_output, const struct specialist *actor_specialist, const bool omniscient, const struct city *homecity)
Returns TRUE iff the wanted action is possible as far as the actor is concerned given that an action ...
Definition: actions.cpp:2790
static struct req_vec_problem * enabler_first_clarification(const struct action_enabler *enabler)
Returns the first action enabler specific clarification possibility in the specified enabler or nullp...
Definition: actions.cpp:2232
struct action_auto_perf * action_auto_perf_slot_number(const int num)
Returns action auto performer rule slot number num so it can be filled.
Definition: actions.cpp:5832
double action_prob_to_0_to_1_pessimist(const struct act_prob ap)
Returns double in the range [0-1] representing the minimum of the given action probability.
Definition: actions.cpp:5479
struct act_prob action_prob_new_unknown()
Returns the "user don't know" action probability.
Definition: actions.cpp:5369
static struct act_prob action_prob_vs_tile_full(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)
Get the actor unit's probability of successfully performing the chosen action on the target tile.
Definition: actions.cpp:5042
const char * action_id_rule_name(action_id act_id)
Get the rule name of the action.
Definition: actions.cpp:1362
bool is_action_possible_on_unit(action_id act_id, const unit *target_unit)
Checks if there is any hopes that the action is possible against the target unit (by chacking the tar...
Definition: actions.cpp:5752
static enum fc_tristate is_action_possible(const action_id wanted_action, const struct player *actor_player, const struct city *actor_city, const struct impr_type *actor_building, const struct tile *actor_tile, const struct unit *actor_unit, const struct unit_type *actor_unittype, const struct output_type *actor_output, const struct specialist *actor_specialist, const struct player *target_player, const struct city *target_city, const struct impr_type *target_building, const struct tile *target_tile, const struct unit *target_unit, const struct unit_type *target_unittype, const struct output_type *target_output, const struct specialist *target_specialist, const struct extra_type *target_extra, const bool omniscient, const struct city *homecity)
Returns if the wanted action is possible given that an action enabler later will enable it.
Definition: actions.cpp:2958
bool action_distance_accepted(const struct action *action, const int distance)
Returns TRUE iff the specified distance between actor and target is within the range acceptable to th...
Definition: actions.cpp:1314
static void hard_code_actions()
Hard code the actions.
Definition: actions.cpp:607
struct action_enabler_list * action_enablers_for_action(action_id action)
Get all enablers for an action in the current ruleset.
Definition: actions.cpp:1884
static bool is_action_enabled_unit_on_unit_full(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)
Returns TRUE if actor_unit can do wanted_action to target_unit as far as action enablers are concerne...
Definition: actions.cpp:3963
static bool may_unit_act_vs_tile_extra(const struct unit *actor, const struct tile *tgt_tile, const struct extra_type *tgt_extra, bool accept_all_actions)
Returns TRUE iff, from the point of view of the owner of the actor unit, it looks like the actor unit...
Definition: actions.cpp:7142
#define ACTPROB_VAL_MIN
Definition: actions.cpp:81
#define ACTION_DISTANCE_MAX
Definition: actions.h:281
#define ACTPROB_CERTAIN
Definition: actions.h:733
#define ACTPROB_NA
Definition: actions.h:734
#define ACTION_DISTANCE_LAST_NON_SIGNAL
Definition: actions.h:277
#define action_enabler_list_iterate_end
Definition: actions.h:376
#define ACTION_DISTANCE_UNLIMITED
Definition: actions.h:279
#define action_iterate_end
Definition: actions.h:383
#define MAX_NUM_ACTIONS
Definition: actions.h:223
#define action_id_would_be_blocked_by(blocked_id, blocker_id)
Definition: actions.h:575
#define action_id_get_actor_kind(act_id)
Definition: actions.h:519
#define ACTPROB_NOT_KNOWN
Definition: actions.h:736
#define action_enabler_list_iterate(action_enabler_list, aenabler)
Definition: actions.h:374
#define action_id_distance_accepted(act_id, distance)
Definition: actions.h:565
#define ACTPROB_IMPOSSIBLE
Definition: actions.h:732
#define ACTPROB_NOT_IMPLEMENTED
Definition: actions.h:735
#define action_iterate(_act_)
Definition: actions.h:378
#define ACTION_ANY
Definition: actions.h:217
#define action_id_get_target_kind(act_id)
Definition: actions.h:522
#define action_id_has_result_safe(act_id, result)
Definition: actions.h:537
#define ACTION_ODDS_PCT_DICE_ROLL_NA
Definition: actions.h:739
#define ACTION_NONE
Definition: actions.h:220
bool can_build_base(const struct unit *punit, const struct base_type *pbase, const struct tile *ptile)
Can unit build base to given tile?
Definition: base.cpp:101
#define BV_CLR_ALL(bv)
Definition: bitvector.h:62
#define BV_SET(bv, bit)
Definition: bitvector.h:44
bool BV_ISSET(const BV &bv, int bit)
Definition: bitvector.h:37
#define BV_ISSET_ANY(vec)
Definition: bitvector.h:76
bool citymindist_prevents_city_on_tile(const struct tile *ptile)
Returns TRUE iff it is illegal to found a city on the specified tile because of citymindist.
Definition: city.cpp:1401
int city_production_build_shield_cost(const struct city *pcity)
Return the number of shields it takes to build current city production.
Definition: city.cpp:701
struct city * is_non_allied_city_tile(const struct tile *ptile, const struct player *pplayer)
Is there an non_allied city on this tile?
Definition: city.cpp:1968
struct player * city_owner(const struct city *pcity)
Return the owner of the city.
Definition: city.cpp:1083
struct city * is_non_attack_city_tile(const struct tile *ptile, const struct player *pplayer)
Is there an enemy city on this tile?
Definition: city.cpp:1953
int city_unit_slots_available(const struct city *pcity)
Return number of free unit slots in a city.
Definition: city.cpp:987
struct tile * city_tile(const struct city *pcity)
Return the tile location of the city.
Definition: city.cpp:1095
bool city_can_grow_to(const struct city *pcity, int pop_size)
Return TRUE iff the city can grow to the given size.
Definition: city.cpp:1914
citizens city_size_get(const struct city *pcity)
Get the city size.
Definition: city.cpp:1101
struct unit * get_defender(const struct unit *attacker, const struct tile *ptile)
Finds the best defender on the tile, given an attacker.
Definition: combat.cpp:721
enum unit_attack_result unit_attack_units_at_tile_result(const struct unit *punit, const struct tile *ptile)
Check if unit can attack unit stack at tile.
Definition: combat.cpp:237
struct unit * get_diplomatic_defender(const struct unit *act_unit, const struct unit *pvictim, const struct tile *tgt_tile)
Returns the defender of the tile in a diplomatic battle or nullptr if no diplomatic defender could be...
Definition: combat.cpp:792
double unit_win_chance(const struct unit *attacker, const struct unit *defender)
Returns a double in the range [0;1] indicating the attackers chance of winning.
Definition: combat.cpp:408
bool can_unit_attack_tile(const struct unit *punit, const struct tile *dest_tile)
Is unit (1) diplomatically allowed to attack and (2) physically able to do so?
Definition: combat.cpp:251
@ ATT_OK
Definition: combat.h:26
int get_target_bonus_effects(struct effect_list *plist, const struct player *target_player, const struct player *other_player, const struct city *target_city, const struct impr_type *target_building, const struct tile *target_tile, const struct unit *target_unit, const struct unit_type *target_unittype, const struct output_type *target_output, const struct specialist *target_specialist, const struct action *target_action, enum effect_type effect_type, enum vision_layer vision_layer, enum national_intelligence nintel)
Returns the effect bonus of a given type for any target.
Definition: effects.cpp:611
struct @19::@20 reqs
const effect_list * get_effects()
Get a list of all effects.
Definition: effects.cpp:117
#define effect_list_iterate_end
Definition: effects.h:349
#define effect_list_iterate(effect_list, peffect)
Definition: effects.h:347
struct extra_type * prev_extra_in_tile(const struct tile *ptile, enum extra_rmcause rmcause, const struct player *pplayer, const struct unit *punit)
Returns prev extra by cause that unit or player can remove from tile.
Definition: extras.cpp:732
bool can_remove_extra(const struct extra_type *pextra, const struct unit *punit, const struct tile *ptile)
Tells if unit can remove extra from tile.
Definition: extras.cpp:543
bool is_extra_removed_by(const struct extra_type *pextra, enum extra_rmcause rmcause)
Is given cause one of the removal causes for the given extra?
Definition: extras.cpp:307
bool can_build_extra(const struct extra_type *pextra, const struct unit *punit, const struct tile *ptile)
Tells if unit can build extra on tile.
Definition: extras.cpp:475
#define extra_type_iterate(_p)
Definition: extras.h:279
#define extra_deps_iterate(_reqs, _dep)
Definition: extras.h:335
#define extra_type_iterate_end
Definition: extras.h:285
#define is_extra_caused_by(e, c)
Definition: extras.h:182
#define extra_index(_e_)
Definition: extras.h:163
#define extra_deps_iterate_end
Definition: extras.h:343
#define extra_type_re_active_iterate_end
Definition: extras.h:294
#define extra_base_get(_e_)
Definition: extras.h:170
#define extra_road_get(_e_)
Definition: extras.h:171
#define extra_type_re_active_iterate(_p)
Definition: extras.h:289
const struct functions * fc_funcs
int Tech_type_id
Definition: fc_types.h:294
#define ACT_TIME_INSTANTANEOUS
Definition: fc_types.h:266
@ RPT_CERTAIN
Definition: fc_types.h:568
@ RPT_POSSIBLE
Definition: fc_types.h:567
int action_id
Definition: fc_types.h:306
#define MAX_NUM_ACTION_AUTO_PERFORMERS
Definition: fc_types.h:48
#define _(String)
Definition: fcintl.h:50
#define N_(String)
Definition: fcintl.h:52
struct civ_game game
Definition: game.cpp:47
struct world wld
Definition: game.cpp:48
struct city * game_city_by_number(int id)
Often used function to get a city pointer from a city ID.
Definition: game.cpp:103
#define RS_DEFAULT_EXPLODE_NUCLEAR_MAX_RANGE
Definition: game.h:831
#define RS_DEFAULT_ACTION_MIN_RANGE
Definition: game.h:829
#define RS_DEFAULT_ACTION_MAX_RANGE
Definition: game.h:830
const char * name
Definition: inputfile.cpp:118
#define fc_assert_msg(condition, message,...)
Definition: log.h:96
#define fc_assert_ret(condition)
Definition: log.h:112
#define fc_assert(condition)
Definition: log.h:89
#define fc_assert_ret_msg(condition, message,...)
Definition: log.h:129
#define fc_assert_action_msg(condition, action, message,...)
Definition: log.h:121
#define fc_assert_ret_val(condition, val)
Definition: log.h:114
#define fc_assert_action(condition, action)
Definition: log.h:104
#define fc_assert_ret_val_msg(condition, val, message,...)
Definition: log.h:132
bv_extras get_tile_infrastructure_set(const struct tile *ptile, int *pcount)
Return a bitfield of the extras on the tile that are infrastructure.
Definition: map.cpp:72
bool terrain_surroundings_allow_change(const struct tile *ptile, const struct terrain *pterrain)
Returns FALSE if a terrain change to 'pterrain' would be prevented by not having enough similar terra...
Definition: map.cpp:706
int real_map_distance(const struct tile *tile0, const struct tile *tile1)
Return real distance between two tiles.
Definition: map.cpp:599
#define MAP_DISTANCE_MAX
Definition: map.h:536
#define square_iterate(nmap, center_tile, radius, tile_itr)
Definition: map.h:312
#define square_iterate_end
Definition: map.h:315
bool can_see_techs_of_target(const struct player *pow_player, const struct player *target_player)
Can pow_player see the techs of target player?
enum fc_tristate mke_eval_reqs(const struct player *pow_player, const struct player *target_player, const struct player *other_player, const struct city *target_city, const struct impr_type *target_building, const struct tile *target_tile, const struct unit *target_unit, const struct output_type *target_output, const struct specialist *target_specialist, const struct requirement_vector *reqs, const enum req_problem_type prob_type)
Evaluate a requirement vector given pow_player's knowledge.
bool can_unit_exist_at_tile(const struct civ_map *nmap, const struct unit *punit, const struct tile *ptile)
Return TRUE iff the unit can "exist" at this location.
Definition: movement.cpp:267
int unit_move_rate(const struct unit *punit)
This function calculates the move rate of the unit.
Definition: movement.cpp:78
bool unit_could_load_at(const struct unit *punit, const struct tile *ptile)
Return whether we could find a suitable transporter for given unit at 'ptile'.
Definition: movement.cpp:743
bool unit_can_move_to_tile(const struct civ_map *nmap, const struct unit *punit, const struct tile *dst_tile, bool igzoc, bool enter_enemy_city)
Returns whether the unit can move from its current tile to the destination tile.
Definition: movement.cpp:531
bool can_unit_type_transport(const struct unit_type *transporter, const struct unit_class *transported)
Return TRUE iff transporter type has ability to transport transported class.
Definition: movement.cpp:698
std::vector< nation_type > nations
Definition: nation.cpp:38
Nation_type_id nation_index(const struct nation_type *pnation)
Return the nation index.
Definition: nation.cpp:464
enum barbarian_type nation_barbarian_type(const struct nation_type *nation)
Returns which kind of barbarians can use this nation.
Definition: nation.cpp:188
bool can_player_see_unit(const struct player *pplayer, const struct unit *punit)
Checks if a unit can be seen by pplayer at its current location.
Definition: player.cpp:1016
bool pplayers_at_war(const struct player *pplayer, const struct player *pplayer2)
Returns true iff players can attack each other.
Definition: player.cpp:1317
bool player_can_see_city_externals(const struct player *pow_player, const struct city *target_city)
Returns TRUE iff pow_player can see externally visible features of target_city.
Definition: player.cpp:1074
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Returns true iff players are allied.
Definition: player.cpp:1334
bool can_player_see_hypotetic_units_at(const struct player *pplayer, const struct tile *ptile)
Check if pplayer could see all units on ptile if it had units.
Definition: player.cpp:917
bool pplayers_non_attack(const struct player *pplayer, const struct player *pplayer2)
Returns true iff players have peace, cease-fire, or armistice.
Definition: player.cpp:1388
bool can_player_see_city_internals(const struct player *pplayer, const struct city *pcity)
Return TRUE iff the player can see the city's internals.
Definition: player.cpp:1060
bool universal_fulfills_requirements(bool check_necessary, const struct requirement_vector *reqs, const struct universal *source)
Will the universal 'source' fulfill the requirements in the list? If 'check_necessary' is FALSE: are ...
struct req_vec_problem * req_vec_problem_new(int num_suggested_solutions, const char *descr,...)
Returns a new requirement vector problem with the specified number of suggested solutions and the spe...
struct req_vec_problem * req_vec_get_first_contradiction(const struct requirement_vector *vec, requirement_vector_number get_num, const void *parent_item)
Returns the first self contradiction found in the specified requirement vector with suggested solutio...
struct requirement req_from_values(int type, int range, bool survives, bool present, bool quiet, int value)
Set the values of a req from serializable integers.
bool are_reqs_active(const struct player *target_player, const struct player *other_player, const struct city *target_city, const struct impr_type *target_building, const struct tile *target_tile, const struct unit *target_unit, const struct unit_type *target_unittype, const struct output_type *target_output, const struct specialist *target_specialist, const struct action *target_action, const struct requirement_vector *reqs, const enum req_problem_type prob_type, const enum vision_layer vision_layer, const enum national_intelligence nintel)
Checks the requirement(s) to see if they are active on the given target.
QString req_to_fstring(const struct requirement *req)
Returns the given requirement as a formatted string ready for printing.
bool are_requirements_contradictions(const struct requirement *req1, const struct requirement *req2)
Returns TRUE if req1 and req2 contradicts each other.
bool does_req_contradicts_reqs(const struct requirement *req, const struct requirement_vector *vec)
Returns TRUE if the given requirement contradicts the given requirement vector.
#define requirement_fulfilled_by_unit_type(_ut_, _rqs_)
Definition: requirements.h:306
signed char req_vec_num_in_item
req_vec_num_in_item a requirement vectors number in an item.
Definition: requirements.h:143
#define requirement_vector_iterate_end
Definition: requirements.h:80
#define requirement_fulfilled_by_government(_gov_, _rqs_)
Definition: requirements.h:283
#define requirement_vector_iterate(req_vec, preq)
Definition: requirements.h:78
struct research * research_get(const struct player *pplayer)
Returns the research structure associated with the player.
Definition: research.cpp:110
enum tech_state research_invention_state(const struct research *presearch, Tech_type_id tech)
Returns state of the tech for current research.
Definition: research.cpp:609
bool research_invention_gettable(const struct research *presearch, const Tech_type_id tech, bool allow_holes)
Returns TRUE iff the given tech can be given to the players sharing the research immediately.
Definition: research.cpp:686
bool can_build_road(struct road_type *proad, const struct unit *punit, const struct tile *ptile)
Tells if unit can build road on tile.
Definition: road.cpp:275
server_setting_id server_setting_by_name(const char *name)
Returns the server setting with the specified name.
int server_setting_value_int_get(server_setting_id id)
Returns the value of the server setting with the specified id.
enum fc_tristate fc_tristate_and(enum fc_tristate one, enum fc_tristate two)
An AND function for fc_tristate.
Definition: shared.cpp:98
fc_tristate
Definition: shared.h:42
@ TRI_YES
Definition: shared.h:42
@ TRI_NO
Definition: shared.h:42
@ TRI_MAYBE
Definition: shared.h:42
#define CLIP(lower, current, upper)
Definition: shared.h:51
#define BOOL_TO_TRISTATE(tri)
Definition: shared.h:43
#define MIN(x, y)
Definition: shared.h:49
#define MAX(x, y)
Definition: shared.h:48
size_t size
Definition: specvec.h:64
int max
Definition: fc_types.h:1060
int min
Definition: fc_types.h:1059
enum action_auto_perf_cause cause
Definition: actions.h:457
action_id alternatives[MAX_NUM_ACTIONS]
Definition: actions.h:465
struct requirement req
Definition: actions.cpp:37
bool disabled
Definition: actions.h:363
action_id action
Definition: actions.h:364
struct requirement_vector actor_reqs
Definition: actions.h:365
struct requirement_vector target_reqs
Definition: actions.h:366
struct action::@10::@11 is_unit
bool unitwaittime_controlled
Definition: actions.h:353
action_id id
Definition: actions.h:306
bool actor_consuming_always
Definition: actions.h:337
bool rare_pop_up
Definition: actions.h:350
int max_distance
Definition: actions.h:320
bool quiet
Definition: actions.h:327
enum action_sub_target_kind sub_target_kind
Definition: actions.h:312
enum moves_actor_kind moves_actor
Definition: actions.h:357
enum action_result result
Definition: actions.h:308
char ui_name[MAX_LEN_NAME]
Definition: actions.h:323
union action::@10 actor
enum action_actor_kind actor_kind
Definition: actions.h:310
enum act_tgt_compl target_complexity
Definition: actions.h:315
bv_actions blocked_by
Definition: actions.h:331
enum action_target_kind target_kind
Definition: actions.h:311
int min_distance
Definition: actions.h:320
struct action_enabler_contradiction * alternative
Definition: actions.cpp:49
int alternatives
Definition: actions.cpp:46
Definition: city.h:291
int id
Definition: city.h:296
int airlift
Definition: city.h:349
struct universal production
Definition: city.h:368
struct tile * tile
Definition: city.h:293
int shield_stock
Definition: city.h:339
struct packet_game_info info
Definition: game.h:80
struct packet_scenario_info scenario
Definition: game.h:78
bool buildable
Definition: extras.h:100
int(* player_tile_city_id_get)(const struct tile *ptile, const struct player *pplayer)
Definition: fc_interface.h:42
struct ae_contra_or * contras
Definition: actions.cpp:59
const char * error_msg
Definition: actions.cpp:63
Definition: player.h:231
struct player_economic economic
Definition: player.h:266
req_vec_num_in_item vector_number
Definition: requirements.h:194
enum req_vec_change_operation operation
Definition: requirements.h:191
struct requirement req
Definition: requirements.h:192
struct req_vec_change * suggested_solutions
Definition: requirements.h:204
enum req_range range
Definition: requirements.h:69
struct universal source
Definition: requirements.h:68
int clean_fallout_time
Definition: terrain.h:213
struct terrain * irrigation_result
Definition: terrain.h:200
int pillage_time
Definition: terrain.h:214
struct terrain * mining_result
Definition: terrain.h:204
int mining_time
Definition: terrain.h:206
int clean_pollution_time
Definition: terrain.h:212
struct terrain * transform_result
Definition: terrain.h:210
int irrigation_time
Definition: terrain.h:202
Definition: tile.h:42
struct unit_list * units
Definition: tile.h:50
int transport_capacity
Definition: unittype.h:488
int convert_time
Definition: unittype.h:496
struct veteran_system * veteran
Definition: unittype.h:509
const struct unit_type * obsoleted_by
Definition: unittype.h:494
int bombard_rate
Definition: unittype.h:512
int city_slots
Definition: unittype.h:517
int hp
Definition: unittype.h:489
const struct unit_type * converted_to
Definition: unittype.h:495
int attack_strength
Definition: unittype.h:479
Definition: unit.h:134
int hp
Definition: unit.h:148
struct extra_type * activity_target
Definition: unit.h:161
int homecity
Definition: unit.h:142
bool paradropped
Definition: unit.h:171
const struct unit_type * utype
Definition: unit.h:135
enum universals_n kind
Definition: fc_types.h:740
universals_u value
Definition: fc_types.h:739
int power_fact
Definition: unittype.h:453
struct civ_map map
Definition: world_object.h:21
int fc_strcasecmp(const char *str0, const char *str1)
Compare strings like strcmp(), but ignoring case.
Definition: support.cpp:89
Tech_type_id advance_number(const struct advance *padvance)
Return the advance index.
Definition: tech.cpp:85
#define advance_iterate(_start, _p)
Definition: tech.h:232
#define A_FIRST
Definition: tech.h:37
#define advance_iterate_end
Definition: tech.h:238
struct extra_type * get_preferred_pillage(bv_extras extras)
Returns the highest-priority (best) extra to be pillaged from the terrain set.
Definition: terrain.cpp:439
#define T_NONE
Definition: terrain.h:50
#define terrain_has_flag(terr, flag)
Definition: terrain.h:260
bool tile_is_seen(const struct tile *target_tile, const struct player *pow_player)
Returns TRUE iff the target_tile is seen by pow_player.
Definition: tile.cpp:416
int tile_activity_time(enum unit_activity activity, const struct tile *ptile, const struct extra_type *tgt)
Time to complete the given activity on the given tile.
Definition: tile.cpp:427
enum known_type tile_get_known(const struct tile *ptile, const struct player *pplayer)
Return a known_type enumeration value for the tile.
Definition: tile.cpp:398
struct city * tile_city(const struct tile *ptile)
Return the city on this tile (or nullptr), checking for city center.
Definition: tile.cpp:72
@ TILE_UNKNOWN
Definition: tile.h:29
@ TILE_KNOWN_SEEN
Definition: tile.h:31
#define ACTIVITY_FACTOR
Definition: tile.h:151
#define tile_terrain(_tile)
Definition: tile.h:93
#define tile_has_extra(ptile, pextra)
Definition: tile.h:130
#define tile_owner(_tile)
Definition: tile.h:78
bool can_cities_trade(const struct city *pc1, const struct city *pc2)
Return TRUE iff the two cities are capable of trade; i.e., if a caravan from one city can enter the o...
bool can_establish_trade_route(const struct city *pc1, const struct city *pc2)
Returns TRUE iff the two cities can establish a trade route.
const struct unit_type * utype
Definition: fc_types.h:585
enum citytile_type citytile
Definition: fc_types.h:594
const struct impr_type * building
Definition: fc_types.h:579
enum unit_upgrade_result unit_upgrade_test(const struct unit *punit, bool is_free)
Tests if the unit could be updated.
Definition: unit.cpp:1826
struct unit * is_non_allied_unit_tile(const struct tile *ptile, const struct player *pplayer)
Is there an non-allied unit on this tile?
Definition: unit.cpp:1252
struct unit * unit_transport_get(const struct unit *pcargo)
Returns the transporter of the unit or nullptr if it is not transported.
Definition: unit.cpp:2189
bool unit_contained_in(const struct unit *pcargo, const struct unit *ptrans)
Returns whether 'pcargo' is transported by 'ptrans', either directly or indirectly.
Definition: unit.cpp:2274
bool could_unit_load(const struct unit *pcargo, const struct unit *ptrans)
Return TRUE iff the given unit could be loaded into the transporter if we moved there.
Definition: unit.cpp:646
bool unit_can_do_action(const struct unit *punit, const action_id act_id)
Return TRUE iff this unit can do the specified generalized (ruleset defined) action enabler controlle...
Definition: unit.cpp:309
bool unit_can_convert(const struct unit *punit)
Tests if unit can be converted to another type.
Definition: unit.cpp:1877
bv_extras get_unit_tile_pillage_set(const struct tile *ptile)
Return a mask of the extras which are actively (currently) being pillaged on the given tile.
Definition: unit.cpp:1063
int get_transporter_capacity(const struct unit *punit)
Return the number of units the transporter can hold (or 0).
Definition: unit.cpp:280
enum unit_airlift_result test_unit_can_airlift_to(const struct player *restriction, const struct unit *punit, const struct city *pdest_city)
Determines if punit can be airlifted to dest_city now! So punit needs to be in a city now.
Definition: unit.cpp:75
bool unit_transported(const struct unit *pcargo)
Returns TRUE iff the unit is transported.
Definition: unit.cpp:2176
bool can_unit_unload(const struct unit *pcargo, const struct unit *ptrans)
Return TRUE iff the given unit can be unloaded from its current transporter.
Definition: unit.cpp:720
#define unit_tile(_pu)
Definition: unit.h:371
#define unit_owner(_pu)
Definition: unit.h:370
@ UU_OK
Definition: unit.h:49
#define unit_home(_pu_)
Definition: unit.h:369
@ AR_SRC_NO_FLIGHTS
Definition: unit.h:71
@ AR_OK_SRC_UNKNOWN
Definition: unit.h:62
@ AR_OK_DST_UNKNOWN
Definition: unit.h:63
@ AR_NO_MOVES
Definition: unit.h:65
@ AR_BAD_DST_CITY
Definition: unit.h:70
@ AR_NOT_IN_CITY
Definition: unit.h:68
@ AR_OCCUPIED
Definition: unit.h:67
@ AR_OK
Definition: unit.h:61
@ AR_DST_NO_FLIGHTS
Definition: unit.h:72
@ AR_WRONG_UNITTYPE
Definition: unit.h:66
@ AR_BAD_SRC_CITY
Definition: unit.h:69
#define unit_list_iterate(unitlist, punit)
Definition: unitlist.h:25
#define unit_list_iterate_end
Definition: unitlist.h:27
const struct unit_type * unit_type_get(const struct unit *punit)
Return the unit type for this unit.
Definition: unittype.cpp:114
int utype_pop_value(const struct unit_type *punittype)
How much city shrinks when it builds unit of this type.
Definition: unittype.cpp:1231
bool utype_may_act_move_frags(const struct unit_type *punit_type, const action_id act_id, const int move_fragments)
Return TRUE iff the given (action enabler controlled) action may be performed by a unit of the given ...
Definition: unittype.cpp:804
bool utype_player_already_has_this_unique(const struct player *pplayer, const struct unit_type *putype)
Returns TRUE iff the unit type is unique and the player already has one.
Definition: unittype.cpp:1599
bool unit_has_type_flag(const struct unit *punit, enum unit_type_flag_id flag)
Return whether the unit has the given flag.
Definition: unittype.cpp:176
int unit_pop_value(const struct unit *punit)
How much population is put to building this unit.
Definition: unittype.cpp:1239
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)
Returns TRUE iff the unit type can do the specified (action enabler controlled) action while its targ...
Definition: unittype.cpp:763
bool utype_can_do_action(const struct unit_type *putype, const action_id act_id)
Return TRUE iff units of the given type can do the specified generalized (ruleset defined) action ena...
Definition: unittype.cpp:386
const struct veteran_level * utype_veteran_level(const struct unit_type *punittype, int level)
Return veteran level properties of given unit in given veterancy level.
Definition: unittype.cpp:2224
#define utype_class(_t_)
Definition: unittype.h:691
#define L_LAST
Definition: unittype.h:406
#define unit_type_iterate(_p)
Definition: unittype.h:785
#define unit_type_iterate_end
Definition: unittype.h:791
#define U_NOT_OBSOLETED
Definition: unittype.h:493