OpenTTD Source 20250312-master-gcdcc6b491d
yapf_type.hpp
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
10#ifndef YAPF_TYPE_HPP
11#define YAPF_TYPE_HPP
12
13#include <iomanip>
14#include <sstream>
15
16#include "../../core/enum_type.hpp"
17#include "../../misc/dbg_helpers.h"
18
19/* Enum used in PfCalcCost() to see why was the segment closed. */
20enum class EndSegmentReason : uint8_t {
21 /* The following reasons can be saved into cached segment */
22 DeadEnd,
23 RailType,
27 Depot,
28 Waypoint,
29 Station,
30 SafeTile,
31
32 /* The following reasons are used only internally by PfCalcCost().
33 * They should not be found in the cached segment. */
38};
40
41/* What reasons mean that the target can be found and needs to be detected. */
42static constexpr EndSegmentReasons ESRF_POSSIBLE_TARGET = {
47};
48
49/* What reasons can be stored back into cached segment. */
50static constexpr EndSegmentReasons ESRF_CACHED_MASK = {
60};
61
62/* Reasons to abort pathfinding in this direction. */
63static constexpr EndSegmentReasons ESRF_ABORT_PF_MASK = {
68};
69
70inline std::string ValueStr(EndSegmentReasons flags)
71{
72 static const std::initializer_list<std::string_view> end_segment_reason_names = {
73 "DEAD_END", "RAIL_TYPE", "INFINITE_LOOP", "SEGMENT_TOO_LONG", "CHOICE_FOLLOWS",
74 "DEPOT", "WAYPOINT", "STATION", "SAFE_TILE",
75 "PATH_TOO_LONG", "FIRST_TWO_WAY_RED", "LOOK_AHEAD_END", "TARGET_REACHED"
76 };
77
78 std::stringstream ss;
79 ss << "0x" << std::setfill('0') << std::setw(4) << std::hex << flags.base(); // 0x%04X
80 ss << " (" << ComposeNameT(flags, end_segment_reason_names, "UNK") << ")";
81 return ss.str();
82}
83
84#endif /* YAPF_TYPE_HPP */
constexpr Tstorage base() const noexcept
Retrieve the raw value behind this bit set.
std::string ValueStr(Trackdir td)
Return name of given Trackdir.
std::string ComposeNameT(E value, T &t, const char *t_unk, E val_inv, const char *name_inv)
Helper template function that returns compound bitfield name that is concatenation of names of each s...
Definition dbg_helpers.h:67
EndSegmentReason
Definition yapf_type.hpp:20
@ SegmentTooLong
the segment is too long (possible infinite loop)
@ ChoiceFollows
the next tile contains a choice (the track splits to more than one segments)
@ Waypoint
waypoint encountered (could be a target next time)
@ Station
station encountered (could be a target next time)
@ RailType
the next tile has a different rail type than our tiles
@ FirstTwoWayRed
first signal was 2-way and it was red
@ LookAheadEnd
we have just passed the last look-ahead signal
@ InfiniteLoop
infinite loop detected
@ DeadEnd
track ends here
@ Depot
stop in the depot (could be a target next time)
@ TargetReached
we have just reached the destination
@ SafeTile
safe waiting position found (could be a target)
@ PathTooLong
the path is too long (searching for the nearest depot in the given radius)