From 20b5c17faa3a45c79a6edddbe6e5243d80e595c1 Mon Sep 17 00:00:00 2001 From: tron Date: Sat, 24 Jun 2006 09:12:15 +0000 Subject: [PATCH] (svn r5349) -Backport: r5315 -Fix: Prohibit altering a road tile while road works are in progress This fixes some glitches like "turning" the excavation by adding/removing road bits or removing the road piece --- lang/english.txt | 1 + lang/german.txt | 1 + rail_cmd.c | 3 +++ road_cmd.c | 5 +++++ road_map.h | 43 +++++++++++++++++++++++++++++++++++++++++++ tunnelbridge_cmd.c | 3 +++ 6 files changed, 56 insertions(+) create mode 100644 road_map.h diff --git a/lang/english.txt b/lang/english.txt index dcb2ebae7c..73255a9885 100644 --- a/lang/english.txt +++ b/lang/english.txt @@ -1450,6 +1450,7 @@ STR_RAILROAD_TRACK_WITH_COMBOSIGNALS :Railway track w ##id 0x1800 STR_1800_LAND_SLOPED_IN_WRONG_DIRECTION :{WHITE}Land sloped in wrong direction for road STR_1801_MUST_REMOVE_ROAD_FIRST :{WHITE}Must remove road first +STR_ROAD_WORKS_IN_PROGRESS :{WHITE}Road works in progress STR_1802_ROAD_CONSTRUCTION :{WHITE}Road Construction STR_1803_SELECT_ROAD_BRIDGE :{WHITE}Select Road Bridge STR_1804_CAN_T_BUILD_ROAD_HERE :{WHITE}Can't build road here... diff --git a/lang/german.txt b/lang/german.txt index 403765b736..d44dc6cde4 100644 --- a/lang/german.txt +++ b/lang/german.txt @@ -1452,6 +1452,7 @@ STR_RAILROAD_TRACK_WITH_COMBOSIGNALS :Gleis mit kombi ##id 0x1800 STR_1800_LAND_SLOPED_IN_WRONG_DIRECTION :{WHITE}Das Land neigt sich in die falsche Richtung STR_1801_MUST_REMOVE_ROAD_FIRST :{WHITE}Straße muss erst entfernt werden +STR_ROAD_WORKS_IN_PROGRESS :{WHITE}Straßenarbeiten sind im Gange STR_1802_ROAD_CONSTRUCTION :{WHITE}Straßenbau STR_1803_SELECT_ROAD_BRIDGE :{WHITE}Brücke wählen STR_1804_CAN_T_BUILD_ROAD_HERE :{WHITE}Kann hier keine Straße bauen... diff --git a/rail_cmd.c b/rail_cmd.c index 66d7547d45..ab297039ee 100644 --- a/rail_cmd.c +++ b/rail_cmd.c @@ -4,6 +4,7 @@ #include "openttd.h" #include "debug.h" #include "functions.h" +#include "road_map.h" #include "table/sprites.h" #include "table/strings.h" #include "map.h" @@ -344,6 +345,8 @@ int32 CmdBuildSingleRail(int x, int y, uint32 flags, uint32 p1, uint32 p2) (track == TRACK_DIAG1 && m5 == 0x05) || (track == TRACK_DIAG2 && m5 == 0x0A) // correct direction? )) { + if (HasRoadWorks(tile)) return_cmd_error(STR_ROAD_WORKS_IN_PROGRESS); + if (flags & DC_EXEC) { _m[tile].m3 = GetTileOwner(tile); SetTileOwner(tile, _current_player); diff --git a/road_cmd.c b/road_cmd.c index 95a6130f74..e730b5b4aa 100644 --- a/road_cmd.c +++ b/road_cmd.c @@ -2,6 +2,7 @@ #include "stdafx.h" #include "openttd.h" +#include "road_map.h" #include "table/sprites.h" #include "table/strings.h" #include "functions.h" @@ -210,6 +211,8 @@ int32 CmdRemoveRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2) if ((ti.map5 & 0xF0) == 0) { // normal road byte c = pieces, t2; + if (HasRoadWorks(tile)) return_cmd_error(STR_ROAD_WORKS_IN_PROGRESS); + if (ti.tileh != 0 && (ti.map5 == 5 || ti.map5 == 10)) { c |= (c & 0xC) >> 2; c |= (c & 0x3) << 2; @@ -372,6 +375,8 @@ int32 CmdBuildRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2) if (ti.type == MP_STREET) { if (!(ti.map5 & 0xF0)) { + if (HasRoadWorks(tile)) return_cmd_error(STR_ROAD_WORKS_IN_PROGRESS); + if ((pieces & (byte)ti.map5) == pieces) return_cmd_error(STR_1007_ALREADY_BUILT); existing = ti.map5; diff --git a/road_map.h b/road_map.h new file mode 100644 index 0000000000..ae08bb2c0b --- /dev/null +++ b/road_map.h @@ -0,0 +1,43 @@ +/* $Id$ */ + +#ifndef ROAD_MAP_H +#define ROAD_MAP_H + +#include "macros.h" +#include "tile.h" + + +typedef enum RoadTileType { + ROAD_TILE_NORMAL, + ROAD_TILE_CROSSING, + ROAD_TILE_DEPOT +} RoadTileType; + +static inline RoadTileType GetRoadTileType(TileIndex t) +{ + assert(IsTileType(t, MP_STREET)); + return (RoadTileType)GB(_m[t].m5, 4, 4); +} + + +typedef enum Roadside { + ROADSIDE_BARREN = 0, + ROADSIDE_GRASS = 1, + ROADSIDE_PAVED = 2, + ROADSIDE_STREET_LIGHTS = 3, + ROADSIDE_TREES = 5, + ROADSIDE_GRASS_ROAD_WORKS = 6, + ROADSIDE_PAVED_ROAD_WORKS = 7 +} Roadside; + +static inline Roadside GetRoadside(TileIndex tile) +{ + return (Roadside)GB(_m[tile].m4, 4, 3); +} + +static inline bool HasRoadWorks(TileIndex t) +{ + return GetRoadside(t) >= ROADSIDE_GRASS_ROAD_WORKS; +} + +#endif diff --git a/tunnelbridge_cmd.c b/tunnelbridge_cmd.c index aad26ad8d7..ae4705a86f 100644 --- a/tunnelbridge_cmd.c +++ b/tunnelbridge_cmd.c @@ -8,6 +8,7 @@ #include "stdafx.h" #include "openttd.h" #include "bridge_map.h" +#include "road_map.h" #include "slope.h" #include "table/sprites.h" #include "table/strings.h" @@ -354,6 +355,8 @@ int32 CmdBuildBridge(int x, int y, uint32 flags, uint32 p1, uint32 p2) } m5 = 0xE0; } else if (ti.type == MP_STREET) { + if (GetRoadTileType(ti.tile) != ROAD_TILE_NORMAL) goto not_valid_below; + if (HasRoadWorks(ti.tile)) return_cmd_error(STR_ROAD_WORKS_IN_PROGRESS); if (direction == 0) { if (ti.map5 != 5) goto not_valid_below; } else {