diff -r 998f151fb7ce source.list --- a/source.list Mon May 02 02:31:20 2016 +0300 +++ b/source.list Thu May 05 00:21:40 2016 +0300 @@ -795,6 +795,8 @@ 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 @@ -862,6 +864,8 @@ 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 -r 998f151fb7ce src/game/game_instance.cpp --- a/src/game/game_instance.cpp Mon May 02 02:31:20 2016 +0300 +++ b/src/game/game_instance.cpp Thu May 05 00:21:40 2016 +0300 @@ -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 @@ 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 -r 998f151fb7ce src/script/api/ai/ai_company.hpp.sq --- a/src/script/api/ai/ai_company.hpp.sq Mon May 02 02:31:20 2016 +0300 +++ b/src/script/api/ai/ai_company.hpp.sq Thu May 05 00:21:40 2016 +0300 @@ -1,4 +1,4 @@ -/* $Id: ai_company.hpp.sq 23521 2011-12-15 18:40:15Z rubidium $ */ +/* $Id$ */ /* * This file is part of OpenTTD. @@ -21,15 +21,16 @@ 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 -r 998f151fb7ce src/script/api/ai/ai_execmode.hpp.sq --- a/src/script/api/ai/ai_execmode.hpp.sq Mon May 02 02:31:20 2016 +0300 +++ b/src/script/api/ai/ai_execmode.hpp.sq Thu May 05 00:21:40 2016 +0300 @@ -1,4 +1,4 @@ -/* $Id: ai_execmode.hpp.sq 23379 2011-11-30 14:11:02Z truebrain $ */ +/* $Id$ */ /* * This file is part of OpenTTD. @@ -19,7 +19,6 @@ { DefSQClass SQAIExecMode("AIExecMode"); SQAIExecMode.PreRegister(engine); - SQAIExecMode.AddConstructor(engine, "x"); SQAIExecMode.PostRegister(engine); } diff -r 998f151fb7ce src/script/api/ai/ai_testmode.hpp.sq --- a/src/script/api/ai/ai_testmode.hpp.sq Mon May 02 02:31:20 2016 +0300 +++ b/src/script/api/ai/ai_testmode.hpp.sq Thu May 05 00:21:40 2016 +0300 @@ -1,4 +1,4 @@ -/* $Id: ai_testmode.hpp.sq 23379 2011-11-30 14:11:02Z truebrain $ */ +/* $Id$ */ /* * This file is part of OpenTTD. @@ -19,7 +19,6 @@ { DefSQClass SQAITestMode("AITestMode"); SQAITestMode.PreRegister(engine); - SQAITestMode.AddConstructor(engine, "x"); SQAITestMode.PostRegister(engine); } diff -r 998f151fb7ce src/script/api/game/game_client.hpp.sq --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/script/api/game/game_client.hpp.sq Thu May 05 00:21:40 2016 +0300 @@ -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::GetJoinedDate, "GetJoinedDate", 2, ".i"); + + SQGSClient.PostRegister(engine); +} diff -r 998f151fb7ce src/script/api/game/game_clientlist.hpp.sq --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/script/api/game/game_clientlist.hpp.sq Thu May 05 00:21:40 2016 +0300 @@ -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 -r 998f151fb7ce src/script/api/game/game_company.hpp.sq --- a/src/script/api/game/game_company.hpp.sq Mon May 02 02:31:20 2016 +0300 +++ b/src/script/api/game/game_company.hpp.sq Thu May 05 00:21:40 2016 +0300 @@ -1,4 +1,4 @@ -/* $Id: game_company.hpp.sq 25808 2013-10-02 21:44:31Z zuu $ */ +/* $Id$ */ /* * This file is part of OpenTTD. @@ -27,6 +27,7 @@ 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 -r 998f151fb7ce src/script/api/game/game_execmode.hpp.sq --- a/src/script/api/game/game_execmode.hpp.sq Mon May 02 02:31:20 2016 +0300 +++ b/src/script/api/game/game_execmode.hpp.sq Thu May 05 00:21:40 2016 +0300 @@ -1,4 +1,4 @@ -/* $Id: game_execmode.hpp.sq 23737 2012-01-03 20:37:56Z truebrain $ */ +/* $Id$ */ /* * This file is part of OpenTTD. @@ -19,7 +19,6 @@ { DefSQClass SQGSExecMode("GSExecMode"); SQGSExecMode.PreRegister(engine); - SQGSExecMode.AddConstructor(engine, "x"); SQGSExecMode.PostRegister(engine); } diff -r 998f151fb7ce src/script/api/game/game_testmode.hpp.sq --- a/src/script/api/game/game_testmode.hpp.sq Mon May 02 02:31:20 2016 +0300 +++ b/src/script/api/game/game_testmode.hpp.sq Thu May 05 00:21:40 2016 +0300 @@ -1,4 +1,4 @@ -/* $Id: game_testmode.hpp.sq 23737 2012-01-03 20:37:56Z truebrain $ */ +/* $Id$ */ /* * This file is part of OpenTTD. @@ -19,7 +19,6 @@ { DefSQClass SQGSTestMode("GSTestMode"); SQGSTestMode.PreRegister(engine); - SQGSTestMode.AddConstructor(engine, "x"); SQGSTestMode.PostRegister(engine); } diff -r 998f151fb7ce src/script/api/script_client.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/script/api/script_client.cpp Thu May 05 00:21:40 2016 +0300 @@ -0,0 +1,53 @@ +/* $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" + +/* static */ NetworkClientInfo *ScriptClient::FindClientInfo(ScriptClient::ClientID client) +{ + if (client == CLIENT_INVALID) return NULL; + if (!_networking) return NULL; + return NetworkClientInfo::GetByClientID((::ClientID)client); +} + +/* static */ ScriptClient::ClientID ScriptClient::ResolveClientID(ScriptClient::ClientID client) +{ + return (FindClientInfo(client) == NULL ? client : CLIENT_INVALID); +} + +/* static */ char *ScriptClient::GetName(ScriptClient::ClientID client) +{ + NetworkClientInfo *ci = FindClientInfo(client); + if (ci == NULL) return NULL; + + return stredup(ci->client_name); +} + +/* static */ ScriptCompany::CompanyID ScriptClient::GetCompany(ScriptClient::ClientID client) +{ + NetworkClientInfo *ci = FindClientInfo(client); + if (ci == NULL) return ScriptCompany::COMPANY_INVALID; + + return (ScriptCompany::CompanyID)ci->client_playas; +} + +/* static */ ScriptDate::Date ScriptClient::GetJoinedDate(ScriptClient::ClientID client) +{ + NetworkClientInfo *ci = FindClientInfo(client); + if (ci == NULL) return ScriptDate::DATE_INVALID; + + return (ScriptDate::Date)ci->join_date; +} diff -r 998f151fb7ce src/script/api/script_client.hpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/script/api/script_client.hpp Thu May 05 00:21:40 2016 +0300 @@ -0,0 +1,79 @@ +/* $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, ///< c1 + CLIENT_SERVER = 1, ///< c2 + CLIENT_FIRST = 2, ///< c3 + }; + + /** + * Resolved 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 as which the given client is playing. + * @param client The client to get company for. + * @pre ResolveClientID(client) != CLIENT_INVALID. + * @return The company as which client is playing. + */ + 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 company as which client is playing. + */ + static ScriptDate::Date GetJoinedDate(ClientID client); + +protected: + /** + * 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(ClientID client); +}; + + +#endif /* SCRIPT_CLIENT_HPP */ diff -r 998f151fb7ce src/script/api/script_clientlist.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/script/api/script_clientlist.cpp Thu May 05 00:21:40 2016 +0300 @@ -0,0 +1,38 @@ +/* $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_clientlist.hpp" +#include "../../network/network.h" +#include "../../network/network_base.h" + +#include "../../safeguards.h" + +ScriptClientList::ScriptClientList() +{ + if (!_networking) return; + NetworkClientInfo *ci; + FOR_ALL_CLIENT_INFOS(ci) { + this->AddItem(ci->client_id); + } +} + +ScriptClientList_Company::ScriptClientList_Company(ScriptCompany::CompanyID company) +{ + if (!_networking) return; + CompanyID c = (CompanyID)company; + if (company == ScriptCompany::COMPANY_INVALID) c = INVALID_COMPANY; + + NetworkClientInfo *ci; + FOR_ALL_CLIENT_INFOS(ci) { + if (ci->client_playas == c) this->AddItem(ci->client_id); + } +} diff -r 998f151fb7ce src/script/api/script_clientlist.hpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/script/api/script_clientlist.hpp Thu May 05 00:21:40 2016 +0300 @@ -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 -r 998f151fb7ce src/script/api/script_company.hpp --- a/src/script/api/script_company.hpp Mon May 02 02:31:20 2016 +0300 +++ b/src/script/api/script_company.hpp Thu May 05 00:21:40 2016 +0300 @@ -30,12 +30,13 @@ /** 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. */