Feature #6459: API for querying network clients from GS (#6736)

This commit is contained in:
Pavel Stupnikov 2018-04-22 16:42:29 +03:00 committed by Patric Stout
parent e0ae67cefa
commit 6ff81b908e
22 changed files with 471 additions and 14 deletions

View File

@ -1010,6 +1010,8 @@
<ClInclude Include="..\src\script\api\script_cargo.hpp" />
<ClInclude Include="..\src\script\api\script_cargolist.hpp" />
<ClInclude Include="..\src\script\api\script_cargomonitor.hpp" />
<ClInclude Include="..\src\script\api\script_client.hpp" />
<ClInclude Include="..\src\script\api\script_clientlist.hpp" />
<ClInclude Include="..\src\script\api\script_company.hpp" />
<ClInclude Include="..\src\script\api\script_companymode.hpp" />
<ClInclude Include="..\src\script\api\script_controller.hpp" />
@ -1075,6 +1077,8 @@
<ClCompile Include="..\src\script\api\script_cargo.cpp" />
<ClCompile Include="..\src\script\api\script_cargolist.cpp" />
<ClCompile Include="..\src\script\api\script_cargomonitor.cpp" />
<ClCompile Include="..\src\script\api\script_client.cpp" />
<ClCompile Include="..\src\script\api\script_clientlist.cpp" />
<ClCompile Include="..\src\script\api\script_company.cpp" />
<ClCompile Include="..\src\script\api\script_companymode.cpp" />
<ClCompile Include="..\src\script\api\script_controller.cpp" />

View File

@ -2223,6 +2223,12 @@
<ClInclude Include="..\src\script\api\script_cargomonitor.hpp">
<Filter>Script API</Filter>
</ClInclude>
<ClInclude Include="..\src\script\api\script_client.hpp">
<Filter>Script API</Filter>
</ClInclude>
<ClInclude Include="..\src\script\api\script_clientlist.hpp">
<Filter>Script API</Filter>
</ClInclude>
<ClInclude Include="..\src\script\api\script_company.hpp">
<Filter>Script API</Filter>
</ClInclude>
@ -2418,6 +2424,12 @@
<ClCompile Include="..\src\script\api\script_cargomonitor.cpp">
<Filter>Script API Implementation</Filter>
</ClCompile>
<ClCompile Include="..\src\script\api\script_client.cpp">
<Filter>Script API Implementation</Filter>
</ClCompile>
<ClCompile Include="..\src\script\api\script_clientlist.cpp">
<Filter>Script API Implementation</Filter>
</ClCompile>
<ClCompile Include="..\src\script\api\script_company.cpp">
<Filter>Script API Implementation</Filter>
</ClCompile>

View File

@ -1031,6 +1031,8 @@
<ClInclude Include="..\src\script\api\script_cargo.hpp" />
<ClInclude Include="..\src\script\api\script_cargolist.hpp" />
<ClInclude Include="..\src\script\api\script_cargomonitor.hpp" />
<ClInclude Include="..\src\script\api\script_client.hpp" />
<ClInclude Include="..\src\script\api\script_clientlist.hpp" />
<ClInclude Include="..\src\script\api\script_company.hpp" />
<ClInclude Include="..\src\script\api\script_companymode.hpp" />
<ClInclude Include="..\src\script\api\script_controller.hpp" />
@ -1096,6 +1098,8 @@
<ClCompile Include="..\src\script\api\script_cargo.cpp" />
<ClCompile Include="..\src\script\api\script_cargolist.cpp" />
<ClCompile Include="..\src\script\api\script_cargomonitor.cpp" />
<ClCompile Include="..\src\script\api\script_client.cpp" />
<ClCompile Include="..\src\script\api\script_clientlist.cpp" />
<ClCompile Include="..\src\script\api\script_company.cpp" />
<ClCompile Include="..\src\script\api\script_companymode.cpp" />
<ClCompile Include="..\src\script\api\script_controller.cpp" />

View File

@ -2223,6 +2223,12 @@
<ClInclude Include="..\src\script\api\script_cargomonitor.hpp">
<Filter>Script API</Filter>
</ClInclude>
<ClInclude Include="..\src\script\api\script_client.hpp">
<Filter>Script API</Filter>
</ClInclude>
<ClInclude Include="..\src\script\api\script_clientlist.hpp">
<Filter>Script API</Filter>
</ClInclude>
<ClInclude Include="..\src\script\api\script_company.hpp">
<Filter>Script API</Filter>
</ClInclude>
@ -2418,6 +2424,12 @@
<ClCompile Include="..\src\script\api\script_cargomonitor.cpp">
<Filter>Script API Implementation</Filter>
</ClCompile>
<ClCompile Include="..\src\script\api\script_client.cpp">
<Filter>Script API Implementation</Filter>
</ClCompile>
<ClCompile Include="..\src\script\api\script_clientlist.cpp">
<Filter>Script API Implementation</Filter>
</ClCompile>
<ClCompile Include="..\src\script\api\script_company.cpp">
<Filter>Script API Implementation</Filter>
</ClCompile>

View File

@ -1031,6 +1031,8 @@
<ClInclude Include="..\src\script\api\script_cargo.hpp" />
<ClInclude Include="..\src\script\api\script_cargolist.hpp" />
<ClInclude Include="..\src\script\api\script_cargomonitor.hpp" />
<ClInclude Include="..\src\script\api\script_client.hpp" />
<ClInclude Include="..\src\script\api\script_clientlist.hpp" />
<ClInclude Include="..\src\script\api\script_company.hpp" />
<ClInclude Include="..\src\script\api\script_companymode.hpp" />
<ClInclude Include="..\src\script\api\script_controller.hpp" />
@ -1096,6 +1098,8 @@
<ClCompile Include="..\src\script\api\script_cargo.cpp" />
<ClCompile Include="..\src\script\api\script_cargolist.cpp" />
<ClCompile Include="..\src\script\api\script_cargomonitor.cpp" />
<ClCompile Include="..\src\script\api\script_client.cpp" />
<ClCompile Include="..\src\script\api\script_clientlist.cpp" />
<ClCompile Include="..\src\script\api\script_company.cpp" />
<ClCompile Include="..\src\script\api\script_companymode.cpp" />
<ClCompile Include="..\src\script\api\script_controller.cpp" />

View File

@ -2223,6 +2223,12 @@
<ClInclude Include="..\src\script\api\script_cargomonitor.hpp">
<Filter>Script API</Filter>
</ClInclude>
<ClInclude Include="..\src\script\api\script_client.hpp">
<Filter>Script API</Filter>
</ClInclude>
<ClInclude Include="..\src\script\api\script_clientlist.hpp">
<Filter>Script API</Filter>
</ClInclude>
<ClInclude Include="..\src\script\api\script_company.hpp">
<Filter>Script API</Filter>
</ClInclude>
@ -2418,6 +2424,12 @@
<ClCompile Include="..\src\script\api\script_cargomonitor.cpp">
<Filter>Script API Implementation</Filter>
</ClCompile>
<ClCompile Include="..\src\script\api\script_client.cpp">
<Filter>Script API Implementation</Filter>
</ClCompile>
<ClCompile Include="..\src\script\api\script_clientlist.cpp">
<Filter>Script API Implementation</Filter>
</ClCompile>
<ClCompile Include="..\src\script\api\script_company.cpp">
<Filter>Script API Implementation</Filter>
</ClCompile>

View File

@ -3326,6 +3326,14 @@
RelativePath=".\..\src\script\api\script_cargomonitor.hpp"
>
</File>
<File
RelativePath=".\..\src\script\api\script_client.hpp"
>
</File>
<File
RelativePath=".\..\src\script\api\script_clientlist.hpp"
>
</File>
<File
RelativePath=".\..\src\script\api\script_company.hpp"
>
@ -3590,6 +3598,14 @@
RelativePath=".\..\src\script\api\script_cargomonitor.cpp"
>
</File>
<File
RelativePath=".\..\src\script\api\script_client.cpp"
>
</File>
<File
RelativePath=".\..\src\script\api\script_clientlist.cpp"
>
</File>
<File
RelativePath=".\..\src\script\api\script_company.cpp"
>

View File

@ -3323,6 +3323,14 @@
RelativePath=".\..\src\script\api\script_cargomonitor.hpp"
>
</File>
<File
RelativePath=".\..\src\script\api\script_client.hpp"
>
</File>
<File
RelativePath=".\..\src\script\api\script_clientlist.hpp"
>
</File>
<File
RelativePath=".\..\src\script\api\script_company.hpp"
>
@ -3587,6 +3595,14 @@
RelativePath=".\..\src\script\api\script_cargomonitor.cpp"
>
</File>
<File
RelativePath=".\..\src\script\api\script_client.cpp"
>
</File>
<File
RelativePath=".\..\src\script\api\script_clientlist.cpp"
>
</File>
<File
RelativePath=".\..\src\script\api\script_company.cpp"
>

View File

@ -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

View File

@ -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);

View File

@ -21,15 +21,16 @@ void SQAICompany_Register(Squirrel *engine)
SQAICompany.PreRegister(engine);
SQAICompany.AddConstructor<void (ScriptCompany::*)(), 1>(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");

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
/* THIS FILE IS AUTO-GENERATED; PLEASE DO NOT ALTER MANUALLY */
#include "../script_client.hpp"
#include "../template/template_client.hpp.sq"
template <> const char *GetClassName<ScriptClient, ST_GS>() { return "GSClient"; }
void SQGSClient_Register(Squirrel *engine)
{
DefSQClass<ScriptClient, ST_GS> SQGSClient("GSClient");
SQGSClient.PreRegister(engine);
SQGSClient.AddConstructor<void (ScriptClient::*)(), 1>(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);
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
/* THIS FILE IS AUTO-GENERATED; PLEASE DO NOT ALTER MANUALLY */
#include "../script_clientlist.hpp"
#include "../template/template_clientlist.hpp.sq"
template <> const char *GetClassName<ScriptClientList, ST_GS>() { return "GSClientList"; }
void SQGSClientList_Register(Squirrel *engine)
{
DefSQClass<ScriptClientList, ST_GS> SQGSClientList("GSClientList");
SQGSClientList.PreRegister(engine, "GSList");
SQGSClientList.AddConstructor<void (ScriptClientList::*)(), 1>(engine, "x");
SQGSClientList.PostRegister(engine);
}
template <> const char *GetClassName<ScriptClientList_Company, ST_GS>() { return "GSClientList_Company"; }
void SQGSClientList_Company_Register(Squirrel *engine)
{
DefSQClass<ScriptClientList_Company, ST_GS> SQGSClientList_Company("GSClientList_Company");
SQGSClientList_Company.PreRegister(engine, "GSList");
SQGSClientList_Company.AddConstructor<void (ScriptClientList_Company::*)(ScriptCompany::CompanyID company), 2>(engine, "xi");
SQGSClientList_Company.PostRegister(engine);
}

View File

@ -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");

View File

@ -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
*

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
/** @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
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
/** @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 */

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
/** @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
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
/** @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 */

View File

@ -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. */

View File

@ -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_client.hpp"
namespace SQConvert {
/* Allow enums to be used as Squirrel parameters */
template <> inline ScriptClient::ClientID GetParam(ForceType<ScriptClient::ClientID>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (ScriptClient::ClientID)tmp; }
template <> inline int Return<ScriptClient::ClientID>(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<ScriptClient *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptClient *)instance; }
template <> inline ScriptClient &GetParam(ForceType<ScriptClient &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(ScriptClient *)instance; }
template <> inline const ScriptClient *GetParam(ForceType<const ScriptClient *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptClient *)instance; }
template <> inline const ScriptClient &GetParam(ForceType<const ScriptClient &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(ScriptClient *)instance; }
template <> inline int Return<ScriptClient *>(HSQUIRRELVM vm, ScriptClient *res) { if (res == NULL) { sq_pushnull(vm); return 1; } res->AddRef(); Squirrel::CreateClassInstanceVM(vm, "Client", res, NULL, DefSQDestructorCallback<ScriptClient>, true); return 1; }
} // namespace SQConvert

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
/* 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<ScriptClientList *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptClientList *)instance; }
template <> inline ScriptClientList &GetParam(ForceType<ScriptClientList &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(ScriptClientList *)instance; }
template <> inline const ScriptClientList *GetParam(ForceType<const ScriptClientList *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptClientList *)instance; }
template <> inline const ScriptClientList &GetParam(ForceType<const ScriptClientList &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(ScriptClientList *)instance; }
template <> inline int Return<ScriptClientList *>(HSQUIRRELVM vm, ScriptClientList *res) { if (res == NULL) { sq_pushnull(vm); return 1; } res->AddRef(); Squirrel::CreateClassInstanceVM(vm, "ClientList", res, NULL, DefSQDestructorCallback<ScriptClientList>, true); return 1; }
} // namespace SQConvert
namespace SQConvert {
/* Allow ScriptClientList_Company to be used as Squirrel parameter */
template <> inline ScriptClientList_Company *GetParam(ForceType<ScriptClientList_Company *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptClientList_Company *)instance; }
template <> inline ScriptClientList_Company &GetParam(ForceType<ScriptClientList_Company &>, 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<const ScriptClientList_Company *>, 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<const ScriptClientList_Company &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(ScriptClientList_Company *)instance; }
template <> inline int Return<ScriptClientList_Company *>(HSQUIRRELVM vm, ScriptClientList_Company *res) { if (res == NULL) { sq_pushnull(vm); return 1; } res->AddRef(); Squirrel::CreateClassInstanceVM(vm, "ClientList_Company", res, NULL, DefSQDestructorCallback<ScriptClientList_Company>, true); return 1; }
} // namespace SQConvert