4 * This file is part of OpenTTD.
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
10 /** @file game_instance.cpp Implementation of GameInstance. */
12 #include "../stdafx.h"
15 #include "../script/convert.hpp"
17 #include "../ai/ai_gui.hpp"
18 #include "game_config.hpp"
19 #include "game_info.hpp"
20 #include "game_instance.hpp"
21 #include "game_text.hpp"
24 #include "../script/api/script_controller.hpp"
26 #include "../script/api/game/game.hpp.sq"
29 GameInstance::GameInstance() :
33 void GameInstance::Initialize (const GameInfo
*info
)
35 this->versionAPI
= info
->GetAPIVersion();
37 /* Register the GameController */
38 SQGSController_Register (this);
40 ScriptInstance::Initialize (info
, OWNER_DEITY
);
43 void GameInstance::RegisterAPI()
45 ScriptInstance::RegisterAPI();
47 /* Register all classes */
50 RegisterGameTranslation (this);
52 if (!this->LoadCompatibilityScripts(this->versionAPI
, GAME_DIR
)) this->Died();
55 int GameInstance::GetSetting(const char *name
)
57 return GameConfig::GetConfig()->GetSetting(name
);
60 ScriptInfo
*GameInstance::FindLibrary(const char *library
, int version
)
62 return (ScriptInfo
*)Game::FindLibrary(library
, version
);
65 void GameInstance::Died()
67 ScriptInstance::Died();
69 ShowAIDebugWindow(OWNER_DEITY
);
71 const GameInfo
*info
= Game::GetInfo();
73 ShowErrorMessage(STR_ERROR_AI_PLEASE_REPORT_CRASH
, INVALID_STRING_ID
, WL_WARNING
);
75 if (info
->GetURL() != NULL
) {
76 ScriptLog::Info("Please report the error to the following URL:");
77 ScriptLog::Info(info
->GetURL());
83 * DoCommand callback function for all commands executed by Game Scripts.
84 * @param result The result of the command.
86 void CcGame (const CommandCost
&result
)
88 Game::GetGameInstance()->DoCommandCallback (result
);
89 Game::GetGameInstance()->Continue();
92 CommandSource
GameInstance::GetCommandSource()