From 99cb93ef6faf7e89720ca0caf5536bb488be990e Mon Sep 17 00:00:00 2001 From: truebrain Date: Tue, 29 Nov 2011 23:21:04 +0000 Subject: (svn r23357) -Codechange: move AIStorage to ScriptStorage --- src/script/api/script_execmode.hpp | 2 +- src/script/api/script_object.cpp | 8 ++-- src/script/api/script_object.hpp | 6 +-- src/script/api/script_testmode.hpp | 2 +- src/script/script_storage.hpp | 82 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 91 insertions(+), 9 deletions(-) create mode 100644 src/script/script_storage.hpp (limited to 'src/script') diff --git a/src/script/api/script_execmode.hpp b/src/script/api/script_execmode.hpp index 8dfa00938..a3ce70d68 100644 --- a/src/script/api/script_execmode.hpp +++ b/src/script/api/script_execmode.hpp @@ -23,7 +23,7 @@ */ class ScriptExecMode : public ScriptObject { private: - AIModeProc *last_mode; ///< The previous mode we were in. + ScriptModeProc *last_mode; ///< The previous mode we were in. ScriptObject *last_instance; ///< The previous instace of the mode. protected: diff --git a/src/script/api/script_object.cpp b/src/script/api/script_object.cpp index 2b6a3039b..0be85a745 100644 --- a/src/script/api/script_object.cpp +++ b/src/script/api/script_object.cpp @@ -15,7 +15,7 @@ #include "../../network/network.h" #include "../../tunnelbridge.h" -#include "../../ai/ai_storage.hpp" +#include "../script_storage.hpp" #include "../../ai/ai_instance.hpp" #include "script_error.hpp" @@ -23,7 +23,7 @@ * Get the storage associated with the current AIInstance. * @return The storage. */ -static AIStorage *GetStorage() +static ScriptStorage *GetStorage() { return ScriptObject::GetActiveInstance()->GetStorage(); } @@ -60,13 +60,13 @@ ScriptObject::ActiveInstance::~ActiveInstance() return GetStorage()->delay; } -/* static */ void ScriptObject::SetDoCommandMode(AIModeProc *proc, ScriptObject *instance) +/* static */ void ScriptObject::SetDoCommandMode(ScriptModeProc *proc, ScriptObject *instance) { GetStorage()->mode = proc; GetStorage()->mode_instance = instance; } -/* static */ AIModeProc *ScriptObject::GetDoCommandMode() +/* static */ ScriptModeProc *ScriptObject::GetDoCommandMode() { return GetStorage()->mode; } diff --git a/src/script/api/script_object.hpp b/src/script/api/script_object.hpp index b4b55c740..b38757cc9 100644 --- a/src/script/api/script_object.hpp +++ b/src/script/api/script_object.hpp @@ -26,7 +26,7 @@ typedef void (AISuspendCallbackProc)(class AIInstance *instance); /** * The callback function for Mode-classes. */ -typedef bool (AIModeProc)(); +typedef bool (ScriptModeProc)(); /** * Uper-parent object of all API classes. You should never use this class in @@ -122,12 +122,12 @@ protected: /** * Set the current mode of your AI to this proc. */ - static void SetDoCommandMode(AIModeProc *proc, ScriptObject *instance); + static void SetDoCommandMode(ScriptModeProc *proc, ScriptObject *instance); /** * Get the current mode your AI is currently under. */ - static AIModeProc *GetDoCommandMode(); + static ScriptModeProc *GetDoCommandMode(); /** * Get the instance of the current mode your AI is currently under. diff --git a/src/script/api/script_testmode.hpp b/src/script/api/script_testmode.hpp index 6954146a9..a1b9e6bbf 100644 --- a/src/script/api/script_testmode.hpp +++ b/src/script/api/script_testmode.hpp @@ -25,7 +25,7 @@ */ class ScriptTestMode : public ScriptObject { private: - AIModeProc *last_mode; ///< The previous mode we were in. + ScriptModeProc *last_mode; ///< The previous mode we were in. ScriptObject *last_instance; ///< The previous instace of the mode. protected: diff --git a/src/script/script_storage.hpp b/src/script/script_storage.hpp new file mode 100644 index 000000000..bf369acfb --- /dev/null +++ b/src/script/script_storage.hpp @@ -0,0 +1,82 @@ +/* $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 . + */ + +/** @file script_storage.hpp Defines ScriptStorage and includes all files required for it. */ + +#ifndef SCRIPT_STORAGE_HPP +#define SCRIPT_STORAGE_HPP + +#include "../signs_func.h" +#include "../vehicle_func.h" +#include "../road_type.h" +#include "../group.h" + +#include "table/strings.h" +#include + +/** + * The callback function for Mode-classes. + */ +typedef bool (ScriptModeProc)(); + +/** + * The storage for each script. It keeps track of important information. + */ +class ScriptStorage { +friend class ScriptObject; +private: + ScriptModeProc *mode; ///< The current build mode we are int. + class ScriptObject *mode_instance; ///< The instance belonging to the current build mode. + + uint delay; ///< The ticks of delay each DoCommand has. + bool allow_do_command; ///< Is the usage of DoCommands restricted? + + CommandCost costs; ///< The costs the script is tracking. + Money last_cost; ///< The last cost of the command. + uint last_error; ///< The last error of the command. + bool last_command_res; ///< The last result of the command. + + VehicleID new_vehicle_id; ///< The ID of the new Vehicle. + SignID new_sign_id; ///< The ID of the new Sign. + TileIndex new_tunnel_endtile; ///< The TileIndex of the new Tunnel. + GroupID new_group_id; ///< The ID of the new Group. + + std::vector callback_value; ///< The values which need to survive a callback. + + RoadType road_type; ///< The current roadtype we build. + RailType rail_type; ///< The current railtype we build. + + void *event_data; ///< Pointer to the event data storage. + void *log_data; ///< Pointer to the log data storage. + +public: + ScriptStorage() : + mode (NULL), + mode_instance (NULL), + delay (1), + allow_do_command (true), + /* costs (can't be set) */ + last_cost (0), + last_error (STR_NULL), + last_command_res (true), + new_vehicle_id (0), + new_sign_id (0), + new_tunnel_endtile(INVALID_TILE), + new_group_id (0), + /* calback_value (can't be set) */ + road_type (INVALID_ROADTYPE), + rail_type (INVALID_RAILTYPE), + event_data (NULL), + log_data (NULL) + { } + + ~ScriptStorage(); +}; + +#endif /* SCRIPT_STORAGE_HPP */ -- cgit v1.2.3-70-g09d2