hedgewars/uScript.pas
branchgettext
changeset 11268 b14de8b74183
parent 11168 e104e060911b
parent 11255 66796cd627d8
equal deleted inserted replaced
11172:db1d14179b6c 11268:b14de8b74183
   627 begin
   627 begin
   628     if CheckLuaParamCount(L, 4,'SpawnFakeHealthCrate', 'x, y, explode, poison') then
   628     if CheckLuaParamCount(L, 4,'SpawnFakeHealthCrate', 'x, y, explode, poison') then
   629         begin
   629         begin
   630         gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2),
   630         gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2),
   631         HealthCrate, lua_toboolean(L, 3), lua_toboolean(L, 4));
   631         HealthCrate, lua_toboolean(L, 3), lua_toboolean(L, 4));
   632         lua_pushinteger(L, gear^.uid);
   632         if gear <> nil then
       
   633              lua_pushinteger(L, gear^.uid)
       
   634         else lua_pushnil(L)
   633         end
   635         end
   634     else
   636     else
   635         lua_pushnil(L);
   637         lua_pushnil(L);
   636     lc_spawnfakehealthcrate := 1;
   638     lc_spawnfakehealthcrate := 1;
   637 end;
   639 end;
   641 begin
   643 begin
   642     if CheckLuaParamCount(L, 4,'SpawnFakeAmmoCrate', 'x, y, explode, poison') then
   644     if CheckLuaParamCount(L, 4,'SpawnFakeAmmoCrate', 'x, y, explode, poison') then
   643         begin
   645         begin
   644         gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2),
   646         gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2),
   645         AmmoCrate, lua_toboolean(L, 3), lua_toboolean(L, 4));
   647         AmmoCrate, lua_toboolean(L, 3), lua_toboolean(L, 4));
   646         lua_pushinteger(L, gear^.uid);
   648         if gear <> nil then
       
   649              lua_pushinteger(L, gear^.uid)
       
   650         else lua_pushnil(L)
   647         end
   651         end
   648     else
   652     else
   649         lua_pushnil(L);
   653         lua_pushnil(L);
   650     lc_spawnfakeammocrate := 1;
   654     lc_spawnfakeammocrate := 1;
   651 end;
   655 end;
   655 begin
   659 begin
   656     if CheckLuaParamCount(L, 4,'SpawnFakeUtilityCrate', 'x, y, explode, poison') then
   660     if CheckLuaParamCount(L, 4,'SpawnFakeUtilityCrate', 'x, y, explode, poison') then
   657         begin
   661         begin
   658         gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2),
   662         gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2),
   659         UtilityCrate, lua_toboolean(L, 3), lua_toboolean(L, 4));
   663         UtilityCrate, lua_toboolean(L, 3), lua_toboolean(L, 4));
   660         lua_pushinteger(L, gear^.uid);
   664         if gear <> nil then
       
   665              lua_pushinteger(L, gear^.uid)
       
   666         else lua_pushnil(L)
   661         end
   667         end
   662     else
   668     else
   663         lua_pushnil(L);
   669         lua_pushnil(L);
   664     lc_spawnfakeutilitycrate := 1;
   670     lc_spawnfakeutilitycrate := 1;
   665 end;
   671 end;
   674             health:= lua_tointeger(L, 3)
   680             health:= lua_tointeger(L, 3)
   675         else
   681         else
   676             health:= cHealthCaseAmount;
   682             health:= cHealthCaseAmount;
   677         gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), HealthCrate, health, 0);
   683         gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), HealthCrate, health, 0);
   678         if gear <> nil then
   684         if gear <> nil then
   679             lua_pushinteger(L, gear^.uid)
   685              lua_pushinteger(L, gear^.uid)
   680         else
   686         else lua_pushnil(L);
   681             lua_pushnil(L);
       
   682         end
   687         end
   683     else
   688     else
   684         lua_pushnil(L);
   689         lua_pushnil(L);
   685     lc_spawnhealthcrate := 1;
   690     lc_spawnhealthcrate := 1;
   686 end;
   691 end;
   693         begin
   698         begin
   694         if n = 3 then
   699         if n = 3 then
   695              gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), AmmoCrate, lua_tointeger(L, 3), 0)
   700              gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), AmmoCrate, lua_tointeger(L, 3), 0)
   696         else gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), AmmoCrate, lua_tointeger(L, 3), lua_tointeger(L, 4));
   701         else gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), AmmoCrate, lua_tointeger(L, 3), lua_tointeger(L, 4));
   697         if gear <> nil then
   702         if gear <> nil then
   698             lua_pushinteger(L, gear^.uid)
   703              lua_pushinteger(L, gear^.uid)
   699         else
   704         else lua_pushnil(L);
   700             lua_pushnil(L);
       
   701         end
   705         end
   702     else
   706     else
   703         lua_pushnil(L);
   707         lua_pushnil(L);
   704     lc_spawnammocrate := 1;
   708     lc_spawnammocrate := 1;
   705 end;
   709 end;
   712         begin
   716         begin
   713         if n = 3 then
   717         if n = 3 then
   714              gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), UtilityCrate, lua_tointeger(L, 3), 0)
   718              gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), UtilityCrate, lua_tointeger(L, 3), 0)
   715         else gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), UtilityCrate, lua_tointeger(L, 3), lua_tointeger(L, 4));
   719         else gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), UtilityCrate, lua_tointeger(L, 3), lua_tointeger(L, 4));
   716         if gear <> nil then
   720         if gear <> nil then
   717             lua_pushinteger(L, gear^.uid)
   721              lua_pushinteger(L, gear^.uid)
   718         else
   722         else lua_pushnil(L);
   719             lua_pushnil(L);
       
   720        end
   723        end
   721     else
   724     else
   722         lua_pushnil(L);
   725         lua_pushnil(L);
   723     lc_spawnutilitycrate := 1;
   726     lc_spawnutilitycrate := 1;
   724 end;
   727 end;
   916             lua_pushinteger(L, gear^.Karma);
   919             lua_pushinteger(L, gear^.Karma);
   917             lua_pushnumber(L,  gear^.DirAngle);
   920             lua_pushnumber(L,  gear^.DirAngle);
   918             lua_pushinteger(L, gear^.AdvBounce);
   921             lua_pushinteger(L, gear^.AdvBounce);
   919             lua_pushinteger(L, Integer(gear^.ImpactSound));
   922             lua_pushinteger(L, Integer(gear^.ImpactSound));
   920             lua_pushinteger(L, gear^.nImpactSounds);
   923             lua_pushinteger(L, gear^.nImpactSounds);
   921             lua_pushinteger(L, gear^.Tint)
   924             lua_pushinteger(L, gear^.Tint);
       
   925             lua_pushinteger(L, gear^.Damage)
   922             end
   926             end
   923         else
   927         else
   924             begin
   928             begin
   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); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L);
   930             lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L);
   927             lua_pushnil(L)
   931             lua_pushnil(L); lua_pushnil(L)
   928             end
   932             end
   929         end
   933         end
   930     else
   934     else
   931         begin
   935         begin
   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); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L);
   937         lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L); lua_pushnil(L);
   934         lua_pushnil(L)
   938         lua_pushnil(L); lua_pushnil(L)
   935         end;
   939         end;
   936     lc_getgearvalues:= 11
   940     lc_getgearvalues:= 12
   937 end;
   941 end;
   938 
   942 
   939 function lc_setgearvalues(L : Plua_State) : LongInt; Cdecl;
   943 function lc_setgearvalues(L : Plua_State) : LongInt; Cdecl;
   940 var gear : PGear;
   944 var gear : PGear;
   941 begin
   945 begin
   942 // Currently allows 1-12 params
   946 // Currently allows 1-13 params
   943 //    if CheckLuaParamCount(L, 12, 'SetGearValues', 'gearUid, Angle, Power, WDTimer, Radius, Density, Karma, DirAngle, AdvBounce, ImpactSound, # ImpactSounds, Tint') then
   947 //    if CheckLuaParamCount(L, 13, 'SetGearValues', 'gearUid, Angle, Power, WDTimer, Radius, Density, Karma, DirAngle, AdvBounce, ImpactSound, # ImpactSounds, Tint, Damage') then
   944 //        begin
   948 //        begin
   945         gear:= GearByUID(lua_tointeger(L, 1));
   949         gear:= GearByUID(lua_tointeger(L, 1));
   946         if gear <> nil then
   950         if gear <> nil then
   947             begin
   951             begin
   948             if not lua_isnoneornil(L, 2) then
   952             if not lua_isnoneornil(L, 2) then
   964             if not lua_isnoneornil(L, 10) then
   968             if not lua_isnoneornil(L, 10) then
   965                 gear^.ImpactSound := TSound(lua_tointeger(L, 10));
   969                 gear^.ImpactSound := TSound(lua_tointeger(L, 10));
   966             if not lua_isnoneornil(L, 11) then
   970             if not lua_isnoneornil(L, 11) then
   967                 gear^.nImpactSounds := lua_tointeger(L, 11);
   971                 gear^.nImpactSounds := lua_tointeger(L, 11);
   968             if not lua_isnoneornil(L, 12) then
   972             if not lua_isnoneornil(L, 12) then
   969                 gear^.Tint := lua_tointeger(L, 12)
   973                 gear^.Tint := lua_tointeger(L, 12);
       
   974             if not lua_isnoneornil(L, 13) then
       
   975                 gear^.Damage := lua_tointeger(L, 13);
   970             end;
   976             end;
   971 //        end
   977 //        end
   972 //    else
   978 //    else
   973 //        lua_pushnil(L); // return value on stack (nil)
   979 //        lua_pushnil(L); // return value on stack (nil)
   974     lc_setgearvalues:= 0
   980     lc_setgearvalues:= 0
  2905     ScriptSetNil('CurrentHedgehog');
  2911     ScriptSetNil('CurrentHedgehog');
  2906 end;
  2912 end;
  2907 
  2913 
  2908 procedure GetGlobals;
  2914 procedure GetGlobals;
  2909 begin
  2915 begin
       
  2916 // TODO
       
  2917 // Use setters instead, because globals should be read-only!
       
  2918 // Otherwise globals might be changed by Lua, but then unexpectatly overwritten by engine when a ScriptCall is triggered by whatever Lua is doing!
       
  2919 // 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.
       
  2920 // It is inconsistent anyway to have some globals be read-only and others not with no indication whatsoever.
       
  2921 // -- sheepluva
  2910 TurnTimeLeft:= ScriptGetInteger('TurnTimeLeft');
  2922 TurnTimeLeft:= ScriptGetInteger('TurnTimeLeft');
  2911 end;
  2923 end;
  2912 
  2924 
  2913 procedure ScriptCall(fname : shortstring);
  2925 procedure ScriptCall(fname : shortstring);
  2914 begin
  2926 begin