ai_instance.hpp

Go to the documentation of this file.
00001 /* $Id$ */
00002 
00003 /*
00004  * This file is part of OpenTTD.
00005  * 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.
00006  * 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.
00007  * 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/>.
00008  */
00009 
00012 #ifndef AI_INSTANCE_HPP
00013 #define AI_INSTANCE_HPP
00014 
00018 typedef void (AISuspendCallbackProc)(class AIInstance *instance);
00019 
00023 class AI_VMSuspend {
00024 public:
00025   AI_VMSuspend(int time, AISuspendCallbackProc *callback) :
00026     time(time),
00027     callback(callback)
00028   {}
00029 
00030   int GetSuspendTime() { return time; }
00031   AISuspendCallbackProc *GetSuspendCallback() { return callback; }
00032 
00033 private:
00034   int time;
00035   AISuspendCallbackProc *callback;
00036 };
00037 
00041 class AI_FatalError {
00042 public:
00043   AI_FatalError(const char *msg) :
00044     msg(msg)
00045   {}
00046 
00047   const char *GetErrorMessage() { return msg; }
00048 
00049 private:
00050   const char *msg;
00051 };
00052 
00053 class AIInstance {
00054 public:
00055   friend class AIObject;
00056   AIInstance(class AIInfo *info);
00057   ~AIInstance();
00058 
00063   void Continue();
00064 
00068   void GameLoop();
00069 
00073   void CollectGarbage();
00074 
00078   static class AIStorage *GetStorage();
00079 
00083   static void DoCommandReturn(AIInstance *instance);
00084 
00088   static void DoCommandReturnVehicleID(AIInstance *instance);
00089 
00093   static void DoCommandReturnSignID(AIInstance *instance);
00094 
00098   static void DoCommandReturnGroupID(AIInstance *instance);
00099 
00103   class AIController *GetController() { return controller; }
00104 
00108   inline bool IsDead() { return this->is_dead; }
00109 
00113   void Save();
00114 
00118   static void SaveEmpty();
00119 
00125   void Load(int version);
00126 
00131   bool CallLoad();
00132 
00136   static void LoadEmpty();
00137 
00138 private:
00139   class AIController *controller;
00140   class AIStorage *storage;
00141   class Squirrel *engine;
00142   SQObject *instance;
00143 
00144   bool is_started;
00145   bool is_dead;
00146   bool is_save_data_on_stack;
00147   int suspend;
00148   AISuspendCallbackProc *callback;
00149 
00153   void RegisterAPI();
00154 
00158   bool LoadCompatibilityScripts(const char *api_version);
00159 
00163   void Died();
00164 
00175   static bool SaveObject(HSQUIRRELVM vm, SQInteger index, int max_depth, bool test);
00176 
00181   static bool LoadObjects(HSQUIRRELVM vm);
00182 };
00183 
00184 #endif /* AI_INSTANCE_HPP */

Generated on Sat Dec 26 20:05:58 2009 for OpenTTD by  doxygen 1.5.6