Freeciv21
Develop your civilization from humble roots to a global empire
freeciv::path_finder Class Reference

A path is a succession of moves and actions to go from one location to another. More...

#include <path_finder.h>

+ Collaboration diagram for freeciv::path_finder:

Classes

class  path_finder_private
 

Public Types

using storage_type = std::multimap< const tile *, std::unique_ptr< detail::vertex > >
 The type of the underlying storage, exposed through destination. More...
 

Public Member Functions

 path_finder (const unit *unit)
 Constructs a path_finder for the given unit. More...
 
 path_finder (const unit *unit, const path::step &init)
 Constructs a path_finder for the given unit. More...
 
virtual ~path_finder ()
 Destructor. More...
 
path_finderoperator= (path_finder &&other)
 Move-assignment operator. More...
 
void set_constraint (std::unique_ptr< step_constraint > &&constraint)
 Sets a constraint to limit the number of steps considered when trying to find a path. More...
 
void push_waypoint (const tile *location)
 Adds a waypoint to the path finding. More...
 
bool pop_waypoint ()
 Removes the last added waypoint. More...
 
void unit_changed (const unit &unit)
 Notifies the path finder that some unit died or changed state. More...
 
std::vector< pathfind_all (const destination &destination)
 Runs the path finding algorithm, searching for all paths leading to the destination. More...
 
std::optional< pathfind_path (const destination &destination)
 Runs the path finding algorithm. More...
 

Private Attributes

std::unique_ptr< path_finder_privatem_d
 

Friends

class destination
 

Detailed Description

A path is a succession of moves and actions to go from one location to another.

Definition at line 55 of file path_finder.h.

Member Typedef Documentation

◆ storage_type

using freeciv::path_finder::storage_type = std::multimap<const tile *, std::unique_ptr<detail::vertex> >

The type of the underlying storage, exposed through destination.

Definition at line 62 of file path_finder.h.

Constructor & Destructor Documentation

◆ path_finder() [1/2]

freeciv::path_finder::path_finder ( const unit unit)
explicit

Constructs a path_finder for the given unit.

Doesn't start the path finding yet.

The path finder becomes useless if the unit state changes.

Definition at line 646 of file path_finder.cpp.

◆ path_finder() [2/2]

freeciv::path_finder::path_finder ( const unit unit,
const path::step init 
)
explicit

Constructs a path_finder for the given unit.

Initializes the search from a step in the unit's planned path. Doesn't start the path finding yet.

The path finder becomes useless if the unit state changes.

Definition at line 658 of file path_finder.cpp.

◆ ~path_finder()

freeciv::path_finder::~path_finder ( )
virtual

Destructor.

Definition at line 667 of file path_finder.cpp.

Member Function Documentation

◆ find_all()

std::vector< path > freeciv::path_finder::find_all ( const destination destination)

Runs the path finding algorithm, searching for all paths leading to the destination.

Make sure to set a harsh step constraint before calling this function, or it will become very slow very quickly.

Warning
Potentially very expensive.

Definition at line 744 of file path_finder.cpp.

◆ find_path()

std::optional< path > freeciv::path_finder::find_path ( const destination destination)

Runs the path finding algorithm.

Definition at line 779 of file path_finder.cpp.

◆ operator=()

path_finder & freeciv::path_finder::operator= ( path_finder &&  other)
inline

Move-assignment operator.

Definition at line 135 of file path_finder.h.

◆ pop_waypoint()

bool freeciv::path_finder::pop_waypoint ( )

Removes the last added waypoint.

See also
push_waypoint

Definition at line 706 of file path_finder.cpp.

◆ push_waypoint()

void freeciv::path_finder::push_waypoint ( const tile location)

Adds a waypoint to the path finding.

Waypoints are tiles that the path must go through (in order) before reaching the destination.

See also
pop_waypoint

Definition at line 691 of file path_finder.cpp.

◆ set_constraint()

void freeciv::path_finder::set_constraint ( std::unique_ptr< step_constraint > &&  constraint)

Sets a constraint to limit the number of steps considered when trying to find a path.

A path_finder can only have one constraint at a time.

Takes ownership of the constraint.

Definition at line 678 of file path_finder.cpp.

◆ unit_changed()

void freeciv::path_finder::unit_changed ( const unit unit)

Notifies the path finder that some unit died or changed state.

In many cases, this will trigger a recalculation of the path.

Definition at line 724 of file path_finder.cpp.

Friends And Related Function Documentation

◆ destination

friend class destination
friend

Definition at line 56 of file path_finder.h.

Member Data Documentation

◆ m_d

std::unique_ptr<path_finder_private> freeciv::path_finder::m_d
private