roadveh_cmd.c
changeset 5573 afa6f92a71fd
parent 5568 75f13d7bfaed
child 5590 dc34c43fc3eb
--- a/roadveh_cmd.c	Wed Dec 27 12:22:25 2006 +0000
+++ b/roadveh_cmd.c	Wed Dec 27 12:38:02 2006 +0000
@@ -21,7 +21,9 @@
 #include "player.h"
 #include "sound.h"
 #include "depot.h"
+#include "bridge.h"
 #include "tunnel_map.h"
+#include "bridge_map.h"
 #include "vehicle_gui.h"
 #include "newgrf_callbacks.h"
 #include "newgrf_engine.h"
@@ -322,8 +324,6 @@
 {
 	TileIndex tile = v->tile;
 
-	if (v->u.road.state == 255) tile = GetVehicleOutOfTunnelTile(v);
-
 	if (_patches.yapf.road_use_yapf) {
 		Depot* ret = YapfFindNearestRoadDepot(v);
 		return ret;
@@ -444,14 +444,19 @@
 
 	if (v->type != VEH_Road || !CheckOwnership(v->owner)) return CMD_ERROR;
 
-	if (v->vehstatus & (VS_HIDDEN | VS_STOPPED) ||
+	if (v->vehstatus & VS_STOPPED ||
 			v->u.road.crashed_ctr != 0 ||
 			v->breakdown_ctr != 0 ||
 			v->u.road.overtaking != 0 ||
+			v->u.road.state == 255 ||
+			IsRoadVehInDepot(v) ||
 			v->cur_speed < 5) {
 		return CMD_ERROR;
 	}
 
+	if (IsTunnelTile(v->tile) && DirToDiagDir(v->direction) == GetTunnelDirection(v->tile)) return CMD_ERROR;
+	if (IsBridgeTile(v->tile) && DirToDiagDir(v->direction) == GetBridgeRampDirection(v->tile)) return CMD_ERROR;
+
 	if (flags & DC_EXEC) v->u.road.reverse_ctr = 180;
 
 	return 0;
@@ -518,11 +523,9 @@
 	byte new_z, old_z;
 
 	// need this hint so it returns the right z coordinate on bridges.
-	_get_z_hint = v->z_pos;
 	v->x_pos = x;
 	v->y_pos = y;
 	new_z = GetSlopeZ(x, y);
-	_get_z_hint = 0;
 
 	old_z = v->z_pos;
 	v->z_pos = new_z;
@@ -872,6 +875,7 @@
 
 	// Clamp
 	spd = min(spd, v->max_speed);
+	if (v->u.road.state == 255) spd = min(spd, SetSpeedLimitOnBridge(v));
 
 	//updates statusbar only if speed have changed to save CPU time
 	if (spd != v->cur_speed) {
@@ -1339,8 +1343,7 @@
 			return;
 		}
 
-		if (IsTunnelTile(gp.new_tile) &&
-				VehicleEnterTile(v, gp.new_tile, gp.x, gp.y) & 4) {
+		if ((IsTunnelTile(gp.new_tile) || IsBridgeTile(gp.new_tile)) && VehicleEnterTile(v, gp.new_tile, gp.x, gp.y) & 4) {
 			//new_dir = RoadGetNewDirection(v, gp.x, gp.y)
 			v->cur_image = GetRoadVehImage(v, v->direction);
 			UpdateRoadVehDeltaXY(v);
@@ -1351,6 +1354,7 @@
 		v->x_pos = gp.x;
 		v->y_pos = gp.y;
 		VehiclePositionChanged(v);
+		if (!(v->vehstatus & VS_HIDDEN)) EndVehicleMove(v);
 		return;
 	}