Freeciv21
Develop your civilization from humble roots to a global empire
goto.cpp File Reference
#include <cstring>
#include <QLoggingCategory>
#include "actions.h"
#include "fc_types.h"
#include "game.h"
#include "map.h"
#include "packets.h"
#include "path_finder.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 dependency graph for goto.cpp:

Go to the source code of this file.

Functions

bool can_unit_move_now (const struct unit *punit)
 Returns if unit can move now. More...
 
void init_client_goto ()
 Called only by handle_map_info() in client/packhand.c. More...
 
void free_client_goto ()
 Called above, and by control_done() in client/control.c. More...
 
bool is_valid_goto_destination (const struct tile *ptile)
 Determines if a goto to the destination tile is allowed. More...
 
void goto_add_waypoint ()
 Inserts a waypoint at the end of the current goto line. More...
 
bool goto_pop_waypoint ()
 Returns whether there were any waypoint popped (we don't remove the initial position) More...
 
static int get_EC (const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
 PF callback to get the path with the minimal number of steps (out of all shortest paths). More...
 
static enum tile_behavior get_TB_aggr (const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
 PF callback to prohibit going into the unknown. More...
 
static enum tile_behavior get_TB_caravan (const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
 PF callback for caravans. More...
 
static enum tile_behavior no_fights_or_unknown_goto (const struct tile *ptile, enum known_type known, const struct pf_parameter *p)
 PF callback to prohibit going into the unknown (conditionally). More...
 
static void goto_fill_parameter_base (struct pf_parameter *parameter, const struct unit *punit)
 Fill the PF parameter with the correct client-goto values. More...
 
void enter_goto_state (const std::vector< unit * > &units)
 Enter the goto state: activate, prepare PF-template and add the initial part. More...
 
void exit_goto_state ()
 Tidy up and deactivate goto state. More...
 
void goto_unit_killed (struct unit *punit)
 Called from control_unit_killed() in client/control.c. More...
 
bool goto_is_active ()
 Is goto state active? More...
 
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. More...
 
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. More...
 
void request_orders_cleared (struct unit *punit)
 Send a packet to the server to request that the current orders be cleared. More...
 
static void make_path_orders (struct unit *punit, const PFPath &path, enum unit_orders orders, struct unit_order *final_order, struct unit_order *order_list, int *length, int *dest_tile)
 Creates orders for a path as a goto or patrol route. More...
 
static void send_path_orders (struct unit *punit, const PFPath &path, bool repeat, bool vigilant, enum unit_orders orders, struct unit_order *final_order)
 Send a path as a goto or patrol route to the server. More...
 
static void send_rally_path_orders (struct city *pcity, struct unit *punit, const PFPath &path, bool vigilant, enum unit_orders orders, struct unit_order *final_order)
 Send a path as a goto or patrol rally orders to the server. More...
 
void send_goto_path (struct unit *punit, const PFPath &path, struct unit_order *final_order)
 Send an arbitrary goto path for the unit to the server. More...
 
void send_rally_path (struct city *pcity, struct unit *punit, const PFPath &path, struct unit_order *final_order)
 Send an arbitrary rally path for the city to the server. More...
 
bool send_goto_tile (struct unit *punit, struct tile *ptile)
 Send orders for the unit to move it to the arbitrary tile. More...
 
bool send_rally_tile (struct city *pcity, struct tile *ptile)
 Send rally orders for the city to move new units to the arbitrary tile. More...
 
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. More...
 
void send_patrol_route ()
 Send the current patrol route (i.e., the one generated via HOVER_STATE) to the server. More...
 
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. More...
 
void send_goto_route ()
 Send the current goto route (i.e., the one generated via HOVER_STATE) to the server. More...
 
struct tiletile_before_end_path (struct unit *punit, struct tile *ptile)
 Finds penultimate tile on path for given unit going to ptile. More...
 

Variables

static auto goto_finders = std::map<int, freeciv::path_finder>()
 
static struct tilegoto_destination = nullptr
 Various stuff for the goto routes. More...
 

Function Documentation

◆ can_unit_move_now()

bool can_unit_move_now ( const struct unit punit)

Returns if unit can move now.

Definition at line 56 of file goto.cpp.

Referenced by find_best_focus_candidate(), get_units_waiting_data(), and popup_info_text().

◆ enter_goto_state()

void enter_goto_state ( const std::vector< unit * > &  units)

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

Definition at line 247 of file goto.cpp.

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

◆ exit_goto_state()

void exit_goto_state ( )

Tidy up and deactivate goto state.

Definition at line 269 of file goto.cpp.

Referenced by send_goto_route(), set_hover_state(), and map_view::shortcut_pressed().

◆ free_client_goto()

void free_client_goto ( )

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

Definition at line 87 of file goto.cpp.

Referenced by control_free().

◆ get_EC()

static int 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 149 of file goto.cpp.

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 149 of file goto.cpp.

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 149 of file goto.cpp.

Referenced by goto_fill_parameter_base().

◆ goto_add_waypoint()

void goto_add_waypoint ( )

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

Definition at line 104 of file goto.cpp.

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 221 of file goto.cpp.

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

◆ goto_is_active()

◆ goto_pop_waypoint()

bool goto_pop_waypoint ( )

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

Definition at line 126 of file goto.cpp.

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 308 of file goto.cpp.

◆ goto_unit_killed()

void goto_unit_killed ( struct unit punit)

Called from control_unit_killed() in client/control.c.

Definition at line 284 of file goto.cpp.

Referenced by control_unit_killed().

◆ init_client_goto()

void init_client_goto ( )

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

Definition at line 79 of file goto.cpp.

Referenced by handle_map_info().

◆ 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 96 of file goto.cpp.

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 383 of file goto.cpp.

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

◆ make_path_orders()

static void make_path_orders ( struct unit punit,
const PFPath 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 465 of file goto.cpp.

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 149 of file goto.cpp.

Referenced by goto_fill_parameter_base().

◆ 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 442 of file goto.cpp.

Referenced by clear_unit_orders().

◆ 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 694 of file goto.cpp.

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 724 of file goto.cpp.

Referenced by do_unit_connect().

◆ send_goto_path()

void send_goto_path ( struct unit punit,
const PFPath path,
struct unit_order final_order 
)

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

Definition at line 611 of file goto.cpp.

Referenced by send_goto_tile().

◆ send_goto_route()

void send_goto_route ( )

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.

Definition at line 836 of file goto.cpp.

Referenced by do_unit_goto(), key_unit_action_select_tgt(), and send_patrol_route().

◆ 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 630 of file goto.cpp.

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

◆ send_path_orders()

static void send_path_orders ( struct unit punit,
const PFPath 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 557 of file goto.cpp.

Referenced by send_attack_tile(), and send_goto_path().

◆ send_patrol_route()

void send_patrol_route ( )

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

Definition at line 718 of file goto.cpp.

Referenced by do_unit_patrol_to().

◆ send_rally_path()

void send_rally_path ( struct city pcity,
struct unit punit,
const PFPath path,
struct unit_order final_order 
)

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

Definition at line 620 of file goto.cpp.

Referenced by send_rally_tile().

◆ send_rally_path_orders()

static void send_rally_path_orders ( struct city pcity,
struct unit punit,
const PFPath path,
bool  vigilant,
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 588 of file goto.cpp.

Referenced by send_rally_path().

◆ send_rally_tile()

bool send_rally_tile ( struct city pcity,
struct tile ptile 
)

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 652 of file goto.cpp.

Referenced by 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 888 of file goto.cpp.

Referenced by mr_menu::find_last_unit_pos().

Variable Documentation

◆ goto_destination

struct tile* goto_destination = nullptr
static

◆ goto_finders