summaryrefslogtreecommitdiff
path: root/src/script/script_suspend.hpp
diff options
context:
space:
mode:
authortruebrain <truebrain@openttd.org>2011-11-29 23:21:24 +0000
committertruebrain <truebrain@openttd.org>2011-11-29 23:21:24 +0000
commit75c4bd280a720592ec4df26efbedd9df5baa2d8f (patch)
tree7e4a3248a93b55f9add46b9935bf3e1d8da93c84 /src/script/script_suspend.hpp
parentbbd9facb44dc09ded5500918319b770c63c0a981 (diff)
downloadopenttd-75c4bd280a720592ec4df26efbedd9df5baa2d8f.tar.xz
(svn r23359) -Codechange: move AI_VMSuspend to Script_Suspend (and to its own file)
Diffstat (limited to 'src/script/script_suspend.hpp')
-rw-r--r--src/script/script_suspend.hpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/script/script_suspend.hpp b/src/script/script_suspend.hpp
new file mode 100644
index 000000000..a67f3f514
--- /dev/null
+++ b/src/script/script_suspend.hpp
@@ -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 */