236 // where L contains the state, returns the number of return values on the stack |
276 // where L contains the state, returns the number of return values on the stack |
237 // call lua_gettop(L) to receive number of parameters passed |
277 // call lua_gettop(L) to receive number of parameters passed |
238 |
278 |
239 function lc_band(L: PLua_State): LongInt; Cdecl; |
279 function lc_band(L: PLua_State): LongInt; Cdecl; |
240 begin |
280 begin |
241 if lua_gettop(L) <> 2 then |
281 if CheckLuaParameterCount(L, 2, 'band', 'value1, value2') then |
242 begin |
282 lua_pushinteger(L, lua_tointeger(L, 2) and lua_tointeger(L, 1)) |
243 LuaParameterCountError('band', 'value1, value2', lua_gettop(L)); |
283 else |
244 lua_pushnil(L); |
284 lua_pushnil(L); |
245 end |
|
246 else |
|
247 lua_pushinteger(L, lua_tointeger(L, 2) and lua_tointeger(L, 1)); |
|
248 lc_band := 1; |
285 lc_band := 1; |
249 end; |
286 end; |
250 |
287 |
251 function lc_bor(L: PLua_State): LongInt; Cdecl; |
288 function lc_bor(L: PLua_State): LongInt; Cdecl; |
252 begin |
289 begin |
253 if lua_gettop(L) <> 2 then |
290 if CheckLuaParameterCount(L, 2, 'bor', 'value1, value2') then |
254 begin |
291 lua_pushinteger(L, lua_tointeger(L, 2) or lua_tointeger(L, 1)) |
255 LuaParameterCountError('bor', 'value1, value2', lua_gettop(L)); |
292 else |
256 lua_pushnil(L); |
293 lua_pushnil(L); |
257 end |
|
258 else |
|
259 lua_pushinteger(L, lua_tointeger(L, 2) or lua_tointeger(L, 1)); |
|
260 lc_bor := 1; |
294 lc_bor := 1; |
261 end; |
295 end; |
262 |
296 |
263 function lc_bnot(L: PLua_State): LongInt; Cdecl; |
297 function lc_bnot(L: PLua_State): LongInt; Cdecl; |
264 begin |
298 begin |
265 if lua_gettop(L) <> 1 then |
299 if CheckLuaParameterCount(L, 1, 'bnot', 'value') then |
266 begin |
300 lua_pushinteger(L, (not lua_tointeger(L, 1))) |
267 LuaParameterCountError('bnot', 'value', lua_gettop(L)); |
301 else |
268 lua_pushnil(L); |
302 lua_pushnil(L); |
269 end |
|
270 else |
|
271 lua_pushinteger(L, (not lua_tointeger(L, 1))); |
|
272 lc_bnot := 1; |
303 lc_bnot := 1; |
273 end; |
304 end; |
274 |
305 |
275 function lc_div(L: PLua_State): LongInt; Cdecl; |
306 function lc_div(L: PLua_State): LongInt; Cdecl; |
276 begin |
307 begin |
277 if lua_gettop(L) <> 2 then |
308 if CheckLuaParameterCount(L, 2, 'div', 'dividend, divisor') then |
278 begin |
309 lua_pushinteger(L, lua_tointeger(L, 1) div lua_tointeger(L, 2)) |
279 LuaParameterCountError('div', 'dividend, divisor', lua_gettop(L)); |
310 else |
280 lua_pushnil(L); |
311 lua_pushnil(L); |
281 end |
|
282 else |
|
283 lua_pushinteger(L, lua_tointeger(L, 1) div lua_tointeger(L, 2)); |
|
284 lc_div := 1; |
312 lc_div := 1; |
285 end; |
313 end; |
286 |
314 |
287 function lc_getinputmask(L : Plua_State) : LongInt; Cdecl; |
315 function lc_getinputmask(L : Plua_State) : LongInt; Cdecl; |
288 begin |
316 begin |
289 if lua_gettop(L) <> 0 then |
317 if CheckLuaParameterCount(L, 0, 'GetInputMask', '') then |
290 LuaParameterCountError('GetInputMask', '', lua_gettop(L)) |
|
291 else |
|
292 lua_pushinteger(L, InputMask); |
318 lua_pushinteger(L, InputMask); |
293 lc_getinputmask:= 1 |
319 lc_getinputmask:= 1 |
294 end; |
320 end; |
295 |
321 |
296 function lc_setinputmask(L : Plua_State) : LongInt; Cdecl; |
322 function lc_setinputmask(L : Plua_State) : LongInt; Cdecl; |
297 begin |
323 begin |
298 if lua_gettop(L) <> 1 then |
324 if CheckLuaParameterCount(L, 1, 'SetInputMask', 'mask') then |
299 LuaParameterCountError('SetInputMask', 'mask', lua_gettop(L)) |
|
300 else |
|
301 InputMask:= lua_tointeger(L, 1); |
325 InputMask:= lua_tointeger(L, 1); |
302 lc_setinputmask:= 0 |
326 lc_setinputmask:= 0 |
303 end; |
327 end; |
304 |
328 |
305 function lc_writelntoconsole(L : Plua_State) : LongInt; Cdecl; |
329 function lc_writelntoconsole(L : Plua_State) : LongInt; Cdecl; |
306 begin |
330 begin |
307 if lua_gettop(L) = 1 then |
331 if CheckLuaParameterCount(L, 1, 'WriteLnToConsole', 'string') then |
308 begin |
|
309 WriteLnToConsole('Lua: ' + lua_tostring(L ,1)); |
332 WriteLnToConsole('Lua: ' + lua_tostring(L ,1)); |
310 end |
|
311 else |
|
312 LuaParameterCountError('WriteLnToConsole', 'string', lua_gettop(L)); |
|
313 lc_writelntoconsole:= 0; |
333 lc_writelntoconsole:= 0; |
314 end; |
334 end; |
315 |
335 |
316 function lc_parsecommand(L : Plua_State) : LongInt; Cdecl; |
336 function lc_parsecommand(L : Plua_State) : LongInt; Cdecl; |
317 var t: PChar; |
337 var t: PChar; |
318 i,c: LongWord; |
338 i,c: LongWord; |
319 s: shortstring; |
339 s: shortstring; |
320 begin |
340 begin |
321 if lua_gettop(L) = 1 then |
341 if CheckLuaParameterCount(L, 1, 'ParseCommand', 'string') then |
322 begin |
342 begin |
323 t:= lua_tolstring(L, 1, Psize_t(@c)); |
343 t:= lua_tolstring(L, 1, Psize_t(@c)); |
324 |
344 |
325 for i:= 1 to c do s[i]:= t[i-1]; |
345 for i:= 1 to c do s[i]:= t[i-1]; |
326 s[0]:= char(c); |
346 s[0]:= char(c); |
327 |
347 |
328 ParseCommand(s, true, true); |
348 ParseCommand(s, true, true); |
329 |
349 |
330 end |
350 end; |
331 else |
|
332 LuaParameterCountError('ParseCommand', 'string', lua_gettop(L)); |
|
333 lc_parsecommand:= 0; |
351 lc_parsecommand:= 0; |
334 end; |
352 end; |
335 |
353 |
336 function lc_showmission(L : Plua_State) : LongInt; Cdecl; |
354 function lc_showmission(L : Plua_State) : LongInt; Cdecl; |
337 begin |
355 begin |
338 if lua_gettop(L) = 5 then |
356 if CheckLuaParameterCount(L, 5, 'ShowMission', 'caption, subcaption, text, icon, time') then |
339 begin |
|
340 ShowMission(lua_tostringA(L, 1), lua_tostringA(L, 2), lua_tostringA(L, 3), lua_tointeger(L, 4), lua_tointeger(L, 5)); |
357 ShowMission(lua_tostringA(L, 1), lua_tostringA(L, 2), lua_tostringA(L, 3), lua_tointeger(L, 4), lua_tointeger(L, 5)); |
341 end |
|
342 else |
|
343 LuaParameterCountError('ShowMission', 'caption, subcaption, text, icon, time', lua_gettop(L)); |
|
344 lc_showmission:= 0; |
358 lc_showmission:= 0; |
345 end; |
359 end; |
346 |
360 |
347 function lc_hidemission(L : Plua_State) : LongInt; Cdecl; |
361 function lc_hidemission(L : Plua_State) : LongInt; Cdecl; |
348 begin |
362 begin |
350 HideMission; |
364 HideMission; |
351 lc_hidemission:= 0; |
365 lc_hidemission:= 0; |
352 end; |
366 end; |
353 |
367 |
354 function lc_enablegameflags(L : Plua_State) : LongInt; Cdecl; |
368 function lc_enablegameflags(L : Plua_State) : LongInt; Cdecl; |
355 var i : integer; |
369 var i, n : integer; |
356 begin |
370 begin |
357 if lua_gettop(L) = 0 then |
371 // can have 1 or more arguments |
358 begin |
372 if CheckAndFetchLuaParameterCount(L, 1, 'EnableGameFlags', 'gameFlag, ... ', n) then |
359 LuaParameterCountError('EnableGameFlags', '', lua_gettop(L)); |
373 begin |
360 lua_pushnil(L); |
374 for i:= 1 to n do |
361 end |
375 GameFlags := GameFlags or LongWord(lua_tointeger(L, i)); |
362 else |
376 ScriptSetInteger('GameFlags', GameFlags); |
363 begin |
|
364 for i:= 1 to lua_gettop(L) do |
|
365 GameFlags := GameFlags or LongWord(lua_tointeger(L, i)); |
|
366 ScriptSetInteger('GameFlags', GameFlags); |
|
367 end; |
377 end; |
368 lc_enablegameflags:= 0; |
378 lc_enablegameflags:= 0; |
369 end; |
379 end; |
370 |
380 |
371 function lc_disablegameflags(L : Plua_State) : LongInt; Cdecl; |
381 function lc_disablegameflags(L : Plua_State) : LongInt; Cdecl; |
372 var i : integer; |
382 var i , n: integer; |
373 begin |
383 begin |
374 if lua_gettop(L) = 0 then |
384 // can have 1 or more arguments |
375 begin |
385 if CheckAndFetchLuaParameterCount(L, 1, 'DisableGameFlags', 'gameFlag, ... ', n) then |
376 LuaParameterCountError('DisableGameFlags', '', lua_gettop(L)); |
386 begin |
377 lua_pushnil(L); |
387 for i:= 1 to n do |
378 end |
|
379 else |
|
380 begin |
|
381 for i:= 1 to lua_gettop(L) do |
|
382 GameFlags := GameFlags and (not LongWord(lua_tointeger(L, i))); |
388 GameFlags := GameFlags and (not LongWord(lua_tointeger(L, i))); |
383 ScriptSetInteger('GameFlags', GameFlags); |
389 ScriptSetInteger('GameFlags', GameFlags); |
384 end; |
390 end; |
385 lc_disablegameflags:= 0; |
391 lc_disablegameflags:= 0; |
386 end; |
392 end; |
387 |
393 |
388 function lc_cleargameflags(L : Plua_State) : LongInt; Cdecl; |
394 function lc_cleargameflags(L : Plua_State) : LongInt; Cdecl; |
389 begin |
395 begin |
390 if lua_gettop(L) <> 0 then |
396 if CheckLuaParameterCount(L, 0, 'ClearGameFlags', '') then |
391 begin |
|
392 LuaParameterCountError('ClearGameFlags', '', lua_gettop(L)); |
|
393 lua_pushnil(L); |
|
394 end |
|
395 else |
|
396 begin |
397 begin |
397 GameFlags:= 0; |
398 GameFlags:= 0; |
398 ScriptSetInteger('GameFlags', GameFlags); |
399 ScriptSetInteger('GameFlags', GameFlags); |
399 end; |
400 end; |
400 lc_cleargameflags:= 0; |
401 lc_cleargameflags:= 0; |
401 end; |
402 end; |
402 |
403 |
403 function lc_getgameflag(L : Plua_State) : LongInt; Cdecl; |
404 function lc_getgameflag(L : Plua_State) : LongInt; Cdecl; |
404 begin |
405 begin |
405 if lua_gettop(L) <> 1 then |
406 if CheckLuaParameterCount(L, 1, 'GetGameFlag', 'gameflag') then |
406 begin |
407 lua_pushboolean(L, (GameFlags and LongWord(lua_tointeger(L, 1)) <> 0)) |
407 LuaParameterCountError('GetGameFlag', 'gameflag', lua_gettop(L)); |
408 else |
408 lua_pushnil(L); |
409 lua_pushnil(L); |
409 end |
|
410 else |
|
411 begin |
|
412 lua_pushboolean(L, (GameFlags and LongWord(lua_tointeger(L, 1)) <> 0)); |
|
413 end; |
|
414 lc_getgameflag:= 1; |
410 lc_getgameflag:= 1; |
415 end; |
411 end; |
416 |
412 |
417 function lc_addcaption(L : Plua_State) : LongInt; Cdecl; |
413 function lc_addcaption(L : Plua_State) : LongInt; Cdecl; |
418 var cg: LongInt; |
414 var cg: LongInt; |
419 const |
415 const |
420 call = 'AddCaption'; |
416 call = 'AddCaption'; |
421 params = 'text [, color, captiongroup]'; |
417 params = 'text [, color, captiongroup]'; |
422 begin |
418 begin |
423 if lua_gettop(L) = 1 then |
419 if CheckAndFetchLuaParameterCount(L, 1, 3, call, params, cg) then |
424 AddCaption(lua_tostringA(L, 1), cWhiteColor, capgrpMessage) |
420 begin |
425 else if lua_gettop(L) = 3 then |
421 if cg = 1 then |
426 begin |
422 AddCaption(lua_tostringA(L, 1), cWhiteColor, capgrpMessage) |
427 cg:= LuaToCapGroupOrd(L, 3, call, params); |
423 else |
428 AddCaption(lua_tostringA(L, 1), lua_tointeger(L, 2) shr 8, TCapGroup(cg)); |
424 begin |
429 end |
425 cg:= LuaToCapGroupOrd(L, 3, call, params); |
430 else |
426 if cg >= 0 then |
431 LuaParameterCountError(call, params, lua_gettop(L)); |
427 AddCaption(lua_tostringA(L, 1), lua_tointeger(L, 2) shr 8, TCapGroup(cg)); |
|
428 end |
|
429 end; |
432 lc_addcaption:= 0; |
430 lc_addcaption:= 0; |
433 end; |
431 end; |
434 |
432 |
435 function lc_campaignlock(L : Plua_State) : LongInt; Cdecl; |
433 function lc_campaignlock(L : Plua_State) : LongInt; Cdecl; |
436 begin |
434 begin |
437 if lua_gettop(L) = 1 then |
435 if CheckLuaParameterCount(L, 1, 'CampaignLock', 'TODO') then |
438 begin |
436 begin |
439 // to be done |
437 // TODO |
440 end |
438 end; |
441 else |
|
442 LuaParameterCountError('CampaignLock', 'TODO', lua_gettop(L)); |
|
443 lc_campaignlock:= 0; |
439 lc_campaignlock:= 0; |
444 end; |
440 end; |
445 |
441 |
446 function lc_campaignunlock(L : Plua_State) : LongInt; Cdecl; |
442 function lc_campaignunlock(L : Plua_State) : LongInt; Cdecl; |
447 begin |
443 begin |
448 if lua_gettop(L) = 1 then |
444 if CheckLuaParameterCount(L, 1, 'CampaignUnlock', 'TODO') then |
449 begin |
445 begin |
450 // to be done |
446 // TODO |
451 end |
447 end; |
452 else |
|
453 LuaParameterCountError('CampaignUnlock', 'TODO', lua_gettop(L)); |
|
454 lc_campaignunlock:= 0; |
448 lc_campaignunlock:= 0; |
455 end; |
449 end; |
456 |
450 |
457 function lc_spawnfakehealthcrate(L: Plua_State) : LongInt; Cdecl; |
451 function lc_spawnfakehealthcrate(L: Plua_State) : LongInt; Cdecl; |
458 var gear: PGear; |
452 var gear: PGear; |
459 begin |
453 begin |
460 if lua_gettop(L) <> 4 then |
454 if CheckLuaParameterCount(L, 4,'SpawnFakeHealthCrate', 'x, y, explode, poison') then |
461 begin |
|
462 LuaParameterCountError('SpawnFakeHealthCrate', 'x, y, explode, poison', lua_gettop(L)); |
|
463 lua_pushnil(L); |
|
464 end |
|
465 else |
|
466 begin |
455 begin |
467 gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), |
456 gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), |
468 HealthCrate, lua_toboolean(L, 3), lua_toboolean(L, 4)); |
457 HealthCrate, lua_toboolean(L, 3), lua_toboolean(L, 4)); |
469 lua_pushinteger(L, gear^.uid); |
458 lua_pushinteger(L, gear^.uid); |
470 end; |
459 end |
|
460 else |
|
461 lua_pushnil(L); |
471 lc_spawnfakehealthcrate := 1; |
462 lc_spawnfakehealthcrate := 1; |
472 end; |
463 end; |
473 |
464 |
474 function lc_spawnfakeammocrate(L: PLua_State): LongInt; Cdecl; |
465 function lc_spawnfakeammocrate(L: PLua_State): LongInt; Cdecl; |
475 var gear: PGear; |
466 var gear: PGear; |
476 begin |
467 begin |
477 if lua_gettop(L) <> 4 then |
468 if CheckLuaParameterCount(L, 4,'SpawnFakeAmmoCrate', 'x, y, explode, poison') then |
478 begin |
|
479 LuaParameterCountError('SpawnFakeAmmoCrate', 'x, y, explode, poison', lua_gettop(L)); |
|
480 lua_pushnil(L); |
|
481 end |
|
482 else |
|
483 begin |
469 begin |
484 gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), |
470 gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), |
485 AmmoCrate, lua_toboolean(L, 3), lua_toboolean(L, 4)); |
471 AmmoCrate, lua_toboolean(L, 3), lua_toboolean(L, 4)); |
486 lua_pushinteger(L, gear^.uid); |
472 lua_pushinteger(L, gear^.uid); |
487 end; |
473 end |
|
474 else |
|
475 lua_pushnil(L); |
488 lc_spawnfakeammocrate := 1; |
476 lc_spawnfakeammocrate := 1; |
489 end; |
477 end; |
490 |
478 |
491 function lc_spawnfakeutilitycrate(L: PLua_State): LongInt; Cdecl; |
479 function lc_spawnfakeutilitycrate(L: PLua_State): LongInt; Cdecl; |
492 var gear: PGear; |
480 var gear: PGear; |
493 begin |
481 begin |
494 if lua_gettop(L) <> 4 then |
482 if CheckLuaParameterCount(L, 4,'SpawnFakeUtilityCrate', 'x, y, explode, poison') then |
495 begin |
|
496 LuaParameterCountError('SpawnFakeUtilityCrate', 'x, y, explode, poison', lua_gettop(L)); |
|
497 lua_pushnil(L); |
|
498 end |
|
499 else |
|
500 begin |
483 begin |
501 gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), |
484 gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), |
502 UtilityCrate, lua_toboolean(L, 3), lua_toboolean(L, 4)); |
485 UtilityCrate, lua_toboolean(L, 3), lua_toboolean(L, 4)); |
503 lua_pushinteger(L, gear^.uid); |
486 lua_pushinteger(L, gear^.uid); |
504 end; |
487 end |
|
488 else |
|
489 lua_pushnil(L); |
505 lc_spawnfakeutilitycrate := 1; |
490 lc_spawnfakeutilitycrate := 1; |
506 end; |
491 end; |
507 |
492 |
508 function lc_spawnhealthcrate(L: Plua_State) : LongInt; Cdecl; |
493 function lc_spawnhealthcrate(L: Plua_State) : LongInt; Cdecl; |
509 var gear: PGear; |
494 var gear: PGear; |
510 var health: LongInt; |
495 var health, n: LongInt; |
511 begin |
496 begin |
512 if (lua_gettop(L) < 2) or (lua_gettop(L) > 3) then |
497 if CheckAndFetchLuaParameterCount(L, 2, 3, 'SpawnHealthCrate', 'x, y [, health]', n) then |
513 begin |
498 begin |
514 LuaParameterCountError('SpawnHealthCrate', 'x, y [, health]', lua_gettop(L)); |
499 if n = 3 then |
515 lua_pushnil(L); |
|
516 end |
|
517 else |
|
518 begin |
|
519 if lua_gettop(L) = 3 then |
|
520 health:= lua_tointeger(L, 3) |
500 health:= lua_tointeger(L, 3) |
521 else |
501 else |
522 health:= cHealthCaseAmount; |
502 health:= cHealthCaseAmount; |
523 gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), HealthCrate, health, 0); |
503 gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), HealthCrate, health, 0); |
524 if gear <> nil then |
504 if gear <> nil then |
525 lua_pushinteger(L, gear^.uid) |
505 lua_pushinteger(L, gear^.uid) |
526 else |
506 else |
527 lua_pushnil(L); |
507 lua_pushnil(L); |
528 end; |
508 end |
|
509 else |
|
510 lua_pushnil(L); |
529 lc_spawnhealthcrate := 1; |
511 lc_spawnhealthcrate := 1; |
530 end; |
512 end; |
531 |
513 |
532 function lc_spawnammocrate(L: PLua_State): LongInt; Cdecl; |
514 function lc_spawnammocrate(L: PLua_State): LongInt; Cdecl; |
533 var gear: PGear; |
515 var gear: PGear; |
534 begin |
516 n : LongInt; |
535 if (lua_gettop(L) <> 3) and (lua_gettop(L) <> 4) then |
517 begin |
536 begin |
518 if CheckAndFetchLuaParameterCount(L, 3, 4, 'SpawnAmmoCrate', 'x, y, content [, amount]', n) then |
537 LuaParameterCountError('SpawnAmmoCrate', 'x, y, content [, amount]', lua_gettop(L)); |
519 begin |
538 lua_pushnil(L); |
520 if n = 3 then |
539 end |
|
540 else |
|
541 begin |
|
542 if (lua_gettop(L) = 3) then |
|
543 gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), AmmoCrate, lua_tointeger(L, 3), 0) |
521 gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), AmmoCrate, lua_tointeger(L, 3), 0) |
544 else gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), AmmoCrate, lua_tointeger(L, 3), lua_tointeger(L, 4)); |
522 else gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), AmmoCrate, lua_tointeger(L, 3), lua_tointeger(L, 4)); |
545 if gear <> nil then |
523 if gear <> nil then |
546 lua_pushinteger(L, gear^.uid) |
524 lua_pushinteger(L, gear^.uid) |
547 else |
525 else |
548 lua_pushnil(L); |
526 lua_pushnil(L); |
549 end; |
527 end |
|
528 else |
|
529 lua_pushnil(L); |
550 lc_spawnammocrate := 1; |
530 lc_spawnammocrate := 1; |
551 end; |
531 end; |
552 |
532 |
553 function lc_spawnutilitycrate(L: PLua_State): LongInt; Cdecl; |
533 function lc_spawnutilitycrate(L: PLua_State): LongInt; Cdecl; |
554 var gear: PGear; |
534 var gear: PGear; |
555 begin |
535 n : LongInt; |
556 if (lua_gettop(L) <> 3) and (lua_gettop(L) <> 4) then |
536 begin |
557 begin |
537 if CheckAndFetchLuaParameterCount(L, 3, 4, 'SpawnUtilityCrate', 'x, y, content [, amount]', n) then |
558 LuaParameterCountError('SpawnUtilityCrate', 'x, y, content [, amount]', lua_gettop(L)); |
538 begin |
559 lua_pushnil(L); |
539 if n = 3 then |
560 end |
|
561 else |
|
562 begin |
|
563 if (lua_gettop(L) = 3) then |
|
564 gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), UtilityCrate, lua_tointeger(L, 3), 0) |
540 gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), UtilityCrate, lua_tointeger(L, 3), 0) |
565 else gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), UtilityCrate, lua_tointeger(L, 3), lua_tointeger(L, 4)); |
541 else gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), UtilityCrate, lua_tointeger(L, 3), lua_tointeger(L, 4)); |
566 if gear <> nil then |
542 if gear <> nil then |
567 lua_pushinteger(L, gear^.uid) |
543 lua_pushinteger(L, gear^.uid) |
568 else |
544 else |
569 lua_pushnil(L); |
545 lua_pushnil(L); |
570 end; |
546 end |
|
547 else |
|
548 lua_pushnil(L); |
571 lc_spawnutilitycrate := 1; |
549 lc_spawnutilitycrate := 1; |
572 end; |
550 end; |
573 |
551 |
574 function lc_addgear(L : Plua_State) : LongInt; Cdecl; |
552 function lc_addgear(L : Plua_State) : LongInt; Cdecl; |
575 var gear : PGear; |
553 var gear : PGear; |
2162 |
2116 |
2163 // boolean TestRectForObstacle(x1, y1, x2, y2, landOnly) |
2117 // boolean TestRectForObstacle(x1, y1, x2, y2, landOnly) |
2164 function lc_testrectforobstacle(L : Plua_State) : LongInt; Cdecl; |
2118 function lc_testrectforobstacle(L : Plua_State) : LongInt; Cdecl; |
2165 var rtn: Boolean; |
2119 var rtn: Boolean; |
2166 begin |
2120 begin |
2167 if lua_gettop(L) <> 5 then |
2121 if CheckLuaParameterCount(L, 5, 'TestRectForObstacle', 'x1, y1, x2, y2, landOnly') then |
2168 begin |
|
2169 LuaParameterCountError('TestRectForObstacle', 'x1, y1, x2, y2, landOnly', lua_gettop(L)); |
|
2170 lua_pushnil(L); // return value on stack (nil) |
|
2171 end |
|
2172 else |
|
2173 begin |
2122 begin |
2174 rtn:= TestRectancleForObstacle( |
2123 rtn:= TestRectancleForObstacle( |
2175 lua_tointeger(L, 1), |
2124 lua_tointeger(L, 1), |
2176 lua_tointeger(L, 2), |
2125 lua_tointeger(L, 2), |
2177 lua_tointeger(L, 3), |
2126 lua_tointeger(L, 3), |
2178 lua_tointeger(L, 4), |
2127 lua_tointeger(L, 4), |
2179 lua_toboolean(L, 5) |
2128 lua_toboolean(L, 5) |
2180 ); |
2129 ); |
2181 lua_pushboolean(L, rtn); |
2130 lua_pushboolean(L, rtn); |
2182 end; |
2131 end |
|
2132 else |
|
2133 lua_pushnil(L); // return value on stack (nil) |
2183 lc_testrectforobstacle:= 1 |
2134 lc_testrectforobstacle:= 1 |
2184 end; |
2135 end; |
2185 |
2136 |
2186 |
2137 |
2187 function lc_getgravity(L : Plua_State) : LongInt; Cdecl; |
2138 function lc_getgravity(L : Plua_State) : LongInt; Cdecl; |
2188 begin |
2139 begin |
2189 if lua_gettop(L) <> 0 then |
2140 if CheckLuaParameterCount(L, 0, 'GetGravity', '') then |
2190 LuaParameterCountError('GetGravity', '', lua_gettop(L)) |
2141 lua_pushinteger(L, hwRound(SignAs(_0_5, cGravity) + (cGravity * 50 / cMaxWindSpeed))); |
2191 else if cGravity.isNegative then |
|
2192 lua_pushinteger(L, hwRound(-_0_5 + (cGravity * 50 / cMaxWindSpeed))) |
|
2193 else |
|
2194 lua_pushinteger(L, hwRound( _0_5 + (cGravity * 50 / cMaxWindSpeed))); |
|
2195 lc_getgravity:= 1 |
2142 lc_getgravity:= 1 |
2196 end; |
2143 end; |
2197 |
2144 |
2198 function lc_setgravity(L : Plua_State) : LongInt; Cdecl; |
2145 function lc_setgravity(L : Plua_State) : LongInt; Cdecl; |
2199 begin |
2146 begin |
2200 if lua_gettop(L) <> 1 then |
2147 if CheckLuaParameterCount(L, 1, 'SetGravity', 'percent') then |
2201 LuaParameterCountError('SetGravity', 'percent', lua_gettop(L)) |
|
2202 else |
|
2203 begin |
2148 begin |
2204 cGravity:= _0_02 * lua_tointeger(L, 1) * cMaxWindSpeed; |
2149 cGravity:= _0_02 * lua_tointeger(L, 1) * cMaxWindSpeed; |
2205 cGravityf:= 0.00025 * lua_tointeger(L, 1) * 0.02 |
2150 cGravityf:= 0.00025 * lua_tointeger(L, 1) * 0.02 |
2206 end; |
2151 end; |
2207 lc_setgravity:= 0 |
2152 lc_setgravity:= 0 |
2208 end; |
2153 end; |
2209 |
2154 |
2210 function lc_setwaterline(L : Plua_State) : LongInt; Cdecl; |
2155 function lc_setwaterline(L : Plua_State) : LongInt; Cdecl; |
2211 var iterator: PGear; |
2156 var iterator: PGear; |
2212 begin |
2157 begin |
2213 if lua_gettop(L) <> 1 then |
2158 if CheckLuaParameterCount(L, 1, 'SetWaterLine', 'waterline') then |
2214 LuaParameterCountError('SetWaterLine', 'waterline', lua_gettop(L)) |
|
2215 else |
|
2216 begin |
2159 begin |
2217 cWaterLine:= lua_tointeger(L,1); |
2160 cWaterLine:= lua_tointeger(L,1); |
2218 AllInactive:= false; |
2161 AllInactive:= false; |
2219 iterator:= GearsList; |
2162 iterator:= GearsList; |
2220 while iterator <> nil do |
2163 while iterator <> nil do |