src/viewport.cpp
branchnoai
changeset 9724 b39bc69bb2f2
parent 9723 eee46cb39750
child 9732 f8eb3e208514
--- a/src/viewport.cpp	Wed Jan 09 18:11:12 2008 +0000
+++ b/src/viewport.cpp	Sun Feb 03 20:17:54 2008 +0000
@@ -8,8 +8,6 @@
 #include "tile_cmd.h"
 #include "gui.h"
 #include "spritecache.h"
-#include "table/sprites.h"
-#include "table/strings.h"
 #include "landscape.h"
 #include "viewport_func.h"
 #include "station.h"
@@ -25,6 +23,11 @@
 #include "strings_func.h"
 #include "zoom_func.h"
 #include "vehicle_func.h"
+#include "player_func.h"
+#include "settings_type.h"
+
+#include "table/sprites.h"
+#include "table/strings.h"
 
 #define VIEWPORT_DRAW_MEM (65536 * 2)
 
@@ -906,7 +909,7 @@
 	int offset;
 
 	FoundationPart foundation_part = FOUNDATION_PART_NORMAL;
-	Slope autorail_tileh = (Slope)(ti->tileh & ~SLOPE_HALFTILE_MASK);
+	Slope autorail_tileh = RemoveHalftileSlope(ti->tileh);
 	if (IsHalftileSlope(ti->tileh)) {
 		static const uint _lower_rail[4] = { 5U, 2U, 4U, 3U };
 		Corner halftile_corner = GetHalftileSlopeCorner(ti->tileh);
@@ -955,7 +958,7 @@
 			FoundationPart foundation_part = FOUNDATION_PART_NORMAL;
 			if (ti->tileh & SLOPE_N) {
 				z += TILE_HEIGHT;
-				if ((ti->tileh & ~SLOPE_HALFTILE_MASK) == SLOPE_STEEP_N) z += TILE_HEIGHT;
+				if (RemoveHalftileSlope(ti->tileh) == SLOPE_STEEP_N) z += TILE_HEIGHT;
 			}
 			if (IsHalftileSlope(ti->tileh)) {
 				Corner halftile_corner = GetHalftileSlopeCorner(ti->tileh);
@@ -2156,9 +2159,8 @@
 /* scrolls the viewport in a window to a given location */
 bool ScrollWindowTo(int x , int y, Window *w, bool instant)
 {
-	Point pt;
-
-	pt = MapXYZToViewport(w->viewport, x, y, GetSlopeZ(x, y));
+	/* The slope cannot be acquired outside of the map, so make sure we are always within the map. */
+	Point pt = MapXYZToViewport(w->viewport, x, y, GetSlopeZ(Clamp(x, 0, MapSizeX()), Clamp(y, 0, MapSizeY())));
 	WP(w, vp_d).follow_vehicle = INVALID_VEHICLE;
 
 	if (WP(w, vp_d).dest_scrollpos_x == pt.x && WP(w, vp_d).dest_scrollpos_y == pt.y)