Codechange: Optimize FlowsDown (#13262)
[openttd-github.git] / src / script / api / script_companymode.hpp
blob1514eefe86c8d5472934e88580bce05c53854e8b
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_companymode.hpp Switch the company. */
10 #ifndef SCRIPT_COMPANYMODE_HPP
11 #define SCRIPT_COMPANYMODE_HPP
13 #include "script_object.hpp"
15 /**
16 * Class to switch the current company.
17 * If you create an instance of this class, the company will be switched.
18 * The original company is stored and recovered from when ever the
19 * instance is destroyed.
20 * All actions performed within the scope of this mode, will be executed
21 * on behalf of the company you switched to. This includes any costs
22 * attached to the action performed. If the company does not have the
23 * funds the action will be aborted. In other words, this is like the
24 * real player is executing the commands.
25 * If the company is not valid during an action, the error
26 * ERR_PRECONDITION_INVALID_COMPANY will be returned. You can switch to
27 * invalid companies, or a company can become invalid (bankrupt) while you
28 * are switched to it.
29 * @api game
31 class ScriptCompanyMode : public ScriptObject {
32 private:
33 CompanyID last_company; ///< The previous company we were in.
35 public:
36 /**
37 * Creating instance of this class switches the company used for queries
38 * and commands.
39 * @param company The new company to switch to.
40 * @note When the instance is destroyed, it restores the company that was
41 * current when the instance was created!
43 ScriptCompanyMode(SQInteger company);
45 /**
46 * Destroying this instance reset the company to that what it was
47 * in when the instance was created.
49 ~ScriptCompanyMode();
51 /**
52 * Check whether a company mode is valid. In other words, are commands
53 * being executed under some company and does the company still exist?
54 * @return true When a company mode is valid.
55 * @post If IsValid() is true, then IsDeity() is false.
57 static bool IsValid();
59 /**
60 * Check whether the company mode is not active, i.e. whether we are a deity.
61 * In other words, are commands are not being executed under some company.
62 * @return true When we are a deity, i.e. company mode is not active.
63 * @post if IsDeity() is true, then IsValid() is false.
65 static bool IsDeity();
68 #endif /* SCRIPT_COMPANYMODE_HPP */