Freeciv-3.2: /fast/freeciv/nightly/S3_2/common/actres.c Source File

Freeciv-3.2

Loading...
Searching...
No Matches
actres.c
Go to the documentation of this file.
1/****************************************************************************
2 Freeciv - Copyright (C) 2023 The Freeciv Team
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12****************************************************************************/
13
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18/* common */
19#include "city.h"
20#include "combat.h"
21#include "fc_interface.h"
22#include "game.h"
23#include "map.h"
24#include "metaknowledge.h"
25#include "movement.h"
26#include "player.h"
27#include "requirements.h"
28#include "tile.h"
29#include "traderoutes.h"
30
31#include "actres.h"
32
33 static struct actres act_results[ACTRES_LAST] = {
34 { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_ESTABLISH_EMBASSY */
35 FALSE, ACTIVITY_LAST, DRT_NONE,
36 EC_NONE, ERM_NONE, ATK_CITY },
37 { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_SPY_INVESTIGATE_CITY */
38 TRUE, ACTIVITY_LAST, DRT_NONE,
39 EC_NONE, ERM_NONE, ATK_CITY },
40 { ACT_TGT_COMPL_SIMPLE, ABK_DIPLOMATIC, /* ACTRES_SPY_POISON */
41 TRUE, ACTIVITY_LAST, DRT_DIPLCHANCE,
42 EC_NONE, ERM_NONE, ATK_CITY },
43 { ACT_TGT_COMPL_SIMPLE, ABK_DIPLOMATIC, /* ACTRES_SPY_STEAL_GOLD */
44 TRUE, ACTIVITY_LAST, DRT_DIPLCHANCE,
45 EC_NONE, ERM_NONE, ATK_CITY },
46 { ACT_TGT_COMPL_SIMPLE, ABK_DIPLOMATIC, /* ACTRES_SPY_SABOTAGE_CITY */
47 TRUE, ACTIVITY_LAST, DRT_DIPLCHANCE,
48 EC_NONE, ERM_NONE, ATK_CITY },
49 { ACT_TGT_COMPL_MANDATORY, ABK_DIPLOMATIC, /* ACTRES_SPY_TARGETED_SABOTAGE_CITY */
50 TRUE, ACTIVITY_LAST, DRT_DIPLCHANCE,
51 EC_NONE, ERM_NONE, ATK_CITY },
52 { ACT_TGT_COMPL_SIMPLE, ABK_DIPLOMATIC, /* ACTRES_SPY_SABOTAGE_CITY_PRODUCTION */
53 TRUE, ACTIVITY_LAST, DRT_DIPLCHANCE,
54 EC_NONE, ERM_NONE, ATK_CITY },
55 { ACT_TGT_COMPL_SIMPLE, ABK_DIPLOMATIC, /* ACTRES_SPY_STEAL_TECH */
56 TRUE, ACTIVITY_LAST, DRT_DIPLCHANCE,
57 EC_NONE, ERM_NONE, ATK_CITY },
58 { ACT_TGT_COMPL_MANDATORY, ABK_DIPLOMATIC, /* ACTRES_SPY_TARGETED_STEAL_TECH */
59 TRUE, ACTIVITY_LAST, DRT_DIPLCHANCE,
60 EC_NONE, ERM_NONE, ATK_CITY },
61 { ACT_TGT_COMPL_SIMPLE, ABK_DIPLOMATIC, /* ACTRES_SPY_INCITE_CITY */
62 TRUE, ACTIVITY_LAST, DRT_DIPLCHANCE,
63 EC_NONE, ERM_NONE, ATK_CITY },
64 { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_TRADE_ROUTE */
65 FALSE, ACTIVITY_LAST, DRT_NONE,
66 EC_NONE, ERM_NONE, ATK_CITY },
67 { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_MARKETPLACE */
68 FALSE, ACTIVITY_LAST, DRT_NONE,
69 EC_NONE, ERM_NONE, ATK_CITY },
70 { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_HELP_WONDER */
71 FALSE, ACTIVITY_LAST, DRT_NONE,
72 EC_NONE, ERM_NONE, ATK_CITY },
73 { ACT_TGT_COMPL_SIMPLE, ABK_DIPLOMATIC, /* ACTRES_SPY_BRIBE_UNIT */
74 TRUE, ACTIVITY_LAST, DRT_NONE,
75 EC_NONE, ERM_NONE, ATK_UNIT },
76 { ACT_TGT_COMPL_SIMPLE, ABK_DIPLOMATIC, /* ACTRES_SPY_SABOTAGE_UNIT */
77 TRUE, ACTIVITY_LAST, DRT_NONE,
78 EC_NONE, ERM_NONE, ATK_UNIT },
79 { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_CAPTURE_UNITS */
80 TRUE, ACTIVITY_LAST, DRT_NONE,
81 EC_NONE, ERM_NONE, ATK_UNITS },
82 { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_FOUND_CITY */
83 FALSE, ACTIVITY_LAST, DRT_NONE,
84 EC_NONE, ERM_NONE, ATK_TILE },
85 { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_JOIN_CITY */
86 FALSE, ACTIVITY_LAST, DRT_NONE,
87 EC_NONE, ERM_NONE, ATK_CITY },
88 { ACT_TGT_COMPL_SIMPLE, ABK_DIPLOMATIC, /* ACTRES_STEAL_MAPS */
89 TRUE, ACTIVITY_LAST, DRT_DIPLCHANCE,
90 EC_NONE, ERM_NONE, ATK_CITY },
91 { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_BOMBARD */
92 TRUE, ACTIVITY_LAST, DRT_NONE,
93 EC_NONE, ERM_NONE, ATK_UNITS },
94 { ACT_TGT_COMPL_SIMPLE, ABK_DIPLOMATIC, /* ACTRES_SPY_NUKE */
95 TRUE, ACTIVITY_LAST, DRT_DIPLCHANCE,
96 EC_NONE, ERM_NONE, ATK_CITY },
97 { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_NUKE */
98 TRUE, ACTIVITY_LAST, DRT_NONE,
99 EC_NONE, ERM_NONE, ATK_TILE },
100 { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_NUKE_UNITS */
101 TRUE, ACTIVITY_LAST, DRT_NONE,
102 EC_NONE, ERM_NONE, ATK_UNITS },
103 { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_DESTROY_CITY */
104 TRUE, ACTIVITY_LAST, DRT_NONE,
105 EC_NONE, ERM_NONE, ATK_CITY },
106 { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_EXPEL_UNIT */
107 TRUE, ACTIVITY_LAST, DRT_NONE,
108 EC_NONE, ERM_NONE, ATK_UNIT },
109 { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_DISBAND_UNIT_RECOVER */
110 FALSE, ACTIVITY_LAST, DRT_NONE,
111 EC_NONE, ERM_NONE, ATK_CITY },
112 { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_DISBAND_UNIT */
113 FALSE, ACTIVITY_LAST, DRT_NONE,
114 EC_NONE, ERM_NONE, ATK_SELF },
115 { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_HOME_CITY */
116 FALSE, ACTIVITY_LAST, DRT_NONE,
117 EC_NONE, ERM_NONE, ATK_CITY },
118 { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_UPGRADE_UNIT */
119 FALSE, ACTIVITY_LAST, DRT_NONE,
120 EC_NONE, ERM_NONE, ATK_CITY },
121 { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_PARADROP */
122 FALSE, ACTIVITY_LAST, DRT_NONE,
123 EC_NONE, ERM_NONE, ATK_TILE },
124 { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_AIRLIFT */
125 FALSE, ACTIVITY_LAST, DRT_NONE,
126 EC_NONE, ERM_NONE, ATK_CITY },
127 { ACT_TGT_COMPL_SIMPLE, ABK_STANDARD, /* ACTRES_ATTACK */
128 TRUE, ACTIVITY_LAST, DRT_NONE,
129 EC_NONE, ERM_NONE, ATK_UNITS },
130 { ACT_TGT_COMPL_MANDATORY, ABK_NONE, /* ACTRES_STRIKE_BUILDING */
131 TRUE, ACTIVITY_LAST, DRT_DIPLCHANCE,
132 EC_NONE, ERM_NONE, ATK_CITY },
133 { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_STRIKE_PRODUCTION */
134 TRUE, ACTIVITY_LAST, DRT_DIPLCHANCE,
135 EC_NONE, ERM_NONE, ATK_CITY },
136 { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_CONQUER_CITY */
137 TRUE, ACTIVITY_LAST, DRT_NONE,
138 EC_NONE, ERM_NONE, ATK_CITY },
139 { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_HEAL_UNIT */
140 FALSE, ACTIVITY_LAST, DRT_NONE,
141 EC_NONE, ERM_NONE, ATK_UNIT },
142 { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_TRANSFORM_TERRAIN */
143 FALSE, ACTIVITY_TRANSFORM, DRT_NONE,
144 EC_NONE, ERM_NONE, ATK_TILE },
145 { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_CULTIVATE */
146 FALSE, ACTIVITY_CULTIVATE, DRT_NONE,
147 EC_NONE, ERM_NONE, ATK_TILE },
148 { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_PLANT */
149 FALSE, ACTIVITY_PLANT, DRT_NONE,
150 EC_NONE, ERM_NONE, ATK_TILE },
151 { ACT_TGT_COMPL_FLEXIBLE, ABK_NONE, /* ACTRES_PILLAGE */
152 TRUE, ACTIVITY_PILLAGE, DRT_NONE,
153 EC_NONE, ERM_PILLAGE, ATK_TILE },
154 { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_FORTIFY */
155 FALSE, ACTIVITY_FORTIFYING, DRT_NONE,
156 EC_NONE, ERM_NONE, ATK_SELF },
157 { ACT_TGT_COMPL_MANDATORY, ABK_NONE, /* ACTRES_ROAD */
158 FALSE, ACTIVITY_GEN_ROAD, DRT_NONE,
159 EC_ROAD, ERM_NONE, ATK_TILE },
160 { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_CONVERT */
161 FALSE, ACTIVITY_CONVERT, DRT_NONE,
162 EC_NONE, ERM_NONE, ATK_SELF },
163 { ACT_TGT_COMPL_MANDATORY, ABK_NONE, /* ACTRES_BASE */
164 FALSE, ACTIVITY_BASE, DRT_NONE,
165 EC_BASE, ERM_NONE, ATK_TILE },
166 { ACT_TGT_COMPL_MANDATORY, ABK_NONE, /* ACTRES_MINE */
167 FALSE, ACTIVITY_MINE, DRT_NONE,
168 EC_MINE, ERM_NONE, ATK_TILE },
169 { ACT_TGT_COMPL_MANDATORY, ABK_NONE, /* ACTRES_IRRIGATE */
170 FALSE, ACTIVITY_IRRIGATE, DRT_NONE,
171 EC_IRRIGATION, ERM_NONE, ATK_TILE },
172 { ACT_TGT_COMPL_SIMPLE, ABK_STANDARD, /* ACTRES_COLLECT_RANSOM */
173 TRUE, ACTIVITY_LAST, DRT_NONE,
174 EC_NONE, ERM_NONE, ATK_UNITS },
175 { ACT_TGT_COMPL_FLEXIBLE, ABK_NONE, /* ACTRES_UNUSED_1 */
176 FALSE, ACTIVITY_LAST, DRT_NONE,
177 EC_NONE, ERM_NONE, RS_DEFAULT_USER_ACTION_TARGET_KIND },
178 { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_TRANSPORT_DEBOARD */
179 FALSE, ACTIVITY_LAST, DRT_NONE,
180 EC_NONE, ERM_NONE, ATK_UNIT },
181 { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_TRANSPORT_UNLOAD */
182 FALSE, ACTIVITY_LAST, DRT_NONE,
183 EC_NONE, ERM_NONE, ATK_UNIT },
184 { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_TRANSPORT_DISEMBARK */
185 FALSE, ACTIVITY_LAST, DRT_NONE,
186 EC_NONE, ERM_NONE, ATK_TILE },
187 { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_TRANSPORT_BOARD */
188 FALSE, ACTIVITY_LAST, DRT_NONE,
189 EC_NONE, ERM_NONE, ATK_UNIT },
190 { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_TRANSPORT_EMBARK */
191 FALSE, ACTIVITY_LAST, DRT_NONE,
192 EC_NONE, ERM_NONE, ATK_UNIT },
193 { ACT_TGT_COMPL_SIMPLE, ABK_DIPLOMATIC, /* ACTRES_SPY_SPREAD_PLAGUE */
194 TRUE, ACTIVITY_LAST, DRT_DIPLCHANCE,
195 EC_NONE, ERM_NONE, ATK_CITY },
196 { ACT_TGT_COMPL_SIMPLE, ABK_DIPLOMATIC, /* ACTRES_SPY_ATTACK */
197 TRUE, ACTIVITY_LAST, DRT_NONE,
198 EC_NONE, ERM_NONE, ATK_UNITS },
199 { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_CONQUER_EXTRAS */
200 TRUE, ACTIVITY_LAST, DRT_NONE,
201 EC_NONE, ERM_NONE, ATK_EXTRAS },
202 { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_HUT_ENTER */
203 FALSE, ACTIVITY_LAST, DRT_NONE,
204 EC_NONE, ERM_ENTER, ATK_TILE },
205 { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_HUT_FRIGHTEN */
206 FALSE, ACTIVITY_LAST, DRT_NONE,
207 EC_NONE, ERM_ENTER, ATK_TILE },
208 { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_UNIT_MOVE */
209 FALSE, ACTIVITY_LAST, DRT_NONE,
210 EC_NONE, ERM_NONE, ATK_TILE },
211 { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_PARADROP_CONQUER */
212 FALSE, ACTIVITY_LAST, DRT_NONE, /* TODO: Should this be hostile? */
213 EC_NONE, ERM_NONE, ATK_TILE },
214 { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_HOMELESS */
215 FALSE, ACTIVITY_LAST, DRT_NONE,
216 EC_NONE, ERM_NONE, ATK_SELF },
217 { ACT_TGT_COMPL_SIMPLE, ABK_STANDARD, /* ACTRES_WIPE_UNITS */
218 TRUE, ACTIVITY_LAST, DRT_NONE,
219 EC_NONE, ERM_NONE, ATK_UNITS },
220 { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_SPY_ESCAPE */
221 FALSE, ACTIVITY_LAST, DRT_NONE,
222 EC_NONE, ERM_NONE, ATK_CITY },
223 { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_TRANSPORT_LOAD */
224 FALSE, ACTIVITY_LAST, DRT_NONE,
225 EC_NONE, ERM_NONE, ATK_UNIT },
226 { ACT_TGT_COMPL_FLEXIBLE, ABK_NONE, /* ACTRES_CLEAN */
227 FALSE, ACTIVITY_CLEAN, DRT_NONE,
228 EC_NONE, ERM_CLEAN, ATK_TILE },
229 { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_TELEPORT */
230 FALSE, ACTIVITY_LAST, DRT_NONE,
231 EC_NONE, ERM_NONE, ATK_TILE },
232 { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_TELEPORT_CONQUER */
233 FALSE, ACTIVITY_LAST, DRT_NONE,
234 EC_NONE, ERM_NONE, ATK_TILE },
235 { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_ENABLER_CHECK */
236 FALSE, ACTIVITY_LAST, DRT_NONE,
237 EC_NONE, ERM_NONE, ATK_SELF }
238};
239
240/*********************************************************************/
243 void actres_init(void)
244{
245}
246
247/*********************************************************************/
250 void actres_free(void)
251{
252}
253
254/**********************************************************************/
258 enum act_tgt_compl actres_target_compl_calc(enum action_result result)
259{
260 if (result == ACTRES_NONE) {
261 return ACT_TGT_COMPL_SIMPLE;
262 }
263
264 fc_assert_ret_val(action_result_is_valid(result), ACT_TGT_COMPL_SIMPLE);
265
266 return act_results[result].sub_tgt_compl;
267}
268
269/**********************************************************************/
272 enum action_battle_kind actres_get_battle_kind(enum action_result result)
273{
274 if (result == ACTRES_NONE) {
275 return ABK_NONE;
276 }
277
278 fc_assert_ret_val(action_result_is_valid(result), ABK_NONE);
279
280 return act_results[result].battle_kind;
281}
282
283/**********************************************************************/
286 bool actres_is_hostile(enum action_result result)
287{
288 if (result == ACTRES_NONE) {
289 return FALSE;
290 }
291
292 return act_results[result].hostile;
293}
294
295/**********************************************************************/
301 enum unit_activity actres_activity_result(enum action_result result)
302{
303 if (result == ACTRES_NONE) {
304 return ACTIVITY_LAST;
305 }
306
307 return act_results[result].activity;
308}
309
310/**********************************************************************/
316 int actres_get_act_time(enum action_result result,
317 const struct unit *actor_unit,
318 const struct tile *tgt_tile,
319 const struct extra_type *tgt_extra)
320{
321 enum unit_activity pactivity = actres_activity_result(result);
322
323 if (pactivity == ACTIVITY_LAST) {
324 /* Happens instantaneously, not at turn change. */
325 return ACT_TIME_INSTANTANEOUS;
326 }
327
328 switch (pactivity) {
329 case ACTIVITY_PILLAGE:
330 case ACTIVITY_CLEAN:
331 case ACTIVITY_BASE:
332 case ACTIVITY_GEN_ROAD:
333 case ACTIVITY_IRRIGATE:
334 case ACTIVITY_MINE:
335 case ACTIVITY_CULTIVATE:
336 case ACTIVITY_PLANT:
337 case ACTIVITY_TRANSFORM:
338 return tile_activity_time(pactivity, tgt_tile, tgt_extra);
339 case ACTIVITY_FORTIFYING:
340 return 1;
341 case ACTIVITY_CONVERT:
342 return unit_type_get(actor_unit)->convert_time * ACTIVITY_FACTOR;
343 case ACTIVITY_EXPLORE:
344 case ACTIVITY_IDLE:
345 case ACTIVITY_FORTIFIED:
346 case ACTIVITY_SENTRY:
347 case ACTIVITY_GOTO:
348 case ACTIVITY_LAST:
349 /* Should not happen. Caught by the assertion below. */
350 break;
351 }
352
353 fc_assert(FALSE);
354
355 return ACT_TIME_INSTANTANEOUS;
356}
357
358/**********************************************************************/
364 enum dice_roll_type actres_dice_type(enum action_result result)
365{
366 if (result == ACTRES_NONE) {
367 return DRT_NONE;
368 }
369
370 return act_results[result].dice;
371}
372
373/**********************************************************************/
376 int actres_min_range_default(enum action_result result)
377{
378 switch (result) {
379 case ACTRES_ESTABLISH_EMBASSY:
380 case ACTRES_SPY_INVESTIGATE_CITY:
381 case ACTRES_SPY_POISON:
382 case ACTRES_SPY_STEAL_GOLD:
383 case ACTRES_SPY_SABOTAGE_CITY:
384 case ACTRES_SPY_TARGETED_SABOTAGE_CITY:
385 case ACTRES_SPY_SABOTAGE_CITY_PRODUCTION:
386 case ACTRES_SPY_STEAL_TECH:
387 case ACTRES_SPY_TARGETED_STEAL_TECH:
388 case ACTRES_SPY_INCITE_CITY:
389 case ACTRES_TRADE_ROUTE:
390 case ACTRES_MARKETPLACE:
391 case ACTRES_HELP_WONDER:
392 case ACTRES_SPY_BRIBE_UNIT:
393 case ACTRES_SPY_SABOTAGE_UNIT:
394 case ACTRES_CAPTURE_UNITS:
395 case ACTRES_FOUND_CITY:
396 case ACTRES_JOIN_CITY:
397 case ACTRES_STEAL_MAPS:
398 case ACTRES_BOMBARD:
399 case ACTRES_SPY_NUKE:
400 case ACTRES_DESTROY_CITY:
401 case ACTRES_EXPEL_UNIT:
402 case ACTRES_DISBAND_UNIT_RECOVER:
403 case ACTRES_DISBAND_UNIT:
404 case ACTRES_HOME_CITY:
405 case ACTRES_HOMELESS:
406 case ACTRES_UPGRADE_UNIT:
407 case ACTRES_PARADROP:
408 case ACTRES_PARADROP_CONQUER:
409 case ACTRES_AIRLIFT:
410 case ACTRES_STRIKE_BUILDING:
411 case ACTRES_STRIKE_PRODUCTION:
412 case ACTRES_ATTACK:
413 case ACTRES_WIPE_UNITS:
414 case ACTRES_COLLECT_RANSOM:
415 case ACTRES_CONQUER_CITY:
416 case ACTRES_HEAL_UNIT:
417 case ACTRES_TRANSFORM_TERRAIN:
418 case ACTRES_CULTIVATE:
419 case ACTRES_PLANT:
420 case ACTRES_PILLAGE:
421 case ACTRES_CLEAN:
422 case ACTRES_FORTIFY:
423 case ACTRES_ROAD:
424 case ACTRES_CONVERT:
425 case ACTRES_BASE:
426 case ACTRES_MINE:
427 case ACTRES_IRRIGATE:
428 case ACTRES_TRANSPORT_DEBOARD:
429 case ACTRES_TRANSPORT_UNLOAD:
430 case ACTRES_TRANSPORT_LOAD:
431 case ACTRES_TRANSPORT_DISEMBARK:
432 case ACTRES_TRANSPORT_BOARD:
433 case ACTRES_TRANSPORT_EMBARK:
434 case ACTRES_SPY_ATTACK:
435 case ACTRES_SPY_SPREAD_PLAGUE:
436 case ACTRES_CONQUER_EXTRAS:
437 case ACTRES_HUT_ENTER:
438 case ACTRES_HUT_FRIGHTEN:
439 case ACTRES_UNIT_MOVE:
440 case ACTRES_SPY_ESCAPE:
441 case ACTRES_ENABLER_CHECK:
442 /* Non ruleset defined action min range not supported here */
443 fc_assert_msg(FALSE, "Probably wrong value.");
444 return RS_DEFAULT_ACTION_MIN_RANGE;
445 case ACTRES_NUKE:
446 case ACTRES_NUKE_UNITS:
447 return RS_DEFAULT_ACTION_MIN_RANGE;
448 case ACTRES_TELEPORT:
449 case ACTRES_TELEPORT_CONQUER:
450 return RS_DEFAULT_MOVE_MIN_RANGE;
451 case ACTRES_NONE:
452 return RS_DEFAULT_ACTION_MIN_RANGE;
453
454 ASSERT_UNUSED_ACTRES_CASES;
455 }
456
457 fc_assert(action_result_is_valid(result) || result == ACTRES_NONE);
458
459 return 0;
460}
461
462/**********************************************************************/
465 int actres_max_range_default(enum action_result result)
466{
467 switch (result) {
468 case ACTRES_ESTABLISH_EMBASSY:
469 case ACTRES_SPY_INVESTIGATE_CITY:
470 case ACTRES_SPY_POISON:
471 case ACTRES_SPY_STEAL_GOLD:
472 case ACTRES_SPY_SABOTAGE_CITY:
473 case ACTRES_SPY_TARGETED_SABOTAGE_CITY:
474 case ACTRES_SPY_SABOTAGE_CITY_PRODUCTION:
475 case ACTRES_SPY_STEAL_TECH:
476 case ACTRES_SPY_TARGETED_STEAL_TECH:
477 case ACTRES_SPY_INCITE_CITY:
478 case ACTRES_TRADE_ROUTE:
479 case ACTRES_MARKETPLACE:
480 case ACTRES_SPY_BRIBE_UNIT:
481 case ACTRES_SPY_SABOTAGE_UNIT:
482 case ACTRES_CAPTURE_UNITS:
483 case ACTRES_FOUND_CITY:
484 case ACTRES_JOIN_CITY:
485 case ACTRES_STEAL_MAPS:
486 case ACTRES_SPY_NUKE:
487 case ACTRES_DESTROY_CITY:
488 case ACTRES_EXPEL_UNIT:
489 case ACTRES_DISBAND_UNIT:
490 case ACTRES_HOME_CITY:
491 case ACTRES_HOMELESS:
492 case ACTRES_UPGRADE_UNIT:
493 case ACTRES_PARADROP:
494 case ACTRES_PARADROP_CONQUER:
495 case ACTRES_STRIKE_BUILDING:
496 case ACTRES_STRIKE_PRODUCTION:
497 case ACTRES_ATTACK:
498 case ACTRES_WIPE_UNITS:
499 case ACTRES_COLLECT_RANSOM:
500 case ACTRES_CONQUER_CITY:
501 case ACTRES_HEAL_UNIT:
502 case ACTRES_TRANSFORM_TERRAIN:
503 case ACTRES_CULTIVATE:
504 case ACTRES_PLANT:
505 case ACTRES_PILLAGE:
506 case ACTRES_CLEAN:
507 case ACTRES_FORTIFY:
508 case ACTRES_ROAD:
509 case ACTRES_CONVERT:
510 case ACTRES_BASE:
511 case ACTRES_MINE:
512 case ACTRES_IRRIGATE:
513 case ACTRES_TRANSPORT_DEBOARD:
514 case ACTRES_TRANSPORT_UNLOAD:
515 case ACTRES_TRANSPORT_LOAD:
516 case ACTRES_TRANSPORT_DISEMBARK:
517 case ACTRES_TRANSPORT_BOARD:
518 case ACTRES_TRANSPORT_EMBARK:
519 case ACTRES_SPY_ATTACK:
520 case ACTRES_SPY_SPREAD_PLAGUE:
521 case ACTRES_CONQUER_EXTRAS:
522 case ACTRES_HUT_ENTER:
523 case ACTRES_HUT_FRIGHTEN:
524 case ACTRES_UNIT_MOVE:
525 case ACTRES_SPY_ESCAPE:
526 case ACTRES_ENABLER_CHECK:
527 /* Non ruleset defined action max range not supported here */
528 fc_assert_msg(FALSE, "Probably wrong value.");
529 return RS_DEFAULT_ACTION_MAX_RANGE;
530 case ACTRES_HELP_WONDER:
531 case ACTRES_DISBAND_UNIT_RECOVER:
532 return RS_DEFAULT_ACTION_MAX_RANGE;
533 case ACTRES_BOMBARD:
534 return RS_DEFAULT_ACTION_MAX_RANGE;
535 case ACTRES_NUKE:
536 return RS_DEFAULT_EXPLODE_NUCLEAR_MAX_RANGE;
537 case ACTRES_NUKE_UNITS:
538 return RS_DEFAULT_ACTION_MAX_RANGE;
539 case ACTRES_AIRLIFT:
540 case ACTRES_TELEPORT:
541 case ACTRES_TELEPORT_CONQUER:
542 return ACTION_DISTANCE_UNLIMITED;
543 case ACTRES_NONE:
544 return RS_DEFAULT_ACTION_MAX_RANGE;
545
546 ASSERT_UNUSED_ACTRES_CASES;
547 }
548
549 fc_assert(action_result_is_valid(result) || result == ACTRES_NONE);
550
551 return 0;
552}
553
554/**********************************************************************/
558 bool actres_legal_target_kind(enum action_result result,
559 enum action_target_kind tgt_kind)
560{
561 fc_assert_ret_val(action_result_is_valid(result) || result == ACTRES_NONE,
562 FALSE);
563 fc_assert_ret_val(action_target_kind_is_valid(tgt_kind),
564 FALSE);
565
566 switch (result) {
567 case ACTRES_ESTABLISH_EMBASSY:
568 case ACTRES_SPY_INVESTIGATE_CITY:
569 case ACTRES_SPY_POISON:
570 case ACTRES_SPY_STEAL_GOLD:
571 case ACTRES_SPY_SABOTAGE_CITY:
572 case ACTRES_SPY_TARGETED_SABOTAGE_CITY:
573 case ACTRES_SPY_SABOTAGE_CITY_PRODUCTION:
574 case ACTRES_SPY_STEAL_TECH:
575 case ACTRES_SPY_TARGETED_STEAL_TECH:
576 case ACTRES_SPY_INCITE_CITY:
577 case ACTRES_TRADE_ROUTE:
578 case ACTRES_MARKETPLACE:
579 case ACTRES_HELP_WONDER:
580 case ACTRES_JOIN_CITY:
581 case ACTRES_STEAL_MAPS:
582 case ACTRES_SPY_NUKE:
583 case ACTRES_DESTROY_CITY:
584 case ACTRES_DISBAND_UNIT_RECOVER:
585 case ACTRES_HOME_CITY:
586 case ACTRES_UPGRADE_UNIT:
587 case ACTRES_AIRLIFT:
588 case ACTRES_STRIKE_BUILDING:
589 case ACTRES_STRIKE_PRODUCTION:
590 case ACTRES_CONQUER_CITY:
591 case ACTRES_SPY_SPREAD_PLAGUE:
592 case ACTRES_SPY_ESCAPE:
593 return tgt_kind == ATK_CITY;
594 case ACTRES_SPY_BRIBE_UNIT:
595 case ACTRES_SPY_SABOTAGE_UNIT:
596 case ACTRES_EXPEL_UNIT:
597 case ACTRES_HEAL_UNIT:
598 case ACTRES_TRANSPORT_DEBOARD:
599 case ACTRES_TRANSPORT_UNLOAD:
600 case ACTRES_TRANSPORT_LOAD:
601 case ACTRES_TRANSPORT_BOARD:
602 case ACTRES_TRANSPORT_EMBARK:
603 return tgt_kind == ATK_UNIT;
604 case ACTRES_CAPTURE_UNITS:
605 case ACTRES_BOMBARD:
606 case ACTRES_NUKE_UNITS:
607 case ACTRES_ATTACK:
608 case ACTRES_WIPE_UNITS:
609 case ACTRES_SPY_ATTACK:
610 case ACTRES_COLLECT_RANSOM:
611 return tgt_kind == ATK_UNITS;
612 case ACTRES_FOUND_CITY:
613 case ACTRES_PARADROP:
614 case ACTRES_PARADROP_CONQUER:
615 case ACTRES_TRANSFORM_TERRAIN:
616 case ACTRES_CULTIVATE:
617 case ACTRES_PLANT:
618 case ACTRES_CLEAN:
619 case ACTRES_ROAD:
620 case ACTRES_BASE:
621 case ACTRES_MINE:
622 case ACTRES_IRRIGATE:
623 case ACTRES_TRANSPORT_DISEMBARK:
624 case ACTRES_HUT_ENTER:
625 case ACTRES_HUT_FRIGHTEN:
626 case ACTRES_UNIT_MOVE:
627 case ACTRES_TELEPORT:
628 case ACTRES_TELEPORT_CONQUER:
629 return tgt_kind == ATK_TILE;
630 case ACTRES_CONQUER_EXTRAS:
631 return tgt_kind == ATK_EXTRAS;
632 case ACTRES_DISBAND_UNIT:
633 case ACTRES_CONVERT:
634 case ACTRES_FORTIFY:
635 case ACTRES_HOMELESS:
636 case ACTRES_ENABLER_CHECK:
637 return tgt_kind == ATK_SELF;
638 case ACTRES_PILLAGE:
639 return (tgt_kind == ATK_TILE || tgt_kind == ATK_EXTRAS);
640 case ACTRES_NUKE:
641 return (tgt_kind == ATK_TILE || tgt_kind == ATK_CITY);
642 case ACTRES_NONE:
643 switch (tgt_kind) {
644 case ATK_CITY:
645 case ATK_UNIT:
646 case ATK_UNITS:
647 case ATK_TILE:
648 case ATK_EXTRAS:
649 case ATK_SELF:
650 /* Works with all existing target kinds. */
651 return TRUE;
652 case ATK_COUNT:
653 fc_assert_ret_val(tgt_kind != ATK_COUNT, FALSE);
654 break;
655 }
656 break;
657
658 ASSERT_UNUSED_ACTRES_CASES;
659 }
660
661 /* Should never be reached. */
662 return FALSE;
663}
664
665/**********************************************************************/
668enum action_sub_target_kind
669actres_sub_target_kind_default(enum action_result result)
670{
671 fc_assert_ret_val(action_result_is_valid(result) || result == ACTRES_NONE,
672 ASTK_NONE);
673
674 switch (result) {
675 case ACTRES_ESTABLISH_EMBASSY:
676 case ACTRES_SPY_INVESTIGATE_CITY:
677 case ACTRES_SPY_POISON:
678 case ACTRES_SPY_STEAL_GOLD:
679 case ACTRES_SPY_SABOTAGE_CITY:
680 case ACTRES_SPY_SABOTAGE_CITY_PRODUCTION:
681 case ACTRES_SPY_STEAL_TECH:
682 case ACTRES_SPY_INCITE_CITY:
683 case ACTRES_TRADE_ROUTE:
684 case ACTRES_MARKETPLACE:
685 case ACTRES_HELP_WONDER:
686 case ACTRES_JOIN_CITY:
687 case ACTRES_STEAL_MAPS:
688 case ACTRES_SPY_NUKE:
689 case ACTRES_DESTROY_CITY:
690 case ACTRES_DISBAND_UNIT_RECOVER:
691 case ACTRES_HOME_CITY:
692 case ACTRES_HOMELESS:
693 case ACTRES_UPGRADE_UNIT:
694 case ACTRES_AIRLIFT:
695 case ACTRES_STRIKE_PRODUCTION:
696 case ACTRES_CONQUER_CITY:
697 case ACTRES_SPY_SPREAD_PLAGUE:
698 return ASTK_NONE;
699 case ACTRES_SPY_TARGETED_SABOTAGE_CITY:
700 case ACTRES_STRIKE_BUILDING:
701 return ASTK_BUILDING;
702 case ACTRES_SPY_TARGETED_STEAL_TECH:
703 return ASTK_TECH;
704 case ACTRES_SPY_BRIBE_UNIT:
705 case ACTRES_SPY_SABOTAGE_UNIT:
706 case ACTRES_EXPEL_UNIT:
707 case ACTRES_HEAL_UNIT:
708 case ACTRES_TRANSPORT_DEBOARD:
709 case ACTRES_TRANSPORT_UNLOAD:
710 case ACTRES_TRANSPORT_LOAD:
711 case ACTRES_TRANSPORT_BOARD:
712 case ACTRES_TRANSPORT_EMBARK:
713 return ASTK_NONE;
714 case ACTRES_CAPTURE_UNITS:
715 case ACTRES_BOMBARD:
716 case ACTRES_NUKE_UNITS:
717 case ACTRES_ATTACK:
718 case ACTRES_WIPE_UNITS:
719 case ACTRES_SPY_ATTACK:
720 case ACTRES_COLLECT_RANSOM:
721 return ASTK_NONE;
722 case ACTRES_FOUND_CITY:
723 case ACTRES_NUKE:
724 case ACTRES_PARADROP:
725 case ACTRES_PARADROP_CONQUER:
726 case ACTRES_TRANSFORM_TERRAIN:
727 case ACTRES_CULTIVATE:
728 case ACTRES_PLANT:
729 case ACTRES_TRANSPORT_DISEMBARK:
730 case ACTRES_HUT_ENTER:
731 case ACTRES_HUT_FRIGHTEN:
732 case ACTRES_UNIT_MOVE:
733 case ACTRES_TELEPORT:
734 case ACTRES_TELEPORT_CONQUER:
735 case ACTRES_ENABLER_CHECK:
736 case ACTRES_SPY_ESCAPE:
737 return ASTK_NONE;
738 case ACTRES_PILLAGE:
739 case ACTRES_CLEAN:
740 return ASTK_EXTRA;
741 case ACTRES_ROAD:
742 case ACTRES_BASE:
743 case ACTRES_MINE:
744 case ACTRES_IRRIGATE:
745 return ASTK_EXTRA_NOT_THERE;
746 case ACTRES_CONQUER_EXTRAS:
747 return ASTK_NONE;
748 case ACTRES_DISBAND_UNIT:
749 case ACTRES_CONVERT:
750 case ACTRES_FORTIFY:
751 return ASTK_NONE;
752 case ACTRES_NONE:
753 return ASTK_NONE;
754
755 ASSERT_UNUSED_ACTRES_CASES;
756 }
757
758 /* Should never be reached. */
759 return ASTK_NONE;
760}
761
762/**********************************************************************/
765enum action_target_kind
766actres_target_kind_default(enum action_result result)
767{
768 if (result == ACTRES_NONE) {
769 return RS_DEFAULT_USER_ACTION_TARGET_KIND;
770 }
771
772 fc_assert_ret_val(action_result_is_valid(result),
773 RS_DEFAULT_USER_ACTION_TARGET_KIND);
774
775 return act_results[result].def_tgt_kind;
776}
777
778/**********************************************************************/
785 bool actres_creates_extra(enum action_result result,
786 const struct extra_type *pextra)
787{
788 if (act_results[result].ecause == EC_NONE) {
789 return FALSE;
790 }
791
792 if (pextra == NULL || !pextra->buildable) {
793 return FALSE;
794 }
795
796 return is_extra_caused_by(pextra, act_results[result].ecause);
797}
798
799/**********************************************************************/
806 bool actres_removes_extra(enum action_result result,
807 const struct extra_type *pextra)
808{
809 if (act_results[result].ermcause == ERM_NONE) {
810 return FALSE;
811 }
812
813 return is_extra_removed_by(pextra, act_results[result].ermcause);
814}
815
816/**********************************************************************/
820 static bool plr_knows_tile(const struct player *plr,
821 const struct tile *ttile)
822{
823 return plr != nullptr
824 && ttile != nullptr
825 && (tile_get_known(ttile, plr) != TILE_UNKNOWN);
826}
827
828/**********************************************************************/
831 enum fc_tristate actres_possible(const struct civ_map *nmap,
832 enum action_result result,
833 const struct req_context *actor,
834 const struct req_context *target,
835 const struct extra_type *target_extra,
836 enum fc_tristate def,
837 bool omniscient,
838 const struct city *homecity)
839{
840 struct terrain *pterrain;
841 bool can_see_tgt_unit;
842 bool can_see_tgt_tile;
843
844 /* Only check requirement against the target unit if the actor can see it
845 * or if the evaluator is omniscient. The game checking the rules is
846 * omniscient. The player asking about their odds isn't. */
847 can_see_tgt_unit = (omniscient || (target->unit
848 && can_player_see_unit(actor->player,
849 target->unit)));
850
851 /* Only check requirement against the target tile if the actor can see it
852 * or if the evaluator is omniscient. The game checking the rules is
853 * omniscient. The player asking about their odds isn't. */
854 can_see_tgt_tile = (omniscient
855 || can_player_see_tile(actor->player, target->tile));
856
857 switch (result) {
858 case ACTRES_CAPTURE_UNITS:
859 case ACTRES_SPY_BRIBE_UNIT:
860 /* Why this is a hard requirement: Can't transfer a unique unit if the
861 * actor player already has one. */
862 /* Info leak: This is only checked for when the actor player can see
863 * the target unit. Since the target unit is seen its type is known.
864 * The fact that a city hiding the unseen unit is occupied is known. */
865
866 if (!can_see_tgt_unit) {
867 /* An omniscient player can see the target unit. */
868 fc_assert(!omniscient);
869
870 return TRI_MAYBE;
871 }
872
873 if (utype_player_already_has_this_unique(actor->player,
874 target->unittype)) {
875 return TRI_NO;
876 }
877
878 /* FIXME: Capture Unit may want to look for more than one unique unit
879 * of the same kind at the target tile. Currently caught by sanity
880 * check in do_capture_units(). */
881
882 break;
883
884 case ACTRES_SPY_TARGETED_STEAL_TECH:
885 /* Reason: The Freeciv code don't support selecting a target tech
886 * unless it is known that the victim player has it. */
887 /* Info leak: The actor player knowns whose techs they can see. */
888 if (!can_see_techs_of_target(actor->player, target->player)) {
889 return TRI_NO;
890 }
891
892 break;
893
894 case ACTRES_SPY_STEAL_GOLD:
895 /* If actor->unit can do the action the actor->player can see how much
896 * gold target->player have. Not requiring it is therefore pointless.
897 */
898 if (target->player->economic.gold <= 0) {
899 return TRI_NO;
900 }
901
902 break;
903
904 case ACTRES_TRADE_ROUTE:
905 case ACTRES_MARKETPLACE:
906 {
907 /* Checked in action_hard_reqs_actor() */
908 fc_assert_ret_val(homecity != NULL, TRI_NO);
909
910 /* Can't establish a trade route or enter the market place if the
911 * cities can't trade at all. */
912 /* TODO: Should this restriction (and the above restriction that the
913 * actor unit must have a home city) be kept for Enter Marketplace? */
914 if (!can_cities_trade(homecity, target->city)) {
915 return TRI_NO;
916 }
917
918 /* There are more restrictions on establishing a trade route than on
919 * entering the market place. */
920 if (result == ACTRES_TRADE_ROUTE
921 && !can_establish_trade_route(homecity, target->city)) {
922 return TRI_NO;
923 }
924 }
925
926 break;
927
928 case ACTRES_HELP_WONDER:
929 case ACTRES_DISBAND_UNIT_RECOVER:
930 /* It is only possible to help the production if the production needs
931 * the help. (If not it would be possible to add shields for something
932 * that can't legally receive help if it is build later) */
933 /* Info leak: The player knows that the production in their own city has
934 * been hurried (bought or helped). The information isn't revealed when
935 * asking for action probabilities since omniscient is FALSE. */
936 if (!omniscient
937 && !can_player_see_city_internals(actor->player, target->city)) {
938 return TRI_MAYBE;
939 }
940
941 if (!(target->city->shield_stock
942 < city_production_build_shield_cost(target->city))) {
943 return TRI_NO;
944 }
945
946 break;
947
948 case ACTRES_FOUND_CITY:
949 if (game.scenario.prevent_new_cities) {
950 /* Reason: allow scenarios to disable city founding. */
951 /* Info leak: the setting is public knowledge. */
952 return TRI_NO;
953 }
954
955 if (can_see_tgt_tile && tile_city(target->tile)) {
956 /* Reason: a tile can have 0 or 1 cities. */
957 return TRI_NO;
958 }
959
960 if (citymindist_prevents_city_on_tile(nmap, target->tile)) {
961 if (omniscient) {
962 /* No need to check again. */
963 return TRI_NO;
964 } else {
965 square_iterate(nmap, target->tile,
966 game.info.citymindist - 1, otile) {
967 if (tile_city(otile) != NULL
968 && can_player_see_tile(actor->player, otile)) {
969 /* Known to be blocked by citymindist */
970 return TRI_NO;
971 }
972 } square_iterate_end;
973 }
974 }
975
976 /* The player may not have enough information to be certain. */
977
978 if (!can_see_tgt_tile) {
979 /* Need to know if target tile already has a city, has TER_NO_CITIES
980 * terrain, is non native to the actor or is owned by a foreigner. */
981 return TRI_MAYBE;
982 }
983
984 if (!omniscient) {
985 /* The player may not have enough information to find out if
986 * citymindist blocks or not. This doesn't depend on if it blocks. */
987 square_iterate(nmap, target->tile,
988 game.info.citymindist - 1, otile) {
989 if (!can_player_see_tile(actor->player, otile)) {
990 /* Could have a city that blocks via citymindist. Even if this
991 * tile has TER_NO_CITIES terrain the player don't know that it
992 * didn't change and had a city built on it. */
993 return TRI_MAYBE;
994 }
995 } square_iterate_end;
996 }
997
998 break;
999
1000 case ACTRES_JOIN_CITY:
1001 {
1002 int new_pop;
1003
1004 if (!omniscient
1005 && !player_can_see_city_externals(actor->player, target->city)) {
1006 return TRI_MAYBE;
1007 }
1008
1009 new_pop = city_size_get(target->city) + unit_pop_value(actor->unit);
1010
1011 if (new_pop > game.info.add_to_size_limit) {
1012 /* Reason: Make the add_to_size_limit setting work. */
1013 return TRI_NO;
1014 }
1015
1016 if (!city_can_grow_to(target->city, new_pop)) {
1017 /* Reason: respect city size limits. */
1018 /* Info leak: when it is legal to join a foreign city is legal and
1019 * the EFT_SIZE_UNLIMIT effect or the EFT_SIZE_ADJ effect depends on
1020 * something the actor player don't have access to.
1021 * Example: depends on a building (like Aqueduct) that isn't
1022 * VisibleByOthers. */
1023 return TRI_NO;
1024 }
1025 }
1026
1027 break;
1028
1029 case ACTRES_NUKE_UNITS:
1030 /* Has only action specific requirements */
1031 break;
1032
1033 case ACTRES_HOME_CITY:
1034 /* Reason: can't change to what is. */
1035 /* Info leak: The player knows their unit's current home city. */
1036 if (homecity != NULL && homecity->id == target->city->id) {
1037 /* This is already the unit's home city. */
1038 return TRI_NO;
1039 }
1040
1041 {
1042 int slots = unit_type_get(actor->unit)->city_slots;
1043
1044 if (slots > 0 && city_unit_slots_available(target->city) < slots) {
1045 return TRI_NO;
1046 }
1047 }
1048
1049 break;
1050
1051 case ACTRES_UPGRADE_UNIT:
1052 /* Reason: Keep the old rules. */
1053 /* Info leak: The player knows their unit's type. They know if they can
1054 * build the unit type upgraded to. If the upgrade happens in a foreign
1055 * city that fact may leak. This can be seen as a price for changing
1056 * the rules to allow upgrading in a foreign city.
1057 * The player knows how much gold they have. If the Upgrade_Price_Pct
1058 * effect depends on information they don't have that information may
1059 * leak. The player knows the location of their unit. They know if the
1060 * tile has a city and if the unit can exist there outside a transport.
1061 * The player knows their unit's cargo. By knowing the number and type
1062 * of cargo, they can predict if there will be enough room in the unit
1063 * upgraded to, as long as they know what unit type their unit will end
1064 * up as. */
1065 if (unit_upgrade_test(nmap, actor->unit, FALSE) != UU_OK) {
1066 return TRI_NO;
1067 }
1068
1069 break;
1070
1071 case ACTRES_PARADROP:
1072 case ACTRES_PARADROP_CONQUER:
1073 /* Reason: Keep the old rules. */
1074 /* Info leak: The player knows if they know the target tile. */
1075 if (!plr_knows_tile(actor->player, target->tile)) {
1076 return TRI_NO;
1077 }
1078
1079 /* Reason: Keep paratroopers_range working. */
1080 /* Info leak: The player knows the location of the actor and of the
1081 * target tile. */
1082 if (unit_type_get(actor->unit)->paratroopers_range
1083 < real_map_distance(actor->tile, target->tile)) {
1084 return TRI_NO;
1085 }
1086
1087 break;
1088
1089 case ACTRES_AIRLIFT:
1090 /* Reason: Keep the old rules. */
1091 /* Info leak: same as test_unit_can_airlift_to() */
1092 switch (test_unit_can_airlift_to(nmap, omniscient ? NULL : actor->player,
1093 actor->unit, target->city)) {
1094 case AR_OK:
1095 return TRI_YES;
1096 case AR_OK_SRC_UNKNOWN:
1097 case AR_OK_DST_UNKNOWN:
1098 return TRI_MAYBE;
1099 case AR_NO_MOVES:
1100 case AR_WRONG_UNITTYPE:
1101 case AR_OCCUPIED:
1102 case AR_NOT_IN_CITY:
1103 case AR_BAD_SRC_CITY:
1104 case AR_BAD_DST_CITY:
1105 case AR_SRC_NO_FLIGHTS:
1106 case AR_DST_NO_FLIGHTS:
1107 return TRI_NO;
1108 }
1109
1110 break;
1111
1112 case ACTRES_ATTACK:
1113 break;
1114
1115 case ACTRES_WIPE_UNITS:
1116 unit_list_iterate(target->tile->units, punit) {
1117 if (get_total_defense_power(actor->unit, punit) > 0) {
1118 return TRI_NO;
1119 }
1120 } unit_list_iterate_end;
1121 break;
1122
1123 case ACTRES_COLLECT_RANSOM:
1124 if (!is_barbarian(actor->player)
1125 || !uclass_has_flag(unit_class_get(actor->unit), UCF_COLLECT_RANSOM)) {
1126 return FALSE;
1127 }
1128
1129 unit_list_iterate(target->tile->units, punit) {
1130 if (!unit_has_type_role(punit, L_BARBARIAN_LEADER)) {
1131 /* Cannot get ransom when there are other kind of units in the tile */
1132 return FALSE;
1133 }
1134 } unit_list_iterate_end;
1135 break;
1136
1137 case ACTRES_CONQUER_CITY:
1138 /* Reason: "Conquer City" involves moving into the city. */
1139 if (!unit_can_move_to_tile(nmap, actor->unit, target->tile,
1140 FALSE, FALSE, TRUE)) {
1141 return TRI_NO;
1142 }
1143
1144 break;
1145
1146 case ACTRES_CONQUER_EXTRAS:
1147 /* Reason: "Conquer Extras" involves moving to the tile. */
1148 if (!unit_can_move_to_tile(nmap, actor->unit, target->tile,
1149 FALSE, FALSE, FALSE)) {
1150 return TRI_NO;
1151 }
1152 /* Reason: Must have something to claim. The more specific restriction
1153 * that the base must be native to the actor unit is hard coded in
1154 * unit_move(), in action_actor_utype_hard_reqs_ok_full(), in
1155 * helptext_extra(), in helptext_unit(), in do_attack() and in
1156 * diplomat_bribe(). */
1157 if (!tile_has_claimable_base(target->tile, actor->unittype)) {
1158 return TRI_NO;
1159 }
1160 break;
1161
1162 case ACTRES_HEAL_UNIT:
1163 /* Reason: It is not the healthy who need a doctor, but the sick. */
1164 /* Info leak: the actor can see the target's HP. */
1165 if (!can_see_tgt_unit) {
1166 return TRI_MAYBE;
1167 }
1168 if (!(target->unit->hp < target->unittype->hp)) {
1169 return TRI_NO;
1170 }
1171 break;
1172
1173 case ACTRES_TRANSFORM_TERRAIN:
1174 pterrain = tile_terrain(target->tile);
1175 if (pterrain->transform_result == T_NONE
1176 || pterrain == pterrain->transform_result
1177 || !terrain_surroundings_allow_change(nmap, target->tile,
1178 pterrain->transform_result)
1179 || (terrain_has_flag(pterrain->transform_result, TER_NO_CITIES)
1180 && (tile_city(target->tile)))) {
1181 return TRI_NO;
1182 }
1183 break;
1184
1185 case ACTRES_CULTIVATE:
1186 pterrain = tile_terrain(target->tile);
1187 if (pterrain->cultivate_result == NULL) {
1188 return TRI_NO;
1189 }
1190 if (!terrain_surroundings_allow_change(nmap, target->tile,
1191 pterrain->cultivate_result)
1192 || (terrain_has_flag(pterrain->cultivate_result, TER_NO_CITIES)
1193 && tile_city(target->tile))) {
1194 return TRI_NO;
1195 }
1196 break;
1197
1198 case ACTRES_PLANT:
1199 pterrain = tile_terrain(target->tile);
1200 if (pterrain->plant_result == NULL) {
1201 return TRI_NO;
1202 }
1203 if (!terrain_surroundings_allow_change(nmap, target->tile,
1204 pterrain->plant_result)
1205 || (terrain_has_flag(pterrain->plant_result, TER_NO_CITIES)
1206 && tile_city(target->tile))) {
1207 return TRI_NO;
1208 }
1209 break;
1210
1211 case ACTRES_ROAD:
1212 if (target_extra == NULL) {
1213 return TRI_NO;
1214 }
1215 if (!is_extra_caused_by(target_extra, EC_ROAD)) {
1216 /* Reason: This is not a road. */
1217 return TRI_NO;
1218 }
1219 if (!can_build_road(nmap, extra_road_get(target_extra), actor->unit,
1220 target->tile)) {
1221 return TRI_NO;
1222 }
1223 break;
1224
1225 case ACTRES_BASE:
1226 if (target_extra == NULL) {
1227 return TRI_NO;
1228 }
1229 if (!is_extra_caused_by(target_extra, EC_BASE)) {
1230 /* Reason: This is not a base. */
1231 return TRI_NO;
1232 }
1233 if (!can_build_base(actor->unit,
1234 extra_base_get(target_extra), target->tile)) {
1235 return TRI_NO;
1236 }
1237 break;
1238
1239 case ACTRES_MINE:
1240 if (target_extra == NULL) {
1241 return TRI_NO;
1242 }
1243 if (!is_extra_caused_by(target_extra, EC_MINE)) {
1244 /* Reason: This is not a mine. */
1245 return TRI_NO;
1246 }
1247
1248 if (!can_build_extra(target_extra, actor->unit, target->tile)) {
1249 return TRI_NO;
1250 }
1251 break;
1252
1253 case ACTRES_IRRIGATE:
1254 if (target_extra == NULL) {
1255 return TRI_NO;
1256 }
1257 if (!is_extra_caused_by(target_extra, EC_IRRIGATION)) {
1258 /* Reason: This is not an irrigation. */
1259 return TRI_NO;
1260 }
1261
1262 if (!can_build_extra(target_extra, actor->unit, target->tile)) {
1263 return TRI_NO;
1264 }
1265 break;
1266
1267 case ACTRES_PILLAGE:
1268 pterrain = tile_terrain(target->tile);
1269 if (pterrain->pillage_time == 0) {
1270 return TRI_NO;
1271 }
1272
1273 {
1274 bv_extras pspresent = get_tile_infrastructure_set(target->tile, NULL);
1275 bv_extras psworking = get_unit_tile_pillage_set(target->tile);
1276 bv_extras pspossible;
1277
1278 BV_CLR_ALL(pspossible);
1279 extra_type_iterate(pextra) {
1280 int idx = extra_index(pextra);
1281
1282 /* Only one unit can pillage a given improvement at a time */
1283 if (BV_ISSET(pspresent, idx)
1284 && (!BV_ISSET(psworking, idx)
1285 || actor->unit->activity_target == pextra)
1286 && can_remove_extra(pextra, actor->unit, target->tile)) {
1287 bool required = FALSE;
1288
1289 extra_type_iterate(pdepending) {
1290 if (BV_ISSET(pspresent, extra_index(pdepending))) {
1291 extra_deps_iterate(&(pdepending->reqs), pdep) {
1292 if (pdep == pextra) {
1293 required = TRUE;
1294 break;
1295 }
1296 } extra_deps_iterate_end;
1297 }
1298 if (required) {
1299 break;
1300 }
1301 } extra_type_iterate_end;
1302
1303 if (!required) {
1304 BV_SET(pspossible, idx);
1305 }
1306 }
1307 } extra_type_iterate_end;
1308
1309 if (!BV_ISSET_ANY(pspossible)) {
1310 /* Nothing available to pillage */
1311 return TRI_NO;
1312 }
1313
1314 if (target_extra != NULL) {
1315 if (!game.info.pillage_select) {
1316 /* Hobson's choice (this case mostly exists for old clients) */
1317 /* Needs to match what unit_activity_assign_target chooses */
1318 struct extra_type *tgt;
1319
1320 tgt = get_preferred_pillage(pspossible);
1321
1322 if (tgt != target_extra) {
1323 /* Only one target allowed, which wasn't the requested one */
1324 return TRI_NO;
1325 }
1326 }
1327
1328 if (!BV_ISSET(pspossible, extra_index(target_extra))) {
1329 return TRI_NO;
1330 }
1331 }
1332 }
1333 break;
1334
1335 case ACTRES_CLEAN:
1336 {
1337 const struct extra_type *pextra = NULL;
1338
1339 pterrain = tile_terrain(target->tile);
1340
1341 if (target_extra != NULL) {
1342 if (tile_has_extra(target->tile, target_extra)
1343 && (is_extra_removed_by(target_extra, ERM_CLEAN))) {
1344 pextra = target_extra;
1345 }
1346 } else {
1347 /* TODO: Make sure that all callers set target so that
1348 * we don't need this fallback. */
1349 pextra = prev_extra_in_tile(target->tile,
1350 ERM_CLEAN,
1351 actor->player,
1352 actor->unit);
1353 }
1354
1355 if (pextra != NULL && pterrain->extra_removal_times[extra_index(pextra)] > 0
1356 && can_remove_extra(pextra, actor->unit, target->tile)) {
1357 return TRI_YES;
1358 }
1359
1360 return TRI_NO;
1361 }
1362
1363 case ACTRES_TRANSPORT_DEBOARD:
1364 if (!can_unit_unload(actor->unit, target->unit)) {
1365 /* Keep the old rules about Unreachable and disembarks. */
1366 return TRI_NO;
1367 }
1368 break;
1369
1370 case ACTRES_TRANSPORT_BOARD:
1371 if (unit_transported(actor->unit)) {
1372 if (target->unit == unit_transport_get(actor->unit)) {
1373 /* Already inside this transport. */
1374 return TRI_NO;
1375 }
1376 }
1377 if (!could_unit_load(actor->unit, target->unit)) {
1378 /* Keep the old rules. */
1379 return TRI_NO;
1380 }
1381 break;
1382
1383 case ACTRES_TRANSPORT_LOAD:
1384 if (unit_transported(target->unit)) {
1385 if (actor->unit == unit_transport_get(target->unit)) {
1386 /* Already transporting this unit. */
1387 return TRI_NO;
1388 }
1389 }
1390 if (!could_unit_load(target->unit, actor->unit)) {
1391 /* Keep the old rules. */
1392 return TRI_NO;
1393 }
1394 if (unit_transported(target->unit)) {
1395 if (!can_unit_unload(target->unit,
1396 unit_transport_get(target->unit))) {
1397 /* Can't leave current transport. */
1398 return TRI_NO;
1399 }
1400 }
1401 break;
1402
1403 case ACTRES_TRANSPORT_UNLOAD:
1404 if (!can_unit_unload(target->unit, actor->unit)) {
1405 /* Keep the old rules about Unreachable and disembarks. */
1406 return TRI_NO;
1407 }
1408 break;
1409
1410 case ACTRES_TRANSPORT_DISEMBARK:
1411 if (!unit_can_move_to_tile(nmap, actor->unit, target->tile,
1412 FALSE, FALSE, FALSE)) {
1413 /* Reason: involves moving to the tile. */
1414 return TRI_NO;
1415 }
1416
1417 /* We cannot move a transport into a tile that holds
1418 * units or cities not allied with all of our cargo. */
1419 if (get_transporter_capacity(actor->unit) > 0) {
1420 unit_list_iterate(unit_tile(actor->unit)->units, pcargo) {
1421 if (unit_contained_in(pcargo, actor->unit)
1422 && (is_non_allied_unit_tile(target->tile, unit_owner(pcargo))
1423 || is_non_allied_city_tile(target->tile,
1424 unit_owner(pcargo)))) {
1425 return TRI_NO;
1426 }
1427 } unit_list_iterate_end;
1428 }
1429 break;
1430
1431 case ACTRES_TRANSPORT_EMBARK:
1432 if (unit_transported(actor->unit)) {
1433 if (target->unit == unit_transport_get(actor->unit)) {
1434 /* Already inside this transport. */
1435 return TRI_NO;
1436 }
1437 }
1438 if (!could_unit_load(actor->unit, target->unit)) {
1439 /* Keep the old rules. */
1440 return TRI_NO;
1441 }
1442 if (!unit_can_move_to_tile(nmap, actor->unit, target->tile,
1443 FALSE, TRUE, FALSE)) {
1444 /* Reason: involves moving to the tile. */
1445 return TRI_NO;
1446 }
1447 /* We cannot move a transport into a tile that holds
1448 * units or cities not allied with all of our cargo. */
1449 if (get_transporter_capacity(actor->unit) > 0) {
1450 unit_list_iterate(unit_tile(actor->unit)->units, pcargo) {
1451 if (unit_contained_in(pcargo, actor->unit)
1452 && (is_non_allied_unit_tile(target->tile, unit_owner(pcargo))
1453 || is_non_allied_city_tile(target->tile,
1454 unit_owner(pcargo)))) {
1455 return TRI_NO;
1456 }
1457 } unit_list_iterate_end;
1458 }
1459 break;
1460
1461 case ACTRES_SPY_ATTACK:
1462 {
1463 bool found;
1464
1465 if (!omniscient
1466 && !can_player_see_hypotetic_units_at(actor->player,
1467 target->tile)) {
1468 /* May have a hidden diplomatic defender. */
1469 return TRI_MAYBE;
1470 }
1471
1472 found = FALSE;
1473 unit_list_iterate(target->tile->units, punit) {
1474 struct player *uplayer = unit_owner(punit);
1475
1476 if (uplayer == actor->player) {
1477 /* Won't defend against its owner. */
1478 continue;
1479 }
1480
1481 if (unit_has_type_flag(punit, UTYF_SUPERSPY)) {
1482 /* This unbeatable diplomatic defender will defend before any
1483 * that can be beaten. */
1484 found = FALSE;
1485 break;
1486 }
1487
1488 if (unit_has_type_flag(punit, UTYF_DIPLOMAT)) {
1489 /* Found a beatable diplomatic defender. */
1490 found = TRUE;
1491 break;
1492 }
1493 } unit_list_iterate_end;
1494
1495 if (!found) {
1496 return TRI_NO;
1497 }
1498 }
1499 break;
1500
1501 case ACTRES_HUT_ENTER:
1502 case ACTRES_HUT_FRIGHTEN:
1503 /* Reason: involves moving to the tile. */
1504 if (!unit_can_move_to_tile(nmap, actor->unit, target->tile,
1505 FALSE, FALSE, FALSE)) {
1506 return TRI_NO;
1507 }
1508 if (!unit_can_displace_hut(actor->unit, target->tile)) {
1509 /* Reason: keep extra rmreqs working. */
1510 return TRI_NO;
1511 }
1512 break;
1513
1514 case ACTRES_UNIT_MOVE:
1515 case ACTRES_TELEPORT:
1516 case ACTRES_TELEPORT_CONQUER:
1517 if (result == ACTRES_UNIT_MOVE) {
1518 /* Reason: is moving to the tile. */
1519 if (!unit_can_move_to_tile(nmap, actor->unit, target->tile,
1520 FALSE, FALSE, FALSE)) {
1521 return TRI_NO;
1522 }
1523 } else {
1524 fc_assert(result == ACTRES_TELEPORT || result == ACTRES_TELEPORT_CONQUER);
1525
1526 /* Reason: is teleporting to the tile. */
1527 if (!unit_can_teleport_to_tile(nmap, actor->unit, target->tile,
1528 FALSE, result == ACTRES_TELEPORT_CONQUER)) {
1529 return TRI_NO;
1530 }
1531 }
1532
1533 /* Reason: Don't override "Transport Embark" */
1534 if (!can_unit_exist_at_tile(nmap, actor->unit, target->tile)) {
1535 return TRI_NO;
1536 }
1537
1538 /* We cannot move a transport into a tile that holds
1539 * units or cities not allied with any of our cargo. */
1540 if (get_transporter_capacity(actor->unit) > 0) {
1541 unit_list_iterate(unit_tile(actor->unit)->units, pcargo) {
1542 if (unit_contained_in(pcargo, actor->unit)
1543 && (is_non_allied_unit_tile(target->tile, unit_owner(pcargo))
1544 || is_non_allied_city_tile(target->tile,
1545 unit_owner(pcargo)))) {
1546 return TRI_NO;
1547 }
1548 } unit_list_iterate_end;
1549 }
1550 break;
1551
1552 case ACTRES_SPY_ESCAPE:
1553 /* Reason: Be merciful. */
1554 /* Info leak: The player know if they have any cities. */
1555 if (city_list_size(actor->player->cities) < 1) {
1556 return TRI_NO;
1557 }
1558 break;
1559
1560 case ACTRES_SPY_SPREAD_PLAGUE:
1561 /* Enabling this action with illness_on = FALSE prevents spread. */
1562 break;
1563 case ACTRES_BOMBARD:
1564 {
1565 /* Allow bombing only if there's reachable units in the target
1566 * tile. Bombing without anybody taking damage is certainly not
1567 * what user really wants.
1568 * Allow bombing when player does not know if there's units in
1569 * target tile. */
1570 if (tile_city(target->tile) == NULL
1571 && fc_funcs->player_tile_vision_get(target->tile, actor->player,
1572 V_MAIN)
1573 && fc_funcs->player_tile_vision_get(target->tile, actor->player,
1574 V_INVIS)
1575 && fc_funcs->player_tile_vision_get(target->tile, actor->player,
1576 V_SUBSURFACE)) {
1577 bool hiding_extra = FALSE;
1578
1579 extra_type_iterate(pextra) {
1580 if (pextra->eus == EUS_HIDDEN
1581 && tile_has_extra(target->tile, pextra)) {
1582 hiding_extra = TRUE;
1583 break;
1584 }
1585 } extra_type_iterate_end;
1586
1587 if (!hiding_extra) {
1588 bool has_target = FALSE;
1589
1590 unit_list_iterate(target->tile->units, punit) {
1591 if (is_unit_reachable_at(punit, actor->unit, target->tile)) {
1592 has_target = TRUE;
1593 break;
1594 }
1595 } unit_list_iterate_end;
1596
1597 if (!has_target) {
1598 return TRI_NO;
1599 }
1600 }
1601 }
1602 }
1603 break;
1604 case ACTRES_ESTABLISH_EMBASSY:
1605 case ACTRES_SPY_INVESTIGATE_CITY:
1606 case ACTRES_SPY_POISON:
1607 case ACTRES_SPY_SABOTAGE_CITY:
1608 case ACTRES_SPY_TARGETED_SABOTAGE_CITY:
1609 case ACTRES_SPY_SABOTAGE_CITY_PRODUCTION:
1610 case ACTRES_SPY_STEAL_TECH:
1611 case ACTRES_SPY_INCITE_CITY:
1612 case ACTRES_SPY_SABOTAGE_UNIT:
1613 case ACTRES_STEAL_MAPS:
1614 case ACTRES_SPY_NUKE:
1615 case ACTRES_NUKE:
1616 case ACTRES_DESTROY_CITY:
1617 case ACTRES_EXPEL_UNIT:
1618 case ACTRES_DISBAND_UNIT:
1619 case ACTRES_CONVERT:
1620 case ACTRES_STRIKE_BUILDING:
1621 case ACTRES_STRIKE_PRODUCTION:
1622 case ACTRES_FORTIFY:
1623 case ACTRES_HOMELESS:
1624 case ACTRES_ENABLER_CHECK:
1625 case ACTRES_NONE:
1626 /* No known hard coded requirements. */
1627 break;
1628
1629 ASSERT_UNUSED_ACTRES_CASES;
1630 }
1631
1632 return def;
1633}
ACTION_DISTANCE_UNLIMITED
#define ACTION_DISTANCE_UNLIMITED
Definition actions.h:355
actres_get_act_time
int actres_get_act_time(enum action_result result, const struct unit *actor_unit, const struct tile *tgt_tile, const struct extra_type *tgt_extra)
Definition actres.c:316
actres_min_range_default
int actres_min_range_default(enum action_result result)
Definition actres.c:376
actres_free
void actres_free(void)
Definition actres.c:250
actres_sub_target_kind_default
enum action_sub_target_kind actres_sub_target_kind_default(enum action_result result)
Definition actres.c:669
actres_target_compl_calc
enum act_tgt_compl actres_target_compl_calc(enum action_result result)
Definition actres.c:258
actres_removes_extra
bool actres_removes_extra(enum action_result result, const struct extra_type *pextra)
Definition actres.c:806
actres_creates_extra
bool actres_creates_extra(enum action_result result, const struct extra_type *pextra)
Definition actres.c:785
actres_init
void actres_init(void)
Definition actres.c:243
act_results
static struct actres act_results[ACTRES_LAST]
Definition actres.c:33
actres_possible
enum fc_tristate actres_possible(const struct civ_map *nmap, enum action_result result, const struct req_context *actor, const struct req_context *target, const struct extra_type *target_extra, enum fc_tristate def, bool omniscient, const struct city *homecity)
Definition actres.c:831
actres_legal_target_kind
bool actres_legal_target_kind(enum action_result result, enum action_target_kind tgt_kind)
Definition actres.c:558
actres_activity_result
enum unit_activity actres_activity_result(enum action_result result)
Definition actres.c:301
actres_max_range_default
int actres_max_range_default(enum action_result result)
Definition actres.c:465
actres_is_hostile
bool actres_is_hostile(enum action_result result)
Definition actres.c:286
plr_knows_tile
static bool plr_knows_tile(const struct player *plr, const struct tile *ttile)
Definition actres.c:820
actres_dice_type
enum dice_roll_type actres_dice_type(enum action_result result)
Definition actres.c:364
actres_get_battle_kind
enum action_battle_kind actres_get_battle_kind(enum action_result result)
Definition actres.c:272
actres_target_kind_default
enum action_target_kind actres_target_kind_default(enum action_result result)
Definition actres.c:766
actres.h
ASSERT_UNUSED_ACTRES_CASES
#define ASSERT_UNUSED_ACTRES_CASES
Definition actres.h:37
dice_roll_type
dice_roll_type
Definition actres.h:110
DRT_DIPLCHANCE
@ DRT_DIPLCHANCE
Definition actres.h:110
DRT_NONE
@ DRT_NONE
Definition actres.h:110
can_build_base
bool can_build_base(const struct unit *punit, const struct base_type *pbase, const struct tile *ptile)
Definition base.c:53
BV_CLR_ALL
#define BV_CLR_ALL(bv)
Definition bitvector.h:95
BV_SET
#define BV_SET(bv, bit)
Definition bitvector.h:81
BV_ISSET
#define BV_ISSET(bv, bit)
Definition bitvector.h:78
BV_ISSET_ANY
#define BV_ISSET_ANY(vec)
Definition bitvector.h:109
city_production_build_shield_cost
int city_production_build_shield_cost(const struct city *pcity)
Definition city.c:736
city_unit_slots_available
int city_unit_slots_available(const struct city *pcity)
Definition city.c:1040
citymindist_prevents_city_on_tile
bool citymindist_prevents_city_on_tile(const struct civ_map *nmap, const struct tile *ptile)
Definition city.c:1456
city_can_grow_to
bool city_can_grow_to(const struct city *pcity, int pop_size)
Definition city.c:2004
city.h
is_non_allied_city_tile
static bool is_non_allied_city_tile(const struct tile *ptile, const struct player *pplayer)
Definition city.h:762
city_size_get
static citizens city_size_get(const struct city *pcity)
Definition city.h:569
is_unit_reachable_at
bool is_unit_reachable_at(const struct unit *defender, const struct unit *attacker, const struct tile *location)
Definition combat.c:85
get_total_defense_power
int get_total_defense_power(const struct unit *attacker, const struct unit *defender)
Definition combat.c:765
combat.h
incite_cost
char * incite_cost
Definition comments.c:74
actor_unit
struct unit * actor_unit
Definition dialogs_g.h:55
actor
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit * actor
Definition dialogs_g.h:73
punit
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit * punit
Definition dialogs_g.h:74
target_extra
struct unit struct city struct unit struct tile struct extra_type * target_extra
Definition dialogs_g.h:57
unit_can_displace_hut
bool unit_can_displace_hut(const struct unit *punit, const struct tile *ptile)
Definition extras.c:738
prev_extra_in_tile
struct extra_type * prev_extra_in_tile(const struct tile *ptile, enum extra_rmcause rmcause, const struct player *pplayer, const struct unit *punit)
Definition extras.c:790
can_remove_extra
bool can_remove_extra(const struct extra_type *pextra, const struct unit *punit, const struct tile *ptile)
Definition extras.c:612
is_extra_removed_by
bool is_extra_removed_by(const struct extra_type *pextra, enum extra_rmcause rmcause)
Definition extras.c:353
can_build_extra
bool can_build_extra(const struct extra_type *pextra, const struct unit *punit, const struct tile *ptile)
Definition extras.c:533
extra_type_iterate
#define extra_type_iterate(_p)
Definition extras.h:315
extra_deps_iterate
#define extra_deps_iterate(_reqs, _dep)
Definition extras.h:371
extra_type_iterate_end
#define extra_type_iterate_end
Definition extras.h:321
is_extra_caused_by
#define is_extra_caused_by(e, c)
Definition extras.h:203
extra_index
#define extra_index(_e_)
Definition extras.h:183
extra_deps_iterate_end
#define extra_deps_iterate_end
Definition extras.h:379
extra_base_get
#define extra_base_get(_e_)
Definition extras.h:190
extra_road_get
#define extra_road_get(_e_)
Definition extras.h:191
fc_funcs
const struct functions * fc_funcs
Definition fc_interface.c:38
fc_interface.h
ACT_TIME_INSTANTANEOUS
#define ACT_TIME_INSTANTANEOUS
Definition fc_types.h:352
EC_NONE
#define EC_NONE
Definition fc_types.h:1114
ACTRES_NONE
#define ACTRES_NONE
Definition fc_types.h:330
ERM_NONE
#define ERM_NONE
Definition fc_types.h:1137
game
struct civ_game game
Definition game.c:62
game.h
RS_DEFAULT_EXPLODE_NUCLEAR_MAX_RANGE
#define RS_DEFAULT_EXPLODE_NUCLEAR_MAX_RANGE
Definition game.h:886
RS_DEFAULT_ACTION_MIN_RANGE
#define RS_DEFAULT_ACTION_MIN_RANGE
Definition game.h:882
RS_DEFAULT_USER_ACTION_TARGET_KIND
#define RS_DEFAULT_USER_ACTION_TARGET_KIND
Definition game.h:881
RS_DEFAULT_MOVE_MIN_RANGE
#define RS_DEFAULT_MOVE_MIN_RANGE
Definition game.h:885
RS_DEFAULT_ACTION_MAX_RANGE
#define RS_DEFAULT_ACTION_MAX_RANGE
Definition game.h:883
fc_assert_msg
#define fc_assert_msg(condition, message,...)
Definition log.h:181
fc_assert
#define fc_assert(condition)
Definition log.h:176
fc_assert_ret_val
#define fc_assert_ret_val(condition, val)
Definition log.h:194
get_tile_infrastructure_set
bv_extras get_tile_infrastructure_set(const struct tile *ptile, int *pcount)
Definition map.c:101
terrain_surroundings_allow_change
bool terrain_surroundings_allow_change(const struct civ_map *nmap, const struct tile *ptile, const struct terrain *pterrain)
Definition map.c:742
real_map_distance
int real_map_distance(const struct tile *tile0, const struct tile *tile1)
Definition map.c:630
map.h
square_iterate
#define square_iterate(nmap, center_tile, radius, tile_itr)
Definition map.h:391
square_iterate_end
#define square_iterate_end
Definition map.h:394
can_see_techs_of_target
bool can_see_techs_of_target(const struct player *pow_player, const struct player *target_player)
Definition metaknowledge.c:774
metaknowledge.h
can_unit_exist_at_tile
bool can_unit_exist_at_tile(const struct civ_map *nmap, const struct unit *punit, const struct tile *ptile)
Definition movement.c:319
unit_can_teleport_to_tile
bool unit_can_teleport_to_tile(const struct civ_map *nmap, const struct unit *punit, const struct tile *dst_tile, bool enter_transport, bool enter_enemy_city)
Definition movement.c:592
unit_can_move_to_tile
bool unit_can_move_to_tile(const struct civ_map *nmap, const struct unit *punit, const struct tile *dst_tile, bool igzoc, bool enter_transport, bool enter_enemy_city)
Definition movement.c:572
movement.h
can_player_see_tile
bool can_player_see_tile(const struct player *plr, const struct tile *ptile)
Definition player.c:1091
can_player_see_unit
bool can_player_see_unit(const struct player *pplayer, const struct unit *punit)
Definition player.c:1104
player_can_see_city_externals
bool player_can_see_city_externals(const struct player *pow_player, const struct city *target_city)
Definition player.c:1164
can_player_see_hypotetic_units_at
bool can_player_see_hypotetic_units_at(const struct player *pplayer, const struct tile *ptile)
Definition player.c:993
slots
struct player_slot * slots
Definition player.c:51
can_player_see_city_internals
bool can_player_see_city_internals(const struct player *pplayer, const struct city *pcity)
Definition player.c:1149
player.h
is_barbarian
static bool is_barbarian(const struct player *pplayer)
Definition player.h:489
requirements.h
can_build_road
bool can_build_road(const struct civ_map *nmap, struct road_type *proad, const struct unit *punit, const struct tile *ptile)
Definition road.c:295
fc_tristate
fc_tristate
Definition shared.h:46
TRI_YES
@ TRI_YES
Definition shared.h:46
TRI_NO
@ TRI_NO
Definition shared.h:46
TRI_MAYBE
@ TRI_MAYBE
Definition shared.h:46
actres
Definition actres.h:112
actres::hostile
bool hostile
Definition actres.h:115
actres::activity
enum unit_activity activity
Definition actres.h:116
actres::def_tgt_kind
enum action_target_kind def_tgt_kind
Definition actres.h:121
actres::dice
enum dice_roll_type dice
Definition actres.h:117
actres::ermcause
enum extra_rmcause ermcause
Definition actres.h:120
actres::sub_tgt_compl
enum act_tgt_compl sub_tgt_compl
Definition actres.h:113
actres::battle_kind
enum action_battle_kind battle_kind
Definition actres.h:114
actres::ecause
enum extra_cause ecause
Definition actres.h:118
city
Definition city.h:320
city::id
int id
Definition city.h:326
city::shield_stock
int shield_stock
Definition city.h:368
civ_game::info
struct packet_game_info info
Definition game.h:89
civ_game::scenario
struct packet_scenario_info scenario
Definition game.h:87
civ_map
Definition map_types.h:71
extra_type
Definition extras.h:88
extra_type::buildable
bool buildable
Definition extras.h:116
functions::player_tile_vision_get
bool(* player_tile_vision_get)(const struct tile *ptile, const struct player *pplayer, enum vision_layer vision)
Definition fc_interface.h:46
packet_game_info::add_to_size_limit
int add_to_size_limit
Definition packets_gen.h:116
packet_game_info::pillage_select
bool pillage_select
Definition packets_gen.h:208
packet_game_info::citymindist
int citymindist
Definition packets_gen.h:145
packet_scenario_info::prevent_new_cities
bool prevent_new_cities
Definition packets_gen.h:1610
player_economic::gold
int gold
Definition player.h:61
player
Definition player.h:247
player::economic
struct player_economic economic
Definition player.h:282
req_context
Definition requirements.h:100
req_context::tile
const struct tile * tile
Definition requirements.h:103
req_context::player
const struct player * player
Definition requirements.h:101
req_context::unittype
const struct unit_type * unittype
Definition requirements.h:107
req_context::unit
const struct unit * unit
Definition requirements.h:106
req_context::city
const struct city * city
Definition requirements.h:102
terrain
Definition terrain.h:182
terrain::cultivate_result
struct terrain * cultivate_result
Definition terrain.h:215
terrain::plant_result
struct terrain * plant_result
Definition terrain.h:218
terrain::pillage_time
int pillage_time
Definition terrain.h:232
terrain::extra_removal_times
int extra_removal_times[MAX_EXTRA_TYPES]
Definition terrain.h:235
terrain::transform_result
struct terrain * transform_result
Definition terrain.h:229
tile
Definition tile.h:50
tile::units
struct unit_list * units
Definition tile.h:58
unit_type::paratroopers_range
int paratroopers_range
Definition unittype.h:541
unit_type::convert_time
int convert_time
Definition unittype.h:531
unit_type::city_slots
int city_slots
Definition unittype.h:552
unit_type::hp
int hp
Definition unittype.h:524
unit
Definition unit.h:138
unit::hp
int hp
Definition unit.h:151
unit::tile
struct tile * tile
Definition unit.h:140
unit::activity_target
struct extra_type * activity_target
Definition unit.h:164
TRUE
#define TRUE
Definition support.h:46
FALSE
#define FALSE
Definition support.h:47
get_preferred_pillage
struct extra_type * get_preferred_pillage(bv_extras extras)
Definition terrain.c:550
T_NONE
#define T_NONE
Definition terrain.h:56
terrain_has_flag
#define terrain_has_flag(terr, flag)
Definition terrain.h:283
tile_has_claimable_base
bool tile_has_claimable_base(const struct tile *ptile, const struct unit_type *punittype)
Definition tile.c:215
tile_activity_time
int tile_activity_time(enum unit_activity activity, const struct tile *ptile, const struct extra_type *tgt)
Definition tile.c:418
tile_get_known
enum known_type tile_get_known(const struct tile *ptile, const struct player *pplayer)
Definition tile.c:392
tile_city
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
tile.h
TILE_UNKNOWN
@ TILE_UNKNOWN
Definition tile.h:36
ACTIVITY_FACTOR
#define ACTIVITY_FACTOR
Definition tile.h:165
tile_terrain
#define tile_terrain(_tile)
Definition tile.h:110
tile_has_extra
#define tile_has_extra(ptile, pextra)
Definition tile.h:147
can_cities_trade
bool can_cities_trade(const struct city *pc1, const struct city *pc2)
Definition traderoutes.c:214
can_establish_trade_route
bool can_establish_trade_route(const struct city *pc1, const struct city *pc2)
Definition traderoutes.c:275
traderoutes.h
unit_transport_get
struct unit * unit_transport_get(const struct unit *pcargo)
Definition unit.c:2437
unit_contained_in
bool unit_contained_in(const struct unit *pcargo, const struct unit *ptrans)
Definition unit.c:2516
test_unit_can_airlift_to
enum unit_airlift_result test_unit_can_airlift_to(const struct civ_map *nmap, const struct player *restriction, const struct unit *punit, const struct city *pdest_city)
Definition unit.c:81
could_unit_load
bool could_unit_load(const struct unit *pcargo, const struct unit *ptrans)
Definition unit.c:696
get_unit_tile_pillage_set
bv_extras get_unit_tile_pillage_set(const struct tile *ptile)
Definition unit.c:1135
get_transporter_capacity
int get_transporter_capacity(const struct unit *punit)
Definition unit.c:299
unit_upgrade_test
enum unit_upgrade_result unit_upgrade_test(const struct civ_map *nmap, const struct unit *punit, bool is_free)
Definition unit.c:1984
unit_transported
bool unit_transported(const struct unit *pcargo)
Definition unit.c:2421
can_unit_unload
bool can_unit_unload(const struct unit *pcargo, const struct unit *ptrans)
Definition unit.c:748
unit_tile
#define unit_tile(_pu)
Definition unit.h:390
unit_owner
#define unit_owner(_pu)
Definition unit.h:389
UU_OK
@ UU_OK
Definition unit.h:61
is_non_allied_unit_tile
static bool is_non_allied_unit_tile(const struct tile *ptile, const struct player *pplayer)
Definition unit.h:425
AR_SRC_NO_FLIGHTS
@ AR_SRC_NO_FLIGHTS
Definition unit.h:84
AR_OK_SRC_UNKNOWN
@ AR_OK_SRC_UNKNOWN
Definition unit.h:75
AR_OK_DST_UNKNOWN
@ AR_OK_DST_UNKNOWN
Definition unit.h:76
AR_NO_MOVES
@ AR_NO_MOVES
Definition unit.h:78
AR_BAD_DST_CITY
@ AR_BAD_DST_CITY
Definition unit.h:83
AR_NOT_IN_CITY
@ AR_NOT_IN_CITY
Definition unit.h:81
AR_OCCUPIED
@ AR_OCCUPIED
Definition unit.h:80
AR_OK
@ AR_OK
Definition unit.h:74
AR_DST_NO_FLIGHTS
@ AR_DST_NO_FLIGHTS
Definition unit.h:85
AR_WRONG_UNITTYPE
@ AR_WRONG_UNITTYPE
Definition unit.h:79
AR_BAD_SRC_CITY
@ AR_BAD_SRC_CITY
Definition unit.h:82
unit_list_iterate
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
unit_list_iterate_end
#define unit_list_iterate_end
Definition unitlist.h:33
unit_type_get
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:123
utype_player_already_has_this_unique
bool utype_player_already_has_this_unique(const struct player *pplayer, const struct unit_type *putype)
Definition unittype.c:1927
unit_class_get
struct unit_class * unit_class_get(const struct unit *punit)
Definition unittype.c:2498
unit_has_type_role
bool unit_has_type_role(const struct unit *punit, enum unit_role_id role)
Definition unittype.c:208
unit_has_type_flag
bool unit_has_type_flag(const struct unit *punit, enum unit_type_flag_id flag)
Definition unittype.c:190
unit_pop_value
int unit_pop_value(const struct unit *punit)
Definition unittype.c:1543
uclass_has_flag
static bool uclass_has_flag(const struct unit_class *punitclass, enum unit_class_flag_id flag)
Definition unittype.h:766