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