Update: Translations from eints
[openttd-github.git] / src / game / game_instance.cpp
blob3dbbc7b056b12223f7bb8475db18297cc697d787
1 /*
2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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/>.
6 */
8 /** @file game_instance.cpp Implementation of GameInstance. */
10 #include "../stdafx.h"
11 #include "../error.h"
13 #include "../script/squirrel_class.hpp"
15 #include "../script/script_storage.hpp"
16 #include "../script/script_cmd.h"
17 #include "../script/script_gui.h"
18 #include "game_config.hpp"
19 #include "game_info.hpp"
20 #include "game_instance.hpp"
21 #include "game_text.hpp"
22 #include "game.hpp"
24 /* Convert all Game related classes to Squirrel data. */
25 #include "../script/api/game/game_includes.hpp"
27 #include "../safeguards.h"
30 GameInstance::GameInstance() :
31 ScriptInstance("GS")
34 void GameInstance::Initialize(GameInfo *info)
36 this->versionAPI = info->GetAPIVersion();
38 /* Register the GameController */
39 SQGSController_Register(this->engine);
41 ScriptInstance::Initialize(info->GetMainScript(), info->GetInstanceName(), OWNER_DEITY);
44 void GameInstance::RegisterAPI()
46 ScriptInstance::RegisterAPI();
48 /* Register all classes */
49 SQGS_RegisterAll(this->engine);
51 RegisterGameTranslation(this->engine);
53 if (!this->LoadCompatibilityScripts(this->versionAPI, GAME_DIR)) this->Died();
56 int GameInstance::GetSetting(const std::string &name)
58 return GameConfig::GetConfig()->GetSetting(name);
61 ScriptInfo *GameInstance::FindLibrary(const std::string &library, int version)
63 return (ScriptInfo *)Game::FindLibrary(library, version);
66 void GameInstance::Died()
68 ScriptInstance::Died();
70 /* Don't show errors while loading savegame. They will be shown at end of loading anyway. */
71 if (_switch_mode != SM_NONE) return;
73 ShowScriptDebugWindow(OWNER_DEITY);
75 const GameInfo *info = Game::GetInfo();
76 if (info != nullptr) {
77 ShowErrorMessage(STR_ERROR_AI_PLEASE_REPORT_CRASH, INVALID_STRING_ID, WL_WARNING);
79 if (!info->GetURL().empty()) {
80 ScriptLog::Info("Please report the error to the following URL:");
81 ScriptLog::Info(info->GetURL());
86 /**
87 * DoCommand callback function for all commands executed by Game Scripts.
88 * @param cmd cmd as given to DoCommandPInternal.
89 * @param result The result of the command.
90 * @param data Command data as given to Command<>::Post.
91 * @param result_data Additional returned data from the command.
93 void CcGame(Commands cmd, const CommandCost &result, const CommandDataBuffer &data, CommandDataBuffer result_data)
95 if (Game::GetGameInstance()->DoCommandCallback(result, data, std::move(result_data), cmd)) {
96 Game::GetGameInstance()->Continue();
100 CommandCallbackData *GameInstance::GetDoCommandCallback()
102 return &CcGame;