Freeciv21
Develop your civilization from humble roots to a global empire
path.cpp
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2022 Louis Moureaux
2 // SPDX-License-Identifier: GPL-3.0-or-later
3 
4 #include "path.h"
5 
6 #include "path_finder.h"
7 
8 #include <algorithm>
9 
10 namespace freeciv {
11 
19 std::vector<path::step>::const_iterator
21 {
22  fc_assert_ret_val(unit != nullptr, m_steps.end());
23  // Bisection search
24  auto it = std::lower_bound(
25  m_steps.begin(), m_steps.end(), 1, [unit](auto step, auto dummy) {
26  Q_UNUSED(dummy);
27  // Always let the search begin. Note that this makes the result not
28  // fully reliable for ORDER_ACTION_MOVE at the end of a path (eg when
29  // attacking a city) [FIXME]. It is, however, better to underestimate
30  // the cost of attack in some cases than to always think that
31  // ORDER_ACTION_MOVE is fuel-unsafe (it's almost always not the
32  // case).
33  step.is_final = false;
34  path_finder finder(unit, step);
35  return bool(finder.find_path(refuel_destination(*unit)));
36  });
37  return it;
38 }
39 
40 } // namespace freeciv
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
#define fc_assert_ret_val(condition, val)
Definition: log.h:114
Definition: path.cpp:10
Definition: unit.h:134