* Continue criteria for the SearchMapEdge function.
* @param iter Value to check.
* @param iter_limit Maximum value for the iter
* @param sy Screen y coordinate calculated for the tile at hand
* @param sy_limit Limit to the screen y coordinate
* @return True when we should continue searching.
*/
typedef bool ContinueMapEdgeSearch(int iter, int iter_limit, int sy, int sy_limit);
/** Continue criteria for searching a no-longer-visible tile in negative direction, starting at some tile. */
static inline bool ContinueLowerMapEdgeSearch(int iter, int iter_limit, int sy, int sy_limit) { return iter > 0 && sy > sy_limit; }
/** Continue criteria for searching a no-longer-visible tile in positive direction, starting at some tile. */
static inline bool ContinueUpperMapEdgeSearch(int iter, int iter_limit, int sy, int sy_limit) { return iter < iter_limit && sy < sy_limit; }
/**
* Searches, starting at the given tile, by applying the given offset to iter, for a no longer visible tile.
* The whole sense of this function is keeping the to-be-written code small, thus it is a little bit abstracted
* so the same function can be used for both the X and Y locations. As such a reference to one of the elements
* in curr_tile was needed.
* @param curr_tile A tile
* @param iter Reference to either the X or Y of curr_tile.
* @param iter_limit Upper search limit for the iter value.
* @param offset Search in steps of this size
* @param sy_limit Search limit to be passed to the criteria
* @param continue_criteria Search as long as this criteria is true
* @return The final value of iter.
* Ensure that a given viewport has a valid scroll position.
*
* There must be a visible piece of the map in the center of the viewport.
* If there isn't, the viewport will be scrolled to nearest such location.
*
* @param vp The viewport.
* @param[in,out] scroll_x Viewport X scroll.
* @param[in,out] scroll_y Viewport Y scroll.
*/
static int SearchMapEdge(Point &curr_tile, int &iter, int iter_limit, int offset, int sy_limit, ContinueMapEdgeSearch continue_criteria)
{
int sy;
do {
iter = Clamp(iter + offset, 0, iter_limit);
sy = GetViewportY(curr_tile);
} while (continue_criteria(iter, iter_limit, sy, sy_limit));
return iter;
}
/**
* Determine the clamping of either the X or Y coordinate to the map.
* @param curr_tile A tile
* @param iter Reference to either the X or Y of curr_tile.
* @param iter_limit Upper search limit for the iter value.
* @param start Start value for the iteration.
* @param other_ref Reference to the opposite axis in curr_tile than of iter.
* @param other_value Start value for of the opposite axis
* @param vp_value Value of the viewport location in the opposite axis as for iter.
* @param other_limit Limit for the other value, so if iter is X, then other_limit is for Y.
* @param vp_top Top of the viewport.
* @param vp_bottom Bottom of the viewport.
* @return Clamped version of vp_value.
*/
static inline int ClampXYToMap(Point &curr_tile, int &iter, int iter_limit, int start, int &other_ref, int other_value, int vp_value, int other_limit, int vp_top, int vp_bottom)
static inline void ClampViewportToMap(const ViewPort *vp, int *scroll_x, int *scroll_y)