(svn r23357) -Codechange: move AIStorage to ScriptStorage

This commit is contained in:
truebrain
2011-11-29 23:21:04 +00:00
parent 0fbe10a2e3
commit b4112dcf8e
12 changed files with 48 additions and 47 deletions

View File

@@ -17,10 +17,11 @@
#include "../script/squirrel_class.hpp"
#include "ai_config.hpp"
#include "ai_storage.hpp"
#include "ai_instance.hpp"
#include "ai_gui.hpp"
#include "../script/script_storage.hpp"
#include "ai_instance.hpp"
/* Convert all AI related classes to Squirrel data.
* Note: this line is a marker in squirrel_export.sh. Do not change! */
#include "api/ai_accounting.hpp.sq"
@@ -82,7 +83,7 @@ static const int MAX_SL_OPS = 100000;
/** 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 @@ AIInstance::AIInstance() :
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 @@ void AIInstance::CollectGarbage() const
instance->engine->InsertResult(ScriptObject::GetNewGroupID());
}
AIStorage *AIInstance::GetStorage()
ScriptStorage *AIInstance::GetStorage()
{
return this->storage;
}

View File

@@ -111,7 +111,7 @@ public:
/**
* Get the storage of this AI.
*/
class AIStorage *GetStorage();
class ScriptStorage *GetStorage();
/**
* Get the log pointer of this AI.
@@ -202,15 +202,15 @@ public:
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.

View File

@@ -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 */