626 begin |
626 begin |
627 if CheckLuaParamCount(L, 4,'SpawnFakeHealthCrate', 'x, y, explode, poison') then |
627 if CheckLuaParamCount(L, 4,'SpawnFakeHealthCrate', 'x, y, explode, poison') then |
628 begin |
628 begin |
629 gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), |
629 gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), |
630 HealthCrate, lua_toboolean(L, 3), lua_toboolean(L, 4)); |
630 HealthCrate, lua_toboolean(L, 3), lua_toboolean(L, 4)); |
631 lua_pushinteger(L, gear^.uid); |
631 if gear <> nil then |
|
632 lua_pushinteger(L, gear^.uid) |
|
633 else lua_pushnil(L) |
632 end |
634 end |
633 else |
635 else |
634 lua_pushnil(L); |
636 lua_pushnil(L); |
635 lc_spawnfakehealthcrate := 1; |
637 lc_spawnfakehealthcrate := 1; |
636 end; |
638 end; |
640 begin |
642 begin |
641 if CheckLuaParamCount(L, 4,'SpawnFakeAmmoCrate', 'x, y, explode, poison') then |
643 if CheckLuaParamCount(L, 4,'SpawnFakeAmmoCrate', 'x, y, explode, poison') then |
642 begin |
644 begin |
643 gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), |
645 gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), |
644 AmmoCrate, lua_toboolean(L, 3), lua_toboolean(L, 4)); |
646 AmmoCrate, lua_toboolean(L, 3), lua_toboolean(L, 4)); |
645 lua_pushinteger(L, gear^.uid); |
647 if gear <> nil then |
|
648 lua_pushinteger(L, gear^.uid) |
|
649 else lua_pushnil(L) |
646 end |
650 end |
647 else |
651 else |
648 lua_pushnil(L); |
652 lua_pushnil(L); |
649 lc_spawnfakeammocrate := 1; |
653 lc_spawnfakeammocrate := 1; |
650 end; |
654 end; |
654 begin |
658 begin |
655 if CheckLuaParamCount(L, 4,'SpawnFakeUtilityCrate', 'x, y, explode, poison') then |
659 if CheckLuaParamCount(L, 4,'SpawnFakeUtilityCrate', 'x, y, explode, poison') then |
656 begin |
660 begin |
657 gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), |
661 gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), |
658 UtilityCrate, lua_toboolean(L, 3), lua_toboolean(L, 4)); |
662 UtilityCrate, lua_toboolean(L, 3), lua_toboolean(L, 4)); |
659 lua_pushinteger(L, gear^.uid); |
663 if gear <> nil then |
|
664 lua_pushinteger(L, gear^.uid) |
|
665 else lua_pushnil(L) |
660 end |
666 end |
661 else |
667 else |
662 lua_pushnil(L); |
668 lua_pushnil(L); |
663 lc_spawnfakeutilitycrate := 1; |
669 lc_spawnfakeutilitycrate := 1; |
664 end; |
670 end; |
673 health:= lua_tointeger(L, 3) |
679 health:= lua_tointeger(L, 3) |
674 else |
680 else |
675 health:= cHealthCaseAmount; |
681 health:= cHealthCaseAmount; |
676 gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), HealthCrate, health, 0); |
682 gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), HealthCrate, health, 0); |
677 if gear <> nil then |
683 if gear <> nil then |
678 lua_pushinteger(L, gear^.uid) |
684 lua_pushinteger(L, gear^.uid) |
679 else |
685 else lua_pushnil(L); |
680 lua_pushnil(L); |
|
681 end |
686 end |
682 else |
687 else |
683 lua_pushnil(L); |
688 lua_pushnil(L); |
684 lc_spawnhealthcrate := 1; |
689 lc_spawnhealthcrate := 1; |
685 end; |
690 end; |
692 begin |
697 begin |
693 if n = 3 then |
698 if n = 3 then |
694 gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), AmmoCrate, lua_tointeger(L, 3), 0) |
699 gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), AmmoCrate, lua_tointeger(L, 3), 0) |
695 else gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), AmmoCrate, lua_tointeger(L, 3), lua_tointeger(L, 4)); |
700 else gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), AmmoCrate, lua_tointeger(L, 3), lua_tointeger(L, 4)); |
696 if gear <> nil then |
701 if gear <> nil then |
697 lua_pushinteger(L, gear^.uid) |
702 lua_pushinteger(L, gear^.uid) |
698 else |
703 else lua_pushnil(L); |
699 lua_pushnil(L); |
|
700 end |
704 end |
701 else |
705 else |
702 lua_pushnil(L); |
706 lua_pushnil(L); |
703 lc_spawnammocrate := 1; |
707 lc_spawnammocrate := 1; |
704 end; |
708 end; |
711 begin |
715 begin |
712 if n = 3 then |
716 if n = 3 then |
713 gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), UtilityCrate, lua_tointeger(L, 3), 0) |
717 gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), UtilityCrate, lua_tointeger(L, 3), 0) |
714 else gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), UtilityCrate, lua_tointeger(L, 3), lua_tointeger(L, 4)); |
718 else gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), UtilityCrate, lua_tointeger(L, 3), lua_tointeger(L, 4)); |
715 if gear <> nil then |
719 if gear <> nil then |
716 lua_pushinteger(L, gear^.uid) |
720 lua_pushinteger(L, gear^.uid) |
717 else |
721 else lua_pushnil(L); |
718 lua_pushnil(L); |
|
719 end |
722 end |
720 else |
723 else |
721 lua_pushnil(L); |
724 lua_pushnil(L); |
722 lc_spawnutilitycrate := 1; |
725 lc_spawnutilitycrate := 1; |
723 end; |
726 end; |
915 lua_pushinteger(L, gear^.Karma); |
918 lua_pushinteger(L, gear^.Karma); |
916 lua_pushnumber(L, gear^.DirAngle); |
919 lua_pushnumber(L, gear^.DirAngle); |
917 lua_pushinteger(L, gear^.AdvBounce); |
920 lua_pushinteger(L, gear^.AdvBounce); |
918 lua_pushinteger(L, Integer(gear^.ImpactSound)); |
921 lua_pushinteger(L, Integer(gear^.ImpactSound)); |
919 lua_pushinteger(L, gear^.nImpactSounds); |
922 lua_pushinteger(L, gear^.nImpactSounds); |
920 lua_pushinteger(L, gear^.Tint) |
923 lua_pushinteger(L, gear^.Tint); |
|
924 lua_pushinteger(L, gear^.Damage) |
921 end |
925 end |
922 else |
926 else |
923 begin |
927 begin |
924 lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); |
928 lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); |
925 lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); |
929 lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); |
926 lua_pushnil(L) |
930 lua_pushnil(L); lua_pushnil(L) |
927 end |
931 end |
928 end |
932 end |
929 else |
933 else |
930 begin |
934 begin |
931 lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); |
935 lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); |
932 lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); |
936 lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); |
933 lua_pushnil(L) |
937 lua_pushnil(L); lua_pushnil(L) |
934 end; |
938 end; |
935 lc_getgearvalues:= 11 |
939 lc_getgearvalues:= 12 |
936 end; |
940 end; |
937 |
941 |
938 function lc_setgearvalues(L : Plua_State) : LongInt; Cdecl; |
942 function lc_setgearvalues(L : Plua_State) : LongInt; Cdecl; |
939 var gear : PGear; |
943 var gear : PGear; |
940 begin |
944 begin |
941 // Currently allows 1-12 params |
945 // Currently allows 1-13 params |
942 // if CheckLuaParamCount(L, 12, 'SetGearValues', 'gearUid, Angle, Power, WDTimer, Radius, Density, Karma, DirAngle, AdvBounce, ImpactSound, # ImpactSounds, Tint') then |
946 // if CheckLuaParamCount(L, 13, 'SetGearValues', 'gearUid, Angle, Power, WDTimer, Radius, Density, Karma, DirAngle, AdvBounce, ImpactSound, # ImpactSounds, Tint, Damage') then |
943 // begin |
947 // begin |
944 gear:= GearByUID(lua_tointeger(L, 1)); |
948 gear:= GearByUID(lua_tointeger(L, 1)); |
945 if gear <> nil then |
949 if gear <> nil then |
946 begin |
950 begin |
947 if not lua_isnoneornil(L, 2) then |
951 if not lua_isnoneornil(L, 2) then |
963 if not lua_isnoneornil(L, 10) then |
967 if not lua_isnoneornil(L, 10) then |
964 gear^.ImpactSound := TSound(lua_tointeger(L, 10)); |
968 gear^.ImpactSound := TSound(lua_tointeger(L, 10)); |
965 if not lua_isnoneornil(L, 11) then |
969 if not lua_isnoneornil(L, 11) then |
966 gear^.nImpactSounds := lua_tointeger(L, 11); |
970 gear^.nImpactSounds := lua_tointeger(L, 11); |
967 if not lua_isnoneornil(L, 12) then |
971 if not lua_isnoneornil(L, 12) then |
968 gear^.Tint := lua_tointeger(L, 12) |
972 gear^.Tint := lua_tointeger(L, 12); |
|
973 if not lua_isnoneornil(L, 13) then |
|
974 gear^.Damage := lua_tointeger(L, 13); |
969 end; |
975 end; |
970 // end |
976 // end |
971 // else |
977 // else |
972 // lua_pushnil(L); // return value on stack (nil) |
978 // lua_pushnil(L); // return value on stack (nil) |
973 lc_setgearvalues:= 0 |
979 lc_setgearvalues:= 0 |
2883 ScriptSetNil('CurrentHedgehog'); |
2889 ScriptSetNil('CurrentHedgehog'); |
2884 end; |
2890 end; |
2885 |
2891 |
2886 procedure GetGlobals; |
2892 procedure GetGlobals; |
2887 begin |
2893 begin |
|
2894 // TODO |
|
2895 // Use setters instead, because globals should be read-only! |
|
2896 // Otherwise globals might be changed by Lua, but then unexpectatly overwritten by engine when a ScriptCall is triggered by whatever Lua is doing! |
|
2897 // Sure, one could work around that in engine (e.g. by setting writable globals in SetGlobals only when their engine-side value has actually changed since SetGlobals was called the last time...), but things just get messier and messier then. |
|
2898 // It is inconsistent anyway to have some globals be read-only and others not with no indication whatsoever. |
|
2899 // -- sheepluva |
2888 TurnTimeLeft:= ScriptGetInteger('TurnTimeLeft'); |
2900 TurnTimeLeft:= ScriptGetInteger('TurnTimeLeft'); |
2889 end; |
2901 end; |
2890 |
2902 |
2891 procedure ScriptCall(fname : shortstring); |
2903 procedure ScriptCall(fname : shortstring); |
2892 begin |
2904 begin |