(svn r3698) Add GetCrossingRailBits() and ComplementRoadBits(). Simplify the code by using them
This commit is contained in:
		
							
								
								
									
										12
									
								
								rail_cmd.c
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								rail_cmd.c
									
									
									
									
									
								
							| @@ -434,23 +434,15 @@ int32 CmdRemoveSingleRail(int x, int y, uint32 flags, uint32 p1, uint32 p2) | |||||||
| 			break; | 			break; | ||||||
|  |  | ||||||
| 		case MP_STREET: { | 		case MP_STREET: { | ||||||
| 			RoadBits bits; |  | ||||||
|  |  | ||||||
| 			if (!IsLevelCrossing(tile)) return CMD_ERROR; | 			if (!IsLevelCrossing(tile)) return CMD_ERROR; | ||||||
|  |  | ||||||
| 			/* This is a crossing, let's check if the direction is correct */ | 			/* This is a crossing, let's check if the direction is correct */ | ||||||
| 			if (_m[tile].m5 & 8) { | 			if (GetCrossingRailBits(tile) != trackbit) return CMD_ERROR; | ||||||
| 				if (track != TRACK_X) return CMD_ERROR; |  | ||||||
| 				bits = ROAD_Y; |  | ||||||
| 			} else { |  | ||||||
| 				if (track != TRACK_Y) return CMD_ERROR; |  | ||||||
| 				bits = ROAD_X; |  | ||||||
| 			} |  | ||||||
|  |  | ||||||
| 			if (!(flags & DC_EXEC)) | 			if (!(flags & DC_EXEC)) | ||||||
| 				return _price.remove_rail; | 				return _price.remove_rail; | ||||||
|  |  | ||||||
| 			MakeRoadNormal(tile, _m[tile].m3, bits, 0); | 			MakeRoadNormal(tile, _m[tile].m3, GetCrossingRoadBits(tile), 0); | ||||||
| 			break; | 			break; | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										11
									
								
								road.h
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								road.h
									
									
									
									
									
								
							| @@ -17,6 +17,11 @@ typedef enum RoadBits { | |||||||
| 	ROAD_ALL = ROAD_X  | ROAD_Y | 	ROAD_ALL = ROAD_X  | ROAD_Y | ||||||
| } RoadBits; | } RoadBits; | ||||||
|  |  | ||||||
|  | static inline RoadBits ComplementRoadBits(RoadBits r) | ||||||
|  | { | ||||||
|  | 	return ROAD_ALL ^ r; | ||||||
|  | } | ||||||
|  |  | ||||||
| static inline RoadBits GetRoadBits(TileIndex tile) | static inline RoadBits GetRoadBits(TileIndex tile) | ||||||
| { | { | ||||||
| 	return GB(_m[tile].m5, 0, 4); | 	return GB(_m[tile].m5, 0, 4); | ||||||
| @@ -27,6 +32,12 @@ static inline RoadBits GetCrossingRoadBits(TileIndex tile) | |||||||
| 	return _m[tile].m5 & 8 ? ROAD_Y : ROAD_X; | 	return _m[tile].m5 & 8 ? ROAD_Y : ROAD_X; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | static inline TrackBits GetCrossingRailBits(TileIndex tile) | ||||||
|  | { | ||||||
|  | 	return _m[tile].m5 & 8 ? TRACK_BIT_X : TRACK_BIT_Y; | ||||||
|  | } | ||||||
|  |  | ||||||
|  |  | ||||||
| typedef enum RoadType { | typedef enum RoadType { | ||||||
| 	ROAD_NORMAL, | 	ROAD_NORMAL, | ||||||
| 	ROAD_CROSSING, | 	ROAD_CROSSING, | ||||||
|   | |||||||
							
								
								
									
										14
									
								
								road_cmd.c
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								road_cmd.c
									
									
									
									
									
								
							| @@ -235,21 +235,15 @@ int32 CmdRemoveRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2) | |||||||
| 				} | 				} | ||||||
|  |  | ||||||
| 				case ROAD_CROSSING: { | 				case ROAD_CROSSING: { | ||||||
| 					TrackBits track; | 					if (pieces & ComplementRoadBits(GetCrossingRoadBits(tile))) { | ||||||
|  | 						goto return_error; | ||||||
| 					if (!(ti.map5 & 8)) { |  | ||||||
| 						if (pieces & ROAD_Y) goto return_error; |  | ||||||
| 						track = TRACK_BIT_Y; |  | ||||||
| 					} else { |  | ||||||
| 						if (pieces & ROAD_X) goto return_error; |  | ||||||
| 						track = TRACK_BIT_X; |  | ||||||
| 					} | 					} | ||||||
|  |  | ||||||
| 					cost = _price.remove_road * 2; | 					cost = _price.remove_road * 2; | ||||||
| 					if (flags & DC_EXEC) { | 					if (flags & DC_EXEC) { | ||||||
| 						ChangeTownRating(t, -road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM); | 						ChangeTownRating(t, -road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM); | ||||||
|  |  | ||||||
| 						MakeRailNormal(tile, GetTileOwner(tile), track, GB(_m[tile].m4, 0, 4)); | 						MakeRailNormal(tile, GetTileOwner(tile), GetCrossingRailBits(tile), GB(_m[tile].m4, 0, 4)); | ||||||
| 						MarkTileDirtyByTile(tile); | 						MarkTileDirtyByTile(tile); | ||||||
| 					} | 					} | ||||||
| 					return cost; | 					return cost; | ||||||
| @@ -371,7 +365,7 @@ int32 CmdBuildRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2) | |||||||
| 					break; | 					break; | ||||||
|  |  | ||||||
| 				case ROAD_CROSSING: | 				case ROAD_CROSSING: | ||||||
| 					if (pieces != (ti.map5 & 8 ? ROAD_Y : ROAD_X)) { // XXX is this correct? | 					if (pieces != GetCrossingRoadBits(ti.tile)) { // XXX is this correct? | ||||||
| 						return_cmd_error(STR_1007_ALREADY_BUILT); | 						return_cmd_error(STR_1007_ALREADY_BUILT); | ||||||
| 					} | 					} | ||||||
| 					goto do_clear; | 					goto do_clear; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 tron
					tron