2786
|
1 |
(*
|
|
2 |
* Hedgewars, a free turn based strategy game
|
|
3 |
* Copyright (c) 2004-2008 Andrey Korotaev <unC0Rr@gmail.com>
|
|
4 |
*
|
|
5 |
* This program is free software; you can redistribute it and/or modify
|
|
6 |
* it under the terms of the GNU General Public License as published by
|
|
7 |
* the Free Software Foundation; version 2 of the License
|
|
8 |
*
|
|
9 |
* This program is distributed in the hope that it will be useful,
|
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
* GNU General Public License for more details.
|
|
13 |
*
|
|
14 |
* You should have received a copy of the GNU General Public License
|
|
15 |
* along with this program; if not, write to the Free Software
|
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
|
17 |
*)
|
|
18 |
|
|
19 |
{$INCLUDE "options.inc"}
|
|
20 |
|
|
21 |
unit uScript;
|
|
22 |
interface
|
|
23 |
|
|
24 |
procedure ScriptPrintStack;
|
|
25 |
procedure ScriptClearStack;
|
|
26 |
|
|
27 |
procedure ScriptLoad(name : string);
|
|
28 |
procedure ScriptOnGameInit;
|
|
29 |
|
|
30 |
procedure ScriptCall(fname : string);
|
|
31 |
function ScriptCall(fname : string; par1: LongInt) : LongInt;
|
|
32 |
function ScriptCall(fname : string; par1, par2: LongInt) : LongInt;
|
|
33 |
function ScriptCall(fname : string; par1, par2, par3: LongInt) : LongInt;
|
|
34 |
function ScriptCall(fname : string; par1, par2, par3, par4 : LongInt) : LongInt;
|
|
35 |
|
|
36 |
procedure init_uScript;
|
|
37 |
procedure free_uScript;
|
|
38 |
|
|
39 |
implementation
|
|
40 |
uses LuaPas in 'LuaPas.pas',
|
|
41 |
uConsole,
|
|
42 |
uMisc,
|
|
43 |
uConsts,
|
|
44 |
uGears,
|
|
45 |
uFloat,
|
|
46 |
uWorld,
|
|
47 |
uAmmos,
|
|
48 |
uSound,
|
|
49 |
uTeams,
|
|
50 |
uKeys,
|
|
51 |
typinfo;
|
|
52 |
|
|
53 |
var luaState : Plua_State;
|
|
54 |
ScriptAmmoStore : string;
|
2793
|
55 |
ScriptLoaded : boolean;
|
2786
|
56 |
|
|
57 |
procedure ScriptPrepareAmmoStore; forward;
|
|
58 |
procedure ScriptApplyAmmoStore; forward;
|
|
59 |
procedure ScriptSetAmmo(ammo : TAmmoType; count, propability: Byte); forward;
|
|
60 |
|
|
61 |
// wrapped calls //
|
|
62 |
|
|
63 |
// functions called from lua:
|
|
64 |
// function(L : Plua_State) : LongInt; Cdecl;
|
|
65 |
// where L contains the state, returns the number of return values on the stack
|
|
66 |
// call lua_gettop(L) to receive number of parameters passed
|
|
67 |
|
|
68 |
function lc_writelntoconsole(L : Plua_State) : LongInt; Cdecl;
|
|
69 |
begin
|
|
70 |
if lua_gettop(L) = 1 then
|
|
71 |
begin
|
|
72 |
WriteLnToConsole('LUA: ' + lua_tostring(L ,1));
|
|
73 |
end
|
|
74 |
else
|
2791
|
75 |
WriteLnToConsole('LUA: Wrong number of parameters passed to WriteLnToConsole!');
|
2786
|
76 |
lc_writelntoconsole:= 0;
|
|
77 |
end;
|
|
78 |
|
|
79 |
function lc_parsecommand(L : Plua_State) : LongInt; Cdecl;
|
|
80 |
begin
|
|
81 |
if lua_gettop(L) = 1 then
|
|
82 |
begin
|
|
83 |
ParseCommand(lua_tostring(L ,1), true);
|
|
84 |
end
|
|
85 |
else
|
2791
|
86 |
WriteLnToConsole('LUA: Wrong number of parameters passed to ParseCommand!');
|
2786
|
87 |
lc_parsecommand:= 0;
|
|
88 |
end;
|
|
89 |
|
|
90 |
function lc_showmission(L : Plua_State) : LongInt; Cdecl;
|
|
91 |
begin
|
|
92 |
if lua_gettop(L) = 5 then
|
|
93 |
begin
|
|
94 |
ShowMission(lua_tostring(L, 1), lua_tostring(L, 2), lua_tostring(L, 3), lua_tointeger(L, 4), lua_tointeger(L, 5));
|
|
95 |
end
|
|
96 |
else
|
2791
|
97 |
WriteLnToConsole('LUA: Wrong number of parameters passed to ShowMission!');
|
2786
|
98 |
lc_showmission:= 0;
|
|
99 |
end;
|
|
100 |
|
|
101 |
function lc_hidemission(L : Plua_State) : LongInt; Cdecl;
|
|
102 |
begin
|
|
103 |
HideMission;
|
|
104 |
lc_hidemission:= 0;
|
|
105 |
end;
|
|
106 |
|
|
107 |
function lc_addgear(L : Plua_State) : LongInt; Cdecl;
|
|
108 |
var gear : PGear;
|
|
109 |
x, y, s, t: LongInt;
|
|
110 |
dx, dy: hwFloat;
|
|
111 |
gt: TGearType;
|
|
112 |
begin
|
|
113 |
if lua_gettop(L) <> 7 then
|
|
114 |
begin
|
2791
|
115 |
WriteLnToConsole('LUA: Wrong number of parameters passed to AddGear!');
|
2786
|
116 |
lua_pushnil(L); // return value on stack (nil)
|
|
117 |
end
|
|
118 |
else
|
|
119 |
begin
|
|
120 |
x:= lua_tointeger(L, 1);
|
|
121 |
y:= lua_tointeger(L, 2);
|
|
122 |
gt:= TGearType(lua_tointeger(L, 3));
|
|
123 |
s:= lua_tointeger(L, 4);
|
|
124 |
dx:= int2hwFloat(round(lua_tonumber(L, 5) * 1000)) / 1000;
|
|
125 |
dy:= int2hwFloat(round(lua_tonumber(L, 6) * 1000)) / 1000;
|
|
126 |
t:= lua_tointeger(L, 7);
|
|
127 |
|
|
128 |
gear:= AddGear(x, y, gt, s, dx, dy, t);
|
2790
|
129 |
lua_pushnumber(L, gear^.uid)
|
2786
|
130 |
end;
|
|
131 |
lc_addgear:= 1; // 1 return value
|
|
132 |
end;
|
|
133 |
|
|
134 |
function lc_getgeartype(L : Plua_State) : LongInt; Cdecl;
|
2790
|
135 |
var gear : PGear;
|
2786
|
136 |
begin
|
|
137 |
if lua_gettop(L) <> 1 then
|
|
138 |
begin
|
2791
|
139 |
WriteLnToConsole('LUA: Wrong number of parameters passed to GetGearType!');
|
2786
|
140 |
lua_pushnil(L); // return value on stack (nil)
|
|
141 |
end
|
|
142 |
else
|
2790
|
143 |
begin
|
|
144 |
gear:= GearByUID(lua_tointeger(L, 1));
|
|
145 |
if gear <> nil then
|
|
146 |
lua_pushinteger(L, ord(gear^.Kind))
|
|
147 |
end;
|
2786
|
148 |
lc_getgeartype:= 1
|
|
149 |
end;
|
|
150 |
|
|
151 |
function lc_endgame(L : Plua_State) : LongInt; Cdecl;
|
|
152 |
begin
|
|
153 |
GameState:= gsExit;
|
|
154 |
lc_endgame:= 0
|
|
155 |
end;
|
|
156 |
|
|
157 |
function lc_findplace(L : Plua_State) : LongInt; Cdecl;
|
|
158 |
var gear: PGear;
|
|
159 |
fall: boolean;
|
|
160 |
left, right: LongInt;
|
|
161 |
begin
|
|
162 |
if lua_gettop(L) <> 4 then
|
2791
|
163 |
WriteLnToConsole('LUA: Wrong number of parameters passed to FindPlace!')
|
2786
|
164 |
else
|
|
165 |
begin
|
2790
|
166 |
gear:= GearByUID(lua_tointeger(L, 1));
|
2786
|
167 |
fall:= lua_toboolean(L, 2);
|
|
168 |
left:= lua_tointeger(L, 3);
|
|
169 |
right:= lua_tointeger(L, 4);
|
2790
|
170 |
if gear <> nil then
|
|
171 |
FindPlace(gear, fall, left, right)
|
2786
|
172 |
end;
|
|
173 |
lc_findplace:= 0
|
|
174 |
end;
|
|
175 |
|
|
176 |
function lc_playsound(L : Plua_State) : LongInt; Cdecl;
|
|
177 |
begin
|
|
178 |
if lua_gettop(L) <> 1 then
|
2791
|
179 |
WriteLnToConsole('LUA: Wrong number of parameters passed to PlaySound!')
|
2786
|
180 |
else
|
|
181 |
PlaySound(TSound(lua_tointeger(L, 1)));
|
|
182 |
lc_playsound:= 0;
|
|
183 |
end;
|
|
184 |
|
|
185 |
function lc_addteam(L : Plua_State) : LongInt; Cdecl;
|
|
186 |
begin
|
|
187 |
if lua_gettop(L) <> 5 then
|
2795
|
188 |
begin
|
|
189 |
WriteLnToConsole('LUA: Wrong number of parameters passed to AddTeam!');
|
|
190 |
//lua_pushnil(L)
|
|
191 |
end
|
2786
|
192 |
else
|
|
193 |
begin
|
|
194 |
ParseCommand('addteam ' + lua_tostring(L, 2) + ' ' + lua_tostring(L, 1), true);
|
|
195 |
ParseCommand('grave ' + lua_tostring(L, 3), true);
|
|
196 |
ParseCommand('fort ' + lua_tostring(L, 4), true);
|
|
197 |
ParseCommand('voicepack ' + lua_tostring(L, 5), true);
|
|
198 |
CurrentTeam^.Binds:= DefaultBinds;
|
2795
|
199 |
// fails on x64
|
|
200 |
//lua_pushinteger(L, LongInt(CurrentTeam));
|
2786
|
201 |
end;
|
2795
|
202 |
lc_addteam:= 0;//1;
|
2786
|
203 |
end;
|
|
204 |
|
|
205 |
function lc_addhog(L : Plua_State) : LongInt; Cdecl;
|
|
206 |
begin
|
|
207 |
if lua_gettop(L) <> 4 then
|
|
208 |
begin
|
2791
|
209 |
WriteLnToConsole('LUA: Wrong number of parameters passed to AddHog!');
|
2786
|
210 |
lua_pushnil(L)
|
|
211 |
end
|
|
212 |
else
|
|
213 |
begin
|
|
214 |
ParseCommand('addhh ' + lua_tostring(L, 2) + ' ' + lua_tostring(L, 3) + ' ' + lua_tostring(L, 1), true);
|
|
215 |
ParseCommand('hat ' + lua_tostring(L, 4), true);
|
2794
|
216 |
lua_pushinteger(L, CurrentHedgehog^.Gear^.uid);
|
2786
|
217 |
end;
|
|
218 |
lc_addhog:= 1;
|
|
219 |
end;
|
|
220 |
|
|
221 |
function lc_getgearposition(L : Plua_State) : LongInt; Cdecl;
|
|
222 |
var gear: PGear;
|
|
223 |
begin
|
|
224 |
if lua_gettop(L) <> 1 then
|
|
225 |
begin
|
2791
|
226 |
WriteLnToConsole('LUA: Wrong number of parameters passed to GetGearPosition!');
|
2786
|
227 |
lua_pushnil(L);
|
|
228 |
lua_pushnil(L)
|
|
229 |
end
|
|
230 |
else
|
|
231 |
begin
|
2790
|
232 |
gear:= GearByUID(lua_tointeger(L, 1));
|
|
233 |
if gear <> nil then
|
|
234 |
begin
|
|
235 |
lua_pushinteger(L, hwRound(gear^.X));
|
|
236 |
lua_pushinteger(L, hwRound(gear^.Y))
|
|
237 |
end
|
2786
|
238 |
end;
|
|
239 |
lc_getgearposition:= 2;
|
|
240 |
end;
|
|
241 |
|
|
242 |
function lc_setgearposition(L : Plua_State) : LongInt; Cdecl;
|
|
243 |
var gear: PGear;
|
|
244 |
x, y: LongInt;
|
|
245 |
begin
|
|
246 |
if lua_gettop(L) <> 3 then
|
2791
|
247 |
WriteLnToConsole('LUA: Wrong number of parameters passed to SetGearPosition!')
|
2786
|
248 |
else
|
|
249 |
begin
|
2790
|
250 |
gear:= GearByUID(lua_tointeger(L, 1));
|
|
251 |
if gear <> nil then
|
|
252 |
begin
|
|
253 |
x:= lua_tointeger(L, 2);
|
|
254 |
y:= lua_tointeger(L, 3);
|
|
255 |
gear^.X:= int2hwfloat(x);
|
|
256 |
gear^.Y:= int2hwfloat(y);
|
|
257 |
end
|
2786
|
258 |
end;
|
|
259 |
lc_setgearposition:= 0
|
|
260 |
end;
|
|
261 |
|
|
262 |
function lc_setammo(L : Plua_State) : LongInt; Cdecl;
|
|
263 |
begin
|
|
264 |
if lua_gettop(L) <> 3 then
|
2791
|
265 |
WriteLnToConsole('LUA: Wrong number of parameters passed to SetAmmo!')
|
2786
|
266 |
else
|
|
267 |
begin
|
|
268 |
ScriptSetAmmo(TAmmoType(lua_tointeger(L, 1)), lua_tointeger(L, 2), lua_tointeger(L, 3));
|
|
269 |
end;
|
|
270 |
lc_setammo:= 0
|
|
271 |
end;
|
|
272 |
///////////////////
|
|
273 |
|
|
274 |
procedure ScriptPrintStack;
|
|
275 |
var n, i : LongInt;
|
|
276 |
begin
|
|
277 |
n:= lua_gettop(luaState);
|
2791
|
278 |
WriteLnToConsole('LUA: Stack (' + inttostr(n) + ' elements):');
|
2786
|
279 |
for i:= 1 to n do
|
|
280 |
if not lua_isboolean(luaState, i) then
|
2791
|
281 |
WriteLnToConsole('LUA: ' + inttostr(i) + ': ' + lua_tostring(luaState, i))
|
2786
|
282 |
else if lua_toboolean(luaState, i) then
|
2791
|
283 |
WriteLnToConsole('LUA: ' + inttostr(i) + ': true')
|
2786
|
284 |
else
|
2791
|
285 |
WriteLnToConsole('LUA: ' + inttostr(i) + ': false');
|
2786
|
286 |
end;
|
|
287 |
|
|
288 |
procedure ScriptClearStack;
|
|
289 |
begin
|
|
290 |
lua_settop(luaState, 0)
|
|
291 |
end;
|
|
292 |
|
|
293 |
procedure ScriptSetInteger(name : string; value : LongInt);
|
|
294 |
begin
|
|
295 |
lua_pushinteger(luaState, value);
|
|
296 |
lua_setglobal(luaState, Str2PChar(name));
|
|
297 |
end;
|
|
298 |
|
|
299 |
procedure ScriptSetString(name : string; value : string);
|
|
300 |
begin
|
|
301 |
lua_pushstring(luaState, Str2PChar(value));
|
|
302 |
lua_setglobal(luaState, Str2PChar(name));
|
|
303 |
end;
|
|
304 |
|
|
305 |
function ScriptGetInteger(name : string) : LongInt;
|
|
306 |
begin
|
|
307 |
lua_getglobal(luaState, Str2PChar(name));
|
|
308 |
ScriptGetInteger:= lua_tointeger(luaState, -1);
|
|
309 |
lua_pop(luaState, 1);
|
|
310 |
end;
|
|
311 |
|
|
312 |
function ScriptGetString(name : string) : string;
|
|
313 |
begin
|
|
314 |
lua_getglobal(luaState, Str2PChar(name));
|
|
315 |
ScriptGetString:= lua_tostring(luaState, -1);
|
|
316 |
lua_pop(luaState, 1);
|
|
317 |
end;
|
|
318 |
|
|
319 |
procedure ScriptOnGameInit;
|
|
320 |
begin
|
2793
|
321 |
// not required if there's no script to run
|
|
322 |
if not ScriptLoaded then
|
|
323 |
exit;
|
|
324 |
|
|
325 |
// push game variables so they may be modified by the script
|
|
326 |
ScriptSetInteger('GameFlags', GameFlags);
|
|
327 |
ScriptSetString('Seed', cSeed);
|
|
328 |
ScriptSetInteger('TurnTime', cHedgehogTurnTime);
|
|
329 |
ScriptSetInteger('CaseFreq', cCaseFactor);
|
|
330 |
ScriptSetInteger('LandAdds', cLandAdditions);
|
|
331 |
ScriptSetInteger('Delay', cInactDelay);
|
|
332 |
ScriptSetString('Map', '');
|
|
333 |
ScriptSetString('Theme', '');
|
2786
|
334 |
|
2793
|
335 |
ScriptCall('onGameInit');
|
|
336 |
|
|
337 |
// pop game variables
|
|
338 |
ParseCommand('seed ' + ScriptGetString('Seed'), true);
|
|
339 |
ParseCommand('$gmflags ' + ScriptGetString('GameFlags'), true);
|
|
340 |
ParseCommand('$turntime ' + ScriptGetString('TurnTime'), true);
|
|
341 |
ParseCommand('$casefreq ' + ScriptGetString('CaseFreq'), true);
|
|
342 |
ParseCommand('$landadds ' + ScriptGetString('LandAdds'), true);
|
|
343 |
ParseCommand('$delay ' + ScriptGetString('Delay'), true);
|
|
344 |
if ScriptGetString('Map') <> '' then
|
|
345 |
ParseCommand('map ' + ScriptGetString('Map'), true);
|
|
346 |
if ScriptGetString('Theme') <> '' then
|
|
347 |
ParseCommand('theme ' + ScriptGetString('Theme'), true);
|
2786
|
348 |
|
|
349 |
ScriptPrepareAmmoStore;
|
|
350 |
ScriptCall('onAmmoStoreInit');
|
|
351 |
ScriptApplyAmmoStore;
|
|
352 |
end;
|
|
353 |
|
|
354 |
procedure ScriptLoad(name : string);
|
|
355 |
var ret : LongInt;
|
|
356 |
begin
|
|
357 |
ret:= luaL_loadfile(luaState, Str2PChar(name));
|
|
358 |
if ret <> 0 then
|
2791
|
359 |
WriteLnToConsole('LUA: Failed to load ' + name + '(error ' + IntToStr(ret) + ')')
|
2786
|
360 |
else
|
|
361 |
begin
|
2791
|
362 |
WriteLnToConsole('LUA: ' + name + ' loaded');
|
2786
|
363 |
// call the script file
|
2793
|
364 |
lua_pcall(luaState, 0, 0, 0);
|
|
365 |
ScriptLoaded:= true
|
2786
|
366 |
end
|
|
367 |
end;
|
|
368 |
|
|
369 |
procedure ScriptCall(fname : string);
|
|
370 |
begin
|
2793
|
371 |
if not ScriptLoaded then
|
|
372 |
exit;
|
2786
|
373 |
lua_getglobal(luaState, Str2PChar(fname));
|
|
374 |
if lua_pcall(luaState, 0, 0, 0) <> 0 then
|
|
375 |
begin
|
2791
|
376 |
WriteLnToConsole('LUA: Error while calling ' + fname + ': ' + lua_tostring(luaState, -1));
|
2786
|
377 |
lua_pop(luaState, 1)
|
|
378 |
end;
|
|
379 |
end;
|
|
380 |
|
|
381 |
function ScriptCall(fname : string; par1: LongInt) : LongInt;
|
|
382 |
begin
|
|
383 |
ScriptCall:= ScriptCall(fname, par1, 0, 0, 0)
|
|
384 |
end;
|
|
385 |
|
|
386 |
function ScriptCall(fname : string; par1, par2: LongInt) : LongInt;
|
|
387 |
begin
|
|
388 |
ScriptCall:= ScriptCall(fname, par1, par2, 0, 0)
|
|
389 |
end;
|
|
390 |
|
|
391 |
function ScriptCall(fname : string; par1, par2, par3: LongInt) : LongInt;
|
|
392 |
begin
|
|
393 |
ScriptCall:= ScriptCall(fname, par1, par2, par3, 0)
|
|
394 |
end;
|
|
395 |
|
|
396 |
function ScriptCall(fname : string; par1, par2, par3, par4 : LongInt) : LongInt;
|
|
397 |
begin
|
2793
|
398 |
if not ScriptLoaded then
|
|
399 |
exit;
|
|
400 |
|
2786
|
401 |
lua_getglobal(luaState, Str2PChar(fname));
|
|
402 |
lua_pushinteger(luaState, par1);
|
|
403 |
lua_pushinteger(luaState, par2);
|
|
404 |
lua_pushinteger(luaState, par3);
|
|
405 |
lua_pushinteger(luaState, par4);
|
|
406 |
ScriptCall:= 0;
|
|
407 |
if lua_pcall(luaState, 4, 1, 0) <> 0 then
|
|
408 |
begin
|
2791
|
409 |
WriteLnToConsole('LUA: Error while calling ' + fname + ': ' + lua_tostring(luaState, -1));
|
2786
|
410 |
lua_pop(luaState, 1)
|
|
411 |
end
|
|
412 |
else
|
|
413 |
begin
|
|
414 |
ScriptCall:= lua_tointeger(luaState, -1);
|
|
415 |
lua_pop(luaState, 1)
|
|
416 |
end;
|
|
417 |
end;
|
|
418 |
|
|
419 |
procedure ScriptPrepareAmmoStore;
|
|
420 |
var i: ShortInt;
|
|
421 |
begin
|
|
422 |
ScriptAmmoStore:= '';
|
|
423 |
for i:=1 to ord(High(TAmmoType)) do
|
|
424 |
ScriptAmmoStore:= ScriptAmmoStore + '00';
|
|
425 |
end;
|
|
426 |
|
|
427 |
procedure ScriptSetAmmo(ammo : TAmmoType; count, propability: Byte);
|
|
428 |
begin
|
|
429 |
if (ord(ammo) < 1) or (count > 9) or (count < 0) or (propability < 0) or (propability > 8) then
|
|
430 |
exit;
|
|
431 |
ScriptAmmoStore[ord(ammo)]:= inttostr(count)[1];
|
|
432 |
ScriptAmmoStore[ord(ammo) + ord(high(TAmmoType))]:= inttostr(propability)[1];
|
|
433 |
end;
|
|
434 |
|
|
435 |
procedure ScriptApplyAmmoStore;
|
|
436 |
begin
|
|
437 |
AddAmmoStore(ScriptAmmoStore);
|
|
438 |
end;
|
|
439 |
|
|
440 |
// small helper functions making registering enums a lot easier
|
|
441 |
function str(const en : TGearType) : string; overload;
|
|
442 |
begin
|
|
443 |
str:= GetEnumName(TypeInfo(TGearType), ord(en))
|
|
444 |
end;
|
|
445 |
|
|
446 |
function str(const en : TSound) : string; overload;
|
|
447 |
begin
|
|
448 |
str:= GetEnumName(TypeInfo(TSound), ord(en))
|
|
449 |
end;
|
|
450 |
|
|
451 |
function str(const en : TAmmoType) : string; overload;
|
|
452 |
begin
|
|
453 |
str:= GetEnumName(TypeInfo(TAmmoType), ord(en))
|
|
454 |
end;
|
|
455 |
///////////////////
|
|
456 |
|
|
457 |
procedure init_uScript;
|
|
458 |
var at : TGearType;
|
|
459 |
am : TAmmoType;
|
|
460 |
st : TSound;
|
|
461 |
begin
|
|
462 |
// initialize lua
|
|
463 |
luaState:= lua_open;
|
|
464 |
|
|
465 |
// open internal libraries
|
|
466 |
luaopen_base(luaState);
|
|
467 |
luaopen_string(luaState);
|
|
468 |
luaopen_math(luaState);
|
|
469 |
|
|
470 |
// import some variables
|
|
471 |
ScriptSetInteger('LAND_WIDTH', LAND_WIDTH);
|
|
472 |
ScriptSetInteger('LAND_HEIGHT', LAND_HEIGHT);
|
|
473 |
|
|
474 |
// import game flags
|
|
475 |
ScriptSetInteger('gfForts',gfForts);
|
|
476 |
ScriptSetInteger('gfMultiWeapon',gfMultiWeapon);
|
|
477 |
ScriptSetInteger('gfSolidLand',gfSolidLand);
|
|
478 |
ScriptSetInteger('gfBorder',gfBorder);
|
|
479 |
ScriptSetInteger('gfDivideTeams',gfDivideTeams);
|
|
480 |
ScriptSetInteger('gfLowGravity',gfLowGravity);
|
|
481 |
ScriptSetInteger('gfLaserSight',gfLaserSight);
|
|
482 |
ScriptSetInteger('gfInvulnerable',gfInvulnerable);
|
|
483 |
ScriptSetInteger('gfMines',gfMines);
|
|
484 |
ScriptSetInteger('gfVampiric',gfVampiric);
|
|
485 |
ScriptSetInteger('gfKarma',gfKarma);
|
|
486 |
ScriptSetInteger('gfArtillery',gfArtillery);
|
|
487 |
ScriptSetInteger('gfOneClanMode',gfOneClanMode);
|
|
488 |
ScriptSetInteger('gfRandomOrder',gfRandomOrder);
|
|
489 |
ScriptSetInteger('gfKing',gfKing);
|
|
490 |
|
|
491 |
// register gear types
|
|
492 |
for at:= Low(TGearType) to High(TGearType) do
|
|
493 |
ScriptSetInteger(str(at), ord(at));
|
|
494 |
|
|
495 |
// register sounds
|
|
496 |
for st:= Low(TSound) to High(TSound) do
|
|
497 |
ScriptSetInteger(str(st), ord(st));
|
|
498 |
|
|
499 |
// register ammo types
|
|
500 |
for am:= Low(TAmmoType) to High(TAmmoType) do
|
|
501 |
ScriptSetInteger(str(am), ord(am));
|
|
502 |
|
|
503 |
// register functions
|
|
504 |
lua_register(luaState, 'AddGear', @lc_addgear);
|
|
505 |
lua_register(luaState, 'WriteLnToConsole', @lc_writelntoconsole);
|
|
506 |
lua_register(luaState, 'GetGearType', @lc_getgeartype);
|
|
507 |
lua_register(luaState, 'EndGame', @lc_endgame);
|
|
508 |
lua_register(luaState, 'FindPlace', @lc_findplace);
|
|
509 |
lua_register(luaState, 'SetGearPosition', @lc_setgearposition);
|
|
510 |
lua_register(luaState, 'GetGearPosition', @lc_getgearposition);
|
|
511 |
lua_register(luaState, 'ParseCommand', @lc_parsecommand);
|
|
512 |
lua_register(luaState, 'ShowMission', @lc_showmission);
|
|
513 |
lua_register(luaState, 'HideMission', @lc_hidemission);
|
|
514 |
lua_register(luaState, 'SetAmmo', @lc_setammo);
|
|
515 |
lua_register(luaState, 'PlaySound', @lc_playsound);
|
|
516 |
lua_register(luaState, 'AddTeam', @lc_addteam);
|
|
517 |
lua_register(luaState, 'AddHog', @lc_addhog);
|
|
518 |
|
|
519 |
ScriptClearStack; // just to be sure stack is empty
|
2793
|
520 |
ScriptLoaded:= false;
|
2786
|
521 |
end;
|
|
522 |
|
|
523 |
procedure free_uScript;
|
|
524 |
begin
|
|
525 |
lua_close(luaState);
|
|
526 |
end;
|
|
527 |
|
|
528 |
end.
|