# Conflicts: # .github/workflows/ci-build.yml # .github/workflows/release-linux.yml # .github/workflows/release-macos.yml # .github/workflows/release-source.yml # .github/workflows/release.yml # CMakeLists.txt # COMPILING.md # src/ai/ai_core.cpp # src/ai/ai_gui.cpp # src/bridge_gui.cpp # src/company_gui.cpp # src/console_cmds.cpp # src/core/CMakeLists.txt # src/core/smallmap_type.hpp # src/disaster_vehicle.h # src/effectvehicle_base.h # src/fontcache.cpp # src/game/game_core.cpp # src/game/game_gui.cpp # src/gamelog.cpp # src/gamelog_internal.h # src/group_gui.cpp # src/linkgraph/linkgraph.h # src/misc.cpp # src/network/core/config.h # src/network/core/udp.cpp # src/network/network_chat_gui.cpp # src/network/network_content_gui.cpp # src/network/network_gui.cpp # src/newgrf.cpp # src/newgrf_gui.cpp # src/newgrf_profiling.cpp # src/newgrf_profiling.h # src/object_gui.cpp # src/openttd.cpp # src/openttd.h # src/order_gui.cpp # src/os/windows/font_win32.cpp # src/rail_gui.cpp # src/road.cpp # src/road_gui.cpp # src/saveload/afterload.cpp # src/saveload/saveload.h # src/script/api/script_controller.cpp # src/script/api/script_roadtypelist.cpp # src/script/script_config.cpp # src/script/script_config.hpp # src/script/script_instance.cpp # src/script/script_scanner.cpp # src/script/squirrel.cpp # src/script/squirrel_helper.hpp # src/settings_gui.cpp # src/settings_internal.h # src/settings_type.h # src/table/settings/network_private_settings.ini # src/timetable_gui.cpp # src/vehicle.cpp # src/vehicle_base.h # src/window_gui.h
102 lines
2.9 KiB
C++
102 lines
2.9 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() :
|
|
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();
|
|
|
|
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 p1, uint32 p2, uint64 p3, uint32 cmd)
|
|
{
|
|
if (Game::GetGameInstance()->DoCommandCallback(result, tile, p1, p2, p3, cmd)) {
|
|
Game::GetGameInstance()->Continue();
|
|
}
|
|
}
|
|
|
|
CommandCallback *GameInstance::GetDoCommandCallback()
|
|
{
|
|
return &CcGame;
|
|
}
|