133 |
133 |
134 WP(w, vp_d).follow_vehicle = (VehicleID)(follow_flags & 0xFFFF); |
134 WP(w, vp_d).follow_vehicle = (VehicleID)(follow_flags & 0xFFFF); |
135 veh = GetVehicle(WP(w, vp_d).follow_vehicle); |
135 veh = GetVehicle(WP(w, vp_d).follow_vehicle); |
136 pt = MapXYZToViewport(vp, veh->x_pos, veh->y_pos, veh->z_pos); |
136 pt = MapXYZToViewport(vp, veh->x_pos, veh->y_pos, veh->z_pos); |
137 } else { |
137 } else { |
138 uint x = TileX(follow_flags) * 16; |
138 uint x = TileX(follow_flags) * TILE_SIZE; |
139 uint y = TileY(follow_flags) * 16; |
139 uint y = TileY(follow_flags) * TILE_SIZE; |
140 |
140 |
141 WP(w, vp_d).follow_vehicle = INVALID_VEHICLE; |
141 WP(w, vp_d).follow_vehicle = INVALID_VEHICLE; |
142 pt = MapXYZToViewport(vp, x, y, GetSlopeZ(x, y)); |
142 pt = MapXYZToViewport(vp, x, y, GetSlopeZ(x, y)); |
143 } |
143 } |
144 |
144 |
1347 // Convert viewport coordinates to map coordinates |
1347 // Convert viewport coordinates to map coordinates |
1348 // Calculation is scaled by 4 to avoid rounding errors |
1348 // Calculation is scaled by 4 to avoid rounding errors |
1349 vx = -x + y * 2; |
1349 vx = -x + y * 2; |
1350 vy = x + y * 2; |
1350 vy = x + y * 2; |
1351 // clamp to size of map |
1351 // clamp to size of map |
1352 vx = clamp(vx, 0 * 4, MapMaxX() * 16 * 4); |
1352 vx = clamp(vx, 0 * 4, MapMaxX() * TILE_SIZE * 4); |
1353 vy = clamp(vy, 0 * 4, MapMaxY() * 16 * 4); |
1353 vy = clamp(vy, 0 * 4, MapMaxY() * TILE_SIZE * 4); |
1354 // Convert map coordinates to viewport coordinates |
1354 // Convert map coordinates to viewport coordinates |
1355 x = (-vx + vy) / 2; |
1355 x = (-vx + vy) / 2; |
1356 y = ( vx + vy) / 4; |
1356 y = ( vx + vy) / 4; |
1357 // Set position |
1357 // Set position |
1358 WP(w, vp_d).scrollpos_x = x - vp->virtual_width / 2; |
1358 WP(w, vp_d).scrollpos_x = x - vp->virtual_width / 2; |
1418 } while (vp++,act>>=1); |
1418 } while (vp++,act>>=1); |
1419 } |
1419 } |
1420 |
1420 |
1421 void MarkTileDirtyByTile(TileIndex tile) |
1421 void MarkTileDirtyByTile(TileIndex tile) |
1422 { |
1422 { |
1423 Point pt = RemapCoords(TileX(tile) * 16, TileY(tile) * 16, GetTileZ(tile)); |
1423 Point pt = RemapCoords(TileX(tile) * TILE_SIZE, TileY(tile) * TILE_SIZE, GetTileZ(tile)); |
1424 MarkAllViewportsDirty( |
1424 MarkAllViewportsDirty( |
1425 pt.x - 31, |
1425 pt.x - 31, |
1426 pt.y - 122, |
1426 pt.y - 122, |
1427 pt.x - 31 + 67, |
1427 pt.x - 31 + 67, |
1428 pt.y - 122 + 154 |
1428 pt.y - 122 + 154 |
1432 void MarkTileDirty(int x, int y) |
1432 void MarkTileDirty(int x, int y) |
1433 { |
1433 { |
1434 uint z = 0; |
1434 uint z = 0; |
1435 Point pt; |
1435 Point pt; |
1436 |
1436 |
1437 if (IS_INT_INSIDE(x, 0, MapSizeX() * 16) && |
1437 if (IS_INT_INSIDE(x, 0, MapSizeX() * TILE_SIZE) && |
1438 IS_INT_INSIDE(y, 0, MapSizeY() * 16)) |
1438 IS_INT_INSIDE(y, 0, MapSizeY() * TILE_SIZE)) |
1439 z = GetTileZ(TileVirtXY(x, y)); |
1439 z = GetTileZ(TileVirtXY(x, y)); |
1440 pt = RemapCoords(x, y, z); |
1440 pt = RemapCoords(x, y, z); |
1441 |
1441 |
1442 MarkAllViewportsDirty( |
1442 MarkAllViewportsDirty( |
1443 pt.x - 31, |
1443 pt.x - 31, |
1817 } |
1817 } |
1818 } |
1818 } |
1819 |
1819 |
1820 void SetTileSelectSize(int w, int h) |
1820 void SetTileSelectSize(int w, int h) |
1821 { |
1821 { |
1822 _thd.new_size.x = w * 16; |
1822 _thd.new_size.x = w * TILE_SIZE; |
1823 _thd.new_size.y = h * 16; |
1823 _thd.new_size.y = h * TILE_SIZE; |
1824 _thd.new_outersize.x = 0; |
1824 _thd.new_outersize.x = 0; |
1825 _thd.new_outersize.y = 0; |
1825 _thd.new_outersize.y = 0; |
1826 } |
1826 } |
1827 |
1827 |
1828 void SetTileSelectBigSize(int ox, int oy, int sx, int sy) |
1828 void SetTileSelectBigSize(int ox, int oy, int sx, int sy) |
1829 { |
1829 { |
1830 _thd.offs.x = ox * 16; |
1830 _thd.offs.x = ox * TILE_SIZE; |
1831 _thd.offs.y = oy * 16; |
1831 _thd.offs.y = oy * TILE_SIZE; |
1832 _thd.new_outersize.x = sx * 16; |
1832 _thd.new_outersize.x = sx * TILE_SIZE; |
1833 _thd.new_outersize.y = sy * 16; |
1833 _thd.new_outersize.y = sy * TILE_SIZE; |
1834 } |
1834 } |
1835 |
1835 |
1836 /* returns the best autorail highlight type from map coordinates */ |
1836 /* returns the best autorail highlight type from map coordinates */ |
1837 static byte GetAutorailHT(int x, int y) |
1837 static byte GetAutorailHT(int x, int y) |
1838 { |
1838 { |
1858 |
1858 |
1859 if (x1 >= x2) intswap(x1,x2); |
1859 if (x1 >= x2) intswap(x1,x2); |
1860 if (y1 >= y2) intswap(y1,y2); |
1860 if (y1 >= y2) intswap(y1,y2); |
1861 _thd.new_pos.x = x1; |
1861 _thd.new_pos.x = x1; |
1862 _thd.new_pos.y = y1; |
1862 _thd.new_pos.y = y1; |
1863 _thd.new_size.x = x2 - x1 + 16; |
1863 _thd.new_size.x = x2 - x1 + TILE_SIZE; |
1864 _thd.new_size.y = y2 - y1 + 16; |
1864 _thd.new_size.y = y2 - y1 + TILE_SIZE; |
1865 _thd.new_drawstyle = _thd.next_drawstyle; |
1865 _thd.new_drawstyle = _thd.next_drawstyle; |
1866 } |
1866 } |
1867 } else if (_thd.place_mode != VHM_NONE) { |
1867 } else if (_thd.place_mode != VHM_NONE) { |
1868 Point pt = GetTileBelowCursor(); |
1868 Point pt = GetTileBelowCursor(); |
1869 x1 = pt.x; |
1869 x1 = pt.x; |
1906 |
1906 |
1907 // highlighting tiles while only going over them with the mouse |
1907 // highlighting tiles while only going over them with the mouse |
1908 void VpStartPlaceSizing(TileIndex tile, int user) |
1908 void VpStartPlaceSizing(TileIndex tile, int user) |
1909 { |
1909 { |
1910 _thd.userdata = user; |
1910 _thd.userdata = user; |
1911 _thd.selend.x = TileX(tile) * 16; |
1911 _thd.selend.x = TileX(tile) * TILE_SIZE; |
1912 _thd.selstart.x = TileX(tile) * 16; |
1912 _thd.selstart.x = TileX(tile) * TILE_SIZE; |
1913 _thd.selend.y = TileY(tile) * 16; |
1913 _thd.selend.y = TileY(tile) * TILE_SIZE; |
1914 _thd.selstart.y = TileY(tile) * 16; |
1914 _thd.selstart.y = TileY(tile) * TILE_SIZE; |
1915 if (_thd.place_mode == VHM_RECT) { |
1915 if (_thd.place_mode == VHM_RECT) { |
1916 _thd.place_mode = VHM_SPECIAL; |
1916 _thd.place_mode = VHM_SPECIAL; |
1917 _thd.next_drawstyle = HT_RECT; |
1917 _thd.next_drawstyle = HT_RECT; |
1918 } else if (_thd.place_mode == VHM_RAIL) { // autorail one piece |
1918 } else if (_thd.place_mode == VHM_RAIL) { // autorail one piece |
1919 _thd.place_mode = VHM_SPECIAL; |
1919 _thd.place_mode = VHM_SPECIAL; |
1930 _thd.sizelimit = limit; |
1930 _thd.sizelimit = limit; |
1931 } |
1931 } |
1932 |
1932 |
1933 void VpSetPresizeRange(uint from, uint to) |
1933 void VpSetPresizeRange(uint from, uint to) |
1934 { |
1934 { |
1935 _thd.selend.x = TileX(to) * 16; |
1935 _thd.selend.x = TileX(to) * TILE_SIZE; |
1936 _thd.selend.y = TileY(to) * 16; |
1936 _thd.selend.y = TileY(to) * TILE_SIZE; |
1937 _thd.selstart.x = TileX(from) * 16; |
1937 _thd.selstart.x = TileX(from) * TILE_SIZE; |
1938 _thd.selstart.y = TileY(from) * 16; |
1938 _thd.selstart.y = TileY(from) * TILE_SIZE; |
1939 _thd.next_drawstyle = HT_RECT; |
1939 _thd.next_drawstyle = HT_RECT; |
1940 } |
1940 } |
1941 |
1941 |
1942 static void VpStartPreSizing(void) |
1942 static void VpStartPreSizing(void) |
1943 { |
1943 { |