Freeciv-3.3
Loading...
Searching...
No Matches
Data Structures | Macros | Functions | Variables
goto.c File Reference
#include <string.h>
#include "log.h"
#include "mem.h"
#include "game.h"
#include "map.h"
#include "movement.h"
#include "packets.h"
#include "pf_tools.h"
#include "road.h"
#include "unit.h"
#include "unitlist.h"
#include "client_main.h"
#include "control.h"
#include "mapview_g.h"
#include "goto.h"
#include "mapctrl_common.h"
#include "speclist.h"

Go to the source code of this file.

Data Structures

struct  part
 
struct  goto_map
 

Macros

#define LOG_GOTO_PATH   LOG_DEBUG
 
#define log_goto_path   log_debug
 
#define log_goto_packet   log_debug
 
#define SPECLIST_TAG   goto_map
 
#define SPECLIST_TYPE   struct goto_map
 
#define goto_map_list_iterate(gotolist, pgoto)    TYPED_LIST_ITERATE(struct goto_map, gotolist, pgoto)
 
#define goto_map_list_iterate_end    LIST_ITERATE_END
 
#define goto_map_unit_iterate(gotolist, pgoto, punit)
 
#define goto_map_unit_iterate_end    } goto_map_list_iterate_end;
 

Functions

static void reset_last_part (struct goto_map *goto_map)
 
static void remove_last_part (struct goto_map *goto_map)
 
static void fill_parameter_part (struct pf_parameter *param, const struct goto_map *goto_map, const struct part *p)
 
static struct goto_mapgoto_map_new (struct unit *punit)
 
static void goto_map_free (struct goto_map *goto_map)
 
static struct unitgoto_map_unit (const struct goto_map *goto_map)
 
void init_client_goto (void)
 
void free_client_goto (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)
 
static void goto_path_undraw (const struct pf_path *path)
 
static bool update_last_part (struct goto_map *goto_map, struct tile *ptile)
 
static void add_part (struct goto_map *goto_map)
 
bool goto_add_waypoint (void)
 
bool goto_pop_waypoint (void)
 
static unsigned get_EC (const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
 
static enum tile_behavior get_TB_aggr (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)
 
static int get_activity_time (const struct tile *ptile, const struct player *pplayer)
 
static bool is_non_allied_city_adjacent (const struct player *pplayer, const struct tile *ptile)
 
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 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 enum tile_behavior no_fights_or_unknown_goto (const struct tile *ptile, enum known_type known, const struct pf_parameter *p)
 
static void goto_fill_parameter_base (struct pf_parameter *parameter, const struct unit *punit)
 
static void goto_fill_parameter_full (struct goto_map *goto_map, const struct unit *punit)
 
void enter_goto_state (struct unit_list *punits)
 
void exit_goto_state (void)
 
void goto_unit_killed (struct unit *punit)
 
bool goto_is_active (void)
 
bool goto_get_turns (int *min, int *max)
 
bool goto_tile_state (const struct tile *ptile, enum goto_tile_state *state, int *turns, bool *waypoint)
 
bool is_valid_goto_draw_line (struct tile *dest_tile)
 
void request_orders_cleared (struct unit *punit)
 
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 send_path_orders (struct unit *punit, struct pf_path *path, bool repeat, bool vigilant, enum unit_orders orders, struct unit_order *final_order)
 
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)
 
void send_goto_path (struct unit *punit, struct pf_path *path, struct unit_order *final_order)
 
static void send_rally_path (struct city *pcity, struct unit *punit, bool persistent, struct pf_path *path, struct unit_order *final_order)
 
bool send_goto_tile (struct unit *punit, struct tile *ptile)
 
bool send_rally_tile (struct city *pcity, struct tile *ptile, bool persistent)
 
bool send_attack_tile (struct unit *punit, struct tile *ptile)
 
void send_patrol_route (void)
 
static bool order_recursive_roads (struct tile *ptile, struct extra_type *pextra, struct packet_unit_orders *p, int rec)
 
void send_connect_route (enum unit_activity activity, struct extra_type *tgt)
 
static bool order_wants_direction (enum unit_orders order, action_id act_id, struct tile *tgt_tile, struct unit *punit)
 
static bool order_demands_direction (enum unit_orders order, action_id act_id)
 
void send_goto_route (void)
 
struct pf_pathpath_to_nearest_allied_city (struct unit *punit)
 
struct tiletile_before_end_path (struct unit *punit, struct tile *ptile)
 

Variables

static struct goto_map_listgoto_maps = nullptr
 
static bool goto_warned = FALSE
 
static struct tilegoto_destination = nullptr
 

Macro Definition Documentation

◆ goto_map_list_iterate

#define goto_map_list_iterate (   gotolist,
  pgoto 
)     TYPED_LIST_ITERATE(struct goto_map, gotolist, pgoto)

Definition at line 78 of file goto.c.

◆ goto_map_list_iterate_end

#define goto_map_list_iterate_end    LIST_ITERATE_END

Definition at line 80 of file goto.c.

◆ goto_map_unit_iterate

#define goto_map_unit_iterate (   gotolist,
  pgoto,
  punit 
)
Value:
char * incite_cost
Definition comments.c:76
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
#define goto_map_list_iterate(gotolist, pgoto)
Definition goto.c:78
static struct unit * goto_map_unit(const struct goto_map *goto_map)
Definition goto.c:139
Definition unit.h:140

Definition at line 84 of file goto.c.

◆ goto_map_unit_iterate_end

#define goto_map_unit_iterate_end    } goto_map_list_iterate_end;

Definition at line 88 of file goto.c.

◆ log_goto_packet

#define log_goto_packet   log_debug

Definition at line 45 of file goto.c.

◆ LOG_GOTO_PATH

#define LOG_GOTO_PATH   LOG_DEBUG

Definition at line 43 of file goto.c.

◆ log_goto_path

#define log_goto_path   log_debug

Definition at line 44 of file goto.c.

◆ SPECLIST_TAG

#define SPECLIST_TAG   goto_map

Definition at line 75 of file goto.c.

◆ SPECLIST_TYPE

#define SPECLIST_TYPE   struct goto_map

Definition at line 76 of file goto.c.

Function Documentation

◆ add_part()

static void add_part ( struct goto_map goto_map)
static

Add a part. Depending on the num of already existing parts the start of the new part is either the unit position (for the first part) or the destination of the last part (not the first part).

Definition at line 439 of file goto.c.

Referenced by enter_goto_state(), and goto_add_waypoint().

◆ enter_goto_state()

void enter_goto_state ( struct unit_list *  punits)

Enter the goto state: activate, prepare PF-template and add the initial part.

Definition at line 1011 of file goto.c.

Referenced by patrol_here_callback(), request_unit_connect(), request_unit_goto(), request_unit_patrol(), and mr_menu::slot_delayed_goto().

◆ exit_goto_state()

void exit_goto_state ( void  )

Tidy up and deactivate goto state.

Definition at line 1033 of file goto.c.

Referenced by paradrop_here_callback(), patrol_here_callback(), set_hover_state(), and map_view::shortcut_pressed().

◆ fill_parameter_part()

static void fill_parameter_part ( struct pf_parameter param,
const struct goto_map goto_map,
const struct part p 
)
static

Fill pathfinding parameter for adding a new part.

Definition at line 408 of file goto.c.

Referenced by add_part(), and update_last_part().

◆ free_client_goto()

void free_client_goto ( void  )

Called above, and by control_done() in client/control.c.

Definition at line 163 of file goto.c.

Referenced by control_free(), and init_client_goto().

◆ get_activity_time()

static int get_activity_time ( const struct tile ptile,
const struct player pplayer 
)
static

Return the number of MP needed to do the connect activity at this position. A negative number means it's impossible.

Definition at line 620 of file goto.c.

Referenced by get_connect_irrig(), get_connect_road(), goto_fill_parameter_full(), goto_get_turns(), and goto_tile_state().

◆ get_connect_irrig()

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

PF jumbo callback for the cost of a connect by irrigation. Here we are only interested in how long it will take to irrigate the path.

param->data should contain the result of get_activity_rate(punit) / 10.

Definition at line 808 of file goto.c.

Referenced by goto_fill_parameter_full().

◆ get_connect_road()

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

PF jumbo callback for the cost of a connect by road. In road-connect mode we are concerned with (1) the number of steps of the resulting path (2) (the tie-breaker) time to build the path (travel plus activity time). In rail-connect the priorities are reversed.

param->data should contain the result of get_activity_rate(punit).

Definition at line 698 of file goto.c.

Referenced by goto_fill_parameter_full().

◆ get_EC()

static unsigned get_EC ( const struct tile ptile,
enum known_type  known,
const struct pf_parameter param 
)
static

PF callback to get the path with the minimal number of steps (out of all shortest paths).

Definition at line 561 of file goto.c.

Referenced by goto_fill_parameter_base().

◆ get_TB_aggr()

static enum tile_behavior get_TB_aggr ( const struct tile ptile,
enum known_type  known,
const struct pf_parameter param 
)
static

PF callback to prohibit going into the unknown. Also makes sure we don't plan our route through enemy city/tile.

Definition at line 571 of file goto.c.

Referenced by goto_fill_parameter_base().

◆ get_TB_caravan()

static enum tile_behavior get_TB_caravan ( const struct tile ptile,
enum known_type  known,
const struct pf_parameter param 
)
static

PF callback for caravans. Caravans doesn't go into the unknown and don't attack enemy units but enter enemy cities.

Definition at line 593 of file goto.c.

Referenced by goto_fill_parameter_base().

◆ goto_add_waypoint()

bool goto_add_waypoint ( void  )

Inserts a waypoint at the end of the current goto line.

Definition at line 489 of file goto.c.

Referenced by request_unit_connect(), request_unit_goto(), and request_unit_patrol().

◆ goto_fill_parameter_base()

static void goto_fill_parameter_base ( struct pf_parameter parameter,
const struct unit punit 
)
static

Fill the PF parameter with the correct client-goto values. See also goto_fill_parameter_full().

Definition at line 898 of file goto.c.

Referenced by goto_fill_parameter_full(), path_to_nearest_allied_city(), send_attack_tile(), send_goto_tile(), send_rally_tile(), and tile_before_end_path().

◆ goto_fill_parameter_full()

static void goto_fill_parameter_full ( struct goto_map goto_map,
const struct unit punit 
)
static

Fill the PF parameter with the correct client-goto values. The storage behind "connect_speed" must remain valid for the lifetime of the pf_map.

Note that you must call this function only if the 'hover_state' is set, and we are in goto mode (usually, this function is only called from enter_goto_state()).

See also goto_fill_parameter_base().

Definition at line 931 of file goto.c.

Referenced by enter_goto_state().

◆ goto_get_turns()

bool goto_get_turns ( int min,
int max 
)

Return the path length (in turns). WARNING: not useful for determining paths of scattered groups.

Definition at line 1079 of file goto.c.

Referenced by get_unit_info_label_text2().

◆ goto_is_active()

bool goto_is_active ( void  )

◆ goto_map_free()

static void goto_map_free ( struct goto_map goto_map)
static

Free an existing goto map.

Definition at line 122 of file goto.c.

Referenced by exit_goto_state(), free_client_goto(), and goto_unit_killed().

◆ goto_map_new()

static struct goto_map * goto_map_new ( struct unit punit)
static

Create a new goto map.

Definition at line 108 of file goto.c.

Referenced by enter_goto_state().

◆ goto_map_unit()

static struct unit * goto_map_unit ( const struct goto_map goto_map)
static

Returns the unit associated with the goto map.

Definition at line 139 of file goto.c.

Referenced by add_part(), and fill_parameter_part().

◆ goto_path_redraw()

static void goto_path_redraw ( const struct pf_path new_path,
const struct pf_path old_path 
)
static

Show goto lines.

Definition at line 188 of file goto.c.

Referenced by update_last_part().

◆ goto_path_undraw()

static void goto_path_undraw ( const struct pf_path path)
static

Remove goto lines.

Definition at line 237 of file goto.c.

Referenced by update_last_part().

◆ goto_pop_waypoint()

bool goto_pop_waypoint ( void  )

Returns whether there were any waypoint popped (we don't remove the initial position)

Definition at line 528 of file goto.c.

Referenced by key_cancel_action().

◆ goto_tile_state()

bool goto_tile_state ( const struct tile ptile,
enum goto_tile_state state,
int turns,
bool waypoint 
)

Returns the state of 'ptile': turn number to print, and whether 'ptile' is a waypoint.

Definition at line 1156 of file goto.c.

◆ goto_unit_killed()

void goto_unit_killed ( struct unit punit)

Called from control_unit_killed() in client/control.c

Definition at line 1051 of file goto.c.

Referenced by control_unit_killed().

◆ init_client_goto()

void init_client_goto ( void  )

Called only by handle_map_info() in client/packhand.c.

Definition at line 153 of file goto.c.

Referenced by handle_map_info().

◆ is_non_allied_city_adjacent()

static bool is_non_allied_city_adjacent ( const struct player pplayer,
const struct tile ptile 
)
static

When building a road or a railroad, we don't want to go next to nonallied cities

Definition at line 677 of file goto.c.

Referenced by get_connect_irrig(), and get_connect_road().

◆ is_valid_goto_destination()

bool is_valid_goto_destination ( const struct tile ptile)

Determines if a goto to the destination tile is allowed.

Definition at line 180 of file goto.c.

Referenced by control_mouse_cursor().

◆ is_valid_goto_draw_line()

bool is_valid_goto_draw_line ( struct tile dest_tile)

Puts a line to dest_tile on the map according to the current goto_map. If there is no route to the dest then don't draw anything.

Definition at line 1350 of file goto.c.

Referenced by do_unit_connect(), do_unit_goto(), do_unit_patrol_to(), overview_update_line(), and update_line().

◆ make_path_orders()

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

Creates orders for a path as a goto or patrol route.

Definition at line 1399 of file goto.c.

Referenced by send_path_orders(), and send_rally_path_orders().

◆ no_fights_or_unknown_goto()

static enum tile_behavior no_fights_or_unknown_goto ( const struct tile ptile,
enum known_type  known,
const struct pf_parameter p 
)
static

PF callback to prohibit going into the unknown (conditionally). Also makes sure we don't plan to attack anyone.

Definition at line 882 of file goto.c.

Referenced by goto_fill_parameter_base().

◆ order_demands_direction()

static bool order_demands_direction ( enum unit_orders  order,
action_id  act_id 
)
static

Returns TRUE if it is certain that the order must be performed from an adjacent tile.

Definition at line 1869 of file goto.c.

Referenced by send_goto_route().

◆ order_recursive_roads()

static bool order_recursive_roads ( struct tile ptile,
struct extra_type pextra,
struct packet_unit_orders p,
int  rec 
)
static

Fill orders to build recursive roads.

Definition at line 1694 of file goto.c.

Referenced by order_recursive_roads(), and send_connect_route().

◆ order_wants_direction()

static bool order_wants_direction ( enum unit_orders  order,
action_id  act_id,
struct tile tgt_tile,
struct unit punit 
)
static

Returns TRUE if the order preferably should be performed from an adjacent tile.

This function doesn't care if a direction is required or just possible. Use order_demands_direction() for that.

Definition at line 1820 of file goto.c.

Referenced by send_goto_route().

◆ path_to_nearest_allied_city()

struct pf_path * path_to_nearest_allied_city ( struct unit punit)

Find the path to the nearest (fastest to reach) allied city for the unit, or nullptr if none is reachable.

Definition at line 2007 of file goto.c.

Referenced by request_unit_return().

◆ remove_last_part()

static void remove_last_part ( struct goto_map goto_map)
static

Remove the last part, erasing the corresponding path segment.

Definition at line 471 of file goto.c.

Referenced by goto_map_free(), and goto_pop_waypoint().

◆ request_orders_cleared()

void request_orders_cleared ( struct unit punit)

Send a packet to the server to request that the current orders be cleared.

Definition at line 1377 of file goto.c.

Referenced by clear_unit_orders().

◆ reset_last_part()

static void reset_last_part ( struct goto_map goto_map)
static

Change the drawn path to a size of 0 steps by setting it to the start position.

Definition at line 395 of file goto.c.

Referenced by remove_last_part(), and update_last_part().

◆ send_attack_tile()

bool send_attack_tile ( struct unit punit,
struct tile ptile 
)

Send orders for the unit to move it to the arbitrary tile and attack everything it approaches. Returns FALSE if no path is found.

Definition at line 1639 of file goto.c.

Referenced by mr_menu::slot_execute_orders().

◆ send_connect_route()

void send_connect_route ( enum unit_activity  activity,
struct extra_type tgt 
)

Send the current connect route (i.e., the one generated via HOVER_STATE) to the server.

Definition at line 1733 of file goto.c.

Referenced by do_unit_connect().

◆ send_goto_path()

void send_goto_path ( struct unit punit,
struct pf_path path,
struct unit_order final_order 
)

Send an arbitrary goto path for the unit to the server.

Definition at line 1548 of file goto.c.

Referenced by request_unit_return(), send_goto_route(), and send_goto_tile().

◆ send_goto_route()

void send_goto_route ( void  )

Send the current goto route (i.e., the one generated via HOVER_STATE) to the server. The route might involve more than one part, if waypoints were used. FIXME: danger paths are not supported.

Definition at line 1894 of file goto.c.

Referenced by do_unit_goto(), and key_unit_action_select_tgt().

◆ send_goto_tile()

bool send_goto_tile ( struct unit punit,
struct tile ptile 
)

Send orders for the unit to move it to the arbitrary tile. Returns FALSE if no path is found.

Definition at line 1569 of file goto.c.

Referenced by goto_dialog::go_to_city(), goto_city_callback(), goto_cmd_callback(), goto_here_callback(), and mr_menu::slot_autocaravan().

◆ send_path_orders()

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

Send a path as a goto or patrol route to the server.

Definition at line 1492 of file goto.c.

Referenced by send_attack_tile(), send_goto_path(), and send_patrol_route().

◆ send_patrol_route()

void send_patrol_route ( void  )

Send the current patrol route (i.e., the one generated via HOVER_STATE) to the server.

Definition at line 1666 of file goto.c.

Referenced by do_unit_patrol_to().

◆ send_rally_path()

static void send_rally_path ( struct city pcity,
struct unit punit,
bool  persistent,
struct pf_path path,
struct unit_order final_order 
)
static

Send an arbitrary rally path for the city to the server.

Definition at line 1557 of file goto.c.

Referenced by send_rally_tile().

◆ send_rally_path_orders()

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 
)
static

Send a path as a goto or patrol rally orders to the server.

Definition at line 1523 of file goto.c.

Referenced by send_rally_path().

◆ send_rally_tile()

bool send_rally_tile ( struct city pcity,
struct tile ptile,
bool  persistent 
)

Send rally orders for the city to move new units to the arbitrary tile. Returns FALSE if no path is found for the currently produced unit type.

Definition at line 1593 of file goto.c.

Referenced by rally_set_tile(), and map_view::shortcut_pressed().

◆ tile_before_end_path()

struct tile * tile_before_end_path ( struct unit punit,
struct tile ptile 
)

Finds penultimate tile on path for given unit going to ptile

Definition at line 2036 of file goto.c.

Referenced by mr_menu::find_last_unit_pos().

◆ update_last_part()

static bool update_last_part ( struct goto_map goto_map,
struct tile ptile 
)
static

Change the destination of the last part to the given location. If a path cannot be found, the destination is set to the start. Return TRUE when the new path is valid.

Definition at line 259 of file goto.c.

Referenced by goto_pop_waypoint(), is_valid_goto_draw_line(), and reset_last_part().

Variable Documentation

◆ goto_destination

struct tile* goto_destination = nullptr
static

◆ goto_maps

struct goto_map_list* goto_maps = nullptr
static

◆ goto_warned

bool goto_warned = FALSE
static

Definition at line 92 of file goto.c.

Referenced by enter_goto_state(), exit_goto_state(), free_client_goto(), and update_last_part().