33 |
33 |
34 procedure ScriptPrintStack; |
34 procedure ScriptPrintStack; |
35 procedure ScriptClearStack; |
35 procedure ScriptClearStack; |
36 |
36 |
37 procedure ScriptLoad(name : shortstring); |
37 procedure ScriptLoad(name : shortstring); |
|
38 procedure ScriptOnPreviewInit; |
38 procedure ScriptOnGameInit; |
39 procedure ScriptOnGameInit; |
39 procedure ScriptOnScreenResize; |
40 procedure ScriptOnScreenResize; |
40 procedure ScriptSetInteger(name : shortstring; value : LongInt); |
41 procedure ScriptSetInteger(name : shortstring; value : LongInt); |
41 procedure ScriptSetString(name : shortstring; value : shortstring); |
42 procedure ScriptSetString(name : shortstring; value : shortstring); |
42 |
43 |
2092 lua_getglobal(luaState, Str2PChar(name)); |
2093 lua_getglobal(luaState, Str2PChar(name)); |
2093 ScriptGetString:= lua_tostring(luaState, -1); |
2094 ScriptGetString:= lua_tostring(luaState, -1); |
2094 lua_pop(luaState, 1); |
2095 lua_pop(luaState, 1); |
2095 end; |
2096 end; |
2096 |
2097 |
|
2098 procedure ScriptOnPreviewInit; |
|
2099 var i, j, k: LongInt; |
|
2100 begin |
|
2101 // not required if there is no script to run |
|
2102 if not ScriptLoaded then |
|
2103 exit; |
|
2104 |
|
2105 ScriptSetString('Seed', cSeed); |
|
2106 ScriptSetInteger('TemplateFilter', cTemplateFilter); |
|
2107 ScriptSetInteger('TemplateNumber', LuaTemplateNumber); |
|
2108 ScriptSetInteger('MapGen', cMapGen); |
|
2109 |
|
2110 ScriptCall('onPreviewInit'); |
|
2111 |
|
2112 // pop game variables |
|
2113 ParseCommand('seed ' + ScriptGetString('Seed'), true, true); |
|
2114 cTemplateFilter := ScriptGetInteger('TemplateFilter'); |
|
2115 LuaTemplateNumber:= ScriptGetInteger('TemplateNumber'); |
|
2116 cMapGen := ScriptGetInteger('MapGen'); |
|
2117 end; |
|
2118 |
2097 procedure ScriptOnGameInit; |
2119 procedure ScriptOnGameInit; |
2098 var i, j, k: LongInt; |
2120 var i, j, k: LongInt; |
2099 begin |
2121 begin |
2100 // not required if there is no script to run |
2122 // not required if there is no script to run |
2101 if not ScriptLoaded then |
2123 if not ScriptLoaded then |
2249 WriteLnToConsole('Lua: ' + name + ' loaded'); |
2271 WriteLnToConsole('Lua: ' + name + ' loaded'); |
2250 // call the script file |
2272 // call the script file |
2251 lua_pcall(luaState, 0, 0, 0); |
2273 lua_pcall(luaState, 0, 0, 0); |
2252 ScriptLoaded:= true |
2274 ScriptLoaded:= true |
2253 end; |
2275 end; |
2254 hedgewarsMountPackage(Str2PChar(copy(s, 1, length(s)-4)+'.hwp')); |
2276 hedgewarsMountPackage(Str2PChar(copy(s, 1, length(s)-4)+'.hwp')); |
2255 end; |
2277 end; |
2256 |
2278 |
2257 procedure SetGlobals; |
2279 procedure SetGlobals; |
2258 begin |
2280 begin |
2259 ScriptSetInteger('TurnTimeLeft', TurnTimeLeft); |
2281 ScriptSetInteger('TurnTimeLeft', TurnTimeLeft); |