diff options
33 files changed, 729 insertions, 37 deletions
diff --git a/projects/openttd_vs100.vcxproj b/projects/openttd_vs100.vcxproj index ff0ec9a9c..44aa0247e 100644 --- a/projects/openttd_vs100.vcxproj +++ b/projects/openttd_vs100.vcxproj @@ -913,6 +913,10 @@ <ClCompile Include="..\src\ai\ai_scanner.cpp" /> <ClInclude Include="..\src\ai\ai_scanner.hpp" /> <ClInclude Include="..\src\script\api\ai_changelog.hpp" /> + <ClInclude Include="..\src\game\game.hpp" /> + <ClCompile Include="..\src\game\game_core.cpp" /> + <ClCompile Include="..\src\game\game_instance.cpp" /> + <ClInclude Include="..\src\game\game_instance.hpp" /> <ClInclude Include="..\src\script\api\script_accounting.hpp" /> <ClInclude Include="..\src\script\api\script_airport.hpp" /> <ClInclude Include="..\src\script\api\script_base.hpp" /> diff --git a/projects/openttd_vs100.vcxproj.filters b/projects/openttd_vs100.vcxproj.filters index a90e8d8d1..7a5d16e2e 100644 --- a/projects/openttd_vs100.vcxproj.filters +++ b/projects/openttd_vs100.vcxproj.filters @@ -43,57 +43,60 @@ <Filter Include="AI API"> <UniqueIdentifier>{c76ff9f1-1e62-46d8-8d55-000000000013}</UniqueIdentifier> </Filter> - <Filter Include="Script API"> + <Filter Include="Game Core"> <UniqueIdentifier>{c76ff9f1-1e62-46d8-8d55-000000000014}</UniqueIdentifier> </Filter> - <Filter Include="Script API Implementation"> + <Filter Include="Script API"> <UniqueIdentifier>{c76ff9f1-1e62-46d8-8d55-000000000015}</UniqueIdentifier> </Filter> - <Filter Include="Blitters"> + <Filter Include="Script API Implementation"> <UniqueIdentifier>{c76ff9f1-1e62-46d8-8d55-000000000016}</UniqueIdentifier> </Filter> - <Filter Include="Drivers"> + <Filter Include="Blitters"> <UniqueIdentifier>{c76ff9f1-1e62-46d8-8d55-000000000017}</UniqueIdentifier> </Filter> - <Filter Include="Sprite loaders"> + <Filter Include="Drivers"> <UniqueIdentifier>{c76ff9f1-1e62-46d8-8d55-000000000018}</UniqueIdentifier> </Filter> - <Filter Include="NewGRF"> + <Filter Include="Sprite loaders"> <UniqueIdentifier>{c76ff9f1-1e62-46d8-8d55-000000000019}</UniqueIdentifier> </Filter> - <Filter Include="Map Accessors"> + <Filter Include="NewGRF"> <UniqueIdentifier>{c76ff9f1-1e62-46d8-8d55-000000000020}</UniqueIdentifier> </Filter> - <Filter Include="Misc"> + <Filter Include="Map Accessors"> <UniqueIdentifier>{c76ff9f1-1e62-46d8-8d55-000000000021}</UniqueIdentifier> </Filter> - <Filter Include="Network Core"> + <Filter Include="Misc"> <UniqueIdentifier>{c76ff9f1-1e62-46d8-8d55-000000000022}</UniqueIdentifier> </Filter> - <Filter Include="Pathfinder"> + <Filter Include="Network Core"> <UniqueIdentifier>{c76ff9f1-1e62-46d8-8d55-000000000023}</UniqueIdentifier> </Filter> - <Filter Include="NPF"> + <Filter Include="Pathfinder"> <UniqueIdentifier>{c76ff9f1-1e62-46d8-8d55-000000000024}</UniqueIdentifier> </Filter> - <Filter Include="YAPF"> + <Filter Include="NPF"> <UniqueIdentifier>{c76ff9f1-1e62-46d8-8d55-000000000025}</UniqueIdentifier> </Filter> - <Filter Include="Video"> + <Filter Include="YAPF"> <UniqueIdentifier>{c76ff9f1-1e62-46d8-8d55-000000000026}</UniqueIdentifier> </Filter> - <Filter Include="Music"> + <Filter Include="Video"> <UniqueIdentifier>{c76ff9f1-1e62-46d8-8d55-000000000027}</UniqueIdentifier> </Filter> - <Filter Include="Sound"> + <Filter Include="Music"> <UniqueIdentifier>{c76ff9f1-1e62-46d8-8d55-000000000028}</UniqueIdentifier> </Filter> - <Filter Include="Windows files"> + <Filter Include="Sound"> <UniqueIdentifier>{c76ff9f1-1e62-46d8-8d55-000000000029}</UniqueIdentifier> </Filter> - <Filter Include="Threading"> + <Filter Include="Windows files"> <UniqueIdentifier>{c76ff9f1-1e62-46d8-8d55-000000000030}</UniqueIdentifier> </Filter> + <Filter Include="Threading"> + <UniqueIdentifier>{c76ff9f1-1e62-46d8-8d55-000000000031}</UniqueIdentifier> + </Filter> </ItemGroup> <ItemGroup> <ClCompile Include="..\src\airport.cpp"> @@ -1962,6 +1965,18 @@ <ClInclude Include="..\src\script\api\ai_changelog.hpp"> <Filter>AI API</Filter> </ClInclude> + <ClInclude Include="..\src\game\game.hpp"> + <Filter>Game Core</Filter> + </ClInclude> + <ClCompile Include="..\src\game\game_core.cpp"> + <Filter>Game Core</Filter> + </ClCompile> + <ClCompile Include="..\src\game\game_instance.cpp"> + <Filter>Game Core</Filter> + </ClCompile> + <ClInclude Include="..\src\game\game_instance.hpp"> + <Filter>Game Core</Filter> + </ClInclude> <ClInclude Include="..\src\script\api\script_accounting.hpp"> <Filter>Script API</Filter> </ClInclude> diff --git a/projects/openttd_vs80.vcproj b/projects/openttd_vs80.vcproj index f60e5fa07..5d6897dfa 100644 --- a/projects/openttd_vs80.vcproj +++ b/projects/openttd_vs80.vcproj @@ -2976,6 +2976,26 @@ </File> </Filter> <Filter + Name="Game Core" + > + <File + RelativePath=".\..\src\game\game.hpp" + > + </File> + <File + RelativePath=".\..\src\game\game_core.cpp" + > + </File> + <File + RelativePath=".\..\src\game\game_instance.cpp" + > + </File> + <File + RelativePath=".\..\src\game\game_instance.hpp" + > + </File> + </Filter> + <Filter Name="Script API" > <File diff --git a/projects/openttd_vs90.vcproj b/projects/openttd_vs90.vcproj index 636b9f131..f253d4c96 100644 --- a/projects/openttd_vs90.vcproj +++ b/projects/openttd_vs90.vcproj @@ -2973,6 +2973,26 @@ </File> </Filter> <Filter + Name="Game Core" + > + <File + RelativePath=".\..\src\game\game.hpp" + > + </File> + <File + RelativePath=".\..\src\game\game_core.cpp" + > + </File> + <File + RelativePath=".\..\src\game\game_instance.cpp" + > + </File> + <File + RelativePath=".\..\src\game\game_instance.hpp" + > + </File> + </Filter> + <Filter Name="Script API" > <File diff --git a/source.list b/source.list index 1de4d68b5..cdc5cbf23 100644 --- a/source.list +++ b/source.list @@ -686,6 +686,12 @@ ai/ai_scanner.hpp # AI API script/api/ai_changelog.hpp +# Game Core +game/game.hpp +game/game_core.cpp +game/game_instance.cpp +game/game_instance.hpp + # Script API script/api/script_accounting.hpp script/api/script_airport.hpp diff --git a/src/command_func.h b/src/command_func.h index a4304de0d..df5f099a7 100644 --- a/src/command_func.h +++ b/src/command_func.h @@ -86,6 +86,9 @@ CommandCallback CcBuildCanal; /* depot_gui.cpp */ CommandCallback CcCloneVehicle; +/* game/game_instance.cpp */ +CommandCallback CcGame; + /* group_gui.cpp */ CommandCallback CcCreateGroup; diff --git a/src/game/game.hpp b/src/game/game.hpp new file mode 100644 index 000000000..de9e8213c --- /dev/null +++ b/src/game/game.hpp @@ -0,0 +1,45 @@ +/* $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.hpp Base functions for all Games. */ + +#ifndef GAME_HPP +#define GAME_HPP + +/** + * Main Game class. Contains all functions needed to start, stop, save and load Game Scripts. + */ +class Game { +public: + /** + * Called every game-tick to let Game do something. + */ + static void GameLoop(); + + /** + * Initialize the Game system. + */ + static void Initialize(); + + /** + * Uninitialize the Game system. + */ + static void Uninitialize(); + + /** + * Get the current GameScript instance. + */ + static class GameInstance *GetGameInstance() { return Game::instance; } + +private: + static uint frame_counter; ///< Tick counter for the Game code. + static class GameInstance *instance; ///< Instance to the current active Game. +}; + +#endif /* GAME_HPP */ diff --git a/src/game/game_core.cpp b/src/game/game_core.cpp new file mode 100644 index 000000000..7894ab2a6 --- /dev/null +++ b/src/game/game_core.cpp @@ -0,0 +1,64 @@ +/* $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_core.cpp Implementation of Game. */ + +#include "../stdafx.h" +#include "../command_func.h" +#include "../core/backup_type.hpp" +#include "../company_base.h" +#include "../company_func.h" +#include "../network/network.h" +#include "game.hpp" +#include "game_instance.hpp" + +/* static */ uint Game::frame_counter = 0; +/* static */ GameInstance *Game::instance = NULL; + +/* static */ void Game::GameLoop() +{ + if (_networking && !_network_server) return; + + Game::frame_counter++; + + Backup<CompanyByte> cur_company(_current_company, FILE_LINE); + cur_company.Change(OWNER_DEITY); + Game::instance->GameLoop(); + cur_company.Restore(); + + /* Occasionally collect garbage */ + if ((Game::frame_counter & 255) == 0) { + Game::instance->CollectGarbage(); + } +} + +/* static */ void Game::Initialize() +{ + if (Game::instance != NULL) Game::Uninitialize(); + + Game::frame_counter = 0; + if (Game::instance == NULL) { + /* Clients shouldn't start GameScripts */ + if (_networking && !_network_server) return; + + Backup<CompanyByte> cur_company(_current_company, FILE_LINE); + cur_company.Change(OWNER_DEITY); + + Game::instance = new GameInstance(); + Game::instance->Initialize(); + + cur_company.Restore(); + } +} + +/* static */ void Game::Uninitialize() +{ + delete Game::instance; + Game::instance = NULL; +} diff --git a/src/game/game_instance.cpp b/src/game/game_instance.cpp new file mode 100644 index 000000000..ed30062e1 --- /dev/null +++ b/src/game/game_instance.cpp @@ -0,0 +1,89 @@ +/* $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" +#include "../debug.h" +#include "../saveload/saveload.h" + +#include "../script/squirrel_class.hpp" + +#include "../script/script_storage.hpp" +#include "game_instance.hpp" +#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" +#include "../script/api/game/game_controller.hpp.sq" +#include "../script/api/game/game_error.hpp.sq" +#include "../script/api/game/game_event.hpp.sq" +#include "../script/api/game/game_execmode.hpp.sq" +#include "../script/api/game/game_list.hpp.sq" +#include "../script/api/game/game_log.hpp.sq" +#include "../script/api/game/game_testmode.hpp.sq" + + +GameInstance::GameInstance() : + ScriptInstance("GS") +{} + +void GameInstance::Initialize() +{ + /* Register the GameController */ + SQGSController_Register(this->engine); + + ScriptInstance::Initialize("test/main.nut", "TestGame"); +} + +void GameInstance::RegisterAPI() +{ + ScriptInstance::RegisterAPI(); + +/* Register all classes */ + SQGSList_Register(this->engine); + SQGSAccounting_Register(this->engine); + SQGSError_Register(this->engine); + SQGSEvent_Register(this->engine); + SQGSEventController_Register(this->engine); + SQGSExecMode_Register(this->engine); + SQGSLog_Register(this->engine); + SQGSTestMode_Register(this->engine); + +} + +int GameInstance::GetSetting(const char *name) +{ + return NULL; +} + +ScriptInfo *GameInstance::FindLibrary(const char *library, int version) +{ + /* 'import' is not supported with GameScripts */ + return NULL; +} + +/** + * 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; +} diff --git a/src/game/game_instance.hpp b/src/game/game_instance.hpp new file mode 100644 index 000000000..10937c648 --- /dev/null +++ b/src/game/game_instance.hpp @@ -0,0 +1,36 @@ +/* $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.hpp The GameInstance tracks games. */ + +#ifndef GAME_INSTANCE_HPP +#define GAME_INSTANCE_HPP + +#include "../script/script_instance.hpp" + +/** Runtime information about a game script like a pointer to the squirrel vm and the current state. */ +class GameInstance : public ScriptInstance { +public: + GameInstance(); + + /** + * Initialize the script and prepare it for its first run. + */ + void Initialize(); + + /* virtual */ int GetSetting(const char *name); + /* virtual */ ScriptInfo *FindLibrary(const char *library, int version); + +private: + /* virtual */ void RegisterAPI(); + /* virtual */ CommandCallback *GetDoCommandCallback(); + /* virtual */ void LoadDummyScript() {} +}; + +#endif /* GAME_INSTANCE_HPP */ diff --git a/src/misc.cpp b/src/misc.cpp index 614ca4013..5f05c9fe9 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -27,6 +27,7 @@ #include "network/network_func.h" #include "window_func.h" #include "core/pool_type.hpp" +#include "game/game.hpp" extern TileIndex _cur_tileloop_tile; @@ -94,6 +95,7 @@ void InitializeGame(uint size_x, uint size_y, bool reset_date, bool reset_settin InitializeCompanies(); AI::Initialize(); + Game::Initialize(); InitializeCheats(); InitTextEffects(); diff --git a/src/network/network_command.cpp b/src/network/network_command.cpp index 02ee6acf8..c5ec83e28 100644 --- a/src/network/network_command.cpp +++ b/src/network/network_command.cpp @@ -47,6 +47,7 @@ static CommandCallback * const _callback_table[] = { /* 0x17 */ CcRoadStop, /* 0x18 */ CcBuildIndustry, /* 0x19 */ CcStartStopVehicle, + /* 0x1A */ CcGame, }; /** diff --git a/src/openttd.cpp b/src/openttd.cpp index 5745fadee..81c9dd443 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -62,6 +62,7 @@ #include "hotkeys.h" #include "newgrf.h" #include "misc/getoptdata.h" +#include "game/game.hpp" #include "town.h" @@ -284,8 +285,9 @@ static void ShutdownGame() UnInitWindowSystem(); - /* stop the AI */ + /* stop the scripts */ AI::Uninitialize(false); + Game::Uninitialize(); /* Uninitialize variables that are allocated dynamically */ GamelogReset(); @@ -1253,6 +1255,7 @@ void StateGameLoop() /* dont execute the state loop during pause */ if (_pause_mode != PM_UNPAUSED) { UpdateLandscapingLimits(); + Game::GameLoop(); CallWindowTickEvent(); return; } @@ -1291,6 +1294,7 @@ void StateGameLoop() ClearStorageChanges(true); AI::GameLoop(); + Game::GameLoop(); UpdateLandscapingLimits(); CallWindowTickEvent(); diff --git a/src/script/api/game/game_accounting.hpp.sq b/src/script/api/game/game_accounting.hpp.sq new file mode 100644 index 000000000..0e78172c0 --- /dev/null +++ b/src/script/api/game/game_accounting.hpp.sq @@ -0,0 +1,28 @@ +/* $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/>. + */ + +/* THIS FILE IS AUTO-GENERATED; PLEASE DO NOT ALTER MANUALLY */ + +#include "../script_accounting.hpp" +#include "../template/template_accounting.hpp.sq" + + +template <> const char *GetClassName<ScriptAccounting, ST_GS>() { return "GSAccounting"; } + +void SQGSAccounting_Register(Squirrel *engine) +{ + DefSQClass<ScriptAccounting, ST_GS> SQGSAccounting("GSAccounting"); + SQGSAccounting.PreRegister(engine); + SQGSAccounting.AddConstructor<void (ScriptAccounting::*)(), 1>(engine, "x"); + + SQGSAccounting.DefSQMethod(engine, &ScriptAccounting::GetCosts, "GetCosts", 1, "x"); + SQGSAccounting.DefSQMethod(engine, &ScriptAccounting::ResetCosts, "ResetCosts", 1, "x"); + + SQGSAccounting.PostRegister(engine); +} diff --git a/src/script/api/game/game_controller.hpp.sq b/src/script/api/game/game_controller.hpp.sq new file mode 100644 index 000000000..53882fd3a --- /dev/null +++ b/src/script/api/game/game_controller.hpp.sq @@ -0,0 +1,28 @@ +/* $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/>. + */ + +#include "../script_controller.hpp" + +template <> const char *GetClassName<ScriptController, ST_GS>() { return "GSController"; } + +void SQGSController_Register(Squirrel *engine) +{ + DefSQClass<ScriptController, ST_GS> SQGSController("GSController"); + SQGSController.PreRegister(engine); + + SQGSController.DefSQStaticMethod(engine, &ScriptController::GetTick, "GetTick", 1, "."); + SQGSController.DefSQStaticMethod(engine, &ScriptController::GetOpsTillSuspend, "GetOpsTillSuspend", 1, "."); + SQGSController.DefSQStaticMethod(engine, &ScriptController::SetCommandDelay, "SetCommandDelay", 2, ".i"); + SQGSController.DefSQStaticMethod(engine, &ScriptController::Sleep, "Sleep", 2, ".i"); + SQGSController.DefSQStaticMethod(engine, &ScriptController::GetSetting, "GetSetting", 2, ".s"); + SQGSController.DefSQStaticMethod(engine, &ScriptController::GetVersion, "GetVersion", 1, "."); + SQGSController.DefSQStaticMethod(engine, &ScriptController::Print, "Print", 3, ".bs"); + + SQGSController.PostRegister(engine); +} diff --git a/src/script/api/game/game_error.hpp.sq b/src/script/api/game/game_error.hpp.sq new file mode 100644 index 000000000..ff3f940f3 --- /dev/null +++ b/src/script/api/game/game_error.hpp.sq @@ -0,0 +1,115 @@ +/* $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/>. + */ + +/* THIS FILE IS AUTO-GENERATED; PLEASE DO NOT ALTER MANUALLY */ + +#include "../script_error.hpp" +#include "../template/template_error.hpp.sq" + + +template <> const char *GetClassName<ScriptError, ST_GS>() { return "GSError"; } + +void SQGSError_Register(Squirrel *engine) +{ + DefSQClass<ScriptError, ST_GS> SQGSError("GSError"); + SQGSError.PreRegister(engine); + SQGSError.AddConstructor<void (ScriptError::*)(), 1>(engine, "x"); + + SQGSError.DefSQConst(engine, ScriptError::ERR_CAT_NONE, "ERR_CAT_NONE"); + SQGSError.DefSQConst(engine, ScriptError::ERR_CAT_GENERAL, "ERR_CAT_GENERAL"); + SQGSError.DefSQConst(engine, ScriptError::ERR_CAT_VEHICLE, "ERR_CAT_VEHICLE"); + SQGSError.DefSQConst(engine, ScriptError::ERR_CAT_STATION, "ERR_CAT_STATION"); + SQGSError.DefSQConst(engine, ScriptError::ERR_CAT_BRIDGE, "ERR_CAT_BRIDGE"); + SQGSError.DefSQConst(engine, ScriptError::ERR_CAT_TUNNEL, "ERR_CAT_TUNNEL"); + SQGSError.DefSQConst(engine, ScriptError::ERR_CAT_TILE, "ERR_CAT_TILE"); + SQGSError.DefSQConst(engine, ScriptError::ERR_CAT_SIGN, "ERR_CAT_SIGN"); + SQGSError.DefSQConst(engine, ScriptError::ERR_CAT_RAIL, "ERR_CAT_RAIL"); + SQGSError.DefSQConst(engine, ScriptError::ERR_CAT_ROAD, "ERR_CAT_ROAD"); + SQGSError.DefSQConst(engine, ScriptError::ERR_CAT_ORDER, "ERR_CAT_ORDER"); + SQGSError.DefSQConst(engine, ScriptError::ERR_CAT_MARINE, "ERR_CAT_MARINE"); + SQGSError.DefSQConst(engine, ScriptError::ERR_CAT_WAYPOINT, "ERR_CAT_WAYPOINT"); + SQGSError.DefSQConst(engine, ScriptError::ERR_CAT_BIT_SIZE, "ERR_CAT_BIT_SIZE"); + SQGSError.DefSQConst(engine, ScriptError::ERR_NONE, "ERR_NONE"); + SQGSError.DefSQConst(engine, ScriptError::ERR_UNKNOWN, "ERR_UNKNOWN"); + SQGSError.DefSQConst(engine, ScriptError::ERR_PRECONDITION_FAILED, "ERR_PRECONDITION_FAILED"); + SQGSError.DefSQConst(engine, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG, "ERR_PRECONDITION_STRING_TOO_LONG"); + SQGSError.DefSQConst(engine, ScriptError::ERR_NEWGRF_SUPPLIED_ERROR, "ERR_NEWGRF_SUPPLIED_ERROR"); + SQGSError.DefSQConst(engine, ScriptError::ERR_GENERAL_BASE, "ERR_GENERAL_BASE"); + SQGSError.DefSQConst(engine, ScriptError::ERR_NOT_ENOUGH_CASH, "ERR_NOT_ENOUGH_CASH"); + SQGSError.DefSQConst(engine, ScriptError::ERR_LOCAL_AUTHORITY_REFUSES, "ERR_LOCAL_AUTHORITY_REFUSES"); + SQGSError.DefSQConst(engine, ScriptError::ERR_ALREADY_BUILT, "ERR_ALREADY_BUILT"); + SQGSError.DefSQConst(engine, ScriptError::ERR_AREA_NOT_CLEAR, "ERR_AREA_NOT_CLEAR"); + SQGSError.DefSQConst(engine, ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY, "ERR_OWNED_BY_ANOTHER_COMPANY"); + SQGSError.DefSQConst(engine, ScriptError::ERR_NAME_IS_NOT_UNIQUE, "ERR_NAME_IS_NOT_UNIQUE"); + SQGSError.DefSQConst(engine, ScriptError::ERR_FLAT_LAND_REQUIRED, "ERR_FLAT_LAND_REQUIRED"); + SQGSError.DefSQConst(engine, ScriptError::ERR_LAND_SLOPED_WRONG, "ERR_LAND_SLOPED_WRONG"); + SQGSError.DefSQConst(engine, ScriptError::ERR_VEHICLE_IN_THE_WAY, "ERR_VEHICLE_IN_THE_WAY"); + SQGSError.DefSQConst(engine, ScriptError::ERR_SITE_UNSUITABLE, "ERR_SITE_UNSUITABLE"); + SQGSError.DefSQConst(engine, ScriptError::ERR_TOO_CLOSE_TO_EDGE, "ERR_TOO_CLOSE_TO_EDGE"); + SQGSError.DefSQConst(engine, ScriptError::ERR_STATION_TOO_SPREAD_OUT, "ERR_STATION_TOO_SPREAD_OUT"); + + ScriptError::RegisterErrorMap(STR_ERROR_NOT_ENOUGH_CASH_REQUIRES_CURRENCY, ScriptError::ERR_NOT_ENOUGH_CASH); + ScriptError::RegisterErrorMap(STR_ERROR_LOCAL_AUTHORITY_REFUSES_TO_ALLOW_THIS, ScriptError::ERR_LOCAL_AUTHORITY_REFUSES); + ScriptError::RegisterErrorMap(STR_ERROR_ALREADY_BUILT, ScriptError::ERR_ALREADY_BUILT); + ScriptError::RegisterErrorMap(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST, ScriptError::ERR_ALREADY_BUILT); + ScriptError::RegisterErrorMap(STR_ERROR_BUILDING_MUST_BE_DEMOLISHED, ScriptError::ERR_AREA_NOT_CLEAR); + ScriptError::RegisterErrorMap(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST, ScriptError::ERR_AREA_NOT_CLEAR); + ScriptError::RegisterErrorMap(STR_ERROR_MUST_DEMOLISH_RAILROAD, ScriptError::ERR_AREA_NOT_CLEAR); + ScriptError::RegisterErrorMap(STR_ERROR_MUST_DEMOLISH_AIRPORT_FIRST, ScriptError::ERR_AREA_NOT_CLEAR); + ScriptError::RegisterErrorMap(STR_ERROR_MUST_DEMOLISH_CARGO_TRAM_STATION_FIRST, ScriptError::ERR_AREA_NOT_CLEAR); + ScriptError::RegisterErrorMap(STR_ERROR_MUST_DEMOLISH_TRUCK_STATION_FIRST, ScriptError::ERR_AREA_NOT_CLEAR); + ScriptError::RegisterErrorMap(STR_ERROR_MUST_DEMOLISH_PASSENGER_TRAM_STATION_FIRST, ScriptError::ERR_AREA_NOT_CLEAR); + ScriptError::RegisterErrorMap(STR_ERROR_MUST_DEMOLISH_BUS_STATION_FIRST, ScriptError::ERR_AREA_NOT_CLEAR); + ScriptError::RegisterErrorMap(STR_ERROR_BUOY_IN_THE_WAY, ScriptError::ERR_AREA_NOT_CLEAR); + ScriptError::RegisterErrorMap(STR_ERROR_MUST_DEMOLISH_DOCK_FIRST, ScriptError::ERR_AREA_NOT_CLEAR); + ScriptError::RegisterErrorMap(STR_ERROR_GENERIC_OBJECT_IN_THE_WAY, ScriptError::ERR_AREA_NOT_CLEAR); + ScriptError::RegisterErrorMap(STR_ERROR_COMPANY_HEADQUARTERS_IN, ScriptError::ERR_AREA_NOT_CLEAR); + ScriptError::RegisterErrorMap(STR_ERROR_OBJECT_IN_THE_WAY, ScriptError::ERR_AREA_NOT_CLEAR); + ScriptError::RegisterErrorMap(STR_ERROR_MUST_REMOVE_ROAD_FIRST, ScriptError::ERR_AREA_NOT_CLEAR); + ScriptError::RegisterErrorMap(STR_ERROR_MUST_REMOVE_RAILROAD_TRACK, ScriptError::ERR_AREA_NOT_CLEAR); + ScriptError::RegisterErrorMap(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST, ScriptError::ERR_AREA_NOT_CLEAR); + ScriptError::RegisterErrorMap(STR_ERROR_MUST_DEMOLISH_TUNNEL_FIRST, ScriptError::ERR_AREA_NOT_CLEAR); + ScriptError::RegisterErrorMap(STR_ERROR_EXCAVATION_WOULD_DAMAGE, ScriptError::ERR_AREA_NOT_CLEAR); + ScriptError::RegisterErrorMap(STR_ERROR_AREA_IS_OWNED_BY_ANOTHER, ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY); + ScriptError::RegisterErrorMap(STR_ERROR_OWNED_BY, ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY); + ScriptError::RegisterErrorMap(STR_ERROR_NAME_MUST_BE_UNIQUE, ScriptError::ERR_NAME_IS_NOT_UNIQUE); + ScriptError::RegisterErrorMap(STR_ERROR_FLAT_LAND_REQUIRED, ScriptError::ERR_FLAT_LAND_REQUIRED); + ScriptError::RegisterErrorMap(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION, ScriptError::ERR_LAND_SLOPED_WRONG); + ScriptError::RegisterErrorMap(STR_ERROR_TRAIN_IN_THE_WAY, ScriptError::ERR_VEHICLE_IN_THE_WAY); + ScriptError::RegisterErrorMap(STR_ERROR_ROAD_VEHICLE_IN_THE_WAY, ScriptError::ERR_VEHICLE_IN_THE_WAY); + ScriptError::RegisterErrorMap(STR_ERROR_SHIP_IN_THE_WAY, ScriptError::ERR_VEHICLE_IN_THE_WAY); + ScriptError::RegisterErrorMap(STR_ERROR_AIRCRAFT_IN_THE_WAY, ScriptError::ERR_VEHICLE_IN_THE_WAY); + ScriptError::RegisterErrorMap(STR_ERROR_SITE_UNSUITABLE, ScriptError::ERR_SITE_UNSUITABLE); + ScriptError::RegisterErrorMap(STR_ERROR_TOO_CLOSE_TO_EDGE_OF_MAP, ScriptError::ERR_TOO_CLOSE_TO_EDGE); + ScriptError::RegisterErrorMap(STR_ERROR_STATION_TOO_SPREAD_OUT, ScriptError::ERR_STATION_TOO_SPREAD_OUT); + + ScriptError::RegisterErrorMapString(ScriptError::ERR_NONE, "ERR_NONE"); + ScriptError::RegisterErrorMapString(ScriptError::ERR_UNKNOWN, "ERR_UNKNOWN"); + ScriptError::RegisterErrorMapString(ScriptError::ERR_PRECONDITION_FAILED, "ERR_PRECONDITION_FAILED"); + ScriptError::RegisterErrorMapString(ScriptError::ERR_PRECONDITION_STRING_TOO_LONG, "ERR_PRECONDITION_STRING_TOO_LONG"); + ScriptError::RegisterErrorMapString(ScriptError::ERR_NEWGRF_SUPPLIED_ERROR, "ERR_NEWGRF_SUPPLIED_ERROR"); + ScriptError::RegisterErrorMapString(ScriptError::ERR_NOT_ENOUGH_CASH, "ERR_NOT_ENOUGH_CASH"); + ScriptError::RegisterErrorMapString(ScriptError::ERR_LOCAL_AUTHORITY_REFUSES, "ERR_LOCAL_AUTHORITY_REFUSES"); + ScriptError::RegisterErrorMapString(ScriptError::ERR_ALREADY_BUILT, "ERR_ALREADY_BUILT"); + ScriptError::RegisterErrorMapString(ScriptError::ERR_AREA_NOT_CLEAR, "ERR_AREA_NOT_CLEAR"); + ScriptError::RegisterErrorMapString(ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY, "ERR_OWNED_BY_ANOTHER_COMPANY"); + ScriptError::RegisterErrorMapString(ScriptError::ERR_NAME_IS_NOT_UNIQUE, "ERR_NAME_IS_NOT_UNIQUE"); + ScriptError::RegisterErrorMapString(ScriptError::ERR_FLAT_LAND_REQUIRED, "ERR_FLAT_LAND_REQUIRED"); + ScriptError::RegisterErrorMapString(ScriptError::ERR_LAND_SLOPED_WRONG, "ERR_LAND_SLOPED_WRONG"); + ScriptError::RegisterErrorMapString(ScriptError::ERR_VEHICLE_IN_THE_WAY, "ERR_VEHICLE_IN_THE_WAY"); + ScriptError::RegisterErrorMapString(ScriptError::ERR_SITE_UNSUITABLE, "ERR_SITE_UNSUITABLE"); + ScriptError::RegisterErrorMapString(ScriptError::ERR_TOO_CLOSE_TO_EDGE, "ERR_TOO_CLOSE_TO_EDGE"); + ScriptError::RegisterErrorMapString(ScriptError::ERR_STATION_TOO_SPREAD_OUT, "ERR_STATION_TOO_SPREAD_OUT"); + + SQGSError.DefSQStaticMethod(engine, &ScriptError::GetErrorCategory, "GetErrorCategory", 1, "."); + SQGSError.DefSQStaticMethod(engine, &ScriptError::GetLastError, "GetLastError", 1, "."); + SQGSError.DefSQStaticMethod(engine, &ScriptError::GetLastErrorString, "GetLastErrorString", 1, "."); + + SQGSError.PostRegister(engine); +} diff --git a/src/script/api/game/game_event.hpp.sq b/src/script/api/game/game_event.hpp.sq new file mode 100644 index 000000000..5f87970f6 --- /dev/null +++ b/src/script/api/game/game_event.hpp.sq @@ -0,0 +1,67 @@ +/* $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/>. + */ + +/* THIS FILE IS AUTO-GENERATED; PLEASE DO NOT ALTER MANUALLY */ + +#include "../script_event.hpp" +#include "../template/template_event.hpp.sq" + + +template <> const char *GetClassName<ScriptEvent, ST_GS>() { return "GSEvent"; } + +void SQGSEvent_Register(Squirrel *engine) +{ + DefSQClass<ScriptEvent, ST_GS> SQGSEvent("GSEvent"); + SQGSEvent.PreRegister(engine); + SQGSEvent.AddConstructor<void (ScriptEvent::*)(ScriptEvent::ScriptEventType type), 2>(engine, "xi"); + + SQGSEvent.DefSQConst(engine, ScriptEvent::ET_INVALID, "ET_INVALID"); + SQGSEvent.DefSQConst(engine, ScriptEvent::ET_TEST, "ET_TEST"); + SQGSEvent.DefSQConst(engine, ScriptEvent::ET_SUBSIDY_OFFER, "ET_SUBSIDY_OFFER"); + SQGSEvent.DefSQConst(engine, ScriptEvent::ET_SUBSIDY_OFFER_EXPIRED, "ET_SUBSIDY_OFFER_EXPIRED"); + SQGSEvent.DefSQConst(engine, ScriptEvent::ET_SUBSIDY_AWARDED, "ET_SUBSIDY_AWARDED"); + SQGSEvent.DefSQConst(engine, ScriptEvent::ET_SUBSIDY_EXPIRED, "ET_SUBSIDY_EXPIRED"); + SQGSEvent.DefSQConst(engine, ScriptEvent::ET_ENGINE_PREVIEW, "ET_ENGINE_PREVIEW"); + SQGSEvent.DefSQConst(engine, ScriptEvent::ET_COMPANY_NEW, "ET_COMPANY_NEW"); + SQGSEvent.DefSQConst(engine, ScriptEvent::ET_COMPANY_IN_TROUBLE, "ET_COMPANY_IN_TROUBLE"); + SQGSEvent.DefSQConst(engine, ScriptEvent::ET_COMPANY_ASK_MERGER, "ET_COMPANY_ASK_MERGER"); + SQGSEvent.DefSQConst(engine, ScriptEvent::ET_COMPANY_MERGER, "ET_COMPANY_MERGER"); + SQGSEvent.DefSQConst(engine, ScriptEvent::ET_COMPANY_BANKRUPT, "ET_COMPANY_BANKRUPT"); + SQGSEvent.DefSQConst(engine, ScriptEvent::ET_VEHICLE_CRASHED, "ET_VEHICLE_CRASHED"); + SQGSEvent.DefSQConst(engine, ScriptEvent::ET_VEHICLE_LOST, "ET_VEHICLE_LOST"); + SQGSEvent.DefSQConst(engine, ScriptEvent::ET_VEHICLE_WAITING_IN_DEPOT, "ET_VEHICLE_WAITING_IN_DEPOT"); + SQGSEvent.DefSQConst(engine, ScriptEvent::ET_VEHICLE_UNPROFITABLE, "ET_VEHICLE_UNPROFITABLE"); + SQGSEvent.DefSQConst(engine, ScriptEvent::ET_INDUSTRY_OPEN, "ET_INDUSTRY_OPEN"); + SQGSEvent.DefSQConst(engine, ScriptEvent::ET_INDUSTRY_CLOSE, "ET_INDUSTRY_CLOSE"); + SQGSEvent.DefSQConst(engine, ScriptEvent::ET_ENGINE_AVAILABLE, "ET_ENGINE_AVAILABLE"); + SQGSEvent.DefSQConst(engine, ScriptEvent::ET_STATION_FIRST_VEHICLE, "ET_STATION_FIRST_VEHICLE"); + SQGSEvent.DefSQConst(engine, ScriptEvent::ET_DISASTER_ZEPPELINER_CRASHED, "ET_DISASTER_ZEPPELINER_CRASHED"); + SQGSEvent.DefSQConst(engine, ScriptEvent::ET_DISASTER_ZEPPELINER_CLEARED, "ET_DISASTER_ZEPPELINER_CLEARED"); + SQGSEvent.DefSQConst(engine, ScriptEvent::ET_TOWN_FOUNDED, "ET_TOWN_FOUNDED"); + SQGSEvent.DefSQConst(engine, ScriptEvent::ET_AIRCRAFT_DEST_TOO_FAR, "ET_AIRCRAFT_DEST_TOO_FAR"); + + SQGSEvent.DefSQMethod(engine, &ScriptEvent::GetEventType, "GetEventType", 1, "x"); + + SQGSEvent.PostRegister(engine); +} + + +template <> const char *GetClassName<ScriptEventController, ST_GS>() { return "GSEventController"; } + +void SQGSEventController_Register(Squirrel *engine) +{ + DefSQClass<ScriptEventController, ST_GS> SQGSEventController("GSEventController"); + SQGSEventController.PreRegister(engine); + SQGSEventController.AddConstructor<void (ScriptEventController::*)(), 1>(engine, "x"); + + SQGSEventController.DefSQStaticMethod(engine, &ScriptEventController::IsEventWaiting, "IsEventWaiting", 1, "."); + SQGSEventController.DefSQStaticMethod(engine, &ScriptEventController::GetNextEvent, "GetNextEvent", 1, "."); + + SQGSEventController.PostRegister(engine); +} diff --git a/src/script/api/game/game_execmode.hpp.sq b/src/script/api/game/game_execmode.hpp.sq new file mode 100644 index 000000000..93d980312 --- /dev/null +++ b/src/script/api/game/game_execmode.hpp.sq @@ -0,0 +1,25 @@ +/* $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/>. + */ + +/* THIS FILE IS AUTO-GENERATED; PLEASE DO NOT ALTER MANUALLY */ + +#include "../script_execmode.hpp" +#include "../template/template_execmode.hpp.sq" + + +template <> const char *GetClassName<ScriptExecMode, ST_GS>() { return "GSExecMode"; } + +void SQGSExecMode_Register(Squirrel *engine) +{ + DefSQClass<ScriptExecMode, ST_GS> SQGSExecMode("GSExecMode"); + SQGSExecMode.PreRegister(engine); + SQGSExecMode.AddConstructor<void (ScriptExecMode::*)(), 1>(engine, "x"); + + SQGSExecMode.PostRegister(engine); +} diff --git a/src/script/api/game/game_list.hpp.sq b/src/script/api/game/game_list.hpp.sq new file mode 100644 index 000000000..03049b314 --- /dev/null +++ b/src/script/api/game/game_list.hpp.sq @@ -0,0 +1,63 @@ +/* $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/>. + */ + +/* THIS FILE IS AUTO-GENERATED; PLEASE DO NOT ALTER MANUALLY */ + +#include "../script_list.hpp" +#include "../template/template_list.hpp.sq" + + +template <> const char *GetClassName<ScriptList, ST_GS>() { return "GSList"; } + +void SQGSList_Register(Squirrel *engine) +{ + DefSQClass<ScriptList, ST_GS> SQGSList("GSList"); + SQGSList.PreRegister(engine); + SQGSList.AddConstructor<void (ScriptList::*)(), 1>(engine, "x"); + + SQGSList.DefSQConst(engine, ScriptList::SORT_BY_VALUE, "SORT_BY_VALUE"); + SQGSList.DefSQConst(engine, ScriptList::SORT_BY_ITEM, "SORT_BY_ITEM"); + + SQGSList.DefSQConst(engine, ScriptList::SORT_ASCENDING, "SORT_ASCENDING"); + SQGSList.DefSQConst(engine, ScriptList::SORT_DESCENDING, "SORT_DESCENDING"); + + SQGSList.DefSQMethod(engine, &ScriptList::AddItem, "AddItem", 3, "xii"); + SQGSList.DefSQMethod(engine, &ScriptList::RemoveItem, "RemoveItem", 2, "xi"); + SQGSList.DefSQMethod(engine, &ScriptList::Clear, "Clear", 1, "x"); + SQGSList.DefSQMethod(engine, &ScriptList::HasItem, "HasItem", 2, "xi"); + SQGSList.DefSQMethod(engine, &ScriptList::Begin, "Begin", 1, "x"); + SQGSList.DefSQMethod(engine, &ScriptList::Next, "Next", 1, "x"); + SQGSList.DefSQMethod(engine, &ScriptList::IsEmpty, "IsEmpty", 1, "x"); + SQGSList.DefSQMethod(engine, &ScriptList::IsEnd, "IsEnd", 1, "x"); + SQGSList.DefSQMethod(engine, &ScriptList::Count, "Count", 1, "x"); + SQGSList.DefSQMethod(engine, &ScriptList::GetValue, "GetValue", 2, "xi"); + SQGSList.DefSQMethod(engine, &ScriptList::SetValue, "SetValue", 3, "xii"); + SQGSList.DefSQMethod(engine, &ScriptList::Sort, "Sort", 3, "xib"); + SQGSList.DefSQMethod(engine, &ScriptList::AddList, "AddList", 2, "xx"); + SQGSList.DefSQMethod(engine, &ScriptList::RemoveAboveValue, "RemoveAboveValue", 2, "xi"); + SQGSList.DefSQMethod(engine, &ScriptList::RemoveBelowValue, "RemoveBelowValue", 2, "xi"); + SQGSList.DefSQMethod(engine, &ScriptList::RemoveBetweenValue, "RemoveBetweenValue", 3, "xii"); + SQGSList.DefSQMethod(engine, &ScriptList::RemoveValue, "RemoveValue", 2, "xi"); + SQGSList.DefSQMethod(engine, &ScriptList::RemoveTop, "RemoveTop", 2, "xi"); + SQGSList.DefSQMethod(engine, &ScriptList::RemoveBottom, "RemoveBottom", 2, "xi"); + SQGSList.DefSQMethod(engine, &ScriptList::RemoveList, "RemoveList", 2, "xx"); + SQGSList.DefSQMethod(engine, &ScriptList::KeepAboveValue, "KeepAboveValue", 2, "xi"); + SQGSList.DefSQMethod(engine, &ScriptList::KeepBelowValue, "KeepBelowValue", 2, "xi"); + SQGSList.DefSQMethod(engine, &ScriptList::KeepBetweenValue, "KeepBetweenValue", 3, "xii"); + SQGSList.DefSQMethod(engine, &ScriptList::KeepValue, "KeepValue", 2, "xi"); + SQGSList.DefSQMethod(engine, &ScriptList::KeepTop, "KeepTop", 2, "xi"); + SQGSList.DefSQMethod(engine, &ScriptList::KeepBottom, "KeepBottom", 2, "xi"); + SQGSList.DefSQMethod(engine, &ScriptList::KeepList, "KeepList", 2, "xx"); + SQGSList.DefSQAdvancedMethod(engine, &ScriptList::_get, "_get"); + SQGSList.DefSQAdvancedMethod(engine, &ScriptList::_set, "_set"); + SQGSList.DefSQAdvancedMethod(engine, &ScriptList::_nexti, "_nexti"); + SQGSList.DefSQAdvancedMethod(engine, &ScriptList::Valuate, "Valuate"); + + SQGSList.PostRegister(engine); +} diff --git a/src/script/api/game/game_log.hpp.sq b/src/script/api/game/game_log.hpp.sq new file mode 100644 index 000000000..1eb44d955 --- /dev/null +++ b/src/script/api/game/game_log.hpp.sq @@ -0,0 +1,29 @@ +/* $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/>. + */ + +/* THIS FILE IS AUTO-GENERATED; PLEASE DO NOT ALTER MANUALLY */ + +#include "../script_log.hpp" +#include "../template/template_log.hpp.sq" + + +template <> const char *GetClassName<ScriptLog, ST_GS>() { return "GSLog"; } + +void SQGSLog_Register(Squirrel *engine) +{ + DefSQClass<ScriptLog, ST_GS> SQGSLog("GSLog"); + SQGSLog.PreRegister(engine); + SQGSLog.AddConstructor<void (ScriptLog::*)(), 1>(engine, "x"); + + SQGSLog.DefSQStaticMethod(engine, &ScriptLog::Info, "Info", 2, ".."); + SQGSLog.DefSQStaticMethod(engine, &ScriptLog::Warning, "Warning", 2, ".."); + SQGSLog.DefSQStaticMethod(engine, &ScriptLog::Error, "Error", 2, ".."); + + SQGSLog.PostRegister(engine); +} diff --git a/src/script/api/game/game_testmode.hpp.sq b/src/script/api/game/game_testmode.hpp.sq new file mode 100644 index 000000000..6e1175f06 --- /dev/null +++ b/src/script/api/game/game_testmode.hpp.sq @@ -0,0 +1,25 @@ +/* $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/>. + */ + +/* THIS FILE IS AUTO-GENERATED; PLEASE DO NOT ALTER MANUALLY */ + +#include "../script_testmode.hpp" +#include "../template/template_testmode.hpp.sq" + + +template <> const char *GetClassName<ScriptTestMode, ST_GS>() { return "GSTestMode"; } + +void SQGSTestMode_Register(Squirrel *engine) +{ + DefSQClass<ScriptTestMode, ST_GS> SQGSTestMode("GSTestMode"); + SQGSTestMode.PreRegister(engine); + SQGSTestMode.AddConstructor<void (ScriptTestMode::*)(), 1>(engine, "x"); + + SQGSTestMode.PostRegister(engine); +} diff --git a/src/script/api/script_accounting.hpp b/src/script/api/script_accounting.hpp index f87d3749c..7477e09fe 100644 --- a/src/script/api/script_accounting.hpp +++ b/src/script/api/script_accounting.hpp @@ -17,7 +17,7 @@ /** * Class that keeps track of the costs, so you can request how much a block of * commands did cost in total. Works in both Execute as in Test mode. - * @api ai + * @api ai game * Example: * <pre> * { diff --git a/src/script/api/script_controller.hpp b/src/script/api/script_controller.hpp index ab8bf8893..03d8604ec 100644 --- a/src/script/api/script_controller.hpp +++ b/src/script/api/script_controller.hpp @@ -19,7 +19,7 @@ * The Controller, the class each Script should extend. It creates the Script, * makes sure the logic kicks in correctly, and that GetTick() has a valid * value. - * @api ai + * @api ai game */ class ScriptController { friend class AIScanner; diff --git a/src/script/api/script_error.hpp b/src/script/api/script_error.hpp index 53c084fad..6e167bd2d 100644 --- a/src/script/api/script_error.hpp +++ b/src/script/api/script_error.hpp @@ -40,7 +40,7 @@ /** * Class that handles all error related functions. - * @api ai + * @api ai game */ class ScriptError : public ScriptObject { public: diff --git a/src/script/api/script_event.hpp b/src/script/api/script_event.hpp index bfb49be78..ba8131eda 100644 --- a/src/script/api/script_event.hpp +++ b/src/script/api/script_event.hpp @@ -18,7 +18,7 @@ * Class that handles all event related functions. * You can lookup the type, and than convert it to the real event-class. * That way you can request more detailed information about the event. - * @api ai + * @api ai game */ class ScriptEvent : public ScriptObject { public: @@ -74,7 +74,7 @@ protected: /** * Class that handles all event related functions. - * @api ai + * @api ai game * @note it is not needed to create an instance of ScriptEvent to access it, as * all members are static, and all data is stored AI-wide. */ diff --git a/src/script/api/script_execmode.hpp b/src/script/api/script_execmode.hpp index 5fe5853af..2c64a7a01 100644 --- a/src/script/api/script_execmode.hpp +++ b/src/script/api/script_execmode.hpp @@ -20,7 +20,7 @@ * Execute. The original mode is stored and recovered from when ever the * instance is destroyed. * In Execute mode all commands you do are executed for real. - * @api ai + * @api ai game */ class ScriptExecMode : public ScriptObject { private: diff --git a/src/script/api/script_info_docs.hpp b/src/script/api/script_info_docs.hpp index 28f2b53f0..10d2f09f7 100644 --- a/src/script/api/script_info_docs.hpp +++ b/src/script/api/script_info_docs.hpp @@ -22,7 +22,7 @@ * the information here can be used for libraries, but the information * will not be shown in the GUI except for error/debug messages. * - * @api ai + * @api ai game */ class ScriptInfo { public: @@ -151,13 +151,12 @@ public: * and not the bugfix number as valid return for this function. * * Valid return values are: - * - "0.7" - * - "1.0" - * - "1.1" - * - "1.2" + * - "0.7" (for AI only) + * - "1.0" (for AI only) + * - "1.1" (for AI only) + * - "1.2" (for both AI and GS) * * @return The version this Script is compatible with. - * @note This function is optional. */ string GetAPIVersion(); diff --git a/src/script/api/script_list.hpp b/src/script/api/script_list.hpp index 42655e950..4e3d357d2 100644 --- a/src/script/api/script_list.hpp +++ b/src/script/api/script_list.hpp @@ -21,7 +21,7 @@ class ScriptListSorter; /** * Class that creates a list which can keep item/value pairs, which you can walk. - * @api ai + * @api ai game */ class ScriptList : public ScriptObject { public: diff --git a/src/script/api/script_log.hpp b/src/script/api/script_log.hpp index a3a1cd9bf..589310694 100644 --- a/src/script/api/script_log.hpp +++ b/src/script/api/script_log.hpp @@ -16,7 +16,7 @@ /** * Class that handles all log related functions. - * @api ai + * @api ai game */ class ScriptLog : public ScriptObject { /* ScriptController needs access to Enum and Log, in order to keep the flow from diff --git a/src/script/api/script_testmode.hpp b/src/script/api/script_testmode.hpp index a447ed814..161e490a3 100644 --- a/src/script/api/script_testmode.hpp +++ b/src/script/api/script_testmode.hpp @@ -22,7 +22,7 @@ * In Test mode all the commands you execute aren't really executed. The * system only checks if it would be able to execute your requests, and what * the cost would be. - * @api ai + * @api ai game */ class ScriptTestMode : public ScriptObject { private: diff --git a/src/script/api/squirrel_export.awk b/src/script/api/squirrel_export.awk index 8e4bc3546..b0b169576 100644 --- a/src/script/api/squirrel_export.awk +++ b/src/script/api/squirrel_export.awk @@ -95,11 +95,13 @@ BEGIN { has_fileheader = "false" cls_level = 0 RS = "\r|\n" + apis = tolower(api) + if (apis == "gs") apis = "game" } /@file/ { filename = $3 - gsub("^" tolower(api) "_", "script_", filename) + gsub("^" apis "_", "script_", filename) } # Ignore special doxygen blocks @@ -133,9 +135,9 @@ BEGIN { api_selected = "false" } else if ($0 == "-all") { api_selected = "false" - } else if (match($0, "-" tolower(api))) { + } else if (match($0, "-" apis)) { api_selected = "false" - } else if (match($0, tolower(api))) { + } else if (match($0, apis)) { api_selected = "true" } diff --git a/src/script/api/squirrel_export.sh b/src/script/api/squirrel_export.sh index c1182ce8f..fb8e5bb8b 100755 --- a/src/script/api/squirrel_export.sh +++ b/src/script/api/squirrel_export.sh @@ -39,6 +39,7 @@ fi case $apilc in template) apiuc="Template" ;; ai) apiuc="AI" ;; + game) apiuc="GS" ;; *) echo "Unknown API type."; exit 1 ;; esac diff --git a/src/script/squirrel.hpp b/src/script/squirrel.hpp index dbccd3c08..4e31d3247 100644 --- a/src/script/squirrel.hpp +++ b/src/script/squirrel.hpp @@ -16,7 +16,8 @@ /** The type of script we're working with, i.e. for who is it? */ enum ScriptType { - ST_AI, ///< The script is for the AI. + ST_AI, ///< The script is for AI scripts. + ST_GS, ///< The script is for Game scripts. }; class Squirrel { |