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

OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

yapf_type.hpp
Go to the documentation of this file.
1 /* $Id: yapf_type.hpp 27885 2017-06-22 16:57:06Z frosch $ */
2
3 /*
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
8 */
9
12 #ifndef YAPF_TYPE_HPP
13 #define YAPF_TYPE_HPP
14
15 /* Enum used in PfCalcCost() to see why was the segment closed. */
16 enum EndSegmentReason {
17 /* The following reasons can be saved into cached segment */
18 ESR_DEAD_END = 0,
19 ESR_RAIL_TYPE,
20 ESR_INFINITE_LOOP,
21 ESR_SEGMENT_TOO_LONG,
22 ESR_CHOICE_FOLLOWS,
23 ESR_DEPOT,
24 ESR_WAYPOINT,
25 ESR_STATION,
26 ESR_SAFE_TILE,
27
28 /* The following reasons are used only internally by PfCalcCost().
29 * They should not be found in the cached segment. */
30 ESR_PATH_TOO_LONG,
31 ESR_FIRST_TWO_WAY_RED,
32 ESR_LOOK_AHEAD_END,
33 ESR_TARGET_REACHED,
34
35 /* Special values */
36 ESR_NONE = 0xFF,
37 };
38
39 enum EndSegmentReasonBits {
40 ESRB_NONE = 0,
41
42 ESRB_DEAD_END = 1 << ESR_DEAD_END,
43 ESRB_RAIL_TYPE = 1 << ESR_RAIL_TYPE,
44 ESRB_INFINITE_LOOP = 1 << ESR_INFINITE_LOOP,
45 ESRB_SEGMENT_TOO_LONG = 1 << ESR_SEGMENT_TOO_LONG,
46 ESRB_CHOICE_FOLLOWS = 1 << ESR_CHOICE_FOLLOWS,
47 ESRB_DEPOT = 1 << ESR_DEPOT,
48 ESRB_WAYPOINT = 1 << ESR_WAYPOINT,
49 ESRB_STATION = 1 << ESR_STATION,
50 ESRB_SAFE_TILE = 1 << ESR_SAFE_TILE,
51
52 ESRB_PATH_TOO_LONG = 1 << ESR_PATH_TOO_LONG,
53 ESRB_FIRST_TWO_WAY_RED = 1 << ESR_FIRST_TWO_WAY_RED,
54 ESRB_LOOK_AHEAD_END = 1 << ESR_LOOK_AHEAD_END,
55 ESRB_TARGET_REACHED = 1 << ESR_TARGET_REACHED,
56
57 /* Additional (composite) values. */
58
59 /* What reasons mean that the target can be found and needs to be detected. */
60 ESRB_POSSIBLE_TARGET = ESRB_DEPOT | ESRB_WAYPOINT | ESRB_STATION | ESRB_SAFE_TILE,
61
62 /* What reasons can be stored back into cached segment. */
63 ESRB_CACHED_MASK = ESRB_DEAD_END | ESRB_RAIL_TYPE | ESRB_INFINITE_LOOP | ESRB_SEGMENT_TOO_LONG | ESRB_CHOICE_FOLLOWS | ESRB_DEPOT | ESRB_WAYPOINT | ESRB_STATION | ESRB_SAFE_TILE,
64
65 /* Reasons to abort pathfinding in this direction. */
66 ESRB_ABORT_PF_MASK = ESRB_DEAD_END | ESRB_PATH_TOO_LONG | ESRB_INFINITE_LOOP | ESRB_FIRST_TWO_WAY_RED,
67 };
68
69 DECLARE_ENUM_AS_BIT_SET(EndSegmentReasonBits)
70
71 inline CStrA ValueStr(EndSegmentReasonBits bits)
72 {
73 static const char * const end_segment_reason_names[] = {
74 "DEAD_END", "RAIL_TYPE", "INFINITE_LOOP", "SEGMENT_TOO_LONG", "CHOICE_FOLLOWS",
75 "DEPOT", "WAYPOINT", "STATION", "SAFE_TILE",
76 "PATH_TOO_LONG", "FIRST_TWO_WAY_RED", "LOOK_AHEAD_END", "TARGET_REACHED"
77 };
78
79 CStrA out;
80 out.Format("0x%04X (%s)", bits, ComposeNameT(bits, end_segment_reason_names, "UNK", ESRB_NONE, "NONE").Data());
81 return out.Transfer();
82 }
83
84 #endif /* YAPF_TYPE_HPP */