(svn r12503) [NoAI] -Sync: with trunk r12461:12501. noai
authorrubidium
Mon, 31 Mar 2008 07:50:27 +0000
branchnoai
changeset 9837 c9ec4f82e0d0
parent 9836 54afebfded49
child 9838 0839682a601b
(svn r12503) [NoAI] -Sync: with trunk r12461:12501.
config.lib
projects/openttd_vs80.vcproj
projects/openttd_vs80.vcproj.in
projects/openttd_vs90.vcproj
projects/openttd_vs90.vcproj.in
source.list
src/ai/api/ai_airport.cpp
src/ai/api/ai_base.cpp
src/ai/api/ai_engine.cpp
src/ai/api/ai_enginelist.cpp
src/ai/api/ai_object.cpp
src/ai/api/ai_object.hpp
src/ai/api/ai_order.cpp
src/ai/api/ai_sign.cpp
src/ai/api/ai_station.cpp
src/ai/api/ai_station.hpp
src/ai/api/ai_stationlist.cpp
src/ai/api/ai_tile.cpp
src/ai/api/ai_tilelist.cpp
src/ai/api/ai_vehicle.cpp
src/ai/api/ai_vehicle.hpp
src/ai/api/ai_vehiclelist.cpp
src/ai/api/ai_vehiclelist.hpp
src/aircraft.h
src/aircraft_cmd.cpp
src/aircraft_gui.cpp
src/airport_gui.cpp
src/articulated_vehicles.cpp
src/articulated_vehicles.h
src/autoreplace_cmd.cpp
src/autoreplace_gui.cpp
src/build_vehicle_gui.cpp
src/cargopacket.cpp
src/cargopacket.h
src/console_cmds.cpp
src/depot.cpp
src/depot.h
src/depot_gui.cpp
src/depot_type.h
src/disaster_cmd.cpp
src/dock_gui.cpp
src/economy.cpp
src/economy_func.h
src/elrail.cpp
src/engine.cpp
src/engine.h
src/engine_func.h
src/engine_gui.cpp
src/engine_type.h
src/genworld.cpp
src/group.h
src/group_cmd.cpp
src/group_gui.cpp
src/group_type.h
src/helpers.cpp
src/industry_cmd.cpp
src/industry_gui.cpp
src/main_gui.cpp
src/misc.cpp
src/misc_gui.cpp
src/network/network_internal.h
src/network/network_server.cpp
src/newgrf.cpp
src/newgrf.h
src/newgrf_engine.cpp
src/newgrf_sound.cpp
src/newgrf_sound.h
src/newgrf_spritegroup.h
src/newgrf_station.cpp
src/newgrf_station.h
src/newgrf_text.cpp
src/news_gui.cpp
src/npf.cpp
src/npf.h
src/oldloader.cpp
src/openttd.cpp
src/openttd.h
src/order.h
src/order_base.h
src/order_cmd.cpp
src/order_func.h
src/order_gui.cpp
src/order_type.h
src/ottdres.rc.in
src/player_base.h
src/players.cpp
src/rail.cpp
src/rail_cmd.cpp
src/rail_gui.cpp
src/rail_map.h
src/resource.h
src/road.cpp
src/road_gui.cpp
src/road_map.cpp
src/roadveh.h
src/roadveh_cmd.cpp
src/roadveh_gui.cpp
src/saveload.cpp
src/settings_gui.cpp
src/ship.h
src/ship_cmd.cpp
src/ship_gui.cpp
src/signs.cpp
src/signs.h
src/signs_base.h
src/signs_func.h
src/signs_gui.cpp
src/signs_type.h
src/sound/win32_s.cpp
src/station.cpp
src/station.h
src/station_base.h
src/station_cmd.cpp
src/station_func.h
src/station_gui.cpp
src/station_map.h
src/station_type.h
src/strings.cpp
src/subsidy_gui.cpp
src/terraform_gui.cpp
src/texteff.hpp
src/timetable_gui.cpp
src/town_cmd.cpp
src/train_cmd.cpp
src/train_gui.cpp
src/tunnelbridge_cmd.cpp
src/unmovable_cmd.cpp
src/vehicle.cpp
src/vehicle_base.h
src/vehicle_func.h
src/vehicle_gui.cpp
src/vehicle_gui.h
src/viewport.cpp
src/water_cmd.cpp
src/waypoint.cpp
src/waypoint.h
src/waypoint_type.h
src/window_gui.h
src/yapf/yapf.h
src/yapf/yapf.hpp
--- a/config.lib	Mon Mar 31 07:37:51 2008 +0000
+++ b/config.lib	Mon Mar 31 07:50:27 2008 +0000
@@ -41,7 +41,7 @@
 	enable_translator="0"
 	enable_unicode="1"
 	enable_assert="1"
-	enable_strip="1"
+	enable_strip="0"
 	enable_universal="1"
 	enable_osx_g5="0"
 	enable_cocoa_quartz="1"
@@ -2341,7 +2341,7 @@
 	echo "                                 version (Win32 ONLY)"
 	echo "  --disable-network              disable network support"
 	echo "  --disable-assert               disable asserts (continue on errors)"
-	echo "  --disable-strip                disable any possible stripping"
+	echo "  --enable-strip                 enable any possible stripping"
 	echo "  --without-osx-sysroot          disable the automatic adding of sysroot "
 	echo "                                 (OSX ONLY)"
 	echo "  --without-application-bundle   disable generation of application bundle"
--- a/projects/openttd_vs80.vcproj	Mon Mar 31 07:37:51 2008 +0000
+++ b/projects/openttd_vs80.vcproj	Mon Mar 31 07:50:27 2008 +0000
@@ -61,7 +61,7 @@
 				FavorSizeOrSpeed="2"
 				OmitFramePointers="true"
 				AdditionalIncludeDirectories="..\objs\langs;..\src\3rdparty\squirrel\include"
-				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\""
+				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";WITH_ASSERT"
 				StringPooling="true"
 				ExceptionHandling="1"
 				RuntimeLibrary="0"
@@ -272,7 +272,7 @@
 				FavorSizeOrSpeed="2"
 				OmitFramePointers="true"
 				AdditionalIncludeDirectories="..\objs\langs;..\src\3rdparty\squirrel\include"
-				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\""
+				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\"OpenTTD\";WITH_ASSERT"
 				StringPooling="true"
 				ExceptionHandling="1"
 				RuntimeLibrary="0"
@@ -892,6 +892,10 @@
 				>
 			</File>
 			<File
+				RelativePath=".\..\src\depot_type.h"
+				>
+			</File>
+			<File
 				RelativePath=".\..\src\direction_func.h"
 				>
 			</File>
@@ -928,7 +932,11 @@
 				>
 			</File>
 			<File
-				RelativePath=".\..\src\engine.h"
+				RelativePath=".\..\src\engine_func.h"
+				>
+			</File>
+			<File
+				RelativePath=".\..\src\engine_type.h"
 				>
 			</File>
 			<File
@@ -980,6 +988,10 @@
 				>
 			</File>
 			<File
+				RelativePath=".\..\src\group_type.h"
+				>
+			</File>
+			<File
 				RelativePath=".\..\src\gui.h"
 				>
 			</File>
@@ -1180,7 +1192,15 @@
 				>
 			</File>
 			<File
-				RelativePath=".\..\src\order.h"
+				RelativePath=".\..\src\order_base.h"
+				>
+			</File>
+			<File
+				RelativePath=".\..\src\order_func.h"
+				>
+			</File>
+			<File
+				RelativePath=".\..\src\order_type.h"
 				>
 			</File>
 			<File
@@ -1316,7 +1336,15 @@
 				>
 			</File>
 			<File
-				RelativePath=".\..\src\signs.h"
+				RelativePath=".\..\src\signs_base.h"
+				>
+			</File>
+			<File
+				RelativePath=".\..\src\signs_func.h"
+				>
+			</File>
+			<File
+				RelativePath=".\..\src\signs_type.h"
 				>
 			</File>
 			<File
@@ -1344,7 +1372,11 @@
 				>
 			</File>
 			<File
-				RelativePath=".\..\src\station.h"
+				RelativePath=".\..\src\station_base.h"
+				>
+			</File>
+			<File
+				RelativePath=".\..\src\station_func.h"
 				>
 			</File>
 			<File
@@ -1352,6 +1384,10 @@
 				>
 			</File>
 			<File
+				RelativePath=".\..\src\station_type.h"
+				>
+			</File>
+			<File
 				RelativePath=".\..\src\stdafx.h"
 				>
 			</File>
@@ -1476,6 +1512,10 @@
 				>
 			</File>
 			<File
+				RelativePath=".\..\src\waypoint_type.h"
+				>
+			</File>
+			<File
 				RelativePath=".\..\src\music\win32_m.h"
 				>
 			</File>
--- a/projects/openttd_vs80.vcproj.in	Mon Mar 31 07:37:51 2008 +0000
+++ b/projects/openttd_vs80.vcproj.in	Mon Mar 31 07:50:27 2008 +0000
@@ -61,7 +61,7 @@
 				FavorSizeOrSpeed="2"
 				OmitFramePointers="true"
 				AdditionalIncludeDirectories="..\objs\langs;..\src\3rdparty\squirrel\include"
-				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\&quot;OpenTTD\&quot;"
+				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\&quot;OpenTTD\&quot;;WITH_ASSERT"
 				StringPooling="true"
 				ExceptionHandling="1"
 				RuntimeLibrary="0"
@@ -272,7 +272,7 @@
 				FavorSizeOrSpeed="2"
 				OmitFramePointers="true"
 				AdditionalIncludeDirectories="..\objs\langs;..\src\3rdparty\squirrel\include"
-				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\&quot;OpenTTD\&quot;"
+				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\&quot;OpenTTD\&quot;;WITH_ASSERT"
 				StringPooling="true"
 				ExceptionHandling="1"
 				RuntimeLibrary="0"
--- a/projects/openttd_vs90.vcproj	Mon Mar 31 07:37:51 2008 +0000
+++ b/projects/openttd_vs90.vcproj	Mon Mar 31 07:50:27 2008 +0000
@@ -62,7 +62,7 @@
 				FavorSizeOrSpeed="2"
 				OmitFramePointers="true"
 				AdditionalIncludeDirectories="..\objs\langs"
-				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\&quot;OpenTTD\&quot;"
+				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\&quot;OpenTTD\&quot;;WITH_ASSERT"
 				StringPooling="true"
 				ExceptionHandling="1"
 				RuntimeLibrary="0"
@@ -270,7 +270,7 @@
 				FavorSizeOrSpeed="2"
 				OmitFramePointers="true"
 				AdditionalIncludeDirectories="..\objs\langs"
-				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\&quot;OpenTTD\&quot;"
+				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\&quot;OpenTTD\&quot;;WITH_ASSERT"
 				StringPooling="true"
 				ExceptionHandling="1"
 				RuntimeLibrary="0"
@@ -889,6 +889,10 @@
 				>
 			</File>
 			<File
+				RelativePath=".\..\src\depot_type.h"
+				>
+			</File>
+			<File
 				RelativePath=".\..\src\direction_func.h"
 				>
 			</File>
@@ -925,7 +929,11 @@
 				>
 			</File>
 			<File
-				RelativePath=".\..\src\engine.h"
+				RelativePath=".\..\src\engine_func.h"
+				>
+			</File>
+			<File
+				RelativePath=".\..\src\engine_type.h"
 				>
 			</File>
 			<File
@@ -977,6 +985,10 @@
 				>
 			</File>
 			<File
+				RelativePath=".\..\src\group_type.h"
+				>
+			</File>
+			<File
 				RelativePath=".\..\src\gui.h"
 				>
 			</File>
@@ -1177,7 +1189,15 @@
 				>
 			</File>
 			<File
-				RelativePath=".\..\src\order.h"
+				RelativePath=".\..\src\order_base.h"
+				>
+			</File>
+			<File
+				RelativePath=".\..\src\order_func.h"
+				>
+			</File>
+			<File
+				RelativePath=".\..\src\order_type.h"
 				>
 			</File>
 			<File
@@ -1313,7 +1333,15 @@
 				>
 			</File>
 			<File
-				RelativePath=".\..\src\signs.h"
+				RelativePath=".\..\src\signs_base.h"
+				>
+			</File>
+			<File
+				RelativePath=".\..\src\signs_func.h"
+				>
+			</File>
+			<File
+				RelativePath=".\..\src\signs_type.h"
 				>
 			</File>
 			<File
@@ -1341,7 +1369,11 @@
 				>
 			</File>
 			<File
-				RelativePath=".\..\src\station.h"
+				RelativePath=".\..\src\station_base.h"
+				>
+			</File>
+			<File
+				RelativePath=".\..\src\station_func.h"
 				>
 			</File>
 			<File
@@ -1349,6 +1381,10 @@
 				>
 			</File>
 			<File
+				RelativePath=".\..\src\station_type.h"
+				>
+			</File>
+			<File
 				RelativePath=".\..\src\stdafx.h"
 				>
 			</File>
@@ -1473,6 +1509,10 @@
 				>
 			</File>
 			<File
+				RelativePath=".\..\src\waypoint_type.h"
+				>
+			</File>
+			<File
 				RelativePath=".\..\src\music\win32_m.h"
 				>
 			</File>
--- a/projects/openttd_vs90.vcproj.in	Mon Mar 31 07:37:51 2008 +0000
+++ b/projects/openttd_vs90.vcproj.in	Mon Mar 31 07:50:27 2008 +0000
@@ -62,7 +62,7 @@
 				FavorSizeOrSpeed="2"
 				OmitFramePointers="true"
 				AdditionalIncludeDirectories="..\objs\langs"
-				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\&quot;OpenTTD\&quot;"
+				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\&quot;OpenTTD\&quot;;WITH_ASSERT"
 				StringPooling="true"
 				ExceptionHandling="1"
 				RuntimeLibrary="0"
@@ -270,7 +270,7 @@
 				FavorSizeOrSpeed="2"
 				OmitFramePointers="true"
 				AdditionalIncludeDirectories="..\objs\langs"
-				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\&quot;OpenTTD\&quot;"
+				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WIN32_EXCEPTION_TRACKER;WIN32_ENABLE_DIRECTMUSIC_SUPPORT;WITH_ZLIB;WITH_PNG;WITH_FREETYPE;ENABLE_NETWORK;WITH_PERSONAL_DIR;PERSONAL_DIR=\&quot;OpenTTD\&quot;;WITH_ASSERT"
 				StringPooling="true"
 				ExceptionHandling="1"
 				RuntimeLibrary="0"
--- a/source.list	Mon Mar 31 07:37:51 2008 +0000
+++ b/source.list	Mon Mar 31 07:50:27 2008 +0000
@@ -131,6 +131,7 @@
 debug.h
 video/dedicated_v.h
 depot.h
+depot_type.h
 direction_func.h
 direction_type.h
 music/dmusic.h
@@ -140,7 +141,8 @@
 economy_func.h
 economy_type.h
 core/endian_func.hpp
-engine.h
+engine_func.h
+engine_type.h
 core/enum_type.hpp
 fileio.h
 fios.h
@@ -153,6 +155,7 @@
 gfxinit.h
 group.h
 group_gui.h
+group_type.h
 gui.h
 heightmap.h
 industry.h
@@ -203,7 +206,9 @@
 video/null_v.h
 oldpool.h
 openttd.h
-order.h
+order_base.h
+order_func.h
+order_type.h
 core/overflowsafe_type.hpp
 pathfind.h
 player_base.h
@@ -237,15 +242,19 @@
 ship.h
 signal_func.h
 signal_type.h
-signs.h
+signs_base.h
+signs_func.h
+signs_type.h
 slope_func.h
 slope_type.h
 sound_func.h
 sound_type.h
 sprite.h
 spritecache.h
-station.h
+station_base.h
+station_func.h
 station_gui.h
+station_type.h
 stdafx.h
 string_func.h
 string_type.h
@@ -277,6 +286,7 @@
 viewport_func.h
 viewport_type.h
 waypoint.h
+waypoint_type.h
 music/win32_m.h
 sound/win32_s.h
 video/win32_v.h
--- a/src/ai/api/ai_airport.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/ai/api/ai_airport.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -3,6 +3,7 @@
 /** @file ai_airport.cpp Implementation of AIAirport. */
 
 #include "ai_airport.hpp"
+#include "../../openttd.h"
 #include "../../variables.h"
 #include "../../station_map.h"
 #include "../../player_func.h"
--- a/src/ai/api/ai_base.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/ai/api/ai_base.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -4,6 +4,7 @@
 
 #include "ai_base.hpp"
 #include "../../network/network.h"
+#include "../../core/random_func.hpp"
 
 /* static */ uint32 AIBase::Rand()
 {
--- a/src/ai/api/ai_engine.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/ai/api/ai_engine.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -4,7 +4,6 @@
 
 #include "ai_engine.hpp"
 #include "ai_cargo.hpp"
-#include "../../engine.h"
 #include "../../player_func.h"
 #include "../../strings_func.h"
 #include "../../roadveh.h"
--- a/src/ai/api/ai_enginelist.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/ai/api/ai_enginelist.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -3,7 +3,7 @@
 /** @file ai_enginelist.cpp Implementation of AIEngineList and friends. */
 
 #include "ai_enginelist.hpp"
-#include "../../engine.h"
+#include "../../engine_func.h"
 
 AIEngineList::AIEngineList(AIVehicle::VehicleType vehicle_type)
 {
--- a/src/ai/api/ai_object.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/ai/api/ai_object.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -6,7 +6,7 @@
 #include "../../command_func.h"
 #include "../../network/network.h"
 #include "../../player_func.h"
-#include "../../signs.h" // for _new_sign_id
+#include "../../signs_func.h"
 #include "../../vehicle_func.h"
 #include "../ai.h"
 #include "../ai_threads.h"
--- a/src/ai/api/ai_object.hpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/ai/api/ai_object.hpp	Mon Mar 31 07:50:27 2008 +0000
@@ -6,8 +6,13 @@
 #define AI_OBJECT_HPP
 
 #include "../../stdafx.h"
-#include "../../functions.h"
+#include "../../openttd.h"
 #include "../../misc/countedptr.hpp"
+#include "../../signs_type.h"
+#include "../../command_type.h"
+#include "../../vehicle_type.h"
+#include "../../tile_type.h"
+#include "../../player_type.h"
 
 #ifndef _SQUIRREL_H_
 /* Life becomes easier when we can tell about a function it needs the VM, but
--- a/src/ai/api/ai_order.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/ai/api/ai_order.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -6,7 +6,6 @@
 #include "ai_map.hpp"
 #include "ai_vehicle.hpp"
 #include "../../command_type.h"
-#include "../../order.h"
 #include "../../vehicle_base.h"
 #include "../../depot.h"
 #include "../../landscape.h"
--- a/src/ai/api/ai_sign.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/ai/api/ai_sign.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -6,7 +6,7 @@
 #include "table/strings.h"
 #include "../../command_func.h"
 #include "../../core/alloc_func.hpp"
-#include "../../signs.h"
+#include "../../signs_base.h"
 #include "../../strings_func.h"
 #include "../../tile_map.h"
 
--- a/src/ai/api/ai_station.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/ai/api/ai_station.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -6,7 +6,6 @@
 #include "ai_cargo.hpp"
 #include "ai_map.hpp"
 #include "../../debug.h"
-#include "../../station.h"
 #include "../../station_map.h"
 #include "../../variables.h"
 #include "../../strings_func.h"
--- a/src/ai/api/ai_station.hpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/ai/api/ai_station.hpp	Mon Mar 31 07:50:27 2008 +0000
@@ -6,6 +6,7 @@
 #define AI_STATION_HPP
 
 #include "ai_object.hpp"
+#include "../../station_type.h"
 
 /**
  * Class that handles all station related functions.
--- a/src/ai/api/ai_stationlist.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/ai/api/ai_stationlist.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -5,8 +5,7 @@
 #include "ai_stationlist.hpp"
 #include "ai_vehicle.hpp"
 #include "../../player_func.h"
-#include "../../station.h"
-#include "../../order.h"
+#include "../../station_base.h"
 #include "../../vehicle_base.h"
 
 AIStationList::AIStationList(AIStation::StationType station_type)
--- a/src/ai/api/ai_tile.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/ai/api/ai_tile.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -7,7 +7,7 @@
 #include "../../tile_map.h"
 #include "../../map_func.h"
 #include "../../variables.h"
-#include "../../station.h"
+#include "../../station_func.h"
 #include "../../command_type.h"
 #include "../../settings_type.h"
 #include "../../road_map.h"
--- a/src/ai/api/ai_tilelist.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/ai/api/ai_tilelist.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -7,7 +7,7 @@
 
 #include "../../landscape.h"
 #include "../../settings_type.h"
-#include "../../station.h"
+#include "../../station_func.h"
 #include "../../map_func.h"
 #include "../../tile_map.h"
 #include "../../industry_map.h"
--- a/src/ai/api/ai_vehicle.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/ai/api/ai_vehicle.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -7,7 +7,6 @@
 #include "ai_cargo.hpp"
 #include "ai_order.hpp"
 #include "../../depot.h"
-#include "../../engine.h"
 #include "../../player_func.h"
 #include "../../aircraft.h"
 #include "../../strings_func.h"
--- a/src/ai/api/ai_vehicle.hpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/ai/api/ai_vehicle.hpp	Mon Mar 31 07:50:27 2008 +0000
@@ -6,7 +6,7 @@
 #define AI_VEHICLE_HPP
 
 #include "ai_object.hpp"
-#include "../../vehicle_type.h"
+#include "../../engine_type.h"
 
 /**
  * Class that handles all vehicle related functions.
--- a/src/ai/api/ai_vehiclelist.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/ai/api/ai_vehiclelist.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -5,7 +5,6 @@
 #include "ai_vehiclelist.hpp"
 #include "ai_station.hpp"
 #include "../../player_func.h"
-#include "../../station.h"
 #include "../../vehicle_base.h"
 
 AIVehicleList::AIVehicleList()
--- a/src/ai/api/ai_vehiclelist.hpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/ai/api/ai_vehiclelist.hpp	Mon Mar 31 07:50:27 2008 +0000
@@ -6,6 +6,7 @@
 #define AI_VEHICLELIST_HPP
 
 #include "ai_abstractlist.hpp"
+#include "../../station_type.h"
 
 /**
  * Creates a list of vehicles of which you are the owner.
--- a/src/aircraft.h	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/aircraft.h	Mon Mar 31 07:50:27 2008 +0000
@@ -6,8 +6,9 @@
 #define AIRCRAFT_H
 
 #include "station_map.h"
+#include "station_base.h"
 #include "vehicle_base.h"
-#include "engine.h"
+#include "engine_func.h"
 
 /** An aircraft can be one ot those types */
 enum AircraftSubType {
--- a/src/aircraft_cmd.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/aircraft_cmd.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -11,8 +11,6 @@
 #include "station_map.h"
 #include "timetable.h"
 #include "depot.h"
-#include "engine.h"
-#include "station.h"
 #include "news_func.h"
 #include "aircraft.h"
 #include "airport.h"
@@ -37,6 +35,7 @@
 #include "ai/ai.h"
 #include "player_func.h"
 #include "settings_type.h"
+#include "order_func.h"
 
 #include "table/strings.h"
 #include "table/sprites.h"
@@ -2135,7 +2134,6 @@
 static void AircraftEventHandler(Vehicle *v, int loop)
 {
 	v->tick_counter++;
-	v->current_order_time++;
 
 	if (v->vehstatus & VS_CRASHED) {
 		HandleCrashedAircraft(v);
@@ -2172,6 +2170,8 @@
 
 	AgeAircraftCargo(this);
 
+	this->current_order_time++;
+
 	for (uint i = 0; i != 2; i++) {
 		AircraftEventHandler(this, i);
 		if (this->type != VEH_AIRCRAFT) // In case it was deleted
--- a/src/aircraft_gui.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/aircraft_gui.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -7,13 +7,13 @@
 #include "aircraft.h"
 #include "debug.h"
 #include "gui.h"
-#include "engine.h"
 #include "depot.h"
 #include "vehicle_gui.h"
 #include "newgrf_engine.h"
 #include "strings_func.h"
 #include "vehicle_func.h"
 #include "gfx_func.h"
+#include "order_func.h"
 
 #include "table/sprites.h"
 #include "table/strings.h"
--- a/src/airport_gui.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/airport_gui.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -9,7 +9,6 @@
 #include "station_gui.h"
 #include "terraform_gui.h"
 #include "command_func.h"
-#include "station.h"
 #include "airport.h"
 #include "depot.h"
 #include "sound_func.h"
@@ -18,6 +17,7 @@
 #include "viewport_func.h"
 #include "gfx_func.h"
 #include "player_func.h"
+#include "order_func.h"
 
 #include "table/sprites.h"
 #include "table/strings.h"
--- a/src/articulated_vehicles.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/articulated_vehicles.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -5,7 +5,6 @@
 #include "stdafx.h"
 #include "openttd.h"
 #include "articulated_vehicles.h"
-#include "engine.h"
 #include "train.h"
 #include "roadveh.h"
 #include "newgrf_callbacks.h"
--- a/src/articulated_vehicles.h	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/articulated_vehicles.h	Mon Mar 31 07:50:27 2008 +0000
@@ -6,6 +6,7 @@
 #define ARTICULATED_VEHICLES_H
 
 #include "vehicle_type.h"
+#include "engine_type.h"
 
 uint CountArticulatedParts(EngineID engine_type, bool purchase_window);
 uint16 *GetCapacityOfArticulatedParts(EngineID engine, VehicleType type);
--- a/src/autoreplace_cmd.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/autoreplace_cmd.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -6,7 +6,6 @@
 #include "ship.h"
 #include "news_func.h"
 #include "player_func.h"
-#include "engine.h"
 #include "debug.h"
 #include "vehicle_gui.h"
 #include "depot.h"
@@ -14,7 +13,6 @@
 #include "aircraft.h"
 #include "cargotype.h"
 #include "group.h"
-#include "order.h"
 #include "strings_func.h"
 #include "command_func.h"
 #include "vehicle_func.h"
--- a/src/autoreplace_gui.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/autoreplace_gui.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -19,10 +19,24 @@
 #include "gfx_func.h"
 #include "player_func.h"
 #include "widgets/dropdown_func.h"
+#include "engine_func.h"
 
 #include "table/sprites.h"
 #include "table/strings.h"
 
+struct replaceveh_d {
+	byte sel_index[2];
+	EngineID sel_engine[2];
+	uint16 count[2];
+	bool wagon_btnstate; ///< true means engine is selected
+	EngineList list[2];
+	bool update_left;
+	bool update_right;
+	bool init_lists;
+	GroupID sel_group;
+};
+assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(replaceveh_d));
+
 static RailType _railtype_selected_in_replace_gui;
 
 static bool _rebuild_left_list;
--- a/src/build_vehicle_gui.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/build_vehicle_gui.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -12,9 +12,7 @@
 #include "gui.h"
 #include "articulated_vehicles.h"
 #include "textbuf_gui.h"
-#include "station.h"
 #include "command_func.h"
-#include "engine.h"
 #include "player_func.h"
 #include "depot.h"
 #include "airport.h"
--- a/src/cargopacket.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/cargopacket.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -4,7 +4,7 @@
 
 #include "stdafx.h"
 #include "openttd.h"
-#include "station.h"
+#include "station_base.h"
 #include "cargopacket.h"
 #include "saveload.h"
 
--- a/src/cargopacket.h	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/cargopacket.h	Mon Mar 31 07:50:27 2008 +0000
@@ -5,8 +5,10 @@
 #ifndef CARGOPACKET_H
 #define CARGOPACKET_H
 
+#include "oldpool.h"
 #include "economy_type.h"
 #include "tile_type.h"
+#include "station_type.h"
 #include <list>
 
 typedef uint32 CargoPacketID;
--- a/src/console_cmds.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/console_cmds.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -6,7 +6,7 @@
 #include "openttd.h"
 #include "console.h"
 #include "debug.h"
-#include "engine.h"
+#include "engine_func.h"
 #include "landscape.h"
 #include "saveload.h"
 #include "variables.h"
@@ -18,7 +18,6 @@
 #include "settings_func.h"
 #include "fios.h"
 #include "fileio.h"
-#include "station.h"
 #include "screenshot.h"
 #include "genworld.h"
 #include "network/network.h"
--- a/src/depot.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/depot.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -7,7 +7,7 @@
 #include "depot.h"
 #include "landscape.h"
 #include "saveload.h"
-#include "order.h"
+#include "order_func.h"
 #include "window_func.h"
 
 #include "table/strings.h"
--- a/src/depot.h	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/depot.h	Mon Mar 31 07:50:27 2008 +0000
@@ -6,13 +6,13 @@
 #define DEPOT_H
 
 #include "direction_type.h"
+#include "depot_type.h"
 #include "oldpool.h"
 #include "road_map.h"
 #include "rail_map.h"
 #include "water_map.h"
 #include "station_map.h"
 
-struct Depot;
 DECLARE_OLD_POOL(Depot, Depot, 3, 8000)
 
 struct Depot : PoolItem<Depot, DepotID, &_Depot_pool> {
--- a/src/depot_gui.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/depot_gui.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -22,6 +22,7 @@
 #include "window_func.h"
 #include "vehicle_func.h"
 #include "player_func.h"
+#include "order_func.h"
 
 #include "table/strings.h"
 #include "table/sprites.h"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/depot_type.h	Mon Mar 31 07:50:27 2008 +0000
@@ -0,0 +1,11 @@
+/* $Id$ */
+
+/** @file depot_type.h Header files for depots (not hangars) */
+
+#ifndef DEPOT_TYPE_H
+#define DEPOT_TYPE_H
+
+typedef uint16 DepotID;
+struct Depot;
+
+#endif /* DEPOT_TYPE_H */
--- a/src/disaster_cmd.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/disaster_cmd.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -25,7 +25,7 @@
 #include "command_func.h"
 #include "tile_cmd.h"
 #include "news_func.h"
-#include "station.h"
+#include "station_base.h"
 #include "waypoint.h"
 #include "town.h"
 #include "industry.h"
--- a/src/dock_gui.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/dock_gui.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -5,7 +5,7 @@
 #include "stdafx.h"
 #include "openttd.h"
 #include "tile_map.h"
-#include "station.h"
+#include "station_type.h"
 #include "gui.h"
 #include "terraform_gui.h"
 #include "window_gui.h"
--- a/src/economy.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/economy.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -8,14 +8,12 @@
 #include "landscape.h"
 #include "player_base.h"
 #include "player_func.h"
-#include "station.h"
 #include "command_func.h"
 #include "saveload.h"
 #include "industry.h"
 #include "town.h"
 #include "news_func.h"
 #include "network/network.h"
-#include "engine.h"
 #include "network/network_data.h"
 #include "variables.h"
 #include "vehicle_gui.h"
--- a/src/economy_func.h	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/economy_func.h	Mon Mar 31 07:50:27 2008 +0000
@@ -13,6 +13,7 @@
 #include "town_type.h"
 #include "industry_type.h"
 #include "player_type.h"
+#include "station_type.h"
 
 struct Player;
 
--- a/src/elrail.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/elrail.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -65,6 +65,7 @@
 #include "vehicle_func.h"
 #include "player_base.h"
 #include "tunnelbridge.h"
+#include "engine_func.h"
 
 #include "table/sprites.h"
 #include "table/elrail_data.h"
--- a/src/engine.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/engine.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -5,7 +5,6 @@
 #include "stdafx.h"
 #include "openttd.h"
 #include "debug.h"
-#include "engine.h"
 #include "player_base.h"
 #include "player_func.h"
 #include "command_func.h"
--- a/src/engine.h	Mon Mar 31 07:37:51 2008 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,277 +0,0 @@
-/* $Id$ */
-
-/** @file engine.h */
-
-#ifndef ENGINE_H
-#define ENGINE_H
-
-#include "rail_type.h"
-#include "cargo_type.h"
-#include "vehicle_type.h"
-#include "gfx_type.h"
-#include "date_type.h"
-#include "sound_type.h"
-#include "player_type.h"
-#include "strings_type.h"
-
-enum RailVehicleTypes {
-	RAILVEH_SINGLEHEAD,  ///< indicates a "standalone" locomotive
-	RAILVEH_MULTIHEAD,   ///< indicates a combination of two locomotives
-	RAILVEH_WAGON,       ///< simple wagon, not motorized
-};
-
-enum EngineClass {
-	EC_STEAM,
-	EC_DIESEL,
-	EC_ELECTRIC,
-	EC_MONORAIL,
-	EC_MAGLEV,
-};
-
-struct RailVehicleInfo {
-	byte image_index;
-	RailVehicleTypes railveh_type;
-	byte base_cost;
-	RailTypeByte railtype;
-	uint16 max_speed;
-	uint16 power;
-	uint16 weight;
-	byte running_cost;
-	byte running_cost_class;
-	EngineClass engclass;           ///< Class of engine for this vehicle
-	byte capacity;
-	CargoID cargo_type;
-	byte ai_rank;
-	byte ai_passenger_only; ///< Bit value to tell AI that this engine is for passenger use only
-	uint16 pow_wag_power;
-	byte pow_wag_weight;
-	byte visual_effect; // NOTE: this is not 100% implemented yet, at the moment it is only used as a 'fallback' value
-	                    //       for when the 'powered wagon' callback fails. But it should really also determine what
-	                    //       kind of visual effect to generate for a vehicle (default, steam, diesel, electric).
-	                    //       Same goes for the callback result, which atm is only used to check if a wagon is powered.
-	byte shorten_factor;   ///< length on main map for this type is 8 - shorten_factor
-	byte tractive_effort;  ///< Tractive effort coefficient
-	byte user_def_data;    ///< Property 0x25: "User-defined bit mask" Used only for (very few) NewGRF vehicles
-};
-
-struct ShipVehicleInfo {
-	byte image_index;
-	byte base_cost;
-	uint16 max_speed;
-	CargoID cargo_type;
-	uint16 capacity;
-	byte running_cost;
-	SoundFxByte sfx;
-	bool refittable;
-};
-
-/* AircraftVehicleInfo subtypes, bitmask type.
- * If bit 0 is 0 then it is a helicopter, otherwise it is a plane
- * in which case bit 1 tells us whether it's a big(fast) plane or not */
-enum {
-	AIR_HELI = 0,
-	AIR_CTOL = 1, ///< Conventional Take Off and Landing, i.e. planes
-	AIR_FAST = 2
-};
-
-struct AircraftVehicleInfo {
-	byte image_index;
-	byte base_cost;
-	byte running_cost;
-	byte subtype;
-	SoundFxByte sfx;
-	byte acceleration;
-	uint16 max_speed;
-	byte mail_capacity;
-	uint16 passenger_capacity;
-};
-
-struct RoadVehicleInfo {
-	byte image_index;
-	byte base_cost;
-	byte running_cost;
-	byte running_cost_class;
-	SoundFxByte sfx;
-	byte max_speed;
-	byte capacity;
-	CargoID cargo_type;
-};
-
-/** Information about a vehicle
- *  @see table/engines.h
- */
-struct EngineInfo {
-	Date base_intro;
-	Year lifelength;
-	Year base_life;
-	byte unk2;         ///< flag for carriage(bit 7) and decay speed(bits0..6)
-	byte load_amount;
-	byte climates;
-	uint32 refit_mask;
-	byte refit_cost;
-	byte misc_flags;
-	byte callbackmask;
-	int8 retire_early;  ///< Number of years early to retire vehicle
-	StringID string_id; ///< Default name of engine
-};
-
-struct Engine {
-	char *name;         ///< Custom name of engine
-	Date intro_date;
-	Date age;
-	uint16 reliability;
-	uint16 reliability_spd_dec;
-	uint16 reliability_start, reliability_max, reliability_final;
-	uint16 duration_phase_1, duration_phase_2, duration_phase_3;
-	byte lifelength;
-	byte flags;
-	uint8 preview_player_rank;
-	byte preview_wait;
-	byte player_avail;
-	VehicleType type; ///< type, ie VEH_ROAD, VEH_TRAIN, etc.
-};
-
-/**
- * EngineInfo.misc_flags is a bitmask, with the following values
- */
-enum {
-	EF_RAIL_TILTS = 0, ///< Rail vehicle tilts in curves
-	EF_ROAD_TRAM  = 0, ///< Road vehicle is a tram/light rail vehicle
-	EF_USES_2CC   = 1, ///< Vehicle uses two company colours
-	EF_RAIL_IS_MU = 2, ///< Rail vehicle is a multiple-unit (DMU/EMU)
-};
-
-/**
- * Engine.flags is a bitmask, with the following values.
- */
-enum {
-	ENGINE_AVAILABLE         = 1, ///< This vehicle is available to everyone.
-	ENGINE_EXCLUSIVE_PREVIEW = 2, ///< This vehicle is in the exclusive preview stage, either being used or being offered to a player.
-	ENGINE_OFFER_WINDOW_OPEN = 4, ///< The exclusive offer window is currently open for a player.
-};
-
-enum {
-	NUM_VEHICLE_TYPES = 6
-};
-
-static const EngineID INVALID_ENGINE = 0xFFFF;
-
-
-void SetupEngines();
-void StartupEngines();
-
-
-void DrawTrainEngine(int x, int y, EngineID engine, SpriteID pal);
-void DrawRoadVehEngine(int x, int y, EngineID engine, SpriteID pal);
-void DrawShipEngine(int x, int y, EngineID engine, SpriteID pal);
-void DrawAircraftEngine(int x, int y, EngineID engine, SpriteID pal);
-
-void LoadCustomEngineNames();
-void DeleteCustomEngineNames();
-
-bool IsEngineBuildable(EngineID engine, VehicleType type, PlayerID player);
-CargoID GetEngineCargoType(EngineID engine);
-
-enum {
-	NUM_NORMAL_RAIL_ENGINES = 54,
-	NUM_MONORAIL_ENGINES    = 30,
-	NUM_MAGLEV_ENGINES      = 32,
-	NUM_TRAIN_ENGINES       = NUM_NORMAL_RAIL_ENGINES + NUM_MONORAIL_ENGINES + NUM_MAGLEV_ENGINES,
-	NUM_ROAD_ENGINES        = 88,
-	NUM_SHIP_ENGINES        = 11,
-	NUM_AIRCRAFT_ENGINES    = 41,
-	TOTAL_NUM_ENGINES       = NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES + NUM_SHIP_ENGINES + NUM_AIRCRAFT_ENGINES,
-	AIRCRAFT_ENGINES_INDEX  = NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES + NUM_SHIP_ENGINES,
-	SHIP_ENGINES_INDEX      = NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES,
-	ROAD_ENGINES_INDEX      = NUM_TRAIN_ENGINES,
-};
-
-static inline EngineID GetFirstEngineOfType(VehicleType type)
-{
-	const EngineID start[] = {0, ROAD_ENGINES_INDEX, SHIP_ENGINES_INDEX, AIRCRAFT_ENGINES_INDEX};
-
-	return start[type];
-}
-
-static inline EngineID GetLastEngineOfType(VehicleType type)
-{
-	const EngineID end[] = {
-		NUM_TRAIN_ENGINES,
-		ROAD_ENGINES_INDEX + NUM_ROAD_ENGINES,
-		SHIP_ENGINES_INDEX + NUM_SHIP_ENGINES,
-		AIRCRAFT_ENGINES_INDEX + NUM_AIRCRAFT_ENGINES};
-
-	return end[type];
-}
-
-extern Engine _engines[TOTAL_NUM_ENGINES];
-#define FOR_ALL_ENGINES(e) for (e = _engines; e != endof(_engines); e++)
-#define FOR_ALL_ENGINEIDS_OF_TYPE(e, type) for (e = GetFirstEngineOfType(type); e != GetLastEngineOfType(type); e++)
-
-
-static inline Engine* GetEngine(EngineID i)
-{
-	assert(i < lengthof(_engines));
-	return &_engines[i];
-}
-
-static inline bool IsEngineIndex(uint index)
-{
-	return index < TOTAL_NUM_ENGINES;
-}
-
-/* Access Vehicle Data */
-extern const EngineInfo _orig_engine_info[TOTAL_NUM_ENGINES];
-extern const RailVehicleInfo _orig_rail_vehicle_info[NUM_TRAIN_ENGINES];
-extern const ShipVehicleInfo _orig_ship_vehicle_info[NUM_SHIP_ENGINES];
-extern const AircraftVehicleInfo _orig_aircraft_vehicle_info[NUM_AIRCRAFT_ENGINES];
-extern const RoadVehicleInfo _orig_road_vehicle_info[NUM_ROAD_ENGINES];
-
-extern EngineInfo _engine_info[TOTAL_NUM_ENGINES];
-extern RailVehicleInfo _rail_vehicle_info[NUM_TRAIN_ENGINES];
-extern ShipVehicleInfo _ship_vehicle_info[NUM_SHIP_ENGINES];
-extern AircraftVehicleInfo _aircraft_vehicle_info[NUM_AIRCRAFT_ENGINES];
-extern RoadVehicleInfo _road_vehicle_info[NUM_ROAD_ENGINES];
-
-static inline const EngineInfo *EngInfo(EngineID e)
-{
-	assert(e < lengthof(_engine_info));
-	return &_engine_info[e];
-}
-
-static inline const RailVehicleInfo* RailVehInfo(EngineID e)
-{
-	assert(e < lengthof(_rail_vehicle_info));
-	return &_rail_vehicle_info[e];
-}
-
-static inline const ShipVehicleInfo* ShipVehInfo(EngineID e)
-{
-	assert(e >= SHIP_ENGINES_INDEX && e < SHIP_ENGINES_INDEX + lengthof(_ship_vehicle_info));
-	return &_ship_vehicle_info[e - SHIP_ENGINES_INDEX];
-}
-
-static inline const AircraftVehicleInfo* AircraftVehInfo(EngineID e)
-{
-	assert(e >= AIRCRAFT_ENGINES_INDEX && e < AIRCRAFT_ENGINES_INDEX + lengthof(_aircraft_vehicle_info));
-	return &_aircraft_vehicle_info[e - AIRCRAFT_ENGINES_INDEX];
-}
-
-static inline const RoadVehicleInfo* RoadVehInfo(EngineID e)
-{
-	assert(e >= ROAD_ENGINES_INDEX && e < ROAD_ENGINES_INDEX + lengthof(_road_vehicle_info));
-	return &_road_vehicle_info[e - ROAD_ENGINES_INDEX];
-}
-
-/* Engine list manipulators - current implementation is only C wrapper of CBlobT<EngineID> class (helpers.cpp) */
-void EngList_Create(EngineList *el);            ///< Creates engine list
-void EngList_Destroy(EngineList *el);           ///< Deallocate and destroy engine list
-uint EngList_Count(const EngineList *el);       ///< Returns number of items in the engine list
-void EngList_Add(EngineList *el, EngineID eid); ///< Append one item at the end of engine list
-EngineID* EngList_Items(EngineList *el);        ///< Returns engine list items as C array
-void EngList_RemoveAll(EngineList *el);         ///< Removes all items from engine list
-typedef int CDECL EngList_SortTypeFunction(const void*, const void*); ///< argument type for EngList_Sort()
-void EngList_Sort(EngineList *el, EngList_SortTypeFunction compare); ///< qsort of the engine list
-void EngList_SortPartial(EngineList *el, EngList_SortTypeFunction compare, uint begin, uint num_items); ///< qsort of specified portion of the engine list
-
-#endif /* ENGINE_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/engine_func.h	Mon Mar 31 07:50:27 2008 +0000
@@ -0,0 +1,113 @@
+/* $Id$ */
+
+/** @file engine.h */
+
+#ifndef ENGINE_H
+#define ENGINE_H
+
+#include "engine_type.h"
+
+void SetupEngines();
+void StartupEngines();
+
+
+void DrawTrainEngine(int x, int y, EngineID engine, SpriteID pal);
+void DrawRoadVehEngine(int x, int y, EngineID engine, SpriteID pal);
+void DrawShipEngine(int x, int y, EngineID engine, SpriteID pal);
+void DrawAircraftEngine(int x, int y, EngineID engine, SpriteID pal);
+
+void LoadCustomEngineNames();
+void DeleteCustomEngineNames();
+
+bool IsEngineBuildable(EngineID engine, VehicleType type, PlayerID player);
+CargoID GetEngineCargoType(EngineID engine);
+
+static inline EngineID GetFirstEngineOfType(VehicleType type)
+{
+	const EngineID start[] = {0, ROAD_ENGINES_INDEX, SHIP_ENGINES_INDEX, AIRCRAFT_ENGINES_INDEX};
+
+	return start[type];
+}
+
+static inline EngineID GetLastEngineOfType(VehicleType type)
+{
+	const EngineID end[] = {
+		NUM_TRAIN_ENGINES,
+		ROAD_ENGINES_INDEX + NUM_ROAD_ENGINES,
+		SHIP_ENGINES_INDEX + NUM_SHIP_ENGINES,
+		AIRCRAFT_ENGINES_INDEX + NUM_AIRCRAFT_ENGINES};
+
+	return end[type];
+}
+
+extern Engine _engines[TOTAL_NUM_ENGINES];
+#define FOR_ALL_ENGINES(e) for (e = _engines; e != endof(_engines); e++)
+#define FOR_ALL_ENGINEIDS_OF_TYPE(e, type) for (e = GetFirstEngineOfType(type); e != GetLastEngineOfType(type); e++)
+
+
+static inline Engine* GetEngine(EngineID i)
+{
+	assert(i < lengthof(_engines));
+	return &_engines[i];
+}
+
+static inline bool IsEngineIndex(uint index)
+{
+	return index < TOTAL_NUM_ENGINES;
+}
+
+/* Access Vehicle Data */
+extern const EngineInfo _orig_engine_info[TOTAL_NUM_ENGINES];
+extern const RailVehicleInfo _orig_rail_vehicle_info[NUM_TRAIN_ENGINES];
+extern const ShipVehicleInfo _orig_ship_vehicle_info[NUM_SHIP_ENGINES];
+extern const AircraftVehicleInfo _orig_aircraft_vehicle_info[NUM_AIRCRAFT_ENGINES];
+extern const RoadVehicleInfo _orig_road_vehicle_info[NUM_ROAD_ENGINES];
+
+extern EngineInfo _engine_info[TOTAL_NUM_ENGINES];
+extern RailVehicleInfo _rail_vehicle_info[NUM_TRAIN_ENGINES];
+extern ShipVehicleInfo _ship_vehicle_info[NUM_SHIP_ENGINES];
+extern AircraftVehicleInfo _aircraft_vehicle_info[NUM_AIRCRAFT_ENGINES];
+extern RoadVehicleInfo _road_vehicle_info[NUM_ROAD_ENGINES];
+
+static inline const EngineInfo *EngInfo(EngineID e)
+{
+	assert(e < lengthof(_engine_info));
+	return &_engine_info[e];
+}
+
+static inline const RailVehicleInfo* RailVehInfo(EngineID e)
+{
+	assert(e < lengthof(_rail_vehicle_info));
+	return &_rail_vehicle_info[e];
+}
+
+static inline const ShipVehicleInfo* ShipVehInfo(EngineID e)
+{
+	assert(e >= SHIP_ENGINES_INDEX && e < SHIP_ENGINES_INDEX + lengthof(_ship_vehicle_info));
+	return &_ship_vehicle_info[e - SHIP_ENGINES_INDEX];
+}
+
+static inline const AircraftVehicleInfo* AircraftVehInfo(EngineID e)
+{
+	assert(e >= AIRCRAFT_ENGINES_INDEX && e < AIRCRAFT_ENGINES_INDEX + lengthof(_aircraft_vehicle_info));
+	return &_aircraft_vehicle_info[e - AIRCRAFT_ENGINES_INDEX];
+}
+
+static inline const RoadVehicleInfo* RoadVehInfo(EngineID e)
+{
+	assert(e >= ROAD_ENGINES_INDEX && e < ROAD_ENGINES_INDEX + lengthof(_road_vehicle_info));
+	return &_road_vehicle_info[e - ROAD_ENGINES_INDEX];
+}
+
+/* Engine list manipulators - current implementation is only C wrapper of CBlobT<EngineID> class (helpers.cpp) */
+void EngList_Create(EngineList *el);            ///< Creates engine list
+void EngList_Destroy(EngineList *el);           ///< Deallocate and destroy engine list
+uint EngList_Count(const EngineList *el);       ///< Returns number of items in the engine list
+void EngList_Add(EngineList *el, EngineID eid); ///< Append one item at the end of engine list
+EngineID* EngList_Items(EngineList *el);        ///< Returns engine list items as C array
+void EngList_RemoveAll(EngineList *el);         ///< Removes all items from engine list
+typedef int CDECL EngList_SortTypeFunction(const void*, const void*); ///< argument type for EngList_Sort()
+void EngList_Sort(EngineList *el, EngList_SortTypeFunction compare); ///< qsort of the engine list
+void EngList_SortPartial(EngineList *el, EngList_SortTypeFunction compare, uint begin, uint num_items); ///< qsort of specified portion of the engine list
+
+#endif /* ENGINE_H */
--- a/src/engine_gui.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/engine_gui.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -7,7 +7,7 @@
 #include "gui.h"
 #include "window_gui.h"
 #include "gfx_func.h"
-#include "engine.h"
+#include "engine_func.h"
 #include "command_func.h"
 #include "economy_func.h"
 #include "news_func.h"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/engine_type.h	Mon Mar 31 07:50:27 2008 +0000
@@ -0,0 +1,177 @@
+/* $Id$ */
+
+/** @file engine_type.h Types related to engines. */
+
+#ifndef ENGINE_TYPE_H
+#define ENGINE_TYPE_H
+
+#include "rail_type.h"
+#include "cargo_type.h"
+#include "vehicle_type.h"
+#include "gfx_type.h"
+#include "date_type.h"
+#include "sound_type.h"
+#include "player_type.h"
+#include "strings_type.h"
+
+typedef uint16 EngineID;
+typedef uint16 EngineRenewID;
+typedef EngineID *EngineList; ///< engine list type placeholder acceptable for C code (see helpers.cpp)
+
+enum RailVehicleTypes {
+	RAILVEH_SINGLEHEAD,  ///< indicates a "standalone" locomotive
+	RAILVEH_MULTIHEAD,   ///< indicates a combination of two locomotives
+	RAILVEH_WAGON,       ///< simple wagon, not motorized
+};
+
+enum EngineClass {
+	EC_STEAM,
+	EC_DIESEL,
+	EC_ELECTRIC,
+	EC_MONORAIL,
+	EC_MAGLEV,
+};
+
+struct RailVehicleInfo {
+	byte image_index;
+	RailVehicleTypes railveh_type;
+	byte base_cost;
+	RailTypeByte railtype;
+	uint16 max_speed;
+	uint16 power;
+	uint16 weight;
+	byte running_cost;
+	byte running_cost_class;
+	EngineClass engclass;           ///< Class of engine for this vehicle
+	byte capacity;
+	CargoID cargo_type;
+	byte ai_rank;
+	byte ai_passenger_only; ///< Bit value to tell AI that this engine is for passenger use only
+	uint16 pow_wag_power;
+	byte pow_wag_weight;
+	byte visual_effect; // NOTE: this is not 100% implemented yet, at the moment it is only used as a 'fallback' value
+	                    //       for when the 'powered wagon' callback fails. But it should really also determine what
+	                    //       kind of visual effect to generate for a vehicle (default, steam, diesel, electric).
+	                    //       Same goes for the callback result, which atm is only used to check if a wagon is powered.
+	byte shorten_factor;   ///< length on main map for this type is 8 - shorten_factor
+	byte tractive_effort;  ///< Tractive effort coefficient
+	byte user_def_data;    ///< Property 0x25: "User-defined bit mask" Used only for (very few) NewGRF vehicles
+};
+
+struct ShipVehicleInfo {
+	byte image_index;
+	byte base_cost;
+	uint16 max_speed;
+	CargoID cargo_type;
+	uint16 capacity;
+	byte running_cost;
+	SoundFxByte sfx;
+	bool refittable;
+};
+
+/* AircraftVehicleInfo subtypes, bitmask type.
+ * If bit 0 is 0 then it is a helicopter, otherwise it is a plane
+ * in which case bit 1 tells us whether it's a big(fast) plane or not */
+enum {
+	AIR_HELI = 0,
+	AIR_CTOL = 1, ///< Conventional Take Off and Landing, i.e. planes
+	AIR_FAST = 2
+};
+
+struct AircraftVehicleInfo {
+	byte image_index;
+	byte base_cost;
+	byte running_cost;
+	byte subtype;
+	SoundFxByte sfx;
+	byte acceleration;
+	uint16 max_speed;
+	byte mail_capacity;
+	uint16 passenger_capacity;
+};
+
+struct RoadVehicleInfo {
+	byte image_index;
+	byte base_cost;
+	byte running_cost;
+	byte running_cost_class;
+	SoundFxByte sfx;
+	byte max_speed;
+	byte capacity;
+	CargoID cargo_type;
+};
+
+/** Information about a vehicle
+ *  @see table/engines.h
+ */
+struct EngineInfo {
+	Date base_intro;
+	Year lifelength;
+	Year base_life;
+	byte unk2;         ///< flag for carriage(bit 7) and decay speed(bits0..6)
+	byte load_amount;
+	byte climates;
+	uint32 refit_mask;
+	byte refit_cost;
+	byte misc_flags;
+	byte callbackmask;
+	int8 retire_early;  ///< Number of years early to retire vehicle
+	StringID string_id; ///< Default name of engine
+};
+
+struct Engine {
+	char *name;         ///< Custom name of engine
+	Date intro_date;
+	Date age;
+	uint16 reliability;
+	uint16 reliability_spd_dec;
+	uint16 reliability_start, reliability_max, reliability_final;
+	uint16 duration_phase_1, duration_phase_2, duration_phase_3;
+	byte lifelength;
+	byte flags;
+	uint8 preview_player_rank;
+	byte preview_wait;
+	byte player_avail;
+	VehicleType type; ///< type, ie VEH_ROAD, VEH_TRAIN, etc.
+};
+
+/**
+ * EngineInfo.misc_flags is a bitmask, with the following values
+ */
+enum {
+	EF_RAIL_TILTS = 0, ///< Rail vehicle tilts in curves
+	EF_ROAD_TRAM  = 0, ///< Road vehicle is a tram/light rail vehicle
+	EF_USES_2CC   = 1, ///< Vehicle uses two company colours
+	EF_RAIL_IS_MU = 2, ///< Rail vehicle is a multiple-unit (DMU/EMU)
+};
+
+/**
+ * Engine.flags is a bitmask, with the following values.
+ */
+enum {
+	ENGINE_AVAILABLE         = 1, ///< This vehicle is available to everyone.
+	ENGINE_EXCLUSIVE_PREVIEW = 2, ///< This vehicle is in the exclusive preview stage, either being used or being offered to a player.
+	ENGINE_OFFER_WINDOW_OPEN = 4, ///< The exclusive offer window is currently open for a player.
+};
+
+enum {
+	NUM_VEHICLE_TYPES = 6
+};
+
+static const EngineID INVALID_ENGINE = 0xFFFF;
+
+enum {
+	NUM_NORMAL_RAIL_ENGINES = 54,
+	NUM_MONORAIL_ENGINES    = 30,
+	NUM_MAGLEV_ENGINES      = 32,
+	NUM_TRAIN_ENGINES       = NUM_NORMAL_RAIL_ENGINES + NUM_MONORAIL_ENGINES + NUM_MAGLEV_ENGINES,
+	NUM_ROAD_ENGINES        = 88,
+	NUM_SHIP_ENGINES        = 11,
+	NUM_AIRCRAFT_ENGINES    = 41,
+	TOTAL_NUM_ENGINES       = NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES + NUM_SHIP_ENGINES + NUM_AIRCRAFT_ENGINES,
+	AIRCRAFT_ENGINES_INDEX  = NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES + NUM_SHIP_ENGINES,
+	SHIP_ENGINES_INDEX      = NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES,
+	ROAD_ENGINES_INDEX      = NUM_TRAIN_ENGINES,
+};
+
+#endif /* ENGINE_TYPE_H */
--- a/src/genworld.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/genworld.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -21,7 +21,7 @@
 #include "map_func.h"
 #include "date_func.h"
 #include "core/random_func.hpp"
-#include "engine.h"
+#include "engine_func.h"
 #include "settings_type.h"
 #include "newgrf_storage.h"
 #include "water.h"
--- a/src/group.h	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/group.h	Mon Mar 31 07:50:27 2008 +0000
@@ -5,18 +5,12 @@
 #ifndef GROUP_H
 #define GROUP_H
 
+#include "group_type.h"
 #include "oldpool.h"
 #include "player_type.h"
 #include "vehicle_type.h"
-#include "engine.h"
+#include "engine_type.h"
 
-enum {
-	ALL_GROUP     = 0xFFFD,
-	DEFAULT_GROUP = 0xFFFE, ///< ungrouped vehicles are in this group.
-	INVALID_GROUP = 0xFFFF,
-};
-
-struct Group;
 DECLARE_OLD_POOL(Group, Group, 5, 2047)
 
 struct Group : PoolItem<Group, GroupID, &_Group_pool> {
--- a/src/group_cmd.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/group_cmd.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -21,6 +21,7 @@
 #include "autoreplace_func.h"
 #include "string_func.h"
 #include "player_func.h"
+#include "order_func.h"
 
 #include "table/strings.h"
 
--- a/src/group_gui.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/group_gui.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -8,7 +8,6 @@
 #include "window_gui.h"
 #include "textbuf_gui.h"
 #include "command_func.h"
-#include "engine.h"
 #include "vehicle_gui.h"
 #include "depot.h"
 #include "train.h"
@@ -29,6 +28,20 @@
 #include "table/strings.h"
 #include "table/sprites.h"
 
+struct grouplist_d {
+	const Group **sort_list;
+	list_d l;                   // General list struct
+};
+assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(grouplist_d));
+
+struct groupveh_d : vehiclelist_d {
+	GroupID group_sel;
+	VehicleID vehicle_sel;
+
+	grouplist_d gl;
+};
+assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(groupveh_d));
+
 struct Sorting {
 	Listing aircraft;
 	Listing roadveh;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/group_type.h	Mon Mar 31 07:50:27 2008 +0000
@@ -0,0 +1,18 @@
+/* $Id$ */
+
+/** @file group_type.h Types of a group. */
+
+#ifndef GROUP_TYPE_H
+#define GROUP_TYPE_H
+
+typedef uint16 GroupID;
+
+enum {
+	ALL_GROUP     = 0xFFFD,
+	DEFAULT_GROUP = 0xFFFE, ///< ungrouped vehicles are in this group.
+	INVALID_GROUP = 0xFFFF,
+};
+
+struct Group;
+
+#endif /* GROUP_TYPE_H */
--- a/src/helpers.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/helpers.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -5,7 +5,7 @@
 #include "stdafx.h"
 
 #include "openttd.h"
-#include "engine.h"
+#include "engine_func.h"
 
 #include <new>
 #include "misc/blob.hpp"
--- a/src/industry_cmd.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/industry_cmd.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -36,6 +36,7 @@
 #include "date_func.h"
 #include "vehicle_func.h"
 #include "sound_func.h"
+#include "station_base.h"
 
 #include "table/strings.h"
 #include "table/sprites.h"
--- a/src/industry_gui.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/industry_gui.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -418,7 +418,6 @@
 	IVW_INFO,
 	IVW_GOTO,
 	IVW_SPACER,
-	IVW_RESIZE_WIDGET,
 };
 
 /** Information to store about the industry window */
@@ -434,71 +433,10 @@
 static void IndustryViewWndProc(Window *w, WindowEvent *e)
 {
 	switch (e->event) {
-	case WE_CREATE: {
-		/* Count the number of lines that we need to resize the GUI with */
-		const Industry *i = GetIndustry(w->window_number);
-		const IndustrySpec *ind = GetIndustrySpec(i->type);
-		int lines = -3;
-		bool first = true;
-		bool has_accept = false;
-
-		if (HasBit(ind->callback_flags, CBM_IND_PRODUCTION_CARGO_ARRIVAL) || HasBit(ind->callback_flags, CBM_IND_PRODUCTION_256_TICKS)) {
-			for (byte j = 0; j < lengthof(i->accepts_cargo); j++) {
-				if (i->accepts_cargo[j] == CT_INVALID) continue;
-				has_accept = true;
-				if (first) {
-					lines++;
-					first = false;
-				}
-				lines++;
-			}
-		} else {
-			for (byte j = 0; j < lengthof(i->accepts_cargo); j++) {
-				if (i->accepts_cargo[j] == CT_INVALID) continue;
-				has_accept = true;
-				lines++;
-				break;
-			}
-		}
-
-		first = true;
-		for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
-			if (i->produced_cargo[j] == CT_INVALID) continue;
-			if (first) {
-				if (has_accept) lines++;
-				lines++;
-				first = false;
-			}
-			lines++;
-		}
-
-		if (HasBit(ind->callback_flags, CBM_IND_WINDOW_MORE_TEXT)) {
-			lines += 2;
-		} else {
-			/* Remove the resizing option from the widgets. Do it before the Hiding since it will be overwritten */
-			for (byte j = IVW_INFO; j <= IVW_RESIZE_WIDGET; j++) {
-				w->widget[j].display_flags = RESIZE_NONE;
-			}
-			/* Hide the resize button and enlarge the spacer so it will take its place */
-			w->HideWidget(IVW_RESIZE_WIDGET);
-			w->widget[IVW_SPACER].right = w->widget[IVW_RESIZE_WIDGET].right;
-		}
-
-		lines *= 10;
-
-		/* Resize the widgets for the new size, given by the addition of cargos */
-		for (byte j = IVW_INFO; j <= IVW_RESIZE_WIDGET; j++) {
-			if (j != IVW_INFO) w->widget[j].top += lines;
-			w->widget[j].bottom += lines;
-		}
-		w->height += lines;
-		w->resize.height += lines;
-	} break;
-
 	case WE_PAINT: {
 		Industry *i = GetIndustry(w->window_number);
 		const IndustrySpec *ind = GetIndustrySpec(i->type);
-		int y = 111;
+		int y = w->widget[IVW_INFO].top + 1;
 		bool first = true;
 		bool has_accept = false;
 
@@ -572,12 +510,19 @@
 
 					PrepareTextRefStackUsage(6);
 					/* Use all the available space left from where we stand up to the end of the window */
-					DrawStringMultiLine(2, y, message, wi->right - wi->left - 4, wi->bottom - y);
+					y += DrawStringMultiLine(2, y, message, wi->right - wi->left - 4, -1);
 					StopTextRefStackUsage();
 				}
 			}
 		}
 
+		if (y > w->widget[IVW_INFO].bottom) {
+			SetWindowDirty(w);
+			ResizeWindowForWidget(w, IVW_INFO, 0, y - w->widget[IVW_INFO].top);
+			SetWindowDirty(w);
+			return;
+		}
+
 		DrawWindowViewport(w);
 	} break;
 
@@ -661,18 +606,17 @@
 {  WWT_STICKYBOX,   RESIZE_NONE,     9,   248,   259,     0,    13, 0x0,               STR_STICKY_BUTTON},                // IVW_STICKY
 {      WWT_PANEL,   RESIZE_NONE,     9,     0,   259,    14,   105, 0x0,               STR_NULL},                         // IVW_BACKGROUND
 {      WWT_INSET,   RESIZE_NONE,     9,     2,   257,    16,   103, 0x0,               STR_NULL},                         // IVW_VIEWPORT
-{      WWT_PANEL, RESIZE_BOTTOM,     9,     0,   259,   106,   147, 0x0,               STR_NULL},                         // IVW_INFO
-{ WWT_PUSHTXTBTN,     RESIZE_TB,     9,     0,   129,   148,   159, STR_00E4_LOCATION, STR_482C_CENTER_THE_MAIN_VIEW_ON}, // IVW_GOTO
-{      WWT_PANEL,     RESIZE_TB,     9,   130,   247,   148,   159, 0x0,               STR_NULL},                         // IVW_SPACER
-{  WWT_RESIZEBOX,     RESIZE_TB,     9,   248,   259,   148,   159, 0x0,               STR_RESIZE_BUTTON},                // IVW_RESIZE_WIDGET
+{      WWT_PANEL, RESIZE_BOTTOM,     9,     0,   259,   106,   107, 0x0,               STR_NULL},                         // IVW_INFO
+{ WWT_PUSHTXTBTN,     RESIZE_TB,     9,     0,   129,   108,   119, STR_00E4_LOCATION, STR_482C_CENTER_THE_MAIN_VIEW_ON}, // IVW_GOTO
+{      WWT_PANEL,     RESIZE_TB,     9,   130,   259,   108,   119, 0x0,               STR_NULL},                         // IVW_SPACER
 {   WIDGETS_END},
 };
 
 /** Window definition of the view industy gui */
 static const WindowDesc _industry_view_desc = {
-	WDP_AUTO, WDP_AUTO, 260, 160, 260, 160,
+	WDP_AUTO, WDP_AUTO, 260, 120, 260, 120,
 	WC_INDUSTRY_VIEW, WC_NONE,
-	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
+	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON,
 	_industry_view_widgets,
 	IndustryViewWndProc
 };
--- a/src/main_gui.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/main_gui.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -16,7 +16,7 @@
 #include "news_func.h"
 #include "town.h"
 #include "console.h"
-#include "signs.h"
+#include "signs_func.h"
 #include "waypoint.h"
 #include "variables.h"
 #include "train.h"
--- a/src/misc.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/misc.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -8,7 +8,6 @@
 #include "landscape.h"
 #include "news_func.h"
 #include "saveload.h"
-#include "engine.h"
 #include "vehicle_gui.h"
 #include "variables.h"
 #include "ai/ai.h"
--- a/src/misc_gui.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/misc_gui.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -17,7 +17,7 @@
 #include "textbuf_gui.h"
 #include "viewport_func.h"
 #include "gfx_func.h"
-#include "station.h"
+#include "station_func.h"
 #include "command_func.h"
 #include "player_func.h"
 #include "player_base.h"
@@ -40,6 +40,7 @@
 #include "string_func.h"
 #include "player_gui.h"
 #include "settings_type.h"
+#include "newgrf_cargo.h"
 
 #include "table/sprites.h"
 #include "table/strings.h"
--- a/src/network/network_internal.h	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/network/network_internal.h	Mon Mar 31 07:50:27 2008 +0000
@@ -10,58 +10,66 @@
 #include "core/config.h"
 #include "core/game.h"
 
-// If this line is enable, every frame will have a sync test
-//  this is not needed in normal games. Normal is like 1 sync in 100
-//  frames. You can enable this if you have a lot of desyncs on a certain
-//  game.
-// Remember: both client and server have to be compiled with this
-//  option enabled to make it to work. If one of the two has it disabled
-//  nothing will happen.
+/**
+ * If this line is enable, every frame will have a sync test
+ *  this is not needed in normal games. Normal is like 1 sync in 100
+ *  frames. You can enable this if you have a lot of desyncs on a certain
+ *  game.
+ * Remember: both client and server have to be compiled with this
+ *  option enabled to make it to work. If one of the two has it disabled
+ *  nothing will happen.
+ */
 //#define ENABLE_NETWORK_SYNC_EVERY_FRAME
 
-// In theory sending 1 of the 2 seeds is enough to check for desyncs
-//   so in theory, this next define can be left off.
+/**
+ * In theory sending 1 of the 2 seeds is enough to check for desyncs
+ *   so in theory, this next define can be left off.
+ */
 //#define NETWORK_SEND_DOUBLE_SEED
 
-// How many clients can we have? Like.. MAX_PLAYERS - 1 is the amount of
-//  players that can really play.. so.. a max of 4 spectators.. gives us..
-//  MAX_PLAYERS + 3
-#define MAX_CLIENTS (MAX_PLAYERS + 3)
-
 
-// Do not change this next line. It should _ALWAYS_ be MAX_CLIENTS + 1
-#define MAX_CLIENT_INFO (MAX_CLIENTS + 1)
+enum {
+	/**
+	 * How many clients can we have? Like.. MAX_PLAYERS - 1 is the amount of
+	 *  players that can really play.. so.. a max of 4 spectators.. gives us..
+	 *  MAX_PLAYERS + 3
+	 */
+	MAX_CLIENTS = MAX_PLAYERS + 3,
 
-#define MAX_INTERFACES 9
-
+	/** Do not change this next line. It should _ALWAYS_ be MAX_CLIENTS + 1 */
+	MAX_CLIENT_INFO = MAX_CLIENTS + 1,
 
-// How many vehicle/station types we put over the network
-#define NETWORK_VEHICLE_TYPES 5
-#define NETWORK_STATION_TYPES 5
+	/** Maximum number of internet interfaces supported. */
+	MAX_INTERFACES = 9,
+
+	/** How many vehicle/station types we put over the network */
+	NETWORK_VEHICLE_TYPES = 5,
+	NETWORK_STATION_TYPES = 5,
+};
 
 struct NetworkPlayerInfo {
-	char company_name[NETWORK_NAME_LENGTH];         // Company name
-	char password[NETWORK_PASSWORD_LENGTH];         // The password for the player
-	Year inaugurated_year;                          // What year the company started in
-	Money company_value;                            // The company value
-	Money money;                                    // The amount of money the company has
-	Money income;                                   // How much did the company earned last year
-	uint16 performance;                             // What was his performance last month?
-	bool use_password;                              // Is there a password
-	uint16 num_vehicle[NETWORK_VEHICLE_TYPES];      // How many vehicles are there of this type?
-	uint16 num_station[NETWORK_STATION_TYPES];      // How many stations are there of this type?
-	char players[NETWORK_PLAYERS_LENGTH];           // The players that control this company (Name1, name2, ..)
-	uint16 months_empty;                            // How many months the company is empty
+	char company_name[NETWORK_NAME_LENGTH];         ///< Company name
+	char password[NETWORK_PASSWORD_LENGTH];         ///< The password for the player
+	Year inaugurated_year;                          ///< What year the company started in
+	Money company_value;                            ///< The company value
+	Money money;                                    ///< The amount of money the company has
+	Money income;                                   ///< How much did the company earned last year
+	uint16 performance;                             ///< What was his performance last month?
+	bool use_password;                              ///< Is there a password
+	uint16 num_vehicle[NETWORK_VEHICLE_TYPES];      ///< How many vehicles are there of this type?
+	uint16 num_station[NETWORK_STATION_TYPES];      ///< How many stations are there of this type?
+	char players[NETWORK_PLAYERS_LENGTH];           ///< The players that control this company (Name1, name2, ..)
+	uint16 months_empty;                            ///< How many months the company is empty
 };
 
 struct NetworkClientInfo {
-	uint16 client_index;                            // Index of the client (same as ClientState->index)
-	char client_name[NETWORK_CLIENT_NAME_LENGTH];   // Name of the client
-	byte client_lang;                               // The language of the client
-	PlayerID client_playas;                         // As which player is this client playing (PlayerID)
-	uint32 client_ip;                               // IP-address of the client (so he can be banned)
-	Date join_date;                                 // Gamedate the player has joined
-	char unique_id[NETWORK_UNIQUE_ID_LENGTH];       // Every play sends an unique id so we can indentify him
+	uint16 client_index;                            ///< Index of the client (same as ClientState->index)
+	char client_name[NETWORK_CLIENT_NAME_LENGTH];   ///< Name of the client
+	byte client_lang;                               ///< The language of the client
+	PlayerID client_playas;                         ///< As which player is this client playing (PlayerID)
+	uint32 client_ip;                               ///< IP-address of the client (so he can be banned)
+	Date join_date;                                 ///< Gamedate the player has joined
+	char unique_id[NETWORK_UNIQUE_ID_LENGTH];       ///< Every play sends an unique id so we can indentify him
 };
 
 enum NetworkJoinStatus {
@@ -75,7 +83,7 @@
 	NETWORK_JOIN_STATUS_GETTING_COMPANY_INFO,
 };
 
-/* Language ids for server_lang and client_lang. Do NOT modify the order. */
+/** Language ids for server_lang and client_lang. Do NOT modify the order. */
 enum NetworkLanguage {
 	NETLANG_ANY = 0,
 	NETLANG_ENGLISH,
--- a/src/network/network_server.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/network/network_server.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -16,7 +16,7 @@
 #include "../console.h"
 #include "../command_func.h"
 #include "../saveload.h"
-#include "../station.h"
+#include "../station_base.h"
 #include "../variables.h"
 #include "../genworld.h"
 #include "../core/alloc_func.hpp"
--- a/src/newgrf.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/newgrf.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -9,9 +9,8 @@
 #include "openttd.h"
 #include "debug.h"
 #include "fileio.h"
-#include "engine.h"
+#include "engine_func.h"
 #include "spritecache.h"
-#include "station.h"
 #include "sprite.h"
 #include "newgrf.h"
 #include "variables.h"
@@ -26,6 +25,7 @@
 #include "newgrf_house.h"
 #include "newgrf_sound.h"
 #include "newgrf_spritegroup.h"
+#include "newgrf_station.h"
 #include "cargotype.h"
 #include "industry.h"
 #include "newgrf_canal.h"
--- a/src/newgrf.h	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/newgrf.h	Mon Mar 31 07:50:27 2008 +0000
@@ -5,11 +5,11 @@
 #ifndef NEWGRF_H
 #define NEWGRF_H
 
-#include "station.h"
 #include "town_type.h"
 #include "newgrf_config.h"
 #include "cargotype.h"
 #include "industry_type.h"
+#include "station_type.h"
 
 enum GrfLoadingStage {
 	GLS_FILESCAN,
--- a/src/newgrf_engine.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/newgrf_engine.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -6,11 +6,11 @@
 #include "openttd.h"
 #include "variables.h"
 #include "debug.h"
-#include "engine.h"
+#include "engine_func.h"
 #include "train.h"
 #include "player_func.h"
 #include "player_base.h"
-#include "station.h"
+#include "station_base.h"
 #include "airport.h"
 #include "newgrf.h"
 #include "newgrf_callbacks.h"
--- a/src/newgrf_sound.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/newgrf_sound.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -5,7 +5,7 @@
 #include "stdafx.h"
 #include "openttd.h"
 #include "oldpool.h"
-#include "engine.h"
+#include "engine_func.h"
 #include "newgrf_callbacks.h"
 #include "newgrf_engine.h"
 #include "newgrf_sound.h"
--- a/src/newgrf_sound.h	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/newgrf_sound.h	Mon Mar 31 07:50:27 2008 +0000
@@ -6,6 +6,7 @@
 #define NEWGRF_SOUND_H
 
 #include "sound_type.h"
+#include "tile_type.h"
 
 enum VehicleSoundEvent {
 	VSE_START        = 1,
--- a/src/newgrf_spritegroup.h	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/newgrf_spritegroup.h	Mon Mar 31 07:50:27 2008 +0000
@@ -7,10 +7,15 @@
 
 #include "town_type.h"
 #include "industry_type.h"
-#include "newgrf_storage.h"
 #include "core/bitmath_func.hpp"
 #include "gfx_type.h"
+#include "engine_type.h"
+#include "tile_type.h"
+
+#include "newgrf_cargo.h"
+#include "newgrf_callbacks.h"
 #include "newgrf_generic.h"
+#include "newgrf_storage.h"
 
 /**
  * Gets the value of a so-called newgrf "register".
--- a/src/newgrf_station.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/newgrf_station.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -9,7 +9,7 @@
 #include "landscape.h"
 #include "debug.h"
 #include "sprite.h"
-#include "station.h"
+#include "station_base.h"
 #include "station_map.h"
 #include "newgrf.h"
 #include "newgrf_callbacks.h"
--- a/src/newgrf_station.h	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/newgrf_station.h	Mon Mar 31 07:50:27 2008 +0000
@@ -5,11 +5,14 @@
 #ifndef NEWGRF_STATION_H
 #define NEWGRF_STATION_H
 
-#include "engine.h"
+#include "engine_type.h"
 #include "newgrf_callbacks.h"
 #include "newgrf_cargo.h"
 #include "tile_type.h"
+#include "station_type.h"
 #include "strings_type.h"
+#include "sprite.h"
+#include "direction_type.h"
 
 enum StationClassID {
 	STAT_CLASS_BEGIN = 0,    ///< the lowest valid value
@@ -120,12 +123,6 @@
 SpriteID GetCustomStationGroundRelocation(const StationSpec *statspec, const Station *st, TileIndex tile);
 uint16 GetStationCallback(CallbackID callback, uint32 param1, uint32 param2, const StationSpec *statspec, const Station *st, TileIndex tile);
 
-/* Check if a rail station tile is traversable. */
-bool IsStationTileBlocked(TileIndex tile);
-
-/* Check if a rail station tile is electrifiable. */
-bool IsStationTileElectrifiable(TileIndex tile);
-
 /* Allocate a StationSpec to a Station. This is called once per build operation. */
 int AllocateSpecToStation(const StationSpec *statspec, Station *st, bool exec);
 
--- a/src/newgrf_text.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/newgrf_text.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -19,6 +19,7 @@
 #include "core/alloc_func.hpp"
 #include "newgrf_storage.h"
 #include "string_func.h"
+#include "date_type.h"
 
 #include "table/strings.h"
 #include "table/control_codes.h"
@@ -642,7 +643,7 @@
 		case SCC_NEWGRF_PRINT_SIGNED_WORD:
 		case SCC_NEWGRF_PRINT_SIGNED_BYTE:
 		case SCC_NEWGRF_PRINT_UNSIGNED_WORD:
-			return SCC_NUM;
+			return SCC_COMMA;
 
 		case SCC_NEWGRF_PRINT_DWORD_CURRENCY:
 		case SCC_NEWGRF_PRINT_QWORD_CURRENCY:
--- a/src/news_gui.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/news_gui.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -134,7 +134,6 @@
 
 		case WE_PAINT: {
 			const NewsItem *ni = WP(w, news_d).ni;
-			ViewPort *vp;
 
 			switch (ni->display_mode) {
 				case NM_NORMAL:
@@ -158,7 +157,7 @@
 						_transparency_opt = to_backup;
 
 						/* Shade the viewport into gray, or color*/
-						vp = w->viewport;
+						ViewPort *vp = w->viewport;
 						GfxFillRect(vp->left - w->left, vp->top - w->top,
 							vp->left - w->left + vp->width - 1, vp->top - w->top + vp->height - 1,
 							(ni->flags & NF_INCOLOR ? PALETTE_TO_TRANSPARENT : PALETTE_TO_STRUCT_GREY) | (1 << USE_COLORTABLE)
@@ -170,12 +169,11 @@
 					break;
 				}
 
-				case NM_CALLBACK: {
+				case NM_CALLBACK:
 					_draw_news_callback[ni->callback](w, ni);
 					break;
-				}
 
-				default: {
+				default:
 					DrawWindowWidgets(w);
 					if (!(ni->flags & NF_VIEWPORT)) {
 						CopyInDParam(0, ni->params, lengthof(ni->params));
@@ -186,7 +184,6 @@
 						DrawStringMultiCenter(w->width / 2, w->height - 16, ni->string_id, w->width - 4);
 					}
 					break;
-				}
 			}
 		} break;
 
@@ -246,7 +243,7 @@
  * Return the correct index in the pseudo-fifo
  * queue and deals with overflows when increasing the index
  */
-static inline NewsID increaseIndex(NewsID i)
+static inline NewsID IncreaseIndex(NewsID i)
 {
 	assert(i != INVALID_NEWS);
 	return (i + 1) % MAX_NEWS;
@@ -256,7 +253,7 @@
  * Return the correct index in the pseudo-fifo
  * queue and deals with overflows when decreasing the index
  */
-static inline NewsID decreaseIndex(NewsID i)
+static inline NewsID DecreaseIndex(NewsID i)
 {
 	assert(i != INVALID_NEWS);
 	return (i + MAX_NEWS - 1) % MAX_NEWS;
@@ -288,26 +285,25 @@
  */
 void AddNewsItem(StringID string, NewsMode display_mode, NewsFlag flags, NewsType type, NewsCallback callback, uint data_a, uint data_b)
 {
-	NewsID l_news;
-
 	if (_game_mode == GM_MENU) return;
 
 	/* check the rare case that the oldest (to be overwritten) news item is open */
-	if (_total_news == MAX_NEWS && (_oldest_news == _current_news || _oldest_news == _forced_news))
+	if (_total_news == MAX_NEWS && (_oldest_news == _current_news || _oldest_news == _forced_news)) {
 		MoveToNextItem();
+	}
 
 	if (_total_news < MAX_NEWS) _total_news++;
 
 	/* Increase _latest_news. If we have no news yet, use _oldest news as an
 	 * index. We cannot use 0 as _oldest_news can jump around due to
 	 * DeleteVehicleNews */
-	l_news = _latest_news;
-	_latest_news = (_latest_news == INVALID_NEWS) ? _oldest_news : increaseIndex(_latest_news);
+	NewsID l_news = _latest_news;
+	_latest_news = (_latest_news == INVALID_NEWS) ? _oldest_news : IncreaseIndex(_latest_news);
 
 	/* If the fifo-buffer is full, overwrite the oldest entry */
 	if (l_news != INVALID_NEWS && _latest_news == _oldest_news) {
 		assert(_total_news == MAX_NEWS);
-		_oldest_news = increaseIndex(_oldest_news);
+		_oldest_news = IncreaseIndex(_oldest_news);
 	}
 
 	/*DEBUG(misc, 0, "+cur %3d, old %2d, lat %3d, for %3d, tot %2d",
@@ -466,44 +462,42 @@
 /** Open up an own newspaper window for the news item */
 static void ShowNewspaper(NewsItem *ni)
 {
-	Window *w;
-	SoundFx sound;
-	int top;
 	ni->flags &= ~NF_FORCE_BIG;
 	ni->duration = 555;
 
-	sound = _news_sounds[ni->type];
+	SoundFx sound = _news_sounds[ni->type];
 	if (sound != 0) SndPlayFx(sound);
 
-	top = _screen.height;
+	int top = _screen.height;
+	Window *w;
 	switch (ni->display_mode) {
 		case NM_NORMAL:
-		case NM_CALLBACK: {
+		case NM_CALLBACK:
 			_news_type13_desc.top = top;
 			w = AllocateWindowDesc(&_news_type13_desc);
-			if (ni->flags & NF_VIEWPORT)
+			if (ni->flags & NF_VIEWPORT) {
 				AssignWindowViewport(w, 2, 58, 0x1AA, 0x6E,
 					ni->data_a | (ni->flags & NF_VEHICLE ? 0x80000000 : 0), ZOOM_LVL_NEWS);
+			}
 			break;
-		}
 
-		case NM_THIN: {
+		case NM_THIN:
 			_news_type2_desc.top = top;
 			w = AllocateWindowDesc(&_news_type2_desc);
-			if (ni->flags & NF_VIEWPORT)
+			if (ni->flags & NF_VIEWPORT) {
 				AssignWindowViewport(w, 2, 58, 0x1AA, 0x46,
 					ni->data_a | (ni->flags & NF_VEHICLE ? 0x80000000 : 0), ZOOM_LVL_NEWS);
+			}
 			break;
-		}
 
-		default: {
+		default:
 			_news_type0_desc.top = top;
 			w = AllocateWindowDesc(&_news_type0_desc);
-			if (ni->flags & NF_VIEWPORT)
+			if (ni->flags & NF_VIEWPORT) {
 				AssignWindowViewport(w, 3, 17, 0x112, 0x2F,
 					ni->data_a | (ni->flags & NF_VEHICLE ? 0x80000000 : 0), ZOOM_LVL_NEWS);
+			}
 			break;
-		}
 	}
 
 	/*DEBUG(misc, 0, " cur %3d, old %2d, lat %3d, for %3d, tot %2d",
@@ -516,12 +510,10 @@
 /** Show news item in the ticker */
 static void ShowTicker(const NewsItem *ni)
 {
-	Window *w;
-
 	if (_news_ticker_sound) SndPlayFx(SND_16_MORSE);
 
 	_statusbar_news_item = *ni;
-	w = FindWindowById(WC_STATUS_BAR, 0);
+	Window *w = FindWindowById(WC_STATUS_BAR, 0);
 	if (w != NULL) WP(w, def_d).data_1 = 360;
 }
 
@@ -532,16 +524,14 @@
  */
 static bool ReadyForNextItem()
 {
-	const Window *w;
 	NewsID item = (_forced_news == INVALID_NEWS) ? _current_news : _forced_news;
-	NewsItem *ni;
 
 	if (item >= MAX_NEWS) return true;
-	ni = &_news_items[item];
+	NewsItem *ni = &_news_items[item];
 
 	/* Ticker message
 	 * Check if the status bar message is still being displayed? */
-	w = FindWindowById(WC_STATUS_BAR, 0);
+	const Window *w = FindWindowById(WC_STATUS_BAR, 0);
 	if (w != NULL && WP(w, const def_d).data_1 > -1280) return false;
 
 	/* Newspaper message, decrement duration counter */
@@ -559,10 +549,8 @@
 
 	/* if we're not at the last item, then move on */
 	if (_current_news != _latest_news) {
-		NewsItem *ni;
-
-		_current_news = (_current_news == INVALID_NEWS) ? _oldest_news : increaseIndex(_current_news);
-		ni = &_news_items[_current_news];
+		_current_news = (_current_news == INVALID_NEWS) ? _oldest_news : IncreaseIndex(_current_news);
+		NewsItem *ni = &_news_items[_current_news];
 
 		/* check the date, don't show too old items */
 		if (_date - _news_items_age[ni->type] > ni->date) return;
@@ -628,13 +616,13 @@
 		/* Not forced any news yet, show the current one, unless a news window is
 		 * open (which can only be the current one), then show the previous item */
 		const Window *w = FindWindowById(WC_NEWS_WINDOW, 0);
-		ShowNewsMessage((w == NULL || (_current_news == _oldest_news)) ? _current_news : decreaseIndex(_current_news));
+		ShowNewsMessage((w == NULL || (_current_news == _oldest_news)) ? _current_news : DecreaseIndex(_current_news));
 	} else if (_forced_news == _oldest_news) {
 		/* We have reached the oldest news, start anew with the latest */
 		ShowNewsMessage(_latest_news);
 	} else {
 		/* 'Scrolling' through news history show each one in turn */
-		ShowNewsMessage(decreaseIndex(_forced_news));
+		ShowNewsMessage(DecreaseIndex(_forced_news));
 	}
 }
 
@@ -666,8 +654,6 @@
 static void DrawNewsString(int x, int y, uint16 color, const NewsItem *ni, uint maxw)
 {
 	char buffer[512], buffer2[512];
-	const char *ptr;
-	char *dest;
 	StringID str;
 
 	if (ni->display_mode == NM_CALLBACK) {
@@ -680,8 +666,8 @@
 	GetString(buffer, str, lastof(buffer));
 	/* Copy the just gotten string to another buffer to remove any formatting
 	 * from it such as big fonts, etc. */
-	ptr  = buffer;
-	dest = buffer2;
+	const char *ptr = buffer;
+	char *dest = buffer2;
 	WChar c_last = '\0';
 	for (;;) {
 		WChar c = Utf8Consume(&ptr);
@@ -708,46 +694,40 @@
 static void MessageHistoryWndProc(Window *w, WindowEvent *e)
 {
 	switch (e->event) {
-	case WE_PAINT: {
-		int y = 19;
-		NewsID p, show;
-
-		SetVScrollCount(w, _total_news);
-		DrawWindowWidgets(w);
-
-		if (_total_news == 0) break;
-		show = min(_total_news, w->vscroll.cap);
-
-		for (p = w->vscroll.pos; p < w->vscroll.pos + show; p++) {
-			/* get news in correct order */
-			const NewsItem *ni = &_news_items[getNews(p)];
+		case WE_PAINT: {
+			int y = 19;
 
-			SetDParam(0, ni->date);
-			DrawString(4, y, STR_SHORT_DATE, TC_WHITE);
-
-			DrawNewsString(82, y, TC_WHITE, ni, w->width - 95);
-			y += 12;
-		}
-		break;
-	}
+			SetVScrollCount(w, _total_news);
+			DrawWindowWidgets(w);
 
-	case WE_CLICK:
-		switch (e->we.click.widget) {
-		case 3: {
-			int y = (e->we.click.pt.y - 19) / 12;
-			NewsID p = getNews(y + w->vscroll.pos);
+			if (_total_news == 0) break;
+			NewsID show = min(_total_news, w->vscroll.cap);
 
-			if (p == INVALID_NEWS) break;
+			for (NewsID p = w->vscroll.pos; p < w->vscroll.pos + show; p++) {
+				/* get news in correct order */
+				const NewsItem *ni = &_news_items[getNews(p)];
 
-			ShowNewsMessage(p);
+				SetDParam(0, ni->date);
+				DrawString(4, y, STR_SHORT_DATE, TC_WHITE);
+
+				DrawNewsString(82, y, TC_WHITE, ni, w->width - 95);
+				y += 12;
+			}
 			break;
 		}
-		}
-		break;
 
-	case WE_RESIZE:
-		w->vscroll.cap += e->we.sizing.diff.y / 12;
-		break;
+		case WE_CLICK:
+			if (e->we.click.widget == 3) {
+				int y = (e->we.click.pt.y - 19) / 12;
+				NewsID p = getNews(y + w->vscroll.pos);
+
+				if (p != INVALID_NEWS) ShowNewsMessage(p);
+			}
+			break;
+
+		case WE_RESIZE:
+			w->vscroll.cap += e->we.sizing.diff.y / 12;
+			break;
 	}
 }
 
@@ -772,10 +752,8 @@
 /** Display window with news messages history */
 void ShowMessageHistory()
 {
-	Window *w;
-
 	DeleteWindowById(WC_MESSAGE_HISTORY, 0);
-	w = AllocateWindowDesc(&_message_history_desc);
+	Window *w = AllocateWindowDesc(&_message_history_desc);
 
 	if (w != NULL) {
 		w->vscroll.cap = 10;
@@ -827,11 +805,10 @@
 		case WE_CREATE: {
 			uint32 val = _news_display_opt;
 			uint32 all_val;
-			int i;
 
 			/* Set up the initial disabled buttons in the case of 'off' or 'full' */
 			all_val = val & 0x3;
-			for (i = 0; i < NT_END; i++, val >>= 2) {
+			for (int i = 0; i < NT_END; i++, val >>= 2) {
 				SetMessageButtonStates(w, val & 0x3, i);
 				/* If the value doesn't match the ALL-button value, set the ALL-button value to 'off' */
 				if ((val & 0x3) != all_val) all_val = 0;
@@ -842,7 +819,6 @@
 
 		case WE_PAINT: {
 			uint32 val = _news_display_opt;
-			int i, y;
 
 			if (_news_ticker_sound) w->LowerWidget(WIDGET_NEWSOPT_SOUNDTICKER);
 
@@ -850,7 +826,7 @@
 			DrawWindowWidgets(w);
 
 			/* Draw the string of each setting on each button. */
-			for (i = 0, y = 26; i < NT_END; i++, y += 12, val >>= 2) {
+			for (int i = 0, y = 26; i < NT_END; i++, y += 12, val >>= 2) {
 				/* 51 comes from 13 + 89 (left and right of the button)+1, shiefted by one as to get division,
 				 * which will give centered position */
 				DrawStringCentered(51, y + 1, message_opt[val & 0x3], TC_BLACK);
@@ -880,19 +856,18 @@
 						SetWindowDirty(w);
 					}
 				} break;
-			} break;
+			}
+			break;
 
-		case WE_DROPDOWN_SELECT: { // Select all settings for newsmessages
-			int i;
-
+		case WE_DROPDOWN_SELECT: // Select all settings for newsmessages
 			WP(w, def_d).data_1 = e->we.dropdown.index;
 
-			for (i = 0; i < NT_END; i++) {
+			for (int i = 0; i < NT_END; i++) {
 				SetMessageButtonStates(w, e->we.dropdown.index, i);
 				SetNewsDisplayValue(i, e->we.dropdown.index);
 			}
 			SetWindowDirty(w);
-		} break;
+			break;
 	}
 }
 
@@ -1007,16 +982,12 @@
 
 void DeleteVehicleNews(VehicleID vid, StringID news)
 {
-	NewsID n;
-
-	for (n = _oldest_news; _latest_news != INVALID_NEWS; n = increaseIndex(n)) {
+	for (NewsID n = _oldest_news; _latest_news != INVALID_NEWS; n = IncreaseIndex(n)) {
 		const NewsItem *ni = &_news_items[n];
 
 		if (ni->flags & NF_VEHICLE &&
 				ni->data_a == vid &&
 				(news == INVALID_STRING_ID || ni->string_id == news)) {
-			Window *w;
-
 			/* If we delete a forced news and it is just before the current news
 			 * then we need to advance to the next news (if any) */
 			if (_forced_news == n) MoveToNextItem();
@@ -1039,27 +1010,27 @@
 			 * We also need an update of the current, forced and visible (open window)
 			 * news's as this shifting could change the items they were pointing to */
 			if (_total_news != 0) {
-				w = FindWindowById(WC_NEWS_WINDOW, 0);
+				Window *w = FindWindowById(WC_NEWS_WINDOW, 0);
 				NewsID visible_news = (w != NULL) ? (NewsID)(WP(w, news_d).ni - _news_items) : INVALID_NEWS;
 
-				for (NewsID i = n;; i = decreaseIndex(i)) {
-					_news_items[i] = _news_items[decreaseIndex(i)];
+				for (NewsID i = n;; i = DecreaseIndex(i)) {
+					_news_items[i] = _news_items[DecreaseIndex(i)];
 
 					if (i != _latest_news) {
-						if (i == _current_news) _current_news = increaseIndex(_current_news);
-						if (i == _forced_news) _forced_news = increaseIndex(_forced_news);
-						if (i == visible_news) WP(w, news_d).ni = &_news_items[increaseIndex(visible_news)];
+						if (i == _current_news) _current_news = IncreaseIndex(_current_news);
+						if (i == _forced_news) _forced_news = IncreaseIndex(_forced_news);
+						if (i == visible_news) WP(w, news_d).ni = &_news_items[IncreaseIndex(visible_news)];
 					}
 
 					if (i == _oldest_news) break;
 				}
-				_oldest_news = increaseIndex(_oldest_news);
+				_oldest_news = IncreaseIndex(_oldest_news);
 			}
 
 			/*DEBUG(misc, 0, "-cur %3d, old %2d, lat %3d, for %3d, tot %2d",
 			  _current_news, _oldest_news, _latest_news, _forced_news, _total_news);*/
 
-			w = FindWindowById(WC_MESSAGE_HISTORY, 0);
+			Window *w = FindWindowById(WC_MESSAGE_HISTORY, 0);
 			if (w != NULL) {
 				SetWindowDirty(w);
 				w->vscroll.count = _total_news;
--- a/src/npf.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/npf.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -12,7 +12,7 @@
 #include "landscape.h"
 #include "aystar.h"
 #include "pathfind.h"
-#include "station.h"
+#include "station_base.h"
 #include "station_map.h"
 #include "depot.h"
 #include "tunnel_map.h"
--- a/src/npf.h	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/npf.h	Mon Mar 31 07:50:27 2008 +0000
@@ -6,7 +6,9 @@
 #define NPF_H
 
 #include "aystar.h"
-#include "station.h"
+#include "station_type.h"
+#include "rail_type.h"
+#include "player_type.h"
 #include "vehicle_type.h"
 #include "tile_type.h"
 #include "track_type.h"
--- a/src/oldloader.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/oldloader.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -7,15 +7,13 @@
 #include "station_map.h"
 #include "town.h"
 #include "industry.h"
-#include "station.h"
 #include "player_func.h"
 #include "player_base.h"
-#include "engine.h"
 #include "aircraft.h"
 #include "roadveh.h"
 #include "ship.h"
 #include "train.h"
-#include "signs.h"
+#include "signs_base.h"
 #include "debug.h"
 #include "depot.h"
 #include "newgrf_config.h"
--- a/src/openttd.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/openttd.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -3,34 +3,41 @@
 /** @file openttd.cpp */
 
 #include "stdafx.h"
+
 #define VARDEF
-#include "debug.h"
-#include "driver.h"
-#include "saveload.h"
-#include "ai/ai_factory.hpp"
+#include "variables.h"
+#include "network/network_internal.h"
+#undef VARDEF
 
 #include "openttd.h"
-#include "bridge_map.h"
-#include "mixer.h"
-#include "spritecache.h"
+
+#include "driver.h"
+#include "blitter/factory.hpp"
+#include "sound/sound_driver.hpp"
+#include "music/music_driver.hpp"
+#include "video/video_driver.hpp"
+#include "ai/ai_factory.hpp"
+
+#include "fontcache.h"
 #include "gfxinit.h"
+#include "gfx_func.h"
 #include "gui.h"
-#include "landscape.h"
-#include "station.h"
-#include "station_map.h"
-#include "town_map.h"
-#include "tunnel_map.h"
+#include "mixer.h"
+#include "sound_func.h"
 #include "viewport_func.h"
-#include "gfx_func.h"
 #include "window_func.h"
 #include "window_gui.h"
+#include "zoom_func.h"
+
+#include "debug.h"
+#include "saveload.h"
+#include "landscape.h"
 #include "player_func.h"
 #include "player_base.h"
 #include "command_func.h"
 #include "town.h"
 #include "industry.h"
 #include "news_func.h"
-#include "engine.h"
 #include "fileio.h"
 #include "fios.h"
 #include "airport.h"
@@ -38,8 +45,8 @@
 #include "console.h"
 #include "screenshot.h"
 #include "network/network.h"
-#include "network/network_internal.h"
-#include "signs.h"
+#include "signs_base.h"
+#include "signs_func.h"
 #include "depot.h"
 #include "waypoint.h"
 #include "ai/ai.h"
@@ -47,35 +54,29 @@
 #include "yapf/yapf.h"
 #include "settings_func.h"
 #include "genworld.h"
-#include "clear_map.h"
-#include "fontcache.h"
+#include "player_face.h"
+#include "group.h"
+#include "strings_func.h"
+#include "date_func.h"
+#include "vehicle_func.h"
+
 #include "newgrf.h"
 #include "newgrf_config.h"
 #include "newgrf_house.h"
 #include "newgrf_commons.h"
-#include "newgrf_storage.h"
-#include "player_face.h"
-#include "group.h"
-#include "blitter/factory.hpp"
-#include "sound/sound_driver.hpp"
-#include "music/music_driver.hpp"
-#include "video/video_driver.hpp"
-#include "strings_func.h"
-#include "zoom_func.h"
-#include "date_func.h"
-#include "vehicle_func.h"
-#include "sound_func.h"
-#include "variables.h"
-#include "road_func.h"
+#include "newgrf_station.h"
 
-#include "bridge_map.h"
 #include "clear_map.h"
+#include "tree_map.h"
 #include "rail_map.h"
 #include "road_map.h"
-#include "water_map.h"
+#include "station_map.h"
+#include "town_map.h"
 #include "industry_map.h"
 #include "unmovable_map.h"
-#include "tree_map.h"
+#include "tunnel_map.h"
+#include "bridge_map.h"
+#include "water_map.h"
 #include "tunnelbridge_map.h"
 #include "void_map.h"
 #include "water.h"
--- a/src/openttd.h	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/openttd.h	Mon Mar 31 07:50:27 2008 +0000
@@ -9,38 +9,9 @@
 #endif
 
 // Forward declarations of structs.
-struct Depot;
-struct Waypoint;
-struct Station;
-struct ViewPort;
-struct DrawPixelInfo;
-struct Group;
-typedef byte VehicleOrderID;  ///< The index of an order within its current vehicle (not pool related)
 typedef byte LandscapeID;
-typedef uint16 EngineID;
 typedef uint16 UnitID;
 
-typedef EngineID *EngineList; ///< engine list type placeholder acceptable for C code (see helpers.cpp)
-
-/* IDs used in Pools */
-typedef uint16 StationID;
-static const StationID INVALID_STATION = 0xFFFF;
-typedef uint16 RoadStopID;
-typedef uint16 DepotID;
-typedef uint16 WaypointID;
-typedef uint16 OrderID;
-typedef uint16 SignID;
-typedef uint16 GroupID;
-typedef uint16 EngineRenewID;
-typedef uint16 DestinationID;
-
-/* DestinationID must be at least as large as every these below, because it can
- * be any of them
- */
-assert_compile(sizeof(DestinationID) >= sizeof(DepotID));
-assert_compile(sizeof(DestinationID) >= sizeof(WaypointID));
-assert_compile(sizeof(DestinationID) >= sizeof(StationID));
-
 enum GameModes {
 	GM_MENU,
 	GM_NORMAL,
--- a/src/order.h	Mon Mar 31 07:37:51 2008 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,235 +0,0 @@
-/* $Id$ */
-
-/** @file order.h */
-
-#ifndef ORDER_H
-#define ORDER_H
-
-#include "oldpool.h"
-#include "core/bitmath_func.hpp"
-#include "cargo_type.h"
-#include "vehicle_type.h"
-#include "tile_type.h"
-#include "date_type.h"
-
-enum {
-	INVALID_VEH_ORDER_ID = 0xFF,
-};
-
-static const OrderID INVALID_ORDER = 0xFFFF;
-
-/* Order types */
-enum OrderType {
-	OT_BEGIN         = 0,
-	OT_NOTHING       = 0,
-	OT_GOTO_STATION  = 1,
-	OT_GOTO_DEPOT    = 2,
-	OT_LOADING       = 3,
-	OT_LEAVESTATION  = 4,
-	OT_DUMMY         = 5,
-	OT_GOTO_WAYPOINT = 6,
-	OT_END
-};
-
-/* It needs to be 8bits, because we save and load it as such */
-/** Define basic enum properties */
-template <> struct EnumPropsT<OrderType> : MakeEnumPropsT<OrderType, byte, OT_BEGIN, OT_END, OT_END> {};
-typedef TinyEnumT<OrderType> OrderTypeByte;
-
-
-/* Order flags -- please use OF instead OF and use HASBIT/SETBIT/CLEARBIT */
-
-/** Order flag masks - these are for direct bit operations */
-enum OrderFlagMasks {
-	//Flags for stations:
-	/** vehicle will transfer cargo (i. e. not deliver to nearby industry/town even if accepted there) */
-	OFB_TRANSFER           = 0x1,
-	/** If OFB_TRANSFER is not set, drop any cargo loaded. If accepted, deliver, otherwise cargo remains at the station.
-      * No new cargo is loaded onto the vehicle whatsoever */
-	OFB_UNLOAD             = 0x2,
-	/** Wait for full load of all vehicles, or of at least one cargo type, depending on patch setting
-	  * @todo make this two different flags */
-	OFB_FULL_LOAD          = 0x4,
-
-	//Flags for depots:
-	/** The current depot-order was initiated because it was in the vehicle's order list */
-	OFB_PART_OF_ORDERS     = 0x2,
-	/** if OFB_PART_OF_ORDERS is not set, this will cause the vehicle to be stopped in the depot */
-	OFB_HALT_IN_DEPOT      = 0x4,
-	/** if OFB_PART_OF_ORDERS is set, this will cause the order only be come active if the vehicle needs servicing */
-	OFB_SERVICE_IF_NEEDED  = 0x4, //used when OFB_PART_OF_ORDERS is set.
-
-	//Common flags
-	/** This causes the vehicle not to stop at intermediate OR the destination station (depending on patch settings)
-	  * @todo make this two different flags */
-	OFB_NON_STOP           = 0x8
-};
-
-/** Order flags bits - these are for the *BIT macros
- * for descrption of flags, see OrderFlagMasks
- * @see OrderFlagMasks
- */
-enum {
-	OF_TRANSFER          = 0,
-	OF_UNLOAD            = 1,
-	OF_FULL_LOAD         = 2,
-	OF_PART_OF_ORDERS    = 1,
-	OF_HALT_IN_DEPOT     = 2,
-	OF_SERVICE_IF_NEEDED = 2,
-	OF_NON_STOP          = 3
-};
-
-
-/* Possible clone options */
-enum {
-	CO_SHARE   = 0,
-	CO_COPY    = 1,
-	CO_UNSHARE = 2
-};
-
-struct Order;
-DECLARE_OLD_POOL(Order, Order, 6, 1000)
-
-/* If you change this, keep in mind that it is saved on 3 places:
- * - Load_ORDR, all the global orders
- * - Vehicle -> current_order
- * - REF_ORDER (all REFs are currently limited to 16 bits!!)
- */
-struct Order : PoolItem<Order, OrderID, &_Order_pool> {
-	Order *next;          ///< Pointer to next order. If NULL, end of list
-
-	OrderTypeByte type;
-	uint8  flags;
-	DestinationID dest;   ///< The destionation of the order.
-
-	CargoID refit_cargo; // Refit CargoID
-	byte refit_subtype; // Refit subtype
-
-	uint16 wait_time;    ///< How long in ticks to wait at the destination.
-	uint16 travel_time;  ///< How long in ticks the journey to this destination should take.
-
-	Order() : refit_cargo(CT_NO_REFIT) {}
-	~Order() { this->type = OT_NOTHING; }
-
-	/**
-	 * Check if a Order really exists.
-	 */
-	inline bool IsValid() const { return this->type != OT_NOTHING; }
-
-	void Free();
-	void FreeChain();
-};
-
-struct BackuppedOrders {
-	BackuppedOrders() : order(NULL), name(NULL) { }
-	~BackuppedOrders() { free(order); free(name); }
-
-	VehicleID clone;
-	VehicleOrderID orderindex;
-	GroupID group;
-	Order *order;
-	uint16 service_interval;
-	char *name;
-};
-
-extern TileIndex _backup_orders_tile;
-extern BackuppedOrders _backup_orders_data;
-
-static inline VehicleOrderID GetMaxOrderIndex()
-{
-	/* TODO - This isn't the real content of the function, but
-	 *  with the new pool-system this will be replaced with one that
-	 *  _really_ returns the highest index. Now it just returns
-	 *  the next safe value we are sure about everything is below.
-	 */
-	return GetOrderPoolSize() - 1;
-}
-
-static inline VehicleOrderID GetNumOrders()
-{
-	return GetOrderPoolSize();
-}
-
-inline void Order::Free()
-{
-	this->type  = OT_NOTHING;
-	this->flags = 0;
-	this->dest  = 0;
-	this->next  = NULL;
-}
-
-inline void Order::FreeChain()
-{
-	if (next != NULL) next->FreeChain();
-	delete this;
-}
-
-#define FOR_ALL_ORDERS_FROM(order, start) for (order = GetOrder(start); order != NULL; order = (order->index + 1U < GetOrderPoolSize()) ? GetOrder(order->index + 1U) : NULL) if (order->IsValid())
-#define FOR_ALL_ORDERS(order) FOR_ALL_ORDERS_FROM(order, 0)
-
-
-#define FOR_VEHICLE_ORDERS(v, order) for (order = v->orders; order != NULL; order = order->next)
-
-static inline bool HasOrderPoolFree(uint amount)
-{
-	const Order *order;
-
-	/* There is always room if not all blocks in the pool are reserved */
-	if (_Order_pool.CanAllocateMoreBlocks()) return true;
-
-	FOR_ALL_ORDERS(order) if (!order->IsValid() && --amount == 0) return true;
-
-	return false;
-}
-
-
-/* Pack and unpack routines */
-
-static inline uint32 PackOrder(const Order *order)
-{
-	return order->dest << 16 | order->flags << 8 | order->type;
-}
-
-static inline Order UnpackOrder(uint32 packed)
-{
-	Order order;
-	order.type    = (OrderType)GB(packed,  0,  8);
-	order.flags   = GB(packed,  8,  8);
-	order.dest    = GB(packed, 16, 16);
-	order.next    = NULL;
-	order.index   = 0; // avoid compiler warning
-	order.refit_cargo   = CT_NO_REFIT;
-	order.refit_subtype = 0;
-	order.wait_time     = 0;
-	order.travel_time   = 0;
-	return order;
-}
-
-/* Functions */
-void BackupVehicleOrders(const Vehicle *v, BackuppedOrders *order = &_backup_orders_data);
-void RestoreVehicleOrders(const Vehicle *v, const BackuppedOrders *order = &_backup_orders_data);
-void RemoveOrderFromAllVehicles(OrderType type, DestinationID destination);
-void InvalidateVehicleOrder(const Vehicle *v);
-bool VehicleHasDepotOrders(const Vehicle *v);
-void CheckOrders(const Vehicle*);
-void DeleteVehicleOrders(Vehicle *v);
-void AssignOrder(Order *order, Order data);
-bool CheckForValidOrders(const Vehicle* v);
-
-Order UnpackOldOrder(uint16 packed);
-
-#define MIN_SERVINT_PERCENT  5
-#define MAX_SERVINT_PERCENT 90
-#define MIN_SERVINT_DAYS    30
-#define MAX_SERVINT_DAYS   800
-
-/**
- * Get the service interval domain.
- * Get the new proposed service interval for the vehicle is indeed, clamped
- * within the given bounds. @see MIN_SERVINT_PERCENT ,etc.
- * @param index proposed service interval
- * @return service interval
- */
-Date GetServiceIntervalClamped(uint index);
-
-#endif /* ORDER_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/order_base.h	Mon Mar 31 07:50:27 2008 +0000
@@ -0,0 +1,118 @@
+/* $Id$ */
+
+/** @file order_base.h */
+
+#ifndef ORDER_BASE_H
+#define ORDER_BASE_H
+
+#include "order_type.h"
+#include "oldpool.h"
+#include "core/bitmath_func.hpp"
+#include "cargo_type.h"
+
+DECLARE_OLD_POOL(Order, Order, 6, 1000)
+
+/* If you change this, keep in mind that it is saved on 3 places:
+ * - Load_ORDR, all the global orders
+ * - Vehicle -> current_order
+ * - REF_ORDER (all REFs are currently limited to 16 bits!!)
+ */
+struct Order : PoolItem<Order, OrderID, &_Order_pool> {
+	Order *next;          ///< Pointer to next order. If NULL, end of list
+
+	OrderTypeByte type;
+	uint8  flags;
+	DestinationID dest;   ///< The destionation of the order.
+
+	CargoID refit_cargo; // Refit CargoID
+	byte refit_subtype; // Refit subtype
+
+	uint16 wait_time;    ///< How long in ticks to wait at the destination.
+	uint16 travel_time;  ///< How long in ticks the journey to this destination should take.
+
+	Order() : refit_cargo(CT_NO_REFIT) {}
+	~Order() { this->type = OT_NOTHING; }
+
+	/**
+	 * Check if a Order really exists.
+	 */
+	inline bool IsValid() const { return this->type != OT_NOTHING; }
+
+	void Free();
+	void FreeChain();
+};
+
+static inline VehicleOrderID GetMaxOrderIndex()
+{
+	/* TODO - This isn't the real content of the function, but
+	 *  with the new pool-system this will be replaced with one that
+	 *  _really_ returns the highest index. Now it just returns
+	 *  the next safe value we are sure about everything is below.
+	 */
+	return GetOrderPoolSize() - 1;
+}
+
+static inline VehicleOrderID GetNumOrders()
+{
+	return GetOrderPoolSize();
+}
+
+inline void Order::Free()
+{
+	this->type  = OT_NOTHING;
+	this->flags = 0;
+	this->dest  = 0;
+	this->next  = NULL;
+}
+
+inline void Order::FreeChain()
+{
+	if (next != NULL) next->FreeChain();
+	delete this;
+}
+
+#define FOR_ALL_ORDERS_FROM(order, start) for (order = GetOrder(start); order != NULL; order = (order->index + 1U < GetOrderPoolSize()) ? GetOrder(order->index + 1U) : NULL) if (order->IsValid())
+#define FOR_ALL_ORDERS(order) FOR_ALL_ORDERS_FROM(order, 0)
+
+
+#define FOR_VEHICLE_ORDERS(v, order) for (order = v->orders; order != NULL; order = order->next)
+
+static inline bool HasOrderPoolFree(uint amount)
+{
+	const Order *order;
+
+	/* There is always room if not all blocks in the pool are reserved */
+	if (_Order_pool.CanAllocateMoreBlocks()) return true;
+
+	FOR_ALL_ORDERS(order) if (!order->IsValid() && --amount == 0) return true;
+
+	return false;
+}
+
+
+/* Pack and unpack routines */
+
+static inline uint32 PackOrder(const Order *order)
+{
+	return order->dest << 16 | order->flags << 8 | order->type;
+}
+
+static inline Order UnpackOrder(uint32 packed)
+{
+	Order order;
+	order.type    = (OrderType)GB(packed,  0,  8);
+	order.flags   = GB(packed,  8,  8);
+	order.dest    = GB(packed, 16, 16);
+	order.next    = NULL;
+	order.index   = 0; // avoid compiler warning
+	order.refit_cargo   = CT_NO_REFIT;
+	order.refit_subtype = 0;
+	order.wait_time     = 0;
+	order.travel_time   = 0;
+	return order;
+}
+
+void AssignOrder(Order *order, Order data);
+Order UnpackOldOrder(uint16 packed);
+
+#endif /* ORDER_H */
--- a/src/order_cmd.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/order_cmd.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -4,12 +4,12 @@
 
 #include "stdafx.h"
 #include "openttd.h"
-#include "order.h"
+#include "order_base.h"
+#include "order_func.h"
 #include "airport.h"
 #include "depot.h"
 #include "waypoint.h"
 #include "command_func.h"
-#include "station.h"
 #include "player_func.h"
 #include "news_func.h"
 #include "saveload.h"
@@ -22,9 +22,17 @@
 #include "window_func.h"
 #include "settings_type.h"
 #include "string_func.h"
+#include "newgrf_cargo.h"
 
 #include "table/strings.h"
 
+/* DestinationID must be at least as large as every these below, because it can
+ * be any of them
+ */
+assert_compile(sizeof(DestinationID) >= sizeof(DepotID));
+assert_compile(sizeof(DestinationID) >= sizeof(WaypointID));
+assert_compile(sizeof(DestinationID) >= sizeof(StationID));
+
 TileIndex _backup_orders_tile;
 BackuppedOrders _backup_orders_data;
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/order_func.h	Mon Mar 31 07:50:27 2008 +0000
@@ -0,0 +1,54 @@
+/* $Id$ */
+
+/** @file order_func.h Functions related to orders. */
+
+#ifndef ORDER_FUNC_H
+#define ORDER_FUNC_H
+
+#include "order_type.h"
+#include "vehicle_type.h"
+#include "tile_type.h"
+#include "group_type.h"
+#include "date_type.h"
+
+struct BackuppedOrders {
+	BackuppedOrders() : order(NULL), name(NULL) { }
+	~BackuppedOrders() { free(order); free(name); }
+
+	VehicleID clone;
+	VehicleOrderID orderindex;
+	GroupID group;
+	Order *order;
+	uint16 service_interval;
+	char *name;
+};
+
+extern TileIndex _backup_orders_tile;
+extern BackuppedOrders _backup_orders_data;
+
+void BackupVehicleOrders(const Vehicle *v, BackuppedOrders *order = &_backup_orders_data);
+void RestoreVehicleOrders(const Vehicle *v, const BackuppedOrders *order = &_backup_orders_data);
+
+/* Functions */
+void RemoveOrderFromAllVehicles(OrderType type, DestinationID destination);
+void InvalidateVehicleOrder(const Vehicle *v);
+bool VehicleHasDepotOrders(const Vehicle *v);
+void CheckOrders(const Vehicle*);
+void DeleteVehicleOrders(Vehicle *v);
+bool CheckForValidOrders(const Vehicle* v);
+
+#define MIN_SERVINT_PERCENT  5
+#define MAX_SERVINT_PERCENT 90
+#define MIN_SERVINT_DAYS    30
+#define MAX_SERVINT_DAYS   800
+
+/**
+ * Get the service interval domain.
+ * Get the new proposed service interval for the vehicle is indeed, clamped
+ * within the given bounds. @see MIN_SERVINT_PERCENT ,etc.
+ * @param index proposed service interval
+ * @return service interval
+ */
+Date GetServiceIntervalClamped(uint index);
+
+#endif /* ORDER_FUNC_H */
--- a/src/order_gui.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/order_gui.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -8,7 +8,7 @@
 #include "station_map.h"
 #include "gui.h"
 #include "window_gui.h"
-#include "station.h"
+#include "station_base.h"
 #include "town.h"
 #include "command_func.h"
 #include "viewport_func.h"
@@ -20,12 +20,12 @@
 #include "vehicle_gui.h"
 #include "timetable.h"
 #include "cargotype.h"
-#include "order.h"
 #include "strings_func.h"
 #include "window_func.h"
 #include "vehicle_func.h"
 #include "settings_type.h"
 #include "player_func.h"
+#include "newgrf_cargo.h"
 
 #include "table/sprites.h"
 #include "table/strings.h"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/order_type.h	Mon Mar 31 07:50:27 2008 +0000
@@ -0,0 +1,91 @@
+/* $Id$ */
+
+/** @file order_type.h Types related to orders. */
+
+#ifndef ORDER_TYPE_H
+#define ORDER_TYPE_H
+
+#include "core/enum_type.hpp"
+
+typedef byte VehicleOrderID;  ///< The index of an order within its current vehicle (not pool related)
+typedef uint16 OrderID;
+typedef uint16 DestinationID;
+
+enum {
+	INVALID_VEH_ORDER_ID = 0xFF,
+};
+
+static const OrderID INVALID_ORDER = 0xFFFF;
+
+/* Order types */
+enum OrderType {
+	OT_BEGIN         = 0,
+	OT_NOTHING       = 0,
+	OT_GOTO_STATION  = 1,
+	OT_GOTO_DEPOT    = 2,
+	OT_LOADING       = 3,
+	OT_LEAVESTATION  = 4,
+	OT_DUMMY         = 5,
+	OT_GOTO_WAYPOINT = 6,
+	OT_END
+};
+
+/* It needs to be 8bits, because we save and load it as such */
+/** Define basic enum properties */
+template <> struct EnumPropsT<OrderType> : MakeEnumPropsT<OrderType, byte, OT_BEGIN, OT_END, OT_END> {};
+typedef TinyEnumT<OrderType> OrderTypeByte;
+
+
+/* Order flags -- please use OF instead OF and use HASBIT/SETBIT/CLEARBIT */
+
+/** Order flag masks - these are for direct bit operations */
+enum OrderFlagMasks {
+	//Flags for stations:
+	/** vehicle will transfer cargo (i. e. not deliver to nearby industry/town even if accepted there) */
+	OFB_TRANSFER           = 0x1,
+	/** If OFB_TRANSFER is not set, drop any cargo loaded. If accepted, deliver, otherwise cargo remains at the station.
+      * No new cargo is loaded onto the vehicle whatsoever */
+	OFB_UNLOAD             = 0x2,
+	/** Wait for full load of all vehicles, or of at least one cargo type, depending on patch setting
+	  * @todo make this two different flags */
+	OFB_FULL_LOAD          = 0x4,
+
+	//Flags for depots:
+	/** The current depot-order was initiated because it was in the vehicle's order list */
+	OFB_PART_OF_ORDERS     = 0x2,
+	/** if OFB_PART_OF_ORDERS is not set, this will cause the vehicle to be stopped in the depot */
+	OFB_HALT_IN_DEPOT      = 0x4,
+	/** if OFB_PART_OF_ORDERS is set, this will cause the order only be come active if the vehicle needs servicing */
+	OFB_SERVICE_IF_NEEDED  = 0x4, //used when OFB_PART_OF_ORDERS is set.
+
+	//Common flags
+	/** This causes the vehicle not to stop at intermediate OR the destination station (depending on patch settings)
+	  * @todo make this two different flags */
+	OFB_NON_STOP           = 0x8
+};
+
+/** Order flags bits - these are for the *BIT macros
+ * for descrption of flags, see OrderFlagMasks
+ * @see OrderFlagMasks
+ */
+enum {
+	OF_TRANSFER          = 0,
+	OF_UNLOAD            = 1,
+	OF_FULL_LOAD         = 2,
+	OF_PART_OF_ORDERS    = 1,
+	OF_HALT_IN_DEPOT     = 2,
+	OF_SERVICE_IF_NEEDED = 2,
+	OF_NON_STOP          = 3
+};
+
+
+/* Possible clone options */
+enum {
+	CO_SHARE   = 0,
+	CO_COPY    = 1,
+	CO_UNSHARE = 2
+};
+
+struct Order;
+
+#endif /* ORDER_TYPE_H */
--- a/src/ottdres.rc.in	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/ottdres.rc.in	Mon Mar 31 07:50:27 2008 +0000
@@ -1,12 +1,11 @@
 //Microsoft Developer Studio generated resource script.
 // $Id$
 //
-#define APSTUDIO_READONLY_SYMBOLS
 /////////////////////////////////////////////////////////////////////////////
 //
 // Generated from the TEXTINCLUDE 2 resource.
 //
-#include "resource.h"
+#define APSTUDIO_READONLY_SYMBOLS
 #define APSTUDIO_HIDDEN_SYMBOLS
 #include "windows.h"
 #undef APSTUDIO_HIDDEN_SYMBOLS
@@ -87,7 +86,7 @@
             VALUE "FileDescription", "OpenTTD\0"
             VALUE "FileVersion", "Development @@VERSION@@\0"
             VALUE "InternalName", "openttd\0"
-            VALUE "LegalCopyright", "Copyright © OpenTTD Developers 2002-2007. All Rights Reserved.\0"
+            VALUE "LegalCopyright", "Copyright © OpenTTD Developers 2002-2008. All Rights Reserved.\0"
             VALUE "LegalTrademarks", "\0"
             VALUE "OriginalFilename", "openttd.exe\0"
             VALUE "PrivateBuild", "\0"
--- a/src/player_base.h	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/player_base.h	Mon Mar 31 07:50:27 2008 +0000
@@ -8,7 +8,7 @@
 #include "road_type.h"
 #include "rail_type.h"
 #include "date_type.h"
-#include "engine.h"
+#include "engine_type.h"
 #include "livery.h"
 #include "autoreplace_type.h"
 #include "economy_type.h"
--- a/src/players.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/players.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -4,18 +4,16 @@
  */
 #include "stdafx.h"
 #include "openttd.h"
-#include "engine.h"
+#include "engine_func.h"
 #include "player_func.h"
 #include "player_gui.h"
 #include "town.h"
-#include "station.h"
 #include "news_func.h"
 #include "saveload.h"
 #include "command_func.h"
 #include "network/network.h"
 #include "network/network_internal.h"
 #include "variables.h"
-#include "engine.h"
 #include "ai/ai.h"
 #include "player_face.h"
 #include "group.h"
@@ -33,6 +31,7 @@
 #include "road_func.h"
 #include "rail.h"
 #include "settings_type.h"
+#include "sprite.h"
 
 #include "table/strings.h"
 #include "table/sprites.h"
--- a/src/rail.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/rail.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -13,6 +13,7 @@
 #include "date_func.h"
 #include "player_func.h"
 #include "player_base.h"
+#include "engine_func.h"
 
 
 /* XXX: Below 3 tables store duplicate data. Maybe remove some? */
--- a/src/rail_cmd.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/rail_cmd.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -17,9 +17,8 @@
 #include "viewport_func.h"
 #include "command_func.h"
 #include "pathfind.h"
-#include "engine.h"
+#include "engine_func.h"
 #include "town.h"
-#include "station.h"
 #include "sprite.h"
 #include "depot.h"
 #include "waypoint.h"
--- a/src/rail_gui.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/rail_gui.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -13,7 +13,7 @@
 #include "viewport_func.h"
 #include "gfx_func.h"
 #include "command_func.h"
-#include "station.h"
+#include "town_type.h"
 #include "waypoint.h"
 #include "debug.h"
 #include "variables.h"
--- a/src/rail_map.h	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/rail_map.h	Mon Mar 31 07:50:27 2008 +0000
@@ -11,6 +11,7 @@
 #include "track_func.h"
 #include "tile_map.h"
 #include "signal_type.h"
+#include "waypoint_type.h"
 
 
 /** Different types of Rail-related tiles */
--- a/src/resource.h	Mon Mar 31 07:37:51 2008 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,19 +0,0 @@
-/* $Id$ */
-
-/** @file resource.h */
-
-//{{NO_DEPENDENCIES}}
-// Microsoft Developer Studio generated include file.
-// Used by ttd.rc
-//
-
-// Next default values for new objects
-//
-#ifdef APSTUDIO_INVOKED
-#ifndef APSTUDIO_READONLY_SYMBOLS
-#define _APS_NEXT_RESOURCE_VALUE        104
-#define _APS_NEXT_COMMAND_VALUE         40001
-#define _APS_NEXT_CONTROL_VALUE         1005
-#define _APS_NEXT_SYMED_VALUE           101
-#endif
-#endif
--- a/src/road.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/road.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -9,7 +9,7 @@
 #include "genworld.h"
 #include "player_func.h"
 #include "player_base.h"
-#include "engine.h"
+#include "engine_func.h"
 #include "settings_type.h"
 #include "date_func.h"
 
--- a/src/road_gui.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/road_gui.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -16,7 +16,6 @@
 #include "road_cmd.h"
 #include "road_map.h"
 #include "station_map.h"
-#include "station.h"
 #include "functions.h"
 #include "window_func.h"
 #include "vehicle_func.h"
@@ -27,7 +26,7 @@
 #include "table/sprites.h"
 #include "table/strings.h"
 
-static void ShowRVStationPicker(RoadStop::Type rs);
+static void ShowRVStationPicker(RoadStopType rs);
 static void ShowRoadDepotPicker();
 
 static bool _remove_button_clicked;
@@ -215,18 +214,18 @@
 static void PlaceRoad_BusStation(TileIndex tile)
 {
 	if (_remove_button_clicked) {
-		DoCommandP(tile, 0, RoadStop::BUS, CcPlaySound1D, CMD_REMOVE_ROAD_STOP | CMD_MSG(_road_type_infos[_cur_roadtype].err_remove_station[RoadStop::BUS]));
+		DoCommandP(tile, 0, ROADSTOP_BUS, CcPlaySound1D, CMD_REMOVE_ROAD_STOP | CMD_MSG(_road_type_infos[_cur_roadtype].err_remove_station[ROADSTOP_BUS]));
 	} else {
-		PlaceRoadStop(tile, (_ctrl_pressed << 5) | RoadTypeToRoadTypes(_cur_roadtype) << 2 | RoadStop::BUS, CMD_BUILD_ROAD_STOP | CMD_NO_WATER | CMD_MSG(_road_type_infos[_cur_roadtype].err_build_station[RoadStop::BUS]));
+		PlaceRoadStop(tile, (_ctrl_pressed << 5) | RoadTypeToRoadTypes(_cur_roadtype) << 2 | ROADSTOP_BUS, CMD_BUILD_ROAD_STOP | CMD_NO_WATER | CMD_MSG(_road_type_infos[_cur_roadtype].err_build_station[ROADSTOP_BUS]));
 	}
 }
 
 static void PlaceRoad_TruckStation(TileIndex tile)
 {
 	if (_remove_button_clicked) {
-		DoCommandP(tile, 0, RoadStop::TRUCK, CcPlaySound1D, CMD_REMOVE_ROAD_STOP | CMD_MSG(_road_type_infos[_cur_roadtype].err_remove_station[RoadStop::TRUCK]));
+		DoCommandP(tile, 0, ROADSTOP_TRUCK, CcPlaySound1D, CMD_REMOVE_ROAD_STOP | CMD_MSG(_road_type_infos[_cur_roadtype].err_remove_station[ROADSTOP_TRUCK]));
 	} else {
-		PlaceRoadStop(tile, (_ctrl_pressed << 5) | RoadTypeToRoadTypes(_cur_roadtype) << 2 | RoadStop::TRUCK, CMD_BUILD_ROAD_STOP | CMD_NO_WATER | CMD_MSG(_road_type_infos[_cur_roadtype].err_build_station[RoadStop::TRUCK]));
+		PlaceRoadStop(tile, (_ctrl_pressed << 5) | RoadTypeToRoadTypes(_cur_roadtype) << 2 | ROADSTOP_TRUCK, CMD_BUILD_ROAD_STOP | CMD_NO_WATER | CMD_MSG(_road_type_infos[_cur_roadtype].err_build_station[ROADSTOP_TRUCK]));
 	}
 }
 
@@ -334,13 +333,13 @@
 static void BuildRoadClick_BusStation(Window *w)
 {
 	if (_game_mode == GM_EDITOR || !CanBuildVehicleInfrastructure(VEH_ROAD)) return;
-	if (HandlePlacePushButton(w, RTW_BUS_STATION, SPR_CURSOR_BUS_STATION, VHM_RECT, PlaceRoad_BusStation)) ShowRVStationPicker(RoadStop::BUS);
+	if (HandlePlacePushButton(w, RTW_BUS_STATION, SPR_CURSOR_BUS_STATION, VHM_RECT, PlaceRoad_BusStation)) ShowRVStationPicker(ROADSTOP_BUS);
 }
 
 static void BuildRoadClick_TruckStation(Window *w)
 {
 	if (_game_mode == GM_EDITOR || !CanBuildVehicleInfrastructure(VEH_ROAD)) return;
-	if (HandlePlacePushButton(w, RTW_TRUCK_STATION, SPR_CURSOR_TRUCK_STATION, VHM_RECT, PlaceRoad_TruckStation)) ShowRVStationPicker(RoadStop::TRUCK);
+	if (HandlePlacePushButton(w, RTW_TRUCK_STATION, SPR_CURSOR_TRUCK_STATION, VHM_RECT, PlaceRoad_TruckStation)) ShowRVStationPicker(ROADSTOP_TRUCK);
 }
 
 /**
@@ -942,12 +941,12 @@
 	RoadStationPickerWndProc
 };
 
-static void ShowRVStationPicker(RoadStop::Type rs)
+static void ShowRVStationPicker(RoadStopType rs)
 {
 	Window *w = AllocateWindowDesc(&_rv_station_picker_desc);
 	if (w == NULL) return;
 
-	w->window_class = (rs == RoadStop::BUS) ? WC_BUS_STATION : WC_TRUCK_STATION;
+	w->window_class = (rs == ROADSTOP_BUS) ? WC_BUS_STATION : WC_TRUCK_STATION;
 	w->widget[BRSW_CAPTION].data = _road_type_infos[_cur_roadtype].picker_title[rs];
 	for (uint i = BRSW_STATION_NE; i < BRSW_LT_OFF; i++) w->widget[i].tooltips = _road_type_infos[_cur_roadtype].picker_tooltip[rs];
 }
--- a/src/road_map.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/road_map.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -7,7 +7,6 @@
 #include "bridge_map.h"
 #include "tile_cmd.h"
 #include "road_map.h"
-#include "station.h"
 #include "tunnel_map.h"
 #include "station_map.h"
 #include "depot.h"
--- a/src/roadveh.h	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/roadveh.h	Mon Mar 31 07:50:27 2008 +0000
@@ -6,7 +6,7 @@
 #define ROADVEH_H
 
 #include "vehicle_base.h"
-#include "engine.h"
+#include "engine_func.h"
 #include "economy_func.h"
 
 enum RoadVehicleSubType {
--- a/src/roadveh_cmd.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/roadveh_cmd.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -11,9 +11,8 @@
 #include "roadveh.h"
 #include "station_map.h"
 #include "timetable.h"
-#include "engine.h"
 #include "command_func.h"
-#include "station.h"
+#include "station_base.h"
 #include "news_func.h"
 #include "pathfind.h"
 #include "npf.h"
@@ -43,6 +42,7 @@
 #include "gfx_func.h"
 #include "ai/ai.h"
 #include "settings_type.h"
+#include "order_func.h"
 
 #include "table/strings.h"
 
@@ -1173,7 +1173,7 @@
 			trackdirs = TRACKDIR_BIT_NONE;
 		} else {
 			/* Our station */
-			RoadStop::Type rstype = IsCargoInClass(v->cargo_type, CC_PASSENGERS) ? RoadStop::BUS : RoadStop::TRUCK;
+			RoadStopType rstype = IsCargoInClass(v->cargo_type, CC_PASSENGERS) ? ROADSTOP_BUS : ROADSTOP_TRUCK;
 
 			if (GetRoadStopType(tile) != rstype) {
 				/* Wrong station type */
@@ -1809,7 +1809,7 @@
 			_road_veh_data_1[v->u.road.state - RVSB_IN_ROAD_STOP + (_opt.road_side << RVS_DRIVE_SIDE)] == v->u.road.frame) ||
 			(IsInsideMM(v->u.road.state, RVSB_IN_DT_ROAD_STOP, RVSB_IN_DT_ROAD_STOP_END) &&
 			v->current_order.dest == GetStationIndex(v->tile) &&
-			GetRoadStopType(v->tile) == (IsCargoInClass(v->cargo_type, CC_PASSENGERS) ? RoadStop::BUS : RoadStop::TRUCK) &&
+			GetRoadStopType(v->tile) == (IsCargoInClass(v->cargo_type, CC_PASSENGERS) ? ROADSTOP_BUS : ROADSTOP_TRUCK) &&
 			v->u.road.frame == RVC_DRIVE_THROUGH_STOP_FRAME))) {
 
 		RoadStop *rs = GetRoadStopByTile(v->tile, GetRoadStopType(v->tile));
@@ -1824,7 +1824,7 @@
 
 			if (IsDriveThroughStopTile(v->tile)) {
 				TileIndex next_tile = TILE_ADD(v->tile, TileOffsByDir(v->direction));
-				RoadStop::Type type = IsCargoInClass(v->cargo_type, CC_PASSENGERS) ? RoadStop::BUS : RoadStop::TRUCK;
+				RoadStopType type = IsCargoInClass(v->cargo_type, CC_PASSENGERS) ? ROADSTOP_BUS : ROADSTOP_TRUCK;
 
 				/* Check if next inline bay is free */
 				if (IsDriveThroughStopTile(next_tile) && (GetRoadStopType(next_tile) == type)) {
--- a/src/roadveh_gui.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/roadveh_gui.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -17,6 +17,7 @@
 #include "strings_func.h"
 #include "vehicle_func.h"
 #include "string_func.h"
+#include "order_func.h"
 
 #include "table/sprites.h"
 #include "table/strings.h"
--- a/src/saveload.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/saveload.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -16,7 +16,7 @@
 #include "stdafx.h"
 #include "openttd.h"
 #include "debug.h"
-#include "station.h"
+#include "station_base.h"
 #include "thread.h"
 #include "town.h"
 #include "saveload.h"
--- a/src/settings_gui.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/settings_gui.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -9,7 +9,7 @@
 #include "window_gui.h"
 #include "textbuf_gui.h"
 #include "command_func.h"
-#include "engine.h"
+#include "engine_func.h"
 #include "screenshot.h"
 #include "newgrf.h"
 #include "network/network.h"
@@ -27,6 +27,7 @@
 #include "waypoint.h"
 #include "widgets/dropdown_type.h"
 #include "widgets/dropdown_func.h"
+#include "station_func.h"
 
 #include "table/sprites.h"
 #include "table/strings.h"
--- a/src/ship.h	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/ship.h	Mon Mar 31 07:50:27 2008 +0000
@@ -6,7 +6,7 @@
 #define SHIP_H
 
 #include "vehicle_base.h"
-#include "engine.h"
+#include "engine_func.h"
 #include "economy_func.h"
 
 void CcBuildShip(bool success, TileIndex tile, uint32 p1, uint32 p2);
--- a/src/ship_cmd.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/ship_cmd.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -11,9 +11,9 @@
 #include "command_func.h"
 #include "pathfind.h"
 #include "station_map.h"
-#include "station.h"
+#include "station_base.h"
 #include "news_func.h"
-#include "engine.h"
+#include "engine_func.h"
 #include "player_func.h"
 #include "player_base.h"
 #include "npf.h"
@@ -38,6 +38,7 @@
 #include "autoreplace_gui.h"
 #include "gfx_func.h"
 #include "settings_type.h"
+#include "order_func.h"
 
 #include "table/strings.h"
 
--- a/src/ship_gui.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/ship_gui.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -15,6 +15,7 @@
 #include "newgrf_engine.h"
 #include "strings_func.h"
 #include "vehicle_func.h"
+#include "order_func.h"
 
 #include "table/strings.h"
 #include "table/sprites.h"
--- a/src/signs.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/signs.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -6,7 +6,8 @@
 #include "openttd.h"
 #include "landscape.h"
 #include "player_func.h"
-#include "signs.h"
+#include "signs_base.h"
+#include "signs_func.h"
 #include "saveload.h"
 #include "command_func.h"
 #include "variables.h"
--- a/src/signs.h	Mon Mar 31 07:37:51 2008 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,73 +0,0 @@
-/* $Id$ */
-
-/** @file signs.h */
-
-#ifndef SIGNS_H
-#define SIGNS_H
-
-#include "oldpool.h"
-
-struct Sign;
-DECLARE_OLD_POOL(Sign, Sign, 2, 16000)
-
-struct Sign : PoolItem<Sign, SignID, &_Sign_pool> {
-	char *name;
-	ViewportSign sign;
-	int32        x;
-	int32        y;
-	byte         z;
-	PlayerByte   owner; // placed by this player. Anyone can delete them though. OWNER_NONE for gray signs from old games.
-
-	/**
-	 * Creates a new sign
-	 */
-	Sign(PlayerID owner = INVALID_PLAYER);
-
-	/** Destroy the sign */
-	~Sign();
-
-	inline bool IsValid() const { return this->owner != INVALID_PLAYER; }
-};
-
-enum {
-	INVALID_SIGN = 0xFFFF,
-};
-
-extern SignID _new_sign_id;
-
-
-static inline SignID GetMaxSignIndex()
-{
-	/* TODO - This isn't the real content of the function, but
-	 *  with the new pool-system this will be replaced with one that
-	 *  _really_ returns the highest index. Now it just returns
-	 *  the next safe value we are sure about everything is below.
-	 */
-	return GetSignPoolSize() - 1;
-}
-
-static inline uint GetNumSigns()
-{
-	extern uint _total_signs;
-	return _total_signs;
-}
-
-static inline bool IsValidSignID(uint index)
-{
-	return index < GetSignPoolSize() && GetSign(index)->IsValid();
-}
-
-#define FOR_ALL_SIGNS_FROM(ss, start) for (ss = GetSign(start); ss != NULL; ss = (ss->index + 1U < GetSignPoolSize()) ? GetSign(ss->index + 1U) : NULL) if (ss->IsValid())
-#define FOR_ALL_SIGNS(ss) FOR_ALL_SIGNS_FROM(ss, 0)
-
-extern bool _sign_sort_dirty;
-
-void UpdateAllSignVirtCoords();
-void PlaceProc_Sign(TileIndex tile);
-
-/* signs_gui.cpp */
-void ShowRenameSignWindow(const Sign *si);
-
-void ShowSignList();
-
-#endif /* SIGNS_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/signs_base.h	Mon Mar 31 07:50:27 2008 +0000
@@ -0,0 +1,56 @@
+/* $Id$ */
+
+/** @file signs_base.h Base class for signs. */
+
+#ifndef SIGNS_BASE_H
+#define SIGNS_BASE_H
+
+#include "signs_type.h"
+#include "oldpool.h"
+
+DECLARE_OLD_POOL(Sign, Sign, 2, 16000)
+
+struct Sign : PoolItem<Sign, SignID, &_Sign_pool> {
+	char *name;
+	ViewportSign sign;
+	int32        x;
+	int32        y;
+	byte         z;
+	PlayerByte   owner; // placed by this player. Anyone can delete them though. OWNER_NONE for gray signs from old games.
+
+	/**
+	 * Creates a new sign
+	 */
+	Sign(PlayerID owner = INVALID_PLAYER);
+
+	/** Destroy the sign */
+	~Sign();
+
+	inline bool IsValid() const { return this->owner != INVALID_PLAYER; }
+};
+
+static inline SignID GetMaxSignIndex()
+{
+	/* TODO - This isn't the real content of the function, but
+	 *  with the new pool-system this will be replaced with one that
+	 *  _really_ returns the highest index. Now it just returns
+	 *  the next safe value we are sure about everything is below.
+	 */
+	return GetSignPoolSize() - 1;
+}
+
+static inline uint GetNumSigns()
+{
+	extern uint _total_signs;
+	return _total_signs;
+}
+
+static inline bool IsValidSignID(uint index)
+{
+	return index < GetSignPoolSize() && GetSign(index)->IsValid();
+}
+
+#define FOR_ALL_SIGNS_FROM(ss, start) for (ss = GetSign(start); ss != NULL; ss = (ss->index + 1U < GetSignPoolSize()) ? GetSign(ss->index + 1U) : NULL) if (ss->IsValid())
+#define FOR_ALL_SIGNS(ss) FOR_ALL_SIGNS_FROM(ss, 0)
+
+#endif /* SIGNS_BASE_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/signs_func.h	Mon Mar 31 07:50:27 2008 +0000
@@ -0,0 +1,21 @@
+/* $Id$ */
+
+/** @file signs_func.h Functions related to signs. */
+
+#ifndef SIGNS_FUNC_H
+#define SIGNS_FUNC_H
+
+#include "signs_type.h"
+
+extern SignID _new_sign_id;
+extern bool _sign_sort_dirty;
+
+void UpdateAllSignVirtCoords();
+void PlaceProc_Sign(TileIndex tile);
+
+/* signs_gui.cpp */
+void ShowRenameSignWindow(const Sign *si);
+
+void ShowSignList();
+
+#endif /* SIGNS_FUNC_H */
--- a/src/signs_gui.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/signs_gui.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -8,7 +8,8 @@
 #include "textbuf_gui.h"
 #include "window_gui.h"
 #include "player_gui.h"
-#include "signs.h"
+#include "signs_base.h"
+#include "signs_func.h"
 #include "debug.h"
 #include "variables.h"
 #include "command_func.h"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/signs_type.h	Mon Mar 31 07:50:27 2008 +0000
@@ -0,0 +1,15 @@
+/* $Id$ */
+
+/** @file signs_type.h Types related to signs */
+
+#ifndef SIGNS_TYPE_H
+#define SIGNS_TYPE_H
+
+typedef uint16 SignID;
+struct Sign;
+
+enum {
+	INVALID_SIGN = 0xFFFF,
+};
+
+#endif /* SIGNS_TYPE_H */
--- a/src/sound/win32_s.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/sound/win32_s.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -59,7 +59,7 @@
 	wfex.nBlockAlign = (wfex.nChannels * wfex.wBitsPerSample) / 8;
 	wfex.nAvgBytesPerSec = wfex.nSamplesPerSec * wfex.nBlockAlign;
 
-	_bufsize = GetDriverParamInt(parm, "bufsize", 1024);
+	_bufsize = GetDriverParamInt(parm, "bufsize", 2048);
 
 	if (waveOutOpen(&_waveout, WAVE_MAPPER, &wfex, (DWORD_PTR)&waveOutProc, 0, CALLBACK_FUNCTION) != MMSYSERR_NOERROR)
 		return "waveOutOpen failed";
--- a/src/station.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/station.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -7,7 +7,7 @@
 #include "bridge_map.h"
 #include "debug.h"
 #include "station_map.h"
-#include "station.h"
+#include "station_base.h"
 #include "town.h"
 #include "saveload.h"
 #include "player_func.h"
@@ -30,6 +30,7 @@
 #include "variables.h"
 #include "settings_type.h"
 #include "command_func.h"
+#include "order_func.h"
 
 #include "table/sprites.h"
 #include "table/strings.h"
@@ -99,7 +100,7 @@
  */
 RoadStop *Station::GetPrimaryRoadStop(const Vehicle *v) const
 {
-	RoadStop *rs = this->GetPrimaryRoadStop(IsCargoInClass(v->cargo_type, CC_PASSENGERS) ? RoadStop::BUS : RoadStop::TRUCK);
+	RoadStop *rs = this->GetPrimaryRoadStop(IsCargoInClass(v->cargo_type, CC_PASSENGERS) ? ROADSTOP_BUS : ROADSTOP_TRUCK);
 
 	for (; rs != NULL; rs = rs->next) {
 		/* The vehicle cannot go to this roadstop (different roadtype) */
--- a/src/station.h	Mon Mar 31 07:37:51 2008 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,306 +0,0 @@
-/* $Id$ */
-
-/** @file station.h */
-
-#ifndef STATION_H
-#define STATION_H
-
-#include "airport.h"
-#include "oldpool.h"
-#include "sprite.h"
-#include "road_type.h"
-#include "newgrf_station.h"
-#include "cargopacket.h"
-#include "cargo_type.h"
-#include "town_type.h"
-#include "core/geometry_type.hpp"
-#include <list>
-#include <set>
-
-struct Station;
-struct RoadStop;
-
-DECLARE_OLD_POOL(Station, Station, 6, 1000)
-DECLARE_OLD_POOL(RoadStop, RoadStop, 5, 2000)
-
-static const byte INITIAL_STATION_RATING = 175;
-
-struct GoodsEntry {
-	enum AcceptancePickup {
-		ACCEPTANCE,
-		PICKUP
-	};
-
-	GoodsEntry() :
-		acceptance_pickup(0),
-		days_since_pickup(255),
-		rating(INITIAL_STATION_RATING),
-		last_speed(0),
-		last_age(255)
-	{}
-
-	byte acceptance_pickup;
-	byte days_since_pickup;
-	byte rating;
-	byte last_speed;
-	byte last_age;
-	CargoList cargo; ///< The cargo packets of cargo waiting in this station
-};
-
-/** A Stop for a Road Vehicle */
-struct RoadStop : PoolItem<RoadStop, RoadStopID, &_RoadStop_pool> {
-	/** Types of RoadStops */
-	enum Type {
-		BUS,                                ///< A standard stop for buses
-		TRUCK                               ///< A standard stop for trucks
-	};
-
-	static const int  cDebugCtorLevel =  5;  ///< Debug level on which Contructor / Destructor messages are printed
-	static const uint LIMIT           = 16;  ///< The maximum amount of roadstops that are allowed at a single station
-	static const uint MAX_BAY_COUNT   =  2;  ///< The maximum number of loading bays
-
-	TileIndex        xy;                    ///< Position on the map
-	byte             status;                ///< Current status of the Stop. Like which spot is taken. Access using *Bay and *Busy functions.
-	byte             num_vehicles;          ///< Number of vehicles currently slotted to this stop
-	struct RoadStop  *next;                 ///< Next stop of the given type at this station
-
-	RoadStop(TileIndex tile = 0);
-	virtual ~RoadStop();
-
-	/**
-	 * Determines whether a road stop exists
-	 * @return true if and only is the road stop exists
-	 */
-	inline bool IsValid() const { return this->xy != 0; }
-
-	/* For accessing status */
-	bool HasFreeBay() const;
-	bool IsFreeBay(uint nr) const;
-	uint AllocateBay();
-	void AllocateDriveThroughBay(uint nr);
-	void FreeBay(uint nr);
-	bool IsEntranceBusy() const;
-	void SetEntranceBusy(bool busy);
-
-	RoadStop *GetNextRoadStop(const Vehicle *v) const;
-};
-
-struct StationSpecList {
-	const StationSpec *spec;
-	uint32 grfid;      ///< GRF ID of this custom station
-	uint8  localidx;   ///< Station ID within GRF of station
-};
-
-/** StationRect - used to track station spread out rectangle - cheaper than scanning whole map */
-struct StationRect : public Rect {
-	enum StationRectMode
-	{
-		ADD_TEST = 0,
-		ADD_TRY,
-		ADD_FORCE
-	};
-
-	StationRect();
-	void MakeEmpty();
-	bool PtInExtendedRect(int x, int y, int distance = 0) const;
-	bool IsEmpty() const;
-	bool BeforeAddTile(TileIndex tile, StationRectMode mode);
-	bool BeforeAddRect(TileIndex tile, int w, int h, StationRectMode mode);
-	bool AfterRemoveTile(Station *st, TileIndex tile);
-	bool AfterRemoveRect(Station *st, TileIndex tile, int w, int h);
-
-	static bool ScanForStationTiles(StationID st_id, int left_a, int top_a, int right_a, int bottom_a);
-
-	StationRect& operator = (Rect src);
-};
-
-struct Station : PoolItem<Station, StationID, &_Station_pool> {
-public:
-	RoadStop *GetPrimaryRoadStop(RoadStop::Type type) const
-	{
-		return type == RoadStop::BUS ? bus_stops : truck_stops;
-	}
-
-	RoadStop *GetPrimaryRoadStop(const Vehicle *v) const;
-
-	const AirportFTAClass *Airport() const
-	{
-		if (airport_tile == 0) return GetAirport(AT_DUMMY);
-		return GetAirport(airport_type);
-	}
-
-	TileIndex xy;
-	RoadStop *bus_stops;
-	RoadStop *truck_stops;
-	TileIndex train_tile;
-	TileIndex airport_tile;
-	TileIndex dock_tile;
-	Town *town;
-	StringID string_id;     ///< Default name (town area) of station
-	char *name;             ///< Custom name
-
-	ViewportSign sign;
-
-	uint16 had_vehicle_of_type;
-
-	byte time_since_load;
-	byte time_since_unload;
-	byte delete_ctr;
-	PlayerByte owner;
-	byte facilities;
-	byte airport_type;
-
-	/* trainstation width/height */
-	byte trainst_w, trainst_h;
-
-	/** List of custom stations (StationSpecs) allocated to the station */
-	uint8 num_specs;
-	StationSpecList *speclist;
-
-	Date build_date;
-
-	uint64 airport_flags;   ///< stores which blocks on the airport are taken. was 16 bit earlier on, then 32
-
-	byte last_vehicle_type;
-	std::list<Vehicle *> loading_vehicles;
-	GoodsEntry goods[NUM_CARGO];
-
-	uint16 random_bits;
-	byte waiting_triggers;
-
-	StationRect rect; ///< Station spread out rectangle (not saved) maintained by StationRect_xxx() functions
-
-	static const int cDebugCtorLevel = 5;
-
-	Station(TileIndex tile = 0);
-	virtual ~Station();
-
-	void AddFacility(byte new_facility_bit, TileIndex facil_xy);
-
-	/**
-	 * Mark the sign of a station dirty for repaint.
-	 *
-	 * @ingroup dirty
-	 */
-	void MarkDirty() const;
-
-	/**
-	 * Marks the tiles of the station as dirty.
-	 *
-	 * @ingroup dirty
-	 */
-	void MarkTilesDirty(bool cargo_change) const;
-	bool TileBelongsToRailStation(TileIndex tile) const;
-	uint GetPlatformLength(TileIndex tile, DiagDirection dir) const;
-	uint GetPlatformLength(TileIndex tile) const;
-	bool IsBuoy() const;
-
-	/**
-	 * Determines whether a station exists
-	 * @return true if and only is the station exists
-	 */
-	inline bool IsValid() const { return this->xy != 0; }
-};
-
-enum StationType {
-	STATION_RAIL,
-	STATION_AIRPORT,
-	STATION_TRUCK,
-	STATION_BUS,
-	STATION_OILRIG,
-	STATION_DOCK,
-	STATION_BUOY
-};
-
-enum {
-	FACIL_TRAIN      = 0x01,
-	FACIL_TRUCK_STOP = 0x02,
-	FACIL_BUS_STOP   = 0x04,
-	FACIL_AIRPORT    = 0x08,
-	FACIL_DOCK       = 0x10,
-};
-
-enum {
-//	HVOT_PENDING_DELETE = 1 << 0, // not needed anymore
-	HVOT_TRAIN    = 1 << 1,
-	HVOT_BUS      = 1 << 2,
-	HVOT_TRUCK    = 1 << 3,
-	HVOT_AIRCRAFT = 1 << 4,
-	HVOT_SHIP     = 1 << 5,
-	/* This bit is used to mark stations. No, it does not belong here, but what
-	 * can we do? ;-) */
-	HVOT_BUOY     = 1 << 6
-};
-
-enum CatchmentArea {
-	CA_NONE            =  0,
-	CA_BUS             =  3,
-	CA_TRUCK           =  3,
-	CA_TRAIN           =  4,
-	CA_DOCK            =  5,
-
-	CA_UNMODIFIED      =  4, ///< Used when _patches.modified_catchment is false
-
-	MAX_CATCHMENT      = 10, ///< Airports have a catchment up to this number.
-};
-
-void ModifyStationRatingAround(TileIndex tile, PlayerID owner, int amount, uint radius);
-
-/** A set of stations (\c const \c Station* ) */
-typedef std::set<Station*> StationSet;
-
-StationSet FindStationsAroundIndustryTile(TileIndex tile, int w, int h);
-
-void ShowStationViewWindow(StationID station);
-void UpdateAllStationVirtCoord();
-
-static inline StationID GetMaxStationIndex()
-{
-	/* TODO - This isn't the real content of the function, but
-	 *  with the new pool-system this will be replaced with one that
-	 *  _really_ returns the highest index. Now it just returns
-	 *  the next safe value we are sure about everything is below.
-	 */
-	return GetStationPoolSize() - 1;
-}
-
-static inline uint GetNumStations()
-{
-	return GetStationPoolSize();
-}
-
-static inline bool IsValidStationID(StationID index)
-{
-	return index < GetStationPoolSize() && GetStation(index)->IsValid();
-}
-
-#define FOR_ALL_STATIONS_FROM(st, start) for (st = GetStation(start); st != NULL; st = (st->index + 1U < GetStationPoolSize()) ? GetStation(st->index + 1U) : NULL) if (st->IsValid())
-#define FOR_ALL_STATIONS(st) FOR_ALL_STATIONS_FROM(st, 0)
-
-
-/* Stuff for ROADSTOPS */
-
-#define FOR_ALL_ROADSTOPS_FROM(rs, start) for (rs = GetRoadStop(start); rs != NULL; rs = (rs->index + 1U < GetRoadStopPoolSize()) ? GetRoadStop(rs->index + 1U) : NULL) if (rs->IsValid())
-#define FOR_ALL_ROADSTOPS(rs) FOR_ALL_ROADSTOPS_FROM(rs, 0)
-
-/* End of stuff for ROADSTOPS */
-
-
-void AfterLoadStations();
-void GetProductionAroundTiles(AcceptedCargo produced, TileIndex tile, int w, int h, int rad);
-void GetAcceptanceAroundTiles(AcceptedCargo accepts, TileIndex tile, int w, int h, int rad);
-
-
-const DrawTileSprites *GetStationTileLayout(StationType st, byte gfx);
-void StationPickerDrawSprite(int x, int y, StationType st, RailType railtype, RoadType roadtype, int image);
-
-RoadStop * GetRoadStopByTile(TileIndex tile, RoadStop::Type type);
-uint GetNumRoadStops(const Station* st, RoadStop::Type type);
-RoadStop * AllocateRoadStop();
-void ClearSlot(Vehicle *v);
-
-bool HasStationInUse(StationID station, PlayerID player);
-
-void DeleteOilRig(TileIndex t);
-
-#endif /* STATION_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/station_base.h	Mon Mar 31 07:50:27 2008 +0000
@@ -0,0 +1,228 @@
+/* $Id$ */
+
+/** @file station_base.h Base classes/functions for stations. */
+
+#ifndef STATION_BASE_H
+#define STATION_BASE_H
+
+#include "station_type.h"
+#include "airport.h"
+#include "oldpool.h"
+#include "cargopacket.h"
+#include "cargo_type.h"
+#include "town_type.h"
+#include "strings_type.h"
+#include "date_type.h"
+#include "vehicle_type.h"
+#include "player_type.h"
+#include "core/geometry_type.hpp"
+#include <list>
+
+DECLARE_OLD_POOL(Station, Station, 6, 1000)
+DECLARE_OLD_POOL(RoadStop, RoadStop, 5, 2000)
+
+static const byte INITIAL_STATION_RATING = 175;
+
+struct GoodsEntry {
+	enum AcceptancePickup {
+		ACCEPTANCE,
+		PICKUP
+	};
+
+	GoodsEntry() :
+		acceptance_pickup(0),
+		days_since_pickup(255),
+		rating(INITIAL_STATION_RATING),
+		last_speed(0),
+		last_age(255)
+	{}
+
+	byte acceptance_pickup;
+	byte days_since_pickup;
+	byte rating;
+	byte last_speed;
+	byte last_age;
+	CargoList cargo; ///< The cargo packets of cargo waiting in this station
+};
+
+/** A Stop for a Road Vehicle */
+struct RoadStop : PoolItem<RoadStop, RoadStopID, &_RoadStop_pool> {
+	static const int  cDebugCtorLevel =  5;  ///< Debug level on which Contructor / Destructor messages are printed
+	static const uint LIMIT           = 16;  ///< The maximum amount of roadstops that are allowed at a single station
+	static const uint MAX_BAY_COUNT   =  2;  ///< The maximum number of loading bays
+
+	TileIndex        xy;                    ///< Position on the map
+	byte             status;                ///< Current status of the Stop. Like which spot is taken. Access using *Bay and *Busy functions.
+	byte             num_vehicles;          ///< Number of vehicles currently slotted to this stop
+	struct RoadStop  *next;                 ///< Next stop of the given type at this station
+
+	RoadStop(TileIndex tile = 0);
+	virtual ~RoadStop();
+
+	/**
+	 * Determines whether a road stop exists
+	 * @return true if and only is the road stop exists
+	 */
+	inline bool IsValid() const { return this->xy != 0; }
+
+	/* For accessing status */
+	bool HasFreeBay() const;
+	bool IsFreeBay(uint nr) const;
+	uint AllocateBay();
+	void AllocateDriveThroughBay(uint nr);
+	void FreeBay(uint nr);
+	bool IsEntranceBusy() const;
+	void SetEntranceBusy(bool busy);
+
+	RoadStop *GetNextRoadStop(const Vehicle *v) const;
+};
+
+struct StationSpecList {
+	const StationSpec *spec;
+	uint32 grfid;      ///< GRF ID of this custom station
+	uint8  localidx;   ///< Station ID within GRF of station
+};
+
+/** StationRect - used to track station spread out rectangle - cheaper than scanning whole map */
+struct StationRect : public Rect {
+	enum StationRectMode
+	{
+		ADD_TEST = 0,
+		ADD_TRY,
+		ADD_FORCE
+	};
+
+	StationRect();
+	void MakeEmpty();
+	bool PtInExtendedRect(int x, int y, int distance = 0) const;
+	bool IsEmpty() const;
+	bool BeforeAddTile(TileIndex tile, StationRectMode mode);
+	bool BeforeAddRect(TileIndex tile, int w, int h, StationRectMode mode);
+	bool AfterRemoveTile(Station *st, TileIndex tile);
+	bool AfterRemoveRect(Station *st, TileIndex tile, int w, int h);
+
+	static bool ScanForStationTiles(StationID st_id, int left_a, int top_a, int right_a, int bottom_a);
+
+	StationRect& operator = (Rect src);
+};
+
+struct Station : PoolItem<Station, StationID, &_Station_pool> {
+public:
+	RoadStop *GetPrimaryRoadStop(RoadStopType type) const
+	{
+		return type == ROADSTOP_BUS ? bus_stops : truck_stops;
+	}
+
+	RoadStop *GetPrimaryRoadStop(const Vehicle *v) const;
+
+	const AirportFTAClass *Airport() const
+	{
+		if (airport_tile == 0) return GetAirport(AT_DUMMY);
+		return GetAirport(airport_type);
+	}
+
+	TileIndex xy;
+	RoadStop *bus_stops;
+	RoadStop *truck_stops;
+	TileIndex train_tile;
+	TileIndex airport_tile;
+	TileIndex dock_tile;
+	Town *town;
+	StringID string_id;     ///< Default name (town area) of station
+	char *name;             ///< Custom name
+
+	ViewportSign sign;
+
+	uint16 had_vehicle_of_type;
+
+	byte time_since_load;
+	byte time_since_unload;
+	byte delete_ctr;
+	PlayerByte owner;
+	byte facilities;
+	byte airport_type;
+
+	/* trainstation width/height */
+	byte trainst_w, trainst_h;
+
+	/** List of custom stations (StationSpecs) allocated to the station */
+	uint8 num_specs;
+	StationSpecList *speclist;
+
+	Date build_date;
+
+	uint64 airport_flags;   ///< stores which blocks on the airport are taken. was 16 bit earlier on, then 32
+
+	byte last_vehicle_type;
+	std::list<Vehicle *> loading_vehicles;
+	GoodsEntry goods[NUM_CARGO];
+
+	uint16 random_bits;
+	byte waiting_triggers;
+
+	StationRect rect; ///< Station spread out rectangle (not saved) maintained by StationRect_xxx() functions
+
+	static const int cDebugCtorLevel = 5;
+
+	Station(TileIndex tile = 0);
+	virtual ~Station();
+
+	void AddFacility(byte new_facility_bit, TileIndex facil_xy);
+
+	/**
+	 * Mark the sign of a station dirty for repaint.
+	 *
+	 * @ingroup dirty
+	 */
+	void MarkDirty() const;
+
+	/**
+	 * Marks the tiles of the station as dirty.
+	 *
+	 * @ingroup dirty
+	 */
+	void MarkTilesDirty(bool cargo_change) const;
+	bool TileBelongsToRailStation(TileIndex tile) const;
+	uint GetPlatformLength(TileIndex tile, DiagDirection dir) const;
+	uint GetPlatformLength(TileIndex tile) const;
+	bool IsBuoy() const;
+
+	/**
+	 * Determines whether a station exists
+	 * @return true if and only is the station exists
+	 */
+	inline bool IsValid() const { return this->xy != 0; }
+};
+
+static inline StationID GetMaxStationIndex()
+{
+	/* TODO - This isn't the real content of the function, but
+	 *  with the new pool-system this will be replaced with one that
+	 *  _really_ returns the highest index. Now it just returns
+	 *  the next safe value we are sure about everything is below.
+	 */
+	return GetStationPoolSize() - 1;
+}
+
+static inline uint GetNumStations()
+{
+	return GetStationPoolSize();
+}
+
+static inline bool IsValidStationID(StationID index)
+{
+	return index < GetStationPoolSize() && GetStation(index)->IsValid();
+}
+
+#define FOR_ALL_STATIONS_FROM(st, start) for (st = GetStation(start); st != NULL; st = (st->index + 1U < GetStationPoolSize()) ? GetStation(st->index + 1U) : NULL) if (st->IsValid())
+#define FOR_ALL_STATIONS(st) FOR_ALL_STATIONS_FROM(st, 0)
+
+
+/* Stuff for ROADSTOPS */
+
+#define FOR_ALL_ROADSTOPS_FROM(rs, start) for (rs = GetRoadStop(start); rs != NULL; rs = (rs->index + 1U < GetRoadStopPoolSize()) ? GetRoadStop(rs->index + 1U) : NULL) if (rs->IsValid())
+#define FOR_ALL_ROADSTOPS(rs) FOR_ALL_ROADSTOPS_FROM(rs, 0)
+
+/* End of stuff for ROADSTOPS */
+
+#endif /* STATION_BASE_H */
--- a/src/station_cmd.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/station_cmd.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -11,7 +11,6 @@
 #include "tile_cmd.h"
 #include "landscape.h"
 #include "station_map.h"
-#include "station.h"
 #include "viewport_func.h"
 #include "command_func.h"
 #include "town.h"
@@ -71,7 +70,7 @@
 	return false;
 }
 
-RoadStop* GetRoadStopByTile(TileIndex tile, RoadStop::Type type)
+RoadStop* GetRoadStopByTile(TileIndex tile, RoadStopType type)
 {
 	const Station* st = GetStationByTile(tile);
 
@@ -82,7 +81,7 @@
 }
 
 
-static uint GetNumRoadStopsInStation(const Station* st, RoadStop::Type type)
+static uint GetNumRoadStopsInStation(const Station* st, RoadStopType type)
 {
 	uint num = 0;
 
@@ -1298,7 +1297,7 @@
 }
 
 /**
- * @param truck_station Determines whether a stop is RoadStop::BUS or RoadStop::TRUCK
+ * @param truck_station Determines whether a stop is ROADSTOP_BUS or ROADSTOP_TRUCK
  * @param st The Station to do the whole procedure for
  * @return a pointer to where to link a new RoadStop*
  */
@@ -1397,7 +1396,7 @@
 	AutoPtrT<RoadStop> rs_auto_delete(road_stop);
 
 	if (st != NULL &&
-			GetNumRoadStopsInStation(st, RoadStop::BUS) + GetNumRoadStopsInStation(st, RoadStop::TRUCK) >= RoadStop::LIMIT) {
+			GetNumRoadStopsInStation(st, ROADSTOP_BUS) + GetNumRoadStopsInStation(st, ROADSTOP_TRUCK) >= RoadStop::LIMIT) {
 		return_cmd_error(type ? STR_TOO_MANY_TRUCK_STOPS : STR_TOO_MANY_BUS_STOPS);
 	}
 
@@ -1442,7 +1441,7 @@
 
 		st->rect.BeforeAddTile(tile, StationRect::ADD_TRY);
 
-		RoadStop::Type rs_type = type ? RoadStop::TRUCK : RoadStop::BUS;
+		RoadStopType rs_type = type ? ROADSTOP_TRUCK : ROADSTOP_BUS;
 		if (is_drive_through) {
 			MakeDriveThroughRoadStop(tile, st->owner, st->index, rs_type, rts, (Axis)p1, town_owned_road);
 		} else {
@@ -1488,10 +1487,10 @@
 	RoadStop *cur_stop;
 	if (is_truck) { // truck stop
 		primary_stop = &st->truck_stops;
-		cur_stop = GetRoadStopByTile(tile, RoadStop::TRUCK);
+		cur_stop = GetRoadStopByTile(tile, ROADSTOP_TRUCK);
 	} else {
 		primary_stop = &st->bus_stops;
-		cur_stop = GetRoadStopByTile(tile, RoadStop::BUS);
+		cur_stop = GetRoadStopByTile(tile, ROADSTOP_BUS);
 	}
 
 	assert(cur_stop != NULL);
@@ -2440,7 +2439,7 @@
 					if (!rs->IsFreeBay(side)) return VETSB_CANNOT_ENTER;
 
 					/* Check if the vehicle is stopping at this road stop */
-					if (GetRoadStopType(tile) == (IsCargoInClass(v->cargo_type, CC_PASSENGERS) ? RoadStop::BUS : RoadStop::TRUCK) &&
+					if (GetRoadStopType(tile) == (IsCargoInClass(v->cargo_type, CC_PASSENGERS) ? ROADSTOP_BUS : ROADSTOP_TRUCK) &&
 							v->current_order.dest == GetStationIndex(tile)) {
 						SetBit(v->u.road.state, RVS_IS_STOPPING);
 						rs->AllocateDriveThroughBay(side);
@@ -2913,7 +2912,7 @@
 	} else {
 		if (IsDriveThroughStopTile(tile)) {
 			/* Remove the drive-through road stop */
-			DoCommand(tile, 0, (GetStationType(tile) == STATION_TRUCK) ? RoadStop::TRUCK : RoadStop::BUS, DC_EXEC | DC_BANKRUPT, CMD_REMOVE_ROAD_STOP);
+			DoCommand(tile, 0, (GetStationType(tile) == STATION_TRUCK) ? ROADSTOP_TRUCK : ROADSTOP_BUS, DC_EXEC | DC_BANKRUPT, CMD_REMOVE_ROAD_STOP);
 			assert(IsTileType(tile, MP_ROAD));
 			/* Change owner of tile and all roadtypes */
 			ChangeTileOwner(tile, old_player, new_player);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/station_func.h	Mon Mar 31 07:50:27 2008 +0000
@@ -0,0 +1,51 @@
+/* $Id$ */
+
+/** @file station_func.h Functions related to stations. */
+
+#ifndef STATION_FUNC_H
+#define STATION_FUNC_H
+
+#include "station_type.h"
+#include "sprite.h"
+#include "rail_type.h"
+#include "road_type.h"
+#include "tile_type.h"
+#include "cargo_type.h"
+#include "vehicle_type.h"
+#include <set>
+
+void ModifyStationRatingAround(TileIndex tile, PlayerID owner, int amount, uint radius);
+
+/** A set of stations (\c const \c Station* ) */
+typedef std::set<Station*> StationSet;
+
+StationSet FindStationsAroundIndustryTile(TileIndex tile, int w, int h);
+
+void ShowStationViewWindow(StationID station);
+void UpdateAllStationVirtCoord();
+
+void AfterLoadStations();
+void GetProductionAroundTiles(AcceptedCargo produced, TileIndex tile, int w, int h, int rad);
+void GetAcceptanceAroundTiles(AcceptedCargo accepts, TileIndex tile, int w, int h, int rad);
+
+const DrawTileSprites *GetStationTileLayout(StationType st, byte gfx);
+void StationPickerDrawSprite(int x, int y, StationType st, RailType railtype, RoadType roadtype, int image);
+
+bool HasStationInUse(StationID station, PlayerID player);
+
+RoadStop * GetRoadStopByTile(TileIndex tile, RoadStopType type);
+uint GetNumRoadStops(const Station* st, RoadStopType type);
+RoadStop * AllocateRoadStop();
+
+void ClearSlot(Vehicle *v);
+
+void DeleteOilRig(TileIndex t);
+
+/* Check if a rail station tile is traversable. */
+bool IsStationTileBlocked(TileIndex tile);
+
+/* Check if a rail station tile is electrifiable. */
+bool IsStationTileElectrifiable(TileIndex tile);
+
+
+#endif /* STATION_FUNC_H */
--- a/src/station_gui.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/station_gui.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -8,7 +8,7 @@
 #include "gui.h"
 #include "window_gui.h"
 #include "textbuf_gui.h"
-#include "station.h"
+#include "station_base.h"
 #include "player_func.h"
 #include "economy_func.h"
 #include "town.h"
@@ -17,13 +17,14 @@
 #include "vehicle_gui.h"
 #include "cargotype.h"
 #include "station_gui.h"
-#include "station.h"
+#include "station_func.h"
 #include "strings_func.h"
 #include "core/alloc_func.hpp"
 #include "window_func.h"
 #include "viewport_func.h"
 #include "gfx_func.h"
 #include "widgets/dropdown_func.h"
+#include "newgrf_cargo.h"
 
 #include "table/strings.h"
 #include "table/sprites.h"
--- a/src/station_map.h	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/station_map.h	Mon Mar 31 07:50:27 2008 +0000
@@ -8,7 +8,8 @@
 #include "rail_map.h"
 #include "road_map.h"
 #include "water_map.h"
-#include "station.h"
+#include "station_func.h"
+#include "station_base.h"
 #include "rail.h"
 
 typedef byte StationGfx;
@@ -49,10 +50,10 @@
 	return (StationType)GB(_m[t].m6, 3, 3);
 }
 
-static inline RoadStop::Type GetRoadStopType(TileIndex t)
+static inline RoadStopType GetRoadStopType(TileIndex t)
 {
 	assert(GetStationType(t) == STATION_TRUCK || GetStationType(t) == STATION_BUS);
-	return GetStationType(t) == STATION_TRUCK ? RoadStop::TRUCK : RoadStop::BUS;
+	return GetStationType(t) == STATION_TRUCK ? ROADSTOP_TRUCK : ROADSTOP_BUS;
 }
 
 static inline StationGfx GetStationGfx(TileIndex t)
@@ -260,15 +261,15 @@
 	SetRailType(t, rt);
 }
 
-static inline void MakeRoadStop(TileIndex t, Owner o, StationID sid, RoadStop::Type rst, RoadTypes rt, DiagDirection d)
+static inline void MakeRoadStop(TileIndex t, Owner o, StationID sid, RoadStopType rst, RoadTypes rt, DiagDirection d)
 {
-	MakeStation(t, o, sid, (rst == RoadStop::BUS ? STATION_BUS : STATION_TRUCK), d);
+	MakeStation(t, o, sid, (rst == ROADSTOP_BUS ? STATION_BUS : STATION_TRUCK), d);
 	SetRoadTypes(t, rt);
 }
 
-static inline void MakeDriveThroughRoadStop(TileIndex t, Owner o, StationID sid, RoadStop::Type rst, RoadTypes rt, Axis a, bool on_town_road)
+static inline void MakeDriveThroughRoadStop(TileIndex t, Owner o, StationID sid, RoadStopType rst, RoadTypes rt, Axis a, bool on_town_road)
 {
-	MakeStation(t, o, sid, (rst == RoadStop::BUS ? STATION_BUS : STATION_TRUCK), GFX_TRUCK_BUS_DRIVETHROUGH_OFFSET + a);
+	MakeStation(t, o, sid, (rst == ROADSTOP_BUS ? STATION_BUS : STATION_TRUCK), GFX_TRUCK_BUS_DRIVETHROUGH_OFFSET + a);
 	SB(_m[t].m6, 2, 1, on_town_road);
 	SetRoadTypes(t, rt);
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/station_type.h	Mon Mar 31 07:50:27 2008 +0000
@@ -0,0 +1,65 @@
+/* $Id$ */
+
+/** @file station_type.h Types related to stations. */
+
+#ifndef STATION_TYPE_H
+#define STATION_TYPE_H
+
+typedef uint16 StationID;
+typedef uint16 RoadStopID;
+
+struct Station;
+struct RoadStop;
+struct StationSpec;
+
+static const StationID INVALID_STATION = 0xFFFF;
+
+enum StationType {
+	STATION_RAIL,
+	STATION_AIRPORT,
+	STATION_TRUCK,
+	STATION_BUS,
+	STATION_OILRIG,
+	STATION_DOCK,
+	STATION_BUOY
+};
+
+/** Types of RoadStops */
+enum RoadStopType {
+	ROADSTOP_BUS,    ///< A standard stop for buses
+	ROADSTOP_TRUCK   ///< A standard stop for trucks
+};
+
+enum {
+	FACIL_TRAIN      = 0x01,
+	FACIL_TRUCK_STOP = 0x02,
+	FACIL_BUS_STOP   = 0x04,
+	FACIL_AIRPORT    = 0x08,
+	FACIL_DOCK       = 0x10,
+};
+
+enum {
+//	HVOT_PENDING_DELETE = 1 << 0, // not needed anymore
+	HVOT_TRAIN    = 1 << 1,
+	HVOT_BUS      = 1 << 2,
+	HVOT_TRUCK    = 1 << 3,
+	HVOT_AIRCRAFT = 1 << 4,
+	HVOT_SHIP     = 1 << 5,
+	/* This bit is used to mark stations. No, it does not belong here, but what
+	 * can we do? ;-) */
+	HVOT_BUOY     = 1 << 6
+};
+
+enum CatchmentArea {
+	CA_NONE            =  0,
+	CA_BUS             =  3,
+	CA_TRUCK           =  3,
+	CA_TRAIN           =  4,
+	CA_DOCK            =  5,
+
+	CA_UNMODIFIED      =  4, ///< Used when _patches.modified_catchment is false
+
+	MAX_CATCHMENT      = 10, ///< Airports have a catchment up to this number.
+};
+
+#endif /* STATION_TYPE_H */
--- a/src/strings.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/strings.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -6,7 +6,7 @@
 #include "openttd.h"
 #include "currency.h"
 #include "namegen_func.h"
-#include "station.h"
+#include "station_base.h"
 #include "town.h"
 #include "screenshot.h"
 #include "waypoint.h"
@@ -20,7 +20,7 @@
 #include "group.h"
 #include "debug.h"
 #include "newgrf_townname.h"
-#include "signs.h"
+#include "signs_base.h"
 #include "newgrf_engine.h"
 #include "spritecache.h"
 #include "fontcache.h"
@@ -36,6 +36,7 @@
 #include "fios.h"
 #include "settings_type.h"
 #include "video/video_driver.hpp"
+#include "engine_func.h"
 
 #include "table/strings.h"
 #include "table/control_codes.h"
--- a/src/subsidy_gui.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/subsidy_gui.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -4,7 +4,7 @@
 
 #include "stdafx.h"
 #include "openttd.h"
-#include "station.h"
+#include "station_base.h"
 #include "industry.h"
 #include "town.h"
 #include "economy_func.h"
--- a/src/terraform_gui.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/terraform_gui.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -13,11 +13,11 @@
 #include "viewport_func.h"
 #include "gfx_func.h"
 #include "command_func.h"
-#include "signs.h"
+#include "signs_func.h"
 #include "variables.h"
 #include "functions.h"
 #include "sound_func.h"
-#include "station.h"
+#include "station_base.h"
 #include "unmovable_map.h"
 #include "textbuf_gui.h"
 #include "genworld.h"
--- a/src/texteff.hpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/texteff.hpp	Mon Mar 31 07:50:27 2008 +0000
@@ -3,6 +3,8 @@
 #ifndef TEXTEFF_HPP
 #define TEXTEFF_HPP
 
+#include "gfx_type.h"
+
 /**
  * Text effect modes.
  */
--- a/src/timetable_gui.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/timetable_gui.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -6,7 +6,6 @@
 #include "openttd.h"
 #include "variables.h"
 #include "command_func.h"
-#include "engine.h"
 #include "gui.h"
 #include "window_gui.h"
 #include "textbuf_gui.h"
--- a/src/town_cmd.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/town_cmd.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -15,7 +15,7 @@
 #include "town.h"
 #include "command_func.h"
 #include "industry.h"
-#include "station.h"
+#include "station_base.h"
 #include "player_base.h"
 #include "news_func.h"
 #include "saveload.h"
@@ -39,6 +39,7 @@
 #include "strings_func.h"
 #include "window_func.h"
 #include "string_func.h"
+#include "newgrf_cargo.h"
 
 #include "table/strings.h"
 #include "table/sprites.h"
--- a/src/train_cmd.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/train_cmd.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -16,9 +16,9 @@
 #include "command_func.h"
 #include "pathfind.h"
 #include "npf.h"
-#include "station.h"
+#include "station_base.h"
 #include "news_func.h"
-#include "engine.h"
+#include "engine_func.h"
 #include "player_func.h"
 #include "player_base.h"
 #include "depot.h"
@@ -48,6 +48,7 @@
 #include "gfx_func.h"
 #include "ai/ai.h"
 #include "settings_type.h"
+#include "order_func.h"
 
 #include "table/strings.h"
 #include "table/train_cmd.h"
@@ -549,6 +550,9 @@
 	uint num_vehicles = 1 + CountArticulatedParts(engine, false);
 
 	if (!(flags & DC_QUERY_COST)) {
+		/* Check that the wagon can drive on the track in question */
+		if (!IsCompatibleRail(rvi->railtype, GetRailType(tile))) return CMD_ERROR;
+
 		/* Allow for the wagon and the articulated parts, plus one to "terminate" the list. */
 		Vehicle **vl = (Vehicle**)alloca(sizeof(*vl) * (num_vehicles + 1));
 		memset(vl, 0, sizeof(*vl) * (num_vehicles + 1));
@@ -703,10 +707,6 @@
 
 	const RailVehicleInfo *rvi = RailVehInfo(p1);
 
-	/* Check if depot and new engine uses the same kind of tracks */
-	/* We need to see if the engine got power on the tile to avoid eletric engines in non-electric depots */
-	if (!HasPowerOnRail(rvi->railtype, GetRailType(tile))) return CMD_ERROR;
-
 	if (rvi->railveh_type == RAILVEH_WAGON) return CmdBuildRailWagon(p1, tile, flags);
 
 	CommandCost value = EstimateTrainCost(p1, rvi);
@@ -716,6 +716,10 @@
 		CountArticulatedParts(p1, false);
 
 	if (!(flags & DC_QUERY_COST)) {
+		/* Check if depot and new engine uses the same kind of tracks *
+		 * We need to see if the engine got power on the tile to avoid eletric engines in non-electric depots */
+		if (!HasPowerOnRail(rvi->railtype, GetRailType(tile))) return CMD_ERROR;
+
 		/* Allow for the dual-heads and the articulated parts, plus one to "terminate" the list. */
 		Vehicle **vl = (Vehicle**)alloca(sizeof(*vl) * (num_vehicles + 1));
 		memset(vl, 0, sizeof(*vl) * (num_vehicles + 1));
--- a/src/train_gui.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/train_gui.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -16,6 +16,8 @@
 #include "strings_func.h"
 #include "vehicle_func.h"
 #include "settings_type.h"
+#include "order_func.h"
+#include "engine_func.h"
 
 #include "table/sprites.h"
 #include "table/strings.h"
--- a/src/tunnelbridge_cmd.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/tunnelbridge_cmd.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -34,6 +34,7 @@
 #include "signal_func.h"
 #include "tunnelbridge.h"
 #include "player_base.h"
+#include "engine_func.h"
 
 #include "table/sprites.h"
 #include "table/strings.h"
--- a/src/unmovable_cmd.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/unmovable_cmd.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -11,7 +11,6 @@
 #include "player_func.h"
 #include "player_base.h"
 #include "gui.h"
-#include "station.h"
 #include "town.h"
 #include "sprite.h"
 #include "bridge_map.h"
--- a/src/vehicle.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/vehicle.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -17,11 +17,9 @@
 #include "command_func.h"
 #include "saveload.h"
 #include "player_func.h"
-#include "engine.h"
 #include "debug.h"
 #include "vehicle_gui.h"
 #include "depot.h"
-#include "station.h"
 #include "rail_type.h"
 #include "train.h"
 #include "aircraft.h"
@@ -34,7 +32,7 @@
 #include "newgrf_engine.h"
 #include "newgrf_sound.h"
 #include "group.h"
-#include "order.h"
+#include "order_func.h"
 #include "strings_func.h"
 #include "zoom_func.h"
 #include "functions.h"
--- a/src/vehicle_base.h	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/vehicle_base.h	Mon Mar 31 07:50:27 2008 +0000
@@ -17,9 +17,11 @@
 #include "date_type.h"
 #include "player_type.h"
 #include "oldpool.h"
-#include "order.h"
+#include "order_base.h"
 #include "cargopacket.h"
 #include "texteff.hpp"
+#include "group_type.h"
+#include "engine_type.h"
 
 /** Road vehicle states */
 enum RoadVehicleStates {
--- a/src/vehicle_func.h	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/vehicle_func.h	Mon Mar 31 07:50:27 2008 +0000
@@ -13,6 +13,7 @@
 #include "command_type.h"
 #include "vehicle_type.h"
 #include "player_type.h"
+#include "engine_type.h"
 
 #define is_custom_sprite(x) (x >= 0xFD)
 #define IS_CUSTOM_FIRSTHEAD_SPRITE(x) (x == 0xFD)
@@ -51,8 +52,6 @@
 Vehicle *FindVehicleBetween(TileIndex from, TileIndex to, byte z, bool without_crashed = false);
 Vehicle *GetVehicleTunnelBridge(TileIndex tile, TileIndex endtile);
 
-Vehicle *CheckClickOnVehicle(const ViewPort *vp, int x, int y);
-
 void DecreaseVehicleValue(Vehicle *v);
 void CheckVehicleBreakdown(Vehicle *v);
 void AgeVehicle(Vehicle *v);
--- a/src/vehicle_gui.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/vehicle_gui.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -6,8 +6,6 @@
 #include "openttd.h"
 #include "debug.h"
 #include "player_func.h"
-#include "station.h"
-#include "engine.h"
 #include "gui.h"
 #include "window_gui.h"
 #include "textbuf_gui.h"
@@ -36,10 +34,20 @@
 #include "string_func.h"
 #include "settings_type.h"
 #include "widgets/dropdown_func.h"
+#include "order_func.h"
 
 #include "table/sprites.h"
 #include "table/strings.h"
 
+struct refit_d {
+	int sel;
+	struct RefitOption *cargo;
+	struct RefitList *list;
+	uint length;
+	VehicleOrderID order;
+};
+assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(refit_d));
+
 struct Sorting {
 	Listing aircraft;
 	Listing roadveh;
--- a/src/vehicle_gui.h	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/vehicle_gui.h	Mon Mar 31 07:50:27 2008 +0000
@@ -7,6 +7,9 @@
 
 #include "window_gui.h"
 #include "vehicle_type.h"
+#include "order_type.h"
+#include "station_type.h"
+#include "engine_type.h"
 
 void DrawVehicleProfitButton(const Vehicle *v, int x, int y);
 void ShowVehicleRefitWindow(const Vehicle *v, VehicleOrderID order);
@@ -99,4 +102,6 @@
 /* Unified window procedure */
 void ShowVehicleViewWindow(const Vehicle *v);
 
+Vehicle *CheckClickOnVehicle(const ViewPort *vp, int x, int y);
+
 #endif /* VEHICLE_GUI_H */
--- a/src/viewport.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/viewport.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -10,9 +10,10 @@
 #include "spritecache.h"
 #include "landscape.h"
 #include "viewport_func.h"
-#include "station.h"
+#include "station_base.h"
 #include "town.h"
-#include "signs.h"
+#include "signs_base.h"
+#include "signs_func.h"
 #include "waypoint.h"
 #include "variables.h"
 #include "train.h"
@@ -25,6 +26,7 @@
 #include "vehicle_func.h"
 #include "player_func.h"
 #include "settings_type.h"
+#include "station_func.h"
 
 #include "table/sprites.h"
 #include "table/strings.h"
--- a/src/water_cmd.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/water_cmd.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -35,6 +35,9 @@
 #include "settings_type.h"
 #include "clear_map.h"
 #include "tree_map.h"
+#include "station_base.h"
+#include "airport.h"
+#include "newgrf_cargo.h"
 
 #include "table/sprites.h"
 #include "table/strings.h"
--- a/src/waypoint.cpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/waypoint.cpp	Mon Mar 31 07:50:27 2008 +0000
@@ -7,12 +7,12 @@
 
 #include "command_func.h"
 #include "landscape.h"
-#include "order.h"
+#include "order_func.h"
 #include "rail_map.h"
 #include "rail.h"
 #include "bridge_map.h"
 #include "saveload.h"
-#include "station.h"
+#include "station_base.h"
 #include "town.h"
 #include "waypoint.h"
 #include "variables.h"
@@ -31,6 +31,7 @@
 #include "signal_func.h"
 #include "player_func.h"
 #include "settings_type.h"
+#include "newgrf_station.h"
 
 #include "table/strings.h"
 
--- a/src/waypoint.h	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/waypoint.h	Mon Mar 31 07:50:27 2008 +0000
@@ -5,11 +5,12 @@
 #ifndef WAYPOINT_H
 #define WAYPOINT_H
 
+#include "waypoint_type.h"
 #include "oldpool.h"
 #include "rail_map.h"
 #include "command_type.h"
+#include "station_type.h"
 
-struct Waypoint;
 DECLARE_OLD_POOL(Waypoint, Waypoint, 3, 8000)
 
 struct Waypoint : PoolItem<Waypoint, WaypointID, &_Waypoint_pool> {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/waypoint_type.h	Mon Mar 31 07:50:27 2008 +0000
@@ -0,0 +1,11 @@
+/* $Id$ */
+
+/** @file waypoint_type.h Types related to waypoints. */
+
+#ifndef WAYPOINT_TYPE_H
+#define WAYPOINT_TYPE_H
+
+typedef uint16 WaypointID;
+struct Waypoint;
+
+#endif /* WAYPOINT_TYPE_H */
--- a/src/window_gui.h	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/window_gui.h	Mon Mar 31 07:50:27 2008 +0000
@@ -331,19 +331,6 @@
 };
 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(tooltips_d));
 
-struct replaceveh_d {
-	byte sel_index[2];
-	EngineID sel_engine[2];
-	uint16 count[2];
-	bool wagon_btnstate; ///< true means engine is selected
-	EngineList list[2];
-	bool update_left;
-	bool update_right;
-	bool init_lists;
-	GroupID sel_group;
-};
-assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(replaceveh_d));
-
 struct depot_d {
 	VehicleID sel;
 	VehicleType type;
@@ -374,15 +361,6 @@
 };
 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(smallmap_d));
 
-struct refit_d {
-	int sel;
-	struct RefitOption *cargo;
-	struct RefitList *list;
-	uint length;
-	VehicleOrderID order;
-};
-assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(refit_d));
-
 struct vp_d {
 	VehicleID follow_vehicle;
 	int32 scrollpos_x;
@@ -443,20 +421,6 @@
 };
 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(vehiclelist_d));
 
-struct grouplist_d {
-	const Group **sort_list;
-	list_d l;                   // General list struct
-};
-assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(grouplist_d));
-
-struct groupveh_d : vehiclelist_d {
-	GroupID group_sel;
-	VehicleID vehicle_sel;
-
-	grouplist_d gl;
-};
-assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(groupveh_d));
-
 /****************** THESE ARE NOT WIDGET TYPES!!!!! *******************/
 enum WindowWidgetBehaviours {
 	WWB_PUSHBUTTON  = 1 << 5,
--- a/src/yapf/yapf.h	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/yapf/yapf.h	Mon Mar 31 07:50:27 2008 +0000
@@ -6,6 +6,8 @@
 #define  YAPF_H
 
 #include "../debug.h"
+#include "../depot_type.h"
+#include "../direction_type.h"
 
 /** Finds the best path for given ship.
  * @param v        the ship that needs to find a path
--- a/src/yapf/yapf.hpp	Mon Mar 31 07:37:51 2008 +0000
+++ b/src/yapf/yapf.hpp	Mon Mar 31 07:50:27 2008 +0000
@@ -14,7 +14,7 @@
 #include "../bridge_map.h"
 #include "../tunnelbridge_map.h"
 #include "../bridge.h"
-#include "../station.h"
+#include "../station_base.h"
 #include "../station_map.h"
 #include "../tile_cmd.h"
 #include "../landscape.h"