43#define LOG_GOTO_PATH LOG_DEBUG
44#define log_goto_path log_debug
45#define log_goto_packet log_debug
75#define SPECLIST_TAG goto_map
76#define SPECLIST_TYPE struct goto_map
78#define goto_map_list_iterate(gotolist, pgoto) \
79 TYPED_LIST_ITERATE(struct goto_map, gotolist, pgoto)
80#define goto_map_list_iterate_end \
84#define goto_map_unit_iterate(gotolist, pgoto, punit) \
85 goto_map_list_iterate(gotolist, pgoto) { \
86 struct unit *punit = goto_map_unit(pgoto);
88#define goto_map_unit_iterate_end \
89 } goto_map_list_iterate_end;
98 const struct part *p);
188 const struct pf_path *old_path)
195 if (old_path != NULL) {
198 for (i = 0; i < new_path->
length - 1 && i < old_path->
length - 1; i++) {
203 || old_pos->
tile != new_pos->
tile) {
210 for (; i < old_path->
length - 1; i++) {
222 for (i = start_index; i < new_path->
length - 1; i++) {
242 for (i = 0; i < path->
length - 1; i++) {
261 struct pf_path *old_path, *new_path;
270 log_debug(
"update_last_part(%d,%d) old (%d,%d)-(%d,%d)",
282 log_error(
"No path found to reach the start point.");
286 if (old_path != NULL) {
322 if (return_path == NULL) {
330 log_error(
"No path found to reach the start point.");
334 if (old_path != NULL) {
350 if (p->
path != NULL) {
398 if (NULL != p->
path) {
409 const struct part *p)
489 bool duplicate_of_last =
TRUE;
500 if (last_part->
path == NULL) {
505 duplicate_of_last =
FALSE;
508 if (duplicate_of_last) {
612 const struct player *pplayer)
620 case ACTIVITY_IRRIGATE:
638 case ACTIVITY_GEN_ROAD:
653 activity_mc += single_mc;
668 const struct tile *ptile)
689 const struct tile *dest_tile,
690 int src_cost,
int src_extra,
691 unsigned *dest_cost,
unsigned *dest_extra,
694 int activity_time, move_cost, moves_left;
695 int total_cost, total_extra;
703 if (activity_time < 0) {
730 total_extra = src_extra + 1;
740 total_cost = src_cost;
743 total_cost += moves_left;
751 if (activity_time > 0) {
755 + (speed - 1)) / speed;
757 total_cost += moves_left;
759 total_cost += activity_time * param->
move_rate;
768 if (*dest_cost != -1) {
770 if (total_extra > *dest_extra
771 || (total_extra == *dest_extra && total_cost >= *dest_cost)) {
776 if (total_cost > *dest_cost
777 || (total_cost == *dest_cost && total_extra >= *dest_extra)) {
784 *dest_cost = total_cost;
785 *dest_extra = total_extra;
800 const struct tile *dest_tile,
801 int src_cost,
int src_extra,
802 unsigned *dest_cost,
unsigned *dest_extra,
805 int activity_time,
move_cost, moves_left, total_cost;
812 if (activity_time < 0) {
834 total_cost = src_cost;
837 total_cost += moves_left;
845 if (activity_time > 0) {
849 + (speed - 1)) / speed;
851 total_cost += moves_left;
853 total_cost += activity_time * param->
move_rate;
856 if (*dest_cost != -1 && total_cost > *dest_cost) {
861 *dest_cost = total_cost;
933 int activity_initial;
950 if (activity_initial > 0) {
980 "Path finding during target selection");
987 "Goto with HOVER_PARADROP?");
989 "Goto with HOVER_ACT_SEL_TGT?");
1044 if (ptest ==
punit) {
1095 if (!moved && path->
length > 1) {
1100 if (moved && activity_time > 0) {
1142 int *turns,
bool *waypoint)
1171 int turns_for_map = -2;
1181 if (path == NULL || path->
length == 0) {
1185 for (j = 0; j < path->
length; j++) {
1187 if (!moved && j > 0) {
1190 if (
pos->tile != ptile) {
1193 if (activity_time > 0) {
1194 if (map_turns +
pos->turn + moved > turns_for_map) {
1195 turns_for_map = map_turns +
pos->turn + moved;
1197 }
else if (
pos->moves_left == 0) {
1198 if (map_turns +
pos->turn > turns_for_map) {
1199 turns_for_map = map_turns +
pos->turn + moved;
1203 map_turns +=
pos->turn;
1207 int ml = (
pos != NULL ?
pos->moves_left : 0);
1209 if (moved && activity_time > 0) {
1212 if (map_turns > *turns) {
1213 *state = (activity_time > 0 || ml == 0
1216 }
else if (map_turns == *turns
1218 && (activity_time > 0 || ml == 0)) {
1222 if (activity_time > 0) {
1223 if (turns_for_map > *turns) {
1225 *turns = turns_for_map;
1228 if (turns_for_map + 1 > *turns) {
1230 *turns = turns_for_map + 1;
1236 bool mark_on_map =
FALSE;
1240 const struct tile *destination;
1245 int turns_for_map = -2;
1250 mark_on_map = *waypoint =
TRUE;
1254 if (path == NULL || path->
length == 0) {
1258 for (j = 0; j < path->
length; j++) {
1261 if (
pos->turn != last_pos->
turn
1262 &&
pos->tile == ptile) {
1266 &&
pos->tile == ptile) {
1269 if (
pos->tile == ptile
1271 && (
pos->moves_left == 0
1273 || (j < path->length - 1 && (
pos + 1)->tile == ptile))
1274 && map_turns +
pos->turn > turns_for_map) {
1275 turns_for_map = map_turns +
pos->turn;
1279 map_turns +=
pos->turn;
1287 for (j = 0; j < path->
length; j++) {
1289 if (
pos->tile == ptile
1291 && (
pos->moves_left == 0
1293 || (j < path->length - 1 && (
pos + 1)->tile == ptile))
1294 && map_turns +
pos->turn > turns_for_map) {
1295 turns_for_map = map_turns +
pos->turn;
1298 map_turns +=
pos->turn;
1299 destination =
pos->tile;
1304 if (ptile == destination) {
1305 int ml = (
pos != NULL ?
pos->moves_left : 0);
1307 if (map_turns > *turns) {
1311 }
else if (map_turns == *turns
1317 if (turns_for_map > *turns) {
1319 *turns = turns_for_map;
1327 return (*turns != -1 || *waypoint);
1338 if (NULL == dest_tile) {
1390 struct tile *old_tile;
1394 "Unit %d has moved without goto cancellation.",
1399 *length = path->
length - 1;
1404 for (i = 0; i < path->
length - 1; i++) {
1407 if (
same_pos(new_tile, old_tile)) {
1410 order_list[i].
activity = ACTIVITY_LAST;
1416 order_list[i].
order = orders;
1418 order_list[i].
activity = ACTIVITY_LAST;
1426 old_tile = new_tile;
1447 log_verbose(
"unit or city blocks the path of your %s",
1455 order_list[i].
dir = final_order->
dir;
1457 ? final_order->
activity : ACTIVITY_LAST;
1473 bool repeat,
bool vigilant,
1479 if (path->
length == 1 && final_order == NULL) {
1483 memset(&p, 0,
sizeof(p));
1512 memset(&p, 0,
sizeof(p));
1655 if (NULL == last_part->
path) {
1720 struct tile *old_tile;
1724 if (NULL == last_part->
path) {
1729 memset(&p, 0,
sizeof(p));
1735 }
while (i < goto_map->num_parts);
1748 case ACTIVITY_IRRIGATE:
1760 case ACTIVITY_GEN_ROAD:
1764 log_error(
"Invalid connect activity: %d.", activity);
1775 old_tile, new_tile);
1782 old_tile = new_tile;
1801 struct tile *tgt_tile)
1875 struct tile *tgt_tile;
1879 if (NULL == last_part->
path) {
1888 }
while (i < goto_map->num_parts);
1932 struct tile *on_tile;
1964 order.
dir = last_order_dir;
1966 order.
target = last_order_target;
bool action_id_exists(const action_id act_id)
#define action_id_distance_accepted(act_id, distance)
#define action_id_has_result_safe(act_id, result)
#define BV_ISSET(bv, bit)
int city_production_unit_veteran_level(struct city *pcity, const struct unit_type *punittype)
static bool is_non_allied_city_tile(const struct tile *ptile, const struct player *pplayer)
static bool is_allied_city_tile(const struct tile *ptile, const struct player *pplayer)
bool can_client_issue_orders(void)
bool unit_is_in_focus(const struct unit *punit)
enum unit_orders goto_last_order
int check_recursive_road_connect(struct tile *ptile, const struct extra_type *pextra, const struct unit *punit, const struct player *pplayer, int rec)
struct extra_type * connect_tgt
struct unit_list * get_units_in_focus(void)
void request_unit_ssa_set(const struct unit *punit, enum server_side_agent agent)
enum unit_activity connect_activity
enum cursor_hover_state hover_state
void clear_unit_orders(struct unit *punit)
action_id goto_last_action
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
static bool is_non_allied_city_adjacent(const struct player *pplayer, const struct tile *ptile)
static int get_connect_irrig(const struct tile *src_tile, enum direction8 dir, const struct tile *dest_tile, int src_cost, int src_extra, unsigned *dest_cost, unsigned *dest_extra, const struct pf_parameter *param)
static void fill_parameter_part(struct pf_parameter *param, const struct goto_map *goto_map, const struct part *p)
#define goto_map_list_iterate_end
static int get_connect_road(const struct tile *src_tile, enum direction8 dir, const struct tile *dest_tile, int src_cost, int src_extra, unsigned *dest_cost, unsigned *dest_extra, const struct pf_parameter *param)
static void make_path_orders(struct unit *punit, struct pf_path *path, enum unit_orders orders, struct unit_order *final_order, struct unit_order *order_list, int *length, int *dest_tile)
static void goto_path_undraw(const struct pf_path *path)
static enum tile_behavior no_fights_or_unknown_goto(const struct tile *ptile, enum known_type known, const struct pf_parameter *p)
static bool order_recursive_roads(struct tile *ptile, struct extra_type *pextra, struct packet_unit_orders *p, int rec)
static void goto_fill_parameter_full(struct goto_map *goto_map, const struct unit *punit)
static struct tile * goto_destination
static unsigned get_EC(const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
static enum tile_behavior get_TB_caravan(const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
void exit_goto_state(void)
struct tile * tile_before_end_path(struct unit *punit, struct tile *ptile)
bool goto_is_active(void)
bool send_attack_tile(struct unit *punit, struct tile *ptile)
struct pf_path * path_to_nearest_allied_city(struct unit *punit)
static struct goto_map_list * goto_maps
static void goto_fill_parameter_base(struct pf_parameter *parameter, const struct unit *punit)
void init_client_goto(void)
#define goto_map_unit_iterate_end
void send_patrol_route(void)
bool send_rally_tile(struct city *pcity, struct tile *ptile, bool persistent)
static bool order_wants_direction(enum unit_orders order, action_id act_id, struct tile *tgt_tile)
static void remove_last_part(struct goto_map *goto_map)
static void send_rally_path_orders(struct city *pcity, struct unit *punit, struct pf_path *path, bool vigilant, bool persistent, enum unit_orders orders, struct unit_order *final_order)
bool is_valid_goto_draw_line(struct tile *dest_tile)
static void send_path_orders(struct unit *punit, struct pf_path *path, bool repeat, bool vigilant, enum unit_orders orders, struct unit_order *final_order)
static struct goto_map * goto_map_new(struct unit *punit)
static bool update_last_part(struct goto_map *goto_map, struct tile *ptile)
static enum tile_behavior get_TB_aggr(const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
#define goto_map_list_iterate(gotolist, pgoto)
static void reset_last_part(struct goto_map *goto_map)
#define goto_map_unit_iterate(gotolist, pgoto, punit)
bool goto_add_waypoint(void)
bool send_goto_tile(struct unit *punit, struct tile *ptile)
static struct unit * goto_map_unit(const struct goto_map *goto_map)
bool goto_pop_waypoint(void)
void send_connect_route(enum unit_activity activity, struct extra_type *tgt)
void goto_unit_killed(struct unit *punit)
void free_client_goto(void)
void enter_goto_state(struct unit_list *punits)
void send_goto_route(void)
bool is_valid_goto_destination(const struct tile *ptile)
static void goto_path_redraw(const struct pf_path *new_path, const struct pf_path *old_path)
bool goto_get_turns(int *min, int *max)
static int get_activity_time(const struct tile *ptile, const struct player *pplayer)
static void goto_map_free(struct goto_map *goto_map)
void request_orders_cleared(struct unit *punit)
static void send_rally_path(struct city *pcity, struct unit *punit, bool persistent, struct pf_path *path, struct unit_order *final_order)
static bool order_demands_direction(enum unit_orders order, action_id act_id)
void send_goto_path(struct unit *punit, struct pf_path *path, struct unit_order *final_order)
static void add_part(struct goto_map *goto_map)
void update_unit_info_label(struct unit_list *punits)
static GtkWidget * persistent
#define fc_assert_msg(condition, message,...)
#define fc_assert_ret(condition)
#define log_verbose(message,...)
#define fc_assert(condition)
#define fc_assert_ret_msg(condition, message,...)
#define fc_assert_ret_val(condition, val)
#define log_debug(message,...)
#define log_error(message,...)
int get_direction_for_step(const struct civ_map *nmap, const struct tile *start_tile, const struct tile *end_tile)
const char * dir_get_name(enum direction8 dir)
bool is_cardinal_dir(enum direction8 dir)
bool same_pos(const struct tile *tile1, const struct tile *tile2)
bool is_valid_dir(enum direction8 dir)
#define adjc_iterate(nmap, center_tile, itr_tile)
void cancel_selection_rectangle(void)
void mapdeco_add_gotoline(const struct tile *ptile, enum direction8 dir)
void refresh_tile_mapcanvas(struct tile *ptile, bool full_refresh, bool write_to_screen)
void mapdeco_remove_gotoline(const struct tile *ptile, enum direction8 dir)
#define fc_realloc(ptr, sz)
bool can_exist_at_tile(const struct civ_map *nmap, const struct unit_type *utype, const struct tile *ptile)
struct client_options gui_options
int send_packet_city_rally_point(struct connection *pc, const struct packet_city_rally_point *packet, bool force_to_send)
int send_packet_unit_orders(struct connection *pc, const struct packet_unit_orders *packet)
struct pf_path * pf_path_concat(struct pf_path *dest_path, const struct pf_path *src_path)
const struct pf_position * pf_path_last_position(const struct pf_path *path)
void pf_path_destroy(struct pf_path *path)
bool pf_path_backtrack(struct pf_path *path, struct tile *ptile)
struct pf_map * pf_map_new(const struct pf_parameter *parameter)
struct pf_path * pf_map_path(struct pf_map *pfm, struct tile *ptile)
void pf_map_destroy(struct pf_map *pfm)
#define pf_path_print(path, level)
#define pf_map_tiles_iterate(ARG_pfm, NAME_tile, COND_from_start)
#define pf_map_tiles_iterate_end
struct unit * player_unit_by_number(const struct player *pplayer, int unit_id)
struct universal production
bool popup_last_move_to_allied
struct goto_map::@132::@135 patrol
struct pf_path * return_path
struct pf_parameter template
struct goto_map::@132::@134 connect
struct unit_order orders[MAX_LEN_ROUTE]
struct unit_order orders[MAX_LEN_ROUTE]
const struct unit_type * transported_by_initially
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)
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
struct pf_position * positions
enum direction8 dir_to_next_pos
enum unit_activity activity
struct unit * transporter
void tile_virtual_destroy(struct tile *vtile)
bool tile_has_road(const struct tile *ptile, const struct road_type *proad)
struct tile * tile_virtual_new(const struct tile *ptile)
enum known_type tile_get_known(const struct tile *ptile, const struct player *pplayer)
#define tile_terrain(_tile)
#define tile_has_extra(ptile, pextra)
const struct unit_type * utype
struct unit * transporter_for_unit_at(const struct unit *pcargo, const struct tile *ptile)
int get_activity_rate(const struct unit *punit)
struct unit * unit_virtual_create(struct player *pplayer, struct city *pcity, const struct unit_type *punittype, int veteran_level)
void unit_virtual_destroy(struct unit *punit)
static bool is_allied_unit_tile(const struct tile *ptile, const struct player *pplayer)
static bool is_non_allied_unit_tile(const struct tile *ptile, const struct player *pplayer)
#define unit_list_iterate(unitlist, punit)
#define unit_list_iterate_end
const struct unit_type * unit_type_get(const struct unit *punit)
const char * unit_rule_name(const struct unit *punit)
bool utype_may_act_at_all(const struct unit_type *putype)
bool utype_acts_hostile(const struct unit_type *putype)
bool can_utype_do_act_if_tgt_diplrel(const struct unit_type *punit_type, const action_id act_id, const int prop, const bool is_there)