From 6ff81b908e8773c5ab94bc8a16c7d564270b0e75 Mon Sep 17 00:00:00 2001 From: Pavel Stupnikov Date: Sun, 22 Apr 2018 16:42:29 +0300 Subject: [PATCH] Feature #6459: API for querying network clients from GS (#6736) --- projects/openttd_vs100.vcxproj | 4 + projects/openttd_vs100.vcxproj.filters | 12 +++ projects/openttd_vs140.vcxproj | 4 + projects/openttd_vs140.vcxproj.filters | 12 +++ projects/openttd_vs141.vcxproj | 4 + projects/openttd_vs141.vcxproj.filters | 12 +++ projects/openttd_vs80.vcproj | 16 ++++ projects/openttd_vs90.vcproj | 16 ++++ source.list | 4 + src/game/game_instance.cpp | 5 ++ src/script/api/ai/ai_company.hpp.sq | 19 ++--- src/script/api/game/game_client.hpp.sq | 34 +++++++++ src/script/api/game/game_clientlist.hpp.sq | 37 ++++++++++ src/script/api/game/game_company.hpp.sq | 1 + src/script/api/game_changelog.hpp | 6 +- src/script/api/script_client.cpp | 74 +++++++++++++++++++ src/script/api/script_client.hpp | 70 ++++++++++++++++++ src/script/api/script_clientlist.cpp | 49 ++++++++++++ src/script/api/script_clientlist.hpp | 42 +++++++++++ src/script/api/script_company.hpp | 9 ++- .../api/template/template_client.hpp.sq | 25 +++++++ .../api/template/template_clientlist.hpp.sq | 30 ++++++++ 22 files changed, 471 insertions(+), 14 deletions(-) create mode 100644 src/script/api/game/game_client.hpp.sq create mode 100644 src/script/api/game/game_clientlist.hpp.sq create mode 100644 src/script/api/script_client.cpp create mode 100644 src/script/api/script_client.hpp create mode 100644 src/script/api/script_clientlist.cpp create mode 100644 src/script/api/script_clientlist.hpp create mode 100644 src/script/api/template/template_client.hpp.sq create mode 100644 src/script/api/template/template_clientlist.hpp.sq diff --git a/projects/openttd_vs100.vcxproj b/projects/openttd_vs100.vcxproj index 46af9b2ad0..5a0763e87f 100644 --- a/projects/openttd_vs100.vcxproj +++ b/projects/openttd_vs100.vcxproj @@ -1010,6 +1010,8 @@ + + @@ -1075,6 +1077,8 @@ + + diff --git a/projects/openttd_vs100.vcxproj.filters b/projects/openttd_vs100.vcxproj.filters index d727309e18..d502733796 100644 --- a/projects/openttd_vs100.vcxproj.filters +++ b/projects/openttd_vs100.vcxproj.filters @@ -2223,6 +2223,12 @@ Script API + + Script API + + + Script API + Script API @@ -2418,6 +2424,12 @@ Script API Implementation + + Script API Implementation + + + Script API Implementation + Script API Implementation diff --git a/projects/openttd_vs140.vcxproj b/projects/openttd_vs140.vcxproj index 09ffcbece2..aabd440b88 100644 --- a/projects/openttd_vs140.vcxproj +++ b/projects/openttd_vs140.vcxproj @@ -1031,6 +1031,8 @@ + + @@ -1096,6 +1098,8 @@ + + diff --git a/projects/openttd_vs140.vcxproj.filters b/projects/openttd_vs140.vcxproj.filters index d727309e18..d502733796 100644 --- a/projects/openttd_vs140.vcxproj.filters +++ b/projects/openttd_vs140.vcxproj.filters @@ -2223,6 +2223,12 @@ Script API + + Script API + + + Script API + Script API @@ -2418,6 +2424,12 @@ Script API Implementation + + Script API Implementation + + + Script API Implementation + Script API Implementation diff --git a/projects/openttd_vs141.vcxproj b/projects/openttd_vs141.vcxproj index d93132e0f6..d5362fe5bf 100644 --- a/projects/openttd_vs141.vcxproj +++ b/projects/openttd_vs141.vcxproj @@ -1031,6 +1031,8 @@ + + @@ -1096,6 +1098,8 @@ + + diff --git a/projects/openttd_vs141.vcxproj.filters b/projects/openttd_vs141.vcxproj.filters index d727309e18..d502733796 100644 --- a/projects/openttd_vs141.vcxproj.filters +++ b/projects/openttd_vs141.vcxproj.filters @@ -2223,6 +2223,12 @@ Script API + + Script API + + + Script API + Script API @@ -2418,6 +2424,12 @@ Script API Implementation + + Script API Implementation + + + Script API Implementation + Script API Implementation diff --git a/projects/openttd_vs80.vcproj b/projects/openttd_vs80.vcproj index 4c6fc837db..e0dea65973 100644 --- a/projects/openttd_vs80.vcproj +++ b/projects/openttd_vs80.vcproj @@ -3326,6 +3326,14 @@ RelativePath=".\..\src\script\api\script_cargomonitor.hpp" > + + + + @@ -3590,6 +3598,14 @@ RelativePath=".\..\src\script\api\script_cargomonitor.cpp" > + + + + diff --git a/projects/openttd_vs90.vcproj b/projects/openttd_vs90.vcproj index 9e01957be8..d2c103a8f9 100644 --- a/projects/openttd_vs90.vcproj +++ b/projects/openttd_vs90.vcproj @@ -3323,6 +3323,14 @@ RelativePath=".\..\src\script\api\script_cargomonitor.hpp" > + + + + @@ -3587,6 +3595,14 @@ RelativePath=".\..\src\script\api\script_cargomonitor.cpp" > + + + + diff --git a/source.list b/source.list index df35cdd26e..cd823aa6ff 100644 --- a/source.list +++ b/source.list @@ -782,6 +782,8 @@ script/api/script_bridgelist.hpp script/api/script_cargo.hpp script/api/script_cargolist.hpp script/api/script_cargomonitor.hpp +script/api/script_client.hpp +script/api/script_clientlist.hpp script/api/script_company.hpp script/api/script_companymode.hpp script/api/script_controller.hpp @@ -849,6 +851,8 @@ script/api/script_bridgelist.cpp script/api/script_cargo.cpp script/api/script_cargolist.cpp script/api/script_cargomonitor.cpp +script/api/script_client.cpp +script/api/script_clientlist.cpp script/api/script_company.cpp script/api/script_companymode.cpp script/api/script_controller.cpp diff --git a/src/game/game_instance.cpp b/src/game/game_instance.cpp index c5e5c7f05a..e2b3775110 100644 --- a/src/game/game_instance.cpp +++ b/src/game/game_instance.cpp @@ -34,6 +34,8 @@ #include "../script/api/game/game_cargo.hpp.sq" #include "../script/api/game/game_cargolist.hpp.sq" #include "../script/api/game/game_cargomonitor.hpp.sq" +#include "../script/api/game/game_client.hpp.sq" +#include "../script/api/game/game_clientlist.hpp.sq" #include "../script/api/game/game_company.hpp.sq" #include "../script/api/game/game_companymode.hpp.sq" #include "../script/api/game/game_controller.hpp.sq" @@ -122,6 +124,9 @@ void GameInstance::RegisterAPI() SQGSCargoList_IndustryProducing_Register(this->engine); SQGSCargoList_StationAccepting_Register(this->engine); SQGSCargoMonitor_Register(this->engine); + SQGSClient_Register(this->engine); + SQGSClientList_Register(this->engine); + SQGSClientList_Company_Register(this->engine); SQGSCompany_Register(this->engine); SQGSCompanyMode_Register(this->engine); SQGSDate_Register(this->engine); diff --git a/src/script/api/ai/ai_company.hpp.sq b/src/script/api/ai/ai_company.hpp.sq index 76cc18e3a5..7ed55d97b6 100644 --- a/src/script/api/ai/ai_company.hpp.sq +++ b/src/script/api/ai/ai_company.hpp.sq @@ -21,15 +21,16 @@ void SQAICompany_Register(Squirrel *engine) SQAICompany.PreRegister(engine); SQAICompany.AddConstructor(engine, "x"); - SQAICompany.DefSQConst(engine, ScriptCompany::CURRENT_QUARTER, "CURRENT_QUARTER"); - SQAICompany.DefSQConst(engine, ScriptCompany::EARLIEST_QUARTER, "EARLIEST_QUARTER"); - SQAICompany.DefSQConst(engine, ScriptCompany::COMPANY_FIRST, "COMPANY_FIRST"); - SQAICompany.DefSQConst(engine, ScriptCompany::COMPANY_LAST, "COMPANY_LAST"); - SQAICompany.DefSQConst(engine, ScriptCompany::COMPANY_INVALID, "COMPANY_INVALID"); - SQAICompany.DefSQConst(engine, ScriptCompany::COMPANY_SELF, "COMPANY_SELF"); - SQAICompany.DefSQConst(engine, ScriptCompany::GENDER_MALE, "GENDER_MALE"); - SQAICompany.DefSQConst(engine, ScriptCompany::GENDER_FEMALE, "GENDER_FEMALE"); - SQAICompany.DefSQConst(engine, ScriptCompany::GENDER_INVALID, "GENDER_INVALID"); + SQAICompany.DefSQConst(engine, ScriptCompany::CURRENT_QUARTER, "CURRENT_QUARTER"); + SQAICompany.DefSQConst(engine, ScriptCompany::EARLIEST_QUARTER, "EARLIEST_QUARTER"); + SQAICompany.DefSQConst(engine, ScriptCompany::COMPANY_FIRST, "COMPANY_FIRST"); + SQAICompany.DefSQConst(engine, ScriptCompany::COMPANY_LAST, "COMPANY_LAST"); + SQAICompany.DefSQConst(engine, ScriptCompany::COMPANY_INVALID, "COMPANY_INVALID"); + SQAICompany.DefSQConst(engine, ScriptCompany::COMPANY_SELF, "COMPANY_SELF"); + SQAICompany.DefSQConst(engine, ScriptCompany::COMPANY_SPECTATOR, "COMPANY_SPECTATOR"); + SQAICompany.DefSQConst(engine, ScriptCompany::GENDER_MALE, "GENDER_MALE"); + SQAICompany.DefSQConst(engine, ScriptCompany::GENDER_FEMALE, "GENDER_FEMALE"); + SQAICompany.DefSQConst(engine, ScriptCompany::GENDER_INVALID, "GENDER_INVALID"); SQAICompany.DefSQStaticMethod(engine, &ScriptCompany::ResolveCompanyID, "ResolveCompanyID", 2, ".i"); SQAICompany.DefSQStaticMethod(engine, &ScriptCompany::IsMine, "IsMine", 2, ".i"); diff --git a/src/script/api/game/game_client.hpp.sq b/src/script/api/game/game_client.hpp.sq new file mode 100644 index 0000000000..b4230a6d05 --- /dev/null +++ b/src/script/api/game/game_client.hpp.sq @@ -0,0 +1,34 @@ +/* $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 . + */ + +/* THIS FILE IS AUTO-GENERATED; PLEASE DO NOT ALTER MANUALLY */ + +#include "../script_client.hpp" +#include "../template/template_client.hpp.sq" + + +template <> const char *GetClassName() { return "GSClient"; } + +void SQGSClient_Register(Squirrel *engine) +{ + DefSQClass SQGSClient("GSClient"); + SQGSClient.PreRegister(engine); + SQGSClient.AddConstructor(engine, "x"); + + SQGSClient.DefSQConst(engine, ScriptClient::CLIENT_INVALID, "CLIENT_INVALID"); + SQGSClient.DefSQConst(engine, ScriptClient::CLIENT_SERVER, "CLIENT_SERVER"); + SQGSClient.DefSQConst(engine, ScriptClient::CLIENT_FIRST, "CLIENT_FIRST"); + + SQGSClient.DefSQStaticMethod(engine, &ScriptClient::ResolveClientID, "ResolveClientID", 2, ".i"); + SQGSClient.DefSQStaticMethod(engine, &ScriptClient::GetName, "GetName", 2, ".i"); + SQGSClient.DefSQStaticMethod(engine, &ScriptClient::GetCompany, "GetCompany", 2, ".i"); + SQGSClient.DefSQStaticMethod(engine, &ScriptClient::GetJoinDate, "GetJoinDate", 2, ".i"); + + SQGSClient.PostRegister(engine); +} diff --git a/src/script/api/game/game_clientlist.hpp.sq b/src/script/api/game/game_clientlist.hpp.sq new file mode 100644 index 0000000000..ef02586474 --- /dev/null +++ b/src/script/api/game/game_clientlist.hpp.sq @@ -0,0 +1,37 @@ +/* $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 . + */ + +/* THIS FILE IS AUTO-GENERATED; PLEASE DO NOT ALTER MANUALLY */ + +#include "../script_clientlist.hpp" +#include "../template/template_clientlist.hpp.sq" + + +template <> const char *GetClassName() { return "GSClientList"; } + +void SQGSClientList_Register(Squirrel *engine) +{ + DefSQClass SQGSClientList("GSClientList"); + SQGSClientList.PreRegister(engine, "GSList"); + SQGSClientList.AddConstructor(engine, "x"); + + SQGSClientList.PostRegister(engine); +} + + +template <> const char *GetClassName() { return "GSClientList_Company"; } + +void SQGSClientList_Company_Register(Squirrel *engine) +{ + DefSQClass SQGSClientList_Company("GSClientList_Company"); + SQGSClientList_Company.PreRegister(engine, "GSList"); + SQGSClientList_Company.AddConstructor(engine, "xi"); + + SQGSClientList_Company.PostRegister(engine); +} diff --git a/src/script/api/game/game_company.hpp.sq b/src/script/api/game/game_company.hpp.sq index 56917a5b21..29476fc8aa 100644 --- a/src/script/api/game/game_company.hpp.sq +++ b/src/script/api/game/game_company.hpp.sq @@ -27,6 +27,7 @@ void SQGSCompany_Register(Squirrel *engine) SQGSCompany.DefSQConst(engine, ScriptCompany::COMPANY_LAST, "COMPANY_LAST"); SQGSCompany.DefSQConst(engine, ScriptCompany::COMPANY_INVALID, "COMPANY_INVALID"); SQGSCompany.DefSQConst(engine, ScriptCompany::COMPANY_SELF, "COMPANY_SELF"); + SQGSCompany.DefSQConst(engine, ScriptCompany::COMPANY_SPECTATOR, "COMPANY_SPECTATOR"); SQGSCompany.DefSQConst(engine, ScriptCompany::GENDER_MALE, "GENDER_MALE"); SQGSCompany.DefSQConst(engine, ScriptCompany::GENDER_FEMALE, "GENDER_FEMALE"); SQGSCompany.DefSQConst(engine, ScriptCompany::GENDER_INVALID, "GENDER_INVALID"); diff --git a/src/script/api/game_changelog.hpp b/src/script/api/game_changelog.hpp index d6d62057a1..776dd892ef 100644 --- a/src/script/api/game_changelog.hpp +++ b/src/script/api/game_changelog.hpp @@ -18,10 +18,14 @@ * \b 1.9.0 * * 1.9.0 is not yet released. The following changes are not set in stone yet. + * API additions: + * \li GSClient + * \li GSClientList + * \li GSClientList_Company * * \b 1.8.0 * - * 1.8.0 is not yet released. The following changes are not set in stone yet. + * No changes * * \b 1.7.0 - 1.7.2 * diff --git a/src/script/api/script_client.cpp b/src/script/api/script_client.cpp new file mode 100644 index 0000000000..771a0ae4ec --- /dev/null +++ b/src/script/api/script_client.cpp @@ -0,0 +1,74 @@ +/* $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 . + */ + +/** @file script_client.cpp Implementation of ScriptClient. */ + +#include "../../stdafx.h" +#include "script_client.hpp" +#include "../../network/network.h" +#include "../../network/network_base.h" + +#include "../../safeguards.h" + +#ifdef ENABLE_NETWORK +/** + * Finds NetworkClientInfo given client-identifier, + * is used by other methods to resolve client-identifier. + * @param client The client to get info structure for + * @return A pointer to corresponding CI struct or NULL when not found. + */ +static NetworkClientInfo *FindClientInfo(ScriptClient::ClientID client) +{ + if (client == ScriptClient::CLIENT_INVALID) return NULL; + if (!_networking) return NULL; + return NetworkClientInfo::GetByClientID((::ClientID)client); +} +#endif + +/* static */ ScriptClient::ClientID ScriptClient::ResolveClientID(ScriptClient::ClientID client) +{ +#ifdef ENABLE_NETWORK + return (FindClientInfo(client) == NULL ? ScriptClient::CLIENT_INVALID : client); +#else + return CLIENT_INVALID; +#endif +} + +/* static */ char *ScriptClient::GetName(ScriptClient::ClientID client) +{ +#ifdef ENABLE_NETWORK + NetworkClientInfo *ci = FindClientInfo(client); + if (ci == NULL) return NULL; + return stredup(ci->client_name); +#else + return NULL; +#endif +} + +/* static */ ScriptCompany::CompanyID ScriptClient::GetCompany(ScriptClient::ClientID client) +{ +#ifdef ENABLE_NETWORK + NetworkClientInfo *ci = FindClientInfo(client); + if (ci == NULL) return ScriptCompany::COMPANY_INVALID; + return (ScriptCompany::CompanyID)ci->client_playas; +#else + return ScriptCompany::COMPANY_INVALID; +#endif +} + +/* static */ ScriptDate::Date ScriptClient::GetJoinDate(ScriptClient::ClientID client) +{ +#ifdef ENABLE_NETWORK + NetworkClientInfo *ci = FindClientInfo(client); + if (ci == NULL) return ScriptDate::DATE_INVALID; + return (ScriptDate::Date)ci->join_date; +#else + return ScriptDate::DATE_INVALID; +#endif +} diff --git a/src/script/api/script_client.hpp b/src/script/api/script_client.hpp new file mode 100644 index 0000000000..423f134c07 --- /dev/null +++ b/src/script/api/script_client.hpp @@ -0,0 +1,70 @@ +/* $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 . + */ + +/** @file script_client.hpp Everything to query a network client's information */ + +#ifndef SCRIPT_CLIENT_HPP +#define SCRIPT_CLIENT_HPP + +#include "script_text.hpp" +#include "script_date.hpp" +#include "script_company.hpp" +#include "../../network/network_type.h" + +/** + * Class that handles all client related functions. + * + * @api game + */ +class ScriptClient : public ScriptObject { +public: + + /** Different constants related to ClientID. */ + enum ClientID { + CLIENT_INVALID = 0, ///< Client is not part of anything + CLIENT_SERVER = 1, ///< Servers always have this ID + CLIENT_FIRST = 2, ///< The first client ID + }; + + /** + * Resolves the given client id to the correct index for the client. + * If the client with the given id does not exist it will + * return CLIENT_INVALID. + * @param client The client id to resolve. + * @return The resolved client id. + */ + static ClientID ResolveClientID(ClientID client); + + /** + * Get the name of the given client. + * @param client The client to get the name for. + * @pre ResolveClientID(client) != CLIENT_INVALID. + * @return The name of the given client. + */ + static char *GetName(ClientID client); + + /** + * Get the company in which the given client is playing. + * @param client The client to get company for. + * @pre ResolveClientID(client) != CLIENT_INVALID. + * @return The company in which client is playing or COMPANY_SPECTATOR. + */ + static ScriptCompany::CompanyID GetCompany(ClientID client); + + /** + * Get the game date when the given client has joined. + * @param client The client to get joining date for. + * @pre ResolveClientID(client) != CLIENT_INVALID. + * @return The date when client has joined. + */ + static ScriptDate::Date GetJoinDate(ClientID client); +}; + + +#endif /* SCRIPT_CLIENT_HPP */ diff --git a/src/script/api/script_clientlist.cpp b/src/script/api/script_clientlist.cpp new file mode 100644 index 0000000000..2f7a19a9ff --- /dev/null +++ b/src/script/api/script_clientlist.cpp @@ -0,0 +1,49 @@ +/* $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 . + */ + +/** @file script_clientlist.cpp Implementation of ScriptClientList and friends. */ + +#include "../../stdafx.h" +#include "script_company.hpp" +#include "script_clientlist.hpp" +#include "../../network/network.h" +#include "../../network/network_base.h" + +#include "../../safeguards.h" + +ScriptClientList::ScriptClientList() +{ +#ifdef ENABLE_NETWORK + if (!_networking) return; + NetworkClientInfo *ci; + FOR_ALL_CLIENT_INFOS(ci) { + this->AddItem(ci->client_id); + } +#endif +} + +ScriptClientList_Company::ScriptClientList_Company(ScriptCompany::CompanyID company) +{ +#ifdef ENABLE_NETWORK + if (!_networking) return; + CompanyID c; + if (company == ScriptCompany::COMPANY_SPECTATOR) { + c = ::COMPANY_SPECTATOR; + } else { + company = ScriptCompany::ResolveCompanyID(company); + if (company == ScriptCompany::COMPANY_INVALID) return; + c = (CompanyID)company; + } + + NetworkClientInfo *ci; + FOR_ALL_CLIENT_INFOS(ci) { + if (ci->client_playas == c) this->AddItem(ci->client_id); + } +#endif +} diff --git a/src/script/api/script_clientlist.hpp b/src/script/api/script_clientlist.hpp new file mode 100644 index 0000000000..58d0177b21 --- /dev/null +++ b/src/script/api/script_clientlist.hpp @@ -0,0 +1,42 @@ +/* $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 . + */ + +/** @file script_clientlist.hpp List all the TODO. */ + +#ifndef SCRIPT_CLIENTLIST_HPP +#define SCRIPT_CLIENTLIST_HPP + +#include "script_list.hpp" +#include "script_company.hpp" + + +/** + * Creates a list of clients that are currently in game. + * @api game + * @ingroup ScriptList + */ +class ScriptClientList : public ScriptList { +public: + ScriptClientList(); +}; + +/** + * Creates a list of clients that are playing in the company. + * @api game + * @ingroup ScriptList + */ +class ScriptClientList_Company : public ScriptList { +public: + /** + * @param company_id The company to list clients for. + */ + ScriptClientList_Company(ScriptCompany::CompanyID company); +}; + +#endif /* SCRIPT_CIENTLIST_HPP */ diff --git a/src/script/api/script_company.hpp b/src/script/api/script_company.hpp index 4deaeed5e3..4bfe0d02e6 100644 --- a/src/script/api/script_company.hpp +++ b/src/script/api/script_company.hpp @@ -30,12 +30,13 @@ public: /** Different constants related to CompanyID. */ enum CompanyID { /* Note: these values represent part of the in-game Owner enum */ - COMPANY_FIRST = ::COMPANY_FIRST, ///< The first available company. - COMPANY_LAST = ::MAX_COMPANIES, ///< The last available company. + COMPANY_FIRST = ::COMPANY_FIRST, ///< The first available company. + COMPANY_LAST = ::MAX_COMPANIES, ///< The last available company. /* Custom added value, only valid for this API */ - COMPANY_INVALID = -1, ///< An invalid company. - COMPANY_SELF = 254, ///< Constant that gets resolved to the correct company index for your company. + COMPANY_INVALID = -1, ///< An invalid company. + COMPANY_SELF = 254, ///< Constant that gets resolved to the correct company index for your company. + COMPANY_SPECTATOR = 255, ///< Constant indicating that player is spectating (gets resolved to COMPANY_INVALID) }; /** Possible genders for company presidents. */ diff --git a/src/script/api/template/template_client.hpp.sq b/src/script/api/template/template_client.hpp.sq new file mode 100644 index 0000000000..13b9d68b6a --- /dev/null +++ b/src/script/api/template/template_client.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 . + */ + +/* THIS FILE IS AUTO-GENERATED; PLEASE DO NOT ALTER MANUALLY */ + +#include "../script_client.hpp" + +namespace SQConvert { + /* Allow enums to be used as Squirrel parameters */ + template <> inline ScriptClient::ClientID GetParam(ForceType, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (ScriptClient::ClientID)tmp; } + template <> inline int Return(HSQUIRRELVM vm, ScriptClient::ClientID res) { sq_pushinteger(vm, (int32)res); return 1; } + + /* Allow ScriptClient to be used as Squirrel parameter */ + template <> inline ScriptClient *GetParam(ForceType, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptClient *)instance; } + template <> inline ScriptClient &GetParam(ForceType, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(ScriptClient *)instance; } + template <> inline const ScriptClient *GetParam(ForceType, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptClient *)instance; } + template <> inline const ScriptClient &GetParam(ForceType, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(ScriptClient *)instance; } + template <> inline int Return(HSQUIRRELVM vm, ScriptClient *res) { if (res == NULL) { sq_pushnull(vm); return 1; } res->AddRef(); Squirrel::CreateClassInstanceVM(vm, "Client", res, NULL, DefSQDestructorCallback, true); return 1; } +} // namespace SQConvert diff --git a/src/script/api/template/template_clientlist.hpp.sq b/src/script/api/template/template_clientlist.hpp.sq new file mode 100644 index 0000000000..74c3f4525f --- /dev/null +++ b/src/script/api/template/template_clientlist.hpp.sq @@ -0,0 +1,30 @@ +/* $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 . + */ + +/* THIS FILE IS AUTO-GENERATED; PLEASE DO NOT ALTER MANUALLY */ + +#include "../script_clientlist.hpp" + +namespace SQConvert { + /* Allow ScriptClientList to be used as Squirrel parameter */ + template <> inline ScriptClientList *GetParam(ForceType, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptClientList *)instance; } + template <> inline ScriptClientList &GetParam(ForceType, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(ScriptClientList *)instance; } + template <> inline const ScriptClientList *GetParam(ForceType, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptClientList *)instance; } + template <> inline const ScriptClientList &GetParam(ForceType, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(ScriptClientList *)instance; } + template <> inline int Return(HSQUIRRELVM vm, ScriptClientList *res) { if (res == NULL) { sq_pushnull(vm); return 1; } res->AddRef(); Squirrel::CreateClassInstanceVM(vm, "ClientList", res, NULL, DefSQDestructorCallback, true); return 1; } +} // namespace SQConvert + +namespace SQConvert { + /* Allow ScriptClientList_Company to be used as Squirrel parameter */ + template <> inline ScriptClientList_Company *GetParam(ForceType, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptClientList_Company *)instance; } + template <> inline ScriptClientList_Company &GetParam(ForceType, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(ScriptClientList_Company *)instance; } + template <> inline const ScriptClientList_Company *GetParam(ForceType, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptClientList_Company *)instance; } + template <> inline const ScriptClientList_Company &GetParam(ForceType, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(ScriptClientList_Company *)instance; } + template <> inline int Return(HSQUIRRELVM vm, ScriptClientList_Company *res) { if (res == NULL) { sq_pushnull(vm); return 1; } res->AddRef(); Squirrel::CreateClassInstanceVM(vm, "ClientList_Company", res, NULL, DefSQDestructorCallback, true); return 1; } +} // namespace SQConvert