src/viewport.cpp
changeset 7764 e594296e90f6
parent 7726 a9c8beebf2c1
child 7769 f072d6bb8b99
equal deleted inserted replaced
7763:342e5357b592 7764:e594296e90f6
   360 	 * GetTileZoomCenterWindow() function can call here with invalid x and/or y,
   360 	 * GetTileZoomCenterWindow() function can call here with invalid x and/or y,
   361 	 * when the user tries to zoom out along the sides of the map */
   361 	 * when the user tries to zoom out along the sides of the map */
   362 	a = clamp(a, 0, (int)(MapMaxX() * TILE_SIZE) - 1);
   362 	a = clamp(a, 0, (int)(MapMaxX() * TILE_SIZE) - 1);
   363 	b = clamp(b, 0, (int)(MapMaxY() * TILE_SIZE) - 1);
   363 	b = clamp(b, 0, (int)(MapMaxY() * TILE_SIZE) - 1);
   364 
   364 
   365 	z = GetSlopeZ(a,     b    ) / 2;
   365 	/* (a, b) is the X/Y-world coordinate that belongs to (x,y) if the landscape would be completely flat on height 0.
   366 	z = GetSlopeZ(a + z, b + z) / 2;
   366 	 * Now find the Z-world coordinate by fix point iteration.
   367 	z = GetSlopeZ(a + z, b + z) / 2;
   367 	 * This is a bit tricky because the tile height is non-continuous at foundations.
   368 	z = GetSlopeZ(a + z, b + z) / 2;
   368 	 * The clicked point should be approached from the back, otherwise there are regions that are not clickable.
   369 	z = GetSlopeZ(a + z, b + z) / 2;
   369 	 * (FOUNDATION_HALFTILE_LOWER on SLOPE_STEEP_S hides north halftile completely)
       
   370 	 * So give it a z-malus of 4 in the first iterations.
       
   371 	 */
       
   372 	z = 0;
       
   373 	for (int i = 0; i < 5; i++) z = GetSlopeZ(a + max(z, 4u) - 4, b + max(z, 4u) - 4) / 2;
       
   374 	for (uint malus = 3; malus > 0; malus--) z = GetSlopeZ(a + max(z, malus) - malus, b + max(z, malus) - malus) / 2;
       
   375 	for (int i = 0; i < 5; i++) z = GetSlopeZ(a + z, b + z) / 2;
   370 
   376 
   371 	pt.x = a + z;
   377 	pt.x = a + z;
   372 	pt.y = b + z;
   378 	pt.y = b + z;
   373 
   379 
   374 	return pt;
   380 	return pt;