changeset 3071:d1a65c954e58 draft

(svn r3660) Convert further road bits and type references to the functions/enums
author tron <tron@openttd.org>
date Thu, 23 Feb 2006 12:24:19 +0000
parents 9c9666dd671a
children 485f5c4261cd
files ai/default/default.c ai/trolly/trolly.c order_gui.c rail_cmd.c road_cmd.c town_cmd.c
diffstat 6 files changed, 22 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/ai/default/default.c
+++ b/ai/default/default.c
@@ -4,6 +4,7 @@
 #include "../../openttd.h"
 #include "../../functions.h"
 #include "../../map.h"
+#include "../../road.h"
 #include "../../tile.h"
 #include "../../player.h"
 #include "../../vehicle.h"
@@ -2506,12 +2507,12 @@
 
 		if (p->mode == 2) {
 			if (IsTileType(c, MP_STREET) &&
-					(_m[c].m5 & 0xF0) == 0 &&
-					(_m[c].m5 & p->attr) != 0) {
+					GetRoadType(c) == ROAD_NORMAL &&
+					(GetRoadBits(c) & p->attr) != 0) {
 				roadflag |= 2;
 
 				// all bits are already built?
-				if ((_m[c].m5 & p->attr) == p->attr) continue;
+				if ((GetRoadBits(c) & p->attr) == p->attr) continue;
 			}
 
 			ret = DoCommandByTile(c, p->attr, 0, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD);
@@ -2548,7 +2549,7 @@
 
 			if (GetTileSlope(c, NULL) != 0) return CMD_ERROR;
 
-			if (!IsTileType(c, MP_STREET) || (_m[c].m5 & 0xF0) != 0) {
+			if (!IsTileType(c, MP_STREET) || GetRoadType(c) != ROAD_NORMAL) {
 				ret = DoCommandByTile(c, 0, 0, flag | DC_AUTO | DC_NO_WATER | DC_AI_BUILDING, CMD_LANDSCAPE_CLEAR);
 				if (CmdFailed(ret)) return CMD_ERROR;
 			}
@@ -2726,7 +2727,7 @@
 	if (dist <= a->best_dist) {
 		TileIndex tile2 = TILE_MASK(tile + TileOffsByDir(_dir_by_track[track]));
 
-		if (IsTileType(tile2, MP_STREET) && GB(_m[tile2].m5, 4, 4) == 0) {
+		if (IsTileType(tile2, MP_STREET) && GetRoadType(tile2) == ROAD_NORMAL) {
 			a->best_dist = dist;
 			a->best_tile = tile;
 			a->best_track = track;
@@ -3631,7 +3632,7 @@
 
 		if (IsLevelCrossing(tile)) goto is_rail_crossing;
 
-		if ((_m[tile].m5 & 0xF0) == 0x20) { // depot
+		if (GetRoadType(tile) == ROAD_DEPOT) {
 			uint dir;
 
 			// Check if there are any stations around.
--- a/ai/trolly/trolly.c
+++ b/ai/trolly/trolly.c
@@ -21,6 +21,7 @@
 #include "../../openttd.h"
 #include "../../debug.h"
 #include "../../functions.h"
+#include "../../road.h"
 #include "../../table/strings.h"
 #include "../../map.h"
 #include "../../tile.h"
@@ -793,8 +794,7 @@
 		tile = p->ainew.path_info.route[i];
 		for (j = 0; j < 4; j++) {
 			if (IsTileType(tile + TileOffsByDir(j), MP_STREET)) {
-				// Its a street, test if it is a depot
-				if (_m[tile + TileOffsByDir(j)].m5 & 0x20) {
+				if (GetRoadType(tile + TileOffsByDir(j)) == ROAD_DEPOT) {
 					// We found a depot, is it ours? (TELL ME!!!)
 					if (IsTileOwner(tile + TileOffsByDir(j), _current_player)) {
 						// Now, is it pointing to the right direction.........
@@ -1100,7 +1100,7 @@
 	int res = 0;
 	assert(p->ainew.state == AI_STATE_BUILD_DEPOT);
 
-	if (IsTileType(p->ainew.depot_tile, MP_STREET) && _m[p->ainew.depot_tile].m5 & 0x20) {
+	if (IsTileType(p->ainew.depot_tile, MP_STREET) && GetRoadType(p->ainew.depot_tile) == ROAD_DEPOT) {
 		if (IsTileOwner(p->ainew.depot_tile, _current_player)) {
 			// The depot is already builded!
 			p->ainew.state = AI_STATE_BUILD_VEHICLE;
--- a/order_gui.c
+++ b/order_gui.c
@@ -2,6 +2,7 @@
 
 #include "stdafx.h"
 #include "openttd.h"
+#include "road.h"
 #include "table/sprites.h"
 #include "table/strings.h"
 #include "functions.h"
@@ -206,7 +207,7 @@
 			break;
 
 		case MP_STREET:
-			if ((_m[tile].m5 & 0xF0) == 0x20 && v->type == VEH_Road && IsTileOwner(tile, _local_player)) {
+			if (GetRoadType(tile) == ROAD_DEPOT && v->type == VEH_Road && IsTileOwner(tile, _local_player)) {
 				order.type = OT_GOTO_DEPOT;
 				order.flags = OF_PART_OF_ORDERS;
 				order.station = GetDepotByTile(tile)->index;
--- a/rail_cmd.c
+++ b/rail_cmd.c
@@ -403,7 +403,6 @@
 	Track track = (Track)p2;
 	TrackBits trackbit;
 	TileIndex tile;
-	byte m5;
 	int32 cost = _price.remove_rail;
 
 	if (!ValParamTrackOrientation(p2)) return CMD_ERROR;
@@ -442,27 +441,30 @@
 			_m[tile].m5 = _m[tile].m5 & 0xC7;
 			break;
 
-		case MP_STREET:
+		case MP_STREET: {
+			RoadBits bits;
+
 			if (!IsLevelCrossing(tile)) return CMD_ERROR;
 
 			/* This is a crossing, let's check if the direction is correct */
 			if (_m[tile].m5 & 8) {
-				m5 = 5;
 				if (track != TRACK_DIAG1)
 					return CMD_ERROR;
+				bits = ROAD_Y;
 			} else {
-				m5 = 10;
 				if (track != TRACK_DIAG2)
 					return CMD_ERROR;
+				bits = ROAD_X;
 			}
 
 			if (!(flags & DC_EXEC))
 				return _price.remove_rail;
 
-			_m[tile].m5 = m5;
 			SetTileOwner(tile, _m[tile].m3);
 			_m[tile].m2 = 0;
+			_m[tile].m5 = (ROAD_NORMAL << 4) | bits;
 			break;
+		}
 
 		case MP_RAILWAY:
 			if (!IsPlainRailTile(tile))
--- a/road_cmd.c
+++ b/road_cmd.c
@@ -1112,7 +1112,7 @@
 			return _m[tile].m5 & 8 ? 0x101 : 0x202;
 
 		case TRANSPORT_ROAD:
-			switch (GB(_m[tile].m5, 4, 4)) {
+			switch (GetRoadType(tile)) {
 				case ROAD_NORMAL:
 					return !_road_special_gettrackstatus && GB(_m[tile].m4, 4, 3) >= 6 ?
 						0 : _road_trackbits[GetRoadBits(tile)] * 0x101;
--- a/town_cmd.c
+++ b/town_cmd.c
@@ -4,6 +4,7 @@
 #include "openttd.h"
 #include "functions.h"
 #include "strings.h"
+#include "road.h"
 #include "table/strings.h"
 #include "table/sprites.h"
 #include "map.h"
@@ -489,7 +490,7 @@
 			// No, try to build one in the direction.
 			// if that fails clear the land, and if that fails exit.
 			// This is to make sure that we can build a road here later.
-			if (CmdFailed(DoCommandByTile(tile, (dir&1)?0xA:0x5, 0, DC_AUTO, CMD_BUILD_ROAD)) &&
+			if (CmdFailed(DoCommandByTile(tile, (dir & 1 ? ROAD_X : ROAD_Y), 0, DC_AUTO, CMD_BUILD_ROAD)) &&
 					CmdFailed(DoCommandByTile(tile, 0, 0, DC_AUTO, CMD_LANDSCAPE_CLEAR)))
 				return false;
 		}