OpenTTD
yapf_type.hpp
Go to the documentation of this file.
1 /* $Id: yapf_type.hpp 25608 2013-07-14 09:20:34Z rubidium $ */
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 */
27 
28  /* The following reasons are used only internally by PfCalcCost().
29  * They should not be found in the cached segment. */
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 */