Changeset - r7922:d7c3cc15726d
[Not reviewed]
src/aircraft_cmd.cpp
Show inline comments
 
@@ -833,12 +833,12 @@ static void SetAircraftPosition(Vehicle 
 

	
 
	Vehicle *u = v->Next();
 

	
 
	int safe_x = clamp(x, 0, MapMaxX() * TILE_SIZE);
 
	int safe_y = clamp(y - 1, 0, MapMaxY() * TILE_SIZE);
 
	int safe_x = Clamp(x, 0, MapMaxX() * TILE_SIZE);
 
	int safe_y = Clamp(y - 1, 0, MapMaxY() * TILE_SIZE);
 
	u->x_pos = x;
 
	u->y_pos = y - ((v->z_pos-GetSlopeZ(safe_x, safe_y)) >> 3);;
 

	
 
	safe_y = clamp(u->y_pos, 0, MapMaxY() * TILE_SIZE);
 
	safe_y = Clamp(u->y_pos, 0, MapMaxY() * TILE_SIZE);
 
	u->z_pos = GetSlopeZ(safe_x, safe_y);
 
	u->cur_image = v->cur_image;
 

	
src/depot.h
Show inline comments
 
@@ -51,7 +51,7 @@ void ShowDepotWindow(TileIndex tile, Veh
 
 */
 
static inline Date GetServiceIntervalClamped(uint index)
 
{
 
	return (_patches.servint_ispercent) ? clamp(index, MIN_SERVINT_PERCENT, MAX_SERVINT_PERCENT) : clamp(index, MIN_SERVINT_DAYS, MAX_SERVINT_DAYS);
 
	return (_patches.servint_ispercent) ? Clamp(index, MIN_SERVINT_PERCENT, MAX_SERVINT_PERCENT) : Clamp(index, MIN_SERVINT_DAYS, MAX_SERVINT_DAYS);
 
}
 

	
 
/**
src/disaster_cmd.cpp
Show inline comments
 
@@ -159,13 +159,13 @@ static void SetDisasterVehiclePos(Vehicl
 
	EndVehicleMove(v);
 

	
 
	if ((u = v->Next()) != NULL) {
 
		int safe_x = clamp(x, 0, MapMaxX() * TILE_SIZE);
 
		int safe_y = clamp(y - 1, 0, MapMaxY() * TILE_SIZE);
 
		int safe_x = Clamp(x, 0, MapMaxX() * TILE_SIZE);
 
		int safe_y = Clamp(y - 1, 0, MapMaxY() * TILE_SIZE);
 
		BeginVehicleMove(u);
 

	
 
		u->x_pos = x;
 
		u->y_pos = y - 1 - (max(z - GetSlopeZ(safe_x, safe_y), 0U) >> 3);
 
		safe_y = clamp(u->y_pos, 0, MapMaxY() * TILE_SIZE);
 
		safe_y = Clamp(u->y_pos, 0, MapMaxY() * TILE_SIZE);
 
		u->z_pos = GetSlopeZ(safe_x, safe_y);
 
		u->direction = v->direction;
 

	
src/economy.cpp
Show inline comments
 
@@ -212,7 +212,7 @@ int UpdateCompanyRatingAndValue(Player *
 
			/* Skip the total */
 
			if (i == SCORE_TOTAL) continue;
 
			/*  Check the score */
 
			s = clamp(_score_part[owner][i], 0, _score_info[i].needed) * _score_info[i].score / _score_info[i].needed;
 
			s = Clamp(_score_part[owner][i], 0, _score_info[i].needed) * _score_info[i].score / _score_info[i].needed;
 
			score += s;
 
			total_score += _score_info[i].score;
 
		}
src/genworld_gui.cpp
Show inline comments
 
@@ -387,7 +387,7 @@ static void GenerateLandscapeWndProc(Win
 
				HandleButtonClick(w, e->we.click.widget);
 
				SetWindowDirty(w);
 

	
 
				_patches_newgame.starting_year = clamp(_patches_newgame.starting_year + e->we.click.widget - GLAND_START_DATE_TEXT, MIN_YEAR, MAX_YEAR);
 
				_patches_newgame.starting_year = Clamp(_patches_newgame.starting_year + e->we.click.widget - GLAND_START_DATE_TEXT, MIN_YEAR, MAX_YEAR);
 
			}
 
			_left_button_clicked = false;
 
			break;
 
@@ -402,7 +402,7 @@ static void GenerateLandscapeWndProc(Win
 
				HandleButtonClick(w, e->we.click.widget);
 
				SetWindowDirty(w);
 

	
 
				_patches_newgame.snow_line_height = clamp(_patches_newgame.snow_line_height + e->we.click.widget - GLAND_SNOW_LEVEL_TEXT, 2, MAX_SNOWLINE_HEIGHT);
 
				_patches_newgame.snow_line_height = Clamp(_patches_newgame.snow_line_height + e->we.click.widget - GLAND_SNOW_LEVEL_TEXT, 2, MAX_SNOWLINE_HEIGHT);
 
			}
 
			_left_button_clicked = false;
 
			break;
 
@@ -494,11 +494,11 @@ static void GenerateLandscapeWndProc(Win
 
			switch (WP(w, generate_d).widget_id) {
 
			case GLAND_START_DATE_TEXT:
 
				InvalidateWidget(w, GLAND_START_DATE_TEXT);
 
				_patches_newgame.starting_year = clamp(value, MIN_YEAR, MAX_YEAR);
 
				_patches_newgame.starting_year = Clamp(value, MIN_YEAR, MAX_YEAR);
 
				break;
 
			case GLAND_SNOW_LEVEL_TEXT:
 
				InvalidateWidget(w, GLAND_SNOW_LEVEL_TEXT);
 
				_patches_newgame.snow_line_height = clamp(value, 2, MAX_SNOWLINE_HEIGHT);
 
				_patches_newgame.snow_line_height = Clamp(value, 2, MAX_SNOWLINE_HEIGHT);
 
				break;
 
			}
 

	
 
@@ -657,7 +657,7 @@ static void CreateScenarioWndProc(Window
 
				HandleButtonClick(w, e->we.click.widget);
 
				SetWindowDirty(w);
 

	
 
				_patches_newgame.starting_year = clamp(_patches_newgame.starting_year + e->we.click.widget - CSCEN_START_DATE_TEXT, MIN_YEAR, MAX_YEAR);
 
				_patches_newgame.starting_year = Clamp(_patches_newgame.starting_year + e->we.click.widget - CSCEN_START_DATE_TEXT, MIN_YEAR, MAX_YEAR);
 
			}
 
			_left_button_clicked = false;
 
			break;
 
@@ -672,7 +672,7 @@ static void CreateScenarioWndProc(Window
 
				HandleButtonClick(w, e->we.click.widget);
 
				SetWindowDirty(w);
 

	
 
				_patches_newgame.se_flat_world_height = clamp(_patches_newgame.se_flat_world_height + e->we.click.widget - CSCEN_FLAT_LAND_HEIGHT_TEXT, 0, MAX_TILE_HEIGHT);
 
				_patches_newgame.se_flat_world_height = Clamp(_patches_newgame.se_flat_world_height + e->we.click.widget - CSCEN_FLAT_LAND_HEIGHT_TEXT, 0, MAX_TILE_HEIGHT);
 
			}
 
			_left_button_clicked = false;
 
			break;
 
@@ -699,11 +699,11 @@ static void CreateScenarioWndProc(Window
 
			switch (WP(w, generate_d).widget_id) {
 
			case CSCEN_START_DATE_TEXT:
 
				InvalidateWidget(w, CSCEN_START_DATE_TEXT);
 
				_patches_newgame.starting_year = clamp(value, MIN_YEAR, MAX_YEAR);
 
				_patches_newgame.starting_year = Clamp(value, MIN_YEAR, MAX_YEAR);
 
				break;
 
			case CSCEN_FLAT_LAND_HEIGHT_TEXT:
 
				InvalidateWidget(w, CSCEN_FLAT_LAND_HEIGHT_TEXT);
 
				_patches_newgame.se_flat_world_height = clamp(value, 0, MAX_TILE_HEIGHT);
 
				_patches_newgame.se_flat_world_height = Clamp(value, 0, MAX_TILE_HEIGHT);
 
				break;
 
			}
 

	
src/graph_gui.cpp
Show inline comments
 
@@ -1006,7 +1006,7 @@ static void PerformanceRatingDetailWndPr
 
				DrawStringRightAligned(107, y, SET_PERFORMANCE_DETAIL_INT, TC_FROMSTRING);
 

	
 
				/* Calculate the %-bar */
 
				x = clamp(val, 0, needed) * 50 / needed;
 
				x = Clamp(val, 0, needed) * 50 / needed;
 

	
 
				/* SCORE_LOAN is inversed */
 
				if (val < 0 && i == SCORE_LOAN) x = 0;
 
@@ -1016,7 +1016,7 @@ static void PerformanceRatingDetailWndPr
 
				if (x != 50) GfxFillRect(112 + x, y - 2, 112 + 50, y + 10, color_notdone);
 

	
 
				/* Calculate the % */
 
				x = clamp(val, 0, needed) * 100 / needed;
 
				x = Clamp(val, 0, needed) * 100 / needed;
 

	
 
				/* SCORE_LOAN is inversed */
 
				if (val < 0 && i == SCORE_LOAN) x = 0;
src/industry_cmd.cpp
Show inline comments
 
@@ -1628,7 +1628,7 @@ CommandCost CmdBuildIndustry(TileIndex t
 
	} else {
 
		int count = indspec->num_table;
 
		const IndustryTileTable * const *itt = indspec->table;
 
		int num = clamp(p2, 0, count - 1);
 
		int num = Clamp(p2, 0, count - 1);
 

	
 
		_error_message = STR_0239_SITE_UNSUITABLE;
 
		do {
 
@@ -2047,7 +2047,7 @@ static void ChangeIndustryProduction(Ind
 
					new_prod += max(((RandomRange(50) + 10) * old_prod) >> 8, 1U);
 
				}
 

	
 
				new_prod = clamp(new_prod, 1, 255);
 
				new_prod = Clamp(new_prod, 1, 255);
 
				/* Do not stop closing the industry when it has the lowest possible production rate */
 
				if (new_prod == old_prod && old_prod > 1) {
 
					closeit = false;
src/industry_gui.cpp
Show inline comments
 
@@ -583,7 +583,7 @@ static void IndustryViewWndProc(Window *
 
			Industry* i = GetIndustry(w->window_number);
 
			int line = WP(w, indview_d).editbox_line;
 

	
 
			i->production_rate[line] = clampu(atoi(e->we.edittext.str), 0, 255);
 
			i->production_rate[line] = ClampU(atoi(e->we.edittext.str), 0, 255);
 
			UpdateIndustryProduction(i);
 
			SetWindowDirty(w);
 
		}
src/macros.h
Show inline comments
 
@@ -151,9 +151,9 @@ static inline uint minu(const uint a, co
 
 * @param min The minimum of the interval.
 
 * @param max the maximum of the interval.
 
 * @returns A value between min and max which is closest to a.
 
 * @see clampu(uint, uint, uint)
 
 * @see ClampU(uint, uint, uint)
 
 */
 
static inline int clamp(const int a, const int min, const int max)
 
static inline int Clamp(const int a, const int min, const int max)
 
{
 
	if (a <= min) return min;
 
	if (a >= max) return max;
 
@@ -174,9 +174,9 @@ static inline int clamp(const int a, con
 
 * @param min The minimum of the interval.
 
 * @param max the maximum of the interval.
 
 * @returns A value between min and max which is closest to a.
 
 * @see clamp(int, int, int)
 
 * @see Clamp(int, int, int)
 
 */
 
static inline uint clampu(const uint a, const uint min, const uint max)
 
static inline uint ClampU(const uint a, const uint min, const uint max)
 
{
 
	if (a <= min) return min;
 
	if (a >= max) return max;
 
@@ -195,7 +195,7 @@ static inline uint clampu(const uint a, 
 
 *
 
 * @param a The 64-bit value to clamps
 
 * @return The 64-bit value reduced to a 32-bit value
 
 * @see clamp(int, int, int)
 
 * @see Clamp(int, int, int)
 
 */
 
static inline int32 ClampToI32(const int64 a)
 
{
src/main_gui.cpp
Show inline comments
 
@@ -96,7 +96,7 @@ void HandleOnEditText(const char *str)
 
		const Player *p = GetPlayer(_current_player);
 
		Money money = min(p->player_money - p->current_loan, (Money)(atoi(str) / _currency->rate));
 

	
 
		uint32 money_c = clamp(ClampToI32(money), 0, 20000000); // Clamp between 20 million and 0
 
		uint32 money_c = Clamp(ClampToI32(money), 0, 20000000); // Clamp between 20 million and 0
 

	
 
		/* Give 'id' the money, and substract it from ourself */
 
		DoCommandP(0, money_c, id, CcGiveMoney, CMD_GIVE_MONEY | CMD_MSG(STR_INSUFFICIENT_FUNDS));
 
@@ -716,7 +716,7 @@ static Window *PopupMainToolbMenu(Window
 
	 * we clicked on and w->left the toolbar window itself. So meaning that
 
	 * the default position is aligned with the left side of the clicked button */
 
	width = max(GetStringListMaxWidth(base_string, item_count) + 6, 140);
 
	x = w->left + clamp(x, 0, w->width - width); // or alternatively '_screen.width - width'
 
	x = w->left + Clamp(x, 0, w->width - width); // or alternatively '_screen.width - width'
 

	
 
	w = AllocateWindow(x, 22, width, item_count * 10 + 2, MenuWndProc, WC_TOOLBAR_MENU, _menu_widgets);
 
	w->widget[0].bottom = item_count * 10 + 1;
 
@@ -995,7 +995,7 @@ static void ToolbarScenDateBackward(Wind
 
		HandleButtonClick(w, 6);
 
		SetWindowDirty(w);
 

	
 
		_patches_newgame.starting_year = clamp(_patches_newgame.starting_year - 1, MIN_YEAR, MAX_YEAR);
 
		_patches_newgame.starting_year = Clamp(_patches_newgame.starting_year - 1, MIN_YEAR, MAX_YEAR);
 
		SetDate(ConvertYMDToDate(_patches_newgame.starting_year, 0, 1));
 
	}
 
	_left_button_clicked = false;
 
@@ -1008,7 +1008,7 @@ static void ToolbarScenDateForward(Windo
 
		HandleButtonClick(w, 7);
 
		SetWindowDirty(w);
 

	
 
		_patches_newgame.starting_year = clamp(_patches_newgame.starting_year + 1, MIN_YEAR, MAX_YEAR);
 
		_patches_newgame.starting_year = Clamp(_patches_newgame.starting_year + 1, MIN_YEAR, MAX_YEAR);
 
		SetDate(ConvertYMDToDate(_patches_newgame.starting_year, 0, 1));
 
	}
 
	_left_button_clicked = false;
src/misc_gui.cpp
Show inline comments
 
@@ -609,8 +609,8 @@ void ShowErrorMessage(StringID msg_1, St
 
		if ( (x|y) != 0) {
 
			pt = RemapCoords2(x, y);
 
			vp = FindWindowById(WC_MAIN_WINDOW, 0)->viewport;
 
			pt.x = clamp(UnScaleByZoom(pt.x - vp->virtual_left, vp->zoom) + vp->left - (334/2), 0, _screen.width - 334);
 
			pt.y = clamp(UnScaleByZoom(pt.y - vp->virtual_top, vp->zoom) + vp->top - (137/2), 22, _screen.height - 137);
 
			pt.x = Clamp(UnScaleByZoom(pt.x - vp->virtual_left, vp->zoom) + vp->left - (334/2), 0, _screen.width - 334);
 
			pt.y = Clamp(UnScaleByZoom(pt.y - vp->virtual_top, vp->zoom) + vp->top - (137/2), 22, _screen.height - 137);
 
		} else {
 
			pt.x = (_screen.width - 334) >> 1;
 
			pt.y = (_screen.height - 137) >> 1;
 
@@ -746,9 +746,9 @@ void GuiShowTooltipsWithArgs(StringID st
 
	/* Correctly position the tooltip position, watch out for window and cursor size
 
	 * Clamp value to below main toolbar and above statusbar. If tooltip would
 
	 * go below window, flip it so it is shown above the cursor */
 
	y = clamp(_cursor.pos.y + _cursor.size.y + _cursor.offs.y + 5, 22, _screen.height - 12);
 
	y = Clamp(_cursor.pos.y + _cursor.size.y + _cursor.offs.y + 5, 22, _screen.height - 12);
 
	if (y + br.height > _screen.height - 12) y = _cursor.pos.y + _cursor.offs.y - br.height - 5;
 
	x = clamp(_cursor.pos.x - (br.width >> 1), 0, _screen.width - br.width);
 
	x = Clamp(_cursor.pos.x - (br.width >> 1), 0, _screen.width - br.width);
 

	
 
	w = AllocateWindow(x, y, br.width, br.height, TooltipsWndProc, WC_TOOLTIPS, _tooltips_widgets);
 

	
 
@@ -1938,7 +1938,7 @@ static void CheatsWndProc(Window *w, Win
 

	
 
				/* Increase or decrease the value and clamp it to extremes */
 
				value += (x >= 30) ? step : -step;
 
				value = clamp(value, ce->min, ce->max);
 
				value = Clamp(value, ce->min, ce->max);
 

	
 
				/* take whatever the function returns */
 
				value = ce->proc(value, (x >= 30) ? 1 : -1);
src/network/core/udp.cpp
Show inline comments
 
@@ -230,8 +230,8 @@ void NetworkUDPSocketHandler::Recv_Netwo
 
			}
 
		} /* Fallthrough */
 
		case 3:
 
			info->game_date      = clamp(p->Recv_uint32(), 0, MAX_DATE);
 
			info->start_date     = clamp(p->Recv_uint32(), 0, MAX_DATE);
 
			info->game_date      = Clamp(p->Recv_uint32(), 0, MAX_DATE);
 
			info->start_date     = Clamp(p->Recv_uint32(), 0, MAX_DATE);
 
			/* Fallthrough */
 
		case 2:
 
			info->companies_max  = p->Recv_uint8 ();
src/network/network_gui.cpp
Show inline comments
 
@@ -692,9 +692,9 @@ static void NetworkStartServerWindowWndP
 
				SetWindowDirty(w);
 
				switch (e->we.click.widget) {
 
					default: NOT_REACHED();
 
					case  9: case 11: _network_game_info.clients_max    = clamp(_network_game_info.clients_max    + e->we.click.widget - 10, 2, MAX_CLIENTS); break;
 
					case 12: case 14: _network_game_info.companies_max  = clamp(_network_game_info.companies_max  + e->we.click.widget - 13, 1, MAX_PLAYERS); break;
 
					case 15: case 17: _network_game_info.spectators_max = clamp(_network_game_info.spectators_max + e->we.click.widget - 16, 0, MAX_CLIENTS); break;
 
					case  9: case 11: _network_game_info.clients_max    = Clamp(_network_game_info.clients_max    + e->we.click.widget - 10, 2, MAX_CLIENTS); break;
 
					case 12: case 14: _network_game_info.companies_max  = Clamp(_network_game_info.companies_max  + e->we.click.widget - 13, 1, MAX_PLAYERS); break;
 
					case 15: case 17: _network_game_info.spectators_max = Clamp(_network_game_info.spectators_max + e->we.click.widget - 16, 0, MAX_CLIENTS); break;
 
				}
 
			}
 
			_left_button_clicked = false;
 
@@ -789,9 +789,9 @@ static void NetworkStartServerWindowWndP
 
			InvalidateWidget(w, nd->widget_id);
 
			switch (nd->widget_id) {
 
				default: NOT_REACHED();
 
				case 10: _network_game_info.clients_max    = clamp(value, 2, MAX_CLIENTS); break;
 
				case 13: _network_game_info.companies_max  = clamp(value, 1, MAX_PLAYERS); break;
 
				case 16: _network_game_info.spectators_max = clamp(value, 0, MAX_CLIENTS); break;
 
				case 10: _network_game_info.clients_max    = Clamp(value, 2, MAX_CLIENTS); break;
 
				case 13: _network_game_info.companies_max  = Clamp(value, 1, MAX_PLAYERS); break;
 
				case 16: _network_game_info.spectators_max = Clamp(value, 0, MAX_CLIENTS); break;
 
			}
 
		}
 

	
src/newgrf.cpp
Show inline comments
 
@@ -1193,7 +1193,7 @@ static bool BridgeChangeInfo(uint brid, 
 
				break;
 

	
 
			case 0x0F: // Long format year of availability (year since year 0)
 
				bridge->avail_year = clamp(grf_load_dword(&buf), MIN_YEAR, MAX_YEAR);
 
				bridge->avail_year = Clamp(grf_load_dword(&buf), MIN_YEAR, MAX_YEAR);
 
				break;
 

	
 
			default:
 
@@ -1370,7 +1370,7 @@ static bool TownHouseChangeInfo(uint hid
 
				break;
 

	
 
			case 0x1B: // Animation speed
 
				housespec->animation_speed = clamp(grf_load_byte(&buf), 2, 16);
 
				housespec->animation_speed = Clamp(grf_load_byte(&buf), 2, 16);
 
				break;
 

	
 
			case 0x1C: // Class of the building type
 
@@ -3409,7 +3409,7 @@ static uint32 GetParamVal(byte param, ui
 
{
 
	switch (param) {
 
		case 0x81: // current year
 
			return clamp(_cur_year, ORIGINAL_BASE_YEAR, ORIGINAL_MAX_YEAR) - ORIGINAL_BASE_YEAR;
 
			return Clamp(_cur_year, ORIGINAL_BASE_YEAR, ORIGINAL_MAX_YEAR) - ORIGINAL_BASE_YEAR;
 

	
 
		case 0x83: // current climate, 0=temp, 1=arctic, 2=trop, 3=toyland
 
			return _opt.landscape;
src/newgrf_engine.cpp
Show inline comments
 
@@ -496,7 +496,7 @@ static uint32 VehicleGetVariable(const R
 
			case 0x43: return _current_player | (LiveryHelper(object->u.vehicle.self_type, NULL) << 24); // Owner information
 
			case 0x46: return 0;               // Motion counter
 
			case 0x48: return GetEngine(object->u.vehicle.self_type)->flags; // Vehicle Type Info
 
			case 0xC4: return clamp(_cur_year, ORIGINAL_BASE_YEAR, ORIGINAL_MAX_YEAR) - ORIGINAL_BASE_YEAR; // Build year
 
			case 0xC4: return Clamp(_cur_year, ORIGINAL_BASE_YEAR, ORIGINAL_MAX_YEAR) - ORIGINAL_BASE_YEAR; // Build year
 
			case 0xDA: return INVALID_VEHICLE; // Next vehicle
 
			case 0x7F: return GetGRFParameter(object->u.vehicle.self_type, parameter); // Read GRF parameter
 
		}
 
@@ -711,7 +711,7 @@ static uint32 VehicleGetVariable(const R
 
		case 0x41: return GB(v->age, 8, 8);
 
		case 0x42: return v->max_age;
 
		case 0x43: return GB(v->max_age, 8, 8);
 
		case 0x44: return clamp(v->build_year, ORIGINAL_BASE_YEAR, ORIGINAL_MAX_YEAR) - ORIGINAL_BASE_YEAR;
 
		case 0x44: return Clamp(v->build_year, ORIGINAL_BASE_YEAR, ORIGINAL_MAX_YEAR) - ORIGINAL_BASE_YEAR;
 
		case 0x45: return v->unitnumber;
 
		case 0x46: return v->engine_type;
 
		case 0x47: return GB(v->engine_type, 8, 8);
src/newgrf_house.cpp
Show inline comments
 
@@ -211,7 +211,7 @@ static uint32 HouseGetVariable(const Res
 
		case 0x40: return (IsTileType(tile, MP_HOUSE) ? GetHouseBuildingStage(tile) : 0) | OriginalTileRandomiser(TileX(tile), TileY(tile)) << 2;
 

	
 
		/* Building age. */
 
		case 0x41: return clamp(_cur_year - GetHouseConstructionYear(tile), 0, 0xFF);
 
		case 0x41: return Clamp(_cur_year - GetHouseConstructionYear(tile), 0, 0xFF);
 

	
 
		/* Town zone */
 
		case 0x42: return GetTownRadiusGroup(town, tile);
 
@@ -369,7 +369,7 @@ void DrawNewHouseTile(TileInfo *ti, Hous
 
	} else {
 
		/* Limit the building stage to the number of stages supplied. */
 
		byte stage = GetHouseBuildingStage(ti->tile);
 
		stage = clamp(stage - 4 + group->g.layout.num_sprites, 0, group->g.layout.num_sprites - 1);
 
		stage = Clamp(stage - 4 + group->g.layout.num_sprites, 0, group->g.layout.num_sprites - 1);
 
		DrawTileLayout(ti, group, stage, house_id);
 
	}
 
}
 
@@ -382,7 +382,7 @@ void AnimateNewHouseTile(TileIndex tile)
 

	
 
	if (HASBIT(hs->callback_mask, CBM_HOUSE_ANIMATION_SPEED)) {
 
		uint16 callback_res = GetHouseCallback(CBID_HOUSE_ANIMATION_SPEED, 0, 0, GetHouseType(tile), GetTownByTile(tile), tile);
 
		if (callback_res != CALLBACK_FAILED) animation_speed = clamp(callback_res & 0xFF, 2, 16);
 
		if (callback_res != CALLBACK_FAILED) animation_speed = Clamp(callback_res & 0xFF, 2, 16);
 
	}
 

	
 
	/* An animation speed of 2 means the animation frame changes 4 ticks, and
src/newgrf_industries.cpp
Show inline comments
 
@@ -315,14 +315,14 @@ uint32 IndustryGetVariable(const Resolve
 
		case 0xA6: return industry->type;
 
		case 0xA7: return industry->founder;
 
		case 0xA8: return industry->random_color;
 
		case 0xA9: return clamp(0, industry->last_prod_year - 1920, 255);
 
		case 0xA9: return Clamp(0, industry->last_prod_year - 1920, 255);
 
		case 0xAA: return industry->counter;
 
		case 0xAB: return GB(industry->counter, 8, 8);
 
		case 0xAC: return industry->was_cargo_delivered;
 

	
 
		case 0xB0: return clamp(0, industry->construction_date - DAYS_TILL_ORIGINAL_BASE_YEAR, 65535); // Date when built since 1920 (in days)
 
		case 0xB0: return Clamp(0, industry->construction_date - DAYS_TILL_ORIGINAL_BASE_YEAR, 65535); // Date when built since 1920 (in days)
 
		case 0xB3: return industry->construction_type; // Construction type
 
		case 0xB4: return clamp(0, industry->last_cargo_accepted_at - DAYS_TILL_ORIGINAL_BASE_YEAR, 65535); // Date last cargo accepted since 1920 (in days)
 
		case 0xB4: return Clamp(0, industry->last_cargo_accepted_at - DAYS_TILL_ORIGINAL_BASE_YEAR, 65535); // Date last cargo accepted since 1920 (in days)
 
	}
 

	
 
	DEBUG(grf, 1, "Unhandled industry property 0x%X", variable);
 
@@ -515,10 +515,10 @@ void IndustryProductionCallback(Industry
 
		bool deref = (group->g.indprod.version == 1);
 

	
 
		for (uint i = 0; i < 3; i++) {
 
			ind->incoming_cargo_waiting[i] = clamp(ind->incoming_cargo_waiting[i] - DerefIndProd(group->g.indprod.substract_input[i], deref), 0, 0xFFFF);
 
			ind->incoming_cargo_waiting[i] = Clamp(ind->incoming_cargo_waiting[i] - DerefIndProd(group->g.indprod.substract_input[i], deref), 0, 0xFFFF);
 
		}
 
		for (uint i = 0; i < 2; i++) {
 
			ind->produced_cargo_waiting[i] = clamp(ind->produced_cargo_waiting[i] + DerefIndProd(group->g.indprod.add_output[i], deref), 0, 0xFFFF);
 
			ind->produced_cargo_waiting[i] = Clamp(ind->produced_cargo_waiting[i] + DerefIndProd(group->g.indprod.add_output[i], deref), 0, 0xFFFF);
 
		}
 

	
 
		int32 again = DerefIndProd(group->g.indprod.again, deref);
src/newgrf_industrytiles.cpp
Show inline comments
 
@@ -244,7 +244,7 @@ bool DrawNewIndustryTile(TileInfo *ti, I
 
	} else {
 
		/* Limit the building stage to the number of stages supplied. */
 
		byte stage = GetIndustryConstructionStage(ti->tile);
 
		stage = clamp(stage - 4 + group->g.layout.num_sprites, 0, group->g.layout.num_sprites - 1);
 
		stage = Clamp(stage - 4 + group->g.layout.num_sprites, 0, group->g.layout.num_sprites - 1);
 
		IndustryDrawTileLayout(ti, group, i->random_color, stage, gfx);
 
		return true;
 
	}
 
@@ -291,7 +291,7 @@ void AnimateNewIndustryTile(TileIndex ti
 

	
 
	if (HASBIT(itspec->callback_flags, CBM_INDT_ANIM_SPEED)) {
 
		uint16 callback_res = GetIndustryTileCallback(CBID_INDTILE_ANIMATION_SPEED, 0, 0, gfx, ind, tile);
 
		if (callback_res != CALLBACK_FAILED) animation_speed = clamp(callback_res & 0xFF, 0, 16);
 
		if (callback_res != CALLBACK_FAILED) animation_speed = Clamp(callback_res & 0xFF, 0, 16);
 
	}
 

	
 
	/* An animation speed of 2 means the animation frame changes 4 ticks, and
src/newgrf_spritegroup.cpp
Show inline comments
 
@@ -84,7 +84,7 @@ static inline uint32 GetVariable(const R
 
	/* Return common variables */
 
	switch (variable) {
 
		case 0x00: return max(_date - DAYS_TILL_ORIGINAL_BASE_YEAR, 0);
 
		case 0x01: return clamp(_cur_year, ORIGINAL_BASE_YEAR, ORIGINAL_MAX_YEAR) - ORIGINAL_BASE_YEAR;
 
		case 0x01: return Clamp(_cur_year, ORIGINAL_BASE_YEAR, ORIGINAL_MAX_YEAR) - ORIGINAL_BASE_YEAR;
 
		case 0x02: return _cur_month;
 
		case 0x03: return _opt.landscape;
 
		case 0x09: return _date_fract;
src/newgrf_station.cpp
Show inline comments
 
@@ -392,7 +392,7 @@ static uint32 StationGetVariable(const R
 
			case 0x42: return 0;               // Rail type (XXX Get current type from GUI?)
 
			case 0x43: return _current_player; // Station owner
 
			case 0x44: return 2;               // PBS status
 
			case 0xFA: return clamp(_date - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 65535); // Build date, clamped to a 16 bit value
 
			case 0xFA: return Clamp(_date - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 65535); // Build date, clamped to a 16 bit value
 
		}
 

	
 
		*available = false;
 
@@ -451,7 +451,7 @@ static uint32 StationGetVariable(const R
 
		case 0xF3: return st->bus_stops->status;
 
		case 0xF6: return st->airport_flags;
 
		case 0xF7: return GB(st->airport_flags, 8, 8);
 
		case 0xFA: return clamp(st->build_date - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 65535);
 
		case 0xFA: return Clamp(st->build_date - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 65535);
 
	}
 

	
 
	/* Handle cargo variables with parameter, 0x60 to 0x65 */
src/npf.cpp
Show inline comments
 
@@ -104,10 +104,10 @@ static TileIndex CalcClosestStationTile(
 

	
 
	/* we are going the aim for the x coordinate of the closest corner
 
	 * but if we are between those coordinates, we will aim for our own x coordinate */
 
	x = clamp(TileX(tile), minx, maxx);
 
	x = Clamp(TileX(tile), minx, maxx);
 

	
 
	/* same for y coordinate, see above comment */
 
	y = clamp(TileY(tile), miny, maxy);
 
	y = Clamp(TileY(tile), miny, maxy);
 

	
 
	/* return the tile of our target coordinates */
 
	return TileXY(x, y);
src/oldloader.cpp
Show inline comments
 
@@ -1635,7 +1635,7 @@ static bool LoadOldMain(LoadgameState *l
 
	AddTypeToEngines();
 

	
 
	/* We have a new difficulty setting */
 
	_opt.diff.town_council_tolerance = clamp(_opt.diff_level, 0, 2);
 
	_opt.diff.town_council_tolerance = Clamp(_opt.diff_level, 0, 2);
 

	
 
	DEBUG(oldloader, 3, "Finished converting game data");
 
	DEBUG(oldloader, 1, "TTD(Patch) savegame successfully converted");
src/openttd.cpp
Show inline comments
 
@@ -280,8 +280,8 @@ static void ParseResolution(int res[2], 
 
		return;
 
	}
 

	
 
	res[0] = clamp(strtoul(s, NULL, 0), 64, MAX_SCREEN_WIDTH);
 
	res[1] = clamp(strtoul(t + 1, NULL, 0), 64, MAX_SCREEN_HEIGHT);
 
	res[0] = Clamp(strtoul(s, NULL, 0), 64, MAX_SCREEN_WIDTH);
 
	res[1] = Clamp(strtoul(t + 1, NULL, 0), 64, MAX_SCREEN_HEIGHT);
 
}
 

	
 
static void InitializeDynamicVariables()
src/players.cpp
Show inline comments
 
@@ -95,7 +95,7 @@ PlayerFace ConvertFromOldPlayerFace(uint
 

	
 
	SetPlayerFaceBits(pf, PFV_GEN_ETHN,    ge, ge);
 
	SetPlayerFaceBits(pf, PFV_HAS_GLASSES, ge, GB(face, 28, 3) <= 1);
 
	SetPlayerFaceBits(pf, PFV_EYE_COLOUR,  ge, HASBIT(ge, ETHNICITY_BLACK) ? 0 : clampu(GB(face, 20, 3), 5, 7) - 5);
 
	SetPlayerFaceBits(pf, PFV_EYE_COLOUR,  ge, HASBIT(ge, ETHNICITY_BLACK) ? 0 : ClampU(GB(face, 20, 3), 5, 7) - 5);
 
	SetPlayerFaceBits(pf, PFV_CHIN,        ge, ScalePlayerFaceValue(PFV_CHIN,     ge, GB(face,  4, 2)));
 
	SetPlayerFaceBits(pf, PFV_EYEBROWS,    ge, ScalePlayerFaceValue(PFV_EYEBROWS, ge, GB(face,  6, 4)));
 
	SetPlayerFaceBits(pf, PFV_HAIR,        ge, ScalePlayerFaceValue(PFV_HAIR,     ge, GB(face, 16, 4)));
src/rail_gui.cpp
Show inline comments
 
@@ -1109,7 +1109,7 @@ static void ShowStationBuilder()
 

	
 
		w->vscroll.count = _railstation.station_count;
 
		w->vscroll.cap   = 5;
 
		w->vscroll.pos   = clamp(_railstation.station_type - 2, 0, w->vscroll.count - w->vscroll.cap);
 
		w->vscroll.pos   = Clamp(_railstation.station_type - 2, 0, w->vscroll.count - w->vscroll.cap);
 
	}
 
}
 

	
src/roadveh_cmd.cpp
Show inline comments
 
@@ -129,7 +129,7 @@ byte GetRoadVehLength(const Vehicle *v)
 

	
 
	uint16 veh_len = GetVehicleCallback(CBID_VEHICLE_LENGTH, 0, 0, v->engine_type, v);
 
	if (veh_len != CALLBACK_FAILED) {
 
		length -= clamp(veh_len, 0, 7);
 
		length -= Clamp(veh_len, 0, 7);
 
	}
 

	
 
	return length;
src/screenshot.cpp
Show inline comments
 
@@ -123,7 +123,7 @@ static bool MakeBmpImage(const char *nam
 
	if (pixelformat == 8) if (fwrite(rq, sizeof(rq), 1, f) != 1) return false;
 

	
 
	/* use by default 64k temp memory */
 
	maxlines = clamp(65536 / padw, 16, 128);
 
	maxlines = Clamp(65536 / padw, 16, 128);
 

	
 
	/* now generate the bitmap bits */
 
	void *buff = MallocT<uint8>(padw * maxlines * bpp); // by default generate 128 lines at a time.
 
@@ -251,7 +251,7 @@ static bool MakePNGImage(const char *nam
 
	}
 

	
 
	/* use by default 64k temp memory */
 
	maxlines = clamp(65536 / w, 16, 128);
 
	maxlines = Clamp(65536 / w, 16, 128);
 

	
 
	/* now generate the bitmap bits */
 
	void *buff = MallocT<uint8>(w * maxlines * bpp); // by default generate 128 lines at a time.
 
@@ -351,7 +351,7 @@ static bool MakePCXImage(const char *nam
 
	}
 

	
 
	/* use by default 64k temp memory */
 
	maxlines = clamp(65536 / w, 16, 128);
 
	maxlines = Clamp(65536 / w, 16, 128);
 

	
 
	/* now generate the bitmap bits */
 
	uint8 *buff = MallocT<uint8>(w * maxlines); // by default generate 128 lines at a time.
src/settings.cpp
Show inline comments
 
@@ -665,12 +665,12 @@ static void Write_ValidateSetting(void *
 
			case SLE_VAR_I32: {
 
				/* Override the minimum value. No value below sdb->min, except special value 0 */
 
				int32 min = ((sdb->flags & SGF_0ISDISABLED) && val <= sdb->min) ? 0 : sdb->min;
 
				val = clamp(val, min, sdb->max);
 
				val = Clamp(val, min, sdb->max);
 
			} break;
 
			case SLE_VAR_U32: {
 
				/* Override the minimum value. No value below sdb->min, except special value 0 */
 
				uint min = ((sdb->flags & SGF_0ISDISABLED) && (uint)val <= (uint)sdb->min) ? 0 : sdb->min;
 
				WriteValue(ptr, SLE_VAR_U32, (int64)clampu(val, min, sdb->max));
 
				WriteValue(ptr, SLE_VAR_U32, (int64)ClampU(val, min, sdb->max));
 
				return;
 
			}
 
			case SLE_VAR_I64:
src/settings_gui.cpp
Show inline comments
 
@@ -429,7 +429,7 @@ void CheckDifficultyLevels()
 
	} else {
 
		for (uint i = 0; i < GAME_DIFFICULTY_NUM; i++) {
 
			GDType *diff = ((GDType*)&_opt_newgame.diff) + i;
 
			*diff = clamp(*diff, _game_setting_info[i].min, _game_setting_info[i].max);
 
			*diff = Clamp(*diff, _game_setting_info[i].min, _game_setting_info[i].max);
 
			*diff -= *diff % _game_setting_info[i].step;
 
		}
 
	}
 
@@ -1149,7 +1149,7 @@ static void CustCurrencyWndProc(Window *
 
							WP(w,def_d).data_1 = 1 << (line * 2 + 0);
 
						} else {
 
							_custom_currency.to_euro =
 
								clamp(_custom_currency.to_euro + 1, 2000, MAX_YEAR);
 
								Clamp(_custom_currency.to_euro + 1, 2000, MAX_YEAR);
 
							WP(w,def_d).data_1 = 1 << (line * 2 + 1);
 
						}
 
					} else { // enter text
 
@@ -1176,7 +1176,7 @@ static void CustCurrencyWndProc(Window *
 

	
 
				switch (WP(w,def_d).data_2) {
 
					case 0: /* Exchange rate */
 
						_custom_currency.rate = clamp(atoi(b), 1, 5000);
 
						_custom_currency.rate = Clamp(atoi(b), 1, 5000);
 
						break;
 

	
 
					case 1: /* Thousands seperator */
src/sound.cpp
Show inline comments
 
@@ -148,7 +148,7 @@ static void StartSound(uint sound, int p
 
	if (mc == NULL) return;
 
	if (!SetBankSource(mc, sound)) return;
 

	
 
	panning = clamp(panning, -PANNING_LEVELS, PANNING_LEVELS);
 
	panning = Clamp(panning, -PANNING_LEVELS, PANNING_LEVELS);
 
	left_vol = (volume * PANNING_LEVELS) - (volume * panning);
 
	right_vol = (volume * PANNING_LEVELS) + (volume * panning);
 
	MxSetChannelVolume(mc, left_vol * 128 / PANNING_LEVELS, right_vol * 128 / PANNING_LEVELS);
src/station_cmd.cpp
Show inline comments
 
@@ -671,7 +671,7 @@ static void UpdateStationSignCoord(Stati
 
	if (r->IsEmpty()) return; /* no tiles belong to this station */
 

	
 
	/* clamp sign coord to be inside the station rect */
 
	st->xy = TileXY(clampu(TileX(st->xy), r->left, r->right), clampu(TileY(st->xy), r->top, r->bottom));
 
	st->xy = TileXY(ClampU(TileX(st->xy), r->left, r->right), ClampU(TileY(st->xy), r->top, r->bottom));
 
	UpdateStationVirtCoordDirty(st);
 
}
 

	
 
@@ -2487,7 +2487,7 @@ static void UpdateStationRating(Station 
 
				int or_ = ge->rating; // old rating
 

	
 
				/* only modify rating in steps of -2, -1, 0, 1 or 2 */
 
				ge->rating = rating = or_ + clamp(clamp(rating, 0, 255) - or_, -2, 2);
 
				ge->rating = rating = or_ + Clamp(Clamp(rating, 0, 255) - or_, -2, 2);
 

	
 
				/* if rating is <= 64 and more than 200 items waiting,
 
				 * remove some random amount of goods from the station */
 
@@ -2577,7 +2577,7 @@ void ModifyStationRatingAround(TileIndex
 
				GoodsEntry* ge = &st->goods[i];
 

	
 
				if (ge->acceptance_pickup != 0) {
 
					ge->rating = clamp(ge->rating + amount, 0, 255);
 
					ge->rating = Clamp(ge->rating + amount, 0, 255);
 
				}
 
			}
 
		}
src/town_map.h
Show inline comments
 
@@ -283,7 +283,7 @@ static inline void IncHouseConstructionT
 
		/* House is now completed.
 
		 * Store the year of construction as well, for newgrf house purpose */
 
		SetHouseCompleted(t, true);
 
		_m[t].m5 = clamp(_cur_year - ORIGINAL_BASE_YEAR, 0, 0xFF);
 
		_m[t].m5 = Clamp(_cur_year - ORIGINAL_BASE_YEAR, 0, 0xFF);
 
	}
 
}
 

	
src/train_cmd.cpp
Show inline comments
 
@@ -244,7 +244,7 @@ void TrainConsistChanged(Vehicle* v)
 
			veh_len = GetVehicleCallback(CBID_VEHICLE_LENGTH, 0, 0, u->engine_type, u);
 
		}
 
		if (veh_len == CALLBACK_FAILED) veh_len = rvi_u->shorten_factor;
 
		veh_len = clamp(veh_len, 0, u->Next() == NULL ? 7 : 5); // the clamp on vehicles not the last in chain is stricter, as too short wagons can break the 'follow next vehicle' code
 
		veh_len = Clamp(veh_len, 0, u->Next() == NULL ? 7 : 5); // the clamp on vehicles not the last in chain is stricter, as too short wagons can break the 'follow next vehicle' code
 
		u->u.rail.cached_veh_length = 8 - veh_len;
 
		v->u.rail.cached_total_length += u->u.rail.cached_veh_length;
 
	}
 
@@ -352,7 +352,7 @@ static int GetTrainAcceleration(Vehicle 
 
		if (curvecount[0] == 1 && curvecount[1] == 1) {
 
			max_speed = 0xFFFF;
 
		} else if (total > 1) {
 
			max_speed = 232 - (13 - clamp(sum, 1, 12)) * (13 - clamp(sum, 1, 12));
 
			max_speed = 232 - (13 - Clamp(sum, 1, 12)) * (13 - Clamp(sum, 1, 12));
 
		}
 
	}
 

	
 
@@ -455,7 +455,7 @@ static void UpdateTrainAcceleration(Vehi
 
	uint power = v->u.rail.cached_power;
 
	uint weight = v->u.rail.cached_weight;
 
	assert(weight != 0);
 
	v->acceleration = clamp(power / weight * 4, 1, 255);
 
	v->acceleration = Clamp(power / weight * 4, 1, 255);
 
}
 

	
 
int Train::GetImage(Direction direction) const
 
@@ -2513,7 +2513,7 @@ static int UpdateTrainSpeed(Vehicle *v)
 
		int tempmax = v->max_speed;
 
		if (v->cur_speed > v->max_speed)
 
			tempmax = v->cur_speed - (v->cur_speed / 10) - 1;
 
		v->cur_speed = spd = clamp(v->cur_speed + ((int)spd >> 8), 0, tempmax);
 
		v->cur_speed = spd = Clamp(v->cur_speed + ((int)spd >> 8), 0, tempmax);
 
	}
 

	
 
	if (!(v->direction & 1)) spd = spd * 3 >> 2;
src/vehicle.cpp
Show inline comments
 
@@ -1352,8 +1352,8 @@ Vehicle *CreateEffectVehicle(int x, int 
 

	
 
Vehicle *CreateEffectVehicleAbove(int x, int y, int z, EffectVehicle type)
 
{
 
	int safe_x = clamp(x, 0, MapMaxX() * TILE_SIZE);
 
	int safe_y = clamp(y, 0, MapMaxY() * TILE_SIZE);
 
	int safe_x = Clamp(x, 0, MapMaxX() * TILE_SIZE);
 
	int safe_y = Clamp(y, 0, MapMaxY() * TILE_SIZE);
 
	return CreateEffectVehicle(x, y, GetSlopeZ(safe_x, safe_y) + z, type);
 
}
 

	
src/video/cocoa_v.mm
Show inline comments
 
@@ -1244,7 +1244,7 @@ static const char* QZ_SetVideoWindowed(u
 
		if (!isCustom) {
 
			[ _cocoa_video_data.window setContentSize:contentRect.size ];
 
			// Ensure frame height - title bar height >= view height
 
			contentRect.size.height = clamp(height, 0, [ _cocoa_video_data.window frame ].size.height - 22 /* 22 is the height of title bar of window*/);
 
			contentRect.size.height = Clamp(height, 0, [ _cocoa_video_data.window frame ].size.height - 22 /* 22 is the height of title bar of window*/);
 
			height = contentRect.size.height;
 
			[ _cocoa_video_data.qdview setFrameSize:contentRect.size ];
 
		}
src/video/sdl_v.cpp
Show inline comments
 
@@ -420,8 +420,8 @@ static int PollEvent()
 
			break;
 

	
 
		case SDL_VIDEORESIZE: {
 
			int w = clamp(ev.resize.w, 64, MAX_SCREEN_WIDTH);
 
			int h = clamp(ev.resize.h, 64, MAX_SCREEN_HEIGHT);
 
			int w = Clamp(ev.resize.w, 64, MAX_SCREEN_WIDTH);
 
			int h = Clamp(ev.resize.h, 64, MAX_SCREEN_HEIGHT);
 
			ChangeResInGame(w, h);
 
			break;
 
		}
src/video/win32_v.cpp
Show inline comments
 
@@ -545,8 +545,8 @@ static LRESULT CALLBACK WndProcGdi(HWND 
 

	
 
			w = r->right - r->left - (r2.right - r2.left);
 
			h = r->bottom - r->top - (r2.bottom - r2.top);
 
			w = clamp(w, 64, MAX_SCREEN_WIDTH);
 
			h = clamp(h, 64, MAX_SCREEN_HEIGHT);
 
			w = Clamp(w, 64, MAX_SCREEN_WIDTH);
 
			h = Clamp(h, 64, MAX_SCREEN_HEIGHT);
 
			SetRect(&r2, 0, 0, w, h);
 

	
 
			AdjustWindowRect(&r2, GetWindowLong(hwnd, GWL_STYLE), FALSE);
 
@@ -677,8 +677,8 @@ static bool AllocateDibSection(int w, in
 
	HDC dc;
 
	int bpp = BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth();
 

	
 
	w = clamp(w, 64, MAX_SCREEN_WIDTH);
 
	h = clamp(h, 64, MAX_SCREEN_HEIGHT);
 
	w = Clamp(w, 64, MAX_SCREEN_WIDTH);
 
	h = Clamp(h, 64, MAX_SCREEN_HEIGHT);
 

	
 
	if (bpp == 0) error("Can't use a blitter that blits 0 bpp for normal visuals");
 

	
src/viewport.cpp
Show inline comments
 
@@ -372,8 +372,8 @@ static Point TranslateXYToTileCoord(cons
 
	/* we need to move variables in to the valid range, as the
 
	 * GetTileZoomCenterWindow() function can call here with invalid x and/or y,
 
	 * when the user tries to zoom out along the sides of the map */
 
	a = clamp(a, 0, (int)(MapMaxX() * TILE_SIZE) - 1);
 
	b = clamp(b, 0, (int)(MapMaxY() * TILE_SIZE) - 1);
 
	a = Clamp(a, 0, (int)(MapMaxX() * TILE_SIZE) - 1);
 
	b = Clamp(b, 0, (int)(MapMaxY() * TILE_SIZE) - 1);
 

	
 
	/* (a, b) is the X/Y-world coordinate that belongs to (x,y) if the landscape would be completely flat on height 0.
 
	 * Now find the Z-world coordinate by fix point iteration.
 
@@ -1649,8 +1649,8 @@ static inline void ClampViewportToMap(co
 
	int vy =  x + y * 2;
 

	
 
	/* clamp to size of map */
 
	vx = clamp(vx, 0, MapMaxX() * TILE_SIZE * 4);
 
	vy = clamp(vy, 0, MapMaxY() * TILE_SIZE * 4);
 
	vx = Clamp(vx, 0, MapMaxX() * TILE_SIZE * 4);
 
	vy = Clamp(vy, 0, MapMaxY() * TILE_SIZE * 4);
 

	
 
	/* Convert map coordinates to viewport coordinates */
 
	x = (-vx + vy) / 2;
 
@@ -1681,8 +1681,8 @@ void UpdateViewportPosition(Window *w)
 
			if (_patches.smooth_scroll) {
 
				int max_scroll = ScaleByMapSize1D(512);
 
				/* Not at our desired positon yet... */
 
				WP(w, vp_d).scrollpos_x += clamp(delta_x / 4, -max_scroll, max_scroll);
 
				WP(w, vp_d).scrollpos_y += clamp(delta_y / 4, -max_scroll, max_scroll);
 
				WP(w, vp_d).scrollpos_x += Clamp(delta_x / 4, -max_scroll, max_scroll);
 
				WP(w, vp_d).scrollpos_y += Clamp(delta_y / 4, -max_scroll, max_scroll);
 
			} else {
 
				WP(w, vp_d).scrollpos_x = WP(w, vp_d).dest_scrollpos_x;
 
				WP(w, vp_d).scrollpos_y = WP(w, vp_d).dest_scrollpos_y;
 
@@ -2719,8 +2719,8 @@ calc_heightdiff_single_direction:;
 

	
 
		case VPM_X_AND_Y_LIMITED: { /* drag an X by Y constrained rect area */
 
			int limit = (_thd.sizelimit - 1) * TILE_SIZE;
 
			x = sx + clamp(x - sx, -limit, limit);
 
			y = sy + clamp(y - sy, -limit, limit);
 
			x = sx + Clamp(x - sx, -limit, limit);
 
			y = sy + Clamp(y - sy, -limit, limit);
 
			} /* Fallthrough */
 
		case VPM_X_AND_Y: { /* drag an X by Y area */
 
			if (_patches.measure_tooltip) {
src/window.cpp
Show inline comments
 
@@ -196,7 +196,7 @@ static void DispatchMouseWheelEvent(Wind
 
			(sb = &w->vscroll2, wi2->type == WWT_SCROLL2BAR) || (sb = &w->vscroll, wi2->type == WWT_SCROLLBAR) ) {
 

	
 
		if (sb->count > sb->cap) {
 
			int pos = clamp(sb->pos + wheel, 0, sb->count - sb->cap);
 
			int pos = Clamp(sb->pos + wheel, 0, sb->count - sb->cap);
 
			if (pos != sb->pos) {
 
				sb->pos = pos;
 
				SetWindowDirty(w);
 
@@ -1295,8 +1295,8 @@ static bool HandleWindowDragging()
 

	
 
			/* Make sure the window doesn't leave the screen
 
			 * 13 is the height of the title bar */
 
			nx = clamp(nx, 13 - t->right, _screen.width - 13 - t->left);
 
			ny = clamp(ny, 0, _screen.height - 13);
 
			nx = Clamp(nx, 13 - t->right, _screen.width - 13 - t->left);
 
			ny = Clamp(ny, 0, _screen.height - 13);
 

	
 
			/* Make sure the title bar isn't hidden by behind the main tool bar */
 
			v = FindWindowById(WC_MAIN_TOOLBAR, 0);
 
@@ -2113,13 +2113,13 @@ void RelocateAllWindows(int neww, int ne
 
				break;
 

	
 
			case WC_STATUS_BAR:
 
				ResizeWindow(w, clamp(neww, 320, 640) - w->width, 0);
 
				ResizeWindow(w, Clamp(neww, 320, 640) - w->width, 0);
 
				top = newh - w->height;
 
				left = (neww - w->width) >> 1;
 
				break;
 

	
 
			case WC_SEND_NETWORK_MSG:
 
				ResizeWindow(w, clamp(neww, 320, 640) - w->width, 0);
 
				ResizeWindow(w, Clamp(neww, 320, 640) - w->width, 0);
 
				top = (newh - 26); // 26 = height of status bar + height of chat bar
 
				left = (neww - w->width) >> 1;
 
				break;
0 comments (0 inline, 0 general)