src/viewport.cpp
branchgamebalance
changeset 9912 1ac8aac92385
parent 9911 0b8b245a2391
child 9913 e79cd19772dd
equal deleted inserted replaced
9911:0b8b245a2391 9912:1ac8aac92385
    21 #include "town.h"
    21 #include "town.h"
    22 #include "signs.h"
    22 #include "signs.h"
    23 #include "waypoint.h"
    23 #include "waypoint.h"
    24 #include "variables.h"
    24 #include "variables.h"
    25 #include "train.h"
    25 #include "train.h"
       
    26 #include "roadveh.h"
    26 
    27 
    27 #define VIEWPORT_DRAW_MEM (65536 * 2)
    28 #define VIEWPORT_DRAW_MEM (65536 * 2)
    28 
    29 
    29 ZoomLevel _saved_scrollpos_zoom;
    30 ZoomLevel _saved_scrollpos_zoom;
    30 
    31 
   181 		pt = MapXYZToViewport(vp, x, y, GetSlopeZ(x, y));
   182 		pt = MapXYZToViewport(vp, x, y, GetSlopeZ(x, y));
   182 	}
   183 	}
   183 
   184 
   184 	WP(w, vp_d).scrollpos_x = pt.x;
   185 	WP(w, vp_d).scrollpos_x = pt.x;
   185 	WP(w, vp_d).scrollpos_y = pt.y;
   186 	WP(w, vp_d).scrollpos_y = pt.y;
       
   187 	WP(w, vp_d).dest_scrollpos_x = pt.x;
       
   188 	WP(w, vp_d).dest_scrollpos_y = pt.y;
       
   189 
   186 	w->viewport = vp;
   190 	w->viewport = vp;
   187 	vp->virtual_left = 0;//pt.x;
   191 	vp->virtual_left = 0;//pt.x;
   188 	vp->virtual_top = 0;//pt.y;
   192 	vp->virtual_top = 0;//pt.y;
   189 }
   193 }
   190 
   194 
   853 					AddStringToDraw(t->sign.left + 1, t->sign.top - 3, STR_TOWN_LABEL_TINY_WHITE, t->index, 0);
   857 					AddStringToDraw(t->sign.left + 1, t->sign.top - 3, STR_TOWN_LABEL_TINY_WHITE, t->index, 0);
   854 				}
   858 				}
   855 			}
   859 			}
   856 			break;
   860 			break;
   857 
   861 
   858 		case ZOOM_LVL_OUT_16X:
       
   859 			break;
       
   860 
       
   861 		default: NOT_REACHED();
   862 		default: NOT_REACHED();
   862 	}
   863 	}
   863 }
   864 }
   864 
   865 
   865 
   866 
   926 					AddStation(st, STR_STATION_SIGN_TINY, st->sign.width_2 | 0x8000);
   927 					AddStation(st, STR_STATION_SIGN_TINY, st->sign.width_2 | 0x8000);
   927 				}
   928 				}
   928 			}
   929 			}
   929 			break;
   930 			break;
   930 
   931 
   931 		case ZOOM_LVL_OUT_16X:
       
   932 			break;
       
   933 
       
   934 		default: NOT_REACHED();
   932 		default: NOT_REACHED();
   935 	}
   933 	}
   936 }
   934 }
   937 
   935 
   938 
   936 
   999 					AddSign(si, STR_2002, si->sign.width_2 | 0x8000);
   997 					AddSign(si, STR_2002, si->sign.width_2 | 0x8000);
  1000 				}
   998 				}
  1001 			}
   999 			}
  1002 			break;
  1000 			break;
  1003 
  1001 
  1004 		case ZOOM_LVL_OUT_16X:
       
  1005 			break;
       
  1006 
       
  1007 		default: NOT_REACHED();
  1002 		default: NOT_REACHED();
  1008 	}
  1003 	}
  1009 }
  1004 }
  1010 
  1005 
  1011 
  1006 
  1070 						right  > wp->sign.left &&
  1065 						right  > wp->sign.left &&
  1071 						left   < wp->sign.left + ScaleByZoom(wp->sign.width_2, dpi->zoom)) {
  1066 						left   < wp->sign.left + ScaleByZoom(wp->sign.width_2, dpi->zoom)) {
  1072 					AddWaypoint(wp, STR_WAYPOINT_VIEWPORT_TINY, wp->sign.width_2 | 0x8000);
  1067 					AddWaypoint(wp, STR_WAYPOINT_VIEWPORT_TINY, wp->sign.width_2 | 0x8000);
  1073 				}
  1068 				}
  1074 			}
  1069 			}
  1075 			break;
       
  1076 
       
  1077 		case ZOOM_LVL_OUT_16X:
       
  1078 			break;
  1070 			break;
  1079 
  1071 
  1080 		default: NOT_REACHED();
  1072 		default: NOT_REACHED();
  1081 	}
  1073 	}
  1082 }
  1074 }
  1384 		int vy;
  1376 		int vy;
  1385 
  1377 
  1386 		/* Center of the viewport is hot spot */
  1378 		/* Center of the viewport is hot spot */
  1387 		x = WP(w,vp_d).scrollpos_x + vp->virtual_width / 2;
  1379 		x = WP(w,vp_d).scrollpos_x + vp->virtual_width / 2;
  1388 		y = WP(w,vp_d).scrollpos_y + vp->virtual_height / 2;
  1380 		y = WP(w,vp_d).scrollpos_y + vp->virtual_height / 2;
       
  1381 
       
  1382 		int dest_x = WP(w,vp_d).dest_scrollpos_x + vp->virtual_width / 2;
       
  1383 		int dest_y = WP(w,vp_d).dest_scrollpos_y + vp->virtual_height / 2;
       
  1384 
       
  1385 		int delta_x = dest_x - x;
       
  1386 		int delta_y = dest_y - y;
       
  1387 
       
  1388 		if (delta_x != 0 || delta_y != 0) {
       
  1389 			if (_patches.smooth_scroll) {
       
  1390 				int max_scroll = ScaleByMapSize1D(512);
       
  1391 				/* Not at our desired positon yet... */
       
  1392 				x += clamp(delta_x / 8, -max_scroll, max_scroll);
       
  1393 				y += clamp(delta_y / 8, -max_scroll, max_scroll);
       
  1394 			} else {
       
  1395 				x = dest_x;
       
  1396 				y = dest_y;
       
  1397 			}
       
  1398 		}
       
  1399 
  1389 		/* Convert viewport coordinates to map coordinates
  1400 		/* Convert viewport coordinates to map coordinates
  1390 		 * Calculation is scaled by 4 to avoid rounding errors */
  1401 		 * Calculation is scaled by 4 to avoid rounding errors */
  1391 		vx = -x + y * 2;
  1402 		vx = -x + y * 2;
  1392 		vy =  x + y * 2;
  1403 		vy =  x + y * 2;
  1393 		/* clamp to size of map */
  1404 		/* clamp to size of map */
  1557 					return true;
  1568 					return true;
  1558 				}
  1569 				}
  1559 			}
  1570 			}
  1560 			break;
  1571 			break;
  1561 
  1572 
  1562 		case ZOOM_LVL_OUT_16X:
       
  1563 			break;
       
  1564 
       
  1565 		default: NOT_REACHED();
  1573 		default: NOT_REACHED();
  1566 	}
  1574 	}
  1567 
  1575 
  1568 	return false;
  1576 	return false;
  1569 }
  1577 }
  1618 					return true;
  1626 					return true;
  1619 				}
  1627 				}
  1620 			}
  1628 			}
  1621 			break;
  1629 			break;
  1622 
  1630 
  1623 		case ZOOM_LVL_OUT_16X:
       
  1624 			break;
       
  1625 
       
  1626 		default: NOT_REACHED();
  1631 		default: NOT_REACHED();
  1627 	}
  1632 	}
  1628 
  1633 
  1629 	return false;
  1634 	return false;
  1630 }
  1635 }
  1679 					return true;
  1684 					return true;
  1680 				}
  1685 				}
  1681 			}
  1686 			}
  1682 			break;
  1687 			break;
  1683 
  1688 
  1684 		case ZOOM_LVL_OUT_16X:
       
  1685 			break;
       
  1686 
       
  1687 		default: NOT_REACHED();
  1689 		default: NOT_REACHED();
  1688 	}
  1690 	}
  1689 
  1691 
  1690 	return false;
  1692 	return false;
  1691 }
  1693 }
  1740 					return true;
  1742 					return true;
  1741 				}
  1743 				}
  1742 			}
  1744 			}
  1743 			break;
  1745 			break;
  1744 
  1746 
  1745 		case ZOOM_LVL_OUT_16X:
       
  1746 			break;
       
  1747 
       
  1748 		default: NOT_REACHED();
  1747 		default: NOT_REACHED();
  1749 	}
  1748 	}
  1750 
  1749 
  1751 	return false;
  1750 	return false;
  1752 }
  1751 }
  1762 
  1761 
  1763 static void SafeShowTrainViewWindow(const Vehicle* v)
  1762 static void SafeShowTrainViewWindow(const Vehicle* v)
  1764 {
  1763 {
  1765 	if (!IsFrontEngine(v)) v = GetFirstVehicleInChain(v);
  1764 	if (!IsFrontEngine(v)) v = GetFirstVehicleInChain(v);
  1766 	ShowTrainViewWindow(v);
  1765 	ShowTrainViewWindow(v);
       
  1766 }
       
  1767 
       
  1768 static void SafeShowRoadVehViewWindow(const Vehicle *v)
       
  1769 {
       
  1770 	if (!IsRoadVehFront(v)) v = GetFirstVehicleInChain(v);
       
  1771 	ShowRoadVehViewWindow(v);
  1767 }
  1772 }
  1768 
  1773 
  1769 static void Nop(const Vehicle *v) {}
  1774 static void Nop(const Vehicle *v) {}
  1770 
  1775 
  1771 typedef void OnVehicleClickProc(const Vehicle *v);
  1776 typedef void OnVehicleClickProc(const Vehicle *v);
  1772 static OnVehicleClickProc* const _on_vehicle_click_proc[] = {
  1777 static OnVehicleClickProc* const _on_vehicle_click_proc[] = {
  1773 	SafeShowTrainViewWindow,
  1778 	SafeShowTrainViewWindow,
  1774 	ShowRoadVehViewWindow,
  1779 	SafeShowRoadVehViewWindow,
  1775 	ShowShipViewWindow,
  1780 	ShowShipViewWindow,
  1776 	ShowAircraftViewWindow,
  1781 	ShowAircraftViewWindow,
  1777 	Nop, // Special vehicles
  1782 	Nop, // Special vehicles
  1778 	Nop  // Disaster vehicles
  1783 	Nop  // Disaster vehicles
  1779 };
  1784 };
  1839 	}
  1844 	}
  1840 }
  1845 }
  1841 
  1846 
  1842 
  1847 
  1843 /* scrolls the viewport in a window to a given location */
  1848 /* scrolls the viewport in a window to a given location */
  1844 bool ScrollWindowTo(int x , int y, Window *w)
  1849 bool ScrollWindowTo(int x , int y, Window *w, bool instant)
  1845 {
  1850 {
  1846 	Point pt;
  1851 	Point pt;
  1847 
  1852 
  1848 	pt = MapXYZToViewport(w->viewport, x, y, GetSlopeZ(x, y));
  1853 	pt = MapXYZToViewport(w->viewport, x, y, GetSlopeZ(x, y));
  1849 	WP(w, vp_d).follow_vehicle = INVALID_VEHICLE;
  1854 	WP(w, vp_d).follow_vehicle = INVALID_VEHICLE;
  1850 
  1855 
  1851 	if (WP(w, vp_d).scrollpos_x == pt.x && WP(w, vp_d).scrollpos_y == pt.y)
  1856 	if (WP(w, vp_d).dest_scrollpos_x == pt.x && WP(w, vp_d).dest_scrollpos_y == pt.y)
  1852 		return false;
  1857 		return false;
  1853 
  1858 
  1854 	WP(w, vp_d).scrollpos_x = pt.x;
  1859 	if (instant) {
  1855 	WP(w, vp_d).scrollpos_y = pt.y;
  1860 		WP(w, vp_d).scrollpos_x = pt.x;
       
  1861 		WP(w, vp_d).scrollpos_y = pt.y;
       
  1862 	}
       
  1863 
       
  1864 	WP(w, vp_d).dest_scrollpos_x = pt.x;
       
  1865 	WP(w, vp_d).dest_scrollpos_y = pt.y;
  1856 	return true;
  1866 	return true;
  1857 }
  1867 }
  1858 
  1868 
  1859 
  1869 
  1860 bool ScrollMainWindowTo(int x, int y)
  1870 bool ScrollMainWindowTo(int x, int y, bool instant)
  1861 {
  1871 {
  1862 	Window *w;
  1872 	Window *w;
  1863 	bool res = ScrollWindowTo(x, y, FindWindowById(WC_MAIN_WINDOW, 0));
  1873 	bool res = ScrollWindowTo(x, y, FindWindowById(WC_MAIN_WINDOW, 0), instant);
  1864 
  1874 
  1865 	/* If a user scrolls to a tile (via what way what so ever) and already is on
  1875 	/* If a user scrolls to a tile (via what way what so ever) and already is on
  1866 	 *  that tile (e.g.: pressed twice), move the smallmap to that location,
  1876 	 *  that tile (e.g.: pressed twice), move the smallmap to that location,
  1867 	 *  so you directly see where you are on the smallmap. */
  1877 	 *  so you directly see where you are on the smallmap. */
  1868 
  1878 
  1875 
  1885 
  1876 	return res;
  1886 	return res;
  1877 }
  1887 }
  1878 
  1888 
  1879 
  1889 
  1880 bool ScrollMainWindowToTile(TileIndex tile)
  1890 bool ScrollMainWindowToTile(TileIndex tile, bool instant)
  1881 {
  1891 {
  1882 	return ScrollMainWindowTo(TileX(tile) * TILE_SIZE + TILE_SIZE / 2, TileY(tile) * TILE_SIZE + TILE_SIZE / 2);
  1892 	return ScrollMainWindowTo(TileX(tile) * TILE_SIZE + TILE_SIZE / 2, TileY(tile) * TILE_SIZE + TILE_SIZE / 2, instant);
  1883 }
  1893 }
  1884 
  1894 
  1885 void SetRedErrorSquare(TileIndex tile)
  1895 void SetRedErrorSquare(TileIndex tile)
  1886 {
  1896 {
  1887 	TileIndex old;
  1897 	TileIndex old;