summaryrefslogtreecommitdiff
path: root/src/game/game_core.cpp
diff options
context:
space:
mode:
authortruebrain <truebrain@openttd.org>2011-12-19 20:55:56 +0000
committertruebrain <truebrain@openttd.org>2011-12-19 20:55:56 +0000
commitc99950c21537f9c890e4eac6d077c0ec6f31b7aa (patch)
treec130b8aa9cf12c7c3a1c9ef014bb35df3f53035f /src/game/game_core.cpp
parentb4f832f29f44dcd48e8f0806d47ce78b1963d639 (diff)
downloadopenttd-c99950c21537f9c890e4eac6d077c0ec6f31b7aa.tar.xz
(svn r23606) -Add: GameScanner, to auto-detect game scripts, and wire it in the console
Diffstat (limited to 'src/game/game_core.cpp')
-rw-r--r--src/game/game_core.cpp101
1 files changed, 98 insertions, 3 deletions
diff --git a/src/game/game_core.cpp b/src/game/game_core.cpp
index 7894ab2a6..22898a3d8 100644
--- a/src/game/game_core.cpp
+++ b/src/game/game_core.cpp
@@ -12,18 +12,26 @@
#include "../stdafx.h"
#include "../command_func.h"
#include "../core/backup_type.hpp"
+#include "../core/bitmath_func.hpp"
#include "../company_base.h"
#include "../company_func.h"
#include "../network/network.h"
+#include "../window_func.h"
+#include "../fileio_func.h"
#include "game.hpp"
+#include "game_scanner.hpp"
+#include "game_config.hpp"
#include "game_instance.hpp"
/* static */ uint Game::frame_counter = 0;
+/* static */ GameInfo *Game::info = NULL;
/* static */ GameInstance *Game::instance = NULL;
+/* static */ GameScannerInfo *Game::scanner = NULL;
/* static */ void Game::GameLoop()
{
if (_networking && !_network_server) return;
+ if (Game::instance == NULL) return;
Game::frame_counter++;
@@ -40,25 +48,112 @@
/* static */ void Game::Initialize()
{
- if (Game::instance != NULL) Game::Uninitialize();
+ if (Game::instance != NULL) Game::Uninitialize(true);
Game::frame_counter = 0;
+
+ if (Game::scanner == NULL) {
+ TarScanner::DoScan(TarScanner::GAME);
+ Game::scanner = new GameScannerInfo();
+ Game::scanner->Initialize();
+ }
+
if (Game::instance == NULL) {
/* Clients shouldn't start GameScripts */
if (_networking && !_network_server) return;
+ GameConfig *config = GameConfig::GetConfig();
+ GameInfo *info = config->GetInfo();
+ if (info == NULL) return;
+
Backup<CompanyByte> cur_company(_current_company, FILE_LINE);
cur_company.Change(OWNER_DEITY);
+ Game::info = info;
Game::instance = new GameInstance();
- Game::instance->Initialize();
+ Game::instance->Initialize(info);
cur_company.Restore();
+
+ InvalidateWindowData(WC_AI_DEBUG, 0, -1);
}
}
-/* static */ void Game::Uninitialize()
+/* static */ void Game::Uninitialize(bool keepConfig)
{
delete Game::instance;
Game::instance = NULL;
+
+ if (keepConfig) {
+ Rescan();
+ } else {
+ delete Game::scanner;
+ Game::scanner = NULL;
+
+ if (_settings_game.game_config != NULL) {
+ delete _settings_game.game_config;
+ _settings_game.game_config = NULL;
+ }
+ if (_settings_newgame.game_config != NULL) {
+ delete _settings_newgame.game_config;
+ _settings_newgame.game_config = NULL;
+ }
+ }
+}
+
+/* static */ void Game::ResetConfig()
+{
+ /* Check for both newgame as current game if we can reload the GameInfo insde
+ * the GameConfig. If not, remove the Game from the list. */
+ if (_settings_game.game_config != NULL && _settings_game.game_config->HasScript()) {
+ if (!_settings_game.game_config->ResetInfo(true)) {
+ DEBUG(script, 0, "After a reload, the GameScript by the name '%s' was no longer found, and removed from the list.", _settings_game.game_config->GetName());
+ _settings_game.game_config->Change(NULL);
+ if (Game::instance != NULL) {
+ delete Game::instance;
+ Game::instance = NULL;
+ }
+ } else if (Game::instance != NULL) {
+ Game::info = _settings_game.game_config->GetInfo();
+ }
+ }
+ if (_settings_newgame.game_config != NULL && _settings_newgame.game_config->HasScript()) {
+ if (!_settings_newgame.game_config->ResetInfo(false)) {
+ DEBUG(script, 0, "After a reload, the GameScript by the name '%s' was no longer found, and removed from the list.", _settings_newgame.game_config->GetName());
+ _settings_newgame.game_config->Change(NULL);
+ }
+ }
+}
+
+/* static */ void Game::Rescan()
+{
+ TarScanner::DoScan(TarScanner::GAME);
+
+ Game::scanner->RescanDir();
+ ResetConfig();
+
+ InvalidateWindowData(WC_AI_LIST, 0, 1);
+ SetWindowClassesDirty(WC_AI_DEBUG);
+ SetWindowDirty(WC_AI_SETTINGS, 0);
+}
+
+
+/* static */ char *Game::GetConsoleList(char *p, const char *last, bool newest_only)
+{
+ return Game::scanner->GetConsoleList(p, last, newest_only);
+}
+
+/* static */ const ScriptInfoList *Game::GetInfoList()
+{
+ return Game::scanner->GetInfoList();
+}
+
+/* static */ const ScriptInfoList *Game::GetUniqueInfoList()
+{
+ return Game::scanner->GetUniqueInfoList();
+}
+
+/* static */ GameInfo *Game::FindInfo(const char *name, int version, bool force_exact_match)
+{
+ return Game::scanner->FindInfo(name, version, force_exact_match);
}