Codechange: Don't use globals for return values from vehicle command procs.
[openttd-github.git] / src / script / script_storage.hpp
blob2afb03827d8d79845990cdbb02fe0039fa412336
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_storage.hpp Defines ScriptStorage and includes all files required for it. */
10 #ifndef SCRIPT_STORAGE_HPP
11 #define SCRIPT_STORAGE_HPP
13 #include "../signs_func.h"
14 #include "../vehicle_func.h"
15 #include "../road_type.h"
16 #include "../group.h"
17 #include "../goal_type.h"
18 #include "../story_type.h"
20 #include "table/strings.h"
21 #include <vector>
23 /**
24 * The callback function for Mode-classes.
26 typedef bool (ScriptModeProc)();
28 /**
29 * The storage for each script. It keeps track of important information.
31 class ScriptStorage {
32 friend class ScriptObject;
33 private:
34 ScriptModeProc *mode; ///< The current build mode we are int.
35 class ScriptObject *mode_instance; ///< The instance belonging to the current build mode.
36 CompanyID root_company; ///< The root company, the company that the script really belongs to.
37 CompanyID company; ///< The current company.
39 uint delay; ///< The ticks of delay each DoCommand has.
40 bool allow_do_command; ///< Is the usage of DoCommands restricted?
42 CommandCost costs; ///< The costs the script is tracking.
43 Money last_cost; ///< The last cost of the command.
44 uint last_error; ///< The last error of the command.
45 bool last_command_res; ///< The last result of the command.
47 TileIndex last_tile; ///< The last tile passed to a command.
48 CommandDataBuffer last_data; ///< The last data passed to a command.
49 Commands last_cmd; ///< The last cmd passed to a command.
50 CommandDataBuffer last_cmd_ret; ///< The extra data returned by the last command.
52 std::vector<int> callback_value; ///< The values which need to survive a callback.
54 RoadType road_type; ///< The current roadtype we build.
55 RailType rail_type; ///< The current railtype we build.
57 void *event_data; ///< Pointer to the event data storage.
58 void *log_data; ///< Pointer to the log data storage.
60 public:
61 ScriptStorage() :
62 mode (nullptr),
63 mode_instance (nullptr),
64 root_company (INVALID_OWNER),
65 company (INVALID_OWNER),
66 delay (1),
67 allow_do_command (true),
68 /* costs (can't be set) */
69 last_cost (0),
70 last_error (STR_NULL),
71 last_command_res (true),
72 last_tile (INVALID_TILE),
73 last_cmd (CMD_END),
74 /* calback_value (can't be set) */
75 road_type (INVALID_ROADTYPE),
76 rail_type (INVALID_RAILTYPE),
77 event_data (nullptr),
78 log_data (nullptr)
79 { }
81 ~ScriptStorage();
84 #endif /* SCRIPT_STORAGE_HPP */