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 
00015 #include <squirrel.h>
00016 
00020 typedef void (AISuspendCallbackProc)(class AIInstance *instance);
00021 
00025 class AI_VMSuspend {
00026 public:
00032   AI_VMSuspend(int time, AISuspendCallbackProc *callback) :
00033     time(time),
00034     callback(callback)
00035   {}
00036 
00041   int GetSuspendTime() { return time; }
00042 
00047   AISuspendCallbackProc *GetSuspendCallback() { return callback; }
00048 
00049 private:
00050   int time;                        
00051   AISuspendCallbackProc *callback; 
00052 };
00053 
00057 class AI_FatalError {
00058 public:
00063   AI_FatalError(const char *msg) :
00064     msg(msg)
00065   {}
00066 
00071   const char *GetErrorMessage() { return msg; }
00072 
00073 private:
00074   const char *msg; 
00075 };
00076 
00078 class AIInstance {
00079 public:
00080   friend class AIObject;
00081 
00086   AIInstance(class AIInfo *info);
00087   ~AIInstance();
00088 
00093   void Continue();
00094 
00098   void GameLoop();
00099 
00103   void CollectGarbage() const;
00104 
00108   static class AIStorage *GetStorage();
00109 
00113   static void DoCommandReturn(AIInstance *instance);
00114 
00118   static void DoCommandReturnVehicleID(AIInstance *instance);
00119 
00123   static void DoCommandReturnSignID(AIInstance *instance);
00124 
00128   static void DoCommandReturnGroupID(AIInstance *instance);
00129 
00133   class AIController *GetController() { return controller; }
00134 
00138   inline bool IsDead() const { return this->is_dead; }
00139 
00143   void Save();
00144 
00148   static void SaveEmpty();
00149 
00155   void Load(int version);
00156 
00161   bool CallLoad();
00162 
00166   static void LoadEmpty();
00167 
00174   void Suspend();
00175 private:
00176   class AIController *controller;  
00177   class AIStorage *storage;        
00178   class Squirrel *engine;          
00179   SQObject *instance;              
00180 
00181   bool is_started;                 
00182   bool is_dead;                    
00183   bool is_save_data_on_stack;      
00184   int suspend;                     
00185   AISuspendCallbackProc *callback; 
00186 
00190   void RegisterAPI();
00191 
00195   bool LoadCompatibilityScripts(const char *api_version);
00196 
00200   void Died();
00201 
00212   static bool SaveObject(HSQUIRRELVM vm, SQInteger index, int max_depth, bool test);
00213 
00218   static bool LoadObjects(HSQUIRRELVM vm);
00219 };
00220 
00221 #endif /* AI_INSTANCE_HPP */

Generated on Fri May 27 04:19:38 2011 for OpenTTD by  doxygen 1.6.1