Freeciv-3.2
Loading...
Searching...
No Matches
pf_tools.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 2003 - The Freeciv Project
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18#include <string.h>
19
20/* utility */
21#include "bitvector.h"
22#include "log.h"
23#include "mem.h"
24
25/* common */
26#include "base.h"
27#include "combat.h"
28#include "game.h"
29#include "movement.h"
30#include "tile.h"
31#include "unit.h"
32#include "unittype.h"
33
34/* aicore */
35#include "aiactions.h"
36
37#include "pf_tools.h"
38
39/* ===================== Capability Functions ======================== */
40
41/************************************************************************/
45static inline bool pf_attack_possible(const struct tile *ptile,
46 enum known_type known,
47 const struct pf_parameter *param)
48{
49 bool non_allied_city;
50 bool attack_any;
51
52 if (!can_attack_non_native(param->utype)
53 && !is_native_tile(param->utype, ptile)) {
54 return FALSE;
55 }
56
57 if (TILE_KNOWN_SEEN != known) {
58 /* We cannot see units, let's assume we can attack. */
59 return TRUE;
60 }
61
64
66 /* Any non-hostile unit will fail the whole stack*/
67 if (!pplayers_at_war(unit_owner(punit), param->owner)) {
68 return FALSE;
69 }
70
71 /* Hostile unit reachability test. */
74 || non_allied_city) {
76 } else if (game.info.unreachable_protects) {
77 /* We get here if punit is unreachable to utype */
79 return FALSE;
80 }
81 /* NB: if there are UTYF_NEVER_PROTECTS units on the tile, 'attack_any'
82 has to get set TRUE at least once to enable an attack to the tile,
83 which is exactly correct behaviour. */
84 }
86
87 return attack_any;
88}
89
90/************************************************************************/
96static enum pf_action pf_get_action(const struct tile *ptile,
97 enum known_type known,
98 const struct pf_parameter *param)
99{
100 bool non_allied_city = is_non_allied_city_tile(ptile, param->owner);
101
102 if (non_allied_city) {
103 if (PF_AA_TRADE_ROUTE & param->actions) {
105 }
106
107 if (PF_AA_DIPLOMAT & param->actions) {
108 return PF_ACTION_DIPLOMAT;
109 }
110 }
111
112 if (is_non_allied_unit_tile(ptile, param->owner)) {
113 if (PF_AA_DIPLOMAT & param->actions) {
114 return PF_ACTION_DIPLOMAT;
115 }
116
117 if (PF_AA_UNIT_ATTACK & param->actions) {
118 return (pf_attack_possible(ptile, known, param)
120 }
121 }
122
123 if (non_allied_city && PF_AA_CITY_ATTACK & param->actions) {
124 /* Consider that there are potentially units, even if
125 * is_non_allied_unit_tile() returned NULL (usually when
126 * '!param->omniscience'). */
127 return ((utype_can_take_over(param->utype)
128 || pf_attack_possible(ptile, TILE_KNOWN_UNSEEN, param))
130 }
131
132 return PF_ACTION_NONE;
133}
134
135/************************************************************************/
139static bool pf_action_possible(const struct tile *src,
141 const struct tile *dst,
142 enum pf_action action,
143 const struct pf_parameter *param)
144{
145 if (PF_ACTION_ATTACK == action) {
146 return (PF_MS_NATIVE & src_scope
148
149 } else if (PF_ACTION_DIPLOMAT == action
151 /* Don't try to act when inside of a transport over non native terrain
152 * when all actions the unit type can do requires the unit to be on
153 * native terrain. */
156 } else {
157 return (PF_MS_NATIVE | PF_MS_CITY) & src_scope;
158 }
159 }
160 return TRUE;
161}
162
163/************************************************************************/
167static enum pf_action pf_reverse_get_action(const struct tile *ptile,
168 enum known_type known,
169 const struct pf_parameter *param)
170{
171 return (ptile == param->data ? PF_ACTION_ATTACK : PF_ACTION_NONE);
172}
173
174/************************************************************************/
177static inline bool pf_transport_check(const struct pf_parameter *param,
178 const struct unit *ptrans,
179 const struct unit_type *trans_utype)
180{
182 || param->utype == trans_utype
186 < 1 + unit_transport_depth(ptrans) + param->cargo_depth)) {
187 return FALSE;
188 }
189
190 if (1 <= param->cargo_depth) {
196 return FALSE;
197 }
199 }
200
203 || param->utype == (trans_utype = unit_type_get(pparent))
205 return FALSE;
206 }
207
208 if (1 <= param->cargo_depth) {
214 return FALSE;
215 }
217 }
219
220 return TRUE;
221}
222
223/************************************************************************/
227static enum pf_move_scope
228pf_get_move_scope(const struct tile *ptile,
229 bool *can_disembark,
231 const struct pf_parameter *param)
232{
234 const struct unit_class *uclass = utype_class(param->utype);
235 struct city *pcity = tile_city(ptile);
236
237 if ((is_native_tile_to_class(uclass, ptile)
239 || is_safe_ocean(param->map, ptile)))) {
241 }
242
243 if (NULL != pcity
244 && (utype_can_take_over(param->utype)
245 || pplayers_allied(param->owner, city_owner(pcity)))
246 && ((previous_scope & PF_MS_CITY) /* City channel previously tested */
248 || is_native_near_tile(param->map, uclass, ptile)
249 || (1 == game.info.citymindist
250 && is_city_channel_tile(param->map, uclass, ptile, NULL)))) {
251 scope |= PF_MS_CITY;
252 }
253
254 if (PF_MS_NONE == scope) {
255 /* Check for transporters. Useless if we already got another way to
256 * move. */
257 bool allied_city_tile = (NULL != pcity
258 && pplayers_allied(param->owner,
259 city_owner(pcity)));
260 const struct unit_type *utype;
261
263
264 unit_list_iterate(ptile->units, punit) {
265 utype = unit_type_get(punit);
266
267 if (!pf_transport_check(param, punit, utype)) {
268 continue;
269 }
270
272 || tile_has_native_base(ptile, utype)) {
274
275 /* If transport is moving, we are not going to continue where we expected
276 * through it. */
278 break;
279 }
280
281 if (!utype_can_freely_load(param->utype, utype)) {
282 continue;
283 }
284
286
287 if (utype_can_freely_unload(param->utype, utype)) {
288
289 /* If transport is moving, we are not going to continue where we expected
290 * through it. */
292 break;
293 }
295 }
296
297 return scope;
298}
299
300/************************************************************************/
303static enum pf_move_scope
304amphibious_move_scope(const struct tile *ptile,
305 bool *can_disembark,
307 const struct pf_parameter *param)
308{
309 struct pft_amphibious *amphibious = param->data;
311 bool dumb;
312
314 &amphibious->land);
316
319 || utype_can_freely_unload(amphibious->land.utype,
320 amphibious->sea.utype)
321 || tile_has_native_base(ptile, amphibious->sea.utype));
323 }
325}
326
327/************************************************************************/
335static inline bool pf_move_possible(const struct tile *src,
337 const struct tile *dst,
339 const struct pf_parameter *param)
340{
342
343 if (PF_MS_NONE == dst_scope) {
344 return FALSE;
345 }
346
349 && !is_native_move(param->map, utype_class(param->utype), src, dst)) {
350 return FALSE;
351 }
352
353 return TRUE;
354}
355
356
357/* ===================== Move Cost Callbacks ========================= */
358
359/************************************************************************/
364static unsigned normal_move(const struct tile *src,
366 const struct tile *dst,
368 const struct pf_parameter *param)
369{
370 if (pf_move_possible(src, src_scope, dst, dst_scope, param)) {
371 return map_move_cost(param->map, param->owner, param->utype, src, dst);
372 }
373
374 return PF_IMPOSSIBLE_MC;
375}
376
377/************************************************************************/
384static unsigned overlap_move(const struct tile *src,
386 const struct tile *dst,
388 const struct pf_parameter *param)
389{
390 if (pf_move_possible(src, src_scope, dst, dst_scope, param)) {
391 return map_move_cost(param->map, param->owner, param->utype, src, dst);
392 } else if (!(PF_MS_NATIVE & dst_scope)) {
393 /* This should always be the last tile reached. */
394 return param->move_rate;
395 }
396
397 return PF_IMPOSSIBLE_MC;
398}
399
400/************************************************************************/
403static unsigned amphibious_move(const struct tile *ptile,
405 const struct tile *ptile1,
407 const struct pf_parameter *param)
408{
409 struct pft_amphibious *amphibious = param->data;
410 unsigned cost;
411 int scale;
412
415 /* Sea move, moving from native terrain to a city, or leaving port. */
416 cost = amphibious->sea.get_MC(ptile,
418 ptile1,
420 &amphibious->sea);
421 scale = amphibious->sea_scale;
422 } else if (PF_MS_NATIVE & dst_scope) {
423 /* Disembark; use land movement function to handle non-native attacks. */
424 cost = amphibious->land.get_MC(ptile, PF_MS_TRANSPORT, ptile1,
425 PF_MS_NATIVE, &amphibious->land);
426 scale = amphibious->land_scale;
427 } else {
428 /* Neither ferry nor passenger can enter tile. */
429 return PF_IMPOSSIBLE_MC;
430 }
431 } else if ((PF_MS_NATIVE | PF_MS_CITY) & dst_scope) {
432 /* Land move */
433 cost = amphibious->land.get_MC(ptile, PF_MS_NATIVE, ptile1,
434 PF_MS_NATIVE, &amphibious->land);
435 scale = amphibious->land_scale;
436 } else {
437 /* Now we have disembarked, our ferry can not help us - we have to
438 * stay on the land. */
439 return PF_IMPOSSIBLE_MC;
440 }
442 cost *= scale;
443 }
444
445 return cost;
446}
447
448/* ===================== Extra Cost Callbacks ======================== */
449
450/************************************************************************/
453static unsigned amphibious_extra_cost(const struct tile *ptile,
454 enum known_type known,
455 const struct pf_parameter *param)
456{
457 struct pft_amphibious *amphibious = param->data;
458 const bool ferry_move = is_native_tile(amphibious->sea.utype, ptile);
459 unsigned cost;
460 int scale;
461
462 if (known == TILE_UNKNOWN) {
463 /* We can travel almost anywhere */
465 scale = MAX(amphibious->sea_scale, amphibious->land_scale);
466 } else if (ferry_move && amphibious->sea.get_EC) {
467 /* Do the EC callback for sea moves. */
468 cost = amphibious->sea.get_EC(ptile, known, &amphibious->sea);
469 scale = amphibious->sea_scale;
470 } else if (!ferry_move && amphibious->land.get_EC) {
471 /* Do the EC callback for land moves. */
472 cost = amphibious->land.get_EC(ptile, known, &amphibious->land);
473 scale = amphibious->land_scale;
474 } else {
475 cost = 0;
476 scale = 1;
477 }
478
479 if (cost != PF_IMPOSSIBLE_MC) {
480 cost *= scale;
481 }
482
483 return cost;
484}
485
486
487/* ===================== Tile Behaviour Callbacks ==================== */
488
489/************************************************************************/
493enum tile_behavior no_fights_or_unknown(const struct tile *ptile,
494 enum known_type known,
495 const struct pf_parameter *param)
496{
497 if (known == TILE_UNKNOWN
498 || is_non_allied_unit_tile(ptile, param->owner)
499 || is_non_allied_city_tile(ptile, param->owner)) {
500 /* Can't attack */
501 return TB_IGNORE;
502 }
503 return TB_NORMAL;
504}
505
506/************************************************************************/
509enum tile_behavior no_fights(const struct tile *ptile,
510 enum known_type known,
511 const struct pf_parameter *param)
512{
513 if (is_non_allied_unit_tile(ptile, param->owner)
514 || is_non_allied_city_tile(ptile, param->owner)) {
515 /* Can't attack */
516 return TB_IGNORE;
517 }
518 return TB_NORMAL;
519}
520
521/************************************************************************/
525 enum known_type known,
526 const struct pf_parameter *param)
527{
528 if (is_non_allied_unit_tile(ptile, param->owner)
529 || is_non_allied_city_tile(ptile, param->owner)) {
530 return TB_DONT_LEAVE;
531 }
532 return TB_NORMAL;
533}
534
535/************************************************************************/
538static enum tile_behavior
539amphibious_behaviour(const struct tile *ptile, enum known_type known,
540 const struct pf_parameter *param)
541{
542 struct pft_amphibious *amphibious = param->data;
543 const bool ferry_move = is_native_tile(amphibious->sea.utype, ptile);
544
545 /* Simply a wrapper for the sea or land tile_behavior callbacks. */
546 if (ferry_move && amphibious->sea.get_TB) {
547 return amphibious->sea.get_TB(ptile, known, &amphibious->sea);
548 } else if (!ferry_move && amphibious->land.get_TB) {
549 return amphibious->land.get_TB(ptile, known, &amphibious->land);
550 }
551 return TB_NORMAL;
552}
553
554/* ===================== Required Moves Lefts Callbacks ================= */
555
556/************************************************************************/
559static bool is_possible_base_fuel(const struct tile *ptile,
560 const struct pf_parameter *param)
561{
562 const struct unit_class *uclass;
563 enum known_type tile_known = (param->omniscience ? TILE_KNOWN_SEEN
564 : tile_get_known(ptile, param->owner));
565
566 if (tile_known == TILE_UNKNOWN) {
567 /* Cannot guess if it is */
568 return FALSE;
569 }
570
571 if (is_allied_city_tile(ptile, param->owner)) {
572 return TRUE;
573 }
574
575 uclass = utype_class(param->utype);
577 /* All airbases are considered possible, simply attack enemies. */
578 if (tile_has_extra(ptile, pextra)) {
579 return TRUE;
580 }
582
583 if (utype_has_flag(param->utype, UTYF_COAST)) {
584 return is_safe_ocean(param->map, ptile);
585 }
586
587 if (tile_known == TILE_KNOWN_UNSEEN) {
588 /* Cannot see units */
589 return FALSE;
590 }
591
592 /* Check for carriers */
594 const struct unit_type *trans_utype = unit_type_get(ptrans);
595
597 && !unit_has_orders(ptrans) /* Don't load to moving carrier */
599 || tile_has_native_base(ptile, trans_utype))) {
600 return TRUE;
601 }
603
604 return FALSE;
605}
606
607/************************************************************************/
610static int get_closest_safe_tile_distance(const struct tile *src_tile,
611 const struct pf_parameter *param,
612 int max_distance)
613{
614 /* This iteration should, according to the documentation in map.h iterate
615 * tiles from the center tile, so we stop the iteration to the first found
616 * refuel point (as it should be the closest). */
617 iterate_outward_dxy(param->map, src_tile, max_distance, ptile, x, y) {
618 if (tile_get_known(ptile, param->owner) == TILE_UNKNOWN) {
619 /* Cannot guess if the tile is safe */
620 continue;
621 }
622 if (is_possible_base_fuel(ptile, param)) {
624 }
626
627 return -1;
628}
629
630/* ==================== Position Dangerous Callbacks =================== */
631
632/************************************************************************/
635static int get_fuel_moves_left_req(const struct tile *ptile,
636 enum known_type known,
637 const struct pf_parameter *param)
638{
639 int dist, max;
640
641 if (is_possible_base_fuel(ptile, param)) {
642 return 0;
643 }
644
645 /* Upper bound for search for refuel point. Sometimes unit can have more
646 * moves left than its own move rate due to wonder transfer. Compare
647 * pf_moves_left_initially(). */
648 max = MAX(param->moves_left_initially
649 + (param->fuel_left_initially - 1) * param->move_rate,
650 param->move_rate * param->fuel);
651 dist = get_closest_safe_tile_distance(ptile, param, max / SINGLE_MOVE);
652
653 return dist != -1 ? dist * SINGLE_MOVE : PF_IMPOSSIBLE_MC;
654}
655
656/************************************************************************/
659static bool amphibious_is_pos_dangerous(const struct tile *ptile,
660 enum known_type known,
661 const struct pf_parameter *param)
662{
663 struct pft_amphibious *amphibious = param->data;
664 const bool ferry_move = is_native_tile(amphibious->sea.utype, ptile);
665
666 /* Simply a wrapper for the sea or land danger callbacks. */
667 if (ferry_move && amphibious->sea.is_pos_dangerous) {
668 return amphibious->sea.is_pos_dangerous(ptile, known, param);
669 } else if (!ferry_move && amphibious->land.is_pos_dangerous) {
670 return amphibious->land.is_pos_dangerous(ptile, known, param);
671 }
672 return FALSE;
673}
674
675/* ======================= Tools for filling parameters ================= */
676
677/************************************************************************/
680static inline void
682 const struct civ_map *nmap,
683 const struct unit_type *punittype)
684{
685 parameter->map = nmap;
686 parameter->get_TB = NULL;
687 parameter->get_EC = NULL;
688 parameter->is_pos_dangerous = NULL;
689 parameter->get_moves_left_req = NULL;
690 parameter->get_costs = NULL;
691 parameter->get_zoc = NULL;
693 parameter->get_action = NULL;
694 parameter->is_action_possible = NULL;
695 parameter->actions = PF_AA_NONE;
696
697 parameter->utype = punittype;
698}
699
700/************************************************************************/
703static inline void
705{
706 if (!utype_has_flag(parameter->utype, UTYF_CIVILIAN)) {
707 parameter->actions |= PF_AA_UNIT_ATTACK;
708 parameter->get_action = pf_get_action;
710 if (!parameter->omniscience) {
711 /* Consider units hidden in cities. */
712 parameter->actions |= PF_AA_CITY_ATTACK;
713 }
714 }
715 if (utype_may_act_at_all(parameter->utype)) {
716 /* FIXME: it should consider action enablers. */
718 parameter->actions |= PF_AA_TRADE_ROUTE;
719 }
720 if (aia_utype_is_considered_spy(parameter->utype)) {
721 parameter->actions |= PF_AA_DIPLOMAT;
722 }
723 parameter->get_action = pf_get_action;
725 }
726}
727
728/************************************************************************/
731static inline void
733 const struct civ_map *nmap,
734 const struct unit_type *punittype,
735 struct tile *pstart_tile,
736 struct player *powner)
737{
740
743 }
744
746
747 parameter->start_tile = pstart_tile;
748 parameter->moves_left_initially = punittype->move_rate;
749 parameter->move_rate = utype_move_rate(punittype, pstart_tile, powner,
751 if (utype_fuel(punittype)) {
753 parameter->fuel = utype_fuel(punittype);
754 } else {
755 parameter->fuel = 1;
756 parameter->fuel_left_initially = 1;
757 }
758 parameter->transported_by_initially = NULL;
759 parameter->cargo_depth = 0;
760 BV_CLR_ALL(parameter->cargo_types);
761 parameter->owner = powner;
762
763 parameter->omniscience = FALSE;
764}
765
766/************************************************************************/
769static inline void
771 const struct civ_map *nmap,
772 const struct unit *punit)
773{
774 const struct unit *ptrans = unit_transport_get(punit);
775 const struct unit_type *ptype = unit_type_get(punit);
776
778
779 parameter->start_tile = unit_tile(punit);
781 parameter->move_rate = unit_move_rate(punit);
782 if (utype_fuel(ptype)) {
783 parameter->fuel_left_initially = punit->fuel;
784 parameter->fuel = utype_fuel(ptype);
785 } else {
786 parameter->fuel = 1;
787 parameter->fuel_left_initially = 1;
788 }
790 : NULL);
791 parameter->cargo_depth = unit_cargo_depth(punit);
792 BV_CLR_ALL(parameter->cargo_types);
796 parameter->owner = unit_owner(punit);
797
798 parameter->omniscience = FALSE;
799}
800
801/************************************************************************/
804static inline void pft_fill_parameter(struct pf_parameter *parameter,
805 const struct unit_type *punittype)
806{
807 parameter->get_MC = normal_move;
808 parameter->ignore_none_scopes = TRUE;
810
811 if (!parameter->get_moves_left_req && utype_fuel(punittype)) {
812 /* Unit needs fuel */
814 }
815
818 } else {
819 parameter->get_zoc = NULL;
820 }
821}
822
823/************************************************************************/
827 const struct civ_map *nmap,
828 const struct unit_type *punittype,
829 struct tile *pstart_tile,
830 struct player *pplayer)
831{
833 pstart_tile, pplayer);
834 pft_fill_parameter(parameter, punittype);
835}
836
837/************************************************************************/
841 const struct civ_map *nmap,
842 const struct unit *punit)
843{
846}
847
848/************************************************************************/
854static void pft_fill_overlap_param(struct pf_parameter *parameter,
855 const struct unit_type *punittype)
856{
857 parameter->get_MC = overlap_move;
858 parameter->ignore_none_scopes = FALSE;
859
862 } else {
863 parameter->get_zoc = NULL;
864 }
865
866 if (!parameter->get_moves_left_req && utype_fuel(punittype)) {
867 /* Unit needs fuel */
869 }
870}
871
872/************************************************************************/
877 const struct civ_map *nmap,
878 const struct unit_type *punittype,
879 struct tile *pstart_tile,
880 struct player *pplayer)
881{
883 pstart_tile, pplayer);
885}
886
887/************************************************************************/
892 const struct civ_map *nmap,
893 const struct unit *punit)
894{
897}
898
899/************************************************************************/
904static void pft_fill_attack_param(struct pf_parameter *parameter,
905 const struct unit_type *punittype)
906{
907 parameter->get_MC = normal_move;
908 parameter->ignore_none_scopes = TRUE;
910 /* We want known units! */
911 parameter->actions &= ~PF_AA_CITY_ATTACK;
912
915 } else {
916 parameter->get_zoc = NULL;
917 }
918
919 /* It is too complicated to work with danger here */
920 parameter->is_pos_dangerous = NULL;
921
922 if (!parameter->get_moves_left_req && utype_fuel(punittype)) {
923 /* Unit needs fuel */
925 }
926}
927
928/************************************************************************/
934 const struct civ_map *nmap,
935 const struct unit_type *punittype,
936 struct tile *pstart_tile,
937 struct player *pplayer)
938{
940 pstart_tile, pplayer);
942}
943
944/************************************************************************/
950 const struct civ_map *nmap,
951 const struct unit *punit)
952{
955}
956
957/************************************************************************/
961 struct pf_parameter *parameter,
962 struct tile *target_tile)
963{
964 memset(parameter, 0, sizeof(*parameter));
965
966 parameter->map = nmap;
967
968 /* We ignore refuel bases in reverse mode. */
969 parameter->fuel = 1;
970 parameter->fuel_left_initially = 1;
971
972 parameter->get_MC = normal_move;
974 parameter->ignore_none_scopes = TRUE;
975
977 parameter->data = target_tile;
978
979 /* Other data may stay at zero. */
980}
981
982/************************************************************************/
995{
996 const int move_rate = parameter->land.move_rate * parameter->sea.move_rate;
997
998 parameter->sea.cargo_depth = 1;
999 BV_SET(parameter->sea.cargo_types, utype_index(parameter->land.utype));
1000
1001 parameter->combined = parameter->sea;
1002 parameter->land_scale = move_rate / parameter->land.move_rate;
1003 parameter->sea_scale = move_rate / parameter->sea.move_rate;
1004 parameter->combined.moves_left_initially *= parameter->sea_scale;
1005 parameter->combined.move_rate = move_rate;
1006 parameter->combined.get_MC = amphibious_move;
1010 if (NULL != parameter->land.is_pos_dangerous
1011 || NULL != parameter->sea.is_pos_dangerous) {
1013 } else {
1014 parameter->combined.is_pos_dangerous = NULL;
1015 }
1016 if (parameter->sea.get_moves_left_req != NULL) {
1017 parameter->combined.get_moves_left_req = parameter->sea.get_moves_left_req;
1018 } else if (parameter->land.get_moves_left_req != NULL) {
1019 parameter->combined.get_moves_left_req = parameter->land.get_moves_left_req;
1020 } else {
1021 parameter->combined.get_moves_left_req = NULL;
1022 }
1023 parameter->combined.get_action = NULL;
1024 parameter->combined.is_action_possible = NULL;
1025
1026 parameter->combined.data = parameter;
1027}
bool aia_utype_is_considered_caravan_trade(const struct unit_type *putype)
Definition aiactions.c:66
bool aia_utype_is_considered_spy(const struct unit_type *putype)
Definition aiactions.c:51
#define BV_CLR_ALL(bv)
Definition bitvector.h:95
#define BV_SET(bv, bit)
Definition bitvector.h:81
#define BV_ISSET(bv, bit)
Definition bitvector.h:78
static bool is_non_allied_city_tile(const struct tile *ptile, const struct player *pplayer)
Definition city.h:770
static bool is_allied_city_tile(const struct tile *ptile, const struct player *pplayer)
Definition city.h:746
#define city_owner(_pcity_)
Definition city.h:563
char * incite_cost
Definition comments.c:75
struct unit struct city struct unit struct tile * target_tile
Definition dialogs_g.h:57
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
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 int cost
Definition dialogs_g.h:74
int get_unittype_bonus(const struct player *pplayer, const struct tile *ptile, const struct unit_type *punittype, const struct action *paction, enum effect_type effect_type)
Definition effects.c:1035
#define extra_type_list_iterate(extralist, pextra)
Definition extras.h:165
#define extra_type_list_iterate_end
Definition extras.h:167
static bool is_server(void)
struct civ_game game
Definition game.c:62
#define GAME_TRANSPORT_MAX_RECURSIVE
Definition game.h:762
#define fc_assert(condition)
Definition log.h:176
bool is_safe_ocean(const struct civ_map *nmap, const struct tile *ptile)
Definition map.c:667
int map_vector_to_real_distance(int dx, int dy)
Definition map.c:578
#define iterate_outward_dxy_end
Definition map.h:362
#define iterate_outward_dxy(nmap, start_tile, max_dist, _tile, _x, _y)
Definition map.h:339
static int map_move_cost(const struct civ_map *nmap, const struct player *pplayer, const struct unit_type *punittype, const struct tile *src_tile, const struct tile *dst_tile)
Definition map.h:305
bool is_native_tile(const struct unit_type *punittype, const struct tile *ptile)
Definition movement.c:331
int unit_move_rate(const struct unit *punit)
Definition movement.c:90
bool can_attack_from_non_native(const struct unit_type *utype)
Definition movement.c:227
bool is_native_move(const struct civ_map *nmap, const struct unit_class *punitclass, const struct tile *src_tile, const struct tile *dst_tile)
Definition movement.c:373
int utype_move_rate(const struct unit_type *utype, const struct tile *ptile, const struct player *pplayer, int veteran_level, int hitpoints)
Definition movement.c:47
bool is_city_channel_tile(const struct civ_map *nmap, const struct unit_class *punitclass, const struct tile *ptile, const struct tile *pexclude)
Definition movement.c:243
bool is_native_near_tile(const struct civ_map *nmap, const struct unit_class *uclass, const struct tile *ptile)
Definition movement.c:465
bool can_unit_type_transport(const struct unit_type *transporter, const struct unit_class *transported)
Definition movement.c:868
bool can_attack_non_native(const struct unit_type *utype)
Definition movement.c:214
#define SINGLE_MOVE
Definition movement.h:26
static bool is_native_tile_to_class(const struct unit_class *punitclass, const struct tile *ptile)
Definition movement.h:84
#define PF_IMPOSSIBLE_MC
pf_action
@ PF_ACTION_ATTACK
@ PF_ACTION_DIPLOMAT
@ PF_ACTION_TRADE_ROUTE
@ PF_ACTION_IMPOSSIBLE
@ PF_ACTION_NONE
pf_move_scope
@ PF_MS_TRANSPORT
@ PF_MS_CITY
@ PF_MS_NATIVE
@ PF_MS_NONE
@ PF_AA_CITY_ATTACK
@ PF_AA_UNIT_ATTACK
@ PF_AA_NONE
@ PF_AA_DIPLOMAT
@ PF_AA_TRADE_ROUTE
tile_behavior
@ TB_NORMAL
@ TB_DONT_LEAVE
@ TB_IGNORE
void pft_fill_unit_parameter(struct pf_parameter *parameter, const struct civ_map *nmap, const struct unit *punit)
Definition pf_tools.c:840
void pft_fill_unit_attack_param(struct pf_parameter *parameter, const struct civ_map *nmap, const struct unit *punit)
Definition pf_tools.c:949
static void pft_fill_utype_default_parameter(struct pf_parameter *parameter, const struct civ_map *nmap, const struct unit_type *punittype, struct tile *pstart_tile, struct player *powner)
Definition pf_tools.c:732
void pft_fill_unit_overlap_param(struct pf_parameter *parameter, const struct civ_map *nmap, const struct unit *punit)
Definition pf_tools.c:891
static void pft_fill_overlap_param(struct pf_parameter *parameter, const struct unit_type *punittype)
Definition pf_tools.c:854
void pft_fill_reverse_parameter(const struct civ_map *nmap, struct pf_parameter *parameter, struct tile *target_tile)
Definition pf_tools.c:960
static bool pf_action_possible(const struct tile *src, enum pf_move_scope src_scope, const struct tile *dst, enum pf_action action, const struct pf_parameter *param)
Definition pf_tools.c:139
static int get_fuel_moves_left_req(const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
Definition pf_tools.c:635
void pft_fill_utype_attack_param(struct pf_parameter *parameter, const struct civ_map *nmap, const struct unit_type *punittype, struct tile *pstart_tile, struct player *pplayer)
Definition pf_tools.c:933
static enum pf_move_scope pf_get_move_scope(const struct tile *ptile, bool *can_disembark, enum pf_move_scope previous_scope, const struct pf_parameter *param)
Definition pf_tools.c:228
static unsigned overlap_move(const struct tile *src, enum pf_move_scope src_scope, const struct tile *dst, enum pf_move_scope dst_scope, const struct pf_parameter *param)
Definition pf_tools.c:384
static void pft_fill_default_parameter(struct pf_parameter *parameter, const struct civ_map *nmap, const struct unit_type *punittype)
Definition pf_tools.c:681
static void pft_fill_unit_default_parameter(struct pf_parameter *parameter, const struct civ_map *nmap, const struct unit *punit)
Definition pf_tools.c:770
static bool pf_transport_check(const struct pf_parameter *param, const struct unit *ptrans, const struct unit_type *trans_utype)
Definition pf_tools.c:177
static enum pf_action pf_get_action(const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
Definition pf_tools.c:96
enum tile_behavior no_fights(const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
Definition pf_tools.c:509
static void pft_fill_attack_param(struct pf_parameter *parameter, const struct unit_type *punittype)
Definition pf_tools.c:904
static enum pf_action pf_reverse_get_action(const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
Definition pf_tools.c:167
static bool pf_attack_possible(const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
Definition pf_tools.c:45
void pft_fill_utype_overlap_param(struct pf_parameter *parameter, const struct civ_map *nmap, const struct unit_type *punittype, struct tile *pstart_tile, struct player *pplayer)
Definition pf_tools.c:876
static void pft_enable_default_actions(struct pf_parameter *parameter)
Definition pf_tools.c:704
static enum tile_behavior amphibious_behaviour(const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
Definition pf_tools.c:539
static bool pf_move_possible(const struct tile *src, enum pf_move_scope src_scope, const struct tile *dst, enum pf_move_scope dst_scope, const struct pf_parameter *param)
Definition pf_tools.c:335
static unsigned amphibious_extra_cost(const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
Definition pf_tools.c:453
enum tile_behavior no_intermediate_fights(const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
Definition pf_tools.c:524
static unsigned amphibious_move(const struct tile *ptile, enum pf_move_scope src_scope, const struct tile *ptile1, enum pf_move_scope dst_scope, const struct pf_parameter *param)
Definition pf_tools.c:403
static unsigned normal_move(const struct tile *src, enum pf_move_scope src_scope, const struct tile *dst, enum pf_move_scope dst_scope, const struct pf_parameter *param)
Definition pf_tools.c:364
static bool is_possible_base_fuel(const struct tile *ptile, const struct pf_parameter *param)
Definition pf_tools.c:559
static int get_closest_safe_tile_distance(const struct tile *src_tile, const struct pf_parameter *param, int max_distance)
Definition pf_tools.c:610
static bool amphibious_is_pos_dangerous(const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
Definition pf_tools.c:659
enum tile_behavior no_fights_or_unknown(const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
Definition pf_tools.c:493
static enum pf_move_scope amphibious_move_scope(const struct tile *ptile, bool *can_disembark, enum pf_move_scope previous_scope, const struct pf_parameter *param)
Definition pf_tools.c:304
void pft_fill_amphibious_parameter(struct pft_amphibious *parameter)
Definition pf_tools.c:994
void pft_fill_utype_parameter(struct pf_parameter *parameter, const struct civ_map *nmap, const struct unit_type *punittype, struct tile *pstart_tile, struct player *pplayer)
Definition pf_tools.c:826
static void pft_fill_parameter(struct pf_parameter *parameter, const struct unit_type *punittype)
Definition pf_tools.c:804
bool pplayers_at_war(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1388
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1405
#define FC_INFINITY
Definition shared.h:36
#define MAX(x, y)
Definition shared.h:54
struct sprite int int y
Definition sprite_g.h:31
struct sprite int int int int struct sprite int int float scale
Definition sprite_g.h:33
struct sprite int x
Definition sprite_g.h:31
Definition city.h:320
struct packet_game_info info
Definition game.h:89
int fuel_left_initially
const struct unit_type * transported_by_initially
enum pf_action(* get_action)(const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
enum pf_move_scope(* get_move_scope)(const struct tile *ptile, bool *can_disembark, enum pf_move_scope previous_scope, const struct pf_parameter *param)
bool ignore_none_scopes
const struct civ_map * map
enum tile_behavior(* get_TB)(const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
enum pf_action_account actions
const struct player * owner
bool(* is_pos_dangerous)(const struct tile *ptile, enum known_type, const struct pf_parameter *param)
int(* get_moves_left_req)(const struct tile *ptile, enum known_type, const struct pf_parameter *param)
int moves_left_initially
bool(* get_zoc)(const struct player *pplayer, const struct tile *ptile, const struct civ_map *zmap)
unsigned(* get_MC)(const struct tile *from_tile, enum pf_move_scope src_move_scope, const struct tile *to_tile, enum pf_move_scope dst_move_scope, const struct pf_parameter *param)
int(* get_costs)(const struct tile *from_tile, enum direction8 dir, const struct tile *to_tile, int from_cost, int from_extra, unsigned *to_cost, unsigned *to_extra, const struct pf_parameter *param)
unsigned(* get_EC)(const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
const struct unit_type * utype
bool(* is_action_possible)(const struct tile *from_tile, enum pf_move_scope src_move_scope, const struct tile *to_tile, enum pf_action action, const struct pf_parameter *param)
bv_unit_types cargo_types
struct tile * start_tile
struct pf_parameter combined
Definition pf_tools.h:42
struct pf_parameter land sea
Definition pf_tools.h:38
Definition tile.h:50
struct unit_list * units
Definition tile.h:58
struct extra_type_list * refuel_extras
Definition unittype.h:168
struct unit_class::@86 cache
int move_rate
Definition unittype.h:517
bv_unit_classes targets
Definition unittype.h:561
Definition unit.h:138
int moves_left
Definition unit.h:150
int fuel
Definition unit.h:153
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
bool tile_has_native_base(const struct tile *ptile, const struct unit_type *punittype)
Definition tile.c:324
enum known_type tile_get_known(const struct tile *ptile, const struct player *pplayer)
Definition tile.c:392
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
known_type
Definition tile.h:35
@ TILE_KNOWN_UNSEEN
Definition tile.h:37
@ TILE_UNKNOWN
Definition tile.h:36
@ TILE_KNOWN_SEEN
Definition tile.h:38
#define tile_has_extra(ptile, pextra)
Definition tile.h:147
bool unit_type_really_ignores_zoc(const struct unit_type *punittype)
Definition unit.c:1504
bool is_plr_zoc_client(const struct player *pplayer, const struct tile *ptile0, const struct civ_map *zmap)
Definition unit.c:1456
int unit_transport_depth(const struct unit *pcargo)
Definition unit.c:2551
struct unit * unit_transport_get(const struct unit *pcargo)
Definition unit.c:2441
int unit_cargo_depth(const struct unit *ptrans)
Definition unit.c:2533
bool is_plr_zoc_srv(const struct player *pplayer, const struct tile *ptile0, const struct civ_map *zmap)
Definition unit.c:1387
bool unit_has_orders(const struct unit *punit)
Definition unit.c:202
#define unit_tile(_pu)
Definition unit.h:397
#define unit_transports_iterate_end
Definition unit.h:563
#define unit_cargo_iterate_end
Definition unit.h:573
#define unit_cargo_iterate(_ptrans, _pcargo)
Definition unit.h:570
#define unit_owner(_pu)
Definition unit.h:396
#define unit_transports_iterate(_pcargo, _ptrans)
Definition unit.h:559
static bool is_non_allied_unit_tile(const struct tile *ptile, const struct player *pplayer)
Definition unit.h:432
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
#define unit_list_iterate_end
Definition unitlist.h:33
bool can_unit_act_when_ustate_is(const struct unit_type *punit_type, const enum ustate_prop prop, const bool is_there)
Definition unittype.c:943
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:123
bool utype_can_freely_unload(const struct unit_type *pcargotype, const struct unit_type *ptranstype)
Definition unittype.c:300
bool utype_may_act_at_all(const struct unit_type *putype)
Definition unittype.c:359
bool utype_can_freely_load(const struct unit_type *pcargotype, const struct unit_type *ptranstype)
Definition unittype.c:288
int utype_veteran_levels(const struct unit_type *punittype)
Definition unittype.c:2625
struct unit_class * unit_class_get(const struct unit *punit)
Definition unittype.c:2499
Unit_type_id utype_index(const struct unit_type *punittype)
Definition unittype.c:91
bool utype_can_take_over(const struct unit_type *punittype)
Definition unittype.c:276
static bool uclass_has_flag(const struct unit_class *punitclass, enum unit_class_flag_id flag)
Definition unittype.h:766
#define utype_class(_t_)
Definition unittype.h:749
#define utype_fuel(ptype)
Definition unittype.h:839
static bool utype_has_flag(const struct unit_type *punittype, int flag)
Definition unittype.h:617
#define unit_type_iterate(_p)
Definition unittype.h:855
#define uclass_index(_c_)
Definition unittype.h:742
#define unit_type_iterate_end
Definition unittype.h:862