diff src/engine.cpp @ 17235:3f6432af5795 draft

(svn r21975) -Add: console command to reset the engine pool. It removes the traces of engines which are no longer associated to a NewGRF, and can be used to e.g. 'fix' scenarios which were screwed up by the author. You can only use it when there are no vehicles in the game though.
author frosch <frosch@openttd.org>
date Sat, 05 Feb 2011 16:07:23 +0000 (2011-02-05)
parents a804b91f3a3e
children f98b40bd4ccb
line wrap: on
line diff
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -29,6 +29,7 @@
 #include "engine_func.h"
 #include "engine_base.h"
 #include "company_base.h"
+#include "vehicle_func.h"
 
 #include "table/strings.h"
 #include "table/engines.h"
@@ -430,6 +431,25 @@
 }
 
 /**
+ * Tries to reset the engine mapping to match the current NewGRF configuration.
+ * This is only possible when there are currently no vehicles in the game.
+ * @return false if resetting failed due to present vehicles.
+ */
+bool EngineOverrideManager::ResetToCurrentNewGRFConfig()
+{
+	const Vehicle *v;
+	FOR_ALL_VEHICLES(v) {
+		if (IsCompanyBuildableVehicleType(v)) return false;
+	}
+
+	/* Reset the engines, they will get new EngineIDs */
+	_engine_mngr.ResetToDefaultMapping();
+	ReloadNewGRFData();
+
+	return true;
+}
+
+/**
  * Sets cached values in Company::num_vehicles and Group::num_vehicles
  */
 void SetCachedEngineCounts()