OpenTTD Source: src/pathfinder/yapf/yapf_type.hpp Source File

OpenTTD Source 15.3

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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
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. */
17 enum class EndSegmentReason : uint8_t {
18 /* The following reasons can be saved into cached segment */
19 DeadEnd,
20 RailType,
21 InfiniteLoop,
22 SegmentTooLong,
23 ChoiceFollows,
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. */
31 PathTooLong,
32 FirstTwoWayRed,
33 LookAheadEnd,
34 TargetReached,
35};
36using EndSegmentReasons = EnumBitSet<EndSegmentReason, uint16_t>;
37
38/* What reasons mean that the target can be found and needs to be detected. */
39static constexpr EndSegmentReasons ESRF_POSSIBLE_TARGET = {
40 EndSegmentReason::Depot,
41 EndSegmentReason::Waypoint,
42 EndSegmentReason::Station,
43 EndSegmentReason::SafeTile,
44};
45
46/* What reasons can be stored back into cached segment. */
47static constexpr EndSegmentReasons ESRF_CACHED_MASK = {
48 EndSegmentReason::DeadEnd,
49 EndSegmentReason::RailType,
50 EndSegmentReason::InfiniteLoop,
51 EndSegmentReason::SegmentTooLong,
52 EndSegmentReason::ChoiceFollows,
53 EndSegmentReason::Depot,
54 EndSegmentReason::Waypoint,
55 EndSegmentReason::Station,
56 EndSegmentReason::SafeTile,
57};
58
59/* Reasons to abort pathfinding in this direction. */
60static constexpr EndSegmentReasons ESRF_ABORT_PF_MASK = {
61 EndSegmentReason::DeadEnd,
62 EndSegmentReason::PathTooLong,
63 EndSegmentReason::InfiniteLoop,
64 EndSegmentReason::FirstTwoWayRed,
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(), ComposeName(flags, end_segment_reason_names, "UNK"));
76}
77
78#endif /* YAPF_TYPE_HPP */
BaseBitSet::base
constexpr Tstorage base() const noexcept
Retrieve the raw value behind this bit set.
Definition base_bitset_type.hpp:219
EnumBitSet< EndSegmentReason, uint16_t >
ValueStr
std::string ValueStr(Trackdir td)
Return name of given Trackdir.
Definition dbg_helpers.cpp:24
ComposeName
std::string ComposeName(E value, std::span< const std::string_view > 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:55
EndSegmentReason
EndSegmentReason
Definition yapf_type.hpp:17
EndSegmentReason::SegmentTooLong
@ SegmentTooLong
the segment is too long (possible infinite loop)
EndSegmentReason::ChoiceFollows
@ ChoiceFollows
the next tile contains a choice (the track splits to more than one segments)
EndSegmentReason::Waypoint
@ Waypoint
waypoint encountered (could be a target next time)
EndSegmentReason::Station
@ Station
station encountered (could be a target next time)
EndSegmentReason::RailType
@ RailType
the next tile has a different rail type than our tiles
EndSegmentReason::FirstTwoWayRed
@ FirstTwoWayRed
first signal was 2-way and it was red
EndSegmentReason::LookAheadEnd
@ LookAheadEnd
we have just passed the last look-ahead signal
EndSegmentReason::InfiniteLoop
@ InfiniteLoop
infinite loop detected
EndSegmentReason::DeadEnd
@ DeadEnd
track ends here
EndSegmentReason::Depot
@ Depot
stop in the depot (could be a target next time)
EndSegmentReason::TargetReached
@ TargetReached
we have just reached the destination
EndSegmentReason::SafeTile
@ SafeTile
safe waiting position found (could be a target)
EndSegmentReason::PathTooLong
@ PathTooLong
the path is too long (searching for the nearest depot in the given radius)