src/tunnelbridge_cmd.cpp
changeset 5838 9c3129cb019b
parent 5835 e0ff603ae0b7
child 5919 2b58160d667d
equal deleted inserted replaced
5837:96b4b92b86ae 5838:9c3129cb019b
   200 
   200 
   201 	if (p1 >= MapSize()) return CMD_ERROR;
   201 	if (p1 >= MapSize()) return CMD_ERROR;
   202 
   202 
   203 	// type of bridge
   203 	// type of bridge
   204 	if (HASBIT(p2, 15)) {
   204 	if (HASBIT(p2, 15)) {
   205 		railtype = 0;
   205 		railtype = RAILTYPE_BEGIN; // ??
   206 		transport = TRANSPORT_ROAD;
   206 		transport = TRANSPORT_ROAD;
   207 	} else {
   207 	} else {
   208 		if (!ValParamRailtype(GB(p2, 8, 8))) return CMD_ERROR;
   208 		if (!ValParamRailtype(GB(p2, 8, 8))) return CMD_ERROR;
   209 		railtype = GB(p2, 8, 8);
   209 		railtype = (RailType)GB(p2, 8, 8);
   210 		transport = TRANSPORT_RAIL;
   210 		transport = TRANSPORT_RAIL;
   211 	}
   211 	}
   212 
   212 
   213 	x = TileX(end_tile);
   213 	x = TileX(end_tile);
   214 	y = TileY(end_tile);
   214 	y = TileY(end_tile);
   467 	}
   467 	}
   468 	cost += _price.build_tunnel + ret;
   468 	cost += _price.build_tunnel + ret;
   469 
   469 
   470 	if (flags & DC_EXEC) {
   470 	if (flags & DC_EXEC) {
   471 		if (GB(p1, 9, 1) == TRANSPORT_RAIL) {
   471 		if (GB(p1, 9, 1) == TRANSPORT_RAIL) {
   472 			MakeRailTunnel(start_tile, _current_player, direction,                 GB(p1, 0, 4));
   472 			MakeRailTunnel(start_tile, _current_player, direction,                 (RailType)GB(p1, 0, 4));
   473 			MakeRailTunnel(end_tile,   _current_player, ReverseDiagDir(direction), GB(p1, 0, 4));
   473 			MakeRailTunnel(end_tile,   _current_player, ReverseDiagDir(direction), (RailType)GB(p1, 0, 4));
   474 			UpdateSignalsOnSegment(start_tile, direction);
   474 			UpdateSignalsOnSegment(start_tile, direction);
   475 			YapfNotifyTrackLayoutChange(start_tile, AxisToTrack(DiagDirToAxis(direction)));
   475 			YapfNotifyTrackLayoutChange(start_tile, AxisToTrack(DiagDirToAxis(direction)));
   476 		} else {
   476 		} else {
   477 			MakeRoadTunnel(start_tile, _current_player, direction);
   477 			MakeRoadTunnel(start_tile, _current_player, direction);
   478 			MakeRoadTunnel(end_tile,   _current_player, ReverseDiagDir(direction));
   478 			MakeRoadTunnel(end_tile,   _current_player, ReverseDiagDir(direction));
  1028 				if (IsSteepSlope(tileh)) {
  1028 				if (IsSteepSlope(tileh)) {
  1029 					z += TILE_HEIGHT;
  1029 					z += TILE_HEIGHT;
  1030 				} else if (f < 15) {
  1030 				} else if (f < 15) {
  1031 					return z + TILE_HEIGHT;
  1031 					return z + TILE_HEIGHT;
  1032 				}
  1032 				}
  1033 				tileh = _inclined_tileh[f - 15];
  1033 				tileh = (Slope)_inclined_tileh[f - 15];
  1034 			}
  1034 			}
  1035 		}
  1035 		}
  1036 	}
  1036 	}
  1037 
  1037 
  1038 	return z + GetPartialZ(x, y, tileh);
  1038 	return z + GetPartialZ(x, y, tileh);
  1048 		} else {
  1048 		} else {
  1049 			uint f = GetBridgeFoundation(tileh, DiagDirToAxis(GetBridgeRampDirection(tile)));
  1049 			uint f = GetBridgeFoundation(tileh, DiagDirToAxis(GetBridgeRampDirection(tile)));
  1050 
  1050 
  1051 			if (f == 0) return tileh;
  1051 			if (f == 0) return tileh;
  1052 			if (f < 15) return SLOPE_FLAT;
  1052 			if (f < 15) return SLOPE_FLAT;
  1053 			return _inclined_tileh[f - 15];
  1053 			return (Slope)_inclined_tileh[f - 15];
  1054 		}
  1054 		}
  1055 	}
  1055 	}
  1056 }
  1056 }
  1057 
  1057 
  1058 
  1058 
  1204 					}
  1204 					}
  1205 					return 0;
  1205 					return 0;
  1206 				}
  1206 				}
  1207 				if (fc == _tunnel_fractcoord_2[dir]) {
  1207 				if (fc == _tunnel_fractcoord_2[dir]) {
  1208 					v->tile = tile;
  1208 					v->tile = tile;
  1209 					v->u.rail.track = 0x40;
  1209 					v->u.rail.track = TRACK_BIT_WORMHOLE;
  1210 					v->vehstatus |= VS_HIDDEN;
  1210 					v->vehstatus |= VS_HIDDEN;
  1211 					return 4;
  1211 					return 4;
  1212 				}
  1212 				}
  1213 			}
  1213 			}
  1214 
  1214 
  1215 			if (dir == ReverseDiagDir(vdir) && fc == _tunnel_fractcoord_3[dir] && z == 0) {
  1215 			if (dir == ReverseDiagDir(vdir) && fc == _tunnel_fractcoord_3[dir] && z == 0) {
  1216 				/* We're at the tunnel exit ?? */
  1216 				/* We're at the tunnel exit ?? */
  1217 				v->tile = tile;
  1217 				v->tile = tile;
  1218 				v->u.rail.track = _exit_tunnel_track[dir];
  1218 				v->u.rail.track = (TrackBits)_exit_tunnel_track[dir];
  1219 				assert(v->u.rail.track);
  1219 				assert(v->u.rail.track);
  1220 				v->vehstatus &= ~VS_HIDDEN;
  1220 				v->vehstatus &= ~VS_HIDDEN;
  1221 				return 4;
  1221 				return 4;
  1222 			}
  1222 			}
  1223 		} else if (v->type == VEH_Road) {
  1223 		} else if (v->type == VEH_Road) {
  1270 				case DIAGDIR_SE: if ((y & 0xF) != TILE_SIZE - 1) return 0; break;
  1270 				case DIAGDIR_SE: if ((y & 0xF) != TILE_SIZE - 1) return 0; break;
  1271 				case DIAGDIR_SW: if ((x & 0xF) != TILE_SIZE - 1) return 0; break;
  1271 				case DIAGDIR_SW: if ((x & 0xF) != TILE_SIZE - 1) return 0; break;
  1272 				case DIAGDIR_NW: if ((y & 0xF) != 0)             return 0; break;
  1272 				case DIAGDIR_NW: if ((y & 0xF) != 0)             return 0; break;
  1273 			}
  1273 			}
  1274 			if (v->type == VEH_Train) {
  1274 			if (v->type == VEH_Train) {
  1275 				v->u.rail.track = 0x40;
  1275 				v->u.rail.track = TRACK_BIT_WORMHOLE;
  1276 				CLRBIT(v->u.rail.flags, VRF_GOINGUP);
  1276 				CLRBIT(v->u.rail.flags, VRF_GOINGUP);
  1277 				CLRBIT(v->u.rail.flags, VRF_GOINGDOWN);
  1277 				CLRBIT(v->u.rail.flags, VRF_GOINGDOWN);
  1278 			} else {
  1278 			} else {
  1279 				v->u.road.state = 0xFF;
  1279 				v->u.road.state = 0xFF;
  1280 			}
  1280 			}
  1281 			return 4;
  1281 			return 4;
  1282 		} else if (DirToDiagDir(v->direction) == ReverseDiagDir(dir)) {
  1282 		} else if (DirToDiagDir(v->direction) == ReverseDiagDir(dir)) {
  1283 			v->tile = tile;
  1283 			v->tile = tile;
  1284 			if (v->type == VEH_Train) {
  1284 			if (v->type == VEH_Train) {
  1285 				if (v->u.rail.track == 0x40) {
  1285 				if (v->u.rail.track == 0x40) {
  1286 					v->u.rail.track = (DiagDirToAxis(dir) == AXIS_X ? 1 : 2);
  1286 					v->u.rail.track = (DiagDirToAxis(dir) == AXIS_X ? TRACK_BIT_X : TRACK_BIT_Y);
  1287 					return 4;
  1287 					return 4;
  1288 				}
  1288 				}
  1289 			} else {
  1289 			} else {
  1290 				if (v->u.road.state == 0xFF) {
  1290 				if (v->u.road.state == 0xFF) {
  1291 					v->u.road.state = _road_exit_tunnel_state[dir];
  1291 					v->u.road.state = _road_exit_tunnel_state[dir];
  1297 		}
  1297 		}
  1298 	}
  1298 	}
  1299 	return 0;
  1299 	return 0;
  1300 }
  1300 }
  1301 
  1301 
  1302 const TileTypeProcs _tile_type_tunnelbridge_procs = {
  1302 extern const TileTypeProcs _tile_type_tunnelbridge_procs = {
  1303 	DrawTile_TunnelBridge,           /* draw_tile_proc */
  1303 	DrawTile_TunnelBridge,           /* draw_tile_proc */
  1304 	GetSlopeZ_TunnelBridge,          /* get_slope_z_proc */
  1304 	GetSlopeZ_TunnelBridge,          /* get_slope_z_proc */
  1305 	ClearTile_TunnelBridge,          /* clear_tile_proc */
  1305 	ClearTile_TunnelBridge,          /* clear_tile_proc */
  1306 	GetAcceptedCargo_TunnelBridge,   /* get_accepted_cargo_proc */
  1306 	GetAcceptedCargo_TunnelBridge,   /* get_accepted_cargo_proc */
  1307 	GetTileDesc_TunnelBridge,        /* get_tile_desc_proc */
  1307 	GetTileDesc_TunnelBridge,        /* get_tile_desc_proc */