(svn r9675) [gamebalance] -Sync: r9420:9520 from trunk gamebalance
authorcelestar
Thu, 19 Apr 2007 14:48:10 +0000
branchgamebalance
changeset 9907 3b068c3a1c74
parent 9906 6f41b8713b65
child 9908 0fa543611bbe
(svn r9675) [gamebalance] -Sync: r9420:9520 from trunk
changelog.txt
configure
docs/openttd.6
known-bugs.txt
os/debian/changelog
os/win32/installer/install.nsi
projects/openttd_vs80.vcproj
readme.txt
src/build_vehicle_gui.cpp
src/currency.cpp
src/currency.h
src/disaster_cmd.cpp
src/economy.cpp
src/fontcache.cpp
src/gfx.cpp
src/gfx.h
src/graph_gui.cpp
src/industry.h
src/industry_cmd.cpp
src/misc/autocopyptr.hpp
src/newgrf.cpp
src/newgrf_cargo.cpp
src/newgrf_cargo.h
src/newgrf_gui.cpp
src/order_cmd.cpp
src/rail_cmd.cpp
src/road_cmd.cpp
src/road_map.h
src/settings.cpp
src/settings_gui.cpp
src/station_cmd.cpp
src/table/build_industry.h
src/texteff.cpp
src/tunnelbridge_cmd.cpp
src/vehicle_gui.h
--- a/changelog.txt	Thu Apr 19 14:43:25 2007 +0000
+++ b/changelog.txt	Thu Apr 19 14:48:10 2007 +0000
@@ -1,3 +1,46 @@
+0.5.1-RC2 (2007-03-23)
+------------------------------------------------------------------------
+- Fix: crashes when the chatbox would be drawn outside of the main window [FS#701] (r9420)
+- Fix: reading out of an array caused a segmentation fault [FS#694] (r9394)
+
+
+0.5.1-RC1 (2007-03-20)
+------------------------------------------------------------------------
+- Feature: Translation dependant formatting of dates (r8906)
+- Feature: Kick inactive initial network connections after some time [FS#115] (r9038, r9061)
+- Feature: Add an extra news group for opening and closing of industries (r9097)
+- Codechange: Disable shares by default and increase the default maximum distance from edge for oil refineries (r9339)
+- Codechange: When you started openttd with '-g' you got the same map every run (r9205)
+- Codechange: When all news-setting buttons are 'full', make the for-all button show 'full' too (r9137)
+- Codechange: Disable the ability to make flooding water with the canal build tool. In the scenario editor you can still make both canals and flood water at height level 0 [FS#622, FS#629] (r9105, r9115)
+- Codechange: The station list, sorted by cargo rating, now takes stations into account that have no cargo waiting [FS#595] (r9062)
+- Fix: Close the Shared Order Vehicle List if you remove the shared link with only 2 vehicles (r9338)
+- Fix: A34-1000, Z-Shuttle, and Kelling K1 are now listed as small aircraft (r9298)
+- Fix: Shared orders got messed up when the 'first' trains got removed in the depot [FS#685] (r9277)
+- Fix: Use a less CPU-intensive algorithm to find a random industry for the AI to prevent it slowing down the game [FS#644] (r9251)
+- Fix: When loading games, enroute_from was updated in the wrong place, causing issues with TTD savegames/scenarios (r9147)
+- Fix: "Train is lost" message is generated incorrectly [FS#676] (r9146)
+- Fix: Difficulty level button was not selected when opening the difficulty window (r9117)
+- Fix: The wrong catenary wires were drawn for tunnel entrances [FS#612] (r9077)
+- Fix: The intercontinental airport used 'T-junction' runway sprites when there is no exit in the middle of the runway as in the city airport [FS#529] (r9076)
+- Fix: [win] dedicated console now doesn't need an extra 'enter' to fully quit [FS#459] (r9074)
+- Fix: Take over companies properly in multiplayer games [FS#459] (r9071)
+- Fix: When a bribe failed and you haven't picked up cargo yet, you would never be able to do so for a given station [FS#404] (r9070)
+- Fix: Don't keep on scrolling for non-numeric values in settings, but require reclick [FS#663] (r9064)
+- Fix: The personal (.openttd) directories were hidden in the load/save directory listings [FS#652] (r9043)
+- Fix: Desync caused by buffer overflow [FS#664] (r9027)
+- Fix: When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length. (r9012)
+- Fix: Play the correct engine sound based on the engine type instead of the sprite (r9009)
+- Fix: New locomotive names were not announced in the news, it said "new railway locomotive available - railway locomotive" [FS#581] (r9000, r9001)
+- Fix: [NewGRF] Do not select a disabled platform length/number of track count when going out of drag-drop mode [FS#450] (r8999)
+- Fix: [win] Resolution doubled in cfg file when fullscreen mode used [FS#642] (r8994)
+- Fix: The industry list should also be (re)set when the number of industries is 0 [FS#656] (r8980)
+- Fix: [win] Possible buffer overflow if unicode text is pasted into an input box and needs trimming. (r8975)
+- Fix: [win] Support compilation with the Vista Platform SDK (r8974)
+- Fix: Crash on loading savegames with GRFs that do not have their GRF info/name set (r8955)
+- Fix: [NewGRF] support for vehicle variable 48 was wrong (r8943)
+
+
 0.5.0 (2007-02-27)
 ------------------------------------------------------------------------
 - Feature: Add the ability to load newer TTDP games (the tile information for coasts has changed) (r8738)
--- a/configure	Thu Apr 19 14:43:25 2007 +0000
+++ b/configure	Thu Apr 19 14:48:10 2007 +0000
@@ -3,7 +3,10 @@
 CONFIGURE_EXECUTABLE="$_"
 # On *nix systems those two are equal when ./configure is done
 if [ "$0" != "$CONFIGURE_EXECUTABLE" ]; then
-	if [ -z "`echo $CONFIGURE_EXECUTABLE | grep make`" ]; then
+	# On some systems, when ./configure is triggered from 'make'
+	#  the $_ is filled with 'make'. So if that is true, skip 'make'
+	#  and use $0 (and hope that is correct ;))
+	if [ -n "`echo $CONFIGURE_EXECUTABLE | grep make`" ]; then
 		CONFIGURE_EXECUTABLE="$0"
 	else
 		CONFIGURE_EXECUTABLE="$CONFIGURE_EXECUTABLE $0"
--- a/docs/openttd.6	Thu Apr 19 14:43:25 2007 +0000
+++ b/docs/openttd.6	Thu Apr 19 14:48:10 2007 +0000
@@ -1,6 +1,6 @@
 .\"                                      Hey, EMACS: -*- nroff -*-
 .\" Please adjust this date whenever revising the manpage.
-.Dd February 27, 2007
+.Dd March 23, 2007
 .Dt OPENTTD 6
 .Sh NAME
 .Nm openttd
--- a/known-bugs.txt	Thu Apr 19 14:43:25 2007 +0000
+++ b/known-bugs.txt	Thu Apr 19 14:48:10 2007 +0000
@@ -15,43 +15,39 @@
 If the bug report is closed, it has been fixed, which then can be verified
 in the latest SVN version.
 
-Bugs for 0.5.0
+Bugs for 0.5.1
 ------------------------------------------------------------------------
 URL: http://bugs.openttd.org
 
+-677 	Badspacing in news summaries
+-674 	Map signs allow less nonenglish characters than english ones
+-672 	Non-transparent station names' backgrounds do not resize properly upon language change
+-669	Docks/Airports/RV Stations can be built without available vehicles
+-646	AI builds useless stations
 -601	airports can't get flooded when they have planes in them
 -599	reloaded game lost company passwords
--595	Sort by max cargo rating does not sort correctly
 -594	terraforming wipes out canals
 -591	Autorenew fails under certain conditions
 -583	Fatal fault or crash during startup
--578	No loading at my industrial centre
--574	Open TTD overiding Power Warnings
 -571	Problems with vehicle purchase lists with NewGRFs
 -559	Front-/Rear-facing engines don't line up with each other
 -553	Autorenew doesn't warn when replacement isn't available
 -546	[0.5.0 RC3] Inflation overflow
 -540	Planes vanished when offered exclusive
 -539	Trains can cash the same cargo multiple times
--529	newairport's sprite issue
 -522	overflow on vehicle costs
 -508	Destroying trees and replanting => raised rating
 -502	OSX can incorrectly print "dbg: [sl] Cannot open savegame 'data/opntitle.dat' for saving/loading."
 -501	Mouse pointer gets hidden, when draging out of window and back again. Only affects Wacom etc.
 -494	Get free money abusing a stock bug
 -474	Overtaking car doesn't hit the against-riding car.
--459	Merging is buggy
 -458	Crash when changing Resolution on Mac OS X (x86)
--450	GUI selecting disabled numbers (newstations)
 -442	Alt-tab behaviour flawed whilst full screen (win32)
--441	Transparent stuff
 -435	Assertion window doesn't show when in fullscreen on Mac OS X
 -423	Improved loading causes high CPU use with long trains
 -410	Openttd in dedicated mode don't run without data files
--404	Cargo never delivered to station after bribe and before first pickup
 -365	Blimp Stuck at airport
 -362	Changing signal type affects whole square
--357	CPU spikes in game
 -355	graphics bugs with trains - water, tunnels
 -354	Maglev Trains faster than All Planes
 -339	Crash in Quicktime when exiting game
@@ -67,7 +63,6 @@
 -165	vehicle length not taken into account
 -153	Language crash with app renaming OSX
 -119	Clipping problems with vehicles on slopes
--115	inactive logins do not get auto kicked
 - 89	Able to build railways/stations before engines become available
 - 65	short wagons bug
 - 51	Windows doesn't support CUSTOM_LANG_DIR
@@ -87,7 +82,7 @@
 -1116638	"More, but smaller changes" deficiency
 -1106356	re-offered prototypes
 
-Minor Bugs for 0.5.0
+Minor Bugs for 0.5.1
 ------------------------------------------------------------------------
 URL: http://sourceforge.net/tracker/?atid=669662&group_id=103924&func=browse
 
--- a/os/debian/changelog	Thu Apr 19 14:43:25 2007 +0000
+++ b/os/debian/changelog	Thu Apr 19 14:48:10 2007 +0000
@@ -4,6 +4,18 @@
 
  -- Matthijs Kooijman <m.kooijman@student.utwente.nl>  Mon, 26 Feb 2007 21:07:05 +0100
 
+openttd (0.5.1~rc2-1) unstable; urgency=low
+
+  * New upstream release.
+
+ -- Matthijs Kooijman <m.kooijman@student.utwente.nl>  Fri, 23 Mar 2007 23:45:46 +0100
+
+openttd (0.5.1~rc1-1) unstable; urgency=low
+
+  * New upstream release.
+
+ -- Matthijs Kooijman <m.kooijman@student.utwente.nl>  Wed, 20 Mar 2007 22:03:46 +0100
+
 openttd (0.5.0-1) unstable; urgency=low
 
   * New upstream release
--- a/os/win32/installer/install.nsi	Thu Apr 19 14:43:25 2007 +0000
+++ b/os/win32/installer/install.nsi	Thu Apr 19 14:48:10 2007 +0000
@@ -1,6 +1,6 @@
 !define APPNAME "OpenTTD"   ; Define application name
-!define APPVERSION "0.5.0"  ; Define application version
-!define INSTALLERVERSION 28 ; NEED TO UPDATE THIS FOR EVERY RELEASE!!!
+!define APPVERSION "0.5.1"  ; Define application version
+!define INSTALLERVERSION 30 ; NEED TO UPDATE THIS FOR EVERY RELEASE!!!
 
 !define APPURLLINK "http://www.openttd.org"
 !define APPNAMEANDVERSION "${APPNAME} ${APPVERSION}"
--- a/projects/openttd_vs80.vcproj	Thu Apr 19 14:43:25 2007 +0000
+++ b/projects/openttd_vs80.vcproj	Thu Apr 19 14:48:10 2007 +0000
@@ -308,7 +308,7 @@
 				AdditionalDependencies="winmm.lib ws2_32.lib libpng.lib zlibstat.lib dxguid.lib libfreetype2.lib"
 				LinkIncremental="0"
 				SuppressStartupBanner="true"
-				IgnoreDefaultLibraryNames="LIBCMT.lib"
+				IgnoreDefaultLibraryNames="LIBCMT.lib;LIBC.lib"
 				GenerateDebugInformation="true"
 				SubSystem="2"
 				TargetMachine="1"
@@ -448,11 +448,11 @@
 				>
 			</File>
 			<File
-				RelativePath=".\..\src\aystar.cpp"
+				RelativePath=".\..\src\autoreplace_cmd.cpp"
 				>
 			</File>
 			<File
-				RelativePath=".\..\src\autoreplace_cmd.cpp"
+				RelativePath=".\..\src\aystar.cpp"
 				>
 			</File>
 			<File
--- a/readme.txt	Thu Apr 19 14:43:25 2007 +0000
+++ b/readme.txt	Thu Apr 19 14:48:10 2007 +0000
@@ -1,6 +1,6 @@
 OpenTTD README
-Last updated:    2007-02-27
-Release version: 0.5.0
+Last updated:    2007-03-23
+Release version: 0.5.1-RC2
 ------------------------------------------------------------------------
 
 
--- a/src/build_vehicle_gui.cpp	Thu Apr 19 14:43:25 2007 +0000
+++ b/src/build_vehicle_gui.cpp	Thu Apr 19 14:48:10 2007 +0000
@@ -41,21 +41,22 @@
 	BUILD_VEHICLE_WIDGET_BUILD,
 	BUILD_VEHICLE_WIDGET_RENAME,
 	BUILD_VEHICLE_WIDGET_RESIZE,
+	BUILD_VEHICLE_WIDGET_END
 };
 
 static const Widget _build_vehicle_widgets[] = {
 	{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,                STR_018B_CLOSE_WINDOW },
-	{    WWT_CAPTION,  RESIZE_RIGHT,    14,    11,   227,     0,    13, 0x0,                     STR_018C_WINDOW_TITLE_DRAG_THIS },
+	{    WWT_CAPTION,  RESIZE_RIGHT,    14,    11,   239,     0,    13, 0x0,                     STR_018C_WINDOW_TITLE_DRAG_THIS },
 	{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,     0,    80,    14,    25, STR_SORT_BY,             STR_SORT_ORDER_TIP},
-	{      WWT_PANEL,  RESIZE_RIGHT,    14,    81,   215,    14,    25, 0x0,                     STR_SORT_CRITERIA_TIP},
-	{    WWT_TEXTBTN,     RESIZE_LR,    14,   216,   227,    14,    25, STR_0225,                STR_SORT_CRITERIA_TIP},
-	{     WWT_MATRIX,     RESIZE_RB,    14,     0,   215,    26,   121, 0x0,                     STR_NULL },
-	{  WWT_SCROLLBAR,    RESIZE_LRB,    14,   216,   227,    26,   121, 0x0,                     STR_0190_SCROLL_BAR_SCROLLS_LIST },
-	{      WWT_PANEL,    RESIZE_RTB,    14,     0,   227,   122,   223, 0x0,                     STR_NULL },
+	{      WWT_PANEL,  RESIZE_RIGHT,    14,    81,   227,    14,    25, 0x0,                     STR_SORT_CRITERIA_TIP},
+	{    WWT_TEXTBTN,     RESIZE_LR,    14,   228,   239,    14,    25, STR_0225,                STR_SORT_CRITERIA_TIP},
+	{     WWT_MATRIX,     RESIZE_RB,    14,     0,   227,    26,   121, 0x0,                     STR_NULL },
+	{  WWT_SCROLLBAR,    RESIZE_LRB,    14,   228,   239,    26,   121, 0x0,                     STR_0190_SCROLL_BAR_SCROLLS_LIST },
+	{      WWT_PANEL,    RESIZE_RTB,    14,     0,   239,   122,   243, 0x0,                     STR_NULL },
 
-	{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,     0,   114,   224,   235, 0x0,                     STR_NULL },
-	{ WWT_PUSHTXTBTN,    RESIZE_RTB,    14,   115,   215,   224,   235, 0x0,                     STR_NULL },
-	{  WWT_RESIZEBOX,   RESIZE_LRTB,    14,   216,   227,   224,   235, 0x0,                     STR_RESIZE_BUTTON },
+	{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,     0,   114,   244,   255, 0x0,                     STR_NULL },
+	{ WWT_PUSHTXTBTN,    RESIZE_RTB,    14,   115,   227,   244,   255, 0x0,                     STR_NULL },
+	{  WWT_RESIZEBOX,   RESIZE_LRTB,    14,   228,   239,   244,   255, 0x0,                     STR_RESIZE_BUTTON },
 	{   WIDGETS_END},
 };
 
@@ -566,8 +567,9 @@
  * @param x,y location where to draw the info
  * @param w how wide are the text allowed to be (size of widget/window to Draw in)
  * @param engine_number the engine of which to draw the info of
+ * @return y after drawing all the text
  */
-void DrawVehiclePurchaseInfo(int x, int y, uint w, EngineID engine_number)
+int DrawVehiclePurchaseInfo(int x, int y, uint w, EngineID engine_number)
 {
 	const Engine *e = GetEngine(engine_number);
 	YearMonthDay ymd;
@@ -633,6 +635,8 @@
 	/* Additional text from NewGRF */
 	y += ShowAdditionalText(x, y, w, engine_number);
 	if (refitable) y += ShowRefitOptionsList(x, y, w, engine_number);
+
+	return y;
 }
 
 /* Figure out what train EngineIDs to put in the list */
@@ -832,6 +836,23 @@
 	}
 }
 
+static void ExpandPurchaseInfoWidget(Window *w, int expand_by)
+{
+	Widget *wi = &w->widget[BUILD_VEHICLE_WIDGET_PANEL];
+
+	SetWindowDirty(w);
+	wi->bottom += expand_by;
+
+	for (uint i = BUILD_VEHICLE_WIDGET_BUILD; i < BUILD_VEHICLE_WIDGET_END; i++) {
+		wi = &w->widget[i];
+		wi->top += expand_by;
+		wi->bottom += expand_by;
+	}
+
+	w->height += expand_by;
+	SetWindowDirty(w);
+}
+
 static void DrawBuildVehicleWindow(Window *w)
 {
 	const buildvehicle_d *bv = &WP(w, buildvehicle_d);
@@ -847,7 +868,9 @@
 
 	if (bv->sel_engine != INVALID_ENGINE) {
 		const Widget *wi = &w->widget[BUILD_VEHICLE_WIDGET_PANEL];
-		DrawVehiclePurchaseInfo(2, wi->top + 1, wi->right - wi->left - 2, bv->sel_engine);
+		int text_end = DrawVehiclePurchaseInfo(2, wi->top + 1, wi->right - wi->left - 2, bv->sel_engine);
+
+		if (text_end > wi->bottom) ExpandPurchaseInfoWidget(w, text_end - wi->bottom);
 	}
 
 	DrawString(85, 15, _sort_listing[bv->vehicle_type][bv->sort_criteria], 0x10);
@@ -980,7 +1003,7 @@
 }
 
 static const WindowDesc _build_vehicle_desc = {
-	WDP_AUTO, WDP_AUTO, 228, 236,
+	WDP_AUTO, WDP_AUTO, 240, 256,
 	WC_BUILD_VEHICLE, WC_NONE,
 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE,
 	_build_vehicle_widgets,
@@ -1021,14 +1044,12 @@
 			ResizeWindow(w, 0, 16);
 			break;
 		case VEH_ROAD:
-			ResizeWindow(w, 20, 16);
+			ResizeWindow(w, 0, 16);
 		case VEH_SHIP:
-			ResizeWindow(w, 27, 0);
 			break;
 		case VEH_AIRCRAFT:
 			bv->filter.flags =
 				tile == 0 ? AirportFTAClass::ALL : GetStationByTile(tile)->Airport()->flags;
-			ResizeWindow(w, 12, 0);
 			break;
 	}
 	SetupWindowStrings(w, type);
--- a/src/currency.cpp	Thu Apr 19 14:43:25 2007 +0000
+++ b/src/currency.cpp	Thu Apr 19 14:48:10 2007 +0000
@@ -158,12 +158,17 @@
 }
 
 /**
- * Called only from newgrf.c.  Will fill _currency_specs array with
+ * Will fill _currency_specs array with
  * default values from origin_currency_specs
+ * Called only from newgrf.cpp and settings.cpp.
+ * @param preserve_custom will not reset custom currency (the latest one on the list)
+ *        if ever it is flagged to true. In which case, the total size of the memory to move
+ *        will be one currency spec less, thus preserving the custom curreny from been
+ *        overwritten.
  **/
-void ResetCurrencies()
+void ResetCurrencies(bool preserve_custom)
 {
-	memcpy(&_currency_specs, &origin_currency_specs, sizeof(origin_currency_specs));
+	memcpy(&_currency_specs, &origin_currency_specs, sizeof(origin_currency_specs) - (preserve_custom ? sizeof(_custom_currency) : 0));
 }
 
 /**
--- a/src/currency.h	Thu Apr 19 14:43:25 2007 +0000
+++ b/src/currency.h	Thu Apr 19 14:48:10 2007 +0000
@@ -40,7 +40,7 @@
 
 uint GetMaskOfAllowedCurrencies();
 void CheckSwitchToEuro();
-void ResetCurrencies();
+void ResetCurrencies(bool preserve_custom = true);
 StringID* BuildCurrencyDropdown();
 byte GetNewgrfCurrencyIdConverted(byte grfcurr_id);
 
--- a/src/disaster_cmd.cpp	Thu Apr 19 14:43:25 2007 +0000
+++ b/src/disaster_cmd.cpp	Thu Apr 19 14:48:10 2007 +0000
@@ -459,7 +459,7 @@
 		ind = GetIndustryIndex(tile);
 		v->dest_tile = ind;
 
-		if (GetIndustry(ind)->type == IT_OIL_REFINERY) {
+		if (GetIndustrySpec(GetIndustry(ind)->type)->behaviour & INDUSTRYBEH_AIRPLANE_ATTACKS) {
 			v->current_order.dest = 1;
 			v->age = 0;
 		}
@@ -532,7 +532,7 @@
 		ind = GetIndustryIndex(tile);
 		v->dest_tile = ind;
 
-		if (GetIndustry(ind)->type == IT_FACTORY) {
+		if (GetIndustrySpec(GetIndustry(ind)->type)->behaviour & INDUSTRYBEH_CHOPPER_ATTACKS) {
 			v->current_order.dest = 1;
 			v->age = 0;
 		}
@@ -828,7 +828,7 @@
 	found = NULL;
 
 	FOR_ALL_INDUSTRIES(i) {
-		if (i->type == IT_OIL_REFINERY &&
+		if ((GetIndustrySpec(i->type)->behaviour & INDUSTRYBEH_AIRPLANE_ATTACKS) &&
 				(found == NULL || CHANCE16(1, 2))) {
 			found = i;
 		}
@@ -864,7 +864,7 @@
 	found = NULL;
 
 	FOR_ALL_INDUSTRIES(i) {
-		if (i->type == IT_FACTORY &&
+		if ((GetIndustrySpec(i->type)->behaviour & INDUSTRYBEH_CHOPPER_ATTACKS) &&
 				(found == NULL || CHANCE16(1, 2))) {
 			found = i;
 		}
@@ -982,7 +982,7 @@
 		const Industry *i;
 
 		FOR_ALL_INDUSTRIES(i) {
-			if (i->type == IT_COAL_MINE && --index < 0) {
+			if ((GetIndustrySpec(i->type)->behaviour & INDUSTRYBEH_CAN_SUBSIDENCE) && --index < 0) {
 				SetDParam(0, i->town->index);
 				AddNewsItem(STR_B005_COAL_MINE_SUBSIDENCE_LEAVES,
 					NEWS_FLAGS(NM_THIN,NF_VIEWPORT|NF_TILE,NT_ACCIDENT,0), i->xy + TileDiffXY(1, 1), 0);
--- a/src/economy.cpp	Thu Apr 19 14:43:25 2007 +0000
+++ b/src/economy.cpp	Thu Apr 19 14:48:10 2007 +0000
@@ -962,7 +962,6 @@
 
 int32 GetTransportedGoodsIncome(uint num_pieces, uint dist, byte transit_days, CargoID cargo_type)
 {
-	CargoID cargo = cargo_type;
 	const CargoSpec *cs = GetCargo(cargo_type);
 	byte f;
 
@@ -987,7 +986,7 @@
 	}
 	if (f < 31) f = 31;
 
-	return BIGMULSS(dist * f * num_pieces, _cargo_payment_rates[cargo], 21);
+	return BIGMULSS(dist * f * num_pieces, _cargo_payment_rates[cargo_type], 21);
 }
 
 static void DeliverGoodsToIndustry(TileIndex xy, CargoID cargo_type, int num_pieces)
--- a/src/fontcache.cpp	Thu Apr 19 14:43:25 2007 +0000
+++ b/src/fontcache.cpp	Thu Apr 19 14:48:10 2007 +0000
@@ -147,10 +147,10 @@
 
 
 folder_error:
+registry_no_font_found:
 #if defined(UNICODE)
-	free(font_path);
+	free(font_namep);
 #endif
-registry_no_font_found:
 	RegCloseKey(hKey);
 	return err;
 }
--- a/src/gfx.cpp	Thu Apr 19 14:43:25 2007 +0000
+++ b/src/gfx.cpp	Thu Apr 19 14:48:10 2007 +0000
@@ -531,7 +531,7 @@
 }
 
 
-uint DrawStringMultiLine(int x, int y, StringID str, int maxw)
+uint DrawStringMultiLine(int x, int y, StringID str, int maxw, int maxh)
 {
 	char buffer[512];
 	uint32 tmp;
@@ -548,6 +548,14 @@
 	mt = GetCharacterHeight((FontSize)GB(tmp, 16, 16));
 	total_height = (num + 1) * mt;
 
+	if (maxh != -1 && (int)total_height > maxh) {
+		/* Check there's room enough for at least one line. */
+		if (maxh < mt) return 0;
+
+		num = maxh / mt - 1;
+		total_height = (num + 1) * mt;
+	}
+
 	src = buffer;
 
 	for (;;) {
--- a/src/gfx.h	Thu Apr 19 14:43:25 2007 +0000
+++ b/src/gfx.h	Thu Apr 19 14:48:10 2007 +0000
@@ -231,7 +231,7 @@
 uint32 FormatStringLinebreaks(char *str, int maxw);
 void LoadStringWidthTable();
 void DrawStringMultiCenter(int x, int y, StringID str, int maxw);
-uint DrawStringMultiLine(int x, int y, StringID str, int maxw);
+uint DrawStringMultiLine(int x, int y, StringID str, int maxw, int maxh = -1);
 void DrawDirtyBlocks();
 void SetDirtyBlocks(int left, int top, int right, int bottom);
 void MarkWholeScreenDirty();
--- a/src/graph_gui.cpp	Thu Apr 19 14:43:25 2007 +0000
+++ b/src/graph_gui.cpp	Thu Apr 19 14:48:10 2007 +0000
@@ -796,7 +796,7 @@
 	}
 
 	/* Resize the window to fit the cargo types */
-	ResizeWindow(w, 0, num_active * 8);
+	ResizeWindow(w, 0, max(num_active, 12U) * 8);
 
 	/* Add widgets for each cargo type */
 	w->widget_count += num_active;
--- a/src/industry.h	Thu Apr 19 14:43:25 2007 +0000
+++ b/src/industry.h	Thu Apr 19 14:48:10 2007 +0000
@@ -6,6 +6,7 @@
 #define INDUSTRY_H
 
 #include "oldpool.h"
+#include "helpers.hpp"
 
 typedef byte IndustryGfx;
 typedef uint8 IndustryType;
@@ -21,6 +22,27 @@
 	INDUSTRYLIFE_CLOSABLE,         ///< Industry can only close (no production change)
 };
 
+enum IndustyBehaviour {
+	INDUSTRYBEH_NONE                  =      0,
+	INDUSTRYBEH_PLANT_FIELDS          = 1 << 0,  ///< periodically plants fileds around itself (temp and artic farms)
+	INDUSTRYBEH_CUT_TREES             = 1 << 1,  ///< cuts trees and produce first output cargo from them (lumber mill)
+	INDUSTRYBEH_BUILT_ONWATER         = 1 << 2,  ///< is built on water (oil rig)
+	INDUSTRYBEH_TOWN1200_MORE         = 1 << 3,  ///< can only be built in towns larger then 1200 inhabitants (temperate bank)
+	INDUSTRYBEH_ONLY_INTOWN           = 1 << 4,  ///< can only be built in towns (arctic/tropic banks, water tower)
+	INDUSTRYBEH_ONLY_NEARTOWN         = 1 << 5,  ///< is always built near towns (toy shop)
+	INDUSTRYBEH_PLANT_ON_BUILT        = 1 << 6,  ///< Fields are planted around when built (all farms)
+	INDUSTRYBEH_DONT_INCR_PROD        = 1 << 7,  ///< do not increase production (oil wells)
+	INDUSTRYBEH_BEFORE_1950           = 1 << 8,  ///< can only be built before 1950 (oil wells)
+	INDUSTRYBEH_AFTER_1960            = 1 << 9,  ///< can only be built after 1960 (oil rigs)
+	INDUSTRYBEH_AI_AIRSHIP_ROUTES     = 1 << 10, ///< ai will attempt to establish air/ship routes to this industry (oil rig)
+	INDUSTRYBEH_AIRPLANE_ATTACKS      = 1 << 11, ///< can be exploded by a military airplane (oil refinery)
+	INDUSTRYBEH_CHOPPER_ATTACKS       = 1 << 12, ///< can be exploded by a military helicopter (factory)
+	INDUSTRYBEH_CAN_SUBSIDENCE        = 1 << 13, ///< can cause a subsidence (coal mine, shaft that collapses)
+};
+
+
+DECLARE_ENUM_AS_BIT_SET(IndustyBehaviour);
+
 /**
  * Defines the internal data of a functionnal industry
  */
@@ -71,6 +93,7 @@
 	CargoID accepts_cargo[3];             ///< 3 accepted cargos
 	IndustryLifeType life_type;           ///< This is also known as Industry production flag, in newgrf specs
 	byte climate_availability;            ///< Bitmask, giving landscape enums as bit position
+	IndustyBehaviour behaviour;           ///< How this industry will behave, and how others entities can use it
 	StringID name;                        ///< Displayed name of the industry
 	StringID new_industry_text;           ///< Message appearing when the industry is built
 	StringID closure_text;                ///< Message appearing when the industry closes
--- a/src/industry_cmd.cpp	Thu Apr 19 14:43:25 2007 +0000
+++ b/src/industry_cmd.cpp	Thu Apr 19 14:48:10 2007 +0000
@@ -117,7 +117,7 @@
 		}
 	END_TILE_LOOP(tile_cur, i->width, i->height, i->xy);
 
-	if (i->type == IT_FARM || i->type == IT_FARM_2) {
+	if (GetIndustrySpec(i->type)->behaviour & INDUSTRYBEH_PLANT_FIELDS) {
 		/* Remove the farmland and convert it to regular tiles over time. */
 		BEGIN_TILE_LOOP(tile_cur, 42, 42, i->xy - TileDiffXY(21, 21)) {
 			tile_cur = TILE_MASK(tile_cur);
@@ -323,6 +323,7 @@
 static int32 ClearTile_Industry(TileIndex tile, byte flags)
 {
 	Industry *i = GetIndustryByTile(tile);
+	const IndustrySpec *indspec = GetIndustrySpec(i->type);
 
 	/* water can destroy industries
 	 * in editor you can bulldoze industries
@@ -331,8 +332,8 @@
 	 */
 	if ((_current_player != OWNER_WATER && _game_mode != GM_EDITOR &&
 			!_cheats.magic_bulldozer.value) ||
-			(_current_player == OWNER_WATER && i->type == IT_OIL_RIG)) {
-		SetDParam(0, GetIndustrySpec(i->type)->name);
+			(_current_player == OWNER_WATER && (indspec->behaviour & INDUSTRYBEH_BUILT_ONWATER))) {
+		SetDParam(0, indspec->name);
 		return_cmd_error(STR_4800_IN_THE_WAY);
 	}
 
@@ -975,12 +976,13 @@
 
 	/* produce some cargo */
 	if ((i->counter & 0xFF) == 0) {
+		IndustyBehaviour indbehav = GetIndustrySpec(i->type)->behaviour;
 		i->cargo_waiting[0] = min(0xffff, i->cargo_waiting[0] + i->production_rate[0]);
 		i->cargo_waiting[1] = min(0xffff, i->cargo_waiting[1] + i->production_rate[1]);
 
-		if (i->type == IT_FARM || i->type == IT_FARM_2) {
+		if (indbehav & INDUSTRYBEH_PLANT_FIELDS) {
 			MaybePlantFarmField(i);
-		} else if (i->type == IT_LUMBER_MILL && (i->counter & 0x1FF) == 0) {
+		} else if ((indbehav & INDUSTRYBEH_CUT_TREES) && (i->counter & 0x1FF) == 0) {
 			ChopLumberMillTrees(i);
 		}
 	}
@@ -1156,9 +1158,10 @@
 			}
 		} else {
 			if (!EnsureNoVehicle(cur_tile)) return false;
+			IndustyBehaviour ind_behav = GetIndustrySpec(type)->behaviour;
 
-			if (type == IT_OIL_RIG)  {
-				if (!IsClearWaterTile(cur_tile)) return false;
+			if (ind_behav & INDUSTRYBEH_BUILT_ONWATER) {
+				return IsClearWaterTile(cur_tile);
 			} else {
 				Slope tileh;
 
@@ -1186,27 +1189,19 @@
 					}
 				}
 
-				if (type == IT_BANK_TEMP) {
+				if (ind_behav & INDUSTRYBEH_ONLY_INTOWN) {
 					if (!IsTileType(cur_tile, MP_HOUSE)) {
 						_error_message = STR_029D_CAN_ONLY_BE_BUILT_IN_TOWNS;
 						return false;
 					}
-				} else if (type == IT_BANK_TROPIC_ARCTIC) {
-					if (!IsTileType(cur_tile, MP_HOUSE)) {
-						_error_message = STR_030D_CAN_ONLY_BE_BUILT_IN_TOWNS;
-						return false;
+				} else {
+					if (ind_behav & INDUSTRYBEH_ONLY_NEARTOWN) {
+						if (!IsTileType(cur_tile, MP_HOUSE)) goto do_clear;
+					} else {
+do_clear:
+						if (CmdFailed(DoCommand(cur_tile, 0, 0, DC_AUTO, CMD_LANDSCAPE_CLEAR)))
+							return false;
 					}
-				} else if (type == IT_TOY_SHOP) {
-					if (!IsTileType(cur_tile, MP_HOUSE)) goto do_clear;
-				} else if (type == IT_WATER_TOWER) {
-					if (!IsTileType(cur_tile, MP_HOUSE)) {
-						_error_message = STR_0316_CAN_ONLY_BE_BUILT_IN_TOWNS;
-						return false;
-					}
-				} else {
-do_clear:
-					if (CmdFailed(DoCommand(cur_tile, 0, 0, DC_AUTO, CMD_LANDSCAPE_CLEAR)))
-						return false;
 				}
 			}
 		}
@@ -1217,12 +1212,12 @@
 
 static bool CheckIfIndustryIsAllowed(TileIndex tile, int type, const Town *t)
 {
-	if (type == IT_BANK_TEMP && t->population < 1200) {
+	if ((GetIndustrySpec(type)->behaviour & INDUSTRYBEH_TOWN1200_MORE) && t->population < 1200) {
 		_error_message = STR_029D_CAN_ONLY_BE_BUILT_IN_TOWNS;
 		return false;
 	}
 
-	if (type == IT_TOY_SHOP && DistanceMax(t->xy, tile) > 9) {
+	if ((GetIndustrySpec(type)->behaviour & INDUSTRYBEH_ONLY_NEARTOWN) && DistanceMax(t->xy, tile) > 9) {
 		_error_message = STR_0239_SITE_UNSUITABLE;
 		return false;
 	}
@@ -1450,7 +1445,7 @@
 	i->width++;
 	i->height++;
 
-	if (i->type == IT_FARM || i->type == IT_FARM_2) {
+	if (GetIndustrySpec(i->type)->behaviour & INDUSTRYBEH_PLANT_ON_BUILT) {
 		for (j = 0; j != 50; j++) PlantRandomFarmField(i);
 	}
 	_industry_sort_dirty = true;
@@ -1737,8 +1732,8 @@
 	Industry *i;
 	const IndustrySpec *ind_spc = GetIndustrySpec(type);;
 
-	if (type == IT_OIL_WELL && _cur_year > 1950) return;
-	if (type == IT_OIL_RIG  && _cur_year < 1960) return;
+	if ((ind_spc->behaviour & INDUSTRYBEH_BEFORE_1950) && _cur_year > 1950) return;
+	if ((ind_spc->behaviour & INDUSTRYBEH_AFTER_1960) && _cur_year < 1960) return;
 
 	j = 2000;
 	for (;;) {
@@ -1766,7 +1761,7 @@
 
 		case INDUSTRYLIFE_PRODUCTION:
 			/* decrease or increase */
-			if (type == IT_OIL_WELL && _opt.landscape == LT_TEMPERATE)
+			if ((indspec->behaviour & INDUSTRYBEH_DONT_INCR_PROD) && _opt.landscape == LT_TEMPERATE)
 				only_decrease = true;
 
 			if (only_decrease || CHANCE16(1,3)) {
--- a/src/misc/autocopyptr.hpp	Thu Apr 19 14:43:25 2007 +0000
+++ b/src/misc/autocopyptr.hpp	Thu Apr 19 14:48:10 2007 +0000
@@ -8,7 +8,7 @@
  *  It is non-invasive smart pointer (reference counter is held outside
  *  of Tdata).
  *  When copied, its new copy shares the same underlaying structure Tdata.
- *  When dereferenced, its behavior depends on 2 factors:
+ *  When dereferenced, its behaviour depends on 2 factors:
  *     - whether the data is shared (used by more than one pointer)
  *     - type of access (read/write)
  *    When shared pointer is dereferenced for write, new clone of Tdata
--- a/src/newgrf.cpp	Thu Apr 19 14:43:25 2007 +0000
+++ b/src/newgrf.cpp	Thu Apr 19 14:48:10 2007 +0000
@@ -261,6 +261,20 @@
 	return str;
 }
 
+static uint8 MapDOSColour(uint8 colour)
+{
+	if (_use_dos_palette) return colour;
+
+	if (colour < 10) {
+		static uint8 dos_to_win_colour_map[] = { 0, 215, 216, 136, 88, 106, 32, 33, 40, 245 };
+		return dos_to_win_colour_map[colour];
+	}
+
+	if (colour >= 245 && colour < 254) return colour - 28;
+
+	return colour;
+}
+
 
 typedef bool (*VCI_Handler)(uint engine, int numinfo, int prop, byte **buf, int len);
 
@@ -1605,11 +1619,11 @@
 			break;
 
 		case 0x13: /* Colour for station rating bars */
-			FOR_EACH_OBJECT cs[i].rating_colour = grf_load_byte(&buf);
+			FOR_EACH_OBJECT cs[i].rating_colour = MapDOSColour(grf_load_byte(&buf));
 			break;
 
 		case 0x14: /* Colour for cargo graph */
-			FOR_EACH_OBJECT cs[i].legend_colour = grf_load_byte(&buf);
+			FOR_EACH_OBJECT cs[i].legend_colour = MapDOSColour(grf_load_byte(&buf));
 			break;
 
 		case 0x15: /* Freight status */
@@ -3142,7 +3156,7 @@
 		_skip_sprites = -1;
 
 		/* If an action 8 hasn't been encountered yet, disable the grf. */
-		if (_cur_grfconfig->status != GCS_ACTIVATED) _cur_grfconfig->status = GCS_DISABLED;
+		if (_cur_stage != GLS_RESERVE && _cur_grfconfig->status != GCS_ACTIVATED) _cur_grfconfig->status = GCS_DISABLED;
 	}
 }
 
@@ -4406,8 +4420,6 @@
 		}
 		_engine_info[engine].refit_mask = ((mask & ~not_mask) ^ xor_mask) & _cargo_mask;
 
-		if (_engine_info[engine].refit_mask == 0) continue;
-
 		/* Check if this engine's cargo type is valid. If not, set to the first refittable
 		 * cargo type. Apparently cargo_type isn't a common property... */
 		switch (GetEngine(engine)->type) {
@@ -4515,7 +4527,7 @@
 		/* 0x03 */ { NULL,     GRFUnsafe, NULL,            NULL,           NULL,              FeatureMapSpriteGroup, },
 		/* 0x04 */ { NULL,     NULL,      NULL,            NULL,           NULL,              FeatureNewName, },
 		/* 0x05 */ { NULL,     NULL,      NULL,            NULL,           NULL,              GraphicsNew, },
-		/* 0x06 */ { NULL,     NULL,      NULL,            CfgApply,       NULL,              CfgApply, },
+		/* 0x06 */ { NULL,     NULL,      NULL,            CfgApply,       CfgApply,          CfgApply, },
 		/* 0x07 */ { NULL,     NULL,      NULL,            NULL,           SkipIf,            SkipIf, },
 		/* 0x08 */ { ScanInfo, NULL,      NULL,            GRFInfo,        NULL,              GRFInfo, },
 		/* 0x09 */ { NULL,     NULL,      NULL,            SkipIf,         SkipIf,            SkipIf, },
--- a/src/newgrf_cargo.cpp	Thu Apr 19 14:43:25 2007 +0000
+++ b/src/newgrf_cargo.cpp	Thu Apr 19 14:48:10 2007 +0000
@@ -2,6 +2,7 @@
 
 #include "stdafx.h"
 #include "openttd.h"
+#include "debug.h"
 #include "cargotype.h"
 #include "newgrf.h"
 #include "newgrf_callbacks.h"
@@ -29,6 +30,8 @@
 
 static uint32 CargoGetVariable(const ResolverObject *object, byte variable, byte parameter, bool *available)
 {
+	DEBUG(grf, 1, "Unhandled cargo property 0x%X", variable);
+
 	*available = false;
 	return 0;
 }
--- a/src/newgrf_cargo.h	Thu Apr 19 14:43:25 2007 +0000
+++ b/src/newgrf_cargo.h	Thu Apr 19 14:48:10 2007 +0000
@@ -21,7 +21,7 @@
 static const CargoID CT_PURCHASE     = NUM_CARGO + 1;
 static const CargoID CT_DEFAULT_NA   = NUM_CARGO + 2;
 
-typedef struct CargoSpec;
+struct CargoSpec;
 
 SpriteID GetCustomCargoSprite(const CargoSpec *cs);
 uint16 GetCargoCallback(uint16 callback, uint32 param1, uint32 param2, const CargoSpec *cs);
--- a/src/newgrf_gui.cpp	Thu Apr 19 14:43:25 2007 +0000
+++ b/src/newgrf_gui.cpp	Thu Apr 19 14:48:10 2007 +0000
@@ -42,7 +42,7 @@
 }
 
 
-static void ShowNewGRFInfo(const GRFConfig *c, uint x, uint y, uint w, bool show_params)
+static void ShowNewGRFInfo(const GRFConfig *c, uint x, uint y, uint w, uint bottom, bool show_params)
 {
 	char buff[256];
 
@@ -62,24 +62,24 @@
 		GetString(message, c->error->message, lastof(message));
 
 		SetDParamStr(0, message);
-		y += DrawStringMultiLine(x, y, c->error->severity, w);
+		y += DrawStringMultiLine(x, y, c->error->severity, w, bottom - y);
 	}
 
 	/* Draw filename or not if it is not known (GRF sent over internet) */
 	if (c->filename != NULL) {
 		SetDParamStr(0, c->filename);
-		y += DrawStringMultiLine(x, y, STR_NEWGRF_FILENAME, w);
+		y += DrawStringMultiLine(x, y, STR_NEWGRF_FILENAME, w, bottom - y);
 	}
 
 	/* Prepare and draw GRF ID */
 	snprintf(buff, lengthof(buff), "%08X", BSWAP32(c->grfid));
 	SetDParamStr(0, buff);
-	y += DrawStringMultiLine(x, y, STR_NEWGRF_GRF_ID, w);
+	y += DrawStringMultiLine(x, y, STR_NEWGRF_GRF_ID, w, bottom - y);
 
 	/* Prepare and draw MD5 sum */
 	md5sumToString(buff, lastof(buff), c->md5sum);
 	SetDParamStr(0, buff);
-	y += DrawStringMultiLine(x, y, STR_NEWGRF_MD5SUM, w);
+	y += DrawStringMultiLine(x, y, STR_NEWGRF_MD5SUM, w, bottom - y);
 
 	/* Show GRF parameter list */
 	if (show_params) {
@@ -89,20 +89,20 @@
 		} else {
 			SetDParam(0, STR_01A9_NONE);
 		}
-		y += DrawStringMultiLine(x, y, STR_NEWGRF_PARAMETER, w);
+		y += DrawStringMultiLine(x, y, STR_NEWGRF_PARAMETER, w, bottom - y);
 	}
 
 	/* Show flags */
-	if (c->status == GCS_NOT_FOUND)        y += DrawStringMultiLine(x, y, STR_NEWGRF_NOT_FOUND, w);
-	if (c->status == GCS_DISABLED)         y += DrawStringMultiLine(x, y, STR_NEWGRF_DISABLED, w);
-	if (HASBIT(c->flags, GCF_COMPATIBLE)) y += DrawStringMultiLine(x, y, STR_NEWGRF_COMPATIBLE_LOADED, w);
+	if (c->status == GCS_NOT_FOUND)        y += DrawStringMultiLine(x, y, STR_NEWGRF_NOT_FOUND, w, bottom - y);
+	if (c->status == GCS_DISABLED)         y += DrawStringMultiLine(x, y, STR_NEWGRF_DISABLED, w, bottom - y);
+	if (HASBIT(c->flags, GCF_COMPATIBLE)) y += DrawStringMultiLine(x, y, STR_NEWGRF_COMPATIBLE_LOADED, w, bottom - y);
 
 	/* Draw GRF info if it exists */
 	if (c->info != NULL && !StrEmpty(c->info)) {
 		SetDParamStr(0, c->info);
-		y += DrawStringMultiLine(x, y, STR_02BD, w);
+		y += DrawStringMultiLine(x, y, STR_02BD, w, bottom - y);
 	} else {
-		y += DrawStringMultiLine(x, y, STR_NEWGRF_NO_INFO, w);
+		y += DrawStringMultiLine(x, y, STR_NEWGRF_NO_INFO, w, bottom - y);
 	}
 }
 
@@ -151,7 +151,7 @@
 
 			if (WP(w, newgrf_add_d).sel != NULL) {
 				const Widget *wi = &w->widget[5];
-				ShowNewGRFInfo(WP(w, newgrf_add_d).sel, wi->left + 2, wi->top + 2, wi->right - wi->left - 2, false);
+				ShowNewGRFInfo(WP(w, newgrf_add_d).sel, wi->left + 2, wi->top + 2, wi->right - wi->left - 2, wi->bottom, false);
 			}
 			break;
 		}
@@ -366,7 +366,7 @@
 			if (WP(w, newgrf_d).sel != NULL) {
 				/* Draw NewGRF file info */
 				const Widget *wi = &w->widget[SNGRFS_NEWGRF_INFO];
-				ShowNewGRFInfo(WP(w, newgrf_d).sel, wi->left + 2, wi->top + 2, wi->right - wi->left - 2, WP(w, newgrf_d).show_params);
+				ShowNewGRFInfo(WP(w, newgrf_d).sel, wi->left + 2, wi->top + 2, wi->right - wi->left - 2, wi->bottom, WP(w, newgrf_d).show_params);
 			}
 
 			break;
--- a/src/order_cmd.cpp	Thu Apr 19 14:43:25 2007 +0000
+++ b/src/order_cmd.cpp	Thu Apr 19 14:48:10 2007 +0000
@@ -463,6 +463,7 @@
  */
 static void RemoveSharedOrderVehicleList(Vehicle *v)
 {
+	assert(v->orders != NULL);
 	WindowClass window_class = WC_NONE;
 
 	switch (v->type) {
@@ -1159,7 +1160,7 @@
 
 		/* If we are the only one left in the Shared Order Vehicle List,
 		 *  remove it, as we are no longer a Shared Order Vehicle */
-		if (u->prev_shared == NULL && u->next_shared == NULL) RemoveSharedOrderVehicleList(u);
+		if (u->prev_shared == NULL && u->next_shared == NULL && u->orders != NULL) RemoveSharedOrderVehicleList(u);
 
 		/* We only need to update this-one, because if there is a third
 		 *  vehicle which shares the same order-list, nothing will change. If
--- a/src/rail_cmd.cpp	Thu Apr 19 14:43:25 2007 +0000
+++ b/src/rail_cmd.cpp	Thu Apr 19 14:48:10 2007 +0000
@@ -855,14 +855,23 @@
 
 typedef int32 DoConvertRailProc(TileIndex tile, RailType totype, bool exec);
 
+/**
+ * Switches the rail type.
+ * Railtypes are stored on a per-tile basis, not on a per-track basis, so
+ * all the tracks in the given tile will be converted.
+ * @param tile        The tile on which the railtype is to be convert.
+ * @param totype      The railtype we want to convert to
+ * @param exec        Switches between test and execute mode
+ * @return            The cost and state of the operation
+ * @retval CMD_ERROR  An error occured during the operation.
+ */
 static int32 DoConvertRail(TileIndex tile, RailType totype, bool exec)
 {
 	if (!CheckTileOwnership(tile)) return CMD_ERROR;
 
-	if (!EnsureNoVehicle(tile) && (!IsCompatibleRail(GetRailType(tile), totype) || IsPlainRailTile(tile))) return CMD_ERROR;
+	if (GetRailType(tile) == totype) return CMD_ERROR;
 
-	// tile is already of requested type?
-	if (GetRailType(tile) == totype) return CMD_ERROR;
+	if (!EnsureNoVehicle(tile) && (!IsCompatibleRail(GetRailType(tile), totype) || IsPlainRailTile(tile))) return CMD_ERROR;
 
 	// 'hidden' elrails can't be downgraded to normal rail when elrails are disabled
 	if (_patches.disable_elrails && totype == RAILTYPE_RAIL && GetRailType(tile) == RAILTYPE_ELECTRIC) return CMD_ERROR;
--- a/src/road_cmd.cpp	Thu Apr 19 14:43:25 2007 +0000
+++ b/src/road_cmd.cpp	Thu Apr 19 14:48:10 2007 +0000
@@ -371,6 +371,14 @@
 	return cost;
 }
 
+/**
+ * Switches the rail type on a level crossing.
+ * @param tile        The tile on which the railtype is to be convert.
+ * @param totype      The railtype we want to convert to
+ * @param exec        Switches between test and execute mode
+ * @return            The cost and state of the operation
+ * @retval CMD_ERROR  An error occured during the operation.
+ */
 int32 DoConvertStreetRail(TileIndex tile, RailType totype, bool exec)
 {
 	// not a railroad crossing?
--- a/src/road_map.h	Thu Apr 19 14:43:25 2007 +0000
+++ b/src/road_map.h	Thu Apr 19 14:48:10 2007 +0000
@@ -166,7 +166,7 @@
 
 /**
  * Returns the RoadBits on an arbitrary tile
- * Special behavior:
+ * Special behaviour:
  * - road depots: entrance is treated as road piece
  * - road tunnels: entrance is treated as road piece
  * - bridge ramps: start of the ramp is treated as road piece
--- a/src/settings.cpp	Thu Apr 19 14:43:25 2007 +0000
+++ b/src/settings.cpp	Thu Apr 19 14:48:10 2007 +0000
@@ -1266,12 +1266,12 @@
 	SDT_GENERAL("diff_custom", SDT_INTLIST, SL_ARR, (SLE_FILE_I16 | SLE_VAR_I32), 0, 0, GameOptions, diff, 17, 0, 0, 0, 0, NULL, STR_NULL, NULL, NULL,  0, 3),
 	SDT_GENERAL("diff_custom", SDT_INTLIST, SL_ARR, (SLE_FILE_I16 | SLE_VAR_I32), 0, 0, GameOptions, diff, 18, 0, 0, 0, 0, NULL, STR_NULL, NULL, NULL,  4, 53),
 	SDT_GENERAL("diff_custom", SDT_INTLIST, SL_ARR, (SLE_FILE_I16 | SLE_VAR_I32), 0, 0, GameOptions, diff, 20, 0, 0, 0, 0, NULL, STR_NULL, NULL, NULL, 54, SL_MAX_VERSION),
-	    SDT_VAR(GameOptions, diff_level,SLE_UINT8, 0, 0, 9, 0,  9, 0, STR_NULL, NULL),
+	    SDT_VAR(GameOptions, diff_level,SLE_UINT8, 0, 0, 0, 0,  3, 0, STR_NULL, NULL),
 	  SDT_OMANY(GameOptions, currency,  SLE_UINT8, N, 0, 0, CUSTOM_CURRENCY_ID, "GBP|USD|EUR|YEN|ATS|BEF|CHF|CZK|DEM|DKK|ESP|FIM|FRF|GRD|HUF|ISK|ITL|NLG|NOK|PLN|ROL|RUR|SIT|SEK|YTL|SKK|BRR|custom", STR_NULL, NULL, NULL),
 	  SDT_OMANY(GameOptions, units,     SLE_UINT8, N, 0, 1,     2, "imperial|metric|si", STR_NULL, NULL, NULL),
 	  SDT_OMANY(GameOptions, town_name, SLE_UINT8, 0, 0, 0,    20, "english|french|german|american|latin|silly|swedish|dutch|finnish|polish|slovakish|norwegian|hungarian|austrian|romanian|czech|swiss|danish|turkish|italian|catalan", STR_NULL, NULL, NULL),
 	  SDT_OMANY(GameOptions, landscape, SLE_UINT8, 0, 0, 0,     3, "temperate|arctic|tropic|toyland", STR_NULL, NULL, ConvertLandscape),
-	    SDT_VAR(GameOptions, snow_line, SLE_UINT8, 0, 0, 1, 0, 56, 0, STR_NULL, NULL),
+	    SDT_VAR(GameOptions, snow_line, SLE_UINT8, 0, 0, 7 * TILE_HEIGHT, 2 * TILE_HEIGHT, 13 * TILE_HEIGHT, 0, STR_NULL, NULL),
 	SDT_CONDOMANY(GameOptions,autosave, SLE_UINT8, 0, 22,             N, 0, 0, 0, "", STR_NULL, NULL, NULL),
 	SDT_CONDOMANY(GameOptions,autosave, SLE_UINT8,23, SL_MAX_VERSION, S, 0, 1, 4, "off|monthly|quarterly|half year|yearly", STR_NULL, NULL, NULL),
 	  SDT_OMANY(GameOptions, road_side, SLE_UINT8, 0, 0, 1,   1, "left|right", STR_NULL, NULL, NULL),
@@ -1510,7 +1510,7 @@
 static const SettingDesc _currency_settings[] = {
 	SDT_VAR(CurrencySpec, rate,    SLE_UINT16, S, 0,  1, 0, 100, 0, STR_NULL, NULL),
 	SDT_CHR(CurrencySpec, separator,           S, 0,        ".",    STR_NULL, NULL),
-	SDT_VAR(CurrencySpec, to_euro,  SLE_INT32, S, 0,  0, 0,1000, 0, STR_NULL, NULL),
+	SDT_VAR(CurrencySpec, to_euro,  SLE_INT32, S, 0,  0, 0,3000, 0, STR_NULL, NULL),
 	SDT_STR(CurrencySpec, prefix,   SLE_STRBQ, S, 0,       NULL,    STR_NULL, NULL),
 	SDT_STR(CurrencySpec, suffix,   SLE_STRBQ, S, 0, " credits",    STR_NULL, NULL),
 	SDT_END()
@@ -1680,14 +1680,18 @@
 #endif /* ENABLE_NETWORK */
 }
 
+extern void CheckDifficultyLevels();
+
 /** Load the values from the configuration files */
 void LoadFromConfig()
 {
 	IniFile *ini = ini_load(_config_file);
+	ResetCurrencies(false); // Initialize the array of curencies, without preserving the custom one
 	HandleSettingDescs(ini, ini_load_settings, ini_load_setting_list);
 	_grfconfig_newgame = GRFLoadConfig(ini, "newgrf", false);
 	_grfconfig_static  = GRFLoadConfig(ini, "newgrf-static", true);
 	_news_display_opt  = NewsDisplayLoadConfig(ini, "news_display");
+	CheckDifficultyLevels();
 	ini_free(ini);
 }
 
--- a/src/settings_gui.cpp	Thu Apr 19 14:43:25 2007 +0000
+++ b/src/settings_gui.cpp	Thu Apr 19 14:48:10 2007 +0000
@@ -373,6 +373,23 @@
 	}
 }
 
+/**
+ * Checks the difficulty levels read from the configuration and
+ * forces them to be correct when invalid.
+ */
+void CheckDifficultyLevels()
+{
+	if (_opt_newgame.diff_level != 3) {
+		SetDifficultyLevel(_opt_newgame.diff_level, &_opt_newgame);
+	} else {
+		for (uint i = 0; i < GAME_DIFFICULTY_NUM; i++) {
+			int *diff = ((int*)&_opt_newgame.diff) + i;
+			*diff = clamp(*diff, _game_setting_info[i].min, _game_setting_info[i].max);
+			*diff -= *diff % _game_setting_info[i].step;
+		}
+	}
+}
+
 extern void StartupEconomy();
 
 enum {
--- a/src/station_cmd.cpp	Thu Apr 19 14:43:25 2007 +0000
+++ b/src/station_cmd.cpp	Thu Apr 19 14:48:10 2007 +0000
@@ -1120,6 +1120,14 @@
 	return cost;
 }
 
+/**
+ * Switches the rail type at a railway station tile.
+ * @param tile        The tile on which the railtype is to be convert.
+ * @param totype      The railtype we want to convert to
+ * @param exec        Switches between test and execute mode
+ * @return            The cost and state of the operation
+ * @retval CMD_ERROR  An error occured during the operation.
+ */
 int32 DoConvertStationRail(TileIndex tile, RailType totype, bool exec)
 {
 	const Station* st = GetStationByTile(tile);
--- a/src/table/build_industry.h	Thu Apr 19 14:43:25 2007 +0000
+++ b/src/table/build_industry.h	Thu Apr 19 14:48:10 2007 +0000
@@ -1083,9 +1083,9 @@
 	CHECK_END,
 };
 
-#define MK(tbl, d, c1, c2, c3, proc, p1, r1, p2, r2, m, a1, a2, a3, pr, clim, in, intx, s1, s2, s3) \
+#define MK(tbl, d, c1, c2, c3, proc, p1, r1, p2, r2, m, a1, a2, a3, pr, clim, bev, in, intx, s1, s2, s3) \
 	{tbl, lengthof(tbl), d, {c1, c2, c3}, proc, {p1, p2}, {r1, r2}, m,            \
-	 {a1, a2, a3}, pr, clim, in, intx, s1, s2, s3}
+	 {a1, a2, a3}, pr, clim, bev, in, intx, s1, s2, s3}
 
 static const IndustrySpec _industry_specs[] = {
 	/* Format:
@@ -1094,6 +1094,7 @@
 	   (produced cargo + rate) (twice)         minimum cargo moved to station
 	   3 accepted cargo
 	   industry life                           climate availability
+	   industry behaviours
 	   industry name                           building text
 	   messages : Closure                      production up                      production down   */
 	MK(_tile_table_coal_mine,                  210,
@@ -1101,6 +1102,7 @@
 	   CT_COAL,       15, CT_INVALID,       0, 5,
 	   CT_INVALID,        CT_INVALID,          CT_INVALID,
 	   INDUSTRYLIFE_PRODUCTION,                1 << LT_TEMPERATE | 1 << LT_ARCTIC,
+	   INDUSTRYBEH_CAN_SUBSIDENCE,
 	   STR_4802_COAL_MINE,                     STR_482D_NEW_UNDER_CONSTRUCTION,
 	   STR_4832_ANNOUNCES_IMMINENT_CLOSURE,    STR_4836_NEW_COAL_SEAM_FOUND_AT,   STR_4839_PRODUCTION_DOWN_BY_50),
 
@@ -1109,6 +1111,7 @@
 	   CT_INVALID,     0, CT_INVALID,       0, 5,
 	   CT_COAL,           CT_INVALID,          CT_INVALID,
 	   INDUSTRYLIFE_NOT_CLOSABLE,              1 << LT_TEMPERATE | 1 << LT_ARCTIC,
+	   INDUSTRYBEH_NONE,
 	   STR_4803_POWER_STATION,                 STR_482D_NEW_UNDER_CONSTRUCTION,
 	   STR_4832_ANNOUNCES_IMMINENT_CLOSURE,    STR_4835_INCREASES_PRODUCTION,     STR_4839_PRODUCTION_DOWN_BY_50),
 
@@ -1117,6 +1120,7 @@
 	   CT_GOODS,       0, CT_INVALID,       0, 5,
 	   CT_WOOD,           CT_INVALID,          CT_INVALID,
 	   INDUSTRYLIFE_CLOSABLE,                  1 << LT_TEMPERATE,
+	   INDUSTRYBEH_CUT_TREES,
 	   STR_4804_SAWMILL,                       STR_482D_NEW_UNDER_CONSTRUCTION,
 	   STR_4833_SUPPLY_PROBLEMS_CAUSE_TO,      STR_4835_INCREASES_PRODUCTION,     STR_4839_PRODUCTION_DOWN_BY_50),
 
@@ -1125,6 +1129,7 @@
 	   CT_WOOD,       13, CT_INVALID,       0, 30,
 	   CT_INVALID,        CT_INVALID,          CT_INVALID,
 	   INDUSTRYLIFE_PRODUCTION,                1 << LT_TEMPERATE | 1 << LT_ARCTIC,
+	   INDUSTRYBEH_NONE,
 	   STR_4805_FOREST,                        STR_482E_NEW_BEING_PLANTED_NEAR,
 	   STR_4832_ANNOUNCES_IMMINENT_CLOSURE,    STR_4835_INCREASES_PRODUCTION,     STR_483A_INSECT_INFESTATION_CAUSES),
 
@@ -1133,6 +1138,7 @@
 	   CT_GOODS,       0, CT_INVALID,       0, 5,
 	   CT_OIL,            CT_INVALID,          CT_INVALID,
 	   INDUSTRYLIFE_CLOSABLE,                  1 << LT_TEMPERATE | 1 << LT_ARCTIC | 1 << LT_TROPIC,
+	   INDUSTRYBEH_AIRPLANE_ATTACKS,
 	   STR_4806_OIL_REFINERY,                  STR_482D_NEW_UNDER_CONSTRUCTION,
 	   STR_4833_SUPPLY_PROBLEMS_CAUSE_TO,      STR_4835_INCREASES_PRODUCTION,     STR_4839_PRODUCTION_DOWN_BY_50),
 
@@ -1141,6 +1147,7 @@
 	   CT_OIL,        15, CT_PASSENGERS,    2, 5,
 	   CT_INVALID,        CT_INVALID,          CT_INVALID,
 	   INDUSTRYLIFE_PRODUCTION,                1 << LT_TEMPERATE,
+	   INDUSTRYBEH_BUILT_ONWATER | INDUSTRYBEH_AFTER_1960 | INDUSTRYBEH_AI_AIRSHIP_ROUTES,
 	   STR_4807_OIL_RIG,                       STR_482D_NEW_UNDER_CONSTRUCTION,
 	   STR_4832_ANNOUNCES_IMMINENT_CLOSURE,    STR_4837_NEW_OIL_RESERVES_FOUND,   STR_4839_PRODUCTION_DOWN_BY_50),
 
@@ -1149,6 +1156,7 @@
 	   CT_GOODS,       0, CT_INVALID,       0, 5,
 	   CT_LIVESTOCK,      CT_GRAIN,            CT_STEEL,
 	   INDUSTRYLIFE_CLOSABLE,                  1 << LT_TEMPERATE,
+	   INDUSTRYBEH_CHOPPER_ATTACKS,
 	   STR_4808_FACTORY,                       STR_482D_NEW_UNDER_CONSTRUCTION,
 	   STR_4833_SUPPLY_PROBLEMS_CAUSE_TO,      STR_4835_INCREASES_PRODUCTION,     STR_4839_PRODUCTION_DOWN_BY_50),
 
@@ -1157,6 +1165,7 @@
 	   CT_GOODS,       0, CT_INVALID,       0, 5,
 	   CT_PAPER,          CT_INVALID,          CT_INVALID,
 	   INDUSTRYLIFE_CLOSABLE,                  1 << LT_ARCTIC,
+	   INDUSTRYBEH_NONE,
 	   STR_4809_PRINTING_WORKS,                STR_482D_NEW_UNDER_CONSTRUCTION,
 	   STR_4833_SUPPLY_PROBLEMS_CAUSE_TO,      STR_4835_INCREASES_PRODUCTION,     STR_4839_PRODUCTION_DOWN_BY_50),
 
@@ -1165,6 +1174,7 @@
 	   CT_STEEL,       0, CT_INVALID,       0, 5,
 	   CT_IRON_ORE,       CT_INVALID,          CT_INVALID,
 	   INDUSTRYLIFE_CLOSABLE,                  1 << LT_TEMPERATE,
+	   INDUSTRYBEH_NONE,
 	   STR_480A_STEEL_MILL,                    STR_482D_NEW_UNDER_CONSTRUCTION,
 	   STR_4833_SUPPLY_PROBLEMS_CAUSE_TO,      STR_4835_INCREASES_PRODUCTION,     STR_4839_PRODUCTION_DOWN_BY_50),
 
@@ -1173,6 +1183,7 @@
 	   CT_GRAIN,      10, CT_LIVESTOCK,    10, 5,
 	   CT_INVALID,        CT_INVALID,          CT_INVALID,
 	   INDUSTRYLIFE_PRODUCTION,                1 << LT_TEMPERATE | 1 << LT_ARCTIC,
+	   INDUSTRYBEH_PLANT_FIELDS | INDUSTRYBEH_PLANT_ON_BUILT,
 	   STR_480B_FARM,                          STR_482D_NEW_UNDER_CONSTRUCTION,
 	   STR_4832_ANNOUNCES_IMMINENT_CLOSURE,    STR_4838_IMPROVED_FARMING_METHODS, STR_483A_INSECT_INFESTATION_CAUSES),
 
@@ -1181,6 +1192,7 @@
 	   CT_COPPER_ORE, 10, CT_INVALID,       0, 5,
 	   CT_INVALID,        CT_INVALID,          CT_INVALID,
 	   INDUSTRYLIFE_PRODUCTION,                1 << LT_TROPIC,
+	   INDUSTRYBEH_NONE,
 	   STR_480C_COPPER_ORE_MINE,               STR_482D_NEW_UNDER_CONSTRUCTION,
 	   STR_4832_ANNOUNCES_IMMINENT_CLOSURE,    STR_4835_INCREASES_PRODUCTION,     STR_4839_PRODUCTION_DOWN_BY_50),
 
@@ -1189,6 +1201,7 @@
 	   CT_OIL,        12, CT_INVALID,       0, 5,
 	   CT_INVALID,        CT_INVALID,          CT_INVALID,
 	   INDUSTRYLIFE_PRODUCTION,                1 << LT_TEMPERATE | 1 << LT_ARCTIC | 1 << LT_TROPIC,
+	   INDUSTRYBEH_DONT_INCR_PROD | INDUSTRYBEH_BEFORE_1950,
 	   STR_480D_OIL_WELLS,                     STR_482D_NEW_UNDER_CONSTRUCTION,
 	   STR_4832_ANNOUNCES_IMMINENT_CLOSURE,    STR_4837_NEW_OIL_RESERVES_FOUND,   STR_4839_PRODUCTION_DOWN_BY_50),
 
@@ -1197,6 +1210,7 @@
 	   CT_VALUABLES,   6, CT_INVALID,       0, 5,
 	   CT_VALUABLES,      CT_INVALID,          CT_INVALID,
 	   INDUSTRYLIFE_NOT_CLOSABLE,              1 << LT_TEMPERATE,
+	   INDUSTRYBEH_TOWN1200_MORE | INDUSTRYBEH_ONLY_INTOWN,
 	   STR_480E_BANK,                          STR_482D_NEW_UNDER_CONSTRUCTION,
 	   STR_4832_ANNOUNCES_IMMINENT_CLOSURE,    STR_4835_INCREASES_PRODUCTION,     STR_4839_PRODUCTION_DOWN_BY_50),
 
@@ -1205,6 +1219,7 @@
 	   CT_FOOD,        0, CT_INVALID,       0, 5,
 	   CT_FRUIT,          CT_MAIZE,            CT_INVALID,
 	   INDUSTRYLIFE_CLOSABLE,                  1 << LT_ARCTIC | 1 << LT_TROPIC,
+	   INDUSTRYBEH_NONE,
 	   STR_480F_FOOD_PROCESSING_PLANT,         STR_482D_NEW_UNDER_CONSTRUCTION,
 	   STR_4833_SUPPLY_PROBLEMS_CAUSE_TO,      STR_4835_INCREASES_PRODUCTION,     STR_4839_PRODUCTION_DOWN_BY_50),
 
@@ -1213,6 +1228,7 @@
 	   CT_PAPER,       0, CT_INVALID,       0, 5,
 	   CT_WOOD,           CT_INVALID,          CT_INVALID,
 	   INDUSTRYLIFE_CLOSABLE,                  1 << LT_ARCTIC,
+	   INDUSTRYBEH_NONE,
 	   STR_4810_PAPER_MILL,                    STR_482D_NEW_UNDER_CONSTRUCTION,
 	   STR_4833_SUPPLY_PROBLEMS_CAUSE_TO,      STR_4835_INCREASES_PRODUCTION,     STR_4839_PRODUCTION_DOWN_BY_50),
 
@@ -1221,6 +1237,7 @@
 	   CT_GOLD,        7, CT_INVALID,       0, 5,
 	   CT_INVALID,        CT_INVALID,          CT_INVALID,
 	   INDUSTRYLIFE_PRODUCTION,                1 << LT_TROPIC,
+	   INDUSTRYBEH_NONE,
 	   STR_4811_GOLD_MINE,                     STR_482D_NEW_UNDER_CONSTRUCTION,
 	   STR_4832_ANNOUNCES_IMMINENT_CLOSURE,    STR_4835_INCREASES_PRODUCTION,     STR_4839_PRODUCTION_DOWN_BY_50),
 
@@ -1229,6 +1246,7 @@
 	   CT_INVALID,     0, CT_INVALID,       0, 5,
 	   CT_GOLD,           CT_INVALID,          CT_INVALID,
 	   INDUSTRYLIFE_NOT_CLOSABLE,              1 << LT_ARCTIC | 1 << LT_TROPIC,
+	   INDUSTRYBEH_ONLY_INTOWN,
 	   STR_4812_BANK,                          STR_482D_NEW_UNDER_CONSTRUCTION,
 	   STR_4832_ANNOUNCES_IMMINENT_CLOSURE,    STR_4835_INCREASES_PRODUCTION,     STR_4839_PRODUCTION_DOWN_BY_50),
 
@@ -1237,6 +1255,7 @@
 	   CT_DIAMONDS,    7, CT_INVALID,       0, 5,
 	   CT_INVALID,        CT_INVALID,          CT_INVALID,
 	   INDUSTRYLIFE_PRODUCTION,                1 << LT_TROPIC,
+	   INDUSTRYBEH_NONE,
 	   STR_4813_DIAMOND_MINE,                  STR_482D_NEW_UNDER_CONSTRUCTION,
 	   STR_4832_ANNOUNCES_IMMINENT_CLOSURE,    STR_4835_INCREASES_PRODUCTION,     STR_4839_PRODUCTION_DOWN_BY_50),
 
@@ -1245,6 +1264,7 @@
 	   CT_IRON_ORE,   10, CT_INVALID,       0, 5,
 	   CT_INVALID,        CT_INVALID,          CT_INVALID,
 	   INDUSTRYLIFE_PRODUCTION,                1 << LT_TEMPERATE,
+	   INDUSTRYBEH_NONE,
 	   STR_4814_IRON_ORE_MINE,                 STR_482D_NEW_UNDER_CONSTRUCTION,
 	   STR_4832_ANNOUNCES_IMMINENT_CLOSURE,    STR_4835_INCREASES_PRODUCTION,     STR_4839_PRODUCTION_DOWN_BY_50),
 
@@ -1253,6 +1273,7 @@
 	   CT_FRUIT,      10, CT_INVALID,       0, 15,
 	   CT_INVALID,        CT_INVALID,          CT_INVALID,
 	   INDUSTRYLIFE_PRODUCTION,                1 << LT_TROPIC,
+	   INDUSTRYBEH_NONE,
 	   STR_4815_FRUIT_PLANTATION,              STR_482E_NEW_BEING_PLANTED_NEAR,
 	   STR_4832_ANNOUNCES_IMMINENT_CLOSURE,    STR_4838_IMPROVED_FARMING_METHODS, STR_483A_INSECT_INFESTATION_CAUSES),
 
@@ -1261,6 +1282,7 @@
 	   CT_RUBBER,     10, CT_INVALID,       0, 15,
 	   CT_INVALID,        CT_INVALID,          CT_INVALID,
 	   INDUSTRYLIFE_PRODUCTION,                1 << LT_TROPIC,
+	   INDUSTRYBEH_NONE,
 	   STR_4816_RUBBER_PLANTATION,             STR_482E_NEW_BEING_PLANTED_NEAR,
 	   STR_4832_ANNOUNCES_IMMINENT_CLOSURE,    STR_4838_IMPROVED_FARMING_METHODS, STR_483A_INSECT_INFESTATION_CAUSES),
 
@@ -1269,6 +1291,7 @@
 	   CT_WATER,      12, CT_INVALID,       0, 5,
 	   CT_INVALID,        CT_INVALID,          CT_INVALID,
 	   INDUSTRYLIFE_PRODUCTION,                1 << LT_TROPIC,
+	   INDUSTRYBEH_NONE,
 	   STR_4817_WATER_SUPPLY,                  STR_482D_NEW_UNDER_CONSTRUCTION,
 	   STR_4832_ANNOUNCES_IMMINENT_CLOSURE,    STR_4835_INCREASES_PRODUCTION,     STR_4839_PRODUCTION_DOWN_BY_50),
 
@@ -1277,6 +1300,7 @@
 	   CT_INVALID,     0, CT_INVALID,       0, 5,
 	   CT_WATER,          CT_INVALID,          CT_INVALID,
 	   INDUSTRYLIFE_NOT_CLOSABLE,              1 << LT_TROPIC,
+	   INDUSTRYBEH_ONLY_INTOWN,
 	   STR_4818_WATER_TOWER,                   STR_482D_NEW_UNDER_CONSTRUCTION,
 	   STR_4832_ANNOUNCES_IMMINENT_CLOSURE,    STR_4835_INCREASES_PRODUCTION,     STR_4839_PRODUCTION_DOWN_BY_50),
 
@@ -1285,6 +1309,7 @@
 	   CT_GOODS,       0, CT_INVALID,       0, 5,
 	   CT_RUBBER,         CT_COPPER_ORE,       CT_WOOD,
 	   INDUSTRYLIFE_CLOSABLE,                  1 << LT_TROPIC,
+	   INDUSTRYBEH_NONE,
 	   STR_4819_FACTORY,                       STR_482D_NEW_UNDER_CONSTRUCTION,
 	   STR_4833_SUPPLY_PROBLEMS_CAUSE_TO,      STR_4835_INCREASES_PRODUCTION,     STR_4839_PRODUCTION_DOWN_BY_50),
 
@@ -1293,6 +1318,7 @@
 	   CT_MAIZE,      11, CT_INVALID,       0, 5,
 	   CT_INVALID,        CT_INVALID,          CT_INVALID,
 	   INDUSTRYLIFE_PRODUCTION,                1 << LT_TROPIC,
+	   INDUSTRYBEH_PLANT_FIELDS | INDUSTRYBEH_PLANT_ON_BUILT,
 	   STR_481A_FARM,                          STR_482D_NEW_UNDER_CONSTRUCTION,
 	   STR_4832_ANNOUNCES_IMMINENT_CLOSURE,    STR_4838_IMPROVED_FARMING_METHODS, STR_483A_INSECT_INFESTATION_CAUSES),
 
@@ -1301,6 +1327,7 @@
 	   CT_WOOD,        0, CT_INVALID,       0, 5,
 	   CT_INVALID,        CT_INVALID,          CT_INVALID,
 	   INDUSTRYLIFE_CLOSABLE,                  1 << LT_TROPIC,
+	   INDUSTRYBEH_CUT_TREES,
 	   STR_481B_LUMBER_MILL,                   STR_482D_NEW_UNDER_CONSTRUCTION,
 	   STR_4834_LACK_OF_NEARBY_TREES_CAUSES,   STR_4835_INCREASES_PRODUCTION,     STR_4839_PRODUCTION_DOWN_BY_50),
 
@@ -1309,6 +1336,7 @@
 	   CT_COTTON_CANDY, 13, CT_INVALID,    0, 30,
 	   CT_INVALID,        CT_INVALID,          CT_INVALID,
 	   INDUSTRYLIFE_PRODUCTION,                1 << LT_TOYLAND,
+	   INDUSTRYBEH_NONE,
 	   STR_481C_COTTON_CANDY_FOREST,           STR_482E_NEW_BEING_PLANTED_NEAR,
 	   STR_4832_ANNOUNCES_IMMINENT_CLOSURE,    STR_4838_IMPROVED_FARMING_METHODS, STR_4839_PRODUCTION_DOWN_BY_50),
 
@@ -1317,6 +1345,7 @@
 	   CT_CANDY,       0, CT_INVALID,       0, 5,
 	   CT_SUGAR,          CT_TOFFEE,           CT_COTTON_CANDY,
 	   INDUSTRYLIFE_CLOSABLE,                  1 << LT_TOYLAND,
+	   INDUSTRYBEH_NONE,
 	   STR_481D_CANDY_FACTORY,                 STR_482D_NEW_UNDER_CONSTRUCTION,
 	   STR_4833_SUPPLY_PROBLEMS_CAUSE_TO,      STR_4835_INCREASES_PRODUCTION,     STR_4839_PRODUCTION_DOWN_BY_50),
 
@@ -1325,6 +1354,7 @@
 	   CT_BATTERIES,  11, CT_INVALID,      0, 30,
 	   CT_INVALID,        CT_INVALID,          CT_INVALID,
 	   INDUSTRYLIFE_PRODUCTION,                1 << LT_TOYLAND,
+	   INDUSTRYBEH_NONE,
 	   STR_481E_BATTERY_FARM,                  STR_482D_NEW_UNDER_CONSTRUCTION,
 	   STR_4832_ANNOUNCES_IMMINENT_CLOSURE,    STR_4838_IMPROVED_FARMING_METHODS, STR_483A_INSECT_INFESTATION_CAUSES),
 
@@ -1333,6 +1363,7 @@
 	   CT_COLA,       12, CT_INVALID,       0, 5,
 	   CT_INVALID,        CT_INVALID,          CT_INVALID,
 	   INDUSTRYLIFE_PRODUCTION,                1 << LT_TOYLAND,
+	   INDUSTRYBEH_NONE,
 	   STR_481F_COLA_WELLS,                    STR_482D_NEW_UNDER_CONSTRUCTION,
 	   STR_4832_ANNOUNCES_IMMINENT_CLOSURE,    STR_4835_INCREASES_PRODUCTION,     STR_4839_PRODUCTION_DOWN_BY_50),
 
@@ -1341,6 +1372,7 @@
 	   CT_INVALID,     0, CT_INVALID,       0, 5,
 	   CT_TOYS,           CT_INVALID,          CT_INVALID,
 	   INDUSTRYLIFE_NOT_CLOSABLE,              1 << LT_TOYLAND,
+	   INDUSTRYBEH_ONLY_NEARTOWN,
 	   STR_4820_TOY_SHOP,                      STR_482D_NEW_UNDER_CONSTRUCTION,
 	   STR_4833_SUPPLY_PROBLEMS_CAUSE_TO,      STR_4835_INCREASES_PRODUCTION,     STR_4839_PRODUCTION_DOWN_BY_50),
 
@@ -1349,6 +1381,7 @@
 	   CT_TOYS,        0, CT_INVALID,       0, 5,
 	   CT_PLASTIC,        CT_BATTERIES,        CT_INVALID,
 	   INDUSTRYLIFE_CLOSABLE,                  1 << LT_TOYLAND,
+	   INDUSTRYBEH_NONE,
 	   STR_4821_TOY_FACTORY,                   STR_482D_NEW_UNDER_CONSTRUCTION,
 	   STR_4833_SUPPLY_PROBLEMS_CAUSE_TO,      STR_4835_INCREASES_PRODUCTION,     STR_4839_PRODUCTION_DOWN_BY_50),
 
@@ -1357,6 +1390,7 @@
 	   CT_PLASTIC,    14, CT_INVALID,       0, 5,
 	   CT_INVALID,        CT_INVALID,          CT_INVALID,
 	   INDUSTRYLIFE_PRODUCTION,                1 << LT_TOYLAND,
+	   INDUSTRYBEH_NONE,
 	   STR_4822_PLASTIC_FOUNTAINS,             STR_482D_NEW_UNDER_CONSTRUCTION,
 	   STR_4832_ANNOUNCES_IMMINENT_CLOSURE,    STR_4835_INCREASES_PRODUCTION,     STR_4839_PRODUCTION_DOWN_BY_50),
 
@@ -1365,6 +1399,7 @@
 	   CT_FIZZY_DRINKS, 0, CT_INVALID,      0, 5,
 	   CT_COLA,           CT_BUBBLES,          CT_INVALID,
 	   INDUSTRYLIFE_CLOSABLE,                  1 << LT_TOYLAND,
+	   INDUSTRYBEH_NONE,
 	   STR_4823_FIZZY_DRINK_FACTORY,           STR_482D_NEW_UNDER_CONSTRUCTION,
 	   STR_4833_SUPPLY_PROBLEMS_CAUSE_TO,      STR_4835_INCREASES_PRODUCTION,     STR_4839_PRODUCTION_DOWN_BY_50),
 
@@ -1373,6 +1408,7 @@
 	   CT_BUBBLES,    13, CT_INVALID,       0, 5,
 	   CT_INVALID,        CT_INVALID,          CT_INVALID,
 	   INDUSTRYLIFE_PRODUCTION,                1 << LT_TOYLAND,
+	   INDUSTRYBEH_NONE,
 	   STR_4824_BUBBLE_GENERATOR,              STR_482D_NEW_UNDER_CONSTRUCTION,
 	   STR_4832_ANNOUNCES_IMMINENT_CLOSURE,    STR_4835_INCREASES_PRODUCTION,     STR_4839_PRODUCTION_DOWN_BY_50),
 
@@ -1381,6 +1417,7 @@
 	   CT_TOFFEE,     10, CT_INVALID,       0, 5,
 	   CT_INVALID,        CT_INVALID,          CT_INVALID,
 	   INDUSTRYLIFE_PRODUCTION,                1 << LT_TOYLAND,
+	   INDUSTRYBEH_NONE,
 	   STR_4825_TOFFEE_QUARRY,                 STR_482D_NEW_UNDER_CONSTRUCTION,
 	   STR_4832_ANNOUNCES_IMMINENT_CLOSURE,    STR_4835_INCREASES_PRODUCTION,     STR_4839_PRODUCTION_DOWN_BY_50),
 
@@ -1389,6 +1426,7 @@
 	   CT_SUGAR,      11, CT_INVALID,       0, 5,
 	   CT_INVALID,        CT_INVALID,          CT_INVALID,
 	   INDUSTRYLIFE_PRODUCTION,                1 << LT_TOYLAND,
+	   INDUSTRYBEH_NONE,
 	   STR_4826_SUGAR_MINE,                    STR_482D_NEW_UNDER_CONSTRUCTION,
 	   STR_4832_ANNOUNCES_IMMINENT_CLOSURE,    STR_4835_INCREASES_PRODUCTION,     STR_4839_PRODUCTION_DOWN_BY_50),
 };
--- a/src/texteff.cpp	Thu Apr 19 14:43:25 2007 +0000
+++ b/src/texteff.cpp	Thu Apr 19 14:48:10 2007 +0000
@@ -156,6 +156,7 @@
 		if (x + width >= _screen.width) {
 			width = _screen.width - x;
 		}
+		if (width <= 0 || height <= 0) return;
 
 		_textmessage_visible = false;
 		/* Put our 'shot' back to the screen */
@@ -220,6 +221,8 @@
 	if (x + width >= _screen.width) {
 		width = _screen.width - x;
 	}
+	if (width <= 0 || height <= 0) return;
+
 	/* Make a copy of the screen as it is before painting (for undraw) */
 	memcpy_pitch(
 		_textmessage_backup,
--- a/src/tunnelbridge_cmd.cpp	Thu Apr 19 14:43:25 2007 +0000
+++ b/src/tunnelbridge_cmd.cpp	Thu Apr 19 14:48:10 2007 +0000
@@ -696,6 +696,16 @@
 	return CMD_ERROR;
 }
 
+/**
+ * Switches the rail type for a tunnel or a bridgehead. As the railtype
+ * on the bridge are determined by the one of the bridgehead, this
+ * functions converts the railtype on the entire bridge.
+ * @param tile        The tile on which the railtype is to be convert.
+ * @param totype      The railtype we want to convert to
+ * @param exec        Switches between test and execute mode
+ * @return            The cost and state of the operation
+ * @retval CMD_ERROR  An error occured during the operation.
+ */
 int32 DoConvertTunnelBridgeRail(TileIndex tile, RailType totype, bool exec)
 {
 	TileIndex endtile;
--- a/src/vehicle_gui.h	Thu Apr 19 14:43:25 2007 +0000
+++ b/src/vehicle_gui.h	Thu Apr 19 14:48:10 2007 +0000
@@ -32,7 +32,7 @@
 
 void PlayerVehWndProc(Window *w, WindowEvent *e);
 
-void DrawVehiclePurchaseInfo(int x, int y, uint w, EngineID engine_number);
+int DrawVehiclePurchaseInfo(int x, int y, uint w, EngineID engine_number);
 
 void DrawTrainImage(const Vehicle *v, int x, int y, int count, int skip, VehicleID selection);
 void DrawRoadVehImage(const Vehicle *v, int x, int y, VehicleID selection);