(svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
authorskidd13
Mon, 19 Nov 2007 18:38:10 +0000
changeset 7922 a7e266f966d9
parent 7921 3437fdd5c0a8
child 7923 91982bd3c549
(svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
src/aircraft_cmd.cpp
src/depot.h
src/disaster_cmd.cpp
src/economy.cpp
src/genworld_gui.cpp
src/graph_gui.cpp
src/industry_cmd.cpp
src/industry_gui.cpp
src/macros.h
src/main_gui.cpp
src/misc_gui.cpp
src/network/core/udp.cpp
src/network/network_gui.cpp
src/newgrf.cpp
src/newgrf_engine.cpp
src/newgrf_house.cpp
src/newgrf_industries.cpp
src/newgrf_industrytiles.cpp
src/newgrf_spritegroup.cpp
src/newgrf_station.cpp
src/npf.cpp
src/oldloader.cpp
src/openttd.cpp
src/players.cpp
src/rail_gui.cpp
src/roadveh_cmd.cpp
src/screenshot.cpp
src/settings.cpp
src/settings_gui.cpp
src/sound.cpp
src/station_cmd.cpp
src/town_map.h
src/train_cmd.cpp
src/vehicle.cpp
src/video/cocoa_v.mm
src/video/sdl_v.cpp
src/video/win32_v.cpp
src/viewport.cpp
src/window.cpp
--- a/src/aircraft_cmd.cpp	Mon Nov 19 04:34:40 2007 +0000
+++ b/src/aircraft_cmd.cpp	Mon Nov 19 18:38:10 2007 +0000
@@ -833,12 +833,12 @@
 
 	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;
 
--- a/src/depot.h	Mon Nov 19 04:34:40 2007 +0000
+++ b/src/depot.h	Mon Nov 19 18:38:10 2007 +0000
@@ -51,7 +51,7 @@
  */
 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);
 }
 
 /**
--- a/src/disaster_cmd.cpp	Mon Nov 19 04:34:40 2007 +0000
+++ b/src/disaster_cmd.cpp	Mon Nov 19 18:38:10 2007 +0000
@@ -159,13 +159,13 @@
 	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;
 
--- a/src/economy.cpp	Mon Nov 19 04:34:40 2007 +0000
+++ b/src/economy.cpp	Mon Nov 19 18:38:10 2007 +0000
@@ -212,7 +212,7 @@
 			/* 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;
 		}
--- a/src/genworld_gui.cpp	Mon Nov 19 04:34:40 2007 +0000
+++ b/src/genworld_gui.cpp	Mon Nov 19 18:38:10 2007 +0000
@@ -387,7 +387,7 @@
 				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 @@
 				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 @@
 			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 @@
 				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 @@
 				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 @@
 			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;
 			}
 
--- a/src/graph_gui.cpp	Mon Nov 19 04:34:40 2007 +0000
+++ b/src/graph_gui.cpp	Mon Nov 19 18:38:10 2007 +0000
@@ -1006,7 +1006,7 @@
 				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 @@
 				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;
--- a/src/industry_cmd.cpp	Mon Nov 19 04:34:40 2007 +0000
+++ b/src/industry_cmd.cpp	Mon Nov 19 18:38:10 2007 +0000
@@ -1628,7 +1628,7 @@
 	} 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 @@
 					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;
--- a/src/industry_gui.cpp	Mon Nov 19 04:34:40 2007 +0000
+++ b/src/industry_gui.cpp	Mon Nov 19 18:38:10 2007 +0000
@@ -583,7 +583,7 @@
 			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);
 		}
--- a/src/macros.h	Mon Nov 19 04:34:40 2007 +0000
+++ b/src/macros.h	Mon Nov 19 18:38:10 2007 +0000
@@ -151,9 +151,9 @@
  * @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 @@
  * @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 @@
  *
  * @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)
 {
--- a/src/main_gui.cpp	Mon Nov 19 04:34:40 2007 +0000
+++ b/src/main_gui.cpp	Mon Nov 19 18:38:10 2007 +0000
@@ -96,7 +96,7 @@
 		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 @@
 	 * 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 @@
 		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 @@
 		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;
--- a/src/misc_gui.cpp	Mon Nov 19 04:34:40 2007 +0000
+++ b/src/misc_gui.cpp	Mon Nov 19 18:38:10 2007 +0000
@@ -609,8 +609,8 @@
 		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 @@
 	/* 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 @@
 
 				/* 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);
--- a/src/network/core/udp.cpp	Mon Nov 19 04:34:40 2007 +0000
+++ b/src/network/core/udp.cpp	Mon Nov 19 18:38:10 2007 +0000
@@ -230,8 +230,8 @@
 			}
 		} /* 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 ();
--- a/src/network/network_gui.cpp	Mon Nov 19 04:34:40 2007 +0000
+++ b/src/network/network_gui.cpp	Mon Nov 19 18:38:10 2007 +0000
@@ -692,9 +692,9 @@
 				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 @@
 			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;
 			}
 		}
 
--- a/src/newgrf.cpp	Mon Nov 19 04:34:40 2007 +0000
+++ b/src/newgrf.cpp	Mon Nov 19 18:38:10 2007 +0000
@@ -1193,7 +1193,7 @@
 				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 @@
 				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 @@
 {
 	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;
--- a/src/newgrf_engine.cpp	Mon Nov 19 04:34:40 2007 +0000
+++ b/src/newgrf_engine.cpp	Mon Nov 19 18:38:10 2007 +0000
@@ -496,7 +496,7 @@
 			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 @@
 		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);
--- a/src/newgrf_house.cpp	Mon Nov 19 04:34:40 2007 +0000
+++ b/src/newgrf_house.cpp	Mon Nov 19 18:38:10 2007 +0000
@@ -211,7 +211,7 @@
 		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 @@
 	} 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 @@
 
 	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
--- a/src/newgrf_industries.cpp	Mon Nov 19 04:34:40 2007 +0000
+++ b/src/newgrf_industries.cpp	Mon Nov 19 18:38:10 2007 +0000
@@ -315,14 +315,14 @@
 		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 @@
 		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);
--- a/src/newgrf_industrytiles.cpp	Mon Nov 19 04:34:40 2007 +0000
+++ b/src/newgrf_industrytiles.cpp	Mon Nov 19 18:38:10 2007 +0000
@@ -244,7 +244,7 @@
 	} 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 @@
 
 	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
--- a/src/newgrf_spritegroup.cpp	Mon Nov 19 04:34:40 2007 +0000
+++ b/src/newgrf_spritegroup.cpp	Mon Nov 19 18:38:10 2007 +0000
@@ -84,7 +84,7 @@
 	/* 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;
--- a/src/newgrf_station.cpp	Mon Nov 19 04:34:40 2007 +0000
+++ b/src/newgrf_station.cpp	Mon Nov 19 18:38:10 2007 +0000
@@ -392,7 +392,7 @@
 			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 @@
 		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 */
--- a/src/npf.cpp	Mon Nov 19 04:34:40 2007 +0000
+++ b/src/npf.cpp	Mon Nov 19 18:38:10 2007 +0000
@@ -104,10 +104,10 @@
 
 	/* 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);
--- a/src/oldloader.cpp	Mon Nov 19 04:34:40 2007 +0000
+++ b/src/oldloader.cpp	Mon Nov 19 18:38:10 2007 +0000
@@ -1635,7 +1635,7 @@
 	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");
--- a/src/openttd.cpp	Mon Nov 19 04:34:40 2007 +0000
+++ b/src/openttd.cpp	Mon Nov 19 18:38:10 2007 +0000
@@ -280,8 +280,8 @@
 		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()
--- a/src/players.cpp	Mon Nov 19 04:34:40 2007 +0000
+++ b/src/players.cpp	Mon Nov 19 18:38:10 2007 +0000
@@ -95,7 +95,7 @@
 
 	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)));
--- a/src/rail_gui.cpp	Mon Nov 19 04:34:40 2007 +0000
+++ b/src/rail_gui.cpp	Mon Nov 19 18:38:10 2007 +0000
@@ -1109,7 +1109,7 @@
 
 		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);
 	}
 }
 
--- a/src/roadveh_cmd.cpp	Mon Nov 19 04:34:40 2007 +0000
+++ b/src/roadveh_cmd.cpp	Mon Nov 19 18:38:10 2007 +0000
@@ -129,7 +129,7 @@
 
 	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;
--- a/src/screenshot.cpp	Mon Nov 19 04:34:40 2007 +0000
+++ b/src/screenshot.cpp	Mon Nov 19 18:38:10 2007 +0000
@@ -123,7 +123,7 @@
 	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 @@
 	}
 
 	/* 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 @@
 	}
 
 	/* 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.
--- a/src/settings.cpp	Mon Nov 19 04:34:40 2007 +0000
+++ b/src/settings.cpp	Mon Nov 19 18:38:10 2007 +0000
@@ -665,12 +665,12 @@
 			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:
--- a/src/settings_gui.cpp	Mon Nov 19 04:34:40 2007 +0000
+++ b/src/settings_gui.cpp	Mon Nov 19 18:38:10 2007 +0000
@@ -429,7 +429,7 @@
 	} 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 @@
 							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 @@
 
 				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 */
--- a/src/sound.cpp	Mon Nov 19 04:34:40 2007 +0000
+++ b/src/sound.cpp	Mon Nov 19 18:38:10 2007 +0000
@@ -148,7 +148,7 @@
 	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);
--- a/src/station_cmd.cpp	Mon Nov 19 04:34:40 2007 +0000
+++ b/src/station_cmd.cpp	Mon Nov 19 18:38:10 2007 +0000
@@ -671,7 +671,7 @@
 	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 @@
 				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 @@
 				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);
 				}
 			}
 		}
--- a/src/town_map.h	Mon Nov 19 04:34:40 2007 +0000
+++ b/src/town_map.h	Mon Nov 19 18:38:10 2007 +0000
@@ -283,7 +283,7 @@
 		/* 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);
 	}
 }
 
--- a/src/train_cmd.cpp	Mon Nov 19 04:34:40 2007 +0000
+++ b/src/train_cmd.cpp	Mon Nov 19 18:38:10 2007 +0000
@@ -244,7 +244,7 @@
 			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 @@
 		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 @@
 	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 @@
 		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;
--- a/src/vehicle.cpp	Mon Nov 19 04:34:40 2007 +0000
+++ b/src/vehicle.cpp	Mon Nov 19 18:38:10 2007 +0000
@@ -1352,8 +1352,8 @@
 
 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);
 }
 
--- a/src/video/cocoa_v.mm	Mon Nov 19 04:34:40 2007 +0000
+++ b/src/video/cocoa_v.mm	Mon Nov 19 18:38:10 2007 +0000
@@ -1244,7 +1244,7 @@
 		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 ];
 		}
--- a/src/video/sdl_v.cpp	Mon Nov 19 04:34:40 2007 +0000
+++ b/src/video/sdl_v.cpp	Mon Nov 19 18:38:10 2007 +0000
@@ -420,8 +420,8 @@
 			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;
 		}
--- a/src/video/win32_v.cpp	Mon Nov 19 04:34:40 2007 +0000
+++ b/src/video/win32_v.cpp	Mon Nov 19 18:38:10 2007 +0000
@@ -545,8 +545,8 @@
 
 			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 @@
 	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");
 
--- a/src/viewport.cpp	Mon Nov 19 04:34:40 2007 +0000
+++ b/src/viewport.cpp	Mon Nov 19 18:38:10 2007 +0000
@@ -372,8 +372,8 @@
 	/* 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 @@
 	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 @@
 			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 @@
 
 		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) {
--- a/src/window.cpp	Mon Nov 19 04:34:40 2007 +0000
+++ b/src/window.cpp	Mon Nov 19 18:38:10 2007 +0000
@@ -196,7 +196,7 @@
 			(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 @@
 
 			/* 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 @@
 				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;