Codechange: Optimize FlowsDown (#13262)
[openttd-github.git] / src / script / api / script_client.hpp
blob7e463e4f940dd0da7f6ab733dd01100062465c7c
1 /*
2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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/>.
6 */
8 /** @file script_client.hpp Everything to query a network client's information */
10 #ifndef SCRIPT_CLIENT_HPP
11 #define SCRIPT_CLIENT_HPP
13 #include "script_text.hpp"
14 #include "script_date.hpp"
15 #include "script_company.hpp"
16 #include "../../network/network_type.h"
18 /**
19 * Class that handles all client related functions.
21 * @api game
23 class ScriptClient : public ScriptObject {
24 public:
26 /** Different constants related to ClientID. */
27 enum ClientID : uint32_t {
28 CLIENT_INVALID = 0, ///< Client is not part of anything
29 CLIENT_SERVER = 1, ///< Servers always have this ID
30 CLIENT_FIRST = 2, ///< The first client ID
33 /**
34 * Resolves the given client id to the correct index for the client.
35 * If the client with the given id does not exist it will
36 * return CLIENT_INVALID.
37 * @param client The client id to resolve.
38 * @return The resolved client id.
40 static ClientID ResolveClientID(ClientID client);
42 /**
43 * Get the name of the given client.
44 * @param client The client to get the name for.
45 * @pre ResolveClientID(client) != CLIENT_INVALID.
46 * @return The name of the given client.
48 static std::optional<std::string> GetName(ClientID client);
50 /**
51 * Get the company in which the given client is playing.
52 * @param client The client to get company for.
53 * @pre ResolveClientID(client) != CLIENT_INVALID.
54 * @return The company in which client is playing or COMPANY_SPECTATOR.
56 static ScriptCompany::CompanyID GetCompany(ClientID client);
58 /**
59 * Get the economy-date when the given client has joined.
60 * @param client The client to get joining date for.
61 * @pre ResolveClientID(client) != CLIENT_INVALID.
62 * @return The economy-date when client has joined.
63 * @see \ref ScriptEconomyTime
65 static ScriptDate::Date GetJoinDate(ClientID client);
69 #endif /* SCRIPT_CLIENT_HPP */