summaryrefslogtreecommitdiff
path: root/src/ai/api/ai_object.hpp
diff options
context:
space:
mode:
authortruebrain <truebrain@openttd.org>2011-11-13 20:43:48 +0000
committertruebrain <truebrain@openttd.org>2011-11-13 20:43:48 +0000
commitb7a655bf4cafc68e14cade593e8b1aca7f04f7dd (patch)
tree1880bbb64896193511e72c23c9387af2bb19acae /src/ai/api/ai_object.hpp
parent407514a590dc06c8b80c5304b5e9227c8c844f91 (diff)
downloadopenttd-b7a655bf4cafc68e14cade593e8b1aca7f04f7dd.tar.xz
(svn r23209) -Codechange: track the current active script instance directly, instead of assuming the current company points you to the right one.
Diffstat (limited to 'src/ai/api/ai_object.hpp')
-rw-r--r--src/ai/api/ai_object.hpp30
1 files changed, 26 insertions, 4 deletions
diff --git a/src/ai/api/ai_object.hpp b/src/ai/api/ai_object.hpp
index 3df150bac..deac277dd 100644
--- a/src/ai/api/ai_object.hpp
+++ b/src/ai/api/ai_object.hpp
@@ -35,10 +35,26 @@ typedef bool (AIModeProc)();
* command processing, and command-validation checks.
*/
class AIObject : public SimpleCountedObject {
-friend void CcAI(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2);
friend class AIInstance;
-friend class AIController;
#ifndef DOXYGEN_AI_DOCS
+protected:
+ /**
+ * A class that handles the current active instance. By instantiating it at
+ * the beginning of a function with the current active instance, it remains
+ * active till the scope of the variable closes. It then automatically
+ * reverts to the active instance it was before instantiating.
+ */
+ class ActiveInstance {
+ friend class AIObject;
+ public:
+ ActiveInstance(AIInstance *instance);
+ ~ActiveInstance();
+ private:
+ AIInstance *last_active; ///< The active instance before we go instantiated.
+
+ static AIInstance *active; ///< The global current active instance.
+ };
+
public:
/**
* Store the latest result of a DoCommand per company.
@@ -47,9 +63,10 @@ public:
static void SetLastCommandRes(bool res);
/**
- * Get the pointer to store log message in.
+ * Get the currently active instance.
+ * @return The instance.
*/
- static void *&GetLogPointer();
+ static class AIInstance *GetActiveInstance();
protected:
/**
@@ -197,6 +214,11 @@ protected:
*/
static void *&GetEventPointer();
+ /**
+ * Get the pointer to store log message in.
+ */
+ static void *&GetLogPointer();
+
private:
/**
* Store a new_vehicle_id per company.