(svn r9893) -Fix (r9892): various small bugs that only act up when using something different than plain roads.
authorrubidium
Sun, 20 May 2007 22:04:24 +0000
changeset 6662 ea30b3497d9a
parent 6661 1716fce5ad29
child 6663 3f0ebbd21f88
(svn r9893) -Fix (r9892): various small bugs that only act up when using something different than plain roads.
src/road_cmd.cpp
src/road_gui.cpp
src/road_map.h
src/station_cmd.cpp
--- a/src/road_cmd.cpp	Sun May 20 19:14:08 2007 +0000
+++ b/src/road_cmd.cpp	Sun May 20 22:04:24 2007 +0000
@@ -147,17 +147,18 @@
 
 			/* limit the bits to delete to the existing bits. */
 			c &= present;
-			if (c == 0) return CMD_ERROR;
+			if (c == ROAD_NONE) return CMD_ERROR;
 
 			if (flags & DC_EXEC) {
 				ChangeTownRating(t, -road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM);
 
 				present ^= c;
-				if (present == 0) {
+				if (present == ROAD_NONE) {
 					RoadTypes rts = GetRoadTypes(tile) & ComplementRoadTypes(RoadTypeToRoadTypes(rt));
 					if (rts == ROADTYPES_NONE) {
 						DoClearSquare(tile);
 					} else {
+						SetRoadBits(tile, ROAD_NONE, rt);
 						SetRoadTypes(tile, rts);
 					}
 				} else {
@@ -299,6 +300,7 @@
 			switch (GetRoadTileType(tile)) {
 				case ROAD_TILE_NORMAL:
 					if (HasRoadWorks(tile)) return_cmd_error(STR_ROAD_WORKS_IN_PROGRESS);
+					if (!HASBIT(GetRoadTypes(tile), rt)) break;
 
 					existing = GetRoadBits(tile, rt);
 					if ((existing & pieces) == pieces) {
@@ -381,7 +383,7 @@
 
 	if (flags & DC_EXEC) {
 		if (IsTileType(tile, MP_STREET)) {
-			if (existing == 0) {
+			if (existing == ROAD_NONE) {
 				SetRoadTypes(tile, GetRoadTypes(tile) | RoadTypeToRoadTypes(rt));
 				SetRoadOwner(tile, rt, _current_player);
 			}
@@ -434,7 +436,7 @@
  * - p2 = (bit 0) - start tile starts in the 2nd half of tile (p2 & 1)
  * - p2 = (bit 1) - end tile starts in the 2nd half of tile (p2 & 2)
  * - p2 = (bit 2) - direction: 0 = along x-axis, 1 = along y-axis (p2 & 4)
- * - p2 = (bit 3) - road type
+ * - p2 = (bit 3 + 4) - road type
  */
 int32 CmdBuildLongRoad(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p2)
 {
@@ -446,7 +448,8 @@
 	if (p1 >= MapSize()) return CMD_ERROR;
 
 	start_tile = p1;
-	RoadType rt = (RoadType)HASBIT(p2, 3);
+	RoadType rt = (RoadType)GB(p2, 3, 2);
+	if (!IsValidRoadType(rt)) return CMD_ERROR;
 
 	/* Only drag in X or Y direction dictated by the direction variable */
 	if (!HASBIT(p2, 2) && TileY(start_tile) != TileY(end_tile)) return CMD_ERROR; // x-axis
@@ -493,7 +496,7 @@
  * - p2 = (bit 0) - start tile starts in the 2nd half of tile (p2 & 1)
  * - p2 = (bit 1) - end tile starts in the 2nd half of tile (p2 & 2)
  * - p2 = (bit 2) - direction: 0 = along x-axis, 1 = along y-axis (p2 & 4)
- * - p2 = (bit 3) - road type
+ * - p2 = (bit 3 + 4) - road type
  */
 int32 CmdRemoveLongRoad(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p2)
 {
@@ -505,7 +508,8 @@
 	if (p1 >= MapSize()) return CMD_ERROR;
 
 	start_tile = p1;
-	RoadType rt = (RoadType)HASBIT(p2, 3);
+	RoadType rt = (RoadType)GB(p2, 3, 2);
+	if (!IsValidRoadType(rt)) return CMD_ERROR;
 
 	/* Only drag in X or Y direction dictated by the direction variable */
 	if (!HASBIT(p2, 2) && TileY(start_tile) != TileY(end_tile)) return CMD_ERROR; // x-axis
@@ -546,7 +550,7 @@
  * @param tile tile where to build the depot
  * @param flags operation to perform
  * @param p1 bit 0..1 entrance direction (DiagDirection)
- *           bit    2 road type
+ *           bit 2..3 road type
  * @param p2 unused
  *
  * @todo When checking for the tile slope,
@@ -561,7 +565,9 @@
 	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
 
 	DiagDirection dir = Extract<DiagDirection, 0>(p1);
-	RoadType rt = (RoadType)HASBIT(p1, 2);
+	RoadType rt = (RoadType)GB(p1, 2, 2);
+
+	if (!IsValidRoadType(rt)) return CMD_ERROR;
 
 	tileh = GetTileSlope(tile, NULL);
 	if (tileh != SLOPE_FLAT && (
--- a/src/road_gui.cpp	Sun May 20 19:14:08 2007 +0000
+++ b/src/road_gui.cpp	Sun May 20 22:04:24 2007 +0000
@@ -84,11 +84,12 @@
 void CcRoadDepot(bool success, TileIndex tile, uint32 p1, uint32 p2)
 {
 	if (success) {
+		DiagDirection dir = (DiagDirection)GB(p1, 0, 2);
 		SndPlayTileFx(SND_1F_SPLAT, tile);
 		ResetObjectToPlace();
-		BuildRoadOutsideStation(tile, (DiagDirection)p1);
+		BuildRoadOutsideStation(tile, dir);
 		/* For a drive-through road stop build connecting road for other entrance */
-		if (HASBIT(p2, 1)) BuildRoadOutsideStation(tile, ReverseDiagDir((DiagDirection)p1));
+		if (HASBIT(p2, 1)) BuildRoadOutsideStation(tile, ReverseDiagDir(dir));
 	}
 }
 
--- a/src/road_map.h	Sun May 20 19:14:08 2007 +0000
+++ b/src/road_map.h	Sun May 20 22:04:24 2007 +0000
@@ -116,6 +116,7 @@
 				case ROADTYPE_TRAM: SB( _m[t].m5, 0, 5, o); break;
 				case ROADTYPE_HWAY: SB(_me[t].m7, 0, 5, o); break;
 			}
+			break;
 		case ROAD_TILE_CROSSING:
 			switch (rt) {
 				default: NOT_REACHED();
@@ -123,6 +124,7 @@
 				case ROADTYPE_TRAM: SB( _m[t].m5, 0, 5, o); break;
 				case ROADTYPE_HWAY: SB(_me[t].m7, 0, 5, o); break;
 			}
+			break;
 		case ROAD_TILE_DEPOT: return SetTileOwner(t, o);
 	}
 }
@@ -264,7 +266,7 @@
 	SetTileOwner(t, road);
 	_m[t].m2 = town;
 	_m[t].m3 = 0;
-	_m[t].m4 = (HASBIT(rot, ROADTYPE_ROAD) ? bits : 0) << 4 | HASBIT(rot, ROADTYPE_TRAM) ? bits : 0;
+	_m[t].m4 = (HASBIT(rot, ROADTYPE_TRAM) ? bits : 0) << 4 | (HASBIT(rot, ROADTYPE_ROAD) ? bits : 0);
 	_m[t].m5 = ROAD_TILE_NORMAL << 6 | tram;
 	SB(_m[t].m6, 2, 4, HASBIT(rot, ROADTYPE_HWAY) ? bits : 0);
 	_me[t].m7 = rot << 5 | hway;
--- a/src/station_cmd.cpp	Sun May 20 19:14:08 2007 +0000
+++ b/src/station_cmd.cpp	Sun May 20 22:04:24 2007 +0000
@@ -1397,7 +1397,7 @@
 	/* Save the stop info before it is removed */
 	bool is_drive_through = IsDriveThroughStopTile(tile);
 	RoadTypes rts = GetRoadTypes(tile);
-	RoadBits road_bits = GetAnyRoadBits(tile, HASBIT(rts, ROADTYPE_ROAD) ? ROADTYPE_ROAD : ROADTYPE_TRAM);
+	RoadBits road_bits = GetAllRoadBits(tile);
 	bool is_towns_road = is_drive_through && GetStopBuiltOnTownRoad(tile);
 
 	int32 ret = RemoveRoadStop(st, flags, tile);