summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormatthijs <matthijs@openttd.org>2006-05-01 09:34:23 +0000
committermatthijs <matthijs@openttd.org>2006-05-01 09:34:23 +0000
commit6756304fc1a45a3db3baeafff29464e5cdf84d4d (patch)
treeda7831369495881ba17fb8ab0c61f332499bafee
parentd76279144d409a2b3d003606baa146bdb6a2bb00 (diff)
downloadopenttd-6756304fc1a45a3db3baeafff29464e5cdf84d4d.tar.xz
(svn r4640) - Add: IsValidDiagDirection, IsValidDirection and IsValidAxis functions.
- Codechange: Use IsValidDiagDirection() in CmdBuildRoadStop().
-rw-r--r--direction.h18
-rw-r--r--station_cmd.c2
2 files changed, 18 insertions, 2 deletions
diff --git a/direction.h b/direction.h
index c7a8498f6..ba3213896 100644
--- a/direction.h
+++ b/direction.h
@@ -93,7 +93,8 @@ static inline Direction DiagDirToDir(DiagDirection dir)
/* the 2 axis */
typedef enum Axis {
AXIS_X = 0,
- AXIS_Y = 1
+ AXIS_Y = 1,
+ AXIS_END
} Axis;
@@ -112,4 +113,19 @@ static inline DiagDirection AxisToDiagDir(Axis a)
return (DiagDirection)(2 - a);
}
+static inline bool IsValidDiagDirection(DiagDirection d)
+{
+ return d < DIAGDIR_END;
+}
+
+static inline bool IsValidDirection(DiagDirection d)
+{
+ return d < DIR_END;
+}
+
+static inline bool IsValidAxis(DiagDirection d)
+{
+ return d < AXIS_END;
+}
+
#endif
diff --git a/station_cmd.c b/station_cmd.c
index e7fcb9ca2..491454573 100644
--- a/station_cmd.c
+++ b/station_cmd.c
@@ -1360,7 +1360,7 @@ int32 CmdBuildRoadStop(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
bool type = !!p2;
/* Saveguard the parameters */
- if (p1 > 3) return CMD_ERROR;
+ if (!IsValidDiagDirection(p1)) return CMD_ERROR;
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);