src/engine.cpp
branchnoai
changeset 9723 eee46cb39750
parent 9722 ebf0ece7d8f6
child 9724 b39bc69bb2f2
--- a/src/engine.cpp	Fri Nov 23 16:59:30 2007 +0000
+++ b/src/engine.cpp	Wed Jan 09 18:11:12 2008 +0000
@@ -5,25 +5,27 @@
 #include "stdafx.h"
 #include "openttd.h"
 #include "debug.h"
-#include "functions.h"
 #include "table/strings.h"
 #include "engine.h"
-#include "gfx.h"
 #include "player.h"
-#include "command.h"
-#include "vehicle.h"
+#include "command_func.h"
 #include "news.h"
 #include "saveload.h"
 #include "variables.h"
 #include "train.h"
 #include "aircraft.h"
 #include "newgrf_cargo.h"
-#include "date.h"
 #include "table/engines.h"
 #include "group.h"
-#include "string.h"
-#include "strings.h"
 #include "misc/autoptr.hpp"
+#include "strings_func.h"
+#include "gfx_func.h"
+#include "functions.h"
+#include "window_func.h"
+#include "date_func.h"
+#include "autoreplace_base.h"
+#include "autoreplace_gui.h"
+#include "string_func.h"
 
 EngineInfo _engine_info[TOTAL_NUM_ENGINES];
 RailVehicleInfo _rail_vehicle_info[NUM_TRAIN_ENGINES];
@@ -36,6 +38,24 @@
 };
 
 
+void SetupEngines()
+{
+	/* Copy original static engine data */
+	memcpy(&_engine_info, &_orig_engine_info, sizeof(_orig_engine_info));
+	memcpy(&_rail_vehicle_info, &_orig_rail_vehicle_info, sizeof(_orig_rail_vehicle_info));
+	memcpy(&_ship_vehicle_info, &_orig_ship_vehicle_info, sizeof(_orig_ship_vehicle_info));
+	memcpy(&_aircraft_vehicle_info, &_orig_aircraft_vehicle_info, sizeof(_orig_aircraft_vehicle_info));
+	memcpy(&_road_vehicle_info, &_orig_road_vehicle_info, sizeof(_orig_road_vehicle_info));
+
+	/* Add type to engines */
+	Engine* e = _engines;
+	do e->type = VEH_TRAIN;    while (++e < &_engines[ROAD_ENGINES_INDEX]);
+	do e->type = VEH_ROAD;     while (++e < &_engines[SHIP_ENGINES_INDEX]);
+	do e->type = VEH_SHIP;     while (++e < &_engines[AIRCRAFT_ENGINES_INDEX]);
+	do e->type = VEH_AIRCRAFT; while (++e < &_engines[TOTAL_NUM_ENGINES]);
+}
+
+
 void ShowEnginePreviewWindow(EngineID engine);
 
 void DeleteCustomEngineNames()
@@ -106,16 +126,6 @@
 	InvalidateWindowClasses(WC_REPLACE_VEHICLE);
 }
 
-void AddTypeToEngines()
-{
-	Engine* e = _engines;
-
-	do e->type = VEH_TRAIN;    while (++e < &_engines[ROAD_ENGINES_INDEX]);
-	do e->type = VEH_ROAD;     while (++e < &_engines[SHIP_ENGINES_INDEX]);
-	do e->type = VEH_SHIP;     while (++e < &_engines[AIRCRAFT_ENGINES_INDEX]);
-	do e->type = VEH_AIRCRAFT; while (++e < &_engines[TOTAL_NUM_ENGINES]);
-}
-
 void StartupEngines()
 {
 	Engine *e;
@@ -327,15 +337,14 @@
 	/* Do not introduce new rail wagons */
 	if (IsWagon(index)) return;
 
-	if (index < NUM_TRAIN_ENGINES) {
+	if (e->type == VEH_TRAIN) {
 		/* maybe make another rail type available */
 		RailType railtype = RailVehInfo(index)->railtype;
 		assert(railtype < RAILTYPE_END);
 		FOR_ALL_PLAYERS(p) {
 			if (p->is_active) SetBit(p->avail_railtypes, railtype);
 		}
-	}
-	if ((index - NUM_TRAIN_ENGINES) < NUM_ROAD_ENGINES) {
+	} else if (e->type == VEH_ROAD) {
 		/* maybe make another road type available */
 		FOR_ALL_PLAYERS(p) {
 			if (p->is_active) SetBit(p->avail_roadtypes, HasBit(EngInfo(index)->misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD);