Mercurial > hg > openttd
changeset 18513:8813b628cb8c draft
(svn r23357) -Codechange: move AIStorage to ScriptStorage
author | truebrain <truebrain@openttd.org> |
---|---|
date | Tue, 29 Nov 2011 23:21:04 +0000 |
parents | 28d01e15d5e6 |
children | a6a3c52c74b1 |
files | projects/openttd_vs100.vcxproj projects/openttd_vs100.vcxproj.filters projects/openttd_vs80.vcproj projects/openttd_vs90.vcproj source.list src/ai/ai_instance.cpp src/ai/ai_instance.hpp src/ai/ai_storage.hpp src/script/api/script_execmode.hpp src/script/api/script_object.cpp src/script/api/script_object.hpp src/script/api/script_testmode.hpp src/script/script_storage.hpp |
diffstat | 13 files changed, 119 insertions(+), 118 deletions(-) [+] |
line wrap: on
line diff
--- a/projects/openttd_vs100.vcxproj +++ b/projects/openttd_vs100.vcxproj @@ -792,6 +792,7 @@ <ClInclude Include="..\src\script\script_info.hpp" /> <ClCompile Include="..\src\script\script_scanner.cpp" /> <ClInclude Include="..\src\script\script_scanner.hpp" /> + <ClInclude Include="..\src\script\script_storage.hpp" /> <ClCompile Include="..\src\script\squirrel.cpp" /> <ClInclude Include="..\src\script\squirrel.hpp" /> <ClInclude Include="..\src\script\squirrel_class.hpp" /> @@ -851,7 +852,6 @@ <ClInclude Include="..\src\ai\ai_instance.hpp" /> <ClCompile Include="..\src\ai\ai_scanner.cpp" /> <ClInclude Include="..\src\ai\ai_scanner.hpp" /> - <ClInclude Include="..\src\ai\ai_storage.hpp" /> <ClInclude Include="..\src\ai\api\ai_changelog.hpp" /> <ClInclude Include="..\src\ai\api\ai_info_docs.hpp" /> <ClInclude Include="..\src\script\api\script_accounting.hpp" />
--- a/projects/openttd_vs100.vcxproj.filters +++ b/projects/openttd_vs100.vcxproj.filters @@ -1599,6 +1599,9 @@ <ClInclude Include="..\src\script\script_scanner.hpp"> <Filter>Script</Filter> </ClInclude> + <ClInclude Include="..\src\script\script_storage.hpp"> + <Filter>Script</Filter> + </ClInclude> <ClCompile Include="..\src\script\squirrel.cpp"> <Filter>Script</Filter> </ClCompile> @@ -1776,9 +1779,6 @@ <ClInclude Include="..\src\ai\ai_scanner.hpp"> <Filter>AI Core</Filter> </ClInclude> - <ClInclude Include="..\src\ai\ai_storage.hpp"> - <Filter>AI Core</Filter> - </ClInclude> <ClInclude Include="..\src\ai\api\ai_changelog.hpp"> <Filter>AI API</Filter> </ClInclude>
--- a/projects/openttd_vs80.vcproj +++ b/projects/openttd_vs80.vcproj @@ -2475,6 +2475,10 @@ > </File> <File + RelativePath=".\..\src\script\script_storage.hpp" + > + </File> + <File RelativePath=".\..\src\script\squirrel.cpp" > </File> @@ -2722,10 +2726,6 @@ RelativePath=".\..\src\ai\ai_scanner.hpp" > </File> - <File - RelativePath=".\..\src\ai\ai_storage.hpp" - > - </File> </Filter> <Filter Name="AI API"
--- a/projects/openttd_vs90.vcproj +++ b/projects/openttd_vs90.vcproj @@ -2472,6 +2472,10 @@ > </File> <File + RelativePath=".\..\src\script\script_storage.hpp" + > + </File> + <File RelativePath=".\..\src\script\squirrel.cpp" > </File> @@ -2719,10 +2723,6 @@ RelativePath=".\..\src\ai\ai_scanner.hpp" > </File> - <File - RelativePath=".\..\src\ai\ai_storage.hpp" - > - </File> </Filter> <Filter Name="AI API"
--- a/source.list +++ b/source.list @@ -557,6 +557,7 @@ script/script_info.hpp script/script_scanner.cpp script/script_scanner.hpp +script/script_storage.hpp script/squirrel.cpp script/squirrel.hpp script/squirrel_class.hpp @@ -622,7 +623,6 @@ ai/ai_instance.hpp ai/ai_scanner.cpp ai/ai_scanner.hpp -ai/ai_storage.hpp # AI API ai/api/ai_changelog.hpp
--- a/src/ai/ai_instance.cpp +++ b/src/ai/ai_instance.cpp @@ -17,9 +17,10 @@ #include "../script/squirrel_class.hpp" #include "ai_config.hpp" -#include "ai_storage.hpp" +#include "ai_gui.hpp" + +#include "../script/script_storage.hpp" #include "ai_instance.hpp" -#include "ai_gui.hpp" /* Convert all AI related classes to Squirrel data. * Note: this line is a marker in squirrel_export.sh. Do not change! */ @@ -82,7 +83,7 @@ /** The maximum number of operations for initial start of an AI. */ static const int MAX_CONSTRUCTOR_OPS = 100000; -AIStorage::~AIStorage() +ScriptStorage::~ScriptStorage() { /* Free our pointers */ if (event_data != NULL) ScriptEventController::FreeEventPointer(); @@ -111,7 +112,7 @@ suspend(0), callback(NULL) { - this->storage = new AIStorage(); + this->storage = new ScriptStorage(); this->engine = new Squirrel("AI"); this->engine->SetPrintFunction(&PrintFunc); } @@ -428,7 +429,7 @@ instance->engine->InsertResult(ScriptObject::GetNewGroupID()); } -AIStorage *AIInstance::GetStorage() +ScriptStorage *AIInstance::GetStorage() { return this->storage; }
--- a/src/ai/ai_instance.hpp +++ b/src/ai/ai_instance.hpp @@ -111,7 +111,7 @@ /** * Get the storage of this AI. */ - class AIStorage *GetStorage(); + class ScriptStorage *GetStorage(); /** * Get the log pointer of this AI. @@ -202,15 +202,15 @@ private: class ScriptController *controller; ///< The AI main class. - class AIStorage *storage; ///< Some global information for each running AI. - class Squirrel *engine; ///< A wrapper around the squirrel vm. - SQObject *instance; ///< Squirrel-pointer to the AI main class. + class ScriptStorage *storage; ///< Some global information for each running AI. + class Squirrel *engine; ///< A wrapper around the squirrel vm. + SQObject *instance; ///< Squirrel-pointer to the AI main class. - bool is_started; ///< Is the AIs constructor executed? - bool is_dead; ///< True if the AI has been stopped. - bool is_save_data_on_stack; ///< Is the save data still on the squirrel stack? - int suspend; ///< The amount of ticks to suspend this AI before it's allowed to continue. - AISuspendCallbackProc *callback; ///< Callback that should be called in the next tick the AI runs. + bool is_started; ///< Is the AIs constructor executed? + bool is_dead; ///< True if the AI has been stopped. + bool is_save_data_on_stack; ///< Is the save data still on the squirrel stack? + int suspend; ///< The amount of ticks to suspend this AI before it's allowed to continue. + AISuspendCallbackProc *callback; ///< Callback that should be called in the next tick the AI runs. /** * Register all API functions to the VM.
deleted file mode 100644 --- a/src/ai/ai_storage.hpp +++ /dev/null @@ -1,82 +0,0 @@ -/* $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 <http://www.gnu.org/licenses/>. - */ - -/** @file ai_storage.hpp Defines AIStorage and includes all files required for it. */ - -#ifndef AI_STORAGE_HPP -#define AI_STORAGE_HPP - -#include "../signs_func.h" -#include "../vehicle_func.h" -#include "../road_type.h" -#include "../group.h" - -#include "table/strings.h" -#include <vector> - -/** - * The callback function for Mode-classes. - */ -typedef bool (AIModeProc)(); - -/** - * The storage for each AI. It keeps track of important information. - */ -class AIStorage { -friend class ScriptObject; -private: - AIModeProc *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 AI 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<int> 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: - AIStorage() : - 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) - { } - - ~AIStorage(); -}; - -#endif /* AI_STORAGE_HPP */
--- 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:
--- 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 @@ 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; }
--- a/src/script/api/script_object.hpp +++ b/src/script/api/script_object.hpp @@ -26,7 +26,7 @@ /** * 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 @@ /** * 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.
--- 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:
new file mode 100644 --- /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 <http://www.gnu.org/licenses/>. + */ + +/** @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 <vector> + +/** + * 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<int> 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 */