Freeciv21
Develop your civilization from humble roots to a global empire
path.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2022 Louis Moureaux
2 // SPDX-License-Identifier: GPL-3.0-or-later
3 
4 #pragma once
5 
6 #include "unit.h"
7 
8 #include <vector>
9 
10 struct tile;
11 
12 namespace freeciv {
13 
18 class path {
19 public:
20  struct step {
21  // Vertex location in the search graph
24  bool moved;
25  bool paradropped;
26  bool is_final;
27  int waypoints;
28 
29  // Cost of the path to come here
30  int turns;
31  int moves_left;
32  int health;
33  int fuel_left;
34 
36  };
37 
41  explicit path() {}
42 
46  explicit path(const std::vector<step> &steps) : m_steps(steps) {}
47 
52  int turns() const { return empty() ? 0 : m_steps.back().turns; }
53 
58  bool empty() const { return m_steps.empty(); }
59 
63  const std::vector<step> &steps() const { return m_steps; }
64 
65  std::vector<step>::const_iterator first_unsafe_step(unit *unit) const;
66 
67 private:
68  std::vector<step> m_steps;
69 };
70 
71 } // namespace freeciv
A path is a succession of moves and actions to go from one location to another.
Definition: path.h:18
bool empty() const
Returns true if the path is empty, usually meaning that a path to the destination was not found.
Definition: path.h:58
path(const std::vector< step > &steps)
Constructor.
Definition: path.h:46
int turns() const
Finds how many turns (rounded down) it takes to reach the end of the path.
Definition: path.h:52
const std::vector< step > & steps() const
Returns the steps making up this path.
Definition: path.h:63
path()
Constructor.
Definition: path.h:41
std::vector< step > m_steps
Definition: path.h:68
std::vector< step >::const_iterator first_unsafe_step(unit *unit) const
Finds the first step in the path that is unsafe (if any).
Definition: path.cpp:20
Definition: path.cpp:10
unit * loaded
The unit we are loaded in.
Definition: path.h:23
int turns
How many turns it takes to get there.
Definition: path.h:30
int waypoints
How many waypoints we have visited so far.
Definition: path.h:27
int health
How many HP the unit has left.
Definition: path.h:32
unit_order order
The order to come here.
Definition: path.h:35
tile * location
Where we are.
Definition: path.h:22
bool moved
Whether we moved this turn (for HP recovery)
Definition: path.h:24
int fuel_left
How much fuel the unit has left.
Definition: path.h:33
bool paradropped
Whether we paradropped this turn.
Definition: path.h:25
int moves_left
How many move fragments the unit has left.
Definition: path.h:31
bool is_final
Whether this vertex can have children.
Definition: path.h:26
Definition: tile.h:42
Definition: unit.h:134