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 SCRIPT_TEXT_HPP 00013 #define SCRIPT_TEXT_HPP 00014 00015 #include "script_object.hpp" 00016 #include "../../core/alloc_type.hpp" 00017 00022 class Text : public ScriptObject { 00023 public: 00029 virtual const char *GetEncodedText() = 0; 00030 }; 00031 00036 class RawText : public Text { 00037 public: 00038 RawText(const char *text) : 00039 text(strdup(text)) {} 00040 ~RawText() { free(this->text); } 00041 00042 /* virtual */ const char *GetEncodedText() { return this->text; } 00043 private: 00044 const char *text; 00045 }; 00046 00070 class ScriptText : public Text , public ZeroedMemoryAllocator { 00071 public: 00072 static const int SCRIPT_TEXT_MAX_PARAMETERS = 20; 00073 00074 #ifndef DOXYGEN_API 00075 00078 ScriptText(HSQUIRRELVM vm); 00079 #else 00080 00086 ScriptText(StringID string, ...); 00087 #endif 00088 ~ScriptText(); 00089 00090 #ifndef DOXYGEN_API 00091 00094 SQInteger _set(HSQUIRRELVM vm); 00095 00099 SQInteger SetParam(HSQUIRRELVM vm); 00100 00104 SQInteger AddParam(HSQUIRRELVM vm); 00105 #else 00106 00111 void SetParam(int parameter, Object value); 00112 00118 ScriptText *AddParam(Object value); 00119 #endif /* DOXYGEN_API */ 00120 00121 /* virtual */ const char *GetEncodedText(); 00122 00123 private: 00124 StringID string; 00125 char *params[SCRIPT_TEXT_MAX_PARAMETERS]; 00126 int parami[SCRIPT_TEXT_MAX_PARAMETERS]; 00127 ScriptText *paramt[SCRIPT_TEXT_MAX_PARAMETERS]; 00128 int paramc; 00129 00137 char *_GetEncodedText(char *p, char *lastofp); 00138 00142 SQInteger _SetParam(int k, HSQUIRRELVM vm); 00143 }; 00144 00145 #endif /* SCRIPT_TEXT_HPP */