OpenTTD Source 20250522-master-g467f832c2f
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 "../../core/enum_type.hpp"
14#include "../../misc/dbg_helpers.h"
15
16/* Enum used in PfCalcCost() to see why was the segment closed. */
17enum class EndSegmentReason : uint8_t {
18 /* The following reasons can be saved into cached segment */
19 DeadEnd,
20 RailType,
24 Depot,
25 Waypoint,
26 Station,
27 SafeTile,
28
29 /* The following reasons are used only internally by PfCalcCost().
30 * They should not be found in the cached segment. */
35};
37
38/* What reasons mean that the target can be found and needs to be detected. */
39static constexpr EndSegmentReasons ESRF_POSSIBLE_TARGET = {
44};
45
46/* What reasons can be stored back into cached segment. */
47static constexpr EndSegmentReasons ESRF_CACHED_MASK = {
57};
58
59/* Reasons to abort pathfinding in this direction. */
60static constexpr EndSegmentReasons ESRF_ABORT_PF_MASK = {
65};
66
67inline std::string ValueStr(EndSegmentReasons flags)
68{
69 static const std::initializer_list<const std::string_view> end_segment_reason_names = {
70 "DEAD_END", "RAIL_TYPE", "INFINITE_LOOP", "SEGMENT_TOO_LONG", "CHOICE_FOLLOWS",
71 "DEPOT", "WAYPOINT", "STATION", "SAFE_TILE",
72 "PATH_TOO_LONG", "FIRST_TWO_WAY_RED", "LOOK_AHEAD_END", "TARGET_REACHED"
73 };
74
75 return fmt::format("0x{:04X} ({})", flags.base(), ComposeNameT(flags, end_segment_reason_names, "UNK"));
76}
77
78#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, std::string_view t_unk, E val_inv, std::string_view name_inv)
Helper template function that returns compound bitfield name that is concatenation of names of each s...
Definition dbg_helpers.h:68
EndSegmentReason
Definition yapf_type.hpp:17
@ 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)