diff options
author | frosch <frosch@openttd.org> | 2011-02-05 16:07:23 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2011-02-05 16:07:23 +0000 |
commit | 915e339d0f395305ec722925bfd8f4fdd09f30a3 (patch) | |
tree | cf6982b3ae86b563f6868379f8f6240b658d6130 /src | |
parent | a4b08dddd10062f49352b5aee49e392f95e281e2 (diff) | |
download | openttd-915e339d0f395305ec722925bfd8f4fdd09f30a3.tar.xz |
(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.
Diffstat (limited to 'src')
-rw-r--r-- | src/console_cmds.cpp | 22 | ||||
-rw-r--r-- | src/engine.cpp | 20 | ||||
-rw-r--r-- | src/engine_base.h | 2 | ||||
-rw-r--r-- | src/settings.cpp | 15 | ||||
-rw-r--r-- | src/terraform_gui.cpp | 4 |
5 files changed, 51 insertions, 12 deletions
diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp index 774d2f093..a8e4c3eb8 100644 --- a/src/console_cmds.cpp +++ b/src/console_cmds.cpp @@ -35,6 +35,7 @@ #include "ai/ai_config.hpp" #include "newgrf.h" #include "console_func.h" +#include "engine_base.h" #ifdef ENABLE_NETWORK #include "table/strings.h" @@ -141,6 +142,26 @@ DEF_CONSOLE_CMD(ConResetEngines) return true; } +DEF_CONSOLE_CMD(ConResetEnginePool) +{ + if (argc == 0) { + IConsoleHelp("Reset NewGRF allocations of engine slots. This will remove invalid engine definitions, and might make default engines available again."); + return true; + } + + if (_game_mode == GM_MENU) { + IConsoleError("This command is only available in game and editor."); + return true; + } + + if (!EngineOverrideManager::ResetToCurrentNewGRFConfig()) { + IConsoleError("This can only be done when there are no vehicles in the game."); + return true; + } + + return true; +} + #ifdef _DEBUG DEF_CONSOLE_CMD(ConResetTile) { @@ -1781,6 +1802,7 @@ void IConsoleStdLibRegister() IConsoleCmdRegister("getdate", ConGetDate); IConsoleCmdRegister("quit", ConExit); IConsoleCmdRegister("resetengines", ConResetEngines, ConHookNoNetwork); + IConsoleCmdRegister("reset_enginepool", ConResetEnginePool, ConHookNoNetwork); IConsoleCmdRegister("return", ConReturn); IConsoleCmdRegister("screenshot", ConScreenShot); IConsoleCmdRegister("script", ConScript); diff --git a/src/engine.cpp b/src/engine.cpp index 048fcc82f..6f544edf8 100644 --- 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 @@ EngineID EngineOverrideManager::GetID(VehicleType type, uint16 grf_local_id, uin } /** + * 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() diff --git a/src/engine_base.h b/src/engine_base.h index 366831ad7..78a647139 100644 --- a/src/engine_base.h +++ b/src/engine_base.h @@ -114,6 +114,8 @@ struct EngineOverrideManager : SmallVector<EngineIDMapping, 256> { void ResetToDefaultMapping(); EngineID GetID(VehicleType type, uint16 grf_local_id, uint32 grfid); + + static bool ResetToCurrentNewGRFConfig(); }; extern EngineOverrideManager _engine_mngr; diff --git a/src/settings.cpp b/src/settings.cpp index 5d4e713be..30201541c 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -36,7 +36,6 @@ #include "train.h" #include "news_func.h" #include "window_func.h" -#include "vehicle_func.h" #include "sound_func.h" #include "company_func.h" #include "rev.h" @@ -58,7 +57,6 @@ #include "ini_type.h" #include "ai/ai_config.hpp" #include "ai/ai.hpp" -#include "newgrf.h" #include "ship.h" #include "smallmap_gui.h" #include "roadveh.h" @@ -1133,18 +1131,11 @@ static bool ChangeDynamicEngines(int32 p1) { if (_game_mode == GM_MENU) return true; - const Vehicle *v; - FOR_ALL_VEHICLES(v) { - if (IsCompanyBuildableVehicleType(v)) { - ShowErrorMessage(STR_CONFIG_SETTING_DYNAMIC_ENGINES_EXISTING_VEHICLES, INVALID_STRING_ID, WL_ERROR); - return false; - } + if (!EngineOverrideManager::ResetToCurrentNewGRFConfig()) { + ShowErrorMessage(STR_CONFIG_SETTING_DYNAMIC_ENGINES_EXISTING_VEHICLES, INVALID_STRING_ID, WL_ERROR); + return false; } - /* Reset the engines, they will get new EngineIDs */ - _engine_mngr.ResetToDefaultMapping(); - ReloadNewGRFData(); - return true; } diff --git a/src/terraform_gui.cpp b/src/terraform_gui.cpp index bf26910e3..30589f2af 100644 --- a/src/terraform_gui.cpp +++ b/src/terraform_gui.cpp @@ -31,6 +31,7 @@ #include "newgrf_object.h" #include "object.h" #include "hotkeys.h" +#include "engine_base.h" #include "table/strings.h" @@ -560,6 +561,9 @@ static void ResetLandscapeConfirmationCallback(Window *w, bool confirmed) if (!st->IsInUse()) delete st; } + /* Now that all vehicles are gone, we can reset the engine pool. Maybe it reduces some NewGRF changing-mess */ + EngineOverrideManager::ResetToCurrentNewGRFConfig(); + MarkWholeScreenDirty(); } } |