author | rubidium |
Sat, 06 Oct 2007 21:16:00 +0000 | |
branch | NewGRF_ports |
changeset 6870 | ca3fd1fbe311 |
parent 6743 | cabfaa4a0295 |
permissions | -rw-r--r-- |
3147
0a09ce6d651a
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
1 |
/* $Id$ */ |
0a09ce6d651a
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
2 |
|
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
5838
diff
changeset
|
3 |
/** @file direction.h */ |
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
5838
diff
changeset
|
4 |
|
3147
0a09ce6d651a
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
5 |
#ifndef DIRECTION_H |
0a09ce6d651a
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
6 |
#define DIRECTION_H |
0a09ce6d651a
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
7 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5726
diff
changeset
|
8 |
#include "helpers.hpp" |
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5726
diff
changeset
|
9 |
|
6743
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
10 |
/** |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
11 |
* Defines the 8 directions on the map. |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
12 |
* |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
13 |
* This enum defines 8 possible directions which are used for |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
14 |
* the vehicles in the game. The directions are aligned straight |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
15 |
* to the viewport, not to the map. So north points to the top of |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
16 |
* your viewport and not rotated by 45 degrees left or right to get |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
17 |
* a "north" used in you games. |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
18 |
*/ |
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6451
diff
changeset
|
19 |
enum Direction { |
6743
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
20 |
DIR_BEGIN = 0, ///< Used to iterate |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
21 |
DIR_N = 0, ///< North |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
22 |
DIR_NE = 1, ///< Northeast |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
23 |
DIR_E = 2, ///< East |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
24 |
DIR_SE = 3, ///< Southeast |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
25 |
DIR_S = 4, ///< South |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
26 |
DIR_SW = 5, ///< Southwest |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
27 |
DIR_W = 6, ///< West |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
28 |
DIR_NW = 7, ///< Northwest |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
29 |
DIR_END, ///< Used to iterate |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
30 |
INVALID_DIR = 0xFF, ///< Flag for an invalid direction |
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6451
diff
changeset
|
31 |
}; |
3147
0a09ce6d651a
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
32 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5726
diff
changeset
|
33 |
/** Define basic enum properties */ |
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5726
diff
changeset
|
34 |
template <> struct EnumPropsT<Direction> : MakeEnumPropsT<Direction, byte, DIR_BEGIN, DIR_END, INVALID_DIR> {}; |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6574
diff
changeset
|
35 |
typedef TinyEnumT<Direction> DirectionByte; //typedefing-enumification of Direction |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5726
diff
changeset
|
36 |
|
6743
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
37 |
/** |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
38 |
* Return the reverse of a direction |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
39 |
* |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
40 |
* @param d The direction to get the reverse from |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
41 |
* @return The reverse Direction |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
42 |
*/ |
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3154
diff
changeset
|
43 |
static inline Direction ReverseDir(Direction d) |
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3154
diff
changeset
|
44 |
{ |
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3154
diff
changeset
|
45 |
return (Direction)(4 ^ d); |
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3154
diff
changeset
|
46 |
} |
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3154
diff
changeset
|
47 |
|
3147
0a09ce6d651a
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
48 |
|
6743
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
49 |
/** |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
50 |
* Enumeration for the difference between two directions. |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
51 |
* |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
52 |
* This enumeration is used to mark differences between |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
53 |
* two directions. If you get one direction you can align |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
54 |
* a second direction in 8 different ways. This enumeration |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
55 |
* only contains 6 of these 8 differences, but the remaining |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
56 |
* two can be calculated by adding to differences together. |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
57 |
* This also means you can add two differences together and |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
58 |
* get the difference you really want to get. The difference |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
59 |
* of 45 degrees left + the difference of 45 degrees right results in the |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
60 |
* difference of 0 degrees. |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
61 |
* |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
62 |
* @note To get this mentioned addition of direction you must use |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
63 |
* modulo DIR_END or use the #ChangeDirDiff(DirDiff, DirDiff) function. |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
64 |
* @see ChangeDirDiff(DirDiff, DirDiff) |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
65 |
*/ |
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6451
diff
changeset
|
66 |
enum DirDiff { |
6743
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
67 |
DIRDIFF_SAME = 0, ///< Both directions faces to the same direction |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
68 |
DIRDIFF_45RIGHT = 1, ///< Angle of 45 degrees right |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
69 |
DIRDIFF_90RIGHT = 2, ///< Angle of 90 degrees right |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
70 |
DIRDIFF_REVERSE = 4, ///< One direction is the opposit of the other one |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
71 |
DIRDIFF_90LEFT = 6, ///< Angle of 90 degrees left |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
72 |
DIRDIFF_45LEFT = 7 ///< Angle of 45 degrees left |
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6451
diff
changeset
|
73 |
}; |
3158
a821c8fec829
(svn r3784) Add a type and functions to handle direction changes
tron
parents:
3157
diff
changeset
|
74 |
|
6743
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
75 |
/** |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
76 |
* Calculate the difference between to directions |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
77 |
* |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
78 |
* @param d0 The first direction as the base |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
79 |
* @param d1 The second direction as the offset from the base |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
80 |
* @return The difference how the second directions drifts of the first one. |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
81 |
*/ |
3158
a821c8fec829
(svn r3784) Add a type and functions to handle direction changes
tron
parents:
3157
diff
changeset
|
82 |
static inline DirDiff DirDifference(Direction d0, Direction d1) |
a821c8fec829
(svn r3784) Add a type and functions to handle direction changes
tron
parents:
3157
diff
changeset
|
83 |
{ |
3162 | 84 |
return (DirDiff)((d0 + 8 - d1) % 8); |
3158
a821c8fec829
(svn r3784) Add a type and functions to handle direction changes
tron
parents:
3157
diff
changeset
|
85 |
} |
a821c8fec829
(svn r3784) Add a type and functions to handle direction changes
tron
parents:
3157
diff
changeset
|
86 |
|
6743
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
87 |
/** |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
88 |
* Applies two differences together |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
89 |
* |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
90 |
* This function adds two differences together and return the resulting |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
91 |
* difference. So adding two DIRDIFF_REVERSE together results in the |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
92 |
* DIRDIFF_SAME difference. |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
93 |
* |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
94 |
* @param d The first difference |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
95 |
* @param delta The second difference to add on |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
96 |
* @return The resulting difference |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
97 |
*/ |
3158
a821c8fec829
(svn r3784) Add a type and functions to handle direction changes
tron
parents:
3157
diff
changeset
|
98 |
static inline DirDiff ChangeDirDiff(DirDiff d, DirDiff delta) |
a821c8fec829
(svn r3784) Add a type and functions to handle direction changes
tron
parents:
3157
diff
changeset
|
99 |
{ |
a821c8fec829
(svn r3784) Add a type and functions to handle direction changes
tron
parents:
3157
diff
changeset
|
100 |
return (DirDiff)((d + delta) % 8); |
a821c8fec829
(svn r3784) Add a type and functions to handle direction changes
tron
parents:
3157
diff
changeset
|
101 |
} |
a821c8fec829
(svn r3784) Add a type and functions to handle direction changes
tron
parents:
3157
diff
changeset
|
102 |
|
6743
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
103 |
/** |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
104 |
* Change a direction by a given difference |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
105 |
* |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
106 |
* This functions returns a new direction of the given direction |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
107 |
* which is rotated by the given difference. |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
108 |
* |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
109 |
* @param d The direction to get a new direction from |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
110 |
* @param delta The offset/drift applied to the direction |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
111 |
* @return The new direction |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
112 |
*/ |
3158
a821c8fec829
(svn r3784) Add a type and functions to handle direction changes
tron
parents:
3157
diff
changeset
|
113 |
static inline Direction ChangeDir(Direction d, DirDiff delta) |
a821c8fec829
(svn r3784) Add a type and functions to handle direction changes
tron
parents:
3157
diff
changeset
|
114 |
{ |
a821c8fec829
(svn r3784) Add a type and functions to handle direction changes
tron
parents:
3157
diff
changeset
|
115 |
return (Direction)((d + delta) % 8); |
a821c8fec829
(svn r3784) Add a type and functions to handle direction changes
tron
parents:
3157
diff
changeset
|
116 |
} |
a821c8fec829
(svn r3784) Add a type and functions to handle direction changes
tron
parents:
3157
diff
changeset
|
117 |
|
a821c8fec829
(svn r3784) Add a type and functions to handle direction changes
tron
parents:
3157
diff
changeset
|
118 |
|
6743
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
119 |
/** |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
120 |
* Enumeration for diagonal directions. |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
121 |
* |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
122 |
* This enumeration is used for the 4 direction of the tile-edges. |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
123 |
*/ |
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6451
diff
changeset
|
124 |
enum DiagDirection { |
6743
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
125 |
DIAGDIR_BEGIN = 0, ///< Used for iterations |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
126 |
DIAGDIR_NE = 0, ///< Northeast, upper right on your monitor |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
127 |
DIAGDIR_SE = 1, ///< Southeast |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
128 |
DIAGDIR_SW = 2, ///< Southwest |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
129 |
DIAGDIR_NW = 3, ///< Northwest |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
130 |
DIAGDIR_END, ///< Used for iterations |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
131 |
INVALID_DIAGDIR = 0xFF, ///< Flag for an invalid DiagDirection |
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6451
diff
changeset
|
132 |
}; |
3147
0a09ce6d651a
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
133 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5726
diff
changeset
|
134 |
DECLARE_POSTFIX_INCREMENT(DiagDirection); |
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5726
diff
changeset
|
135 |
|
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5726
diff
changeset
|
136 |
/** Define basic enum properties */ |
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5726
diff
changeset
|
137 |
template <> struct EnumPropsT<DiagDirection> : MakeEnumPropsT<DiagDirection, byte, DIAGDIR_BEGIN, DIAGDIR_END, INVALID_DIAGDIR> {}; |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6574
diff
changeset
|
138 |
typedef TinyEnumT<DiagDirection> DiagDirectionByte; //typedefing-enumification of DiagDirection |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5726
diff
changeset
|
139 |
|
6743
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
140 |
/** |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
141 |
* Returns the reverse direction of the given DiagDirection |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
142 |
* |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
143 |
* @param d The DiagDirection to get the reverse from |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
144 |
* @return The reverse direction |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
145 |
*/ |
3147
0a09ce6d651a
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
146 |
static inline DiagDirection ReverseDiagDir(DiagDirection d) |
0a09ce6d651a
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
147 |
{ |
3148
82e8641d2b42
(svn r3769) Add a cast to make KUDr's C++ compiler happy
tron
parents:
3147
diff
changeset
|
148 |
return (DiagDirection)(2 ^ d); |
3147
0a09ce6d651a
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
149 |
} |
0a09ce6d651a
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
150 |
|
6743
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
151 |
/** |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
152 |
* Enumeration for the difference between to DiagDirection. |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
153 |
* |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
154 |
* As the DiagDirection only contains 4 possible directions the |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
155 |
* difference between two of these directions can only be in 4 ways. |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
156 |
* As the DirDiff enumeration the values can be added together and |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
157 |
* you will get the resulting difference (use modulo DIAGDIR_END). |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
158 |
* |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
159 |
* @see DirDiff |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
160 |
*/ |
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6451
diff
changeset
|
161 |
enum DiagDirDiff { |
6743
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
162 |
DIAGDIRDIFF_SAME = 0, ///< Same directions |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
163 |
DIAGDIRDIFF_90RIGHT = 1, ///< 90 degrees right |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
164 |
DIAGDIRDIFF_REVERSE = 2, ///< Reverse directions |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
165 |
DIAGDIRDIFF_90LEFT = 3 ///< 90 degrees left |
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6451
diff
changeset
|
166 |
}; |
3163
129a91e147b8
(svn r3789) Add an enum and function to handle DiagDirection changes
tron
parents:
3162
diff
changeset
|
167 |
|
6870
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6743
diff
changeset
|
168 |
/** Allow incrementing of DiagDirDiff variables */ |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6743
diff
changeset
|
169 |
DECLARE_POSTFIX_INCREMENT(DiagDirDiff); |
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6743
diff
changeset
|
170 |
|
6743
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
171 |
/** |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
172 |
* Applies a difference on a DiagDirection |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
173 |
* |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
174 |
* This function applies a difference on a DiagDirection and returns |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
175 |
* the new DiagDirection. |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
176 |
* |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
177 |
* @param d The DiagDirection |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
178 |
* @param delta The difference to applie on |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
179 |
* @return The new direction which was calculated |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
180 |
*/ |
3163
129a91e147b8
(svn r3789) Add an enum and function to handle DiagDirection changes
tron
parents:
3162
diff
changeset
|
181 |
static inline DiagDirection ChangeDiagDir(DiagDirection d, DiagDirDiff delta) |
129a91e147b8
(svn r3789) Add an enum and function to handle DiagDirection changes
tron
parents:
3162
diff
changeset
|
182 |
{ |
129a91e147b8
(svn r3789) Add an enum and function to handle DiagDirection changes
tron
parents:
3162
diff
changeset
|
183 |
return (DiagDirection)((d + delta) % 4); |
129a91e147b8
(svn r3789) Add an enum and function to handle DiagDirection changes
tron
parents:
3162
diff
changeset
|
184 |
} |
129a91e147b8
(svn r3789) Add an enum and function to handle DiagDirection changes
tron
parents:
3162
diff
changeset
|
185 |
|
6743
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
186 |
/** |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
187 |
* Convert a Direction to a DiagDirection. |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
188 |
* |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
189 |
* This function can be used to convert the 8-way Direction to |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
190 |
* the 4-way DiagDirection. If the direction cannot be mapped its |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
191 |
* "rounded clockwise". So DIR_N becomes DIAGDIR_NE. |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
192 |
* |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
193 |
* @param dir The direction to convert |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
194 |
* @return The resulting DiagDirection, maybe "rounded clockwise". |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
195 |
*/ |
3153
301c1d71122b
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3148
diff
changeset
|
196 |
static inline DiagDirection DirToDiagDir(Direction dir) |
3147
0a09ce6d651a
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
197 |
{ |
0a09ce6d651a
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
198 |
return (DiagDirection)(dir >> 1); |
0a09ce6d651a
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
199 |
} |
0a09ce6d651a
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
200 |
|
6743
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
201 |
/** |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
202 |
* Convert a DiagDirection to a Direction. |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
203 |
* |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
204 |
* This function can be used to convert the 4-way DiagDirection |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
205 |
* to the 8-way Direction. As 4-way are less than 8-way not all |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
206 |
* possible directions can be calculated. |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
207 |
* |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
208 |
* @param dir The direction to convert |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
209 |
* @return The resulting Direction |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
210 |
*/ |
3153
301c1d71122b
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3148
diff
changeset
|
211 |
static inline Direction DiagDirToDir(DiagDirection dir) |
301c1d71122b
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3148
diff
changeset
|
212 |
{ |
301c1d71122b
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3148
diff
changeset
|
213 |
return (Direction)(dir * 2 + 1); |
301c1d71122b
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3148
diff
changeset
|
214 |
} |
301c1d71122b
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3148
diff
changeset
|
215 |
|
301c1d71122b
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3148
diff
changeset
|
216 |
|
6743
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
217 |
/** |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
218 |
* Enumeration for the two axis X and Y |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
219 |
* |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
220 |
* This enumeration represente the two axis X and Y in the game. |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
221 |
* The X axis is the one which goes align the north-west edge |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
222 |
* (and south-east edge). The Y axis must be so the one which goes |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
223 |
* align the north-east edge (and south-west) edge. |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
224 |
*/ |
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6451
diff
changeset
|
225 |
enum Axis { |
6743
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
226 |
AXIS_X = 0, ///< The X axis |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
227 |
AXIS_Y = 1, ///< The y axis |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
228 |
AXIS_END ///< Used for iterations |
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6451
diff
changeset
|
229 |
}; |
3147
0a09ce6d651a
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff
changeset
|
230 |
|
3154 | 231 |
|
6743
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
232 |
/** |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
233 |
* Select the other axis as provided. |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
234 |
* |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
235 |
* This is basically the not-operator for the axis. |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
236 |
* |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
237 |
* @param a The given axis |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
238 |
* @return The other axis |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
239 |
*/ |
4158 | 240 |
static inline Axis OtherAxis(Axis a) |
241 |
{ |
|
242 |
return (Axis)(a ^ 1); |
|
243 |
} |
|
244 |
||
245 |
||
6743
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
246 |
/** |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
247 |
* Convert a DiagDirection to the axis. |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
248 |
* |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
249 |
* This function returns the axis which belongs to the given |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
250 |
* DiagDirection. The axis X belongs to the DiagDirection |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
251 |
* north-east and south-west. |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
252 |
* |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
253 |
* @param d The DiagDirection |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
254 |
* @return The axis which belongs to the direction |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
255 |
*/ |
3154 | 256 |
static inline Axis DiagDirToAxis(DiagDirection d) |
257 |
{ |
|
258 |
return (Axis)(d & 1); |
|
259 |
} |
|
260 |
||
3209
e0b7d48351a3
(svn r3877) Add functions to turn a tile into a rail/road bridge ramp/middle part
tron
parents:
3163
diff
changeset
|
261 |
|
6743
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
262 |
/** |
3209
e0b7d48351a3
(svn r3877) Add functions to turn a tile into a rail/road bridge ramp/middle part
tron
parents:
3163
diff
changeset
|
263 |
* Converts an Axis to a DiagDirection |
6743
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
264 |
* |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
265 |
* This function returns the DiagDirection which |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
266 |
* belongs to the axis. As 2 directions are mapped to an axis |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
267 |
* this function returns the one which points to south, |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
268 |
* either south-west (on X axis) or south-east (on Y axis) |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
269 |
* |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
270 |
* @param a The axis |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
271 |
* @return The direction pointed to south |
3209
e0b7d48351a3
(svn r3877) Add functions to turn a tile into a rail/road bridge ramp/middle part
tron
parents:
3163
diff
changeset
|
272 |
*/ |
e0b7d48351a3
(svn r3877) Add functions to turn a tile into a rail/road bridge ramp/middle part
tron
parents:
3163
diff
changeset
|
273 |
static inline DiagDirection AxisToDiagDir(Axis a) |
e0b7d48351a3
(svn r3877) Add functions to turn a tile into a rail/road bridge ramp/middle part
tron
parents:
3163
diff
changeset
|
274 |
{ |
e0b7d48351a3
(svn r3877) Add functions to turn a tile into a rail/road bridge ramp/middle part
tron
parents:
3163
diff
changeset
|
275 |
return (DiagDirection)(2 - a); |
e0b7d48351a3
(svn r3877) Add functions to turn a tile into a rail/road bridge ramp/middle part
tron
parents:
3163
diff
changeset
|
276 |
} |
e0b7d48351a3
(svn r3877) Add functions to turn a tile into a rail/road bridge ramp/middle part
tron
parents:
3163
diff
changeset
|
277 |
|
3953
db302c2d1a2a
(svn r5101) Add a function to convert an axis and a flag for north/south into a DiagDirection. Use it for bridge ramps and ship depots
tron
parents:
3744
diff
changeset
|
278 |
/** |
db302c2d1a2a
(svn r5101) Add a function to convert an axis and a flag for north/south into a DiagDirection. Use it for bridge ramps and ship depots
tron
parents:
3744
diff
changeset
|
279 |
* Convert an axis and a flag for north/south into a DiagDirection |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6574
diff
changeset
|
280 |
* @param xy axis to convert |
3953
db302c2d1a2a
(svn r5101) Add a function to convert an axis and a flag for north/south into a DiagDirection. Use it for bridge ramps and ship depots
tron
parents:
3744
diff
changeset
|
281 |
* @param ns north -> 0, south -> 1 |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6574
diff
changeset
|
282 |
* @return the desired DiagDirection |
3953
db302c2d1a2a
(svn r5101) Add a function to convert an axis and a flag for north/south into a DiagDirection. Use it for bridge ramps and ship depots
tron
parents:
3744
diff
changeset
|
283 |
*/ |
db302c2d1a2a
(svn r5101) Add a function to convert an axis and a flag for north/south into a DiagDirection. Use it for bridge ramps and ship depots
tron
parents:
3744
diff
changeset
|
284 |
static inline DiagDirection XYNSToDiagDir(Axis xy, uint ns) |
db302c2d1a2a
(svn r5101) Add a function to convert an axis and a flag for north/south into a DiagDirection. Use it for bridge ramps and ship depots
tron
parents:
3744
diff
changeset
|
285 |
{ |
db302c2d1a2a
(svn r5101) Add a function to convert an axis and a flag for north/south into a DiagDirection. Use it for bridge ramps and ship depots
tron
parents:
3744
diff
changeset
|
286 |
return (DiagDirection)(xy * 3 ^ ns * 2); |
db302c2d1a2a
(svn r5101) Add a function to convert an axis and a flag for north/south into a DiagDirection. Use it for bridge ramps and ship depots
tron
parents:
3744
diff
changeset
|
287 |
} |
db302c2d1a2a
(svn r5101) Add a function to convert an axis and a flag for north/south into a DiagDirection. Use it for bridge ramps and ship depots
tron
parents:
3744
diff
changeset
|
288 |
|
6743
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
289 |
/** |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
290 |
* Checks if an interger value is a valid DiagDirection |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
291 |
* |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
292 |
* @param d The value to check |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
293 |
* @return True if the value belongs to a DiagDirection, else false |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
294 |
*/ |
3699
15e473a194ef
(svn r4640) - Add: IsValidDiagDirection, IsValidDirection and IsValidAxis functions.
matthijs
parents:
3209
diff
changeset
|
295 |
static inline bool IsValidDiagDirection(DiagDirection d) |
15e473a194ef
(svn r4640) - Add: IsValidDiagDirection, IsValidDirection and IsValidAxis functions.
matthijs
parents:
3209
diff
changeset
|
296 |
{ |
15e473a194ef
(svn r4640) - Add: IsValidDiagDirection, IsValidDirection and IsValidAxis functions.
matthijs
parents:
3209
diff
changeset
|
297 |
return d < DIAGDIR_END; |
15e473a194ef
(svn r4640) - Add: IsValidDiagDirection, IsValidDirection and IsValidAxis functions.
matthijs
parents:
3209
diff
changeset
|
298 |
} |
15e473a194ef
(svn r4640) - Add: IsValidDiagDirection, IsValidDirection and IsValidAxis functions.
matthijs
parents:
3209
diff
changeset
|
299 |
|
6743
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
300 |
/** |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
301 |
* Checks if an integer value is a valid Direction |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
302 |
* |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
303 |
* @param d The value to check |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
304 |
* @return True if the value belongs to a Direction, else false |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
305 |
*/ |
3744
d5f308a7218b
(svn r4732) - Fix: use correct types in IsValid[Direction|Axis]
glx
parents:
3699
diff
changeset
|
306 |
static inline bool IsValidDirection(Direction d) |
3699
15e473a194ef
(svn r4640) - Add: IsValidDiagDirection, IsValidDirection and IsValidAxis functions.
matthijs
parents:
3209
diff
changeset
|
307 |
{ |
15e473a194ef
(svn r4640) - Add: IsValidDiagDirection, IsValidDirection and IsValidAxis functions.
matthijs
parents:
3209
diff
changeset
|
308 |
return d < DIR_END; |
15e473a194ef
(svn r4640) - Add: IsValidDiagDirection, IsValidDirection and IsValidAxis functions.
matthijs
parents:
3209
diff
changeset
|
309 |
} |
15e473a194ef
(svn r4640) - Add: IsValidDiagDirection, IsValidDirection and IsValidAxis functions.
matthijs
parents:
3209
diff
changeset
|
310 |
|
6743
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
311 |
/** |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
312 |
* Checks if an integer value is a valid Axis |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
313 |
* |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
314 |
* @param d The value to check |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
315 |
* @return True if the value belongs to an Axis, else false |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6719
diff
changeset
|
316 |
*/ |
3744
d5f308a7218b
(svn r4732) - Fix: use correct types in IsValid[Direction|Axis]
glx
parents:
3699
diff
changeset
|
317 |
static inline bool IsValidAxis(Axis d) |
3699
15e473a194ef
(svn r4640) - Add: IsValidDiagDirection, IsValidDirection and IsValidAxis functions.
matthijs
parents:
3209
diff
changeset
|
318 |
{ |
15e473a194ef
(svn r4640) - Add: IsValidDiagDirection, IsValidDirection and IsValidAxis functions.
matthijs
parents:
3209
diff
changeset
|
319 |
return d < AXIS_END; |
15e473a194ef
(svn r4640) - Add: IsValidDiagDirection, IsValidDirection and IsValidAxis functions.
matthijs
parents:
3209
diff
changeset
|
320 |
} |
15e473a194ef
(svn r4640) - Add: IsValidDiagDirection, IsValidDirection and IsValidAxis functions.
matthijs
parents:
3209
diff
changeset
|
321 |
|
4666
850b5b6e4bac
(svn r6560) - Codechange: Minor fix; add missing #include guards and comments, and correct svn properties on bmp.[ch]
peter1138
parents:
4158
diff
changeset
|
322 |
#endif /* DIRECTION_H */ |