352 |
352 |
353 end; |
353 end; |
354 lc_parsecommand:= 0; |
354 lc_parsecommand:= 0; |
355 end; |
355 end; |
356 |
356 |
|
357 // sets weapon to the desired ammo type |
357 function lc_setweapon(L : Plua_State) : LongInt; Cdecl; |
358 function lc_setweapon(L : Plua_State) : LongInt; Cdecl; |
358 var at: LongInt; |
359 var at: LongInt; |
359 const |
360 const |
360 call = 'SetWeapon'; |
361 call = 'SetWeapon'; |
361 params = 'ammoType'; |
362 params = 'ammoType'; |
362 begin |
363 begin |
363 if CheckLuaParameterCount(L, 1, call, params) then |
364 // no point to run this without any CurrentHedgehog |
|
365 if (CurrentHedgehog <> nil) and (CheckLuaParameterCount(L, 1, call, params)) then |
364 begin |
366 begin |
365 at:= LuaToAmmoTypeOrd(L, 1, call, params); |
367 at:= LuaToAmmoTypeOrd(L, 1, call, params); |
366 if at >= 0 then |
368 if at >= 0 then |
367 ParseCommand('setweap ' + char(at), true, true); |
369 ParseCommand('setweap ' + char(at), true, true); |
368 end; |
370 end; |
369 lc_setweapon:= 0; |
371 lc_setweapon:= 0; |
|
372 end; |
|
373 |
|
374 // sets weapon to whatever weapons is next (wraps around, amSkip is skipped) |
|
375 function lc_setnextweapon(L : Plua_State) : LongInt; Cdecl; |
|
376 var at : LongInt; |
|
377 nextAmmo : TAmmo; |
|
378 s, a, cs, fa: LongInt; |
|
379 const |
|
380 call = 'SetNextWeapon'; |
|
381 params = ''; |
|
382 begin |
|
383 if (CurrentHedgehog <> nil) and (CheckLuaParameterCount(L, 0, call, params)) then |
|
384 begin |
|
385 at:= -1; |
|
386 with CurrentHedgehog^ do |
|
387 begin |
|
388 cs:= 0; // current slot |
|
389 fa:= 0; // first ammo item to check |
|
390 |
|
391 // if something is selected, find it's successor |
|
392 if curAmmoType <> amNothing then |
|
393 begin |
|
394 // get current slot index |
|
395 cs:= Ammoz[CurAmmoType].Slot; |
|
396 // find current ammo index |
|
397 while (fa < cMaxSlotAmmoIndex) |
|
398 and (Ammo^[cs, fa].AmmoType <> CurAmmoType) do |
|
399 inc(fa); |
|
400 // increase once more because we won't successor |
|
401 inc(fa); |
|
402 end; |
|
403 |
|
404 // find first available ammo |
|
405 // revisit current slot too (current item might not be first) |
|
406 for s:= cs to cs + cMaxSlotIndex + 1 do |
|
407 begin |
|
408 for a:= fa to cMaxSlotAmmoIndex do |
|
409 begin |
|
410 // check if we went full circle |
|
411 if (a = fa) and (s = cs + cMaxSlotIndex + 1) then |
|
412 exit(0); |
|
413 |
|
414 // get ammo |
|
415 nextAmmo:= Ammo^[s mod (cMaxSlotIndex + 1), a]; |
|
416 // only switch to ammos the hog actually has |
|
417 if (nextAmmo.AmmoType <> amNothing) |
|
418 and (nextAmmo.AmmoType <> amSkip) and (nextAmmo.Count > 0) then |
|
419 begin |
|
420 at:= ord(nextAmmo.AmmoType); |
|
421 break; |
|
422 end; |
|
423 end; |
|
424 // stop slot loop if something was found |
|
425 if at >= 0 then |
|
426 break; |
|
427 // check following slots starting with first item |
|
428 fa:= 0; |
|
429 end; |
|
430 end; |
|
431 |
|
432 if at >= 0 then |
|
433 ParseCommand('setweap ' + char(at), true, true); |
|
434 end; |
|
435 lc_setnextweapon:= 0; |
370 end; |
436 end; |
371 |
437 |
372 function lc_showmission(L : Plua_State) : LongInt; Cdecl; |
438 function lc_showmission(L : Plua_State) : LongInt; Cdecl; |
373 begin |
439 begin |
374 if CheckLuaParameterCount(L, 5, 'ShowMission', 'caption, subcaption, text, icon, time') then |
440 if CheckLuaParameterCount(L, 5, 'ShowMission', 'caption, subcaption, text, icon, time') then |
1520 //lua_pushnil(L) |
1586 //lua_pushnil(L) |
1521 lc_addteam:= 0;//1; |
1587 lc_addteam:= 0;//1; |
1522 end; |
1588 end; |
1523 |
1589 |
1524 function lc_dismissteam(L : Plua_State) : LongInt; Cdecl; |
1590 function lc_dismissteam(L : Plua_State) : LongInt; Cdecl; |
1525 var np: LongInt; |
|
1526 begin |
1591 begin |
1527 if CheckLuaParameterCount(L, 1, 'DismissTeam', 'teamname') then |
1592 if CheckLuaParameterCount(L, 1, 'DismissTeam', 'teamname') then |
1528 ParseCommand('teamgone ' + lua_tostring(L, 1), true, true); |
1593 ParseCommand('teamgone ' + lua_tostring(L, 1), true, true); |
1529 lc_dismissteam:= 0;; |
1594 lc_dismissteam:= 0;; |
1530 end; |
1595 end; |
1917 lc_placegirder:= 1 |
1982 lc_placegirder:= 1 |
1918 end; |
1983 end; |
1919 |
1984 |
1920 function lc_getcurammotype(L : Plua_State): LongInt; Cdecl; |
1985 function lc_getcurammotype(L : Plua_State): LongInt; Cdecl; |
1921 begin |
1986 begin |
1922 if CheckLuaParameterCount(L, 0, 'GetCurAmmoType', '') then |
1987 if (CurrentHedgehog <> nil) and (CheckLuaParameterCount(L, 0, 'GetCurAmmoType', '')) then |
1923 lua_pushinteger(L, ord(CurrentHedgehog^.CurAmmoType)); |
1988 lua_pushinteger(L, ord(CurrentHedgehog^.CurAmmoType)) |
|
1989 else |
|
1990 lua_pushinteger(L, ord(amNothing)); |
1924 lc_getcurammotype := 1; |
1991 lc_getcurammotype := 1; |
1925 end; |
1992 end; |
1926 |
1993 |
1927 function lc_savecampaignvar(L : Plua_State): LongInt; Cdecl; |
1994 function lc_savecampaignvar(L : Plua_State): LongInt; Cdecl; |
1928 begin |
1995 begin |
2746 lua_register(luaState, _P'GetCurAmmoType', @lc_getcurammotype); |
2813 lua_register(luaState, _P'GetCurAmmoType', @lc_getcurammotype); |
2747 lua_register(luaState, _P'TestRectForObstacle', @lc_testrectforobstacle); |
2814 lua_register(luaState, _P'TestRectForObstacle', @lc_testrectforobstacle); |
2748 lua_register(luaState, _P'GetGravity', @lc_getgravity); |
2815 lua_register(luaState, _P'GetGravity', @lc_getgravity); |
2749 lua_register(luaState, _P'SetGravity', @lc_setgravity); |
2816 lua_register(luaState, _P'SetGravity', @lc_setgravity); |
2750 lua_register(luaState, _P'SetWaterLine', @lc_setwaterline); |
2817 lua_register(luaState, _P'SetWaterLine', @lc_setwaterline); |
|
2818 lua_register(luaState, _P'SetNextWeapon', @lc_setnextweapon); |
2751 lua_register(luaState, _P'SetWeapon', @lc_setweapon); |
2819 lua_register(luaState, _P'SetWeapon', @lc_setweapon); |
2752 |
2820 |
2753 lua_register(luaState, _P'SetGearAIHints', @lc_setaihintsongear); |
2821 lua_register(luaState, _P'SetGearAIHints', @lc_setaihintsongear); |
2754 lua_register(luaState, _P'HedgewarsScriptLoad', @lc_hedgewarsscriptload); |
2822 lua_register(luaState, _P'HedgewarsScriptLoad', @lc_hedgewarsscriptload); |
2755 lua_register(luaState, _P'DeclareAchievement', @lc_declareachievement); |
2823 lua_register(luaState, _P'DeclareAchievement', @lc_declareachievement); |