$treeview $search $mathjax
Stratagus
2.2.6
$projectbrief
|
$projectbrief
|
$searchbox |
_________ __ __ / _____// |_____________ _/ |______ ____ __ __ ______ \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/ / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ \ /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ > \/ \/ \//_____/ \/ ______________________ ______________________ T H E W A R B E G I N S Stratagus - A free fantasy real time strategy game engine
00001 // _________ __ __ 00002 // / _____// |_____________ _/ |______ ____ __ __ ______ 00003 // \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/ 00004 // / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ | 00005 // /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ > 00006 // \/ \/ \//_____/ \/ 00007 // ______________________ ______________________ 00008 // T H E W A R B E G I N S 00009 // Stratagus - A free fantasy real time strategy game engine 00010 // 00012 // 00013 // (c) Copyright 1998-2006 by Lutz Sammer and Jimmy Salmon 00014 // 00015 // This program is free software; you can redistribute it and/or modify 00016 // it under the terms of the GNU General Public License as published by 00017 // the Free Software Foundation; only version 2 of the License. 00018 // 00019 // This program is distributed in the hope that it will be useful, 00020 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00021 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00022 // GNU General Public License for more details. 00023 // 00024 // You should have received a copy of the GNU General Public License 00025 // along with this program; if not, write to the Free Software 00026 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 00027 // 02111-1307, USA. 00028 // 00029 00030 #ifndef __SCRIPT_H__ 00031 #define __SCRIPT_H__ 00032 00034 00035 /*---------------------------------------------------------------------------- 00036 -- Includes 00037 ----------------------------------------------------------------------------*/ 00038 00039 #ifdef __cplusplus 00040 extern "C" { 00041 #endif 00042 #include <lua.h> 00043 #include <lauxlib.h> 00044 #include <lualib.h> 00045 #ifdef __cplusplus 00046 } 00047 #endif 00048 00049 /*---------------------------------------------------------------------------- 00050 -- Declarations 00051 ----------------------------------------------------------------------------*/ 00052 00053 class CUnit; 00054 class CFile; 00055 class CFont; 00056 00057 typedef struct _lua_user_data_ { 00058 int Type; 00059 void *Data; 00060 } LuaUserData; 00061 00062 enum { 00063 LuaUnitType = 100, 00064 LuaSoundType 00065 }; 00066 00067 extern lua_State *Lua; 00068 00069 extern int LuaLoadFile(const std::string &file); 00070 extern int LuaCall(int narg, int clear, bool exitOnError = true); 00071 00072 #ifdef _MSC_VER 00073 #ifndef __func__ 00074 #define __func__ __FUNCTION__ 00075 #endif 00076 #endif 00077 00078 #define LuaError(l, args) \ 00079 do { \ 00080 fprintf(stdout, "%s:%d: %s: ", __FILE__, __LINE__, __func__); \ 00081 fprintf(stdout, args); \ 00082 fprintf(stdout, "\n"); \ 00083 lua_pushfstring(l, args); lua_error(l); \ 00084 } while (0) 00085 00086 #define LuaCheckArgs(l, args) \ 00087 do { \ 00088 if (lua_gettop(l) != args) { \ 00089 LuaError(l, "incorrect argument"); \ 00090 } \ 00091 } while (0) 00092 00093 00094 typedef enum { 00095 ENumber_Lua, 00096 ENumber_Dir, 00097 ENumber_Add, 00098 ENumber_Sub, 00099 ENumber_Mul, 00100 ENumber_Div, 00101 ENumber_Min, 00102 ENumber_Max, 00103 ENumber_Rand, 00104 00105 ENumber_Gt, 00106 ENumber_GtEq, 00107 ENumber_Lt, 00108 ENumber_LtEq, 00109 ENumber_Eq, 00110 ENumber_NEq, 00111 00112 ENumber_VideoTextLength, 00113 ENumber_StringFind, 00114 00115 00116 ENumber_UnitStat 00117 // FIXME: add others. 00118 } ENumber; 00119 00120 00121 typedef enum { 00122 EUnit_Ref 00123 // FIXME: add others. 00124 } EUnit; 00125 00126 typedef enum { 00127 EString_Lua, 00128 EString_Dir, 00129 EString_Concat, 00130 EString_String, 00131 EString_InverseVideo, 00132 EString_If, 00133 EString_UnitName, 00134 EString_SubString, 00135 EString_Line 00136 // FIXME: add others. 00137 } EString; 00138 00139 typedef enum { 00140 ES_GameInfo_Objectives 00141 } ES_GameInfo; 00142 00146 typedef enum { 00147 VariableValue = 0, 00148 VariableMax, 00149 VariableIncrease, 00150 VariableDiff, 00151 VariablePercent, 00152 VariableName 00153 } EnumVariable; 00154 00159 typedef enum { 00160 UnitRefItSelf = 0, 00161 UnitRefInside, 00162 UnitRefContainer, 00163 UnitRefWorker, 00164 UnitRefGoal 00165 } EnumUnit; 00166 00167 00172 typedef struct _NumberDesc_ NumberDesc; 00173 00178 typedef struct _UnitDesc_ UnitDesc; 00179 00180 00185 typedef struct _StringDesc_ StringDesc; 00186 00187 00188 typedef struct _binop_ { 00189 NumberDesc *Left; 00190 NumberDesc *Right; 00191 } BinOp; 00192 00196 struct _NumberDesc_ { 00197 ENumber e; 00198 union { 00199 unsigned int Index; 00200 int Val; 00201 NumberDesc *N; 00202 struct _binop_ BinOp; 00203 struct { 00204 UnitDesc *Unit; 00205 int Index; 00206 EnumVariable Component; 00207 int Loc; 00208 } UnitStat; 00209 struct { 00210 StringDesc *String; 00211 CFont *Font; 00212 } VideoTextLength; 00213 struct { 00214 StringDesc *String; 00215 char C; 00216 } StringFind; 00217 00218 } D; 00219 }; 00220 00224 struct _UnitDesc_ { 00225 EUnit e; 00226 union { 00227 CUnit **AUnit; 00228 } D; 00229 }; 00230 00234 struct _StringDesc_ { 00235 EString e; 00236 union { 00237 unsigned int Index; 00238 char *Val; 00239 struct { 00240 StringDesc **Strings; 00241 int n; 00242 } Concat; 00243 NumberDesc *Number; 00244 StringDesc *String; 00245 UnitDesc *Unit; 00246 struct { 00247 NumberDesc *Cond; 00248 StringDesc *True; 00249 StringDesc *False; 00250 } If; 00251 struct { 00252 StringDesc *String; 00253 NumberDesc *Begin; 00254 NumberDesc *End; 00255 } SubString; 00256 struct { 00257 StringDesc *String; 00258 NumberDesc *Line; 00259 NumberDesc *MaxLen; 00260 CFont *Font; 00261 } Line; 00262 ES_GameInfo GameInfoType; 00263 } D; 00264 }; 00265 00266 /*---------------------------------------------------------------------------- 00267 -- Variables 00268 ----------------------------------------------------------------------------*/ 00269 00270 extern int CclInConfigFile; 00271 00272 /*---------------------------------------------------------------------------- 00273 -- Functions 00274 ----------------------------------------------------------------------------*/ 00275 00276 extern const char *LuaToString(lua_State *l, int narg); 00277 extern int LuaToNumber(lua_State *l, int narg); 00278 extern bool LuaToBoolean(lua_State *l, int narg); 00279 00280 extern void CclGarbageCollect(int fast); 00281 extern void InitCcl(); 00282 extern void LoadCcl(const std::string& filename); 00283 extern void SaveCcl(CFile *file); 00284 extern void SavePreferences(); 00285 extern int CclCommand(const std::string &command, bool exitOnError = true); 00286 00287 extern NumberDesc *Damage; 00288 00290 extern EnumVariable Str2EnumVariable(lua_State *l, const char *s); 00291 extern NumberDesc *CclParseNumberDesc(lua_State *l); 00292 extern UnitDesc *CclParseUnitDesc(lua_State *l); 00293 StringDesc *CclParseStringDesc(lua_State *l); 00294 00295 StringDesc *NewStringDesc(const char *s); 00296 extern int EvalNumber(const NumberDesc *numberdesc); 00297 extern CUnit *EvalUnit(const UnitDesc *unitdesc); 00298 std::string EvalString(const StringDesc *s); 00299 00300 void FreeNumberDesc(NumberDesc *number); 00301 void FreeUnitDesc(UnitDesc *unitdesc); 00302 void FreeStringDesc(StringDesc *s); 00303 00304 00306 00307 #endif // !__CCL_H__