script_object.hpp

Go to the documentation of this file.
00001 /* $Id: script_object.hpp 23632 2011-12-19 21:05:25Z truebrain $ */
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 SCRIPT_OBJECT_HPP
00013 #define SCRIPT_OBJECT_HPP
00014 
00015 #include "../../misc/countedptr.hpp"
00016 #include "../../road_type.h"
00017 #include "../../rail_type.h"
00018 
00019 #include "script_types.hpp"
00020 #include "../script_suspend.hpp"
00021 
00025 typedef bool (ScriptModeProc)();
00026 
00034 class ScriptObject : public SimpleCountedObject {
00035 friend class ScriptInstance;
00036 protected:
00043   class ActiveInstance {
00044   friend class ScriptObject;
00045   public:
00046     ActiveInstance(ScriptInstance *instance);
00047     ~ActiveInstance();
00048   private:
00049     ScriptInstance *last_active;    
00050 
00051     static ScriptInstance *active;  
00052   };
00053 
00054 public:
00059   static void SetLastCommandRes(bool res);
00060 
00065   static class ScriptInstance *GetActiveInstance();
00066 
00067 protected:
00071   static bool DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint cmd, const char *text = NULL, Script_SuspendCallbackProc *callback = NULL);
00072 
00076   static void SetDoCommandCosts(Money value);
00077 
00081   static void IncreaseDoCommandCosts(Money value);
00082 
00086   static Money GetDoCommandCosts();
00087 
00091   static void SetLastError(ScriptErrorType last_error);
00092 
00096   static ScriptErrorType GetLastError();
00097 
00101   static void SetRoadType(RoadType road_type);
00102 
00106   static RoadType GetRoadType();
00107 
00111   static void SetRailType(RailType rail_type);
00112 
00116   static RailType GetRailType();
00117 
00121   static void SetDoCommandMode(ScriptModeProc *proc, ScriptObject *instance);
00122 
00126   static ScriptModeProc *GetDoCommandMode();
00127 
00131   static ScriptObject *GetDoCommandModeInstance();
00132 
00136   static void SetDoCommandDelay(uint ticks);
00137 
00141   static uint GetDoCommandDelay();
00142 
00146   static bool GetLastCommandRes();
00147 
00151   static VehicleID GetNewVehicleID();
00152 
00156   static SignID GetNewSignID();
00157 
00161   static GroupID GetNewGroupID();
00162 
00166   static GoalID GetNewGoalID();
00167 
00172   static void SetAllowDoCommand(bool allow);
00173 
00181   static bool GetAllowDoCommand();
00182 
00188   static void SetCompany(CompanyID company);
00189 
00195   static CompanyID GetCompany();
00196 
00202   static CompanyID GetRootCompany();
00203 
00207   static void SetLastCost(Money last_cost);
00208 
00212   static Money GetLastCost();
00213 
00217   static void SetCallbackVariable(int index, int value);
00218 
00222   static int GetCallbackVariable(int index);
00223 
00227   static bool CanSuspend();
00228 
00232   static void *&GetEventPointer();
00233 
00237   static void *&GetLogPointer();
00238 
00239 private:
00244   static void SetNewVehicleID(VehicleID vehicle_id);
00245 
00250   static void SetNewSignID(SignID sign_id);
00251 
00256   static void SetNewGroupID(GroupID group_id);
00257 
00262   static void SetNewGoalID(GoalID goal_id);
00263 };
00264 
00265 #endif /* SCRIPT_OBJECT_HPP */