summaryrefslogtreecommitdiff
path: root/src/road_cmd.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2008-05-18 17:40:13 +0000
committerrubidium <rubidium@openttd.org>2008-05-18 17:40:13 +0000
commit2e25df3ddf2e7981c9681443e7ad77414827c301 (patch)
tree6a1c347049553c5f0c89f505f9eee414b354b925 /src/road_cmd.cpp
parent9defec78767131d1dc9765c8943ae3bb165e8713 (diff)
downloadopenttd-2e25df3ddf2e7981c9681443e7ad77414827c301.tar.xz
(svn r13166) -Codechange: CmdSetRoadDriveSide belongs in road_cmd.cpp, not settings_gui.cpp.
Diffstat (limited to 'src/road_cmd.cpp')
-rw-r--r--src/road_cmd.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp
index 22a4fac0f..3624a6931 100644
--- a/src/road_cmd.cpp
+++ b/src/road_cmd.cpp
@@ -43,6 +43,37 @@
#include "table/sprites.h"
#include "table/strings.h"
+
+bool RoadVehiclesAreBuilt()
+{
+ const Vehicle* v;
+
+ FOR_ALL_VEHICLES(v) {
+ if (v->type == VEH_ROAD) return true;
+ }
+ return false;
+}
+
+/**
+ * Change the side of the road vehicles drive on (server only).
+ * @param tile unused
+ * @param flags operation to perform
+ * @param p1 the side of the road; 0 = left side and 1 = right side
+ * @param p2 unused
+ */
+CommandCost CmdSetRoadDriveSide(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
+{
+ /* Check boundaries and you can only change this if NO vehicles have been built yet,
+ * except in the intro-menu where of course it's always possible to do so. */
+ if (p1 > 1 || (_game_mode != GM_MENU && RoadVehiclesAreBuilt())) return CMD_ERROR;
+
+ if (flags & DC_EXEC) {
+ _opt_ptr->road_side = p1;
+ InvalidateWindow(WC_GAME_OPTIONS, 0);
+ }
+ return CommandCost();
+}
+
#define M(x) (1 << (x))
/* Level crossings may only be built on these slopes */
static const uint32 VALID_LEVEL_CROSSING_SLOPES = (M(SLOPE_SEN) | M(SLOPE_ENW) | M(SLOPE_NWS) | M(SLOPE_NS) | M(SLOPE_WSE) | M(SLOPE_EW) | M(SLOPE_FLAT));