OpenTTD Source: src/script/script_storage.hpp Source File

OpenTTD Source 15.3

script_storage.hpp
Go to the documentation of this file.
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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
10#ifndef SCRIPT_STORAGE_HPP
11#define SCRIPT_STORAGE_HPP
12
13#include <queue>
14
15#include "../command_type.h"
16#include "../company_type.h"
17#include "../rail_type.h"
18#include "../road_type.h"
19
20#include "script_types.hpp"
21#include "script_log_types.hpp"
22#include "script_object.hpp"
23
24class ScriptEvent;
25
26/* This is a "struct", so we can forward declare it, and use as incomplete type. */
27 struct ScriptEventQueue : std::queue<ScriptObjectRef<ScriptEvent>> {
28};
29
33 typedef bool (ScriptModeProc)();
34
38 typedef bool (ScriptAsyncModeProc)();
39
43 class ScriptStorage {
44friend class ScriptObject;
45private:
46 ScriptModeProc *mode = nullptr;
47 class ScriptObject *mode_instance = nullptr;
48 ScriptAsyncModeProc *async_mode = nullptr;
49 class ScriptObject *async_mode_instance = nullptr;
50 CompanyID root_company = INVALID_OWNER;
51 CompanyID company = INVALID_OWNER;
52
53 uint delay = 1;
54 bool allow_do_command = true;
55
56 CommandCost costs;
57 Money last_cost = 0;
58 ScriptErrorType last_error{};
59 bool last_command_res = true;
60
61 CommandDataBuffer last_data;
62 Commands last_cmd = CMD_END;
63 CommandDataBuffer last_cmd_ret;
64
65 std::vector<int> callback_value;
66
67 RoadType road_type = INVALID_ROADTYPE;
68 RailType rail_type = INVALID_RAILTYPE;
69
70 ScriptEventQueue event_queue;
71 ScriptLogTypes::LogData log_data;
72
73public:
74 ScriptStorage();
75 ~ScriptStorage();
76};
77
78#endif /* SCRIPT_STORAGE_HPP */
CommandCost
Common return value for all commands.
Definition command_type.h:24
OverflowSafeInt< int64_t >
ScriptStorage
The storage for each script.
Definition script_storage.hpp:43
ScriptStorage::log_data
ScriptLogTypes::LogData log_data
Log data storage.
Definition script_storage.hpp:71
ScriptStorage::last_cmd_ret
CommandDataBuffer last_cmd_ret
The extra data returned by the last command.
Definition script_storage.hpp:63
ScriptStorage::rail_type
RailType rail_type
The current railtype we build.
Definition script_storage.hpp:68
ScriptStorage::root_company
CompanyID root_company
The root company, the company that the script really belongs to.
Definition script_storage.hpp:50
ScriptStorage::delay
uint delay
The ticks of delay each DoCommand has.
Definition script_storage.hpp:53
ScriptStorage::last_error
ScriptErrorType last_error
The last error of the command.
Definition script_storage.hpp:58
ScriptStorage::async_mode_instance
class ScriptObject * async_mode_instance
The instance belonging to the current command async mode.
Definition script_storage.hpp:49
ScriptStorage::last_data
CommandDataBuffer last_data
The last data passed to a command.
Definition script_storage.hpp:61
ScriptStorage::callback_value
std::vector< int > callback_value
The values which need to survive a callback.
Definition script_storage.hpp:65
ScriptStorage::last_cost
Money last_cost
The last cost of the command.
Definition script_storage.hpp:57
ScriptStorage::allow_do_command
bool allow_do_command
Is the usage of DoCommands restricted?
Definition script_storage.hpp:54
ScriptStorage::async_mode
ScriptAsyncModeProc * async_mode
The current command async mode we are in.
Definition script_storage.hpp:48
ScriptStorage::mode_instance
class ScriptObject * mode_instance
The instance belonging to the current build mode.
Definition script_storage.hpp:47
ScriptStorage::road_type
RoadType road_type
The current roadtype we build.
Definition script_storage.hpp:67
ScriptStorage::costs
CommandCost costs
The costs the script is tracking.
Definition script_storage.hpp:56
ScriptStorage::mode
ScriptModeProc * mode
The current build mode we are int.
Definition script_storage.hpp:46
ScriptStorage::last_command_res
bool last_command_res
The last result of the command.
Definition script_storage.hpp:59
ScriptStorage::event_queue
ScriptEventQueue event_queue
Event queue for this script.
Definition script_storage.hpp:70
ScriptStorage::last_cmd
Commands last_cmd
The last cmd passed to a command.
Definition script_storage.hpp:62
ScriptStorage::company
CompanyID company
The current company.
Definition script_storage.hpp:51
CommandDataBuffer
std::vector< uint8_t > CommandDataBuffer
Storage buffer for serialized command data.
Definition command_type.h:481
Commands
Commands
List of commands.
Definition command_type.h:196
CMD_END
@ CMD_END
Must ALWAYS be on the end of this list!! (period)
Definition command_type.h:378
INVALID_OWNER
static constexpr Owner INVALID_OWNER
An invalid owner.
Definition company_type.h:30
RailType
RailType
Enumeration for all possible railtypes.
Definition rail_type.h:25
INVALID_RAILTYPE
@ INVALID_RAILTYPE
Flag for invalid railtype.
Definition rail_type.h:32
RoadType
RoadType
The different roadtypes we support.
Definition road_type.h:23
INVALID_ROADTYPE
@ INVALID_ROADTYPE
flag for invalid roadtype
Definition road_type.h:28
ScriptAsyncModeProc
bool() ScriptAsyncModeProc()
The callback function for Async Mode-classes.
Definition script_storage.hpp:38
ScriptModeProc
bool() ScriptModeProc()
The callback function for Mode-classes.
Definition script_storage.hpp:33
PoolID< uint8_t, struct CompanyIDTag, 0xF, 0xFF >
ScriptEventQueue
Definition script_storage.hpp:27