115 L:= L; // avoid compiler hint |
115 L:= L; // avoid compiler hint |
116 HideMission; |
116 HideMission; |
117 lc_hidemission:= 0; |
117 lc_hidemission:= 0; |
118 end; |
118 end; |
119 |
119 |
|
120 function lc_spawnhealthcrate(L: Plua_State) : LongInt; Cdecl; |
|
121 var x, y: LongInt; |
|
122 begin |
|
123 if lua_gettop(L) <> 2 then begin |
|
124 LuaError('Lua: Wrong number of parameters passed to SpawnHealthCrate!'); |
|
125 lua_pushnil(L); |
|
126 end |
|
127 else begin |
|
128 x:= lua_tointeger(L, 1); |
|
129 y:= lua_tointeger(L, 2); |
|
130 cCaseFactor := 0; |
|
131 SpawnHealthCrate(x, y); |
|
132 end; |
|
133 lc_spawnhealthCrate := 1; |
|
134 end; |
|
135 |
120 function lc_addgear(L : Plua_State) : LongInt; Cdecl; |
136 function lc_addgear(L : Plua_State) : LongInt; Cdecl; |
121 var gear : PGear; |
137 var gear : PGear; |
122 x, y, s, t: LongInt; |
138 x, y, s, t: LongInt; |
123 dx, dy: hwFloat; |
139 dx, dy: hwFloat; |
124 gt: TGearType; |
140 gt: TGearType; |
216 end |
232 end |
217 else |
233 else |
218 lua_pushnil(L); |
234 lua_pushnil(L); |
219 end; |
235 end; |
220 lc_gethogname:= 1 |
236 lc_gethogname:= 1 |
|
237 end; |
|
238 |
|
239 function lc_gettimer(L : Plua_State) : LongInt; Cdecl; |
|
240 var gear : PGear; |
|
241 begin |
|
242 if lua_gettop(L) <> 1 then |
|
243 begin |
|
244 LuaError('Lua: Wrong number of parameters passed to GetTimer!'); |
|
245 lua_pushnil(L); // return value on stack (nil) |
|
246 end |
|
247 else |
|
248 begin |
|
249 gear:= GearByUID(lua_tointeger(L, 1)); |
|
250 if gear <> nil then |
|
251 lua_pushnumber(L, gear^.Timer) |
|
252 else |
|
253 lua_pushnil(L); |
|
254 end; |
|
255 lc_gettimer:= 1 |
|
256 end; |
|
257 |
|
258 function lc_gethealth(L : Plua_State) : LongInt; Cdecl; |
|
259 var gear : PGear; |
|
260 begin |
|
261 if lua_gettop(L) <> 1 then |
|
262 begin |
|
263 LuaError('Lua: Wrong number of parameters passed to GetHealth!'); |
|
264 lua_pushnil(L); // return value on stack (nil) |
|
265 end |
|
266 else |
|
267 begin |
|
268 gear:= GearByUID(lua_tointeger(L, 1)); |
|
269 if gear <> nil then |
|
270 lua_pushnumber(L, gear^.Health) |
|
271 else |
|
272 lua_pushnil(L); |
|
273 end; |
|
274 lc_gethealth:= 1 |
221 end; |
275 end; |
222 |
276 |
223 function lc_getx(L : Plua_State) : LongInt; Cdecl; |
277 function lc_getx(L : Plua_State) : LongInt; Cdecl; |
224 var gear : PGear; |
278 var gear : PGear; |
225 begin |
279 begin |
323 LuaError('Lua: Wrong number of parameters passed to SetHealth!'); |
377 LuaError('Lua: Wrong number of parameters passed to SetHealth!'); |
324 end |
378 end |
325 else |
379 else |
326 begin |
380 begin |
327 gear:= GearByUID(lua_tointeger(L, 1)); |
381 gear:= GearByUID(lua_tointeger(L, 1)); |
328 if gear <> nil then gear^.Health:= lua_tointeger(L, 2) |
382 if gear <> nil then |
|
383 begin |
|
384 gear^.Health:= lua_tointeger(L, 2); |
|
385 SetAllToActive; |
|
386 end |
329 end; |
387 end; |
330 lc_sethealth:= 0 |
388 lc_sethealth:= 0 |
331 end; |
389 end; |
332 |
390 |
|
391 function lc_settimer(L : Plua_State) : LongInt; Cdecl; |
|
392 var gear : PGear; |
|
393 begin |
|
394 if lua_gettop(L) <> 2 then |
|
395 begin |
|
396 LuaError('Lua: Wrong number of parameters passed to SetTimer!'); |
|
397 end |
|
398 else |
|
399 begin |
|
400 gear:= GearByUID(lua_tointeger(L, 1)); |
|
401 if gear <> nil then gear^.Timer:= lua_tointeger(L, 2) |
|
402 end; |
|
403 lc_settimer:= 0 |
|
404 end; |
|
405 |
333 function lc_setstate(L : Plua_State) : LongInt; Cdecl; |
406 function lc_setstate(L : Plua_State) : LongInt; Cdecl; |
334 var gear : PGear; |
407 var gear : PGear; |
335 begin |
408 begin |
336 if lua_gettop(L) <> 2 then |
409 if lua_gettop(L) <> 2 then |
337 begin |
410 begin |
338 LuaError('Lua: Wrong number of parameters passed to SetState!'); |
411 LuaError('Lua: Wrong number of parameters passed to SetState!'); |
339 end |
412 end |
340 else |
413 else |
341 begin |
414 begin |
342 gear:= GearByUID(lua_tointeger(L, 1)); |
415 gear:= GearByUID(lua_tointeger(L, 1)); |
343 if gear <> nil then gear^.State:= lua_tointeger(L, 2) |
416 if gear <> nil then |
|
417 begin |
|
418 gear^.State:= lua_tointeger(L, 2); |
|
419 SetAllToActive; |
|
420 end |
344 end; |
421 end; |
345 lc_setstate:= 0 |
422 lc_setstate:= 0 |
346 end; |
423 end; |
347 |
424 |
348 function lc_getstate(L : Plua_State) : LongInt; Cdecl; |
425 function lc_getstate(L : Plua_State) : LongInt; Cdecl; |
371 LuaError('Lua: Wrong number of parameters passed to SetTag!'); |
448 LuaError('Lua: Wrong number of parameters passed to SetTag!'); |
372 end |
449 end |
373 else |
450 else |
374 begin |
451 begin |
375 gear:= GearByUID(lua_tointeger(L, 1)); |
452 gear:= GearByUID(lua_tointeger(L, 1)); |
376 if gear <> nil then gear^.Tag:= lua_tointeger(L, 2) |
453 if gear <> nil then |
|
454 begin |
|
455 gear^.Tag:= lua_tointeger(L, 2); |
|
456 SetAllToActive; |
|
457 end |
377 end; |
458 end; |
378 lc_settag:= 0 |
459 lc_settag:= 0 |
379 end; |
460 end; |
380 |
461 |
381 function lc_endgame(L : Plua_State) : LongInt; Cdecl; |
462 function lc_endgame(L : Plua_State) : LongInt; Cdecl; |
485 begin |
566 begin |
486 x:= lua_tointeger(L, 2); |
567 x:= lua_tointeger(L, 2); |
487 y:= lua_tointeger(L, 3); |
568 y:= lua_tointeger(L, 3); |
488 gear^.X:= int2hwfloat(x); |
569 gear^.X:= int2hwfloat(x); |
489 gear^.Y:= int2hwfloat(y); |
570 gear^.Y:= int2hwfloat(y); |
|
571 SetAllToActive; |
490 end |
572 end |
491 end; |
573 end; |
492 lc_setgearposition:= 0 |
574 lc_setgearposition:= 0 |
493 end; |
575 end; |
494 |
576 |
753 |
835 |
754 // open internal libraries |
836 // open internal libraries |
755 luaopen_base(luaState); |
837 luaopen_base(luaState); |
756 luaopen_string(luaState); |
838 luaopen_string(luaState); |
757 luaopen_math(luaState); |
839 luaopen_math(luaState); |
|
840 luaopen_table(luaState); |
758 |
841 |
759 // import some variables |
842 // import some variables |
760 ScriptSetInteger('LAND_WIDTH', LAND_WIDTH); |
843 ScriptSetInteger('LAND_WIDTH', LAND_WIDTH); |
761 ScriptSetInteger('LAND_HEIGHT', LAND_HEIGHT); |
844 ScriptSetInteger('LAND_HEIGHT', LAND_HEIGHT); |
762 |
845 |
793 for am:= Low(TAmmoType) to High(TAmmoType) do |
876 for am:= Low(TAmmoType) to High(TAmmoType) do |
794 ScriptSetInteger(EnumToStr(am), ord(am)); |
877 ScriptSetInteger(EnumToStr(am), ord(am)); |
795 |
878 |
796 // register functions |
879 // register functions |
797 lua_register(luaState, 'AddGear', @lc_addgear); |
880 lua_register(luaState, 'AddGear', @lc_addgear); |
|
881 lua_register(luaState, 'SpawnHealthCrate', @lc_spawnhealthcrate); |
798 lua_register(luaState, 'WriteLnToConsole', @lc_writelntoconsole); |
882 lua_register(luaState, 'WriteLnToConsole', @lc_writelntoconsole); |
799 lua_register(luaState, 'GetGearType', @lc_getgeartype); |
883 lua_register(luaState, 'GetGearType', @lc_getgeartype); |
800 lua_register(luaState, 'EndGame', @lc_endgame); |
884 lua_register(luaState, 'EndGame', @lc_endgame); |
801 lua_register(luaState, 'FindPlace', @lc_findplace); |
885 lua_register(luaState, 'FindPlace', @lc_findplace); |
802 lua_register(luaState, 'SetGearPosition', @lc_setgearposition); |
886 lua_register(luaState, 'SetGearPosition', @lc_setgearposition); |
818 lua_register(luaState, 'FollowGear', @lc_followgear); |
902 lua_register(luaState, 'FollowGear', @lc_followgear); |
819 lua_register(luaState, 'GetFollowGear', @lc_getfollowgear); |
903 lua_register(luaState, 'GetFollowGear', @lc_getfollowgear); |
820 lua_register(luaState, 'SetState', @lc_setstate); |
904 lua_register(luaState, 'SetState', @lc_setstate); |
821 lua_register(luaState, 'GetState', @lc_getstate); |
905 lua_register(luaState, 'GetState', @lc_getstate); |
822 lua_register(luaState, 'SetTag', @lc_settag); |
906 lua_register(luaState, 'SetTag', @lc_settag); |
|
907 lua_register(luaState, 'SetTimer', @lc_settimer); |
|
908 lua_register(luaState, 'GetTimer', @lc_gettimer); |
|
909 lua_register(luaState, 'GetHealth', @lc_gethealth); |
823 |
910 |
824 |
911 |
825 ScriptClearStack; // just to be sure stack is empty |
912 ScriptClearStack; // just to be sure stack is empty |
826 ScriptLoaded:= false; |
913 ScriptLoaded:= false; |
827 end; |
914 end; |