src/viewport.cpp
branchgamebalance
changeset 9912 1ac8aac92385
parent 9911 0b8b245a2391
child 9913 e79cd19772dd
--- a/src/viewport.cpp	Wed Jun 13 11:45:14 2007 +0000
+++ b/src/viewport.cpp	Wed Jun 13 12:05:56 2007 +0000
@@ -23,6 +23,7 @@
 #include "waypoint.h"
 #include "variables.h"
 #include "train.h"
+#include "roadveh.h"
 
 #define VIEWPORT_DRAW_MEM (65536 * 2)
 
@@ -183,6 +184,9 @@
 
 	WP(w, vp_d).scrollpos_x = pt.x;
 	WP(w, vp_d).scrollpos_y = pt.y;
+	WP(w, vp_d).dest_scrollpos_x = pt.x;
+	WP(w, vp_d).dest_scrollpos_y = pt.y;
+
 	w->viewport = vp;
 	vp->virtual_left = 0;//pt.x;
 	vp->virtual_top = 0;//pt.y;
@@ -855,9 +859,6 @@
 			}
 			break;
 
-		case ZOOM_LVL_OUT_16X:
-			break;
-
 		default: NOT_REACHED();
 	}
 }
@@ -928,9 +929,6 @@
 			}
 			break;
 
-		case ZOOM_LVL_OUT_16X:
-			break;
-
 		default: NOT_REACHED();
 	}
 }
@@ -1001,9 +999,6 @@
 			}
 			break;
 
-		case ZOOM_LVL_OUT_16X:
-			break;
-
 		default: NOT_REACHED();
 	}
 }
@@ -1074,9 +1069,6 @@
 			}
 			break;
 
-		case ZOOM_LVL_OUT_16X:
-			break;
-
 		default: NOT_REACHED();
 	}
 }
@@ -1386,6 +1378,25 @@
 		/* Center of the viewport is hot spot */
 		x = WP(w,vp_d).scrollpos_x + vp->virtual_width / 2;
 		y = WP(w,vp_d).scrollpos_y + vp->virtual_height / 2;
+
+		int dest_x = WP(w,vp_d).dest_scrollpos_x + vp->virtual_width / 2;
+		int dest_y = WP(w,vp_d).dest_scrollpos_y + vp->virtual_height / 2;
+
+		int delta_x = dest_x - x;
+		int delta_y = dest_y - y;
+
+		if (delta_x != 0 || delta_y != 0) {
+			if (_patches.smooth_scroll) {
+				int max_scroll = ScaleByMapSize1D(512);
+				/* Not at our desired positon yet... */
+				x += clamp(delta_x / 8, -max_scroll, max_scroll);
+				y += clamp(delta_y / 8, -max_scroll, max_scroll);
+			} else {
+				x = dest_x;
+				y = dest_y;
+			}
+		}
+
 		/* Convert viewport coordinates to map coordinates
 		 * Calculation is scaled by 4 to avoid rounding errors */
 		vx = -x + y * 2;
@@ -1559,9 +1570,6 @@
 			}
 			break;
 
-		case ZOOM_LVL_OUT_16X:
-			break;
-
 		default: NOT_REACHED();
 	}
 
@@ -1620,9 +1628,6 @@
 			}
 			break;
 
-		case ZOOM_LVL_OUT_16X:
-			break;
-
 		default: NOT_REACHED();
 	}
 
@@ -1681,9 +1686,6 @@
 			}
 			break;
 
-		case ZOOM_LVL_OUT_16X:
-			break;
-
 		default: NOT_REACHED();
 	}
 
@@ -1742,9 +1744,6 @@
 			}
 			break;
 
-		case ZOOM_LVL_OUT_16X:
-			break;
-
 		default: NOT_REACHED();
 	}
 
@@ -1766,12 +1765,18 @@
 	ShowTrainViewWindow(v);
 }
 
+static void SafeShowRoadVehViewWindow(const Vehicle *v)
+{
+	if (!IsRoadVehFront(v)) v = GetFirstVehicleInChain(v);
+	ShowRoadVehViewWindow(v);
+}
+
 static void Nop(const Vehicle *v) {}
 
 typedef void OnVehicleClickProc(const Vehicle *v);
 static OnVehicleClickProc* const _on_vehicle_click_proc[] = {
 	SafeShowTrainViewWindow,
-	ShowRoadVehViewWindow,
+	SafeShowRoadVehViewWindow,
 	ShowShipViewWindow,
 	ShowAircraftViewWindow,
 	Nop, // Special vehicles
@@ -1841,26 +1846,31 @@
 
 
 /* scrolls the viewport in a window to a given location */
-bool ScrollWindowTo(int x , int y, Window *w)
+bool ScrollWindowTo(int x , int y, Window *w, bool instant)
 {
 	Point pt;
 
 	pt = MapXYZToViewport(w->viewport, x, y, GetSlopeZ(x, y));
 	WP(w, vp_d).follow_vehicle = INVALID_VEHICLE;
 
-	if (WP(w, vp_d).scrollpos_x == pt.x && WP(w, vp_d).scrollpos_y == pt.y)
+	if (WP(w, vp_d).dest_scrollpos_x == pt.x && WP(w, vp_d).dest_scrollpos_y == pt.y)
 		return false;
 
-	WP(w, vp_d).scrollpos_x = pt.x;
-	WP(w, vp_d).scrollpos_y = pt.y;
+	if (instant) {
+		WP(w, vp_d).scrollpos_x = pt.x;
+		WP(w, vp_d).scrollpos_y = pt.y;
+	}
+
+	WP(w, vp_d).dest_scrollpos_x = pt.x;
+	WP(w, vp_d).dest_scrollpos_y = pt.y;
 	return true;
 }
 
 
-bool ScrollMainWindowTo(int x, int y)
+bool ScrollMainWindowTo(int x, int y, bool instant)
 {
 	Window *w;
-	bool res = ScrollWindowTo(x, y, FindWindowById(WC_MAIN_WINDOW, 0));
+	bool res = ScrollWindowTo(x, y, FindWindowById(WC_MAIN_WINDOW, 0), instant);
 
 	/* If a user scrolls to a tile (via what way what so ever) and already is on
 	 *  that tile (e.g.: pressed twice), move the smallmap to that location,
@@ -1877,9 +1887,9 @@
 }
 
 
-bool ScrollMainWindowToTile(TileIndex tile)
+bool ScrollMainWindowToTile(TileIndex tile, bool instant)
 {
-	return ScrollMainWindowTo(TileX(tile) * TILE_SIZE + TILE_SIZE / 2, TileY(tile) * TILE_SIZE + TILE_SIZE / 2);
+	return ScrollMainWindowTo(TileX(tile) * TILE_SIZE + TILE_SIZE / 2, TileY(tile) * TILE_SIZE + TILE_SIZE / 2, instant);
 }
 
 void SetRedErrorSquare(TileIndex tile)