(svn r23359) -Codechange: move AI_VMSuspend to Script_Suspend (and to its own file)
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
#include "../../ai/ai_config.hpp"
|
||||
#include "../../ai/ai.hpp"
|
||||
#include "../script_fatalerror.hpp"
|
||||
#include "../script_suspend.hpp"
|
||||
#include "script_log.hpp"
|
||||
|
||||
/* static */ void ScriptController::SetCommandDelay(int ticks)
|
||||
@@ -40,7 +41,7 @@
|
||||
ticks = 1;
|
||||
}
|
||||
|
||||
throw AI_VMSuspend(ticks, NULL);
|
||||
throw Script_Suspend(ticks, NULL);
|
||||
}
|
||||
|
||||
/* static */ void ScriptController::Print(bool error_msg, const char *message)
|
||||
|
@@ -18,6 +18,7 @@
|
||||
#include "../script_storage.hpp"
|
||||
#include "../../ai/ai_instance.hpp"
|
||||
#include "../script_fatalerror.hpp"
|
||||
#include "../script_suspend.hpp"
|
||||
#include "script_error.hpp"
|
||||
|
||||
/**
|
||||
@@ -265,7 +266,7 @@ ScriptObject::ActiveInstance::~ActiveInstance()
|
||||
|
||||
if (_networking) {
|
||||
/* Suspend the AI till the command is really executed. */
|
||||
throw AI_VMSuspend(-(int)GetDoCommandDelay(), callback);
|
||||
throw Script_Suspend(-(int)GetDoCommandDelay(), callback);
|
||||
} else {
|
||||
IncreaseDoCommandCosts(res.GetCost());
|
||||
|
||||
@@ -273,7 +274,7 @@ ScriptObject::ActiveInstance::~ActiveInstance()
|
||||
* both avoids confusion when a developer launched his AI in a
|
||||
* multiplayer game, but also gives time for the GUI and human player
|
||||
* to interact with the game. */
|
||||
throw AI_VMSuspend(GetDoCommandDelay(), callback);
|
||||
throw Script_Suspend(GetDoCommandDelay(), callback);
|
||||
}
|
||||
|
||||
NOT_REACHED();
|
||||
|
52
src/script/script_suspend.hpp
Normal file
52
src/script/script_suspend.hpp
Normal file
@@ -0,0 +1,52 @@
|
||||
/* $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_suspend.hpp The Script_Suspend tracks the suspension of a script. */
|
||||
|
||||
#ifndef SCRIPT_SUSPEND_HPP
|
||||
#define SCRIPT_SUSPEND_HPP
|
||||
|
||||
/**
|
||||
* The callback function when a script suspends.
|
||||
*/
|
||||
typedef void (Script_SuspendCallbackProc)(class AIInstance *instance);
|
||||
|
||||
/**
|
||||
* A throw-class that is given when the script wants to suspend.
|
||||
*/
|
||||
class Script_Suspend {
|
||||
public:
|
||||
/**
|
||||
* Create the suspend exception.
|
||||
* @param time The amount of ticks to suspend.
|
||||
* @param callback The callback to call when the script may resume again.
|
||||
*/
|
||||
Script_Suspend(int time, Script_SuspendCallbackProc *callback) :
|
||||
time(time),
|
||||
callback(callback)
|
||||
{}
|
||||
|
||||
/**
|
||||
* Get the amount of ticks the script should be suspended.
|
||||
* @return The amount of ticks to suspend the script.
|
||||
*/
|
||||
int GetSuspendTime() { return time; }
|
||||
|
||||
/**
|
||||
* Get the callback to call when the script can run again.
|
||||
* @return The callback function to run.
|
||||
*/
|
||||
Script_SuspendCallbackProc *GetSuspendCallback() { return callback; }
|
||||
|
||||
private:
|
||||
int time; ///< Amount of ticks to suspend the script.
|
||||
Script_SuspendCallbackProc *callback; ///< Callback function to call when the script can run again.
|
||||
};
|
||||
|
||||
#endif /* SCRIPT_SUSPEND_HPP */
|
Reference in New Issue
Block a user