You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
OpenTTD-patches/src/game/game_instance.cpp

105 lines
3.1 KiB
C++

/*
* This file is part of OpenTTD.
* 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.
* 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.
* 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/>.
*/
/** @file game_instance.cpp Implementation of GameInstance. */
#include "../stdafx.h"
#include "../error.h"
#include "../script/squirrel_class.hpp"
#include "../script/script_storage.hpp"
#include "../script/script_gui.h"
#include "game_config.hpp"
#include "game_info.hpp"
#include "game_instance.hpp"
#include "game_text.hpp"
#include "game.hpp"
/* Convert all Game related classes to Squirrel data. */
#include "../script/api/game/game_includes.hpp"
#include "../safeguards.h"
GameInstance::GameInstance() :
Merge branch 'master' into jgrpp # Conflicts: # src/animated_tile.cpp # src/cargopacket.h # src/cheat_gui.cpp # src/company_cmd.cpp # src/company_gui.cpp # src/date.cpp # src/disaster_vehicle.cpp # src/dock_gui.cpp # src/economy.cpp # src/engine.cpp # src/error_gui.cpp # src/fontcache/spritefontcache.cpp # src/game/game_gui.cpp # src/game/game_text.cpp # src/gfx.cpp # src/graph_gui.cpp # src/highscore_gui.cpp # src/industry_cmd.cpp # src/lang/dutch.txt # src/lang/english_AU.txt # src/lang/english_US.txt # src/lang/finnish.txt # src/lang/french.txt # src/lang/italian.txt # src/lang/portuguese.txt # src/lang/russian.txt # src/lang/turkish.txt # src/lang/vietnamese.txt # src/main_gui.cpp # src/misc_gui.cpp # src/network/network_gui.cpp # src/network/network_server.cpp # src/newgrf.cpp # src/newgrf.h # src/newgrf_generic.cpp # src/news_gui.cpp # src/openttd.cpp # src/os/unix/unix.cpp # src/os/windows/font_win32.cpp # src/os/windows/win32.cpp # src/rail_gui.cpp # src/road_gui.cpp # src/saveload/afterload.cpp # src/saveload/misc_sl.cpp # src/saveload/oldloader_sl.cpp # src/saveload/saveload.cpp # src/saveload/saveload.h # src/script/script_gui.cpp # src/settings_table.cpp # src/signs_gui.cpp # src/smallmap_gui.cpp # src/smallmap_gui.h # src/spritecache.cpp # src/spritecache.h # src/spriteloader/grf.cpp # src/station_cmd.cpp # src/statusbar_gui.cpp # src/stdafx.h # src/strgen/strgen_base.cpp # src/subsidy.cpp # src/table/settings/difficulty_settings.ini # src/texteff.cpp # src/timetable_cmd.cpp # src/timetable_gui.cpp # src/toolbar_gui.cpp # src/town_cmd.cpp # src/town_gui.cpp # src/townname.cpp # src/vehicle.cpp # src/waypoint_cmd.cpp # src/widgets/dropdown.cpp # src/window.cpp
1 year ago
ScriptInstance("GS", ScriptType::GS)
{}
void GameInstance::Initialize(GameInfo *info)
{
this->versionAPI = info->GetAPIVersion();
/* Register the GameController */
SQGSController_Register(this->engine);
ScriptInstance::Initialize(info->GetMainScript(), info->GetInstanceName(), OWNER_DEITY);
}
void GameInstance::RegisterAPI()
{
ScriptInstance::RegisterAPI();
/* Register all classes */
SQGS_RegisterAll(this->engine);
RegisterGameTranslation(this->engine);
if (!this->LoadCompatibilityScripts(this->versionAPI, GAME_DIR)) this->Died();
}
int GameInstance::GetSetting(const std::string &name)
{
return GameConfig::GetConfig()->GetSetting(name);
}
ScriptInfo *GameInstance::FindLibrary(const std::string &library, int version)
{
return (ScriptInfo *)Game::FindLibrary(library, version);
}
void GameInstance::Died()
{
ScriptInstance::Died();
/* Don't show errors while loading savegame. They will be shown at end of loading anyway. */
if (_switch_mode != SM_NONE) return;
ShowScriptDebugWindow(OWNER_DEITY);
const GameInfo *info = Game::GetInfo();
if (info != nullptr) {
ShowErrorMessage(STR_ERROR_AI_PLEASE_REPORT_CRASH, INVALID_STRING_ID, WL_WARNING);
if (!info->GetURL().empty()) {
ScriptLog::Info("Please report the error to the following URL:");
ScriptLog::Info(info->GetURL());
}
}
}
/**
* DoCommand callback function for all commands executed by Game Scripts.
* @param result The result of the command.
* @param tile The tile on which the command was executed.
* @param p1 p1 as given to DoCommandPInternal.
* @param p2 p2 as given to DoCommandPInternal.
* @param p3 p3 as given to DoCommandPInternal.
* @param cmd cmd as given to DoCommandPInternal.
*/
void CcGame(const CommandCost &result, TileIndex tile, uint32_t p1, uint32_t p2, uint64_t p3, uint32_t cmd)
{
if (Game::GetGameInstance()->DoCommandCallback(result, tile, p1, p2, p3, cmd)) {
Game::GetGameInstance()->Continue();
}
}
CommandCallback *GameInstance::GetDoCommandCallback()
{
return &CcGame;
}