36#define SPECPQ_TAG map_index
37#define SPECPQ_DATA_TYPE int
38#define SPECPQ_PRIORITY_TYPE int
40#define INITIAL_QUEUE_SIZE 100
97#define PF_MAP(pfm) ((struct pf_map *) (pfm))
173 unsigned cost,
unsigned extra)
245 return NULL,
"Wrong pf_map to pf_normal_map conversion.");
248#define PF_NORMAL_MAP(pfm) \
249 pf_normal_map_check(pfm, __FILE__, __FUNCTION__, __FC_LINE__)
251#define PF_NORMAL_MAP(pfm) ((struct pf_normal_map *) (pfm))
291#ifdef ZERO_VARIABLES_FOR_SEARCHING
331#ifdef ZERO_VARIABLES_FOR_SEARCHING
368#ifdef ZERO_VARIABLES_FOR_SEARCHING
377#ifdef ZERO_VARIABLES_FOR_SEARCHING
387#ifdef ZERO_VARIABLES_FOR_SEARCHING
411 "Unreached destination (%d, %d).",
TILE_XY(ptile));
428 if (node->
cost > 0) {
439 struct tile *dest_tile)
450 "Unreached destination (%d, %d).",
477 for (;
i >= 0;
i--) {
576 node1->dir_to_here = dir;
704 extra +=
node1->extra_tile;
713 node1->extra_cost = extra;
715 node1->dir_to_here = dir;
719 node1->extra_cost)) {
723 node1->extra_cost = extra;
725 node1->dir_to_here = dir;
792 if (ptile ==
pfm->params.start_tile) {
812 if (ptile ==
pfm->params.start_tile) {
831 if (ptile ==
pfm->params.start_tile) {
865 base_map = &
pfnm->base_map;
866 params = &base_map->
params;
885 *params = *parameter;
996 return NULL,
"Wrong pf_map to pf_danger_map conversion.");
999#define PF_DANGER_MAP(pfm) \
1000 pf_danger_map_check(pfm, __FILE__, __FUNCTION__, __FC_LINE__)
1002#define PF_DANGER_MAP(pfm) ((struct pf_danger_map *) (pfm))
1042#ifdef ZERO_VARIABLES_FOR_SEARCHING
1082#ifdef ZERO_VARIABLES_FOR_SEARCHING
1119#ifdef ZERO_VARIABLES_FOR_SEARCHING
1128#ifdef ZERO_VARIABLES_FOR_SEARCHING
1138#ifdef ZERO_VARIABLES_FOR_SEARCHING
1145#ifdef ZERO_VARIABLES_FOR_SEARCHING
1172 "Unreached destination (%d, %d).",
TILE_XY(ptile));
1189 if (node->
cost > 0) {
1206 return cost + moves_left;
1223 bool waited =
FALSE;
1225 unsigned length = 1;
1234 "Unreached destination (%d, %d).",
1274 for (
i = length - 1;
i >= 0;
i--) {
1289 pos->fuel_left = params->
fuel;
1325 if (node->
cost > 0) {
1382 struct pf_danger_pos *
pos;
1383 unsigned length = 0;
1389 log_error(
"Possible memory leak in pf_danger_map_create_segment().");
1401 node1->danger_segment =
fc_malloc(length *
sizeof(
struct pf_danger_pos));
1408 for (
i = 0,
pos =
node1->danger_segment;
i < length;
i++,
pos++) {
1413 if (
i == length - 1) {
1572 node1->action, params)) {
1614 if (!
node1->is_dangerous) {
1619 node1->extra_cost))) {
1623 node1->extra_cost = extra;
1625 node1->dir_to_here = dir;
1659 node1->extra_cost = extra;
1661 node1->dir_to_here = dir;
1671 node1->extra_cost)))) {
1673 node1->extra_cost = extra;
1675 node1->dir_to_here = dir;
1709 node =
pfdm->lattice + tindex;
1724 node =
pfdm->lattice + tindex;
1797 if (ptile ==
pfm->params.start_tile) {
1817 if (ptile ==
pfm->params.start_tile) {
1836 if (ptile ==
pfm->params.start_tile) {
1879 base_map = &
pfdm->base_map;
1880 params = &base_map->
params;
1901 *params = *parameter;
2017 return NULL,
"Wrong pf_map to pf_fuel_map conversion.");
2020#define PF_FUEL_MAP(pfm) \
2021 pf_fuel_map_check(pfm, __FILE__, __FUNCTION__, __FC_LINE__)
2023#define PF_FUEL_MAP(pfm) ((struct pf_fuel_map *) (pfm))
2080#ifdef ZERO_VARIABLES_FOR_SEARCHING
2121#ifdef ZERO_VARIABLES_FOR_SEARCHING
2125#ifdef ZERO_VARIABLES_FOR_SEARCHING
2172#ifdef ZERO_VARIABLES_FOR_SEARCHING
2193#ifdef ZERO_VARIABLES_FOR_SEARCHING
2203#ifdef ZERO_VARIABLES_FOR_SEARCHING
2210#ifdef ZERO_VARIABLES_FOR_SEARCHING
2250 while (
NULL !=
pos && 0 == --
pos->ref_count) {
2270 }
else if (1 <
pos->ref_count) {
2345 "Unreached destination (%d, %d).",
TILE_XY(ptile));
2349 pos->total_EC =
head->extra_cost;
2352 pos->dir_to_here =
head->dir_to_here;
2364 int cost,
int moves_left)
2383 unsigned length = 1;
2391 "Unreached destination (%d, %d).",
2401 if (segment != node->
segment) {
2415 segment = segment->
prev;
2434 for (
i = length - 1;
i >= 0;
i--) {
2447 pos->fuel_left = params->
fuel;
2452 if (
NULL == segment) {
2485 segment = segment->
prev;
2572 int moves_left,
int moves_left_req)
2640 bool waited =
FALSE;
2684 int cost, extra = 0;
2694 && 0 ==
node1->moves_left_req) {
2722 node1->action, params)) {
2809 pos->moves_left -
node1->moves_left_req);
2826 node1->extra_cost = extra;
2829 node1->dir_to_here = dir;
2854 || 0 ==
node1->moves_left_req) {
2873 node1->extra_cost = extra;
2876 node1->dir_to_here = dir;
2925 node =
pffm->lattice + tindex;
2933#ifndef FREECIV_NDEBUG
2946 node =
pffm->lattice + tindex;
3030 if (ptile ==
pfm->params.start_tile) {
3052 if (ptile ==
pfm->params.start_tile) {
3071 if (ptile ==
pfm->params.start_tile) {
3113 base_map = &
pffm->base_map;
3114 params = &base_map->
params;
3135 *params = *parameter;
3186 log_error(
"path finding code cannot deal with dangers "
3187 "and fuel together.");
3190 log_error(
"jumbo callbacks for danger maps are not yet implemented.");
3195 log_error(
"jumbo callbacks for fuel maps are not yet implemented.");
3225 return pfm->get_move_cost(
pfm, ptile);
3242 path =
pfm->get_path(
pfm, ptile);
3245#ifndef FREECIV_NDEBUG
3258 return pfm->get_path(
pfm, ptile);
3274 return pfm->get_position(
pfm, ptile,
pos);
3300 if (!
pfm->iterate(
pfm)) {
3330 return pfm->get_move_cost(
pfm,
pfm->tile);
3370 return &
pfm->params;
3448 ==
src_path->positions[0].moves_left);
3450 ==
src_path->positions[0].fuel_left);
3548 "PF: path (at %p) consists of %d positions:",
3549 (
void *) path, path->
length);
3557 "PF: %2d/%2d: (%2d,%2d) dir=%-2s cost=%2d (%2d, %d) EC=%d",
3560 pos->turn,
pos->moves_left,
pos->total_EC);
3577#define SPECHASH_TAG pf_pos
3578#define SPECHASH_IKEY_TYPE struct pf_parameter *
3579#define SPECHASH_IDATA_TYPE struct pf_position *
3580#define SPECHASH_IKEY_VAL pf_pos_hash_val
3581#define SPECHASH_IKEY_COMP pf_pos_hash_cmp
3582#define SPECHASH_IKEY_FREE pf_reverse_map_destroy_param
3583#define SPECHASH_IDATA_FREE pf_reverse_map_destroy_pos
3612 result |= (1u << b);
3689 const struct player *pplayer,
3697 pfrm->max_turns = max_turns;
3701 param->
owner = pplayer;
3716 const struct city *pcity,
3717 const struct player *attacker,
3758 if (
pfrm->max_turns >= 0) {
3773 }
while (
pfm->iterate(
pfm));
3787 }
while (
pfm->iterate(
pfm));
static struct action * action_by_number(action_id act_id)
#define city_tile(_pcity_)
struct unit struct city struct unit struct tile * target_tile
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
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
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)
unsigned int genhash_val_t
void do_log(const char *file, const char *function, int line, bool print_from_where, enum log_level level, const char *message,...)
#define fc_assert_msg(condition, message,...)
#define fc_assert_ret(condition)
#define fc_assert(condition)
#define fc_assert_full(file, function, line, condition, action, message,...)
#define fc_assert_ret_msg(condition, message,...)
#define fc_assert_ret_val(condition, val)
#define log_debug(message,...)
#define log_error(message,...)
#define fc_assert_ret_val_msg(condition, val, message,...)
const char * dir_get_name(enum direction8 dir)
struct tile * index_to_tile(const struct civ_map *imap, int mindex)
struct tile * mapstep(const struct civ_map *nmap, const struct tile *ptile, enum direction8 dir)
#define adjc_dir_iterate(nmap, center_tile, itr_tile, dir_itr)
#define adjc_dir_iterate_end
#define fc_calloc(n, esz)
#define fc_realloc(ptr, sz)
int unit_move_rate(const struct unit *punit)
int utype_move_rate(const struct unit_type *utype, const struct tile *ptile, const struct player *pplayer, int veteran_level, int hitpoints)
static struct pf_path * pf_fuel_map_path(struct pf_map *pfm, struct tile *ptile)
bool pf_reverse_map_unit_position(struct pf_reverse_map *pfrm, const struct unit *punit, struct pf_position *pos)
static void pf_danger_map_fill_position(const struct pf_danger_map *pfdm, struct tile *ptile, struct pf_position *pos)
struct pf_path * pf_path_concat(struct pf_path *dest_path, const struct pf_path *src_path)
static bool pf_fuel_map_iterate(struct pf_map *pfm)
static const struct pf_position * pf_reverse_map_pos(struct pf_reverse_map *pfrm, const struct pf_parameter *param)
static struct pf_map * pf_danger_map_new(const struct pf_parameter *parameter)
const struct pf_parameter * pf_map_parameter(const struct pf_map *pfm)
void pf_path_print_real(const struct pf_path *path, enum log_level level, const char *file, const char *function, int line)
const struct pf_position * pf_path_last_position(const struct pf_path *path)
void pf_path_destroy(struct pf_path *path)
#define PF_DANGER_MAP(pfm)
static bool pf_normal_node_init(struct pf_normal_map *pfnm, struct pf_normal_node *node, struct tile *ptile, enum pf_move_scope previous_scope)
static struct pf_path * pf_danger_map_construct_path(const struct pf_danger_map *pfdm, struct tile *ptile)
static bool pf_danger_node_init(struct pf_danger_map *pfdm, struct pf_danger_node *node, struct tile *ptile, enum pf_move_scope previous_scope)
static const size_t signifiant_flags_num
bool pf_path_backtrack(struct pf_path *path, struct tile *ptile)
static void pf_fuel_finalize_position_base(const struct pf_parameter *param, struct pf_position *pos, int cost, int moves_left)
static int pf_normal_map_move_cost(struct pf_map *pfm, struct tile *ptile)
static int pf_fuel_map_fill_cost_for_full_moves(const struct pf_parameter *param, int cost, int moves_left)
struct pf_map * pf_map_new(const struct pf_parameter *parameter)
static const struct pf_position * pf_reverse_map_unit_pos(struct pf_reverse_map *pfrm, const struct unit *punit)
static bool pf_fuel_map_position(struct pf_map *pfm, struct tile *ptile, struct pf_position *pos)
static void pf_fuel_map_fill_position(const struct pf_fuel_map *pffm, struct tile *ptile, struct pf_position *pos)
struct pf_path * pf_map_path(struct pf_map *pfm, struct tile *ptile)
bool pf_map_iterate(struct pf_map *pfm)
static void pf_fuel_map_create_segment(struct pf_fuel_map *pffm, struct tile *ptile, struct pf_fuel_node *node)
static bool pf_pos_hash_cmp(const struct pf_parameter *parameter1, const struct pf_parameter *parameter2)
bool pf_map_position(struct pf_map *pfm, struct tile *ptile, struct pf_position *pos)
static int pf_move_rate(const struct pf_parameter *param)
void pf_map_iter_position(struct pf_map *pfm, struct pf_position *pos)
int pf_map_iter_move_cost(struct pf_map *pfm)
static bool pf_jumbo_map_iterate(struct pf_map *pfm)
static int pf_normal_map_adjust_cost(int cost, int moves_left)
static bool pf_normal_map_iterate_until(struct pf_normal_map *pfnm, struct tile *ptile)
static bool pf_fuel_node_init(struct pf_fuel_map *pffm, struct pf_fuel_node *node, struct tile *ptile, enum pf_move_scope previous_scope)
static struct pf_path * pf_danger_map_path(struct pf_map *pfm, struct tile *ptile)
static genhash_val_t pf_pos_hash_val(const struct pf_parameter *parameter)
static struct pf_map * pf_normal_map_new(const struct pf_parameter *parameter)
static struct pf_path * pf_normal_map_path(struct pf_map *pfm, struct tile *ptile)
static struct pf_fuel_pos * pf_fuel_pos_replace(struct pf_fuel_pos *pos, const struct pf_fuel_node *node)
static struct pf_path * pf_normal_map_construct_path(const struct pf_normal_map *pfnm, struct tile *dest_tile)
static bool pf_danger_map_position(struct pf_map *pfm, struct tile *ptile, struct pf_position *pos)
struct pf_reverse_map * pf_reverse_map_new_for_city(const struct civ_map *nmap, const struct city *pcity, const struct player *attacker, int max_turns, bool omniscient)
static int pf_moves_left_initially(const struct pf_parameter *param)
static void pf_reverse_map_destroy_pos(struct pf_position *pos)
static struct pf_fuel_pos * pf_fuel_pos_ref(struct pf_fuel_pos *pos)
static int pf_danger_map_move_cost(struct pf_map *pfm, struct tile *ptile)
static bool pf_fuel_map_attack_is_possible(const struct pf_parameter *param, int moves_left, int moves_left_req)
static enum unit_type_flag_id signifiant_flags[]
static void pf_finalize_position(const struct pf_parameter *param, struct pf_position *pos)
void pf_reverse_map_destroy(struct pf_reverse_map *pfrm)
struct pf_path * pf_map_iter_path(struct pf_map *pfm)
static void pf_fuel_finalize_position(struct pf_position *pos, const struct pf_parameter *params, const struct pf_fuel_node *node, const struct pf_fuel_pos *head)
static void pf_normal_map_fill_position(const struct pf_normal_map *pfnm, struct tile *ptile, struct pf_position *pos)
static int pf_fuel_map_adjust_cost(int cost, int moves_left, int move_rate)
static bool pf_danger_map_iterate(struct pf_map *pfm)
static int pf_fuel_map_move_cost(struct pf_map *pfm, struct tile *ptile)
static void pf_position_fill_start_tile(struct pf_position *pos, const struct pf_parameter *param)
static void pf_fuel_pos_unref(struct pf_fuel_pos *pos)
int pf_reverse_map_unit_move_cost(struct pf_reverse_map *pfrm, const struct unit *punit)
static bool pf_normal_map_position(struct pf_map *pfm, struct tile *ptile, struct pf_position *pos)
static struct pf_path * pf_path_new_to_start_tile(const struct pf_parameter *param)
static int pf_total_CC(const struct pf_parameter *param, unsigned cost, unsigned extra)
static bool pf_fuel_node_dangerous(const struct pf_fuel_node *node)
static void pf_danger_map_destroy(struct pf_map *pfm)
static bool pf_normal_map_iterate(struct pf_map *pfm)
void pf_map_destroy(struct pf_map *pfm)
static int pf_moves_left(const struct pf_parameter *param, int cost)
struct tile * pf_map_iter(struct pf_map *pfm)
static int pf_danger_map_adjust_cost(const struct pf_parameter *params, int cost, bool to_danger, int moves_left)
struct pf_reverse_map * pf_reverse_map_new(const struct civ_map *nmap, const struct player *pplayer, struct tile *target_tile, int max_turns, bool omniscient)
static const struct pf_position * pf_reverse_map_utype_pos(struct pf_reverse_map *pfrm, const struct unit_type *punittype, struct tile *ptile)
static bool pf_fuel_map_iterate_until(struct pf_fuel_map *pffm, struct tile *ptile)
static void pf_normal_map_destroy(struct pf_map *pfm)
int pf_map_move_cost(struct pf_map *pfm, struct tile *ptile)
bool pf_path_advance(struct pf_path *path, struct tile *ptile)
static int pf_fuel_total_CC(const struct pf_parameter *param, int cost, int extra, int safety)
static void pf_fuel_map_destroy(struct pf_map *pfm)
int pf_reverse_map_utype_move_cost(struct pf_reverse_map *pfrm, const struct unit_type *punittype, struct tile *ptile)
static struct pf_map * pf_fuel_map_new(const struct pf_parameter *parameter)
static struct pf_path * pf_fuel_map_construct_path(const struct pf_fuel_map *pffm, struct tile *ptile)
static bool pf_danger_map_iterate_until(struct pf_danger_map *pfdm, struct tile *ptile)
bool pf_reverse_map_utype_position(struct pf_reverse_map *pfrm, const struct unit_type *punittype, struct tile *ptile, struct pf_position *pos)
#define INITIAL_QUEUE_SIZE
static int pf_danger_map_fill_cost_for_full_moves(const struct pf_parameter *param, int cost)
#define PF_NORMAL_MAP(pfm)
static int pf_turns(const struct pf_parameter *param, int cost)
static int pf_fuel_waited_total_CC(int cost, int safety)
static void pf_reverse_map_destroy_param(struct pf_parameter *param)
static void pf_danger_map_create_segment(struct pf_danger_map *pfdm, struct pf_danger_node *node1)
bool player_can_invade_tile(const struct player *pplayer, const struct tile *ptile)
struct setting_list * level[OLEVELS_NUM]
SPECPQ_PRIORITY_TYPE priority
struct map_index_pq * danger_queue
struct pf_danger_node * lattice
struct map_index_pq * queue
struct pf_danger_node::pf_danger_pos * danger_segment
unsigned short extra_tile
struct map_index_pq * waited_queue
struct map_index_pq * queue
struct pf_fuel_node * lattice
struct pf_fuel_pos * segment
unsigned short cost_to_here[DIR8_MAGIC_MAX]
unsigned short extra_tile
struct pf_fuel_pos * prev
bool(* get_position)(struct pf_map *pfm, struct tile *ptile, struct pf_position *pos)
int(* get_move_cost)(struct pf_map *pfm, struct tile *ptile)
struct pf_path *(* get_path)(struct pf_map *pfm, struct tile *ptile)
bool(* iterate)(struct pf_map *pfm)
void(* destroy)(struct pf_map *pfm)
struct pf_parameter params
struct pf_normal_node * lattice
struct map_index_pq * queue
unsigned short extra_tile
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)
const struct civ_map * map
enum tile_behavior(* get_TB)(const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
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)
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)
struct pf_position * positions
enum direction8 dir_to_next_pos
struct pf_parameter template
struct pf_pos_hash * hash
struct tile * target_tile
#define terrain_has_flag(terr, flag)
bool tile_has_native_base(const struct tile *ptile, const struct unit_type *punittype)
enum known_type tile_get_known(const struct tile *ptile, const struct player *pplayer)
struct city * tile_city(const struct tile *ptile)
#define tile_terrain(_tile)
bool utype_action_takes_all_mp(const struct unit_type *putype, struct action *paction)
const struct unit_type * unit_type_get(const struct unit *punit)
bool utype_can_freely_unload(const struct unit_type *pcargotype, const struct unit_type *ptranstype)
int utype_veteran_levels(const struct unit_type *punittype)
Unit_Class_id uclass_number(const struct unit_class *pclass)
bool utype_can_do_action(const struct unit_type *putype, const action_id act_id)
static bool utype_has_flag(const struct unit_type *punittype, int flag)