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