2011-12-19 20:50:54 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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"
|
2012-01-02 22:44:28 +00:00
|
|
|
#include "../error.h"
|
2011-12-19 20:50:54 +00:00
|
|
|
|
|
|
|
#include "../script/squirrel_class.hpp"
|
|
|
|
|
|
|
|
#include "../script/script_storage.hpp"
|
2012-01-02 22:44:28 +00:00
|
|
|
#include "../ai/ai_gui.hpp"
|
2011-12-19 20:55:56 +00:00
|
|
|
#include "game_config.hpp"
|
|
|
|
#include "game_info.hpp"
|
2011-12-19 20:50:54 +00:00
|
|
|
#include "game_instance.hpp"
|
2011-12-19 21:05:46 +00:00
|
|
|
#include "game_text.hpp"
|
2011-12-19 20:50:54 +00:00
|
|
|
#include "game.hpp"
|
|
|
|
|
|
|
|
/* Convert all Game related classes to Squirrel data.
|
|
|
|
* Note: this line is a marker in squirrel_export.sh. Do not change! */
|
|
|
|
#include "../script/api/game/game_accounting.hpp.sq"
|
2011-12-19 21:00:32 +00:00
|
|
|
#include "../script/api/game/game_admin.hpp.sq"
|
2011-12-19 20:57:23 +00:00
|
|
|
#include "../script/api/game/game_airport.hpp.sq"
|
|
|
|
#include "../script/api/game/game_base.hpp.sq"
|
2011-12-19 20:57:34 +00:00
|
|
|
#include "../script/api/game/game_basestation.hpp.sq"
|
|
|
|
#include "../script/api/game/game_bridge.hpp.sq"
|
|
|
|
#include "../script/api/game/game_bridgelist.hpp.sq"
|
2011-12-19 20:57:23 +00:00
|
|
|
#include "../script/api/game/game_cargo.hpp.sq"
|
2011-12-19 20:57:34 +00:00
|
|
|
#include "../script/api/game/game_cargolist.hpp.sq"
|
2012-07-15 17:11:14 +00:00
|
|
|
#include "../script/api/game/game_cargomonitor.hpp.sq"
|
2018-04-22 13:42:29 +00:00
|
|
|
#include "../script/api/game/game_client.hpp.sq"
|
|
|
|
#include "../script/api/game/game_clientlist.hpp.sq"
|
2011-12-19 20:57:23 +00:00
|
|
|
#include "../script/api/game/game_company.hpp.sq"
|
2011-12-19 21:05:25 +00:00
|
|
|
#include "../script/api/game/game_companymode.hpp.sq"
|
2011-12-19 20:50:54 +00:00
|
|
|
#include "../script/api/game/game_controller.hpp.sq"
|
2011-12-19 20:57:23 +00:00
|
|
|
#include "../script/api/game/game_date.hpp.sq"
|
2011-12-19 20:57:34 +00:00
|
|
|
#include "../script/api/game/game_depotlist.hpp.sq"
|
|
|
|
#include "../script/api/game/game_engine.hpp.sq"
|
|
|
|
#include "../script/api/game/game_enginelist.hpp.sq"
|
2011-12-19 20:50:54 +00:00
|
|
|
#include "../script/api/game/game_error.hpp.sq"
|
|
|
|
#include "../script/api/game/game_event.hpp.sq"
|
2011-12-19 20:59:36 +00:00
|
|
|
#include "../script/api/game/game_event_types.hpp.sq"
|
2011-12-19 20:50:54 +00:00
|
|
|
#include "../script/api/game/game_execmode.hpp.sq"
|
2011-12-19 20:58:59 +00:00
|
|
|
#include "../script/api/game/game_game.hpp.sq"
|
2011-12-19 20:57:23 +00:00
|
|
|
#include "../script/api/game/game_gamesettings.hpp.sq"
|
2011-12-19 21:03:17 +00:00
|
|
|
#include "../script/api/game/game_goal.hpp.sq"
|
2011-12-19 20:57:23 +00:00
|
|
|
#include "../script/api/game/game_industry.hpp.sq"
|
|
|
|
#include "../script/api/game/game_industrylist.hpp.sq"
|
|
|
|
#include "../script/api/game/game_industrytype.hpp.sq"
|
|
|
|
#include "../script/api/game/game_industrytypelist.hpp.sq"
|
|
|
|
#include "../script/api/game/game_infrastructure.hpp.sq"
|
2011-12-19 20:50:54 +00:00
|
|
|
#include "../script/api/game/game_list.hpp.sq"
|
|
|
|
#include "../script/api/game/game_log.hpp.sq"
|
2011-12-19 20:57:23 +00:00
|
|
|
#include "../script/api/game/game_map.hpp.sq"
|
|
|
|
#include "../script/api/game/game_marine.hpp.sq"
|
2011-12-19 21:01:03 +00:00
|
|
|
#include "../script/api/game/game_news.hpp.sq"
|
2012-01-22 17:42:03 +00:00
|
|
|
#include "../script/api/game/game_order.hpp.sq"
|
2011-12-19 20:57:34 +00:00
|
|
|
#include "../script/api/game/game_rail.hpp.sq"
|
|
|
|
#include "../script/api/game/game_railtypelist.hpp.sq"
|
2011-12-19 20:57:23 +00:00
|
|
|
#include "../script/api/game/game_road.hpp.sq"
|
2011-12-19 20:59:29 +00:00
|
|
|
#include "../script/api/game/game_sign.hpp.sq"
|
2011-12-19 20:57:23 +00:00
|
|
|
#include "../script/api/game/game_signlist.hpp.sq"
|
2011-12-19 20:57:34 +00:00
|
|
|
#include "../script/api/game/game_station.hpp.sq"
|
|
|
|
#include "../script/api/game/game_stationlist.hpp.sq"
|
2013-06-09 12:19:09 +00:00
|
|
|
#include "../script/api/game/game_story_page.hpp.sq"
|
2014-02-06 19:41:56 +00:00
|
|
|
#include "../script/api/game/game_storypageelementlist.hpp.sq"
|
2014-02-06 19:25:39 +00:00
|
|
|
#include "../script/api/game/game_storypagelist.hpp.sq"
|
2011-12-19 20:57:34 +00:00
|
|
|
#include "../script/api/game/game_subsidy.hpp.sq"
|
|
|
|
#include "../script/api/game/game_subsidylist.hpp.sq"
|
2011-12-19 20:50:54 +00:00
|
|
|
#include "../script/api/game/game_testmode.hpp.sq"
|
2011-12-19 21:05:57 +00:00
|
|
|
#include "../script/api/game/game_text.hpp.sq"
|
2011-12-19 20:57:23 +00:00
|
|
|
#include "../script/api/game/game_tile.hpp.sq"
|
2011-12-19 20:57:34 +00:00
|
|
|
#include "../script/api/game/game_tilelist.hpp.sq"
|
2011-12-19 20:57:23 +00:00
|
|
|
#include "../script/api/game/game_town.hpp.sq"
|
|
|
|
#include "../script/api/game/game_townlist.hpp.sq"
|
2011-12-19 20:57:34 +00:00
|
|
|
#include "../script/api/game/game_tunnel.hpp.sq"
|
2011-12-19 20:57:23 +00:00
|
|
|
#include "../script/api/game/game_vehicle.hpp.sq"
|
2011-12-19 20:57:34 +00:00
|
|
|
#include "../script/api/game/game_vehiclelist.hpp.sq"
|
2011-12-19 21:00:48 +00:00
|
|
|
#include "../script/api/game/game_viewport.hpp.sq"
|
2011-12-19 20:57:34 +00:00
|
|
|
#include "../script/api/game/game_waypoint.hpp.sq"
|
|
|
|
#include "../script/api/game/game_waypointlist.hpp.sq"
|
2011-12-19 21:05:14 +00:00
|
|
|
#include "../script/api/game/game_window.hpp.sq"
|
2011-12-19 20:50:54 +00:00
|
|
|
|
2014-04-23 20:13:33 +00:00
|
|
|
#include "../safeguards.h"
|
|
|
|
|
2011-12-19 20:50:54 +00:00
|
|
|
|
|
|
|
GameInstance::GameInstance() :
|
|
|
|
ScriptInstance("GS")
|
|
|
|
{}
|
|
|
|
|
2011-12-19 20:55:56 +00:00
|
|
|
void GameInstance::Initialize(GameInfo *info)
|
2011-12-19 20:50:54 +00:00
|
|
|
{
|
2012-08-13 19:22:26 +00:00
|
|
|
this->versionAPI = info->GetAPIVersion();
|
|
|
|
|
2011-12-19 20:50:54 +00:00
|
|
|
/* Register the GameController */
|
|
|
|
SQGSController_Register(this->engine);
|
|
|
|
|
2011-12-19 21:05:25 +00:00
|
|
|
ScriptInstance::Initialize(info->GetMainScript(), info->GetInstanceName(), OWNER_DEITY);
|
2011-12-19 20:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GameInstance::RegisterAPI()
|
|
|
|
{
|
|
|
|
ScriptInstance::RegisterAPI();
|
|
|
|
|
|
|
|
/* Register all classes */
|
|
|
|
SQGSList_Register(this->engine);
|
|
|
|
SQGSAccounting_Register(this->engine);
|
2011-12-19 21:00:32 +00:00
|
|
|
SQGSAdmin_Register(this->engine);
|
2011-12-19 20:57:23 +00:00
|
|
|
SQGSAirport_Register(this->engine);
|
|
|
|
SQGSBase_Register(this->engine);
|
2011-12-19 20:57:34 +00:00
|
|
|
SQGSBaseStation_Register(this->engine);
|
|
|
|
SQGSBridge_Register(this->engine);
|
|
|
|
SQGSBridgeList_Register(this->engine);
|
|
|
|
SQGSBridgeList_Length_Register(this->engine);
|
2011-12-19 20:57:23 +00:00
|
|
|
SQGSCargo_Register(this->engine);
|
2011-12-19 20:57:34 +00:00
|
|
|
SQGSCargoList_Register(this->engine);
|
|
|
|
SQGSCargoList_IndustryAccepting_Register(this->engine);
|
|
|
|
SQGSCargoList_IndustryProducing_Register(this->engine);
|
|
|
|
SQGSCargoList_StationAccepting_Register(this->engine);
|
2012-07-15 17:11:14 +00:00
|
|
|
SQGSCargoMonitor_Register(this->engine);
|
2018-04-22 13:42:29 +00:00
|
|
|
SQGSClient_Register(this->engine);
|
|
|
|
SQGSClientList_Register(this->engine);
|
|
|
|
SQGSClientList_Company_Register(this->engine);
|
2011-12-19 20:57:23 +00:00
|
|
|
SQGSCompany_Register(this->engine);
|
2011-12-19 21:05:25 +00:00
|
|
|
SQGSCompanyMode_Register(this->engine);
|
2011-12-19 20:57:23 +00:00
|
|
|
SQGSDate_Register(this->engine);
|
2011-12-19 20:57:34 +00:00
|
|
|
SQGSDepotList_Register(this->engine);
|
|
|
|
SQGSEngine_Register(this->engine);
|
|
|
|
SQGSEngineList_Register(this->engine);
|
2011-12-19 20:50:54 +00:00
|
|
|
SQGSError_Register(this->engine);
|
|
|
|
SQGSEvent_Register(this->engine);
|
2011-12-19 21:00:32 +00:00
|
|
|
SQGSEventAdminPort_Register(this->engine);
|
2011-12-19 20:59:36 +00:00
|
|
|
SQGSEventCompanyBankrupt_Register(this->engine);
|
|
|
|
SQGSEventCompanyInTrouble_Register(this->engine);
|
|
|
|
SQGSEventCompanyMerger_Register(this->engine);
|
|
|
|
SQGSEventCompanyNew_Register(this->engine);
|
2012-05-26 14:16:32 +00:00
|
|
|
SQGSEventCompanyTown_Register(this->engine);
|
2011-12-19 20:50:54 +00:00
|
|
|
SQGSEventController_Register(this->engine);
|
2012-05-26 14:16:38 +00:00
|
|
|
SQGSEventExclusiveTransportRights_Register(this->engine);
|
2012-01-03 16:36:24 +00:00
|
|
|
SQGSEventGoalQuestionAnswer_Register(this->engine);
|
2011-12-19 20:59:36 +00:00
|
|
|
SQGSEventIndustryClose_Register(this->engine);
|
|
|
|
SQGSEventIndustryOpen_Register(this->engine);
|
2012-05-26 14:16:45 +00:00
|
|
|
SQGSEventRoadReconstruction_Register(this->engine);
|
2011-12-19 20:59:36 +00:00
|
|
|
SQGSEventStationFirstVehicle_Register(this->engine);
|
|
|
|
SQGSEventSubsidyAwarded_Register(this->engine);
|
|
|
|
SQGSEventSubsidyExpired_Register(this->engine);
|
|
|
|
SQGSEventSubsidyOffer_Register(this->engine);
|
|
|
|
SQGSEventSubsidyOfferExpired_Register(this->engine);
|
|
|
|
SQGSEventTownFounded_Register(this->engine);
|
|
|
|
SQGSEventVehicleCrashed_Register(this->engine);
|
2011-12-19 21:05:14 +00:00
|
|
|
SQGSEventWindowWidgetClick_Register(this->engine);
|
2011-12-19 20:50:54 +00:00
|
|
|
SQGSExecMode_Register(this->engine);
|
2011-12-19 20:58:59 +00:00
|
|
|
SQGSGame_Register(this->engine);
|
2011-12-19 20:57:23 +00:00
|
|
|
SQGSGameSettings_Register(this->engine);
|
2011-12-19 21:03:17 +00:00
|
|
|
SQGSGoal_Register(this->engine);
|
2011-12-19 20:57:23 +00:00
|
|
|
SQGSIndustry_Register(this->engine);
|
|
|
|
SQGSIndustryList_Register(this->engine);
|
|
|
|
SQGSIndustryList_CargoAccepting_Register(this->engine);
|
|
|
|
SQGSIndustryList_CargoProducing_Register(this->engine);
|
|
|
|
SQGSIndustryType_Register(this->engine);
|
|
|
|
SQGSIndustryTypeList_Register(this->engine);
|
|
|
|
SQGSInfrastructure_Register(this->engine);
|
2011-12-19 20:50:54 +00:00
|
|
|
SQGSLog_Register(this->engine);
|
2011-12-19 20:57:23 +00:00
|
|
|
SQGSMap_Register(this->engine);
|
|
|
|
SQGSMarine_Register(this->engine);
|
2011-12-19 21:01:03 +00:00
|
|
|
SQGSNews_Register(this->engine);
|
2012-01-22 17:42:03 +00:00
|
|
|
SQGSOrder_Register(this->engine);
|
2011-12-19 20:57:34 +00:00
|
|
|
SQGSRail_Register(this->engine);
|
|
|
|
SQGSRailTypeList_Register(this->engine);
|
2011-12-19 20:57:23 +00:00
|
|
|
SQGSRoad_Register(this->engine);
|
2011-12-19 20:59:29 +00:00
|
|
|
SQGSSign_Register(this->engine);
|
2011-12-19 20:57:23 +00:00
|
|
|
SQGSSignList_Register(this->engine);
|
2011-12-19 20:57:34 +00:00
|
|
|
SQGSStation_Register(this->engine);
|
|
|
|
SQGSStationList_Register(this->engine);
|
2014-09-21 16:20:48 +00:00
|
|
|
SQGSStationList_Cargo_Register(this->engine);
|
|
|
|
SQGSStationList_CargoPlanned_Register(this->engine);
|
|
|
|
SQGSStationList_CargoPlannedByFrom_Register(this->engine);
|
|
|
|
SQGSStationList_CargoPlannedByVia_Register(this->engine);
|
|
|
|
SQGSStationList_CargoPlannedFromByVia_Register(this->engine);
|
|
|
|
SQGSStationList_CargoPlannedViaByFrom_Register(this->engine);
|
|
|
|
SQGSStationList_CargoWaiting_Register(this->engine);
|
|
|
|
SQGSStationList_CargoWaitingByFrom_Register(this->engine);
|
|
|
|
SQGSStationList_CargoWaitingByVia_Register(this->engine);
|
|
|
|
SQGSStationList_CargoWaitingFromByVia_Register(this->engine);
|
|
|
|
SQGSStationList_CargoWaitingViaByFrom_Register(this->engine);
|
2011-12-19 20:57:34 +00:00
|
|
|
SQGSStationList_Vehicle_Register(this->engine);
|
2013-06-09 12:19:09 +00:00
|
|
|
SQGSStoryPage_Register(this->engine);
|
2014-02-06 19:41:56 +00:00
|
|
|
SQGSStoryPageElementList_Register(this->engine);
|
2014-02-06 19:25:39 +00:00
|
|
|
SQGSStoryPageList_Register(this->engine);
|
2011-12-19 20:57:34 +00:00
|
|
|
SQGSSubsidy_Register(this->engine);
|
|
|
|
SQGSSubsidyList_Register(this->engine);
|
2011-12-19 20:50:54 +00:00
|
|
|
SQGSTestMode_Register(this->engine);
|
2011-12-19 21:05:57 +00:00
|
|
|
SQGSText_Register(this->engine);
|
2011-12-19 20:57:23 +00:00
|
|
|
SQGSTile_Register(this->engine);
|
2011-12-19 20:57:34 +00:00
|
|
|
SQGSTileList_Register(this->engine);
|
|
|
|
SQGSTileList_IndustryAccepting_Register(this->engine);
|
|
|
|
SQGSTileList_IndustryProducing_Register(this->engine);
|
|
|
|
SQGSTileList_StationType_Register(this->engine);
|
2011-12-19 20:57:23 +00:00
|
|
|
SQGSTown_Register(this->engine);
|
|
|
|
SQGSTownEffectList_Register(this->engine);
|
|
|
|
SQGSTownList_Register(this->engine);
|
2011-12-19 20:57:34 +00:00
|
|
|
SQGSTunnel_Register(this->engine);
|
2011-12-19 20:57:23 +00:00
|
|
|
SQGSVehicle_Register(this->engine);
|
2011-12-19 20:57:34 +00:00
|
|
|
SQGSVehicleList_Register(this->engine);
|
|
|
|
SQGSVehicleList_Depot_Register(this->engine);
|
|
|
|
SQGSVehicleList_SharedOrders_Register(this->engine);
|
|
|
|
SQGSVehicleList_Station_Register(this->engine);
|
2011-12-19 21:00:48 +00:00
|
|
|
SQGSViewport_Register(this->engine);
|
2011-12-19 20:57:34 +00:00
|
|
|
SQGSWaypoint_Register(this->engine);
|
|
|
|
SQGSWaypointList_Register(this->engine);
|
|
|
|
SQGSWaypointList_Vehicle_Register(this->engine);
|
2011-12-19 21:05:14 +00:00
|
|
|
SQGSWindow_Register(this->engine);
|
2011-12-19 20:50:54 +00:00
|
|
|
|
2011-12-19 21:05:46 +00:00
|
|
|
RegisterGameTranslation(this->engine);
|
2012-08-13 19:22:26 +00:00
|
|
|
|
|
|
|
if (!this->LoadCompatibilityScripts(this->versionAPI, GAME_DIR)) this->Died();
|
2011-12-19 20:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int GameInstance::GetSetting(const char *name)
|
|
|
|
{
|
2011-12-19 20:55:56 +00:00
|
|
|
return GameConfig::GetConfig()->GetSetting(name);
|
2011-12-19 20:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ScriptInfo *GameInstance::FindLibrary(const char *library, int version)
|
|
|
|
{
|
2011-12-19 20:56:59 +00:00
|
|
|
return (ScriptInfo *)Game::FindLibrary(library, version);
|
2011-12-19 20:50:54 +00:00
|
|
|
}
|
|
|
|
|
2012-01-02 22:44:28 +00:00
|
|
|
void GameInstance::Died()
|
|
|
|
{
|
|
|
|
ScriptInstance::Died();
|
|
|
|
|
|
|
|
ShowAIDebugWindow(OWNER_DEITY);
|
|
|
|
|
|
|
|
const GameInfo *info = Game::GetInfo();
|
|
|
|
if (info != NULL) {
|
|
|
|
ShowErrorMessage(STR_ERROR_AI_PLEASE_REPORT_CRASH, INVALID_STRING_ID, WL_WARNING);
|
|
|
|
|
|
|
|
if (info->GetURL() != NULL) {
|
|
|
|
ScriptLog::Info("Please report the error to the following URL:");
|
|
|
|
ScriptLog::Info(info->GetURL());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-19 20:50:54 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
void CcGame(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
|
|
|
|
{
|
|
|
|
Game::GetGameInstance()->DoCommandCallback(result, tile, p1, p2);
|
|
|
|
Game::GetGameInstance()->Continue();
|
|
|
|
}
|
|
|
|
|
|
|
|
CommandCallback *GameInstance::GetDoCommandCallback()
|
|
|
|
{
|
|
|
|
return &CcGame;
|
|
|
|
}
|