Freeciv-3.3
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,
114 if (PF_AA_DIPLOMAT & param->actions) {
115 return PF_ACTION_DIPLOMAT;
116 }
117
118 if (PF_AA_UNIT_ATTACK & param->actions) {
119 return (pf_attack_possible(ptile, known, param)
121 }
122 }
123
124 if (non_allied_city && PF_AA_CITY_ATTACK & param->actions) {
125 /* Consider that there are potentially units, even if
126 * is_non_allied_unit_tile() returned NULL (usually when
127 * '!param->omniscience'). */
128 return ((utype_can_take_over(param->utype)
129 || pf_attack_possible(ptile, TILE_KNOWN_UNSEEN, param))
131 }
132
133 return PF_ACTION_NONE;
134}
135
136/************************************************************************/
140static bool pf_action_possible(const struct tile *src,
142 const struct tile *dst,
143 enum pf_action action,
144 const struct pf_parameter *param)
145{
146 if (PF_ACTION_ATTACK == action) {
147 return (PF_MS_NATIVE & src_scope
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)
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,
500 || is_non_allied_city_tile(ptile, param->owner)) {
501 /* Can't attack */
502 return TB_IGNORE;
503 }
504 return TB_NORMAL;
505}
506
507/************************************************************************/
510enum tile_behavior no_fights(const struct tile *ptile,
511 enum known_type known,
512 const struct pf_parameter *param)
513{
514 if (is_non_allied_unit_tile(ptile, param->owner,
516 || is_non_allied_city_tile(ptile, param->owner)) {
517 /* Can't attack */
518 return TB_IGNORE;
519 }
520 return TB_NORMAL;
521}
522
523/************************************************************************/
527 enum known_type known,
528 const struct pf_parameter *param)
529{
530 if (is_non_allied_unit_tile(ptile, param->owner,
532 || is_non_allied_city_tile(ptile, param->owner)) {
533 return TB_DONT_LEAVE;
534 }
535 return TB_NORMAL;
536}
537
538/************************************************************************/
541static enum tile_behavior
542amphibious_behaviour(const struct tile *ptile, enum known_type known,
543 const struct pf_parameter *param)
544{
545 struct pft_amphibious *amphibious = param->data;
546 const bool ferry_move = is_native_tile(amphibious->sea.utype, ptile);
547
548 /* Simply a wrapper for the sea or land tile_behavior callbacks. */
549 if (ferry_move && amphibious->sea.get_TB) {
550 return amphibious->sea.get_TB(ptile, known, &amphibious->sea);
551 } else if (!ferry_move && amphibious->land.get_TB) {
552 return amphibious->land.get_TB(ptile, known, &amphibious->land);
553 }
554 return TB_NORMAL;
555}
556
557/* ===================== Required Moves Lefts Callbacks ================= */
558
559/************************************************************************/
562static bool is_possible_base_fuel(const struct tile *ptile,
563 const struct pf_parameter *param)
564{
565 const struct unit_class *uclass;
566 enum known_type tile_known = (param->omniscience ? TILE_KNOWN_SEEN
567 : tile_get_known(ptile, param->owner));
568
569 if (tile_known == TILE_UNKNOWN) {
570 /* Cannot guess if it is */
571 return FALSE;
572 }
573
574 if (is_allied_city_tile(ptile, param->owner)) {
575 return TRUE;
576 }
577
578 uclass = utype_class(param->utype);
580 /* All airbases are considered possible, simply attack enemies. */
581 if (tile_has_extra(ptile, pextra)) {
582 return TRUE;
583 }
585
586 if (utype_has_flag(param->utype, UTYF_COAST)) {
587 return is_safe_ocean(param->map, ptile);
588 }
589
590 if (tile_known == TILE_KNOWN_UNSEEN) {
591 /* Cannot see units */
592 return FALSE;
593 }
594
595 /* Check for carriers */
597 const struct unit_type *trans_utype = unit_type_get(ptrans);
598
600 && !unit_has_orders(ptrans) /* Don't load to moving carrier */
602 || tile_has_native_base(ptile, trans_utype))) {
603 return TRUE;
604 }
606
607 return FALSE;
608}
609
610/************************************************************************/
613static int get_closest_safe_tile_distance(const struct tile *src_tile,
614 const struct pf_parameter *param,
615 int max_distance)
616{
617 /* This iteration should, according to the documentation in map.h iterate
618 * tiles from the center tile, so we stop the iteration to the first found
619 * refuel point (as it should be the closest). */
620 iterate_outward_dxy(param->map, src_tile, max_distance, ptile, x, y) {
621 if (tile_get_known(ptile, param->owner) == TILE_UNKNOWN) {
622 /* Cannot guess if the tile is safe */
623 continue;
624 }
625 if (is_possible_base_fuel(ptile, param)) {
627 }
629
630 return -1;
631}
632
633/* ==================== Position Dangerous Callbacks =================== */
634
635/************************************************************************/
638static int get_fuel_moves_left_req(const struct tile *ptile,
639 enum known_type known,
640 const struct pf_parameter *param)
641{
642 int dist, max;
643
644 if (is_possible_base_fuel(ptile, param)) {
645 return 0;
646 }
647
648 /* Upper bound for search for refuel point. Sometimes unit can have more
649 * moves left than its own move rate due to wonder transfer. Compare
650 * pf_moves_left_initially(). */
651 max = MAX(param->moves_left_initially
652 + (param->fuel_left_initially - 1) * param->move_rate,
653 param->move_rate * param->fuel);
654 dist = get_closest_safe_tile_distance(ptile, param, max / SINGLE_MOVE);
655
656 return dist != -1 ? dist * SINGLE_MOVE : PF_IMPOSSIBLE_MC;
657}
658
659/************************************************************************/
662static bool amphibious_is_pos_dangerous(const struct tile *ptile,
663 enum known_type known,
664 const struct pf_parameter *param)
665{
666 struct pft_amphibious *amphibious = param->data;
667 const bool ferry_move = is_native_tile(amphibious->sea.utype, ptile);
668
669 /* Simply a wrapper for the sea or land danger callbacks. */
670 if (ferry_move && amphibious->sea.is_pos_dangerous) {
671 return amphibious->sea.is_pos_dangerous(ptile, known, param);
672 } else if (!ferry_move && amphibious->land.is_pos_dangerous) {
673 return amphibious->land.is_pos_dangerous(ptile, known, param);
674 }
675 return FALSE;
676}
677
678/* ======================= Tools for filling parameters ================= */
679
680/************************************************************************/
683static inline void
685 const struct civ_map *nmap,
686 const struct unit_type *punittype)
687{
688 parameter->map = nmap;
689 parameter->get_TB = NULL;
690 parameter->get_EC = NULL;
691 parameter->is_pos_dangerous = NULL;
692 parameter->get_moves_left_req = NULL;
693 parameter->get_costs = NULL;
694 parameter->get_zoc = NULL;
696 parameter->get_action = NULL;
697 parameter->is_action_possible = NULL;
698 parameter->actions = PF_AA_NONE;
699
700 parameter->utype = punittype;
701}
702
703/************************************************************************/
706static inline void
708{
709 if (!utype_has_flag(parameter->utype, UTYF_CIVILIAN)) {
710 parameter->actions |= PF_AA_UNIT_ATTACK;
711 parameter->get_action = pf_get_action;
713 if (!parameter->omniscience) {
714 /* Consider units hidden in cities. */
715 parameter->actions |= PF_AA_CITY_ATTACK;
716 }
717 }
718 if (utype_may_act_at_all(parameter->utype)) {
719 /* FIXME: it should consider action enablers. */
721 parameter->actions |= PF_AA_TRADE_ROUTE;
722 }
723 if (aia_utype_is_considered_spy(parameter->utype)) {
724 parameter->actions |= PF_AA_DIPLOMAT;
725 }
726 parameter->get_action = pf_get_action;
728 }
729}
730
731/************************************************************************/
734static inline void
736 const struct civ_map *nmap,
737 const struct unit_type *punittype,
738 struct tile *pstart_tile,
739 struct player *powner)
740{
743
746 }
747
749
750 parameter->start_tile = pstart_tile;
751 parameter->moves_left_initially = punittype->move_rate;
752 parameter->move_rate = utype_move_rate(punittype, pstart_tile, powner,
754 if (utype_fuel(punittype)) {
756 parameter->fuel = utype_fuel(punittype);
757 } else {
758 parameter->fuel = 1;
759 parameter->fuel_left_initially = 1;
760 }
761 parameter->transported_by_initially = NULL;
762 parameter->cargo_depth = 0;
763 BV_CLR_ALL(parameter->cargo_types);
764 parameter->owner = powner;
765
766 parameter->omniscience = FALSE;
767}
768
769/************************************************************************/
772static inline void
774 const struct civ_map *nmap,
775 const struct unit *punit)
776{
777 const struct unit *ptrans = unit_transport_get(punit);
778 const struct unit_type *ptype = unit_type_get(punit);
779
781
782 parameter->start_tile = unit_tile(punit);
784 parameter->move_rate = unit_move_rate(punit);
785 if (utype_fuel(ptype)) {
786 parameter->fuel_left_initially = punit->fuel;
787 parameter->fuel = utype_fuel(ptype);
788 } else {
789 parameter->fuel = 1;
790 parameter->fuel_left_initially = 1;
791 }
793 : NULL);
794 parameter->cargo_depth = unit_cargo_depth(punit);
795 BV_CLR_ALL(parameter->cargo_types);
799 parameter->owner = unit_owner(punit);
800
801 parameter->omniscience = FALSE;
802}
803
804/************************************************************************/
807static inline void pft_fill_parameter(struct pf_parameter *parameter,
808 const struct unit_type *punittype)
809{
810 parameter->get_MC = normal_move;
811 parameter->ignore_none_scopes = TRUE;
813
814 if (!parameter->get_moves_left_req && utype_fuel(punittype)) {
815 /* Unit needs fuel */
817 }
818
821 } else {
822 parameter->get_zoc = NULL;
823 }
824}
825
826/************************************************************************/
830 const struct civ_map *nmap,
831 const struct unit_type *punittype,
832 struct tile *pstart_tile,
833 struct player *pplayer)
834{
836 pstart_tile, pplayer);
837 pft_fill_parameter(parameter, punittype);
838}
839
840/************************************************************************/
844 const struct civ_map *nmap,
845 const struct unit *punit)
846{
849}
850
851/************************************************************************/
857static void pft_fill_overlap_param(struct pf_parameter *parameter,
858 const struct unit_type *punittype)
859{
860 parameter->get_MC = overlap_move;
861 parameter->ignore_none_scopes = FALSE;
862
865 } else {
866 parameter->get_zoc = NULL;
867 }
868
869 if (!parameter->get_moves_left_req && utype_fuel(punittype)) {
870 /* Unit needs fuel */
872 }
873}
874
875/************************************************************************/
880 const struct civ_map *nmap,
881 const struct unit_type *punittype,
882 struct tile *pstart_tile,
883 struct player *pplayer)
884{
886 pstart_tile, pplayer);
888}
889
890/************************************************************************/
895 const struct civ_map *nmap,
896 const struct unit *punit)
897{
900}
901
902/************************************************************************/
907static void pft_fill_attack_param(struct pf_parameter *parameter,
908 const struct unit_type *punittype)
909{
910 parameter->get_MC = normal_move;
911 parameter->ignore_none_scopes = TRUE;
913 /* We want known units! */
914 parameter->actions &= ~PF_AA_CITY_ATTACK;
915
918 } else {
919 parameter->get_zoc = NULL;
920 }
921
922 /* It is too complicated to work with danger here */
923 parameter->is_pos_dangerous = NULL;
924
925 if (!parameter->get_moves_left_req && utype_fuel(punittype)) {
926 /* Unit needs fuel */
928 }
929}
930
931/************************************************************************/
937 const struct civ_map *nmap,
938 const struct unit_type *punittype,
939 struct tile *pstart_tile,
940 struct player *pplayer)
941{
943 pstart_tile, pplayer);
945}
946
947/************************************************************************/
953 const struct civ_map *nmap,
954 const struct unit *punit)
955{
958}
959
960/************************************************************************/
964 struct pf_parameter *parameter,
965 struct tile *target_tile)
966{
967 memset(parameter, 0, sizeof(*parameter));
968
969 parameter->map = nmap;
970
971 /* We ignore refuel bases in reverse mode. */
972 parameter->fuel = 1;
973 parameter->fuel_left_initially = 1;
974
975 parameter->get_MC = normal_move;
977 parameter->ignore_none_scopes = TRUE;
978
980 parameter->data = target_tile;
981
982 /* Other data may stay at zero. */
983}
984
985/************************************************************************/
998{
999 const int move_rate = parameter->land.move_rate * parameter->sea.move_rate;
1000
1001 parameter->sea.cargo_depth = 1;
1002 BV_SET(parameter->sea.cargo_types, utype_index(parameter->land.utype));
1003
1004 parameter->combined = parameter->sea;
1005 parameter->land_scale = move_rate / parameter->land.move_rate;
1006 parameter->sea_scale = move_rate / parameter->sea.move_rate;
1007 parameter->combined.moves_left_initially *= parameter->sea_scale;
1008 parameter->combined.move_rate = move_rate;
1009 parameter->combined.get_MC = amphibious_move;
1013 if (NULL != parameter->land.is_pos_dangerous
1014 || NULL != parameter->sea.is_pos_dangerous) {
1016 } else {
1017 parameter->combined.is_pos_dangerous = NULL;
1018 }
1019 if (parameter->sea.get_moves_left_req != NULL) {
1020 parameter->combined.get_moves_left_req = parameter->sea.get_moves_left_req;
1021 } else if (parameter->land.get_moves_left_req != NULL) {
1022 parameter->combined.get_moves_left_req = parameter->land.get_moves_left_req;
1023 } else {
1024 parameter->combined.get_moves_left_req = NULL;
1025 }
1026 parameter->combined.get_action = NULL;
1027 parameter->combined.is_action_possible = NULL;
1028
1029 parameter->combined.data = parameter;
1030}
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:103
#define BV_SET(bv, bit)
Definition bitvector.h:89
#define BV_ISSET(bv, bit)
Definition bitvector.h:86
static bool is_non_allied_city_tile(const struct tile *ptile, const struct player *pplayer)
Definition city.h:767
static bool is_allied_city_tile(const struct tile *ptile, const struct player *pplayer)
Definition city.h:743
#define city_owner(_pcity_)
Definition city.h:560
char * incite_cost
Definition comments.c:76
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 const struct action *paction struct unit struct city * pcity
Definition dialogs_g.h:78
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:1031
#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:61
#define GAME_TRANSPORT_MAX_RECURSIVE
Definition game.h:767
#define fc_assert(condition)
Definition log.h:177
bool is_safe_ocean(const struct civ_map *nmap, const struct tile *ptile)
Definition map.c:712
int map_vector_to_real_distance(int dx, int dy)
Definition map.c:623
#define iterate_outward_dxy_end
Definition map.h:359
#define iterate_outward_dxy(nmap, start_tile, max_dist, _tile, _x, _y)
Definition map.h:336
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:302
bool is_native_tile(const struct unit_type *punittype, const struct tile *ptile)
Definition movement.c:330
int unit_move_rate(const struct unit *punit)
Definition movement.c:89
bool can_attack_from_non_native(const struct unit_type *utype)
Definition movement.c:226
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:372
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:242
bool is_native_near_tile(const struct civ_map *nmap, const struct unit_class *uclass, const struct tile *ptile)
Definition movement.c:464
bool can_unit_type_transport(const struct unit_type *transporter, const struct unit_class *transported)
Definition movement.c:869
bool can_attack_non_native(const struct unit_type *utype)
Definition movement.c:213
#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:843
void pft_fill_unit_attack_param(struct pf_parameter *parameter, const struct civ_map *nmap, const struct unit *punit)
Definition pf_tools.c:952
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:735
void pft_fill_unit_overlap_param(struct pf_parameter *parameter, const struct civ_map *nmap, const struct unit *punit)
Definition pf_tools.c:894
static void pft_fill_overlap_param(struct pf_parameter *parameter, const struct unit_type *punittype)
Definition pf_tools.c:857
void pft_fill_reverse_parameter(const struct civ_map *nmap, struct pf_parameter *parameter, struct tile *target_tile)
Definition pf_tools.c:963
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:140
static int get_fuel_moves_left_req(const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
Definition pf_tools.c:638
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:936
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:684
static void pft_fill_unit_default_parameter(struct pf_parameter *parameter, const struct civ_map *nmap, const struct unit *punit)
Definition pf_tools.c:773
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:510
static void pft_fill_attack_param(struct pf_parameter *parameter, const struct unit_type *punittype)
Definition pf_tools.c:907
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:879
static void pft_enable_default_actions(struct pf_parameter *parameter)
Definition pf_tools.c:707
static enum tile_behavior amphibious_behaviour(const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
Definition pf_tools.c:542
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:526
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:562
static int get_closest_safe_tile_distance(const struct tile *src_tile, const struct pf_parameter *param, int max_distance)
Definition pf_tools.c:613
static bool amphibious_is_pos_dangerous(const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
Definition pf_tools.c:662
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:997
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:829
static void pft_fill_parameter(struct pf_parameter *parameter, const struct unit_type *punittype)
Definition pf_tools.c:807
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:1409
#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:317
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 unit_class::@89 cache
struct extra_type_list * refuel_extras
Definition unittype.h:168
int move_rate
Definition unittype.h:524
bv_unit_classes targets
Definition unittype.h:568
Definition unit.h:140
int moves_left
Definition unit.h:152
int fuel
Definition unit.h:155
#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:148
bool unit_type_really_ignores_zoc(const struct unit_type *punittype)
Definition unit.c:1541
bool is_plr_zoc_client(const struct player *pplayer, const struct tile *ptile0, const struct civ_map *zmap)
Definition unit.c:1493
int unit_transport_depth(const struct unit *pcargo)
Definition unit.c:2628
struct unit * unit_transport_get(const struct unit *pcargo)
Definition unit.c:2518
int unit_cargo_depth(const struct unit *ptrans)
Definition unit.c:2610
bool is_plr_zoc_srv(const struct player *pplayer, const struct tile *ptile0, const struct civ_map *zmap)
Definition unit.c:1424
bool unit_has_orders(const struct unit *punit)
Definition unit.c:202
#define unit_tile(_pu)
Definition unit.h:404
#define unit_transports_iterate_end
Definition unit.h:575
#define unit_cargo_iterate_end
Definition unit.h:585
#define unit_cargo_iterate(_ptrans, _pcargo)
Definition unit.h:582
#define unit_owner(_pu)
Definition unit.h:403
#define unit_transports_iterate(_pcargo, _ptrans)
Definition unit.h:571
static bool is_non_allied_unit_tile(const struct tile *ptile, const struct player *pplayer, bool everyone_non_allied)
Definition unit.h:440
#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:949
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:306
bool utype_may_act_at_all(const struct unit_type *putype)
Definition unittype.c:365
bool utype_can_freely_load(const struct unit_type *pcargotype, const struct unit_type *ptranstype)
Definition unittype.c:294
int utype_veteran_levels(const struct unit_type *punittype)
Definition unittype.c:2631
struct unit_class * unit_class_get(const struct unit *punit)
Definition unittype.c:2505
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:282
static bool uclass_has_flag(const struct unit_class *punitclass, enum unit_class_flag_id flag)
Definition unittype.h:773
#define utype_class(_t_)
Definition unittype.h:756
#define utype_fuel(ptype)
Definition unittype.h:846
static bool utype_has_flag(const struct unit_type *punittype, int flag)
Definition unittype.h:624
#define unit_type_iterate(_p)
Definition unittype.h:862
#define uclass_index(_c_)
Definition unittype.h:749
#define unit_type_iterate_end
Definition unittype.h:869